RTEMS 6.1-rc6
Loading...
Searching...
No Matches
arm-cp15-start.h
Go to the documentation of this file.
1
10/*
11 * Copyright (c) 2013 Hesham AL-Matary.
12 * Copyright (C) 2009, 2019 embedded brains GmbH & Co. KG
13 *
14 * The license and distribution terms for this file may be
15 * found in the file LICENSE in this distribution or at
16 * http://www.rtems.org/license/LICENSE.
17 */
18
19#ifndef LIBBSP_ARM_SHARED_ARM_CP15_START_H
20#define LIBBSP_ARM_SHARED_ARM_CP15_START_H
21
22#include <libcpu/arm-cp15.h>
23#include <bsp/start.h>
24#include <bsp/linker-symbols.h>
25#include <bspopts.h>
26
27#ifdef __cplusplus
28extern "C" {
29#endif /* __cplusplus */
30
31typedef struct {
32 uint32_t begin;
33 uint32_t end;
34 uint32_t flags;
36
37#define ARMV7_CP15_START_DEFAULT_SECTIONS \
38 { \
39 .begin = (uint32_t) bsp_section_fast_text_begin, \
40 .end = (uint32_t) bsp_section_fast_text_end, \
41 .flags = ARMV7_MMU_CODE_CACHED \
42 }, { \
43 .begin = (uint32_t) bsp_section_fast_data_begin, \
44 .end = (uint32_t) bsp_section_fast_data_end, \
45 .flags = ARMV7_MMU_DATA_READ_WRITE_CACHED \
46 }, { \
47 .begin = (uint32_t) bsp_section_start_begin, \
48 .end = (uint32_t) bsp_section_start_end, \
49 .flags = ARMV7_MMU_CODE_CACHED \
50 }, { \
51 .begin = (uint32_t) bsp_section_vector_begin, \
52 .end = (uint32_t) bsp_section_vector_end, \
53 .flags = ARMV7_MMU_DATA_READ_WRITE_CACHED \
54 }, { \
55 .begin = (uint32_t) bsp_section_text_begin, \
56 .end = (uint32_t) bsp_section_text_end, \
57 .flags = ARMV7_MMU_CODE_CACHED \
58 }, { \
59 .begin = (uint32_t) bsp_section_rodata_begin, \
60 .end = (uint32_t) bsp_section_rodata_end, \
61 .flags = ARMV7_MMU_DATA_READ_ONLY_CACHED \
62 }, { \
63 .begin = (uint32_t) bsp_section_data_begin, \
64 .end = (uint32_t) bsp_section_data_end, \
65 .flags = ARMV7_MMU_DATA_READ_WRITE_CACHED \
66 }, { \
67 .begin = (uint32_t) bsp_section_bss_begin, \
68 .end = (uint32_t) bsp_section_bss_end, \
69 .flags = ARMV7_MMU_DATA_READ_WRITE_CACHED \
70 }, { \
71 .begin = (uint32_t) bsp_section_rtemsstack_begin, \
72 .end = (uint32_t) bsp_section_rtemsstack_end, \
73 .flags = ARMV7_MMU_DATA_READ_WRITE_CACHED \
74 }, { \
75 .begin = (uint32_t) bsp_section_noinit_begin, \
76 .end = (uint32_t) bsp_section_noinit_end, \
77 .flags = ARMV7_MMU_DATA_READ_WRITE_CACHED \
78 }, { \
79 .begin = (uint32_t) bsp_section_work_begin, \
80 .end = (uint32_t) bsp_section_work_end, \
81 .flags = ARMV7_MMU_DATA_READ_WRITE_CACHED \
82 }, { \
83 .begin = (uint32_t) bsp_section_stack_begin, \
84 .end = (uint32_t) bsp_section_stack_end, \
85 .flags = ARMV7_MMU_DATA_READ_WRITE_CACHED \
86 }, { \
87 .begin = (uint32_t) bsp_section_nocache_begin, \
88 .end = (uint32_t) bsp_section_nocache_end, \
89 .flags = ARMV7_MMU_DEVICE \
90 }, { \
91 .begin = (uint32_t) bsp_section_nocachenoload_begin, \
92 .end = (uint32_t) bsp_section_nocachenoload_end, \
93 .flags = ARMV7_MMU_DEVICE \
94 }, { \
95 .begin = (uint32_t) bsp_translation_table_base, \
96 .end = (uint32_t) bsp_translation_table_end, \
97 .flags = ARMV7_MMU_DATA_READ_WRITE_CACHED \
98 }
99
100#define ARMV7_CP15_START_WORKSPACE_ENTRY_INDEX 10
101
102BSP_START_DATA_SECTION extern const arm_cp15_start_section_config
103 arm_cp15_start_mmu_config_table[];
104
105BSP_START_DATA_SECTION extern const size_t
106 arm_cp15_start_mmu_config_table_size;
107
108BSP_START_TEXT_SECTION static inline void
109arm_cp15_start_set_translation_table_entries(
110 uint32_t *ttb,
112)
113{
114 if (config->begin != config->end) {
115 uint32_t i;
116 uint32_t iend;
117 uint32_t index_mask;
118 uint32_t flags;
119#ifdef ARM_MMU_USE_SMALL_PAGES
120 uint32_t *pt;
121
122 pt = &ttb[ARM_MMU_TRANSLATION_TABLE_ENTRY_COUNT];
123 i = ARM_MMU_SMALL_PAGE_GET_INDEX(config->begin);
124 iend = ARM_MMU_SMALL_PAGE_GET_INDEX(ARM_MMU_SMALL_PAGE_MVA_ALIGN_UP(config->end));
125 index_mask = (1U << (32 - ARM_MMU_SMALL_PAGE_BASE_SHIFT)) - 1U;
126 flags = ARM_MMU_SECT_FLAGS_TO_SMALL_PAGE(config->flags);
127
128 while (i != iend) {
129 pt[i] = (i << ARM_MMU_SMALL_PAGE_BASE_SHIFT) | flags;
130 i = (i + 1U) & index_mask;
131 }
132#else
133 i = ARM_MMU_SECT_GET_INDEX(config->begin);
134 iend = ARM_MMU_SECT_GET_INDEX(ARM_MMU_SECT_MVA_ALIGN_UP(config->end));
135 index_mask = (1U << (32 - ARM_MMU_SECT_BASE_SHIFT)) - 1U;
136 flags = config->flags;
137
138 while (i != iend) {
139 ttb[i] = (i << ARM_MMU_SECT_BASE_SHIFT) | flags;
140 i = (i + 1U) & index_mask;
141 }
142#endif
143 }
144}
145
146BSP_START_TEXT_SECTION static inline void
147arm_cp15_start_setup_translation_table(
148 uint32_t *ttb,
149 uint32_t client_domain,
150 const arm_cp15_start_section_config *config_table,
151 size_t config_count
152)
153{
154#ifdef ARM_MMU_USE_SMALL_PAGES
155 uint32_t *pt;
156#endif
157 uint32_t dac;
158 size_t i;
159
160 dac = ARM_CP15_DAC_DOMAIN(client_domain, ARM_CP15_DAC_CLIENT);
161 arm_cp15_set_domain_access_control(dac);
162 arm_cp15_set_translation_table_base(ttb);
163
164 /* Initialize translation table with invalid entries */
165#ifdef ARM_MMU_USE_SMALL_PAGES
166 pt = &ttb[ARM_MMU_TRANSLATION_TABLE_ENTRY_COUNT];
167 for (i = 0; i < ARM_MMU_TRANSLATION_TABLE_ENTRY_COUNT; ++i) {
168 size_t j;
169
170 for (j = 0; j < ARM_MMU_SMALL_PAGE_TABLE_ENTRY_COUNT; ++j) {
171 pt[j] = 0;
172 }
173
174 ttb[i] = (uint32_t) pt | (client_domain << ARM_MMU_SECT_DOMAIN_SHIFT)
175 | ARM_MMU_PAGE_TABLE_DEFAULT;
176 pt += ARM_MMU_SMALL_PAGE_TABLE_ENTRY_COUNT;
177 }
178#else
179 for (i = 0; i < ARM_MMU_TRANSLATION_TABLE_ENTRY_COUNT; ++i) {
180 ttb[i] = 0;
181 }
182#endif
183
184 for (i = 0; i < config_count; ++i) {
185 arm_cp15_start_set_translation_table_entries(ttb, &config_table [i]);
186 }
187}
188
189BSP_START_TEXT_SECTION static inline void
190arm_cp15_start_setup_translation_table_and_enable_mmu_and_cache(
191 uint32_t ctrl,
192 uint32_t *ttb,
193 uint32_t client_domain,
194 const arm_cp15_start_section_config *config_table,
195 size_t config_count
196)
197{
198 arm_cp15_start_setup_translation_table(
199 ttb,
200 client_domain,
201 config_table,
202 config_count
203 );
204
205 /* Enable MMU and cache */
206 ctrl |= ARM_CP15_CTRL_I | ARM_CP15_CTRL_C | ARM_CP15_CTRL_M;
207
208 arm_cp15_set_control(ctrl);
209}
210
211BSP_START_TEXT_SECTION static inline uint32_t
212arm_cp15_start_setup_mmu_and_cache(uint32_t ctrl_clear, uint32_t ctrl_set)
213{
214 uint32_t ctrl = arm_cp15_get_control();
215
216 ctrl &= ~ctrl_clear;
217 ctrl |= ctrl_set;
218
219 arm_cp15_set_control(ctrl);
220
221 arm_cp15_tlb_invalidate();
222
223 return ctrl;
224}
225
226#ifdef __cplusplus
227}
228#endif /* __cplusplus */
229
230#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:31
Definition: deflate.c:114