blob: 9f542b54890739a4ef7cefbdbec89826d71f5d65 [file] [log] [blame]
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02001/*
2 * Copyright (c) 2018, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <assert.h>
8#include <debug.h>
9#include <mm_svc.h>
10#include <secure_partition.h>
11#include <sp_helpers.h>
12#include <spm_svc.h>
13#include <string.h>
14
15
16/*
17 * Handle a fast secure service request, i.e. one made through an MM_COMMUNICATE
18 * call.
19 *
20 * cc
21 * Calling convention. If MM_COMMUNICATE has been invoked using the SMC32
22 * calling convention, this argument must be 32, else 64.
23 *
24 * sps
25 * Communication buffer attached to the secure partition service request.
26 */
27static int32_t cactus_handle_fast_request(int cc,
28 secure_partition_request_info_t *sps)
29{
30 assert(cc == 32 || cc == 64);
31
32 /* No SMC32 is supported at the moment. Just ignore them. */
33 if (cc == 32) {
34 INFO("Ignoring MM_COMMUNICATE_AARCH32 call\n");
35 return SPM_SUCCESS;
36 }
37
38 /* See secure_partition.h for possible ID values. */
39 switch (sps->id) {
40 case SPS_TIMER_SLEEP: {
41 if (sps->data_size != 1) {
42 ERROR("Invalid payload size for SPM_SPS_TIMER_SLEEP request (%llu)\n",
43 sps->data_size);
44 return SPM_INVALID_PARAMETER;
45 }
46 int duration_sec = sps->data[0];
47 sp_sleep(duration_sec);
48
49 /*
50 * Write back to the communication buffer to acknowledge the
51 * request has been successfully handled.
52 */
53 uint32_t response = CACTUS_FAST_REQUEST_SUCCESS;
54 memcpy(sps->data, &response, sizeof(response));
55 return SPM_SUCCESS;
56 }
57
58 case SPS_CHECK_ALIVE:
59 return SPM_SUCCESS;
60
61 default:
62 INFO("Unsupported MM_COMMUNICATE_AARCH64 call with service ID 0x%x, ignoring it\n",
63 sps->id);
64 return SPM_INVALID_PARAMETER;
65 }
66}
67
68__dead2 void secure_services_loop(void)
69{
70 int32_t event_status_code;
71 svc_args svc_values = { 0 };
72
73 /*
74 * The first time this loop is executed corresponds to when Cactus has
75 * finished initialising its run time environment and is ready to handle
76 * secure service requests.
77 */
78 NOTICE("Cactus: Signal end of init to SPM\n");
79 event_status_code = SPM_SUCCESS;
80
81 while (1) {
82 svc_values.arg0 = SP_EVENT_COMPLETE_AARCH64;
83 svc_values.arg1 = event_status_code;
84 int32_t event_id = sp_svc(&svc_values);
85
86 switch (event_id) {
87 case MM_COMMUNICATE_AARCH64:
88 {
89 uint64_t ctx_addr = svc_values.arg1;
90 uint32_t ctx_size = svc_values.arg2;
91 uint64_t cookie = svc_values.arg3;
92
93 NOTICE("Cactus: Received MM_COMMUNICATE_AARCH64 call\n");
94 NOTICE("Cactus: Context address: 0x%llx\n", ctx_addr);
95 NOTICE("Cactus: Context size : %u\n", ctx_size);
96 NOTICE("Cactus: Cookie : 0x%llx\n", cookie);
97
98 if (ctx_addr == 0) {
99 ERROR("Context address is invalid\n");
100 event_status_code = SPM_INVALID_PARAMETER;
101 continue;
102 }
103
104 secure_partition_request_info_t *sps = (void *)(uintptr_t) ctx_addr;
105 NOTICE("Received fast secure service request with ID #%u\n",
106 sps->id);
107 event_status_code = cactus_handle_fast_request(64, sps);
108 break;
109 }
110
111 case MM_COMMUNICATE_AARCH32:
112 {
113 uint32_t ctx_addr = svc_values.arg1;
114 uint32_t ctx_size = svc_values.arg2;
115 uint32_t cookie = svc_values.arg3;
116
117 NOTICE("Cactus: Received MM_COMMUNICATE_AARCH32 call\n");
118 NOTICE("Cactus: Context address: 0x%x\n", ctx_addr);
119 NOTICE("Cactus: Context size : %u\n", ctx_size);
120 NOTICE("Cactus: Cookie : 0x%x\n", cookie);
121
122 if (ctx_addr == 0) {
123 ERROR("Context address is invalid\n");
124 event_status_code = SPM_INVALID_PARAMETER;
125 continue;
126 }
127
128 secure_partition_request_info_t *sps = (void *)(uintptr_t) ctx_addr;
129 NOTICE("Received fast secure service request with ID #%u\n",
130 sps->id);
131 event_status_code = cactus_handle_fast_request(32, sps);
132 break;
133 }
134
135 default:
136 NOTICE("Unhandled Service ID 0x%x\n", event_id);
137 event_status_code = SPM_NOT_SUPPORTED;
138 break;
139 }
140 }
141}