Skip to content

Commit b6cc338

Browse files
committed
fix: various system init, build, and K3 driver fixes
- Move console initialization before platform initialization. - Remove hw host ownership check from K3 sec proxy probe. - Add missing newlines to logging macros across TISCI and K3 proxy drivers. - Fix definition generation build issue for BeagleBone-AI64. Signed-off-by: puranikvinit <kvp933.vinit@gmail.com>
1 parent be10aa6 commit b6cc338

4 files changed

Lines changed: 38 additions & 51 deletions

File tree

src/core/init.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ void init(cpuid_t cpu_id)
2424

2525
/* -------------------------------------------------------------- */
2626

27-
platform_init();
28-
2927
console_init();
3028

29+
platform_init();
30+
3131
if (cpu_is_master()) {
3232
console_printk("Bao Hypervisor\n\r");
3333
}

src/platform/beaglebone-ai64/inc/plat/platform.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88

99
#define UART8250_REG_WIDTH (4U)
1010

11+
#ifndef GENERATING_DEFS
1112
#include <drivers/8250_uart.h>
1213
#include <drivers/k3_sec_proxy.h>
1314
#include <drivers/tisci.h>
15+
#endif
1416

1517
/* j721e host id enumeration */
1618
#define J721E_HOST_ID_MAIN_A72_CONTEXT_0_SECURE (10)

src/platform/drivers/firmware/tisci.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ static int32_t _get_rsp(tisci_ctx* ctx, uint8_t chan_id, void* rx_buf, size_t rx
6363

6464
/* Validate buffer size before receiving to prevent overflow */
6565
if (rx_len > TISCI_MSG_MAX_SIZE) {
66-
ERROR("channel_%d expected msg len too long", chan_id);
66+
ERROR("channel_%d expected msg len too long\n", chan_id);
6767
return TISCI_STATUS_CODE_INVALID_MSG_LEN;
6868
}
6969

7070
unsigned int retry_iterator = TISCI_MSG_NUM_RETRIES;
7171
for (; retry_iterator > 0; retry_iterator--) {
7272
int32_t recv_status = ctx->ops.recv(chan_id, rx_buf, rx_len);
7373
if (TISCI_STATUS_CODE_NO_ERROR != recv_status) {
74-
ERROR("channel_%d tisci msg rcv failed", chan_id);
74+
ERROR("channel_%d tisci msg rcv failed\n", chan_id);
7575
return TISCI_STATUS_CODE_MSG_RCV_FAILED;
7676
}
7777

@@ -80,19 +80,19 @@ static int32_t _get_rsp(tisci_ctx* ctx, uint8_t chan_id, void* rx_buf, size_t rx
8080
if (msg_hdr->seq_id == expected_seq_id) {
8181
break;
8282
} else {
83-
WARNING("channel_%d unexpected seq_id (rcvd=%d, expected=%d)", chan_id, msg_hdr->seq_id,
83+
ERROR("channel_%d unexpected seq_id (rcvd=%d, expected=%d)\n", chan_id, msg_hdr->seq_id,
8484
expected_seq_id);
8585
}
8686
}
8787

8888
if (0 == retry_iterator) {
89-
ERROR("channel_%d timed out waiting for msg", chan_id);
89+
ERROR("channel_%d timed out waiting for msg\n", chan_id);
9090
return TISCI_STATUS_CODE_MSG_RX_TIMEOUT;
9191
}
9292

9393
/* Check if the DMSC acknowledged the request */
9494
if (0 == (msg_hdr->msg_flags & TISCI_MSG_RSP_FLAG_ACK)) {
95-
ERROR("channel_%d no ack rcvd", chan_id);
95+
ERROR("channel_%d no ack rcvd\n", chan_id);
9696
return TISCI_STATUS_CODE_NO_ACK_RCVD;
9797
}
9898

@@ -131,13 +131,13 @@ static int32_t _perform_txn(tisci_ctx* ctx, txn_ctx* tx_ctx, txn_ctx* rx_ctx, ui
131131
{
132132
int32_t txn_status = ctx->ops.send(tx_ctx->chan_id, tx_ctx->buff, tx_ctx->buff_len);
133133
if (TISCI_STATUS_CODE_NO_ERROR != txn_status) {
134-
ERROR("channel_%d txn - write failed", tx_ctx->chan_id);
134+
ERROR("channel_%d txn - write failed\n", tx_ctx->chan_id);
135135
return TISCI_STATUS_CODE_MSG_SEND_FAILED;
136136
}
137137

138138
txn_status = _get_rsp(ctx, rx_ctx->chan_id, rx_ctx->buff, rx_ctx->buff_len, seq_id);
139139
if (TISCI_STATUS_CODE_NO_ERROR != txn_status) {
140-
ERROR("channel_%d txn - read failed", rx_ctx->chan_id);
140+
ERROR("channel_%d txn - read failed\n", rx_ctx->chan_id);
141141
return txn_status;
142142
}
143143

@@ -158,7 +158,7 @@ int32_t tisci_get_revision(tisci_ctx* ctx, uint8_t host_id, uint8_t tx_chan_id,
158158

159159
int32_t rev_status = _setup_hdr(ctx, &msg_header, sizeof(msg_header));
160160
if (TISCI_STATUS_CODE_NO_ERROR != rev_status) {
161-
ERROR("channel_%d msg hdr setup failed", tx_chan_id);
161+
ERROR("channel_%d msg hdr setup failed\n", tx_chan_id);
162162
spin_unlock(&(ctx->seq_id_lock));
163163
return rev_status;
164164
}
@@ -179,7 +179,7 @@ int32_t tisci_get_revision(tisci_ctx* ctx, uint8_t host_id, uint8_t tx_chan_id,
179179
rev_status = _perform_txn(ctx, &tx_ctx, &rx_ctx, cur_seq_id);
180180

181181
if (TISCI_STATUS_CODE_NO_ERROR != rev_status) {
182-
ERROR("channel_%d tisci txn failed", tx_chan_id);
182+
ERROR("channel_%d tisci txn failed\n", tx_chan_id);
183183
return rev_status;
184184
}
185185

@@ -200,7 +200,7 @@ int32_t tisci_rm_irq_set(tisci_ctx* ctx, uint8_t host_id, uint8_t tx_chan_id, ui
200200

201201
int32_t rev_status = _setup_hdr(ctx, &msg_header, sizeof(msg_header));
202202
if (TISCI_STATUS_CODE_NO_ERROR != rev_status) {
203-
ERROR("channel_%d msg hdr setup failed", tx_chan_id);
203+
ERROR("channel_%d msg hdr setup failed\n", tx_chan_id);
204204
spin_unlock(&(ctx->seq_id_lock));
205205
return rev_status;
206206
}
@@ -223,7 +223,7 @@ int32_t tisci_rm_irq_set(tisci_ctx* ctx, uint8_t host_id, uint8_t tx_chan_id, ui
223223
rev_status = _perform_txn(ctx, &tx_ctx, &rx_ctx, cur_seq_id);
224224

225225
if (TISCI_STATUS_CODE_NO_ERROR != rev_status) {
226-
ERROR("channel_%d tisci txn failed", tx_chan_id);
226+
ERROR("channel_%d tisci txn failed\n", tx_chan_id);
227227
return rev_status;
228228
}
229229

@@ -245,7 +245,7 @@ int32_t tisci_rm_irq_release(tisci_ctx* ctx, uint8_t host_id, uint8_t tx_chan_id
245245

246246
int32_t rev_status = _setup_hdr(ctx, &msg_header, sizeof(msg_header));
247247
if (TISCI_STATUS_CODE_NO_ERROR != rev_status) {
248-
ERROR("channel_%d msg hdr setup failed", tx_chan_id);
248+
ERROR("channel_%d msg hdr setup failed\n", tx_chan_id);
249249
spin_unlock(&(ctx->seq_id_lock));
250250
return rev_status;
251251
}
@@ -268,7 +268,7 @@ int32_t tisci_rm_irq_release(tisci_ctx* ctx, uint8_t host_id, uint8_t tx_chan_id
268268
rev_status = _perform_txn(ctx, &tx_ctx, &rx_ctx, cur_seq_id);
269269

270270
if (TISCI_STATUS_CODE_NO_ERROR != rev_status) {
271-
ERROR("channel_%d tisci txn failed", tx_chan_id);
271+
ERROR("channel_%d tisci txn failed\n", tx_chan_id);
272272
return rev_status;
273273
}
274274

src/platform/drivers/mailbox/k3_sec_proxy.c

Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
* @return The 32-bit value read from the register.
1515
*/
1616
static inline uint32_t read_reg(paddr_t addr, paddr_t offset)
17-
{
18-
return *((volatile uint32_t*)((paddr_t)(addr + offset)));
19-
}
17+
{ return *((volatile uint32_t*)((paddr_t)(addr + offset))); }
2018

2119
/**
2220
* @brief Writes a 32-bit value to a memory-mapped register.
@@ -26,9 +24,7 @@ static inline uint32_t read_reg(paddr_t addr, paddr_t offset)
2624
* @param value The 32-bit value to write.
2725
*/
2826
static inline void write_reg(paddr_t addr, paddr_t offset, uint32_t value)
29-
{
30-
*((volatile uint32_t*)((paddr_t)(addr + offset))) = value;
31-
}
27+
{ *((volatile uint32_t*)((paddr_t)(addr + offset))) = value; }
3228

3329
int32_t mbox_k3_sec_proxy_verify_thread(mbox_k3_sec_proxy_desc* sec_proxy_desc, uint8_t thread_id,
3430
uint8_t msg_drxn)
@@ -41,7 +37,7 @@ int32_t mbox_k3_sec_proxy_verify_thread(mbox_k3_sec_proxy_desc* sec_proxy_desc,
4137
/* check for existing errors */
4238
if (read_reg(thread_rt_base, MBOX_K3_SEC_PROXY_RT_THREAD_STATUS_OFFSET) &
4339
MBOX_K3_SEC_PROXY_RT_STATUS_ERROR_MASK) {
44-
ERROR("secure_proxy_thread_%d corrupted", thread_id);
40+
ERROR("secure_proxy_thread_%d corrupted\n", thread_id);
4541
return MBOX_K3_SEC_PROXY_STATUS_CODE_THREAD_CORRUPTED;
4642
}
4743

@@ -51,10 +47,10 @@ int32_t mbox_k3_sec_proxy_verify_thread(mbox_k3_sec_proxy_desc* sec_proxy_desc,
5147
MBOX_K3_SEC_PROXY_SCFG_THREAD_CTRL_DIR_IDX !=
5248
msg_drxn) {
5349
if (MBOX_K3_SEC_PROXY_MSG_DRXN_WRITE == msg_drxn) {
54-
ERROR("secure_proxy_thread_%d cannot READ on WRITE thread", thread_id);
50+
ERROR("secure_proxy_thread_%d cannot READ on WRITE thread\n", thread_id);
5551
return MBOX_K3_SEC_PROXY_STATUS_CODE_INCORRECT_DRXN;
5652
} else {
57-
ERROR("secure_proxy_thread_%d cannot WRITE on READ thread", thread_id);
53+
ERROR("secure_proxy_thread_%d cannot WRITE on READ thread\n", thread_id);
5854
return MBOX_K3_SEC_PROXY_STATUS_CODE_INCORRECT_DRXN;
5955
}
6056
}
@@ -68,7 +64,6 @@ int32_t mbox_k3_sec_proxy_verify_thread(mbox_k3_sec_proxy_desc* sec_proxy_desc,
6864
MBOX_K3_SEC_PROXY_RT_STATUS_CUR_CNT_MASK)) {
6965
if ((sysreg_cntpct_el0_read() - tick_start) >
7066
(sec_proxy_desc->read_timeout_us * ticks_per_us)) {
71-
ERROR("secure_proxy_thread_%d no entries in message queue", thread_id);
7267
return MBOX_K3_SEC_PROXY_STATUS_CODE_NO_DATA;
7368
}
7469
}
@@ -108,7 +103,11 @@ int32_t mbox_k3_sec_proxy_read(mbox_k3_sec_proxy_desc* sec_proxy_desc, uint8_t t
108103
int32_t read_status =
109104
mbox_k3_sec_proxy_verify_thread(sec_proxy_desc, thread_id, MBOX_K3_SEC_PROXY_MSG_DRXN_READ);
110105
if (MBOX_K3_SEC_PROXY_STATUS_CODE_NO_ERROR != read_status) {
111-
ERROR("secure_proxy_thread_%d thread verif failed", thread_id);
106+
if (MBOX_K3_SEC_PROXY_STATUS_CODE_NO_DATA == read_status) {
107+
ERROR("secure_proxy_thread_%d no entries in message queue\n", thread_id);
108+
} else {
109+
ERROR("secure_proxy_thread_%d thread verif failed\n", thread_id);
110+
}
112111
return read_status;
113112
}
114113

@@ -143,7 +142,7 @@ int32_t mbox_k3_sec_proxy_read(mbox_k3_sec_proxy_desc* sec_proxy_desc, uint8_t t
143142
read_reg(data_reg, MBOX_K3_SEC_PROXY_DATA_END_OFFSET - MBOX_K3_SEC_PROXY_DATA_START_OFFSET);
144143
}
145144

146-
INFO("secure_proxy_thread_%d data READ success", thread_id);
145+
INFO("secure_proxy_thread_%d data READ success\n", thread_id);
147146

148147
return read_status;
149148
}
@@ -184,13 +183,13 @@ int32_t mbox_k3_sec_proxy_write(mbox_k3_sec_proxy_desc* sec_proxy_desc, uint8_t
184183
int32_t write_status = mbox_k3_sec_proxy_verify_thread(sec_proxy_desc, thread_id,
185184
MBOX_K3_SEC_PROXY_MSG_DRXN_WRITE);
186185
if (MBOX_K3_SEC_PROXY_STATUS_CODE_NO_ERROR != write_status) {
187-
ERROR("secure_proxy_thread_%d thread verif failed", thread_id);
186+
ERROR("secure_proxy_thread_%d thread verif failed\n", thread_id);
188187
return write_status;
189188
}
190189

191190
/* msg len check */
192191
if (len > sec_proxy_desc->thread_inst.max_msg_size) {
193-
ERROR("secure_proxy_thread_%d msg len exceeds limit", thread_id);
192+
ERROR("secure_proxy_thread_%d msg len exceeds limit\n", thread_id);
194193
return MBOX_K3_SEC_PROXY_STATUS_CODE_INVALID_MSG_LEN;
195194
}
196195

@@ -228,7 +227,7 @@ int32_t mbox_k3_sec_proxy_write(mbox_k3_sec_proxy_desc* sec_proxy_desc, uint8_t
228227
write_reg(data_reg, word_iterator++ * sizeof(uint32_t), 0U);
229228
}
230229

231-
INFO("secure_proxy_thread_%d data WRITE success", thread_id);
230+
INFO("secure_proxy_thread_%d data WRITE success\n", thread_id);
232231

233232
return write_status;
234233
}
@@ -238,7 +237,7 @@ int32_t mbox_k3_sec_proxy_clear(mbox_k3_sec_proxy_desc* sec_proxy_desc, uint8_t
238237
int32_t clear_status =
239238
mbox_k3_sec_proxy_verify_thread(sec_proxy_desc, thread_id, MBOX_K3_SEC_PROXY_MSG_DRXN_READ);
240239
if (MBOX_K3_SEC_PROXY_STATUS_CODE_NO_ERROR != clear_status) {
241-
ERROR("secure_proxy_thread_%d thread verif failed", thread_id);
240+
ERROR("secure_proxy_thread_%d thread verif failed\n", thread_id);
242241
return clear_status;
243242
}
244243

@@ -252,11 +251,11 @@ int32_t mbox_k3_sec_proxy_clear(mbox_k3_sec_proxy_desc* sec_proxy_desc, uint8_t
252251
(read_reg(thread_rt_base, MBOX_K3_SEC_PROXY_RT_THREAD_STATUS_OFFSET) &
253252
MBOX_K3_SEC_PROXY_RT_STATUS_CUR_CNT_MASK)) {
254253
if (0 == (try_count--)) {
255-
ERROR("secure_proxy_thread_%d mailbox clear failed", thread_id);
254+
ERROR("secure_proxy_thread_%d mailbox clear failed\n", thread_id);
256255
return MBOX_K3_SEC_PROXY_STATUS_CODE_THREAD_CLEAR_FAILED;
257256
}
258257

259-
WARNING("secure_proxy_thread_%d mailbox clear in progress", thread_id);
258+
WARNING("secure_proxy_thread_%d mailbox clear in progress\n", thread_id);
260259
read_reg(data_reg, MBOX_K3_SEC_PROXY_DATA_END_OFFSET);
261260
}
262261

@@ -265,28 +264,14 @@ int32_t mbox_k3_sec_proxy_clear(mbox_k3_sec_proxy_desc* sec_proxy_desc, uint8_t
265264

266265
int32_t mbox_k3_sec_proxy_probe(mbox_k3_sec_proxy_desc* sec_proxy_desc, uint8_t thread_id)
267266
{
268-
paddr_t thread_scfg_base =
269-
sec_proxy_desc->thread_inst.scfg_base + MBOX_K3_SEC_PROXY_THREAD_OFFSET(thread_id);
270-
uint32_t config = read_reg(thread_scfg_base, MBOX_K3_SEC_PROXY_SCFG_THREAD_CTRL_OFFSET);
271-
272-
uint8_t hw_host = (config >> 8) & 0xFF;
273-
uint8_t expected_host = sec_proxy_desc->sec_proxy_thread_desc[thread_id].host_id;
274-
275-
/* [step-1] verify thread access/host ownership */
276-
if (hw_host != expected_host) {
277-
ERROR("sec_proxy_thread_%d probe failed (hw_host=%d, expected=%d)", thread_id, hw_host,
278-
expected_host);
279-
return MBOX_K3_SEC_PROXY_STATUS_CODE_THREAD_CORRUPTED;
280-
}
281-
282-
/* [step-2] verify if thread is clean */
267+
/* verify if thread is clean */
283268
int32_t probe_status = mbox_k3_sec_proxy_verify_thread(sec_proxy_desc, thread_id,
284269
sec_proxy_desc->sec_proxy_thread_desc[thread_id].msg_drxn);
285270

286271
if (MBOX_K3_SEC_PROXY_MSG_DRXN_READ ==
287272
sec_proxy_desc->sec_proxy_thread_desc[thread_id].msg_drxn &&
288273
MBOX_K3_SEC_PROXY_STATUS_CODE_NO_ERROR == probe_status) {
289-
ERROR("secure_proxy_thread_%d probe failed (message queue not clean)", thread_id);
274+
ERROR("secure_proxy_thread_%d probe failed (message queue not clean)\n", thread_id);
290275
return MBOX_K3_SEC_PROXY_STATUS_CODE_DIRTY_HANDOFF;
291276
}
292277

@@ -297,11 +282,11 @@ int32_t mbox_k3_sec_proxy_probe(mbox_k3_sec_proxy_desc* sec_proxy_desc, uint8_t
297282
}
298283

299284
if (MBOX_K3_SEC_PROXY_STATUS_CODE_NO_ERROR != probe_status) {
300-
INFO("sec_proxy_thread_%d probe failed (error_id=%d)", thread_id, probe_status);
285+
INFO("sec_proxy_thread_%d probe failed (error_id=%d)\n", thread_id, probe_status);
301286
return probe_status;
302287
}
303288

304-
INFO("sec_proxy_thread_%d probe success", thread_id);
289+
INFO("sec_proxy_thread_%d probe success\n", thread_id);
305290
return probe_status;
306291
}
307292

0 commit comments

Comments
 (0)