ec_host_cmd: add missing fields and improve compatibility
Add missing fields in structure containing the arguments used by the host commands handlers and change the order of parameters in macro used for defining the handlers. Signed-off-by: Michał Barnaś <mb@semihalf.com>
This commit is contained in:
parent
e184e45a52
commit
b91849c4bd
3 changed files with 26 additions and 19 deletions
|
@ -20,21 +20,25 @@
|
|||
* @brief Arguments passed into every installed host command handler
|
||||
*/
|
||||
struct ec_host_cmd_handler_args {
|
||||
/** Reserved for compatibility. */
|
||||
void *reserved;
|
||||
/** Command identifier. */
|
||||
uint16_t command;
|
||||
/**
|
||||
* The version of the host command that is being requested. This will
|
||||
* be a value that has been static registered as valid for the handler.
|
||||
*/
|
||||
const uint8_t version;
|
||||
/** The incoming data that can be cast to the handlers request type. */
|
||||
const void *const input_buf;
|
||||
/** The number of valid bytes that can be read from @a input_buf. */
|
||||
const uint16_t input_buf_size;
|
||||
/** The data written to this buffer will be send to the host. */
|
||||
void *const output_buf;
|
||||
/** [in/out] Upon entry, this is the maximum number of bytes that can
|
||||
* be written to the @a output_buf. Upon exit, this should be
|
||||
* the number of bytes of @a output_buf to send to the host.
|
||||
*/
|
||||
/** Maximum number of bytes that can be written to the @a output_buf. */
|
||||
uint16_t output_buf_max;
|
||||
/** Number of bytes of @a output_buf to send to the host. */
|
||||
uint16_t output_buf_size;
|
||||
/** The version of the host command that is being requested. This will
|
||||
* be a value that has been static registered as valid for the handler.
|
||||
*/
|
||||
const uint8_t version;
|
||||
};
|
||||
|
||||
typedef enum ec_host_cmd_status (*ec_host_cmd_handler_cb)(
|
||||
|
@ -69,15 +73,15 @@ struct ec_host_cmd_handler {
|
|||
* Helper macro to statically define and register a host command handler that
|
||||
* has a compile-time-fixed sizes for its both request and response structures.
|
||||
*
|
||||
* @param _function Name of handler function.
|
||||
* @param _id Id of host command to handle request for.
|
||||
* @param _function Name of handler function.
|
||||
* @param _version_mask The bitfield of all versions that the @a _function
|
||||
* supports. E.g. BIT(0) corresponds to version 0.
|
||||
* @param _request_type The datatype of the request parameters for @a _function.
|
||||
* @param _response_type The datatype of the response parameters for
|
||||
* @a _function.
|
||||
*/
|
||||
#define EC_HOST_CMD_HANDLER(_function, _id, _version_mask, _request_type, \
|
||||
#define EC_HOST_CMD_HANDLER(_id, _function, _version_mask, _request_type, \
|
||||
_response_type) \
|
||||
const STRUCT_SECTION_ITERABLE(ec_host_cmd_handler, __cmd##_id) = { \
|
||||
.id = _id, \
|
||||
|
@ -94,12 +98,12 @@ struct ec_host_cmd_handler {
|
|||
* Helper macro to statically define and register a host command handler whose
|
||||
* request or response structure size is not known as compile time.
|
||||
*
|
||||
* @param _function Name of handler function.
|
||||
* @param _id Id of host command to handle request for.
|
||||
* @param _function Name of handler function.
|
||||
* @param _version_mask The bitfield of all versions that the @a _function
|
||||
* supports. E.g. BIT(0) corresponds to version 0.
|
||||
*/
|
||||
#define EC_HOST_CMD_HANDLER_UNBOUND(_function, _id, _version_mask) \
|
||||
#define EC_HOST_CMD_HANDLER_UNBOUND(_id, _function, _version_mask) \
|
||||
const STRUCT_SECTION_ITERABLE(ec_host_cmd_handler, __cmd##_id) = { \
|
||||
.id = _id, \
|
||||
.handler = _function, \
|
||||
|
|
|
@ -139,11 +139,14 @@ static void handle_host_cmds_entry(void *arg1, void *arg2, void *arg3)
|
|||
}
|
||||
|
||||
struct ec_host_cmd_handler_args args = {
|
||||
.reserved = NULL,
|
||||
.command = rx_header->cmd_id,
|
||||
.version = rx_header->cmd_ver,
|
||||
.input_buf = rx.buf + RX_HEADER_SIZE,
|
||||
.input_buf_size = rx_header->data_len,
|
||||
.output_buf = tx_buffer + TX_HEADER_SIZE,
|
||||
.output_buf_size = sizeof(tx_buffer) - TX_HEADER_SIZE,
|
||||
.version = rx_header->cmd_ver,
|
||||
.output_buf_max = sizeof(tx_buffer) - TX_HEADER_SIZE,
|
||||
.output_buf_size = 0,
|
||||
};
|
||||
|
||||
if (found_handler->min_rqt_size > args.input_buf_size) {
|
||||
|
@ -152,7 +155,7 @@ static void handle_host_cmds_entry(void *arg1, void *arg2, void *arg3)
|
|||
continue;
|
||||
}
|
||||
|
||||
if (found_handler->min_rsp_size > args.output_buf_size) {
|
||||
if (found_handler->min_rsp_size > args.output_buf_max) {
|
||||
send_error_response(ec_host_cmd_dev,
|
||||
EC_HOST_CMD_INVALID_RESPONSE);
|
||||
continue;
|
||||
|
|
|
@ -162,7 +162,7 @@ ec_host_cmd_add(struct ec_host_cmd_handler_args *args)
|
|||
args->output_buf_size = sizeof(*response);
|
||||
return EC_HOST_CMD_SUCCESS;
|
||||
}
|
||||
EC_HOST_CMD_HANDLER(ec_host_cmd_add, EC_CMD_HELLO, BIT(0) | BIT(1) | BIT(2),
|
||||
EC_HOST_CMD_HANDLER(EC_CMD_HELLO, ec_host_cmd_add, BIT(0) | BIT(1) | BIT(2),
|
||||
struct ec_params_add, struct ec_response_add);
|
||||
|
||||
ZTEST(ec_host_cmd, test_add)
|
||||
|
@ -372,7 +372,7 @@ ec_host_cmd_unbounded(struct ec_host_cmd_handler_args *args)
|
|||
}
|
||||
|
||||
/* Version 0 (and 2) write request bytes if it can fit */
|
||||
if (request->bytes_to_write > args->output_buf_size) {
|
||||
if (request->bytes_to_write > args->output_buf_max) {
|
||||
return EC_HOST_CMD_OVERFLOW;
|
||||
}
|
||||
|
||||
|
@ -384,7 +384,7 @@ ec_host_cmd_unbounded(struct ec_host_cmd_handler_args *args)
|
|||
args->output_buf_size = request->bytes_to_write;
|
||||
return EC_HOST_CMD_SUCCESS;
|
||||
}
|
||||
EC_HOST_CMD_HANDLER_UNBOUND(ec_host_cmd_unbounded, EC_CMD_UNBOUNDED,
|
||||
EC_HOST_CMD_HANDLER_UNBOUND(EC_CMD_UNBOUNDED, ec_host_cmd_unbounded,
|
||||
BIT(0) | BIT(1) | BIT(2));
|
||||
|
||||
ZTEST(ec_host_cmd, test_unbounded_handler_error_return)
|
||||
|
@ -421,7 +421,7 @@ ec_host_cmd_too_big(struct ec_host_cmd_handler_args *args)
|
|||
{
|
||||
return EC_HOST_CMD_SUCCESS;
|
||||
}
|
||||
EC_HOST_CMD_HANDLER(ec_host_cmd_too_big, EC_CMD_TOO_BIG, BIT(0), uint32_t,
|
||||
EC_HOST_CMD_HANDLER(EC_CMD_TOO_BIG, ec_host_cmd_too_big, BIT(0), uint32_t,
|
||||
struct ec_response_too_big);
|
||||
|
||||
ZTEST(ec_host_cmd, test_response_always_too_big)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue