[coreboot-gerrit] Change in coreboot[master]: ectool: Add an option to get and use EC ports from /proc/ioports
Iru Cai (Code Review)
gerrit at coreboot.org
Tue Apr 17 06:17:48 CEST 2018
Iru Cai has uploaded this change for review. ( https://review.coreboot.org/25696
Change subject: ectool: Add an option to get and use EC ports from /proc/ioports
......................................................................
ectool: Add an option to get and use EC ports from /proc/ioports
There are boards that don't use ports 0x62 and 0x66 for EC, e.g. Dell
Latitude E6230 uses 0x930 and 0x934.
Change-Id: Ie3005f5cd6e37206ef187267b0542efdeb26b3af
Signed-off-by: Iru Cai <mytbk920423 at gmail.com>
Change-Id: I453a2954401db7f120b63729b98096e3839847ef
Signed-off-by: Iru Cai <mytbk920423 at gmail.com>
---
M util/autoport/log_maker.go
M util/ectool/ec.c
M util/ectool/ec.h
M util/ectool/ectool.c
4 files changed, 54 insertions(+), 14 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/96/25696/1
diff --git a/util/autoport/log_maker.go b/util/autoport/log_maker.go
index a62f8f6..08b35d2 100644
--- a/util/autoport/log_maker.go
+++ b/util/autoport/log_maker.go
@@ -94,7 +94,7 @@
}
RunAndSave(outDir+"/inteltool.log", "../inteltool/inteltool", inteltoolArgs)
- RunAndSave(outDir+"/ectool.log", "../ectool/ectool", "-d")
+ RunAndSave(outDir+"/ectool.log", "../ectool/ectool", "-pd")
RunAndSave(outDir+"/superiotool.log", "../superiotool/superiotool", "-ade")
SysDir := "/sys/class/sound/card0/"
diff --git a/util/ectool/ec.c b/util/ectool/ec.c
index 53a5360..d6c2000 100644
--- a/util/ectool/ec.c
+++ b/util/ectool/ec.c
@@ -16,12 +16,16 @@
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
+#include <string.h>
#include <unistd.h>
#if !(defined __NetBSD__ || defined __OpenBSD__)
#include <sys/io.h>
#endif
#include "ec.h"
+static int ec_data = 0x62;
+static int ec_sc = 0x66;
+
#if defined __NetBSD__ || defined __OpenBSD__
#include <machine/sysarch.h>
static uint8_t inb(unsigned port)
@@ -45,7 +49,7 @@
int timeout;
timeout = 0x7ff;
- while ((inb(EC_SC) & EC_IBF) && --timeout) {
+ while ((inb(ec_sc) & EC_IBF) && --timeout) {
usleep(10);
if ((timeout & 0xff) == 0)
debug(".");
@@ -56,7 +60,7 @@
// return -1;
}
- outb(command, EC_SC);
+ outb(command, ec_sc);
return 0;
}
@@ -65,7 +69,7 @@
int timeout;
timeout = 0x7ff;
- while ((inb(EC_SC) & EC_IBF) && --timeout) { // wait for IBF = 0
+ while ((inb(ec_sc) & EC_IBF) && --timeout) { // wait for IBF = 0
usleep(10);
if ((timeout & 0xff) == 0)
debug(".");
@@ -75,14 +79,14 @@
// return -1;
}
- outb(data, EC_DATA);
+ outb(data, ec_data);
return 0;
}
int send_ec_data_nowait(uint8_t data)
{
- outb(data, EC_DATA);
+ outb(data, ec_data);
return 0;
}
@@ -94,9 +98,9 @@
timeout = 0x7fff;
while (--timeout) { // Wait for OBF = 1
- if (inb(EC_SC) & EC_OBF) {
+ if (inb(ec_sc) & EC_OBF)
break;
- }
+
usleep(10);
if ((timeout & 0xff) == 0)
debug(".");
@@ -106,7 +110,7 @@
// return -1;
}
- data = inb(EC_DATA);
+ data = inb(ec_data);
debug("recv_ec_data: 0x%02x\n", data);
return data;
@@ -165,3 +169,32 @@
send_ec_command(QR_EC);
return recv_ec_data();
}
+
+int get_ec_ports(void)
+{
+ FILE *fp = fopen("/proc/ioports", "r");
+ int data = 0, cmd = 0;
+ char line[100];
+
+ if (fp == NULL)
+ return -1;
+
+ while (!feof(fp) && (data == 0 || cmd == 0)) {
+ fgets(line, sizeof(line), fp);
+ if (strstr(line, "EC data") != NULL)
+ data = strtol(line, NULL, 16);
+
+ if (strstr(line, "EC cmd") != NULL)
+ cmd = strtol(line, NULL, 16);
+ }
+
+ fclose(fp);
+ if (data != 0 && cmd != 0) {
+ debug("EC data = 0x%x, EC cmd = 0x%x\n", data, cmd);
+ ec_data = data;
+ ec_sc = cmd;
+ } else {
+ return -1;
+ }
+ return 0;
+}
diff --git a/util/ectool/ec.h b/util/ectool/ec.h
index 4f65f60..fd06235 100644
--- a/util/ectool/ec.h
+++ b/util/ectool/ec.h
@@ -16,9 +16,6 @@
#ifndef _EC_H
#define _EC_H
-#define EC_DATA 0x62
-#define EC_SC 0x66
-
/* EC_SC input */
#define EC_SMI_EVT (1 << 6) // 1: SMI event pending
#define EC_SCI_EVT (1 << 5) // 1: SCI event pending
@@ -47,4 +44,5 @@
int ec_ext_write(uint16_t addr, uint8_t data);
uint8_t ec_idx_read(uint16_t addr);
uint8_t ec_query(void);
+int get_ec_ports(void);
#endif
diff --git a/util/ectool/ectool.c b/util/ectool/ectool.c
index dcf1728..df6b406 100644
--- a/util/ectool/ectool.c
+++ b/util/ectool/ectool.c
@@ -62,6 +62,7 @@
" -v | --version: print the version\n"
" -h | --help: print this help\n\n"
" -V | --verbose: print debug information\n"
+ " -p | --getports: get EC data and cmd ports from /proc/ioports\n"
" -d | --dump: print RAM\n"
" -i | --idx: print IDX RAM & RAM\n"
" -q | --query: print query byte\n"
@@ -71,7 +72,7 @@
exit(1);
}
-int verbose = 0, dump_idx = 0, dump_ram = 0, dump_query = 0;
+int verbose = 0, dump_idx = 0, dump_ram = 0, dump_query = 0, get_ports = 0;
int main(int argc, char *argv[])
{
@@ -85,10 +86,11 @@
{"verbose", 0, 0, 'V'},
{"idx", 0, 0, 'i'},
{"query", 0, 0, 'q'},
+ {"getports", 0, 0, 'p'},
{0, 0, 0, 0}
};
- while ((opt = getopt_long(argc, argv, "vh?Vidqw:z:",
+ while ((opt = getopt_long(argc, argv, "vh?Vidqpw:z:",
long_options, &option_index)) != EOF) {
switch (opt) {
case 'v':
@@ -114,6 +116,9 @@
case 'q':
dump_query = 1;
break;
+ case 'p':
+ get_ports = 1;
+ break;
case 'h':
case '?':
default:
@@ -123,6 +128,10 @@
}
}
+ if (get_ports && get_ec_ports() != 0)
+ puts("Cannot get EC ports from /proc/ioports, "
+ "fallback to default.");
+
if (iopl(3)) {
printf("You need to be root.\n");
exit(1);
--
To view, visit https://review.coreboot.org/25696
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I453a2954401db7f120b63729b98096e3839847ef
Gerrit-Change-Number: 25696
Gerrit-PatchSet: 1
Gerrit-Owner: Iru Cai <mytbk920423 at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.coreboot.org/pipermail/coreboot-gerrit/attachments/20180417/9cbb8fc7/attachment.html>
More information about the coreboot-gerrit
mailing list