Core: Move context information to the service db
This commit removes the ctx array, and moves all the service context
related data.
Two new dummy services are added, one for the non-secure PE, and one
for the core. The latter, TFM_SEC_FUNC_CORE_ID, is used as running
service when calling secure tests. This way the checks done at context
switch pass.
Change-Id: I4fc3cad59a57e8dea630c642b8c363cbacfd58f3
Signed-off-by: Mate Toth-Pal <mate.toth-pal@arm.com>
diff --git a/secure_fw/spm/spm_db.h b/secure_fw/spm/spm_db.h
index ed31dbd..cb3dd3a 100644
--- a/secure_fw/spm/spm_db.h
+++ b/secure_fw/spm/spm_db.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, Arm Limited. All rights reserved.
+ * Copyright (c) 2017-2018, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
@@ -23,6 +23,12 @@
#if TFM_LVL == 1
struct spm_service_region_t {
uint32_t service_id;
+ uint32_t service_state;
+ uint32_t caller_service_id;
+ uint32_t orig_psp;
+ uint32_t orig_psplim;
+ uint32_t orig_lr;
+ uint32_t share;
uint32_t stack_ptr;
uint32_t periph_start;
uint32_t periph_limit;
@@ -33,6 +39,12 @@
#else
struct spm_service_region_t {
uint32_t service_id;
+ uint32_t service_state;
+ uint32_t caller_service_id;
+ uint32_t orig_psp;
+ uint32_t orig_psplim;
+ uint32_t orig_lr;
+ uint32_t share;
uint32_t code_start;
uint32_t code_limit;
uint32_t ro_start;
@@ -55,6 +67,7 @@
struct spm_service_db_t {
uint32_t is_init;
uint32_t services_count;
+ uint32_t running_service_id;
struct spm_service_region_t services[SPM_MAX_SERVICES];
};
@@ -87,6 +100,12 @@
} \
db_ptr = (uint32_t *)&(db->services[index]); \
*db_ptr++ = service##_ID; \
+ *db_ptr++ = SPM_PART_STATE_UNINIT; /* service_state */ \
+ *db_ptr++ = 0U; /* caller service id */ \
+ *db_ptr++ = 0U; /* original psp */ \
+ *db_ptr++ = 0U; /* original psplim */ \
+ *db_ptr++ = 0U; /* original lr */ \
+ *db_ptr++ = 0U; /* share */ \
*db_ptr++ = 0U; /* stack pointer on service enter */ \
*db_ptr++ = 0U; /* peripheral start */ \
*db_ptr++ = 0U; /* peripheral limit */ \
@@ -101,6 +120,12 @@
} \
db_ptr = (uint32_t *)&(db->services[index]); \
*db_ptr++ = service##_ID; \
+ *db_ptr++ = SPM_PART_STATE_UNINIT; /* service_state */ \
+ *db_ptr++ = 0U; /* caller service id */ \
+ *db_ptr++ = 0U; /* original psp */ \
+ *db_ptr++ = 0U; /* original psplim */ \
+ *db_ptr++ = 0U; /* original lr */ \
+ *db_ptr++ = 0U; /* share */ \
*db_ptr++ = (uint32_t)®ION_NAME(Image$$, service, $$Base); \
*db_ptr++ = (uint32_t)®ION_NAME(Image$$, service, $$Limit); \
*db_ptr++ = (uint32_t)®ION_NAME(Image$$, service, $$RO$$Base); \
@@ -120,6 +145,58 @@
}
#endif
+#if TFM_LVL == 1
+#define DUMMY_SERVICE_ADD(service) { \
+ if (index >= max_services) { \
+ return max_services; \
+ } \
+ db_ptr = (uint32_t *)&(db->services[index]); \
+ *db_ptr++ = service##_ID; \
+ *db_ptr++ = SPM_PART_STATE_UNINIT; /* service_state */ \
+ *db_ptr++ = 0U; /* caller service id */ \
+ *db_ptr++ = 0U; /* original psp */ \
+ *db_ptr++ = 0U; /* original psplim */ \
+ *db_ptr++ = 0U; /* original lr */ \
+ *db_ptr++ = 0U; /* share */ \
+ *db_ptr++ = 0U; /* stack pointer on service enter */ \
+ *db_ptr++ = 0U; /* peripheral start */ \
+ *db_ptr++ = 0U; /* peripheral limit */ \
+ *db_ptr++ = 0U; /* uint16_t[2] peripheral bank/loc */ \
+ *db_ptr++ = 0U; /* service init function*/ \
+ index++; \
+ }
+#else
+#define DUMMY_SERVICE_ADD(service) { \
+ if (index >= max_services) { \
+ return max_services; \
+ } \
+ db_ptr = (uint32_t *)&(db->services[index]); \
+ *db_ptr++ = service##_ID; \
+ *db_ptr++ = SPM_PART_STATE_UNINIT; /* service_state */ \
+ *db_ptr++ = 0U; /* caller service id */ \
+ *db_ptr++ = 0U; /* original_psp */ \
+ *db_ptr++ = 0U; /* original_psplim */ \
+ *db_ptr++ = 0U; /* original_lr */ \
+ *db_ptr++ = 0U; /* share */ \
+ *db_ptr++ = 0U; \
+ *db_ptr++ = 0U; \
+ *db_ptr++ = 0U; \
+ *db_ptr++ = 0U; \
+ *db_ptr++ = 0U; \
+ *db_ptr++ = 0U; \
+ *db_ptr++ = 0U; \
+ *db_ptr++ = 0U; \
+ *db_ptr++ = 0U; \
+ *db_ptr++ = 0U; \
+ *db_ptr++ = 0U; \
+ *db_ptr++ = 0U; /* peripheral start */ \
+ *db_ptr++ = 0U; /* peripheral limit */ \
+ *db_ptr++ = 0U; /* uint16_t[2] peripheral bank/loc */ \
+ *db_ptr++ = 0U; /* service init function*/ \
+ index++; \
+}
+#endif
+
#define SERVICE_ADD_PERIPHERAL(service, start, limit, bank, loc) { \
db_ptr = (uint32_t *)&(db->services[SERVICE_ID_GET(service##_ID)]); \
((struct spm_service_region_t *)db_ptr)->periph_start = start; \