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