1 /* $NetBSD: pmap.h,v 1.9 2004/08/31 01:06:12 simonb 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 /* 111 * Definitions for sizes of 1st and 2nd level page tables. 112 * 113 */ 114 #define PTSZ (PAGE_SIZE / 4) 115 #define PTMAP (PTSZ * PAGE_SIZE) 116 #define PTMSK ((PTMAP - 1) & ~(PGOFSET)) 117 118 #define PTIDX(v) (((v) & PTMSK) >> PGSHIFT) 119 120 /* 2nd level tables map in any bits not mapped by 1st level tables. */ 121 #define STSZ ((0xffffffffU / (PAGE_SIZE * PTSZ)) + 1) 122 #define STMAP (0xffffffffU) 123 #define STMSK (~(PTMAP - 1)) 124 125 #define STIDX(v) ((v) >> (PGSHIFT + 12)) 126 127 128 /* 129 * Extra flags to pass to pmap_enter() -- make sure they don't conflict 130 * w/PMAP_CANFAIL or PMAP_WIRED 131 */ 132 #define PME_NOCACHE 0x100 133 #define PME_WRITETHROUG 0x200 134 #define PMAP_NC PME_NOCACHE /* XXX: OEA pmap compat. for bus_dma */ 135 136 #ifndef _LOCORE 137 138 /* 139 * Pmap stuff 140 */ 141 struct pmap { 142 volatile tlbpid_t pm_ctx; /* PID to identify PMAP's entries in TLB */ 143 int pm_refs; /* ref count */ 144 struct pmap_statistics pm_stats; /* pmap statistics */ 145 volatile u_int *pm_ptbl[STSZ]; /* Array of 64 pointers to page tables. */ 146 }; 147 148 typedef struct pmap *pmap_t; 149 150 #ifdef _KERNEL 151 #define PMAP_GROWKERNEL 152 extern struct pmap kernel_pmap_; 153 #define pmap_kernel() (&kernel_pmap_) 154 155 #define pmap_clear_modify(pg) (check_attr((pg), PTE_HI_CHG, 1)) 156 #define pmap_clear_reference(pg) (check_attr((pg), PTE_HI_REF, 1)) 157 #define pmap_is_modified(pg) (check_attr((pg), PTE_HI_CHG, 0)) 158 #define pmap_is_referenced(pg) (check_attr((pg), PTE_HI_REF, 0)) 159 160 #define pmap_phys_address(x) (x) 161 162 #define pmap_resident_count(pmap) ((pmap)->pm_stats.resident_count) 163 164 void pmap_unwire(struct pmap *pm, vaddr_t va); 165 void pmap_bootstrap(u_int kernelstart, u_int kernelend); 166 boolean_t pmap_extract(struct pmap *, vaddr_t, paddr_t *); 167 boolean_t check_attr(struct vm_page *, u_int, int); 168 void pmap_real_memory(paddr_t *, psize_t *); 169 int pmap_tlbmiss(vaddr_t va, int ctx); 170 171 static __inline void 172 pmap_remove_all(struct pmap *pmap) 173 { 174 /* Nothing. */ 175 } 176 177 int ctx_alloc(struct pmap*); 178 void ctx_free(struct pmap*); 179 180 #define PMAP_NEED_PROCWR 181 void pmap_procwr(struct proc *, vaddr_t, size_t); 182 183 /* 184 * Alternate mapping hooks for pool pages. Avoids thrashing the TLB. 185 * 186 * Note: This won't work if we have more memory than can be direct-mapped 187 * VA==PA all at once. But pmap_copy_page() and pmap_zero_page() will have 188 * this problem, too. 189 */ 190 #define PMAP_MAP_POOLPAGE(pa) (pa) 191 #define PMAP_UNMAP_POOLPAGE(pa) (pa) 192 193 static __inline paddr_t vtophys(vaddr_t); 194 195 static __inline paddr_t 196 vtophys(vaddr_t va) 197 { 198 paddr_t pa; 199 200 /* XXX should check battable */ 201 202 if (pmap_extract(pmap_kernel(), va, &pa)) 203 return pa; 204 return va; 205 } 206 #endif /* _KERNEL */ 207 #endif /* _LOCORE */ 208 #endif /* _IBM4XX_PMAP_H_ */ 209