Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 1 | /* |
Deepika Bhavnani | c249d5e | 2020-02-06 16:29:45 -0600 | [diff] [blame] | 2 | * Copyright (c) 2018-2020, Arm Limited. All rights reserved. |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <arch_helpers.h> |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 8 | #include <debug.h> |
Antonio Nino Diaz | 09a00ef | 2019-01-11 13:12:58 +0000 | [diff] [blame] | 9 | #include <drivers/arm/sp805.h> |
| 10 | #include <drivers/console.h> |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 11 | #include <platform.h> |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 12 | #include <xlat_tables_v2.h> |
| 13 | |
| 14 | /* |
| 15 | * The following platform functions are all weakly defined. They provide typical |
| 16 | * implementations that may be re-used by multiple platforms but may also be |
| 17 | * overridden by a platform if required. |
| 18 | */ |
| 19 | |
| 20 | #pragma weak tftf_platform_end |
| 21 | #pragma weak tftf_platform_watchdog_set |
| 22 | #pragma weak tftf_platform_watchdog_reset |
| 23 | #pragma weak tftf_plat_configure_mmu |
| 24 | #pragma weak tftf_plat_enable_mmu |
| 25 | #pragma weak tftf_plat_reset |
| 26 | #pragma weak plat_get_prot_regions |
| 27 | |
| 28 | #if IMAGE_TFTF |
| 29 | |
Ambroise Vincent | ee3e7cd | 2019-07-03 16:44:49 +0100 | [diff] [blame] | 30 | #define IMAGE_TEXT_BASE TFTF_BASE |
| 31 | IMPORT_SYM(uintptr_t, __TEXT_END__, IMAGE_TEXT_END); |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 32 | |
Ambroise Vincent | ee3e7cd | 2019-07-03 16:44:49 +0100 | [diff] [blame] | 33 | #define IMAGE_RODATA_BASE IMAGE_TEXT_END |
| 34 | IMPORT_SYM(uintptr_t, __RODATA_END__, IMAGE_RODATA_END); |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 35 | |
Ambroise Vincent | ee3e7cd | 2019-07-03 16:44:49 +0100 | [diff] [blame] | 36 | #define IMAGE_RW_BASE IMAGE_RODATA_END |
| 37 | IMPORT_SYM(uintptr_t, __TFTF_END__, IMAGE_RW_END); |
| 38 | |
| 39 | IMPORT_SYM(uintptr_t, __COHERENT_RAM_START__, COHERENT_RAM_START); |
| 40 | IMPORT_SYM(uintptr_t, __COHERENT_RAM_END__, COHERENT_RAM_END); |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 41 | |
| 42 | #elif IMAGE_NS_BL1U |
| 43 | |
Ambroise Vincent | ee3e7cd | 2019-07-03 16:44:49 +0100 | [diff] [blame] | 44 | #define IMAGE_TEXT_BASE NS_BL1U_BASE |
| 45 | IMPORT_SYM(uintptr_t, __TEXT_END__, IMAGE_TEXT_END); |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 46 | |
Ambroise Vincent | ee3e7cd | 2019-07-03 16:44:49 +0100 | [diff] [blame] | 47 | #define IMAGE_RODATA_BASE IMAGE_TEXT_END |
| 48 | IMPORT_SYM(uintptr_t, __RODATA_END__, IMAGE_RODATA_END); |
| 49 | |
| 50 | #define IMAGE_RW_BASE NS_BL1U_RW_BASE |
| 51 | IMPORT_SYM(uintptr_t, __NS_BL1U_RAM_END__, IMAGE_RW_END); |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 52 | |
| 53 | #elif IMAGE_NS_BL2U |
| 54 | |
Ambroise Vincent | ee3e7cd | 2019-07-03 16:44:49 +0100 | [diff] [blame] | 55 | #define IMAGE_TEXT_BASE NS_BL2U_BASE |
| 56 | IMPORT_SYM(uintptr_t, __TEXT_END__, IMAGE_TEXT_END); |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 57 | |
Ambroise Vincent | ee3e7cd | 2019-07-03 16:44:49 +0100 | [diff] [blame] | 58 | #define IMAGE_RODATA_BASE IMAGE_TEXT_END |
| 59 | IMPORT_SYM(uintptr_t, __RODATA_END__, IMAGE_RODATA_END); |
| 60 | |
| 61 | #define IMAGE_RW_BASE IMAGE_RODATA_END |
| 62 | IMPORT_SYM(uintptr_t, __NS_BL2U_END__, IMAGE_RW_END_UNALIGNED); |
| 63 | #define IMAGE_RW_END round_up(IMAGE_RW_END_UNALIGNED, PAGE_SIZE) |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 64 | |
| 65 | #endif |
| 66 | |
| 67 | void tftf_platform_end(void) |
| 68 | { |
| 69 | /* |
| 70 | * Send EOT (End Of Transmission) on the UART. |
| 71 | * This can be used to shutdown a software model. |
| 72 | */ |
| 73 | static const char ascii_eot = 4; |
| 74 | console_putc(ascii_eot); |
| 75 | } |
| 76 | |
| 77 | void tftf_platform_watchdog_set(void) |
| 78 | { |
| 79 | /* Placeholder function which should be redefined by each platform */ |
| 80 | } |
| 81 | |
| 82 | void tftf_platform_watchdog_reset(void) |
| 83 | { |
| 84 | /* Placeholder function which should be redefined by each platform */ |
| 85 | } |
| 86 | |
| 87 | void tftf_plat_configure_mmu(void) |
| 88 | { |
Ambroise Vincent | ee3e7cd | 2019-07-03 16:44:49 +0100 | [diff] [blame] | 89 | /* Code */ |
| 90 | mmap_add_region(IMAGE_TEXT_BASE, IMAGE_TEXT_BASE, |
Alexei Fedorov | df954c9 | 2020-06-17 15:37:17 +0100 | [diff] [blame] | 91 | IMAGE_TEXT_END - IMAGE_TEXT_BASE, MT_CODE | MT_NS); |
Ambroise Vincent | ee3e7cd | 2019-07-03 16:44:49 +0100 | [diff] [blame] | 92 | |
| 93 | /* RO data */ |
| 94 | mmap_add_region(IMAGE_RODATA_BASE, IMAGE_RODATA_BASE, |
Alexei Fedorov | df954c9 | 2020-06-17 15:37:17 +0100 | [diff] [blame] | 95 | IMAGE_RODATA_END - IMAGE_RODATA_BASE, MT_RO_DATA | MT_NS); |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 96 | |
| 97 | /* Data + BSS */ |
| 98 | mmap_add_region(IMAGE_RW_BASE, IMAGE_RW_BASE, |
Alexei Fedorov | df954c9 | 2020-06-17 15:37:17 +0100 | [diff] [blame] | 99 | IMAGE_RW_END - IMAGE_RW_BASE, MT_RW_DATA | MT_NS); |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 100 | |
| 101 | #if IMAGE_TFTF |
| 102 | mmap_add_region(COHERENT_RAM_START, COHERENT_RAM_START, |
| 103 | COHERENT_RAM_END - COHERENT_RAM_START, |
| 104 | MT_DEVICE | MT_RW | MT_NS); |
| 105 | #endif |
| 106 | |
| 107 | mmap_add(tftf_platform_get_mmap()); |
| 108 | init_xlat_tables(); |
| 109 | |
| 110 | tftf_plat_enable_mmu(); |
| 111 | } |
| 112 | |
| 113 | void tftf_plat_enable_mmu(void) |
| 114 | { |
Deepika Bhavnani | c249d5e | 2020-02-06 16:29:45 -0600 | [diff] [blame] | 115 | #ifdef __aarch64__ |
Sandrine Bailleux | 3cd87d7 | 2018-10-09 11:12:55 +0200 | [diff] [blame] | 116 | if (IS_IN_EL1()) |
| 117 | enable_mmu_el1(0); |
| 118 | else if (IS_IN_EL2()) |
| 119 | enable_mmu_el2(0); |
| 120 | else |
| 121 | panic(); |
| 122 | #else |
| 123 | if (IS_IN_HYP()) |
| 124 | enable_mmu_hyp(0); |
| 125 | else |
| 126 | enable_mmu_svc_mon(0); |
| 127 | #endif |
| 128 | } |
| 129 | |
| 130 | void tftf_plat_reset(void) |
| 131 | { |
| 132 | /* |
| 133 | * SP805 peripheral interrupt is not serviced in TFTF. The reset signal |
| 134 | * generated by it is used to reset the platform. |
| 135 | */ |
| 136 | sp805_wdog_start(1); |
| 137 | |
| 138 | /* |
| 139 | * Reset might take some execution cycles, Depending on the ratio between |
| 140 | * CPU clock frequency and Watchdog clock frequency |
| 141 | */ |
| 142 | while (1) |
| 143 | ; |
| 144 | } |
| 145 | |
| 146 | const mem_region_t *plat_get_prot_regions(int *nelem) |
| 147 | { |
| 148 | *nelem = 0; |
| 149 | return NULL; |
| 150 | } |