1 /* $NetBSD: pmap_tlb.h,v 1.15 2020/08/19 06:11:49 skrll Exp $ */ 2 3 /* 4 * Copyright (c) 1992, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * Ralph Campbell. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. Neither the name of the University nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * @(#)pmap.h 8.1 (Berkeley) 6/10/93 35 */ 36 37 /* 38 * Copyright (c) 1987 Carnegie-Mellon University 39 * 40 * This code is derived from software contributed to Berkeley by 41 * Ralph Campbell. 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 the University of 54 * California, Berkeley and its contributors. 55 * 4. Neither the name of the University nor the names of its contributors 56 * may be used to endorse or promote products derived from this software 57 * without specific prior written permission. 58 * 59 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 60 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 61 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 62 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 63 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 64 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 65 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 66 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 67 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 68 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 69 * SUCH DAMAGE. 70 * 71 * @(#)pmap.h 8.1 (Berkeley) 6/10/93 72 */ 73 74 #ifndef _UVM_PMAP_PMAP_TLB_H_ 75 #define _UVM_PMAP_PMAP_TLB_H_ 76 77 #include <sys/evcnt.h> 78 #include <sys/kcpuset.h> 79 #include <sys/bitops.h> 80 81 #if !defined(PMAP_TLB_MAX) 82 # if defined(MULTIPROCESSOR) 83 # define PMAP_TLB_MAX MAXCPUS 84 # else 85 # define PMAP_TLB_MAX 1 86 # endif 87 #endif 88 89 /* 90 * Per TLB (normally same as CPU) asid info 91 */ 92 struct pmap_asid_info { 93 LIST_ENTRY(pmap_asid_info) pai_link; 94 uint32_t pai_asid; /* TLB address space tag */ 95 }; 96 97 #define TLBINFO_LOCK(ti) mutex_spin_enter((ti)->ti_lock) 98 #define TLBINFO_UNLOCK(ti) mutex_spin_exit((ti)->ti_lock) 99 #define TLBINFO_OWNED(ti) mutex_owned((ti)->ti_lock) 100 #define PMAP_PAI_ASIDVALID_P(pai, ti) ((pai)->pai_asid != 0) 101 #define PMAP_PAI(pmap, ti) (&(pmap)->pm_pai[tlbinfo_index(ti)]) 102 #define PAI_PMAP(pai, ti) \ 103 ((pmap_t)((intptr_t)(pai) \ 104 - offsetof(struct pmap, pm_pai[tlbinfo_index(ti)]))) 105 106 enum tlb_invalidate_op { 107 TLBINV_NOBODY = 0, 108 TLBINV_ONE = 1, 109 TLBINV_ALLUSER = 2, 110 TLBINV_ALLKERNEL = 3, 111 TLBINV_ALL = 4 112 }; 113 114 struct pmap_tlb_info { 115 char ti_name[8]; 116 uint32_t ti_asids_free; /* # of ASIDs free */ 117 #define tlbinfo_noasids_p(ti) ((ti)->ti_asids_free == 0) 118 kmutex_t *ti_lock; 119 u_int ti_wired; /* # of wired TLB entries */ 120 tlb_asid_t ti_asid_hint; /* probable next ASID to use */ 121 tlb_asid_t ti_asid_max; 122 LIST_HEAD(, pmap_asid_info) ti_pais; /* list of active ASIDs */ 123 #ifdef MULTIPROCESSOR 124 pmap_t ti_victim; 125 uint32_t ti_synci_page_bitmap; /* page indices needing a syncicache */ 126 #if PMAP_TLB_MAX > 1 127 kcpuset_t *ti_kcpuset; /* bitmask of CPUs sharing this TLB */ 128 u_int ti_index; 129 enum tlb_invalidate_op ti_tlbinvop; 130 #define tlbinfo_index(ti) ((ti)->ti_index) 131 #else 132 #define tlbinfo_index(ti) ((void)(ti), 0) 133 #endif 134 #if !defined(PMAP_TLB_NO_SYNCI_EVCNT) 135 struct evcnt ti_evcnt_synci_asts; 136 struct evcnt ti_evcnt_synci_all; 137 struct evcnt ti_evcnt_synci_pages; 138 struct evcnt ti_evcnt_synci_deferred; 139 struct evcnt ti_evcnt_synci_desired; 140 struct evcnt ti_evcnt_synci_duplicate; 141 #endif /* !PMAP_TLB_NO_SYNCI_EVCNT */ 142 #else 143 #define tlbinfo_index(ti) ((void)(ti), 0) 144 #endif 145 struct evcnt ti_evcnt_asid_reinits; 146 #ifndef PMAP_TLB_BITMAP_LENGTH 147 #define PMAP_TLB_BITMAP_LENGTH 256 148 #endif 149 __BITMAP_TYPE(, u_long, PMAP_TLB_BITMAP_LENGTH) ti_asid_bitmap; 150 }; 151 152 #ifdef _KERNEL 153 extern struct pmap_tlb_info pmap_tlb0_info; 154 #ifdef MULTIPROCESSOR 155 extern struct pmap_tlb_info *pmap_tlbs[PMAP_TLB_MAX]; 156 extern u_int pmap_ntlbs; 157 #endif 158 159 #ifndef cpu_set_tlb_info 160 # define cpu_set_tlb_info(ci, ti) ((void)((ci)->ci_tlb_info = (ti))) 161 #endif 162 #ifndef cpu_tlb_info 163 # if PMAP_TLB_MAX > 1 164 # define cpu_tlb_info(ci) ((ci)->ci_tlb_info) 165 # else 166 # define cpu_tlb_info(ci) (&pmap_tlb0_info) 167 # endif 168 #endif 169 170 #ifdef MULTIPROCESSOR 171 void pmap_tlb_shootdown_process(void); 172 bool pmap_tlb_shootdown_bystanders(pmap_t pmap); 173 void pmap_tlb_info_attach(struct pmap_tlb_info *, struct cpu_info *); 174 void pmap_md_tlb_info_attach(struct pmap_tlb_info *, struct cpu_info *); 175 #endif 176 void pmap_tlb_info_init(struct pmap_tlb_info *); 177 void pmap_tlb_info_evcnt_attach(struct pmap_tlb_info *); 178 void pmap_tlb_asid_acquire(pmap_t, struct lwp *l); 179 void pmap_tlb_asid_deactivate(pmap_t); 180 void pmap_tlb_asid_release_all(pmap_t); 181 int pmap_tlb_update_addr(pmap_t, vaddr_t, pt_entry_t, u_int); 182 #define PMAP_TLB_NEED_IPI 0x01 183 #define PMAP_TLB_INSERT 0x02 184 void pmap_tlb_invalidate_addr(pmap_t, vaddr_t); 185 void pmap_tlb_check(pmap_t, bool (*)(void *, vaddr_t, tlb_asid_t, pt_entry_t)); 186 void pmap_tlb_asid_check(void); 187 188 #endif /* _KERNEL */ 189 #endif /* _UVM_PMAP_PMAP_TLB_H_ */ 190