1 /* $NetBSD: pmap.h,v 1.3 2002/03/13 00:47:59 eeh 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 #include <powerpc/ibm4xx/pte.h> 73 #include <powerpc/ibm4xx/tlb.h> 74 75 #define KERNEL_PID 1 /* TLB PID to use for kernel translation */ 76 77 /* 78 * A TTE is a 16KB or greater TLB entry w/size and endiannes bits 79 * stuffed in the (unused) low bits of the PA. 80 */ 81 #define TTE_PA_MASK 0xffffc000 82 #define TTE_RPN_MASK(sz) (~((1 << (10 + 2 * (sz))) - 1)) 83 #define TTE_ENDIAN 0x00002000 84 #define TTE_SZ_MASK 0x00001c00 85 #define TTE_SZ_SHIFT 10 86 87 /* TTE_SZ_1K and TTE_SZ_4K are not allowed. */ 88 #define TTE_SZ_16K (TLB_SIZE_16K << TTE_SZ_SHIFT) 89 #define TTE_SZ_64K (TLB_SIZE_64K << TTE_SZ_SHIFT) 90 #define TTE_SZ_256K (TLB_SIZE_256K << TTE_SZ_SHIFT) 91 #define TTE_SZ_1M (TLB_SIZE_1M << TTE_SZ_SHIFT) 92 #define TTE_SZ_4M (TLB_SIZE_4M << TTE_SZ_SHIFT) 93 #define TTE_SZ_16M (TLB_SIZE_16M << TTE_SZ_SHIFT) 94 95 #define TTE_EX TLB_EX 96 #define TTE_WR TLB_WR 97 #define TTE_ZSEL_MASK TLB_ZSEL_MASK 98 #define TTE_ZSEL_SHFT TLB_ZSEL_SHFT 99 #define TTE_W TLB_W 100 #define TTE_I TLB_I 101 #define TTE_M TLB_M 102 #define TTE_G TLB_G 103 104 #define ZONE_PRIV 0 105 #define ZONE_USER 1 106 107 #define TTE_PA(p) ((p)&TTE_PA_MASK) 108 #define TTE_ZONE(z) TLB_ZONE(z) 109 110 #define MKTTE(pa,sz,zn,e,fl) (((pa)&TTE_PA_MASK)|((sz)&TTE_SZ_MASK)|\ 111 (TTE_ZONE(zn))|(fl)|((e)?TTE_ENDIAN:0) 112 113 /* 114 * Definitions for sizes of 1st and 2nd level page tables. 115 * 116 */ 117 #define PTSZ (NBPG / 4) 118 #define PTMAP (PTSZ * NBPG) 119 #define PTMSK ((PTMAP - 1) & ~(PGOFSET)) 120 121 #define PTIDX(v) (((v) & PTMSK) >> PGSHIFT) 122 123 /* 2nd level tables map in any bits not mapped by 1st level tables. */ 124 #define STSZ ((0xffffffffU / (NBPG * PTSZ)) + 1) 125 #define STMAP (0xffffffffU) 126 #define STMSK (~(PTMAP - 1)) 127 128 #define STIDX(v) ((v) >> (PGSHIFT + 12)) 129 130 131 /* 132 * Extra flags to pass to pmap_enter() -- make sure they don't conflict 133 * w/PMAP_CANFAIL or PMAP_WIRED 134 */ 135 #define PME_NOCACHE 0x100 136 #define PME_WRITETHROUG 0x200 137 138 #ifndef _LOCORE 139 140 /* 141 * Pmap stuff 142 */ 143 struct pmap { 144 volatile tlbpid_t pm_ctx; /* PID to identify PMAP's entries in TLB */ 145 int pm_refs; /* ref count */ 146 struct pmap_statistics pm_stats; /* pmap statistics */ 147 volatile u_int *pm_ptbl[STSZ]; /* Array of 64 pointers to page tables. */ 148 }; 149 150 typedef struct pmap *pmap_t; 151 152 #ifdef _KERNEL 153 #define PMAP_GROWKERNEL 154 extern struct pmap kernel_pmap_; 155 #define pmap_kernel() (&kernel_pmap_) 156 157 #define pmap_clear_modify(pg) (check_attr((pg), PTE_HI_CHG, 1)) 158 #define pmap_clear_reference(pg) (check_attr((pg), PTE_HI_REF, 1)) 159 #define pmap_is_modified(pg) (check_attr((pg), PTE_HI_CHG, 0)) 160 #define pmap_is_referenced(pg) (check_attr((pg), PTE_HI_REF, 0)) 161 162 #define pmap_phys_address(x) (x) 163 164 #define pmap_resident_count(pmap) ((pmap)->pm_stats.resident_count) 165 166 void pmap_unwire(struct pmap *pm, vaddr_t va); 167 void pmap_bootstrap(u_int kernelstart, u_int kernelend); 168 boolean_t pmap_extract(struct pmap *, vaddr_t, paddr_t *); 169 boolean_t check_attr(struct vm_page *, u_int, int); 170 int ptereadonly(struct vm_page *); 171 void pmap_real_memory(paddr_t *, psize_t *); 172 int pmap_tlbmiss(vaddr_t va, int ctx); 173 174 int ctx_alloc(struct pmap*); 175 void ctx_free(struct pmap*); 176 177 #define PMAP_NEED_PROCWR 178 void pmap_procwr(struct proc *, vaddr_t, size_t); 179 180 /* 181 * Alternate mapping hooks for pool pages. Avoids thrashing the TLB. 182 * 183 * Note: This won't work if we have more memory than can be direct-mapped 184 * VA==PA all at once. But pmap_copy_page() and pmap_zero_page() will have 185 * this problem, too. 186 */ 187 #define PMAP_MAP_POOLPAGE(pa) (pa) 188 #define PMAP_UNMAP_POOLPAGE(pa) (pa) 189 190 static __inline paddr_t vtophys(vaddr_t); 191 192 static __inline paddr_t 193 vtophys(vaddr_t va) 194 { 195 paddr_t pa; 196 197 /* XXX should check battable */ 198 199 if (pmap_extract(pmap_kernel(), va, &pa)) 200 return pa; 201 return va; 202 } 203 #endif /* _KERNEL */ 204 #endif /* _LOCORE */ 205 #endif /* _IBM4XX_PMAP_H_ */ 206