Home | History | Annotate | Line # | Download | only in pmap
pmap.h revision 1.1
      1  1.1  christos /*	$NetBSD: pmap.h,v 1.1 2012/10/03 00:51:46 christos Exp $	*/
      2  1.1  christos 
      3  1.1  christos /*
      4  1.1  christos  * Copyright (c) 1992, 1993
      5  1.1  christos  *	The Regents of the University of California.  All rights reserved.
      6  1.1  christos  *
      7  1.1  christos  * This code is derived from software contributed to Berkeley by
      8  1.1  christos  * Ralph Campbell.
      9  1.1  christos  *
     10  1.1  christos  * Redistribution and use in source and binary forms, with or without
     11  1.1  christos  * modification, are permitted provided that the following conditions
     12  1.1  christos  * are met:
     13  1.1  christos  * 1. Redistributions of source code must retain the above copyright
     14  1.1  christos  *    notice, this list of conditions and the following disclaimer.
     15  1.1  christos  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  christos  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  christos  *    documentation and/or other materials provided with the distribution.
     18  1.1  christos  * 3. Neither the name of the University nor the names of its contributors
     19  1.1  christos  *    may be used to endorse or promote products derived from this software
     20  1.1  christos  *    without specific prior written permission.
     21  1.1  christos  *
     22  1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23  1.1  christos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24  1.1  christos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25  1.1  christos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26  1.1  christos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27  1.1  christos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28  1.1  christos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  1.1  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30  1.1  christos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  1.1  christos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  1.1  christos  * SUCH DAMAGE.
     33  1.1  christos  *
     34  1.1  christos  *	@(#)pmap.h	8.1 (Berkeley) 6/10/93
     35  1.1  christos  */
     36  1.1  christos 
     37  1.1  christos /*
     38  1.1  christos  * Copyright (c) 1987 Carnegie-Mellon University
     39  1.1  christos  *
     40  1.1  christos  * This code is derived from software contributed to Berkeley by
     41  1.1  christos  * Ralph Campbell.
     42  1.1  christos  *
     43  1.1  christos  * Redistribution and use in source and binary forms, with or without
     44  1.1  christos  * modification, are permitted provided that the following conditions
     45  1.1  christos  * are met:
     46  1.1  christos  * 1. Redistributions of source code must retain the above copyright
     47  1.1  christos  *    notice, this list of conditions and the following disclaimer.
     48  1.1  christos  * 2. Redistributions in binary form must reproduce the above copyright
     49  1.1  christos  *    notice, this list of conditions and the following disclaimer in the
     50  1.1  christos  *    documentation and/or other materials provided with the distribution.
     51  1.1  christos  * 3. All advertising materials mentioning features or use of this software
     52  1.1  christos  *    must display the following acknowledgement:
     53  1.1  christos  *	This product includes software developed by the University of
     54  1.1  christos  *	California, Berkeley and its contributors.
     55  1.1  christos  * 4. Neither the name of the University nor the names of its contributors
     56  1.1  christos  *    may be used to endorse or promote products derived from this software
     57  1.1  christos  *    without specific prior written permission.
     58  1.1  christos  *
     59  1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     60  1.1  christos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     61  1.1  christos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     62  1.1  christos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     63  1.1  christos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     64  1.1  christos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     65  1.1  christos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     66  1.1  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     67  1.1  christos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     68  1.1  christos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     69  1.1  christos  * SUCH DAMAGE.
     70  1.1  christos  *
     71  1.1  christos  *	@(#)pmap.h	8.1 (Berkeley) 6/10/93
     72  1.1  christos  */
     73  1.1  christos 
     74  1.1  christos #ifndef	_COMMON_PMAP_H_
     75  1.1  christos #define	_COMMON_PMAP_H_
     76  1.1  christos 
     77  1.1  christos #include <uvm/uvm_stat.h>
     78  1.1  christos #ifdef UVMHIST
     79  1.1  christos UVMHIST_DECL(pmapexechist);
     80  1.1  christos UVMHIST_DECL(pmaphist);
     81  1.1  christos #endif
     82  1.1  christos 
     83  1.1  christos /*
     84  1.1  christos  * The user address space is mapped using a two level structure where
     85  1.1  christos  * virtual address bits 31..22 are used to index into a segment table which
     86  1.1  christos  * points to a page worth of PTEs (4096 page can hold 1024 PTEs).
     87  1.1  christos  * Bits 21..12 are then used to index a PTE which describes a page within
     88  1.1  christos  * a segment.
     89  1.1  christos  */
     90  1.1  christos 
     91  1.1  christos #define pmap_trunc_seg(x)	((vaddr_t)(x) & ~SEGOFSET)
     92  1.1  christos #define pmap_round_seg(x)	(((vaddr_t)(x) + SEGOFSET) & ~SEGOFSET)
     93  1.1  christos 
     94  1.1  christos /*
     95  1.1  christos  * Each seg_tab point an array of pt_entry [NPTEPG]
     96  1.1  christos  */
     97  1.1  christos typedef union pmap_segtab {
     98  1.1  christos 	union pmap_segtab *	seg_seg[PMAP_SEGTABSIZE];
     99  1.1  christos 	pt_entry_t *		seg_tab[PMAP_SEGTABSIZE];
    100  1.1  christos } pmap_segtab_t;
    101  1.1  christos 
    102  1.1  christos #ifdef _KERNEL
    103  1.1  christos struct pmap;
    104  1.1  christos typedef bool (*pte_callback_t)(struct pmap *, vaddr_t, vaddr_t,
    105  1.1  christos 	pt_entry_t *, uintptr_t);
    106  1.1  christos pt_entry_t *pmap_pte_lookup(struct pmap *, vaddr_t);
    107  1.1  christos pt_entry_t *pmap_pte_reserve(struct pmap *, vaddr_t, int);
    108  1.1  christos void pmap_pte_process(struct pmap *, vaddr_t, vaddr_t, pte_callback_t,
    109  1.1  christos 	uintptr_t);
    110  1.1  christos void pmap_segtab_activate(struct pmap *, struct lwp *);
    111  1.1  christos void pmap_segtab_init(struct pmap *);
    112  1.1  christos void pmap_segtab_destroy(struct pmap *, pte_callback_t, uintptr_t);
    113  1.1  christos extern kmutex_t pmap_segtab_lock;
    114  1.1  christos #endif /* _KERNEL */
    115  1.1  christos 
    116  1.1  christos /*
    117  1.1  christos  * Per TLB (normally same as CPU) asid info
    118  1.1  christos  */
    119  1.1  christos struct pmap_asid_info {
    120  1.1  christos 	LIST_ENTRY(pmap_asid_info) pai_link;
    121  1.1  christos 	uint32_t	pai_asid;	/* TLB address space tag */
    122  1.1  christos };
    123  1.1  christos 
    124  1.1  christos #define	TLBINFO_LOCK(ti)		mutex_spin_enter((ti)->ti_lock)
    125  1.1  christos #define	TLBINFO_UNLOCK(ti)		mutex_spin_exit((ti)->ti_lock)
    126  1.1  christos #define	PMAP_PAI_ASIDVALID_P(pai, ti)	((pai)->pai_asid != 0)
    127  1.1  christos #define	PMAP_PAI(pmap, ti)		(&(pmap)->pm_pai[tlbinfo_index(ti)])
    128  1.1  christos #define	PAI_PMAP(pai, ti)	\
    129  1.1  christos 	((pmap_t)((intptr_t)(pai) \
    130  1.1  christos 	    - offsetof(struct pmap, pm_pai[tlbinfo_index(ti)])))
    131  1.1  christos 
    132  1.1  christos /*
    133  1.1  christos  * Machine dependent pmap structure.
    134  1.1  christos  */
    135  1.1  christos struct pmap {
    136  1.1  christos #ifdef MULTIPROCESSOR
    137  1.1  christos 	__cpuset_t		pm_active;	/* pmap was active on ... */
    138  1.1  christos 	__cpuset_t		pm_onproc;	/* pmap is active on ... */
    139  1.1  christos 	volatile u_int		pm_shootdown_pending;
    140  1.1  christos #endif
    141  1.1  christos 	pmap_segtab_t *		pm_segtab;	/* pointers to pages of PTEs */
    142  1.1  christos 	u_int			pm_count;	/* pmap reference count */
    143  1.1  christos 	u_int			pm_flags;
    144  1.1  christos #define	PMAP_DEFERRED_ACTIVATE	0x0001
    145  1.1  christos 	struct pmap_statistics	pm_stats;	/* pmap statistics */
    146  1.1  christos 	vaddr_t			pm_minaddr;
    147  1.1  christos 	vaddr_t			pm_maxaddr;
    148  1.1  christos 	struct pmap_asid_info	pm_pai[1];
    149  1.1  christos };
    150  1.1  christos 
    151  1.1  christos enum tlb_invalidate_op {
    152  1.1  christos 	TLBINV_NOBODY=0,
    153  1.1  christos 	TLBINV_ONE=1,
    154  1.1  christos 	TLBINV_ALLUSER=2,
    155  1.1  christos 	TLBINV_ALLKERNEL=3,
    156  1.1  christos 	TLBINV_ALL=4
    157  1.1  christos };
    158  1.1  christos 
    159  1.1  christos struct pmap_tlb_info {
    160  1.1  christos 	char ti_name[8];
    161  1.1  christos 	uint32_t ti_asid_hint;		/* probable next ASID to use */
    162  1.1  christos 	uint32_t ti_asids_free;		/* # of ASIDs free */
    163  1.1  christos #define	tlbinfo_noasids_p(ti)	((ti)->ti_asids_free == 0)
    164  1.1  christos 	kmutex_t *ti_lock;
    165  1.1  christos 	u_int ti_wired;			/* # of wired TLB entries */
    166  1.1  christos 	uint32_t ti_asid_max;
    167  1.1  christos 	LIST_HEAD(, pmap_asid_info) ti_pais; /* list of active ASIDs */
    168  1.1  christos #ifdef MULTIPROCESSOR
    169  1.1  christos 	pmap_t ti_victim;
    170  1.1  christos 	uint32_t ti_synci_page_bitmap;	/* page indices needing a syncicache */
    171  1.1  christos 	__cpuset_t ti_cpu_mask;		/* bitmask of CPUs sharing this TLB */
    172  1.1  christos 	enum tlb_invalidate_op ti_tlbinvop;
    173  1.1  christos 	u_int ti_index;
    174  1.1  christos #define tlbinfo_index(ti)	((ti)->ti_index)
    175  1.1  christos 	struct evcnt ti_evcnt_synci_asts;
    176  1.1  christos 	struct evcnt ti_evcnt_synci_all;
    177  1.1  christos 	struct evcnt ti_evcnt_synci_pages;
    178  1.1  christos 	struct evcnt ti_evcnt_synci_deferred;
    179  1.1  christos 	struct evcnt ti_evcnt_synci_desired;
    180  1.1  christos 	struct evcnt ti_evcnt_synci_duplicate;
    181  1.1  christos #else
    182  1.1  christos #define tlbinfo_index(ti)	(0)
    183  1.1  christos #endif
    184  1.1  christos 	struct evcnt ti_evcnt_asid_reinits;
    185  1.1  christos 	u_long ti_asid_bitmap[256 / (sizeof(u_long) * 8)];
    186  1.1  christos };
    187  1.1  christos 
    188  1.1  christos #ifdef	_KERNEL
    189  1.1  christos 
    190  1.1  christos struct pmap_kernel {
    191  1.1  christos 	struct pmap kernel_pmap;
    192  1.1  christos #ifdef MULTIPROCESSOR
    193  1.1  christos 	struct pmap_asid_info kernel_pai[MAXCPUS-1];
    194  1.1  christos #endif
    195  1.1  christos };
    196  1.1  christos 
    197  1.1  christos struct pmap_limits {
    198  1.1  christos 	paddr_t avail_start;
    199  1.1  christos 	paddr_t avail_end;
    200  1.1  christos 	vaddr_t virtual_end;
    201  1.1  christos };
    202  1.1  christos 
    203  1.1  christos /*
    204  1.1  christos  * The pools from which pmap structures and sub-structures are allocated.
    205  1.1  christos  */
    206  1.1  christos extern struct pool pmap_pmap_pool;
    207  1.1  christos extern struct pool pmap_pv_pool;
    208  1.1  christos extern struct pool_allocator pmap_pv_page_allocator;
    209  1.1  christos 
    210  1.1  christos extern struct pmap_kernel kernel_pmap_store;
    211  1.1  christos extern struct pmap_tlb_info pmap_tlb0_info;
    212  1.1  christos #ifdef MULTIPROCESSOR
    213  1.1  christos extern struct pmap_tlb_info *pmap_tlbs[MAXCPUS];
    214  1.1  christos extern u_int pmap_ntlbs;
    215  1.1  christos #endif
    216  1.1  christos extern struct pmap_limits pmap_limits;
    217  1.1  christos 
    218  1.1  christos #define	pmap_wired_count(pmap) 	((pmap)->pm_stats.wired_count)
    219  1.1  christos #define pmap_resident_count(pmap) ((pmap)->pm_stats.resident_count)
    220  1.1  christos 
    221  1.1  christos /*
    222  1.1  christos  *	Bootstrap the system enough to run with virtual memory.
    223  1.1  christos  */
    224  1.1  christos void	pmap_remove_all(pmap_t);
    225  1.1  christos void	pmap_set_modified(paddr_t);
    226  1.1  christos bool	pmap_page_clear_attributes(struct vm_page_md *, u_int);
    227  1.1  christos void	pmap_page_set_attributes(struct vm_page_md *, u_int);
    228  1.1  christos void	pmap_pvlist_lock_init(size_t);
    229  1.1  christos 
    230  1.1  christos #define	PMAP_WB		0
    231  1.1  christos #define	PMAP_WBINV	1
    232  1.1  christos #define	PMAP_INV	2
    233  1.1  christos 
    234  1.1  christos #ifdef MULTIPROCESSOR
    235  1.1  christos void	pmap_tlb_shootdown_process(void);
    236  1.1  christos bool	pmap_tlb_shootdown_bystanders(pmap_t pmap);
    237  1.1  christos void	pmap_tlb_info_attach(struct pmap_tlb_info *, struct cpu_info *);
    238  1.1  christos void	pmap_md_tlb_info_attach(struct pmap_tlb_info *, struct cpu_info *);
    239  1.1  christos void	pmap_syncicache_ast(struct cpu_info *);
    240  1.1  christos void	pmap_syncicache_wanted(struct cpu_info *);
    241  1.1  christos void	pmap_syncicache(vaddr_t, uint32_t);
    242  1.1  christos #endif
    243  1.1  christos void	pmap_tlb_info_init(struct pmap_tlb_info *);
    244  1.1  christos void	pmap_tlb_info_evcnt_attach(struct pmap_tlb_info *);
    245  1.1  christos void	pmap_tlb_asid_acquire(pmap_t, struct lwp *l);
    246  1.1  christos void	pmap_tlb_asid_deactivate(pmap_t);
    247  1.1  christos void	pmap_tlb_asid_release_all(pmap_t);
    248  1.1  christos int	pmap_tlb_update_addr(pmap_t, vaddr_t, uint32_t, u_int);
    249  1.1  christos #define	PMAP_TLB_NEED_IPI	0x01
    250  1.1  christos #define	PMAP_TLB_INSERT		0x02
    251  1.1  christos void	pmap_tlb_invalidate_addr(pmap_t, vaddr_t);
    252  1.1  christos void	pmap_tlb_check(pmap_t, bool (*)(void *, vaddr_t, tlb_asid_t, pt_entry_t));
    253  1.1  christos void	pmap_tlb_asid_check(void);
    254  1.1  christos 
    255  1.1  christos uint16_t pmap_pvlist_lock(struct vm_page_md *, bool);
    256  1.1  christos 
    257  1.1  christos #define	PMAP_STEAL_MEMORY	/* enable pmap_steal_memory() */
    258  1.1  christos #define	PMAP_GROWKERNEL		/* enable pmap_growkernel() */
    259  1.1  christos 
    260  1.1  christos /*
    261  1.1  christos  * Alternate mapping hooks for pool pages.  Avoids thrashing the TLB.
    262  1.1  christos  */
    263  1.1  christos vaddr_t pmap_map_poolpage(paddr_t);
    264  1.1  christos paddr_t pmap_unmap_poolpage(vaddr_t);
    265  1.1  christos struct vm_page *pmap_md_alloc_poolpage(int);
    266  1.1  christos #define	PMAP_ALLOC_POOLPAGE(flags)	pmap_md_alloc_poolpage(flags)
    267  1.1  christos #define	PMAP_MAP_POOLPAGE(pa)		pmap_map_poolpage(pa)
    268  1.1  christos #define	PMAP_UNMAP_POOLPAGE(va)		pmap_unmap_poolpage(va)
    269  1.1  christos 
    270  1.1  christos #endif	/* _KERNEL */
    271  1.1  christos #endif	/* _COMMON_PMAP_H_ */
    272