1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup lpc32xx_mmu |
---|
5 | * |
---|
6 | * @brief MMU support implementation. |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * Copyright (c) 2010-2011 embedded brains GmbH. All rights reserved. |
---|
11 | * |
---|
12 | * embedded brains GmbH |
---|
13 | * Obere Lagerstr. 30 |
---|
14 | * 82178 Puchheim |
---|
15 | * Germany |
---|
16 | * <rtems@embedded-brains.de> |
---|
17 | * |
---|
18 | * The license and distribution terms for this file may be |
---|
19 | * found in the file LICENSE in this distribution or at |
---|
20 | * http://www.rtems.com/license/LICENSE. |
---|
21 | */ |
---|
22 | |
---|
23 | #include <bsp/mmu.h> |
---|
24 | |
---|
25 | static uint32_t disable_mmu(void) |
---|
26 | { |
---|
27 | uint32_t ctrl = 0; |
---|
28 | |
---|
29 | arm_cp15_data_cache_test_and_clean_and_invalidate(); |
---|
30 | |
---|
31 | ctrl = arm_cp15_get_control(); |
---|
32 | arm_cp15_set_control(ctrl & ~ARM_CP15_CTRL_M); |
---|
33 | |
---|
34 | arm_cp15_tlb_invalidate(); |
---|
35 | |
---|
36 | return ctrl; |
---|
37 | } |
---|
38 | |
---|
39 | static void restore_mmu_control(uint32_t ctrl) |
---|
40 | { |
---|
41 | arm_cp15_set_control(ctrl); |
---|
42 | } |
---|
43 | |
---|
44 | uint32_t set_translation_table_entries( |
---|
45 | const void *begin, |
---|
46 | const void *end, |
---|
47 | uint32_t section_flags |
---|
48 | ) |
---|
49 | { |
---|
50 | uint32_t *ttb = arm_cp15_get_translation_table_base(); |
---|
51 | uint32_t i = ARM_MMU_SECT_GET_INDEX(begin); |
---|
52 | uint32_t iend = ARM_MMU_SECT_GET_INDEX(ARM_MMU_SECT_MVA_ALIGN_UP(end)); |
---|
53 | uint32_t ctrl = disable_mmu(); |
---|
54 | uint32_t section_flags_of_first_entry = ttb [i]; |
---|
55 | |
---|
56 | while (i < iend) { |
---|
57 | ttb [i] = (i << ARM_MMU_SECT_BASE_SHIFT) | section_flags; |
---|
58 | ++i; |
---|
59 | } |
---|
60 | |
---|
61 | restore_mmu_control(ctrl); |
---|
62 | |
---|
63 | return section_flags_of_first_entry; |
---|
64 | } |
---|
65 | |
---|
66 | uint32_t lpc32xx_set_translation_table_entries( |
---|
67 | const void *begin, |
---|
68 | const void *end, |
---|
69 | uint32_t section_flags |
---|
70 | ) |
---|
71 | { |
---|
72 | rtems_interrupt_level level; |
---|
73 | uint32_t section_flags_of_first_entry = 0; |
---|
74 | |
---|
75 | rtems_interrupt_disable(level); |
---|
76 | section_flags_of_first_entry = |
---|
77 | set_translation_table_entries(begin, end, section_flags); |
---|
78 | rtems_interrupt_enable(level); |
---|
79 | |
---|
80 | return section_flags_of_first_entry; |
---|
81 | } |
---|