1*0a6a1f1dSLionel Sambuc /* $NetBSD: pmap_tlb.h,v 1.8 2015/04/02 06:17:52 matt Exp $ */ 284d9c625SLionel Sambuc 384d9c625SLionel Sambuc /* 484d9c625SLionel Sambuc * Copyright (c) 1992, 1993 584d9c625SLionel Sambuc * The Regents of the University of California. All rights reserved. 684d9c625SLionel Sambuc * 784d9c625SLionel Sambuc * This code is derived from software contributed to Berkeley by 884d9c625SLionel Sambuc * Ralph Campbell. 984d9c625SLionel Sambuc * 1084d9c625SLionel Sambuc * Redistribution and use in source and binary forms, with or without 1184d9c625SLionel Sambuc * modification, are permitted provided that the following conditions 1284d9c625SLionel Sambuc * are met: 1384d9c625SLionel Sambuc * 1. Redistributions of source code must retain the above copyright 1484d9c625SLionel Sambuc * notice, this list of conditions and the following disclaimer. 1584d9c625SLionel Sambuc * 2. Redistributions in binary form must reproduce the above copyright 1684d9c625SLionel Sambuc * notice, this list of conditions and the following disclaimer in the 1784d9c625SLionel Sambuc * documentation and/or other materials provided with the distribution. 1884d9c625SLionel Sambuc * 3. Neither the name of the University nor the names of its contributors 1984d9c625SLionel Sambuc * may be used to endorse or promote products derived from this software 2084d9c625SLionel Sambuc * without specific prior written permission. 2184d9c625SLionel Sambuc * 2284d9c625SLionel Sambuc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2384d9c625SLionel Sambuc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2484d9c625SLionel Sambuc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2584d9c625SLionel Sambuc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2684d9c625SLionel Sambuc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2784d9c625SLionel Sambuc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2884d9c625SLionel Sambuc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2984d9c625SLionel Sambuc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3084d9c625SLionel Sambuc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3184d9c625SLionel Sambuc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3284d9c625SLionel Sambuc * SUCH DAMAGE. 3384d9c625SLionel Sambuc * 3484d9c625SLionel Sambuc * @(#)pmap.h 8.1 (Berkeley) 6/10/93 3584d9c625SLionel Sambuc */ 3684d9c625SLionel Sambuc 3784d9c625SLionel Sambuc /* 3884d9c625SLionel Sambuc * Copyright (c) 1987 Carnegie-Mellon University 3984d9c625SLionel Sambuc * 4084d9c625SLionel Sambuc * This code is derived from software contributed to Berkeley by 4184d9c625SLionel Sambuc * Ralph Campbell. 4284d9c625SLionel Sambuc * 4384d9c625SLionel Sambuc * Redistribution and use in source and binary forms, with or without 4484d9c625SLionel Sambuc * modification, are permitted provided that the following conditions 4584d9c625SLionel Sambuc * are met: 4684d9c625SLionel Sambuc * 1. Redistributions of source code must retain the above copyright 4784d9c625SLionel Sambuc * notice, this list of conditions and the following disclaimer. 4884d9c625SLionel Sambuc * 2. Redistributions in binary form must reproduce the above copyright 4984d9c625SLionel Sambuc * notice, this list of conditions and the following disclaimer in the 5084d9c625SLionel Sambuc * documentation and/or other materials provided with the distribution. 5184d9c625SLionel Sambuc * 3. All advertising materials mentioning features or use of this software 5284d9c625SLionel Sambuc * must display the following acknowledgement: 5384d9c625SLionel Sambuc * This product includes software developed by the University of 5484d9c625SLionel Sambuc * California, Berkeley and its contributors. 5584d9c625SLionel Sambuc * 4. Neither the name of the University nor the names of its contributors 5684d9c625SLionel Sambuc * may be used to endorse or promote products derived from this software 5784d9c625SLionel Sambuc * without specific prior written permission. 5884d9c625SLionel Sambuc * 5984d9c625SLionel Sambuc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 6084d9c625SLionel Sambuc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 6184d9c625SLionel Sambuc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 6284d9c625SLionel Sambuc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 6384d9c625SLionel Sambuc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 6484d9c625SLionel Sambuc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 6584d9c625SLionel Sambuc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 6684d9c625SLionel Sambuc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 6784d9c625SLionel Sambuc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 6884d9c625SLionel Sambuc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 6984d9c625SLionel Sambuc * SUCH DAMAGE. 7084d9c625SLionel Sambuc * 7184d9c625SLionel Sambuc * @(#)pmap.h 8.1 (Berkeley) 6/10/93 7284d9c625SLionel Sambuc */ 7384d9c625SLionel Sambuc 7484d9c625SLionel Sambuc #ifndef _COMMON_PMAP_TLB_H_ 7584d9c625SLionel Sambuc #define _COMMON_PMAP_TLB_H_ 7684d9c625SLionel Sambuc 77*0a6a1f1dSLionel Sambuc #include <sys/evcnt.h> 7884d9c625SLionel Sambuc #include <sys/kcpuset.h> 7984d9c625SLionel Sambuc 80*0a6a1f1dSLionel Sambuc #if !defined(PMAP_TLB_MAX) 81*0a6a1f1dSLionel Sambuc # if defined(MULTIPROCESSOR) 8284d9c625SLionel Sambuc # define PMAP_TLB_MAX MAXCPUS 83*0a6a1f1dSLionel Sambuc # else 84*0a6a1f1dSLionel Sambuc # define PMAP_TLB_MAX 1 85*0a6a1f1dSLionel Sambuc # endif 8684d9c625SLionel Sambuc #endif 8784d9c625SLionel Sambuc 8884d9c625SLionel Sambuc /* 8984d9c625SLionel Sambuc * Per TLB (normally same as CPU) asid info 9084d9c625SLionel Sambuc */ 9184d9c625SLionel Sambuc struct pmap_asid_info { 9284d9c625SLionel Sambuc LIST_ENTRY(pmap_asid_info) pai_link; 9384d9c625SLionel Sambuc uint32_t pai_asid; /* TLB address space tag */ 9484d9c625SLionel Sambuc }; 9584d9c625SLionel Sambuc 9684d9c625SLionel Sambuc #define TLBINFO_LOCK(ti) mutex_spin_enter((ti)->ti_lock) 9784d9c625SLionel Sambuc #define TLBINFO_UNLOCK(ti) mutex_spin_exit((ti)->ti_lock) 9884d9c625SLionel Sambuc #define PMAP_PAI_ASIDVALID_P(pai, ti) ((pai)->pai_asid != 0) 9984d9c625SLionel Sambuc #define PMAP_PAI(pmap, ti) (&(pmap)->pm_pai[tlbinfo_index(ti)]) 10084d9c625SLionel Sambuc #define PAI_PMAP(pai, ti) \ 10184d9c625SLionel Sambuc ((pmap_t)((intptr_t)(pai) \ 10284d9c625SLionel Sambuc - offsetof(struct pmap, pm_pai[tlbinfo_index(ti)]))) 10384d9c625SLionel Sambuc 10484d9c625SLionel Sambuc enum tlb_invalidate_op { 10584d9c625SLionel Sambuc TLBINV_NOBODY=0, 10684d9c625SLionel Sambuc TLBINV_ONE=1, 10784d9c625SLionel Sambuc TLBINV_ALLUSER=2, 10884d9c625SLionel Sambuc TLBINV_ALLKERNEL=3, 10984d9c625SLionel Sambuc TLBINV_ALL=4 11084d9c625SLionel Sambuc }; 11184d9c625SLionel Sambuc 11284d9c625SLionel Sambuc struct pmap_tlb_info { 11384d9c625SLionel Sambuc char ti_name[8]; 11484d9c625SLionel Sambuc uint32_t ti_asids_free; /* # of ASIDs free */ 11584d9c625SLionel Sambuc #define tlbinfo_noasids_p(ti) ((ti)->ti_asids_free == 0) 11684d9c625SLionel Sambuc kmutex_t *ti_lock; 11784d9c625SLionel Sambuc u_int ti_wired; /* # of wired TLB entries */ 11884d9c625SLionel Sambuc tlb_asid_t ti_asid_hint; /* probable next ASID to use */ 11984d9c625SLionel Sambuc tlb_asid_t ti_asid_max; 12084d9c625SLionel Sambuc LIST_HEAD(, pmap_asid_info) ti_pais; /* list of active ASIDs */ 12184d9c625SLionel Sambuc #ifdef MULTIPROCESSOR 12284d9c625SLionel Sambuc pmap_t ti_victim; 12384d9c625SLionel Sambuc uint32_t ti_synci_page_bitmap; /* page indices needing a syncicache */ 12484d9c625SLionel Sambuc #if PMAP_TLB_MAX > 1 12584d9c625SLionel Sambuc kcpuset_t *ti_kcpuset; /* bitmask of CPUs sharing this TLB */ 12684d9c625SLionel Sambuc u_int ti_index; 12784d9c625SLionel Sambuc enum tlb_invalidate_op ti_tlbinvop; 12884d9c625SLionel Sambuc #define tlbinfo_index(ti) ((ti)->ti_index) 12984d9c625SLionel Sambuc #else 130*0a6a1f1dSLionel Sambuc #define tlbinfo_index(ti) ((void)(ti), 0) 13184d9c625SLionel Sambuc #endif 13284d9c625SLionel Sambuc struct evcnt ti_evcnt_synci_asts; 13384d9c625SLionel Sambuc struct evcnt ti_evcnt_synci_all; 13484d9c625SLionel Sambuc struct evcnt ti_evcnt_synci_pages; 13584d9c625SLionel Sambuc struct evcnt ti_evcnt_synci_deferred; 13684d9c625SLionel Sambuc struct evcnt ti_evcnt_synci_desired; 13784d9c625SLionel Sambuc struct evcnt ti_evcnt_synci_duplicate; 13884d9c625SLionel Sambuc #else 139*0a6a1f1dSLionel Sambuc #define tlbinfo_index(ti) ((void)(ti), 0) 14084d9c625SLionel Sambuc #endif 14184d9c625SLionel Sambuc struct evcnt ti_evcnt_asid_reinits; 14284d9c625SLionel Sambuc u_long ti_asid_bitmap[256 / (sizeof(u_long) * 8)]; 14384d9c625SLionel Sambuc }; 14484d9c625SLionel Sambuc 14584d9c625SLionel Sambuc #ifdef _KERNEL 14684d9c625SLionel Sambuc extern struct pmap_tlb_info pmap_tlb0_info; 14784d9c625SLionel Sambuc #ifdef MULTIPROCESSOR 148*0a6a1f1dSLionel Sambuc extern struct pmap_tlb_info *pmap_tlbs[PMAP_TLB_MAX]; 14984d9c625SLionel Sambuc extern u_int pmap_ntlbs; 15084d9c625SLionel Sambuc #endif 15184d9c625SLionel Sambuc 15284d9c625SLionel Sambuc #ifndef cpu_set_tlb_info 15384d9c625SLionel Sambuc # define cpu_set_tlb_info(ci, ti) ((void)((ci)->ci_tlb_info = (ti))) 15484d9c625SLionel Sambuc #endif 15584d9c625SLionel Sambuc #ifndef cpu_tlb_info 156*0a6a1f1dSLionel Sambuc # if PMAP_TLB_MAX > 1 15784d9c625SLionel Sambuc # define cpu_tlb_info(ci) ((ci)->ci_tlb_info) 15884d9c625SLionel Sambuc # else 15984d9c625SLionel Sambuc # define cpu_tlb_info(ci) (&pmap_tlb0_info) 16084d9c625SLionel Sambuc # endif 16184d9c625SLionel Sambuc #endif 16284d9c625SLionel Sambuc 16384d9c625SLionel Sambuc #ifdef MULTIPROCESSOR 16484d9c625SLionel Sambuc void pmap_tlb_shootdown_process(void); 16584d9c625SLionel Sambuc bool pmap_tlb_shootdown_bystanders(pmap_t pmap); 16684d9c625SLionel Sambuc void pmap_tlb_info_attach(struct pmap_tlb_info *, struct cpu_info *); 16784d9c625SLionel Sambuc void pmap_md_tlb_info_attach(struct pmap_tlb_info *, struct cpu_info *); 16884d9c625SLionel Sambuc #endif 16984d9c625SLionel Sambuc void pmap_tlb_info_init(struct pmap_tlb_info *); 17084d9c625SLionel Sambuc void pmap_tlb_info_evcnt_attach(struct pmap_tlb_info *); 17184d9c625SLionel Sambuc void pmap_tlb_asid_acquire(pmap_t, struct lwp *l); 17284d9c625SLionel Sambuc void pmap_tlb_asid_deactivate(pmap_t); 17384d9c625SLionel Sambuc void pmap_tlb_asid_release_all(pmap_t); 17484d9c625SLionel Sambuc int pmap_tlb_update_addr(pmap_t, vaddr_t, uint32_t, u_int); 17584d9c625SLionel Sambuc #define PMAP_TLB_NEED_IPI 0x01 17684d9c625SLionel Sambuc #define PMAP_TLB_INSERT 0x02 17784d9c625SLionel Sambuc void pmap_tlb_invalidate_addr(pmap_t, vaddr_t); 17884d9c625SLionel Sambuc void pmap_tlb_check(pmap_t, bool (*)(void *, vaddr_t, tlb_asid_t, pt_entry_t)); 17984d9c625SLionel Sambuc void pmap_tlb_asid_check(void); 18084d9c625SLionel Sambuc 18184d9c625SLionel Sambuc #endif /* _KERNEL */ 18284d9c625SLionel Sambuc #endif /* _COMMON_PMAP_TLB_H_ */ 183