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