Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 1 | /* |
| 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 Diaz | 43ef393 | 2018-07-03 14:39:47 +0100 | [diff] [blame] | 8 | #include <cactus_def.h> |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 9 | #include <debug.h> |
Antonio Nino Diaz | 09a00ef | 2019-01-11 13:12:58 +0000 | [diff] [blame^] | 10 | #include <drivers/arm/pl011.h> |
| 11 | #include <drivers/console.h> |
Antonio Nino Diaz | 43ef393 | 2018-07-03 14:39:47 +0100 | [diff] [blame] | 12 | #include <errno.h> |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 13 | #include <plat_arm.h> |
| 14 | #include <platform_def.h> |
Antonio Nino Diaz | 2ac6f8f | 2018-07-02 09:04:07 +0100 | [diff] [blame] | 15 | #include <sp_helpers.h> |
Antonio Nino Diaz | 43ef393 | 2018-07-03 14:39:47 +0100 | [diff] [blame] | 16 | #include <sprt_client.h> |
| 17 | #include <sprt_svc.h> |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 18 | #include <std_svc.h> |
| 19 | |
| 20 | #include "cactus.h" |
Antonio Nino Diaz | 1486f3b | 2018-06-26 10:30:10 +0100 | [diff] [blame] | 21 | #include "cactus_def.h" |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 22 | #include "cactus_tests.h" |
| 23 | |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 24 | /* Host machine information injected by the build system in the ELF file. */ |
| 25 | extern const char build_message[]; |
| 26 | extern const char version_string[]; |
| 27 | |
Antonio Nino Diaz | 1486f3b | 2018-06-26 10:30:10 +0100 | [diff] [blame] | 28 | static void cactus_print_memory_layout(void) |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 29 | { |
| 30 | NOTICE("Secure Partition memory layout:\n"); |
| 31 | |
Antonio Nino Diaz | 1486f3b | 2018-06-26 10:30:10 +0100 | [diff] [blame] | 32 | NOTICE(" Image regions\n"); |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 33 | NOTICE(" Text region : %p - %p\n", |
Antonio Nino Diaz | 1486f3b | 2018-06-26 10:30:10 +0100 | [diff] [blame] | 34 | (void *)CACTUS_TEXT_START, (void *)CACTUS_TEXT_END); |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 35 | NOTICE(" Read-only data region : %p - %p\n", |
Antonio Nino Diaz | 1486f3b | 2018-06-26 10:30:10 +0100 | [diff] [blame] | 36 | (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 Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 55 | } |
| 56 | |
Antonio Nino Diaz | 43ef393 | 2018-07-03 14:39:47 +0100 | [diff] [blame] | 57 | static 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 Diaz | 2ac6f8f | 2018-07-02 09:04:07 +0100 | [diff] [blame] | 74 | case CACTUS_SLEEP_MS: |
| 75 | sp_sleep(message->args[2]); |
| 76 | ret0 = SPRT_SUCCESS; |
| 77 | break; |
| 78 | |
Antonio Nino Diaz | 43ef393 | 2018-07-03 14:39:47 +0100 | [diff] [blame] | 79 | 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 Diaz | 1486f3b | 2018-06-26 10:30:10 +0100 | [diff] [blame] | 94 | void __dead2 cactus_main(void) |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 95 | { |
Antonio Nino Diaz | 99f4fd2 | 2018-07-03 20:25:16 +0100 | [diff] [blame] | 96 | console_init(PL011_UART2_BASE, |
| 97 | PL011_UART2_CLK_IN_HZ, |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 98 | 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 Diaz | 1486f3b | 2018-06-26 10:30:10 +0100 | [diff] [blame] | 105 | cactus_print_memory_layout(); |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 106 | |
| 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 Diaz | 1486f3b | 2018-06-26 10:30:10 +0100 | [diff] [blame] | 115 | mem_attr_changes_tests(); |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 116 | |
| 117 | /* |
| 118 | * Handle secure service requests. |
| 119 | */ |
Antonio Nino Diaz | 43ef393 | 2018-07-03 14:39:47 +0100 | [diff] [blame] | 120 | 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 Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 150 | } |