blob: bfbfa48c54b1384d950c31d4023eecd6cb3e0b84 [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 <console.h>
10#include <debug.h>
Antonio Nino Diaz43ef3932018-07-03 14:39:47 +010011#include <errno.h>
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020012#include <pl011.h>
13#include <plat_arm.h>
14#include <platform_def.h>
Antonio Nino Diaz43ef3932018-07-03 14:39:47 +010015#include <sprt_client.h>
16#include <sprt_svc.h>
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020017#include <std_svc.h>
18
19#include "cactus.h"
Antonio Nino Diaz1486f3b2018-06-26 10:30:10 +010020#include "cactus_def.h"
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020021#include "cactus_tests.h"
22
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020023/* Host machine information injected by the build system in the ELF file. */
24extern const char build_message[];
25extern const char version_string[];
26
Antonio Nino Diaz1486f3b2018-06-26 10:30:10 +010027static void cactus_print_memory_layout(void)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020028{
29 NOTICE("Secure Partition memory layout:\n");
30
Antonio Nino Diaz1486f3b2018-06-26 10:30:10 +010031 NOTICE(" Image regions\n");
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020032 NOTICE(" Text region : %p - %p\n",
Antonio Nino Diaz1486f3b2018-06-26 10:30:10 +010033 (void *)CACTUS_TEXT_START, (void *)CACTUS_TEXT_END);
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020034 NOTICE(" Read-only data region : %p - %p\n",
Antonio Nino Diaz1486f3b2018-06-26 10:30:10 +010035 (void *)CACTUS_RODATA_START, (void *)CACTUS_RODATA_END);
36 NOTICE(" Data region : %p - %p\n",
37 (void *)CACTUS_DATA_START, (void *)CACTUS_DATA_END);
38 NOTICE(" BSS region : %p - %p\n",
39 (void *)CACTUS_BSS_START, (void *)CACTUS_BSS_END);
40 NOTICE(" Total image memory : %p - %p\n",
41 (void *)CACTUS_IMAGE_BASE,
42 (void *)(CACTUS_IMAGE_BASE + CACTUS_IMAGE_SIZE));
43 NOTICE(" SPM regions\n");
44 NOTICE(" SPM <-> SP buffer : %p - %p\n",
45 (void *)CACTUS_SPM_BUF_BASE,
46 (void *)(CACTUS_SPM_BUF_BASE + CACTUS_SPM_BUF_SIZE));
47 NOTICE(" NS <-> SP buffer : %p - %p\n",
48 (void *)CACTUS_NS_BUF_BASE,
49 (void *)(CACTUS_NS_BUF_BASE + CACTUS_NS_BUF_SIZE));
50 NOTICE(" Test regions\n");
51 NOTICE(" Test region : %p - %p\n",
52 (void *)CACTUS_TEST_MEM_BASE,
53 (void *)(CACTUS_TEST_MEM_BASE + CACTUS_TEST_MEM_SIZE));
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020054}
55
Antonio Nino Diaz43ef3932018-07-03 14:39:47 +010056static void cactus_message_handler(struct sprt_queue_entry_message *message)
57{
58 u_register_t ret0 = 0U, ret1 = 0U, ret2 = 0U, ret3 = 0U;
59
60 if (message->type == SPRT_MSG_TYPE_SERVICE_REQUEST) {
61 switch (message->args[1]) {
62
63 case CACTUS_PRINT_MAGIC:
64 INFO("Cactus: Magic: 0x%x\n", CACTUS_MAGIC_NUMBER);
65 ret0 = SPRT_SUCCESS;
66 break;
67
68 case CACTUS_GET_MAGIC:
69 ret1 = CACTUS_MAGIC_NUMBER;
70 ret0 = SPRT_SUCCESS;
71 break;
72
73 default:
74 NOTICE("Cactus: Unhandled Service ID 0x%x\n",
75 (unsigned int)message->args[1]);
76 ret0 = SPRT_NOT_SUPPORTED;
77 break;
78 }
79 } else {
80 NOTICE("Cactus: Unhandled Service type 0x%x\n",
81 (unsigned int)message->type);
82 ret0 = SPRT_NOT_SUPPORTED;
83 }
84
85 sprt_message_end(message, ret0, ret1, ret2, ret3);
86}
87
Antonio Nino Diaz1486f3b2018-06-26 10:30:10 +010088void __dead2 cactus_main(void)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020089{
Antonio Nino Diaz99f4fd22018-07-03 20:25:16 +010090 console_init(PL011_UART2_BASE,
91 PL011_UART2_CLK_IN_HZ,
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020092 PL011_BAUDRATE);
93
94 NOTICE("Booting test Secure Partition Cactus\n");
95 NOTICE("%s\n", build_message);
96 NOTICE("%s\n", version_string);
97 NOTICE("Running at S-EL0\n");
98
Antonio Nino Diaz1486f3b2018-06-26 10:30:10 +010099 cactus_print_memory_layout();
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200100
101 /*
102 * Run some initial tests.
103 *
104 * These are executed when the system is still booting, just after SPM
105 * has handed over to Cactus.
106 */
107 misc_tests();
108 system_setup_tests();
Antonio Nino Diaz1486f3b2018-06-26 10:30:10 +0100109 mem_attr_changes_tests();
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200110
111 /*
112 * Handle secure service requests.
113 */
Antonio Nino Diaz43ef3932018-07-03 14:39:47 +0100114 sprt_initialize_queues((void *)CACTUS_SPM_BUF_BASE);
115
116 while (1) {
117 struct sprt_queue_entry_message message;
118
119 /*
120 * Try to fetch a message from the blocking requests queue. If
121 * it is empty, try to fetch from the non-blocking requests
122 * queue. Repeat until both of them are empty.
123 */
124 while (1) {
125 int err = sprt_get_next_message(&message,
126 SPRT_QUEUE_NUM_BLOCKING);
127 if (err == -ENOENT) {
128 err = sprt_get_next_message(&message,
129 SPRT_QUEUE_NUM_NON_BLOCKING);
130 if (err == -ENOENT) {
131 break;
132 } else {
133 assert(err == 0);
134 cactus_message_handler(&message);
135 }
136 } else {
137 assert(err == 0);
138 cactus_message_handler(&message);
139 }
140 }
141
142 sprt_wait_for_messages();
143 }
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200144}