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