blob: 4580f23eb9e66cac0ac2f5122cdb722be61ba4a7 [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>
Antonio Nino Diaz43ef3932018-07-03 14:39:47 +01008#include <cactus_def.h>
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02009#include <debug.h>
Antonio Nino Diaz09a00ef2019-01-11 13:12:58 +000010#include <drivers/arm/pl011.h>
11#include <drivers/console.h>
Antonio Nino Diaz43ef3932018-07-03 14:39:47 +010012#include <errno.h>
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020013#include <plat_arm.h>
14#include <platform_def.h>
Antonio Nino Diaz2ac6f8f2018-07-02 09:04:07 +010015#include <sp_helpers.h>
Antonio Nino Diaz43ef3932018-07-03 14:39:47 +010016#include <sprt_client.h>
17#include <sprt_svc.h>
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020018#include <std_svc.h>
19
20#include "cactus.h"
Antonio Nino Diaz1486f3b2018-06-26 10:30:10 +010021#include "cactus_def.h"
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020022#include "cactus_tests.h"
23
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020024/* Host machine information injected by the build system in the ELF file. */
25extern const char build_message[];
26extern const char version_string[];
27
Antonio Nino Diaz1486f3b2018-06-26 10:30:10 +010028static void cactus_print_memory_layout(void)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020029{
30 NOTICE("Secure Partition memory layout:\n");
31
Antonio Nino Diaz1486f3b2018-06-26 10:30:10 +010032 NOTICE(" Image regions\n");
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020033 NOTICE(" Text region : %p - %p\n",
Antonio Nino Diaz1486f3b2018-06-26 10:30:10 +010034 (void *)CACTUS_TEXT_START, (void *)CACTUS_TEXT_END);
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020035 NOTICE(" Read-only data region : %p - %p\n",
Antonio Nino Diaz1486f3b2018-06-26 10:30:10 +010036 (void *)CACTUS_RODATA_START, (void *)CACTUS_RODATA_END);
37 NOTICE(" Data region : %p - %p\n",
38 (void *)CACTUS_DATA_START, (void *)CACTUS_DATA_END);
39 NOTICE(" BSS region : %p - %p\n",
40 (void *)CACTUS_BSS_START, (void *)CACTUS_BSS_END);
41 NOTICE(" Total image memory : %p - %p\n",
42 (void *)CACTUS_IMAGE_BASE,
43 (void *)(CACTUS_IMAGE_BASE + CACTUS_IMAGE_SIZE));
44 NOTICE(" SPM regions\n");
45 NOTICE(" SPM <-> SP buffer : %p - %p\n",
46 (void *)CACTUS_SPM_BUF_BASE,
47 (void *)(CACTUS_SPM_BUF_BASE + CACTUS_SPM_BUF_SIZE));
48 NOTICE(" NS <-> SP buffer : %p - %p\n",
49 (void *)CACTUS_NS_BUF_BASE,
50 (void *)(CACTUS_NS_BUF_BASE + CACTUS_NS_BUF_SIZE));
51 NOTICE(" Test regions\n");
52 NOTICE(" Test region : %p - %p\n",
53 (void *)CACTUS_TEST_MEM_BASE,
54 (void *)(CACTUS_TEST_MEM_BASE + CACTUS_TEST_MEM_SIZE));
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020055}
56
Antonio Nino Diaz43ef3932018-07-03 14:39:47 +010057static void cactus_message_handler(struct sprt_queue_entry_message *message)
58{
59 u_register_t ret0 = 0U, ret1 = 0U, ret2 = 0U, ret3 = 0U;
60
61 if (message->type == SPRT_MSG_TYPE_SERVICE_REQUEST) {
62 switch (message->args[1]) {
63
64 case CACTUS_PRINT_MAGIC:
65 INFO("Cactus: Magic: 0x%x\n", CACTUS_MAGIC_NUMBER);
66 ret0 = SPRT_SUCCESS;
67 break;
68
69 case CACTUS_GET_MAGIC:
70 ret1 = CACTUS_MAGIC_NUMBER;
71 ret0 = SPRT_SUCCESS;
72 break;
73
Antonio Nino Diaz2ac6f8f2018-07-02 09:04:07 +010074 case CACTUS_SLEEP_MS:
75 sp_sleep(message->args[2]);
76 ret0 = SPRT_SUCCESS;
77 break;
78
Antonio Nino Diaz43ef3932018-07-03 14:39:47 +010079 default:
80 NOTICE("Cactus: Unhandled Service ID 0x%x\n",
81 (unsigned int)message->args[1]);
82 ret0 = SPRT_NOT_SUPPORTED;
83 break;
84 }
85 } else {
86 NOTICE("Cactus: Unhandled Service type 0x%x\n",
87 (unsigned int)message->type);
88 ret0 = SPRT_NOT_SUPPORTED;
89 }
90
91 sprt_message_end(message, ret0, ret1, ret2, ret3);
92}
93
Antonio Nino Diaz1486f3b2018-06-26 10:30:10 +010094void __dead2 cactus_main(void)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020095{
Antonio Nino Diaz99f4fd22018-07-03 20:25:16 +010096 console_init(PL011_UART2_BASE,
97 PL011_UART2_CLK_IN_HZ,
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020098 PL011_BAUDRATE);
99
100 NOTICE("Booting test Secure Partition Cactus\n");
101 NOTICE("%s\n", build_message);
102 NOTICE("%s\n", version_string);
103 NOTICE("Running at S-EL0\n");
104
Antonio Nino Diaz1486f3b2018-06-26 10:30:10 +0100105 cactus_print_memory_layout();
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200106
107 /*
108 * Run some initial tests.
109 *
110 * These are executed when the system is still booting, just after SPM
111 * has handed over to Cactus.
112 */
113 misc_tests();
114 system_setup_tests();
Antonio Nino Diaz1486f3b2018-06-26 10:30:10 +0100115 mem_attr_changes_tests();
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200116
117 /*
118 * Handle secure service requests.
119 */
Antonio Nino Diaz43ef3932018-07-03 14:39:47 +0100120 sprt_initialize_queues((void *)CACTUS_SPM_BUF_BASE);
121
122 while (1) {
123 struct sprt_queue_entry_message message;
124
125 /*
126 * Try to fetch a message from the blocking requests queue. If
127 * it is empty, try to fetch from the non-blocking requests
128 * queue. Repeat until both of them are empty.
129 */
130 while (1) {
131 int err = sprt_get_next_message(&message,
132 SPRT_QUEUE_NUM_BLOCKING);
133 if (err == -ENOENT) {
134 err = sprt_get_next_message(&message,
135 SPRT_QUEUE_NUM_NON_BLOCKING);
136 if (err == -ENOENT) {
137 break;
138 } else {
139 assert(err == 0);
140 cactus_message_handler(&message);
141 }
142 } else {
143 assert(err == 0);
144 cactus_message_handler(&message);
145 }
146 }
147
148 sprt_wait_for_messages();
149 }
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200150}