1 /* $NetBSD: pmap.h,v 1.24 2020/12/20 16:38:25 skrll Exp $ */ 2 /*- 3 * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc. 4 * All rights reserved. 5 * 6 * This code is derived from software contributed to The NetBSD Foundation 7 * by Raytheon BBN Technologies Corp and Defense Advanced Research Projects 8 * Agency and which was developed by Matt Thomas of 3am Software Foundry. 9 * 10 * This material is based upon work supported by the Defense Advanced Research 11 * Projects Agency and Space and Naval Warfare Systems Center, Pacific, under 12 * Contract No. N66001-09-C-2073. 13 * Approved for Public Release, Distribution Unlimited 14 * 15 * Redistribution and use in source and binary forms, with or without 16 * modification, are permitted provided that the following conditions 17 * are met: 18 * 1. Redistributions of source code must retain the above copyright 19 * notice, this list of conditions and the following disclaimer. 20 * 2. Redistributions in binary form must reproduce the above copyright 21 * notice, this list of conditions and the following disclaimer in the 22 * documentation and/or other materials provided with the distribution. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 25 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 26 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 27 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 28 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 * POSSIBILITY OF SUCH DAMAGE. 35 */ 36 37 #ifndef _POWERPC_BOOKE_PMAP_H_ 38 #define _POWERPC_BOOKE_PMAP_H_ 39 40 #ifdef _LOCORE 41 #error use assym.h instead 42 #endif 43 44 #if defined(_MODULE) 45 #error this file should not be included by loadable kernel modules 46 #endif 47 48 #ifdef _KERNEL_OPT 49 #include "opt_multiprocessor.h" 50 #include "opt_pmap.h" 51 #endif 52 53 #include <sys/cpu.h> 54 #include <sys/kcore.h> 55 #include <uvm/uvm_page.h> 56 #include <uvm/uvm_physseg.h> 57 #ifdef __PMAP_PRIVATE 58 #include <powerpc/booke/cpuvar.h> 59 #endif 60 61 #define PMAP_NEED_PROCWR 62 63 #include <uvm/pmap/vmpagemd.h> 64 65 #include <powerpc/booke/pte.h> 66 67 #define NBSEG (NBPG*NPTEPG) 68 #define SEGSHIFT (PGSHIFT + PGSHIFT - 2) 69 #define SEGOFSET ((1 << SEGSHIFT) - 1) 70 #define PMAP_SEGTABSIZE (1 << (32 - SEGSHIFT)) 71 #define NPTEPG (NBPG >> 2) 72 73 #define KERNEL_PID 0 74 75 #define PMAP_TLB_NUM_PIDS 256 76 #define PMAP_TLB_MAX 1 77 #define PMAP_INVALID_SEGTAB_ADDRESS ((pmap_segtab_t *)0xfeeddead) 78 #define PMAP_TLB_FLUSH_ASID_ON_RESET false 79 80 #define pmap_phys_address(x) (x) 81 82 void pmap_procwr(struct proc *, vaddr_t, size_t); 83 #define PMAP_NEED_PROCWR 84 85 #ifdef __PMAP_PRIVATE 86 struct vm_page * 87 pmap_md_alloc_poolpage(int flags); 88 vaddr_t pmap_md_map_poolpage(paddr_t, vsize_t); 89 void pmap_md_unmap_poolpage(vaddr_t, vsize_t); 90 bool pmap_md_direct_mapped_vaddr_p(vaddr_t); 91 bool pmap_md_io_vaddr_p(vaddr_t); 92 paddr_t pmap_md_direct_mapped_vaddr_to_paddr(vaddr_t); 93 vaddr_t pmap_md_direct_map_paddr(paddr_t); 94 void pmap_md_init(void); 95 96 bool pmap_md_tlb_check_entry(void *, vaddr_t, tlb_asid_t, pt_entry_t); 97 98 #ifdef MULTIPROCESSOR 99 #define PMAP_NEED_TLB_MISS_LOCK 100 #endif /* MULTIPROCESSOR */ 101 102 #ifdef PMAP_MINIMALTLB 103 vaddr_t pmap_kvptefill(vaddr_t, vaddr_t, pt_entry_t); 104 #endif 105 #endif 106 107 void pmap_md_page_syncicache(struct vm_page_md *, const kcpuset_t *); 108 vaddr_t pmap_bootstrap(vaddr_t, vaddr_t, phys_ram_seg_t *, size_t); 109 bool pmap_extract(struct pmap *, vaddr_t, paddr_t *); 110 111 static __inline paddr_t vtophys(vaddr_t); 112 113 static __inline paddr_t 114 vtophys(vaddr_t va) 115 { 116 paddr_t pa; 117 118 if (pmap_extract(pmap_kernel(), va, &pa)) 119 return pa; 120 KASSERT(0); 121 return (paddr_t) -1; 122 } 123 124 #ifdef __PMAP_PRIVATE 125 /* 126 * Virtual Cache Alias helper routines. Not a problem for Booke CPUs. 127 */ 128 static __inline bool 129 pmap_md_vca_add(struct vm_page_md *mdpg, vaddr_t va, pt_entry_t *nptep) 130 { 131 return false; 132 } 133 134 static __inline void 135 pmap_md_vca_remove(struct vm_page_md *mdpg, vaddr_t va, bool dirty) 136 { 137 138 } 139 140 static __inline void 141 pmap_md_vca_clean(struct vm_page_md *mdpg, vaddr_t va, int op) 142 { 143 } 144 145 static __inline size_t 146 pmap_md_tlb_asid_max(void) 147 { 148 return PMAP_TLB_NUM_PIDS - 1; 149 } 150 151 struct vm_physseg; 152 static __inline bool 153 pmap_md_ok_to_steal_p(const uvm_physseg_t bank, size_t npgs) 154 { 155 return true; 156 } 157 158 static __inline void 159 pmap_md_xtab_activate(struct pmap *pm, struct lwp *l) 160 { 161 162 /* nothing */ 163 } 164 165 static __inline void 166 pmap_md_xtab_deactivate(struct pmap *pm) 167 { 168 169 /* nothing */ 170 } 171 172 #endif 173 174 #define POOL_VTOPHYS(va) ((paddr_t)(vaddr_t)(va)) 175 #define POOL_PHYSTOV(pa) ((vaddr_t)(paddr_t)(pa)) 176 177 #include <uvm/pmap/pmap.h> 178 179 #endif /* !_POWERPC_BOOKE_PMAP_H_ */ 180