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:
committed by
Damien George
parent
facd0b7190
commit
b9e5f1ffba
@@ -37,8 +37,9 @@
|
|||||||
#include "py/mphal.h"
|
#include "py/mphal.h"
|
||||||
|
|
||||||
// MHU indices.
|
// MHU indices.
|
||||||
#define MHU_M55_SE_MHU0 0
|
#define MHU_SESS_MHU0 0
|
||||||
#define MAX_MHU 1
|
#define MHU_RTSS_MHU0 1
|
||||||
|
#define MAX_MHU 2
|
||||||
|
|
||||||
// The following timeout is implemented in se_services_handle.c as a
|
// The following timeout is implemented in se_services_handle.c as a
|
||||||
// simple loop busy polling on a variable set from an IRQ.
|
// 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] = {
|
static const uint32_t mhu_sender_base_address_list[MAX_MHU] = {
|
||||||
MHU_SESS_S_TX_BASE,
|
MHU_SESS_S_TX_BASE,
|
||||||
|
MHU_RTSS_S_TX_BASE
|
||||||
};
|
};
|
||||||
|
|
||||||
static const uint32_t mhu_receiver_base_address_list[MAX_MHU] = {
|
static const uint32_t mhu_receiver_base_address_list[MAX_MHU] = {
|
||||||
MHU_SESS_S_RX_BASE,
|
MHU_SESS_S_RX_BASE,
|
||||||
|
MHU_RTSS_S_RX_BASE
|
||||||
};
|
};
|
||||||
|
|
||||||
// Must be aligned as a uint32_t.
|
// Must be aligned as a uint32_t.
|
||||||
static uint32_t packet_buffer[SERVICES_MAX_PACKET_BUFFER_SIZE / sizeof(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 mhu_driver_out_t mhu_driver_out;
|
||||||
static uint32_t se_services_handle;
|
|
||||||
|
|
||||||
void MHU_SESS_S_TX_IRQHandler(void) {
|
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) {
|
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, ...) {
|
int dummy_printf(const char *fmt, ...) {
|
||||||
@@ -82,6 +95,33 @@ int dummy_printf(const char *fmt, ...) {
|
|||||||
return 0;
|
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) {
|
void se_services_init(void) {
|
||||||
// Initialize MHU.
|
// Initialize MHU.
|
||||||
mhu_driver_in_t mhu_driver_in;
|
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.receiver_base_address_list = (uint32_t *)mhu_receiver_base_address_list;
|
||||||
mhu_driver_in.mhu_count = MAX_MHU;
|
mhu_driver_in.mhu_count = MAX_MHU;
|
||||||
mhu_driver_in.send_msg_acked_callback = SERVICES_send_msg_acked_callback;
|
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_in.debug_print = NULL; // not currently used by MHU_driver_initialize
|
||||||
MHU_driver_initialize(&mhu_driver_in, &mhu_driver_out);
|
MHU_driver_initialize(&mhu_driver_in, &mhu_driver_out);
|
||||||
|
|
||||||
@@ -103,29 +143,38 @@ void se_services_init(void) {
|
|||||||
};
|
};
|
||||||
SERVICES_initialize(&services_init_params);
|
SERVICES_initialize(&services_init_params);
|
||||||
|
|
||||||
// Create SE services channel for sending requests.
|
// Register SESS MHU channel.
|
||||||
se_services_handle = SERVICES_register_channel(MHU_M55_SE_MHU0, 0);
|
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.
|
// Register RTSS MHU channel.
|
||||||
NVIC_ClearPendingIRQ(MHU_SESS_S_RX_IRQ_IRQn);
|
se_rtss_handle = SERVICES_register_channel(MHU_RTSS_MHU0, 0);
|
||||||
NVIC_SetPriority(MHU_SESS_S_RX_IRQ_IRQn, IRQ_PRI_MHU);
|
se_services_irq_config(MHU_RTSS_S_RX_IRQ_IRQn, true);
|
||||||
NVIC_EnableIRQ(MHU_SESS_S_RX_IRQ_IRQn);
|
se_services_irq_config(MHU_RTSS_S_TX_IRQ_IRQn, true);
|
||||||
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);
|
|
||||||
|
|
||||||
// Send heartbeat services requests until one succeeds.
|
// 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) {
|
void se_services_dump_device_data(void) {
|
||||||
uint32_t error_code;
|
uint32_t error_code;
|
||||||
|
|
||||||
uint8_t revision[80];
|
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_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("SE revision: %s\n", revision);
|
||||||
printf("ALIF_PN: %s\n", data.ALIF_PN);
|
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]) {
|
void se_services_get_unique_id(uint8_t id[8]) {
|
||||||
uint32_t error_code;
|
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) {
|
__attribute__((noreturn)) void se_services_reset_soc(void) {
|
||||||
SERVICES_boot_reset_soc(se_services_handle);
|
SERVICES_boot_reset_soc(se_sess_handle);
|
||||||
NVIC_SystemReset();
|
NVIC_SystemReset();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,7 +204,7 @@ uint64_t se_services_rand64(void) {
|
|||||||
for (int retry = 0; retry < 100; ++retry) {
|
for (int retry = 0; retry < 100; ++retry) {
|
||||||
uint64_t value;
|
uint64_t value;
|
||||||
int32_t error_code;
|
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) {
|
if (ret == SERVICES_REQ_SUCCESS) {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
@@ -165,51 +214,59 @@ uint64_t se_services_rand64(void) {
|
|||||||
return 0;
|
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 se_services_enable_clock(clock_enable_t clock, bool enable) {
|
||||||
uint32_t error_code;
|
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;
|
return error_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t se_services_select_pll_source(pll_source_t source, pll_target_t target) {
|
uint32_t se_services_select_pll_source(pll_source_t source, pll_target_t target) {
|
||||||
uint32_t error_code;
|
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;
|
return error_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t se_services_get_run_profile(run_profile_t *profile) {
|
uint32_t se_services_get_run_profile(run_profile_t *profile) {
|
||||||
uint32_t error_code;
|
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;
|
return error_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t se_services_set_run_profile(run_profile_t *profile) {
|
uint32_t se_services_set_run_profile(run_profile_t *profile) {
|
||||||
uint32_t error_code;
|
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;
|
return error_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t se_services_get_off_profile(off_profile_t *profile) {
|
uint32_t se_services_get_off_profile(off_profile_t *profile) {
|
||||||
uint32_t error_code;
|
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;
|
return error_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t se_services_set_off_profile(off_profile_t *profile) {
|
uint32_t se_services_set_off_profile(off_profile_t *profile) {
|
||||||
uint32_t error_code;
|
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;
|
return error_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t se_services_boot_process_toc_entry(const uint8_t *image_id) {
|
uint32_t se_services_boot_process_toc_entry(const uint8_t *image_id) {
|
||||||
uint32_t error_code;
|
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;
|
return error_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t se_services_boot_cpu(uint32_t cpu_id, uint32_t address) {
|
uint32_t se_services_boot_cpu(uint32_t cpu_id, uint32_t address) {
|
||||||
uint32_t error_code;
|
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;
|
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)) {
|
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) {
|
if (ret != SERVICES_REQ_SUCCESS) {
|
||||||
return error_code;
|
return error_code;
|
||||||
}
|
}
|
||||||
@@ -234,11 +291,12 @@ uint32_t se_services_boot_reset_cpu(uint32_t cpu_id) {
|
|||||||
return SERVICES_REQ_TIMEOUT;
|
return SERVICES_REQ_TIMEOUT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return error_code;
|
return error_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t se_services_boot_release_cpu(uint32_t cpu_id) {
|
uint32_t se_services_boot_release_cpu(uint32_t cpu_id) {
|
||||||
uint32_t error_code;
|
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;
|
return error_code;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,12 +29,16 @@
|
|||||||
#include "services_lib_api.h"
|
#include "services_lib_api.h"
|
||||||
|
|
||||||
void se_services_init(void);
|
void se_services_init(void);
|
||||||
|
void se_services_deinit(void);
|
||||||
void se_services_dump_device_data(void);
|
void se_services_dump_device_data(void);
|
||||||
void se_services_get_unique_id(uint8_t id[8]);
|
void se_services_get_unique_id(uint8_t id[8]);
|
||||||
__attribute__((noreturn)) void se_services_reset_soc(void);
|
__attribute__((noreturn)) void se_services_reset_soc(void);
|
||||||
uint64_t se_services_rand64(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_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_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_get_run_profile(run_profile_t *profile);
|
||||||
uint32_t se_services_set_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);
|
uint32_t se_services_get_off_profile(off_profile_t *profile);
|
||||||
|
|||||||
Reference in New Issue
Block a user