forked from zephyrproject-rtos/zephyr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ec_host_cmd.h
207 lines (194 loc) · 7.26 KB
/
ec_host_cmd.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*
* Copyright (c) 2020 Google LLC
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ZEPHYR_INCLUDE_EC_HOST_CMD_H_
#define ZEPHYR_INCLUDE_EC_HOST_CMD_H_
/**
* @brief EC Host Command Interface
* @defgroup ec_host_cmd_periph_interface EC Host Command Interface
* @ingroup io_interfaces
* @{
*/
#include <stdint.h>
/**
* @brief Arguments passed into every installed host command handler
*/
struct ec_host_cmd_handler_args {
/** 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.
*/
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)(
struct ec_host_cmd_handler_args *args);
/**
* @brief Structure use for statically registering host command handlers
*/
struct ec_host_cmd_handler {
/** Callback routine to process commands that match @a id. */
ec_host_cmd_handler_cb handler;
/** The numberical command id used as the lookup for commands. */
uint16_t id;
/** The bitfield of all versions that the @a handler supports, where
* each bit value represents that the @a handler supports that version.
* E.g. BIT(0) corresponse to version 0.
*/
uint16_t version_mask;
/** The minimum @a input_buf_size enforced by the framework before
* passing to the handler.
*/
uint16_t min_rqt_size;
/** The minimum @a output_buf_size enforced by the framework before
* passing to the handler.
*/
uint16_t min_rsp_size;
};
/**
* @def EC_HOST_CMD_HANDLER
* @brief Statically define and register a host command 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 _version_mask The bitfield of all versions that the @a _function
* supports. E.g. BIT(0) corresponse 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, \
_response_type) \
const Z_STRUCT_SECTION_ITERABLE(ec_host_cmd_handler, __cmd##_id) = { \
.id = _id, \
.handler = _function, \
.version_mask = _version_mask, \
.min_rqt_size = sizeof(_request_type), \
.min_rsp_size = sizeof(_response_type), \
}
/**
* @def EC_HOST_CMD_HANDLER_UNBOUND
* @brief Statically define and register a host command handler without sizes.
*
* 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 _version_mask The bitfield of all versions that the @a _function
* supports. E.g. BIT(0) corresponse to version 0.
*/
#define EC_HOST_CMD_HANDLER_UNBOUND(_function, _id, _version_mask) \
const Z_STRUCT_SECTION_ITERABLE(ec_host_cmd_handler, __cmd##_id) = { \
.id = _id, \
.handler = _function, \
.version_mask = _version_mask, \
.min_rqt_size = 0, \
.min_rsp_size = 0, \
}
/**
* @brief Header for requests from host to embedded controller
*
* Represent the over-the-wire header in LE format for host command requests.
* This represent version 3 of the host command header. The requests are always
* sent from host to embedded controller.
*/
struct ec_host_cmd_request_header {
/** Should be 3. The EC will return EC_HOST_CMD_INVALID_HEADER if it
* receives a header with a version it doesn't know how to parse.
*/
uint8_t prtcl_ver;
/** Checksum of response and data; sum of all bytes including checksum.
* Should total to 0.
*/
uint8_t checksum;
/** Id of command that is being sent. */
uint16_t cmd_id;
/** Version of the specific @a cmd_id being requested. Valid
* versions start at 0.
*/
uint8_t cmd_ver;
/** Unused byte in current protocol version; set to 0. */
uint8_t reserved;
/** Length of data which follows this header. */
uint16_t data_len;
} __packed;
/**
* @brief Header for responses from embedded controller to host
*
* Represent the over-the-wire header in LE format for host command responses.
* This represent version 3 of the host command header. Responses are always
* sent from embedded controller to host.
*/
struct ec_host_cmd_response_header {
/** Should be 3. */
uint8_t prtcl_ver;
/** Checksum of response and data; sum of all bytes including checksum.
* Should total to 0.
*/
uint8_t checksum;
/** A @a ec_host_cmd_status response code for specific command. */
uint16_t result;
/** Length of data which follows this header. */
uint16_t data_len;
/** Unused bytes in current protocol version; set to 0. */
uint16_t reserved;
} __packed;
/*
* Host command response codes (16-bit).
*/
enum ec_host_cmd_status {
/** Host command was successful. */
EC_HOST_CMD_SUCCESS = 0,
/** The specified command id is not recognized or supported. */
EC_HOST_CMD_INVALID_COMMAND = 1,
/** Generic Error. */
EC_HOST_CMD_ERROR = 2,
/** One of more of the input request parameters is invalid. */
EC_HOST_CMD_INVALID_PARAM = 3,
/** Host command is not permitted. */
EC_HOST_CMD_ACCESS_DENIED = 4,
/** Response was invalid (e.g. not version 3 of header). */
EC_HOST_CMD_INVALID_RESPONSE = 5,
/** Host command id version unsupported. */
EC_HOST_CMD_INVALID_VERSION = 6,
/** Checksum did not match */
EC_HOST_CMD_INVALID_CHECKSUM = 7,
/** A host command is currently being processed. */
EC_HOST_CMD_IN_PROGRESS = 8,
/** Requested information is currently unavailable. */
EC_HOST_CMD_UNAVAILABLE = 9,
/** Timeout during processing. */
EC_HOST_CMD_TIMEOUT = 10,
/** Data or table overflow. */
EC_HOST_CMD_OVERFLOW = 11,
/** Header is invalid or unsupported (e.g. not version 3 of header). */
EC_HOST_CMD_INVALID_HEADER = 12,
/** Did not receive all expected request data. */
EC_HOST_CMD_REQUEST_TRUNCATED = 13,
/** Response was too big to send within one response packet. */
EC_HOST_CMD_RESPONSE_TOO_BIG = 14,
/** Error on underlying communication bus. */
EC_HOST_CMD_BUS_ERROR = 15,
/** System busy. Should retry later. */
EC_HOST_CMD_BUSY = 16,
EC_HOST_CMD_MAX = UINT16_MAX /* Force enum to be 16 bits */
} __packed;
/**
* @}
*/
#endif /* ZEPHYR_INCLUDE_EC_HOST_CMD_H_ */