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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since df15e5f was c0699467, checked in by Martin Decky <martin@…>, 14 years ago

do not provide general access to kernel headers from uspace, only allow specific headers to be accessed or shared
externalize headers which serve as kernel/uspace API/ABI into a special tree

  • Property mode set to 100644
File size: 5.6 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/* Macros for querying the last-level PTEs. */
132#define PTE_VALID_ARCH(pte) (*((uint32_t *) (pte)) != 0)
133#define PTE_PRESENT_ARCH(pte) ((pte)->present != 0)
134#define PTE_GET_FRAME_ARCH(pte) ((pte)->pfn << 12)
135#define PTE_WRITABLE_ARCH(pte) 1
136#define PTE_EXECUTABLE_ARCH(pte) 1
137
138#ifndef __ASM__
139
140#include <mm/mm.h>
141#include <arch/interrupt.h>
142
143/** Page Table Entry. */
144typedef struct {
145 unsigned int present : 1; /**< Present bit. */
146 unsigned int page_write_through : 1; /**< Write thought caching. */
147 unsigned int page_cache_disable : 1; /**< No caching. */
148 unsigned int accessed : 1; /**< Accessed bit. */
149 unsigned int global : 1; /**< Global bit. */
150 unsigned int valid : 1; /**< Valid content even if not present. */
151 unsigned int pfn : 20; /**< Physical frame number. */
152} pte_t;
153
154NO_TRACE static inline unsigned int get_pt_flags(pte_t *pt, size_t i)
155{
156 pte_t *entry = &pt[i];
157
158 return (((!entry->page_cache_disable) << PAGE_CACHEABLE_SHIFT) |
159 ((!entry->present) << PAGE_PRESENT_SHIFT) |
160 (1 << PAGE_USER_SHIFT) |
161 (1 << PAGE_READ_SHIFT) |
162 (1 << PAGE_WRITE_SHIFT) |
163 (1 << PAGE_EXEC_SHIFT) |
164 (entry->global << PAGE_GLOBAL_SHIFT));
165}
166
167NO_TRACE static inline void set_pt_flags(pte_t *pt, size_t i, int flags)
168{
169 pte_t *entry = &pt[i];
170
171 entry->page_cache_disable = !(flags & PAGE_CACHEABLE);
172 entry->present = !(flags & PAGE_NOT_PRESENT);
173 entry->global = (flags & PAGE_GLOBAL) != 0;
174 entry->valid = 1;
175}
176
177extern void page_arch_init(void);
178
179#endif /* __ASM__ */
180
181#endif
182
183/** @}
184 */
Note: See TracBrowser for help on using the repository browser.