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