Jonathan Doman | 1cf66fe | 2023-03-09 12:28:21 -0800 | [diff] [blame^] | 1 | #!/bin/sh |
Jonathan Doman | 94c94bf | 2020-10-05 23:25:45 -0700 | [diff] [blame] | 2 | |
| 3 | # Utility to print all SST data present on D-Bus. |
| 4 | # Simply searches for all objects implementing known interfaces and prints out |
| 5 | # the property values on those interfaces. |
| 6 | |
Jonathan Doman | 703a185 | 2020-11-11 13:04:02 -0800 | [diff] [blame] | 7 | set -e |
| 8 | |
Jonathan Doman | 94c94bf | 2020-10-05 23:25:45 -0700 | [diff] [blame] | 9 | BUSCTL='busctl' |
| 10 | XYZ='xyz.openbmc_project' |
Jonathan Doman | 94c94bf | 2020-10-05 23:25:45 -0700 | [diff] [blame] | 11 | CPU_INTF="$XYZ.Control.Processor.CurrentOperatingConfig" |
| 12 | CONFIG_INTF="$XYZ.Inventory.Item.Cpu.OperatingConfig" |
| 13 | |
Jonathan Doman | 1cf66fe | 2023-03-09 12:28:21 -0800 | [diff] [blame^] | 14 | trim_quotes() { |
Jonathan Doman | 94c94bf | 2020-10-05 23:25:45 -0700 | [diff] [blame] | 15 | trim_obj=${1%\"} |
| 16 | trim_obj=${trim_obj#\"} |
Patrick Williams | 3e6be2e | 2022-12-04 15:46:55 -0600 | [diff] [blame] | 17 | echo "$trim_obj" |
Jonathan Doman | 94c94bf | 2020-10-05 23:25:45 -0700 | [diff] [blame] | 18 | } |
| 19 | |
Jonathan Doman | 1cf66fe | 2023-03-09 12:28:21 -0800 | [diff] [blame^] | 20 | object_mapper_call() { |
| 21 | $BUSCTL call $XYZ.ObjectMapper /xyz/openbmc_project/object_mapper \ |
| 22 | $XYZ.ObjectMapper "$@" |
| 23 | } |
| 24 | |
| 25 | get_sub_tree_paths() { |
| 26 | resp=$(object_mapper_call GetSubTreePaths sias "$1" 0 "$2" "$3" \ |
Patrick Williams | 306df48 | 2022-12-08 06:26:05 -0600 | [diff] [blame] | 27 | | cut -d' ' -f3-) |
Jonathan Doman | 94c94bf | 2020-10-05 23:25:45 -0700 | [diff] [blame] | 28 | for obj in $resp |
| 29 | do |
Patrick Williams | 3e6be2e | 2022-12-04 15:46:55 -0600 | [diff] [blame] | 30 | trim_quotes "$obj" |
Jonathan Doman | 94c94bf | 2020-10-05 23:25:45 -0700 | [diff] [blame] | 31 | done |
| 32 | } |
| 33 | |
Jonathan Doman | 1cf66fe | 2023-03-09 12:28:21 -0800 | [diff] [blame^] | 34 | get_service_from_object() { |
| 35 | trim_quotes "$(object_mapper_call GetObject sas "$1" "$2" "$3" \ |
Patrick Williams | 3e6be2e | 2022-12-04 15:46:55 -0600 | [diff] [blame] | 36 | | cut -d' ' -f3)" |
Jonathan Doman | 94c94bf | 2020-10-05 23:25:45 -0700 | [diff] [blame] | 37 | } |
| 38 | |
Jonathan Doman | 1cf66fe | 2023-03-09 12:28:21 -0800 | [diff] [blame^] | 39 | get_property_names() { |
Jonathan Doman | 94c94bf | 2020-10-05 23:25:45 -0700 | [diff] [blame] | 40 | service=$1 |
| 41 | object=$2 |
| 42 | intf=$3 |
Patrick Williams | 3e6be2e | 2022-12-04 15:46:55 -0600 | [diff] [blame] | 43 | $BUSCTL introspect "$service" "$object" "$intf" \ |
Jonathan Doman | 94c94bf | 2020-10-05 23:25:45 -0700 | [diff] [blame] | 44 | | awk '/property/ {print substr($1, 2)}' |
| 45 | } |
| 46 | |
Jonathan Doman | 1cf66fe | 2023-03-09 12:28:21 -0800 | [diff] [blame^] | 47 | get_property() { |
Jonathan Doman | 94c94bf | 2020-10-05 23:25:45 -0700 | [diff] [blame] | 48 | service=$1 |
| 49 | object=$2 |
| 50 | intf=$3 |
| 51 | prop=$4 |
Patrick Williams | 3e6be2e | 2022-12-04 15:46:55 -0600 | [diff] [blame] | 52 | $BUSCTL get-property "$service" "$object" "$intf" "$prop" |
Jonathan Doman | 94c94bf | 2020-10-05 23:25:45 -0700 | [diff] [blame] | 53 | } |
| 54 | |
Jonathan Doman | 1cf66fe | 2023-03-09 12:28:21 -0800 | [diff] [blame^] | 55 | set_property() { |
Jonathan Doman | 703a185 | 2020-11-11 13:04:02 -0800 | [diff] [blame] | 56 | service=$1 |
| 57 | object=$2 |
| 58 | intf=$3 |
| 59 | prop=$4 |
| 60 | signature=$5 |
| 61 | value=$6 |
Patrick Williams | 3e6be2e | 2022-12-04 15:46:55 -0600 | [diff] [blame] | 62 | $BUSCTL set-property "$service" "$object" "$intf" "$prop" \ |
| 63 | "$signature" "$value" |
Jonathan Doman | 703a185 | 2020-11-11 13:04:02 -0800 | [diff] [blame] | 64 | } |
Jonathan Doman | 94c94bf | 2020-10-05 23:25:45 -0700 | [diff] [blame] | 65 | |
Jonathan Doman | 1cf66fe | 2023-03-09 12:28:21 -0800 | [diff] [blame^] | 66 | show() { |
Jonathan Doman | 703a185 | 2020-11-11 13:04:02 -0800 | [diff] [blame] | 67 | cpu_paths=$(get_sub_tree_paths "/" 1 "$CPU_INTF") |
| 68 | for cpu_path in $cpu_paths |
Jonathan Doman | 94c94bf | 2020-10-05 23:25:45 -0700 | [diff] [blame] | 69 | do |
Patrick Williams | 3e6be2e | 2022-12-04 15:46:55 -0600 | [diff] [blame] | 70 | service=$(get_service_from_object "$cpu_path" 1 "$CPU_INTF") |
Jonathan Doman | 703a185 | 2020-11-11 13:04:02 -0800 | [diff] [blame] | 71 | echo "Found SST on $cpu_path on $service" |
Patrick Williams | 3e6be2e | 2022-12-04 15:46:55 -0600 | [diff] [blame] | 72 | for prop in $(get_property_names "$service" "$cpu_path" "$CPU_INTF") |
Jonathan Doman | 94c94bf | 2020-10-05 23:25:45 -0700 | [diff] [blame] | 73 | do |
Patrick Williams | 3e6be2e | 2022-12-04 15:46:55 -0600 | [diff] [blame] | 74 | echo " $prop: $(get_property "$service" "$cpu_path" "$CPU_INTF" "$prop")" |
Jonathan Doman | 703a185 | 2020-11-11 13:04:02 -0800 | [diff] [blame] | 75 | done |
| 76 | |
Jonathan Doman | 703a185 | 2020-11-11 13:04:02 -0800 | [diff] [blame] | 77 | profiles=$(get_sub_tree_paths "$cpu_path" 1 "$CONFIG_INTF") |
| 78 | for profile in $profiles |
| 79 | do |
| 80 | echo |
| 81 | echo " Found Profile $profile" |
Patrick Williams | 3e6be2e | 2022-12-04 15:46:55 -0600 | [diff] [blame] | 82 | for prop in $(get_property_names "$service" "$profile" "$CONFIG_INTF") |
Jonathan Doman | 703a185 | 2020-11-11 13:04:02 -0800 | [diff] [blame] | 83 | do |
Patrick Williams | 3e6be2e | 2022-12-04 15:46:55 -0600 | [diff] [blame] | 84 | echo " $prop: $(get_property "$service" "$profile" "$CONFIG_INTF" "$prop")" |
Jonathan Doman | 703a185 | 2020-11-11 13:04:02 -0800 | [diff] [blame] | 85 | done |
Jonathan Doman | 94c94bf | 2020-10-05 23:25:45 -0700 | [diff] [blame] | 86 | done |
| 87 | done |
Jonathan Doman | 703a185 | 2020-11-11 13:04:02 -0800 | [diff] [blame] | 88 | } |
| 89 | |
Jonathan Doman | 1cf66fe | 2023-03-09 12:28:21 -0800 | [diff] [blame^] | 90 | set_cpu_prop() { |
Jonathan Doman | 703a185 | 2020-11-11 13:04:02 -0800 | [diff] [blame] | 91 | cpu_basename=$1 |
| 92 | prop=$2 |
| 93 | signature=$3 |
| 94 | value=$4 |
| 95 | |
Jonathan Doman | 703a185 | 2020-11-11 13:04:02 -0800 | [diff] [blame] | 96 | cpu_paths=$(get_sub_tree_paths "/" 1 "$CPU_INTF") |
| 97 | for cpu_path in $cpu_paths |
| 98 | do |
Jonathan Doman | 1cf66fe | 2023-03-09 12:28:21 -0800 | [diff] [blame^] | 99 | case $cpu_path in |
| 100 | */$cpu_basename) ;; |
| 101 | *) continue ;; |
| 102 | esac |
Jonathan Doman | 703a185 | 2020-11-11 13:04:02 -0800 | [diff] [blame] | 103 | |
Jonathan Doman | 1cf66fe | 2023-03-09 12:28:21 -0800 | [diff] [blame^] | 104 | if [ "$prop" = "AppliedConfig" ] |
Jonathan Doman | 703a185 | 2020-11-11 13:04:02 -0800 | [diff] [blame] | 105 | then |
| 106 | value=$cpu_path/$value |
| 107 | fi |
| 108 | |
Patrick Williams | 3e6be2e | 2022-12-04 15:46:55 -0600 | [diff] [blame] | 109 | service=$(get_service_from_object "$cpu_path" 1 "$CPU_INTF") |
| 110 | set_property "$service" "$cpu_path" "$CPU_INTF" "$prop" "$signature" "$value" |
Jonathan Doman | 703a185 | 2020-11-11 13:04:02 -0800 | [diff] [blame] | 111 | return 0 |
| 112 | done |
| 113 | |
| 114 | echo "$cpu_basename not found" |
| 115 | return 1 |
| 116 | } |
| 117 | |
Jonathan Doman | 1cf66fe | 2023-03-09 12:28:21 -0800 | [diff] [blame^] | 118 | if [ "${DEBUG:=0}" -eq 1 ] |
Jonathan Doman | 703a185 | 2020-11-11 13:04:02 -0800 | [diff] [blame] | 119 | then |
| 120 | set -x |
| 121 | fi |
| 122 | |
| 123 | action=${1:-show} |
| 124 | |
| 125 | case "$action" in |
| 126 | show) show ;; |
Patrick Williams | 3e6be2e | 2022-12-04 15:46:55 -0600 | [diff] [blame] | 127 | set-config) set_cpu_prop "$2" AppliedConfig o "$3" ;; |
| 128 | set-bf) set_cpu_prop "$2" BaseSpeedPriorityEnabled b "$3" ;; |
Jonathan Doman | 703a185 | 2020-11-11 13:04:02 -0800 | [diff] [blame] | 129 | *) |
| 130 | echo "Usage:" |
| 131 | echo "$0 (show|set-config|set-bf) [ARGS...]" |
| 132 | echo "" |
| 133 | echo "show (Default action) - show info" |
| 134 | echo "set-config cpuN configM - Set applied operating config for cpuN to configM" |
| 135 | echo "set-bf cpuN val - Set SST-BF enablement for cpuN to val (boolean)" |
| 136 | ;; |
| 137 | esac |