summaryrefslogtreecommitdiff
path: root/sys/arch/i386/include/pmap.h
diff options
context:
space:
mode:
Diffstat (limited to 'sys/arch/i386/include/pmap.h')
-rw-r--r--sys/arch/i386/include/pmap.h363
1 files changed, 203 insertions, 160 deletions
diff --git a/sys/arch/i386/include/pmap.h b/sys/arch/i386/include/pmap.h
index b1e1c2ec4b8..405edfe6ada 100644
--- a/sys/arch/i386/include/pmap.h
+++ b/sys/arch/i386/include/pmap.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: pmap.h,v 1.42 2006/04/27 15:37:53 mickey Exp $ */
+/* $OpenBSD: pmap.h,v 1.43 2007/02/20 21:15:01 tom Exp $ */
/* $NetBSD: pmap.h,v 1.44 2000/04/24 17:18:18 thorpej Exp $ */
/*
@@ -47,11 +47,123 @@
#include <uvm/uvm_object.h>
/*
- * The following defines identify the slots used as described in pmap.c .
+ * See pte.h for a description of i386 MMU terminology and hardware
+ * interface.
+ *
+ * A pmap describes a process' 4GB virtual address space. This
+ * virtual address space can be broken up into 1024 4MB regions which
+ * are described by PDEs in the PDP. The PDEs are defined as follows:
+ *
+ * Ranges are inclusive -> exclusive, just like vm_map_entry start/end.
+ * The following assumes that KERNBASE is 0xd0000000.
+ *
+ * PDE#s VA range Usage
+ * 0->831 0x0 -> 0xcfc00000 user address space, note that the
+ * max user address is 0xcfbfe000
+ * the final two pages in the last 4MB
+ * used to be reserved for the UAREA
+ * but now are no longer used.
+ * 831 0xcfc00000-> recursive mapping of PDP (used for
+ * 0xd0000000 linear mapping of PTPs).
+ * 832->1023 0xd0000000-> kernel address space (constant
+ * 0xffc00000 across all pmaps/processes).
+ * 1023 0xffc00000-> "alternate" recursive PDP mapping
+ * <end> (for other pmaps).
+ *
+ *
+ * Note: A recursive PDP mapping provides a way to map all the PTEs for
+ * a 4GB address space into a linear chunk of virtual memory. In other
+ * words, the PTE for page 0 is the first int mapped into the 4MB recursive
+ * area. The PTE for page 1 is the second int. The very last int in the
+ * 4MB range is the PTE that maps VA 0xffffe000 (the last page in a 4GB
+ * address).
+ *
+ * All pmaps' PDs must have the same values in slots 832->1023 so that
+ * the kernel is always mapped in every process. These values are loaded
+ * into the PD at pmap creation time.
+ *
+ * At any one time only one pmap can be active on a processor. This is
+ * the pmap whose PDP is pointed to by processor register %cr3. This pmap
+ * will have all its PTEs mapped into memory at the recursive mapping
+ * point (slot #831 as show above). When the pmap code wants to find the
+ * PTE for a virtual address, all it has to do is the following:
+ *
+ * Address of PTE = (831 * 4MB) + (VA / NBPG) * sizeof(pt_entry_t)
+ * = 0xcfc00000 + (VA / 4096) * 4
+ *
+ * What happens if the pmap layer is asked to perform an operation
+ * on a pmap that is not the one which is currently active? In that
+ * case we take the PA of the PDP of non-active pmap and put it in
+ * slot 1023 of the active pmap. This causes the non-active pmap's
+ * PTEs to get mapped in the final 4MB of the 4GB address space
+ * (e.g. starting at 0xffc00000).
+ *
+ * The following figure shows the effects of the recursive PDP mapping:
+ *
+ * PDP (%cr3)
+ * +----+
+ * | 0| -> PTP#0 that maps VA 0x0 -> 0x400000
+ * | |
+ * | |
+ * | 831| -> points back to PDP (%cr3) mapping VA 0xcfc00000 -> 0xd0000000
+ * | 832| -> first kernel PTP (maps 0xd0000000 -> 0xe0400000)
+ * | |
+ * |1023| -> points to alternate pmap's PDP (maps 0xffc00000 -> end)
+ * +----+
+ *
+ * Note that the PDE#831 VA (0xcfc00000) is defined as "PTE_BASE".
+ * Note that the PDE#1023 VA (0xffc00000) is defined as "APTE_BASE".
+ *
+ * Starting at VA 0xcfc00000 the current active PDP (%cr3) acts as a
+ * PTP:
+ *
+ * PTP#831 == PDP(%cr3) => maps VA 0xcfc00000 -> 0xd0000000
+ * +----+
+ * | 0| -> maps the contents of PTP#0 at VA 0xcfc00000->0xcfc01000
+ * | |
+ * | |
+ * | 831| -> maps the contents of PTP#831 (the PDP) at VA 0xcff3f000
+ * | 832| -> maps the contents of first kernel PTP
+ * | |
+ * |1023|
+ * +----+
+ *
+ * Note that mapping of the PDP at PTP#831's VA (0xcff3f000) is
+ * defined as "PDP_BASE".... within that mapping there are two
+ * defines:
+ * "PDP_PDE" (0xcff3fcfc) is the VA of the PDE in the PDP
+ * which points back to itself.
+ * "APDP_PDE" (0xcff3fffc) is the VA of the PDE in the PDP which
+ * establishes the recursive mapping of the alternate pmap.
+ * To set the alternate PDP, one just has to put the correct
+ * PA info in *APDP_PDE.
+ *
+ * Note that in the APTE_BASE space, the APDP appears at VA
+ * "APDP_BASE" (0xfffff000).
*/
-#define PDSLOT_PTE ((KERNBASE/NBPD)-2) /* 830: for recursive PDP map */
-#define PDSLOT_KERN (KERNBASE/NBPD) /* 832: start of kernel space */
-#define PDSLOT_APTE ((unsigned)1022) /* 1022: alternative recursive slot */
+
+/*
+ * The following defines identify the slots used as described above.
+ */
+
+#define PDSLOT_PTE ((KERNBASE/NBPD)-1) /* 831: for recursive PDP map */
+#define PDSLOT_KERN (KERNBASE/NBPD) /* 832: start of kernel space */
+#define PDSLOT_APTE ((unsigned)1023) /* 1023: alternative recursive slot */
+
+/*
+ * The following defines give the virtual addresses of various MMU
+ * data structures:
+ * PTE_BASE and APTE_BASE: the base VA of the linear PTE mappings
+ * PTD_BASE and APTD_BASE: the base VA of the recursive mapping of the PTD
+ * PDP_PDE and APDP_PDE: the VA of the PDE that points back to the PDP/APDP
+ */
+
+#define PTE_BASE ((pt_entry_t *) (PDSLOT_PTE * NBPD) )
+#define APTE_BASE ((pt_entry_t *) (PDSLOT_APTE * NBPD) )
+#define PDP_BASE ((pd_entry_t *)(((char *)PTE_BASE) + (PDSLOT_PTE * NBPG)))
+#define APDP_BASE ((pd_entry_t *)(((char *)APTE_BASE) + (PDSLOT_APTE * NBPG)))
+#define PDP_PDE (PDP_BASE + PDSLOT_PTE)
+#define APDP_PDE (PDP_BASE + PDSLOT_APTE)
/*
* The following define determines how many PTPs should be set up for the
@@ -59,10 +171,55 @@
* get the VM system running. Once the VM system is running, the
* pmap module can add more PTPs to the kernel area on demand.
*/
+
#ifndef NKPTP
-#define NKPTP 8 /* 16/32MB to start */
+#define NKPTP 4 /* 16MB to start */
#endif
#define NKPTP_MIN 4 /* smallest value we allow */
+#define NKPTP_MAX (1024 - (KERNBASE/NBPD) - 1)
+ /* largest value (-1 for APTP space) */
+
+/*
+ * various address macros
+ *
+ * vtopte: return a pointer to the PTE mapping a VA
+ * kvtopte: same as above (takes a KVA, but doesn't matter with this pmap)
+ * ptetov: given a pointer to a PTE, return the VA that it maps
+ * vtophys: translate a VA to the PA mapped to it
+ *
+ * plus alternative versions of the above
+ */
+
+#define vtopte(VA) (PTE_BASE + atop(VA))
+#define kvtopte(VA) vtopte(VA)
+#define ptetov(PT) (ptoa(PT - PTE_BASE))
+#define vtophys(VA) ((*vtopte(VA) & PG_FRAME) | \
+ ((unsigned)(VA) & ~PG_FRAME))
+#define avtopte(VA) (APTE_BASE + atop(VA))
+#define ptetoav(PT) (ptoa(PT - APTE_BASE))
+#define avtophys(VA) ((*avtopte(VA) & PG_FRAME) | \
+ ((unsigned)(VA) & ~PG_FRAME))
+
+/*
+ * pdei/ptei: generate index into PDP/PTP from a VA
+ */
+#define pdei(VA) (((VA) & PD_MASK) >> PDSHIFT)
+#define ptei(VA) (((VA) & PT_MASK) >> PGSHIFT)
+
+/*
+ * PTP macros:
+ * A PTP's index is the PD index of the PDE that points to it.
+ * A PTP's offset is the byte-offset in the PTE space that this PTP is at.
+ * A PTP's VA is the first VA mapped by that PTP.
+ *
+ * Note that NBPG == number of bytes in a PTP (4096 bytes == 1024 entries)
+ * NBPD == number of bytes a PTP can map (4MB)
+ */
+
+#define ptp_i2o(I) ((I) * NBPG) /* index => offset */
+#define ptp_o2i(O) ((O) / NBPG) /* offset => index */
+#define ptp_i2v(I) ((I) * NBPD) /* index => VA */
+#define ptp_v2i(V) ((V) / NBPD) /* VA => index (same as pdei) */
/*
* PG_AVAIL usage: we make use of the ignored bits of the PTE
@@ -72,6 +229,12 @@
#define PG_PVLIST PG_AVAIL2 /* mapping has entry on pvlist */
#define PG_X PG_AVAIL3 /* executable mapping */
+/*
+ * Number of PTE's per cache line. 4 byte pte, 32-byte cache line
+ * Used to avoid false sharing of cache lines.
+ */
+#define NPTECL 8
+
#ifdef _KERNEL
/*
* pmap data structures: see pmap.c for details of locking.
@@ -94,15 +257,13 @@ LIST_HEAD(pmap_head, pmap); /* struct pmap_head: head of a pmap list */
*/
struct pmap {
- paddr_t pm_pdidx[4]; /* PDIEs for PAE mode */
- paddr_t pm_pdirpa; /* PA of PD (read-only after create) */
- vaddr_t pm_pdir; /* VA of PD (lck by object lock) */
- int pm_pdirsize; /* PD size (4k vs 16k on pae */
struct uvm_object pm_obj; /* object (lck by object lock) */
#define pm_lock pm_obj.vmobjlock
LIST_ENTRY(pmap) pm_list; /* list (lck by pm_list lock) */
+ pd_entry_t *pm_pdir; /* VA of PD (lck by object lock) */
+ paddr_t pm_pdirpa; /* PA of PD (read-only after create) */
struct vm_page *pm_ptphint; /* pointer to a PTP in our pmap */
- struct pmap_statistics pm_stats;/* pmap stats (lck by object lock) */
+ struct pmap_statistics pm_stats; /* pmap stats (lck by object lock) */
vaddr_t pm_hiexec; /* highest executable mapping */
int pm_flags; /* see below */
@@ -172,185 +333,67 @@ struct pv_page {
/*
* global kernel variables
*/
-extern char PTD[];
+
+extern pd_entry_t PTD[];
+
+/* PTDpaddr: is the physical address of the kernel's PDP */
+extern u_int32_t PTDpaddr;
+
extern struct pmap kernel_pmap_store; /* kernel pmap */
-extern int nkptp_max;
+extern int nkpde; /* current # of PDEs for kernel */
+extern int pmap_pg_g; /* do we support PG_G? */
/*
- * Our dual-pmap design requires to play a pointer-and-seek.
- * Although being nice folks we are handle single-pmap kernels special.
+ * Macros
*/
-#define PMAP_EXCLUDE_DECLS /* tells uvm_pmap.h *not* to include decls */
-/*
- * Dumb macros
- */
#define pmap_kernel() (&kernel_pmap_store)
#define pmap_resident_count(pmap) ((pmap)->pm_stats.resident_count)
#define pmap_update(pm) /* nada */
-#define pmap_clear_modify(pg) pmap_change_attrs(pg, 0, PG_M)
-#define pmap_clear_reference(pg) pmap_change_attrs(pg, 0, PG_U)
-#define pmap_copy(DP,SP,D,L,S) /* nicht */
-#define pmap_is_modified(pg) pmap_test_attrs(pg, PG_M)
-#define pmap_is_referenced(pg) pmap_test_attrs(pg, PG_U)
-#define pmap_phys_address(ppn) ptoa(ppn)
-#define pmap_valid_entry(E) ((E) & PG_V) /* is PDE or PTE valid? */
+#define pmap_clear_modify(pg) pmap_change_attrs(pg, 0, PG_M)
+#define pmap_clear_reference(pg) pmap_change_attrs(pg, 0, PG_U)
+#define pmap_copy(DP,SP,D,L,S)
+#define pmap_is_modified(pg) pmap_test_attrs(pg, PG_M)
+#define pmap_is_referenced(pg) pmap_test_attrs(pg, PG_U)
+#define pmap_phys_address(ppn) ptoa(ppn)
+#define pmap_valid_entry(E) ((E) & PG_V) /* is PDE or PTE valid? */
+
+#define pmap_proc_iflush(p,va,len) /* nothing */
+#define pmap_unuse_final(p) /* nothing */
-#define pmap_proc_iflush(p,va,len) /* nothing */
-#define pmap_unuse_final(p) /* 4anaEB u nycToTa */
/*
* Prototypes
*/
+
void pmap_bootstrap(vaddr_t);
-void pmap_bootstrap_pae(void);
-void pmap_virtual_space(vaddr_t *, vaddr_t *);
-void pmap_init(void);
-struct pmap * pmap_create(void);
-void pmap_destroy(struct pmap *);
-void pmap_reference(struct pmap *);
-void pmap_fork(struct pmap *, struct pmap *);
-void pmap_collect(struct pmap *);
-void pmap_activate(struct proc *);
-void pmap_deactivate(struct proc *);
-void pmap_kenter_pa(vaddr_t, paddr_t, vm_prot_t);
-void pmap_kremove(vaddr_t, vsize_t);
-void pmap_zero_page(struct vm_page *);
-void pmap_copy_page(struct vm_page *, struct vm_page *);
-
-struct pv_entry*pmap_alloc_pv(struct pmap *, int);
-void pmap_enter_pv(struct pv_head *, struct pv_entry *,
- struct pmap *, vaddr_t, struct vm_page *);
-void pmap_free_pv(struct pmap *, struct pv_entry *);
-void pmap_free_pvs(struct pmap *, struct pv_entry *);
-void pmap_free_pv_doit(struct pv_entry *);
-void pmap_free_pvpage(void);
+boolean_t pmap_change_attrs(struct vm_page *, int, int);
static void pmap_page_protect(struct vm_page *, vm_prot_t);
-static void pmap_protect(struct pmap *, vaddr_t, vaddr_t, vm_prot_t);
+void pmap_page_remove(struct vm_page *);
+static void pmap_protect(struct pmap *, vaddr_t,
+ vaddr_t, vm_prot_t);
+void pmap_remove(struct pmap *, vaddr_t, vaddr_t);
+boolean_t pmap_test_attrs(struct vm_page *, int);
static void pmap_update_pg(vaddr_t);
-static void pmap_update_2pg(vaddr_t, vaddr_t);
+static void pmap_update_2pg(vaddr_t,vaddr_t);
+void pmap_write_protect(struct pmap *, vaddr_t,
+ vaddr_t, vm_prot_t);
int pmap_exec_fixup(struct vm_map *, struct trapframe *,
struct pcb *);
-void pmap_exec_account(struct pmap *, vaddr_t, u_int32_t,
- u_int32_t);
vaddr_t reserve_dumppages(vaddr_t); /* XXX: not a pmap fn */
-paddr_t vtophys(vaddr_t va);
-void pmap_tlb_shootdown(pmap_t, vaddr_t, u_int32_t, int32_t *);
+void pmap_tlb_shootdown(pmap_t, vaddr_t, pt_entry_t, int32_t *);
void pmap_tlb_shootnow(int32_t);
void pmap_do_tlb_shootdown(struct cpu_info *);
-boolean_t pmap_is_curpmap(struct pmap *);
-boolean_t pmap_is_active(struct pmap *, int);
-void pmap_apte_flush(struct pmap *);
-struct pv_entry *pmap_remove_pv(struct pv_head *, struct pmap *, vaddr_t);
-
-#ifdef SMALL_KERNEL
-#define pmap_pte_set_86 pmap_pte_set
-#define pmap_pte_setbits_86 pmap_pte_setbits
-#define pmap_pte_bits_86 pmap_pte_bits
-#define pmap_pte_paddr_86 pmap_pte_paddr
-#define pmap_change_attrs_86 pmap_change_attrs
-#define pmap_enter_86 pmap_enter
-#define pmap_extract_86 pmap_extract
-#define pmap_growkernel_86 pmap_growkernel
-#define pmap_page_remove_86 pmap_page_remove
-#define pmap_remove_86 pmap_remove
-#define pmap_test_attrs_86 pmap_test_attrs
-#define pmap_unwire_86 pmap_unwire
-#define pmap_write_protect_86 pmap_write_protect
-#define pmap_pinit_pd_86 pmap_pinit_pd
-#define pmap_zero_phys_86 pmap_zero_phys
-#define pmap_zero_page_uncached_86 pmap_zero_page_uncached
-#define pmap_copy_page_86 pmap_copy_page
-#define pmap_try_steal_pv_86 pmap_try_steal_pv
-#else
-extern u_int32_t (*pmap_pte_set_p)(vaddr_t, paddr_t, u_int32_t);
-extern u_int32_t (*pmap_pte_setbits_p)(vaddr_t, u_int32_t, u_int32_t);
-extern u_int32_t (*pmap_pte_bits_p)(vaddr_t);
-extern paddr_t (*pmap_pte_paddr_p)(vaddr_t);
-extern boolean_t (*pmap_change_attrs_p)(struct vm_page *, int, int);
-extern int (*pmap_enter_p)(pmap_t, vaddr_t, paddr_t, vm_prot_t, int);
-extern boolean_t (*pmap_extract_p)(pmap_t, vaddr_t, paddr_t *);
-extern vaddr_t (*pmap_growkernel_p)(vaddr_t);
-extern void (*pmap_page_remove_p)(struct vm_page *);
-extern void (*pmap_remove_p)(struct pmap *, vaddr_t, vaddr_t);
-extern boolean_t (*pmap_test_attrs_p)(struct vm_page *, int);
-extern void (*pmap_unwire_p)(struct pmap *, vaddr_t);
-extern void (*pmap_write_protect_p)(struct pmap*, vaddr_t, vaddr_t, vm_prot_t);
-extern void (*pmap_pinit_pd_p)(pmap_t);
-extern void (*pmap_zero_phys_p)(paddr_t);
-extern boolean_t (*pmap_zero_page_uncached_p)(paddr_t);
-extern void (*pmap_copy_page_p)(struct vm_page *, struct vm_page *);
-extern boolean_t (*pmap_try_steal_pv_p)(struct pv_head *pvh,
- struct pv_entry *cpv, struct pv_entry *prevpv);
-
-u_int32_t pmap_pte_set_pae(vaddr_t, paddr_t, u_int32_t);
-u_int32_t pmap_pte_setbits_pae(vaddr_t, u_int32_t, u_int32_t);
-u_int32_t pmap_pte_bits_pae(vaddr_t);
-paddr_t pmap_pte_paddr_pae(vaddr_t);
-boolean_t pmap_try_steal_pv_pae(struct pv_head *pvh, struct pv_entry *cpv,
- struct pv_entry *prevpv);
-boolean_t pmap_change_attrs_pae(struct vm_page *, int, int);
-int pmap_enter_pae(pmap_t, vaddr_t, paddr_t, vm_prot_t, int);
-boolean_t pmap_extract_pae(pmap_t, vaddr_t, paddr_t *);
-vaddr_t pmap_growkernel_pae(vaddr_t);
-void pmap_page_remove_pae(struct vm_page *);
-void pmap_remove_pae(struct pmap *, vaddr_t, vaddr_t);
-boolean_t pmap_test_attrs_pae(struct vm_page *, int);
-void pmap_unwire_pae(struct pmap *, vaddr_t);
-void pmap_write_protect_pae(struct pmap *, vaddr_t, vaddr_t, vm_prot_t);
-void pmap_pinit_pd_pae(pmap_t);
-void pmap_zero_phys_pae(paddr_t);
-boolean_t pmap_zero_page_uncached_pae(paddr_t);
-void pmap_copy_page_pae(struct vm_page *, struct vm_page *);
-
-#define pmap_pte_set (*pmap_pte_set_p)
-#define pmap_pte_setbits (*pmap_pte_setbits_p)
-#define pmap_pte_bits (*pmap_pte_bits_p)
-#define pmap_pte_paddr (*pmap_pte_paddr_p)
-#define pmap_change_attrs (*pmap_change_attrs_p)
-#define pmap_enter (*pmap_enter_p)
-#define pmap_extract (*pmap_extract_p)
-#define pmap_growkernel (*pmap_growkernel_p)
-#define pmap_page_remove (*pmap_page_remove_p)
-#define pmap_remove (*pmap_remove_p)
-#define pmap_test_attrs (*pmap_test_attrs_p)
-#define pmap_unwire (*pmap_unwire_p)
-#define pmap_write_protect (*pmap_write_protect_p)
-#define pmap_pinit_pd (*pmap_pinit_pd_p)
-#define pmap_zero_phys (*pmap_zero_phys_p)
-#define pmap_zero_page_uncached (*pmap_zero_page_uncached_p)
-#define pmap_copy_page (*pmap_copy_page_p)
-#define pmap_try_steal_pv (*pmap_try_steal_pv_p)
-#endif
-
-u_int32_t pmap_pte_set_86(vaddr_t, paddr_t, u_int32_t);
-u_int32_t pmap_pte_setbits_86(vaddr_t, u_int32_t, u_int32_t);
-u_int32_t pmap_pte_bits_86(vaddr_t);
-paddr_t pmap_pte_paddr_86(vaddr_t);
-boolean_t pmap_try_steal_pv_86(struct pv_head *pvh, struct pv_entry *cpv,
- struct pv_entry *prevpv);
-boolean_t pmap_change_attrs_86(struct vm_page *, int, int);
-int pmap_enter_86(pmap_t, vaddr_t, paddr_t, vm_prot_t, int);
-boolean_t pmap_extract_86(pmap_t, vaddr_t, paddr_t *);
-vaddr_t pmap_growkernel_86(vaddr_t);
-void pmap_page_remove_86(struct vm_page *);
-void pmap_remove_86(struct pmap *, vaddr_t, vaddr_t);
-boolean_t pmap_test_attrs_86(struct vm_page *, int);
-void pmap_unwire_86(struct pmap *, vaddr_t);
-void pmap_write_protect_86(struct pmap *, vaddr_t, vaddr_t, vm_prot_t);
-void pmap_pinit_pd_86(pmap_t);
-void pmap_zero_phys_86(paddr_t);
-boolean_t pmap_zero_page_uncached_86(paddr_t);
-void pmap_copy_page_86(struct vm_page *, struct vm_page *);
#define PMAP_GROWKERNEL /* turn on pmap_growkernel interface */
/*
* Do idle page zero'ing uncached to avoid polluting the cache.
*/
+boolean_t pmap_zero_page_uncached(paddr_t);
#define PMAP_PAGEIDLEZERO(pg) pmap_zero_page_uncached(VM_PAGE_TO_PHYS(pg))
/*