blob: c06ad132b6b4e71aa92b3d50bbf6cac9a5bd4d50 [file] [log] [blame]
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02001/*
AlexeiFedorov718fd792024-11-08 14:55:20 +00002 * Copyright (c) 2018-2025, 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
Soby Mathew2c2810f2024-11-15 17:11:24 +000027#pragma weak plat_pcie_get_info_table
Maheedhar Bollapalli1e4f7a02025-02-14 10:40:56 +053028#pragma weak plat_get_invalid_addr
AlexeiFedorov718fd792024-11-08 14:55:20 +000029#pragma weak plat_get_dev_region
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020030
31#if IMAGE_TFTF
32
Ambroise Vincentee3e7cd2019-07-03 16:44:49 +010033#define IMAGE_TEXT_BASE TFTF_BASE
34IMPORT_SYM(uintptr_t, __TEXT_END__, IMAGE_TEXT_END);
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020035
Ambroise Vincentee3e7cd2019-07-03 16:44:49 +010036#define IMAGE_RODATA_BASE IMAGE_TEXT_END
37IMPORT_SYM(uintptr_t, __RODATA_END__, IMAGE_RODATA_END);
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020038
Ambroise Vincentee3e7cd2019-07-03 16:44:49 +010039#define IMAGE_RW_BASE IMAGE_RODATA_END
40IMPORT_SYM(uintptr_t, __TFTF_END__, IMAGE_RW_END);
41
42IMPORT_SYM(uintptr_t, __COHERENT_RAM_START__, COHERENT_RAM_START);
43IMPORT_SYM(uintptr_t, __COHERENT_RAM_END__, COHERENT_RAM_END);
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020044
45#elif IMAGE_NS_BL1U
46
Ambroise Vincentee3e7cd2019-07-03 16:44:49 +010047#define IMAGE_TEXT_BASE NS_BL1U_BASE
48IMPORT_SYM(uintptr_t, __TEXT_END__, IMAGE_TEXT_END);
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020049
Ambroise Vincentee3e7cd2019-07-03 16:44:49 +010050#define IMAGE_RODATA_BASE IMAGE_TEXT_END
51IMPORT_SYM(uintptr_t, __RODATA_END__, IMAGE_RODATA_END);
52
53#define IMAGE_RW_BASE NS_BL1U_RW_BASE
54IMPORT_SYM(uintptr_t, __NS_BL1U_RAM_END__, IMAGE_RW_END);
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020055
56#elif IMAGE_NS_BL2U
57
Ambroise Vincentee3e7cd2019-07-03 16:44:49 +010058#define IMAGE_TEXT_BASE NS_BL2U_BASE
59IMPORT_SYM(uintptr_t, __TEXT_END__, IMAGE_TEXT_END);
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020060
Ambroise Vincentee3e7cd2019-07-03 16:44:49 +010061#define IMAGE_RODATA_BASE IMAGE_TEXT_END
62IMPORT_SYM(uintptr_t, __RODATA_END__, IMAGE_RODATA_END);
63
64#define IMAGE_RW_BASE IMAGE_RODATA_END
65IMPORT_SYM(uintptr_t, __NS_BL2U_END__, IMAGE_RW_END_UNALIGNED);
66#define IMAGE_RW_END round_up(IMAGE_RW_END_UNALIGNED, PAGE_SIZE)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020067
68#endif
69
70void tftf_platform_end(void)
71{
72 /*
73 * Send EOT (End Of Transmission) on the UART.
74 * This can be used to shutdown a software model.
75 */
76 static const char ascii_eot = 4;
77 console_putc(ascii_eot);
78}
79
80void tftf_platform_watchdog_set(void)
81{
82 /* Placeholder function which should be redefined by each platform */
83}
84
85void tftf_platform_watchdog_reset(void)
86{
87 /* Placeholder function which should be redefined by each platform */
88}
89
90void tftf_plat_configure_mmu(void)
91{
Ambroise Vincentee3e7cd2019-07-03 16:44:49 +010092 /* Code */
93 mmap_add_region(IMAGE_TEXT_BASE, IMAGE_TEXT_BASE,
Alexei Fedorovdf954c92020-06-17 15:37:17 +010094 IMAGE_TEXT_END - IMAGE_TEXT_BASE, MT_CODE | MT_NS);
Ambroise Vincentee3e7cd2019-07-03 16:44:49 +010095
96 /* RO data */
97 mmap_add_region(IMAGE_RODATA_BASE, IMAGE_RODATA_BASE,
Alexei Fedorovdf954c92020-06-17 15:37:17 +010098 IMAGE_RODATA_END - IMAGE_RODATA_BASE, MT_RO_DATA | MT_NS);
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020099
100 /* Data + BSS */
101 mmap_add_region(IMAGE_RW_BASE, IMAGE_RW_BASE,
Alexei Fedorovdf954c92020-06-17 15:37:17 +0100102 IMAGE_RW_END - IMAGE_RW_BASE, MT_RW_DATA | MT_NS);
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200103
104#if IMAGE_TFTF
105 mmap_add_region(COHERENT_RAM_START, COHERENT_RAM_START,
106 COHERENT_RAM_END - COHERENT_RAM_START,
107 MT_DEVICE | MT_RW | MT_NS);
108#endif
109
110 mmap_add(tftf_platform_get_mmap());
111 init_xlat_tables();
112
113 tftf_plat_enable_mmu();
114}
115
116void tftf_plat_enable_mmu(void)
117{
Deepika Bhavnanic249d5e2020-02-06 16:29:45 -0600118#ifdef __aarch64__
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200119 if (IS_IN_EL1())
120 enable_mmu_el1(0);
121 else if (IS_IN_EL2())
122 enable_mmu_el2(0);
123 else
124 panic();
125#else
126 if (IS_IN_HYP())
127 enable_mmu_hyp(0);
128 else
129 enable_mmu_svc_mon(0);
130#endif
131}
132
133void tftf_plat_reset(void)
134{
135 /*
136 * SP805 peripheral interrupt is not serviced in TFTF. The reset signal
137 * generated by it is used to reset the platform.
138 */
139 sp805_wdog_start(1);
140
141 /*
142 * Reset might take some execution cycles, Depending on the ratio between
143 * CPU clock frequency and Watchdog clock frequency
144 */
145 while (1)
146 ;
147}
148
149const mem_region_t *plat_get_prot_regions(int *nelem)
150{
151 *nelem = 0;
152 return NULL;
153}
Soby Mathew2c2810f2024-11-15 17:11:24 +0000154
155const struct pcie_info_table *plat_pcie_get_info_table(void)
156{
157 return NULL;
158}
Maheedhar Bollapalli1e4f7a02025-02-14 10:40:56 +0530159
160uintptr_t plat_get_invalid_addr(void)
161{
162 return (uintptr_t)0x0;
163}
AlexeiFedorov718fd792024-11-08 14:55:20 +0000164
165int plat_get_dev_region(uint64_t *dev_base, size_t *dev_size,
166 uint32_t dev_type, uint32_t dev_idx)
167{
168 return -1;
169}