RTEMS 7.0-rc1
Loading...
Searching...
No Matches
arm-cp15-start.h
Go to the documentation of this file.
1
9/*
10 * Copyright (C) 2013 Hesham AL-Matary
11 * Copyright (C) 2009, 2019 embedded brains GmbH & Co. KG
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 */
34
35#ifndef LIBBSP_ARM_SHARED_ARM_CP15_START_H
36#define LIBBSP_ARM_SHARED_ARM_CP15_START_H
37
38#include <libcpu/arm-cp15.h>
39#include <bsp/start.h>
40#include <bsp/linker-symbols.h>
41#include <bspopts.h>
42
43#ifdef __cplusplus
44extern "C" {
45#endif /* __cplusplus */
46
47typedef struct {
48 uint32_t begin;
49 uint32_t end;
50 uint32_t flags;
52
53#define ARMV7_CP15_START_DEFAULT_SECTIONS \
54 { \
55 .begin = (uint32_t) bsp_section_fast_text_begin, \
56 .end = (uint32_t) bsp_section_fast_text_end, \
57 .flags = ARMV7_MMU_CODE_CACHED \
58 }, { \
59 .begin = (uint32_t) bsp_section_fast_data_begin, \
60 .end = (uint32_t) bsp_section_fast_data_end, \
61 .flags = ARMV7_MMU_DATA_READ_WRITE_CACHED \
62 }, { \
63 .begin = (uint32_t) bsp_section_start_begin, \
64 .end = (uint32_t) bsp_section_start_end, \
65 .flags = ARMV7_MMU_CODE_CACHED \
66 }, { \
67 .begin = (uint32_t) bsp_section_vector_begin, \
68 .end = (uint32_t) bsp_section_vector_end, \
69 .flags = ARMV7_MMU_DATA_READ_WRITE_CACHED \
70 }, { \
71 .begin = (uint32_t) bsp_section_text_begin, \
72 .end = (uint32_t) bsp_section_text_end, \
73 .flags = ARMV7_MMU_CODE_CACHED \
74 }, { \
75 .begin = (uint32_t) bsp_section_rodata_begin, \
76 .end = (uint32_t) bsp_section_rodata_end, \
77 .flags = ARMV7_MMU_DATA_READ_ONLY_CACHED \
78 }, { \
79 .begin = (uint32_t) bsp_section_data_begin, \
80 .end = (uint32_t) bsp_section_data_end, \
81 .flags = ARMV7_MMU_DATA_READ_WRITE_CACHED \
82 }, { \
83 .begin = (uint32_t) bsp_section_bss_begin, \
84 .end = (uint32_t) bsp_section_bss_end, \
85 .flags = ARMV7_MMU_DATA_READ_WRITE_CACHED \
86 }, { \
87 .begin = (uint32_t) bsp_section_rtemsstack_begin, \
88 .end = (uint32_t) bsp_section_rtemsstack_end, \
89 .flags = ARMV7_MMU_DATA_READ_WRITE_CACHED \
90 }, { \
91 .begin = (uint32_t) bsp_section_noinit_begin, \
92 .end = (uint32_t) bsp_section_noinit_end, \
93 .flags = ARMV7_MMU_DATA_READ_WRITE_CACHED \
94 }, { \
95 .begin = (uint32_t) bsp_section_work_begin, \
96 .end = (uint32_t) bsp_section_work_end, \
97 .flags = ARMV7_MMU_DATA_READ_WRITE_CACHED \
98 }, { \
99 .begin = (uint32_t) bsp_section_stack_begin, \
100 .end = (uint32_t) bsp_section_stack_end, \
101 .flags = ARMV7_MMU_DATA_READ_WRITE_CACHED \
102 }, { \
103 .begin = (uint32_t) bsp_section_nocache_begin, \
104 .end = (uint32_t) bsp_section_nocache_end, \
105 .flags = ARMV7_MMU_DEVICE \
106 }, { \
107 .begin = (uint32_t) bsp_section_nocachenoload_begin, \
108 .end = (uint32_t) bsp_section_nocachenoload_end, \
109 .flags = ARMV7_MMU_DEVICE \
110 }, { \
111 .begin = (uint32_t) bsp_translation_table_base, \
112 .end = (uint32_t) bsp_translation_table_end, \
113 .flags = ARMV7_MMU_DATA_READ_WRITE_CACHED \
114 }
115
116#define ARMV7_CP15_START_WORKSPACE_ENTRY_INDEX 10
117
118BSP_START_DATA_SECTION extern const arm_cp15_start_section_config
119 arm_cp15_start_mmu_config_table[];
120
121BSP_START_DATA_SECTION extern const size_t
122 arm_cp15_start_mmu_config_table_size;
123
124BSP_START_TEXT_SECTION static inline void
125arm_cp15_start_set_translation_table_entries(
126 uint32_t *ttb,
128)
129{
130 if (config->begin != config->end) {
131 uint32_t i;
132 uint32_t iend;
133 uint32_t index_mask;
134 uint32_t flags;
135#ifdef ARM_MMU_USE_SMALL_PAGES
136 uint32_t *pt;
137
138 pt = &ttb[ARM_MMU_TRANSLATION_TABLE_ENTRY_COUNT];
139 i = ARM_MMU_SMALL_PAGE_GET_INDEX(config->begin);
140 iend = ARM_MMU_SMALL_PAGE_GET_INDEX(ARM_MMU_SMALL_PAGE_MVA_ALIGN_UP(config->end));
141 index_mask = (1U << (32 - ARM_MMU_SMALL_PAGE_BASE_SHIFT)) - 1U;
142 flags = ARM_MMU_SECT_FLAGS_TO_SMALL_PAGE(config->flags);
143
144 while (i != iend) {
145 pt[i] = (i << ARM_MMU_SMALL_PAGE_BASE_SHIFT) | flags;
146 i = (i + 1U) & index_mask;
147 }
148#else
149 i = ARM_MMU_SECT_GET_INDEX(config->begin);
150 iend = ARM_MMU_SECT_GET_INDEX(ARM_MMU_SECT_MVA_ALIGN_UP(config->end));
151 index_mask = (1U << (32 - ARM_MMU_SECT_BASE_SHIFT)) - 1U;
152 flags = config->flags;
153
154 while (i != iend) {
155 ttb[i] = (i << ARM_MMU_SECT_BASE_SHIFT) | flags;
156 i = (i + 1U) & index_mask;
157 }
158#endif
159 }
160}
161
162BSP_START_TEXT_SECTION static inline void
163arm_cp15_start_setup_translation_table(
164 uint32_t *ttb,
165 uint32_t client_domain,
166 const arm_cp15_start_section_config *config_table,
167 size_t config_count
168)
169{
170#ifdef ARM_MMU_USE_SMALL_PAGES
171 uint32_t *pt;
172#endif
173 uint32_t dac;
174 size_t i;
175
176 dac = ARM_CP15_DAC_DOMAIN(client_domain, ARM_CP15_DAC_CLIENT);
177 arm_cp15_set_domain_access_control(dac);
178 arm_cp15_set_translation_table_base(ttb);
179
180 /* Initialize translation table with invalid entries */
181#ifdef ARM_MMU_USE_SMALL_PAGES
182 pt = &ttb[ARM_MMU_TRANSLATION_TABLE_ENTRY_COUNT];
183 for (i = 0; i < ARM_MMU_TRANSLATION_TABLE_ENTRY_COUNT; ++i) {
184 size_t j;
185
186 for (j = 0; j < ARM_MMU_SMALL_PAGE_TABLE_ENTRY_COUNT; ++j) {
187 pt[j] = 0;
188 }
189
190 ttb[i] = (uint32_t) pt | (client_domain << ARM_MMU_SECT_DOMAIN_SHIFT)
191 | ARM_MMU_PAGE_TABLE_DEFAULT;
192 pt += ARM_MMU_SMALL_PAGE_TABLE_ENTRY_COUNT;
193 }
194#else
195 for (i = 0; i < ARM_MMU_TRANSLATION_TABLE_ENTRY_COUNT; ++i) {
196 ttb[i] = 0;
197 }
198#endif
199
200 for (i = 0; i < config_count; ++i) {
201 arm_cp15_start_set_translation_table_entries(ttb, &config_table [i]);
202 }
203}
204
205BSP_START_TEXT_SECTION static inline void
206arm_cp15_start_setup_translation_table_and_enable_mmu_and_cache(
207 uint32_t ctrl,
208 uint32_t *ttb,
209 uint32_t client_domain,
210 const arm_cp15_start_section_config *config_table,
211 size_t config_count
212)
213{
214 arm_cp15_start_setup_translation_table(
215 ttb,
216 client_domain,
217 config_table,
218 config_count
219 );
220
221 /* Enable MMU and cache */
222 ctrl |= ARM_CP15_CTRL_I | ARM_CP15_CTRL_C | ARM_CP15_CTRL_M;
223
224 arm_cp15_set_control(ctrl);
225}
226
227BSP_START_TEXT_SECTION static inline uint32_t
228arm_cp15_start_setup_mmu_and_cache(uint32_t ctrl_clear, uint32_t ctrl_set)
229{
230 uint32_t ctrl = arm_cp15_get_control();
231
232 ctrl &= ~ctrl_clear;
233 ctrl |= ctrl_set;
234
235 arm_cp15_set_control(ctrl);
236
237 arm_cp15_tlb_invalidate();
238
239 return ctrl;
240}
241
242#ifdef __cplusplus
243}
244#endif /* __cplusplus */
245
246#endif /* LIBBSP_ARM_SHARED_ARM_CP15_START_H */
ARM co-processor 15 (CP15) API.
This header file provides interfaces to BSP-specific linker symbols and sections.
Definition: arm-cp15-start.h:47