blob: b6cfec30c9bad626dfed621cacd9d0c818def5ae [file] [log] [blame]
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02001/*
Deepika Bhavnanic249d5e2020-02-06 16:29:45 -06002 * Copyright (c) 2018-2020, Arm Limited. All rights reserved.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <arch_helpers.h>
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02008#include <debug.h>
Antonio Nino Diaz09a00ef2019-01-11 13:12:58 +00009#include <drivers/arm/sp805.h>
10#include <drivers/console.h>
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020011#include <platform.h>
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020012#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 Vincentee3e7cd2019-07-03 16:44:49 +010030#define IMAGE_TEXT_BASE TFTF_BASE
31IMPORT_SYM(uintptr_t, __TEXT_END__, IMAGE_TEXT_END);
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020032
Ambroise Vincentee3e7cd2019-07-03 16:44:49 +010033#define IMAGE_RODATA_BASE IMAGE_TEXT_END
34IMPORT_SYM(uintptr_t, __RODATA_END__, IMAGE_RODATA_END);
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020035
Ambroise Vincentee3e7cd2019-07-03 16:44:49 +010036#define IMAGE_RW_BASE IMAGE_RODATA_END
37IMPORT_SYM(uintptr_t, __TFTF_END__, IMAGE_RW_END);
38
39IMPORT_SYM(uintptr_t, __COHERENT_RAM_START__, COHERENT_RAM_START);
40IMPORT_SYM(uintptr_t, __COHERENT_RAM_END__, COHERENT_RAM_END);
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020041
42#elif IMAGE_NS_BL1U
43
Ambroise Vincentee3e7cd2019-07-03 16:44:49 +010044#define IMAGE_TEXT_BASE NS_BL1U_BASE
45IMPORT_SYM(uintptr_t, __TEXT_END__, IMAGE_TEXT_END);
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020046
Ambroise Vincentee3e7cd2019-07-03 16:44:49 +010047#define IMAGE_RODATA_BASE IMAGE_TEXT_END
48IMPORT_SYM(uintptr_t, __RODATA_END__, IMAGE_RODATA_END);
49
50#define IMAGE_RW_BASE NS_BL1U_RW_BASE
51IMPORT_SYM(uintptr_t, __NS_BL1U_RAM_END__, IMAGE_RW_END);
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020052
53#elif IMAGE_NS_BL2U
54
Ambroise Vincentee3e7cd2019-07-03 16:44:49 +010055#define IMAGE_TEXT_BASE NS_BL2U_BASE
56IMPORT_SYM(uintptr_t, __TEXT_END__, IMAGE_TEXT_END);
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020057
Ambroise Vincentee3e7cd2019-07-03 16:44:49 +010058#define IMAGE_RODATA_BASE IMAGE_TEXT_END
59IMPORT_SYM(uintptr_t, __RODATA_END__, IMAGE_RODATA_END);
60
61#define IMAGE_RW_BASE IMAGE_RODATA_END
62IMPORT_SYM(uintptr_t, __NS_BL2U_END__, IMAGE_RW_END_UNALIGNED);
63#define IMAGE_RW_END round_up(IMAGE_RW_END_UNALIGNED, PAGE_SIZE)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020064
65#endif
66
67void 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
77void tftf_platform_watchdog_set(void)
78{
79 /* Placeholder function which should be redefined by each platform */
80}
81
82void tftf_platform_watchdog_reset(void)
83{
84 /* Placeholder function which should be redefined by each platform */
85}
86
87void tftf_plat_configure_mmu(void)
88{
Ambroise Vincentee3e7cd2019-07-03 16:44:49 +010089 /* Code */
90 mmap_add_region(IMAGE_TEXT_BASE, IMAGE_TEXT_BASE,
91 IMAGE_TEXT_END - IMAGE_TEXT_BASE, MT_CODE);
92
93 /* RO data */
94 mmap_add_region(IMAGE_RODATA_BASE, IMAGE_RODATA_BASE,
95 IMAGE_RODATA_END - IMAGE_RODATA_BASE, MT_RO_DATA);
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020096
97 /* Data + BSS */
98 mmap_add_region(IMAGE_RW_BASE, IMAGE_RW_BASE,
99 IMAGE_RW_END - IMAGE_RW_BASE, MT_RW_DATA);
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
113void tftf_plat_enable_mmu(void)
114{
Deepika Bhavnanic249d5e2020-02-06 16:29:45 -0600115#ifdef __aarch64__
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200116 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
130void 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
146const mem_region_t *plat_get_prot_regions(int *nelem)
147{
148 *nelem = 0;
149 return NULL;
150}