diff options
author | Sandrine Bailleux <sandrine.bailleux@arm.com> | 2018-01-16 10:07:39 +0100 |
---|---|---|
committer | Sandrine Bailleux <sandrine.bailleux@arm.com> | 2018-01-22 14:49:59 +0000 |
commit | 545817be60d1a6e8dc3366cbe7a25b22233f6311 (patch) | |
tree | 7226f5e02fe904334d13f324961a882e4fe96644 /cactus | |
parent | 992788147ff7461b37eb52f17ad962ef21fc372f (diff) |
Cactus: Implement timer sleep secure service
Add support for the first fast secure service in Cactus: the timer
sleep secure service, which allows a caller to request Cactus to
sleep for a certain amount of time.
Change-Id: I85263d33ca570ef08ecc51164ba89d288d1a2cbc
Signed-off-by: Sandrine Bailleux <sandrine.bailleux@arm.com>
Diffstat (limited to 'cactus')
-rw-r--r-- | cactus/cactus.h | 17 | ||||
-rw-r--r-- | cactus/cactus.mk | 1 | ||||
-rw-r--r-- | cactus/cactus_fast_secure_services.c | 67 | ||||
-rw-r--r-- | cactus/cactus_main.c | 4 |
4 files changed, 87 insertions, 2 deletions
diff --git a/cactus/cactus.h b/cactus/cactus.h index 88a041e..7378360 100644 --- a/cactus/cactus.h +++ b/cactus/cactus.h @@ -7,6 +7,7 @@ #ifndef __CACTUS_H__ #define __CACTUS_H__ +#include <secure_partition.h> #include <types.h> /* Linker symbols used to figure out the memory layout of Cactus. */ @@ -26,4 +27,20 @@ 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. + */ +int32_t cactus_handle_fast_request(int cc, + secure_partition_request_info_t *sps); + + #endif /* __CACTUS_H__ */ diff --git a/cactus/cactus.mk b/cactus/cactus.mk index 0ca9be7..0f1a4bc 100644 --- a/cactus/cactus.mk +++ b/cactus/cactus.mk @@ -8,6 +8,7 @@ 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 \ diff --git a/cactus/cactus_fast_secure_services.c b/cactus/cactus_fast_secure_services.c new file mode 100644 index 0000000..dae1119 --- /dev/null +++ b/cactus/cactus_fast_secure_services.c @@ -0,0 +1,67 @@ +/* + * 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_main.c b/cactus/cactus_main.c index 3dd5009..f0605d0 100644 --- a/cactus/cactus_main.c +++ b/cactus/cactus_main.c @@ -117,7 +117,7 @@ static __dead2 void secure_services_loop(void) 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 = SPM_SUCCESS; + event_status_code = cactus_handle_fast_request(64, sps); break; } @@ -141,7 +141,7 @@ static __dead2 void secure_services_loop(void) 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 = SPM_SUCCESS; + event_status_code = cactus_handle_fast_request(32, sps); break; } |