diff options
author | Vadim Bendebury <vbendeb@chromium.org> | 2015-11-12 17:21:17 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2015-11-18 00:14:03 -0800 |
commit | ee1a2a3a8329323e0600d12ad1b371d62136867e (patch) | |
tree | d726fbe4768075f33c3e6baa8bfe4de84a171a7a /common | |
parent | 7f1baece0a5be8e7860cfe09bd94b39ffb3ba93c (diff) | |
download | chrome-ec-ee1a2a3a8329323e0600d12ad1b371d62136867e.tar.gz |
add command multiplexer to the TPM driver
This code allows to send extension commands over TPM protocol, no
callbacks have been registered yet.
The same buffer is used as input and output data. The header is
stripped off before the callback is called and then re-added after
processing.
This could be used for testing, for proprietary firmware update
protocol, etc.
BRANCH=none
BUG=chrome-os-partner:47524
TEST=none yet
Change-Id: I91f692cc6e20abe774ee4ef001be28e5af102b2a
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/312587
Diffstat (limited to 'common')
-rw-r--r-- | common/build.mk | 1 | ||||
-rw-r--r-- | common/tpm_registers.c | 60 |
2 files changed, 54 insertions, 7 deletions
diff --git a/common/build.mk b/common/build.mk index f88e534fbb..b889b641f9 100644 --- a/common/build.mk +++ b/common/build.mk @@ -38,6 +38,7 @@ common-$(CONFIG_COMMON_PANIC_OUTPUT)+=panic_output.o common-$(CONFIG_COMMON_RUNTIME)+=hooks.o main.o system.o shared_mem.o common-$(CONFIG_COMMON_TIMER)+=timer.o common-$(CONFIG_CRC8)+= crc8.o +common-$(CONFIG_EXTENSION_COMMAND)+=extension.o common-$(CONFIG_EXTPOWER_GPIO)+=extpower_gpio.o common-$(CONFIG_FANS)+=fan.o common-$(CONFIG_FLASH)+=flash.o diff --git a/common/tpm_registers.c b/common/tpm_registers.c index 52de4aa6f6..debfbfb613 100644 --- a/common/tpm_registers.c +++ b/common/tpm_registers.c @@ -10,9 +10,8 @@ */ #include "byteorder.h" -#include "common.h" #include "console.h" -#include "hooks.h" +#include "extension.h" #include "task.h" #include "tpm_registers.h" #include "util.h" @@ -412,6 +411,35 @@ static void tpm_init(void) _plat__SetNvAvail(); } +#ifdef CONFIG_EXTENSION_COMMAND + +static void call_extension_command(struct tpm_cmd_header *tpmh, + size_t *total_size) +{ + size_t command_size = be32toh(tpmh->size); + + /* Verify there is room for at least the extension command header. */ + if (command_size >= sizeof(struct tpm_cmd_header)) { + uint16_t subcommand_code; + + /* The header takes room in the buffer. */ + *total_size -= sizeof(struct tpm_cmd_header); + + subcommand_code = be16toh(tpmh->subcommand_code); + extension_route_command(subcommand_code, + tpmh + 1, + command_size - + sizeof(struct tpm_cmd_header), + total_size); + /* Add the header size back. */ + *total_size += sizeof(struct tpm_cmd_header); + tpmh->size = htobe32(*total_size); + } else { + *total_size = command_size; + } +} +#endif + void tpm_task(void) { tpm_init(); @@ -429,14 +457,32 @@ void tpm_task(void) CPRINTF("%s: received fifo command 0x%04x\n", __func__, command_code); - ExecuteCommand(tpm_.fifo_write_index, - tpm_.regs.data_fifo, - &response_size, - &response); +#ifdef CONFIG_EXTENSION_COMMAND + if (command_code == CONFIG_EXTENSION_COMMAND) { + response_size = sizeof(tpm_.regs.data_fifo); + call_extension_command(tpmh, &response_size); + } else +#endif + { + ExecuteCommand(tpm_.fifo_write_index, + tpm_.regs.data_fifo, + &response_size, + &response); + } CPRINTF("got %d bytes in response\n", response_size); if (response_size && (response_size <= sizeof(tpm_.regs.data_fifo))) { - memcpy(tpm_.regs.data_fifo, response, response_size); +#ifdef CONFIG_EXTENSION_COMMAND + if (command_code != CONFIG_EXTENSION_COMMAND) +#endif + { + /* + * Extension commands reuse FIFO buffer, the + * rest need to copy. + */ + memcpy(tpm_.regs.data_fifo, + response, response_size); + } tpm_.fifo_read_index = 0; tpm_.fifo_write_index = response_size; tpm_.regs.sts |= data_avail; |