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 <arch_helpers.h> |
| 8 | #include <console.h> |
| 9 | #include <debug.h> |
| 10 | #include <platform.h> |
| 11 | #include <sp805.h> |
| 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 | |
| 30 | #define IMAGE_RO_BASE TFTF_BASE |
| 31 | IMPORT_SYM(uintptr_t, __RO_END__, IMAGE_RO_END); |
| 32 | |
| 33 | #define IMAGE_RW_BASE IMAGE_RO_END |
| 34 | IMPORT_SYM(uintptr_t, __TFTF_END__, IMAGE_RW_END); |
| 35 | |
| 36 | IMPORT_SYM(uintptr_t, __COHERENT_RAM_START__, COHERENT_RAM_START); |
| 37 | IMPORT_SYM(uintptr_t, __COHERENT_RAM_END__, COHERENT_RAM_END); |
| 38 | |
| 39 | #elif IMAGE_NS_BL1U |
| 40 | |
| 41 | IMPORT_SYM(uintptr_t, __RO_END__, IMAGE_RO_END_UNALIGNED); |
| 42 | #define IMAGE_RO_BASE NS_BL1U_RO_BASE |
| 43 | #define IMAGE_RO_END round_up(IMAGE_RO_END_UNALIGNED, PAGE_SIZE) |
| 44 | |
| 45 | #define IMAGE_RW_BASE NS_BL1U_RW_BASE |
| 46 | IMPORT_SYM(uintptr_t, __NS_BL1U_RAM_END__, IMAGE_RW_END); |
| 47 | |
| 48 | #elif IMAGE_NS_BL2U |
| 49 | |
| 50 | #define IMAGE_RO_BASE NS_BL2U_BASE |
| 51 | IMPORT_SYM(uintptr_t, __RO_END__, IMAGE_RO_END); |
| 52 | |
| 53 | #define IMAGE_RW_BASE IMAGE_RO_END |
| 54 | IMPORT_SYM(uintptr_t, __NS_BL2U_END__, IMAGE_RW_END_UNALIGNED); |
| 55 | #define IMAGE_RW_END round_up(IMAGE_RW_END_UNALIGNED, PAGE_SIZE) |
| 56 | |
| 57 | #endif |
| 58 | |
| 59 | void tftf_platform_end(void) |
| 60 | { |
| 61 | /* |
| 62 | * Send EOT (End Of Transmission) on the UART. |
| 63 | * This can be used to shutdown a software model. |
| 64 | */ |
| 65 | static const char ascii_eot = 4; |
| 66 | console_putc(ascii_eot); |
| 67 | } |
| 68 | |
| 69 | void tftf_platform_watchdog_set(void) |
| 70 | { |
| 71 | /* Placeholder function which should be redefined by each platform */ |
| 72 | } |
| 73 | |
| 74 | void tftf_platform_watchdog_reset(void) |
| 75 | { |
| 76 | /* Placeholder function which should be redefined by each platform */ |
| 77 | } |
| 78 | |
| 79 | void tftf_plat_configure_mmu(void) |
| 80 | { |
| 81 | /* RO data + Code */ |
| 82 | mmap_add_region(IMAGE_RO_BASE, IMAGE_RO_BASE, |
| 83 | IMAGE_RO_END - IMAGE_RO_BASE, MT_CODE); |
| 84 | |
| 85 | /* Data + BSS */ |
| 86 | mmap_add_region(IMAGE_RW_BASE, IMAGE_RW_BASE, |
| 87 | IMAGE_RW_END - IMAGE_RW_BASE, MT_RW_DATA); |
| 88 | |
| 89 | #if IMAGE_TFTF |
| 90 | mmap_add_region(COHERENT_RAM_START, COHERENT_RAM_START, |
| 91 | COHERENT_RAM_END - COHERENT_RAM_START, |
| 92 | MT_DEVICE | MT_RW | MT_NS); |
| 93 | #endif |
| 94 | |
| 95 | mmap_add(tftf_platform_get_mmap()); |
| 96 | init_xlat_tables(); |
| 97 | |
| 98 | tftf_plat_enable_mmu(); |
| 99 | } |
| 100 | |
| 101 | void tftf_plat_enable_mmu(void) |
| 102 | { |
| 103 | #ifndef AARCH32 |
| 104 | if (IS_IN_EL1()) |
| 105 | enable_mmu_el1(0); |
| 106 | else if (IS_IN_EL2()) |
| 107 | enable_mmu_el2(0); |
| 108 | else |
| 109 | panic(); |
| 110 | #else |
| 111 | if (IS_IN_HYP()) |
| 112 | enable_mmu_hyp(0); |
| 113 | else |
| 114 | enable_mmu_svc_mon(0); |
| 115 | #endif |
| 116 | } |
| 117 | |
| 118 | void tftf_plat_reset(void) |
| 119 | { |
| 120 | /* |
| 121 | * SP805 peripheral interrupt is not serviced in TFTF. The reset signal |
| 122 | * generated by it is used to reset the platform. |
| 123 | */ |
| 124 | sp805_wdog_start(1); |
| 125 | |
| 126 | /* |
| 127 | * Reset might take some execution cycles, Depending on the ratio between |
| 128 | * CPU clock frequency and Watchdog clock frequency |
| 129 | */ |
| 130 | while (1) |
| 131 | ; |
| 132 | } |
| 133 | |
| 134 | const mem_region_t *plat_get_prot_regions(int *nelem) |
| 135 | { |
| 136 | *nelem = 0; |
| 137 | return NULL; |
| 138 | } |