source: mainline/kernel/arch/arm32/include/arch/mm/page.h@ 999efa9

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 999efa9 was 999efa9, checked in by Jakub Jermar <jakub@…>, 8 years ago

Reformat copyright messages

The goal is to have one copyright-holder per line so that it is easier
to do some sort of automatic processing.

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