diff options
author | Vadim Bendebury <vbendeb@chromium.org> | 2015-11-12 13:30:00 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2015-11-15 13:08:00 -0800 |
commit | 422cb0c5e227b4f944af5e31d8c34c18dd0c5b11 (patch) | |
tree | cfc1af264704be10ccc34c3c1018a96601ec93a7 /common/tpm_registers.c | |
parent | 684d25b41aa77f14aae48afb5968a8aa1643c629 (diff) | |
download | chrome-ec-stabilize-7647.74.B.tar.gz |
cr50: make use of byteorder routinesstabilize-7647.74.Bstabilize-7647.72.Bstabilize-7647.32.Brelease-R48-7647.B
Use the previously introduced endian conversion routines in the driver
and the TPM2 library.
Use packed TPM message header structure to make it easy to access
unaligned header fields.
BRANCH=none
BUG=chrome-os-partner:43025
TEST=the tpm startup command still succeeds.
Change-Id: I03078481664858a19617e248f98cb20013c27445
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/312585
Diffstat (limited to 'common/tpm_registers.c')
-rw-r--r-- | common/tpm_registers.c | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/common/tpm_registers.c b/common/tpm_registers.c index 5aba839764..52de4aa6f6 100644 --- a/common/tpm_registers.c +++ b/common/tpm_registers.c @@ -9,6 +9,7 @@ * 24-bit address. There is no provision for error reporting at this level. */ +#include "byteorder.h" #include "common.h" #include "console.h" #include "hooks.h" @@ -273,22 +274,12 @@ static void sts_reg_write(const uint8_t *data, uint32_t data_size) } } -/* We presume to be running on a little endian CPU. */ -static uint32_t be32_to_cpu(const uint8_t *data) -{ - int i; - uint32_t value = 0; - - for (i = 0; i < sizeof(value); i++) - value |= ((uint32_t)data[i]) << (8 * (sizeof(value) - i - 1)); - - return value; -} - /* Collect received data in the local buffer and change state accordingly. */ static void fifo_reg_write(const uint8_t *data, uint32_t data_size) { uint32_t packet_size; + struct tpm_cmd_header *tpmh; + /* * Make sure we are in the approriate sate, otherwise ignore this * access. @@ -322,7 +313,8 @@ static void fifo_reg_write(const uint8_t *data, uint32_t data_size) return; } - packet_size = be32_to_cpu(tpm_.regs.data_fifo + 2); + tpmh = (struct tpm_cmd_header *)tpm_.regs.data_fifo; + packet_size = be32toh(tpmh->size); if (tpm_.fifo_write_index < packet_size) { tpm_.regs.sts |= expect; /* More data is needed. */ return; @@ -427,11 +419,15 @@ void tpm_task(void) while (1) { uint8_t *response; unsigned response_size; + uint32_t command_code; + struct tpm_cmd_header *tpmh; /* Wait for the next command event */ task_wait_event(-1); + tpmh = (struct tpm_cmd_header *)tpm_.regs.data_fifo; + command_code = be32toh(tpmh->command_code); CPRINTF("%s: received fifo command 0x%04x\n", - __func__, be32_to_cpu(tpm_.regs.data_fifo + 6)); + __func__, command_code); ExecuteCommand(tpm_.fifo_write_index, tpm_.regs.data_fifo, |