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