From e74e60c4651111a66380d99683ecd5cf9d7dbfb2 Mon Sep 17 00:00:00 2001 From: Randall Spangler Date: Thu, 13 Jun 2013 20:18:14 -0700 Subject: Refactor host command interface to support version 3 packets This will fix EC flash commands on pit, once the host side (u-boot and cros_ec driver) are upgraded to match. This change is backwards-compatible the EC still supports the existing version 2 protocols for talking to existing AP/kernel/ectool. Once the AP-side supports version 3 for SPI (and existing systems are upgraded), we will remove older SPI support since we haven't shipped a product which uses SPI. BUG=chrome-os-partner:20257 BRANCH=none TEST=disable cros_ec driver support in ectool; 'ectool hello' works on link And with an old ectool which predates this CL, 'ectool hello' also works. On pit, from u-boot prompt, 'crosec test' and 'crosec version' work, and keyboard works. Change-Id: I01f193e316e9aa442fe50d632dc8a4681723e282 Signed-off-by: Randall Spangler Reviewed-on: https://gerrit.chromium.org/gerrit/58908 Reviewed-by: Simon Glass Commit-Queue: Doug Anderson --- include/host_command.h | 74 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 70 insertions(+), 4 deletions(-) (limited to 'include/host_command.h') diff --git a/include/host_command.h b/include/host_command.h index cc14d672af..4c994463f6 100644 --- a/include/host_command.h +++ b/include/host_command.h @@ -19,10 +19,12 @@ struct host_cmd_handler_args { * send the response back to the host. */ void (*send_response)(struct host_cmd_handler_args *args); - uint8_t command; /* Command (e.g., EC_CMD_FLASH_GET_INFO) */ + uint16_t command; /* Command (e.g., EC_CMD_FLASH_GET_INFO) */ uint8_t version; /* Version of command (0-31) */ - uint8_t params_size; /* Size of input parameters in bytes */ + const void *params; /* Input parameters */ + uint16_t params_size; /* Size of input parameters in bytes */ + /* * Pointer to output response data buffer. On input to the handler, * points to a buffer of size response_max. Command handler can change @@ -35,8 +37,8 @@ struct host_cmd_handler_args { * handler changes response to point to its own larger buffer, it may * return a response_size greater than response_max. */ - uint8_t response_max; - uint8_t response_size; /* Size of data pointed to by resp_ptr */ + uint16_t response_max; + uint16_t response_size; /* Size of data pointed to by response */ /* * This is the result returned by command and therefore the status to @@ -50,6 +52,53 @@ struct host_cmd_handler_args { enum ec_status result; }; +/* Args for host packet handler */ +struct host_packet { + /* + * The driver that receives the command sets up the send_response() + * handler. Once the command is processed this handler is called to + * send the response back to the host. + */ + void (*send_response)(struct host_packet *pkt); + + /* Input request data */ + const void *request; + + /* + * Input request temp buffer. If this is non-null, the data has not + * been copied from here into the request buffer yet. The host command + * handler should do so while verifying the command. The interface + * can't do it, because it doesn't know how much to copy. + */ + void *request_temp; + + /* + * Maximum size of request the interface can handle, in bytes. The + * buffers pointed to by *request and *request_temp must be at least + * this big. + */ + uint16_t request_max; + + /* Size of input request data, in bytes */ + uint16_t request_size; + + /* Pointer to output response data buffer */ + void *response; + + /* Maximum size of response buffer provided to command handler */ + uint16_t response_max; + + /* Size of output response data, in bytes */ + uint16_t response_size; + + /* + * Error from driver; if this is non-zero, host command handler will + * return a properly formatted error response packet rather than + * calling a command handler. + */ + enum ec_status driver_result; +}; + /* Host command */ struct host_command { /* @@ -132,6 +181,23 @@ void host_send_response(struct host_cmd_handler_args *args); */ void host_command_received(struct host_cmd_handler_args *args); +/** + * Return the expected host packet size given its header. + * + * Also does some sanity checking on the host request. + * + * @param r Host request header + * @return The expected packet size, or 0 if error. + */ +int host_request_expected_size(const struct ec_host_request *r); + +/** + * Handle a received host packet. + * + * @param packet Host packet args + */ +void host_packet_receive(struct host_packet *pkt); + /* Register a host command handler */ #define DECLARE_HOST_COMMAND(command, routine, version_mask) \ const struct host_command __host_cmd_##command \ -- cgit v1.2.1