Skip to content

Commit b9e5f1f

Browse files
iabdalkaderdpgeorge
authored andcommitted
alif/se_services: Add a secondary MHU channel.
This channel can be used to communicate (pass messages) between the M55 cores in the RTSS. Currently it's only used to notify the cores. Signed-off-by: iabdalkader <[email protected]>
1 parent facd0b7 commit b9e5f1f

File tree

2 files changed

+93
-31
lines changed

2 files changed

+93
-31
lines changed

ports/alif/se_services.c

Lines changed: 89 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@
3737
#include "py/mphal.h"
3838

3939
// MHU indices.
40-
#define MHU_M55_SE_MHU0 0
41-
#define MAX_MHU 1
40+
#define MHU_SESS_MHU0 0
41+
#define MHU_RTSS_MHU0 1
42+
#define MAX_MHU 2
4243

4344
// The following timeout is implemented in se_services_handle.c as a
4445
// simple loop busy polling on a variable set from an IRQ.
@@ -57,39 +58,78 @@ typedef struct {
5758

5859
static const uint32_t mhu_sender_base_address_list[MAX_MHU] = {
5960
MHU_SESS_S_TX_BASE,
61+
MHU_RTSS_S_TX_BASE
6062
};
6163

6264
static const uint32_t mhu_receiver_base_address_list[MAX_MHU] = {
6365
MHU_SESS_S_RX_BASE,
66+
MHU_RTSS_S_RX_BASE
6467
};
6568

6669
// Must be aligned as a uint32_t.
6770
static uint32_t packet_buffer[SERVICES_MAX_PACKET_BUFFER_SIZE / sizeof(uint32_t)];
6871

72+
static uint32_t se_sess_handle;
73+
static uint32_t se_rtss_handle;
74+
6975
static mhu_driver_out_t mhu_driver_out;
70-
static uint32_t se_services_handle;
7176

7277
void MHU_SESS_S_TX_IRQHandler(void) {
73-
mhu_driver_out.sender_irq_handler(MHU_M55_SE_MHU0);
78+
mhu_driver_out.sender_irq_handler(MHU_SESS_MHU0);
7479
}
7580

7681
void MHU_SESS_S_RX_IRQHandler(void) {
77-
mhu_driver_out.receiver_irq_handler(MHU_M55_SE_MHU0);
82+
mhu_driver_out.receiver_irq_handler(MHU_SESS_MHU0);
83+
}
84+
85+
void MHU_RTSS_S_TX_IRQHandler(void) {
86+
mhu_driver_out.sender_irq_handler(MHU_RTSS_MHU0);
87+
}
88+
89+
void MHU_RTSS_S_RX_IRQHandler(void) {
90+
mhu_driver_out.receiver_irq_handler(MHU_RTSS_MHU0);
7891
}
7992

8093
int dummy_printf(const char *fmt, ...) {
8194
(void)fmt;
8295
return 0;
8396
}
8497

98+
static void se_services_irq_config(IRQn_Type irqn, bool enable) {
99+
if (enable) {
100+
NVIC_ClearPendingIRQ(irqn);
101+
NVIC_SetPriority(irqn, IRQ_PRI_MHU);
102+
NVIC_EnableIRQ(irqn);
103+
} else {
104+
NVIC_DisableIRQ(irqn);
105+
NVIC_ClearPendingIRQ(irqn);
106+
}
107+
}
108+
109+
void se_services_rx_callback(uint32_t id, uint32_t channel, uint32_t data) {
110+
switch (id) {
111+
case MHU_SESS_MHU0:
112+
SERVICES_rx_msg_callback(id, channel, data);
113+
break;
114+
case MHU_RTSS_MHU0:
115+
#if MICROPY_PY_OPENAMP
116+
extern void metal_rproc_notified(void);
117+
metal_rproc_notified();
118+
#endif
119+
break;
120+
default:
121+
break;
122+
}
123+
}
124+
85125
void se_services_init(void) {
86126
// Initialize MHU.
87127
mhu_driver_in_t mhu_driver_in;
88128
mhu_driver_in.sender_base_address_list = (uint32_t *)mhu_sender_base_address_list;
89129
mhu_driver_in.receiver_base_address_list = (uint32_t *)mhu_receiver_base_address_list;
90130
mhu_driver_in.mhu_count = MAX_MHU;
91131
mhu_driver_in.send_msg_acked_callback = SERVICES_send_msg_acked_callback;
92-
mhu_driver_in.rx_msg_callback = SERVICES_rx_msg_callback;
132+
mhu_driver_in.rx_msg_callback = se_services_rx_callback;
93133
mhu_driver_in.debug_print = NULL; // not currently used by MHU_driver_initialize
94134
MHU_driver_initialize(&mhu_driver_in, &mhu_driver_out);
95135

@@ -103,29 +143,38 @@ void se_services_init(void) {
103143
};
104144
SERVICES_initialize(&services_init_params);
105145

106-
// Create SE services channel for sending requests.
107-
se_services_handle = SERVICES_register_channel(MHU_M55_SE_MHU0, 0);
146+
// Register SESS MHU channel.
147+
se_sess_handle = SERVICES_register_channel(MHU_SESS_MHU0, 0);
148+
se_services_irq_config(MHU_SESS_S_RX_IRQ_IRQn, true);
149+
se_services_irq_config(MHU_SESS_S_TX_IRQ_IRQn, true);
108150

109-
// Enable MHU interrupts.
110-
NVIC_ClearPendingIRQ(MHU_SESS_S_RX_IRQ_IRQn);
111-
NVIC_SetPriority(MHU_SESS_S_RX_IRQ_IRQn, IRQ_PRI_MHU);
112-
NVIC_EnableIRQ(MHU_SESS_S_RX_IRQ_IRQn);
113-
NVIC_ClearPendingIRQ(MHU_SESS_S_TX_IRQ_IRQn);
114-
NVIC_SetPriority(MHU_SESS_S_TX_IRQ_IRQn, IRQ_PRI_MHU);
115-
NVIC_EnableIRQ(MHU_SESS_S_TX_IRQ_IRQn);
151+
// Register RTSS MHU channel.
152+
se_rtss_handle = SERVICES_register_channel(MHU_RTSS_MHU0, 0);
153+
se_services_irq_config(MHU_RTSS_S_RX_IRQ_IRQn, true);
154+
se_services_irq_config(MHU_RTSS_S_TX_IRQ_IRQn, true);
116155

117156
// Send heartbeat services requests until one succeeds.
118-
SERVICES_synchronize_with_se(se_services_handle);
157+
SERVICES_synchronize_with_se(se_sess_handle);
158+
}
159+
160+
void se_services_deinit(void) {
161+
// Disable SESS MHU channel IRQs.
162+
se_services_irq_config(MHU_SESS_S_RX_IRQ_IRQn, false);
163+
se_services_irq_config(MHU_SESS_S_TX_IRQ_IRQn, false);
164+
165+
// Disable RTSS MHU channel IRQs.
166+
se_services_irq_config(MHU_RTSS_S_RX_IRQ_IRQn, false);
167+
se_services_irq_config(MHU_RTSS_S_TX_IRQ_IRQn, false);
119168
}
120169

121170
void se_services_dump_device_data(void) {
122171
uint32_t error_code;
123172

124173
uint8_t revision[80];
125-
SERVICES_get_se_revision(se_services_handle, revision, &error_code);
174+
SERVICES_get_se_revision(se_sess_handle, revision, &error_code);
126175

127176
SERVICES_version_data_t data;
128-
SERVICES_system_get_device_data(se_services_handle, &data, &error_code);
177+
SERVICES_system_get_device_data(se_sess_handle, &data, &error_code);
129178

130179
printf("SE revision: %s\n", revision);
131180
printf("ALIF_PN: %s\n", data.ALIF_PN);
@@ -141,11 +190,11 @@ void se_services_dump_device_data(void) {
141190

142191
void se_services_get_unique_id(uint8_t id[8]) {
143192
uint32_t error_code;
144-
SERVICES_system_get_eui_extension(se_services_handle, false, id, &error_code);
193+
SERVICES_system_get_eui_extension(se_sess_handle, false, id, &error_code);
145194
}
146195

147196
__attribute__((noreturn)) void se_services_reset_soc(void) {
148-
SERVICES_boot_reset_soc(se_services_handle);
197+
SERVICES_boot_reset_soc(se_sess_handle);
149198
NVIC_SystemReset();
150199
}
151200

@@ -155,7 +204,7 @@ uint64_t se_services_rand64(void) {
155204
for (int retry = 0; retry < 100; ++retry) {
156205
uint64_t value;
157206
int32_t error_code;
158-
uint32_t ret = SERVICES_cryptocell_get_rnd(se_services_handle, sizeof(uint64_t), &value, &error_code);
207+
uint32_t ret = SERVICES_cryptocell_get_rnd(se_sess_handle, sizeof(uint64_t), &value, &error_code);
159208
if (ret == SERVICES_REQ_SUCCESS) {
160209
return value;
161210
}
@@ -165,51 +214,59 @@ uint64_t se_services_rand64(void) {
165214
return 0;
166215
}
167216

217+
uint32_t se_services_notify(void) {
218+
uint32_t ret = SERVICES_send_msg(se_rtss_handle, LocalToGlobal(0));
219+
if (ret != SERVICES_REQ_SUCCESS) {
220+
return -1;
221+
}
222+
return 0;
223+
}
224+
168225
uint32_t se_services_enable_clock(clock_enable_t clock, bool enable) {
169226
uint32_t error_code;
170-
SERVICES_clocks_enable_clock(se_services_handle, clock, enable, &error_code);
227+
SERVICES_clocks_enable_clock(se_sess_handle, clock, enable, &error_code);
171228
return error_code;
172229
}
173230

174231
uint32_t se_services_select_pll_source(pll_source_t source, pll_target_t target) {
175232
uint32_t error_code;
176-
SERVICES_clocks_select_pll_source(se_services_handle, source, target, &error_code);
233+
SERVICES_clocks_select_pll_source(se_sess_handle, source, target, &error_code);
177234
return error_code;
178235
}
179236

180237
uint32_t se_services_get_run_profile(run_profile_t *profile) {
181238
uint32_t error_code;
182-
SERVICES_get_run_cfg(se_services_handle, profile, &error_code);
239+
SERVICES_get_run_cfg(se_sess_handle, profile, &error_code);
183240
return error_code;
184241
}
185242

186243
uint32_t se_services_set_run_profile(run_profile_t *profile) {
187244
uint32_t error_code;
188-
SERVICES_set_run_cfg(se_services_handle, profile, &error_code);
245+
SERVICES_set_run_cfg(se_sess_handle, profile, &error_code);
189246
return error_code;
190247
}
191248

192249
uint32_t se_services_get_off_profile(off_profile_t *profile) {
193250
uint32_t error_code;
194-
SERVICES_get_off_cfg(se_services_handle, profile, &error_code);
251+
SERVICES_get_off_cfg(se_sess_handle, profile, &error_code);
195252
return error_code;
196253
}
197254

198255
uint32_t se_services_set_off_profile(off_profile_t *profile) {
199256
uint32_t error_code;
200-
SERVICES_set_off_cfg(se_services_handle, profile, &error_code);
257+
SERVICES_set_off_cfg(se_sess_handle, profile, &error_code);
201258
return error_code;
202259
}
203260

204261
uint32_t se_services_boot_process_toc_entry(const uint8_t *image_id) {
205262
uint32_t error_code;
206-
SERVICES_boot_process_toc_entry(se_services_handle, image_id, &error_code);
263+
SERVICES_boot_process_toc_entry(se_sess_handle, image_id, &error_code);
207264
return error_code;
208265
}
209266

210267
uint32_t se_services_boot_cpu(uint32_t cpu_id, uint32_t address) {
211268
uint32_t error_code;
212-
SERVICES_boot_cpu(se_services_handle, cpu_id, address, &error_code);
269+
SERVICES_boot_cpu(se_sess_handle, cpu_id, address, &error_code);
213270
return error_code;
214271
}
215272

@@ -221,7 +278,7 @@ uint32_t se_services_boot_reset_cpu(uint32_t cpu_id) {
221278
}
222279

223280
for (mp_uint_t start = mp_hal_ticks_ms(); ; mp_hal_delay_ms(1)) {
224-
uint32_t ret = SERVICES_boot_reset_cpu(se_services_handle, cpu_id, &error_code);
281+
uint32_t ret = SERVICES_boot_reset_cpu(se_sess_handle, cpu_id, &error_code);
225282
if (ret != SERVICES_REQ_SUCCESS) {
226283
return error_code;
227284
}
@@ -234,11 +291,12 @@ uint32_t se_services_boot_reset_cpu(uint32_t cpu_id) {
234291
return SERVICES_REQ_TIMEOUT;
235292
}
236293
}
294+
237295
return error_code;
238296
}
239297

240298
uint32_t se_services_boot_release_cpu(uint32_t cpu_id) {
241299
uint32_t error_code;
242-
SERVICES_boot_release_cpu(se_services_handle, cpu_id, &error_code);
300+
SERVICES_boot_release_cpu(se_sess_handle, cpu_id, &error_code);
243301
return error_code;
244302
}

ports/alif/se_services.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,16 @@
2929
#include "services_lib_api.h"
3030

3131
void se_services_init(void);
32+
void se_services_deinit(void);
3233
void se_services_dump_device_data(void);
3334
void se_services_get_unique_id(uint8_t id[8]);
3435
__attribute__((noreturn)) void se_services_reset_soc(void);
3536
uint64_t se_services_rand64(void);
37+
uint32_t se_services_notify(void);
38+
3639
uint32_t se_services_enable_clock(clock_enable_t clock, bool enable);
3740
uint32_t se_services_select_pll_source(pll_source_t source, pll_target_t target);
41+
3842
uint32_t se_services_get_run_profile(run_profile_t *profile);
3943
uint32_t se_services_set_run_profile(run_profile_t *profile);
4044
uint32_t se_services_get_off_profile(off_profile_t *profile);

0 commit comments

Comments
 (0)