xref: /openbmc/smbios-mdr/tools/sst-info.sh (revision 1cf66fee)
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'
11CPU_INTF="$XYZ.Control.Processor.CurrentOperatingConfig"
12CONFIG_INTF="$XYZ.Inventory.Item.Cpu.OperatingConfig"
13
14trim_quotes() {
15    trim_obj=${1%\"}
16    trim_obj=${trim_obj#\"}
17    echo "$trim_obj"
18}
19
20object_mapper_call() {
21    $BUSCTL call $XYZ.ObjectMapper /xyz/openbmc_project/object_mapper \
22        $XYZ.ObjectMapper "$@"
23}
24
25get_sub_tree_paths() {
26    resp=$(object_mapper_call GetSubTreePaths sias "$1" 0 "$2" "$3" \
27        | cut -d' ' -f3-)
28    for obj in $resp
29    do
30        trim_quotes "$obj"
31    done
32}
33
34get_service_from_object() {
35    trim_quotes "$(object_mapper_call GetObject sas "$1" "$2" "$3" \
36        | cut -d' ' -f3)"
37}
38
39get_property_names() {
40    service=$1
41    object=$2
42    intf=$3
43    $BUSCTL introspect "$service" "$object" "$intf" \
44        | awk '/property/ {print substr($1, 2)}'
45}
46
47get_property() {
48    service=$1
49    object=$2
50    intf=$3
51    prop=$4
52    $BUSCTL get-property "$service" "$object" "$intf" "$prop"
53}
54
55set_property() {
56    service=$1
57    object=$2
58    intf=$3
59    prop=$4
60    signature=$5
61    value=$6
62    $BUSCTL set-property "$service" "$object" "$intf" "$prop" \
63        "$signature" "$value"
64}
65
66show() {
67    cpu_paths=$(get_sub_tree_paths "/" 1 "$CPU_INTF")
68    for cpu_path in $cpu_paths
69    do
70        service=$(get_service_from_object "$cpu_path" 1 "$CPU_INTF")
71        echo "Found SST on $cpu_path on $service"
72        for prop in $(get_property_names "$service" "$cpu_path" "$CPU_INTF")
73        do
74            echo "  $prop: $(get_property "$service" "$cpu_path" "$CPU_INTF" "$prop")"
75        done
76
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"
82            for prop in $(get_property_names "$service" "$profile" "$CONFIG_INTF")
83            do
84                echo "    $prop: $(get_property "$service" "$profile" "$CONFIG_INTF" "$prop")"
85            done
86        done
87    done
88}
89
90set_cpu_prop() {
91    cpu_basename=$1
92    prop=$2
93    signature=$3
94    value=$4
95
96    cpu_paths=$(get_sub_tree_paths "/" 1 "$CPU_INTF")
97    for cpu_path in $cpu_paths
98    do
99        case $cpu_path in
100            */$cpu_basename) ;;
101            *) continue ;;
102        esac
103
104        if [ "$prop" = "AppliedConfig" ]
105        then
106            value=$cpu_path/$value
107        fi
108
109        service=$(get_service_from_object "$cpu_path" 1 "$CPU_INTF")
110        set_property "$service" "$cpu_path" "$CPU_INTF" "$prop" "$signature" "$value"
111        return 0
112    done
113
114    echo "$cpu_basename not found"
115    return 1
116}
117
118if [ "${DEBUG:=0}" -eq 1 ]
119then
120    set -x
121fi
122
123action=${1:-show}
124
125case "$action" in
126    show) show ;;
127    set-config) set_cpu_prop "$2" AppliedConfig o "$3" ;;
128    set-bf) set_cpu_prop "$2" BaseSpeedPriorityEnabled b "$3" ;;
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        ;;
137esac
138