MCPcopy Create free account
hub / github.com/coreboot/coreboot / get_ec_ports

Function get_ec_ports

util/ectool/ec.c:160–190  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

158}
159
160int get_ec_ports(void)
161{
162 FILE *fp = fopen("/proc/ioports", "r");
163 int data = 0, cmd = 0;
164 char line[100];
165
166 if (fp == NULL)
167 return -1;
168
169 while (!feof(fp) && (data == 0 || cmd == 0)) {
170 if (fgets(line, sizeof(line), fp) == NULL) {
171 fprintf(stderr, "Can not read from /proc/ioports.\n");
172 break;
173 }
174 if (strstr(line, "EC data") != NULL)
175 data = strtol(line, NULL, 16);
176
177 if (strstr(line, "EC cmd") != NULL)
178 cmd = strtol(line, NULL, 16);
179 }
180
181 fclose(fp);
182 if (data != 0 && cmd != 0) {
183 debug("EC data = 0x%x, EC cmd = 0x%x\n", data, cmd);
184 ec_data = data;
185 ec_sc = cmd;
186 } else {
187 return -1;
188 }
189 return 0;
190}

Callers 1

mainFunction · 0.85

Calls 5

fopenFunction · 0.85
fprintfFunction · 0.85
fcloseFunction · 0.85
strstrFunction · 0.50
strtolFunction · 0.50

Tested by

no test coverage detected