1 /* $NetBSD: pmap.h,v 1.21 2020/03/14 14:05:43 ad Exp $ */
2
3 /*
4 * Copyright 2001 Wasabi Systems, Inc.
5 * All rights reserved.
6 *
7 * Written by Eduardo Horvath and Simon Burge for Wasabi Systems, Inc.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed for the NetBSD Project by
20 * Wasabi Systems, Inc.
21 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 * or promote products derived from this software without specific prior
23 * written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 */
37
38 /*-
39 * Copyright (C) 1995, 1996 Wolfgang Solfrank.
40 * Copyright (C) 1995, 1996 TooLs GmbH.
41 * All rights reserved.
42 *
43 * Redistribution and use in source and binary forms, with or without
44 * modification, are permitted provided that the following conditions
45 * are met:
46 * 1. Redistributions of source code must retain the above copyright
47 * notice, this list of conditions and the following disclaimer.
48 * 2. Redistributions in binary form must reproduce the above copyright
49 * notice, this list of conditions and the following disclaimer in the
50 * documentation and/or other materials provided with the distribution.
51 * 3. All advertising materials mentioning features or use of this software
52 * must display the following acknowledgement:
53 * This product includes software developed by TooLs GmbH.
54 * 4. The name of TooLs GmbH may not be used to endorse or promote products
55 * derived from this software without specific prior written permission.
56 *
57 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
58 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
59 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
60 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
61 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
62 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
63 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
64 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
65 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
66 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
67 */
68
69 #ifndef _IBM4XX_PMAP_H_
70 #define _IBM4XX_PMAP_H_
71
72 #ifdef _LOCORE
73 #error use assym.h instead
74 #endif
75
76 #if defined(_MODULE)
77 #error this file should not be included by loadable kernel modules
78 #endif
79
80 #include <powerpc/ibm4xx/tlb.h>
81
82 #define KERNEL_PID 1 /* TLB PID to use for kernel translation */
83
84 /*
85 * A TTE is a 16KB or greater TLB entry w/size and endianness bits
86 * stuffed in the (unused) low bits of the PA.
87 */
88 #define TTE_PA_MASK 0xffffc000
89 #define TTE_RPN_MASK(sz) (~((1 << (10 + 2 * (sz))) - 1))
90 #define TTE_ENDIAN 0x00002000
91 #define TTE_SZ_MASK 0x00001c00
92 #define TTE_SZ_SHIFT 10
93
94 /* TTE_SZ_1K and TTE_SZ_4K are not allowed. */
95 #define TTE_SZ_16K (TLB_SIZE_16K << TTE_SZ_SHIFT)
96 #define TTE_SZ_64K (TLB_SIZE_64K << TTE_SZ_SHIFT)
97 #define TTE_SZ_256K (TLB_SIZE_256K << TTE_SZ_SHIFT)
98 #define TTE_SZ_1M (TLB_SIZE_1M << TTE_SZ_SHIFT)
99 #define TTE_SZ_4M (TLB_SIZE_4M << TTE_SZ_SHIFT)
100 #define TTE_SZ_16M (TLB_SIZE_16M << TTE_SZ_SHIFT)
101
102 #define TTE_EX TLB_EX
103 #define TTE_WR TLB_WR
104 #define TTE_ZSEL_MASK TLB_ZSEL_MASK
105 #define TTE_ZSEL_SHFT TLB_ZSEL_SHFT
106 #define TTE_W TLB_W
107 #define TTE_I TLB_I
108 #define TTE_M TLB_M
109 #define TTE_G TLB_G
110
111 #define ZONE_PRIV 0
112 #define ZONE_USER 1
113
114 #define TTE_PA(p) ((p)&TTE_PA_MASK)
115 #define TTE_ZONE(z) TLB_ZONE(z)
116
117 /*
118 * Definitions for sizes of 1st and 2nd level page tables.
119 *
120 */
121 #define PTSZ (PAGE_SIZE / 4)
122 #define PTMAP (PTSZ * PAGE_SIZE)
123 #define PTMSK ((PTMAP - 1) & ~(PGOFSET))
124
125 #define PTIDX(v) (((v) & PTMSK) >> PGSHIFT)
126
127 /* 2nd level tables map in any bits not mapped by 1st level tables. */
128 #define STSZ ((0xffffffffU / (PAGE_SIZE * PTSZ)) + 1)
129 #define STMAP (0xffffffffU)
130 #define STMSK (~(PTMAP - 1))
131
132 #define STIDX(v) ((v) >> (PGSHIFT + 12))
133
134
135 /*
136 * Extra flags to pass to pmap_enter() -- make sure they don't conflict
137 * w/PMAP_CANFAIL or PMAP_WIRED
138 */
139 #define PME_NOCACHE 0x1000000
140 #define PME_WRITETHROUG 0x2000000
141
142 /*
143 * Pmap stuff
144 */
145 struct pmap {
146 volatile int pm_ctx; /* PID to identify PMAP's entries in TLB */
147 int pm_refs; /* ref count */
148 struct pmap_statistics pm_stats; /* pmap statistics */
149 volatile u_int *pm_ptbl[STSZ]; /* Array of 64 pointers to page tables. */
150 };
151
152 #ifdef _KERNEL
153 #define PMAP_GROWKERNEL
154
155 #define PMAP_ATTR_REF 0x1
156 #define PMAP_ATTR_CHG 0x2
157
158 #define pmap_clear_modify(pg) (pmap_check_attr((pg), PMAP_ATTR_CHG, 1))
159 #define pmap_clear_reference(pg)(pmap_check_attr((pg), PMAP_ATTR_REF, 1))
160 #define pmap_is_modified(pg) (pmap_check_attr((pg), PMAP_ATTR_CHG, 0))
161 #define pmap_is_referenced(pg) (pmap_check_attr((pg), PMAP_ATTR_REF, 0))
162
163 #define pmap_phys_address(x) (x)
164
165 #define pmap_resident_count(pmap) ((pmap)->pm_stats.resident_count)
166 #define pmap_wired_count(pmap) ((pmap)->pm_stats.wired_count)
167
168 void pmap_unwire(struct pmap *pm, vaddr_t va);
169 void pmap_bootstrap(u_int kernelstart, u_int kernelend);
170 bool pmap_extract(struct pmap *, vaddr_t, paddr_t *);
171 bool pmap_check_attr(struct vm_page *, u_int, int);
172 void pmap_real_memory(paddr_t *, psize_t *);
173 int pmap_tlbmiss(vaddr_t va, int ctx);
174
175 static __inline bool
pmap_remove_all(struct pmap * pmap)176 pmap_remove_all(struct pmap *pmap)
177 {
178 /* Nothing. */
179 return false;
180 }
181
182 int ctx_alloc(struct pmap *);
183 void ctx_free(struct pmap *);
184
185 #define PMAP_NEED_PROCWR
186 void pmap_procwr(struct proc *, vaddr_t, size_t);
187
188 /*
189 * Alternate mapping hooks for pool pages. Avoids thrashing the TLB.
190 *
191 * Note: This won't work if we have more memory than can be direct-mapped
192 * VA==PA all at once. But pmap_copy_page() and pmap_zero_page() will have
193 * this problem, too.
194 */
195 #define PMAP_MAP_POOLPAGE(pa) (pa)
196 #define PMAP_UNMAP_POOLPAGE(pa) (pa)
197
198 static __inline paddr_t vtophys(vaddr_t);
199
200 static __inline paddr_t
vtophys(vaddr_t va)201 vtophys(vaddr_t va)
202 {
203 paddr_t pa;
204
205 /* XXX should check battable */
206
207 if (pmap_extract(pmap_kernel(), va, &pa))
208 return pa;
209 return va;
210 }
211 #endif /* _KERNEL */
212 #endif /* _IBM4XX_PMAP_H_ */
213