Norman James | 19e4591 | 2015-10-04 20:19:41 -0500 | [diff] [blame] | 1 | #include "interfaces/openbmc_intf.h"
|
| 2 | #include "openbmc.h"
|
| 3 | #include "gpio.h"
|
| 4 | #define NUM_SLOTS 8
|
| 5 | GPIO slots[NUM_SLOTS] = {
|
| 6 | { "SLOT0_RISER_PRESENT" },
|
| 7 | { "SLOT1_RISER_PRESENT" },
|
| 8 | { "SLOT2_RISER_PRESENT" },
|
| 9 | { "SLOT0_PRESENT" },
|
| 10 | { "SLOT1_PRESENT" },
|
| 11 | { "SLOT2_PRESENT" },
|
| 12 | { "MEZZ0_PRESENT" },
|
| 13 | { "MEZZ1_PRESENT" },
|
| 14 | };
|
| 15 |
|
| 16 | typedef struct {
|
| 17 | const char* bus_name;
|
| 18 | const char* path;
|
| 19 | } object_info;
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 | /* ---------------------------------------------------------------------------------------------------- */
|
| 24 | int get_object(GDBusProxy *proxy, GPIO* gpio, object_info* obj_info)
|
| 25 | {
|
| 26 | g_print("Here: %s\n",gpio->name);
|
| 27 | GError *error;
|
| 28 | GVariant *parm;
|
| 29 | GVariant *result;
|
| 30 |
|
| 31 | error = NULL;
|
| 32 | parm = g_variant_new("(ss)","GPIO_PRESENT",gpio->name);
|
| 33 | result = g_dbus_proxy_call_sync (proxy,
|
| 34 | "getObjectFromId",
|
| 35 | parm,
|
| 36 | G_DBUS_CALL_FLAGS_NONE,
|
| 37 | -1,
|
| 38 | NULL,
|
| 39 | &error);
|
| 40 | g_assert_no_error (error);
|
| 41 | const gchar* bus_name;
|
| 42 | const gchar* obj_path;
|
| 43 | gsize bus_name_size;
|
| 44 | gsize obj_path_size;
|
| 45 | GVariantIter *iter = g_variant_iter_new(result);
|
| 46 | GVariant* dict = g_variant_iter_next_value(iter);
|
| 47 |
|
| 48 | GVariant* b = g_variant_lookup_value(dict,"bus_name",(const GVariantType *) "s");
|
| 49 | bus_name = g_variant_get_string(b,&bus_name_size);
|
| 50 | GVariant* o = g_variant_lookup_value(dict,"obj_path",(const GVariantType *) "s");
|
| 51 | obj_path = g_variant_get_string(o,&obj_path_size);
|
| 52 |
|
| 53 | int rc = 0;
|
| 54 | if (bus_name_size == 0 || obj_path_size == 0) {
|
| 55 | g_print("ERROR: gpio %s not found in lookup\n",gpio->name);
|
| 56 | rc = 1;
|
| 57 |
|
| 58 | } else {
|
| 59 | obj_info->bus_name = bus_name;
|
| 60 | obj_info->path = obj_path;
|
| 61 | }
|
| 62 | g_variant_unref(b);
|
| 63 | g_variant_unref(o);
|
| 64 | g_variant_unref(dict);
|
| 65 | g_variant_unref(result);
|
| 66 |
|
| 67 | return rc;
|
| 68 | }
|
| 69 |
|
| 70 | int get_presence(GDBusConnection* connection, GPIO* gpio, uint8_t* present)
|
| 71 | {
|
| 72 | int rc = GPIO_OK;
|
| 73 | do {
|
| 74 | rc = gpio_init(connection,gpio);
|
| 75 | if (rc != GPIO_OK) { break; }
|
| 76 | uint8_t gpio_val;
|
| 77 | rc = gpio_open(gpio);
|
| 78 | if (rc != GPIO_OK) { break; }
|
| 79 | rc = gpio_read(gpio,&gpio_val);
|
| 80 | if (rc != GPIO_OK) { gpio_close(gpio); break; }
|
| 81 | gpio_close(gpio);
|
| 82 | *present = gpio_val;
|
| 83 | } while(0);
|
| 84 | if (rc != GPIO_OK)
|
| 85 | {
|
| 86 | g_print("ERROR: gpio error %s\n",gpio->name);
|
| 87 | }
|
| 88 | return rc;
|
| 89 | }
|
| 90 |
|
| 91 | void update_fru_obj(GDBusConnection* connection, object_info* obj_info, uint8_t state)
|
| 92 | {
|
| 93 | GDBusProxy *proxy;
|
| 94 | GError *error;
|
| 95 | GVariant *parm;
|
| 96 | GVariant *result;
|
| 97 |
|
| 98 | error = NULL;
|
| 99 | proxy = g_dbus_proxy_new_sync (connection,
|
| 100 | G_DBUS_PROXY_FLAGS_NONE,
|
| 101 | NULL, /* GDBusInterfaceInfo* */
|
| 102 | obj_info->bus_name, /* name */
|
| 103 | obj_info->path, /* object path */
|
| 104 | "org.openbmc.SensorValue", /* interface name */
|
| 105 | NULL, /* GCancellable */
|
| 106 | &error);
|
| 107 | g_assert_no_error (error);
|
| 108 |
|
| 109 | error = NULL;
|
| 110 | parm = g_variant_new("(y)",state);
|
| 111 |
|
| 112 | result = g_dbus_proxy_call_sync (proxy,
|
| 113 | "setValue",
|
| 114 | parm,
|
| 115 | G_DBUS_CALL_FLAGS_NONE,
|
| 116 | -1,
|
| 117 | NULL,
|
| 118 | &error);
|
| 119 |
|
| 120 | g_assert_no_error (error);
|
| 121 | }
|
| 122 |
|
| 123 | gint
|
| 124 | main (gint argc, gchar *argv[])
|
| 125 | {
|
| 126 | GMainLoop *loop;
|
| 127 | GDBusConnection *c;
|
| 128 | GDBusProxy *sys_proxy;
|
| 129 | GError *error;
|
| 130 | GVariant *parm;
|
| 131 | GVariant *result;
|
| 132 |
|
| 133 | loop = g_main_loop_new (NULL, FALSE);
|
| 134 |
|
| 135 | error = NULL;
|
| 136 | c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
|
| 137 |
|
| 138 | error = NULL;
|
| 139 | sys_proxy = g_dbus_proxy_new_sync (c,
|
| 140 | G_DBUS_PROXY_FLAGS_NONE,
|
| 141 | NULL, /* GDBusInterfaceInfo* */
|
| 142 | "org.openbmc.managers.System", /* name */
|
| 143 | "/org/openbmc/managers/System", /* object path */
|
| 144 | "org.openbmc.managers.System", /* interface name */
|
| 145 | NULL, /* GCancellable */
|
| 146 | &error);
|
| 147 | g_assert_no_error (error);
|
| 148 |
|
| 149 | int i = 0;
|
| 150 | int rc = 0;
|
| 151 | for (i=0;i<NUM_SLOTS;i++)
|
| 152 | {
|
| 153 | object_info obj_info;
|
| 154 | uint8_t present;
|
| 155 | do {
|
| 156 | rc = get_object(sys_proxy,&slots[i],&obj_info);
|
| 157 | if (rc) { break; }
|
| 158 | rc = get_presence(c,&slots[i],&present);
|
| 159 | if (rc) { break; }
|
| 160 | // TODO: send correct state
|
| 161 | update_fru_obj(c,&obj_info,present);
|
| 162 | } while(0);
|
| 163 | }
|
| 164 |
|
| 165 | g_object_unref(c);
|
| 166 | g_main_loop_unref (loop);
|
| 167 | return 0;
|
| 168 | }
|