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