1*3e6e9bd4Stsutsui /* $NetBSD: pmap_pvt.h,v 1.16 2013/09/06 17:43:19 tsutsui Exp $ */ 2cd05f419Sgwr 3cd05f419Sgwr /*- 4cd05f419Sgwr * Copyright (c) 1996 The NetBSD Foundation, Inc. 5cd05f419Sgwr * All rights reserved. 6cd05f419Sgwr * 7cd05f419Sgwr * This code is derived from software contributed to The NetBSD Foundation 8cd05f419Sgwr * by Jeremy Cooper. 9cd05f419Sgwr * 10cd05f419Sgwr * Redistribution and use in source and binary forms, with or without 11cd05f419Sgwr * modification, are permitted provided that the following conditions 12cd05f419Sgwr * are met: 13cd05f419Sgwr * 1. Redistributions of source code must retain the above copyright 14cd05f419Sgwr * notice, this list of conditions and the following disclaimer. 15cd05f419Sgwr * 2. Redistributions in binary form must reproduce the above copyright 16cd05f419Sgwr * notice, this list of conditions and the following disclaimer in the 17cd05f419Sgwr * documentation and/or other materials provided with the distribution. 18cd05f419Sgwr * 19cd05f419Sgwr * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20cd05f419Sgwr * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21cd05f419Sgwr * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22cd05f419Sgwr * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23cd05f419Sgwr * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24cd05f419Sgwr * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25cd05f419Sgwr * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26cd05f419Sgwr * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27cd05f419Sgwr * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28cd05f419Sgwr * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29cd05f419Sgwr * POSSIBILITY OF SUCH DAMAGE. 30cd05f419Sgwr */ 31cd05f419Sgwr 32cd05f419Sgwr #ifndef _SUN3X_PMAPPVT_H 33cd05f419Sgwr #define _SUN3X_PMAPPVT_H 34cd05f419Sgwr 35d505b189Smartin #include "opt_pmap_debug.h" 36d505b189Smartin 37cd05f419Sgwr /*************************** TMGR STRUCTURES *************************** 38cd05f419Sgwr * The sun3x 'tmgr' structures contain MMU tables and additional * 39cd05f419Sgwr * information about their current usage and availability. * 40cd05f419Sgwr ***********************************************************************/ 41cd05f419Sgwr typedef struct a_tmgr_struct a_tmgr_t; 42cd05f419Sgwr typedef struct b_tmgr_struct b_tmgr_t; 43cd05f419Sgwr typedef struct c_tmgr_struct c_tmgr_t; 44cd05f419Sgwr 45cd05f419Sgwr /* A level A table manager contains a pointer to an MMU table of long 46cd05f419Sgwr * format table descriptors (an 'A' table), a pointer to the pmap 47cd05f419Sgwr * currently using the table, and the number of wired and active entries 48cd05f419Sgwr * it contains. 49cd05f419Sgwr */ 50cd05f419Sgwr struct a_tmgr_struct { 51cd05f419Sgwr pmap_t at_parent; /* pmap currently using this table */ 52cd05f419Sgwr mmu_long_dte_t *at_dtbl; /* the MMU table being managed */ 5310b1a7beSchs uint8_t at_wcnt; /* no. of wired entries in this table */ 5410b1a7beSchs uint8_t at_ecnt; /* no. of valid entries in this table */ 5510b1a7beSchs uint16_t at_dum1; /* structure padding */ 56cd05f419Sgwr TAILQ_ENTRY(a_tmgr_struct) at_link; /* list linker */ 57cd05f419Sgwr }; 58cd05f419Sgwr 59cd05f419Sgwr /* A level B table manager contains a pointer to an MMU table of 60cd05f419Sgwr * short format table descriptors (a 'B' table), a pointer to the level 61cd05f419Sgwr * A table manager currently using it, the index of this B table 62cd05f419Sgwr * within that parent A table, and the number of wired and active entries 63cd05f419Sgwr * it currently contains. 64cd05f419Sgwr */ 65cd05f419Sgwr struct b_tmgr_struct { 66cd05f419Sgwr a_tmgr_t *bt_parent; /* Parent 'A' table manager */ 67cd05f419Sgwr mmu_short_dte_t *bt_dtbl; /* the MMU table being managed */ 6810b1a7beSchs uint8_t bt_pidx; /* this table's index in the parent */ 6910b1a7beSchs uint8_t bt_wcnt; /* no. of wired entries in table */ 7010b1a7beSchs uint8_t bt_ecnt; /* no. of valid entries in table */ 7110b1a7beSchs uint8_t bt_dum1; /* structure padding */ 72cd05f419Sgwr TAILQ_ENTRY(b_tmgr_struct) bt_link; /* list linker */ 73cd05f419Sgwr }; 74cd05f419Sgwr 75cd05f419Sgwr /* A level 'C' table manager consists of pointer to an MMU table of short 76cd05f419Sgwr * format page descriptors (a 'C' table), a pointer to the level B table 77cd05f419Sgwr * manager currently using it, and the number of wired and active pages 78cd05f419Sgwr * it currently contains. 79bbf76eb6Sjeremy * 80bbf76eb6Sjeremy * Additionally, the table manager contains a pointer to the pmap 81bbf76eb6Sjeremy * that is currently using it and the starting virtual address of the 82bbf76eb6Sjeremy * range that the MMU table manages. These two items can be obtained 83bbf76eb6Sjeremy * through the traversal of other table manager structures, but having 84bbf76eb6Sjeremy * them close at hand helps speed up operations in the PV system. 85cd05f419Sgwr */ 86cd05f419Sgwr struct c_tmgr_struct { 87cd05f419Sgwr b_tmgr_t *ct_parent; /* Parent 'B' table manager */ 88cd05f419Sgwr mmu_short_pte_t *ct_dtbl; /* the MMU table being managed */ 8910b1a7beSchs uint8_t ct_pidx; /* this table's index in the parent */ 9010b1a7beSchs uint8_t ct_wcnt; /* no. of wired entries in table */ 9110b1a7beSchs uint8_t ct_ecnt; /* no. of valid entries in table */ 9210b1a7beSchs uint8_t ct_dum1; /* structure padding */ 93cd05f419Sgwr TAILQ_ENTRY(c_tmgr_struct) ct_link; /* list linker */ 94cd05f419Sgwr #define MMU_SHORT_PTE_WIRED MMU_SHORT_PTE_UN1 95cd05f419Sgwr #define MMU_PTE_WIRED ((*pte)->attr.raw & MMU_SHORT_PTE_WIRED) 96bbf76eb6Sjeremy pmap_t ct_pmap; /* pmap currently using this table */ 970637b20aStsutsui vaddr_t ct_va; /* starting va that this table maps */ 98cd05f419Sgwr }; 99cd05f419Sgwr 100cd05f419Sgwr /* The Mach VM code requires that the pmap module be able to apply 101cd05f419Sgwr * several different operations on all page descriptors that map to a 102cd05f419Sgwr * given physical address. A few of these are: 103cd05f419Sgwr * + invalidate all mappings to a page. 104cd05f419Sgwr * + change the type of protection on all mappings to a page. 105cd05f419Sgwr * + determine if a physical page has been written to 106cd05f419Sgwr * + determine if a physical page has been accessed (read from) 107cd05f419Sgwr * + clear such information 108cd05f419Sgwr * The collection of structures and tables which we used to make this 109cd05f419Sgwr * possible is known as the 'Physical to Virtual' or 'PV' system. 110cd05f419Sgwr * 111cd05f419Sgwr * Every physical page of memory managed by the virtual memory system 112cd05f419Sgwr * will have a structure which describes whether or not it has been 113cd05f419Sgwr * modified or referenced, and contains a list of page descriptors that 114cd05f419Sgwr * are currently mapped to it (if any). This array of structures is 115cd05f419Sgwr * known as the 'PV' list. 116cd05f419Sgwr * 11727b8c796Sgwr ** Old PV Element structure 118cd05f419Sgwr * To keep a list of page descriptors currently using the page, another 119cd05f419Sgwr * structure had to be invented. Its sole purpose is to be a link in 120cd05f419Sgwr * a chain of such structures. No other information is contained within 121cd05f419Sgwr * the structure however! The other piece of information it holds is 122cd05f419Sgwr * hidden within its address. By maintaining a one-to-one correspondence 123cd05f419Sgwr * of page descriptors in the system and such structures, this address can 124cd05f419Sgwr * readily be translated into its associated page descriptor by using a 125cd05f419Sgwr * simple macro. This bizzare structure is simply known as a 'PV 126cd05f419Sgwr * Element', or 'pve' for short. 12727b8c796Sgwr * 12827b8c796Sgwr ** New PV Element structure 12927b8c796Sgwr * To keep a list of page descriptors currently using the page, another 13027b8c796Sgwr * structure had to be invented. Its sole purpose is to indicate the index 13127b8c796Sgwr * of the next PTE currently referencing the page. By maintaining a one-to- 13227b8c796Sgwr * one correspondence of page descriptors in the system and such structures, 13327b8c796Sgwr * this same index is also the index of the next PV element, which describes 13427b8c796Sgwr * the index of yet another page mapped to the same address and so on. The 13527b8c796Sgwr * special index 'PVE_EOL' is used to represent the end of the list. 136cd05f419Sgwr */ 137cd05f419Sgwr struct pv_struct { 13827b8c796Sgwr u_short pv_idx; /* Index of PTE using this page */ 13927b8c796Sgwr u_short pv_flags; /* Physical page status flags */ 140cd05f419Sgwr #define PV_FLAGS_USED MMU_SHORT_PTE_USED 141cd05f419Sgwr #define PV_FLAGS_MDFY MMU_SHORT_PTE_M 142cd05f419Sgwr }; 143cd05f419Sgwr typedef struct pv_struct pv_t; 144cd05f419Sgwr 145cd05f419Sgwr struct pv_elem_struct { 14627b8c796Sgwr u_short pve_next; 14727b8c796Sgwr #define PVE_EOL 0xffff /* End-of-list marker */ 148cd05f419Sgwr }; 149cd05f419Sgwr typedef struct pv_elem_struct pv_elem_t; 150cd05f419Sgwr 151cd05f419Sgwr /* Physical memory on the 3/80 is not contiguous. The ROM Monitor 152cd05f419Sgwr * provides us with a linked list of memory segments describing each 153cd05f419Sgwr * segment with its base address and its size. 154cd05f419Sgwr */ 155cd05f419Sgwr struct pmap_physmem_struct { 1560637b20aStsutsui paddr_t pmem_start; /* Starting physical address */ 1570637b20aStsutsui paddr_t pmem_end; /* First byte outside of range */ 158cd05f419Sgwr int pmem_pvbase; /* Offset within the pv list */ 159cd05f419Sgwr struct pmap_physmem_struct *pmem_next; /* Next block of memory */ 160cd05f419Sgwr }; 161cd05f419Sgwr 162cd05f419Sgwr /* These are defined in pmap.c */ 163cd05f419Sgwr extern struct pmap_physmem_struct avail_mem[]; 164cd05f419Sgwr 165c44c5152Stsutsui #endif /* _SUN3X_PMAPPVT_H */ 166