Brad Bishop | de6ed12 | 2016-08-30 20:14:57 -0400 | [diff] [blame] | 1 | #!/usr/bin/env python |
Norman James | 89de916 | 2015-08-27 21:41:36 -0500 | [diff] [blame] | 2 | |
CamVan Nguyen | d65b2d5 | 2018-02-27 15:14:41 -0600 | [diff] [blame] | 3 | # TODO: openbmc/openbmc#2994 remove python 2 support |
| 4 | try: # python 2 |
| 5 | import gobject |
| 6 | except ImportError: # python 3 |
| 7 | from gi.repository import GObject as gobject |
Norman James | 89de916 | 2015-08-27 21:41:36 -0500 | [diff] [blame] | 8 | import dbus |
| 9 | import dbus.service |
| 10 | import dbus.mainloop.glib |
Norman James | 90baede | 2015-09-02 20:32:49 -0500 | [diff] [blame] | 11 | import os |
Brad Bishop | 84e73b5 | 2016-05-12 15:57:52 -0400 | [diff] [blame] | 12 | from obmc.dbuslib.bindings import DbusProperties, DbusObjectManager, get_dbus |
| 13 | import obmc.enums |
Brad Bishop | 0b380f7 | 2016-06-10 00:29:50 -0400 | [diff] [blame] | 14 | import obmc_system_config as System |
Andrew Geissler | f6e918e | 2018-03-26 14:17:51 -0700 | [diff] [blame] | 15 | import obmc.inventory |
Brad Bishop | a7ac805 | 2016-09-21 09:17:05 -0400 | [diff] [blame] | 16 | import obmc.system |
Norman James | 89de916 | 2015-08-27 21:41:36 -0500 | [diff] [blame] | 17 | |
Patrick Williams | 75fe8cc | 2022-07-22 16:12:12 -0500 | [diff] [blame] | 18 | DBUS_NAME = "org.openbmc.managers.System" |
| 19 | OBJ_NAME = "/org/openbmc/managers/System" |
| 20 | INTF_SENSOR = "org.openbmc.SensorValue" |
| 21 | |
Norman James | cf74f95 | 2015-10-28 12:45:18 -0500 | [diff] [blame] | 22 | |
Brad Bishop | 416539d | 2016-07-22 07:22:42 -0400 | [diff] [blame] | 23 | class SystemManager(DbusProperties, DbusObjectManager): |
| 24 | def __init__(self, bus, obj_name): |
Patrick Williams | 75fe8cc | 2022-07-22 16:12:12 -0500 | [diff] [blame] | 25 | super(SystemManager, self).__init__(conn=bus, object_path=obj_name) |
Brad Bishop | 416539d | 2016-07-22 07:22:42 -0400 | [diff] [blame] | 26 | self.bus = bus |
Norman James | 9e6acf9 | 2015-09-08 07:00:04 -0500 | [diff] [blame] | 27 | |
Andrew Geissler | f6e918e | 2018-03-26 14:17:51 -0700 | [diff] [blame] | 28 | # replace symbolic path in ID_LOOKUP |
| 29 | for category in System.ID_LOOKUP: |
| 30 | for key in System.ID_LOOKUP[category]: |
| 31 | val = System.ID_LOOKUP[category][key] |
| 32 | new_val = val.replace( |
Patrick Williams | 75fe8cc | 2022-07-22 16:12:12 -0500 | [diff] [blame] | 33 | "<inventory_root>", obmc.inventory.INVENTORY_ROOT |
| 34 | ) |
Andrew Geissler | f6e918e | 2018-03-26 14:17:51 -0700 | [diff] [blame] | 35 | System.ID_LOOKUP[category][key] = new_val |
| 36 | |
CamVan Nguyen | d65b2d5 | 2018-02-27 15:14:41 -0600 | [diff] [blame] | 37 | print("SystemManager Init Done") |
Brad Bishop | 4de4264 | 2016-06-29 21:55:47 -0400 | [diff] [blame] | 38 | |
Andrew Geissler | f6e918e | 2018-03-26 14:17:51 -0700 | [diff] [blame] | 39 | def doObjectLookup(self, category, key): |
| 40 | obj_path = "" |
| 41 | intf_name = INTF_SENSOR |
| 42 | try: |
| 43 | obj_path = System.ID_LOOKUP[category][key] |
Patrick Williams | 75fe8cc | 2022-07-22 16:12:12 -0500 | [diff] [blame] | 44 | parts = obj_path.split("/") |
| 45 | if parts[3] != "sensors": |
| 46 | print("ERROR SystemManager: SENSOR only supported type") |
Andrew Geissler | f6e918e | 2018-03-26 14:17:51 -0700 | [diff] [blame] | 47 | intf_name = "" |
| 48 | except Exception as e: |
Patrick Williams | 75fe8cc | 2022-07-22 16:12:12 -0500 | [diff] [blame] | 49 | print("ERROR SystemManager: " + str(e) + " not found in lookup") |
Andrew Geissler | f6e918e | 2018-03-26 14:17:51 -0700 | [diff] [blame] | 50 | |
| 51 | return [obj_path, intf_name] |
| 52 | |
Patrick Williams | 75fe8cc | 2022-07-22 16:12:12 -0500 | [diff] [blame] | 53 | @dbus.service.method(DBUS_NAME, in_signature="ss", out_signature="(ss)") |
Andrew Geissler | f6e918e | 2018-03-26 14:17:51 -0700 | [diff] [blame] | 54 | def getObjectFromId(self, category, key): |
| 55 | return self.doObjectLookup(category, key) |
| 56 | |
Patrick Williams | 75fe8cc | 2022-07-22 16:12:12 -0500 | [diff] [blame] | 57 | @dbus.service.method(DBUS_NAME, in_signature="sy", out_signature="(ss)") |
Andrew Geissler | f6e918e | 2018-03-26 14:17:51 -0700 | [diff] [blame] | 58 | def getObjectFromByteId(self, category, key): |
| 59 | byte = int(key) |
| 60 | return self.doObjectLookup(category, byte) |
| 61 | |
Patrick Williams | 75fe8cc | 2022-07-22 16:12:12 -0500 | [diff] [blame] | 62 | @dbus.service.method(DBUS_NAME, in_signature="s", out_signature="sis") |
Brad Bishop | 416539d | 2016-07-22 07:22:42 -0400 | [diff] [blame] | 63 | def gpioInit(self, name): |
Patrick Williams | 75fe8cc | 2022-07-22 16:12:12 -0500 | [diff] [blame] | 64 | gpio_path = "" |
Brad Bishop | 416539d | 2016-07-22 07:22:42 -0400 | [diff] [blame] | 65 | gpio_num = -1 |
Patrick Williams | 75fe8cc | 2022-07-22 16:12:12 -0500 | [diff] [blame] | 66 | r = ["", gpio_num, ""] |
Brad Bishop | 416539d | 2016-07-22 07:22:42 -0400 | [diff] [blame] | 67 | if name not in System.GPIO_CONFIG: |
Xo Wang | 605620d | 2016-09-21 12:46:29 -0700 | [diff] [blame] | 68 | # TODO: Better error handling |
Patrick Williams | 75fe8cc | 2022-07-22 16:12:12 -0500 | [diff] [blame] | 69 | msg = "ERROR: " + name + " not found in GPIO config table" |
CamVan Nguyen | d65b2d5 | 2018-02-27 15:14:41 -0600 | [diff] [blame] | 70 | print(msg) |
Xo Wang | 605620d | 2016-09-21 12:46:29 -0700 | [diff] [blame] | 71 | raise Exception(msg) |
Brad Bishop | 416539d | 2016-07-22 07:22:42 -0400 | [diff] [blame] | 72 | else: |
| 73 | |
| 74 | gpio_num = -1 |
| 75 | gpio = System.GPIO_CONFIG[name] |
Patrick Williams | 75fe8cc | 2022-07-22 16:12:12 -0500 | [diff] [blame] | 76 | if "gpio_num" in System.GPIO_CONFIG[name]: |
| 77 | gpio_num = gpio["gpio_num"] |
Brad Bishop | 416539d | 2016-07-22 07:22:42 -0400 | [diff] [blame] | 78 | else: |
Patrick Williams | 75fe8cc | 2022-07-22 16:12:12 -0500 | [diff] [blame] | 79 | if "gpio_pin" in System.GPIO_CONFIG[name]: |
| 80 | gpio_num = obmc.system.convertGpio(gpio["gpio_pin"]) |
Brad Bishop | 416539d | 2016-07-22 07:22:42 -0400 | [diff] [blame] | 81 | else: |
Patrick Williams | 75fe8cc | 2022-07-22 16:12:12 -0500 | [diff] [blame] | 82 | msg = ( |
| 83 | "ERROR: SystemManager - GPIO lookup failed for " + name |
| 84 | ) |
CamVan Nguyen | d65b2d5 | 2018-02-27 15:14:41 -0600 | [diff] [blame] | 85 | print(msg) |
Xo Wang | 605620d | 2016-09-21 12:46:29 -0700 | [diff] [blame] | 86 | raise Exception(msg) |
Brad Bishop | 416539d | 2016-07-22 07:22:42 -0400 | [diff] [blame] | 87 | |
Patrick Williams | 75fe8cc | 2022-07-22 16:12:12 -0500 | [diff] [blame] | 88 | if gpio_num != -1: |
| 89 | r = [obmc.enums.GPIO_DEV, gpio_num, gpio["direction"]] |
Brad Bishop | 416539d | 2016-07-22 07:22:42 -0400 | [diff] [blame] | 90 | return r |
| 91 | |
Patrick Williams | 75fe8cc | 2022-07-22 16:12:12 -0500 | [diff] [blame] | 92 | @dbus.service.method( |
| 93 | DBUS_NAME, in_signature="", out_signature="ssa(sb)a(sb)a(sbb)ssssa(sb)" |
| 94 | ) |
Lei YU | 75a18a2 | 2016-11-22 01:47:47 +0800 | [diff] [blame] | 95 | def getGpioConfiguration(self): |
Patrick Williams | 75fe8cc | 2022-07-22 16:12:12 -0500 | [diff] [blame] | 96 | power_config = System.GPIO_CONFIGS.get("power_config", {}) |
| 97 | power_good_in = power_config.get("power_good_in", "") |
| 98 | latch_out = power_config.get("latch_out", "") |
| 99 | power_up_outs = power_config.get("power_up_outs", []) |
| 100 | reset_outs = power_config.get("reset_outs", []) |
| 101 | pci_reset_outs = power_config.get("pci_reset_outs", []) |
| 102 | hostctl_config = System.GPIO_CONFIGS.get("hostctl_config", {}) |
| 103 | fsi_data = hostctl_config.get("fsi_data", "") |
| 104 | fsi_clk = hostctl_config.get("fsi_clk", "") |
| 105 | fsi_enable = hostctl_config.get("fsi_enable", "") |
| 106 | cronus_sel = hostctl_config.get("cronus_sel", "") |
| 107 | optionals = hostctl_config.get("optionals", []) |
| 108 | r = [ |
| 109 | power_good_in, |
| 110 | latch_out, |
| 111 | power_up_outs, |
| 112 | reset_outs, |
| 113 | pci_reset_outs, |
| 114 | fsi_data, |
| 115 | fsi_clk, |
| 116 | fsi_enable, |
| 117 | cronus_sel, |
| 118 | optionals, |
| 119 | ] |
CamVan Nguyen | d65b2d5 | 2018-02-27 15:14:41 -0600 | [diff] [blame] | 120 | print("Power GPIO config: " + str(r)) |
Xo Wang | 3f87de8 | 2016-09-22 11:17:01 -0700 | [diff] [blame] | 121 | return r |
| 122 | |
Norman James | 89de916 | 2015-08-27 21:41:36 -0500 | [diff] [blame] | 123 | |
Patrick Williams | 75fe8cc | 2022-07-22 16:12:12 -0500 | [diff] [blame] | 124 | if __name__ == "__main__": |
Norman James | 89de916 | 2015-08-27 21:41:36 -0500 | [diff] [blame] | 125 | dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) |
Brad Bishop | 84e73b5 | 2016-05-12 15:57:52 -0400 | [diff] [blame] | 126 | bus = get_dbus() |
Brad Bishop | 416539d | 2016-07-22 07:22:42 -0400 | [diff] [blame] | 127 | obj = SystemManager(bus, OBJ_NAME) |
Norman James | 6f8d042 | 2015-09-14 18:48:00 -0500 | [diff] [blame] | 128 | mainloop = gobject.MainLoop() |
Brad Bishop | f0f3efe | 2016-06-29 23:20:24 -0400 | [diff] [blame] | 129 | obj.unmask_signals() |
Brad Bishop | 416539d | 2016-07-22 07:22:42 -0400 | [diff] [blame] | 130 | name = dbus.service.BusName(DBUS_NAME, bus) |
Norman James | 89de916 | 2015-08-27 21:41:36 -0500 | [diff] [blame] | 131 | |
CamVan Nguyen | d65b2d5 | 2018-02-27 15:14:41 -0600 | [diff] [blame] | 132 | print("Running SystemManager") |
Norman James | 89de916 | 2015-08-27 21:41:36 -0500 | [diff] [blame] | 133 | mainloop.run() |
Brad Bishop | 5306675 | 2016-09-21 08:48:04 -0400 | [diff] [blame] | 134 | |
| 135 | # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 |