blob: f8524cfae5e73fa15773b6de1a76ca048302714f [file] [log] [blame]
Arunachalam Ganapathy503b89a2025-06-19 10:34:11 +01001
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02002/*
AlexeiFedorov718fd792024-11-08 14:55:20 +00003 * Copyright (c) 2018-2025, Arm Limited. All rights reserved.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02004 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 */
7
8#include <arch_helpers.h>
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02009#include <debug.h>
Antonio Nino Diaz09a00ef2019-01-11 13:12:58 +000010#include <drivers/arm/sp805.h>
11#include <drivers/console.h>
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020012#include <platform.h>
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020013#include <xlat_tables_v2.h>
14
15/*
16 * The following platform functions are all weakly defined. They provide typical
17 * implementations that may be re-used by multiple platforms but may also be
18 * overridden by a platform if required.
19 */
20
21#pragma weak tftf_platform_end
22#pragma weak tftf_platform_watchdog_set
23#pragma weak tftf_platform_watchdog_reset
24#pragma weak tftf_plat_configure_mmu
25#pragma weak tftf_plat_enable_mmu
26#pragma weak tftf_plat_reset
27#pragma weak plat_get_prot_regions
Soby Mathew2c2810f2024-11-15 17:11:24 +000028#pragma weak plat_pcie_get_info_table
Arunachalam Ganapathy503b89a2025-06-19 10:34:11 +010029#pragma weak plat_pcie_get_bar_config
Maheedhar Bollapalli1e4f7a02025-02-14 10:40:56 +053030#pragma weak plat_get_invalid_addr
AlexeiFedorov718fd792024-11-08 14:55:20 +000031#pragma weak plat_get_dev_region
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020032
33#if IMAGE_TFTF
34
Ambroise Vincentee3e7cd2019-07-03 16:44:49 +010035#define IMAGE_TEXT_BASE TFTF_BASE
36IMPORT_SYM(uintptr_t, __TEXT_END__, IMAGE_TEXT_END);
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020037
Ambroise Vincentee3e7cd2019-07-03 16:44:49 +010038#define IMAGE_RODATA_BASE IMAGE_TEXT_END
39IMPORT_SYM(uintptr_t, __RODATA_END__, IMAGE_RODATA_END);
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020040
Ambroise Vincentee3e7cd2019-07-03 16:44:49 +010041#define IMAGE_RW_BASE IMAGE_RODATA_END
42IMPORT_SYM(uintptr_t, __TFTF_END__, IMAGE_RW_END);
43
44IMPORT_SYM(uintptr_t, __COHERENT_RAM_START__, COHERENT_RAM_START);
45IMPORT_SYM(uintptr_t, __COHERENT_RAM_END__, COHERENT_RAM_END);
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020046
47#elif IMAGE_NS_BL1U
48
Ambroise Vincentee3e7cd2019-07-03 16:44:49 +010049#define IMAGE_TEXT_BASE NS_BL1U_BASE
50IMPORT_SYM(uintptr_t, __TEXT_END__, IMAGE_TEXT_END);
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020051
Ambroise Vincentee3e7cd2019-07-03 16:44:49 +010052#define IMAGE_RODATA_BASE IMAGE_TEXT_END
53IMPORT_SYM(uintptr_t, __RODATA_END__, IMAGE_RODATA_END);
54
55#define IMAGE_RW_BASE NS_BL1U_RW_BASE
56IMPORT_SYM(uintptr_t, __NS_BL1U_RAM_END__, IMAGE_RW_END);
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020057
58#elif IMAGE_NS_BL2U
59
Ambroise Vincentee3e7cd2019-07-03 16:44:49 +010060#define IMAGE_TEXT_BASE NS_BL2U_BASE
61IMPORT_SYM(uintptr_t, __TEXT_END__, IMAGE_TEXT_END);
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020062
Ambroise Vincentee3e7cd2019-07-03 16:44:49 +010063#define IMAGE_RODATA_BASE IMAGE_TEXT_END
64IMPORT_SYM(uintptr_t, __RODATA_END__, IMAGE_RODATA_END);
65
66#define IMAGE_RW_BASE IMAGE_RODATA_END
67IMPORT_SYM(uintptr_t, __NS_BL2U_END__, IMAGE_RW_END_UNALIGNED);
68#define IMAGE_RW_END round_up(IMAGE_RW_END_UNALIGNED, PAGE_SIZE)
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020069
70#endif
71
72void tftf_platform_end(void)
73{
74 /*
75 * Send EOT (End Of Transmission) on the UART.
76 * This can be used to shutdown a software model.
77 */
78 static const char ascii_eot = 4;
79 console_putc(ascii_eot);
80}
81
82void tftf_platform_watchdog_set(void)
83{
84 /* Placeholder function which should be redefined by each platform */
85}
86
87void tftf_platform_watchdog_reset(void)
88{
89 /* Placeholder function which should be redefined by each platform */
90}
91
92void tftf_plat_configure_mmu(void)
93{
Ambroise Vincentee3e7cd2019-07-03 16:44:49 +010094 /* Code */
95 mmap_add_region(IMAGE_TEXT_BASE, IMAGE_TEXT_BASE,
Alexei Fedorovdf954c92020-06-17 15:37:17 +010096 IMAGE_TEXT_END - IMAGE_TEXT_BASE, MT_CODE | MT_NS);
Ambroise Vincentee3e7cd2019-07-03 16:44:49 +010097
98 /* RO data */
99 mmap_add_region(IMAGE_RODATA_BASE, IMAGE_RODATA_BASE,
Alexei Fedorovdf954c92020-06-17 15:37:17 +0100100 IMAGE_RODATA_END - IMAGE_RODATA_BASE, MT_RO_DATA | MT_NS);
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200101
102 /* Data + BSS */
103 mmap_add_region(IMAGE_RW_BASE, IMAGE_RW_BASE,
Alexei Fedorovdf954c92020-06-17 15:37:17 +0100104 IMAGE_RW_END - IMAGE_RW_BASE, MT_RW_DATA | MT_NS);
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200105
106#if IMAGE_TFTF
107 mmap_add_region(COHERENT_RAM_START, COHERENT_RAM_START,
108 COHERENT_RAM_END - COHERENT_RAM_START,
109 MT_DEVICE | MT_RW | MT_NS);
110#endif
111
112 mmap_add(tftf_platform_get_mmap());
113 init_xlat_tables();
114
115 tftf_plat_enable_mmu();
116}
117
118void tftf_plat_enable_mmu(void)
119{
Deepika Bhavnanic249d5e2020-02-06 16:29:45 -0600120#ifdef __aarch64__
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200121 if (IS_IN_EL1())
122 enable_mmu_el1(0);
123 else if (IS_IN_EL2())
124 enable_mmu_el2(0);
125 else
126 panic();
127#else
128 if (IS_IN_HYP())
129 enable_mmu_hyp(0);
130 else
131 enable_mmu_svc_mon(0);
132#endif
133}
134
135void tftf_plat_reset(void)
136{
137 /*
138 * SP805 peripheral interrupt is not serviced in TFTF. The reset signal
139 * generated by it is used to reset the platform.
140 */
141 sp805_wdog_start(1);
142
143 /*
144 * Reset might take some execution cycles, Depending on the ratio between
145 * CPU clock frequency and Watchdog clock frequency
146 */
147 while (1)
148 ;
149}
150
151const mem_region_t *plat_get_prot_regions(int *nelem)
152{
153 *nelem = 0;
154 return NULL;
155}
Soby Mathew2c2810f2024-11-15 17:11:24 +0000156
157const struct pcie_info_table *plat_pcie_get_info_table(void)
158{
159 return NULL;
160}
Maheedhar Bollapalli1e4f7a02025-02-14 10:40:56 +0530161
Arunachalam Ganapathy503b89a2025-06-19 10:34:11 +0100162int plat_pcie_get_bar_config(uint64_t *bar64_val, uint64_t *rp_bar64_val,
163 uint32_t *bar32np_val, uint32_t *bar32p_val,
164 uint32_t *rp_bar32_val)
165{
166 return -1;
167}
168
Maheedhar Bollapalli1e4f7a02025-02-14 10:40:56 +0530169uintptr_t plat_get_invalid_addr(void)
170{
171 return (uintptr_t)0x0;
172}
AlexeiFedorov718fd792024-11-08 14:55:20 +0000173
174int plat_get_dev_region(uint64_t *dev_base, size_t *dev_size,
175 uint32_t dev_type, uint32_t dev_idx)
176{
177 return -1;
178}