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