blob: cd81e882db0c9da0525bdd6f2359256cb98f01d1 [file] [log] [blame]
Antonio Nino Diaz0b1ab402018-12-05 15:38:39 +00001/*
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 <console.h>
9#include <debug.h>
10#include <errno.h>
11#include <ivy_def.h>
12#include <pl011.h>
13#include <plat_arm.h>
14#include <platform_def.h>
15#include <sprt_client.h>
16#include <sprt_svc.h>
17
18#include "ivy.h"
19#include "ivy_def.h"
20
21/* Host machine information injected by the build system in the ELF file. */
22extern const char build_message[];
23extern const char version_string[];
24
25static void ivy_print_memory_layout(void)
26{
27 NOTICE("Secure Partition memory layout:\n");
28
29 NOTICE(" Image regions\n");
30 NOTICE(" Text region : %p - %p\n",
31 (void *)IVY_TEXT_START, (void *)IVY_TEXT_END);
32 NOTICE(" Read-only data region : %p - %p\n",
33 (void *)IVY_RODATA_START, (void *)IVY_RODATA_END);
34 NOTICE(" Data region : %p - %p\n",
35 (void *)IVY_DATA_START, (void *)IVY_DATA_END);
36 NOTICE(" BSS region : %p - %p\n",
37 (void *)IVY_BSS_START, (void *)IVY_BSS_END);
38 NOTICE(" Total image memory : %p - %p\n",
39 (void *)IVY_IMAGE_BASE,
40 (void *)(IVY_IMAGE_BASE + IVY_IMAGE_SIZE));
41 NOTICE(" SPM regions\n");
42 NOTICE(" SPM <-> SP buffer : %p - %p\n",
43 (void *)IVY_SPM_BUF_BASE,
44 (void *)(IVY_SPM_BUF_BASE + IVY_SPM_BUF_SIZE));
45 NOTICE(" NS <-> SP buffer : %p - %p\n",
46 (void *)IVY_NS_BUF_BASE,
47 (void *)(IVY_NS_BUF_BASE + IVY_NS_BUF_SIZE));
48}
49
50void ivy_message_handler(struct sprt_queue_entry_message *message)
51{
52 u_register_t ret0 = 0U, ret1 = 0U, ret2 = 0U, ret3 = 0U;
53
54 if (message->type == SPRT_MSG_TYPE_SERVICE_REQUEST) {
55 switch (message->args[1]) {
56
57 case IVY_PRINT_MAGIC:
58 INFO("IVY: Magic: 0x%x\n", IVY_MAGIC_NUMBER);
59 ret0 = SPRT_SUCCESS;
60 break;
61
62 case IVY_GET_MAGIC:
63 ret1 = IVY_MAGIC_NUMBER;
64 ret0 = SPRT_SUCCESS;
65 break;
66
67 default:
68 NOTICE("IVY: Unhandled Service ID 0x%x\n",
69 (unsigned int)message->args[1]);
70 ret0 = SPRT_NOT_SUPPORTED;
71 break;
72 }
73 } else {
74 NOTICE("Ivy: Unhandled Service type 0x%x\n",
75 (unsigned int)message->type);
76 ret0 = SPRT_NOT_SUPPORTED;
77 }
78
79
80 sprt_message_end(message, ret0, ret1, ret2, ret3);
81}
82
83void __dead2 ivy_main(void)
84{
85 console_init(PL011_UART3_BASE,
86 PL011_UART3_CLK_IN_HZ,
87 PL011_BAUDRATE);
88
89 NOTICE("Booting test Secure Partition Ivy\n");
90 NOTICE("%s\n", build_message);
91 NOTICE("%s\n", version_string);
92 NOTICE("Running at S-EL0\n");
93
94 ivy_print_memory_layout();
95
96 /*
97 * Handle secure service requests.
98 */
99 sprt_initialize_queues((void *)IVY_SPM_BUF_BASE);
100
101 while (1) {
102 struct sprt_queue_entry_message message;
103
104 /*
105 * Try to fetch a message from the blocking requests queue. If
106 * it is empty, try to fetch from the non-blocking requests
107 * queue. Repeat until both of them are empty.
108 */
109 while (1) {
110 int err = sprt_get_next_message(&message,
111 SPRT_QUEUE_NUM_BLOCKING);
112 if (err == -ENOENT) {
113 err = sprt_get_next_message(&message,
114 SPRT_QUEUE_NUM_NON_BLOCKING);
115 if (err == -ENOENT) {
116 break;
117 } else {
118 assert(err == 0);
119 ivy_message_handler(&message);
120 }
121 } else {
122 assert(err == 0);
123 ivy_message_handler(&message);
124 }
125 }
126
127 sprt_wait_for_messages();
128 }
129}