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 /include/extension.h | |
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 'include/extension.h')
-rw-r--r-- | include/extension.h | 85 |
1 files changed, 51 insertions, 34 deletions
diff --git a/include/extension.h b/include/extension.h index bec6bf3ffd..7ef43bc2a3 100644 --- a/include/extension.h +++ b/include/extension.h @@ -22,19 +22,31 @@ enum vendor_cmd_flags { VENDOR_CMD_FROM_USB = (1 << 0), }; -/* - * Type of function handling extension commands. - * - * @param buffer As input points to the input data to be processed, as - * output stores data, processing result. - * @param command_size Number of bytes of input data - * @param response_size On input - max size of the buffer, on output - actual - * number of data returned by the handler. - */ -typedef enum vendor_cmd_rc (*extension_handler)(enum vendor_cmd_cc code, - void *buffer, - size_t command_size, - size_t *response_size); +/* Parameters for vendor commands */ +struct vendor_cmd_params { + /* Command code */ + enum vendor_cmd_cc code; + + /* On input, data to be processed. On output, response data. */ + void *buffer; + + /* Number of bytes of input data */ + size_t in_size; + + /* + * On input, size of output buffer. On output, actual response size. + * Both in bytes. A single response byte usually indicates an error + * and contains the error code. + */ + size_t out_size; + + /* Flags; zero or more of enum vendor_cmd_flags */ + uint32_t flags; +}; + +/* Type of function handling extension commands. */ +typedef enum vendor_cmd_rc + (*extension_handler)(struct vendor_cmd_params *params); /** * Find handler for an extension command. @@ -42,20 +54,11 @@ typedef enum vendor_cmd_rc (*extension_handler)(enum vendor_cmd_cc code, * Use the interface specific function call in order to check the policies for * handling the commands on that interface. * - * @param command_code Code associated with a extension command handler. - * @param buffer Data to be processd by the handler, the same space - * is used for data returned by the handler. - * @param in_size Size of the input data. - * @param out_size On input: max size of the buffer. On output: actual - * number of bytes returned by the handler; a single byte - * usually indicates an error and contains the error code. - * @param flags Zero or more flags from vendor_cmd_flags. + * @param p Parameters for the command + * @return The return code from processing the command. */ -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); + /* Pointer table */ struct extension_command { @@ -64,20 +67,34 @@ struct extension_command { } __packed; #define DECLARE_EXTENSION_COMMAND(code, func) \ - static enum vendor_cmd_rc func##_wrap(enum vendor_cmd_cc code, \ - void *cmd_body, \ - size_t cmd_size, \ - size_t *response_size) { \ - func(cmd_body, cmd_size, response_size); \ + static enum vendor_cmd_rc \ + func##_wrap(struct vendor_cmd_params *params) \ + { \ + func(params->buffer, params->in_size, \ + ¶ms->out_size); \ return 0; \ } \ const struct extension_command __keep __extension_cmd_##code \ __attribute__((section(".rodata.extensioncmds"))) \ = {.command_code = code, .handler = func##_wrap } -#define DECLARE_VENDOR_COMMAND(code, func) \ - const struct extension_command __keep __vendor_cmd_##code \ +/* Vendor command which takes params directly */ +#define DECLARE_VENDOR_COMMAND(cmd_code, func) \ + static enum vendor_cmd_rc \ + func##_wrap(struct vendor_cmd_params *params) \ + { \ + func(params->code, params->buffer, params->in_size, \ + ¶ms->out_size); \ + return 0; \ + } \ + const struct extension_command __keep __vendor_cmd_##cmd_code \ + __attribute__((section(".rodata.extensioncmds"))) \ + = {.command_code = cmd_code, .handler = func##_wrap} + +/* Vendor command which takes params as struct */ +#define DECLARE_VENDOR_COMMAND_P(cmd_code, func) \ + const struct extension_command __keep __vendor_cmd_##cmd_code \ __attribute__((section(".rodata.extensioncmds"))) \ - = {.command_code = code, .handler = func} + = {.command_code = cmd_code, .handler = func} #endif /* __EC_INCLUDE_EXTENSION_H */ |