summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGwendal Grignou <gwendal@chromium.org>2016-04-22 11:09:33 -0700
committerchrome-bot <chrome-bot@chromium.org>2016-04-22 17:17:56 -0700
commite54d1284ffbd1d7c3b1f77a2a696ce275c527de4 (patch)
treedba186d112dd55598819dd5c53db6e451d59407e
parent1546b4de0b6d8b443f6c8b3e49810010f896b40b (diff)
downloadchrome-ec-e54d1284ffbd1d7c3b1f77a2a696ce275c527de4.tar.gz
ectool: Revert "ectool: Remove CROS_EC_DEV_IOCRDMEM"
CROS_EC_DEV_IOCRDMEM must be used on architecture where legacy IO mapped registers are accessed inderectly via EMI. The kernel is taking care of the translation. TEST=Check on reks that we need to use the IOCTL. BUG=chrome-os-partner:52550,chromium:602832 BRANCH=none This reverts commit de45353bbdf0 ("ectool: Remove CROS_EC_DEV_IOCRDMEM"). Change-Id: I8efad56df90c58c25bdc9ccd70a508547e629a77 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/340348 Reviewed-by: Shawn N <shawnn@chromium.org>
-rw-r--r--util/comm-dev.c68
-rw-r--r--util/comm-host.c11
-rw-r--r--util/comm-host.h11
-rw-r--r--util/comm-lpc.c19
4 files changed, 70 insertions, 39 deletions
diff --git a/util/comm-dev.c b/util/comm-dev.c
index 3b215d924d..94a5cdde52 100644
--- a/util/comm-dev.c
+++ b/util/comm-dev.c
@@ -91,6 +91,31 @@ static int ec_command_dev(int command, int version,
return r;
}
+static int ec_readmem_dev(int offset, int bytes, void *dest)
+{
+ struct cros_ec_readmem s_mem;
+ struct ec_params_read_memmap r_mem;
+ int r;
+ static int fake_it;
+
+ if (!fake_it) {
+ s_mem.offset = offset;
+ s_mem.bytes = bytes;
+ s_mem.buffer = dest;
+ r = ioctl(fd, CROS_EC_DEV_IOCRDMEM, &s_mem);
+ if (r < 0 && errno == ENOTTY)
+ fake_it = 1;
+ else
+ return r;
+ }
+
+ r_mem.offset = offset;
+ r_mem.size = bytes;
+ return ec_command_dev(EC_CMD_READ_MEMMAP, 0,
+ &r_mem, sizeof(r_mem),
+ dest, bytes);
+}
+
/* New ioctl format, used by Chrome OS 4.4 and later as well as upstream 4.0+ */
static int ec_command_dev_v2(int command, int version,
@@ -131,6 +156,8 @@ static int ec_command_dev_v2(int command, int version,
} else {
memcpy(indata, s_cmd->data, MIN(r, insize));
if (s_cmd->result != EC_RES_SUCCESS) {
+ fprintf(stderr, "EC result %d (%s)\n", s_cmd->result,
+ strresult(s_cmd->result));
r = -EECRESULT - s_cmd->result;
}
}
@@ -139,6 +166,31 @@ static int ec_command_dev_v2(int command, int version,
return r;
}
+static int ec_readmem_dev_v2(int offset, int bytes, void *dest)
+{
+ struct cros_ec_readmem_v2 s_mem;
+ struct ec_params_read_memmap r_mem;
+ int r;
+ static int fake_it;
+
+ if (!fake_it) {
+ s_mem.offset = offset;
+ s_mem.bytes = bytes;
+ r = ioctl(fd, CROS_EC_DEV_IOCRDMEM_V2, &s_mem);
+ if (r < 0 && errno == ENOTTY) {
+ fake_it = 1;
+ } else {
+ memcpy(dest, s_mem.buffer, bytes);
+ return r;
+ }
+ }
+
+ r_mem.offset = offset;
+ r_mem.size = bytes;
+ return ec_command_dev(EC_CMD_READ_MEMMAP, 0,
+ &r_mem, sizeof(r_mem),
+ dest, bytes);
+}
/*
* Attempt to communicate with kernel using old ioctl format.
@@ -169,6 +221,7 @@ static int ec_dev_is_v2(void)
int comm_init_dev(const char *device_name)
{
+ int (*ec_cmd_readmem)(int offset, int bytes, void *dest);
char version[80];
char device[80] = "/dev/";
int r;
@@ -195,20 +248,15 @@ int comm_init_dev(const char *device_name)
if (ec_dev_is_v2()) {
ec_command_proto = ec_command_dev_v2;
+ ec_cmd_readmem = ec_readmem_dev_v2;
} else {
ec_command_proto = ec_command_dev;
+ ec_cmd_readmem = ec_readmem_dev;
}
- if (ec_readmem(EC_MEMMAP_ID, 2, version) < 0) {
- /*
- * Unable to read memory map through command protocol,
- * assume LPC transport underneath.
- */
- comm_init_lpc(1);
- if (ec_readmem(EC_MEMMAP_ID, 2, version) < 0)
- fprintf(stderr,
- "Unable to read memory mapped registers.\n");
- }
+ if (ec_cmd_readmem(EC_MEMMAP_ID, 2, version) == 2 &&
+ version[0] == 'E' && version[1] == 'C')
+ ec_readmem = ec_cmd_readmem;
/*
* Set temporary size, will be updated later.
diff --git a/util/comm-host.c b/util/comm-host.c
index f7514904cd..31ad56343e 100644
--- a/util/comm-host.c
+++ b/util/comm-host.c
@@ -25,6 +25,10 @@ void *ec_outbuf;
void *ec_inbuf;
static int command_offset;
+int comm_init_dev(const char *device_name) __attribute__((weak));
+int comm_init_lpc(void) __attribute__((weak));
+int comm_init_i2c(void) __attribute__((weak));
+
static int fake_readmem(int offset, int bytes, void *dest)
{
struct ec_params_read_memmap p;
@@ -88,15 +92,16 @@ int comm_init(int interfaces, const char *device_name)
}
/* Prefer new /dev method */
- if ((interfaces & COMM_DEV) && !comm_init_dev(device_name))
+ if ((interfaces & COMM_DEV) && comm_init_dev &&
+ !comm_init_dev(device_name))
goto init_ok;
/* Fallback to direct LPC on x86 */
- if ((interfaces & COMM_LPC) && !comm_init_lpc(0))
+ if ((interfaces & COMM_LPC) && comm_init_lpc && !comm_init_lpc())
goto init_ok;
/* Fallback to direct i2c on ARM */
- if ((interfaces & COMM_I2C) && !comm_init_i2c())
+ if ((interfaces & COMM_I2C) && comm_init_i2c && !comm_init_i2c())
goto init_ok;
/* Give up */
diff --git a/util/comm-host.h b/util/comm-host.h
index bfe99b2179..1d3cb9e36d 100644
--- a/util/comm-host.h
+++ b/util/comm-host.h
@@ -74,15 +74,4 @@ extern int (*ec_command_proto)(int command, int version,
*/
extern int (*ec_readmem)(int offset, int bytes, void *dest);
-/*
- * Functions for initializing communication protocols.
- * @param device_name: device name to open to access the ec.
- * @param init_readmem_only:
- * 1: init only ec_readmem
- * 0: set ec_command_proto as well.
- */
-int comm_init_dev(const char *device_name);
-int comm_init_lpc(int init_readmem_only);
-int comm_init_i2c(void);
-
#endif /* __UTIL_COMM_HOST_H */
diff --git a/util/comm-lpc.c b/util/comm-lpc.c
index 27a32f3b69..54f16b3ffc 100644
--- a/util/comm-lpc.c
+++ b/util/comm-lpc.c
@@ -246,7 +246,7 @@ static int ec_readmem_lpc(int offset, int bytes, void *dest)
return cnt;
}
-int comm_init_lpc(int init_readmem_only)
+int comm_init_lpc(void)
{
int i;
int byte = 0xff;
@@ -257,13 +257,6 @@ int comm_init_lpc(int init_readmem_only)
return -3;
}
- ec_readmem = ec_readmem_lpc;
-
- if (init_readmem_only) {
- /* Function to send commands already defined. */
- return 0;
- }
-
/*
* Test if the I/O port has been configured for Chromium EC LPC
* interface. Chromium EC guarantees that at least one status bit will
@@ -315,13 +308,9 @@ int comm_init_lpc(int init_readmem_only)
return -5;
}
+ /* Either one supports reading mapped memory directly. */
+ ec_readmem = ec_readmem_lpc;
return 0;
}
-#else /* defined(__i386__) || defined(__x86_64__) */
-#include <errno.h>
-int comm_init_lpc(int unused)
-{
- return -EOPNOTSUPP;
-}
-#endif /* defined(__i386__) || defined(__x86_64__) */
+#endif