blob: c5f4592c77cd390f36818dec099650a44b722f5c [file] [log] [blame]
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02001/*
2 * Copyright (c) 2018, Arm Limited. All rights reserved.
3 *
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
30#define IMAGE_RO_BASE TFTF_BASE
31IMPORT_SYM(uintptr_t, __RO_END__, IMAGE_RO_END);
32
33#define IMAGE_RW_BASE IMAGE_RO_END
34IMPORT_SYM(uintptr_t, __TFTF_END__, IMAGE_RW_END);
35
36IMPORT_SYM(uintptr_t, __COHERENT_RAM_START__, COHERENT_RAM_START);
37IMPORT_SYM(uintptr_t, __COHERENT_RAM_END__, COHERENT_RAM_END);
38
39#elif IMAGE_NS_BL1U
40
41IMPORT_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
46IMPORT_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
51IMPORT_SYM(uintptr_t, __RO_END__, IMAGE_RO_END);
52
53#define IMAGE_RW_BASE IMAGE_RO_END
54IMPORT_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
59void 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
69void tftf_platform_watchdog_set(void)
70{
71 /* Placeholder function which should be redefined by each platform */
72}
73
74void tftf_platform_watchdog_reset(void)
75{
76 /* Placeholder function which should be redefined by each platform */
77}
78
79void 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
101void 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
118void 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
134const mem_region_t *plat_get_prot_regions(int *nelem)
135{
136 *nelem = 0;
137 return NULL;
138}