Home | History | Annotate | Line # | Download | only in include
mc68851.h revision 1.5.152.1
      1  1.5.152.1     mjf /*	$NetBSD: mc68851.h,v 1.5.152.1 2008/06/02 13:22:46 mjf Exp $	*/
      2        1.1     gwr 
      3        1.1     gwr /*-
      4        1.1     gwr  * Copyright (c) 1997 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  *
     19        1.1     gwr  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20        1.1     gwr  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21        1.1     gwr  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22        1.1     gwr  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23        1.1     gwr  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24        1.1     gwr  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25        1.1     gwr  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26        1.1     gwr  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27        1.1     gwr  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28        1.1     gwr  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29        1.1     gwr  * POSSIBILITY OF SUCH DAMAGE.
     30        1.1     gwr  */
     31        1.1     gwr 
     32        1.2     gwr /*
     33        1.5  jeremy  * This file contains the machine-independent definitions
     34        1.5  jeremy  * related to the Motorola MC68851 Memory Management Unit (MMU).
     35        1.2     gwr  * Things that depend on the contents of the Translation Control
     36        1.5  jeremy  * (TC) register are in <machine/pte.h>.
     37        1.2     gwr  */
     38        1.2     gwr 
     39        1.1     gwr #ifndef _SUN3X_MC68851_H
     40        1.1     gwr #define _SUN3X_MC68851_H
     41        1.1     gwr 
     42        1.1     gwr /**************************** MMU STRUCTURES ****************************
     43        1.1     gwr  * MMU structures define the format of data used by the MC68851.        *
     44        1.1     gwr  ************************************************************************
     45        1.5  jeremy  ** MC68851 Root Pointer
     46        1.3     gwr  * All address translations begin with the examination of the value
     47        1.3     gwr  * in the MC68851 Root Pointer register.  It describes the base address
     48        1.3     gwr  * (in physical memory) of the root table to be used as well as any limits
     49        1.3     gwr  * to the address range it supports.  Its structure is identical to a Long
     50        1.3     gwr  * Format Table Descriptor (described below.)
     51        1.2     gwr  */
     52        1.2     gwr struct mmu_rootptr {
     53        1.3     gwr 	u_long	rp_attr;	/* Lower/Upper Limit and access flags */
     54        1.3     gwr 	u_long	rp_addr;	/* Physical Base Address */
     55        1.2     gwr };
     56        1.3     gwr typedef struct mmu_rootptr mmu_rootptr_t;
     57        1.2     gwr 
     58        1.1     gwr 
     59        1.1     gwr /** MC68851 Long Format Table Descriptor
     60        1.1     gwr  * The root table for a sun3x pmap is a 128 element array of 'long format
     61        1.1     gwr  * table descriptors'.  The structure of a long format table descriptor is:
     62        1.1     gwr  *
     63        1.1     gwr  *  63                                                             48
     64        1.1     gwr  *  +---+---.---.---.---.---.---.---.---.---.---.---.---.---.---.---+
     65        1.1     gwr  *  |L/U|                 LIMIT                                     |
     66        1.1     gwr  *  +---+---.---+---.---.---+---+---+---+---+---+---+---+---+---.---+
     67        1.1     gwr  *  |    RAL    |    WAL    |SG | S | 0 | 0 | 0 | 0 | U |WP |DT (10)|
     68        1.1     gwr  *  +---.---.---+---.---.---+---+---+---+---+---+---+---+---+---.---+
     69        1.1     gwr  *  |              TABLE PHYSICAL ADDRESS (BITS 31-16)              |
     70        1.1     gwr  *  +---.---.---.---.---.---.---.---.---.---.---.---+---.---.---.---+
     71        1.1     gwr  *  |       TABLE PHYSICAL ADDRESS (15-4)           |     UNUSED    |
     72        1.1     gwr  *  +---.---.---.---.---.---.---.---.---.---.---.---+---.---.---.---+
     73        1.1     gwr  *  15                                                              0
     74        1.1     gwr  *
     75        1.1     gwr  * Note: keep the unused bits set to zero so that no masking of the
     76        1.1     gwr  *       base address is needed.
     77        1.1     gwr  */
     78        1.1     gwr struct mmu_long_dte_struct { /* 'dte' stands for 'descriptor table entry' */
     79        1.1     gwr 	union {
     80        1.1     gwr 		struct {
     81        1.1     gwr 			char	lu_flag:1;	/* Lower/Upper Limit flag */
     82        1.1     gwr 			int	limit:15;	/* Table Size limit */
     83        1.1     gwr 			char	ral:3;		/* Read Access Level */
     84        1.1     gwr 			char	wal:3;		/* Write Access Level */
     85        1.1     gwr 			char	sg:1;		/* Shared Globally flag */
     86        1.1     gwr 			char	supv:1;		/* Supervisor Only flag */
     87        1.1     gwr 			char	rsvd:4;		/* Reserved (All zeros) */
     88        1.1     gwr 			char	u:1;		/* Used flag */
     89        1.1     gwr 			char	wp:1;		/* Write Protect flag */
     90        1.1     gwr 			char	dt:2;		/* Descriptor Type */
     91        1.1     gwr 			/* Bit masks for fields above */
     92        1.1     gwr #define			MMU_LONG_DTE_LU    0x80000000
     93        1.1     gwr #define			MMU_LONG_DTE_LIMIT 0x7fff0000
     94        1.1     gwr #define			MMU_LONG_DTE_RAL   0x0000e000
     95        1.1     gwr #define			MMU_LONG_DTE_WAL   0x00001c00
     96        1.1     gwr #define			MMU_LONG_DTE_SG    0x00000200
     97        1.1     gwr #define			MMU_LONG_DTE_SUPV  0x00000100
     98        1.1     gwr #define			MMU_LONG_DTE_USED  0x00000008
     99        1.1     gwr #define			MMU_LONG_DTE_WP    0x00000004
    100        1.1     gwr #define			MMU_LONG_DTE_DT    0x00000003
    101        1.1     gwr 		} attr_struct;
    102        1.1     gwr 		u_long raw; /* struct above, addressable as a long */
    103        1.1     gwr 	} attr;
    104        1.1     gwr 	union	{
    105        1.1     gwr 		struct {
    106        1.1     gwr 			int	base_addr:28;	/* Physical base address
    107        1.1     gwr 			char	unused:4;	 * of the table pointed to
    108        1.1     gwr 						 * by this entry.
    109        1.1     gwr 						 */
    110        1.1     gwr 			/* Bit masks for fields above */
    111        1.1     gwr #define			MMU_LONG_DTE_BASEADDR   0xfffffff0
    112        1.1     gwr 		} addr_struct;
    113        1.1     gwr 		u_long	raw; /* struct above, addressable as a long */
    114        1.1     gwr 	} addr;
    115        1.1     gwr };
    116        1.1     gwr typedef struct mmu_long_dte_struct mmu_long_dte_t;
    117        1.1     gwr typedef struct mmu_long_dte_struct *mmu_long_dtbl_t;
    118        1.1     gwr 
    119        1.1     gwr /** MC68851 Long Format Page Descriptor
    120        1.1     gwr  * Although not likely to be used in this implementation, a level
    121        1.1     gwr  * 'A' table may contain long format PAGE descriptors.  A long format
    122        1.1     gwr  * page descriptor is the same size as a long format table descriptor.
    123        1.1     gwr  * Its discriminating feature to the MMU is its descriptor field: 01.
    124        1.1     gwr  *  63                                                             48
    125        1.1     gwr  *  +---.---.---.---.---.---.---.---.---.---.---.---.---.---.---.---+
    126        1.1     gwr  *  |                          UNUSED                               |
    127        1.1     gwr  *  +---.---.---+---.---.---+---+---+---+---+---+---+---+---+---.---+
    128        1.1     gwr  *  |    RAL    |    WAL    |SG | S | G |CI | L | M | U |WP |DT (01)|
    129        1.1     gwr  *  +---.---.---+---.---.---+---+---+---+---+---+---+---+---+---.---+
    130        1.1     gwr  *  |              TABLE PHYSICAL ADDRESS (BITS 31-16)              |
    131        1.1     gwr  *  +---.---.---.---.---.---.---.---.---.---.---.---.---.---.---.---+
    132        1.1     gwr  *  |TABLE PHYS. ADDRESS (15-8)     |            UNUSED             |
    133        1.1     gwr  *  +---.---.---.---.---.---.---.---.---.---.---.---.---.---.---.---+
    134        1.1     gwr  *  15                                                              0
    135        1.1     gwr  */
    136        1.1     gwr struct mmu_long_pte_struct { /* 'pte' stands for 'page table entry' */
    137        1.1     gwr 	union {
    138        1.1     gwr 		struct {
    139        1.1     gwr 			int	unused:16;	/* Unused */
    140        1.1     gwr 			char	ral:3;		/* Read Access Level */
    141        1.1     gwr 			char	wal:3;		/* Write Access Level */
    142        1.1     gwr 			char	sg:1;		/* Shared Globally flag */
    143        1.1     gwr 			char	supv:1;		/* Supervisor Only flag */
    144        1.1     gwr 			char	g:1;		/* Gate allowed */
    145        1.1     gwr 			char	ci:1;		/* Cache inhibit */
    146        1.1     gwr 			char	l:1;		/* Lock entry */
    147        1.1     gwr 			char	m:1;		/* Modified flag */
    148        1.1     gwr 			char	u:1;		/* Used flag */
    149        1.1     gwr 			char	wp:1;		/* Write Protect flag */
    150        1.1     gwr 			char	dt:2;		/* Descriptor Type */
    151        1.1     gwr 			/* Bit masks for fields above */
    152        1.1     gwr #define			MMU_LONG_PTE_RAL   0x0000e000
    153        1.1     gwr #define			MMU_LONG_PTE_WAL   0x00001c00
    154        1.1     gwr #define			MMU_LONG_PTE_SG    0x00000200
    155        1.1     gwr #define			MMU_LONG_PTE_SUPV  0x00000100
    156        1.1     gwr #define			MMU_LONG_PTE_GATE  0x00000080
    157        1.1     gwr #define			MMU_LONG_PTE_CI    0x00000040
    158        1.1     gwr #define			MMU_LONG_PTE_LOCK  0x00000020
    159        1.1     gwr #define			MMU_LONG_PTE_M     0x00000010
    160        1.1     gwr #define			MMU_LONG_PTE_USED  0x00000008
    161        1.1     gwr #define			MMU_LONG_PTE_WP    0x00000004
    162        1.1     gwr #define			MMU_LONG_PTE_DT    0x00000003
    163        1.1     gwr 		} attr_struct;
    164        1.1     gwr 		u_long	raw; /* struct above, addressable as a long */
    165        1.1     gwr 	} attr;
    166        1.1     gwr 	union	{
    167        1.1     gwr 		struct {
    168        1.1     gwr 			long	base_addr:24;	/* Physical base address
    169        1.1     gwr 			char	unused:8;	 * of page this entry
    170        1.1     gwr 						 * points to.
    171        1.1     gwr 						 */
    172        1.1     gwr 			/* Bit masks for fields above */
    173        1.1     gwr #define			MMU_LONG_PTE_BASEADDR   0xffffff00
    174        1.1     gwr 		} addr_struct;
    175        1.1     gwr 		u_long	raw; /* struct above, addressable as a long */
    176        1.1     gwr 	} addr;
    177        1.1     gwr };
    178        1.1     gwr typedef struct mmu_long_pte_struct mmu_long_pte_t;
    179        1.1     gwr typedef struct mmu_long_pte_struct *mmu_long_ptbl_t;
    180        1.1     gwr 
    181        1.1     gwr /* Every entry in the level A table (except for the page entries
    182        1.1     gwr  * described above) points to a level B table.  Level B tables are
    183        1.1     gwr  * arrays of 'short format' table descriptors.  Their structure
    184        1.1     gwr  * is smaller than an A table descriptor and is as follows:
    185        1.1     gwr  *
    186        1.1     gwr  * 31                                                             16
    187        1.1     gwr  * +---.---.---.---.---.---.---.---.---.---.---.---.---.---.---.---+
    188        1.1     gwr  * |           TABLE PHYSICAL BASE ADDRESS (BITS 31-16)            |
    189        1.1     gwr  * +---.---.---.---.---.---.---.---.---.---.---.---+---+---+---.---+
    190        1.1     gwr  * | TABLE PHYSICAL BASE ADDRESS (15-4)            | U |WP |DT (10)|
    191        1.1     gwr  * +---.---.---.---.---.---.---.---.---.---.---.---+---+---+---.---+
    192        1.1     gwr  * 15                                                              0
    193        1.1     gwr  */
    194        1.1     gwr struct mmu_short_dte_struct { /* 'dte' stands for 'descriptor table entry' */
    195        1.1     gwr 	union {
    196        1.1     gwr 		struct {
    197        1.1     gwr 			long	base_addr:28;
    198        1.1     gwr 			char	u:1;
    199        1.1     gwr 			char	wp:1;
    200        1.1     gwr 			char	dt:2;
    201        1.1     gwr #define			MMU_SHORT_DTE_BASEADDR	0xfffffff0
    202        1.1     gwr #define			MMU_SHORT_DTE_USED	0x00000008
    203        1.1     gwr #define			MMU_SHORT_DTE_WP	0x00000004
    204        1.1     gwr #define			MMU_SHORT_DTE_DT	0x00000003
    205        1.1     gwr 		} attr_struct;
    206        1.1     gwr 		u_long	raw;
    207        1.1     gwr 	} attr;
    208        1.1     gwr };
    209        1.1     gwr typedef struct mmu_short_dte_struct mmu_short_dte_t;
    210        1.1     gwr typedef struct mmu_short_dte_struct *mmu_short_dtbl_t;
    211        1.1     gwr 
    212        1.1     gwr /* Every entry in a level B table points to a level C table.  Level C tables
    213        1.1     gwr  * contain arrays of short format page 'entry' descriptors.  A short format
    214        1.1     gwr  * page 'entry' is the same size as a short format page 'table'
    215        1.1     gwr  * descriptor (a B table entry).  Thus B and C tables can be allocated
    216        1.1     gwr  * interchangeably from the same pool.  However, we will keep them separate.
    217        1.1     gwr  *
    218        1.1     gwr  * The descriptor type (DT) field of a Page Table Entry (PTE) is '01'. This
    219        1.1     gwr  * indicates to the MMU that the address contained in the PTE's 'base
    220        1.1     gwr  * address' field is the base address for a physical page in memory to which
    221        1.1     gwr  * the VA should be mapped, and not a base address for a yet another
    222        1.1     gwr  * descriptor table, thus ending the table walk.
    223        1.1     gwr  *
    224        1.1     gwr  * 31                                                             16
    225        1.1     gwr  * +---.---.---.---.---.---.---.---.---.---.---.---.---.---.---.---+
    226        1.1     gwr  * |           TABLE PHYSICAL BASE ADDRESS (BITS 31-16)            |
    227        1.1     gwr  * +---.---.---.---.---.---.---.---+---+---+---+---+---+---+---.---+
    228        1.1     gwr  * |TABLE PHYS. BASE ADDRESS (15-8)| G |CI | L | M | U |WP |DT (10)|
    229        1.1     gwr  * +---.---.---.---.---.---.---.---+---+---+---+---+---+---+---.---+
    230        1.1     gwr  * 15                                                              0
    231        1.1     gwr  */
    232        1.1     gwr struct mmu_short_pte_struct { /* 'pte' stands for 'page table entry' */
    233        1.1     gwr 	union {
    234        1.1     gwr 		struct {
    235        1.1     gwr 			long	base_addr:24;
    236        1.1     gwr 			char	g:1;
    237        1.1     gwr 			char	ci:1;
    238        1.1     gwr 			char	l:1;
    239        1.1     gwr 			char	m:1;
    240        1.1     gwr 			char	u:1;
    241        1.1     gwr 			char	wp:1;
    242        1.1     gwr 			char	dt:2;
    243        1.1     gwr #define			MMU_SHORT_PTE_BASEADDR 0xffffff00
    244        1.1     gwr #define			MMU_SHORT_PTE_UN2      0x00000080
    245        1.1     gwr #define			MMU_SHORT_PTE_CI       0x00000040
    246        1.1     gwr #define			MMU_SHORT_PTE_UN1      0x00000020
    247        1.1     gwr #define			MMU_SHORT_PTE_M        0x00000010
    248        1.1     gwr #define			MMU_SHORT_PTE_USED     0x00000008
    249        1.1     gwr #define			MMU_SHORT_PTE_WP       0x00000004
    250        1.1     gwr #define			MMU_SHORT_PTE_DT       0x00000003
    251        1.1     gwr 		} attr_struct;
    252        1.1     gwr 		u_long raw;
    253        1.1     gwr 	} attr;
    254        1.1     gwr };
    255        1.1     gwr typedef struct mmu_short_pte_struct mmu_short_pte_t;
    256        1.1     gwr typedef struct mmu_short_pte_struct *mmu_short_ptbl_t;
    257        1.1     gwr 
    258        1.1     gwr /* These are bit masks and other values that are common to all types of
    259        1.1     gwr  * descriptors.
    260        1.1     gwr  */
    261        1.1     gwr /* Page table descriptors have a 'Descriptor Type' field describing the
    262        1.1     gwr  * format of the tables they point to.  It is two bits wide and is one of:
    263        1.1     gwr  */
    264        1.1     gwr #define MMU_DT_INVALID	0x0 /* Invalid descriptor entry            */
    265        1.1     gwr #define MMU_DT_PAGE	0x1 /* Descriptor describes a page entry   */
    266        1.1     gwr #define MMU_DT_SHORT	0x2 /*   describes a short format table    */
    267        1.1     gwr #define MMU_DT_LONG	0x3 /*   describes a long format table     */
    268        1.1     gwr #define MMU_DT_MASK	0x00000003 /* Bit location of the DT field */
    269        1.1     gwr 
    270        1.1     gwr /* Various macros for manipulating and setting MMU descriptor
    271        1.1     gwr  * characteristics.
    272        1.1     gwr  */
    273        1.1     gwr /* returns true if a descriptor is valid. */
    274        1.1     gwr #define MMU_VALID_DT(dte)	((dte).attr.raw & MMU_DT_MASK)
    275        1.1     gwr /* returns true if a descriptor is invalid */
    276        1.1     gwr #define	MMU_INVALID_DT(dte)	(!((dte).attr.raw & MMU_DT_MASK))
    277        1.1     gwr /* returns true if a descriptor has been referenced */
    278        1.1     gwr #define MMU_PTE_USED(pte)	((pte).attr.raw & MMU_SHORT_PTE_USED)
    279        1.1     gwr /* returns true if a descriptor has been modified */
    280        1.1     gwr #define MMU_PTE_MODIFIED(pte)	((pte).attr.raw & MMU_SHORT_PTE_M)
    281        1.1     gwr /* extracts the physical address from a pte */
    282        1.1     gwr #define MMU_PTE_PA(pte)		((pte).attr.raw & MMU_SHORT_PTE_BASEADDR)
    283        1.1     gwr /* extracts the physical address from a dte */
    284        1.1     gwr #define MMU_DTE_PA(dte)		((dte).attr.raw & MMU_SHORT_DTE_BASEADDR)
    285        1.1     gwr 
    286        1.1     gwr #endif /* _SUN3X_MC68851_H */
    287