Skip to content

Commit f3cb05b

Browse files
committed
feat(drivers): add ti k3 secure proxy mailbox driver
1 parent a20a8aa commit f3cb05b

3 files changed

Lines changed: 525 additions & 0 deletions

File tree

Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
/**
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright (c) Bao Project and Contributors. All rights reserved.
4+
*/
5+
6+
#ifndef __MBOX_K3_SEC_PROXY_H_
7+
#define __MBOX_K3_SEC_PROXY_H_
8+
9+
#include <bao.h>
10+
#include <plat/platform.h>
11+
#include <stddef.h>
12+
#include <stdint.h>
13+
#include <types.h>
14+
15+
/**
16+
* @brief Defines the specific host function associated with a Secure Proxy
17+
* thread.
18+
*/
19+
typedef enum {
20+
HOST_FUNCTION_NOTIFY,
21+
HOST_FUNCTION_RESPONSE,
22+
HOST_FUNCTION_HIGH_PRIORITY,
23+
HOST_FUNCTION_LOW_PRIORITY,
24+
HOST_FUNCTION_NOTIFY_RESP,
25+
} MBOX_K3_SEC_PROXY_HOST_FUNCTION;
26+
27+
/**
28+
* @brief Specifies the direction of data flow for a Secure Proxy thread.
29+
*/
30+
typedef enum {
31+
MSG_DRXN_WRITE = 0,
32+
MSG_DRXN_READ = 1,
33+
} MBOX_K3_SEC_PROXY_MSG_DRXN;
34+
35+
/**
36+
* @brief Status codes returned by Secure Proxy APIs.
37+
*/
38+
typedef enum {
39+
STATUS_CODE_NO_ERROR = 0,
40+
STATUS_CODE_THREAD_CORRUPTED = -1,
41+
STATUS_CODE_INCORRECT_DRXN = -2,
42+
STATUS_CODE_NO_DATA = -4,
43+
STATUS_CODE_INVALID_MSG_LEN = -5,
44+
STATUS_CODE_THREAD_CLEAR_FAILED = -6,
45+
} MBOX_K3_SEC_PROXY_STATUS_CODES;
46+
47+
/* bit indices */
48+
#define MBOX_K3_SEC_PROXY_RT_THREAD_STATUS_OFFSET (0x0U)
49+
#define MBOX_K3_SEC_PROXY_RT_THREAD_THRESHOLD_OFFSET (0x4U)
50+
51+
#define MBOX_K3_SEC_PROXY_RT_STATUS_ERROR_IDX (31)
52+
#define MBOX_K3_SEC_PROXY_RT_STATUS_ERROR_MASK (1U << MBOX_K3_SEC_PROXY_RT_STATUS_ERROR_IDX)
53+
54+
#define MBOX_K3_SEC_PROXY_RT_STATUS_CUR_CNT_IDX (0)
55+
#define MBOX_K3_SEC_PROXY_RT_STATUS_CUR_CNT_MASK (0xFFU << MBOX_K3_SEC_PROXY_RT_STATUS_CUR_CNT_IDX)
56+
57+
#define MBOX_K3_SEC_PROXY_SCFG_THREAD_CTRL_OFFSET (0x1000U)
58+
59+
#define MBOX_K3_SEC_PROXY_SCFG_THREAD_CTRL_DIR_IDX (31)
60+
#define MBOX_K3_SEC_PROXY_SCFG_THREAD_CTRL_DIR_MASK \
61+
(1U << MBOX_K3_SEC_PROXY_SCFG_THREAD_CTRL_DIR_IDX)
62+
63+
#define MBOX_K3_SEC_PROXY_THREAD_OFFSET(thread_id) (0x1000U * (thread_id))
64+
65+
#define MBOX_K3_SEC_PROXY_DATA_START_OFFSET (0x4U)
66+
#define MBOX_K3_SEC_PROXY_DATA_END_OFFSET (0x3CU) /* completion trigger offset */
67+
68+
/**
69+
* @brief Structure representing a message to be sent or received via Secure
70+
* Proxy.
71+
*/
72+
typedef struct {
73+
size_t len; /**< Length of the message in bytes */
74+
uint32_t *buffer; /**< Pointer to the message data buffer */
75+
} mbox_k3_sec_proxy_msg;
76+
77+
/**
78+
* @brief Hardware configuration for a Secure Proxy instance.
79+
*/
80+
typedef struct {
81+
/* note: declared as a 32-bit val because it is kept as such in u-boot
82+
* implementation. However, in J721E, there are only 2 supported sec_proxy
83+
* IDs:
84+
* 0 => NAVSS0_SEC_PROXY_0
85+
* 1 => MCU_NAVSS0_SEC_PROXY0
86+
* can modify type based on requirements...
87+
*/
88+
uint32_t id; /**< Instance ID (e.g., NAVSS0_SEC_PROXY_0) */
89+
90+
paddr_t rt_base; /**< Base address of Real-Time (RT) region */
91+
size_t rt_size; /**< Size of RT region */
92+
93+
paddr_t scfg_base; /**< Base address of Secure Configuration (SCFG) region */
94+
size_t scfg_size; /**< Size of SCFG region */
95+
96+
paddr_t data_base; /**< Base address of Data region */
97+
size_t data_size; /**< Size of Data region */
98+
99+
size_t max_msg_size;
100+
} mbox_k3_sec_proxy_instance;
101+
102+
/**
103+
* @brief Configuration descriptor for a single Secure Proxy thread.
104+
*/
105+
typedef struct {
106+
uint8_t sec_proxy_thread_id; /**< Secure Proxy thread ID */
107+
MBOX_K3_SEC_PROXY_MSG_DRXN msg_drxn; /**< Message direction (Read/Write) */
108+
uint8_t mbox_queue_depth; /**< Depth of the mailbox queue */
109+
uint8_t host_id; /**< ID of the host associated with this thread */
110+
MBOX_K3_SEC_PROXY_HOST_FUNCTION
111+
host_function; /**< Function/Role of the thread */
112+
uint16_t irq_line_threshold; /**< IRQ threshold configuration */
113+
uint16_t irq_line_error; /**< IRQ error configuration */
114+
} mbox_k3_sec_proxy_thread_desc;
115+
116+
/**
117+
* @brief Top-level descriptor aggregating the Secure Proxy instance and its
118+
* thread configurations.
119+
*/
120+
typedef struct {
121+
mbox_k3_sec_proxy_instance thread_inst; /**< Secure Proxy instance configuration */
122+
mbox_k3_sec_proxy_thread_desc sec_proxy_thread_desc[]; /**< Array of thread descriptors */
123+
} mbox_k3_sec_proxy_desc;
124+
125+
// clang-format off
126+
#define MBOX_K3_SEC_PROXY_THREAD_DESC_ENTRY( \
127+
host, base_thread_id, notify_queue_depth, resp_queue_depth, \
128+
high_priority_queue_depth, low_priority_queue_depth) \
129+
[base_thread_id] = \
130+
(mbox_k3_sec_proxy_thread_desc){ \
131+
.sec_proxy_thread_id = base_thread_id, \
132+
.msg_drxn = MSG_DRXN_READ, \
133+
.mbox_queue_depth = notify_queue_depth, \
134+
.host_id = host, \
135+
.host_function = HOST_FUNCTION_NOTIFY}, \
136+
[base_thread_id + 1] = \
137+
(mbox_k3_sec_proxy_thread_desc){ \
138+
.sec_proxy_thread_id = (base_thread_id + 1), \
139+
.msg_drxn = MSG_DRXN_READ, \
140+
.mbox_queue_depth = resp_queue_depth, \
141+
.host_id = host, \
142+
.host_function = HOST_FUNCTION_RESPONSE}, \
143+
[base_thread_id + 2] = \
144+
(mbox_k3_sec_proxy_thread_desc){ \
145+
.sec_proxy_thread_id = (base_thread_id + 2), \
146+
.msg_drxn = MSG_DRXN_WRITE, \
147+
.mbox_queue_depth = high_priority_queue_depth, \
148+
.host_id = host, \
149+
.host_function = HOST_FUNCTION_HIGH_PRIORITY}, \
150+
[base_thread_id + 3] = \
151+
(mbox_k3_sec_proxy_thread_desc){ \
152+
.sec_proxy_thread_id = (base_thread_id + 3), \
153+
.msg_drxn = MSG_DRXN_WRITE, \
154+
.mbox_queue_depth = low_priority_queue_depth, \
155+
.host_id = host, \
156+
.host_function = HOST_FUNCTION_LOW_PRIORITY}, \
157+
[base_thread_id + 4] = \
158+
(mbox_k3_sec_proxy_thread_desc) { \
159+
.sec_proxy_thread_id = (base_thread_id + 4), \
160+
.msg_drxn = MSG_DRXN_WRITE, \
161+
.mbox_queue_depth = 2, .host_id = host, \
162+
.host_function = HOST_FUNCTION_NOTIFY_RESP}
163+
// clang-format on
164+
165+
extern mbox_k3_sec_proxy_desc sec_proxy_desc;
166+
167+
/**
168+
* @brief Verifies the status and configuration of a Secure Proxy thread.
169+
*
170+
* @param thread_id The ID of the thread to verify.
171+
* @param msg_drxn Expected message direction (MSG_DRXN_READ or MSG_DRXN_WRITE).
172+
*
173+
* @return int32_t STATUS_CODE_NO_ERROR on success, or respective error codes
174+
* on failure.
175+
*/
176+
int32_t mbox_k3_sec_proxy_verify_thread(uint8_t thread_id, uint8_t msg_drxn);
177+
178+
/**
179+
* @brief Reads a message from a specific Secure Proxy thread.
180+
*
181+
* @param thread_id The ID of the thread to read from.
182+
* @param msg Pointer to the structure where the read message will be stored.
183+
*
184+
* @return int32_t STATUS_CODE_NO_ERROR on success, or respective error codes
185+
* on failure.
186+
*
187+
* @notes
188+
* - does not support little-endian systems, current implementation only is
189+
* for big-endian.
190+
* - byte-ordering logic for trailing bytes assumes MSB-first memory layout.
191+
*/
192+
int32_t mbox_k3_sec_proxy_read(uint8_t thread_id, mbox_k3_sec_proxy_msg *msg);
193+
194+
/**
195+
* @brief Writes a message to a specific Secure Proxy thread.
196+
*
197+
* @param thread_id The ID of the thread to write to.
198+
* @param msg Pointer to the structure containing the message to send.
199+
*
200+
* @return int32_t STATUS_CODE_NO_ERROR on success, or an error code on
201+
* failure.
202+
*
203+
* @notes
204+
* - does not support little-endian systems, current implementation only is
205+
* for big-endian.
206+
* - byte-ordering logic for trailing bytes assumes MSB-first memory layout.
207+
*/
208+
int32_t mbox_k3_sec_proxy_write(uint8_t thread_id, mbox_k3_sec_proxy_msg *msg);
209+
210+
/**
211+
* @brief Clears all pending messages from a Secure Proxy thread.
212+
*
213+
* @param thread_id The ID of the thread to clear.
214+
*
215+
* @return int32_t STATUS_CODE_NO_ERROR on success, or an error code on failure.
216+
*/
217+
int32_t mbox_k3_sec_proxy_clear(uint8_t thread_id);
218+
219+
/**
220+
* @brief Performs a health check on a Secure Proxy thread and reports status.
221+
*
222+
* @param thread_id The ID of the thread to probe.
223+
*
224+
* @return int32_t STATUS_CODE_NO_ERROR on success, or respective error codes
225+
* on failure.
226+
*/
227+
int32_t mbox_k3_sec_proxy_probe(uint8_t thread_id);
228+
229+
#endif /* __MBOX_K3_SEC_PROXY_H_ */

0 commit comments

Comments
 (0)