1 /* $OpenBSD: pmap.h,v 1.16 2001/07/18 19:36:57 mickey Exp $ */ 2 /* $NetBSD: pmap.h,v 1.1 1996/09/30 16:34:29 ws Exp $ */ 3 4 /*- 5 * Copyright (C) 1995, 1996 Wolfgang Solfrank. 6 * Copyright (C) 1995, 1996 TooLs GmbH. 7 * All rights reserved. 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 by TooLs GmbH. 20 * 4. The name of TooLs GmbH may not be used to endorse or promote products 21 * derived from this software without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR 24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 28 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 29 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 30 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 31 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 32 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 */ 34 35 #ifndef _MACHINE_PMAP_H_ 36 #define _MACHINE_PMAP_H_ 37 38 #include <machine/pte.h> 39 40 /* 41 * Segment registers 42 */ 43 #ifndef _LOCORE 44 typedef u_int sr_t; 45 #endif /* _LOCORE */ 46 #define SR_TYPE 0x80000000 47 #define SR_SUKEY 0x40000000 48 #define SR_PRKEY 0x20000000 49 #define SR_VSID 0x00ffffff 50 51 #ifndef _LOCORE 52 /* V->P mapping data */ 53 typedef int pmapv_t; 54 #define VP_SR_SIZE 32 55 #define VP_SR_MASK (VP_SR_SIZE-1) 56 #define VP_SR_POS 27 57 #define VP_IDX1_SIZE 1024 58 #define VP_IDX1_MASK (VP_IDX1_SIZE-1) 59 #define VP_IDX1_POS 17 60 #define VP_IDX2_SIZE 32 61 #define VP_IDX2_MASK (VP_IDX2_SIZE-1) 62 #define VP_IDX2_POS 12 63 64 /* 65 * Pmap stuff 66 */ 67 struct pmap { 68 sr_t pm_sr[16]; /* segments used in this pmap */ 69 int pm_refs; /* ref count */ 70 pmapv_t *vps[VP_SR_SIZE]; /* virtual to physical table */ 71 struct pmap_statistics pm_stats; /* pmap statistics */ 72 }; 73 74 typedef struct pmap *pmap_t; 75 boolean_t ptemodify(paddr_t pa, u_int mask, u_int val); 76 77 #ifdef _KERNEL 78 extern struct pmap kernel_pmap_; 79 #define pmap_kernel() (&kernel_pmap_) 80 int ptebits(paddr_t pa, int bit); 81 82 83 #define pmap_clear_modify(page) (ptemodify(VM_PAGE_TO_PHYS(page), PTE_CHG, 0)) 84 #define pmap_clear_reference(page) (ptemodify(VM_PAGE_TO_PHYS(page), PTE_REF, 0)) 85 #define pmap_is_modified(page) (ptebits(VM_PAGE_TO_PHYS(page), PTE_CHG)) 86 #define pmap_is_referenced(page) (ptebits(VM_PAGE_TO_PHYS(page), PTE_REF)) 87 #define pmap_unwire(pm, va) 88 #define pmap_phys_address(x) (x) 89 90 #define pmap_resident_count(pmap) ((pmap)->pm_stats.resident_count) 91 92 /* 93 * Alternate mapping methods for pool. 94 * Really simple. 0x0->0x80000000 contain 1->1 mappings of the physical 95 * memory. 96 */ 97 #define PMAP_MAP_POOLPAGE(pa) ((vaddr_t)pa) 98 #define PMAP_UNMAP_POOLPAGE(va) ((paddr_t)va) 99 100 void pmap_bootstrap __P((u_int kernelstart, u_int kernelend)); 101 102 void pmap_deactivate __P((struct proc *p)); 103 void pmap_activate __P((struct proc *p)); 104 void pmap_real_memory __P((vm_offset_t *start, vm_size_t *size)); 105 void switchexit __P((struct proc *)); 106 107 paddr_t vtophys __P((vaddr_t)); 108 109 #endif /* _KERNEL */ 110 #endif /* _LOCORE */ 111 #endif /* _MACHINE_PMAP_H_ */ 112