Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <string.h> |
| 3 | #include <stdint.h> |
| 4 | |
| 5 | |
| 6 | extern unsigned char findSensor(char); |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame^] | 7 | extern int set_sensor_dbus_state_v(uint8_t , const char *, char *); |
| 8 | |
| 9 | |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 10 | |
| 11 | struct sensorRES_t { |
| 12 | uint8_t sensor_number; |
| 13 | uint8_t operation; |
| 14 | uint8_t sensor_reading; |
| 15 | uint8_t assert_state7_0; |
| 16 | uint8_t assert_state14_8; |
| 17 | uint8_t deassert_state7_0; |
| 18 | uint8_t deassert_state14_8; |
| 19 | uint8_t event_data1; |
| 20 | uint8_t event_data2; |
| 21 | uint8_t event_data3; |
| 22 | } __attribute__ ((packed)); |
| 23 | |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame^] | 24 | #define ISBITSET(x,y) (((x)>>(y))&0x01) |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 25 | #define ASSERTINDEX 0 |
| 26 | #define DEASSERTINDEX 1 |
| 27 | |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 28 | // Sensor Type, Offset, function handler, Dbus Method, Assert value, Deassert value |
| 29 | struct lookup_t { |
| 30 | uint8_t sensor_type; |
| 31 | uint8_t offset; |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame^] | 32 | int (*func)(const sensorRES_t *, const lookup_t *, const char *); |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 33 | char method[16]; |
| 34 | char assertion[16]; |
| 35 | char deassertion[16]; |
| 36 | }; |
| 37 | |
| 38 | |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame^] | 39 | extern int updateDbusInterface(uint8_t , const char *, const char *) ; |
| 40 | extern int set_sensor_dbus_state(uint8_t ,const char *, const char *); |
| 41 | |
| 42 | |
| 43 | int set_sensor_dbus_state_simple(const sensorRES_t *pRec, const lookup_t *pTable, const char *value) { |
| 44 | |
| 45 | return set_sensor_dbus_state(pRec->sensor_number, pTable->method, value); |
| 46 | } |
| 47 | |
| 48 | struct event_data_t { |
| 49 | uint8_t data; |
| 50 | char text[32]; |
| 51 | }; |
| 52 | |
| 53 | event_data_t g_fwprogress02h[] = { |
| 54 | {0x00, "Unspecified"}, |
| 55 | {0x01, "Memory Init"}, |
| 56 | {0x02, "HD Init"}, |
| 57 | {0x03, "Secondary Proc Init"}, |
| 58 | {0x04, "User Authentication"}, |
| 59 | {0x05, "User init system setup"}, |
| 60 | {0x06, "USB configuration"}, |
| 61 | {0x07, "PCI configuration"}, |
| 62 | {0x08, "Option ROM Init"}, |
| 63 | {0x09, "Video Init"}, |
| 64 | {0x0A, "Cache Init"}, |
| 65 | {0x0B, "SM Bus init"}, |
| 66 | {0x0C, "Keyboard Init"}, |
| 67 | {0x0D, "Embedded ctrl init"}, |
| 68 | {0x0E, "Docking station attachment"}, |
| 69 | {0x0F, "Enable docking station"}, |
| 70 | {0x10, "Docking station ejection"}, |
| 71 | {0x11, "Disabling docking station"}, |
| 72 | {0x12, "Calling OS Wakeup"}, |
| 73 | {0x13, "Starting OS"}, |
| 74 | {0x14, "Baseboard Init"}, |
| 75 | {0x15, ""}, |
| 76 | {0x16, "Floppy Init"}, |
| 77 | {0x17, "Keyboard Test"}, |
| 78 | {0x18, "Pointing Device Test"}, |
| 79 | {0x19, "Primary Proc Init"}, |
| 80 | {0xFF, "Unknown"} |
| 81 | }; |
| 82 | |
| 83 | |
| 84 | char *getfw02string(uint8_t b) { |
| 85 | |
| 86 | int i = 0; |
| 87 | event_data_t *p = g_fwprogress02h; |
| 88 | |
| 89 | do { |
| 90 | |
| 91 | if ((p+i)->data == b) |
| 92 | break; |
| 93 | i++; |
| 94 | } while ((p+i)->data != 0xFF); |
| 95 | |
| 96 | return p->text; |
| 97 | } |
| 98 | // The fw progress sensor contains some additional information that needs to be processed |
| 99 | // prior to calling the dbus code. |
| 100 | int set_sensor_dbus_state_fwprogress(const sensorRES_t *pRec, const lookup_t *pTable, const char *value) { |
| 101 | |
| 102 | char valuestring[32]; |
| 103 | char* pStr = valuestring; |
| 104 | |
| 105 | switch (pTable->offset) { |
| 106 | |
| 107 | case 0x00 : sprintf(valuestring, "POST Error, 0x%02x", pRec->event_data2); |
| 108 | break; |
| 109 | case 0x01 : sprintf(valuestring, "FW Hang, 0x%02x", pRec->event_data2); |
| 110 | break; |
| 111 | case 0x02 : sprintf(valuestring, "FW Progress, 0x%02x", getfw02string(pRec->event_data2)); |
| 112 | } |
| 113 | |
| 114 | return set_sensor_dbus_state_v(pRec->sensor_number, pTable->method, pStr); |
| 115 | } |
| 116 | |
| 117 | |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 118 | // This table lists only senors we care about telling dbus about. |
| 119 | // Offset definition cab be found in section 42.2 of the IPMI 2.0 |
| 120 | // spec. Add more if/when there are more items of interest. |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame^] | 121 | lookup_t g_ipmidbuslookup[] = { |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 122 | |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame^] | 123 | {0x07, 0x07, set_sensor_dbus_state_simple, "setPresent", "True", "False"}, |
| 124 | {0x07, 0x08, set_sensor_dbus_state_simple, "setFault", "True", "False"}, |
| 125 | {0x0C, 0x06, set_sensor_dbus_state_simple, "setPresent", "True", "False"}, |
| 126 | {0x0C, 0x04, set_sensor_dbus_state_simple, "setFault", "True", "False"}, |
| 127 | {0x0F, 0x02, set_sensor_dbus_state_fwprogress, "setValue", "True", "False"}, |
| 128 | {0x0F, 0x01, set_sensor_dbus_state_fwprogress, "setValue", "True", "False"}, |
| 129 | {0x0F, 0x00, set_sensor_dbus_state_fwprogress, "setValue", "True", "False"}, |
| 130 | |
| 131 | {0xFF, 0xFF, NULL, "", "", ""} |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 132 | }; |
| 133 | |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame^] | 134 | |
| 135 | |
| 136 | void reportSensorEventAssert(sensorRES_t *pRec, int index) { |
| 137 | lookup_t *pTable = &g_ipmidbuslookup[index]; |
| 138 | (*pTable->func)(pRec, pTable, pTable->assertion); |
| 139 | } |
| 140 | void reportSensorEventDeassert(sensorRES_t *pRec, int index) { |
| 141 | lookup_t *pTable = &g_ipmidbuslookup[index]; |
| 142 | (*pTable->func)(pRec, pTable, pTable->deassertion); |
| 143 | } |
| 144 | |
| 145 | |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 146 | int findindex(const uint8_t sensor_type, int offset, int *index) { |
| 147 | |
| 148 | int i=0, rc=0; |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame^] | 149 | lookup_t *pTable = g_ipmidbuslookup; |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 150 | |
| 151 | do { |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 152 | if ( ((pTable+i)->sensor_type == sensor_type) && |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame^] | 153 | ((pTable+i)->offset == offset) ) { |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 154 | rc = 1; |
| 155 | *index = i; |
| 156 | break; |
| 157 | } |
| 158 | i++; |
| 159 | } while ((pTable+i)->sensor_type != 0xFF); |
| 160 | |
| 161 | return rc; |
| 162 | } |
| 163 | |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame^] | 164 | bool shouldReport(uint8_t sensorType, int offset, int *index) { |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 165 | |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame^] | 166 | bool rc = false; |
| 167 | if (findindex(sensorType, offset, index)) { rc = true; } |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 168 | |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame^] | 169 | return rc; |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | |
| 173 | int updateSensorRecordFromSSRAESC(const void *record) { |
| 174 | |
| 175 | sensorRES_t *pRec = (sensorRES_t *) record; |
| 176 | unsigned char stype; |
| 177 | int index, i=0; |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 178 | stype = findSensor(pRec->sensor_number); |
| 179 | |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame^] | 180 | |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 181 | // Scroll through each bit position . Determine |
| 182 | // if any bit is either asserted or Deasserted. |
| 183 | for(i=0;i<8;i++) { |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame^] | 184 | if ((ISBITSET(pRec->assert_state7_0,i)) && |
| 185 | (shouldReport(stype, i, &index))) |
| 186 | { |
| 187 | reportSensorEventAssert(pRec, index); |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 188 | } |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame^] | 189 | if ((ISBITSET(pRec->assert_state14_8,i+8)) && |
| 190 | (shouldReport(stype, i+8, &index))) |
| 191 | { |
| 192 | reportSensorEventAssert(pRec, index); |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 193 | } |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame^] | 194 | if ((ISBITSET(pRec->deassert_state7_0,i)) && |
| 195 | (shouldReport(stype, i, &index))) |
| 196 | { |
| 197 | reportSensorEventDeassert(pRec, index); |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 198 | } |
Chris Austen | 0130d6e | 2015-10-15 22:32:36 -0500 | [diff] [blame^] | 199 | if ((ISBITSET(pRec->deassert_state14_8,i+8)) && |
| 200 | (shouldReport(stype, i+8, &index))) |
| 201 | { |
| 202 | reportSensorEventDeassert(pRec, index); |
Chris Austen | 8a45e7c | 2015-10-15 00:31:46 -0500 | [diff] [blame] | 203 | } |
| 204 | } |
| 205 | |
| 206 | return 0; |
| 207 | } |