1 | /* |
---|
2 | * Copyright (c) 2009-2013 embedded brains GmbH. All rights reserved. |
---|
3 | * |
---|
4 | * embedded brains GmbH |
---|
5 | * Dornierstr. 4 |
---|
6 | * 82178 Puchheim |
---|
7 | * Germany |
---|
8 | * <info@embedded-brains.de> |
---|
9 | * |
---|
10 | * The license and distribution terms for this file may be |
---|
11 | * found in the file LICENSE in this distribution or at |
---|
12 | * http://www.rtems.com/license/LICENSE. |
---|
13 | */ |
---|
14 | |
---|
15 | #ifndef LIBBSP_ARM_SHARED_ARM_CP15_START_H |
---|
16 | #define LIBBSP_ARM_SHARED_ARM_CP15_START_H |
---|
17 | |
---|
18 | #include <libcpu/arm-cp15.h> |
---|
19 | |
---|
20 | #include <bsp/start.h> |
---|
21 | |
---|
22 | #ifdef __cplusplus |
---|
23 | extern "C" { |
---|
24 | #endif /* __cplusplus */ |
---|
25 | |
---|
26 | BSP_START_TEXT_SECTION static inline void |
---|
27 | arm_cp15_set_domain_access_control(uint32_t val); |
---|
28 | |
---|
29 | BSP_START_TEXT_SECTION static inline void |
---|
30 | arm_cp15_set_translation_table_base(uint32_t *base); |
---|
31 | |
---|
32 | BSP_START_TEXT_SECTION static inline void |
---|
33 | arm_cp15_set_control(uint32_t val); |
---|
34 | |
---|
35 | BSP_START_TEXT_SECTION static inline uint32_t |
---|
36 | arm_cp15_get_control(void); |
---|
37 | |
---|
38 | BSP_START_TEXT_SECTION static inline void |
---|
39 | arm_cp15_cache_invalidate(void); |
---|
40 | |
---|
41 | BSP_START_TEXT_SECTION static inline void |
---|
42 | arm_cp15_tlb_invalidate(void); |
---|
43 | |
---|
44 | typedef struct { |
---|
45 | uint32_t begin; |
---|
46 | uint32_t end; |
---|
47 | uint32_t flags; |
---|
48 | } arm_cp15_start_section_config; |
---|
49 | |
---|
50 | BSP_START_TEXT_SECTION static inline void |
---|
51 | arm_cp15_start_set_translation_table_entries( |
---|
52 | uint32_t *ttb, |
---|
53 | const arm_cp15_start_section_config *config |
---|
54 | ) |
---|
55 | { |
---|
56 | uint32_t i = ARM_MMU_SECT_GET_INDEX(config->begin); |
---|
57 | uint32_t iend = |
---|
58 | ARM_MMU_SECT_GET_INDEX(ARM_MMU_SECT_MVA_ALIGN_UP(config->end)); |
---|
59 | |
---|
60 | if (config->begin != config->end) { |
---|
61 | while (i < iend) { |
---|
62 | ttb [i] = (i << ARM_MMU_SECT_BASE_SHIFT) | config->flags; |
---|
63 | ++i; |
---|
64 | } |
---|
65 | } |
---|
66 | } |
---|
67 | |
---|
68 | BSP_START_TEXT_SECTION static void |
---|
69 | arm_cp15_start_setup_translation_table_and_enable_mmu( |
---|
70 | uint32_t ctrl, |
---|
71 | uint32_t *ttb, |
---|
72 | uint32_t client_domain, |
---|
73 | const arm_cp15_start_section_config *config_table, |
---|
74 | size_t config_count |
---|
75 | ) |
---|
76 | { |
---|
77 | uint32_t dac = ARM_CP15_DAC_DOMAIN(client_domain, ARM_CP15_DAC_CLIENT); |
---|
78 | size_t i; |
---|
79 | |
---|
80 | arm_cp15_set_domain_access_control(dac); |
---|
81 | arm_cp15_set_translation_table_base(ttb); |
---|
82 | |
---|
83 | /* Initialize translation table with invalid entries */ |
---|
84 | for (i = 0; i < ARM_MMU_TRANSLATION_TABLE_ENTRY_COUNT; ++i) { |
---|
85 | ttb [i] = 0; |
---|
86 | } |
---|
87 | |
---|
88 | for (i = 0; i < config_count; ++i) { |
---|
89 | arm_cp15_start_set_translation_table_entries(ttb, &config_table [i]); |
---|
90 | } |
---|
91 | |
---|
92 | /* Enable MMU and cache */ |
---|
93 | ctrl |= ARM_CP15_CTRL_I | ARM_CP15_CTRL_C | ARM_CP15_CTRL_M; |
---|
94 | arm_cp15_set_control(ctrl); |
---|
95 | } |
---|
96 | |
---|
97 | BSP_START_TEXT_SECTION static inline uint32_t |
---|
98 | arm_cp15_start_setup_mmu_and_cache(uint32_t ctrl_clear, uint32_t ctrl_set) |
---|
99 | { |
---|
100 | uint32_t ctrl = arm_cp15_get_control(); |
---|
101 | |
---|
102 | ctrl &= ~ctrl_clear; |
---|
103 | ctrl |= ctrl_set; |
---|
104 | |
---|
105 | arm_cp15_set_control(ctrl); |
---|
106 | |
---|
107 | arm_cp15_tlb_invalidate(); |
---|
108 | |
---|
109 | return ctrl; |
---|
110 | } |
---|
111 | |
---|
112 | #ifdef __cplusplus |
---|
113 | } |
---|
114 | #endif /* __cplusplus */ |
---|
115 | |
---|
116 | #endif /* LIBBSP_ARM_SHARED_ARM_CP15_START_H */ |
---|