1 /* $NetBSD: pmap.h,v 1.14 2008/12/09 20:45:45 pooka 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 #ifdef _KERNEL 148 #define PMAP_GROWKERNEL 149 150 #define PMAP_ATTR_REF 0x1 151 #define PMAP_ATTR_CHG 0x2 152 153 #define pmap_clear_modify(pg) (pmap_check_attr((pg), PMAP_ATTR_CHG, 1)) 154 #define pmap_clear_reference(pg)(pmap_check_attr((pg), PMAP_ATTR_REF, 1)) 155 #define pmap_is_modified(pg) (pmap_check_attr((pg), PMAP_ATTR_CHG, 0)) 156 #define pmap_is_referenced(pg) (pmap_check_attr((pg), PMAP_ATTR_REF, 0)) 157 158 #define pmap_phys_address(x) (x) 159 160 #define pmap_resident_count(pmap) ((pmap)->pm_stats.resident_count) 161 #define pmap_wired_count(pmap) ((pmap)->pm_stats.wired_count) 162 163 void pmap_unwire(struct pmap *pm, vaddr_t va); 164 void pmap_bootstrap(u_int kernelstart, u_int kernelend); 165 bool pmap_extract(struct pmap *, vaddr_t, paddr_t *); 166 bool pmap_check_attr(struct vm_page *, u_int, int); 167 void pmap_real_memory(paddr_t *, psize_t *); 168 int pmap_tlbmiss(vaddr_t va, int ctx); 169 170 static inline void 171 pmap_remove_all(struct pmap *pmap) 172 { 173 /* Nothing. */ 174 } 175 176 int ctx_alloc(struct pmap *); 177 void ctx_free(struct pmap *); 178 179 #define PMAP_NEED_PROCWR 180 void pmap_procwr(struct proc *, vaddr_t, size_t); 181 182 /* 183 * Alternate mapping hooks for pool pages. Avoids thrashing the TLB. 184 * 185 * Note: This won't work if we have more memory than can be direct-mapped 186 * VA==PA all at once. But pmap_copy_page() and pmap_zero_page() will have 187 * this problem, too. 188 */ 189 #define PMAP_MAP_POOLPAGE(pa) (pa) 190 #define PMAP_UNMAP_POOLPAGE(pa) (pa) 191 192 static inline paddr_t vtophys(vaddr_t); 193 194 static inline paddr_t 195 vtophys(vaddr_t va) 196 { 197 paddr_t pa; 198 199 /* XXX should check battable */ 200 201 if (pmap_extract(pmap_kernel(), va, &pa)) 202 return pa; 203 return va; 204 } 205 #endif /* _KERNEL */ 206 #endif /* _LOCORE */ 207 #endif /* _IBM4XX_PMAP_H_ */ 208