pte.h revision 1.1 1 1.1 thorpej /* $NetBSD: pte.h,v 1.1 2001/11/23 17:39:04 thorpej Exp $ */
2 1.1 thorpej
3 1.1 thorpej /*
4 1.1 thorpej * Copyright (c) 1994 Mark Brinicombe.
5 1.1 thorpej * All rights reserved.
6 1.1 thorpej *
7 1.1 thorpej * Redistribution and use in source and binary forms, with or without
8 1.1 thorpej * modification, are permitted provided that the following conditions
9 1.1 thorpej * are met:
10 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
11 1.1 thorpej * notice, this list of conditions and the following disclaimer.
12 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
14 1.1 thorpej * documentation and/or other materials provided with the distribution.
15 1.1 thorpej * 3. All advertising materials mentioning features or use of this software
16 1.1 thorpej * must display the following acknowledgement:
17 1.1 thorpej * This product includes software developed by the RiscBSD team.
18 1.1 thorpej * 4. The name "RiscBSD" nor the name of the author may be used to
19 1.1 thorpej * endorse or promote products derived from this software without specific
20 1.1 thorpej * prior written permission.
21 1.1 thorpej *
22 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY RISCBSD ``AS IS'' AND ANY EXPRESS OR IMPLIED
23 1.1 thorpej * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24 1.1 thorpej * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 1.1 thorpej * IN NO EVENT SHALL RISCBSD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
26 1.1 thorpej * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 1.1 thorpej * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 1.1 thorpej * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 1.1 thorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 1.1 thorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 1.1 thorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 1.1 thorpej * SUCH DAMAGE.
33 1.1 thorpej */
34 1.1 thorpej
35 1.1 thorpej #ifndef _ARM32_PTE_H_
36 1.1 thorpej #define _ARM32_PTE_H_
37 1.1 thorpej
38 1.1 thorpej #define PDSHIFT 20 /* LOG2(NBPDR) */
39 1.1 thorpej #define NBPD (1 << PDSHIFT) /* bytes/page dir */
40 1.1 thorpej #define NPTEPD (NBPD / NBPG)
41 1.1 thorpej
42 1.1 thorpej #ifndef _LOCORE
43 1.1 thorpej typedef int pd_entry_t; /* page directory entry */
44 1.1 thorpej typedef int pt_entry_t; /* page table entry */
45 1.1 thorpej #endif
46 1.1 thorpej
47 1.1 thorpej #define PD_MASK 0xfff00000 /* page directory address bits */
48 1.1 thorpej #define PT_MASK 0x000ff000 /* page table address bits */
49 1.1 thorpej
50 1.1 thorpej #define PG_FRAME 0xfffff000
51 1.1 thorpej
52 1.1 thorpej /* The PT_SIZE definition is misleading... A page table is only 0x400
53 1.1 thorpej * bytes long. But since VM mapping can only be done to 0x1000 a single
54 1.1 thorpej * 1KB blocks cannot be steered to a va by itself. Therefore the
55 1.1 thorpej * pages tables are allocated in blocks of 4. i.e. if a 1 KB block
56 1.1 thorpej * was allocated for a PT then the other 3KB would also get mapped
57 1.1 thorpej * whenever the 1KB was mapped.
58 1.1 thorpej */
59 1.1 thorpej
60 1.1 thorpej #define PT_SIZE 0x1000
61 1.1 thorpej #define PD_SIZE 0x4000
62 1.1 thorpej
63 1.1 thorpej /* Access permissions for L1 sections and L2 pages */
64 1.1 thorpej #define AP_KR 0x00
65 1.1 thorpej #define AP_KRW 0x01
66 1.1 thorpej #define AP_KRWUR 0x02
67 1.1 thorpej #define AP_KRWURW 0x03
68 1.1 thorpej
69 1.1 thorpej #define AP_W 0x01
70 1.1 thorpej #define AP_U 0x02
71 1.1 thorpej
72 1.1 thorpej /* Physical bits in a pte */
73 1.1 thorpej #define PT_B 0x04 /* Phys - Buffered (write) */
74 1.1 thorpej #define PT_C 0x08 /* Phys - Cacheable */
75 1.1 thorpej #define PT_U 0x10 /* Phys - Updateable */
76 1.1 thorpej
77 1.1 thorpej #ifndef _LOCORE
78 1.1 thorpej extern pt_entry_t pte_cache_mode;
79 1.1 thorpej
80 1.1 thorpej #define PT_CACHEABLE (pte_cache_mode)
81 1.1 thorpej #endif
82 1.1 thorpej
83 1.1 thorpej /* Page R/M attributes (in pmseg.attrs). */
84 1.1 thorpej #define PT_M 0x01 /* Virt - Modified */
85 1.1 thorpej #define PT_H 0x02 /* Virt - Handled (Used) */
86 1.1 thorpej /* Mapping wired/writeable/cacheable attributes (in pv_flags). */
87 1.1 thorpej #define PT_W 0x04 /* Virt - Wired */
88 1.1 thorpej #define PT_Wr 0x08 /* Virt / Phys Write */
89 1.1 thorpej #define PT_NC 0x10 /* Cacheing disabled (multi-mapped page) */
90 1.1 thorpej
91 1.1 thorpej /* access permissions for L2 pages (all sub pages have the same perms) */
92 1.1 thorpej #define PT_AP(x) ((x << 10) | (x << 8) | (x << 6) | (x << 4))
93 1.1 thorpej
94 1.1 thorpej /* shift for access permissions in a L1 section mapping */
95 1.1 thorpej #define AP_SECTION_SHIFT 10
96 1.1 thorpej
97 1.1 thorpej /* Page table types and masks */
98 1.1 thorpej #define L1_PAGE 0x01 /* L1 page table mapping */
99 1.1 thorpej #define L1_SECTION 0x02 /* L1 section mapping */
100 1.1 thorpej #define L1_FPAGE 0x03 /* L1 fine page mapping */
101 1.1 thorpej #define L1_MASK 0x03 /* Mask for L1 entry type */
102 1.1 thorpej #define L2_LPAGE 0x01 /* L2 large page (64KB) */
103 1.1 thorpej #define L2_SPAGE 0x02 /* L2 small page (4KB) */
104 1.1 thorpej #define L2_MASK 0x03 /* Mask for L2 entry type */
105 1.1 thorpej #define L2_INVAL 0x00 /* L2 invalid type */
106 1.1 thorpej
107 1.1 thorpej /* PTE construction macros */
108 1.1 thorpej #define L2_LPTE(p, a, f) ((p) | PT_AP(a) | L2_LPAGE | (f))
109 1.1 thorpej #define L2_SPTE(p, a, f) ((p) | PT_AP(a) | L2_SPAGE | (f))
110 1.1 thorpej #define L2_PTE(p, a) L2_SPTE((p), (a), PT_CACHEABLE)
111 1.1 thorpej #define L2_PTE_NC(p, a) L2_SPTE((p), (a), PT_B)
112 1.1 thorpej #define L2_PTE_NC_NB(p, a) L2_SPTE((p), (a), 0)
113 1.1 thorpej #define L1_SECPTE(p, a, f) ((p) | ((a) << AP_SECTION_SHIFT) | (f) \
114 1.1 thorpej | L1_SECTION | PT_U)
115 1.1 thorpej
116 1.1 thorpej #define L1_PTE(p) ((p) | 0x00 | L1_PAGE | PT_U)
117 1.1 thorpej #define L1_SEC(p, c) L1_SECPTE((p), AP_KRW, (c))
118 1.1 thorpej
119 1.1 thorpej #define L1_SEC_SIZE (1 << PDSHIFT)
120 1.1 thorpej #define L2_LPAGE_SIZE (NBPG * 16)
121 1.1 thorpej
122 1.1 thorpej /* Domain types */
123 1.1 thorpej #define DOMAIN_FAULT 0x00
124 1.1 thorpej #define DOMAIN_CLIENT 0x01
125 1.1 thorpej #define DOMAIN_RESERVED 0x02
126 1.1 thorpej #define DOMAIN_MANAGER 0x03
127 1.1 thorpej
128 1.1 thorpej #endif
129 1.1 thorpej
130 1.1 thorpej /* End of pte.h */
131