2002-11-02 10:07:09 +03:00
|
|
|
/* $NetBSD: pmap.h,v 1.66 2002/11/02 07:07:09 perry Exp $ */
|
1998-08-15 08:57:50 +04:00
|
|
|
|
1999-06-17 04:12:10 +04:00
|
|
|
/*
|
1998-08-15 08:57:50 +04:00
|
|
|
*
|
1999-06-17 04:12:10 +04:00
|
|
|
* Copyright (c) 1997 Charles D. Cranor and Washington University.
|
1993-03-21 12:45:37 +03:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
1999-06-17 04:12:10 +04:00
|
|
|
* must display the following acknowledgment:
|
|
|
|
* This product includes software developed by Charles D. Cranor and
|
|
|
|
* Washington University.
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
1999-06-17 04:12:10 +04:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
1999-06-17 04:12:10 +04:00
|
|
|
* pmap.h: see pmap.c for the history of this pmap module.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
|
|
|
|
1999-06-17 04:12:10 +04:00
|
|
|
#ifndef _I386_PMAP_H_
|
|
|
|
#define _I386_PMAP_H_
|
|
|
|
|
2001-05-30 15:57:16 +04:00
|
|
|
#if defined(_KERNEL_OPT)
|
1999-05-12 23:28:28 +04:00
|
|
|
#include "opt_user_ldt.h"
|
2000-09-07 21:20:58 +04:00
|
|
|
#include "opt_largepages.h"
|
1998-02-10 17:08:44 +03:00
|
|
|
#endif
|
|
|
|
|
1994-10-09 18:00:38 +03:00
|
|
|
#include <machine/cpufunc.h>
|
1993-12-14 08:31:17 +03:00
|
|
|
#include <machine/pte.h>
|
1999-05-12 23:28:28 +04:00
|
|
|
#include <machine/segments.h>
|
1999-06-17 04:12:10 +04:00
|
|
|
#include <uvm/uvm_object.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
1999-06-17 04:12:10 +04:00
|
|
|
* see pte.h for a description of i386 MMU terminology and hardware
|
|
|
|
* interface.
|
|
|
|
*
|
|
|
|
* a pmap describes a processes' 4GB virtual address space. this
|
|
|
|
* virtual address space can be broken up into 1024 4MB regions which
|
1999-07-19 01:33:20 +04:00
|
|
|
* are described by PDEs in the PDP. the PDEs are defined as follows:
|
1999-06-17 04:12:10 +04:00
|
|
|
*
|
|
|
|
* (ranges are inclusive -> exclusive, just like vm_map_entry start/end)
|
2000-02-11 10:00:11 +03:00
|
|
|
* (the following assumes that KERNBASE is 0xc0000000)
|
1999-06-17 04:12:10 +04:00
|
|
|
*
|
|
|
|
* PDE#s VA range usage
|
2002-10-01 16:56:36 +04:00
|
|
|
* 0->766 0x0 -> 0xbfc00000 user address space, note that the
|
2000-02-11 10:00:11 +03:00
|
|
|
* max user address is 0xbfbfe000
|
1999-06-17 04:12:10 +04:00
|
|
|
* the final two pages in the last 4MB
|
|
|
|
* used to be reserved for the UAREA
|
|
|
|
* but now are no longer used
|
2001-11-07 13:52:08 +03:00
|
|
|
* 767 0xbfc00000-> recursive mapping of PDP (used for
|
2000-02-11 10:00:11 +03:00
|
|
|
* 0xc0000000 linear mapping of PTPs)
|
|
|
|
* 768->1023 0xc0000000-> kernel address space (constant
|
1999-06-17 04:12:10 +04:00
|
|
|
* 0xffc00000 across all pmap's/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
|
1999-07-19 01:33:20 +04:00
|
|
|
* 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
|
1999-06-17 04:12:10 +04:00
|
|
|
* 4MB range is the PTE that maps VA 0xffffe000 (the last page in a 4GB
|
|
|
|
* address).
|
|
|
|
*
|
2000-02-11 10:00:11 +03:00
|
|
|
* all pmap's PD's must have the same values in slots 768->1023 so that
|
1999-07-19 01:33:20 +04:00
|
|
|
* the kernel is always mapped in every process. these values are loaded
|
1999-06-17 04:12:10 +04:00
|
|
|
* into the PD at pmap creation time.
|
|
|
|
*
|
1999-07-19 01:33:20 +04:00
|
|
|
* 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
|
1999-06-17 04:12:10 +04:00
|
|
|
* will have all its PTEs mapped into memory at the recursive mapping
|
2000-02-11 10:00:11 +03:00
|
|
|
* point (slot #767 as show above). when the pmap code wants to find the
|
1999-06-17 04:12:10 +04:00
|
|
|
* PTE for a virtual address, all it has to do is the following:
|
|
|
|
*
|
2000-02-11 10:00:11 +03:00
|
|
|
* address of PTE = (767 * 4MB) + (VA / NBPG) * sizeof(pt_entry_t)
|
|
|
|
* = 0xbfc00000 + (VA / 4096) * 4
|
1999-06-17 04:12:10 +04:00
|
|
|
*
|
|
|
|
* what happens if the pmap layer is asked to perform an operation
|
1999-07-19 01:33:20 +04:00
|
|
|
* 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
|
1999-06-17 04:12:10 +04:00
|
|
|
* 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
|
|
|
|
* | |
|
|
|
|
* | |
|
2000-02-11 10:00:11 +03:00
|
|
|
* | 767| -> points back to PDP (%cr3) mapping VA 0xbfc00000 -> 0xc0000000
|
|
|
|
* | 768| -> first kernel PTP (maps 0xc0000000 -> 0xf0400000)
|
1999-06-17 04:12:10 +04:00
|
|
|
* | |
|
|
|
|
* |1023| -> points to alternate pmap's PDP (maps 0xffc00000 -> end)
|
|
|
|
* +----+
|
|
|
|
*
|
2000-02-11 10:00:11 +03:00
|
|
|
* note that the PDE#767 VA (0xbfc00000) is defined as "PTE_BASE"
|
1999-06-17 04:12:10 +04:00
|
|
|
* note that the PDE#1023 VA (0xffc00000) is defined as "APTE_BASE"
|
|
|
|
*
|
2000-02-11 10:00:11 +03:00
|
|
|
* starting at VA 0xbfc00000 the current active PDP (%cr3) acts as a
|
1999-06-17 04:12:10 +04:00
|
|
|
* PTP:
|
|
|
|
*
|
2000-02-11 10:00:11 +03:00
|
|
|
* PTP#767 == PDP(%cr3) => maps VA 0xbfc00000 -> 0xc0000000
|
1999-06-17 04:12:10 +04:00
|
|
|
* +----+
|
2000-02-11 10:00:11 +03:00
|
|
|
* | 0| -> maps the contents of PTP#0 at VA 0xbfc00000->0xbfc01000
|
1999-06-17 04:12:10 +04:00
|
|
|
* | |
|
|
|
|
* | |
|
2000-02-11 10:00:11 +03:00
|
|
|
* | 767| -> maps contents of PTP#767 (the PDP) at VA 0xbffbf000
|
|
|
|
* | 768| -> maps contents of first kernel PTP
|
1999-06-17 04:12:10 +04:00
|
|
|
* | |
|
|
|
|
* |1023|
|
|
|
|
* +----+
|
|
|
|
*
|
2002-10-01 16:56:36 +04:00
|
|
|
* note that mapping of the PDP at PTP#767's VA (0xbffbf000) is
|
1999-06-17 04:12:10 +04:00
|
|
|
* defined as "PDP_BASE".... within that mapping there are two
|
1999-07-19 01:33:20 +04:00
|
|
|
* defines:
|
2001-08-12 04:20:32 +04:00
|
|
|
* "PDP_PDE" (0xbfeffbfc) is the VA of the PDE in the PDP
|
1999-07-19 01:33:20 +04:00
|
|
|
* which points back to itself.
|
2001-08-12 04:20:32 +04:00
|
|
|
* "APDP_PDE" (0xbfeffffc) is the VA of the PDE in the PDP which
|
1999-06-17 04:12:10 +04:00
|
|
|
* 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.
|
|
|
|
*
|
1999-07-19 01:33:20 +04:00
|
|
|
* note that in the APTE_BASE space, the APDP appears at VA
|
1999-06-17 04:12:10 +04:00
|
|
|
* "APDP_BASE" (0xfffff000).
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
2002-10-01 16:56:36 +04:00
|
|
|
/* XXX MP should we allocate one APDP_PDE per processor?? */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1998-02-06 10:21:42 +03:00
|
|
|
/*
|
1999-06-17 04:12:10 +04:00
|
|
|
* the following defines identify the slots used as described above.
|
1998-02-06 10:21:42 +03:00
|
|
|
*/
|
|
|
|
|
2000-02-11 10:00:11 +03:00
|
|
|
#define PDSLOT_PTE ((KERNBASE/NBPD)-1) /* 767: for recursive PDP map */
|
|
|
|
#define PDSLOT_KERN (KERNBASE/NBPD) /* 768: start of kernel space */
|
1999-06-17 04:12:10 +04:00
|
|
|
#define PDSLOT_APTE ((unsigned)1023) /* 1023: alternative recursive slot */
|
1998-02-06 10:21:42 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1999-07-19 01:33:20 +04:00
|
|
|
* the following defines give the virtual addresses of various MMU
|
1999-06-17 04:12:10 +04:00
|
|
|
* 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
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
|
|
|
|
1999-06-17 04:12:10 +04:00
|
|
|
#define PTE_BASE ((pt_entry_t *) (PDSLOT_PTE * NBPD) )
|
|
|
|
#define APTE_BASE ((pt_entry_t *) (PDSLOT_APTE * NBPD) )
|
1999-07-19 01:33:20 +04:00
|
|
|
#define PDP_BASE ((pd_entry_t *)(((char *)PTE_BASE) + (PDSLOT_PTE * NBPG)))
|
|
|
|
#define APDP_BASE ((pd_entry_t *)(((char *)APTE_BASE) + (PDSLOT_APTE * NBPG)))
|
1999-06-17 04:12:10 +04:00
|
|
|
#define PDP_PDE (PDP_BASE + PDSLOT_PTE)
|
|
|
|
#define APDP_PDE (PDP_BASE + PDSLOT_APTE)
|
1997-12-08 00:30:11 +03:00
|
|
|
|
1999-06-17 04:12:10 +04:00
|
|
|
/*
|
|
|
|
* the follow define determines how many PTPs should be set up for the
|
1999-07-19 01:33:20 +04:00
|
|
|
* kernel by locore.s at boot time. this should be large enough to
|
|
|
|
* get the VM system running. once the VM system is running, the
|
1999-06-17 04:12:10 +04:00
|
|
|
* pmap module can add more PTPs to the kernel area on demand.
|
|
|
|
*/
|
1994-09-08 00:48:52 +04:00
|
|
|
|
1999-06-17 04:12:10 +04:00
|
|
|
#ifndef NKPTP
|
|
|
|
#define NKPTP 4 /* 16MB to start */
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif
|
1999-06-17 04:12:10 +04:00
|
|
|
#define NKPTP_MIN 4 /* smallest value we allow */
|
|
|
|
#define NKPTP_MAX (1024 - (KERNBASE/NBPD) - 1)
|
|
|
|
/* largest value (-1 for APTP space) */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
1999-06-17 04:12:10 +04:00
|
|
|
* pdei/ptei: generate index into PDP/PTP from a VA
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
1999-06-17 04:12:10 +04:00
|
|
|
#define pdei(VA) (((VA) & PD_MASK) >> PDSHIFT)
|
|
|
|
#define ptei(VA) (((VA) & PT_MASK) >> PGSHIFT)
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
1999-06-17 04:12:10 +04:00
|
|
|
* 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)
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
1999-05-12 23:28:28 +04:00
|
|
|
|
1999-06-17 04:12:10 +04:00
|
|
|
#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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define PG_W PG_AVAIL1 /* "wired" mapping */
|
|
|
|
#define PG_PVLIST PG_AVAIL2 /* mapping has entry on pvlist */
|
|
|
|
/* PG_AVAIL3 not used */
|
|
|
|
|
2002-10-01 16:56:36 +04:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
|
1999-06-17 04:12:10 +04:00
|
|
|
#ifdef _KERNEL
|
|
|
|
/*
|
|
|
|
* pmap data structures: see pmap.c for details of locking.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct pmap;
|
|
|
|
typedef struct pmap *pmap_t;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* we maintain a list of all non-kernel pmaps
|
|
|
|
*/
|
|
|
|
|
|
|
|
LIST_HEAD(pmap_head, pmap); /* struct pmap_head: head of a pmap list */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* the pmap structure
|
|
|
|
*
|
|
|
|
* note that the pm_obj contains the simple_lock, the reference count,
|
|
|
|
* page list, and number of PTPs within the pmap.
|
2002-10-01 16:56:36 +04:00
|
|
|
*
|
|
|
|
* XXX If we ever support processor numbers higher than 31, we'll have
|
|
|
|
* XXX to rethink the CPU mask.
|
1999-06-17 04:12:10 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
struct pmap {
|
1999-07-19 01:33:20 +04:00
|
|
|
struct uvm_object pm_obj; /* object (lck by object lock) */
|
1999-06-17 04:12:10 +04:00
|
|
|
#define pm_lock pm_obj.vmobjlock
|
1999-07-19 01:33:20 +04:00
|
|
|
LIST_ENTRY(pmap) pm_list; /* list (lck by pm_list lock) */
|
|
|
|
pd_entry_t *pm_pdir; /* VA of PD (lck by object lock) */
|
|
|
|
u_int32_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) */
|
1999-06-17 04:12:10 +04:00
|
|
|
|
1999-07-19 01:33:20 +04:00
|
|
|
int pm_flags; /* see below */
|
1999-05-12 23:28:28 +04:00
|
|
|
|
1999-07-19 01:33:20 +04:00
|
|
|
union descriptor *pm_ldt; /* user-set LDT */
|
|
|
|
int pm_ldt_len; /* number of LDT entries */
|
|
|
|
int pm_ldt_sel; /* LDT selector */
|
2002-10-01 16:56:36 +04:00
|
|
|
u_int32_t pm_cpus; /* mask of CPUs using pmap */
|
1999-06-17 04:12:10 +04:00
|
|
|
};
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1999-05-12 23:28:28 +04:00
|
|
|
/* pm_flags */
|
|
|
|
#define PMF_USER_LDT 0x01 /* pmap has user-set LDT */
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1999-06-17 04:12:10 +04:00
|
|
|
* for each managed physical page we maintain a list of <PMAP,VA>'s
|
1999-07-19 01:33:20 +04:00
|
|
|
* which it is mapped at. the list is headed by a pv_head structure.
|
1999-06-17 04:12:10 +04:00
|
|
|
* there is one pv_head per managed phys page (allocated at boot time).
|
|
|
|
* the pv_head structure points to a list of pv_entry structures (each
|
|
|
|
* describes one mapping).
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
1999-06-17 04:12:10 +04:00
|
|
|
|
|
|
|
struct pv_entry;
|
|
|
|
|
|
|
|
struct pv_head {
|
2001-05-26 20:32:40 +04:00
|
|
|
struct simplelock pvh_lock; /* locks every pv on this list */
|
1999-07-19 01:33:20 +04:00
|
|
|
struct pv_entry *pvh_list; /* head of list (locked by pvh_lock) */
|
1994-09-08 00:48:52 +04:00
|
|
|
};
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1999-07-19 01:33:20 +04:00
|
|
|
struct pv_entry { /* locked by its list's pvh_lock */
|
|
|
|
struct pv_entry *pv_next; /* next entry */
|
|
|
|
struct pmap *pv_pmap; /* the pmap */
|
|
|
|
vaddr_t pv_va; /* the virtual address */
|
|
|
|
struct vm_page *pv_ptp; /* the vm_page of the PTP */
|
1999-06-17 04:12:10 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* pv_entrys are dynamically allocated in chunks from a single page.
|
|
|
|
* we keep track of how many pv_entrys are in use for each page and
|
1999-07-19 01:33:20 +04:00
|
|
|
* we can free pv_entry pages if needed. there is one lock for the
|
1999-06-17 04:12:10 +04:00
|
|
|
* entire allocation system.
|
|
|
|
*/
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-09-08 00:48:52 +04:00
|
|
|
struct pv_page_info {
|
1999-07-19 01:33:20 +04:00
|
|
|
TAILQ_ENTRY(pv_page) pvpi_list;
|
|
|
|
struct pv_entry *pvpi_pvfree;
|
|
|
|
int pvpi_nfree;
|
1994-09-08 00:48:52 +04:00
|
|
|
};
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-09-08 00:48:52 +04:00
|
|
|
/*
|
1999-06-17 04:12:10 +04:00
|
|
|
* number of pv_entry's in a pv_page
|
|
|
|
* (note: won't work on systems where NPBG isn't a constant)
|
|
|
|
*/
|
|
|
|
|
1999-07-19 01:33:20 +04:00
|
|
|
#define PVE_PER_PVPAGE ((NBPG - sizeof(struct pv_page_info)) / \
|
|
|
|
sizeof(struct pv_entry))
|
1999-06-17 04:12:10 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* a pv_page: where pv_entrys are allocated from
|
1994-09-08 00:48:52 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
struct pv_page {
|
1999-07-19 01:33:20 +04:00
|
|
|
struct pv_page_info pvinfo;
|
|
|
|
struct pv_entry pvents[PVE_PER_PVPAGE];
|
1999-06-17 04:12:10 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* global kernel variables
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* PTDpaddr: is the physical address of the kernel's PDP */
|
|
|
|
extern u_long PTDpaddr;
|
|
|
|
|
|
|
|
extern struct pmap kernel_pmap_store; /* kernel pmap */
|
|
|
|
extern int nkpde; /* current # of PDEs for kernel */
|
|
|
|
extern int pmap_pg_g; /* do we support PG_G? */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* macros
|
|
|
|
*/
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1995-04-10 16:41:29 +04:00
|
|
|
#define pmap_kernel() (&kernel_pmap_store)
|
1993-03-21 12:45:37 +03:00
|
|
|
#define pmap_resident_count(pmap) ((pmap)->pm_stats.resident_count)
|
2000-09-28 17:09:10 +04:00
|
|
|
#define pmap_wired_count(pmap) ((pmap)->pm_stats.wired_count)
|
2001-09-11 01:19:08 +04:00
|
|
|
#define pmap_update(pmap) /* nothing (yet) */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2002-10-01 16:56:36 +04:00
|
|
|
#define pmap_clear_modify(pg) pmap_clear_attrs(pg, PG_M)
|
|
|
|
#define pmap_clear_reference(pg) pmap_clear_attrs(pg, PG_U)
|
|
|
|
#define pmap_copy(DP,SP,D,L,S)
|
1999-06-17 04:12:10 +04:00
|
|
|
#define pmap_is_modified(pg) pmap_test_attrs(pg, PG_M)
|
|
|
|
#define pmap_is_referenced(pg) pmap_test_attrs(pg, PG_U)
|
2002-10-01 16:56:36 +04:00
|
|
|
#define pmap_move(DP,SP,D,L,S)
|
1999-06-17 04:12:10 +04:00
|
|
|
#define pmap_phys_address(ppn) i386_ptob(ppn)
|
|
|
|
#define pmap_valid_entry(E) ((E) & PG_V) /* is PDE or PTE valid? */
|
1996-05-03 23:26:28 +04:00
|
|
|
|
1994-09-08 00:48:52 +04:00
|
|
|
|
1999-06-17 04:12:10 +04:00
|
|
|
/*
|
|
|
|
* prototypes
|
|
|
|
*/
|
|
|
|
|
|
|
|
void pmap_activate __P((struct proc *));
|
|
|
|
void pmap_bootstrap __P((vaddr_t));
|
2002-10-01 16:56:36 +04:00
|
|
|
boolean_t pmap_clear_attrs __P((struct vm_page *, int));
|
1999-06-17 04:12:10 +04:00
|
|
|
void pmap_deactivate __P((struct proc *));
|
|
|
|
void pmap_page_remove __P((struct vm_page *));
|
|
|
|
void pmap_remove __P((struct pmap *, vaddr_t, vaddr_t));
|
|
|
|
boolean_t pmap_test_attrs __P((struct vm_page *, int));
|
1999-07-19 01:33:20 +04:00
|
|
|
void pmap_write_protect __P((struct pmap *, vaddr_t,
|
1999-06-17 04:12:10 +04:00
|
|
|
vaddr_t, vm_prot_t));
|
|
|
|
|
|
|
|
vaddr_t reserve_dumppages __P((vaddr_t)); /* XXX: not a pmap fn */
|
|
|
|
|
2002-10-01 16:56:36 +04:00
|
|
|
void pmap_tlb_shootdown __P((pmap_t, vaddr_t, pt_entry_t, int32_t *));
|
|
|
|
void pmap_tlb_shootnow __P((int32_t));
|
|
|
|
void pmap_do_tlb_shootdown __P((struct cpu_info *));
|
|
|
|
|
1999-06-17 04:12:10 +04:00
|
|
|
#define PMAP_GROWKERNEL /* turn on pmap_growkernel interface */
|
|
|
|
|
2000-04-24 21:18:16 +04:00
|
|
|
/*
|
|
|
|
* Do idle page zero'ing uncached to avoid polluting the cache.
|
|
|
|
*/
|
2001-04-29 08:42:04 +04:00
|
|
|
boolean_t pmap_pageidlezero __P((paddr_t));
|
|
|
|
#define PMAP_PAGEIDLEZERO(pa) pmap_pageidlezero((pa))
|
2000-04-24 21:18:16 +04:00
|
|
|
|
1999-06-17 04:12:10 +04:00
|
|
|
/*
|
|
|
|
* inline functions
|
|
|
|
*/
|
|
|
|
|
2002-11-02 10:07:09 +03:00
|
|
|
/*ARGSUSED*/
|
2002-09-22 11:17:08 +04:00
|
|
|
static __inline void
|
2002-09-22 11:53:39 +04:00
|
|
|
pmap_remove_all(struct pmap *pmap)
|
2002-09-22 11:17:08 +04:00
|
|
|
{
|
|
|
|
/* Nothing. */
|
|
|
|
}
|
|
|
|
|
1999-06-17 04:12:10 +04:00
|
|
|
/*
|
|
|
|
* pmap_update_pg: flush one page from the TLB (or flush the whole thing
|
|
|
|
* if hardware doesn't support one-page flushing)
|
|
|
|
*/
|
|
|
|
|
2001-12-24 02:08:41 +03:00
|
|
|
__inline static void __attribute__((__unused__))
|
|
|
|
pmap_update_pg(vaddr_t va)
|
1994-09-08 00:48:52 +04:00
|
|
|
{
|
1999-06-17 04:12:10 +04:00
|
|
|
#if defined(I386_CPU)
|
1999-07-19 01:33:20 +04:00
|
|
|
if (cpu_class == CPUCLASS_386)
|
2001-01-02 01:13:53 +03:00
|
|
|
tlbflush();
|
1999-07-19 01:33:20 +04:00
|
|
|
else
|
1999-06-17 04:12:10 +04:00
|
|
|
#endif
|
1999-07-19 01:33:20 +04:00
|
|
|
invlpg((u_int) va);
|
1994-09-08 00:48:52 +04:00
|
|
|
}
|
|
|
|
|
1999-06-17 04:12:10 +04:00
|
|
|
/*
|
|
|
|
* pmap_update_2pg: flush two pages from the TLB
|
|
|
|
*/
|
|
|
|
|
2001-12-24 02:08:41 +03:00
|
|
|
__inline static void __attribute__((__unused__))
|
|
|
|
pmap_update_2pg(vaddr_t va, vaddr_t vb)
|
1994-09-08 00:48:52 +04:00
|
|
|
{
|
1999-06-17 04:12:10 +04:00
|
|
|
#if defined(I386_CPU)
|
1999-07-19 01:33:20 +04:00
|
|
|
if (cpu_class == CPUCLASS_386)
|
2001-01-02 01:13:53 +03:00
|
|
|
tlbflush();
|
1999-07-19 01:33:20 +04:00
|
|
|
else
|
1999-06-17 04:12:10 +04:00
|
|
|
#endif
|
1999-07-19 01:33:20 +04:00
|
|
|
{
|
|
|
|
invlpg((u_int) va);
|
|
|
|
invlpg((u_int) vb);
|
|
|
|
}
|
1994-09-08 00:48:52 +04:00
|
|
|
}
|
|
|
|
|
1999-06-17 04:12:10 +04:00
|
|
|
/*
|
|
|
|
* pmap_page_protect: change the protection of all recorded mappings
|
|
|
|
* of a managed page
|
|
|
|
*
|
2002-10-01 16:56:36 +04:00
|
|
|
* => this function is a frontend for pmap_page_remove/pmap_clear_attrs
|
1999-06-17 04:12:10 +04:00
|
|
|
* => we only have to worry about making the page more protected.
|
|
|
|
* unprotecting a page is done on-demand at fault time.
|
|
|
|
*/
|
|
|
|
|
2001-12-24 02:08:41 +03:00
|
|
|
__inline static void __attribute__((__unused__))
|
|
|
|
pmap_page_protect(struct vm_page *pg, vm_prot_t prot)
|
1994-09-08 00:48:52 +04:00
|
|
|
{
|
1999-07-19 01:33:20 +04:00
|
|
|
if ((prot & VM_PROT_WRITE) == 0) {
|
|
|
|
if (prot & (VM_PROT_READ|VM_PROT_EXECUTE)) {
|
2002-10-01 16:56:36 +04:00
|
|
|
(void) pmap_clear_attrs(pg, PG_RW);
|
1999-07-19 01:33:20 +04:00
|
|
|
} else {
|
|
|
|
pmap_page_remove(pg);
|
|
|
|
}
|
|
|
|
}
|
1994-09-08 00:48:52 +04:00
|
|
|
}
|
|
|
|
|
1999-06-17 04:12:10 +04:00
|
|
|
/*
|
|
|
|
* pmap_protect: change the protection of pages in a pmap
|
|
|
|
*
|
|
|
|
* => this function is a frontend for pmap_remove/pmap_write_protect
|
|
|
|
* => we only have to worry about making the page more protected.
|
|
|
|
* unprotecting a page is done on-demand at fault time.
|
|
|
|
*/
|
|
|
|
|
2001-12-24 02:08:41 +03:00
|
|
|
__inline static void __attribute__((__unused__))
|
|
|
|
pmap_protect(struct pmap *pmap, vaddr_t sva, vaddr_t eva, vm_prot_t prot)
|
1994-09-08 00:48:52 +04:00
|
|
|
{
|
1999-07-19 01:33:20 +04:00
|
|
|
if ((prot & VM_PROT_WRITE) == 0) {
|
|
|
|
if (prot & (VM_PROT_READ|VM_PROT_EXECUTE)) {
|
|
|
|
pmap_write_protect(pmap, sva, eva, prot);
|
|
|
|
} else {
|
|
|
|
pmap_remove(pmap, sva, eva);
|
|
|
|
}
|
|
|
|
}
|
1994-09-08 00:48:52 +04:00
|
|
|
}
|
|
|
|
|
2000-09-07 03:32:13 +04:00
|
|
|
/*
|
|
|
|
* various address inlines
|
|
|
|
*
|
|
|
|
* vtopte: return a pointer to the PTE mapping a VA, works only for
|
|
|
|
* user and PT addresses
|
|
|
|
*
|
|
|
|
* kvtopte: return a pointer to the PTE mapping a kernel VA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <lib/libkern/libkern.h>
|
|
|
|
|
2001-12-24 02:08:41 +03:00
|
|
|
static __inline pt_entry_t * __attribute__((__unused__))
|
2000-09-07 03:32:13 +04:00
|
|
|
vtopte(vaddr_t va)
|
|
|
|
{
|
|
|
|
|
|
|
|
KASSERT(va < (PDSLOT_KERN << PDSHIFT));
|
|
|
|
|
|
|
|
return (PTE_BASE + i386_btop(va));
|
|
|
|
}
|
|
|
|
|
2001-12-24 02:08:41 +03:00
|
|
|
static __inline pt_entry_t * __attribute__((__unused__))
|
2000-09-07 03:32:13 +04:00
|
|
|
kvtopte(vaddr_t va)
|
|
|
|
{
|
|
|
|
|
|
|
|
KASSERT(va >= (PDSLOT_KERN << PDSHIFT));
|
|
|
|
|
2000-09-07 21:20:58 +04:00
|
|
|
#ifdef LARGEPAGES
|
|
|
|
{
|
|
|
|
pd_entry_t *pde;
|
|
|
|
|
2000-12-06 06:13:47 +03:00
|
|
|
pde = PDP_BASE + pdei(va);
|
2000-09-07 21:20:58 +04:00
|
|
|
if (*pde & PG_PS)
|
|
|
|
return ((pt_entry_t *)pde);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2000-09-07 03:32:13 +04:00
|
|
|
return (PTE_BASE + i386_btop(va));
|
|
|
|
}
|
|
|
|
|
2000-09-06 23:09:45 +04:00
|
|
|
paddr_t vtophys __P((vaddr_t));
|
1999-07-19 01:33:20 +04:00
|
|
|
vaddr_t pmap_map __P((vaddr_t, paddr_t, paddr_t, vm_prot_t));
|
1998-02-18 05:05:32 +03:00
|
|
|
|
1999-05-12 23:28:28 +04:00
|
|
|
#if defined(USER_LDT)
|
|
|
|
void pmap_ldt_cleanup __P((struct proc *));
|
|
|
|
#define PMAP_FORK
|
|
|
|
#endif /* USER_LDT */
|
|
|
|
|
1999-06-17 04:12:10 +04:00
|
|
|
#endif /* _KERNEL */
|
|
|
|
#endif /* _I386_PMAP_H_ */
|