Home | History | Annotate | Line # | Download | only in sun3x
pmap_pvt.h revision 1.1.1.1
      1 /*	$NetBSD: pmap_pvt.h,v 1.1.1.1 1997/01/14 20:57:08 gwr Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1996 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Jeremy Cooper.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *        This product includes software developed by the NetBSD
     21  *        Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 #ifndef _SUN3X_PMAPPVT_H
     40 #define _SUN3X_PMAPPVT_H
     41 
     42 /*************************** TMGR STRUCTURES ***************************
     43  * The sun3x 'tmgr' structures contain MMU tables and additional       *
     44  * information about their current usage and availability.             *
     45  ***********************************************************************/
     46 typedef struct a_tmgr_struct a_tmgr_t;
     47 typedef struct b_tmgr_struct b_tmgr_t;
     48 typedef struct c_tmgr_struct c_tmgr_t;
     49 
     50 /* A level A table manager contains a pointer to an MMU table of long
     51  * format table descriptors (an 'A' table), a pointer to the pmap
     52  * currently using the table, and the number of wired and active entries
     53  * it contains.
     54  */
     55 struct a_tmgr_struct {
     56 	pmap_t		at_parent; /* pmap currently using this table    */
     57 	mmu_long_dte_t	*at_dtbl;  /* the MMU table being managed        */
     58 	u_char          at_wcnt;   /* no. of wired entries in this table */
     59 	u_char          at_ecnt;   /* no. of valid entries in this table */
     60     	TAILQ_ENTRY(a_tmgr_struct) at_link;  /* list linker              */
     61 };
     62 
     63 /* A level B table manager contains a pointer to an MMU table of
     64  * short format table descriptors (a 'B' table), a pointer to the level
     65  * A table manager currently using it, the index of this B table
     66  * within that parent A table, and the number of wired and active entries
     67  * it currently contains.
     68  */
     69 struct b_tmgr_struct {
     70 	a_tmgr_t	*bt_parent; /* Parent 'A' table manager         */
     71 	mmu_short_dte_t *bt_dtbl;   /* the MMU table being managed      */
     72 	u_char		bt_pidx;    /* this table's index in the parent */
     73 	u_char		bt_wcnt;    /* no. of wired entries in table    */
     74 	u_char		bt_ecnt;    /* no. of valid entries in table    */
     75     	TAILQ_ENTRY(b_tmgr_struct) bt_link; /* list linker              */
     76 };
     77 
     78 /* A level 'C' table manager consists of pointer to an MMU table of short
     79  * format page descriptors (a 'C' table), a pointer to the level B table
     80  * manager currently using it, and the number of wired and active pages
     81  * it currently contains.
     82  */
     83 struct c_tmgr_struct {
     84 	b_tmgr_t	*ct_parent; /* Parent 'B' table manager         */
     85 	mmu_short_pte_t	*ct_dtbl;   /* the MMU table being managed      */
     86 	u_char		ct_pidx;    /* this table's index in the parent */
     87 	u_char		ct_wcnt;    /* no. of wired entries in table    */
     88 	u_char		ct_ecnt;    /* no. of valid entries in table    */
     89 	TAILQ_ENTRY(c_tmgr_struct) ct_link; /* list linker              */
     90 #define	MMU_SHORT_PTE_WIRED	MMU_SHORT_PTE_UN1
     91 #define MMU_PTE_WIRED		((*pte)->attr.raw & MMU_SHORT_PTE_WIRED)
     92 };
     93 
     94 /* The Mach VM code requires that the pmap module be able to apply
     95  * several different operations on all page descriptors that map to a
     96  * given physical address.  A few of these are:
     97  *  + invalidate all mappings to a page.
     98  *  + change the type of protection on all mappings to a page.
     99  *  + determine if a physical page has been written to
    100  *  + determine if a physical page has been accessed (read from)
    101  *  + clear such information
    102  * The collection of structures and tables which we used to make this
    103  * possible is known as the 'Physical to Virtual' or 'PV' system.
    104  *
    105  * Every physical page of memory managed by the virtual memory system
    106  * will have a structure which describes whether or not it has been
    107  * modified or referenced, and contains a list of page descriptors that
    108  * are currently mapped to it (if any).  This array of structures is
    109  * known as the 'PV' list.
    110  *
    111  * To keep a list of page descriptors currently using the page, another
    112  * structure had to be invented.  Its sole purpose is to be a link in
    113  * a chain of such structures.  No other information is contained within
    114  * the structure however!  The other piece of information it holds is
    115  * hidden within its address.  By maintaining a one-to-one correspondence
    116  * of page descriptors in the system and such structures, this address can
    117  * readily be translated into its associated page descriptor by using a
    118  * simple macro.  This bizzare structure is simply known as a 'PV
    119  * Element', or 'pve' for short.
    120  */
    121 struct pv_struct {
    122     LIST_HEAD(pv_head_struct, pv_elem_struct) pv_head;
    123     int pv_flags; /* Physical page status flags */
    124 #define PV_FLAGS_USED	MMU_SHORT_PTE_USED
    125 #define PV_FLAGS_MDFY	MMU_SHORT_PTE_M
    126 };
    127 typedef struct pv_struct pv_t;
    128 
    129 struct pv_elem_struct {
    130     LIST_ENTRY(pv_elem_struct) pve_link;
    131 };
    132 typedef struct pv_elem_struct pv_elem_t;
    133 
    134 /* Physical memory on the 3/80 is not contiguous.  The ROM Monitor
    135  * provides us with a linked list of memory segments describing each
    136  * segment with its base address and its size.
    137  */
    138 struct pmap_physmem_struct {
    139 	vm_offset_t	pmem_start;  /* Starting physical address      */
    140 	vm_offset_t	pmem_end;    /* First byte outside of range    */
    141 	int             pmem_pvbase; /* Offset within the pv list      */
    142 	struct pmap_physmem_struct *pmem_next; /* Next block of memory */
    143 };
    144 
    145 /* XXX Temporary statement about the 3/80 */
    146 #define SUN3X_80_MEM_BANKS	4
    147 
    148 /* Internal function definitions. */
    149 a_tmgr_t *get_a_table __P((void));
    150 b_tmgr_t *get_b_table __P((void));
    151 c_tmgr_t *get_c_table __P((void));
    152 a_tmgr_t *pmap_find_a_tmgr __P((mmu_long_dte_t *));
    153 b_tmgr_t *pmap_find_b_tmgr __P((mmu_short_dte_t *));
    154 c_tmgr_t *pmap_find_c_tmgr __P((mmu_short_pte_t *));
    155 int    free_a_table __P((a_tmgr_t *));
    156 int    free_b_table __P((b_tmgr_t *));
    157 int    free_c_table __P((c_tmgr_t *));
    158 void   free_c_table_novalid __P((c_tmgr_t *));
    159 void   pmap_bootstrap_aalign __P((int));
    160 void   pmap_alloc_usermmu __P((void));
    161 void   pmap_alloc_usertmgr __P((void));
    162 void   pmap_alloc_pv __P((void));
    163 void   pmap_alloc_etc __P((void));
    164 void   pmap_init_a_tables __P((void));
    165 void   pmap_init_b_tables __P((void));
    166 void   pmap_init_c_tables __P((void));
    167 void   pmap_init_pv __P((void));
    168 void   pmap_clear_pv __P((vm_offset_t, int));
    169 void   pmap_remove_a __P((a_tmgr_t *, vm_offset_t, vm_offset_t));
    170 void   pmap_remove_b __P((b_tmgr_t *, vm_offset_t, vm_offset_t));
    171 void   pmap_remove_c __P((c_tmgr_t *, vm_offset_t, vm_offset_t));
    172 void   pmap_remove_pte __P((mmu_short_pte_t *));
    173 void   pmap_dereference_pte __P((mmu_short_pte_t *));
    174 void   pmap_enter_kernel __P((vm_offset_t, vm_offset_t, vm_prot_t));
    175 void   pmap_remove_kernel __P((vm_offset_t, vm_offset_t));
    176 void   pmap_protect_kernel __P((vm_offset_t, vm_offset_t, vm_prot_t));
    177 pmap_t pmap_who_owns_pte __P((mmu_short_pte_t *));
    178 vm_offset_t pmap_extract_kernel __P((vm_offset_t));
    179 vm_offset_t pmap_find_va __P((mmu_short_pte_t *));
    180 char   pmap_find_tia __P((mmu_long_dte_t *));
    181 char   pmap_find_tib __P((mmu_short_dte_t *));
    182 char   pmap_find_tic __P((mmu_short_pte_t *));
    183 void   pmap_pinit __P((pmap_t));
    184 int    pmap_dereference __P((pmap_t));
    185 void   flush_atc_crp __P((mmu_long_dte_t *));
    186 pv_t   *pa2pv __P((vm_offset_t));
    187 boolean_t is_managed __P((vm_offset_t));
    188 boolean_t pmap_stroll __P((pmap_t, vm_offset_t, a_tmgr_t **, b_tmgr_t **,\
    189 	c_tmgr_t **, mmu_short_pte_t **, int *, int *, int *));
    190 void  pmap_bootstrap_copyprom __P((void));
    191 void  pmap_takeover_mmu __P((void));
    192 
    193 /* These are defined in pmap.c */
    194 extern struct pmap_physmem_struct avail_mem[];
    195 
    196 #endif /* _SUN3X_MYPMAP_H */
    197 
    198