RTEMS 7.0-rc1
Loading...
Searching...
No Matches
aarch64-mmu.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
11/*
12 * Copyright (C) 2021 On-Line Applications Research Corporation (OAR)
13 * Written by Kinsey Moore <kinsey.moore@oarcorp.com>
14 *
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
17 * are met:
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 */
36
37#ifndef LIBBSP_AARCH64_SHARED_AARCH64_MMU_H
38#define LIBBSP_AARCH64_SHARED_AARCH64_MMU_H
39
40#include <bsp/fatal.h>
41#include <bsp/linker-symbols.h>
42#include <bsp/start.h>
43#include <bsp/utility.h>
44#include <bspopts.h>
47
48#ifdef __cplusplus
49extern "C" {
50#endif /* __cplusplus */
51
52typedef struct {
53 uintptr_t begin;
54 uintptr_t end;
55 uint64_t flags;
57
58#define AARCH64_MMU_DEFAULT_SECTIONS \
59 { \
60 .begin = (uintptr_t) bsp_section_fast_text_begin, \
61 .end = (uintptr_t) bsp_section_fast_text_end, \
62 .flags = AARCH64_MMU_CODE_CACHED \
63 }, { \
64 .begin = (uintptr_t) bsp_section_fast_data_begin, \
65 .end = (uintptr_t) bsp_section_fast_data_end, \
66 .flags = AARCH64_MMU_DATA_RW_CACHED \
67 }, { \
68 .begin = (uintptr_t) bsp_section_start_begin, \
69 .end = (uintptr_t) bsp_section_start_end, \
70 .flags = AARCH64_MMU_CODE_CACHED \
71 }, { \
72 .begin = (uintptr_t) bsp_section_vector_begin, \
73 .end = (uintptr_t) bsp_section_vector_end, \
74 .flags = AARCH64_MMU_DATA_RW_CACHED \
75 }, { \
76 .begin = (uintptr_t) bsp_section_text_begin, \
77 .end = (uintptr_t) bsp_section_text_end, \
78 .flags = AARCH64_MMU_CODE_CACHED \
79 }, { \
80 .begin = (uintptr_t) bsp_section_rodata_begin, \
81 .end = (uintptr_t) bsp_section_rodata_end, \
82 .flags = AARCH64_MMU_DATA_RO_CACHED \
83 }, { \
84 .begin = (uintptr_t) bsp_section_data_begin, \
85 .end = (uintptr_t) bsp_section_data_end, \
86 .flags = AARCH64_MMU_DATA_RW_CACHED \
87 }, { \
88 .begin = (uintptr_t) bsp_section_bss_begin, \
89 .end = (uintptr_t) bsp_section_bss_end, \
90 .flags = AARCH64_MMU_DATA_RW_CACHED \
91 }, { \
92 .begin = (uintptr_t) bsp_section_rtemsstack_begin, \
93 .end = (uintptr_t) bsp_section_rtemsstack_end, \
94 .flags = AARCH64_MMU_DATA_RW_CACHED \
95 }, { \
96 .begin = (uintptr_t) bsp_section_noinit_begin, \
97 .end = (uintptr_t) bsp_section_noinit_end, \
98 .flags = AARCH64_MMU_DATA_RW_CACHED \
99 }, { \
100 .begin = (uintptr_t) bsp_section_work_begin, \
101 .end = (uintptr_t) bsp_section_work_end, \
102 .flags = AARCH64_MMU_DATA_RW_CACHED \
103 }, { \
104 .begin = (uintptr_t) bsp_section_stack_begin, \
105 .end = (uintptr_t) bsp_section_stack_end, \
106 .flags = AARCH64_MMU_DATA_RW_CACHED \
107 }, { \
108 .begin = (uintptr_t) bsp_section_nocache_begin, \
109 .end = (uintptr_t) bsp_section_nocache_end, \
110 .flags = AARCH64_MMU_DEVICE \
111 }, { \
112 .begin = (uintptr_t) bsp_section_nocachenoload_begin, \
113 .end = (uintptr_t) bsp_section_nocachenoload_end, \
114 .flags = AARCH64_MMU_DEVICE \
115 }, { \
116 .begin = (uintptr_t) bsp_translation_table_base, \
117 .end = (uintptr_t) bsp_translation_table_end, \
118 .flags = AARCH64_MMU_DATA_RW_CACHED \
119 }, { \
120 .begin = (uintptr_t) bsp_start_vector_table_begin, \
121 .end = (uintptr_t) bsp_start_vector_table_end, \
122 .flags = AARCH64_MMU_CODE_CACHED \
123 }
124
132
139extern const size_t aarch64_mmu_config_table_size;
140
145typedef struct {
149 uint64_t *ttb;
150
158
163
186 const aarch64_mmu_config_entry *config
187);
188
205 const aarch64_mmu_config_entry *config_table,
206 size_t config_count
207);
208
209BSP_START_TEXT_SECTION static inline void
210aarch64_mmu_enable( const aarch64_mmu_control *control )
211{
212 uint64_t sctlr;
213
214 /* CPUECTLR_EL1.SMPEN is already set on ZynqMP and is not writable */
215
216 /* Flush and invalidate cache */
218
219 _AArch64_Write_ttbr0_el1( (uintptr_t) control->ttb );
220 _AARCH64_Instruction_synchronization_barrier();
221
222 /* Enable MMU and cache */
223 sctlr = _AArch64_Read_sctlr_el1();
224 sctlr |= AARCH64_SCTLR_EL1_I | AARCH64_SCTLR_EL1_C | AARCH64_SCTLR_EL1_M;
225 _AArch64_Write_sctlr_el1( sctlr );
226
227 /* Ensure write to sctlr_el1 is complete before returning */
228 _AARCH64_Instruction_synchronization_barrier();
229}
230
231BSP_START_TEXT_SECTION static inline void
232aarch64_mmu_disable( void )
233{
234 uint64_t sctlr;
235
236 /*
237 * Flush data cache before disabling the MMU. While the MMU is disabled, all
238 * accesses are treated as uncached device memory.
239 */
241
242 /* Disable MMU */
243 sctlr = _AArch64_Read_sctlr_el1();
244 sctlr &= ~(AARCH64_SCTLR_EL1_M);
245 _AArch64_Write_sctlr_el1( sctlr );
246}
247
248BSP_START_TEXT_SECTION static inline void aarch64_mmu_setup( void )
249{
250 /* Set TCR */
251 /* 256TB/48 bits mappable (64-0x10) */
252 _AArch64_Write_tcr_el1(
253 AARCH64_TCR_EL1_T0SZ( 0x10 ) | AARCH64_TCR_EL1_IRGN0( 0x1 ) |
254 AARCH64_TCR_EL1_ORGN0( 0x1 ) | AARCH64_TCR_EL1_SH0( 0x3 ) |
255 AARCH64_TCR_EL1_TG0( 0x0 ) | AARCH64_TCR_EL1_IPS( 0x5ULL ) |
256 AARCH64_TCR_EL1_EPD1
257 );
258
259 /* Set MAIR */
260 _AArch64_Write_mair_el1(
261 AARCH64_MAIR_EL1_ATTR0( 0x0 ) | AARCH64_MAIR_EL1_ATTR1( 0x4 ) |
262 AARCH64_MAIR_EL1_ATTR2( 0x44 ) | AARCH64_MAIR_EL1_ATTR3( 0xFF )
263 );
264}
265
266#ifdef __cplusplus
267}
268#endif /* __cplusplus */
269
270#endif /* LIBBSP_AARCH64_SHARED_AARCH64_MMU_H */
aarch64_mmu_control aarch64_mmu_instance
This object is used to maintain the MMU translation tables.
Definition: mmu-setup.c:45
const aarch64_mmu_config_entry aarch64_mmu_config_table[]
This is the AArch64 MMU configuration table.
Definition: mmu-config.c:44
rtems_status_code aarch64_mmu_set_translation_table_entries(aarch64_mmu_control *control, const aarch64_mmu_config_entry *config)
Sets the MMU translation table entries associated with the memory region.
Definition: mmu-setup.c:260
void aarch64_mmu_setup_translation_table(aarch64_mmu_control *control, const aarch64_mmu_config_entry *config_table, size_t config_count)
Sets up the MMU translation table.
Definition: mmu-setup.c:294
const size_t aarch64_mmu_config_table_size
This is the count of entries in the AArch64 MMU configuration table.
Definition: mmu-config.c:69
This header file provides the API to read and write the AArch64 system registers.
This header file provides fatal codes for RTEMS_FATAL_SOURCE_BSP.
void rtems_cache_flush_entire_data(void)
Flushes the entire data cache.
Definition: cacheimpl.h:232
rtems_status_code
This enumeration provides status codes for directives of the Classic API.
Definition: status.h:85
This header file provides utility macros for BSPs.
This header file provides interfaces to BSP-specific linker symbols and sections.
Definitions used in MMU setup.
Definition: aarch64-mmu.h:52
This structure represents the state to maintain the MMU translation tables.
Definition: aarch64-mmu.h:145
size_t used_page_tables
This member contains the count of used page tables.
Definition: aarch64-mmu.h:156
uint64_t * ttb
This member references the translation table base.
Definition: aarch64-mmu.h:149
Definition: intercom.c:87