blob: 72cb57618a360f2819aeea421ff60f4f6eda8ee1 [file] [log] [blame]
Chris Austen8a45e7c2015-10-15 00:31:46 -05001#include <stdio.h>
2#include <string.h>
3#include <stdint.h>
4
5
6extern unsigned char findSensor(char);
Chris Austen0130d6e2015-10-15 22:32:36 -05007extern int set_sensor_dbus_state_v(uint8_t , const char *, char *);
8
9
Chris Austen8a45e7c2015-10-15 00:31:46 -050010
11struct 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 Austen0130d6e2015-10-15 22:32:36 -050024#define ISBITSET(x,y) (((x)>>(y))&0x01)
Chris Austen8a45e7c2015-10-15 00:31:46 -050025#define ASSERTINDEX 0
26#define DEASSERTINDEX 1
27
Chris Austen8a45e7c2015-10-15 00:31:46 -050028// Sensor Type, Offset, function handler, Dbus Method, Assert value, Deassert value
29struct lookup_t {
30 uint8_t sensor_type;
31 uint8_t offset;
Chris Austen0130d6e2015-10-15 22:32:36 -050032 int (*func)(const sensorRES_t *, const lookup_t *, const char *);
Chris Austen8a45e7c2015-10-15 00:31:46 -050033 char method[16];
34 char assertion[16];
35 char deassertion[16];
36};
37
38
Chris Austen0130d6e2015-10-15 22:32:36 -050039extern int updateDbusInterface(uint8_t , const char *, const char *) ;
40extern int set_sensor_dbus_state(uint8_t ,const char *, const char *);
41
42
43int 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
48struct event_data_t {
49 uint8_t data;
50 char text[32];
51};
52
53event_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
84char *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.
100int 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 Austen8a45e7c2015-10-15 00:31:46 -0500118// 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 Austen0130d6e2015-10-15 22:32:36 -0500121lookup_t g_ipmidbuslookup[] = {
Chris Austen8a45e7c2015-10-15 00:31:46 -0500122
Chris Austen0130d6e2015-10-15 22:32:36 -0500123 {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 Austen8a45e7c2015-10-15 00:31:46 -0500132};
133
Chris Austen0130d6e2015-10-15 22:32:36 -0500134
135
136void reportSensorEventAssert(sensorRES_t *pRec, int index) {
137 lookup_t *pTable = &g_ipmidbuslookup[index];
138 (*pTable->func)(pRec, pTable, pTable->assertion);
139}
140void reportSensorEventDeassert(sensorRES_t *pRec, int index) {
141 lookup_t *pTable = &g_ipmidbuslookup[index];
142 (*pTable->func)(pRec, pTable, pTable->deassertion);
143}
144
145
Chris Austen8a45e7c2015-10-15 00:31:46 -0500146int findindex(const uint8_t sensor_type, int offset, int *index) {
147
148 int i=0, rc=0;
Chris Austen0130d6e2015-10-15 22:32:36 -0500149 lookup_t *pTable = g_ipmidbuslookup;
Chris Austen8a45e7c2015-10-15 00:31:46 -0500150
151 do {
Chris Austen8a45e7c2015-10-15 00:31:46 -0500152 if ( ((pTable+i)->sensor_type == sensor_type) &&
Chris Austen0130d6e2015-10-15 22:32:36 -0500153 ((pTable+i)->offset == offset) ) {
Chris Austen8a45e7c2015-10-15 00:31:46 -0500154 rc = 1;
155 *index = i;
156 break;
157 }
158 i++;
159 } while ((pTable+i)->sensor_type != 0xFF);
160
161 return rc;
162}
163
Chris Austen0130d6e2015-10-15 22:32:36 -0500164bool shouldReport(uint8_t sensorType, int offset, int *index) {
Chris Austen8a45e7c2015-10-15 00:31:46 -0500165
Chris Austen0130d6e2015-10-15 22:32:36 -0500166 bool rc = false;
167 if (findindex(sensorType, offset, index)) { rc = true; }
Chris Austen8a45e7c2015-10-15 00:31:46 -0500168
Chris Austen0130d6e2015-10-15 22:32:36 -0500169 return rc;
Chris Austen8a45e7c2015-10-15 00:31:46 -0500170}
171
172
173int updateSensorRecordFromSSRAESC(const void *record) {
174
175 sensorRES_t *pRec = (sensorRES_t *) record;
176 unsigned char stype;
177 int index, i=0;
Chris Austen8a45e7c2015-10-15 00:31:46 -0500178 stype = findSensor(pRec->sensor_number);
179
Chris Austen0130d6e2015-10-15 22:32:36 -0500180
Chris Austen8a45e7c2015-10-15 00:31:46 -0500181 // Scroll through each bit position . Determine
182 // if any bit is either asserted or Deasserted.
183 for(i=0;i<8;i++) {
Chris Austen0130d6e2015-10-15 22:32:36 -0500184 if ((ISBITSET(pRec->assert_state7_0,i)) &&
185 (shouldReport(stype, i, &index)))
186 {
187 reportSensorEventAssert(pRec, index);
Chris Austen8a45e7c2015-10-15 00:31:46 -0500188 }
Chris Austen0130d6e2015-10-15 22:32:36 -0500189 if ((ISBITSET(pRec->assert_state14_8,i+8)) &&
190 (shouldReport(stype, i+8, &index)))
191 {
192 reportSensorEventAssert(pRec, index);
Chris Austen8a45e7c2015-10-15 00:31:46 -0500193 }
Chris Austen0130d6e2015-10-15 22:32:36 -0500194 if ((ISBITSET(pRec->deassert_state7_0,i)) &&
195 (shouldReport(stype, i, &index)))
196 {
197 reportSensorEventDeassert(pRec, index);
Chris Austen8a45e7c2015-10-15 00:31:46 -0500198 }
Chris Austen0130d6e2015-10-15 22:32:36 -0500199 if ((ISBITSET(pRec->deassert_state14_8,i+8)) &&
200 (shouldReport(stype, i+8, &index)))
201 {
202 reportSensorEventDeassert(pRec, index);
Chris Austen8a45e7c2015-10-15 00:31:46 -0500203 }
204 }
205
206 return 0;
207}