1 | /* |
---|
2 | * Copyright (c) 2010-2019 embedded brains GmbH. All rights reserved. |
---|
3 | * |
---|
4 | * The license and distribution terms for this file may be |
---|
5 | * found in the file LICENSE in this distribution or at |
---|
6 | * http://www.rtems.org/license/LICENSE. |
---|
7 | */ |
---|
8 | |
---|
9 | #include <rtems.h> |
---|
10 | #include <libcpu/arm-cp15.h> |
---|
11 | #include <bspopts.h> |
---|
12 | |
---|
13 | /* |
---|
14 | * Translation table modification requires to propagate |
---|
15 | * information to memory and other cores. |
---|
16 | * |
---|
17 | * Algorithm follows example found in the section |
---|
18 | * |
---|
19 | * B3.10.1 General TLB maintenance requirements |
---|
20 | * TLB maintenance operations and the memory order model |
---|
21 | * |
---|
22 | * of ARM Architecture Reference Manual |
---|
23 | * ARMv7-A and ARMv7-R edition |
---|
24 | * ARM DDI 0406C.b (ID072512) |
---|
25 | */ |
---|
26 | |
---|
27 | static uint32_t set_translation_table_entries( |
---|
28 | const void *begin, |
---|
29 | const void *end, |
---|
30 | uint32_t section_flags |
---|
31 | ) |
---|
32 | { |
---|
33 | uint32_t *ttb; |
---|
34 | #ifdef ARM_MMU_USE_SMALL_PAGES |
---|
35 | uint32_t *pt; |
---|
36 | uint32_t flags; |
---|
37 | #endif |
---|
38 | uint32_t istart; |
---|
39 | uint32_t iend; |
---|
40 | uint32_t index_mask; |
---|
41 | uint32_t section_flags_of_first_entry; |
---|
42 | uint32_t i; |
---|
43 | uint32_t *modified_begin; |
---|
44 | size_t modified_size; |
---|
45 | |
---|
46 | ttb = arm_cp15_get_translation_table_base(); |
---|
47 | #ifdef ARM_MMU_USE_SMALL_PAGES |
---|
48 | pt = &ttb[ARM_MMU_TRANSLATION_TABLE_ENTRY_COUNT]; |
---|
49 | istart = ARM_MMU_SMALL_PAGE_GET_INDEX(begin); |
---|
50 | iend = ARM_MMU_SMALL_PAGE_GET_INDEX(ARM_MMU_SMALL_PAGE_MVA_ALIGN_UP(end)); |
---|
51 | index_mask = (1U << (32 - ARM_MMU_SMALL_PAGE_BASE_SHIFT)) - 1U; |
---|
52 | section_flags_of_first_entry = ARM_MMU_SMALL_PAGE_FLAGS_TO_SECT(pt[istart]) |
---|
53 | | ARM_MMU_PAGE_TABLE_FLAGS_TO_SECT(ttb[ARM_MMU_SECT_GET_INDEX(begin)]); |
---|
54 | modified_begin = &pt[istart]; |
---|
55 | flags = ARM_MMU_SECT_FLAGS_TO_SMALL_PAGE(section_flags); |
---|
56 | #else |
---|
57 | istart = ARM_MMU_SECT_GET_INDEX(begin); |
---|
58 | iend = ARM_MMU_SECT_GET_INDEX(ARM_MMU_SECT_MVA_ALIGN_UP(end)); |
---|
59 | index_mask = (1U << (32 - ARM_MMU_SECT_BASE_SHIFT)) - 1U; |
---|
60 | section_flags_of_first_entry = ttb[istart]; |
---|
61 | modified_begin = &ttb[istart]; |
---|
62 | #endif |
---|
63 | modified_size = 0; |
---|
64 | |
---|
65 | for ( i = istart; i != iend; i = (i + 1U) & index_mask ) { |
---|
66 | uint32_t pa; |
---|
67 | |
---|
68 | #ifdef ARM_MMU_USE_SMALL_PAGES |
---|
69 | pa = i << ARM_MMU_SMALL_PAGE_BASE_SHIFT; |
---|
70 | pt[i] = pa | flags; |
---|
71 | modified_size += ARM_MMU_SMALL_PAGE_TABLE_ENTRY_SIZE; |
---|
72 | #else |
---|
73 | pa = i << ARM_MMU_SECT_BASE_SHIFT; |
---|
74 | ttb[i] = pa | section_flags; |
---|
75 | modified_size += ARM_MMU_TRANSLATION_TABLE_ENTRY_SIZE; |
---|
76 | #endif |
---|
77 | } |
---|
78 | |
---|
79 | if ((arm_cp15_get_control() & (ARM_CP15_CTRL_C | ARM_CP15_CTRL_M)) != 0) { |
---|
80 | rtems_cache_flush_multiple_data_lines(modified_begin, modified_size); |
---|
81 | } |
---|
82 | |
---|
83 | _ARM_Data_synchronization_barrier(); |
---|
84 | |
---|
85 | for ( i = istart; i != iend; i = (i + 1U) & index_mask ) { |
---|
86 | void *mva; |
---|
87 | |
---|
88 | #ifdef ARM_MMU_USE_SMALL_PAGES |
---|
89 | mva = (void *) (i << ARM_MMU_SMALL_PAGE_BASE_SHIFT); |
---|
90 | #else |
---|
91 | mva = (void *) (i << ARM_MMU_SECT_BASE_SHIFT); |
---|
92 | #endif |
---|
93 | |
---|
94 | #if defined(__ARM_ARCH_7A__) |
---|
95 | /* |
---|
96 | * Bit 31 needs to be 1 to indicate the register implements the |
---|
97 | * Multiprocessing Extensions register format and the U (bit 30) |
---|
98 | * is 0. |
---|
99 | */ |
---|
100 | #define MPIDR_MX_FMT (1 << 31) |
---|
101 | #define MPIDR_UP (1 << 30) |
---|
102 | const uint32_t mpidr = arm_cp15_get_multiprocessor_affinity(); |
---|
103 | if ((mpidr & (MPIDR_MX_FMT | MPIDR_UP)) == MPIDR_MX_FMT) { |
---|
104 | arm_cp15_tlb_invalidate_entry_all_asids_inner_shareable(mva); |
---|
105 | } |
---|
106 | else |
---|
107 | #endif |
---|
108 | { |
---|
109 | arm_cp15_tlb_instruction_invalidate_entry(mva); |
---|
110 | arm_cp15_tlb_data_invalidate_entry(mva); |
---|
111 | } |
---|
112 | } |
---|
113 | |
---|
114 | _ARM_Data_synchronization_barrier(); |
---|
115 | _ARM_Instruction_synchronization_barrier(); |
---|
116 | |
---|
117 | return section_flags_of_first_entry; |
---|
118 | } |
---|
119 | |
---|
120 | uint32_t arm_cp15_set_translation_table_entries( |
---|
121 | const void *begin, |
---|
122 | const void *end, |
---|
123 | uint32_t section_flags |
---|
124 | ) |
---|
125 | { |
---|
126 | return set_translation_table_entries(begin, end, section_flags); |
---|
127 | } |
---|