1*45754Smckusick /* 2*45754Smckusick * Copyright (c) 1987 Carnegie-Mellon University 3*45754Smckusick * Copyright (c) 1991 Regents of the University of California. 4*45754Smckusick * All rights reserved. 5*45754Smckusick * 6*45754Smckusick * This code is derived from software contributed to Berkeley by 7*45754Smckusick * The Mach Operating System project at Carnegie-Mellon University. 8*45754Smckusick * 9*45754Smckusick * The CMU software License Agreement specifies the terms and conditions 10*45754Smckusick * for use and redistribution. 11*45754Smckusick * 12*45754Smckusick * @(#)pmap.h 7.1 (Berkeley) 12/05/90 13*45754Smckusick */ 14*45754Smckusick 15*45754Smckusick #ifndef _PMAP_MACHINE_ 16*45754Smckusick #define _PMAP_MACHINE_ 1 17*45754Smckusick 18*45754Smckusick #ifdef KERNEL 19*45754Smckusick #include "../sys/lock.h" 20*45754Smckusick #include "machine/vmparam.h" 21*45754Smckusick #include "../vm/vm_statistics.h" 22*45754Smckusick #else 23*45754Smckusick #include <sys/lock.h> 24*45754Smckusick #include <machine/vmparam.h> 25*45754Smckusick #include <vm/vm_statistics.h> 26*45754Smckusick #endif /* KERNEL */ 27*45754Smckusick 28*45754Smckusick /* 29*45754Smckusick * HP300 hardware segment/page table entries 30*45754Smckusick */ 31*45754Smckusick 32*45754Smckusick struct ste { 33*45754Smckusick unsigned int sg_pfnum:20; /* page table frame number */ 34*45754Smckusick unsigned int :8; /* reserved at 0 */ 35*45754Smckusick unsigned int :1; /* reserved at 1 */ 36*45754Smckusick unsigned int sg_prot:1; /* write protect bit */ 37*45754Smckusick unsigned int sg_v:2; /* valid bits */ 38*45754Smckusick }; 39*45754Smckusick 40*45754Smckusick struct pte { 41*45754Smckusick unsigned int pg_pfnum:20; /* page frame number or 0 */ 42*45754Smckusick unsigned int :3; 43*45754Smckusick unsigned int pg_w:1; /* is wired */ 44*45754Smckusick unsigned int :1; /* reserved at zero */ 45*45754Smckusick unsigned int pg_ci:1; /* cache inhibit bit */ 46*45754Smckusick unsigned int :1; /* reserved at zero */ 47*45754Smckusick unsigned int pg_m:1; /* hardware modified (dirty) bit */ 48*45754Smckusick unsigned int pg_u:1; /* hardware used (reference) bit */ 49*45754Smckusick unsigned int pg_prot:1; /* write protect bit */ 50*45754Smckusick unsigned int pg_v:2; /* valid bit */ 51*45754Smckusick }; 52*45754Smckusick 53*45754Smckusick typedef struct ste st_entry_t; /* segment table entry */ 54*45754Smckusick typedef struct pte pt_entry_t; /* Mach page table entry */ 55*45754Smckusick 56*45754Smckusick #define PT_ENTRY_NULL ((pt_entry_t *) 0) 57*45754Smckusick #define ST_ENTRY_NULL ((st_entry_t *) 0) 58*45754Smckusick 59*45754Smckusick #define SG_V 0x00000002 /* segment is valid */ 60*45754Smckusick #define SG_NV 0x00000000 61*45754Smckusick #define SG_PROT 0x00000004 /* access protection mask */ 62*45754Smckusick #define SG_RO 0x00000004 63*45754Smckusick #define SG_RW 0x00000000 64*45754Smckusick #define SG_FRAME 0xfffff000 65*45754Smckusick #define SG_IMASK 0xffc00000 66*45754Smckusick #define SG_PMASK 0x003ff000 67*45754Smckusick #define SG_ISHIFT 22 68*45754Smckusick #define SG_PSHIFT 12 69*45754Smckusick 70*45754Smckusick #define PG_V 0x00000001 71*45754Smckusick #define PG_NV 0x00000000 72*45754Smckusick #define PG_PROT 0x00000004 73*45754Smckusick #define PG_U 0x00000008 74*45754Smckusick #define PG_M 0x00000010 75*45754Smckusick #define PG_W 0x00000100 76*45754Smckusick #define PG_RO 0x00000004 77*45754Smckusick #define PG_RW 0x00000000 78*45754Smckusick #define PG_FRAME 0xfffff000 79*45754Smckusick #define PG_CI 0x00000040 80*45754Smckusick #define PG_SHIFT 12 81*45754Smckusick #define PG_PFNUM(x) (((x) & PG_FRAME) >> PG_SHIFT) 82*45754Smckusick 83*45754Smckusick #define HP_PAGE_SIZE NBPG 84*45754Smckusick #define HP_SEG_SIZE NBSEG 85*45754Smckusick 86*45754Smckusick #define HP_STSIZE HP_PAGE_SIZE /* segment table size */ 87*45754Smckusick #define HP_MAX_PTSIZE HP_SEG_SIZE /* max size of UPT */ 88*45754Smckusick #define HP_MAX_KPTSIZE 0x100000 /* max memory to allocate to KPT */ 89*45754Smckusick #define HP_PTBASE 0x10000000 /* UPT map base address */ 90*45754Smckusick #define HP_PTMAXSIZE 0x70000000 /* UPT map maximum size */ 91*45754Smckusick 92*45754Smckusick /* 93*45754Smckusick * Kernel virtual address to page table entry and to physical address. 94*45754Smckusick */ 95*45754Smckusick #define kvtopte(va) \ 96*45754Smckusick (&Sysmap[((unsigned)(va) - VM_MIN_KERNEL_ADDRESS) >> PGSHIFT]) 97*45754Smckusick #define ptetokv(pt) \ 98*45754Smckusick ((((pt_entry_t *)(pt) - Sysmap) << PGSHIFT) + VM_MIN_KERNEL_ADDRESS) 99*45754Smckusick #define kvtophys(va) \ 100*45754Smckusick ((kvtopte(va)->pg_pfnum << PGSHIFT) | ((int)(va) & PGOFSET)) 101*45754Smckusick 102*45754Smckusick /* 103*45754Smckusick * Pmap stuff 104*45754Smckusick */ 105*45754Smckusick #define PMAP_NULL ((pmap_t) 0) 106*45754Smckusick 107*45754Smckusick struct pmap { 108*45754Smckusick pt_entry_t *pm_ptab; /* KVA of page table */ 109*45754Smckusick st_entry_t *pm_stab; /* KVA of segment table */ 110*45754Smckusick boolean_t pm_stchanged; /* ST changed */ 111*45754Smckusick short pm_sref; /* segment table ref count */ 112*45754Smckusick short pm_count; /* pmap reference count */ 113*45754Smckusick simple_lock_data_t pm_lock; /* lock on pmap */ 114*45754Smckusick struct pmap_statistics pm_stats; /* pmap statistics */ 115*45754Smckusick long pm_ptpages; /* more stats: PT pages */ 116*45754Smckusick }; 117*45754Smckusick 118*45754Smckusick typedef struct pmap *pmap_t; 119*45754Smckusick 120*45754Smckusick extern pmap_t kernel_pmap; 121*45754Smckusick 122*45754Smckusick /* 123*45754Smckusick * Macros for speed 124*45754Smckusick */ 125*45754Smckusick #define PMAP_ACTIVATE(pmapp, pcbp) \ 126*45754Smckusick if ((pmapp) != PMAP_NULL && (pmapp)->pm_stchanged) { \ 127*45754Smckusick (pcbp)->pcb_ustp = \ 128*45754Smckusick hp300_btop(pmap_extract(kernel_pmap, (pmapp)->pm_stab)); \ 129*45754Smckusick if ((pmapp) == u.u_procp->p_map->pmap) \ 130*45754Smckusick loadustp((pcbp)->pcb_ustp); \ 131*45754Smckusick (pmapp)->pm_stchanged = FALSE; \ 132*45754Smckusick } 133*45754Smckusick #define PMAP_DEACTIVATE(pmapp, pcbp) 134*45754Smckusick 135*45754Smckusick /* 136*45754Smckusick * For each vm_page_t, there is a list of all currently valid virtual 137*45754Smckusick * mappings of that page. An entry is a pv_entry_t, the list is pv_table. 138*45754Smckusick */ 139*45754Smckusick typedef struct pv_entry { 140*45754Smckusick struct pv_entry *pv_next; /* next pv_entry */ 141*45754Smckusick pmap_t pv_pmap; /* pmap where mapping lies */ 142*45754Smckusick vm_offset_t pv_va; /* virtual address for mapping */ 143*45754Smckusick st_entry_t *pv_ptste; /* non-zero if VA maps a PT page */ 144*45754Smckusick pmap_t pv_ptpmap; /* if pv_ptste, pmap for PT page */ 145*45754Smckusick int pv_flags; /* flags */ 146*45754Smckusick } *pv_entry_t; 147*45754Smckusick 148*45754Smckusick #define PV_ENTRY_NULL ((pv_entry_t) 0) 149*45754Smckusick 150*45754Smckusick #define PV_CI 0x01 /* all entries must be cache inhibited */ 151*45754Smckusick #define PV_PTPAGE 0x02 /* entry maps a page table page */ 152*45754Smckusick 153*45754Smckusick #ifdef KERNEL 154*45754Smckusick 155*45754Smckusick pv_entry_t pv_table; /* array of entries, one per page */ 156*45754Smckusick 157*45754Smckusick #define pa_index(pa) atop(pa - vm_first_phys) 158*45754Smckusick #define pa_to_pvh(pa) (&pv_table[pa_index(pa)]) 159*45754Smckusick 160*45754Smckusick #define pmap_resident_count(pmap) ((pmap)->pm_stats.resident_count) 161*45754Smckusick 162*45754Smckusick extern pt_entry_t *Sysmap; 163*45754Smckusick #endif KERNEL 164*45754Smckusick 165*45754Smckusick #endif _PMAP_MACHINE_ 166