1997-06-13 03:57:26 +04:00
|
|
|
/* $NetBSD: pmap.h,v 1.26 1997/06/12 23:57:30 thorpej Exp $ */
|
1994-10-27 07:14:23 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1995-10-11 07:19:29 +03:00
|
|
|
* Copyright (c) 1995 Charles M. Hannum. All rights reserved.
|
1993-03-21 12:45:37 +03:00
|
|
|
* Copyright (c) 1991 Regents of the University of California.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* the Systems Programming Group of the University of Utah Computer
|
|
|
|
* Science Department and William Jolitz of UUNET Technologies Inc.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
|
|
|
|
*
|
1994-10-27 07:14:23 +03:00
|
|
|
* @(#)pmap.h 7.4 (Berkeley) 5/12/91
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Derived from hp300 version by Mike Hibler, this version by William
|
|
|
|
* Jolitz uses a recursive map [a pde points to the page directory] to
|
|
|
|
* map the page tables using the pagetables themselves. This is done to
|
|
|
|
* reduce the impact on kernel virtual memory for lots of sparse address
|
|
|
|
* space, and to reduce the cost of memory to each process.
|
|
|
|
*
|
|
|
|
* from hp300: @(#)pmap.h 7.2 (Berkeley) 12/16/90
|
|
|
|
*/
|
|
|
|
|
1993-12-14 08:31:17 +03:00
|
|
|
#ifndef _I386_PMAP_H_
|
|
|
|
#define _I386_PMAP_H_
|
|
|
|
|
1994-10-09 18:00:38 +03:00
|
|
|
#include <machine/cpufunc.h>
|
1993-12-14 08:31:17 +03:00
|
|
|
#include <machine/pte.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 386 page table entry and page table directory
|
|
|
|
* W.Jolitz, 8/89
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* One page directory, shared between
|
|
|
|
* kernel and user modes.
|
|
|
|
*/
|
1994-01-05 19:02:36 +03:00
|
|
|
#define PTDPTDI 0x3df /* ptd entry that points to ptd! */
|
|
|
|
#define KPTDI 0x3e0 /* start of kernel virtual pde's */
|
1996-11-18 04:06:09 +03:00
|
|
|
#define NKPDE_BASE 4 /* min. # of kernel PDEs */
|
|
|
|
#define NKPDE_MAX 31 /* max. # of kernel PDEs */
|
|
|
|
#define NKPDE_SCALE 1 /* # of kernel PDEs to add per meg. */
|
1993-12-14 08:31:17 +03:00
|
|
|
#define APTDPTDI 0x3ff /* start of alternate page directory */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Address of current and alternate address space page table maps
|
|
|
|
* and directories.
|
|
|
|
*/
|
1995-03-28 22:13:48 +04:00
|
|
|
#ifdef _KERNEL
|
1994-08-15 18:46:45 +04:00
|
|
|
extern pt_entry_t PTmap[], APTmap[], Upte;
|
|
|
|
extern pd_entry_t PTD[], APTD[], PTDpde, APTDpde, Upde;
|
1993-12-14 08:31:17 +03:00
|
|
|
extern pt_entry_t *Sysmap;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1995-06-26 17:25:29 +04:00
|
|
|
extern int PTDpaddr; /* physical address of kernel PTD */
|
1994-09-08 00:48:52 +04:00
|
|
|
|
|
|
|
void pmap_bootstrap __P((vm_offset_t start));
|
|
|
|
boolean_t pmap_testbit __P((vm_offset_t, int));
|
|
|
|
void pmap_changebit __P((vm_offset_t, int, int));
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* virtual address to page table entry and
|
|
|
|
* to physical address. Likewise for alternate address space.
|
|
|
|
* Note: these work recursively, thus vtopte of a pte will give
|
|
|
|
* the corresponding pde that in turn maps it.
|
|
|
|
*/
|
|
|
|
#define vtopte(va) (PTmap + i386_btop(va))
|
|
|
|
#define kvtopte(va) vtopte(va)
|
|
|
|
#define ptetov(pt) (i386_ptob(pt - PTmap))
|
1993-12-14 08:31:17 +03:00
|
|
|
#define vtophys(va) \
|
1994-08-15 18:46:45 +04:00
|
|
|
((*vtopte(va) & PG_FRAME) | ((unsigned)(va) & ~PG_FRAME))
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
#define avtopte(va) (APTmap + i386_btop(va))
|
|
|
|
#define ptetoav(pt) (i386_ptob(pt - APTmap))
|
1993-12-14 08:31:17 +03:00
|
|
|
#define avtophys(va) \
|
1994-08-15 18:46:45 +04:00
|
|
|
((*avtopte(va) & PG_FRAME) | ((unsigned)(va) & ~PG_FRAME))
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* macros to generate page directory/table indicies
|
|
|
|
*/
|
1994-08-15 18:46:45 +04:00
|
|
|
#define pdei(va) (((va) & PD_MASK) >> PDSHIFT)
|
|
|
|
#define ptei(va) (((va) & PT_MASK) >> PGSHIFT)
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Pmap stuff
|
|
|
|
*/
|
1994-09-08 00:48:52 +04:00
|
|
|
typedef struct pmap {
|
1993-03-21 12:45:37 +03:00
|
|
|
pd_entry_t *pm_pdir; /* KVA of page directory */
|
|
|
|
boolean_t pm_pdchanged; /* pdir changed */
|
|
|
|
short pm_dref; /* page directory ref count */
|
|
|
|
short pm_count; /* pmap reference count */
|
|
|
|
simple_lock_data_t pm_lock; /* lock on pmap */
|
|
|
|
struct pmap_statistics pm_stats; /* pmap statistics */
|
|
|
|
long pm_ptpages; /* more stats: PT pages */
|
1994-09-08 00:48:52 +04:00
|
|
|
} *pmap_t;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* For each vm_page_t, there is a list of all currently valid virtual
|
1994-09-08 00:48:52 +04:00
|
|
|
* mappings of that page. An entry is a pv_entry, the list is pv_table.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
1994-09-08 00:48:52 +04:00
|
|
|
struct pv_entry {
|
1993-03-21 12:45:37 +03:00
|
|
|
struct pv_entry *pv_next; /* next pv_entry */
|
|
|
|
pmap_t pv_pmap; /* pmap where mapping lies */
|
|
|
|
vm_offset_t pv_va; /* virtual address for mapping */
|
1994-09-08 00:48:52 +04:00
|
|
|
};
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-09-08 00:48:52 +04:00
|
|
|
struct pv_page;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-09-08 00:48:52 +04:00
|
|
|
struct pv_page_info {
|
|
|
|
TAILQ_ENTRY(pv_page) pgi_list;
|
|
|
|
struct pv_entry *pgi_freelist;
|
|
|
|
int pgi_nfree;
|
|
|
|
};
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-09-08 00:48:52 +04:00
|
|
|
/*
|
|
|
|
* This is basically:
|
|
|
|
* ((NBPG - sizeof(struct pv_page_info)) / sizeof(struct pv_entry))
|
|
|
|
*/
|
|
|
|
#define NPVPPG 340
|
|
|
|
|
|
|
|
struct pv_page {
|
|
|
|
struct pv_page_info pvp_pgi;
|
|
|
|
struct pv_entry pvp_pv[NPVPPG];
|
|
|
|
};
|
|
|
|
|
1995-05-11 20:52:54 +04:00
|
|
|
#ifdef _KERNEL
|
1996-11-18 04:06:09 +03:00
|
|
|
extern int nkpde; /* number of kernel page dir. ents */
|
1994-09-10 03:58:48 +04:00
|
|
|
extern struct pmap kernel_pmap_store;
|
|
|
|
struct pv_entry *pv_table; /* array of entries, one per page */
|
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)
|
1994-10-09 16:11:18 +03:00
|
|
|
#define pmap_update() tlbflush()
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1996-05-03 23:26:28 +04:00
|
|
|
vm_offset_t reserve_dumppages __P((vm_offset_t));
|
|
|
|
|
1994-09-08 00:48:52 +04:00
|
|
|
static __inline void
|
|
|
|
pmap_clear_modify(vm_offset_t pa)
|
|
|
|
{
|
|
|
|
pmap_changebit(pa, 0, ~PG_M);
|
|
|
|
}
|
|
|
|
|
|
|
|
static __inline void
|
|
|
|
pmap_clear_reference(vm_offset_t pa)
|
|
|
|
{
|
|
|
|
pmap_changebit(pa, 0, ~PG_U);
|
|
|
|
}
|
|
|
|
|
|
|
|
static __inline void
|
|
|
|
pmap_copy_on_write(vm_offset_t pa)
|
|
|
|
{
|
|
|
|
pmap_changebit(pa, PG_RO, ~PG_RW);
|
|
|
|
}
|
|
|
|
|
|
|
|
static __inline boolean_t
|
|
|
|
pmap_is_modified(vm_offset_t pa)
|
|
|
|
{
|
|
|
|
return pmap_testbit(pa, PG_M);
|
|
|
|
}
|
|
|
|
|
|
|
|
static __inline boolean_t
|
|
|
|
pmap_is_referenced(vm_offset_t pa)
|
|
|
|
{
|
|
|
|
return pmap_testbit(pa, PG_U);
|
|
|
|
}
|
|
|
|
|
|
|
|
static __inline vm_offset_t
|
|
|
|
pmap_phys_address(int ppn)
|
|
|
|
{
|
|
|
|
return i386_ptob(ppn);
|
|
|
|
}
|
|
|
|
|
1996-05-03 23:26:28 +04:00
|
|
|
void pmap_activate __P((pmap_t, struct pcb *));
|
|
|
|
|
1995-03-28 22:13:48 +04:00
|
|
|
#endif /* _KERNEL */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1993-12-14 08:31:17 +03:00
|
|
|
#endif /* _I386_PMAP_H_ */
|