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 <console.h> |
| 10 | #include <debug.h> |
Antonio Nino Diaz | 43ef393 | 2018-07-03 14:39:47 +0100 | [diff] [blame^] | 11 | #include <errno.h> |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 12 | #include <pl011.h> |
| 13 | #include <plat_arm.h> |
| 14 | #include <platform_def.h> |
Antonio Nino Diaz | 43ef393 | 2018-07-03 14:39:47 +0100 | [diff] [blame^] | 15 | #include <sprt_client.h> |
| 16 | #include <sprt_svc.h> |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 17 | #include <std_svc.h> |
| 18 | |
| 19 | #include "cactus.h" |
Antonio Nino Diaz | 1486f3b | 2018-06-26 10:30:10 +0100 | [diff] [blame] | 20 | #include "cactus_def.h" |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 21 | #include "cactus_tests.h" |
| 22 | |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 23 | /* Host machine information injected by the build system in the ELF file. */ |
| 24 | extern const char build_message[]; |
| 25 | extern const char version_string[]; |
| 26 | |
Antonio Nino Diaz | 1486f3b | 2018-06-26 10:30:10 +0100 | [diff] [blame] | 27 | static void cactus_print_memory_layout(void) |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 28 | { |
| 29 | NOTICE("Secure Partition memory layout:\n"); |
| 30 | |
Antonio Nino Diaz | 1486f3b | 2018-06-26 10:30:10 +0100 | [diff] [blame] | 31 | NOTICE(" Image regions\n"); |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 32 | NOTICE(" Text region : %p - %p\n", |
Antonio Nino Diaz | 1486f3b | 2018-06-26 10:30:10 +0100 | [diff] [blame] | 33 | (void *)CACTUS_TEXT_START, (void *)CACTUS_TEXT_END); |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 34 | NOTICE(" Read-only data region : %p - %p\n", |
Antonio Nino Diaz | 1486f3b | 2018-06-26 10:30:10 +0100 | [diff] [blame] | 35 | (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 Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 54 | } |
| 55 | |
Antonio Nino Diaz | 43ef393 | 2018-07-03 14:39:47 +0100 | [diff] [blame^] | 56 | static 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 Diaz | 1486f3b | 2018-06-26 10:30:10 +0100 | [diff] [blame] | 88 | void __dead2 cactus_main(void) |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 89 | { |
Antonio Nino Diaz | 99f4fd2 | 2018-07-03 20:25:16 +0100 | [diff] [blame] | 90 | console_init(PL011_UART2_BASE, |
| 91 | PL011_UART2_CLK_IN_HZ, |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 92 | 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 Diaz | 1486f3b | 2018-06-26 10:30:10 +0100 | [diff] [blame] | 99 | cactus_print_memory_layout(); |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 100 | |
| 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 Diaz | 1486f3b | 2018-06-26 10:30:10 +0100 | [diff] [blame] | 109 | mem_attr_changes_tests(); |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 110 | |
| 111 | /* |
| 112 | * Handle secure service requests. |
| 113 | */ |
Antonio Nino Diaz | 43ef393 | 2018-07-03 14:39:47 +0100 | [diff] [blame^] | 114 | 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 Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 144 | } |