1 1.1 cherry /*- 2 1.1 cherry * Copyright (c) 1998, 1999, 2000, 2001 The NetBSD Foundation, Inc. 3 1.1 cherry * All rights reserved. 4 1.1 cherry * 5 1.1 cherry * This code is derived from software contributed to The NetBSD Foundation 6 1.1 cherry * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 7 1.1 cherry * NASA Ames Research Center and by Chris G. Demetriou. 8 1.1 cherry * 9 1.1 cherry * Redistribution and use in source and binary forms, with or without 10 1.1 cherry * modification, are permitted provided that the following conditions 11 1.1 cherry * are met: 12 1.1 cherry * 1. Redistributions of source code must retain the above copyright 13 1.1 cherry * notice, this list of conditions and the following disclaimer. 14 1.1 cherry * 2. Redistributions in binary form must reproduce the above copyright 15 1.1 cherry * notice, this list of conditions and the following disclaimer in the 16 1.1 cherry * documentation and/or other materials provided with the distribution. 17 1.1 cherry * 18 1.1 cherry * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19 1.1 cherry * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 1.1 cherry * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 1.1 cherry * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 1.1 cherry * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 1.1 cherry * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 1.1 cherry * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 1.1 cherry * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 1.1 cherry * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 1.1 cherry * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 1.1 cherry * POSSIBILITY OF SUCH DAMAGE. 29 1.1 cherry */ 30 1.1 cherry 31 1.1 cherry /*- 32 1.1 cherry * Copyright (c) 1991 Regents of the University of California. 33 1.1 cherry * All rights reserved. 34 1.1 cherry * 35 1.1 cherry * This code is derived from software contributed to Berkeley by 36 1.1 cherry * the Systems Programming Group of the University of Utah Computer 37 1.1 cherry * Science Department and William Jolitz of UUNET Technologies Inc. 38 1.1 cherry * 39 1.1 cherry * Redistribution and use in source and binary forms, with or without 40 1.1 cherry * modification, are permitted provided that the following conditions 41 1.1 cherry * are met: 42 1.1 cherry * 1. Redistributions of source code must retain the above copyright 43 1.1 cherry * notice, this list of conditions and the following disclaimer. 44 1.1 cherry * 2. Redistributions in binary form must reproduce the above copyright 45 1.1 cherry * notice, this list of conditions and the following disclaimer in the 46 1.1 cherry * documentation and/or other materials provided with the distribution. 47 1.1 cherry * 4. Neither the name of the University nor the names of its contributors 48 1.1 cherry * may be used to endorse or promote products derived from this software 49 1.1 cherry * without specific prior written permission. 50 1.1 cherry * 51 1.1 cherry * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 52 1.1 cherry * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 53 1.1 cherry * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 54 1.1 cherry * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 55 1.1 cherry * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 56 1.1 cherry * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 57 1.1 cherry * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 58 1.1 cherry * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 59 1.1 cherry * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 60 1.1 cherry * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 61 1.1 cherry * SUCH DAMAGE. 62 1.1 cherry * 63 1.1 cherry * Derived from hp300 version by Mike Hibler, this version by William 64 1.1 cherry * Jolitz uses a recursive map [a pde points to the page directory] to 65 1.1 cherry * map the page tables using the pagetables themselves. This is done to 66 1.1 cherry * reduce the impact on kernel virtual memory for lots of sparse address 67 1.1 cherry * space, and to reduce the cost of memory to each process. 68 1.1 cherry * 69 1.1 cherry * from: hp300: @(#)pmap.h 7.2 (Berkeley) 12/16/90 70 1.1 cherry * from: @(#)pmap.h 7.4 (Berkeley) 5/12/91 71 1.1 cherry * from: i386 pmap.h,v 1.54 1997/11/20 19:30:35 bde Exp 72 1.8 scole * $FreeBSD: releng/10.1/sys/ia64/include/pmap.h 268201 2014-07-02 23:57:55Z marcel $ 73 1.1 cherry */ 74 1.1 cherry 75 1.8 scole #ifndef _IA64_PMAP_H_ 76 1.8 scole #define _IA64_PMAP_H_ 77 1.1 cherry 78 1.8 scole #include <sys/types.h> 79 1.8 scole #include <sys/queue.h> 80 1.2 cherry #include <sys/lock.h> 81 1.8 scole #include <sys/mutex.h> 82 1.8 scole 83 1.8 scole #include <machine/pte.h> 84 1.8 scole #include <machine/vmparam.h> 85 1.8 scole 86 1.8 scole #include <machine/md_var.h> 87 1.8 scole 88 1.8 scole typedef char vm_memattr_t; 89 1.2 cherry 90 1.8 scole #define VM_MEMATTR_WRITE_BACK ((vm_memattr_t)PTE_MA_WB) 91 1.8 scole #define VM_MEMATTR_UNCACHEABLE ((vm_memattr_t)PTE_MA_UC) 92 1.8 scole #define VM_MEMATTR_UNCACHEABLE_EXPORTED ((vm_memattr_t)PTE_MA_UCE) 93 1.8 scole #define VM_MEMATTR_WRITE_COMBINING ((vm_memattr_t)PTE_MA_WC) 94 1.8 scole #define VM_MEMATTR_NATPAGE ((vm_memattr_t)PTE_MA_NATPAGE) 95 1.8 scole #define VM_MEMATTR_DEFAULT VM_MEMATTR_WRITE_BACK 96 1.1 cherry 97 1.8 scole #ifdef _KERNEL 98 1.8 scole 99 1.8 scole #define MAXKPT (PAGE_SIZE/sizeof(vaddr_t)) 100 1.8 scole 101 1.8 scole #define vtophys(va) pmap_kextract((vaddr_t)(va)) 102 1.8 scole 103 1.8 scole #endif /* _KERNEL */ 104 1.8 scole 105 1.8 scole /* 106 1.8 scole * Pmap stuff 107 1.8 scole */ 108 1.8 scole struct pv_entry; 109 1.8 scole struct pv_chunk; 110 1.1 cherry 111 1.1 cherry struct pmap { 112 1.8 scole kmutex_t pm_mtx; 113 1.8 scole TAILQ_HEAD(,pv_chunk) pm_pvchunk; /* list of mappings in pmap */ 114 1.8 scole uint32_t pm_rid[IA64_VM_MINKERN_REGION]; 115 1.1 cherry struct pmap_statistics pm_stats; /* pmap statistics */ 116 1.8 scole uint64_t pm_refcount; /* pmap reference count, atomic */ 117 1.8 scole }; 118 1.8 scole 119 1.8 scole typedef struct pmap *pmap_t; 120 1.1 cherry 121 1.8 scole #ifdef _KERNEL 122 1.8 scole 123 1.8 scole #define PMAP_LOCK(pmap) mutex_enter(&(pmap)->pm_mtx) 124 1.8 scole #define PMAP_LOCK_ASSERT(pmap) KASSERT(mutex_owned(&(pmap)->pm_mtx)) 125 1.8 scole #define PMAP_LOCK_DESTROY(pmap) mutex_destroy(&(pmap)->pm_mtx) 126 1.8 scole #define PMAP_LOCK_INIT(pmap) mutex_init(&(pmap)->pm_mtx, MUTEX_DEFAULT, IPL_NONE) 127 1.8 scole #define PMAP_LOCKED(pmap) mutex_owned(&(pmap)->pm_mtx) 128 1.8 scole #define PMAP_MTX(pmap) (&(pmap)->pm_mtx) 129 1.8 scole #define PMAP_TRYLOCK(pmap) mutex_tryenter(&(pmap)->pm_mtx) 130 1.8 scole #define PMAP_UNLOCK(pmap) mutex_exit(&(pmap)->pm_mtx) 131 1.8 scole 132 1.8 scole #endif 133 1.1 cherry 134 1.1 cherry /* 135 1.1 cherry * For each vm_page_t, there is a list of all currently valid virtual 136 1.8 scole * mappings of that page. An entry is a pv_entry_t, the list is pv_list. 137 1.1 cherry */ 138 1.1 cherry typedef struct pv_entry { 139 1.8 scole vaddr_t pv_va; /* virtual address for mapping */ 140 1.1 cherry TAILQ_ENTRY(pv_entry) pv_list; 141 1.1 cherry } *pv_entry_t; 142 1.1 cherry 143 1.1 cherry void pmap_bootstrap(void); 144 1.1 cherry 145 1.8 scole /* optional pmap API functions, according to pmap(9) */ 146 1.8 scole #define PMAP_STEAL_MEMORY 147 1.8 scole #define PMAP_GROWKERNEL 148 1.1 cherry 149 1.8 scole #define PMAP_NEED_PROCWR 150 1.8 scole void pmap_procwr(struct proc *, vaddr_t, vsize_t); 151 1.1 cherry 152 1.1 cherry /* 153 1.1 cherry * Alternate mapping hooks for pool pages. Avoids thrashing the TLB. 154 1.1 cherry */ 155 1.8 scole /* XXX 156 1.1 cherry #define PMAP_MAP_POOLPAGE(pa) IA64_PHYS_TO_RR7((pa)) 157 1.1 cherry #define PMAP_UNMAP_POOLPAGE(va) IA64_RR_MASK((va)) 158 1.8 scole */ 159 1.1 cherry 160 1.1 cherry /* 161 1.1 cherry * Macros for locking pmap structures. 162 1.1 cherry * 163 1.1 cherry * Note that we if we access the kernel pmap in interrupt context, it 164 1.1 cherry * is only to update statistics. Since stats are updated using atomic 165 1.1 cherry * operations, locking the kernel pmap is not necessary. Therefore, 166 1.10 msaitoh * it is not necessary to block interrupts when locking pmap structures. 167 1.1 cherry */ 168 1.8 scole /* XXX 169 1.3 kochi #define PMAP_LOCK(pmap) mutex_enter(&(pmap)->pm_slock) 170 1.3 kochi #define PMAP_UNLOCK(pmap) mutex_exit(&(pmap)->pm_slock) 171 1.8 scole */ 172 1.1 cherry 173 1.7 uebayasi /* 174 1.7 uebayasi * pmap-specific data store in the vm_page structure. 175 1.7 uebayasi */ 176 1.7 uebayasi #define __HAVE_VM_PAGE_MD 177 1.8 scole 178 1.7 uebayasi struct vm_page_md { 179 1.8 scole TAILQ_HEAD(,pv_entry) pv_list; 180 1.8 scole vm_memattr_t memattr; 181 1.9 skrll #if 0 /* XXX freebsd */ 182 1.8 scole uint8_t pv_flags; 183 1.8 scole uint8_t aflags; 184 1.9 skrll #endif 185 1.7 uebayasi }; 186 1.7 uebayasi 187 1.7 uebayasi #define VM_MDPAGE_INIT(pg) \ 188 1.7 uebayasi do { \ 189 1.7 uebayasi TAILQ_INIT(&(pg)->mdpage.pv_list); \ 190 1.8 scole (pg)->mdpage.memattr = VM_MEMATTR_DEFAULT; \ 191 1.7 uebayasi } while (/*CONSTCOND*/0) 192 1.7 uebayasi 193 1.8 scole #ifdef _KERNEL 194 1.8 scole 195 1.8 scole extern uint64_t pmap_vhpt_base[]; 196 1.8 scole extern uint64_t pmap_vhpt_log2size; 197 1.8 scole 198 1.8 scole vaddr_t pmap_page_to_va(struct vm_page*); 199 1.8 scole 200 1.8 scole /* Machine-architecture private */ 201 1.8 scole vaddr_t pmap_alloc_vhpt(void); 202 1.8 scole void pmap_bootstrap(void); 203 1.8 scole void pmap_invalidate_all(void); 204 1.8 scole paddr_t pmap_kextract(vaddr_t va); 205 1.8 scole struct pmap *pmap_switch(struct pmap *pmap); 206 1.8 scole void pmap_remove_all_phys(struct vm_page*); /* used in only pmap_page_protect */ 207 1.8 scole 208 1.8 scole #endif /* _KERNEL */ 209 1.8 scole 210 1.8 scole #endif /* _IA64_PMAP_H_ */ 211