Home | History | Annotate | Line # | Download | only in include
pmap.h revision 1.40
      1  1.40   thorpej /*	$NetBSD: pmap.h,v 1.40 1999/06/17 00:12:12 thorpej 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.34       mrg #if defined(_KERNEL) && !defined(_LKM)
     43  1.39   thorpej #include "opt_user_ldt.h"
     44  1.34       mrg #endif
     45   1.1       cgd 
     46  1.14   mycroft #include <machine/cpufunc.h>
     47   1.6   mycroft #include <machine/pte.h>
     48  1.39   thorpej #include <machine/segments.h>
     49  1.40   thorpej #include <uvm/uvm_object.h>
     50   1.1       cgd 
     51   1.1       cgd /*
     52  1.40   thorpej  * see pte.h for a description of i386 MMU terminology and hardware
     53  1.40   thorpej  * interface.
     54  1.40   thorpej  *
     55  1.40   thorpej  * a pmap describes a processes' 4GB virtual address space.  this
     56  1.40   thorpej  * virtual address space can be broken up into 1024 4MB regions which
     57  1.40   thorpej  * are described by PDEs in the PDP.   the PDEs are defined as follows:
     58  1.40   thorpej  *
     59  1.40   thorpej  * (ranges are inclusive -> exclusive, just like vm_map_entry start/end)
     60  1.40   thorpej  * (the following assumes that KERNBASE is 0xf0000000)
     61  1.40   thorpej  *
     62  1.40   thorpej  * PDE#s	VA range		usage
     63  1.40   thorpej  * 0->959	0x0 -> 0xefc00000	user address space, note that the
     64  1.40   thorpej  *					max user address is 0xefbfe000
     65  1.40   thorpej  *					the final two pages in the last 4MB
     66  1.40   thorpej  *					used to be reserved for the UAREA
     67  1.40   thorpej  *					but now are no longer used
     68  1.40   thorpej  * 959		0xefc00000->		recursive mapping of PDP (used for
     69  1.40   thorpej  *			0xf0000000	linear mapping of PTPs)
     70  1.40   thorpej  * 960->1023	0xf0000000->		kernel address space (constant
     71  1.40   thorpej  *			0xffc00000	across all pmap's/processes)
     72  1.40   thorpej  * 1023		0xffc00000->		"alternate" recursive PDP mapping
     73  1.40   thorpej  *			<end>		(for other pmaps)
     74  1.40   thorpej  *
     75  1.40   thorpej  *
     76  1.40   thorpej  * note: a recursive PDP mapping provides a way to map all the PTEs for
     77  1.40   thorpej  * a 4GB address space into a linear chunk of virtual memory.   in other
     78  1.40   thorpej  * words, the PTE for page 0 is the first int mapped into the 4MB recursive
     79  1.40   thorpej  * area.   the PTE for page 1 is the second int.    the very last int in the
     80  1.40   thorpej  * 4MB range is the PTE that maps VA 0xffffe000 (the last page in a 4GB
     81  1.40   thorpej  * address).
     82  1.40   thorpej  *
     83  1.40   thorpej  * all pmap's PD's must have the same values in slots 960->1023 so that
     84  1.40   thorpej  * the kernel is always mapped in every process.   these values are loaded
     85  1.40   thorpej  * into the PD at pmap creation time.
     86  1.40   thorpej  *
     87  1.40   thorpej  * at any one time only one pmap can be active on a processor.   this is
     88  1.40   thorpej  * the pmap whose PDP is pointed to by processor register %cr3.   this pmap
     89  1.40   thorpej  * will have all its PTEs mapped into memory at the recursive mapping
     90  1.40   thorpej  * point (slot #959 as show above).   when the pmap code wants to find the
     91  1.40   thorpej  * PTE for a virtual address, all it has to do is the following:
     92  1.40   thorpej  *
     93  1.40   thorpej  * address of PTE = (959 * 4MB) + (VA / NBPG) * sizeof(pt_entry_t)
     94  1.40   thorpej  *                = 0xefc00000 + (VA /4096) * 4
     95  1.40   thorpej  *
     96  1.40   thorpej  * what happens if the pmap layer is asked to perform an operation
     97  1.40   thorpej  * on a pmap that is not the one which is currently active?   in that
     98  1.40   thorpej  * case we take the PA of the PDP of non-active pmap and put it in
     99  1.40   thorpej  * slot 1023 of the active pmap.   this causes the non-active pmap's
    100  1.40   thorpej  * PTEs to get mapped in the final 4MB of the 4GB address space
    101  1.40   thorpej  * (e.g. starting at 0xffc00000).
    102  1.40   thorpej  *
    103  1.40   thorpej  * the following figure shows the effects of the recursive PDP mapping:
    104  1.40   thorpej  *
    105  1.40   thorpej  *   PDP (%cr3)
    106  1.40   thorpej  *   +----+
    107  1.40   thorpej  *   |   0| -> PTP#0 that maps VA 0x0 -> 0x400000
    108  1.40   thorpej  *   |    |
    109  1.40   thorpej  *   |    |
    110  1.40   thorpej  *   | 959| -> points back to PDP (%cr3) mapping VA 0xefc00000 -> 0xf0000000
    111  1.40   thorpej  *   | 960| -> first kernel PTP (maps 0xf0000000 -> 0xf0400000)
    112  1.40   thorpej  *   |    |
    113  1.40   thorpej  *   |1023| -> points to alternate pmap's PDP (maps 0xffc00000 -> end)
    114  1.40   thorpej  *   +----+
    115  1.40   thorpej  *
    116  1.40   thorpej  * note that the PDE#959 VA (0xefc00000) is defined as "PTE_BASE"
    117  1.40   thorpej  * note that the PDE#1023 VA (0xffc00000) is defined as "APTE_BASE"
    118  1.40   thorpej  *
    119  1.40   thorpej  * starting at VA 0xefc00000 the current active PDP (%cr3) acts as a
    120  1.40   thorpej  * PTP:
    121  1.40   thorpej  *
    122  1.40   thorpej  * PTP#959 == PDP(%cr3) => maps VA 0xefc00000 -> 0xf0000000
    123  1.40   thorpej  *   +----+
    124  1.40   thorpej  *   |   0| -> maps the contents of PTP#0 at VA 0xefc00000->0xefc01000
    125  1.40   thorpej  *   |    |
    126  1.40   thorpej  *   |    |
    127  1.40   thorpej  *   | 959| -> maps contents of PTP#959 (the PDP) at VA 0xeffbf000
    128  1.40   thorpej  *   | 960| -> maps contents of first kernel PTP
    129  1.40   thorpej  *   |    |
    130  1.40   thorpej  *   |1023|
    131  1.40   thorpej  *   +----+
    132  1.40   thorpej  *
    133  1.40   thorpej  * note that mapping of the PDP at PTP#959's VA (0xeffbf000) is
    134  1.40   thorpej  * defined as "PDP_BASE".... within that mapping there are two
    135  1.40   thorpej  * defines:
    136  1.40   thorpej  *   "PDP_PDE" (0xeffbfefc) is the VA of the PDE in the PDP
    137  1.40   thorpej  *      which points back to itself.
    138  1.40   thorpej  *   "APDP_PDE" (0xeffbfffc) is the VA of the PDE in the PDP which
    139  1.40   thorpej  *      establishes the recursive mapping of the alternate pmap.
    140  1.40   thorpej  *      to set the alternate PDP, one just has to put the correct
    141  1.40   thorpej  *	PA info in *APDP_PDE.
    142  1.40   thorpej  *
    143  1.40   thorpej  * note that in the APTE_BASE space, the APDP appears at VA
    144  1.40   thorpej  * "APDP_BASE" (0xfffff000).
    145   1.1       cgd  */
    146  1.33       mrg 
    147  1.33       mrg /*
    148  1.40   thorpej  * the following defines identify the slots used as described above.
    149  1.33       mrg  */
    150  1.33       mrg 
    151  1.40   thorpej #define PDSLOT_PTE	((KERNBASE/NBPD)-1) /* 959: for recursive PDP map */
    152  1.40   thorpej #define PDSLOT_KERN	(KERNBASE/NBPD)	    /* 960: start of kernel space */
    153  1.40   thorpej #define PDSLOT_APTE	((unsigned)1023) /* 1023: alternative recursive slot */
    154   1.1       cgd 
    155   1.1       cgd /*
    156  1.40   thorpej  * the following defines give the virtual addresses of various MMU
    157  1.40   thorpej  * data structures:
    158  1.40   thorpej  * PTE_BASE and APTE_BASE: the base VA of the linear PTE mappings
    159  1.40   thorpej  * PTD_BASE and APTD_BASE: the base VA of the recursive mapping of the PTD
    160  1.40   thorpej  * PDP_PDE and APDP_PDE: the VA of the PDE that points back to the PDP/APDP
    161   1.1       cgd  */
    162  1.29      fvdl 
    163  1.40   thorpej #define PTE_BASE	((pt_entry_t *)  (PDSLOT_PTE * NBPD) )
    164  1.40   thorpej #define APTE_BASE	((pt_entry_t *)  (PDSLOT_APTE * NBPD) )
    165  1.40   thorpej #define PDP_BASE ((pd_entry_t *)  (((char *)PTE_BASE)  + (PDSLOT_PTE * NBPG)) )
    166  1.40   thorpej #define APDP_BASE ((pd_entry_t *)  (((char *)APTE_BASE)  + (PDSLOT_APTE * NBPG)) )
    167  1.40   thorpej #define PDP_PDE		(PDP_BASE + PDSLOT_PTE)
    168  1.40   thorpej #define APDP_PDE	(PDP_BASE + PDSLOT_APTE)
    169   1.1       cgd 
    170   1.1       cgd /*
    171  1.40   thorpej  * XXXCDC: tmp xlate from old names:
    172  1.40   thorpej  * PTDPTDI -> PDSLOT_PTE
    173  1.40   thorpej  * KPTDI -> PDSLOT_KERN
    174  1.40   thorpej  * APTDPTDI -> PDSLOT_APTE
    175   1.1       cgd  */
    176  1.40   thorpej 
    177  1.40   thorpej /*
    178  1.40   thorpej  * the follow define determines how many PTPs should be set up for the
    179  1.40   thorpej  * kernel by locore.s at boot time.   this should be large enough to
    180  1.40   thorpej  * get the VM system running.   once the VM system is running, the
    181  1.40   thorpej  * pmap module can add more PTPs to the kernel area on demand.
    182  1.40   thorpej  */
    183  1.40   thorpej 
    184  1.40   thorpej #ifndef NKPTP
    185  1.40   thorpej #define NKPTP		4	/* 16MB to start */
    186   1.1       cgd #endif
    187  1.40   thorpej #define NKPTP_MIN	4	/* smallest value we allow */
    188  1.40   thorpej #define NKPTP_MAX	(1024 - (KERNBASE/NBPD) - 1)
    189  1.40   thorpej 				/* largest value (-1 for APTP space) */
    190   1.1       cgd 
    191   1.1       cgd /*
    192  1.40   thorpej  * various address macros
    193  1.40   thorpej  *
    194  1.40   thorpej  *  vtopte: return a pointer to the PTE mapping a VA
    195  1.40   thorpej  *  kvtopte: same as above (takes a KVA, but doesn't matter with this pmap)
    196  1.40   thorpej  *  ptetov: given a pointer to a PTE, return the VA that it maps
    197  1.40   thorpej  *  vtophys: translate a VA to the PA mapped to it
    198  1.40   thorpej  *
    199  1.40   thorpej  * plus alternative versions of the above
    200   1.1       cgd  */
    201   1.1       cgd 
    202  1.40   thorpej #define vtopte(VA)	(PTE_BASE + i386_btop(VA))
    203  1.40   thorpej #define kvtopte(VA)	vtopte(VA)
    204  1.40   thorpej #define ptetov(PT)	(i386_ptob(PT - PTE_BASE))
    205  1.40   thorpej #define	vtophys(VA) ((*vtopte(VA) & PG_FRAME) | ((unsigned)(VA) & ~PG_FRAME))
    206  1.40   thorpej #define	avtopte(VA)	(APTE_BASE + i386_btop(VA))
    207  1.40   thorpej #define	ptetoav(PT)	(i386_ptob(PT - APTE_BASE))
    208  1.40   thorpej #define	avtophys(VA) ((*avtopte(VA) & PG_FRAME) | ((unsigned)(VA) & ~PG_FRAME))
    209   1.1       cgd 
    210   1.1       cgd /*
    211  1.40   thorpej  * pdei/ptei: generate index into PDP/PTP from a VA
    212   1.1       cgd  */
    213  1.40   thorpej #define	pdei(VA)	(((VA) & PD_MASK) >> PDSHIFT)
    214  1.40   thorpej #define	ptei(VA)	(((VA) & PT_MASK) >> PGSHIFT)
    215   1.1       cgd 
    216   1.1       cgd /*
    217  1.40   thorpej  * PTP macros:
    218  1.40   thorpej  *   a PTP's index is the PD index of the PDE that points to it
    219  1.40   thorpej  *   a PTP's offset is the byte-offset in the PTE space that this PTP is at
    220  1.40   thorpej  *   a PTP's VA is the first VA mapped by that PTP
    221  1.40   thorpej  *
    222  1.40   thorpej  * note that NBPG == number of bytes in a PTP (4096 bytes == 1024 entries)
    223  1.40   thorpej  *           NBPD == number of bytes a PTP can map (4MB)
    224   1.1       cgd  */
    225  1.39   thorpej 
    226  1.40   thorpej #define ptp_i2o(I)	((I) * NBPG)	/* index => offset */
    227  1.40   thorpej #define ptp_o2i(O)	((O) / NBPG)	/* offset => index */
    228  1.40   thorpej #define ptp_i2v(I)	((I) * NBPD)	/* index => VA */
    229  1.40   thorpej #define ptp_v2i(V)	((V) / NBPD)	/* VA => index (same as pdei) */
    230  1.39   thorpej 
    231  1.40   thorpej /*
    232  1.40   thorpej  * PG_AVAIL usage: we make use of the ignored bits of the PTE
    233  1.40   thorpej  */
    234  1.40   thorpej 
    235  1.40   thorpej #define PG_W		PG_AVAIL1	/* "wired" mapping */
    236  1.40   thorpej #define PG_PVLIST	PG_AVAIL2	/* mapping has entry on pvlist */
    237  1.40   thorpej /* PG_AVAIL3 not used */
    238  1.40   thorpej 
    239  1.40   thorpej #ifdef _KERNEL
    240  1.40   thorpej /*
    241  1.40   thorpej  * pmap data structures: see pmap.c for details of locking.
    242  1.40   thorpej  */
    243  1.40   thorpej 
    244  1.40   thorpej struct pmap;
    245  1.40   thorpej typedef struct pmap *pmap_t;
    246  1.40   thorpej 
    247  1.40   thorpej /*
    248  1.40   thorpej  * we maintain a list of all non-kernel pmaps
    249  1.40   thorpej  */
    250  1.40   thorpej 
    251  1.40   thorpej LIST_HEAD(pmap_head, pmap); /* struct pmap_head: head of a pmap list */
    252  1.40   thorpej 
    253  1.40   thorpej /*
    254  1.40   thorpej  * the pmap structure
    255  1.40   thorpej  *
    256  1.40   thorpej  * note that the pm_obj contains the simple_lock, the reference count,
    257  1.40   thorpej  * page list, and number of PTPs within the pmap.
    258  1.40   thorpej  */
    259  1.40   thorpej 
    260  1.40   thorpej struct pmap {
    261  1.40   thorpej   struct uvm_object pm_obj;	/* object (lck by object lock) */
    262  1.40   thorpej #define	pm_lock	pm_obj.vmobjlock
    263  1.40   thorpej   LIST_ENTRY(pmap) pm_list;	/* list (lck by pm_list lock) */
    264  1.40   thorpej   pd_entry_t *pm_pdir;		/* VA of PD (lck by object lock) */
    265  1.40   thorpej   u_int32_t pm_pdirpa;		/* PA of PD (read-only after create) */
    266  1.40   thorpej   struct vm_page *pm_ptphint;	/* pointer to a random PTP in our pmap */
    267  1.40   thorpej   struct pmap_statistics pm_stats;  /* pmap stats (lck by object lock) */
    268  1.40   thorpej 
    269  1.40   thorpej   int pm_flags;			/* see below */
    270  1.40   thorpej 
    271  1.40   thorpej   union descriptor *pm_ldt;	/* user-set LDT */
    272  1.40   thorpej   int pm_ldt_len;		/* number of LDT entries */
    273  1.40   thorpej   int pm_ldt_sel;		/* LDT selector */
    274  1.40   thorpej };
    275   1.1       cgd 
    276  1.39   thorpej /* pm_flags */
    277  1.39   thorpej #define	PMF_USER_LDT	0x01	/* pmap has user-set LDT */
    278  1.39   thorpej 
    279   1.1       cgd /*
    280  1.40   thorpej  * for each managed physical page we maintain a list of <PMAP,VA>'s
    281  1.40   thorpej  * which it is mapped at.   the list is headed by a pv_head structure.
    282  1.40   thorpej  * there is one pv_head per managed phys page (allocated at boot time).
    283  1.40   thorpej  * the pv_head structure points to a list of pv_entry structures (each
    284  1.40   thorpej  * describes one mapping).
    285   1.1       cgd  */
    286  1.40   thorpej 
    287  1.40   thorpej struct pv_entry;
    288  1.40   thorpej 
    289  1.40   thorpej struct pv_head {
    290  1.40   thorpej   simple_lock_data_t pvh_lock;	/* locks every pv on this list */
    291  1.40   thorpej   struct pv_entry *pvh_list;	/* head of list (locked by pvh_lock) */
    292  1.40   thorpej };
    293  1.40   thorpej 
    294  1.40   thorpej struct pv_entry {		/* all fields locked by their pvh_lock */
    295  1.40   thorpej   struct pv_entry *pv_next;	/* next entry */
    296  1.40   thorpej   struct pmap *pv_pmap;		/* the pmap */
    297  1.40   thorpej   vaddr_t pv_va;		/* the virtual address */
    298  1.40   thorpej   struct vm_page *pv_ptp;	/* the vm_page of the PTP */
    299  1.11   mycroft };
    300  1.11   mycroft 
    301  1.40   thorpej /*
    302  1.40   thorpej  * pv_entrys are dynamically allocated in chunks from a single page.
    303  1.40   thorpej  * we keep track of how many pv_entrys are in use for each page and
    304  1.40   thorpej  * we can free pv_entry pages if needed.   there is one lock for the
    305  1.40   thorpej  * entire allocation system.
    306  1.40   thorpej  */
    307  1.11   mycroft 
    308  1.11   mycroft struct pv_page_info {
    309  1.40   thorpej   TAILQ_ENTRY(pv_page) pvpi_list;
    310  1.40   thorpej   struct pv_entry *pvpi_pvfree;
    311  1.40   thorpej   int pvpi_nfree;
    312  1.11   mycroft };
    313   1.1       cgd 
    314  1.11   mycroft /*
    315  1.40   thorpej  * number of pv_entry's in a pv_page
    316  1.40   thorpej  * (note: won't work on systems where NPBG isn't a constant)
    317  1.40   thorpej  */
    318  1.40   thorpej 
    319  1.40   thorpej #define PVE_PER_PVPAGE ( (NBPG - sizeof(struct pv_page_info)) / \
    320  1.40   thorpej 				sizeof(struct pv_entry) )
    321  1.40   thorpej 
    322  1.40   thorpej /*
    323  1.40   thorpej  * a pv_page: where pv_entrys are allocated from
    324  1.11   mycroft  */
    325   1.1       cgd 
    326  1.11   mycroft struct pv_page {
    327  1.40   thorpej   struct pv_page_info pvinfo;
    328  1.40   thorpej   struct pv_entry pvents[PVE_PER_PVPAGE];
    329  1.40   thorpej };
    330  1.40   thorpej 
    331  1.40   thorpej /*
    332  1.40   thorpej  * pmap_remove_record: a record of VAs that have been unmapped, used to
    333  1.40   thorpej  * flush TLB.   if we have more than PMAP_RR_MAX then we stop recording.
    334  1.40   thorpej  */
    335  1.40   thorpej 
    336  1.40   thorpej #define PMAP_RR_MAX	16	/* max of 16 pages (64K) */
    337  1.40   thorpej 
    338  1.40   thorpej struct pmap_remove_record {
    339  1.40   thorpej   int prr_npages;
    340  1.40   thorpej   vaddr_t prr_vas[PMAP_RR_MAX];
    341  1.40   thorpej };
    342  1.40   thorpej 
    343  1.40   thorpej /*
    344  1.40   thorpej  * pmap_transfer_location: used to pass the current location in the
    345  1.40   thorpej  * pmap between pmap_transfer and pmap_transfer_ptes [e.g. during
    346  1.40   thorpej  * a pmap_copy].
    347  1.40   thorpej  */
    348  1.40   thorpej 
    349  1.40   thorpej struct pmap_transfer_location {
    350  1.40   thorpej   vaddr_t addr;			/* the address (page-aligned) */
    351  1.40   thorpej   pt_entry_t *pte;		/* the PTE that maps address */
    352  1.40   thorpej   struct vm_page *ptp;		/* the PTP that the PTE lives in */
    353  1.11   mycroft };
    354   1.1       cgd 
    355  1.40   thorpej /*
    356  1.40   thorpej  * global kernel variables
    357  1.40   thorpej  */
    358  1.40   thorpej 
    359  1.40   thorpej /* PTDpaddr: is the physical address of the kernel's PDP */
    360  1.40   thorpej extern u_long PTDpaddr;
    361  1.40   thorpej 
    362  1.40   thorpej extern struct pmap kernel_pmap_store;	/* kernel pmap */
    363  1.40   thorpej extern int nkpde;			/* current # of PDEs for kernel */
    364  1.40   thorpej extern int pmap_pg_g;			/* do we support PG_G? */
    365  1.40   thorpej 
    366  1.40   thorpej /*
    367  1.40   thorpej  * macros
    368  1.40   thorpej  */
    369   1.1       cgd 
    370  1.18   mycroft #define	pmap_kernel()			(&kernel_pmap_store)
    371   1.1       cgd #define	pmap_resident_count(pmap)	((pmap)->pm_stats.resident_count)
    372  1.13   mycroft #define	pmap_update()			tlbflush()
    373  1.11   mycroft 
    374  1.40   thorpej #define pmap_clear_modify(pg)		pmap_change_attrs(pg, 0, PG_M)
    375  1.40   thorpej #define pmap_clear_reference(pg)	pmap_change_attrs(pg, 0, PG_U)
    376  1.40   thorpej #define pmap_copy(DP,SP,D,L,S)		pmap_transfer(DP,SP,D,L,S, FALSE)
    377  1.40   thorpej #define pmap_is_modified(pg)		pmap_test_attrs(pg, PG_M)
    378  1.40   thorpej #define pmap_is_referenced(pg)		pmap_test_attrs(pg, PG_U)
    379  1.40   thorpej #define pmap_move(DP,SP,D,L,S)		pmap_transfer(DP,SP,D,L,S, TRUE)
    380  1.40   thorpej #define pmap_phys_address(ppn)		i386_ptob(ppn)
    381  1.40   thorpej #define pmap_valid_entry(E) 		((E) & PG_V) /* is PDE or PTE valid? */
    382  1.40   thorpej 
    383  1.40   thorpej 
    384  1.40   thorpej /*
    385  1.40   thorpej  * prototypes
    386  1.40   thorpej  */
    387  1.40   thorpej 
    388  1.40   thorpej void		pmap_activate __P((struct proc *));
    389  1.40   thorpej void		pmap_bootstrap __P((vaddr_t));
    390  1.40   thorpej boolean_t	pmap_change_attrs __P((struct vm_page *, int, int));
    391  1.40   thorpej void		pmap_deactivate __P((struct proc *));
    392  1.40   thorpej static void	pmap_kenter_pa __P((vaddr_t, paddr_t, vm_prot_t));
    393  1.40   thorpej static void	pmap_page_protect __P((struct vm_page *, vm_prot_t));
    394  1.40   thorpej void		pmap_page_remove  __P((struct vm_page *));
    395  1.40   thorpej static void	pmap_protect __P((struct pmap *, vaddr_t,
    396  1.40   thorpej 				vaddr_t, vm_prot_t));
    397  1.40   thorpej void		pmap_remove __P((struct pmap *, vaddr_t, vaddr_t));
    398  1.40   thorpej boolean_t	pmap_test_attrs __P((struct vm_page *, int));
    399  1.40   thorpej void		pmap_transfer __P((struct pmap *, struct pmap *, vaddr_t,
    400  1.40   thorpej 				   vsize_t, vaddr_t, boolean_t));
    401  1.40   thorpej static void	pmap_update_pg __P((vaddr_t));
    402  1.40   thorpej static void	pmap_update_2pg __P((vaddr_t,vaddr_t));
    403  1.40   thorpej void		pmap_write_protect __P((struct pmap *, vaddr_t,
    404  1.40   thorpej 				vaddr_t, vm_prot_t));
    405  1.40   thorpej 
    406  1.40   thorpej vaddr_t reserve_dumppages __P((vaddr_t)); /* XXX: not a pmap fn */
    407  1.40   thorpej 
    408  1.40   thorpej #define PMAP_GROWKERNEL		/* turn on pmap_growkernel interface */
    409  1.40   thorpej 
    410  1.40   thorpej /*
    411  1.40   thorpej  * inline functions
    412  1.40   thorpej  */
    413  1.40   thorpej 
    414  1.40   thorpej /*
    415  1.40   thorpej  * pmap_update_pg: flush one page from the TLB (or flush the whole thing
    416  1.40   thorpej  *	if hardware doesn't support one-page flushing)
    417  1.40   thorpej  */
    418  1.40   thorpej 
    419  1.40   thorpej __inline static void pmap_update_pg(va)
    420  1.40   thorpej 
    421  1.40   thorpej vaddr_t va;
    422  1.23  christos 
    423  1.11   mycroft {
    424  1.40   thorpej #if defined(I386_CPU)
    425  1.40   thorpej   if (cpu_class == CPUCLASS_386)
    426  1.40   thorpej     pmap_update();
    427  1.40   thorpej   else
    428  1.40   thorpej #endif
    429  1.40   thorpej     invlpg((u_int) va);
    430  1.11   mycroft }
    431  1.11   mycroft 
    432  1.40   thorpej /*
    433  1.40   thorpej  * pmap_update_2pg: flush two pages from the TLB
    434  1.40   thorpej  */
    435  1.40   thorpej 
    436  1.40   thorpej __inline static void pmap_update_2pg(va, vb)
    437  1.40   thorpej 
    438  1.40   thorpej vaddr_t va, vb;
    439  1.40   thorpej 
    440  1.11   mycroft {
    441  1.40   thorpej #if defined(I386_CPU)
    442  1.40   thorpej   if (cpu_class == CPUCLASS_386)
    443  1.40   thorpej     pmap_update();
    444  1.40   thorpej   else
    445  1.40   thorpej #endif
    446  1.40   thorpej     {
    447  1.40   thorpej       invlpg((u_int) va);
    448  1.40   thorpej       invlpg((u_int) vb);
    449  1.40   thorpej     }
    450  1.11   mycroft }
    451  1.11   mycroft 
    452  1.40   thorpej /*
    453  1.40   thorpej  * pmap_page_protect: change the protection of all recorded mappings
    454  1.40   thorpej  *	of a managed page
    455  1.40   thorpej  *
    456  1.40   thorpej  * => this function is a frontend for pmap_page_remove/pmap_change_attrs
    457  1.40   thorpej  * => we only have to worry about making the page more protected.
    458  1.40   thorpej  *	unprotecting a page is done on-demand at fault time.
    459  1.40   thorpej  */
    460  1.40   thorpej 
    461  1.40   thorpej __inline static void pmap_page_protect(pg, prot)
    462  1.40   thorpej 
    463  1.40   thorpej struct vm_page *pg;
    464  1.40   thorpej vm_prot_t prot;
    465  1.40   thorpej 
    466  1.11   mycroft {
    467  1.40   thorpej   if ((prot & VM_PROT_WRITE) == 0) {
    468  1.40   thorpej     if (prot & (VM_PROT_READ|VM_PROT_EXECUTE)) {
    469  1.40   thorpej       (void) pmap_change_attrs(pg, PG_RO, PG_RW);
    470  1.40   thorpej     } else {
    471  1.40   thorpej       pmap_page_remove(pg);
    472  1.40   thorpej     }
    473  1.40   thorpej   }
    474  1.11   mycroft }
    475  1.11   mycroft 
    476  1.40   thorpej /*
    477  1.40   thorpej  * pmap_protect: change the protection of pages in a pmap
    478  1.40   thorpej  *
    479  1.40   thorpej  * => this function is a frontend for pmap_remove/pmap_write_protect
    480  1.40   thorpej  * => we only have to worry about making the page more protected.
    481  1.40   thorpej  *	unprotecting a page is done on-demand at fault time.
    482  1.40   thorpej  */
    483  1.40   thorpej 
    484  1.40   thorpej __inline static void pmap_protect(pmap, sva, eva, prot)
    485  1.40   thorpej 
    486  1.40   thorpej struct pmap *pmap;
    487  1.40   thorpej vaddr_t sva, eva;
    488  1.40   thorpej vm_prot_t prot;
    489  1.11   mycroft 
    490  1.11   mycroft {
    491  1.40   thorpej   if ((prot & VM_PROT_WRITE) == 0) {
    492  1.40   thorpej     if (prot & (VM_PROT_READ|VM_PROT_EXECUTE)) {
    493  1.40   thorpej       pmap_write_protect(pmap, sva, eva, prot);
    494  1.40   thorpej     } else {
    495  1.40   thorpej       pmap_remove(pmap, sva, eva);
    496  1.40   thorpej     }
    497  1.40   thorpej   }
    498  1.11   mycroft }
    499  1.11   mycroft 
    500  1.40   thorpej /*
    501  1.40   thorpej  * pmap_kenter_pa: enter a kernel mapping without R/M (pv_entry) tracking
    502  1.40   thorpej  *
    503  1.40   thorpej  * => no need to lock anything, assume va is already allocated
    504  1.40   thorpej  * => should be faster than normal pmap enter function
    505  1.40   thorpej  */
    506  1.40   thorpej 
    507  1.40   thorpej __inline static void pmap_kenter_pa(va, pa, prot)
    508  1.40   thorpej 
    509  1.40   thorpej vaddr_t va;
    510  1.40   thorpej paddr_t pa;
    511  1.40   thorpej vm_prot_t prot;
    512  1.40   thorpej 
    513  1.11   mycroft {
    514  1.40   thorpej   struct pmap *pm = pmap_kernel();
    515  1.40   thorpej   pt_entry_t *pte, opte;
    516  1.40   thorpej   int s;
    517  1.40   thorpej 
    518  1.40   thorpej   s = splimp();
    519  1.40   thorpej   simple_lock(&pm->pm_obj.vmobjlock);
    520  1.40   thorpej   pm->pm_stats.resident_count++;
    521  1.40   thorpej   pm->pm_stats.wired_count++;
    522  1.40   thorpej   simple_unlock(&pm->pm_obj.vmobjlock);
    523  1.40   thorpej   splx(s);
    524  1.40   thorpej 
    525  1.40   thorpej   pte = vtopte(va);
    526  1.40   thorpej   opte = *pte;
    527  1.40   thorpej   *pte = pa | ((prot & VM_PROT_WRITE)? PG_RW : PG_RO) |
    528  1.40   thorpej 	      PG_V | pmap_pg_g;         /* zap! */
    529  1.40   thorpej   if (pmap_valid_entry(opte))
    530  1.40   thorpej     pmap_update_pg(va);
    531  1.40   thorpej }
    532  1.35       cgd 
    533  1.37   thorpej vaddr_t	pmap_map __P((vaddr_t, paddr_t, paddr_t, int));
    534  1.39   thorpej 
    535  1.39   thorpej #if defined(USER_LDT)
    536  1.39   thorpej void	pmap_ldt_cleanup __P((struct proc *));
    537  1.39   thorpej #define	PMAP_FORK
    538  1.39   thorpej #endif /* USER_LDT */
    539   1.1       cgd 
    540  1.40   thorpej #endif /* _KERNEL */
    541  1.40   thorpej #endif	/* _I386_PMAP_H_ */
    542