xref: /openbmc/smbios-mdr/tools/sst-info.sh (revision 703a1856)
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
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
15trim_quotes() {
16    trim_obj=${1%\"}
17    trim_obj=${trim_obj#\"}
18    echo $trim_obj
19}
20
21get_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
30get_service_from_object() {
31    trim_quotes $($BUSCTL call $OBJECT_MAPPER GetObject sas "$1" "$2" "$3" \
32                  | cut -d' ' -f3)
33}
34
35get_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
43get_property() {
44    service=$1
45    object=$2
46    intf=$3
47    prop=$4
48    $BUSCTL get-property $service $object $intf $prop
49}
50
51set_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}
60
61show() {
62    cpu_paths=$(get_sub_tree_paths "/" 1 "$CPU_INTF")
63    for cpu_path in $cpu_paths
64    do
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)
68        do
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
82        done
83    done
84}
85
86set_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
115if [[ ${DEBUG:=0} -eq 1 ]]
116then
117    set -x
118fi
119
120action=${1:-show}
121
122case "$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        ;;
134esac
135