blob: 82ab9039e52c9f7127b8330a9e03b6afa1c37012 [file] [log] [blame]
Brad Bishopde6ed122016-08-30 20:14:57 -04001#!/usr/bin/env python
Norman James89de9162015-08-27 21:41:36 -05002
CamVan Nguyend65b2d52018-02-27 15:14:41 -06003# TODO: openbmc/openbmc#2994 remove python 2 support
4try: # python 2
5 import gobject
6except ImportError: # python 3
7 from gi.repository import GObject as gobject
Norman James89de9162015-08-27 21:41:36 -05008import dbus
9import dbus.service
10import dbus.mainloop.glib
Norman James90baede2015-09-02 20:32:49 -050011import os
Brad Bishop84e73b52016-05-12 15:57:52 -040012from obmc.dbuslib.bindings import DbusProperties, DbusObjectManager, get_dbus
13import obmc.enums
Brad Bishop0b380f72016-06-10 00:29:50 -040014import obmc_system_config as System
Andrew Geisslerf6e918e2018-03-26 14:17:51 -070015import obmc.inventory
Brad Bishopa7ac8052016-09-21 09:17:05 -040016import obmc.system
Norman James89de9162015-08-27 21:41:36 -050017
Patrick Williams75fe8cc2022-07-22 16:12:12 -050018DBUS_NAME = "org.openbmc.managers.System"
19OBJ_NAME = "/org/openbmc/managers/System"
20INTF_SENSOR = "org.openbmc.SensorValue"
21
Norman Jamescf74f952015-10-28 12:45:18 -050022
Brad Bishop416539d2016-07-22 07:22:42 -040023class SystemManager(DbusProperties, DbusObjectManager):
24 def __init__(self, bus, obj_name):
Patrick Williams75fe8cc2022-07-22 16:12:12 -050025 super(SystemManager, self).__init__(conn=bus, object_path=obj_name)
Brad Bishop416539d2016-07-22 07:22:42 -040026 self.bus = bus
Norman James9e6acf92015-09-08 07:00:04 -050027
Andrew Geisslerf6e918e2018-03-26 14:17:51 -070028 # 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 Williams75fe8cc2022-07-22 16:12:12 -050033 "<inventory_root>", obmc.inventory.INVENTORY_ROOT
34 )
Andrew Geisslerf6e918e2018-03-26 14:17:51 -070035 System.ID_LOOKUP[category][key] = new_val
36
CamVan Nguyend65b2d52018-02-27 15:14:41 -060037 print("SystemManager Init Done")
Brad Bishop4de42642016-06-29 21:55:47 -040038
Andrew Geisslerf6e918e2018-03-26 14:17:51 -070039 def doObjectLookup(self, category, key):
40 obj_path = ""
41 intf_name = INTF_SENSOR
42 try:
43 obj_path = System.ID_LOOKUP[category][key]
Patrick Williams75fe8cc2022-07-22 16:12:12 -050044 parts = obj_path.split("/")
45 if parts[3] != "sensors":
46 print("ERROR SystemManager: SENSOR only supported type")
Andrew Geisslerf6e918e2018-03-26 14:17:51 -070047 intf_name = ""
48 except Exception as e:
Patrick Williams75fe8cc2022-07-22 16:12:12 -050049 print("ERROR SystemManager: " + str(e) + " not found in lookup")
Andrew Geisslerf6e918e2018-03-26 14:17:51 -070050
51 return [obj_path, intf_name]
52
Patrick Williams75fe8cc2022-07-22 16:12:12 -050053 @dbus.service.method(DBUS_NAME, in_signature="ss", out_signature="(ss)")
Andrew Geisslerf6e918e2018-03-26 14:17:51 -070054 def getObjectFromId(self, category, key):
55 return self.doObjectLookup(category, key)
56
Patrick Williams75fe8cc2022-07-22 16:12:12 -050057 @dbus.service.method(DBUS_NAME, in_signature="sy", out_signature="(ss)")
Andrew Geisslerf6e918e2018-03-26 14:17:51 -070058 def getObjectFromByteId(self, category, key):
59 byte = int(key)
60 return self.doObjectLookup(category, byte)
61
Patrick Williams75fe8cc2022-07-22 16:12:12 -050062 @dbus.service.method(DBUS_NAME, in_signature="s", out_signature="sis")
Brad Bishop416539d2016-07-22 07:22:42 -040063 def gpioInit(self, name):
Patrick Williams75fe8cc2022-07-22 16:12:12 -050064 gpio_path = ""
Brad Bishop416539d2016-07-22 07:22:42 -040065 gpio_num = -1
Patrick Williams75fe8cc2022-07-22 16:12:12 -050066 r = ["", gpio_num, ""]
Brad Bishop416539d2016-07-22 07:22:42 -040067 if name not in System.GPIO_CONFIG:
Xo Wang605620d2016-09-21 12:46:29 -070068 # TODO: Better error handling
Patrick Williams75fe8cc2022-07-22 16:12:12 -050069 msg = "ERROR: " + name + " not found in GPIO config table"
CamVan Nguyend65b2d52018-02-27 15:14:41 -060070 print(msg)
Xo Wang605620d2016-09-21 12:46:29 -070071 raise Exception(msg)
Brad Bishop416539d2016-07-22 07:22:42 -040072 else:
73
74 gpio_num = -1
75 gpio = System.GPIO_CONFIG[name]
Patrick Williams75fe8cc2022-07-22 16:12:12 -050076 if "gpio_num" in System.GPIO_CONFIG[name]:
77 gpio_num = gpio["gpio_num"]
Brad Bishop416539d2016-07-22 07:22:42 -040078 else:
Patrick Williams75fe8cc2022-07-22 16:12:12 -050079 if "gpio_pin" in System.GPIO_CONFIG[name]:
80 gpio_num = obmc.system.convertGpio(gpio["gpio_pin"])
Brad Bishop416539d2016-07-22 07:22:42 -040081 else:
Patrick Williams75fe8cc2022-07-22 16:12:12 -050082 msg = (
83 "ERROR: SystemManager - GPIO lookup failed for " + name
84 )
CamVan Nguyend65b2d52018-02-27 15:14:41 -060085 print(msg)
Xo Wang605620d2016-09-21 12:46:29 -070086 raise Exception(msg)
Brad Bishop416539d2016-07-22 07:22:42 -040087
Patrick Williams75fe8cc2022-07-22 16:12:12 -050088 if gpio_num != -1:
89 r = [obmc.enums.GPIO_DEV, gpio_num, gpio["direction"]]
Brad Bishop416539d2016-07-22 07:22:42 -040090 return r
91
Patrick Williams75fe8cc2022-07-22 16:12:12 -050092 @dbus.service.method(
93 DBUS_NAME, in_signature="", out_signature="ssa(sb)a(sb)a(sbb)ssssa(sb)"
94 )
Lei YU75a18a22016-11-22 01:47:47 +080095 def getGpioConfiguration(self):
Patrick Williams75fe8cc2022-07-22 16:12:12 -050096 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 Nguyend65b2d52018-02-27 15:14:41 -0600120 print("Power GPIO config: " + str(r))
Xo Wang3f87de82016-09-22 11:17:01 -0700121 return r
122
Norman James89de9162015-08-27 21:41:36 -0500123
Patrick Williams75fe8cc2022-07-22 16:12:12 -0500124if __name__ == "__main__":
Norman James89de9162015-08-27 21:41:36 -0500125 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
Brad Bishop84e73b52016-05-12 15:57:52 -0400126 bus = get_dbus()
Brad Bishop416539d2016-07-22 07:22:42 -0400127 obj = SystemManager(bus, OBJ_NAME)
Norman James6f8d0422015-09-14 18:48:00 -0500128 mainloop = gobject.MainLoop()
Brad Bishopf0f3efe2016-06-29 23:20:24 -0400129 obj.unmask_signals()
Brad Bishop416539d2016-07-22 07:22:42 -0400130 name = dbus.service.BusName(DBUS_NAME, bus)
Norman James89de9162015-08-27 21:41:36 -0500131
CamVan Nguyend65b2d52018-02-27 15:14:41 -0600132 print("Running SystemManager")
Norman James89de9162015-08-27 21:41:36 -0500133 mainloop.run()
Brad Bishop53066752016-09-21 08:48:04 -0400134
135# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4