cactus: re-align secure partition id
According to [1] and [2] secure partition ids are defined from
0x8001 to 0xfffe. Update the cactus test payload and TFTF such
that it uses the appropriate IDs.
0x8000 and 0xffff are reserved FF-A IDs respectively for the SPMC
and the SPMD.
Conversely in the NWd, the Hypervisor ID is 0 and VMs are numbered
in the range of 1 to 0x7fff.
[1] https://trustedfirmware-a.readthedocs.io/en/latest/components/
secure-partition-manager.html#ffa-id-get
[2] https://review.trustedfirmware.org/c/hafnium/hafnium/+/5165
Signed-off-by: Olivier Deprez <olivier.deprez@arm.com>
Change-Id: I3e9786212b227e6637a7650e60ddc4e59ad05a46
diff --git a/spm/cactus/cactus_def.h b/spm/cactus/cactus_def.h
index 5a4a5dd..be6f06a 100644
--- a/spm/cactus/cactus_def.h
+++ b/spm/cactus/cactus_def.h
@@ -31,10 +31,10 @@
/*
* RX/TX buffer helpers.
*/
-#define get_sp_rx_start(sp_id) (CACTUS_RX_BASE + ((sp_id - 1) * CACTUS_RX_TX_SIZE))
-#define get_sp_rx_end(sp_id) (CACTUS_RX_BASE + ((sp_id - 1) * CACTUS_RX_TX_SIZE) + PAGE_SIZE)
-#define get_sp_tx_start(sp_id) (CACTUS_TX_BASE + ((sp_id - 1) * CACTUS_RX_TX_SIZE))
-#define get_sp_tx_end(sp_id) (CACTUS_TX_BASE + ((sp_id - 1) * CACTUS_RX_TX_SIZE) + PAGE_SIZE)
+#define get_sp_rx_start(sp_id) (CACTUS_RX_BASE + (((sp_id & 0x7FFFU) - 1U) * CACTUS_RX_TX_SIZE))
+#define get_sp_rx_end(sp_id) (CACTUS_RX_BASE + (((sp_id & 0x7FFFU) - 1U) * CACTUS_RX_TX_SIZE) + PAGE_SIZE)
+#define get_sp_tx_start(sp_id) (CACTUS_TX_BASE + (((sp_id & 0x7FFFU) - 1U) * CACTUS_RX_TX_SIZE))
+#define get_sp_tx_end(sp_id) (CACTUS_TX_BASE + (((sp_id & 0x7FFFU) - 1U) * CACTUS_RX_TX_SIZE) + PAGE_SIZE)
/*
* UUID of secure partition as defined in the respective manifests.
diff --git a/spm/cactus/cactus_ffa_tests.c b/spm/cactus/cactus_ffa_tests.c
index 085923a..a242e41 100644
--- a/spm/cactus/cactus_ffa_tests.c
+++ b/spm/cactus/cactus_ffa_tests.c
@@ -121,9 +121,9 @@
const char *test_all = "Get all partitions info";
const struct ffa_partition_info expected_info[] = {
- {.id = SPM_VM_ID_FIRST, .exec_context = 8, .properties = 0}, /* Primary partition info */
- {.id = SPM_VM_ID_SECOND, .exec_context = 2, .properties = 0}, /* Secondary partition info */
- {.id = SPM_VM_ID_THIRD, .exec_context = 2, .properties = 0} /* Tertiary partition info */
+ {.id = SPM_VM_ID_FIRST, .exec_context = 8U, .properties = 0U}, /* Primary partition info */
+ {.id = SPM_VM_ID_FIRST + 1U, .exec_context = 8U, .properties = 0U}, /* Secondary partition info */
+ {.id = SPM_VM_ID_FIRST + 2U, .exec_context = 8U, .properties = 0U} /* Tertiary partition info */
};
announce_test_section_start(test_partition_info);
diff --git a/spm/cactus/cactus_main.c b/spm/cactus/cactus_main.c
index e833310..737fd11 100644
--- a/spm/cactus/cactus_main.c
+++ b/spm/cactus/cactus_main.c
@@ -54,7 +54,7 @@
continue;
}
- if (ffa_ret.ret1 != SP_ID(vm_id)) {
+ if (ffa_ret.ret1 != vm_id) {
ffa_ret = ffa_error(-2);
continue;
}
@@ -74,8 +74,7 @@
* Send a response through direct messaging then block
* until receiving a new message request.
*/
- ffa_ret = ffa_msg_send_direct_resp(SP_ID(vm_id),
- HYP_ID, sp_response);
+ ffa_ret = ffa_msg_send_direct_resp(vm_id, HYP_ID, sp_response);
}
}
@@ -188,7 +187,7 @@
NOTICE("Booting Secondary Cactus Secure Partition (ID: %u)\n%s\n%s\n",
ffa_id, build_message, version_string);
- if (ffa_id == SPM_VM_ID_THIRD) {
+ if (ffa_id == (SPM_VM_ID_FIRST + 2)) {
NOTICE("Mapping RXTX Region\n");
/* Declare RX/TX buffers at virtual FF-A instance */
diff --git a/spm/common/sp_helpers.h b/spm/common/sp_helpers.h
index 7096daf..965f799 100644
--- a/spm/common/sp_helpers.h
+++ b/spm/common/sp_helpers.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018, Arm Limited. All rights reserved.
+ * Copyright (c) 2018-2020, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -11,9 +11,7 @@
#include <tftf_lib.h>
#include <ffa_helpers.h>
-#define SPM_VM_ID_FIRST (1)
-#define SPM_VM_ID_SECOND (2)
-#define SPM_VM_ID_THIRD (3)
+#define SPM_VM_ID_FIRST SP_ID(1)
#define SPM_VM_GET_COUNT (0xFF01)
#define SPM_VCPU_GET_COUNT (0xFF02)
diff --git a/tftf/tests/runtime_services/secure_service/ffa_helpers.c b/tftf/tests/runtime_services/secure_service/ffa_helpers.c
index 7ccf890..bda47c9 100644
--- a/tftf/tests/runtime_services/secure_service/ffa_helpers.c
+++ b/tftf/tests/runtime_services/secure_service/ffa_helpers.c
@@ -134,7 +134,7 @@
*
*/
ret_values = ffa_msg_send_direct_req(HYP_ID, SP_ID(1),
- OPTEE_FFA_GET_API_VERSION);
+ OPTEE_FFA_GET_API_VERSION);
if ((ret_values.ret3 == FFA_VERSION_MAJOR) &&
(ret_values.ret4 == FFA_VERSION_MINOR)) {
is_optee_spmc_criteria++;
@@ -146,7 +146,7 @@
*
*/
ret_values = ffa_msg_send_direct_req(HYP_ID, SP_ID(1),
- OPTEE_FFA_GET_OS_VERSION);
+ OPTEE_FFA_GET_OS_VERSION);
if ((ret_values.ret3 == OPTEE_FFA_GET_OS_VERSION_MAJOR) &&
(ret_values.ret4 == OPTEE_FFA_GET_OS_VERSION_MINOR)) {
is_optee_spmc_criteria++;
diff --git a/tftf/tests/runtime_services/secure_service/test_ffa_direct_messaging.c b/tftf/tests/runtime_services/secure_service/test_ffa_direct_messaging.c
index 6008b78..d00793a 100644
--- a/tftf/tests/runtime_services/secure_service/test_ffa_direct_messaging.c
+++ b/tftf/tests/runtime_services/secure_service/test_ffa_direct_messaging.c
@@ -22,8 +22,7 @@
smc_ret_values ret_values;
/* Send a message to SP through direct messaging */
- ret_values = ffa_msg_send_direct_req(HYP_ID, SP_ID(sp_id),
- test_pattern);
+ ret_values = ffa_msg_send_direct_req(HYP_ID, sp_id, test_pattern);
/*
* Return responses may be FFA_MSG_SEND_DIRECT_RESP or FFA_INTERRUPT,
@@ -70,7 +69,7 @@
/**********************************************************************
* Send a message to SP1 through direct messaging
**********************************************************************/
- result = send_receive_direct_msg(1, DIRECT_MSG_TEST_PATTERN1);
+ result = send_receive_direct_msg(SP_ID(1), DIRECT_MSG_TEST_PATTERN1);
if (result != TEST_RESULT_SUCCESS) {
return result;
}
@@ -78,7 +77,7 @@
/**********************************************************************
* Send a message to SP2 through direct messaging
**********************************************************************/
- result = send_receive_direct_msg(2, DIRECT_MSG_TEST_PATTERN2);
+ result = send_receive_direct_msg(SP_ID(2), DIRECT_MSG_TEST_PATTERN2);
if (result != TEST_RESULT_SUCCESS) {
return result;
}
@@ -86,13 +85,7 @@
/**********************************************************************
* Send a message to SP1 through direct messaging
**********************************************************************/
- result = send_receive_direct_msg(1, DIRECT_MSG_TEST_PATTERN3);
- if (result != TEST_RESULT_SUCCESS) {
- return result;
- }
+ result = send_receive_direct_msg(SP_ID(1), DIRECT_MSG_TEST_PATTERN3);
- /**********************************************************************
- * All tests passed.
- **********************************************************************/
- return TEST_RESULT_SUCCESS;
+ return result;
}