summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSandrine Bailleux <sandrine.bailleux@arm.com>2018-01-16 10:07:39 +0100
committerSandrine Bailleux <sandrine.bailleux@arm.com>2018-01-22 14:49:59 +0000
commit545817be60d1a6e8dc3366cbe7a25b22233f6311 (patch)
tree7226f5e02fe904334d13f324961a882e4fe96644
parent992788147ff7461b37eb52f17ad962ef21fc372f (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>
-rw-r--r--cactus/cactus.h17
-rw-r--r--cactus/cactus.mk1
-rw-r--r--cactus/cactus_fast_secure_services.c67
-rw-r--r--cactus/cactus_main.c4
-rw-r--r--include/lib/aarch64/arch.h2
-rw-r--r--include/runtime_services/secure_el0_payloads/secure_partition.h5
-rw-r--r--plat/arm/board/fvp/include/platform_def.h4
7 files changed, 98 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;
}
diff --git a/include/lib/aarch64/arch.h b/include/lib/aarch64/arch.h
index 22c8a62..fe97b25 100644
--- a/include/lib/aarch64/arch.h
+++ b/include/lib/aarch64/arch.h
@@ -368,6 +368,8 @@
******************************************************************************/
/* Physical Count register. */
#define CNTPCT_LO 0x0
+/* Counter Frequency register. */
+#define CNTFRQ 0x10
/* Physical Timer CompareValue register. */
#define CNTP_CVAL_LO 0x20
/* Physical Timer Control register. */
diff --git a/include/runtime_services/secure_el0_payloads/secure_partition.h b/include/runtime_services/secure_el0_payloads/secure_partition.h
index f5c2004..994c0a8 100644
--- a/include/runtime_services/secure_el0_payloads/secure_partition.h
+++ b/include/runtime_services/secure_el0_payloads/secure_partition.h
@@ -69,6 +69,11 @@ typedef struct secure_partition_request_info {
uint8_t data[SPS_MAX_PAYLOAD_SIZE];
} secure_partition_request_info_t;
+/* Define some fast secure partition requests (SPS) IDs. */
+#define SPS_TIMER_SLEEP 1
+
+#define CACTUS_FAST_REQUEST_SUCCESS 0xCACF900D
+
secure_partition_request_info_t *create_sps_request(uint32_t id,
const void *data,
uint64_t data_size);
diff --git a/plat/arm/board/fvp/include/platform_def.h b/plat/arm/board/fvp/include/platform_def.h
index e734371..052d7d1 100644
--- a/plat/arm/board/fvp/include/platform_def.h
+++ b/plat/arm/board/fvp/include/platform_def.h
@@ -136,6 +136,10 @@
/******************************************************************************
* Memory mapped Generic timer interfaces
******************************************************************************/
+/* REFCLK CNTControl, Generic Timer. Secure Access only. */
+#define SYS_CNT_CONTROL_BASE 0x2a430000
+/* REFCLK CNTRead, Generic Timer. */
+#define SYS_CNT_READ_BASE 0x2a800000
/* AP_REFCLK CNTBase1, Generic Timer. */
#define SYS_CNT_BASE1 0x2a830000