fix(realm): fix calculation of Realm's REC index
This patch fixes the issues related to the calculation of
Realm's REC index based on the read value of MPIDR_EL1 register
and REC's mpidr parameter from the REC's index.
RMM reports MPIDR_EL1.Aff0 field matching RmiRecMpidr type
with [7:4] bits RES0, making MPIDR_EL1=0x80000100 represent
REC 16, but not 256 as it is implemented in the existing code.
The patch adds the following macros:
- RMI_REC_MPIDR(idx) which calculates RmiRecMpidr value based
on REC index.
- REC_IDX(mpidr) gets REC index from MPIDR_EL1.
Change-Id: Ieac473984f3a50d2815dcfe8d291d31bd70ebae7
Signed-off-by: AlexeiFedorov <Alexei.Fedorov@arm.com>
diff --git a/realm/realm_shared_data.c b/realm/realm_shared_data.c
index 2d09f78..2825796 100644
--- a/realm/realm_shared_data.c
+++ b/realm/realm_shared_data.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022, Arm Limited. All rights reserved.
+ * Copyright (c) 2022-2024, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -8,6 +8,7 @@
#include <arch_helpers.h>
#include <assert.h>
#include <host_shared_data.h>
+#include <realm_def.h>
/**
* @brief - Returns the base address of the shared region
@@ -30,7 +31,7 @@
*/
host_shared_data_t *realm_get_my_shared_structure(void)
{
- return &guest_shared_data[read_mpidr_el1() & MPID_MASK];
+ return &guest_shared_data[REC_IDX(read_mpidr_el1())];
}
/*
@@ -39,7 +40,7 @@
u_register_t realm_shared_data_get_my_host_val(uint8_t index)
{
assert(index < MAX_DATA_SIZE);
- return guest_shared_data[read_mpidr_el1() & MPID_MASK].host_param_val[index];
+ return guest_shared_data[REC_IDX(read_mpidr_el1())].host_param_val[index];
}
/*
@@ -47,7 +48,7 @@
*/
uint8_t realm_shared_data_get_my_realm_cmd(void)
{
- return guest_shared_data[read_mpidr_el1() & MPID_MASK].realm_cmd;
+ return guest_shared_data[REC_IDX(read_mpidr_el1())].realm_cmd;
}
/*
@@ -56,6 +57,6 @@
void realm_shared_data_set_my_realm_val(uint8_t index, u_register_t val)
{
assert(index < MAX_DATA_SIZE);
- guest_shared_data[read_mpidr_el1() & MPID_MASK].realm_out_val[index] = val;
+ guest_shared_data[REC_IDX(read_mpidr_el1())].realm_out_val[index] = val;
}