ectool: Remove CROS_EC_DEV_IOCRDMEM

On !LPC EC, we can read memory via CROS_EC_DEV_IOCXCMD ioctl,
using command EC_CMD_READ_MEMMAP.
On platform that supports direct memory access (lpc), we access
the memory directly, bypassing the ioctl.

BUG=chromium:602832
TEST=On gnawty and veyron, check 'ectool battery' works.
Verify that gnawty use io mapped registers.
BRANCH=none

Change-Id: I9bfcddcf450bf8df63ead78e1df97dd7392289e6
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/338853
Reviewed-by: Randall Spangler <rspangler@chromium.org>
This commit is contained in:
Gwendal Grignou
2016-04-13 12:34:08 -07:00
committed by chrome-bot
parent fef9abf3b3
commit de45353bbd
4 changed files with 39 additions and 70 deletions

View File

@@ -91,31 +91,6 @@ static int ec_command_dev(int command, int version,
return r; 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+ */ /* 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, static int ec_command_dev_v2(int command, int version,
@@ -156,8 +131,6 @@ static int ec_command_dev_v2(int command, int version,
} else { } else {
memcpy(indata, s_cmd->data, MIN(r, insize)); memcpy(indata, s_cmd->data, MIN(r, insize));
if (s_cmd->result != EC_RES_SUCCESS) { 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; r = -EECRESULT - s_cmd->result;
} }
} }
@@ -166,31 +139,6 @@ static int ec_command_dev_v2(int command, int version,
return r; 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. * Attempt to communicate with kernel using old ioctl format.
@@ -221,7 +169,6 @@ static int ec_dev_is_v2(void)
int comm_init_dev(const char *device_name) int comm_init_dev(const char *device_name)
{ {
int (*ec_cmd_readmem)(int offset, int bytes, void *dest);
char version[80]; char version[80];
char device[80] = "/dev/"; char device[80] = "/dev/";
int r; int r;
@@ -248,15 +195,20 @@ int comm_init_dev(const char *device_name)
if (ec_dev_is_v2()) { if (ec_dev_is_v2()) {
ec_command_proto = ec_command_dev_v2; ec_command_proto = ec_command_dev_v2;
ec_cmd_readmem = ec_readmem_dev_v2;
} else { } else {
ec_command_proto = ec_command_dev; ec_command_proto = ec_command_dev;
ec_cmd_readmem = ec_readmem_dev;
} }
if (ec_cmd_readmem(EC_MEMMAP_ID, 2, version) == 2 && if (ec_readmem(EC_MEMMAP_ID, 2, version) < 0) {
version[0] == 'E' && version[1] == 'C') /*
ec_readmem = ec_cmd_readmem; * 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");
}
/* /*
* Set temporary size, will be updated later. * Set temporary size, will be updated later.

View File

@@ -25,10 +25,6 @@ void *ec_outbuf;
void *ec_inbuf; void *ec_inbuf;
static int command_offset; 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) static int fake_readmem(int offset, int bytes, void *dest)
{ {
struct ec_params_read_memmap p; struct ec_params_read_memmap p;
@@ -92,16 +88,15 @@ int comm_init(int interfaces, const char *device_name)
} }
/* Prefer new /dev method */ /* Prefer new /dev method */
if ((interfaces & COMM_DEV) && comm_init_dev && if ((interfaces & COMM_DEV) && !comm_init_dev(device_name))
!comm_init_dev(device_name))
goto init_ok; goto init_ok;
/* Fallback to direct LPC on x86 */ /* Fallback to direct LPC on x86 */
if ((interfaces & COMM_LPC) && comm_init_lpc && !comm_init_lpc()) if ((interfaces & COMM_LPC) && !comm_init_lpc(0))
goto init_ok; goto init_ok;
/* Fallback to direct i2c on ARM */ /* Fallback to direct i2c on ARM */
if ((interfaces & COMM_I2C) && comm_init_i2c && !comm_init_i2c()) if ((interfaces & COMM_I2C) && !comm_init_i2c())
goto init_ok; goto init_ok;
/* Give up */ /* Give up */

View File

@@ -74,4 +74,15 @@ extern int (*ec_command_proto)(int command, int version,
*/ */
extern int (*ec_readmem)(int offset, int bytes, void *dest); 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 */ #endif /* __UTIL_COMM_HOST_H */

View File

@@ -246,7 +246,7 @@ static int ec_readmem_lpc(int offset, int bytes, void *dest)
return cnt; return cnt;
} }
int comm_init_lpc(void) int comm_init_lpc(int init_readmem_only)
{ {
int i; int i;
int byte = 0xff; int byte = 0xff;
@@ -257,6 +257,13 @@ int comm_init_lpc(void)
return -3; 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 * Test if the I/O port has been configured for Chromium EC LPC
* interface. Chromium EC guarantees that at least one status bit will * interface. Chromium EC guarantees that at least one status bit will
@@ -308,9 +315,13 @@ int comm_init_lpc(void)
return -5; return -5;
} }
/* Either one supports reading mapped memory directly. */
ec_readmem = ec_readmem_lpc;
return 0; return 0;
} }
#endif #else /* defined(__i386__) || defined(__x86_64__) */
#include <errno.h>
int comm_init_lpc(int unused)
{
return -EOPNOTSUPP;
}
#endif /* defined(__i386__) || defined(__x86_64__) */