From 19ffcb3412d4fae370825c16b4bb0aaa0ed90ea9 Mon Sep 17 00:00:00 2001 From: Shawn Nematbakhsh Date: Fri, 27 Mar 2015 13:44:34 -0700 Subject: [PATCH] chromeec: Access ID + flags through ACPI I/O ports If CONFIG_EC_GOOGLE_CHROMEEC_ACPI_MEMMAP is set, access to memmap data should go through the ACPI CMD / DATA ports. BUG=chrome-os-partner:38224 TEST=Manual on Samus. Define EC_GOOGLE_CHROMEEC_ACPI_MEMMAP. Verify system boots cleanly. BRANCH=None Change-Id: I9d19704df259f5a25e04a9b07b23968e93fe6302 Signed-off-by: Patrick Georgi Original-Commit-Id: d0b59b040a7889d2d1bd6eeaf57dd960bd29927d Original-Signed-off-by: Shawn Nematbakhsh Original-Change-Id: I405e28828457a1fd83a7ece7192a7e7d0a37be95 Original-Reviewed-on: https://chromium-review.googlesource.com/262932 Original-Reviewed-by: Randall Spangler Original-Reviewed-by: Duncan Laurie Reviewed-on: http://review.coreboot.org/9893 Tested-by: build bot (Jenkins) Reviewed-by: Stefan Reinauer --- src/ec/google/chromeec/ec_lpc.c | 87 ++++++++++++++++++++++++--------- 1 file changed, 63 insertions(+), 24 deletions(-) diff --git a/src/ec/google/chromeec/ec_lpc.c b/src/ec/google/chromeec/ec_lpc.c index 061c1032c1..f5f5434548 100644 --- a/src/ec/google/chromeec/ec_lpc.c +++ b/src/ec/google/chromeec/ec_lpc.c @@ -29,30 +29,6 @@ #include "ec.h" #include "ec_commands.h" -static int google_chromeec_command_version(void) -{ - u8 id1, id2, flags; - - id1 = inb(EC_LPC_ADDR_MEMMAP + EC_MEMMAP_ID); - id2 = inb(EC_LPC_ADDR_MEMMAP + EC_MEMMAP_ID + 1); - flags = inb(EC_LPC_ADDR_MEMMAP + EC_MEMMAP_HOST_CMD_FLAGS); - - if (id1 != 'E' || id2 != 'C') { - printk(BIOS_ERR, "Missing Chromium EC memory map.\n"); - return -1; - } - - if (flags & EC_HOST_CMD_FLAG_VERSION_3) { - return EC_HOST_CMD_FLAG_VERSION_3; - } else if (flags & EC_HOST_CMD_FLAG_LPC_ARGS_SUPPORTED) { - return EC_HOST_CMD_FLAG_LPC_ARGS_SUPPORTED; - } else { - printk(BIOS_ERR, - "Chromium EC command version unsupported\n"); - return -1; - } -} - static int google_chromeec_wait_ready(u16 port) { u8 ec_status = inb(port); @@ -75,6 +51,69 @@ static int google_chromeec_wait_ready(u16 port) return 0; } +#if CONFIG_EC_GOOGLE_CHROMEEC_ACPI_MEMMAP +/* Read memmap data through ACPI port 66/62 */ +static int read_memmap(u8 *data, u8 offset) +{ + if (google_chromeec_wait_ready(EC_LPC_ADDR_ACPI_CMD)) { + printk(BIOS_ERR, "Timeout waiting for EC ready!\n"); + return -1; + } + + /* Issue the ACPI read command */ + outb(EC_CMD_ACPI_READ, EC_LPC_ADDR_ACPI_CMD); + + if (google_chromeec_wait_ready(EC_LPC_ADDR_ACPI_CMD)) { + printk(BIOS_ERR, "Timeout waiting for EC READ_EVENT!\n"); + return -1; + } + + /* Write data address */ + outb(offset + EC_ACPI_MEM_MAPPED_BEGIN, EC_LPC_ADDR_ACPI_DATA); + + if (google_chromeec_wait_ready(EC_LPC_ADDR_ACPI_CMD)) { + printk(BIOS_ERR, "Timeout waiting for EC DATA!\n"); + return -1; + } + + *data = inb(EC_LPC_ADDR_ACPI_DATA); + return 0; +} +#endif + +static int google_chromeec_command_version(void) +{ + u8 id1, id2, flags; + +#if CONFIG_EC_GOOGLE_CHROMEEC_ACPI_MEMMAP + if (read_memmap(&id1, EC_MEMMAP_ID) || + read_memmap(&id2, EC_MEMMAP_ID + 1) || + read_memmap(&flags, EC_MEMMAP_HOST_CMD_FLAGS)) { + printk(BIOS_ERR, "Error reading memmap data.\n"); + return -1; + } +#else + id1 = inb(EC_LPC_ADDR_MEMMAP + EC_MEMMAP_ID); + id2 = inb(EC_LPC_ADDR_MEMMAP + EC_MEMMAP_ID + 1); + flags = inb(EC_LPC_ADDR_MEMMAP + EC_MEMMAP_HOST_CMD_FLAGS); +#endif + + if (id1 != 'E' || id2 != 'C') { + printk(BIOS_ERR, "Missing Chromium EC memory map.\n"); + return -1; + } + + if (flags & EC_HOST_CMD_FLAG_VERSION_3) { + return EC_HOST_CMD_FLAG_VERSION_3; + } else if (flags & EC_HOST_CMD_FLAG_LPC_ARGS_SUPPORTED) { + return EC_HOST_CMD_FLAG_LPC_ARGS_SUPPORTED; + } else { + printk(BIOS_ERR, + "Chromium EC command version unsupported\n"); + return -1; + } +} + static int google_chromeec_command_v3(struct chromeec_command *cec_command) { struct ec_host_request rq;