diff options
author | Gerrit <chrome-bot@google.com> | 2012-05-14 17:27:49 -0700 |
---|---|---|
committer | Gerrit Code Review <gerrit@gerrit.golo.chromium.org> | 2012-05-14 17:27:49 -0700 |
commit | dc703b5ae48442f094dd8f3122e4507a8b043970 (patch) | |
tree | 0ad29d5aef38484722fce0afedb89cef00c847a3 | |
parent | e00c460c933da8926905762735d9fef70d058609 (diff) | |
parent | 87d3707f62c14376f9c5013e455544bf32d0fb33 (diff) | |
download | chrome-ec-dc703b5ae48442f094dd8f3122e4507a8b043970.tar.gz |
Merge "Slightly update the host commands API"
-rw-r--r-- | chip/lm4/lpc.c | 13 | ||||
-rw-r--r-- | common/flash_commands.c | 23 | ||||
-rw-r--r-- | common/host_command.c | 42 | ||||
-rw-r--r-- | common/host_event_commands.c | 17 | ||||
-rw-r--r-- | common/lightbar.c | 4 | ||||
-rw-r--r-- | common/pstore_commands.c | 8 | ||||
-rw-r--r-- | common/pwm_commands.c | 10 | ||||
-rw-r--r-- | common/system_common.c | 15 | ||||
-rw-r--r-- | common/thermal_commands.c | 7 | ||||
-rw-r--r-- | common/usb_charge_commands.c | 2 | ||||
-rw-r--r-- | include/host_command.h | 27 | ||||
-rw-r--r-- | include/lpc.h | 10 | ||||
-rw-r--r-- | include/lpc_commands.h | 25 |
13 files changed, 144 insertions, 59 deletions
diff --git a/chip/lm4/lpc.c b/chip/lm4/lpc.c index 64cdfb2d50..9587c6b8fa 100644 --- a/chip/lm4/lpc.c +++ b/chip/lm4/lpc.c @@ -114,7 +114,7 @@ static void lpc_generate_sci(void) } -uint8_t *lpc_get_host_range(int slot) +uint8_t *host_get_buffer(int slot) { return (uint8_t *)LPC_POOL_CMD_DATA + EC_LPC_PARAM_SIZE * slot; } @@ -126,7 +126,7 @@ uint8_t *lpc_get_memmap_range(void) } -void lpc_send_host_response(int slot, int result) +void host_send_result(int slot, int result) { int ch = slot ? LPC_CH_USER : LPC_CH_KERNEL; @@ -151,6 +151,15 @@ void lpc_send_host_response(int slot, int result) lpc_generate_sci(); } +void host_send_response(int slot, const uint8_t *data, int size) +{ + uint8_t *out = host_get_buffer(slot); + + if (data != out) + memcpy(out, data, size); + + host_send_result(slot, EC_LPC_RESULT_SUCCESS); +} /* Return true if the TOH is still set */ int lpc_keyboard_has_char(void) { diff --git a/common/flash_commands.c b/common/flash_commands.c index 715746d787..cd4497301c 100644 --- a/common/flash_commands.c +++ b/common/flash_commands.c @@ -199,7 +199,7 @@ DECLARE_CONSOLE_COMMAND(flashwp, command_flash_wp); /*****************************************************************************/ /* Host commands */ -enum lpc_status flash_command_get_info(uint8_t *data) +int flash_command_get_info(uint8_t *data, int *resp_size) { struct lpc_response_flash_info *r = (struct lpc_response_flash_info *)data; @@ -208,13 +208,14 @@ enum lpc_status flash_command_get_info(uint8_t *data) 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 lpc_response_flash_info); return EC_LPC_RESULT_SUCCESS; } DECLARE_HOST_COMMAND(EC_LPC_COMMAND_FLASH_INFO, flash_command_get_info); #ifdef SUPPORT_CHECKSUM -enum lpc_status flash_command_checksum(uint8_t *data) +int flash_command_checksum(uint8_t *data, int *resp_size) { struct lpc_params_flash_checksum *p = (struct lpc_params_flash_checksum *)data; @@ -231,13 +232,14 @@ enum lpc_status flash_command_checksum(uint8_t *data) r->checksum = cs; + *resp_size = sizeof(struct lpc_response_flash_checksum); return EC_LPC_RESULT_SUCCESS; } DECLARE_HOST_COMMAND(EC_LPC_COMMAND_FLASH_CHECKSUM, flash_command_checksum); #endif -enum lpc_status flash_command_read(uint8_t *data) +int flash_command_read(uint8_t *data, int *resp_size) { struct lpc_params_flash_read *p = (struct lpc_params_flash_read *)data; @@ -250,12 +252,13 @@ enum lpc_status flash_command_read(uint8_t *data) if (flash_read(p->offset, p->size, r->data)) return EC_LPC_RESULT_ERROR; + *resp_size = sizeof(struct lpc_response_flash_read); return EC_LPC_RESULT_SUCCESS; } DECLARE_HOST_COMMAND(EC_LPC_COMMAND_FLASH_READ, flash_command_read); -enum lpc_status flash_command_write(uint8_t *data) +int flash_command_write(uint8_t *data, int *resp_size) { struct lpc_params_flash_write *p = (struct lpc_params_flash_write *)data; @@ -274,7 +277,7 @@ enum lpc_status flash_command_write(uint8_t *data) DECLARE_HOST_COMMAND(EC_LPC_COMMAND_FLASH_WRITE, flash_command_write); -enum lpc_status flash_command_erase(uint8_t *data) +int flash_command_erase(uint8_t *data, int *resp_size) { struct lpc_params_flash_erase *p = (struct lpc_params_flash_erase *)data; @@ -290,7 +293,7 @@ enum lpc_status flash_command_erase(uint8_t *data) DECLARE_HOST_COMMAND(EC_LPC_COMMAND_FLASH_ERASE, flash_command_erase); -enum lpc_status flash_command_wp_enable(uint8_t *data) +int flash_command_wp_enable(uint8_t *data, int *resp_size) { struct lpc_params_flash_wp_enable *p = (struct lpc_params_flash_wp_enable *)data; @@ -301,7 +304,7 @@ DECLARE_HOST_COMMAND(EC_LPC_COMMAND_FLASH_WP_ENABLE, flash_command_wp_enable); -enum lpc_status flash_command_wp_get_state(uint8_t *data) +int flash_command_wp_get_state(uint8_t *data, int *resp_size) { struct lpc_response_flash_wp_enable *p = (struct lpc_response_flash_wp_enable *)data; @@ -311,13 +314,14 @@ enum lpc_status flash_command_wp_get_state(uint8_t *data) else p->enable_wp = 0; + *resp_size = sizeof(struct lpc_response_flash_wp_enable); return EC_LPC_RESULT_SUCCESS; } DECLARE_HOST_COMMAND(EC_LPC_COMMAND_FLASH_WP_GET_STATE, flash_command_wp_get_state); -enum lpc_status flash_command_wp_set_range(uint8_t *data) +int flash_command_wp_set_range(uint8_t *data, int *resp_size) { struct lpc_params_flash_wp_range *p = (struct lpc_params_flash_wp_range *)data; @@ -334,7 +338,7 @@ DECLARE_HOST_COMMAND(EC_LPC_COMMAND_FLASH_WP_SET_RANGE, flash_command_wp_set_range); -enum lpc_status flash_command_wp_get_range(uint8_t *data) +int flash_command_wp_get_range(uint8_t *data, int *resp_size) { struct lpc_response_flash_wp_range *p = (struct lpc_response_flash_wp_range *)data; @@ -371,6 +375,7 @@ enum lpc_status flash_command_wp_get_range(uint8_t *data) p->size = (max - min + 1) * pbsize; } + *resp_size = sizeof(struct lpc_response_flash_wp_range); return EC_LPC_RESULT_SUCCESS; } DECLARE_HOST_COMMAND(EC_LPC_COMMAND_FLASH_WP_GET_RANGE, diff --git a/common/host_command.c b/common/host_command.c index 8428edc497..5b202c8248 100644 --- a/common/host_command.c +++ b/common/host_command.c @@ -34,7 +34,7 @@ void host_command_received(int slot, int command) if (command == EC_LPC_COMMAND_REBOOT) { system_reset(1); /* Reset should never return; if it does, post an error */ - lpc_send_host_response(slot, EC_LPC_RESULT_ERROR); + host_send_result(slot, EC_LPC_RESULT_ERROR); return; } @@ -45,8 +45,20 @@ void host_command_received(int slot, int command) task_set_event(TASK_ID_HOSTCMD, TASK_EVENT_SLOT(slot), 0); } +static int host_command_proto_version(uint8_t *data, int *resp_size) +{ + struct lpc_response_proto_version *r = + (struct lpc_response_proto_version *)data; + + r->version = EC_LPC_PROTO_VERSION; + + *resp_size = sizeof(struct lpc_response_proto_version); + return EC_LPC_RESULT_SUCCESS; +} +DECLARE_HOST_COMMAND(EC_LPC_COMMAND_PROTO_VERSION, + host_command_proto_version); -static enum lpc_status host_command_hello(uint8_t *data) +static int host_command_hello(uint8_t *data, int *resp_size) { struct lpc_params_hello *p = (struct lpc_params_hello *)data; struct lpc_response_hello *r = (struct lpc_response_hello *)data; @@ -66,12 +78,13 @@ static enum lpc_status host_command_hello(uint8_t *data) CPUTS("[LPC sending hello back]\n"); r->out_data = d + 0x01020304; + *resp_size = sizeof(struct lpc_response_hello); return EC_LPC_RESULT_SUCCESS; } DECLARE_HOST_COMMAND(EC_LPC_COMMAND_HELLO, host_command_hello); -static enum lpc_status host_command_read_test(uint8_t *data) +static int host_command_read_test(uint8_t *data, int *resp_size) { struct lpc_params_read_test *p = (struct lpc_params_read_test *)data; struct lpc_response_read_test *r = @@ -87,6 +100,7 @@ static enum lpc_status host_command_read_test(uint8_t *data) for (i = 0; i < size; i++) r->data[i] = offset + i; + *resp_size = sizeof(struct lpc_response_read_test); return EC_LPC_RESULT_SUCCESS; } DECLARE_HOST_COMMAND(EC_LPC_COMMAND_READ_TEST, host_command_read_test); @@ -95,7 +109,7 @@ DECLARE_HOST_COMMAND(EC_LPC_COMMAND_READ_TEST, host_command_read_test); /* ACPI query event handler. Note that the returned value is NOT actually * an EC_LPC_RESULT enum; it's 0 if no event was pending, or the 1-based * index of the lowest bit which was set. */ -static enum lpc_status host_command_acpi_query_event(uint8_t *data) +static int host_command_acpi_query_event(uint8_t *data, int *resp_size) { uint32_t events = lpc_get_host_events(); int i; @@ -103,12 +117,12 @@ static enum lpc_status host_command_acpi_query_event(uint8_t *data) for (i = 0; i < 32; i++) { if (events & (1 << i)) { lpc_clear_host_events(1 << i); - return (enum lpc_status)(i + 1); + return i + 1; } } /* No events pending */ - return (enum lpc_status)0; + return 0; } DECLARE_HOST_COMMAND(EC_LPC_COMMAND_ACPI_QUERY_EVENT, host_command_acpi_query_event); @@ -133,15 +147,21 @@ static const struct host_command *find_host_command(int command) static void command_process(int slot) { int command = host_command[slot]; - uint8_t *data = lpc_get_host_range(slot); + uint8_t *data = host_get_buffer(slot); const struct host_command *cmd = find_host_command(command); CPRINTF("[hostcmd%d 0x%02x]\n", slot, command); - if (cmd) - lpc_send_host_response(slot, cmd->handler(data)); - else - lpc_send_host_response(slot, EC_LPC_RESULT_INVALID_COMMAND); + if (cmd) { + int size = 0; + int res = cmd->handler(data, &size); + if ((res == EC_LPC_RESULT_SUCCESS) && size) + host_send_response(slot, data, size); + else + host_send_result(slot, res); + } else { + host_send_result(slot, EC_LPC_RESULT_INVALID_COMMAND); + } } /*****************************************************************************/ diff --git a/common/host_event_commands.c b/common/host_event_commands.c index 3590966fd2..d009d5df65 100644 --- a/common/host_event_commands.c +++ b/common/host_event_commands.c @@ -60,43 +60,46 @@ DECLARE_CONSOLE_COMMAND(hostevent, command_host_event); /*****************************************************************************/ /* Host commands */ -static enum lpc_status host_event_get_smi_mask(uint8_t *data) +static int host_event_get_smi_mask(uint8_t *data, int *resp_size) { struct lpc_response_host_event_mask *r = (struct lpc_response_host_event_mask *)data; r->mask = lpc_get_host_event_mask(LPC_HOST_EVENT_SMI); + *resp_size = sizeof(struct lpc_response_host_event_mask); return EC_LPC_RESULT_SUCCESS; } DECLARE_HOST_COMMAND(EC_LPC_COMMAND_HOST_EVENT_GET_SMI_MASK, host_event_get_smi_mask); -static enum lpc_status host_event_get_sci_mask(uint8_t *data) +static int host_event_get_sci_mask(uint8_t *data, int *resp_size) { struct lpc_response_host_event_mask *r = (struct lpc_response_host_event_mask *)data; r->mask = lpc_get_host_event_mask(LPC_HOST_EVENT_SCI); + *resp_size = sizeof(struct lpc_response_host_event_mask); return EC_LPC_RESULT_SUCCESS; } DECLARE_HOST_COMMAND(EC_LPC_COMMAND_HOST_EVENT_GET_SCI_MASK, host_event_get_sci_mask); -static enum lpc_status host_event_get_wake_mask(uint8_t *data) +static int host_event_get_wake_mask(uint8_t *data, int *resp_size) { struct lpc_response_host_event_mask *r = (struct lpc_response_host_event_mask *)data; r->mask = lpc_get_host_event_mask(LPC_HOST_EVENT_WAKE); + *resp_size = sizeof(struct lpc_response_host_event_mask); return EC_LPC_RESULT_SUCCESS; } DECLARE_HOST_COMMAND(EC_LPC_COMMAND_HOST_EVENT_GET_WAKE_MASK, host_event_get_wake_mask); -static enum lpc_status host_event_set_smi_mask(uint8_t *data) +static int host_event_set_smi_mask(uint8_t *data, int *resp_size) { const struct lpc_params_host_event_mask *p = (const struct lpc_params_host_event_mask *)data; @@ -108,7 +111,7 @@ DECLARE_HOST_COMMAND(EC_LPC_COMMAND_HOST_EVENT_SET_SMI_MASK, host_event_set_smi_mask); -static enum lpc_status host_event_set_sci_mask(uint8_t *data) +static int host_event_set_sci_mask(uint8_t *data, int *resp_size) { const struct lpc_params_host_event_mask *p = (const struct lpc_params_host_event_mask *)data; @@ -120,7 +123,7 @@ DECLARE_HOST_COMMAND(EC_LPC_COMMAND_HOST_EVENT_SET_SCI_MASK, host_event_set_sci_mask); -static enum lpc_status host_event_set_wake_mask(uint8_t *data) +static int host_event_set_wake_mask(uint8_t *data, int *resp_size) { const struct lpc_params_host_event_mask *p = (const struct lpc_params_host_event_mask *)data; @@ -132,7 +135,7 @@ DECLARE_HOST_COMMAND(EC_LPC_COMMAND_HOST_EVENT_SET_WAKE_MASK, host_event_set_wake_mask); -static enum lpc_status host_event_clear(uint8_t *data) +static int host_event_clear(uint8_t *data, int *resp_size) { const struct lpc_params_host_event_mask *p = (const struct lpc_params_host_event_mask *)data; diff --git a/common/lightbar.c b/common/lightbar.c index 6154ddb7ea..d2b49c340b 100644 --- a/common/lightbar.c +++ b/common/lightbar.c @@ -718,7 +718,7 @@ static void do_cmd_rgb(uint8_t led, /* Host commands via LPC bus */ /****************************************************************************/ -static enum lpc_status lpc_cmd_lightbar(uint8_t *data) +static int lpc_cmd_lightbar(uint8_t *data, int *resp_size) { struct lpc_params_lightbar_cmd *ptr = (struct lpc_params_lightbar_cmd *)data; @@ -726,6 +726,7 @@ static enum lpc_status lpc_cmd_lightbar(uint8_t *data) switch (ptr->in.cmd) { case LIGHTBAR_CMD_DUMP: do_cmd_dump(ptr); + *resp_size = sizeof(struct lpc_params_lightbar_cmd); break; case LIGHTBAR_CMD_OFF: lightbar_off(); @@ -755,6 +756,7 @@ static enum lpc_status lpc_cmd_lightbar(uint8_t *data) break; case LIGHTBAR_CMD_GET_SEQ: ptr->out.get_seq.num = current_state; + *resp_size = sizeof(struct lpc_params_lightbar_cmd); break; default: CPRINTF("[invalid lightbar cmd 0x%x]\n", ptr->in.cmd); diff --git a/common/pstore_commands.c b/common/pstore_commands.c index afb9a16852..036f5d6b3b 100644 --- a/common/pstore_commands.c +++ b/common/pstore_commands.c @@ -11,7 +11,7 @@ #include "util.h" -enum lpc_status pstore_command_get_info(uint8_t *data) +int pstore_command_get_info(uint8_t *data, int *resp_size) { struct lpc_response_pstore_info *r = (struct lpc_response_pstore_info *)data; @@ -21,12 +21,13 @@ enum lpc_status pstore_command_get_info(uint8_t *data) r->pstore_size = EEPROM_BLOCK_COUNT_PSTORE * eeprom_get_block_size(); r->access_size = sizeof(uint32_t); + *resp_size = sizeof(struct lpc_response_pstore_info); return EC_LPC_RESULT_SUCCESS; } DECLARE_HOST_COMMAND(EC_LPC_COMMAND_PSTORE_INFO, pstore_command_get_info); -enum lpc_status pstore_command_read(uint8_t *data) +int pstore_command_read(uint8_t *data, int *resp_size) { struct lpc_params_pstore_read *p = (struct lpc_params_pstore_read *)data; @@ -59,12 +60,13 @@ enum lpc_status pstore_command_read(uint8_t *data) dest += bytes_this; } + *resp_size = sizeof(struct lpc_response_pstore_read); return EC_LPC_RESULT_SUCCESS; } DECLARE_HOST_COMMAND(EC_LPC_COMMAND_PSTORE_READ, pstore_command_read); -enum lpc_status pstore_command_write(uint8_t *data) +int pstore_command_write(uint8_t *data, int *resp_size) { struct lpc_params_pstore_write *p = (struct lpc_params_pstore_write *)data; diff --git a/common/pwm_commands.c b/common/pwm_commands.c index 8321e57fbb..8009cf2ff9 100644 --- a/common/pwm_commands.c +++ b/common/pwm_commands.c @@ -10,18 +10,19 @@ #include "thermal.h" -enum lpc_status pwm_command_get_fan_rpm(uint8_t *data) +int pwm_command_get_fan_rpm(uint8_t *data, int *resp_size) { struct lpc_response_pwm_get_fan_rpm *r = (struct lpc_response_pwm_get_fan_rpm *)data; r->rpm = pwm_get_fan_target_rpm(); + *resp_size = sizeof(struct lpc_response_pwm_get_fan_rpm); return EC_LPC_RESULT_SUCCESS; } DECLARE_HOST_COMMAND(EC_LPC_COMMAND_PWM_GET_FAN_RPM, pwm_command_get_fan_rpm); -enum lpc_status pwm_command_set_fan_target_rpm(uint8_t *data) +int pwm_command_set_fan_target_rpm(uint8_t *data, int *resp_size) { struct lpc_params_pwm_set_fan_target_rpm *p = (struct lpc_params_pwm_set_fan_target_rpm *)data; @@ -36,19 +37,20 @@ DECLARE_HOST_COMMAND(EC_LPC_COMMAND_PWM_SET_FAN_TARGET_RPM, pwm_command_set_fan_target_rpm); -enum lpc_status pwm_command_get_keyboard_backlight(uint8_t *data) +int pwm_command_get_keyboard_backlight(uint8_t *data, int *resp_size) { struct lpc_response_pwm_get_keyboard_backlight *r = (struct lpc_response_pwm_get_keyboard_backlight *)data; r->percent = pwm_get_keyboard_backlight(); + *resp_size = sizeof(struct lpc_response_pwm_get_keyboard_backlight); return EC_LPC_RESULT_SUCCESS; } DECLARE_HOST_COMMAND(EC_LPC_COMMAND_PWM_GET_KEYBOARD_BACKLIGHT, pwm_command_get_keyboard_backlight); -enum lpc_status pwm_command_set_keyboard_backlight(uint8_t *data) +int pwm_command_set_keyboard_backlight(uint8_t *data, int *resp_size) { struct lpc_params_pwm_set_keyboard_backlight *p = (struct lpc_params_pwm_set_keyboard_backlight *)data; diff --git a/common/system_common.c b/common/system_common.c index 4fe6204af2..0eb82d065c 100644 --- a/common/system_common.c +++ b/common/system_common.c @@ -543,7 +543,7 @@ DECLARE_CONSOLE_COMMAND(reboot, command_reboot); /*****************************************************************************/ /* Host commands */ -static enum lpc_status host_command_get_version(uint8_t *data) +static int host_command_get_version(uint8_t *data, int *resp_size) { struct lpc_response_get_version *r = (struct lpc_response_get_version *)data; @@ -570,12 +570,13 @@ static enum lpc_status host_command_get_version(uint8_t *data) break; } + *resp_size = sizeof(struct lpc_response_get_version); return EC_LPC_RESULT_SUCCESS; } DECLARE_HOST_COMMAND(EC_LPC_COMMAND_GET_VERSION, host_command_get_version); -static enum lpc_status host_command_build_info(uint8_t *data) +static int host_command_build_info(uint8_t *data, int *resp_size) { struct lpc_response_get_build_info *r = (struct lpc_response_get_build_info *)data; @@ -583,12 +584,13 @@ static enum lpc_status host_command_build_info(uint8_t *data) strzcpy(r->build_string, system_get_build_info(), sizeof(r->build_string)); + *resp_size = sizeof(struct lpc_response_get_build_info); return EC_LPC_RESULT_SUCCESS; } DECLARE_HOST_COMMAND(EC_LPC_COMMAND_GET_BUILD_INFO, host_command_build_info); -static enum lpc_status host_command_get_chip_info(uint8_t *data) +static int host_command_get_chip_info(uint8_t *data, int *resp_size) { struct lpc_response_get_chip_info *r = (struct lpc_response_get_chip_info *)data; @@ -597,6 +599,7 @@ static enum lpc_status host_command_get_chip_info(uint8_t *data) strzcpy(r->name, system_get_chip_name(), sizeof(r->name)); strzcpy(r->revision, system_get_chip_revision(), sizeof(r->revision)); + *resp_size = sizeof(struct lpc_response_get_chip_info); return EC_LPC_RESULT_SUCCESS; } DECLARE_HOST_COMMAND(EC_LPC_COMMAND_GET_CHIP_INFO, host_command_get_chip_info); @@ -605,12 +608,12 @@ DECLARE_HOST_COMMAND(EC_LPC_COMMAND_GET_CHIP_INFO, host_command_get_chip_info); #ifdef CONFIG_REBOOT_EC static void clean_busy_bits(void) { #ifdef CONFIG_LPC - lpc_send_host_response(0, EC_LPC_RESULT_SUCCESS); - lpc_send_host_response(1, EC_LPC_RESULT_SUCCESS); + host_send_result(0, EC_LPC_RESULT_SUCCESS); + host_send_result(1, EC_LPC_RESULT_SUCCESS); #endif } -enum lpc_status host_command_reboot(uint8_t *data) +int host_command_reboot(uint8_t *data, int *resp_size) { enum system_image_copy_t copy; diff --git a/common/thermal_commands.c b/common/thermal_commands.c index e3be7429ab..f3476f8348 100644 --- a/common/thermal_commands.c +++ b/common/thermal_commands.c @@ -9,7 +9,7 @@ #include "thermal.h" -enum lpc_status thermal_command_set_threshold(uint8_t *data) +int thermal_command_set_threshold(uint8_t *data, int *resp_size) { struct lpc_params_thermal_set_threshold *p = (struct lpc_params_thermal_set_threshold *)data; @@ -22,7 +22,7 @@ DECLARE_HOST_COMMAND(EC_LPC_COMMAND_THERMAL_SET_THRESHOLD, thermal_command_set_threshold); -enum lpc_status thermal_command_get_threshold(uint8_t *data) +int thermal_command_get_threshold(uint8_t *data, int *resp_size) { struct lpc_params_thermal_get_threshold *p = (struct lpc_params_thermal_get_threshold *)data; @@ -33,13 +33,14 @@ enum lpc_status thermal_command_get_threshold(uint8_t *data) if (r->value == -1) return EC_LPC_RESULT_ERROR; + *resp_size = sizeof(struct lpc_response_thermal_get_threshold); return EC_LPC_RESULT_SUCCESS; } DECLARE_HOST_COMMAND(EC_LPC_COMMAND_THERMAL_GET_THRESHOLD, thermal_command_get_threshold); -enum lpc_status thermal_command_auto_fan_ctrl(uint8_t *data) +int thermal_command_auto_fan_ctrl(uint8_t *data, int *resp_size) { if (thermal_toggle_auto_fan_ctrl(1)) return EC_LPC_RESULT_ERROR; diff --git a/common/usb_charge_commands.c b/common/usb_charge_commands.c index a8a855841a..ad0380186d 100644 --- a/common/usb_charge_commands.c +++ b/common/usb_charge_commands.c @@ -15,7 +15,7 @@ #define CPRINTF(format, args...) cprintf(CC_USBCHARGE, format, ## args) -enum lpc_status usb_charge_command_set_mode(uint8_t *data) +int usb_charge_command_set_mode(uint8_t *data, int *resp_size) { struct lpc_params_usb_charge_set_mode *p = (struct lpc_params_usb_charge_set_mode *)data; diff --git a/include/host_command.h b/include/host_command.h index c00df1a93d..7bebbe5e19 100644 --- a/include/host_command.h +++ b/include/host_command.h @@ -15,8 +15,10 @@ struct host_command { /* Command code. */ int command; - /* Handler for the command; data points to parameters/response. */ - enum lpc_status (*handler)(uint8_t *data); + /* Handler for the command; data points to parameters/response. + * returns negative error code if case of failure (using EC_LPC_STATUS + * codes). sets <response_size> if it returns a payload to the host. */ + int (*handler)(uint8_t *data, int *response_size); }; @@ -24,6 +26,27 @@ struct host_command { command slots (0=kernel, 1=user). */ void host_command_received(int slot, int command); +/* Send errors or success result code to a host command, + * without response data. + * <slot> is 0 for kernel-originated commands, + * 1 for usermode-originated commands. + * <result> is the error code. */ +void host_send_result(int slot, int result); + + // success results with response data +/* Send a successful result code along with response data to a host command. + * <slot> is 0 for kernel-originated commands, + * 1 for usermode-originated commands. + * <data> is the buffer with the response payload. + * <size> is the size of the response buffer. */ +void host_send_response(int slot, const uint8_t *data, int size); + +/* Return a pointer to the host command data buffer. This buffer must + * only be accessed between a notification to host_command_received() + * and a subsequent call to lpc_SendHostResponse(). <slot> is 0 for + * kernel-originated commands, 1 for usermode-originated commands. */ +uint8_t *host_get_buffer(int slot); + /* Register a host command handler */ #define DECLARE_HOST_COMMAND(command, routine) \ const struct host_command __host_cmd_##command \ diff --git a/include/lpc.h b/include/lpc.h index 295522ad1f..45e777689a 100644 --- a/include/lpc.h +++ b/include/lpc.h @@ -15,20 +15,10 @@ */ void lpc_manual_irq(int irq_num); -/* Return a pointer to the host command data buffer. This buffer must - * only be accessed between a notification to host_command_received() - * and a subsequent call to lpc_SendHostResponse(). <slot> is 0 for - * kernel-originated commands, 1 for usermode-originated commands. */ -uint8_t *lpc_get_host_range(int slot); - /* Return a pointer to the memory-mapped buffer. This buffer is writable at * any time, and the host can read it at any time. */ uint8_t *lpc_get_memmap_range(void); -/* Send a result code to a host command. <slot> is 0 for kernel-originated - * commands, 1 for usermode-originated commands. */ -void lpc_send_host_response(int slot, int result); - /* Return true if the TOH is still set */ int lpc_keyboard_has_char(void); diff --git a/include/lpc_commands.h b/include/lpc_commands.h index c7f2530df1..fd93136421 100644 --- a/include/lpc_commands.h +++ b/include/lpc_commands.h @@ -14,6 +14,8 @@ */ #define SUPPORT_CHECKSUM +/* Current version of this protocol */ +#define EC_LPC_PROTO_VERSION 0x00000002 /* I/O addresses for LPC commands */ #define EC_LPC_ADDR_KERNEL_DATA 0x62 @@ -156,6 +158,13 @@ enum host_event_code { /*****************************************************************************/ /* General / test commands */ +/* Get protocol version, used to deal with non-backward compatible protocol + * changes. */ +#define EC_LPC_COMMAND_PROTO_VERSION 0x00 +struct lpc_response_proto_version { + uint32_t version; +} __attribute__ ((packed)); + /* Hello. This is a simple command to test the EC is responsive to * commands. */ #define EC_LPC_COMMAND_HELLO 0x01 @@ -458,6 +467,22 @@ struct lpc_response_thermal_get_threshold { #define EC_LPC_COMMAND_THERMAL_AUTO_FAN_CTRL 0x52 /*****************************************************************************/ +/* Matrix KeyBoard Protocol */ + +/* Read key state */ +#define EC_LPC_COMMAND_MKBP_STATE 0x60 +struct lpc_response_mkbp_state { + uint8_t cols[32]; +} __attribute__ ((packed)); + +/* Provide information about the matrix : number of rows and columns */ +#define EC_LPC_COMMAND_MKBP_INFO 0x61 +struct lpc_response_mkbp_info { + uint32_t rows; + uint32_t cols; +} __attribute__ ((packed)); + +/*****************************************************************************/ /* Host event commands */ /* Host event mask params and response structures, shared by all of the host |