| 1 | /*
|
|---|
| 2 | * Copyright (c) 2007 Pavel Jancik, Michal Kebrt
|
|---|
| 3 | * All rights reserved.
|
|---|
| 4 | *
|
|---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 6 | * modification, are permitted provided that the following conditions
|
|---|
| 7 | * are met:
|
|---|
| 8 | *
|
|---|
| 9 | * - Redistributions of source code must retain the above copyright
|
|---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
|---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 13 | * documentation and/or other materials provided with the distribution.
|
|---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 15 | * derived from this software without specific prior written permission.
|
|---|
| 16 | *
|
|---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 27 | */
|
|---|
| 28 |
|
|---|
| 29 | /** @addtogroup arm32mm
|
|---|
| 30 | * @{
|
|---|
| 31 | */
|
|---|
| 32 | /** @file
|
|---|
| 33 | * @brief Paging related declarations.
|
|---|
| 34 | */
|
|---|
| 35 |
|
|---|
| 36 | #ifndef KERN_arm32_PAGE_H_
|
|---|
| 37 | #define KERN_arm32_PAGE_H_
|
|---|
| 38 |
|
|---|
| 39 | #include <arch/mm/frame.h>
|
|---|
| 40 | #include <mm/mm.h>
|
|---|
| 41 | #include <arch/exception.h>
|
|---|
| 42 | #include <arch/barrier.h>
|
|---|
| 43 | #include <arch/cp15.h>
|
|---|
| 44 | #include <trace.h>
|
|---|
| 45 |
|
|---|
| 46 | #define PAGE_WIDTH FRAME_WIDTH
|
|---|
| 47 | #define PAGE_SIZE FRAME_SIZE
|
|---|
| 48 |
|
|---|
| 49 | #if (defined MACHINE_beagleboardxm) || (defined MACHINE_beaglebone)
|
|---|
| 50 | #ifndef __ASM__
|
|---|
| 51 | # define KA2PA(x) ((uintptr_t) (x))
|
|---|
| 52 | # define PA2KA(x) ((uintptr_t) (x))
|
|---|
| 53 | #else
|
|---|
| 54 | # define KA2PA(x) (x)
|
|---|
| 55 | # define PA2KA(x) (x)
|
|---|
| 56 | #endif
|
|---|
| 57 | #else
|
|---|
| 58 | #ifndef __ASM__
|
|---|
| 59 | # define KA2PA(x) (((uintptr_t) (x)) - 0x80000000)
|
|---|
| 60 | # define PA2KA(x) (((uintptr_t) (x)) + 0x80000000)
|
|---|
| 61 | #else
|
|---|
| 62 | # define KA2PA(x) ((x) - 0x80000000)
|
|---|
| 63 | # define PA2KA(x) ((x) + 0x80000000)
|
|---|
| 64 | #endif
|
|---|
| 65 | #endif
|
|---|
| 66 |
|
|---|
| 67 | /* Number of entries in each level. */
|
|---|
| 68 | #define PTL0_ENTRIES_ARCH (1 << 12) /* 4096 */
|
|---|
| 69 | #define PTL1_ENTRIES_ARCH 0
|
|---|
| 70 | #define PTL2_ENTRIES_ARCH 0
|
|---|
| 71 | /* coarse page tables used (256 * 4 = 1KB per page) */
|
|---|
| 72 | #define PTL3_ENTRIES_ARCH (1 << 8) /* 256 */
|
|---|
| 73 |
|
|---|
| 74 | /* Page table sizes for each level. */
|
|---|
| 75 | #define PTL0_SIZE_ARCH FOUR_FRAMES
|
|---|
| 76 | #define PTL1_SIZE_ARCH 0
|
|---|
| 77 | #define PTL2_SIZE_ARCH 0
|
|---|
| 78 | #define PTL3_SIZE_ARCH ONE_FRAME
|
|---|
| 79 |
|
|---|
| 80 | /* Macros calculating indices into page tables for each level. */
|
|---|
| 81 | #define PTL0_INDEX_ARCH(vaddr) (((vaddr) >> 20) & 0xfff)
|
|---|
| 82 | #define PTL1_INDEX_ARCH(vaddr) 0
|
|---|
| 83 | #define PTL2_INDEX_ARCH(vaddr) 0
|
|---|
| 84 | #define PTL3_INDEX_ARCH(vaddr) (((vaddr) >> 12) & 0x0ff)
|
|---|
| 85 |
|
|---|
| 86 | /* Get PTE address accessors for each level. */
|
|---|
| 87 | #define GET_PTL1_ADDRESS_ARCH(ptl0, i) \
|
|---|
| 88 | ((pte_t *) ((((pte_t *)(ptl0))[(i)].l0).coarse_table_addr << 10))
|
|---|
| 89 | #define GET_PTL2_ADDRESS_ARCH(ptl1, i) \
|
|---|
| 90 | (ptl1)
|
|---|
| 91 | #define GET_PTL3_ADDRESS_ARCH(ptl2, i) \
|
|---|
| 92 | (ptl2)
|
|---|
| 93 | #define GET_FRAME_ADDRESS_ARCH(ptl3, i) \
|
|---|
| 94 | ((uintptr_t) ((((pte_t *)(ptl3))[(i)].l1).frame_base_addr << 12))
|
|---|
| 95 |
|
|---|
| 96 | /* Set PTE address accessors for each level. */
|
|---|
| 97 | #define SET_PTL0_ADDRESS_ARCH(ptl0) \
|
|---|
| 98 | set_ptl0_addr((pte_t *) (ptl0))
|
|---|
| 99 | #define SET_PTL1_ADDRESS_ARCH(ptl0, i, a) \
|
|---|
| 100 | set_ptl1_addr((pte_t*) (ptl0), i, a)
|
|---|
| 101 | #define SET_PTL2_ADDRESS_ARCH(ptl1, i, a)
|
|---|
| 102 | #define SET_PTL3_ADDRESS_ARCH(ptl2, i, a)
|
|---|
| 103 | #define SET_FRAME_ADDRESS_ARCH(ptl3, i, a) \
|
|---|
| 104 | set_ptl3_addr((pte_t*) (ptl3), i, a)
|
|---|
| 105 |
|
|---|
| 106 | /* Get PTE flags accessors for each level. */
|
|---|
| 107 | #define GET_PTL1_FLAGS_ARCH(ptl0, i) \
|
|---|
| 108 | get_pt_level0_flags((pte_t *) (ptl0), (size_t) (i))
|
|---|
| 109 | #define GET_PTL2_FLAGS_ARCH(ptl1, i) \
|
|---|
| 110 | PAGE_PRESENT
|
|---|
| 111 | #define GET_PTL3_FLAGS_ARCH(ptl2, i) \
|
|---|
| 112 | PAGE_PRESENT
|
|---|
| 113 | #define GET_FRAME_FLAGS_ARCH(ptl3, i) \
|
|---|
| 114 | get_pt_level1_flags((pte_t *) (ptl3), (size_t) (i))
|
|---|
| 115 |
|
|---|
| 116 | /* Set PTE flags accessors for each level. */
|
|---|
| 117 | #define SET_PTL1_FLAGS_ARCH(ptl0, i, x) \
|
|---|
| 118 | set_pt_level0_flags((pte_t *) (ptl0), (size_t) (i), (x))
|
|---|
| 119 | #define SET_PTL2_FLAGS_ARCH(ptl1, i, x)
|
|---|
| 120 | #define SET_PTL3_FLAGS_ARCH(ptl2, i, x)
|
|---|
| 121 | #define SET_FRAME_FLAGS_ARCH(ptl3, i, x) \
|
|---|
| 122 | set_pt_level1_flags((pte_t *) (ptl3), (size_t) (i), (x))
|
|---|
| 123 |
|
|---|
| 124 | /* Set PTE present bit accessors for each level. */
|
|---|
| 125 | #define SET_PTL1_PRESENT_ARCH(ptl0, i) \
|
|---|
| 126 | set_pt_level0_present((pte_t *) (ptl0), (size_t) (i))
|
|---|
| 127 | #define SET_PTL2_PRESENT_ARCH(ptl1, i)
|
|---|
| 128 | #define SET_PTL3_PRESENT_ARCH(ptl2, i)
|
|---|
| 129 | #define SET_FRAME_PRESENT_ARCH(ptl3, i) \
|
|---|
| 130 | set_pt_level1_present((pte_t *) (ptl3), (size_t) (i))
|
|---|
| 131 |
|
|---|
| 132 |
|
|---|
| 133 | #define pt_coherence(page) pt_coherence_m(page, 1)
|
|---|
| 134 |
|
|---|
| 135 | #if defined(PROCESSOR_ARCH_armv6) | defined(PROCESSOR_ARCH_armv7_a)
|
|---|
| 136 | #include "page_armv6.h"
|
|---|
| 137 | #elif defined(PROCESSOR_ARCH_armv4) | defined(PROCESSOR_ARCH_armv5)
|
|---|
| 138 | #include "page_armv4.h"
|
|---|
| 139 | #else
|
|---|
| 140 | #error "Unsupported architecture"
|
|---|
| 141 | #endif
|
|---|
| 142 |
|
|---|
| 143 | /** Sets the address of level 0 page table.
|
|---|
| 144 | *
|
|---|
| 145 | * @param pt Pointer to the page table to set.
|
|---|
| 146 | *
|
|---|
| 147 | * Page tables are always in cacheable memory.
|
|---|
| 148 | * Make sure the memory type is correct, and in sync with:
|
|---|
| 149 | * init_boot_pt (boot/arch/arm32/src/mm.c)
|
|---|
| 150 | * init_ptl0_section (boot/arch/arm32/src/mm.c)
|
|---|
| 151 | * set_pt_level1_flags (kernel/arch/arm32/include/arch/mm/page_armv6.h)
|
|---|
| 152 | */
|
|---|
| 153 | NO_TRACE static inline void set_ptl0_addr(pte_t *pt)
|
|---|
| 154 | {
|
|---|
| 155 | uint32_t val = (uint32_t)pt & TTBR_ADDR_MASK;
|
|---|
| 156 | val |= TTBR_RGN_WBWA_CACHE | TTBR_C_FLAG;
|
|---|
| 157 | TTBR0_write(val);
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 | NO_TRACE static inline void set_ptl1_addr(pte_t *pt, size_t i, uintptr_t address)
|
|---|
| 161 | {
|
|---|
| 162 | pt[i].l0.coarse_table_addr = address >> 10;
|
|---|
| 163 | pt_coherence(&pt[i].l0);
|
|---|
| 164 | }
|
|---|
| 165 |
|
|---|
| 166 | NO_TRACE static inline void set_ptl3_addr(pte_t *pt, size_t i, uintptr_t address)
|
|---|
| 167 | {
|
|---|
| 168 | pt[i].l1.frame_base_addr = address >> 12;
|
|---|
| 169 | pt_coherence(&pt[i].l1);
|
|---|
| 170 | }
|
|---|
| 171 |
|
|---|
| 172 | #endif
|
|---|
| 173 |
|
|---|
| 174 | /** @}
|
|---|
| 175 | */
|
|---|