Home | History | Annotate | Line # | Download | only in include
pmap.h revision 1.109
      1  1.109     chuck /*	$NetBSD: pmap.h,v 1.109 2011/02/01 20:09:08 chuck Exp $	*/
      2   1.38   mycroft 
      3   1.40   thorpej /*
      4   1.40   thorpej  * Copyright (c) 1997 Charles D. Cranor and Washington University.
      5   1.38   mycroft  * All rights reserved.
      6   1.38   mycroft  *
      7   1.38   mycroft  * Redistribution and use in source and binary forms, with or without
      8   1.38   mycroft  * modification, are permitted provided that the following conditions
      9   1.38   mycroft  * are met:
     10   1.38   mycroft  * 1. Redistributions of source code must retain the above copyright
     11   1.38   mycroft  *    notice, this list of conditions and the following disclaimer.
     12   1.38   mycroft  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.38   mycroft  *    notice, this list of conditions and the following disclaimer in the
     14   1.38   mycroft  *    documentation and/or other materials provided with the distribution.
     15    1.1       cgd  *
     16   1.40   thorpej  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17   1.40   thorpej  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18   1.40   thorpej  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19   1.40   thorpej  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20   1.40   thorpej  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     21   1.40   thorpej  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     22   1.40   thorpej  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     23   1.40   thorpej  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     24   1.40   thorpej  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     25   1.40   thorpej  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26    1.1       cgd  */
     27    1.1       cgd 
     28    1.1       cgd /*
     29   1.94      yamt  * Copyright (c) 2001 Wasabi Systems, Inc.
     30   1.94      yamt  * All rights reserved.
     31   1.94      yamt  *
     32   1.94      yamt  * Written by Frank van der Linden for Wasabi Systems, Inc.
     33   1.94      yamt  *
     34   1.94      yamt  * Redistribution and use in source and binary forms, with or without
     35   1.94      yamt  * modification, are permitted provided that the following conditions
     36   1.94      yamt  * are met:
     37   1.94      yamt  * 1. Redistributions of source code must retain the above copyright
     38   1.94      yamt  *    notice, this list of conditions and the following disclaimer.
     39   1.94      yamt  * 2. Redistributions in binary form must reproduce the above copyright
     40   1.94      yamt  *    notice, this list of conditions and the following disclaimer in the
     41   1.94      yamt  *    documentation and/or other materials provided with the distribution.
     42   1.94      yamt  * 3. All advertising materials mentioning features or use of this software
     43   1.94      yamt  *    must display the following acknowledgement:
     44   1.94      yamt  *      This product includes software developed for the NetBSD Project by
     45   1.94      yamt  *      Wasabi Systems, Inc.
     46   1.94      yamt  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     47   1.94      yamt  *    or promote products derived from this software without specific prior
     48   1.94      yamt  *    written permission.
     49   1.94      yamt  *
     50   1.94      yamt  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     51   1.94      yamt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     52   1.94      yamt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     53   1.94      yamt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     54   1.94      yamt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     55   1.94      yamt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     56   1.94      yamt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     57   1.94      yamt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     58   1.94      yamt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     59   1.94      yamt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     60   1.94      yamt  * POSSIBILITY OF SUCH DAMAGE.
     61    1.1       cgd  */
     62   1.34       mrg 
     63   1.40   thorpej #ifndef	_I386_PMAP_H_
     64   1.40   thorpej #define	_I386_PMAP_H_
     65   1.40   thorpej 
     66   1.58       mrg #if defined(_KERNEL_OPT)
     67   1.39   thorpej #include "opt_user_ldt.h"
     68   1.98    bouyer #include "opt_xen.h"
     69   1.34       mrg #endif
     70    1.1       cgd 
     71   1.96        ad #include <sys/atomic.h>
     72   1.96        ad 
     73  1.103       mrg #include <i386/pte.h>
     74   1.39   thorpej #include <machine/segments.h>
     75   1.92        ad #if defined(_KERNEL)
     76   1.91        ad #include <machine/cpufunc.h>
     77   1.91        ad #endif
     78   1.90        ad 
     79   1.40   thorpej #include <uvm/uvm_object.h>
     80   1.98    bouyer #ifdef XEN
     81   1.98    bouyer #include <xen/xenfunc.h>
     82   1.98    bouyer #include <xen/xenpmap.h>
     83   1.98    bouyer #endif /* XEN */
     84    1.1       cgd 
     85    1.1       cgd /*
     86   1.40   thorpej  * see pte.h for a description of i386 MMU terminology and hardware
     87   1.40   thorpej  * interface.
     88   1.40   thorpej  *
     89  1.102    bouyer  * a pmap describes a processes' 4GB virtual address space.  when PAE
     90  1.102    bouyer  * is not in use, this virtual address space can be broken up into 1024 4MB
     91  1.102    bouyer  * regions which are described by PDEs in the PDP.  the PDEs are defined as
     92  1.102    bouyer  * follows:
     93   1.40   thorpej  *
     94   1.40   thorpej  * (ranges are inclusive -> exclusive, just like vm_map_entry start/end)
     95   1.43   thorpej  * (the following assumes that KERNBASE is 0xc0000000)
     96   1.40   thorpej  *
     97   1.40   thorpej  * PDE#s	VA range		usage
     98   1.68  drochner  * 0->766	0x0 -> 0xbfc00000	user address space
     99   1.61      yamt  * 767		0xbfc00000->		recursive mapping of PDP (used for
    100   1.43   thorpej  *			0xc0000000	linear mapping of PTPs)
    101   1.43   thorpej  * 768->1023	0xc0000000->		kernel address space (constant
    102   1.40   thorpej  *			0xffc00000	across all pmap's/processes)
    103   1.40   thorpej  * 1023		0xffc00000->		"alternate" recursive PDP mapping
    104   1.40   thorpej  *			<end>		(for other pmaps)
    105   1.40   thorpej  *
    106   1.40   thorpej  *
    107   1.40   thorpej  * note: a recursive PDP mapping provides a way to map all the PTEs for
    108   1.41       chs  * a 4GB address space into a linear chunk of virtual memory.  in other
    109   1.41       chs  * words, the PTE for page 0 is the first int mapped into the 4MB recursive
    110   1.41       chs  * area.  the PTE for page 1 is the second int.  the very last int in the
    111   1.81  junyoung  * 4MB range is the PTE that maps VA 0xfffff000 (the last page in a 4GB
    112   1.40   thorpej  * address).
    113   1.40   thorpej  *
    114   1.43   thorpej  * all pmap's PD's must have the same values in slots 768->1023 so that
    115   1.41       chs  * the kernel is always mapped in every process.  these values are loaded
    116   1.40   thorpej  * into the PD at pmap creation time.
    117   1.40   thorpej  *
    118   1.41       chs  * at any one time only one pmap can be active on a processor.  this is
    119   1.41       chs  * the pmap whose PDP is pointed to by processor register %cr3.  this pmap
    120   1.40   thorpej  * will have all its PTEs mapped into memory at the recursive mapping
    121   1.43   thorpej  * point (slot #767 as show above).  when the pmap code wants to find the
    122   1.40   thorpej  * PTE for a virtual address, all it has to do is the following:
    123   1.40   thorpej  *
    124   1.71   thorpej  * address of PTE = (767 * 4MB) + (VA / PAGE_SIZE) * sizeof(pt_entry_t)
    125   1.43   thorpej  *                = 0xbfc00000 + (VA / 4096) * 4
    126   1.40   thorpej  *
    127   1.40   thorpej  * what happens if the pmap layer is asked to perform an operation
    128   1.41       chs  * on a pmap that is not the one which is currently active?  in that
    129   1.41       chs  * case we take the PA of the PDP of non-active pmap and put it in
    130   1.41       chs  * slot 1023 of the active pmap.  this causes the non-active pmap's
    131   1.40   thorpej  * PTEs to get mapped in the final 4MB of the 4GB address space
    132   1.40   thorpej  * (e.g. starting at 0xffc00000).
    133   1.40   thorpej  *
    134   1.40   thorpej  * the following figure shows the effects of the recursive PDP mapping:
    135   1.40   thorpej  *
    136   1.40   thorpej  *   PDP (%cr3)
    137   1.40   thorpej  *   +----+
    138   1.40   thorpej  *   |   0| -> PTP#0 that maps VA 0x0 -> 0x400000
    139   1.40   thorpej  *   |    |
    140   1.40   thorpej  *   |    |
    141   1.43   thorpej  *   | 767| -> points back to PDP (%cr3) mapping VA 0xbfc00000 -> 0xc0000000
    142   1.83  junyoung  *   | 768| -> first kernel PTP (maps 0xc0000000 -> 0xc0400000)
    143   1.40   thorpej  *   |    |
    144   1.40   thorpej  *   |1023| -> points to alternate pmap's PDP (maps 0xffc00000 -> end)
    145   1.40   thorpej  *   +----+
    146   1.40   thorpej  *
    147   1.43   thorpej  * note that the PDE#767 VA (0xbfc00000) is defined as "PTE_BASE"
    148   1.40   thorpej  * note that the PDE#1023 VA (0xffc00000) is defined as "APTE_BASE"
    149   1.40   thorpej  *
    150   1.43   thorpej  * starting at VA 0xbfc00000 the current active PDP (%cr3) acts as a
    151   1.40   thorpej  * PTP:
    152   1.40   thorpej  *
    153   1.43   thorpej  * PTP#767 == PDP(%cr3) => maps VA 0xbfc00000 -> 0xc0000000
    154   1.40   thorpej  *   +----+
    155   1.43   thorpej  *   |   0| -> maps the contents of PTP#0 at VA 0xbfc00000->0xbfc01000
    156   1.40   thorpej  *   |    |
    157   1.40   thorpej  *   |    |
    158   1.81  junyoung  *   | 767| -> maps contents of PTP#767 (the PDP) at VA 0xbfeff000
    159   1.43   thorpej  *   | 768| -> maps contents of first kernel PTP
    160   1.40   thorpej  *   |    |
    161   1.40   thorpej  *   |1023|
    162   1.40   thorpej  *   +----+
    163   1.40   thorpej  *
    164   1.81  junyoung  * note that mapping of the PDP at PTP#767's VA (0xbfeff000) is
    165   1.40   thorpej  * defined as "PDP_BASE".... within that mapping there are two
    166   1.41       chs  * defines:
    167   1.59       chs  *   "PDP_PDE" (0xbfeffbfc) is the VA of the PDE in the PDP
    168   1.41       chs  *      which points back to itself.
    169   1.59       chs  *   "APDP_PDE" (0xbfeffffc) is the VA of the PDE in the PDP which
    170   1.40   thorpej  *      establishes the recursive mapping of the alternate pmap.
    171   1.40   thorpej  *      to set the alternate PDP, one just has to put the correct
    172   1.40   thorpej  *	PA info in *APDP_PDE.
    173   1.40   thorpej  *
    174   1.41       chs  * note that in the APTE_BASE space, the APDP appears at VA
    175   1.40   thorpej  * "APDP_BASE" (0xfffff000).
    176  1.102    bouyer  *
    177  1.107       jym  * - PAE support -
    178  1.107       jym  * ---------------
    179  1.107       jym  *
    180  1.107       jym  * PAE adds another layer of indirection during address translation, breaking
    181  1.107       jym  * up the translation process in 3 different levels:
    182  1.107       jym  * - L3 page directory, containing 4 * 64-bits addresses (index determined by
    183  1.107       jym  * bits [31:30] from the virtual address). This breaks up the address space
    184  1.107       jym  * in 4 1GB regions.
    185  1.107       jym  * - the PD (L2), containing 512 64-bits addresses, breaking each L3 region
    186  1.107       jym  * in 512 * 2MB regions.
    187  1.107       jym  * - the PT (L1), also containing 512 64-bits addresses (at L1, the size of
    188  1.107       jym  * the pages is still 4K).
    189  1.107       jym  *
    190  1.102    bouyer  * The kernel virtual space is mapped by the last entry in the L3 page,
    191  1.102    bouyer  * the first 3 entries mapping the user VA space.
    192  1.107       jym  *
    193  1.102    bouyer  * Because the L3 has only 4 entries of 1GB each, we can't use recursive
    194  1.107       jym  * mappings at this level for PDP_PDE and APDP_PDE (this would eat up 2 of
    195  1.107       jym  * the 4GB virtual space). There are also restrictions imposed by Xen on the
    196  1.107       jym  * last entry of the L3 PD (reference count to this page cannot be bigger
    197  1.107       jym  * than 1), which makes it hard to use one L3 page per pmap to switch
    198  1.107       jym  * between pmaps using %cr3.
    199  1.107       jym  *
    200  1.107       jym  * As such, each CPU gets its own L3 page that is always loaded into its %cr3
    201  1.107       jym  * (ci_pae_l3_pd in the associated cpu_info struct). We claim that the VM has
    202  1.107       jym  * only a 2-level PTP (similar to the non-PAE case). L2 PD is now 4 contiguous
    203  1.107       jym  * pages long (corresponding to the 4 entries of the L3), and the different
    204  1.107       jym  * index/slots (like PDP_PDE) are adapted accordingly.
    205  1.107       jym  *
    206  1.107       jym  * Kernel space remains in L3[3], L3[0-2] maps the user VA space. Switching
    207  1.107       jym  * between pmaps consists in modifying the first 3 entries of the CPU's L3 page.
    208  1.107       jym  *
    209  1.107       jym  * PTE_BASE and APTE_BASE will need 4 entries in the L2 PD pages to map the
    210  1.107       jym  * L2 pages recursively.
    211  1.107       jym  *
    212  1.107       jym  * In addition, for Xen, we can't recursively map L3[3] (Xen wants the ref
    213  1.107       jym  * count on this page to be exactly one), so we use a shadow PD page for
    214  1.107       jym  * the last L2 PD. The shadow page could be static too, but to make pm_pdir[]
    215  1.107       jym  * contiguous we'll allocate/copy one page per pmap.
    216    1.1       cgd  */
    217   1.65      fvdl /* XXX MP should we allocate one APDP_PDE per processor?? */
    218   1.33       mrg 
    219   1.33       mrg /*
    220   1.94      yamt  * Mask to get rid of the sign-extended part of addresses.
    221   1.94      yamt  */
    222   1.94      yamt #define VA_SIGN_MASK		0
    223   1.94      yamt #define VA_SIGN_NEG(va)		((va) | VA_SIGN_MASK)
    224   1.94      yamt /*
    225   1.94      yamt  * XXXfvdl this one's not right.
    226   1.94      yamt  */
    227   1.94      yamt #define VA_SIGN_POS(va)		((va) & ~VA_SIGN_MASK)
    228   1.94      yamt 
    229   1.94      yamt /*
    230   1.40   thorpej  * the following defines identify the slots used as described above.
    231   1.33       mrg  */
    232  1.102    bouyer #ifdef PAE
    233  1.102    bouyer #define L2_SLOT_PTE	(KERNBASE/NBPD_L2-4) /* 1532: for recursive PDP map */
    234  1.102    bouyer #define L2_SLOT_KERN	(KERNBASE/NBPD_L2)   /* 1536: start of kernel space */
    235  1.107       jym #ifndef XEN
    236  1.107       jym #define L2_SLOT_APTE	2044		/* 2044: alternative recursive slot */
    237  1.107       jym #else
    238  1.107       jym #define L2_SLOT_APTE	1960		/* 1964-2047 reserved by Xen */
    239  1.107       jym #endif
    240  1.102    bouyer #else /* PAE */
    241  1.102    bouyer #define L2_SLOT_PTE	(KERNBASE/NBPD_L2-1) /* 767: for recursive PDP map */
    242  1.102    bouyer #define L2_SLOT_KERN	(KERNBASE/NBPD_L2)   /* 768: start of kernel space */
    243   1.98    bouyer #ifndef XEN
    244  1.107       jym #define L2_SLOT_APTE	1023		/* 1023: alternative recursive slot */
    245   1.98    bouyer #else
    246   1.98    bouyer #define L2_SLOT_APTE	1007		/* 1008-1023 reserved by Xen */
    247   1.98    bouyer #endif
    248  1.102    bouyer #endif /* PAE */
    249   1.98    bouyer 
    250  1.106       jym #define	L2_SLOT_KERNBASE L2_SLOT_KERN
    251   1.94      yamt 
    252   1.94      yamt #define PDIR_SLOT_KERN	L2_SLOT_KERN
    253   1.94      yamt #define PDIR_SLOT_PTE	L2_SLOT_PTE
    254   1.94      yamt #define PDIR_SLOT_APTE	L2_SLOT_APTE
    255    1.1       cgd 
    256    1.1       cgd /*
    257   1.41       chs  * the following defines give the virtual addresses of various MMU
    258   1.40   thorpej  * data structures:
    259   1.40   thorpej  * PTE_BASE and APTE_BASE: the base VA of the linear PTE mappings
    260   1.81  junyoung  * PDP_BASE and APDP_BASE: the base VA of the recursive mapping of the PDP
    261   1.40   thorpej  * PDP_PDE and APDP_PDE: the VA of the PDE that points back to the PDP/APDP
    262    1.1       cgd  */
    263   1.29      fvdl 
    264  1.102    bouyer #define PTE_BASE  ((pt_entry_t *) (PDIR_SLOT_PTE * NBPD_L2))
    265  1.102    bouyer #define APTE_BASE ((pt_entry_t *) (VA_SIGN_NEG((PDIR_SLOT_APTE * NBPD_L2))))
    266   1.40   thorpej 
    267   1.94      yamt #define L1_BASE		PTE_BASE
    268   1.94      yamt #define AL1_BASE	APTE_BASE
    269   1.40   thorpej 
    270   1.94      yamt #define L2_BASE ((pd_entry_t *)((char *)L1_BASE + L2_SLOT_PTE * NBPD_L1))
    271   1.94      yamt #define AL2_BASE ((pd_entry_t *)((char *)AL1_BASE + L2_SLOT_PTE * NBPD_L1))
    272   1.40   thorpej 
    273   1.94      yamt #define PDP_PDE		(L2_BASE + PDIR_SLOT_PTE)
    274  1.107       jym #if defined(PAE) && defined(XEN)
    275  1.102    bouyer /*
    276  1.107       jym  * when PAE is in use under Xen, we can't write APDP_PDE through the recursive
    277  1.107       jym  * mapping, because it points to the shadow PD. Use the kernel PD instead,
    278  1.107       jym  * which is static
    279  1.102    bouyer  */
    280  1.102    bouyer #define APDP_PDE	(&pmap_kl2pd[l2tol2(PDIR_SLOT_APTE)])
    281  1.102    bouyer #define APDP_PDE_SHADOW	(L2_BASE + PDIR_SLOT_APTE)
    282  1.107       jym #else /* PAE && XEN */
    283   1.94      yamt #define APDP_PDE	(L2_BASE + PDIR_SLOT_APTE)
    284  1.107       jym #endif /* PAE && XEN */
    285   1.40   thorpej 
    286   1.94      yamt #define PDP_BASE	L2_BASE
    287   1.94      yamt #define APDP_BASE	AL2_BASE
    288    1.1       cgd 
    289   1.94      yamt /* largest value (-1 for APTP space) */
    290   1.94      yamt #define NKL2_MAX_ENTRIES	(NTOPLEVEL_PDES - (KERNBASE/NBPD_L2) - 1)
    291   1.94      yamt #define NKL1_MAX_ENTRIES	(unsigned long)(NKL2_MAX_ENTRIES * NPDPG)
    292   1.39   thorpej 
    293   1.94      yamt #define NKL2_KIMG_ENTRIES	0	/* XXX unused */
    294   1.40   thorpej 
    295   1.94      yamt #define NKL2_START_ENTRIES	0	/* XXX computed on runtime */
    296   1.94      yamt #define NKL1_START_ENTRIES	0	/* XXX unused */
    297   1.11   mycroft 
    298  1.105       jym #define NTOPLEVEL_PDES		(PAGE_SIZE * PDP_SIZE / (sizeof (pd_entry_t)))
    299   1.11   mycroft 
    300   1.94      yamt #define NPDPG			(PAGE_SIZE / sizeof (pd_entry_t))
    301    1.1       cgd 
    302   1.94      yamt #define PTP_MASK_INITIALIZER	{ L1_FRAME, L2_FRAME }
    303   1.94      yamt #define PTP_SHIFT_INITIALIZER	{ L1_SHIFT, L2_SHIFT }
    304   1.94      yamt #define NKPTP_INITIALIZER	{ NKL1_START_ENTRIES, NKL2_START_ENTRIES }
    305   1.94      yamt #define NKPTPMAX_INITIALIZER	{ NKL1_MAX_ENTRIES, NKL2_MAX_ENTRIES }
    306   1.94      yamt #define NBPD_INITIALIZER	{ NBPD_L1, NBPD_L2 }
    307   1.94      yamt #define PDES_INITIALIZER	{ L2_BASE }
    308   1.94      yamt #define APDES_INITIALIZER	{ AL2_BASE }
    309   1.40   thorpej 
    310   1.94      yamt #define PTP_LEVELS	2
    311   1.40   thorpej 
    312   1.40   thorpej /*
    313   1.94      yamt  * PG_AVAIL usage: we make use of the ignored bits of the PTE
    314   1.11   mycroft  */
    315    1.1       cgd 
    316   1.94      yamt #define PG_W		PG_AVAIL1	/* "wired" mapping */
    317   1.94      yamt #define PG_PVLIST	PG_AVAIL2	/* mapping has entry on pvlist */
    318   1.94      yamt #define PG_X		PG_AVAIL3	/* executable mapping */
    319   1.40   thorpej 
    320   1.40   thorpej /*
    321   1.94      yamt  * Number of PTE's per cache line.  4 byte pte, 32-byte cache line
    322   1.94      yamt  * Used to avoid false sharing of cache lines.
    323   1.40   thorpej  */
    324  1.102    bouyer #ifdef PAE
    325  1.102    bouyer #define NPTECL		4
    326  1.102    bouyer #else
    327   1.94      yamt #define NPTECL		8
    328  1.102    bouyer #endif
    329   1.70      fvdl 
    330   1.98    bouyer #include <x86/pmap.h>
    331   1.98    bouyer 
    332   1.98    bouyer #ifndef XEN
    333   1.95    bouyer #define pmap_pa2pte(a)			(a)
    334   1.95    bouyer #define pmap_pte2pa(a)			((a) & PG_FRAME)
    335   1.95    bouyer #define pmap_pte_set(p, n)		do { *(p) = (n); } while (0)
    336  1.107       jym #define pmap_pte_flush()		/* nothing */
    337  1.107       jym 
    338  1.107       jym #ifdef PAE
    339  1.107       jym #define pmap_pte_cas(p, o, n)		atomic_cas_64((p), (o), (n))
    340  1.107       jym #define pmap_pte_testset(p, n)		\
    341  1.107       jym     atomic_swap_64((volatile uint64_t *)p, n)
    342  1.107       jym #define pmap_pte_setbits(p, b)		\
    343  1.107       jym     atomic_or_64((volatile uint64_t *)p, b)
    344  1.107       jym #define pmap_pte_clearbits(p, b)	\
    345  1.107       jym     atomic_and_64((volatile uint64_t *)p, ~(b))
    346  1.107       jym #else /* PAE */
    347  1.100      yamt #define pmap_pte_cas(p, o, n)		atomic_cas_32((p), (o), (n))
    348   1.96        ad #define pmap_pte_testset(p, n)		\
    349   1.96        ad     atomic_swap_ulong((volatile unsigned long *)p, n)
    350   1.96        ad #define pmap_pte_setbits(p, b)		\
    351   1.96        ad     atomic_or_ulong((volatile unsigned long *)p, b)
    352   1.96        ad #define pmap_pte_clearbits(p, b)	\
    353   1.96        ad     atomic_and_ulong((volatile unsigned long *)p, ~(b))
    354  1.107       jym #endif /* PAE */
    355  1.107       jym 
    356  1.107       jym #else /* XEN */
    357   1.98    bouyer static __inline pt_entry_t
    358   1.98    bouyer pmap_pa2pte(paddr_t pa)
    359   1.98    bouyer {
    360   1.98    bouyer 	return (pt_entry_t)xpmap_ptom_masked(pa);
    361   1.98    bouyer }
    362   1.98    bouyer 
    363   1.98    bouyer static __inline paddr_t
    364   1.98    bouyer pmap_pte2pa(pt_entry_t pte)
    365   1.98    bouyer {
    366   1.98    bouyer 	return xpmap_mtop_masked(pte & PG_FRAME);
    367   1.98    bouyer }
    368   1.98    bouyer static __inline void
    369   1.98    bouyer pmap_pte_set(pt_entry_t *pte, pt_entry_t npte)
    370   1.98    bouyer {
    371   1.98    bouyer 	int s = splvm();
    372  1.102    bouyer 	xpq_queue_pte_update(xpmap_ptetomach(pte), npte);
    373   1.98    bouyer 	splx(s);
    374   1.98    bouyer }
    375   1.98    bouyer 
    376   1.98    bouyer static __inline pt_entry_t
    377  1.101    bouyer pmap_pte_cas(volatile pt_entry_t *ptep, pt_entry_t o, pt_entry_t n)
    378  1.100      yamt {
    379  1.100      yamt 	int s = splvm();
    380  1.100      yamt 	pt_entry_t opte = *ptep;
    381  1.100      yamt 
    382  1.100      yamt 	if (opte == o) {
    383  1.102    bouyer 		xpq_queue_pte_update(xpmap_ptetomach(__UNVOLATILE(ptep)), n);
    384  1.100      yamt 		xpq_flush_queue();
    385  1.100      yamt 	}
    386  1.100      yamt 	splx(s);
    387  1.100      yamt 	return opte;
    388  1.100      yamt }
    389  1.100      yamt 
    390  1.100      yamt static __inline pt_entry_t
    391   1.98    bouyer pmap_pte_testset(volatile pt_entry_t *pte, pt_entry_t npte)
    392   1.98    bouyer {
    393   1.98    bouyer 	int s = splvm();
    394   1.98    bouyer 	pt_entry_t opte = *pte;
    395  1.102    bouyer 	xpq_queue_pte_update(xpmap_ptetomach(__UNVOLATILE(pte)),
    396   1.98    bouyer 	    npte);
    397   1.98    bouyer 	xpq_flush_queue();
    398   1.98    bouyer 	splx(s);
    399   1.98    bouyer 	return opte;
    400   1.98    bouyer }
    401   1.98    bouyer 
    402   1.98    bouyer static __inline void
    403   1.98    bouyer pmap_pte_setbits(volatile pt_entry_t *pte, pt_entry_t bits)
    404   1.98    bouyer {
    405   1.98    bouyer 	int s = splvm();
    406  1.102    bouyer 	xpq_queue_pte_update(xpmap_ptetomach(__UNVOLATILE(pte)), (*pte) | bits);
    407   1.98    bouyer 	xpq_flush_queue();
    408   1.98    bouyer 	splx(s);
    409   1.98    bouyer }
    410   1.98    bouyer 
    411   1.98    bouyer static __inline void
    412   1.98    bouyer pmap_pte_clearbits(volatile pt_entry_t *pte, pt_entry_t bits)
    413   1.98    bouyer {
    414   1.98    bouyer 	int s = splvm();
    415  1.102    bouyer 	xpq_queue_pte_update(xpmap_ptetomach(__UNVOLATILE(pte)),
    416   1.98    bouyer 	    (*pte) & ~bits);
    417   1.98    bouyer 	xpq_flush_queue();
    418   1.98    bouyer 	splx(s);
    419   1.98    bouyer }
    420   1.98    bouyer 
    421   1.98    bouyer static __inline void
    422   1.98    bouyer pmap_pte_flush(void)
    423   1.98    bouyer {
    424   1.98    bouyer 	int s = splvm();
    425   1.98    bouyer 	xpq_flush_queue();
    426   1.98    bouyer 	splx(s);
    427   1.98    bouyer }
    428  1.102    bouyer 
    429   1.98    bouyer #endif
    430   1.73   thorpej 
    431  1.102    bouyer #ifdef PAE
    432  1.107       jym /* Address of the static kernel's L2 page */
    433  1.102    bouyer pd_entry_t *pmap_kl2pd;
    434  1.102    bouyer paddr_t pmap_kl2paddr;
    435  1.102    bouyer #endif
    436  1.102    bouyer 
    437  1.102    bouyer 
    438   1.94      yamt struct trapframe;
    439    1.1       cgd 
    440   1.94      yamt int	pmap_exec_fixup(struct vm_map *, struct trapframe *, struct pcb *);
    441   1.94      yamt void	pmap_ldt_cleanup(struct lwp *);
    442   1.90        ad 
    443  1.108  uebayasi #include <x86/pmap_pv.h>
    444  1.108  uebayasi 
    445  1.108  uebayasi #define	__HAVE_VM_PAGE_MD
    446  1.108  uebayasi #define	VM_MDPAGE_INIT(pg) \
    447  1.108  uebayasi 	memset(&(pg)->mdpage, 0, sizeof((pg)->mdpage)); \
    448  1.108  uebayasi 	PMAP_PAGE_INIT(&(pg)->mdpage.mp_pp)
    449  1.108  uebayasi 
    450  1.108  uebayasi struct vm_page_md {
    451  1.108  uebayasi 	struct pmap_page mp_pp;
    452  1.108  uebayasi };
    453  1.108  uebayasi 
    454   1.40   thorpej #endif	/* _I386_PMAP_H_ */
    455