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 <i.abdalkader@gmail.com>
This commit is contained in:
iabdalkader
2025-02-15 13:53:44 +01:00
committed by Damien George
parent facd0b7190
commit b9e5f1ffba
2 changed files with 93 additions and 31 deletions

View File

@@ -37,8 +37,9 @@
#include "py/mphal.h"
// MHU indices.
#define MHU_M55_SE_MHU0 0
#define MAX_MHU 1
#define MHU_SESS_MHU0 0
#define MHU_RTSS_MHU0 1
#define MAX_MHU 2
// The following timeout is implemented in se_services_handle.c as a
// simple loop busy polling on a variable set from an IRQ.
@@ -57,24 +58,36 @@ typedef struct {
static const uint32_t mhu_sender_base_address_list[MAX_MHU] = {
MHU_SESS_S_TX_BASE,
MHU_RTSS_S_TX_BASE
};
static const uint32_t mhu_receiver_base_address_list[MAX_MHU] = {
MHU_SESS_S_RX_BASE,
MHU_RTSS_S_RX_BASE
};
// Must be aligned as a uint32_t.
static uint32_t packet_buffer[SERVICES_MAX_PACKET_BUFFER_SIZE / sizeof(uint32_t)];
static uint32_t se_sess_handle;
static uint32_t se_rtss_handle;
static mhu_driver_out_t mhu_driver_out;
static uint32_t se_services_handle;
void MHU_SESS_S_TX_IRQHandler(void) {
mhu_driver_out.sender_irq_handler(MHU_M55_SE_MHU0);
mhu_driver_out.sender_irq_handler(MHU_SESS_MHU0);
}
void MHU_SESS_S_RX_IRQHandler(void) {
mhu_driver_out.receiver_irq_handler(MHU_M55_SE_MHU0);
mhu_driver_out.receiver_irq_handler(MHU_SESS_MHU0);
}
void MHU_RTSS_S_TX_IRQHandler(void) {
mhu_driver_out.sender_irq_handler(MHU_RTSS_MHU0);
}
void MHU_RTSS_S_RX_IRQHandler(void) {
mhu_driver_out.receiver_irq_handler(MHU_RTSS_MHU0);
}
int dummy_printf(const char *fmt, ...) {
@@ -82,6 +95,33 @@ int dummy_printf(const char *fmt, ...) {
return 0;
}
static void se_services_irq_config(IRQn_Type irqn, bool enable) {
if (enable) {
NVIC_ClearPendingIRQ(irqn);
NVIC_SetPriority(irqn, IRQ_PRI_MHU);
NVIC_EnableIRQ(irqn);
} else {
NVIC_DisableIRQ(irqn);
NVIC_ClearPendingIRQ(irqn);
}
}
void se_services_rx_callback(uint32_t id, uint32_t channel, uint32_t data) {
switch (id) {
case MHU_SESS_MHU0:
SERVICES_rx_msg_callback(id, channel, data);
break;
case MHU_RTSS_MHU0:
#if MICROPY_PY_OPENAMP
extern void metal_rproc_notified(void);
metal_rproc_notified();
#endif
break;
default:
break;
}
}
void se_services_init(void) {
// Initialize MHU.
mhu_driver_in_t mhu_driver_in;
@@ -89,7 +129,7 @@ void se_services_init(void) {
mhu_driver_in.receiver_base_address_list = (uint32_t *)mhu_receiver_base_address_list;
mhu_driver_in.mhu_count = MAX_MHU;
mhu_driver_in.send_msg_acked_callback = SERVICES_send_msg_acked_callback;
mhu_driver_in.rx_msg_callback = SERVICES_rx_msg_callback;
mhu_driver_in.rx_msg_callback = se_services_rx_callback;
mhu_driver_in.debug_print = NULL; // not currently used by MHU_driver_initialize
MHU_driver_initialize(&mhu_driver_in, &mhu_driver_out);
@@ -103,29 +143,38 @@ void se_services_init(void) {
};
SERVICES_initialize(&services_init_params);
// Create SE services channel for sending requests.
se_services_handle = SERVICES_register_channel(MHU_M55_SE_MHU0, 0);
// Register SESS MHU channel.
se_sess_handle = SERVICES_register_channel(MHU_SESS_MHU0, 0);
se_services_irq_config(MHU_SESS_S_RX_IRQ_IRQn, true);
se_services_irq_config(MHU_SESS_S_TX_IRQ_IRQn, true);
// Enable MHU interrupts.
NVIC_ClearPendingIRQ(MHU_SESS_S_RX_IRQ_IRQn);
NVIC_SetPriority(MHU_SESS_S_RX_IRQ_IRQn, IRQ_PRI_MHU);
NVIC_EnableIRQ(MHU_SESS_S_RX_IRQ_IRQn);
NVIC_ClearPendingIRQ(MHU_SESS_S_TX_IRQ_IRQn);
NVIC_SetPriority(MHU_SESS_S_TX_IRQ_IRQn, IRQ_PRI_MHU);
NVIC_EnableIRQ(MHU_SESS_S_TX_IRQ_IRQn);
// Register RTSS MHU channel.
se_rtss_handle = SERVICES_register_channel(MHU_RTSS_MHU0, 0);
se_services_irq_config(MHU_RTSS_S_RX_IRQ_IRQn, true);
se_services_irq_config(MHU_RTSS_S_TX_IRQ_IRQn, true);
// Send heartbeat services requests until one succeeds.
SERVICES_synchronize_with_se(se_services_handle);
SERVICES_synchronize_with_se(se_sess_handle);
}
void se_services_deinit(void) {
// Disable SESS MHU channel IRQs.
se_services_irq_config(MHU_SESS_S_RX_IRQ_IRQn, false);
se_services_irq_config(MHU_SESS_S_TX_IRQ_IRQn, false);
// Disable RTSS MHU channel IRQs.
se_services_irq_config(MHU_RTSS_S_RX_IRQ_IRQn, false);
se_services_irq_config(MHU_RTSS_S_TX_IRQ_IRQn, false);
}
void se_services_dump_device_data(void) {
uint32_t error_code;
uint8_t revision[80];
SERVICES_get_se_revision(se_services_handle, revision, &error_code);
SERVICES_get_se_revision(se_sess_handle, revision, &error_code);
SERVICES_version_data_t data;
SERVICES_system_get_device_data(se_services_handle, &data, &error_code);
SERVICES_system_get_device_data(se_sess_handle, &data, &error_code);
printf("SE revision: %s\n", revision);
printf("ALIF_PN: %s\n", data.ALIF_PN);
@@ -141,11 +190,11 @@ void se_services_dump_device_data(void) {
void se_services_get_unique_id(uint8_t id[8]) {
uint32_t error_code;
SERVICES_system_get_eui_extension(se_services_handle, false, id, &error_code);
SERVICES_system_get_eui_extension(se_sess_handle, false, id, &error_code);
}
__attribute__((noreturn)) void se_services_reset_soc(void) {
SERVICES_boot_reset_soc(se_services_handle);
SERVICES_boot_reset_soc(se_sess_handle);
NVIC_SystemReset();
}
@@ -155,7 +204,7 @@ uint64_t se_services_rand64(void) {
for (int retry = 0; retry < 100; ++retry) {
uint64_t value;
int32_t error_code;
uint32_t ret = SERVICES_cryptocell_get_rnd(se_services_handle, sizeof(uint64_t), &value, &error_code);
uint32_t ret = SERVICES_cryptocell_get_rnd(se_sess_handle, sizeof(uint64_t), &value, &error_code);
if (ret == SERVICES_REQ_SUCCESS) {
return value;
}
@@ -165,51 +214,59 @@ uint64_t se_services_rand64(void) {
return 0;
}
uint32_t se_services_notify(void) {
uint32_t ret = SERVICES_send_msg(se_rtss_handle, LocalToGlobal(0));
if (ret != SERVICES_REQ_SUCCESS) {
return -1;
}
return 0;
}
uint32_t se_services_enable_clock(clock_enable_t clock, bool enable) {
uint32_t error_code;
SERVICES_clocks_enable_clock(se_services_handle, clock, enable, &error_code);
SERVICES_clocks_enable_clock(se_sess_handle, clock, enable, &error_code);
return error_code;
}
uint32_t se_services_select_pll_source(pll_source_t source, pll_target_t target) {
uint32_t error_code;
SERVICES_clocks_select_pll_source(se_services_handle, source, target, &error_code);
SERVICES_clocks_select_pll_source(se_sess_handle, source, target, &error_code);
return error_code;
}
uint32_t se_services_get_run_profile(run_profile_t *profile) {
uint32_t error_code;
SERVICES_get_run_cfg(se_services_handle, profile, &error_code);
SERVICES_get_run_cfg(se_sess_handle, profile, &error_code);
return error_code;
}
uint32_t se_services_set_run_profile(run_profile_t *profile) {
uint32_t error_code;
SERVICES_set_run_cfg(se_services_handle, profile, &error_code);
SERVICES_set_run_cfg(se_sess_handle, profile, &error_code);
return error_code;
}
uint32_t se_services_get_off_profile(off_profile_t *profile) {
uint32_t error_code;
SERVICES_get_off_cfg(se_services_handle, profile, &error_code);
SERVICES_get_off_cfg(se_sess_handle, profile, &error_code);
return error_code;
}
uint32_t se_services_set_off_profile(off_profile_t *profile) {
uint32_t error_code;
SERVICES_set_off_cfg(se_services_handle, profile, &error_code);
SERVICES_set_off_cfg(se_sess_handle, profile, &error_code);
return error_code;
}
uint32_t se_services_boot_process_toc_entry(const uint8_t *image_id) {
uint32_t error_code;
SERVICES_boot_process_toc_entry(se_services_handle, image_id, &error_code);
SERVICES_boot_process_toc_entry(se_sess_handle, image_id, &error_code);
return error_code;
}
uint32_t se_services_boot_cpu(uint32_t cpu_id, uint32_t address) {
uint32_t error_code;
SERVICES_boot_cpu(se_services_handle, cpu_id, address, &error_code);
SERVICES_boot_cpu(se_sess_handle, cpu_id, address, &error_code);
return error_code;
}
@@ -221,7 +278,7 @@ uint32_t se_services_boot_reset_cpu(uint32_t cpu_id) {
}
for (mp_uint_t start = mp_hal_ticks_ms(); ; mp_hal_delay_ms(1)) {
uint32_t ret = SERVICES_boot_reset_cpu(se_services_handle, cpu_id, &error_code);
uint32_t ret = SERVICES_boot_reset_cpu(se_sess_handle, cpu_id, &error_code);
if (ret != SERVICES_REQ_SUCCESS) {
return error_code;
}
@@ -234,11 +291,12 @@ uint32_t se_services_boot_reset_cpu(uint32_t cpu_id) {
return SERVICES_REQ_TIMEOUT;
}
}
return error_code;
}
uint32_t se_services_boot_release_cpu(uint32_t cpu_id) {
uint32_t error_code;
SERVICES_boot_release_cpu(se_services_handle, cpu_id, &error_code);
SERVICES_boot_release_cpu(se_sess_handle, cpu_id, &error_code);
return error_code;
}

View File

@@ -29,12 +29,16 @@
#include "services_lib_api.h"
void se_services_init(void);
void se_services_deinit(void);
void se_services_dump_device_data(void);
void se_services_get_unique_id(uint8_t id[8]);
__attribute__((noreturn)) void se_services_reset_soc(void);
uint64_t se_services_rand64(void);
uint32_t se_services_notify(void);
uint32_t se_services_enable_clock(clock_enable_t clock, bool enable);
uint32_t se_services_select_pll_source(pll_source_t source, pll_target_t target);
uint32_t se_services_get_run_profile(run_profile_t *profile);
uint32_t se_services_set_run_profile(run_profile_t *profile);
uint32_t se_services_get_off_profile(off_profile_t *profile);