Home | History | Annotate | Line # | Download | only in pmap
pmap.h revision 1.14
      1 /*	$NetBSD: pmap.h,v 1.14 2020/03/15 11:36:24 rin 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_H_
     75 #define	_UVM_PMAP_PMAP_H_
     76 
     77 #include <uvm/uvm_stat.h>
     78 #ifdef UVMHIST
     79 UVMHIST_DECL(pmapexechist);
     80 UVMHIST_DECL(pmaphist);
     81 #endif
     82 
     83 /*
     84  * The user address space is mapped using a two level structure where
     85  * virtual address bits 31..22 are used to index into a segment table which
     86  * points to a page worth of PTEs (4096 page can hold 1024 PTEs).
     87  * Bits 21..12 are then used to index a PTE which describes a page within
     88  * a segment.
     89  */
     90 
     91 #define pmap_trunc_seg(x)	((vaddr_t)(x) & ~SEGOFSET)
     92 #define pmap_round_seg(x)	(((vaddr_t)(x) + SEGOFSET) & ~SEGOFSET)
     93 
     94 /*
     95  * Each seg_tab point an array of pt_entry [NPTEPG]
     96  */
     97 typedef union pmap_segtab {
     98 	union pmap_segtab *	seg_seg[PMAP_SEGTABSIZE];
     99 	pt_entry_t *		seg_tab[PMAP_SEGTABSIZE];
    100 } pmap_segtab_t;
    101 
    102 #ifdef _KERNEL
    103 struct pmap;
    104 typedef bool (*pte_callback_t)(struct pmap *, vaddr_t, vaddr_t,
    105 	pt_entry_t *, uintptr_t);
    106 void pmap_bootstrap_common(void);
    107 pt_entry_t *pmap_pte_lookup(struct pmap *, vaddr_t);
    108 pt_entry_t *pmap_pte_reserve(struct pmap *, vaddr_t, int);
    109 void pmap_pte_process(struct pmap *, vaddr_t, vaddr_t, pte_callback_t,
    110 	uintptr_t);
    111 void pmap_segtab_activate(struct pmap *, struct lwp *);
    112 void pmap_segtab_init(struct pmap *);
    113 void pmap_segtab_destroy(struct pmap *, pte_callback_t, uintptr_t);
    114 extern kmutex_t pmap_segtab_lock;
    115 #endif /* _KERNEL */
    116 
    117 #ifdef MULTIPROCESSOR
    118 #include <sys/kcpuset.h>
    119 #endif
    120 #include <uvm/pmap/pmap_tlb.h>
    121 
    122 /*
    123  * Machine dependent pmap structure.
    124  */
    125 struct pmap {
    126 #ifdef MULTIPROCESSOR
    127 	kcpuset_t		*pm_active;	/* pmap was active on ... */
    128 	kcpuset_t		*pm_onproc;	/* pmap is active on ... */
    129 	volatile u_int		pm_shootdown_pending;
    130 #endif
    131 	pmap_segtab_t *		pm_segtab;	/* pointers to pages of PTEs */
    132 	u_int			pm_count;	/* pmap reference count */
    133 	u_int			pm_flags;
    134 #define	PMAP_DEFERRED_ACTIVATE	__BIT(0)
    135 	struct pmap_statistics	pm_stats;	/* pmap statistics */
    136 	vaddr_t			pm_minaddr;
    137 	vaddr_t			pm_maxaddr;
    138 #ifdef __HAVE_PMAP_MD
    139 	struct pmap_md		pm_md;
    140 #endif
    141 	struct pmap_asid_info	pm_pai[1];
    142 };
    143 
    144 #ifdef	_KERNEL
    145 struct pmap_kernel {
    146 	struct pmap kernel_pmap;
    147 #if defined(MULTIPROCESSOR) && PMAP_TLB_MAX > 1
    148 	struct pmap_asid_info kernel_pai[PMAP_TLB_MAX-1];
    149 #endif
    150 };
    151 
    152 struct pmap_limits {
    153 	paddr_t avail_start;
    154 	paddr_t avail_end;
    155 	vaddr_t virtual_start;
    156 	vaddr_t virtual_end;
    157 };
    158 
    159 /*
    160  * Initialize the kernel pmap.
    161  */
    162 #ifdef MULTIPROCESSOR
    163 #define PMAP_SIZE	offsetof(struct pmap, pm_pai[PMAP_TLB_MAX])
    164 #else
    165 #define PMAP_SIZE	sizeof(struct pmap)
    166 #endif
    167 
    168 /*
    169  * The pools from which pmap structures and sub-structures are allocated.
    170  */
    171 extern struct pool pmap_pmap_pool;
    172 extern struct pool pmap_pv_pool;
    173 extern struct pool_allocator pmap_pv_page_allocator;
    174 
    175 extern struct pmap_kernel kernel_pmap_store;
    176 extern struct pmap_limits pmap_limits;
    177 
    178 extern u_int pmap_page_colormask;
    179 
    180 extern pmap_segtab_t pmap_kern_segtab;
    181 
    182 #define	pmap_wired_count(pmap) 	((pmap)->pm_stats.wired_count)
    183 #define pmap_resident_count(pmap) ((pmap)->pm_stats.resident_count)
    184 
    185 /*
    186  *	Bootstrap the system enough to run with virtual memory.
    187  */
    188 bool	pmap_remove_all(pmap_t);
    189 void	pmap_set_modified(paddr_t);
    190 bool	pmap_page_clear_attributes(struct vm_page_md *, u_int);
    191 void	pmap_page_set_attributes(struct vm_page_md *, u_int);
    192 void	pmap_pvlist_lock_init(size_t);
    193 #ifdef PMAP_VIRTUAL_CACHE_ALIASES
    194 void	pmap_page_cache(struct vm_page *, bool cached);
    195 #endif
    196 
    197 
    198 #define	PMAP_WB		0
    199 #define	PMAP_WBINV	1
    200 #define	PMAP_INV	2
    201 
    202 //uint16_t pmap_pvlist_lock(struct vm_page_md *, bool);
    203 kmutex_t *pmap_pvlist_lock_addr(struct vm_page_md *);
    204 
    205 #define	PMAP_STEAL_MEMORY	/* enable pmap_steal_memory() */
    206 #define	PMAP_GROWKERNEL		/* enable pmap_growkernel() */
    207 
    208 /*
    209  * Alternate mapping hooks for pool pages.  Avoids thrashing the TLB.
    210  */
    211 vaddr_t pmap_map_poolpage(paddr_t);
    212 paddr_t pmap_unmap_poolpage(vaddr_t);
    213 struct vm_page *pmap_md_alloc_poolpage(int);
    214 #define	PMAP_ALLOC_POOLPAGE(flags)	pmap_md_alloc_poolpage(flags)
    215 #define	PMAP_MAP_POOLPAGE(pa)		pmap_map_poolpage(pa)
    216 #define	PMAP_UNMAP_POOLPAGE(va)		pmap_unmap_poolpage(va)
    217 
    218 #define PMAP_COUNT(name)	(pmap_evcnt_##name.ev_count++ + 0)
    219 #define PMAP_COUNTER(name, desc) \
    220 struct evcnt pmap_evcnt_##name = \
    221 	EVCNT_INITIALIZER(EVCNT_TYPE_MISC, NULL, "pmap", desc); \
    222 EVCNT_ATTACH_STATIC(pmap_evcnt_##name)
    223 
    224 #endif	/* _KERNEL */
    225 #endif	/* _UVM_PMAP_PMAP_H_ */
    226