diff options
author | Sandrine Bailleux <sandrine.bailleux@arm.com> | 2018-03-13 13:16:12 +0100 |
---|---|---|
committer | Sandrine Bailleux <sandrine.bailleux@arm.com> | 2018-03-19 11:54:40 +0000 |
commit | 90d54fce5f4c2ed0ab4de290e2c47f9093d998b2 (patch) | |
tree | 67090a9fa733bf5465ad520d966e6f1ff64559f8 | |
parent | 2c95f88f8fff99f8ab41bd1a7fd6b9100b18e445 (diff) |
Cactus: Move legacy MM_COMMUNICATE code in a sub-directory
The goal is to easily build a version of Cactus that speaks the
MM_COMMUNICATE legacy language, without interfering with the new
SPCI/SPRT interfaces.
This patch introduces the notion of "profile" for Cactus. For now, the
only profile is "legacy". In a subsequent patch we will introduce a
profile for SPCI/SPRT. Profiles are specified on the command line when
building Cactus, e.g.:
> make CACTUS_PROFILE=legacy cactus
The initialisation code is shared amongst all profiles but then each
profile is supposed to provide its own version of the
secure_services_loop() function, which is called from cactus_main().
The profile name is printed in the version string at boot time.
The cactus_sleep() function has been moved to the cactus_helpers.c
file because it will be shared amongst the legacy and SPCI/SPRT
profiles.
Change-Id: Iab1d0ec972f9bd5b818eec6eed131fd0ea328c51
Signed-off-by: Sandrine Bailleux <sandrine.bailleux@arm.com>
-rw-r--r-- | cactus/cactus.h | 16 | ||||
-rw-r--r-- | cactus/cactus.mk | 50 | ||||
-rw-r--r-- | cactus/cactus_fast_secure_services.c | 67 | ||||
-rw-r--r-- | cactus/cactus_helpers.c | 16 | ||||
-rw-r--r-- | cactus/cactus_helpers.h | 4 | ||||
-rw-r--r-- | cactus/cactus_main.c | 81 | ||||
-rw-r--r-- | cactus/legacy/aarch64/cactus_entrypoint.S (renamed from cactus/aarch64/cactus_entrypoint.S) | 0 | ||||
-rw-r--r-- | cactus/legacy/cactus_legacy.c | 138 |
8 files changed, 195 insertions, 177 deletions
diff --git a/cactus/cactus.h b/cactus/cactus.h index 7378360..7f86c92 100644 --- a/cactus/cactus.h +++ b/cactus/cactus.h @@ -27,20 +27,10 @@ extern uintptr_t __BSS_START__, __BSS_END__; #define CACTUS_BSS_START ((uintptr_t)&__BSS_START__) #define CACTUS_BSS_END ((uintptr_t)&__BSS_END__) - /* - * Handle a fast secure service request, i.e. one made through an MM_COMMUNICATE - * call. - * - * cc - * Calling convention. If MM_COMMUNICATE has been invoked using the SMC32 - * calling convention, this argument must be 32, else 64. - * - * sps - * Communication buffer attached to the secure partition service request. + * Once Cactus has finished its initialisation, this is the function it will + * jump to to handle runtime services for the rest of its lifetime. */ -int32_t cactus_handle_fast_request(int cc, - secure_partition_request_info_t *sps); - +__dead2 void secure_services_loop(void); #endif /* __CACTUS_H__ */ diff --git a/cactus/cactus.mk b/cactus/cactus.mk index 4c18e92..95bc64b 100644 --- a/cactus/cactus.mk +++ b/cactus/cactus.mk @@ -6,27 +6,43 @@ INCLUDES += -I cactus -CACTUS_SOURCES := cactus/aarch64/cactus_entrypoint.S \ - cactus/aarch64/cactus_arch_helpers.S \ - cactus/cactus_fast_secure_services.c \ - cactus/cactus_helpers.c \ - cactus/cactus_main.c \ - cactus/cactus_tests_memory_attributes.c \ - cactus/cactus_tests_misc.c \ - cactus/cactus_tests_system_setup.c \ - drivers/arm/pl011/${ARCH}/pl011_console.S \ +CACTUS_SOURCES := $(addprefix cactus/, \ + aarch64/cactus_arch_helpers.S \ + cactus_helpers.c \ + cactus_main.c \ + cactus_tests_memory_attributes.c \ + cactus_tests_misc.c \ + cactus_tests_system_setup.c \ +) + +STDLIB_SOURCES := $(addprefix lib/stdlib/, \ + assert.c \ + mem.c \ + putchar.c \ + printf.c \ + rand.c \ + strlen.c \ + subr_prf.c \ +) + +CACTUS_SOURCES += drivers/arm/pl011/${ARCH}/pl011_console.S \ framework/debug.c \ framework/${ARCH}/asm_debug.S \ lib/${ARCH}/cache_helpers.S \ lib/${ARCH}/misc_helpers.S \ - lib/stdlib/assert.c \ - lib/stdlib/mem.c \ - lib/stdlib/putchar.c \ - lib/stdlib/printf.c \ - lib/stdlib/rand.c \ - lib/stdlib/strlen.c \ - lib/stdlib/subr_prf.c \ - plat/common/${ARCH}/platform_helpers.S + plat/common/${ARCH}/platform_helpers.S \ + ${STDLIB_SOURCES} + +CACTUS_PROFILE ?= legacy + +ifeq (${CACTUS_PROFILE},legacy) + VERSION_STRING := ${VERSION_STRING}-legacy + + CACTUS_SOURCES += $(addprefix cactus/legacy/, \ + aarch64/cactus_entrypoint.S \ + cactus_legacy.c \ + ) +endif CACTUS_LINKERFILE := cactus/cactus.ld.S diff --git a/cactus/cactus_fast_secure_services.c b/cactus/cactus_fast_secure_services.c deleted file mode 100644 index dae1119..0000000 --- a/cactus/cactus_fast_secure_services.c +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#include <assert.h> -#include <debug.h> -#include <mmio.h> -#include <platform_def.h> -#include <secure_partition.h> -#include <spm_svc.h> -#include <string.h> - - -static 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); - - INFO("Sleeping for %u seconds...\n", 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"); -} - - -int32_t cactus_handle_fast_request(int cc, secure_partition_request_info_t *sps) -{ - assert(cc == 32 || cc == 64); - - /* No SMC32 is supported at the moment. Just ignore them. */ - if (cc == 32) { - INFO("Ignoring MM_COMMUNICATE_AARCH32 call\n"); - return SPM_SUCCESS; - } - - /* See secure_partition.h for possible ID values. */ - switch (sps->id) { - case SPS_TIMER_SLEEP: { - if (sps->data_size != 1) { - ERROR("Invalid payload size for SPM_SPS_TIMER_SLEEP request (%lu)\n", - sps->data_size); - return SPM_INVALID_PARAMETER; - } - int duration_sec = sps->data[0]; - cactus_sleep(duration_sec); - - /* - * Write back to the communication buffer to acknowledge the - * request has been successfully handled. - */ - uint32_t response = CACTUS_FAST_REQUEST_SUCCESS; - memcpy(sps->data, &response, sizeof(response)); - return SPM_SUCCESS; - } - - default: - INFO("Unsupported MM_COMMUNICATE_AARCH64 call with service ID 0x%x, ignoring it\n", - sps->id); - return SPM_SUCCESS; - } -} diff --git a/cactus/cactus_helpers.c b/cactus/cactus_helpers.c index 7b646bc..8844339 100644 --- a/cactus/cactus_helpers.c +++ b/cactus/cactus_helpers.c @@ -5,6 +5,8 @@ */ #include <debug.h> +#include <mmio.h> +#include <platform_def.h> #include <stdint.h> #include <stdlib.h> @@ -53,3 +55,17 @@ void announce_test_end(const char *test_desc) INFO("Test \"%s\" passed.\n", 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); + + INFO("Sleeping for %u seconds...\n", 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"); +} diff --git a/cactus/cactus_helpers.h b/cactus/cactus_helpers.h index 465ced3..cbd91aa 100644 --- a/cactus/cactus_helpers.h +++ b/cactus/cactus_helpers.h @@ -8,6 +8,7 @@ #define __CACTUS_HELPERS_H__ #include <stdint.h> +#include <sys/types.h> typedef struct { @@ -55,4 +56,7 @@ void announce_test_section_end(const char *test_sect_desc); void announce_test_start(const char *test_desc); void announce_test_end(const char *test_desc); +/* Sleep for at least 'duration_sec' seconds then return. */ +void cactus_sleep(uint32_t duration_sec); + #endif /* __CACTUS_HELPERS_H__ */ diff --git a/cactus/cactus_main.c b/cactus/cactus_main.c index f0605d0..e32b616 100644 --- a/cactus/cactus_main.c +++ b/cactus/cactus_main.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved. + * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ @@ -7,7 +7,6 @@ #include <assert.h> #include <console.h> #include <debug.h> -#include <mm_svc.h> #include <pl011.h> #include <plat_arm.h> #include <platform_def.h> @@ -76,84 +75,6 @@ static void cactus_print_memory_layout(const secure_partition_boot_info_t *boot_ } - - -static __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 = SP_EVENT_COMPLETE_AARCH64; - svc_values.arg1 = event_status_code; - int32_t event_id = cactus_svc(&svc_values); - - switch (event_id) { - case MM_COMMUNICATE_AARCH64: - { - uint64_t ctx_addr = svc_values.arg1; - uint32_t ctx_size = svc_values.arg2; - uint64_t cookie = svc_values.arg3; - - NOTICE("Cactus: Received MM_COMMUNICATE_AARCH64 call\n"); - NOTICE("Cactus: Context address: 0x%lx\n", ctx_addr); - NOTICE("Cactus: Context size : %u\n", ctx_size); - NOTICE("Cactus: Cookie : 0x%lx\n", cookie); - - if (ctx_addr == 0) { - ERROR("Context address is invalid\n"); - event_status_code = SPM_INVALID_PARAMETER; - continue; - } - - secure_partition_request_info_t *sps = (void *)(uintptr_t) ctx_addr; - NOTICE("Received fast secure service request with ID #%u\n", - sps->id); - event_status_code = cactus_handle_fast_request(64, sps); - break; - } - - case MM_COMMUNICATE_AARCH32: - { - uint32_t ctx_addr = svc_values.arg1; - uint32_t ctx_size = svc_values.arg2; - uint32_t cookie = svc_values.arg3; - - NOTICE("Cactus: Received MM_COMMUNICATE_AARCH32 call\n"); - NOTICE("Cactus: Context address: 0x%x\n", ctx_addr); - NOTICE("Cactus: Context size : %u\n", ctx_size); - NOTICE("Cactus: Cookie : 0x%x\n", cookie); - - if (ctx_addr == 0) { - ERROR("Context address is invalid\n"); - event_status_code = SPM_INVALID_PARAMETER; - continue; - } - - secure_partition_request_info_t *sps = (void *)(uintptr_t) ctx_addr; - NOTICE("Received fast secure service request with ID #%u\n", - sps->id); - event_status_code = cactus_handle_fast_request(32, sps); - break; - } - - default: - NOTICE("Unhandled Service ID 0x%x\n", event_id); - event_status_code = SPM_NOT_SUPPORTED; - break; - } - } -} - - void __dead2 cactus_main(void *el3_el0_buffer, size_t el3_el0_buffer_size) { console_init(PLAT_ARM_UART_BASE, diff --git a/cactus/aarch64/cactus_entrypoint.S b/cactus/legacy/aarch64/cactus_entrypoint.S index 6ac51a7..6ac51a7 100644 --- a/cactus/aarch64/cactus_entrypoint.S +++ b/cactus/legacy/aarch64/cactus_entrypoint.S diff --git a/cactus/legacy/cactus_legacy.c b/cactus/legacy/cactus_legacy.c new file mode 100644 index 0000000..134bc46 --- /dev/null +++ b/cactus/legacy/cactus_legacy.c @@ -0,0 +1,138 @@ +/* + * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include <assert.h> +#include <cactus_helpers.h> +#include <debug.h> +#include <mm_svc.h> +#include <secure_partition.h> +#include <spm_svc.h> +#include <string.h> + + +/* + * Handle a fast secure service request, i.e. one made through an MM_COMMUNICATE + * call. + * + * cc + * Calling convention. If MM_COMMUNICATE has been invoked using the SMC32 + * calling convention, this argument must be 32, else 64. + * + * sps + * Communication buffer attached to the secure partition service request. + */ +static int32_t cactus_handle_fast_request(int cc, + secure_partition_request_info_t *sps) +{ + assert(cc == 32 || cc == 64); + + /* No SMC32 is supported at the moment. Just ignore them. */ + if (cc == 32) { + INFO("Ignoring MM_COMMUNICATE_AARCH32 call\n"); + return SPM_SUCCESS; + } + + /* See secure_partition.h for possible ID values. */ + switch (sps->id) { + case SPS_TIMER_SLEEP: { + if (sps->data_size != 1) { + ERROR("Invalid payload size for SPM_SPS_TIMER_SLEEP request (%lu)\n", + sps->data_size); + return SPM_INVALID_PARAMETER; + } + int duration_sec = sps->data[0]; + cactus_sleep(duration_sec); + + /* + * Write back to the communication buffer to acknowledge the + * request has been successfully handled. + */ + uint32_t response = CACTUS_FAST_REQUEST_SUCCESS; + memcpy(sps->data, &response, sizeof(response)); + return SPM_SUCCESS; + } + + default: + INFO("Unsupported MM_COMMUNICATE_AARCH64 call with service ID 0x%x, ignoring it\n", + sps->id); + return SPM_SUCCESS; + } +} + +__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 = SP_EVENT_COMPLETE_AARCH64; + svc_values.arg1 = event_status_code; + int32_t event_id = cactus_svc(&svc_values); + + switch (event_id) { + case MM_COMMUNICATE_AARCH64: + { + uint64_t ctx_addr = svc_values.arg1; + uint32_t ctx_size = svc_values.arg2; + uint64_t cookie = svc_values.arg3; + + NOTICE("Cactus: Received MM_COMMUNICATE_AARCH64 call\n"); + NOTICE("Cactus: Context address: 0x%lx\n", ctx_addr); + NOTICE("Cactus: Context size : %u\n", ctx_size); + NOTICE("Cactus: Cookie : 0x%lx\n", cookie); + + if (ctx_addr == 0) { + ERROR("Context address is invalid\n"); + event_status_code = SPM_INVALID_PARAMETER; + continue; + } + + secure_partition_request_info_t *sps = (void *)(uintptr_t) ctx_addr; + NOTICE("Received fast secure service request with ID #%u\n", + sps->id); + event_status_code = cactus_handle_fast_request(64, sps); + break; + } + + case MM_COMMUNICATE_AARCH32: + { + uint32_t ctx_addr = svc_values.arg1; + uint32_t ctx_size = svc_values.arg2; + uint32_t cookie = svc_values.arg3; + + NOTICE("Cactus: Received MM_COMMUNICATE_AARCH32 call\n"); + NOTICE("Cactus: Context address: 0x%x\n", ctx_addr); + NOTICE("Cactus: Context size : %u\n", ctx_size); + NOTICE("Cactus: Cookie : 0x%x\n", cookie); + + if (ctx_addr == 0) { + ERROR("Context address is invalid\n"); + event_status_code = SPM_INVALID_PARAMETER; + continue; + } + + secure_partition_request_info_t *sps = (void *)(uintptr_t) ctx_addr; + NOTICE("Received fast secure service request with ID #%u\n", + sps->id); + event_status_code = cactus_handle_fast_request(32, sps); + break; + } + + default: + NOTICE("Unhandled Service ID 0x%x\n", event_id); + event_status_code = SPM_NOT_SUPPORTED; + break; + } + } +} |