diff options
author | Randall Spangler <rspangler@chromium.org> | 2012-07-11 16:08:15 -0700 |
---|---|---|
committer | Randall Spangler <rspangler@chromium.org> | 2012-07-12 14:48:50 -0700 |
commit | c171fbe3dcc2c9982b7de5ff7d2b5df6dcee542c (patch) | |
tree | 55b7960053545e341a689a27d9315c7ef2be1a08 | |
parent | 02f0ad7ea8b955d456e1e692e6e6e1a7199f2de1 (diff) | |
download | chrome-ec-c171fbe3dcc2c9982b7de5ff7d2b5df6dcee542c.tar.gz |
Map 256 bytes of data for host command args/params
And retain compatibility for old requests.
BUG=chrome-os-partner:11275
TEST=from u-boot prompt, 'mkbp hash'
from root shell, 'ectool flashread 0 68084 /tmp/foo'
then compare to first 68084 bytes of ec.bin
Change-Id: Id82068773703543febde79fc820af7486502e01f
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/27226
-rw-r--r-- | board/link/board.h | 12 | ||||
-rw-r--r-- | chip/lm4/lpc.c | 48 | ||||
-rw-r--r-- | chip/stm32/i2c.c | 6 | ||||
-rw-r--r-- | include/ec_commands.h | 20 | ||||
-rw-r--r-- | util/burn_my_ec.c | 4 | ||||
-rw-r--r-- | util/comm-lpc.c | 27 | ||||
-rw-r--r-- | util/ectool.c | 6 |
7 files changed, 67 insertions, 56 deletions
diff --git a/board/link/board.h b/board/link/board.h index eeb091b046..41809b5357 100644 --- a/board/link/board.h +++ b/board/link/board.h @@ -45,26 +45,26 @@ /* LPC channels */ #define LPC_CH_ACPI 0 /* ACPI commands */ #define LPC_CH_PORT80 1 /* Port 80 debug output */ -#define LPC_CH_CMD_DATA 2 /* Data for kernel/user-mode commands */ +#define LPC_CH_CMD_DATA 2 /* Data for host commands (args/params/response) */ #define LPC_CH_KEYBOARD 3 /* 8042 keyboard emulation */ -#define LPC_CH_USER 4 /* User-mode commands */ -#define LPC_CH_MEMMAP 5 /* Data for kernel/user-mode commands */ +#define LPC_CH_CMD 4 /* Host commands */ +#define LPC_CH_MEMMAP 5 /* Memory-mapped data */ #define LPC_CH_COMX 7 /* UART emulation */ /* LPC pool offsets */ #define LPC_POOL_OFFS_ACPI 0 /* ACPI commands - 0=in, 1=out */ #define LPC_POOL_OFFS_PORT80 4 /* Port 80 - 4=in, 5=out */ #define LPC_POOL_OFFS_COMX 8 /* UART emulation range - 8-15 */ #define LPC_POOL_OFFS_KEYBOARD 16 /* Keyboard - 16=in, 17=out */ -#define LPC_POOL_OFFS_USER 20 /* User commands - 20=in, 21=out */ -#define LPC_POOL_OFFS_CMD_DATA 512 /* Data range for user commands - 512-639 */ +#define LPC_POOL_OFFS_CMD 20 /* Host commands - 20=in, 21=out */ +#define LPC_POOL_OFFS_CMD_DATA 512 /* Data range for host commands - 512-767 */ #define LPC_POOL_OFFS_MEMMAP 768 /* Memory-mapped data - 768-1023 */ /* LPC pool data pointers */ #define LPC_POOL_ACPI (LM4_LPC_LPCPOOL + LPC_POOL_OFFS_ACPI) #define LPC_POOL_PORT80 (LM4_LPC_LPCPOOL + LPC_POOL_OFFS_PORT80) #define LPC_POOL_COMX (LM4_LPC_LPCPOOL + LPC_POOL_OFFS_COMX) #define LPC_POOL_KEYBOARD (LM4_LPC_LPCPOOL + LPC_POOL_OFFS_KEYBOARD) +#define LPC_POOL_CMD (LM4_LPC_LPCPOOL + LPC_POOL_OFFS_CMD) #define LPC_POOL_CMD_DATA (LM4_LPC_LPCPOOL + LPC_POOL_OFFS_CMD_DATA) -#define LPC_POOL_USER (LM4_LPC_LPCPOOL + LPC_POOL_OFFS_USER) #define LPC_POOL_MEMMAP (LM4_LPC_LPCPOOL + LPC_POOL_OFFS_MEMMAP) /* LPC COMx I/O address (in x86 I/O address space) */ #define LPC_COMX_ADDR 0x3f8 /* COM1 */ diff --git a/chip/lm4/lpc.c b/chip/lm4/lpc.c index eb66289615..172e55e1d1 100644 --- a/chip/lm4/lpc.c +++ b/chip/lm4/lpc.c @@ -37,6 +37,11 @@ static uint32_t host_events; /* Currently pending SCI/SMI events */ static uint32_t event_mask[3]; /* Event masks for each type */ static struct host_cmd_handler_args host_cmd_args; +static uint8_t * const cmd_params = (uint8_t *)LPC_POOL_CMD_DATA + + EC_LPC_ADDR_HOST_PARAM - EC_LPC_ADDR_HOST_ARGS; +static uint8_t * const old_params = (uint8_t *)LPC_POOL_CMD_DATA + + EC_LPC_ADDR_OLD_PARAM - EC_LPC_ADDR_HOST_ARGS; + /* Configure GPIOs for module */ static void configure_gpio(void) { @@ -116,13 +121,6 @@ static void lpc_generate_sci(void) host_events & event_mask[LPC_HOST_EVENT_SCI]); } -/* Return buffer for host command params/response. */ -static uint8_t *host_get_buffer(void) -{ - return (uint8_t *)LPC_POOL_CMD_DATA; -} - - uint8_t *lpc_get_memmap_range(void) { return (uint8_t *)LPC_POOL_MEMMAP; @@ -130,10 +128,10 @@ uint8_t *lpc_get_memmap_range(void) void host_send_response(enum ec_status result, const uint8_t *data, int size) { - uint8_t *out = host_get_buffer(); + uint8_t *out = old_params; /* Fail if response doesn't fit in the param buffer */ - if (size < 0 || size > EC_PARAM_SIZE) + if (size < 0 || size > EC_OLD_PARAM_SIZE) result = EC_RES_INVALID_RESPONSE; else if (data != out) memcpy(out, data, size); @@ -146,11 +144,11 @@ void host_send_response(enum ec_status result, const uint8_t *data, int size) * TODO: (crosbug.com/p/7496) or it would, if we actually set up host * IRQs */ - LPC_POOL_USER[1] = result; + LPC_POOL_CMD[1] = result; /* Clear the busy bit */ task_disable_irq(LM4_IRQ_LPC); - LM4_LPC_ST(LPC_CH_USER) &= ~LPC_STATUS_MASK_BUSY; + LM4_LPC_ST(LPC_CH_CMD) &= ~LPC_STATUS_MASK_BUSY; task_enable_irq(LM4_IRQ_LPC); } @@ -364,20 +362,20 @@ static void lpc_interrupt(void) handle_acpi_command(); /* Handle user command writes */ - if (mis & LM4_LPC_INT_MASK(LPC_CH_USER, 4)) { + if (mis & LM4_LPC_INT_MASK(LPC_CH_CMD, 4)) { /* Set the busy bit */ - LM4_LPC_ST(LPC_CH_USER) |= LPC_STATUS_MASK_BUSY; + LM4_LPC_ST(LPC_CH_CMD) |= LPC_STATUS_MASK_BUSY; /* * Read the command byte and pass to the host command handler. * This clears the FRMH bit in the status byte. */ - host_cmd_args.command = LPC_POOL_USER[0]; + host_cmd_args.command = LPC_POOL_CMD[0]; host_cmd_args.version = 0; - host_cmd_args.params = host_get_buffer(); - host_cmd_args.params_size = EC_PARAM_SIZE; - host_cmd_args.response = host_get_buffer(); - host_cmd_args.response_max = EC_PARAM_SIZE; + host_cmd_args.params = old_params; + host_cmd_args.params_size = EC_OLD_PARAM_SIZE; + host_cmd_args.response = old_params; + host_cmd_args.response_max = EC_OLD_PARAM_SIZE; host_cmd_args.response_size = 0; host_command_received(&host_cmd_args); } @@ -493,8 +491,8 @@ static int lpc_init(void) * * pci_write32 0 0x1f 0 0x88 0x007c0801 */ - LM4_LPC_ADR(LPC_CH_CMD_DATA) = EC_LPC_ADDR_USER_PARAM; - LM4_LPC_CTL(LPC_CH_CMD_DATA) = 0x8015 | + LM4_LPC_ADR(LPC_CH_CMD_DATA) = EC_LPC_ADDR_HOST_ARGS; + LM4_LPC_CTL(LPC_CH_CMD_DATA) = 0x8019 | (LPC_POOL_OFFS_CMD_DATA << (5 - 1)); /* @@ -514,11 +512,11 @@ static int lpc_init(void) * single endpoint, offset 0 for host command/writes and 1 for EC * data writes, pool bytes 0(data)/1(cmd) */ - LM4_LPC_ADR(LPC_CH_USER) = EC_LPC_ADDR_USER_DATA; - LM4_LPC_CTL(LPC_CH_USER) = (LPC_POOL_OFFS_USER << (5 - 1)); - LM4_LPC_ST(LPC_CH_USER) = 0; + LM4_LPC_ADR(LPC_CH_CMD) = EC_LPC_ADDR_HOST_DATA; + LM4_LPC_CTL(LPC_CH_CMD) = (LPC_POOL_OFFS_CMD << (5 - 1)); + LM4_LPC_ST(LPC_CH_CMD) = 0; /* Unmask interrupt for host command writes */ - LM4_LPC_LPCIM |= LM4_LPC_INT_MASK(LPC_CH_USER, 4); + LM4_LPC_LPCIM |= LM4_LPC_INT_MASK(LPC_CH_CMD, 4); /* * Set LPC channel 5 to I/O address 0x900, range endpoint, @@ -562,7 +560,7 @@ static int lpc_init(void) (1 << LPC_CH_PORT80) | (1 << LPC_CH_CMD_DATA) | (1 << LPC_CH_KEYBOARD) | - (1 << LPC_CH_USER) | + (1 << LPC_CH_CMD) | (1 << LPC_CH_MEMMAP) | (1 << LPC_CH_COMX); diff --git a/chip/stm32/i2c.c b/chip/stm32/i2c.c index bb6fb729a9..044531e903 100644 --- a/chip/stm32/i2c.c +++ b/chip/stm32/i2c.c @@ -42,7 +42,7 @@ static uint16_t i2c_sr1[NUM_PORTS]; static struct mutex i2c_mutex; /* buffer for host commands (including error code and checksum) */ -static uint8_t host_buffer[EC_PARAM_SIZE + 2]; +static uint8_t host_buffer[EC_HOST_PARAM_SIZE + 2]; static struct host_cmd_handler_args host_cmd_args; /* current position in host buffer for reception */ @@ -176,10 +176,10 @@ static void i2c_event_handler(int port) host_cmd_args.command = host_buffer[0]; host_cmd_args.version = 0; host_cmd_args.params = host_buffer + 1; - host_cmd_args.params_size = EC_PARAM_SIZE; + host_cmd_args.params_size = EC_HOST_PARAM_SIZE; /* skip room for error code */ host_cmd_args.response = host_buffer + 1; - host_cmd_args.response_max = EC_PARAM_SIZE; + host_cmd_args.response_max = EC_HOST_PARAM_SIZE; host_cmd_args.response_size = 0; host_command_received(&host_cmd_args); /* reset host buffer after end of transfer */ diff --git a/include/ec_commands.h b/include/ec_commands.h index 397fdefbdf..d028b96671 100644 --- a/include/ec_commands.h +++ b/include/ec_commands.h @@ -33,13 +33,23 @@ /* Command version mask */ #define EC_VER_MASK(version) (1UL << (version)) -/* I/O addresses for LPC commands */ +/* I/O addresses for ACPI commands */ #define EC_LPC_ADDR_ACPI_DATA 0x62 #define EC_LPC_ADDR_ACPI_CMD 0x66 -#define EC_LPC_ADDR_USER_DATA 0x200 -#define EC_LPC_ADDR_USER_CMD 0x204 -#define EC_LPC_ADDR_USER_PARAM 0x880 -#define EC_PARAM_SIZE 128 /* Size of param area in bytes */ + +/* I/O addresses for host command */ +#define EC_LPC_ADDR_HOST_DATA 0x200 +#define EC_LPC_ADDR_HOST_CMD 0x204 + +/* I/O addresses for host command args and params */ +#define EC_LPC_ADDR_HOST_ARGS 0x800 +#define EC_LPC_ADDR_HOST_PARAM 0x804 +#define EC_HOST_PARAM_SIZE 0x0fc /* Size of param area in bytes */ + +/* I/O addresses for host command params, old interface */ +#define EC_LPC_ADDR_OLD_PARAM 0x880 +#define EC_OLD_PARAM_SIZE 0x080 /* Size of param area in bytes */ + /* EC command register bit functions */ #define EC_LPC_CMDR_DATA (1 << 0) diff --git a/util/burn_my_ec.c b/util/burn_my_ec.c index f0b2a569b6..5af1a8e63a 100644 --- a/util/burn_my_ec.c +++ b/util/burn_my_ec.c @@ -20,7 +20,7 @@ static const char * const part_name[] = {"unknown", "RO", "A", "B"}; enum ec_current_image get_version(enum ec_current_image *version_ptr) { struct ec_response_get_version r; - char build_info[EC_PARAM_SIZE]; + char build_info[EC_HOST_PARAM_SIZE]; int res; res = ec_command(EC_CMD_GET_VERSION, NULL, 0, &r, sizeof(r)); @@ -59,7 +59,7 @@ int flash_partition(enum ec_current_image part, const uint8_t *payload, struct ec_params_flash_erase er_req; struct ec_params_flash_write wr_req; struct ec_params_flash_read rd_req; - uint8_t rd_resp[EC_PARAM_SIZE]; + uint8_t rd_resp[EC_OLD_PARAM_SIZE]; int res; uint32_t i; enum ec_current_image current = EC_IMAGE_UNKNOWN; diff --git a/util/comm-lpc.c b/util/comm-lpc.c index d91a8a2cc6..54686dbcbb 100644 --- a/util/comm-lpc.c +++ b/util/comm-lpc.c @@ -34,15 +34,15 @@ int comm_init(void) * byte, since we don't support ACPI burst mode and thus bit 4 should * be 0. */ - byte &= inb(EC_LPC_ADDR_USER_CMD); - byte &= inb(EC_LPC_ADDR_USER_DATA); - for (i = 0; i < EC_PARAM_SIZE && byte == 0xff; ++i) - byte &= inb(EC_LPC_ADDR_USER_PARAM + i); + byte &= inb(EC_LPC_ADDR_HOST_CMD); + byte &= inb(EC_LPC_ADDR_HOST_DATA); + for (i = 0; i < EC_OLD_PARAM_SIZE && byte == 0xff; ++i) + byte &= inb(EC_LPC_ADDR_OLD_PARAM + i); if (byte == 0xff) { fprintf(stderr, "Port 0x%x,0x%x,0x%x-0x%x are all 0xFF.\n", - EC_LPC_ADDR_USER_CMD, EC_LPC_ADDR_USER_DATA, - EC_LPC_ADDR_USER_PARAM, - EC_LPC_ADDR_USER_PARAM + EC_PARAM_SIZE - 1); + EC_LPC_ADDR_HOST_CMD, EC_LPC_ADDR_HOST_DATA, + EC_LPC_ADDR_OLD_PARAM, + EC_LPC_ADDR_OLD_PARAM + EC_OLD_PARAM_SIZE - 1); fprintf(stderr, "Very likely this board doesn't have a Chromium EC.\n"); return -4; @@ -86,16 +86,19 @@ int ec_command(int command, const void *indata, int insize, uint8_t *d; int i; - /* TODO: add command line option to use kernel command/param window */ - int cmd_addr = EC_LPC_ADDR_USER_CMD; - int data_addr = EC_LPC_ADDR_USER_DATA; - int param_addr = EC_LPC_ADDR_USER_PARAM; + int cmd_addr = EC_LPC_ADDR_HOST_CMD; + int data_addr = EC_LPC_ADDR_HOST_DATA; + int param_addr = EC_LPC_ADDR_OLD_PARAM; - if (insize > EC_PARAM_SIZE || outsize > EC_PARAM_SIZE) { + if (insize > EC_OLD_PARAM_SIZE) { fprintf(stderr, "Data size too big\n"); return -EC_RES_ERROR; } + /* Clip output buffer to the size we can actually use */ + if (outsize > EC_OLD_PARAM_SIZE) + outsize = EC_OLD_PARAM_SIZE; + if (wait_for_ec(cmd_addr, 1000000)) { fprintf(stderr, "Timeout waiting for EC ready\n"); return -EC_RES_ERROR; diff --git a/util/ectool.c b/util/ectool.c index 9e3efec836..74ed7d9d70 100644 --- a/util/ectool.c +++ b/util/ectool.c @@ -270,7 +270,7 @@ int cmd_version(int argc, char *argv[]) { static const char * const fw_copies[] = {"unknown", "RO", "A", "B"}; struct ec_response_get_version r; - char build_string[EC_PARAM_SIZE]; + char build_string[EC_HOST_PARAM_SIZE]; int rv; rv = ec_command(EC_CMD_GET_VERSION, NULL, 0, &r, sizeof(r)); @@ -432,7 +432,7 @@ int cmd_flash_info(int argc, char *argv[]) int cmd_flash_read(int argc, char *argv[]) { struct ec_params_flash_read p; - uint8_t rdata[EC_PARAM_SIZE]; + uint8_t rdata[EC_OLD_PARAM_SIZE]; int offset, size; int rv; int i; @@ -1166,7 +1166,7 @@ int cmd_pstore_info(int argc, char *argv[]) int cmd_pstore_read(int argc, char *argv[]) { struct ec_params_pstore_read p; - uint8_t rdata[EC_PARAM_SIZE]; + uint8_t rdata[EC_PSTORE_SIZE_MAX]; int offset, size; int rv; int i; |