diff options
author | Antonio Nino Diaz <antonio.ninodiaz@arm.com> | 2018-03-14 14:26:25 +0000 |
---|---|---|
committer | Antonio Nino Diaz <antonio.ninodiaz@arm.com> | 2018-03-26 18:15:22 +0100 |
commit | 78ea0f89cce0cbde03171ad2855db9de9bab0305 (patch) | |
tree | 673f0acb65ab6afc9ac60a8016af82da4d60c722 /cactus | |
parent | c4a96088776e43f9ab74f6b3dc1b28304601af7c (diff) |
Cactus: Add new Cactus version for SPCI and SPRT
Change-Id: I1c90856346941df4f49811755991c9a0683ce6b2
Signed-off-by: Antonio Nino Diaz <antonio.ninodiaz@arm.com>
Diffstat (limited to 'cactus')
-rw-r--r-- | cactus/cactus.mk | 11 | ||||
-rw-r--r-- | cactus/cactus_helpers.c | 6 | ||||
-rw-r--r-- | cactus/spci_sprt/aarch64/cactus_entrypoint.S | 112 | ||||
-rw-r--r-- | cactus/spci_sprt/cactus_spci_sprt.c | 42 |
4 files changed, 167 insertions, 4 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; + + } + } +} |