diff options
-rw-r--r-- | common/flash_commands.c | 24 | ||||
-rw-r--r-- | common/host_command.c | 106 | ||||
-rw-r--r-- | common/main.c | 2 | ||||
-rw-r--r-- | common/pstore_commands.c | 6 | ||||
-rw-r--r-- | common/pwm_commands.c | 13 | ||||
-rw-r--r-- | common/usb_charge_commands.c | 8 | ||||
-rw-r--r-- | core/cortex-m/ec.lds.S | 3 | ||||
-rw-r--r-- | include/flash_commands.h | 28 | ||||
-rw-r--r-- | include/host_command.h | 18 | ||||
-rw-r--r-- | include/lpc.h | 2 | ||||
-rw-r--r-- | include/pstore_commands.h | 18 | ||||
-rw-r--r-- | include/pwm_commands.h | 21 | ||||
-rw-r--r-- | include/usb_charge_commands.h | 19 |
13 files changed, 82 insertions, 186 deletions
diff --git a/common/flash_commands.c b/common/flash_commands.c index 6da536b40c..04e4b89b6e 100644 --- a/common/flash_commands.c +++ b/common/flash_commands.c @@ -1,14 +1,13 @@ -/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved. +/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved. * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ -/* Flash memory module for Chrome EC */ +/* Flash memory commands for Chrome EC */ #include "console.h" #include "flash.h" -#include "flash_commands.h" -#include "lpc_commands.h" +#include "host_command.h" #include "registers.h" /* TODO: remove; only for temp debugging */ #include "shared_mem.h" #include "uart.h" @@ -203,6 +202,7 @@ enum lpc_status flash_command_get_info(uint8_t *data) r->protect_block_size = FLASH_PROTECT_BYTES; return EC_LPC_STATUS_SUCCESS; } +DECLARE_HOST_COMMAND(EC_LPC_COMMAND_FLASH_INFO, flash_command_get_info); #ifdef SUPPORT_CHECKSUM @@ -228,6 +228,7 @@ enum lpc_status flash_command_checksum(uint8_t *data) return EC_LPC_STATUS_SUCCESS; } +DECLARE_HOST_COMMAND(EC_LPC_COMMAND_FLASH_CHECKSUM, flash_command_checksum); #endif @@ -246,6 +247,7 @@ enum lpc_status flash_command_read(uint8_t *data) return EC_LPC_STATUS_SUCCESS; } +DECLARE_HOST_COMMAND(EC_LPC_COMMAND_FLASH_READ, flash_command_read); enum lpc_status flash_command_write(uint8_t *data) @@ -261,6 +263,7 @@ enum lpc_status flash_command_write(uint8_t *data) return EC_LPC_STATUS_SUCCESS; } +DECLARE_HOST_COMMAND(EC_LPC_COMMAND_FLASH_WRITE, flash_command_write); enum lpc_status flash_command_erase(uint8_t *data) @@ -273,6 +276,8 @@ enum lpc_status flash_command_erase(uint8_t *data) return EC_LPC_STATUS_SUCCESS; } +DECLARE_HOST_COMMAND(EC_LPC_COMMAND_FLASH_ERASE, flash_command_erase); + /* TODO: use shadow range in EEPROM */ static int shadow_wp_offset; @@ -296,6 +301,9 @@ enum lpc_status flash_command_wp_enable(uint8_t *data) return EC_LPC_STATUS_SUCCESS; } +DECLARE_HOST_COMMAND(EC_LPC_COMMAND_FLASH_WP_ENABLE, + flash_command_wp_enable); + enum lpc_status flash_command_wp_get_state(uint8_t *data) { @@ -309,6 +317,9 @@ enum lpc_status flash_command_wp_get_state(uint8_t *data) return EC_LPC_STATUS_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) { @@ -320,6 +331,9 @@ enum lpc_status flash_command_wp_set_range(uint8_t *data) return EC_LPC_STATUS_SUCCESS; } +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) { @@ -331,3 +345,5 @@ enum lpc_status flash_command_wp_get_range(uint8_t *data) return EC_LPC_STATUS_SUCCESS; } +DECLARE_HOST_COMMAND(EC_LPC_COMMAND_FLASH_WP_GET_RANGE, + flash_command_wp_get_range); diff --git a/common/host_command.c b/common/host_command.c index f52c6095ad..faf29bfa63 100644 --- a/common/host_command.c +++ b/common/host_command.c @@ -5,24 +5,22 @@ /* Host command module for Chrome EC */ -#include "board.h" -#include "config.h" #include "console.h" -#include "flash_commands.h" #include "host_command.h" #include "lpc.h" #include "lpc_commands.h" -#include "pstore_commands.h" -#include "pwm_commands.h" #include "system.h" #include "task.h" #include "timer.h" #include "uart.h" -#include "usb_charge_commands.h" #include "util.h" static int host_command[2]; +/* Host commands are described in a special section */ +extern const struct host_command __hcmds[]; +extern const struct host_command __hcmds_end[]; + /*****************************************************************************/ /* Host commands */ @@ -71,6 +69,7 @@ static enum lpc_status host_command_hello(uint8_t *data) r->out_data = d + 0x01020304; return EC_LPC_STATUS_SUCCESS; } +DECLARE_HOST_COMMAND(EC_LPC_COMMAND_HELLO, host_command_hello); static enum lpc_status host_command_get_version(uint8_t *data) @@ -104,6 +103,7 @@ static enum lpc_status host_command_get_version(uint8_t *data) return EC_LPC_STATUS_SUCCESS; } +DECLARE_HOST_COMMAND(EC_LPC_COMMAND_GET_VERSION, host_command_get_version); static enum lpc_status host_command_read_test(uint8_t *data) @@ -124,89 +124,37 @@ static enum lpc_status host_command_read_test(uint8_t *data) return EC_LPC_STATUS_SUCCESS; } +DECLARE_HOST_COMMAND(EC_LPC_COMMAND_READ_TEST, host_command_read_test); + + +/* Finds 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; + + for (cmd = __hcmds; cmd < __hcmds_end; cmd++) { + if (command == cmd->command) + return cmd; + } + + return NULL; +} -/* handle a LPC command */ +/* Handle a LPC command */ static void command_process(int slot) { int command = host_command[slot]; uint8_t *data = lpc_get_host_range(slot); + const struct host_command *cmd = find_host_command(command); uart_printf("[hostcmd%d 0x%02x]\n", slot, command); - /* TODO: might be smaller to make this a table, once we get a bunch - * of commands. */ - switch (command) { - case EC_LPC_COMMAND_HELLO: - lpc_send_host_response(slot, host_command_hello(data)); - return; - case EC_LPC_COMMAND_GET_VERSION: - lpc_send_host_response(slot, host_command_get_version(data)); - return; - case EC_LPC_COMMAND_READ_TEST: - lpc_send_host_response(slot, host_command_read_test(data)); - return; - case EC_LPC_COMMAND_FLASH_INFO: - lpc_send_host_response(slot, flash_command_get_info(data)); - return; - case EC_LPC_COMMAND_FLASH_READ: - lpc_send_host_response(slot, flash_command_read(data)); - return; - case EC_LPC_COMMAND_FLASH_WRITE: - lpc_send_host_response(slot, flash_command_write(data)); - return; - case EC_LPC_COMMAND_FLASH_ERASE: - lpc_send_host_response(slot, flash_command_erase(data)); - return; - case EC_LPC_COMMAND_FLASH_WP_ENABLE: - lpc_send_host_response(slot, flash_command_wp_enable(data)); - return; - case EC_LPC_COMMAND_FLASH_WP_GET_STATE: - lpc_send_host_response(slot, flash_command_wp_get_state(data)); - return; - case EC_LPC_COMMAND_FLASH_WP_SET_RANGE: - lpc_send_host_response(slot, flash_command_wp_set_range(data)); - return; - case EC_LPC_COMMAND_FLASH_WP_GET_RANGE: - lpc_send_host_response(slot, flash_command_wp_get_range(data)); - return; -#ifdef SUPPORT_CHECKSUM - case EC_LPC_COMMAND_FLASH_CHECKSUM: - lpc_send_host_response(slot, flash_command_checksum(data)); - return; -#endif - case EC_LPC_COMMAND_PWM_GET_FAN_RPM: - lpc_send_host_response(slot, pwm_command_get_fan_rpm(data)); - return; - case EC_LPC_COMMAND_PWM_SET_FAN_TARGET_RPM: - lpc_send_host_response(slot, - pwm_command_set_fan_target_rpm(data)); - return; - case EC_LPC_COMMAND_PWM_GET_KEYBOARD_BACKLIGHT: - lpc_send_host_response(slot, - pwm_command_get_keyboard_backlight(data)); - return; - case EC_LPC_COMMAND_PWM_SET_KEYBOARD_BACKLIGHT: - lpc_send_host_response(slot, - pwm_command_set_keyboard_backlight(data)); - return; - case EC_LPC_COMMAND_USB_CHARGE_SET_MODE: - lpc_send_host_response(slot, usb_charge_command_set_mode(data)); - return; -#ifdef CONFIG_PSTORE - case EC_LPC_COMMAND_PSTORE_INFO: - lpc_send_host_response(slot, pstore_command_get_info(data)); - return; - case EC_LPC_COMMAND_PSTORE_READ: - lpc_send_host_response(slot, pstore_command_read(data)); - return; - case EC_LPC_COMMAND_PSTORE_WRITE: - lpc_send_host_response(slot, pstore_command_write(data)); - return; -#endif - default: + if (cmd) + lpc_send_host_response(slot, cmd->handler(data)); + else lpc_send_host_response(slot, EC_LPC_STATUS_INVALID_COMMAND); - } } /*****************************************************************************/ diff --git a/common/main.c b/common/main.c index f342bad9a0..628227d627 100644 --- a/common/main.c +++ b/common/main.c @@ -13,7 +13,6 @@ #include "console.h" #include "eeprom.h" #include "flash.h" -#include "flash_commands.h" #include "gpio.h" #include "i2c.h" #include "jtag.h" @@ -26,7 +25,6 @@ #include "power_button.h" #include "powerdemo.h" #include "pwm.h" -#include "pwm_commands.h" #include "system.h" #include "task.h" #include "temp_sensor.h" diff --git a/common/pstore_commands.c b/common/pstore_commands.c index 24ce7c7878..67c35d1bab 100644 --- a/common/pstore_commands.c +++ b/common/pstore_commands.c @@ -7,8 +7,7 @@ #include "board.h" #include "eeprom.h" -#include "lpc_commands.h" -#include "pstore_commands.h" +#include "host_command.h" #include "uart.h" #include "util.h" @@ -34,6 +33,7 @@ enum lpc_status pstore_command_get_info(uint8_t *data) r->access_size = sizeof(uint32_t); return EC_LPC_STATUS_SUCCESS; } +DECLARE_HOST_COMMAND(EC_LPC_COMMAND_PSTORE_INFO, pstore_command_get_info); enum lpc_status pstore_command_read(uint8_t *data) @@ -71,6 +71,7 @@ enum lpc_status pstore_command_read(uint8_t *data) return EC_LPC_STATUS_SUCCESS; } +DECLARE_HOST_COMMAND(EC_LPC_COMMAND_PSTORE_READ, pstore_command_read); enum lpc_status pstore_command_write(uint8_t *data) @@ -107,3 +108,4 @@ enum lpc_status pstore_command_write(uint8_t *data) return EC_LPC_STATUS_SUCCESS; } +DECLARE_HOST_COMMAND(EC_LPC_COMMAND_PSTORE_WRITE, pstore_command_write); diff --git a/common/pwm_commands.c b/common/pwm_commands.c index e186436d79..3e6a9ee52b 100644 --- a/common/pwm_commands.c +++ b/common/pwm_commands.c @@ -5,14 +5,10 @@ /* PWM host commands for Chrome EC */ +#include "host_command.h" #include "pwm.h" -#include "pwm_commands.h" -#include "lpc_commands.h" -/*****************************************************************************/ -/* Host commands */ - enum lpc_status pwm_command_get_fan_rpm(uint8_t *data) { struct lpc_response_pwm_get_fan_rpm *r = @@ -21,6 +17,7 @@ enum lpc_status pwm_command_get_fan_rpm(uint8_t *data) r->rpm = pwm_get_fan_target_rpm(); return EC_LPC_STATUS_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) @@ -31,6 +28,8 @@ enum lpc_status pwm_command_set_fan_target_rpm(uint8_t *data) pwm_set_fan_target_rpm(p->rpm); return EC_LPC_STATUS_SUCCESS; } +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) @@ -41,6 +40,8 @@ enum lpc_status pwm_command_get_keyboard_backlight(uint8_t *data) r->percent = pwm_get_keyboard_backlight(); return EC_LPC_STATUS_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) @@ -51,3 +52,5 @@ enum lpc_status pwm_command_set_keyboard_backlight(uint8_t *data) pwm_set_keyboard_backlight(p->percent); return EC_LPC_STATUS_SUCCESS; } +DECLARE_HOST_COMMAND(EC_LPC_COMMAND_PWM_SET_KEYBOARD_BACKLIGHT, + pwm_command_set_keyboard_backlight); diff --git a/common/usb_charge_commands.c b/common/usb_charge_commands.c index 6d72f48742..22fdb3374d 100644 --- a/common/usb_charge_commands.c +++ b/common/usb_charge_commands.c @@ -7,15 +7,11 @@ #include "console.h" #include "usb_charge.h" -#include "usb_charge_commands.h" -#include "lpc_commands.h" +#include "host_command.h" #include "uart.h" #include "util.h" -/*****************************************************************************/ -/* Host commands */ - enum lpc_status usb_charge_command_set_mode(uint8_t *data) { struct lpc_params_usb_charge_set_mode *p = @@ -31,3 +27,5 @@ enum lpc_status usb_charge_command_set_mode(uint8_t *data) return EC_LPC_STATUS_SUCCESS; } +DECLARE_HOST_COMMAND(EC_LPC_COMMAND_USB_CHARGE_SET_MODE, + usb_charge_command_set_mode); diff --git a/core/cortex-m/ec.lds.S b/core/cortex-m/ec.lds.S index 35006ae77f..94027c7b61 100644 --- a/core/cortex-m/ec.lds.S +++ b/core/cortex-m/ec.lds.S @@ -34,6 +34,9 @@ SECTIONS __cmds = .; *(.rodata.cmds) __cmds_end = .; + __hcmds = .; + *(.rodata.hcmds) + __hcmds_end = .; *(.rodata*) . = ALIGN(4); #ifdef COMPILE_FOR_RAM diff --git a/include/flash_commands.h b/include/flash_commands.h deleted file mode 100644 index 9a46bef5e5..0000000000 --- a/include/flash_commands.h +++ /dev/null @@ -1,28 +0,0 @@ -/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -/* Flash memory commands for Chrome EC */ - -#ifndef __CROS_EC_FLASH_COMMANDS_H -#define __CROS_EC_FLASH_COMMANDS_H - -#include "common.h" -#include "lpc_commands.h" - -/* Host command handlers. */ -enum lpc_status flash_command_get_info(uint8_t *data); -enum lpc_status flash_command_read(uint8_t *data); -enum lpc_status flash_command_write(uint8_t *data); -enum lpc_status flash_command_erase(uint8_t *data); -enum lpc_status flash_command_wp_enable(uint8_t *data); -enum lpc_status flash_command_wp_get_state(uint8_t *data); -enum lpc_status flash_command_wp_set_range(uint8_t *data); -enum lpc_status flash_command_wp_get_range(uint8_t *data); -#ifdef SUPPORT_CHECKSUM -enum lpc_status flash_command_checksum(uint8_t *data); -#endif - - -#endif /* __CROS_EC_FLASH_COMMANDS_H */ diff --git a/include/host_command.h b/include/host_command.h index 9c2dda2a69..c00df1a93d 100644 --- a/include/host_command.h +++ b/include/host_command.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved. +/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved. * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ @@ -9,9 +9,25 @@ #define __CROS_EC_HOST_COMMAND_H #include "common.h" +#include "lpc_commands.h" + +/* Host command */ +struct host_command { + /* Command code. */ + int command; + /* Handler for the command; data points to parameters/response. */ + enum lpc_status (*handler)(uint8_t *data); +}; + /* Called by LPC module when a command is written to one of the command slots (0=kernel, 1=user). */ void host_command_received(int slot, int command); +/* Register a host command handler */ +#define DECLARE_HOST_COMMAND(command, routine) \ + const struct host_command __host_cmd_##command \ + __attribute__((section(".rodata.hcmds"))) \ + = {command, routine} + #endif /* __CROS_EC_HOST_COMMAND_H */ diff --git a/include/lpc.h b/include/lpc.h index 69968dba99..b616659300 100644 --- a/include/lpc.h +++ b/include/lpc.h @@ -10,13 +10,11 @@ #include "common.h" - /* Manually generates an IRQ to host. * Note that the irq_num == 0 would set the AH bit (Active High). */ void lpc_manual_irq(int irq_num); - /* Initializes the LPC module. */ int lpc_init(void); diff --git a/include/pstore_commands.h b/include/pstore_commands.h deleted file mode 100644 index 123d6f28f9..0000000000 --- a/include/pstore_commands.h +++ /dev/null @@ -1,18 +0,0 @@ -/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -/* Persistent storage commands for Chrome EC */ - -#ifndef __CROS_EC_PSTORE_COMMANDS_H -#define __CROS_EC_PSTORE_COMMANDS_H - -#include "common.h" - -/* Host command handlers. */ -enum lpc_status pstore_command_get_info(uint8_t *data); -enum lpc_status pstore_command_read(uint8_t *data); -enum lpc_status pstore_command_write(uint8_t *data); - -#endif /* __CROS_EC_PSTORE_COMMANDS_H */ diff --git a/include/pwm_commands.h b/include/pwm_commands.h deleted file mode 100644 index 8f2dbdfb0c..0000000000 --- a/include/pwm_commands.h +++ /dev/null @@ -1,21 +0,0 @@ -/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -/* PWM commands for Chrome EC */ - -#ifndef __CROS_EC_PWM_COMMANDS_H -#define __CROS_EC_PWM_COMMANDS_H - -#include "common.h" -#include "lpc_commands.h" - -/* Host command handlers. */ -enum lpc_status pwm_command_get_fan_rpm(uint8_t *data); -enum lpc_status pwm_command_set_fan_target_rpm(uint8_t *data); -enum lpc_status pwm_command_get_keyboard_backlight(uint8_t *data); -enum lpc_status pwm_command_set_keyboard_backlight(uint8_t *data); - - -#endif /* __CROS_EC_PWM_COMMANDS_H */ diff --git a/include/usb_charge_commands.h b/include/usb_charge_commands.h deleted file mode 100644 index 8871fdd294..0000000000 --- a/include/usb_charge_commands.h +++ /dev/null @@ -1,19 +0,0 @@ -/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -/* USB charging control commands for Chrome EC */ - -#ifndef __CROS_EC_USB_CHARGE_COMMANDS_H -#define __CROS_EC_USB_CHARGE_COMMANDS_H - -#include "common.h" - -/* Initializes the module. */ -int usb_charge_commands_init(void); - -/* Host command handlers. */ -enum lpc_status usb_charge_command_set_mode(uint8_t *data); - -#endif /* __CROS_EC_USB_CHARGE_COMMANDS_H */ |