diff options
author | Randall Spangler <rspangler@chromium.org> | 2018-05-18 15:24:25 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-05-23 20:35:12 -0700 |
commit | 57ed31bcc5af3d79a24dfc1937560c922685d280 (patch) | |
tree | 7e3c06a0b2733fc94c46801e76c91a334967a702 /common | |
parent | f07e300fe457575394c21d040cfc80e6dc2829f0 (diff) | |
download | chrome-ec-57ed31bcc5af3d79a24dfc1937560c922685d280.tar.gz |
cr50: pass params to vendor commands as struct
This makes it easier to add params or flags for vendor commands
without changing all of the command handlers. It also reduces code
size by 56 bytes.
For now, existing command handlers continue to use
DECLARE_VENDOR_COMMAND(). Added DECLARE_VENDOR_COMMAND_P() for
handlers which take the params struct directly. The CCD command will
be the first user of that, since it will have different rules for
'open' based on where the command comes from.
No change to existing command behavior.
BUG=b:79983505
BRANCH=cr50
TEST=gsctool -I still works
Change-Id: I7ed288a9c45e381162e246b50ae88cf76e67490d
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1069538
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
Diffstat (limited to 'common')
-rw-r--r-- | common/extension.c | 21 | ||||
-rw-r--r-- | common/tpm_registers.c | 26 |
2 files changed, 21 insertions, 26 deletions
diff --git a/common/extension.c b/common/extension.c index d75bbbe4f3..fecb61ec9e 100644 --- a/common/extension.c +++ b/common/extension.c @@ -11,11 +11,7 @@ #define CPRINTS(format, args...) cprints(CC_EXTENSION, format, ## args) -uint32_t extension_route_command(uint16_t command_code, - void *buffer, - size_t in_size, - size_t *out_size, - uint32_t flags) +uint32_t extension_route_command(struct vendor_cmd_params *p) { struct extension_command *cmd_p; struct extension_command *end_p; @@ -27,8 +23,8 @@ uint32_t extension_route_command(uint16_t command_code, #endif /* Filter commands from USB */ - if (flags & VENDOR_CMD_FROM_USB) { - switch (command_code) { + if (p->flags & VENDOR_CMD_FROM_USB) { + switch (p->code) { #ifdef CR50_DEV case VENDOR_CC_IMMEDIATE_RESET: case VENDOR_CC_INVALIDATE_INACTIVE_RW: @@ -54,7 +50,7 @@ uint32_t extension_route_command(uint16_t command_code, * Cr50 firmware. */ if (board_id_is_mismatched()) { - switch (command_code) { + switch (p->code) { case EXTENSION_FW_UPGRADE: case VENDOR_CC_REPORT_TPM_STATE: case VENDOR_CC_TURN_UPDATE_ON: @@ -71,15 +67,14 @@ uint32_t extension_route_command(uint16_t command_code, cmd_p = (struct extension_command *)&__extension_cmds; end_p = (struct extension_command *)&__extension_cmds_end; while (cmd_p != end_p) { - if (cmd_p->command_code == command_code) - return cmd_p->handler(command_code, buffer, - in_size, out_size); + if (cmd_p->command_code == p->code) + return cmd_p->handler(p); cmd_p++; } ignore_cmd: /* Command not found or not allowed */ - CPRINTS("%s: ignore %d: %s", __func__, command_code, why_ignore); - *out_size = 0; + CPRINTS("%s: ignore %d: %s", __func__, p->code, why_ignore); + p->out_size = 0; return VENDOR_RC_NO_SUCH_COMMAND; } diff --git a/common/tpm_registers.c b/common/tpm_registers.c index a8a3546109..215905efa9 100644 --- a/common/tpm_registers.c +++ b/common/tpm_registers.c @@ -643,21 +643,21 @@ static void call_extension_command(struct tpm_cmd_header *tpmh, /* 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); - rc = extension_route_command(subcommand_code, - tpmh + 1, - command_size - - sizeof(struct tpm_cmd_header), - total_size, - flags); + struct vendor_cmd_params p = { + .code = be16toh(tpmh->subcommand_code), + /* The header takes room in the buffer. */ + .buffer = tpmh + 1, + .in_size = command_size - sizeof(struct tpm_cmd_header), + .out_size = *total_size - sizeof(struct tpm_cmd_header), + .flags = flags + }; + + rc = extension_route_command(&p); + /* Add the header size back. */ - *total_size += sizeof(struct tpm_cmd_header); + *total_size = p.out_size + sizeof(struct tpm_cmd_header); tpmh->size = htobe32(*total_size); + /* Flag errors from commands as vendor-specific */ if (rc) rc |= VENDOR_RC_ERR; |