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