Home | History | Annotate | Line # | Download | only in include
pmap.h revision 1.89.20.3
      1  1.89.20.3     joerg /*	$NetBSD: pmap.h,v 1.89.20.3 2007/10/02 18:27:25 joerg Exp $	*/
      2       1.38   mycroft 
      3       1.40   thorpej /*
      4       1.40   thorpej  *
      5       1.40   thorpej  * Copyright (c) 1997 Charles D. Cranor and Washington University.
      6       1.38   mycroft  * All rights reserved.
      7       1.38   mycroft  *
      8       1.38   mycroft  * Redistribution and use in source and binary forms, with or without
      9       1.38   mycroft  * modification, are permitted provided that the following conditions
     10       1.38   mycroft  * are met:
     11       1.38   mycroft  * 1. Redistributions of source code must retain the above copyright
     12       1.38   mycroft  *    notice, this list of conditions and the following disclaimer.
     13       1.38   mycroft  * 2. Redistributions in binary form must reproduce the above copyright
     14       1.38   mycroft  *    notice, this list of conditions and the following disclaimer in the
     15       1.38   mycroft  *    documentation and/or other materials provided with the distribution.
     16       1.38   mycroft  * 3. All advertising materials mentioning features or use of this software
     17       1.40   thorpej  *    must display the following acknowledgment:
     18       1.40   thorpej  *      This product includes software developed by Charles D. Cranor and
     19       1.40   thorpej  *      Washington University.
     20       1.40   thorpej  * 4. The name of the author may not be used to endorse or promote products
     21       1.40   thorpej  *    derived from this software without specific prior written permission.
     22        1.1       cgd  *
     23       1.40   thorpej  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     24       1.40   thorpej  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     25       1.40   thorpej  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     26       1.40   thorpej  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     27       1.40   thorpej  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     28       1.40   thorpej  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     29       1.40   thorpej  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     30       1.40   thorpej  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     31       1.40   thorpej  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     32       1.40   thorpej  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     33        1.1       cgd  */
     34        1.1       cgd 
     35        1.1       cgd /*
     36       1.40   thorpej  * pmap.h: see pmap.c for the history of this pmap module.
     37        1.1       cgd  */
     38       1.34       mrg 
     39       1.40   thorpej #ifndef	_I386_PMAP_H_
     40       1.40   thorpej #define	_I386_PMAP_H_
     41       1.40   thorpej 
     42       1.58       mrg #if defined(_KERNEL_OPT)
     43       1.39   thorpej #include "opt_user_ldt.h"
     44       1.48   thorpej #include "opt_largepages.h"
     45       1.34       mrg #endif
     46        1.1       cgd 
     47        1.6   mycroft #include <machine/pte.h>
     48       1.39   thorpej #include <machine/segments.h>
     49  1.89.20.1  jmcneill #include <machine/atomic.h>
     50  1.89.20.3     joerg #if defined(_KERNEL) || defined(_LKM)
     51  1.89.20.3     joerg #include <machine/cpufunc.h>
     52  1.89.20.3     joerg #endif
     53  1.89.20.1  jmcneill 
     54       1.40   thorpej #include <uvm/uvm_object.h>
     55        1.1       cgd 
     56        1.1       cgd /*
     57       1.40   thorpej  * see pte.h for a description of i386 MMU terminology and hardware
     58       1.40   thorpej  * interface.
     59       1.40   thorpej  *
     60       1.40   thorpej  * a pmap describes a processes' 4GB virtual address space.  this
     61       1.40   thorpej  * virtual address space can be broken up into 1024 4MB regions which
     62       1.41       chs  * are described by PDEs in the PDP.  the PDEs are defined as follows:
     63       1.40   thorpej  *
     64       1.40   thorpej  * (ranges are inclusive -> exclusive, just like vm_map_entry start/end)
     65       1.43   thorpej  * (the following assumes that KERNBASE is 0xc0000000)
     66       1.40   thorpej  *
     67       1.40   thorpej  * PDE#s	VA range		usage
     68       1.68  drochner  * 0->766	0x0 -> 0xbfc00000	user address space
     69       1.61      yamt  * 767		0xbfc00000->		recursive mapping of PDP (used for
     70       1.43   thorpej  *			0xc0000000	linear mapping of PTPs)
     71       1.43   thorpej  * 768->1023	0xc0000000->		kernel address space (constant
     72       1.40   thorpej  *			0xffc00000	across all pmap's/processes)
     73       1.40   thorpej  * 1023		0xffc00000->		"alternate" recursive PDP mapping
     74       1.40   thorpej  *			<end>		(for other pmaps)
     75       1.40   thorpej  *
     76       1.40   thorpej  *
     77       1.40   thorpej  * note: a recursive PDP mapping provides a way to map all the PTEs for
     78       1.41       chs  * a 4GB address space into a linear chunk of virtual memory.  in other
     79       1.41       chs  * words, the PTE for page 0 is the first int mapped into the 4MB recursive
     80       1.41       chs  * area.  the PTE for page 1 is the second int.  the very last int in the
     81       1.81  junyoung  * 4MB range is the PTE that maps VA 0xfffff000 (the last page in a 4GB
     82       1.40   thorpej  * address).
     83       1.40   thorpej  *
     84       1.43   thorpej  * all pmap's PD's must have the same values in slots 768->1023 so that
     85       1.41       chs  * the kernel is always mapped in every process.  these values are loaded
     86       1.40   thorpej  * into the PD at pmap creation time.
     87       1.40   thorpej  *
     88       1.41       chs  * at any one time only one pmap can be active on a processor.  this is
     89       1.41       chs  * the pmap whose PDP is pointed to by processor register %cr3.  this pmap
     90       1.40   thorpej  * will have all its PTEs mapped into memory at the recursive mapping
     91       1.43   thorpej  * point (slot #767 as show above).  when the pmap code wants to find the
     92       1.40   thorpej  * PTE for a virtual address, all it has to do is the following:
     93       1.40   thorpej  *
     94       1.71   thorpej  * address of PTE = (767 * 4MB) + (VA / PAGE_SIZE) * sizeof(pt_entry_t)
     95       1.43   thorpej  *                = 0xbfc00000 + (VA / 4096) * 4
     96       1.40   thorpej  *
     97       1.40   thorpej  * what happens if the pmap layer is asked to perform an operation
     98       1.41       chs  * on a pmap that is not the one which is currently active?  in that
     99       1.41       chs  * case we take the PA of the PDP of non-active pmap and put it in
    100       1.41       chs  * slot 1023 of the active pmap.  this causes the non-active pmap's
    101       1.40   thorpej  * PTEs to get mapped in the final 4MB of the 4GB address space
    102       1.40   thorpej  * (e.g. starting at 0xffc00000).
    103       1.40   thorpej  *
    104       1.40   thorpej  * the following figure shows the effects of the recursive PDP mapping:
    105       1.40   thorpej  *
    106       1.40   thorpej  *   PDP (%cr3)
    107       1.40   thorpej  *   +----+
    108       1.40   thorpej  *   |   0| -> PTP#0 that maps VA 0x0 -> 0x400000
    109       1.40   thorpej  *   |    |
    110       1.40   thorpej  *   |    |
    111       1.43   thorpej  *   | 767| -> points back to PDP (%cr3) mapping VA 0xbfc00000 -> 0xc0000000
    112       1.83  junyoung  *   | 768| -> first kernel PTP (maps 0xc0000000 -> 0xc0400000)
    113       1.40   thorpej  *   |    |
    114       1.40   thorpej  *   |1023| -> points to alternate pmap's PDP (maps 0xffc00000 -> end)
    115       1.40   thorpej  *   +----+
    116       1.40   thorpej  *
    117       1.43   thorpej  * note that the PDE#767 VA (0xbfc00000) is defined as "PTE_BASE"
    118       1.40   thorpej  * note that the PDE#1023 VA (0xffc00000) is defined as "APTE_BASE"
    119       1.40   thorpej  *
    120       1.43   thorpej  * starting at VA 0xbfc00000 the current active PDP (%cr3) acts as a
    121       1.40   thorpej  * PTP:
    122       1.40   thorpej  *
    123       1.43   thorpej  * PTP#767 == PDP(%cr3) => maps VA 0xbfc00000 -> 0xc0000000
    124       1.40   thorpej  *   +----+
    125       1.43   thorpej  *   |   0| -> maps the contents of PTP#0 at VA 0xbfc00000->0xbfc01000
    126       1.40   thorpej  *   |    |
    127       1.40   thorpej  *   |    |
    128       1.81  junyoung  *   | 767| -> maps contents of PTP#767 (the PDP) at VA 0xbfeff000
    129       1.43   thorpej  *   | 768| -> maps contents of first kernel PTP
    130       1.40   thorpej  *   |    |
    131       1.40   thorpej  *   |1023|
    132       1.40   thorpej  *   +----+
    133       1.40   thorpej  *
    134       1.81  junyoung  * note that mapping of the PDP at PTP#767's VA (0xbfeff000) is
    135       1.40   thorpej  * defined as "PDP_BASE".... within that mapping there are two
    136       1.41       chs  * defines:
    137       1.59       chs  *   "PDP_PDE" (0xbfeffbfc) is the VA of the PDE in the PDP
    138       1.41       chs  *      which points back to itself.
    139       1.59       chs  *   "APDP_PDE" (0xbfeffffc) is the VA of the PDE in the PDP which
    140       1.40   thorpej  *      establishes the recursive mapping of the alternate pmap.
    141       1.40   thorpej  *      to set the alternate PDP, one just has to put the correct
    142       1.40   thorpej  *	PA info in *APDP_PDE.
    143       1.40   thorpej  *
    144       1.41       chs  * note that in the APTE_BASE space, the APDP appears at VA
    145       1.40   thorpej  * "APDP_BASE" (0xfffff000).
    146        1.1       cgd  */
    147       1.65      fvdl /* XXX MP should we allocate one APDP_PDE per processor?? */
    148       1.33       mrg 
    149       1.33       mrg /*
    150       1.40   thorpej  * the following defines identify the slots used as described above.
    151       1.33       mrg  */
    152       1.33       mrg 
    153       1.43   thorpej #define PDSLOT_PTE	((KERNBASE/NBPD)-1) /* 767: for recursive PDP map */
    154       1.43   thorpej #define PDSLOT_KERN	(KERNBASE/NBPD)	    /* 768: start of kernel space */
    155       1.40   thorpej #define PDSLOT_APTE	((unsigned)1023) /* 1023: alternative recursive slot */
    156        1.1       cgd 
    157        1.1       cgd /*
    158       1.41       chs  * the following defines give the virtual addresses of various MMU
    159       1.40   thorpej  * data structures:
    160       1.40   thorpej  * PTE_BASE and APTE_BASE: the base VA of the linear PTE mappings
    161       1.81  junyoung  * PDP_BASE and APDP_BASE: the base VA of the recursive mapping of the PDP
    162       1.40   thorpej  * PDP_PDE and APDP_PDE: the VA of the PDE that points back to the PDP/APDP
    163        1.1       cgd  */
    164       1.29      fvdl 
    165       1.40   thorpej #define PTE_BASE	((pt_entry_t *)  (PDSLOT_PTE * NBPD) )
    166       1.40   thorpej #define APTE_BASE	((pt_entry_t *)  (PDSLOT_APTE * NBPD) )
    167       1.71   thorpej #define PDP_BASE ((pd_entry_t *)(((char *)PTE_BASE) + (PDSLOT_PTE * PAGE_SIZE)))
    168       1.71   thorpej #define APDP_BASE ((pd_entry_t *)(((char *)APTE_BASE) + (PDSLOT_APTE * PAGE_SIZE)))
    169       1.40   thorpej #define PDP_PDE		(PDP_BASE + PDSLOT_PTE)
    170       1.40   thorpej #define APDP_PDE	(PDP_BASE + PDSLOT_APTE)
    171       1.40   thorpej 
    172       1.40   thorpej /*
    173       1.40   thorpej  * the follow define determines how many PTPs should be set up for the
    174       1.81  junyoung  * kernel by locore.S at boot time.  this should be large enough to
    175       1.41       chs  * get the VM system running.  once the VM system is running, the
    176       1.40   thorpej  * pmap module can add more PTPs to the kernel area on demand.
    177       1.40   thorpej  */
    178       1.40   thorpej 
    179       1.40   thorpej #ifndef NKPTP
    180       1.80   mycroft #define NKPTP		0	/* 16MB to start */
    181        1.1       cgd #endif
    182       1.80   mycroft #define NKPTP_MIN	2	/* smallest value we allow */
    183       1.40   thorpej #define NKPTP_MAX	(1024 - (KERNBASE/NBPD) - 1)
    184       1.40   thorpej 				/* largest value (-1 for APTP space) */
    185        1.1       cgd 
    186        1.1       cgd /*
    187       1.40   thorpej  * pdei/ptei: generate index into PDP/PTP from a VA
    188        1.1       cgd  */
    189       1.40   thorpej #define	pdei(VA)	(((VA) & PD_MASK) >> PDSHIFT)
    190       1.40   thorpej #define	ptei(VA)	(((VA) & PT_MASK) >> PGSHIFT)
    191        1.1       cgd 
    192        1.1       cgd /*
    193       1.40   thorpej  * PTP macros:
    194       1.40   thorpej  *   a PTP's index is the PD index of the PDE that points to it
    195       1.40   thorpej  *   a PTP's offset is the byte-offset in the PTE space that this PTP is at
    196       1.40   thorpej  *   a PTP's VA is the first VA mapped by that PTP
    197       1.40   thorpej  *
    198       1.71   thorpej  * note that PAGE_SIZE == number of bytes in a PTP (4096 bytes == 1024 entries)
    199       1.40   thorpej  *           NBPD == number of bytes a PTP can map (4MB)
    200        1.1       cgd  */
    201       1.39   thorpej 
    202       1.71   thorpej #define ptp_i2o(I)	((I) * PAGE_SIZE)	/* index => offset */
    203       1.71   thorpej #define ptp_o2i(O)	((O) / PAGE_SIZE)	/* offset => index */
    204       1.40   thorpej #define ptp_i2v(I)	((I) * NBPD)	/* index => VA */
    205       1.40   thorpej #define ptp_v2i(V)	((V) / NBPD)	/* VA => index (same as pdei) */
    206       1.39   thorpej 
    207       1.40   thorpej /*
    208       1.40   thorpej  * PG_AVAIL usage: we make use of the ignored bits of the PTE
    209       1.40   thorpej  */
    210       1.40   thorpej 
    211       1.40   thorpej #define PG_W		PG_AVAIL1	/* "wired" mapping */
    212       1.40   thorpej #define PG_PVLIST	PG_AVAIL2	/* mapping has entry on pvlist */
    213       1.75       chs #define PG_X		PG_AVAIL3	/* executable mapping */
    214       1.40   thorpej 
    215       1.65      fvdl /*
    216       1.65      fvdl  * Number of PTE's per cache line.  4 byte pte, 32-byte cache line
    217       1.65      fvdl  * Used to avoid false sharing of cache lines.
    218       1.65      fvdl  */
    219       1.65      fvdl #define NPTECL			8
    220       1.65      fvdl 
    221       1.40   thorpej #ifdef _KERNEL
    222       1.40   thorpej /*
    223       1.40   thorpej  * pmap data structures: see pmap.c for details of locking.
    224       1.40   thorpej  */
    225       1.40   thorpej 
    226       1.40   thorpej struct pmap;
    227       1.40   thorpej typedef struct pmap *pmap_t;
    228       1.40   thorpej 
    229       1.40   thorpej /*
    230       1.40   thorpej  * we maintain a list of all non-kernel pmaps
    231       1.40   thorpej  */
    232       1.40   thorpej 
    233       1.40   thorpej LIST_HEAD(pmap_head, pmap); /* struct pmap_head: head of a pmap list */
    234       1.40   thorpej 
    235       1.40   thorpej /*
    236       1.40   thorpej  * the pmap structure
    237       1.40   thorpej  *
    238       1.40   thorpej  * note that the pm_obj contains the simple_lock, the reference count,
    239       1.40   thorpej  * page list, and number of PTPs within the pmap.
    240       1.65      fvdl  *
    241       1.65      fvdl  * XXX If we ever support processor numbers higher than 31, we'll have
    242       1.65      fvdl  * XXX to rethink the CPU mask.
    243       1.40   thorpej  */
    244       1.40   thorpej 
    245       1.40   thorpej struct pmap {
    246       1.41       chs 	struct uvm_object pm_obj;	/* object (lck by object lock) */
    247       1.40   thorpej #define	pm_lock	pm_obj.vmobjlock
    248       1.41       chs 	LIST_ENTRY(pmap) pm_list;	/* list (lck by pm_list lock) */
    249       1.41       chs 	pd_entry_t *pm_pdir;		/* VA of PD (lck by object lock) */
    250       1.85     perry 	uint32_t pm_pdirpa;		/* PA of PD (read-only after create) */
    251       1.41       chs 	struct vm_page *pm_ptphint;	/* pointer to a PTP in our pmap */
    252       1.41       chs 	struct pmap_statistics pm_stats;  /* pmap stats (lck by object lock) */
    253       1.41       chs 
    254       1.75       chs 	vaddr_t pm_hiexec;		/* highest executable mapping */
    255       1.41       chs 	int pm_flags;			/* see below */
    256       1.41       chs 
    257       1.41       chs 	union descriptor *pm_ldt;	/* user-set LDT */
    258       1.41       chs 	int pm_ldt_len;			/* number of LDT entries */
    259       1.41       chs 	int pm_ldt_sel;			/* LDT selector */
    260       1.85     perry 	uint32_t pm_cpus;		/* mask of CPUs using pmap */
    261  1.89.20.1  jmcneill 	uint32_t pm_kernel_cpus;	/* mask of CPUs using kernel part
    262  1.89.20.1  jmcneill 					 of pmap */
    263       1.40   thorpej };
    264        1.1       cgd 
    265       1.39   thorpej /* pm_flags */
    266       1.39   thorpej #define	PMF_USER_LDT	0x01	/* pmap has user-set LDT */
    267       1.39   thorpej 
    268        1.1       cgd /*
    269       1.40   thorpej  * for each managed physical page we maintain a list of <PMAP,VA>'s
    270       1.41       chs  * which it is mapped at.  the list is headed by a pv_head structure.
    271       1.40   thorpej  * there is one pv_head per managed phys page (allocated at boot time).
    272       1.40   thorpej  * the pv_head structure points to a list of pv_entry structures (each
    273       1.40   thorpej  * describes one mapping).
    274        1.1       cgd  */
    275       1.40   thorpej 
    276       1.41       chs struct pv_entry {			/* locked by its list's pvh_lock */
    277       1.77       chs 	SPLAY_ENTRY(pv_entry) pv_node;	/* splay-tree node */
    278       1.41       chs 	struct pmap *pv_pmap;		/* the pmap */
    279       1.41       chs 	vaddr_t pv_va;			/* the virtual address */
    280       1.41       chs 	struct vm_page *pv_ptp;		/* the vm_page of the PTP */
    281  1.89.20.1  jmcneill 	struct pmap_cpu *pv_alloc_cpu;	/* CPU allocated from */
    282       1.11   mycroft };
    283       1.11   mycroft 
    284       1.40   thorpej /*
    285       1.40   thorpej  * pv_entrys are dynamically allocated in chunks from a single page.
    286       1.40   thorpej  * we keep track of how many pv_entrys are in use for each page and
    287       1.41       chs  * we can free pv_entry pages if needed.  there is one lock for the
    288       1.40   thorpej  * entire allocation system.
    289       1.40   thorpej  */
    290       1.11   mycroft 
    291       1.11   mycroft struct pv_page_info {
    292       1.41       chs 	TAILQ_ENTRY(pv_page) pvpi_list;
    293       1.41       chs 	struct pv_entry *pvpi_pvfree;
    294       1.41       chs 	int pvpi_nfree;
    295       1.11   mycroft };
    296        1.1       cgd 
    297       1.11   mycroft /*
    298       1.40   thorpej  * number of pv_entry's in a pv_page
    299       1.40   thorpej  * (note: won't work on systems where NPBG isn't a constant)
    300       1.40   thorpej  */
    301       1.40   thorpej 
    302       1.71   thorpej #define PVE_PER_PVPAGE ((PAGE_SIZE - sizeof(struct pv_page_info)) / \
    303       1.41       chs 			sizeof(struct pv_entry))
    304       1.40   thorpej 
    305       1.40   thorpej /*
    306       1.40   thorpej  * a pv_page: where pv_entrys are allocated from
    307       1.11   mycroft  */
    308        1.1       cgd 
    309       1.11   mycroft struct pv_page {
    310       1.41       chs 	struct pv_page_info pvinfo;
    311       1.41       chs 	struct pv_entry pvents[PVE_PER_PVPAGE];
    312       1.40   thorpej };
    313       1.40   thorpej 
    314       1.40   thorpej /*
    315       1.40   thorpej  * global kernel variables
    316       1.40   thorpej  */
    317       1.40   thorpej 
    318       1.82  junyoung /* PDPpaddr: is the physical address of the kernel's PDP */
    319       1.82  junyoung extern u_long PDPpaddr;
    320       1.40   thorpej 
    321       1.40   thorpej extern struct pmap kernel_pmap_store;	/* kernel pmap */
    322       1.40   thorpej extern int nkpde;			/* current # of PDEs for kernel */
    323       1.40   thorpej extern int pmap_pg_g;			/* do we support PG_G? */
    324       1.40   thorpej 
    325       1.40   thorpej /*
    326       1.40   thorpej  * macros
    327       1.40   thorpej  */
    328        1.1       cgd 
    329       1.18   mycroft #define	pmap_kernel()			(&kernel_pmap_store)
    330        1.1       cgd #define	pmap_resident_count(pmap)	((pmap)->pm_stats.resident_count)
    331       1.50        is #define	pmap_wired_count(pmap)		((pmap)->pm_stats.wired_count)
    332       1.11   mycroft 
    333       1.65      fvdl #define pmap_clear_modify(pg)		pmap_clear_attrs(pg, PG_M)
    334       1.65      fvdl #define pmap_clear_reference(pg)	pmap_clear_attrs(pg, PG_U)
    335       1.65      fvdl #define pmap_copy(DP,SP,D,L,S)
    336       1.40   thorpej #define pmap_is_modified(pg)		pmap_test_attrs(pg, PG_M)
    337       1.40   thorpej #define pmap_is_referenced(pg)		pmap_test_attrs(pg, PG_U)
    338       1.65      fvdl #define pmap_move(DP,SP,D,L,S)
    339       1.69      fvdl #define pmap_phys_address(ppn)		x86_ptob(ppn)
    340       1.40   thorpej #define pmap_valid_entry(E) 		((E) & PG_V) /* is PDE or PTE valid? */
    341       1.40   thorpej 
    342       1.40   thorpej 
    343       1.40   thorpej /*
    344       1.40   thorpej  * prototypes
    345       1.40   thorpej  */
    346       1.40   thorpej 
    347       1.78  junyoung void		pmap_activate(struct lwp *);
    348       1.78  junyoung void		pmap_bootstrap(vaddr_t);
    349       1.89   thorpej bool		pmap_clear_attrs(struct vm_page *, int);
    350       1.78  junyoung void		pmap_deactivate(struct lwp *);
    351       1.79      yamt void		pmap_deactivate2(struct lwp *);
    352       1.78  junyoung void		pmap_page_remove (struct vm_page *);
    353       1.78  junyoung void		pmap_remove(struct pmap *, vaddr_t, vaddr_t);
    354       1.89   thorpej bool		pmap_test_attrs(struct vm_page *, int);
    355       1.78  junyoung void		pmap_write_protect(struct pmap *, vaddr_t, vaddr_t, vm_prot_t);
    356       1.75       chs int		pmap_exec_fixup(struct vm_map *, struct trapframe *,
    357       1.75       chs 		    struct pcb *);
    358       1.79      yamt void		pmap_load(void);
    359  1.89.20.2     joerg paddr_t		pmap_init_tmp_pgtbl(paddr_t);
    360       1.40   thorpej 
    361       1.78  junyoung vaddr_t reserve_dumppages(vaddr_t); /* XXX: not a pmap fn */
    362       1.40   thorpej 
    363  1.89.20.1  jmcneill void	pmap_tlb_shootdown(pmap_t, vaddr_t, vaddr_t, pt_entry_t);
    364  1.89.20.1  jmcneill void	pmap_tlb_shootwait(void);
    365       1.65      fvdl 
    366       1.40   thorpej #define PMAP_GROWKERNEL		/* turn on pmap_growkernel interface */
    367       1.44   thorpej 
    368       1.44   thorpej /*
    369       1.44   thorpej  * Do idle page zero'ing uncached to avoid polluting the cache.
    370       1.44   thorpej  */
    371       1.89   thorpej bool	pmap_pageidlezero(paddr_t);
    372       1.56   thorpej #define	PMAP_PAGEIDLEZERO(pa)	pmap_pageidlezero((pa))
    373       1.40   thorpej 
    374       1.40   thorpej /*
    375       1.40   thorpej  * inline functions
    376       1.40   thorpej  */
    377       1.63       chs 
    378       1.66     perry /*ARGSUSED*/
    379       1.86     perry static __inline void
    380       1.88  christos pmap_remove_all(struct pmap *pmap)
    381       1.63       chs {
    382       1.63       chs 	/* Nothing. */
    383       1.63       chs }
    384       1.40   thorpej 
    385       1.40   thorpej /*
    386       1.40   thorpej  * pmap_update_pg: flush one page from the TLB (or flush the whole thing
    387       1.40   thorpej  *	if hardware doesn't support one-page flushing)
    388       1.40   thorpej  */
    389       1.40   thorpej 
    390       1.86     perry __inline static void __attribute__((__unused__))
    391       1.62   thorpej pmap_update_pg(vaddr_t va)
    392       1.11   mycroft {
    393       1.40   thorpej #if defined(I386_CPU)
    394       1.41       chs 	if (cpu_class == CPUCLASS_386)
    395       1.52   thorpej 		tlbflush();
    396       1.41       chs 	else
    397       1.40   thorpej #endif
    398       1.41       chs 		invlpg((u_int) va);
    399       1.11   mycroft }
    400       1.11   mycroft 
    401       1.40   thorpej /*
    402       1.40   thorpej  * pmap_update_2pg: flush two pages from the TLB
    403       1.40   thorpej  */
    404       1.40   thorpej 
    405       1.86     perry __inline static void __attribute__((__unused__))
    406       1.62   thorpej pmap_update_2pg(vaddr_t va, vaddr_t vb)
    407       1.11   mycroft {
    408       1.40   thorpej #if defined(I386_CPU)
    409       1.41       chs 	if (cpu_class == CPUCLASS_386)
    410       1.52   thorpej 		tlbflush();
    411       1.41       chs 	else
    412       1.40   thorpej #endif
    413       1.41       chs 	{
    414       1.41       chs 		invlpg((u_int) va);
    415       1.41       chs 		invlpg((u_int) vb);
    416       1.41       chs 	}
    417       1.11   mycroft }
    418       1.11   mycroft 
    419       1.40   thorpej /*
    420       1.40   thorpej  * pmap_page_protect: change the protection of all recorded mappings
    421       1.40   thorpej  *	of a managed page
    422       1.40   thorpej  *
    423       1.65      fvdl  * => this function is a frontend for pmap_page_remove/pmap_clear_attrs
    424       1.40   thorpej  * => we only have to worry about making the page more protected.
    425       1.40   thorpej  *	unprotecting a page is done on-demand at fault time.
    426       1.40   thorpej  */
    427       1.40   thorpej 
    428       1.86     perry __inline static void __attribute__((__unused__))
    429       1.62   thorpej pmap_page_protect(struct vm_page *pg, vm_prot_t prot)
    430       1.11   mycroft {
    431       1.41       chs 	if ((prot & VM_PROT_WRITE) == 0) {
    432       1.41       chs 		if (prot & (VM_PROT_READ|VM_PROT_EXECUTE)) {
    433       1.65      fvdl 			(void) pmap_clear_attrs(pg, PG_RW);
    434       1.41       chs 		} else {
    435       1.41       chs 			pmap_page_remove(pg);
    436       1.41       chs 		}
    437       1.41       chs 	}
    438       1.11   mycroft }
    439       1.11   mycroft 
    440       1.40   thorpej /*
    441       1.40   thorpej  * pmap_protect: change the protection of pages in a pmap
    442       1.40   thorpej  *
    443       1.40   thorpej  * => this function is a frontend for pmap_remove/pmap_write_protect
    444       1.40   thorpej  * => we only have to worry about making the page more protected.
    445       1.40   thorpej  *	unprotecting a page is done on-demand at fault time.
    446       1.40   thorpej  */
    447       1.40   thorpej 
    448       1.86     perry __inline static void __attribute__((__unused__))
    449       1.62   thorpej pmap_protect(struct pmap *pmap, vaddr_t sva, vaddr_t eva, vm_prot_t prot)
    450       1.11   mycroft {
    451       1.41       chs 	if ((prot & VM_PROT_WRITE) == 0) {
    452       1.41       chs 		if (prot & (VM_PROT_READ|VM_PROT_EXECUTE)) {
    453       1.41       chs 			pmap_write_protect(pmap, sva, eva, prot);
    454       1.41       chs 		} else {
    455       1.41       chs 			pmap_remove(pmap, sva, eva);
    456       1.41       chs 		}
    457       1.41       chs 	}
    458       1.47   thorpej }
    459       1.47   thorpej 
    460       1.47   thorpej /*
    461       1.47   thorpej  * various address inlines
    462       1.47   thorpej  *
    463       1.47   thorpej  *  vtopte: return a pointer to the PTE mapping a VA, works only for
    464       1.47   thorpej  *  user and PT addresses
    465       1.47   thorpej  *
    466       1.47   thorpej  *  kvtopte: return a pointer to the PTE mapping a kernel VA
    467       1.47   thorpej  */
    468       1.47   thorpej 
    469       1.47   thorpej #include <lib/libkern/libkern.h>
    470       1.47   thorpej 
    471       1.86     perry static __inline pt_entry_t * __attribute__((__unused__))
    472       1.47   thorpej vtopte(vaddr_t va)
    473       1.47   thorpej {
    474       1.47   thorpej 
    475       1.47   thorpej 	KASSERT(va < (PDSLOT_KERN << PDSHIFT));
    476       1.47   thorpej 
    477       1.69      fvdl 	return (PTE_BASE + x86_btop(va));
    478       1.47   thorpej }
    479       1.47   thorpej 
    480       1.86     perry static __inline pt_entry_t * __attribute__((__unused__))
    481       1.47   thorpej kvtopte(vaddr_t va)
    482       1.47   thorpej {
    483       1.47   thorpej 
    484       1.47   thorpej 	KASSERT(va >= (PDSLOT_KERN << PDSHIFT));
    485       1.48   thorpej 
    486       1.48   thorpej #ifdef LARGEPAGES
    487       1.48   thorpej 	{
    488       1.48   thorpej 		pd_entry_t *pde;
    489       1.48   thorpej 
    490       1.51       chs 		pde = PDP_BASE + pdei(va);
    491       1.48   thorpej 		if (*pde & PG_PS)
    492       1.48   thorpej 			return ((pt_entry_t *)pde);
    493       1.48   thorpej 	}
    494       1.48   thorpej #endif
    495       1.47   thorpej 
    496       1.69      fvdl 	return (PTE_BASE + x86_btop(va));
    497       1.41       chs }
    498       1.70      fvdl 
    499  1.89.20.1  jmcneill #define pmap_pte_set(p, n)		x86_atomic_testset_ul(p, n)
    500  1.89.20.1  jmcneill #define pmap_pte_setbits(p, b)		x86_atomic_setbits_l(p, b)
    501  1.89.20.1  jmcneill #define pmap_pte_clearbits(p, b)	x86_atomic_clearbits_l(p, b)
    502       1.70      fvdl #define pmap_cpu_has_pg_n()		(cpu_class != CPUCLASS_386)
    503       1.70      fvdl #define pmap_cpu_has_invlpg()		(cpu_class != CPUCLASS_386)
    504       1.35       cgd 
    505       1.78  junyoung paddr_t vtophys(vaddr_t);
    506       1.78  junyoung vaddr_t	pmap_map(vaddr_t, paddr_t, paddr_t, vm_prot_t);
    507       1.78  junyoung void	pmap_ldt_cleanup(struct lwp *);
    508  1.89.20.1  jmcneill void	pmap_cpu_init_early(struct cpu_info *);
    509  1.89.20.1  jmcneill void	pmap_cpu_init_late(struct cpu_info *);
    510  1.89.20.1  jmcneill void	sse2_zero_page(void *);
    511  1.89.20.1  jmcneill void	sse2_copy_page(void *, void *);
    512       1.73   thorpej 
    513       1.83  junyoung /*
    514       1.73   thorpej  * Hooks for the pool allocator.
    515       1.73   thorpej  */
    516       1.73   thorpej #define	POOL_VTOPHYS(va)	vtophys((vaddr_t) (va))
    517        1.1       cgd 
    518  1.89.20.1  jmcneill /*
    519  1.89.20.1  jmcneill  * TLB shootdown mailbox.
    520  1.89.20.1  jmcneill  */
    521  1.89.20.1  jmcneill 
    522  1.89.20.1  jmcneill struct pmap_mbox {
    523  1.89.20.1  jmcneill 	volatile void		*mb_pointer;
    524  1.89.20.1  jmcneill 	volatile uintptr_t	mb_addr1;
    525  1.89.20.1  jmcneill 	volatile uintptr_t	mb_addr2;
    526  1.89.20.1  jmcneill 	volatile uintptr_t	mb_head;
    527  1.89.20.1  jmcneill 	volatile uintptr_t	mb_tail;
    528  1.89.20.1  jmcneill 	volatile uintptr_t	mb_global;
    529  1.89.20.1  jmcneill };
    530  1.89.20.1  jmcneill 
    531       1.40   thorpej #endif /* _KERNEL */
    532       1.40   thorpej #endif	/* _I386_PMAP_H_ */
    533