145754Smckusick /* 245754Smckusick * Copyright (c) 1987 Carnegie-Mellon University 3*63160Sbostic * Copyright (c) 1991, 1993 4*63160Sbostic * The Regents of the University of California. All rights reserved. 545754Smckusick * 645754Smckusick * This code is derived from software contributed to Berkeley by 749622Smckusick * the Systems Programming Group of the University of Utah Computer 849622Smckusick * Science Department. 945754Smckusick * 1049631Sbostic * %sccs.include.redist.c% 1149631Sbostic * 12*63160Sbostic * @(#)pmap.h 8.1 (Berkeley) 06/10/93 1345754Smckusick */ 1445754Smckusick 1545754Smckusick #ifndef _PMAP_MACHINE_ 1648461Skarels #define _PMAP_MACHINE_ 1745754Smckusick 1845754Smckusick #define HP_PAGE_SIZE NBPG 1953928Shibler #if defined(HP380) 2053928Shibler #define HP_SEG_SIZE (mmutype == MMU_68040 ? 0x40000 : NBSEG) 2153928Shibler #else 2245754Smckusick #define HP_SEG_SIZE NBSEG 2353928Shibler #endif 2445754Smckusick 2553928Shibler #define hp300_trunc_seg(x) (((unsigned)(x)) & ~(HP_SEG_SIZE-1)) 2653928Shibler #define hp300_round_seg(x) hp300_trunc_seg((unsigned)(x) + HP_SEG_SIZE-1) 2753928Shibler 2845754Smckusick /* 2945754Smckusick * Pmap stuff 3045754Smckusick */ 3145754Smckusick struct pmap { 3248461Skarels struct pte *pm_ptab; /* KVA of page table */ 3348461Skarels struct ste *pm_stab; /* KVA of segment table */ 3448461Skarels int pm_stchanged; /* ST changed */ 3553928Shibler int pm_stfree; /* 040: free lev2 blocks */ 3653928Shibler struct ste *pm_stpa; /* 040: ST phys addr */ 3745754Smckusick short pm_sref; /* segment table ref count */ 3845754Smckusick short pm_count; /* pmap reference count */ 3945754Smckusick simple_lock_data_t pm_lock; /* lock on pmap */ 4045754Smckusick struct pmap_statistics pm_stats; /* pmap statistics */ 4145754Smckusick long pm_ptpages; /* more stats: PT pages */ 4245754Smckusick }; 4345754Smckusick 4445754Smckusick typedef struct pmap *pmap_t; 4545754Smckusick 4652604Smckusick extern struct pmap kernel_pmap_store; 4745754Smckusick 4857321Shibler #define kernel_pmap (&kernel_pmap_store) 4957321Shibler #define active_pmap(pm) \ 5057321Shibler ((pm) == kernel_pmap || (pm) == curproc->p_vmspace->vm_map.pmap) 5157321Shibler 5245754Smckusick /* 5353928Shibler * On the 040 we keep track of which level 2 blocks are already in use 5453928Shibler * with the pm_stfree mask. Bits are arranged from LSB (block 0) to MSB 5553928Shibler * (block 31). For convenience, the level 1 table is considered to be 5653928Shibler * block 0. 5753928Shibler * 5853928Shibler * MAX[KU]L2SIZE control how many pages of level 2 descriptors are allowed. 5953928Shibler * for the kernel and users. 8 implies only the initial "segment table" 6053928Shibler * page is used. WARNING: don't change MAXUL2SIZE unless you can allocate 6153928Shibler * physically contiguous pages for the ST in pmap.c! 6253928Shibler */ 6354205Smkm #define MAXKL2SIZE 32 6453928Shibler #define MAXUL2SIZE 8 6553928Shibler #define l2tobm(n) (1 << (n)) 6653928Shibler #define bmtol2(n) (ffs(n) - 1) 6753928Shibler 6853928Shibler /* 6945754Smckusick * Macros for speed 7045754Smckusick */ 7148461Skarels #define PMAP_ACTIVATE(pmapp, pcbp, iscurproc) \ 7248461Skarels if ((pmapp) != NULL && (pmapp)->pm_stchanged) { \ 7353928Shibler (pcbp)->pcb_ustp = hp300_btop((vm_offset_t)(pmapp)->pm_stpa); \ 7448461Skarels if (iscurproc) \ 7545754Smckusick loadustp((pcbp)->pcb_ustp); \ 7645754Smckusick (pmapp)->pm_stchanged = FALSE; \ 7745754Smckusick } 7845754Smckusick #define PMAP_DEACTIVATE(pmapp, pcbp) 7945754Smckusick 8045754Smckusick /* 8145754Smckusick * For each vm_page_t, there is a list of all currently valid virtual 8245754Smckusick * mappings of that page. An entry is a pv_entry_t, the list is pv_table. 8345754Smckusick */ 8445754Smckusick typedef struct pv_entry { 8545754Smckusick struct pv_entry *pv_next; /* next pv_entry */ 8648461Skarels struct pmap *pv_pmap; /* pmap where mapping lies */ 8745754Smckusick vm_offset_t pv_va; /* virtual address for mapping */ 8848461Skarels struct ste *pv_ptste; /* non-zero if VA maps a PT page */ 8948461Skarels struct pmap *pv_ptpmap; /* if pv_ptste, pmap for PT page */ 9045754Smckusick int pv_flags; /* flags */ 9145754Smckusick } *pv_entry_t; 9245754Smckusick 9357321Shibler #define PV_CI 0x01 /* header: all entries are cache inhibited */ 9457321Shibler #define PV_PTPAGE 0x02 /* header: entry maps a page table page */ 9545754Smckusick 9645754Smckusick #ifdef KERNEL 9757321Shibler #if defined(HP320) || defined(HP350) 9857321Shibler #define HAVEVAC /* include cheezy VAC support */ 9957321Shibler #endif 10057321Shibler 10145754Smckusick pv_entry_t pv_table; /* array of entries, one per page */ 10245754Smckusick 10345754Smckusick #define pa_index(pa) atop(pa - vm_first_phys) 10445754Smckusick #define pa_to_pvh(pa) (&pv_table[pa_index(pa)]) 10545754Smckusick 10645754Smckusick #define pmap_resident_count(pmap) ((pmap)->pm_stats.resident_count) 10760997Shibler #define pmap_wired_count(pmap) ((pmap)->pm_stats.wired_count) 10845754Smckusick 10948461Skarels extern struct pte *Sysmap; 11048461Skarels extern char *vmmap; /* map for mem, dumps, etc. */ 11160343Storek #endif /* KERNEL */ 11245754Smckusick 11360343Storek #endif /* _PMAP_MACHINE_ */ 114