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