source: mainline/kernel/arch/ppc32/include/mm/page.h@ 0d8269b

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

Add macros for setting the present bit in PTEs separately.

  • Property mode set to 100644
File size: 6.0 KB
Line 
1/*
2 * Copyright (c) 2005 Martin Decky
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 ppc32mm
30 * @{
31 */
32/** @file
33 */
34
35#ifndef KERN_ppc32_PAGE_H_
36#define KERN_ppc32_PAGE_H_
37
38#include <arch/mm/frame.h>
39#include <trace.h>
40
41#define PAGE_WIDTH FRAME_WIDTH
42#define PAGE_SIZE FRAME_SIZE
43
44#ifndef __ASM__
45 #define KA2PA(x) (((uintptr_t) (x)) - 0x80000000)
46 #define PA2KA(x) (((uintptr_t) (x)) + 0x80000000)
47#else
48 #define KA2PA(x) ((x) - 0x80000000)
49 #define PA2KA(x) ((x) + 0x80000000)
50#endif
51
52/*
53 * Implementation of generic 4-level page table interface,
54 * the hardware Page Hash Table is used as cache.
55 *
56 * Page table layout:
57 * - 32-bit virtual addressess
58 * - Offset is 12 bits => pages are 4K long
59 * - PTL0 has 1024 entries (10 bits)
60 * - PTL1 is not used
61 * - PTL2 is not used
62 * - PLT3 has 1024 entries (10 bits)
63 */
64
65/* Number of entries in each level. */
66#define PTL0_ENTRIES_ARCH 1024
67#define PTL1_ENTRIES_ARCH 0
68#define PTL2_ENTRIES_ARCH 0
69#define PTL3_ENTRIES_ARCH 1024
70
71/* Page table sizes for each level. */
72#define PTL0_SIZE_ARCH ONE_FRAME
73#define PTL1_SIZE_ARCH 0
74#define PTL2_SIZE_ARCH 0
75#define PTL3_SIZE_ARCH ONE_FRAME
76
77/* Macros calculating indices into page tables on each level. */
78#define PTL0_INDEX_ARCH(vaddr) (((vaddr) >> 22) & 0x3ff)
79#define PTL1_INDEX_ARCH(vaddr) 0
80#define PTL2_INDEX_ARCH(vaddr) 0
81#define PTL3_INDEX_ARCH(vaddr) (((vaddr) >> 12) & 0x3ff)
82
83/* Get PTE address accessors for each level. */
84#define GET_PTL1_ADDRESS_ARCH(ptl0, i) \
85 (((pte_t *) (ptl0))[(i)].pfn << 12)
86
87#define GET_PTL2_ADDRESS_ARCH(ptl1, i) \
88 (ptl1)
89
90#define GET_PTL3_ADDRESS_ARCH(ptl2, i) \
91 (ptl2)
92
93#define GET_FRAME_ADDRESS_ARCH(ptl3, i) \
94 (((pte_t *) (ptl3))[(i)].pfn << 12)
95
96/* Set PTE address accessors for each level. */
97#define SET_PTL0_ADDRESS_ARCH(ptl0)
98
99#define SET_PTL1_ADDRESS_ARCH(ptl0, i, a) \
100 (((pte_t *) (ptl0))[(i)].pfn = (a) >> 12)
101
102#define SET_PTL2_ADDRESS_ARCH(ptl1, i, a)
103#define SET_PTL3_ADDRESS_ARCH(ptl2, i, a)
104
105#define SET_FRAME_ADDRESS_ARCH(ptl3, i, a) \
106 (((pte_t *) (ptl3))[(i)].pfn = (a) >> 12)
107
108/* Get PTE flags accessors for each level. */
109#define GET_PTL1_FLAGS_ARCH(ptl0, i) \
110 get_pt_flags((pte_t *) (ptl0), (size_t) (i))
111
112#define GET_PTL2_FLAGS_ARCH(ptl1, i) \
113 PAGE_PRESENT
114
115#define GET_PTL3_FLAGS_ARCH(ptl2, i) \
116 PAGE_PRESENT
117
118#define GET_FRAME_FLAGS_ARCH(ptl3, i) \
119 get_pt_flags((pte_t *) (ptl3), (size_t) (i))
120
121/* Set PTE flags accessors for each level. */
122#define SET_PTL1_FLAGS_ARCH(ptl0, i, x) \
123 set_pt_flags((pte_t *) (ptl0), (size_t) (i), (x))
124
125#define SET_PTL2_FLAGS_ARCH(ptl1, i, x)
126#define SET_PTL3_FLAGS_ARCH(ptl2, i, x)
127
128#define SET_FRAME_FLAGS_ARCH(ptl3, i, x) \
129 set_pt_flags((pte_t *) (ptl3), (size_t) (i), (x))
130
131/* Set PTE present accessors for each level. */
132#define SET_PTL1_PRESENT_ARCH(ptl0, i) \
133 set_pt_present((pte_t *) (ptl0), (size_t) (i))
134
135#define SET_PTL2_PRESENT_ARCH(ptl1, i)
136#define SET_PTL3_PRESENT_ARCH(ptl2, i)
137
138#define SET_FRAME_PRESENT_ARCH(ptl3, i) \
139 set_pt_present((pte_t *) (ptl3), (size_t) (i))
140
141/* Macros for querying the last-level PTEs. */
142#define PTE_VALID_ARCH(pte) (*((uint32_t *) (pte)) != 0)
143#define PTE_PRESENT_ARCH(pte) ((pte)->present != 0)
144#define PTE_GET_FRAME_ARCH(pte) ((pte)->pfn << 12)
145#define PTE_WRITABLE_ARCH(pte) 1
146#define PTE_EXECUTABLE_ARCH(pte) 1
147
148#ifndef __ASM__
149
150#include <mm/mm.h>
151#include <arch/interrupt.h>
152
153/** Page Table Entry. */
154typedef struct {
155 unsigned int present : 1; /**< Present bit. */
156 unsigned int page_write_through : 1; /**< Write thought caching. */
157 unsigned int page_cache_disable : 1; /**< No caching. */
158 unsigned int accessed : 1; /**< Accessed bit. */
159 unsigned int global : 1; /**< Global bit. */
160 unsigned int valid : 1; /**< Valid content even if not present. */
161 unsigned int pfn : 20; /**< Physical frame number. */
162} pte_t;
163
164NO_TRACE static inline unsigned int get_pt_flags(pte_t *pt, size_t i)
165{
166 pte_t *entry = &pt[i];
167
168 return (((!entry->page_cache_disable) << PAGE_CACHEABLE_SHIFT) |
169 ((!entry->present) << PAGE_PRESENT_SHIFT) |
170 (1 << PAGE_USER_SHIFT) |
171 (1 << PAGE_READ_SHIFT) |
172 (1 << PAGE_WRITE_SHIFT) |
173 (1 << PAGE_EXEC_SHIFT) |
174 (entry->global << PAGE_GLOBAL_SHIFT));
175}
176
177NO_TRACE static inline void set_pt_flags(pte_t *pt, size_t i, int flags)
178{
179 pte_t *entry = &pt[i];
180
181 entry->page_cache_disable = !(flags & PAGE_CACHEABLE);
182 entry->present = !(flags & PAGE_NOT_PRESENT);
183 entry->global = (flags & PAGE_GLOBAL) != 0;
184 entry->valid = 1;
185}
186
187NO_TRACE static inline void set_pt_present(pte_t *pt, size_t i)
188{
189 pte_t *entry = &pt[i];
190
191 entry->present = 1;
192}
193
194extern void page_arch_init(void);
195
196#endif /* __ASM__ */
197
198#endif
199
200/** @}
201 */
Note: See TracBrowser for help on using the repository browser.