Home | History | Annotate | Line # | Download | only in pmap
pmap.h revision 1.9.4.2
      1  1.9.4.2  jdolecek /*	$NetBSD: pmap.h,v 1.9.4.2 2017/12/03 11:39:23 jdolecek Exp $	*/
      2  1.9.4.2  jdolecek 
      3  1.9.4.2  jdolecek /*
      4  1.9.4.2  jdolecek  * Copyright (c) 1992, 1993
      5  1.9.4.2  jdolecek  *	The Regents of the University of California.  All rights reserved.
      6  1.9.4.2  jdolecek  *
      7  1.9.4.2  jdolecek  * This code is derived from software contributed to Berkeley by
      8  1.9.4.2  jdolecek  * Ralph Campbell.
      9  1.9.4.2  jdolecek  *
     10  1.9.4.2  jdolecek  * Redistribution and use in source and binary forms, with or without
     11  1.9.4.2  jdolecek  * modification, are permitted provided that the following conditions
     12  1.9.4.2  jdolecek  * are met:
     13  1.9.4.2  jdolecek  * 1. Redistributions of source code must retain the above copyright
     14  1.9.4.2  jdolecek  *    notice, this list of conditions and the following disclaimer.
     15  1.9.4.2  jdolecek  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.9.4.2  jdolecek  *    notice, this list of conditions and the following disclaimer in the
     17  1.9.4.2  jdolecek  *    documentation and/or other materials provided with the distribution.
     18  1.9.4.2  jdolecek  * 3. Neither the name of the University nor the names of its contributors
     19  1.9.4.2  jdolecek  *    may be used to endorse or promote products derived from this software
     20  1.9.4.2  jdolecek  *    without specific prior written permission.
     21  1.9.4.2  jdolecek  *
     22  1.9.4.2  jdolecek  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23  1.9.4.2  jdolecek  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24  1.9.4.2  jdolecek  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25  1.9.4.2  jdolecek  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26  1.9.4.2  jdolecek  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27  1.9.4.2  jdolecek  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28  1.9.4.2  jdolecek  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  1.9.4.2  jdolecek  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30  1.9.4.2  jdolecek  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  1.9.4.2  jdolecek  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  1.9.4.2  jdolecek  * SUCH DAMAGE.
     33  1.9.4.2  jdolecek  *
     34  1.9.4.2  jdolecek  *	@(#)pmap.h	8.1 (Berkeley) 6/10/93
     35  1.9.4.2  jdolecek  */
     36  1.9.4.2  jdolecek 
     37  1.9.4.2  jdolecek /*
     38  1.9.4.2  jdolecek  * Copyright (c) 1987 Carnegie-Mellon University
     39  1.9.4.2  jdolecek  *
     40  1.9.4.2  jdolecek  * This code is derived from software contributed to Berkeley by
     41  1.9.4.2  jdolecek  * Ralph Campbell.
     42  1.9.4.2  jdolecek  *
     43  1.9.4.2  jdolecek  * Redistribution and use in source and binary forms, with or without
     44  1.9.4.2  jdolecek  * modification, are permitted provided that the following conditions
     45  1.9.4.2  jdolecek  * are met:
     46  1.9.4.2  jdolecek  * 1. Redistributions of source code must retain the above copyright
     47  1.9.4.2  jdolecek  *    notice, this list of conditions and the following disclaimer.
     48  1.9.4.2  jdolecek  * 2. Redistributions in binary form must reproduce the above copyright
     49  1.9.4.2  jdolecek  *    notice, this list of conditions and the following disclaimer in the
     50  1.9.4.2  jdolecek  *    documentation and/or other materials provided with the distribution.
     51  1.9.4.2  jdolecek  * 3. All advertising materials mentioning features or use of this software
     52  1.9.4.2  jdolecek  *    must display the following acknowledgement:
     53  1.9.4.2  jdolecek  *	This product includes software developed by the University of
     54  1.9.4.2  jdolecek  *	California, Berkeley and its contributors.
     55  1.9.4.2  jdolecek  * 4. Neither the name of the University nor the names of its contributors
     56  1.9.4.2  jdolecek  *    may be used to endorse or promote products derived from this software
     57  1.9.4.2  jdolecek  *    without specific prior written permission.
     58  1.9.4.2  jdolecek  *
     59  1.9.4.2  jdolecek  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     60  1.9.4.2  jdolecek  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     61  1.9.4.2  jdolecek  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     62  1.9.4.2  jdolecek  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     63  1.9.4.2  jdolecek  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     64  1.9.4.2  jdolecek  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     65  1.9.4.2  jdolecek  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     66  1.9.4.2  jdolecek  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     67  1.9.4.2  jdolecek  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     68  1.9.4.2  jdolecek  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     69  1.9.4.2  jdolecek  * SUCH DAMAGE.
     70  1.9.4.2  jdolecek  *
     71  1.9.4.2  jdolecek  *	@(#)pmap.h	8.1 (Berkeley) 6/10/93
     72  1.9.4.2  jdolecek  */
     73  1.9.4.2  jdolecek 
     74  1.9.4.2  jdolecek #ifndef	_UVM_PMAP_PMAP_H_
     75  1.9.4.2  jdolecek #define	_UVM_PMAP_PMAP_H_
     76  1.9.4.2  jdolecek 
     77  1.9.4.2  jdolecek #include <uvm/uvm_stat.h>
     78  1.9.4.2  jdolecek #ifdef UVMHIST
     79  1.9.4.2  jdolecek UVMHIST_DECL(pmapexechist);
     80  1.9.4.2  jdolecek UVMHIST_DECL(pmaphist);
     81  1.9.4.2  jdolecek #endif
     82  1.9.4.2  jdolecek 
     83  1.9.4.2  jdolecek /*
     84  1.9.4.2  jdolecek  * The user address space is mapped using a two level structure where
     85  1.9.4.2  jdolecek  * virtual address bits 31..22 are used to index into a segment table which
     86  1.9.4.2  jdolecek  * points to a page worth of PTEs (4096 page can hold 1024 PTEs).
     87  1.9.4.2  jdolecek  * Bits 21..12 are then used to index a PTE which describes a page within
     88  1.9.4.2  jdolecek  * a segment.
     89  1.9.4.2  jdolecek  */
     90  1.9.4.2  jdolecek 
     91  1.9.4.2  jdolecek #define pmap_trunc_seg(x)	((vaddr_t)(x) & ~SEGOFSET)
     92  1.9.4.2  jdolecek #define pmap_round_seg(x)	(((vaddr_t)(x) + SEGOFSET) & ~SEGOFSET)
     93  1.9.4.2  jdolecek 
     94  1.9.4.2  jdolecek /*
     95  1.9.4.2  jdolecek  * Each seg_tab point an array of pt_entry [NPTEPG]
     96  1.9.4.2  jdolecek  */
     97  1.9.4.2  jdolecek typedef union pmap_segtab {
     98  1.9.4.2  jdolecek 	union pmap_segtab *	seg_seg[PMAP_SEGTABSIZE];
     99  1.9.4.2  jdolecek 	pt_entry_t *		seg_tab[PMAP_SEGTABSIZE];
    100  1.9.4.2  jdolecek } pmap_segtab_t;
    101  1.9.4.2  jdolecek 
    102  1.9.4.2  jdolecek #ifdef _KERNEL
    103  1.9.4.2  jdolecek struct pmap;
    104  1.9.4.2  jdolecek typedef bool (*pte_callback_t)(struct pmap *, vaddr_t, vaddr_t,
    105  1.9.4.2  jdolecek 	pt_entry_t *, uintptr_t);
    106  1.9.4.2  jdolecek pt_entry_t *pmap_pte_lookup(struct pmap *, vaddr_t);
    107  1.9.4.2  jdolecek pt_entry_t *pmap_pte_reserve(struct pmap *, vaddr_t, int);
    108  1.9.4.2  jdolecek void pmap_pte_process(struct pmap *, vaddr_t, vaddr_t, pte_callback_t,
    109  1.9.4.2  jdolecek 	uintptr_t);
    110  1.9.4.2  jdolecek void pmap_segtab_activate(struct pmap *, struct lwp *);
    111  1.9.4.2  jdolecek void pmap_segtab_init(struct pmap *);
    112  1.9.4.2  jdolecek void pmap_segtab_destroy(struct pmap *, pte_callback_t, uintptr_t);
    113  1.9.4.2  jdolecek extern kmutex_t pmap_segtab_lock;
    114  1.9.4.2  jdolecek #endif /* _KERNEL */
    115  1.9.4.2  jdolecek 
    116  1.9.4.2  jdolecek #ifdef MULTIPROCESSOR
    117  1.9.4.2  jdolecek #include <sys/kcpuset.h>
    118  1.9.4.2  jdolecek #endif
    119  1.9.4.2  jdolecek #include <uvm/pmap/pmap_tlb.h>
    120  1.9.4.2  jdolecek 
    121  1.9.4.2  jdolecek /*
    122  1.9.4.2  jdolecek  * Machine dependent pmap structure.
    123  1.9.4.2  jdolecek  */
    124  1.9.4.2  jdolecek struct pmap {
    125  1.9.4.2  jdolecek #ifdef MULTIPROCESSOR
    126  1.9.4.2  jdolecek 	kcpuset_t		*pm_active;	/* pmap was active on ... */
    127  1.9.4.2  jdolecek 	kcpuset_t		*pm_onproc;	/* pmap is active on ... */
    128  1.9.4.2  jdolecek 	volatile u_int		pm_shootdown_pending;
    129  1.9.4.2  jdolecek #endif
    130  1.9.4.2  jdolecek 	pmap_segtab_t *		pm_segtab;	/* pointers to pages of PTEs */
    131  1.9.4.2  jdolecek 	u_int			pm_count;	/* pmap reference count */
    132  1.9.4.2  jdolecek 	u_int			pm_flags;
    133  1.9.4.2  jdolecek #define	PMAP_DEFERRED_ACTIVATE	0x0001
    134  1.9.4.2  jdolecek 	struct pmap_statistics	pm_stats;	/* pmap statistics */
    135  1.9.4.2  jdolecek 	vaddr_t			pm_minaddr;
    136  1.9.4.2  jdolecek 	vaddr_t			pm_maxaddr;
    137  1.9.4.2  jdolecek 	struct pmap_asid_info	pm_pai[1];
    138  1.9.4.2  jdolecek };
    139  1.9.4.2  jdolecek 
    140  1.9.4.2  jdolecek #ifdef	_KERNEL
    141  1.9.4.2  jdolecek struct pmap_kernel {
    142  1.9.4.2  jdolecek 	struct pmap kernel_pmap;
    143  1.9.4.2  jdolecek #if defined(MULTIPROCESSOR) && PMAP_TLB_MAX > 1
    144  1.9.4.2  jdolecek 	struct pmap_asid_info kernel_pai[PMAP_TLB_MAX-1];
    145  1.9.4.2  jdolecek #endif
    146  1.9.4.2  jdolecek };
    147  1.9.4.2  jdolecek 
    148  1.9.4.2  jdolecek struct pmap_limits {
    149  1.9.4.2  jdolecek 	paddr_t avail_start;
    150  1.9.4.2  jdolecek 	paddr_t avail_end;
    151  1.9.4.2  jdolecek 	vaddr_t virtual_start;
    152  1.9.4.2  jdolecek 	vaddr_t virtual_end;
    153  1.9.4.2  jdolecek };
    154  1.9.4.2  jdolecek 
    155  1.9.4.2  jdolecek /*
    156  1.9.4.2  jdolecek  * Initialize the kernel pmap.
    157  1.9.4.2  jdolecek  */
    158  1.9.4.2  jdolecek #ifdef MULTIPROCESSOR
    159  1.9.4.2  jdolecek #define PMAP_SIZE	offsetof(struct pmap, pm_pai[PMAP_TLB_MAX])
    160  1.9.4.2  jdolecek #else
    161  1.9.4.2  jdolecek #define PMAP_SIZE	sizeof(struct pmap)
    162  1.9.4.2  jdolecek #endif
    163  1.9.4.2  jdolecek 
    164  1.9.4.2  jdolecek /*
    165  1.9.4.2  jdolecek  * The pools from which pmap structures and sub-structures are allocated.
    166  1.9.4.2  jdolecek  */
    167  1.9.4.2  jdolecek extern struct pool pmap_pmap_pool;
    168  1.9.4.2  jdolecek extern struct pool pmap_pv_pool;
    169  1.9.4.2  jdolecek extern struct pool_allocator pmap_pv_page_allocator;
    170  1.9.4.2  jdolecek 
    171  1.9.4.2  jdolecek extern struct pmap_kernel kernel_pmap_store;
    172  1.9.4.2  jdolecek extern struct pmap_limits pmap_limits;
    173  1.9.4.2  jdolecek 
    174  1.9.4.2  jdolecek extern u_int pmap_page_colormask;
    175  1.9.4.2  jdolecek 
    176  1.9.4.2  jdolecek extern pmap_segtab_t pmap_kern_segtab;
    177  1.9.4.2  jdolecek 
    178  1.9.4.2  jdolecek #define	pmap_wired_count(pmap) 	((pmap)->pm_stats.wired_count)
    179  1.9.4.2  jdolecek #define pmap_resident_count(pmap) ((pmap)->pm_stats.resident_count)
    180  1.9.4.2  jdolecek 
    181  1.9.4.2  jdolecek /*
    182  1.9.4.2  jdolecek  *	Bootstrap the system enough to run with virtual memory.
    183  1.9.4.2  jdolecek  */
    184  1.9.4.2  jdolecek void	pmap_remove_all(pmap_t);
    185  1.9.4.2  jdolecek void	pmap_set_modified(paddr_t);
    186  1.9.4.2  jdolecek bool	pmap_page_clear_attributes(struct vm_page_md *, u_int);
    187  1.9.4.2  jdolecek void	pmap_page_set_attributes(struct vm_page_md *, u_int);
    188  1.9.4.2  jdolecek void	pmap_pvlist_lock_init(size_t);
    189  1.9.4.2  jdolecek #ifdef PMAP_VIRTUAL_CACHE_ALIASES
    190  1.9.4.2  jdolecek void	pmap_page_cache(struct vm_page *, bool cached);
    191  1.9.4.2  jdolecek #endif
    192  1.9.4.2  jdolecek 
    193  1.9.4.2  jdolecek 
    194  1.9.4.2  jdolecek #define	PMAP_WB		0
    195  1.9.4.2  jdolecek #define	PMAP_WBINV	1
    196  1.9.4.2  jdolecek #define	PMAP_INV	2
    197  1.9.4.2  jdolecek 
    198  1.9.4.2  jdolecek //uint16_t pmap_pvlist_lock(struct vm_page_md *, bool);
    199  1.9.4.2  jdolecek kmutex_t *pmap_pvlist_lock_addr(struct vm_page_md *);
    200  1.9.4.2  jdolecek 
    201  1.9.4.2  jdolecek #define	PMAP_STEAL_MEMORY	/* enable pmap_steal_memory() */
    202  1.9.4.2  jdolecek #define	PMAP_GROWKERNEL		/* enable pmap_growkernel() */
    203  1.9.4.2  jdolecek 
    204  1.9.4.2  jdolecek /*
    205  1.9.4.2  jdolecek  * Alternate mapping hooks for pool pages.  Avoids thrashing the TLB.
    206  1.9.4.2  jdolecek  */
    207  1.9.4.2  jdolecek vaddr_t pmap_map_poolpage(paddr_t);
    208  1.9.4.2  jdolecek paddr_t pmap_unmap_poolpage(vaddr_t);
    209  1.9.4.2  jdolecek struct vm_page *pmap_md_alloc_poolpage(int);
    210  1.9.4.2  jdolecek #define	PMAP_ALLOC_POOLPAGE(flags)	pmap_md_alloc_poolpage(flags)
    211  1.9.4.2  jdolecek #define	PMAP_MAP_POOLPAGE(pa)		pmap_map_poolpage(pa)
    212  1.9.4.2  jdolecek #define	PMAP_UNMAP_POOLPAGE(va)		pmap_unmap_poolpage(va)
    213  1.9.4.2  jdolecek 
    214  1.9.4.2  jdolecek #define PMAP_COUNT(name)	(pmap_evcnt_##name.ev_count++ + 0)
    215  1.9.4.2  jdolecek #define PMAP_COUNTER(name, desc) \
    216  1.9.4.2  jdolecek struct evcnt pmap_evcnt_##name = \
    217  1.9.4.2  jdolecek 	EVCNT_INITIALIZER(EVCNT_TYPE_MISC, NULL, "pmap", desc); \
    218  1.9.4.2  jdolecek EVCNT_ATTACH_STATIC(pmap_evcnt_##name)
    219  1.9.4.2  jdolecek 
    220  1.9.4.2  jdolecek #endif	/* _KERNEL */
    221  1.9.4.2  jdolecek #endif	/* _UVM_PMAP_PMAP_H_ */
    222