summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntonio Nino Diaz <antonio.ninodiaz@arm.com>2018-03-14 14:26:25 +0000
committerAntonio Nino Diaz <antonio.ninodiaz@arm.com>2018-03-26 18:15:22 +0100
commit78ea0f89cce0cbde03171ad2855db9de9bab0305 (patch)
tree673f0acb65ab6afc9ac60a8016af82da4d60c722
parentc4a96088776e43f9ab74f6b3dc1b28304601af7c (diff)
Cactus: Add new Cactus version for SPCI and SPRT
Change-Id: I1c90856346941df4f49811755991c9a0683ce6b2 Signed-off-by: Antonio Nino Diaz <antonio.ninodiaz@arm.com>
-rw-r--r--cactus/cactus.mk11
-rw-r--r--cactus/cactus_helpers.c6
-rw-r--r--cactus/spci_sprt/aarch64/cactus_entrypoint.S112
-rw-r--r--cactus/spci_sprt/cactus_spci_sprt.c42
-rw-r--r--include/runtime_services/smc.h7
-rw-r--r--include/runtime_services/sprt_svc.h46
-rw-r--r--tests/tests.mk20
7 files changed, 236 insertions, 8 deletions
diff --git a/cactus/cactus.mk b/cactus/cactus.mk
index 95bc64b..106a875 100644
--- a/cactus/cactus.mk
+++ b/cactus/cactus.mk
@@ -33,7 +33,7 @@ CACTUS_SOURCES += drivers/arm/pl011/${ARCH}/pl011_console.S \
plat/common/${ARCH}/platform_helpers.S \
${STDLIB_SOURCES}
-CACTUS_PROFILE ?= legacy
+CACTUS_PROFILE ?= spci_sprt
ifeq (${CACTUS_PROFILE},legacy)
VERSION_STRING := ${VERSION_STRING}-legacy
@@ -44,6 +44,15 @@ ifeq (${CACTUS_PROFILE},legacy)
)
endif
+ifeq (${CACTUS_PROFILE},spci_sprt)
+ VERSION_STRING := ${VERSION_STRING}-spci-sprt
+
+ CACTUS_SOURCES += $(addprefix cactus/spci_sprt/, \
+ aarch64/cactus_entrypoint.S \
+ cactus_spci_sprt.c \
+ )
+endif
+
CACTUS_LINKERFILE := cactus/cactus.ld.S
# Position-independent code
diff --git a/cactus/cactus_helpers.c b/cactus/cactus_helpers.c
index 8844339..070ae7b 100644
--- a/cactus/cactus_helpers.c
+++ b/cactus/cactus_helpers.c
@@ -58,14 +58,14 @@ void announce_test_end(const char *test_desc)
void cactus_sleep(uint32_t duration_sec)
{
uint32_t timer_freq = mmio_read_32(SYS_CNT_CONTROL_BASE + CNTFID_OFF);
- VERBOSE("Timer frequency = %u\n", timer_freq);
+ VERBOSE("%s: Timer frequency = %u\n", __func__, timer_freq);
- INFO("Sleeping for %u seconds...\n", duration_sec);
+ INFO("%s: Sleeping for %u seconds...\n", __func__, duration_sec);
uint64_t time1 = mmio_read_64(SYS_CNT_READ_BASE);
volatile uint64_t time2 = time1;
while ((time2 - time1) < duration_sec * timer_freq) {
time2 = mmio_read_64(SYS_CNT_READ_BASE);
}
- INFO("Done\n");
+ INFO("%s: Done\n", __func__);
}
diff --git a/cactus/spci_sprt/aarch64/cactus_entrypoint.S b/cactus/spci_sprt/aarch64/cactus_entrypoint.S
new file mode 100644
index 0000000..23110c7
--- /dev/null
+++ b/cactus/spci_sprt/aarch64/cactus_entrypoint.S
@@ -0,0 +1,112 @@
+/*
+ * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <asm_macros.S>
+#include <secure_partition.h>
+#include <spm_svc.h>
+#include <sprt_svc.h>
+#include <xlat_tables.h>
+
+ .globl cactus_entrypoint
+
+func cactus_entrypoint
+
+ /*
+ * All the information needed to remap the memory of the Secure
+ * Partition is in the buffer whose pointer is passed on X0 and size on
+ * X1. If the size is 0, return with an error.
+ */
+ cmp x1, #0
+ beq .return_error
+
+ /* Save the base address and size of the buffer. */
+ mov x20, x0
+ mov x21, x1
+ /* Size of the Secure Partition image. */
+ ldr x22, [x20, SP_BOOT_INFO_IMAGE_SIZE_OFFSET]
+
+ /*
+ * Remap all sections of the image before doing anything else.
+ *
+ * Not even the console can be initialized before because it needs to
+ * initialize variables (that can only be modified after remapping that
+ * region as RW).
+ *
+ * If any of the calls fails, loop, as there is no console to print an
+ * error message to.
+ */
+ .macro set_sp_mem_attributes
+ cmp x2, #0 /* If size is 0, skip the call. */
+ beq 1f
+ mov_imm x0, SP_MEMORY_ATTRIBUTES_SET_AARCH64
+ svc #0
+ cmp x0, #0
+ bne .return_error
+1:
+ .endm
+
+ adr x1, __TEXT_START__
+ adr x2, __TEXT_END__
+ sub x2, x2, x1 /* __TEXT_SIZE__ */
+ lsr x2, x2, PAGE_SIZE_SHIFT /* __TEXT_SIZE__ in pages */
+ mov x3, SP_MEMORY_ATTRIBUTES_ACCESS_RO | SP_MEMORY_ATTRIBUTES_EXEC
+ set_sp_mem_attributes
+
+ adr x1, __RODATA_START__
+ adr x2, __RODATA_END__
+ sub x2, x2, x1 /* __RODATA_SIZE__ */
+ lsr x2, x2, PAGE_SIZE_SHIFT /* __RODATA_SIZE__ in pages */
+ mov x3, SP_MEMORY_ATTRIBUTES_ACCESS_RO | SP_MEMORY_ATTRIBUTES_NON_EXEC
+ set_sp_mem_attributes
+
+ adr x1, __RWDATA_START__
+ adr x2, __RWDATA_END__
+ sub x2, x2, x1 /* __RWDATA_SIZE__ */
+ lsr x2, x2, PAGE_SIZE_SHIFT /* __RWDATA_SIZE__ in pages */
+ mov x3, SP_MEMORY_ATTRIBUTES_ACCESS_RW | SP_MEMORY_ATTRIBUTES_NON_EXEC
+ set_sp_mem_attributes
+
+ /*
+ * To avoid accessing it by mistake, prevent EL0 from accessing the rest
+ * of the memory reserved for the Secure Partition.
+ *
+ * Unused size = Total size - Used size
+ * = Total size - (__RWDATA_END__ - __TEXT_START__)
+ */
+ adr x1, __RWDATA_END__
+ adr x2, __TEXT_START__
+ sub x2, x1, x2 /* x2 = Used size, x22 = Total size */
+ sub x2, x22, x2 /* x2 = Unused size */
+ lsr x2, x2, PAGE_SIZE_SHIFT /* Unused size in pages */
+ mov x3, SP_MEMORY_ATTRIBUTES_ACCESS_NOACCESS | SP_MEMORY_ATTRIBUTES_NON_EXEC
+ set_sp_mem_attributes
+
+ adr x0, __BSS_START__
+ adr x1, __BSS_END__
+ sub x1, x1, x0
+ bl zeromem16
+
+ /* Setup the stack pointer. */
+ ldr x0, [x20, SP_BOOT_INFO_STACK_BASE_OFFSET]
+ ldr x1, [x20, SP_BOOT_INFO_PCPU_STACK_SIZE_OFFSET]
+ add x0, x0, x1
+ mov sp, x0
+
+ /* And do the rest in C code */
+ mov x0, x20
+ mov x1, x21
+ b cactus_main
+
+.return_error:
+ /* Tell SPM that the initialization failed. */
+ mov_imm x0, SPRT_RETURN_RESPONSE
+ mov x1, #-1
+ svc #0
+
+ /* Loop forever */
+ b .
+
+endfunc cactus_entrypoint
diff --git a/cactus/spci_sprt/cactus_spci_sprt.c b/cactus/spci_sprt/cactus_spci_sprt.c
new file mode 100644
index 0000000..0baed4f
--- /dev/null
+++ b/cactus/spci_sprt/cactus_spci_sprt.c
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <cactus_helpers.h>
+#include <debug.h>
+#include <secure_partition.h>
+#include <spm_svc.h>
+#include <sprt_svc.h>
+
+
+__dead2 void secure_services_loop(void)
+{
+ int32_t event_status_code;
+ svc_args svc_values = { 0 };
+
+ /*
+ * The first time this loop is executed corresponds to when Cactus has
+ * finished initialising its run time environment and is ready to handle
+ * secure service requests.
+ */
+ NOTICE("Cactus: Signal end of init to SPM\n");
+ event_status_code = SPM_SUCCESS;
+
+ while (1) {
+ svc_values.arg0 = SPRT_RETURN_RESPONSE;
+ svc_values.arg1 = event_status_code;
+
+ int32_t event_id = cactus_svc(&svc_values);
+
+ switch (event_id) {
+
+ default:
+ NOTICE("Unhandled Service ID 0x%x\n", event_id);
+ event_status_code = SPM_NOT_SUPPORTED;
+ break;
+
+ }
+ }
+}
diff --git a/include/runtime_services/smc.h b/include/runtime_services/smc.h
index c83dea3..58d36ae 100644
--- a/include/runtime_services/smc.h
+++ b/include/runtime_services/smc.h
@@ -14,6 +14,13 @@
#define SMC_UNKNOWN -1
+/* TODO REMOVE THIS SUPPORT SMCCC 2.0 */
+#define FUNCID_SERV_SHIFT U(28)
+#define FUNCID_SERV_MASK U(0x3)
+#define FUNCID_SERV_WIDTH U(2)
+#define FUNCID_SERV_SPRT U(2)
+#define FUNCID_SERV_SPCI U(3)
+
/*******************************************************************************
* Bit definitions inside the function id as per the SMC calling convention
******************************************************************************/
diff --git a/include/runtime_services/sprt_svc.h b/include/runtime_services/sprt_svc.h
new file mode 100644
index 0000000..b1c05d8
--- /dev/null
+++ b/include/runtime_services/sprt_svc.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef __SPRT_SVC_H__
+#define __SPRT_SVC_H__
+
+#include <smc.h>
+#include <utils_def.h>
+
+/* SPRT_VERSION helpers */
+#define SPRT_VERSION_MAJOR U(0)
+#define SPRT_VERSION_MAJOR_SHIFT 16
+#define SPRT_VERSION_MAJOR_MASK U(0x7FFF)
+/* TODO: Move up minor version to 1 when SPRT is properly supported. */
+#define SPRT_VERSION_MINOR U(0)
+#define SPRT_VERSION_MINOR_SHIFT 0
+#define SPRT_VERSION_MINOR_MASK U(0xFFFF)
+#define SPRT_VERSION_FORM(major, minor) ((((major) & SPRT_VERSION_MAJOR_MASK) << SPRT_VERSION_MAJOR_SHIFT) | \
+ ((minor) & SPRT_VERSION_MINOR_MASK))
+#define SPRT_VERSION_COMPILED SPRT_VERSION_FORM(SPRT_VERSION_MAJOR, SPRT_VERSION_MINOR)
+
+/* TODO: Check all values below are correct when they're specified in SPRT. */
+
+/* SPRT function IDs */
+#define SPRT_FID_VERSION U(0x0)
+#define SPRT_FID_RETURN_RESPONSE U(0x1)
+
+#define SPRT_FID_MASK U(0xFF)
+
+/* Definitions to build the complete SMC ID */
+#define SPRT_SMC_ID(sprt_fid) ((FUNCID_SERV_SPRT << FUNCID_SERV_SHIFT) | \
+ (U(1) << 31) | ((sprt_fid) & SPRT_FID_MASK))
+
+/* Complete SMC IDs */
+#define SPRT_VERSION SPRT_SMC_ID(SPRT_FID_VERSION)
+#define SPRT_RETURN_RESPONSE SPRT_SMC_ID(SPRT_FID_RETURN_RESPONSE)
+
+/* SPRT error codes. */
+#define SPRT_SUCCESS 0
+#define SPRT_NOT_SUPPORTED -1
+#define SPRT_INVALID_PARAMETER -2
+
+#endif /* __SPRT_SVC_H__ */
diff --git a/tests/tests.mk b/tests/tests.mk
index 24f2316..3c84454 100644
--- a/tests/tests.mk
+++ b/tests/tests.mk
@@ -4,6 +4,20 @@
# SPDX-License-Identifier: BSD-3-Clause
#
+ifeq (${TESTS_FILE},tests/tests-spm-legacy.xml)
+ SPM_TESTS_SOURCES := \
+ tests/runtime_services/secure_service/secure_service_helpers.c \
+ $(addprefix tests/runtime_services/secure_service/legacy/, \
+ test_secure_service_handle.c \
+ test_secure_service_interrupts.c \
+ )
+endif
+
+ifeq (${TESTS_FILE},tests/tests-spm-spci-sprt.xml)
+ SPM_TESTS_SOURCES := \
+ tests/runtime_services/secure_service/secure_service_helpers.c
+endif
+
TESTS_SOURCES := tests/extensions/amu/test_amu.c \
tests/framework_validation_tests/test_timer_framework.c \
tests/framework_validation_tests/test_validation_events.c \
@@ -12,9 +26,6 @@ TESTS_SOURCES := tests/extensions/amu/test_amu.c \
tests/framework_validation_tests/test_validation_sgi.c \
tests/performance_tests/smc_latencies.c \
tests/runtime_services/arm_arch_svc/arm_arch_svc.c \
- tests/runtime_services/secure_service/legacy/test_secure_service_handle.c \
- tests/runtime_services/secure_service/legacy/test_secure_service_interrupts.c \
- tests/runtime_services/secure_service/secure_service_helpers.c \
tests/runtime_services/sip_service/test_exec_state_switch.c \
tests/runtime_services/sip_service/test_exec_state_switch_asm.S \
tests/runtime_services/standard_service/pmf/api_tests/runtime_instr/test_pmf_rt_instr.c \
@@ -44,7 +55,8 @@ TESTS_SOURCES := tests/extensions/amu/test_amu.c \
tests/runtime_services/trusted_os/tsp/test_irq_preempted_std_smc.c \
tests/runtime_services/trusted_os/tsp/test_normal_int_switch.c \
tests/runtime_services/trusted_os/tsp/test_smc_tsp_std_fn_call.c \
- tests/runtime_services/trusted_os/tsp/test_tsp_fast_smc.c
+ tests/runtime_services/trusted_os/tsp/test_tsp_fast_smc.c \
+ ${SPM_TESTS_SOURCES}
ifeq (${FWU_BL_TEST},1)
TESTS_SOURCES += tests/fwu_tests/test_fwu_toc.c \