diff options
author | Randall Spangler <rspangler@chromium.org> | 2012-07-11 11:18:17 -0700 |
---|---|---|
committer | Gerrit <chrome-bot@google.com> | 2012-07-11 14:46:30 -0700 |
commit | 07ca0977fe554696288048c5c691aa5b9cfa7ac8 (patch) | |
tree | aade5d33536338c2baa869c1865e4eb11b390e3e /common | |
parent | 61e0e5508a559cc9935951be4f68455809300a2e (diff) | |
download | chrome-ec-07ca0977fe554696288048c5c691aa5b9cfa7ac8.tar.gz |
Refactor API for host commands, and handle variable length data better
Added version mask field to DECLARE_HOST_COMMAND() because it's
convenient to do so when I'm touching all host command
implementations, but all commands simply declare version 0 and nothing
checks it yet. Will add version support in a followup CL.
This change is internal to the EC; it does not change the data sent
over the host interface.
BUG=chrome-os-partner:11275
TEST=manual
ectool version && ectool echash; should get sane data from both
ectool flashread 0x80 0x40 /tmp/foo && od -tx1 /tmp/foo
should match data from offset 0x80 of ec.bin (od -j128 -n64 -tx1 ec.bin)
Change-Id: I5699f72b8d5e1ac23929353c9a34158d76c44206
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/27172
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Diffstat (limited to 'common')
-rw-r--r-- | common/flash_commands.c | 124 | ||||
-rw-r--r-- | common/host_command.c | 92 | ||||
-rw-r--r-- | common/host_event_commands.c | 60 | ||||
-rw-r--r-- | common/keyboard.c | 10 | ||||
-rw-r--r-- | common/lightbar.c | 24 | ||||
-rw-r--r-- | common/pstore_commands.c | 45 | ||||
-rw-r--r-- | common/pwm_commands.c | 57 | ||||
-rw-r--r-- | common/system_common.c | 63 | ||||
-rw-r--r-- | common/temp_sensor_commands.c | 22 | ||||
-rw-r--r-- | common/thermal_commands.c | 34 | ||||
-rw-r--r-- | common/usb_charge_commands.c | 14 | ||||
-rw-r--r-- | common/vboot.c | 26 | ||||
-rw-r--r-- | common/vboot_hash.c | 18 | ||||
-rw-r--r-- | common/x86_power.c | 11 |
14 files changed, 354 insertions, 246 deletions
diff --git a/common/flash_commands.c b/common/flash_commands.c index 5df42504c5..d8953bc3c7 100644 --- a/common/flash_commands.c +++ b/common/flash_commands.c @@ -186,45 +186,48 @@ DECLARE_CONSOLE_COMMAND(flashwp, command_flash_wp, /*****************************************************************************/ /* Host commands */ -static int flash_command_get_info(uint8_t *data, int *resp_size) +static int flash_command_get_info(struct host_cmd_handler_args *args) { struct ec_response_flash_info *r = - (struct ec_response_flash_info *)data; + (struct ec_response_flash_info *)args->response; r->flash_size = flash_get_size(); r->write_block_size = flash_get_write_block_size(); r->erase_block_size = flash_get_erase_block_size(); r->protect_block_size = flash_get_protect_block_size(); - *resp_size = sizeof(struct ec_response_flash_info); + args->response_size = sizeof(*r); return EC_RES_SUCCESS; } -DECLARE_HOST_COMMAND(EC_CMD_FLASH_INFO, flash_command_get_info); +DECLARE_HOST_COMMAND(EC_CMD_FLASH_INFO, + flash_command_get_info, + EC_VER_MASK(0)); -static int flash_command_read(uint8_t *data, int *resp_size) +static int flash_command_read(struct host_cmd_handler_args *args) { - struct ec_params_flash_read *p = - (struct ec_params_flash_read *)data; - struct ec_response_flash_read *r = - (struct ec_response_flash_read *)data; + const struct ec_params_flash_read *p = + (const struct ec_params_flash_read *)args->params; - if (p->size > sizeof(r->data)) - return EC_RES_ERROR; + if (p->size > EC_PARAM_SIZE) + return EC_RES_INVALID_PARAM; - if (flash_read(p->offset, p->size, r->data)) + if (flash_dataptr(p->offset, p->size, 1, (char **)&args->response) < 0) return EC_RES_ERROR; - *resp_size = sizeof(struct ec_response_flash_read); + args->response_size = p->size; + return EC_RES_SUCCESS; } -DECLARE_HOST_COMMAND(EC_CMD_FLASH_READ, flash_command_read); +DECLARE_HOST_COMMAND(EC_CMD_FLASH_READ, + flash_command_read, + EC_VER_MASK(0)); -static int flash_command_write(uint8_t *data, int *resp_size) +static int flash_command_write(struct host_cmd_handler_args *args) { - struct ec_params_flash_write *p = - (struct ec_params_flash_write *)data; + const struct ec_params_flash_write *p = + (const struct ec_params_flash_write *)args->params; if (p->size > sizeof(p->data)) - return EC_RES_ERROR; + return EC_RES_INVALID_PARAM; if (system_unsafe_to_overwrite(p->offset, p->size)) return EC_RES_ACCESS_DENIED; @@ -234,12 +237,14 @@ static int flash_command_write(uint8_t *data, int *resp_size) return EC_RES_SUCCESS; } -DECLARE_HOST_COMMAND(EC_CMD_FLASH_WRITE, flash_command_write); +DECLARE_HOST_COMMAND(EC_CMD_FLASH_WRITE, + flash_command_write, + EC_VER_MASK(0)); -static int flash_command_erase(uint8_t *data, int *resp_size) +static int flash_command_erase(struct host_cmd_handler_args *args) { - struct ec_params_flash_erase *p = - (struct ec_params_flash_erase *)data; + const struct ec_params_flash_erase *p = + (const struct ec_params_flash_erase *)args->params; if (system_unsafe_to_overwrite(p->offset, p->size)) return EC_RES_ACCESS_DENIED; @@ -249,51 +254,64 @@ static int flash_command_erase(uint8_t *data, int *resp_size) return EC_RES_SUCCESS; } -DECLARE_HOST_COMMAND(EC_CMD_FLASH_ERASE, flash_command_erase); +DECLARE_HOST_COMMAND(EC_CMD_FLASH_ERASE, + flash_command_erase, + EC_VER_MASK(0)); -static int flash_command_wp_enable(uint8_t *data, int *resp_size) +static int flash_command_wp_enable(struct host_cmd_handler_args *args) { - struct ec_params_flash_wp_enable *p = - (struct ec_params_flash_wp_enable *)data; + const struct ec_params_flash_wp_enable *p = + (const struct ec_params_flash_wp_enable *)args->params; + /* + * TODO: this is wrong; needs to translate return code to EC_RES_*. + * But since this command is going away imminently, no rush. + */ return flash_lock_protect(p->enable_wp ? 1 : 0); } -DECLARE_HOST_COMMAND(EC_CMD_FLASH_WP_ENABLE, flash_command_wp_enable); +DECLARE_HOST_COMMAND(EC_CMD_FLASH_WP_ENABLE, + flash_command_wp_enable, + EC_VER_MASK(0)); -static int flash_command_wp_get_state(uint8_t *data, int *resp_size) +static int flash_command_wp_get_state(struct host_cmd_handler_args *args) { - struct ec_response_flash_wp_enable *p = - (struct ec_response_flash_wp_enable *)data; + struct ec_response_flash_wp_enable *r = + (struct ec_response_flash_wp_enable *)args->response; if (flash_get_protect_lock() & FLASH_PROTECT_LOCK_SET) - p->enable_wp = 1; + r->enable_wp = 1; else - p->enable_wp = 0; + r->enable_wp = 0; - *resp_size = sizeof(struct ec_response_flash_wp_enable); + args->response_size = sizeof(*r); return EC_RES_SUCCESS; } -DECLARE_HOST_COMMAND(EC_CMD_FLASH_WP_GET_STATE, flash_command_wp_get_state); +DECLARE_HOST_COMMAND(EC_CMD_FLASH_WP_GET_STATE, + flash_command_wp_get_state, + EC_VER_MASK(0)); -static int flash_command_wp_set_range(uint8_t *data, int *resp_size) +static int flash_command_wp_set_range(struct host_cmd_handler_args *args) { - struct ec_params_flash_wp_range *p = - (struct ec_params_flash_wp_range *)data; - enum ec_status ret; + const struct ec_params_flash_wp_range *p = + (const struct ec_params_flash_wp_range *)args->params; + /* + * TODO: this is wrong; needs to translate return code to EC_RES_*. + * But since this command is going away imminently, no rush. + */ if (p->size) - ret = flash_set_protect(p->offset, p->size, 1); + return flash_set_protect(p->offset, p->size, 1); else - ret = flash_set_protect(0, flash_get_size(), 0); - - return ret; + return flash_set_protect(0, flash_get_size(), 0); } -DECLARE_HOST_COMMAND(EC_CMD_FLASH_WP_SET_RANGE, flash_command_wp_set_range); +DECLARE_HOST_COMMAND(EC_CMD_FLASH_WP_SET_RANGE, + flash_command_wp_set_range, + EC_VER_MASK(0)); -static int flash_command_wp_get_range(uint8_t *data, int *resp_size) +static int flash_command_wp_get_range(struct host_cmd_handler_args *args) { - struct ec_response_flash_wp_range *p = - (struct ec_response_flash_wp_range *)data; + struct ec_response_flash_wp_range *r = + (struct ec_response_flash_wp_range *)args->response; int pbsize = flash_get_protect_block_size(); int banks = flash_get_size() / pbsize; const uint8_t *blocks; @@ -320,14 +338,16 @@ static int flash_command_wp_get_range(uint8_t *data, int *resp_size) /* TODO(crosbug.com/p/9492): return multiple region of ranges(). */ if (min == -1) { /* None of bank is protected. */ - p->offset = 0; - p->size = 0; + r->offset = 0; + r->size = 0; } else { - p->offset = min * pbsize; - p->size = (max - min + 1) * pbsize; + r->offset = min * pbsize; + r->size = (max - min + 1) * pbsize; } - *resp_size = sizeof(struct ec_response_flash_wp_range); + args->response_size = sizeof(*r); return EC_RES_SUCCESS; } -DECLARE_HOST_COMMAND(EC_CMD_FLASH_WP_GET_RANGE, flash_command_wp_get_range); +DECLARE_HOST_COMMAND(EC_CMD_FLASH_WP_GET_RANGE, + flash_command_wp_get_range, + EC_VER_MASK(0)); diff --git a/common/host_command.c b/common/host_command.c index db71c11261..58e144fddc 100644 --- a/common/host_command.c +++ b/common/host_command.c @@ -60,38 +60,43 @@ void host_command_received(int command) task_set_event(TASK_ID_HOSTCMD, TASK_EVENT_CMD_PENDING, 0); } - -static int host_command_proto_version(uint8_t *data, int *resp_size) +static int host_command_proto_version(struct host_cmd_handler_args *args) { struct ec_response_proto_version *r = - (struct ec_response_proto_version *)data; + (struct ec_response_proto_version *)args->response; r->version = EC_PROTO_VERSION; + args->response_size = sizeof(*r); - *resp_size = sizeof(struct ec_response_proto_version); return EC_RES_SUCCESS; } -DECLARE_HOST_COMMAND(EC_CMD_PROTO_VERSION, host_command_proto_version); - +DECLARE_HOST_COMMAND(EC_CMD_PROTO_VERSION, + host_command_proto_version, + EC_VER_MASK(0)); -static int host_command_hello(uint8_t *data, int *resp_size) +static int host_command_hello(struct host_cmd_handler_args *args) { - struct ec_params_hello *p = (struct ec_params_hello *)data; - struct ec_response_hello *r = (struct ec_response_hello *)data; + const struct ec_params_hello *p = + (const struct ec_params_hello *)args->params; + struct ec_response_hello *r = + (struct ec_response_hello *)args->response; uint32_t d = p->in_data; r->out_data = d + 0x01020304; - *resp_size = sizeof(struct ec_response_hello); + args->response_size = sizeof(*r); + return EC_RES_SUCCESS; } -DECLARE_HOST_COMMAND(EC_CMD_HELLO, host_command_hello); - +DECLARE_HOST_COMMAND(EC_CMD_HELLO, + host_command_hello, + EC_VER_MASK(0)); -static int host_command_read_test(uint8_t *data, int *resp_size) +static int host_command_read_test(struct host_cmd_handler_args *args) { - struct ec_params_read_test *p = (struct ec_params_read_test *)data; + const struct ec_params_read_test *p = + (const struct ec_params_read_test *)args->params; struct ec_response_read_test *r = - (struct ec_response_read_test *)data; + (struct ec_response_read_test *)args->response; int offset = p->offset; int size = p->size / sizeof(uint32_t); @@ -103,40 +108,46 @@ static int host_command_read_test(uint8_t *data, int *resp_size) for (i = 0; i < size; i++) r->data[i] = offset + i; - *resp_size = sizeof(struct ec_response_read_test); + args->response_size = sizeof(*r); + return EC_RES_SUCCESS; } -DECLARE_HOST_COMMAND(EC_CMD_READ_TEST, host_command_read_test); +DECLARE_HOST_COMMAND(EC_CMD_READ_TEST, + host_command_read_test, + EC_VER_MASK(0)); #ifndef CONFIG_LPC /* * Host command to read memory map is not needed on LPC, because LPC can * directly map the data to the host's memory space. */ -static int host_command_read_memmap(uint8_t *data, int *resp_size) +static int host_command_read_memmap(struct host_cmd_handler_args *args) { - struct ec_params_read_memmap *p = (struct ec_params_read_memmap *)data; - struct ec_response_read_memmap *r = - (struct ec_response_read_memmap *)data; + const struct ec_params_read_memmap *p = + (const struct ec_params_read_memmap *)args->params; /* Copy params out of data before we overwrite it with output */ uint8_t offset = p->offset; uint8_t size = p->size; - if (size > sizeof(r->data) || offset > EC_MEMMAP_SIZE || + if (size > EC_PARAM_SIZE || offset > EC_MEMMAP_SIZE || offset + size > EC_MEMMAP_SIZE) return EC_RES_INVALID_PARAM; - memcpy(r->data, host_get_memmap(offset), size); + args->response = host_get_memmap(offset); + args->response_size = size; - *resp_size = size; return EC_RES_SUCCESS; } -DECLARE_HOST_COMMAND(EC_CMD_READ_MEMMAP, host_command_read_memmap); +DECLARE_HOST_COMMAND(EC_CMD_READ_MEMMAP, + host_command_read_memmap, + EC_VER_MASK(0)); #endif -/* Finds a command by command number. Returns the command structure, or NULL if - * no match found. */ +/* + * Find a command by command number. Returns the command structure, or NULL if + * no match found. + */ static const struct host_command *find_host_command(int command) { const struct host_command *cmd; @@ -153,13 +164,32 @@ enum ec_status host_command_process(int command, uint8_t *data, int *response_size) { const struct host_command *cmd = find_host_command(command); - enum ec_status res = EC_RES_INVALID_COMMAND; + struct host_cmd_handler_args args; + enum ec_status res; CPRINTF("[%T hostcmd 0x%02x]\n", command); - *response_size = 0; - if (cmd) - res = cmd->handler(data, response_size); + if (!cmd) + return EC_RES_INVALID_COMMAND; + + /* TODO: right now we assume the same data buffer for both params + * and response. This isn't true for I2C/SPI; we should + * propagate args farther up the call chain. */ + args.command = command; + args.version = 0; + args.params = data; + args.params_size = EC_PARAM_SIZE; + args.response = data; + args.response_size = 0; + + res = cmd->handler(&args); + + /* Copy response data if necessary */ + *response_size = args.response_size; + if (args.response_size > EC_PARAM_SIZE) + return EC_RES_INVALID_RESPONSE; + else if (args.response_size && args.response != data) + memcpy(data, args.response, args.response_size); return res; } diff --git a/common/host_event_commands.c b/common/host_event_commands.c index 0d87fcac38..3242a6de83 100644 --- a/common/host_event_commands.c +++ b/common/host_event_commands.c @@ -5,6 +5,7 @@ /* Host event commands for Chrome EC */ +#include "common.h" #include "console.h" #include "host_command.h" #include "lpc.h" @@ -93,83 +94,94 @@ DECLARE_CONSOLE_COMMAND(hostevent, command_host_event, #ifdef CONFIG_LPC -static int host_event_get_smi_mask(uint8_t *data, int *resp_size) +static int host_event_get_smi_mask(struct host_cmd_handler_args *args) { struct ec_response_host_event_mask *r = - (struct ec_response_host_event_mask *)data; + (struct ec_response_host_event_mask *)args->response; r->mask = lpc_get_host_event_mask(LPC_HOST_EVENT_SMI); - *resp_size = sizeof(struct ec_response_host_event_mask); + args->response_size = sizeof(*r); + return EC_RES_SUCCESS; } DECLARE_HOST_COMMAND(EC_CMD_HOST_EVENT_GET_SMI_MASK, - host_event_get_smi_mask); + host_event_get_smi_mask, + EC_VER_MASK(0)); -static int host_event_get_sci_mask(uint8_t *data, int *resp_size) +static int host_event_get_sci_mask(struct host_cmd_handler_args *args) { struct ec_response_host_event_mask *r = - (struct ec_response_host_event_mask *)data; + (struct ec_response_host_event_mask *)args->response; r->mask = lpc_get_host_event_mask(LPC_HOST_EVENT_SCI); - *resp_size = sizeof(struct ec_response_host_event_mask); + args->response_size = sizeof(*r); + return EC_RES_SUCCESS; } DECLARE_HOST_COMMAND(EC_CMD_HOST_EVENT_GET_SCI_MASK, - host_event_get_sci_mask); + host_event_get_sci_mask, + EC_VER_MASK(0)); -static int host_event_get_wake_mask(uint8_t *data, int *resp_size) +static int host_event_get_wake_mask(struct host_cmd_handler_args *args) { struct ec_response_host_event_mask *r = - (struct ec_response_host_event_mask *)data; + (struct ec_response_host_event_mask *)args->response; r->mask = lpc_get_host_event_mask(LPC_HOST_EVENT_WAKE); - *resp_size = sizeof(struct ec_response_host_event_mask); + args->response_size = sizeof(*r); + return EC_RES_SUCCESS; } DECLARE_HOST_COMMAND(EC_CMD_HOST_EVENT_GET_WAKE_MASK, - host_event_get_wake_mask); + host_event_get_wake_mask, + EC_VER_MASK(0)); -static int host_event_set_smi_mask(uint8_t *data, int *resp_size) +static int host_event_set_smi_mask(struct host_cmd_handler_args *args) { const struct ec_params_host_event_mask *p = - (const struct ec_params_host_event_mask *)data; + (const struct ec_params_host_event_mask *)args->params; lpc_set_host_event_mask(LPC_HOST_EVENT_SMI, p->mask); return EC_RES_SUCCESS; } DECLARE_HOST_COMMAND(EC_CMD_HOST_EVENT_SET_SMI_MASK, - host_event_set_smi_mask); + host_event_set_smi_mask, + EC_VER_MASK(0)); -static int host_event_set_sci_mask(uint8_t *data, int *resp_size) +static int host_event_set_sci_mask(struct host_cmd_handler_args *args) { const struct ec_params_host_event_mask *p = - (const struct ec_params_host_event_mask *)data; + (const struct ec_params_host_event_mask *)args->params; lpc_set_host_event_mask(LPC_HOST_EVENT_SCI, p->mask); return EC_RES_SUCCESS; } DECLARE_HOST_COMMAND(EC_CMD_HOST_EVENT_SET_SCI_MASK, - host_event_set_sci_mask); + host_event_set_sci_mask, + EC_VER_MASK(0)); -static int host_event_set_wake_mask(uint8_t *data, int *resp_size) +static int host_event_set_wake_mask(struct host_cmd_handler_args *args) { const struct ec_params_host_event_mask *p = - (const struct ec_params_host_event_mask *)data; + (const struct ec_params_host_event_mask *)args->params; lpc_set_host_event_mask(LPC_HOST_EVENT_WAKE, p->mask); return EC_RES_SUCCESS; } DECLARE_HOST_COMMAND(EC_CMD_HOST_EVENT_SET_WAKE_MASK, - host_event_set_wake_mask); + host_event_set_wake_mask, + EC_VER_MASK(0)); #endif /* CONFIG_LPC */ -static int host_event_clear(uint8_t *data, int *resp_size) +static int host_event_clear(struct host_cmd_handler_args *args) { const struct ec_params_host_event_mask *p = - (const struct ec_params_host_event_mask *)data; + (const struct ec_params_host_event_mask *)args->params; host_clear_events(p->mask); return EC_RES_SUCCESS; } -DECLARE_HOST_COMMAND(EC_CMD_HOST_EVENT_CLEAR, host_event_clear); +DECLARE_HOST_COMMAND(EC_CMD_HOST_EVENT_CLEAR, + host_event_clear, + EC_VER_MASK(0)); diff --git a/common/keyboard.c b/common/keyboard.c index 083b209e98..ccd0da63b1 100644 --- a/common/keyboard.c +++ b/common/keyboard.c @@ -893,10 +893,10 @@ DECLARE_CONSOLE_COMMAND(kbd, command_keyboard, /*****************************************************************************/ /* Host commands */ -static int mkbp_command_simulate_key(uint8_t *data, int *resp_size) +static int mkbp_command_simulate_key(struct host_cmd_handler_args *args) { - struct ec_params_mkbp_simulate_key *p = - (struct ec_params_mkbp_simulate_key *)data; + const struct ec_params_mkbp_simulate_key *p = + (const struct ec_params_mkbp_simulate_key *)args->params; /* Only available on unlocked systems */ if (system_is_locked()) @@ -911,7 +911,9 @@ static int mkbp_command_simulate_key(uint8_t *data, int *resp_size) keyboard_state_changed(p->row, p->col, p->pressed); return EC_RES_SUCCESS; } -DECLARE_HOST_COMMAND(EC_CMD_MKBP_SIMULATE_KEY, mkbp_command_simulate_key); +DECLARE_HOST_COMMAND(EC_CMD_MKBP_SIMULATE_KEY, + mkbp_command_simulate_key, + EC_VER_MASK(0)); /*****************************************************************************/ /* Hooks */ diff --git a/common/lightbar.c b/common/lightbar.c index 2e8434423f..bb7805c98d 100644 --- a/common/lightbar.c +++ b/common/lightbar.c @@ -5,7 +5,7 @@ * LED controls. */ -#include "board.h" +#include "common.h" #include "console.h" #include "gpio.h" #include "hooks.h" @@ -678,15 +678,24 @@ static void do_cmd_rgb(uint8_t led, /* Host commands via LPC bus */ /****************************************************************************/ -static int lpc_cmd_lightbar(uint8_t *data, int *resp_size) +static int lpc_cmd_lightbar(struct host_cmd_handler_args *args) { struct ec_params_lightbar_cmd *ptr = - (struct ec_params_lightbar_cmd *)data; + (struct ec_params_lightbar_cmd *)args->response; + + /* + * TODO: (crosbug.com/p/11277) Now that params and response are + * separate pointers, they need to be propagated to the lightbar + * sub-commands. For now, just copy params to response so the + * sub-commands above will work unchanged. + */ + if (args->params != args->response) + memcpy(args->response, args->params, args->params_size); switch (ptr->in.cmd) { case LIGHTBAR_CMD_DUMP: do_cmd_dump(ptr); - *resp_size = sizeof(struct ec_params_lightbar_cmd); + args->response_size = sizeof(struct ec_params_lightbar_cmd); break; case LIGHTBAR_CMD_OFF: lightbar_off(); @@ -716,7 +725,7 @@ static int lpc_cmd_lightbar(uint8_t *data, int *resp_size) break; case LIGHTBAR_CMD_GET_SEQ: ptr->out.get_seq.num = current_state; - *resp_size = sizeof(struct ec_params_lightbar_cmd); + args->response_size = sizeof(struct ec_params_lightbar_cmd); break; default: CPRINTF("[%T LB bad cmd 0x%x]\n", ptr->in.cmd); @@ -726,7 +735,10 @@ static int lpc_cmd_lightbar(uint8_t *data, int *resp_size) return EC_RES_SUCCESS; } -DECLARE_HOST_COMMAND(EC_CMD_LIGHTBAR_CMD, lpc_cmd_lightbar); +DECLARE_HOST_COMMAND(EC_CMD_LIGHTBAR_CMD, + lpc_cmd_lightbar, + EC_VER_MASK(0)); + /****************************************************************************/ diff --git a/common/pstore_commands.c b/common/pstore_commands.c index fdd0eaf26c..9717d3ccdb 100644 --- a/common/pstore_commands.c +++ b/common/pstore_commands.c @@ -5,42 +5,40 @@ /* Persistent storage commands for Chrome EC */ -#include "board.h" +#include "common.h" #include "eeprom.h" #include "host_command.h" #include "util.h" - -int pstore_command_get_info(uint8_t *data, int *resp_size) +int pstore_command_get_info(struct host_cmd_handler_args *args) { struct ec_response_pstore_info *r = - (struct ec_response_pstore_info *)data; + (struct ec_response_pstore_info *)args->response; ASSERT(EEPROM_BLOCK_START_PSTORE + EEPROM_BLOCK_COUNT_PSTORE <= eeprom_get_block_count()); r->pstore_size = EEPROM_BLOCK_COUNT_PSTORE * eeprom_get_block_size(); r->access_size = sizeof(uint32_t); - *resp_size = sizeof(struct ec_response_pstore_info); + args->response_size = sizeof(*r); return EC_RES_SUCCESS; } -DECLARE_HOST_COMMAND(EC_CMD_PSTORE_INFO, pstore_command_get_info); - +DECLARE_HOST_COMMAND(EC_CMD_PSTORE_INFO, + pstore_command_get_info, + EC_VER_MASK(0)); -int pstore_command_read(uint8_t *data, int *resp_size) +int pstore_command_read(struct host_cmd_handler_args *args) { - struct ec_params_pstore_read *p = - (struct ec_params_pstore_read *)data; - struct ec_response_pstore_read *r = - (struct ec_response_pstore_read *)data; - char *dest = r->data; + const struct ec_params_pstore_read *p = + (const struct ec_params_pstore_read *)args->params; + char *dest = args->response; int block_size = eeprom_get_block_size(); int block = p->offset / block_size + EEPROM_BLOCK_COUNT_PSTORE; int offset = p->offset % block_size; int bytes_left = p->size; - if (p->size > sizeof(r->data)) - return EC_RES_ERROR; + if (p->size > sizeof(EC_PARAM_SIZE)) + return EC_RES_INVALID_PARAM; while (bytes_left) { /* Read what we can from the current block */ @@ -60,16 +58,17 @@ int pstore_command_read(uint8_t *data, int *resp_size) dest += bytes_this; } - *resp_size = sizeof(struct ec_response_pstore_read); + args->response_size = p->size; return EC_RES_SUCCESS; } -DECLARE_HOST_COMMAND(EC_CMD_PSTORE_READ, pstore_command_read); - +DECLARE_HOST_COMMAND(EC_CMD_PSTORE_READ, + pstore_command_read, + EC_VER_MASK(0)); -int pstore_command_write(uint8_t *data, int *resp_size) +int pstore_command_write(struct host_cmd_handler_args *args) { - struct ec_params_pstore_write *p = - (struct ec_params_pstore_write *)data; + const struct ec_params_pstore_write *p = + (const struct ec_params_pstore_write *)args->params; const char *src = p->data; int block_size = eeprom_get_block_size(); @@ -100,4 +99,6 @@ int pstore_command_write(uint8_t *data, int *resp_size) return EC_RES_SUCCESS; } -DECLARE_HOST_COMMAND(EC_CMD_PSTORE_WRITE, pstore_command_write); +DECLARE_HOST_COMMAND(EC_CMD_PSTORE_WRITE, + pstore_command_write, + EC_VER_MASK(0)); diff --git a/common/pwm_commands.c b/common/pwm_commands.c index 12de09b3d0..0493bb9b5e 100644 --- a/common/pwm_commands.c +++ b/common/pwm_commands.c @@ -10,64 +10,73 @@ #include "thermal.h" -int pwm_command_get_fan_rpm(uint8_t *data, int *resp_size) +int pwm_command_get_fan_target_rpm(struct host_cmd_handler_args *args) { struct ec_response_pwm_get_fan_rpm *r = - (struct ec_response_pwm_get_fan_rpm *)data; + (struct ec_response_pwm_get_fan_rpm *)args->response; r->rpm = pwm_get_fan_target_rpm(); - *resp_size = sizeof(struct ec_response_pwm_get_fan_rpm); + args->response_size = sizeof(*r); + return EC_RES_SUCCESS; } -DECLARE_HOST_COMMAND(EC_CMD_PWM_GET_FAN_RPM, pwm_command_get_fan_rpm); - +DECLARE_HOST_COMMAND(EC_CMD_PWM_GET_FAN_TARGET_RPM, + pwm_command_get_fan_target_rpm, + EC_VER_MASK(0)); -int pwm_command_set_fan_target_rpm(uint8_t *data, int *resp_size) +int pwm_command_set_fan_target_rpm(struct host_cmd_handler_args *args) { - struct ec_params_pwm_set_fan_target_rpm *p = - (struct ec_params_pwm_set_fan_target_rpm *)data; + const struct ec_params_pwm_set_fan_target_rpm *p = + (const struct ec_params_pwm_set_fan_target_rpm *)args->params; #ifdef CONFIG_TASK_THERMAL thermal_toggle_auto_fan_ctrl(0); #endif pwm_set_fan_target_rpm(p->rpm); + return EC_RES_SUCCESS; } DECLARE_HOST_COMMAND(EC_CMD_PWM_SET_FAN_TARGET_RPM, - pwm_command_set_fan_target_rpm); + pwm_command_set_fan_target_rpm, + EC_VER_MASK(0)); - -int pwm_command_fan_duty(uint8_t *data, int *resp_size) +int pwm_command_fan_duty(struct host_cmd_handler_args *args) { - struct ec_params_pwm_set_fan_duty *p = - (struct ec_params_pwm_set_fan_duty *)data; + const struct ec_params_pwm_set_fan_duty *p = + (const struct ec_params_pwm_set_fan_duty *)args->params; pwm_set_fan_duty(p->percent); + return EC_RES_SUCCESS; } -DECLARE_HOST_COMMAND(EC_CMD_PWM_SET_FAN_DUTY, pwm_command_fan_duty); +DECLARE_HOST_COMMAND(EC_CMD_PWM_SET_FAN_DUTY, + pwm_command_fan_duty, + EC_VER_MASK(0)); - -int pwm_command_get_keyboard_backlight(uint8_t *data, int *resp_size) +int pwm_command_get_keyboard_backlight(struct host_cmd_handler_args *args) { struct ec_response_pwm_get_keyboard_backlight *r = - (struct ec_response_pwm_get_keyboard_backlight *)data; + (struct ec_response_pwm_get_keyboard_backlight *)args->response; r->percent = pwm_get_keyboard_backlight(); r->enabled = pwm_get_keyboard_backlight_enabled(); - *resp_size = sizeof(struct ec_response_pwm_get_keyboard_backlight); + args->response_size = sizeof(*r); + return EC_RES_SUCCESS; } DECLARE_HOST_COMMAND(EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT, - pwm_command_get_keyboard_backlight); + pwm_command_get_keyboard_backlight, + EC_VER_MASK(0)); - -int pwm_command_set_keyboard_backlight(uint8_t *data, int *resp_size) +int pwm_command_set_keyboard_backlight(struct host_cmd_handler_args *args) { - struct ec_params_pwm_set_keyboard_backlight *p = - (struct ec_params_pwm_set_keyboard_backlight *)data; + const struct ec_params_pwm_set_keyboard_backlight *p = + (const struct ec_params_pwm_set_keyboard_backlight *) + args->params; pwm_set_keyboard_backlight(p->percent); + return EC_RES_SUCCESS; } DECLARE_HOST_COMMAND(EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT, - pwm_command_set_keyboard_backlight); + pwm_command_set_keyboard_backlight, + EC_VER_MASK(0)); diff --git a/common/system_common.c b/common/system_common.c index 10c7c42088..46fa33794f 100644 --- a/common/system_common.c +++ b/common/system_common.c @@ -684,10 +684,10 @@ DECLARE_CONSOLE_COMMAND(syslock, command_system_lock, /*****************************************************************************/ /* Host commands */ -static int host_command_get_version(uint8_t *data, int *resp_size) +static int host_command_get_version(struct host_cmd_handler_args *args) { struct ec_response_get_version *r = - (struct ec_response_get_version *)data; + (struct ec_response_get_version *)args->response; strzcpy(r->version_string_ro, system_get_version(SYSTEM_IMAGE_RO), sizeof(r->version_string_ro)); @@ -711,55 +711,60 @@ static int host_command_get_version(uint8_t *data, int *resp_size) break; } - *resp_size = sizeof(struct ec_response_get_version); + args->response_size = sizeof(*r); + return EC_RES_SUCCESS; } -DECLARE_HOST_COMMAND(EC_CMD_GET_VERSION, host_command_get_version); - +DECLARE_HOST_COMMAND(EC_CMD_GET_VERSION, + host_command_get_version, + EC_VER_MASK(0)); -static int host_command_build_info(uint8_t *data, int *resp_size) +static int host_command_build_info(struct host_cmd_handler_args *args) { - struct ec_response_get_build_info *r = - (struct ec_response_get_build_info *)data; + const char *info = system_get_build_info(); - strzcpy(r->build_string, system_get_build_info(), - sizeof(r->build_string)); + args->response = (uint8_t *)info; + args->response_size = strlen(info) + 1; - *resp_size = sizeof(struct ec_response_get_build_info); return EC_RES_SUCCESS; } -DECLARE_HOST_COMMAND(EC_CMD_GET_BUILD_INFO, host_command_build_info); +DECLARE_HOST_COMMAND(EC_CMD_GET_BUILD_INFO, + host_command_build_info, + EC_VER_MASK(0)); - -static int host_command_get_chip_info(uint8_t *data, int *resp_size) +static int host_command_get_chip_info(struct host_cmd_handler_args *args) { struct ec_response_get_chip_info *r = - (struct ec_response_get_chip_info *)data; + (struct ec_response_get_chip_info *)args->response; strzcpy(r->vendor, system_get_chip_vendor(), sizeof(r->vendor)); strzcpy(r->name, system_get_chip_name(), sizeof(r->name)); strzcpy(r->revision, system_get_chip_revision(), sizeof(r->revision)); - *resp_size = sizeof(struct ec_response_get_chip_info); + args->response_size = sizeof(*r); + return EC_RES_SUCCESS; } -DECLARE_HOST_COMMAND(EC_CMD_GET_CHIP_INFO, host_command_get_chip_info); +DECLARE_HOST_COMMAND(EC_CMD_GET_CHIP_INFO, + host_command_get_chip_info, + EC_VER_MASK(0)); - -int host_command_get_board_version(uint8_t *data, int *resp_size) +int host_command_get_board_version(struct host_cmd_handler_args *args) { - struct ec_params_board_version *board_v = - (struct ec_params_board_version *) data; + struct ec_response_board_version *r = + (struct ec_response_board_version *)args->response; + + r->board_version = (uint16_t) system_get_board_version(); - board_v->board_version = (uint16_t) system_get_board_version(); + args->response_size = sizeof(*r); - *resp_size = sizeof(struct ec_params_board_version); return EC_RES_SUCCESS; } -DECLARE_HOST_COMMAND(EC_CMD_GET_BOARD_VERSION, host_command_get_board_version); - +DECLARE_HOST_COMMAND(EC_CMD_GET_BOARD_VERSION, + host_command_get_board_version, + EC_VER_MASK(0)); -int host_command_reboot(uint8_t *data, int *resp_size) +int host_command_reboot(struct host_cmd_handler_args *args) { struct ec_params_reboot_ec p; @@ -767,7 +772,7 @@ int host_command_reboot(uint8_t *data, int *resp_size) * Ensure reboot parameters don't get clobbered when the response * is sent in case data argument points to the host tx/rx buffer. */ - memcpy(&p, data, sizeof(p)); + memcpy(&p, args->params, sizeof(p)); if (p.cmd == EC_REBOOT_CANCEL) { /* Cancel pending reboot */ @@ -798,4 +803,6 @@ int host_command_reboot(uint8_t *data, int *resp_size) return EC_RES_ERROR; } } -DECLARE_HOST_COMMAND(EC_CMD_REBOOT_EC, host_command_reboot); +DECLARE_HOST_COMMAND(EC_CMD_REBOOT_EC, + host_command_reboot, + EC_VER_MASK(0)); diff --git a/common/temp_sensor_commands.c b/common/temp_sensor_commands.c index bf303f2cb7..43b92385c7 100644 --- a/common/temp_sensor_commands.c +++ b/common/temp_sensor_commands.c @@ -5,23 +5,23 @@ /* Temp sensor host commands for Chrome EC */ +#include "common.h" #include "host_command.h" #include "temp_sensor.h" #include "util.h" - -/* Defined in board_temp_sensor.c. Must be in the same order as - * in enum temp_sensor_id. +/* + * Defined in board_temp_sensor.c. Must be in the same order as in enum + * temp_sensor_id. */ extern const struct temp_sensor_t temp_sensors[TEMP_SENSOR_COUNT]; - -int temp_sensor_command_get_info(uint8_t *data, int *resp_size) +int temp_sensor_command_get_info(struct host_cmd_handler_args *args) { - struct ec_params_temp_sensor_get_info *p = - (struct ec_params_temp_sensor_get_info *)data; + const struct ec_params_temp_sensor_get_info *p = + (const struct ec_params_temp_sensor_get_info *)args->params; struct ec_response_temp_sensor_get_info *r = - (struct ec_response_temp_sensor_get_info *)data; + (struct ec_response_temp_sensor_get_info *)args->response; int id = p->id; if (id >= TEMP_SENSOR_COUNT) @@ -30,8 +30,10 @@ int temp_sensor_command_get_info(uint8_t *data, int *resp_size) strzcpy(r->sensor_name, temp_sensors[id].name, sizeof(r->sensor_name)); r->sensor_type = temp_sensors[id].type; - *resp_size = sizeof(struct ec_response_temp_sensor_get_info); + args->response_size = sizeof(*r); + return EC_RES_SUCCESS; } DECLARE_HOST_COMMAND(EC_CMD_TEMP_SENSOR_GET_INFO, - temp_sensor_command_get_info); + temp_sensor_command_get_info, + EC_VER_MASK(0)); diff --git a/common/thermal_commands.c b/common/thermal_commands.c index f4bb8d6497..5e6e024f89 100644 --- a/common/thermal_commands.c +++ b/common/thermal_commands.c @@ -5,47 +5,51 @@ /* Thermal engine host commands for Chrome EC */ +#include "common.h" #include "host_command.h" #include "thermal.h" - -int thermal_command_set_threshold(uint8_t *data, int *resp_size) +int thermal_command_set_threshold(struct host_cmd_handler_args *args) { - struct ec_params_thermal_set_threshold *p = - (struct ec_params_thermal_set_threshold *)data; + const struct ec_params_thermal_set_threshold *p = + (const struct ec_params_thermal_set_threshold *)args->params; if (thermal_set_threshold(p->sensor_type, p->threshold_id, p->value)) return EC_RES_ERROR; + return EC_RES_SUCCESS; } DECLARE_HOST_COMMAND(EC_CMD_THERMAL_SET_THRESHOLD, - thermal_command_set_threshold); - + thermal_command_set_threshold, + EC_VER_MASK(0)); -int thermal_command_get_threshold(uint8_t *data, int *resp_size) +int thermal_command_get_threshold(struct host_cmd_handler_args *args) { - struct ec_params_thermal_get_threshold *p = - (struct ec_params_thermal_get_threshold *)data; + const struct ec_params_thermal_get_threshold *p = + (const struct ec_params_thermal_get_threshold *)args->params; struct ec_response_thermal_get_threshold *r = - (struct ec_response_thermal_get_threshold *)data; + (struct ec_response_thermal_get_threshold *)args->response; int value = thermal_get_threshold(p->sensor_type, p->threshold_id); if (value == -1) return EC_RES_ERROR; r->value = value; - *resp_size = sizeof(struct ec_response_thermal_get_threshold); + args->response_size = sizeof(*r); + return EC_RES_SUCCESS; } DECLARE_HOST_COMMAND(EC_CMD_THERMAL_GET_THRESHOLD, - thermal_command_get_threshold); - + thermal_command_get_threshold, + EC_VER_MASK(0)); -int thermal_command_auto_fan_ctrl(uint8_t *data, int *resp_size) +int thermal_command_auto_fan_ctrl(struct host_cmd_handler_args *args) { if (thermal_toggle_auto_fan_ctrl(1)) return EC_RES_ERROR; return EC_RES_SUCCESS; } DECLARE_HOST_COMMAND(EC_CMD_THERMAL_AUTO_FAN_CTRL, - thermal_command_auto_fan_ctrl); + thermal_command_auto_fan_ctrl, + EC_VER_MASK(0)); + diff --git a/common/usb_charge_commands.c b/common/usb_charge_commands.c index 4e69208622..7be591f2d2 100644 --- a/common/usb_charge_commands.c +++ b/common/usb_charge_commands.c @@ -5,24 +5,25 @@ /* USB charging control commands for Chrome EC */ +#include "common.h" #include "console.h" -#include "usb_charge.h" #include "host_command.h" +#include "usb_charge.h" #include "util.h" /* Console output macros */ #define CPUTS(outstr) cputs(CC_USBCHARGE, outstr) #define CPRINTF(format, args...) cprintf(CC_USBCHARGE, format, ## args) - -int usb_charge_command_set_mode(uint8_t *data, int *resp_size) +static int usb_charge_command_set_mode(struct host_cmd_handler_args *args) { - struct ec_params_usb_charge_set_mode *p = - (struct ec_params_usb_charge_set_mode *)data; + const struct ec_params_usb_charge_set_mode *p = + (const struct ec_params_usb_charge_set_mode *)args->params; int rv; CPRINTF("[Setting USB port %d to mode %d]\n", p->usb_port_id, p->mode); + rv = usb_charge_set_mode(p->usb_port_id, p->mode); if (rv != EC_SUCCESS) @@ -31,4 +32,5 @@ int usb_charge_command_set_mode(uint8_t *data, int *resp_size) return EC_RES_SUCCESS; } DECLARE_HOST_COMMAND(EC_CMD_USB_CHARGE_SET_MODE, - usb_charge_command_set_mode); + usb_charge_command_set_mode, + EC_VER_MASK(0)); diff --git a/common/vboot.c b/common/vboot.c index 97ae09bede..e4b9ee0aed 100644 --- a/common/vboot.c +++ b/common/vboot.c @@ -5,10 +5,8 @@ /* Verified boot module for Chrome EC */ -#include "board.h" -#include "config.h" +#include "common.h" #include "console.h" -#include "eoption.h" #include "host_command.h" #include "system.h" #include "vboot.h" @@ -26,27 +24,31 @@ int vboot_pre_init(void) /****************************************************************************/ /* Host commands */ -static int host_cmd_vboot(uint8_t *data, int *resp_size) +static int host_cmd_vboot(struct host_cmd_handler_args *args) { - struct ec_params_vboot_cmd *ptr = - (struct ec_params_vboot_cmd *)data; + const struct ec_params_vboot_cmd *p = + (const struct ec_params_vboot_cmd *)args->params; + struct ec_params_vboot_cmd *r = + (struct ec_params_vboot_cmd *)args->response; uint8_t v; - switch (ptr->in.cmd) { + switch (p->in.cmd) { case VBOOT_CMD_GET_FLAGS: v = VBOOT_FLAGS_IMAGE_MASK & system_get_image_copy(); - ptr->out.get_flags.val = v; - *resp_size = sizeof(struct ec_params_vboot_cmd); + r->out.get_flags.val = v; + args->response_size = sizeof(r); break; case VBOOT_CMD_SET_FLAGS: - v = ptr->in.set_flags.val; + v = p->in.set_flags.val; break; default: - CPRINTF("[%T LB bad cmd 0x%x]\n", ptr->in.cmd); + CPRINTF("[%T LB bad cmd 0x%x]\n", p->in.cmd); return EC_RES_INVALID_PARAM; } return EC_RES_SUCCESS; } -DECLARE_HOST_COMMAND(EC_CMD_VBOOT_CMD, host_cmd_vboot); +DECLARE_HOST_COMMAND(EC_CMD_VBOOT_CMD, + host_cmd_vboot, + EC_VER_MASK(0)); diff --git a/common/vboot_hash.c b/common/vboot_hash.c index fc801a2e98..47b860111c 100644 --- a/common/vboot_hash.c +++ b/common/vboot_hash.c @@ -5,7 +5,7 @@ /* Verified boot hash computing module for Chrome EC */ -#include "config.h" +#include "common.h" #include "console.h" #include "cryptolib.h" #include "hooks.h" @@ -243,18 +243,18 @@ static void fill_response(struct ec_response_vboot_hash *r) r->status = EC_VBOOT_HASH_STATUS_NONE; } - -static int host_command_vboot_hash(uint8_t *data, int *resp_size) +static int host_command_vboot_hash(struct host_cmd_handler_args *args) { - struct ec_params_vboot_hash *p = (struct ec_params_vboot_hash *)data; + const struct ec_params_vboot_hash *p = + (const struct ec_params_vboot_hash *)args->params; struct ec_response_vboot_hash *r = - (struct ec_response_vboot_hash *)data; + (struct ec_response_vboot_hash *)args->response; int rv; switch (p->cmd) { case EC_VBOOT_HASH_GET: fill_response(r); - *resp_size = sizeof(struct ec_response_vboot_hash); + args->response_size = sizeof(*r); return EC_RES_SUCCESS; case EC_VBOOT_HASH_ABORT: @@ -295,11 +295,13 @@ static int host_command_vboot_hash(uint8_t *data, int *resp_size) usleep(1000); fill_response(r); - *resp_size = sizeof(struct ec_response_vboot_hash); + args->response_size = sizeof(*r); return EC_RES_SUCCESS; default: return EC_RES_INVALID_PARAM; } } -DECLARE_HOST_COMMAND(EC_CMD_VBOOT_HASH, host_command_vboot_hash); +DECLARE_HOST_COMMAND(EC_CMD_VBOOT_HASH, + host_command_vboot_hash, + EC_VER_MASK(0)); diff --git a/common/x86_power.c b/common/x86_power.c index 6aa98002f8..7136795529 100644 --- a/common/x86_power.c +++ b/common/x86_power.c @@ -674,15 +674,18 @@ DECLARE_CONSOLE_COMMAND(x86shutdown, command_x86shutdown, /*****************************************************************************/ /* Host commands */ -int switch_command_enable_wireless(uint8_t *data, int *resp_size) +static int switch_command_enable_wireless(struct host_cmd_handler_args *args) { - struct ec_params_switch_enable_wireless *p = - (struct ec_params_switch_enable_wireless *)data; + const struct ec_params_switch_enable_wireless *p = + (const struct ec_params_switch_enable_wireless *)args->params; + gpio_set_level(GPIO_RADIO_ENABLE_WLAN, p->enabled & EC_WIRELESS_SWITCH_WLAN); gpio_set_level(GPIO_RADIO_ENABLE_BT, p->enabled & EC_WIRELESS_SWITCH_BLUETOOTH); + return EC_RES_SUCCESS; } DECLARE_HOST_COMMAND(EC_CMD_SWITCH_ENABLE_WIRELESS, - switch_command_enable_wireless); + switch_command_enable_wireless, + EC_VER_MASK(0)); |