Skip to content

Commit

Permalink
Merge "fix(rmm): changes for Release build and logging" into integration
Browse files Browse the repository at this point in the history
  • Loading branch information
soby-mathew authored and TrustedFirmware Code Review committed Dec 6, 2023
2 parents 719493e + 7c38ef4 commit ff10c06
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 29 deletions.
8 changes: 7 additions & 1 deletion lib/debug/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@

add_library(rmm-lib-debug INTERFACE)

#
# Set default log level of 20 for Release build and
# 40 for Debug build.
#
arm_config_option(
NAME LOG_LEVEL
HELP "Log level to apply for RMM (0 - 50)"
TYPE STRING
DEFAULT 40)
DEFAULT 20
DEPENDS ${CMAKE_BUILD_TYPE} STREQUAL "Release"
ELSE 40)

target_compile_definitions(rmm-lib-debug
INTERFACE "LOG_LEVEL=${LOG_LEVEL}")
Expand Down
3 changes: 2 additions & 1 deletion lib/realm/include/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ enum buffer_slot {

struct granule;

void assert_cpu_slots_empty(void);
bool check_cpu_slots_empty(void);
void *granule_map(struct granule *g, enum buffer_slot slot);
void buffer_unmap(void *buf);

Expand All @@ -48,6 +48,7 @@ bool ns_buffer_read(enum buffer_slot slot,
unsigned int offset,
size_t size,
void *dest);

bool ns_buffer_write(enum buffer_slot slot,
struct granule *ns_gr,
unsigned int offset,
Expand Down
9 changes: 6 additions & 3 deletions lib/realm/src/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,15 @@ void slot_buf_finish_warmboot_init(void)
* Buffer slots are intended to be transient, and should not be live at
* entry/exit of the RMM.
*/
void assert_cpu_slots_empty(void)
bool check_cpu_slots_empty(void)
{
for (unsigned int i = 0U; i < (unsigned int)NR_CPU_SLOTS; i++) {
assert(slot_to_descriptor((enum buffer_slot)i) ==
TRANSIENT_DESC);
if (slot_to_descriptor((enum buffer_slot)i) !=
TRANSIENT_DESC) {
return false;
}
}
return true;
}

static inline bool is_ns_slot(enum buffer_slot slot)
Expand Down
37 changes: 13 additions & 24 deletions runtime/core/handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,11 @@ static const struct smc_handler smc_handlers[] = {

COMPILER_ASSERT(ARRAY_LEN(smc_handlers) == SMC64_NUM_FIDS_IN_RANGE(RMI));

static bool rmi_call_log_enabled = true;

static inline bool rmi_handler_needs_fpu(unsigned int id)
{
#ifdef RMM_FPU_USE_AT_REL2
if (id == SMC_RMM_REALM_CREATE || id == SMC_RMM_DATA_CREATE ||
id == SMC_RMM_REC_CREATE || id == SMC_RMM_RTT_INIT_RIPAS) {
if ((id == SMC_RMM_REALM_CREATE) || (id == SMC_RMM_DATA_CREATE) ||
(id == SMC_RMM_REC_CREATE) || (id == SMC_RMM_RTT_INIT_RIPAS)) {
return true;
}
#else
Expand Down Expand Up @@ -245,6 +243,7 @@ void handle_ns_smc(unsigned int function_id,
bool restore_ns_simd_state = false;
struct simd_context *ns_simd_ctx;
bool sve_hint = false;
unsigned long args[] __unused = {arg0, arg1, arg2, arg3, arg4};

/* Save the SVE hint bit and clear it from the function ID */
if ((function_id & SMC_SVE_HINT) != 0U) {
Expand All @@ -270,7 +269,7 @@ void handle_ns_smc(unsigned int function_id,
return;
}

assert_cpu_slots_empty();
assert(check_cpu_slots_empty());

/* Current CPU's SIMD state must not be saved when entering RMM */
assert(simd_is_state_saved() == false);
Expand Down Expand Up @@ -331,11 +330,7 @@ void handle_ns_smc(unsigned int function_id,
assert(false);
}

if (rmi_call_log_enabled) {
unsigned long args[] = {arg0, arg1, arg2, arg3, arg4};

rmi_log_on_exit(handler_id, args, res);
}
rmi_log_on_exit(handler_id, args, res);

/* If the handler uses FPU, restore the saved NS simd context. */
if (restore_ns_simd_state) {
Expand All @@ -344,24 +339,18 @@ void handle_ns_smc(unsigned int function_id,

/* Current CPU's SIMD state must not be saved when exiting RMM */
assert(simd_is_state_saved() == false);

assert_cpu_slots_empty();
assert(check_cpu_slots_empty());
}

static void report_unexpected(void)
{
unsigned long spsr = read_spsr_el2();
unsigned long esr = read_esr_el2();
unsigned long elr = read_elr_el2();
unsigned long far = read_far_el2();

INFO("----\n");
INFO("Unexpected exception:\n");
INFO("SPSR_EL2: 0x%016lx\n", spsr);
INFO("ESR_EL2: 0x%016lx\n", esr);
INFO("ELR_EL2: 0x%016lx\n", elr);
INFO("FAR_EL2: 0x%016lx\n", far);
INFO("----\n");
ERROR("----\n");
ERROR("Unexpected exception:\n");
ERROR("SPSR_EL2: 0x%016lx\n", read_spsr_el2());
ERROR("ESR_EL2: 0x%016lx\n", read_esr_el2());
ERROR("ELR_EL2: 0x%016lx\n", read_elr_el2());
ERROR("FAR_EL2: 0x%016lx\n", read_far_el2());
ERROR("----\n");
}

/*
Expand Down

0 comments on commit ff10c06

Please sign in to comment.