Skip to content

Commit 9285933

Browse files
committed
ref(drivers/mailbox): flatten mbox APIs to support protocol agnosticism
Signed-off-by: puranikvinit <kvp933.vinit@gmail.com>
1 parent 8db6270 commit 9285933

2 files changed

Lines changed: 109 additions & 109 deletions

File tree

src/platform/drivers/mailbox/inc/drivers/k3_sec_proxy.h

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,32 @@
1818
* thread.
1919
*/
2020
typedef enum {
21-
HOST_FUNCTION_NOTIFY,
22-
HOST_FUNCTION_RESPONSE,
23-
HOST_FUNCTION_HIGH_PRIORITY,
24-
HOST_FUNCTION_LOW_PRIORITY,
25-
HOST_FUNCTION_NOTIFY_RESP,
21+
MBOX_K3_SEC_PROXY_HOST_FUNCTION_NOTIFY,
22+
MBOX_K3_SEC_PROXY_HOST_FUNCTION_RESPONSE,
23+
MBOX_K3_SEC_PROXY_HOST_FUNCTION_HIGH_PRIORITY,
24+
MBOX_K3_SEC_PROXY_HOST_FUNCTION_LOW_PRIORITY,
25+
MBOX_K3_SEC_PROXY_HOST_FUNCTION_NOTIFY_RESP,
2626
} MBOX_K3_SEC_PROXY_HOST_FUNCTION;
2727

2828
/**
2929
* @brief Specifies the direction of data flow for a Secure Proxy thread.
3030
*/
3131
typedef enum {
32-
MSG_DRXN_WRITE = 0,
33-
MSG_DRXN_READ = 1,
32+
MBOX_K3_SEC_PROXY_MSG_DRXN_WRITE = 0,
33+
MBOX_K3_SEC_PROXY_MSG_DRXN_READ = 1,
3434
} MBOX_K3_SEC_PROXY_MSG_DRXN;
3535

3636
/**
3737
* @brief Status codes returned by Secure Proxy APIs.
3838
*/
3939
typedef enum {
40-
STATUS_CODE_NO_ERROR = 0,
41-
STATUS_CODE_THREAD_CORRUPTED = -1,
42-
STATUS_CODE_INCORRECT_DRXN = -2,
43-
STATUS_CODE_NO_DATA = -4,
44-
STATUS_CODE_INVALID_MSG_LEN = -5,
45-
STATUS_CODE_THREAD_CLEAR_FAILED = -6,
46-
STATUS_CODE_DIRTY_HANDOFF = -7,
40+
MBOX_K3_SEC_PROXY_STATUS_CODE_NO_ERROR = 0,
41+
MBOX_K3_SEC_PROXY_STATUS_CODE_THREAD_CORRUPTED = -1,
42+
MBOX_K3_SEC_PROXY_STATUS_CODE_INCORRECT_DRXN = -2,
43+
MBOX_K3_SEC_PROXY_STATUS_CODE_NO_DATA = -4,
44+
MBOX_K3_SEC_PROXY_STATUS_CODE_INVALID_MSG_LEN = -5,
45+
MBOX_K3_SEC_PROXY_STATUS_CODE_THREAD_CLEAR_FAILED = -6,
46+
MBOX_K3_SEC_PROXY_STATUS_CODE_DIRTY_HANDOFF = -7,
4747
} MBOX_K3_SEC_PROXY_STATUS_CODES;
4848

4949
/* bit indices */
@@ -67,15 +67,6 @@ typedef enum {
6767
#define MBOX_K3_SEC_PROXY_DATA_START_OFFSET (0x4U)
6868
#define MBOX_K3_SEC_PROXY_DATA_END_OFFSET (0x3CU) /* completion trigger offset */
6969

70-
/**
71-
* @brief Structure representing a message to be sent or received via Secure
72-
* Proxy.
73-
*/
74-
typedef struct {
75-
size_t len; /**< Length of the message in bytes */
76-
uint32_t *buffer; /**< Pointer to the message data buffer */
77-
} mbox_k3_sec_proxy_msg;
78-
7970
/**
8071
* @brief Hardware configuration for a Secure Proxy instance.
8172
*/
@@ -164,24 +155,30 @@ typedef struct {
164155
.host_function = HOST_FUNCTION_NOTIFY_RESP}
165156
// clang-format on
166157

167-
extern mbox_k3_sec_proxy_desc sec_proxy_desc;
168-
169158
/**
170-
* @brief Verifies the status and configuration of a Secure Proxy thread.
159+
* @brief Verifies the status and configuration of a Secure Proxy thread before
160+
* a transaction.
161+
*
162+
* @desc This function checks for thread corruption, validates the thread's
163+
* configured direction (read/write) against its intended usage, and ensures the
164+
* message queue is not empty if reading.
171165
*
166+
* @param sec_proxy_desc Pointer to the Secure Proxy descriptor.
172167
* @param thread_id The ID of the thread to verify.
173168
* @param msg_drxn Expected message direction (MSG_DRXN_READ or MSG_DRXN_WRITE).
174169
*
175-
* @return int32_t STATUS_CODE_NO_ERROR on success, or respective error codes
176-
* on failure.
170+
* @return int32_t STATUS_CODE_NO_ERROR if the thread is valid and ready,
171+
* otherwise respective error codes.
177172
*/
178-
int32_t mbox_k3_sec_proxy_verify_thread(uint8_t thread_id, uint8_t msg_drxn);
173+
int32_t mbox_k3_sec_proxy_verify_thread(mbox_k3_sec_proxy_desc *sec_proxy_desc, uint8_t thread_id, uint8_t msg_drxn);
179174

180175
/**
181176
* @brief Reads a message from a specific Secure Proxy thread.
182177
*
178+
* @param sec_proxy_desc Pointer to the Secure Proxy descriptor.
183179
* @param thread_id The ID of the thread to read from.
184-
* @param msg Pointer to the structure where the read message will be stored.
180+
* @param buffer Pointer to the buffer where the read message will be stored.
181+
* @param len Length of the message to read in bytes.
185182
*
186183
* @return int32_t STATUS_CODE_NO_ERROR on success, or respective error codes
187184
* on failure.
@@ -191,13 +188,15 @@ int32_t mbox_k3_sec_proxy_verify_thread(uint8_t thread_id, uint8_t msg_drxn);
191188
* for little-endian.
192189
* - byte-ordering logic for trailing bytes assumes LSB-first memory layout.
193190
*/
194-
int32_t mbox_k3_sec_proxy_read(uint8_t thread_id, mbox_k3_sec_proxy_msg *msg);
191+
int32_t mbox_k3_sec_proxy_read(mbox_k3_sec_proxy_desc *sec_proxy_desc, uint8_t thread_id, void* buffer, size_t len);
195192

196193
/**
197194
* @brief Writes a message to a specific Secure Proxy thread.
198195
*
196+
* @param sec_proxy_desc Pointer to the Secure Proxy descriptor.
199197
* @param thread_id The ID of the thread to write to.
200-
* @param msg Pointer to the structure containing the message to send.
198+
* @param buffer Pointer to the buffer containing the message to send.
199+
* @param len Length of the message to send in bytes.
201200
*
202201
* @return int32_t STATUS_CODE_NO_ERROR on success, or an error code on
203202
* failure.
@@ -207,30 +206,33 @@ int32_t mbox_k3_sec_proxy_read(uint8_t thread_id, mbox_k3_sec_proxy_msg *msg);
207206
* for little-endian.
208207
* - byte-ordering logic for trailing bytes assumes LSB-first memory layout.
209208
*/
210-
int32_t mbox_k3_sec_proxy_write(uint8_t thread_id, mbox_k3_sec_proxy_msg *msg);
209+
int32_t mbox_k3_sec_proxy_write(mbox_k3_sec_proxy_desc *sec_proxy_desc, uint8_t thread_id, void* buffer, size_t len);
211210

212211
/**
213212
* @brief Clears all pending messages from a Secure Proxy thread.
214213
*
214+
* @param sec_proxy_desc Pointer to the Secure Proxy descriptor.
215215
* @param thread_id The ID of the thread to clear.
216216
*
217217
* @return int32_t STATUS_CODE_NO_ERROR on success, or an error code on failure.
218218
*/
219-
int32_t mbox_k3_sec_proxy_clear(uint8_t thread_id);
219+
int32_t mbox_k3_sec_proxy_clear(mbox_k3_sec_proxy_desc *sec_proxy_desc, uint8_t thread_id);
220220

221221
/**
222222
* @brief Performs a health check on a Secure Proxy thread and reports status.
223223
*
224+
* @param sec_proxy_desc Pointer to the Secure Proxy descriptor.
224225
* @param thread_id The ID of the thread to probe.
225226
*
226227
* @return int32_t STATUS_CODE_NO_ERROR on success, or respective error codes
227228
* on failure.
228229
*/
229-
int32_t mbox_k3_sec_proxy_probe(uint8_t thread_id);
230+
int32_t mbox_k3_sec_proxy_probe(mbox_k3_sec_proxy_desc *sec_proxy_desc, uint8_t thread_id);
230231

231232
/**
232233
* @brief Protocol-level ping test hook.
233234
*
235+
* @param sec_proxy_desc Pointer to the Secure Proxy descriptor.
234236
* @param thread_id The ID of the thread to test.
235237
*
236238
* @return int32_t STATUS_CODE_NO_ERROR on success, or an error code on failure.
@@ -239,6 +241,6 @@ int32_t mbox_k3_sec_proxy_probe(uint8_t thread_id);
239241
* - this is a weak function; a strong implementation should be provided by
240242
* the platform to verify pipeline cleanliness.
241243
*/
242-
int32_t mbox_k3_sec_proxy_ping_test(uint8_t thread_id);
244+
int32_t mbox_k3_sec_proxy_ping_test(mbox_k3_sec_proxy_desc *sec_proxy_desc, uint8_t thread_id);
243245

244246
#endif /* __MBOX_K3_SEC_PROXY_H_ */

0 commit comments

Comments
 (0)