Home | History | Annotate | Line # | Download | only in include
      1  1.4   andvar /*	$NetBSD: mmu_51.h,v 1.4 2024/02/08 20:11:56 andvar Exp $	*/
      2  1.1  thorpej 
      3  1.1  thorpej /*-
      4  1.1  thorpej  * Copyright (c) 1997, 2023 The NetBSD Foundation, Inc.
      5  1.1  thorpej  * All rights reserved.
      6  1.1  thorpej  *
      7  1.1  thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  thorpej  * by Jeremy Cooper and by Jason R. Thorpe.
      9  1.1  thorpej  *
     10  1.1  thorpej  * Redistribution and use in source and binary forms, with or without
     11  1.1  thorpej  * modification, are permitted provided that the following conditions
     12  1.1  thorpej  * are met:
     13  1.1  thorpej  * 1. Redistributions of source code must retain the above copyright
     14  1.1  thorpej  *    notice, this list of conditions and the following disclaimer.
     15  1.1  thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  thorpej  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  thorpej  *    documentation and/or other materials provided with the distribution.
     18  1.1  thorpej  *
     19  1.1  thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.1  thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.1  thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.1  thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.1  thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.1  thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.1  thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.1  thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.1  thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.1  thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.1  thorpej  * POSSIBILITY OF SUCH DAMAGE.
     30  1.1  thorpej  */
     31  1.1  thorpej 
     32  1.1  thorpej #ifndef _M68K_MMU_51_H_
     33  1.1  thorpej #define	_M68K_MMU_51_H_
     34  1.1  thorpej 
     35  1.1  thorpej /*
     36  1.1  thorpej  * Translation table structures for the 68851 MMU.
     37  1.1  thorpej  *
     38  1.1  thorpej  * The 68851 MMU (as well as the 68030's built-in MMU) are pretty flexible and
     39  1.1  thorpej  * can use a 1, 2, 3, or 4-level tree structure and a number of page sizes.
     40  1.1  thorpej  *
     41  1.1  thorpej  * The logical address format is defined as:
     42  1.1  thorpej  *
     43  1.1  thorpej  *  31                                                                0
     44  1.1  thorpej  * |        |          |          |          |          |              |
     45  1.1  thorpej  *  SSSSSSSS AAAAAAAAAA BBBBBBBBBB CCCCCCCCCC DDDDDDDDDD PPPPPPPPPPPPPP
     46  1.1  thorpej  *  Initial   A Index    B Index    C Index    D Index    Page Offset
     47  1.1  thorpej  *   Shift
     48  1.1  thorpej  *
     49  1.1  thorpej  * The Initial Shift, and number of A, B, C, and D index bits are defined
     50  1.1  thorpej  * in the Translation Control register.  Once the MMU encounters a tree
     51  1.1  thorpej  * level where the number of index bits is 0, tree traversal stops.  The
     52  1.1  thorpej  * values of IS + TIA + TIB + TIC + TID + page offset must equal 32.  For
     53  1.1  thorpej  * example, for a 2-level arrangment using 4KB pages where all 32-bits of
     54  1.1  thorpej  * the address are significant:
     55  1.1  thorpej  *
     56  1.1  thorpej  *     IS  TIA  TIB  TIC  TID  page
     57  1.1  thorpej  *	0 + 10 + 10 +  0 +  0 +  12 == 32
     58  1.1  thorpej  */
     59  1.1  thorpej 
     60  1.1  thorpej /*
     61  1.1  thorpej  * The 68851 has 3 descriptor formats:
     62  1.1  thorpej  *
     63  1.1  thorpej  *	Long Table Descriptors		(8 byte)
     64  1.1  thorpej  *	Short Table Descriptors		(4 byte)
     65  1.1  thorpej  *	Page Descriptors		(4 byte)
     66  1.1  thorpej  *
     67  1.1  thorpej  * These occupy the lower 2 bits of each descriptor and the root pointers.
     68  1.1  thorpej  */
     69  1.1  thorpej #define	DT51_INVALID	0
     70  1.1  thorpej #define	DT51_PAGE	1	/* points to a page */
     71  1.1  thorpej #define	DT51_SHORT	2	/* points to a short entry table */
     72  1.1  thorpej #define	DT51_LONG	3	/* points to a long entry table */
     73  1.1  thorpej 
     74  1.1  thorpej /*
     75  1.1  thorpej  * Long Format Table Descriptor
     76  1.1  thorpej  *
     77  1.1  thorpej  *  63                                                             48
     78  1.1  thorpej  *  +---+---.---.---.---.---.---.---.---.---.---.---.---.---.---.---+
     79  1.1  thorpej  *  |L/U|                 LIMIT                                     |
     80  1.1  thorpej  *  +---+---.---+---.---.---+---+---+---+---+---+---+---+---+---.---+
     81  1.1  thorpej  *  |    RAL    |    WAL    |SG | S | 0 | 0 | 0 | 0 | U |WP |  DT   |
     82  1.1  thorpej  *  +---.---.---+---.---.---+---+---+---+---+---+---+---+---+---.---+
     83  1.1  thorpej  *  |              TABLE PHYSICAL ADDRESS (BITS 31-16)              |
     84  1.1  thorpej  *  +---.---.---.---.---.---.---.---.---.---.---.---+---.---.---.---+
     85  1.1  thorpej  *  |       TABLE PHYSICAL ADDRESS (15-4)           |     UNUSED    |
     86  1.1  thorpej  *  +---.---.---.---.---.---.---.---.---.---.---.---+---.---.---.---+
     87  1.1  thorpej  *  15                                                              0
     88  1.1  thorpej  *
     89  1.1  thorpej  * DT is either 2 or 3, depending on what next table descriptor format is.
     90  1.1  thorpej  */
     91  1.1  thorpej struct mmu51_ldte {		/* 'dte' stands for 'descriptor table entry' */
     92  1.1  thorpej 	uint32_t	ldte_attr;
     93  1.1  thorpej 	uint32_t	ldte_addr;
     94  1.1  thorpej };
     95  1.1  thorpej #define	DTE51_ADDR	__BITS(4,31)	/* table address mask */
     96  1.1  thorpej #define	DTE51_LOWER	__BIT(31)	/* L: Index limit is lower limit */
     97  1.1  thorpej #define	DTE51_LIMIT	__BITS(16,30)	/* L: Index limit */
     98  1.1  thorpej #define	DTE51_RAL	__BITS(13,15)	/* L: Read Access Level */
     99  1.1  thorpej #define	DTE51_WAL	__BITS(10,12)	/* L: Write Access Level */
    100  1.1  thorpej #define	DTE51_SG	__BIT(9)	/* L: Shared Globally */
    101  1.1  thorpej #define	DTE51_S		__BIT(8)	/* L: Supervisor protected */
    102  1.1  thorpej #define	DTE51_U		__BIT(3)	/* Used */
    103  1.1  thorpej #define	DTE51_WP	__BIT(2)	/* Write Protected */
    104  1.1  thorpej 
    105  1.1  thorpej /*
    106  1.1  thorpej  * Short Format Table Descriptor
    107  1.1  thorpej  *
    108  1.1  thorpej  * 31                                                             16
    109  1.1  thorpej  * +---.---.---.---.---.---.---.---.---.---.---.---.---.---.---.---+
    110  1.1  thorpej  * |           TABLE PHYSICAL BASE ADDRESS (BITS 31-16)            |
    111  1.1  thorpej  * +---.---.---.---.---.---.---.---.---.---.---.---+---+---+---.---+
    112  1.1  thorpej  * | TABLE PHYSICAL BASE ADDRESS (15-4)            | U |WP |  DT   |
    113  1.1  thorpej  * +---.---.---.---.---.---.---.---.---.---.---.---+---+---+---.---+
    114  1.1  thorpej  * 15                                                              0
    115  1.1  thorpej  *
    116  1.1  thorpej  * DT is either 2 or 3, depending on what next table descriptor format is.
    117  1.1  thorpej  */
    118  1.1  thorpej 
    119  1.1  thorpej /*
    120  1.1  thorpej  * Long Format Page Descriptor (Level A table only)
    121  1.1  thorpej  *
    122  1.1  thorpej  *  63                                                             48
    123  1.1  thorpej  *  +---.---.---.---.---.---.---.---.---.---.---.---.---.---.---.---+
    124  1.1  thorpej  *  |                          UNUSED                               |
    125  1.1  thorpej  *  +---.---.---+---.---.---+---+---+---+---+---+---+---+---+---.---+
    126  1.1  thorpej  *  |    RAL    |    WAL    |SG | S | G |CI | L | M | U |WP |DT (01)|
    127  1.1  thorpej  *  +---.---.---+---.---.---+---+---+---+---+---+---+---+---+---.---+
    128  1.1  thorpej  *  |               PAGE PHYSICAL ADDRESS (BITS 31-16)              |
    129  1.1  thorpej  *  +---.---.---.---.---.---.---.---.---.---.---.---.---.---.---.---+
    130  1.1  thorpej  *  | PAGE PHYS. ADDRESS (15-8)     |            UNUSED             |
    131  1.1  thorpej  *  +---.---.---.---.---.---.---.---.---.---.---.---.---.---.---.---+
    132  1.1  thorpej  *  15                                                              0
    133  1.1  thorpej  *
    134  1.1  thorpej  * N.B. Unused bits of the page address (if the page size is larger
    135  1.1  thorpej  * than 256 bytes) can be used as software-defined PTE bits.
    136  1.1  thorpej  */
    137  1.1  thorpej struct mmu51_lpte {		/* 'pte' stands for 'page table entry' */
    138  1.1  thorpej 	uint32_t	lpte_attr;
    139  1.1  thorpej 	uint32_t	lpte_addr;
    140  1.1  thorpej };
    141  1.1  thorpej #define	PTE51_ADDR	__BITS(8,31)	/* page address mask */
    142  1.1  thorpej #define	PTE51_RAL	__BITS(13,15)	/* L: Read Access Level */
    143  1.1  thorpej #define	PTE51_WAL	__BITS(10,12)	/* L: Write Access Level */
    144  1.1  thorpej #define	PTE51_SG	__BIT(9)	/* L: Shared Globally */
    145  1.1  thorpej #define	PTE51_S		__BIT(8)	/* L: Supervisor protected */
    146  1.1  thorpej #define	PTE51_G		__BIT(7)	/* Gate allowed */
    147  1.1  thorpej #define	PTE51_CI	__BIT(6)	/* Cache inhibit */
    148  1.1  thorpej #define	PTE51_L		__BIT(5)	/* Lock entry */
    149  1.1  thorpej #define	PTE51_M		__BIT(4)	/* Modified */
    150  1.1  thorpej #define	PTE51_U		__BIT(3)	/* Used */
    151  1.1  thorpej #define	PTE51_WP	__BIT(2)	/* Write Protected */
    152  1.1  thorpej 
    153  1.1  thorpej /*
    154  1.1  thorpej  * Short Format Page Descriptor
    155  1.1  thorpej  *
    156  1.1  thorpej  * 31                                                             16
    157  1.1  thorpej  * +---.---.---.---.---.---.---.---.---.---.---.---.---.---.---.---+
    158  1.1  thorpej  * |            PAGE PHYSICAL BASE ADDRESS (BITS 31-16)            |
    159  1.1  thorpej  * +---.---.---.---.---.---.---.---+---+---+---+---+---+---+---.---+
    160  1.1  thorpej  * | PAGE PHYS. BASE ADDRESS (15-8)| G |CI | L | M | U |WP |DT (01)|
    161  1.1  thorpej  * +---.---.---.---.---.---.---.---+---+---+---+---+---+---+---.---+
    162  1.1  thorpej  * 15                                                              0
    163  1.1  thorpej  *
    164  1.1  thorpej  * N.B. Unused bits of the page address (if the page size is larger
    165  1.1  thorpej  * than 256 bytes) can be used as software-defined PTE bits.
    166  1.1  thorpej  */
    167  1.1  thorpej 
    168  1.1  thorpej /*
    169  1.1  thorpej  * MMU registers (and the sections in the 68851 manual that
    170  1.1  thorpej  * describe them).
    171  1.1  thorpej  */
    172  1.1  thorpej 
    173  1.1  thorpej /*
    174  1.1  thorpej  * 5.1.4 -- Root Pointer
    175  1.1  thorpej  * (and also 6.1.1)
    176  1.1  thorpej  *
    177  1.1  thorpej  * This is a 64-bit register.  The upper 32 bits contain configuration
    178  1.1  thorpej  * information, and the lower 32 bits contain the A table address.
    179  1.1  thorpej  * Bits 3-0 of the address must be 0.  The root pointer is essentially
    180  1.1  thorpej  * a long format table descriptor with only the U/L, limit, and SG bits.
    181  1.1  thorpej  *
    182  1.1  thorpej  * The 68851 has 3 root pointers:
    183  1.1  thorpej  *
    184  1.1  thorpej  * CRP		CPU root pointer, for user accesses
    185  1.1  thorpej  * SRP		Supervisor root pointer
    186  1.1  thorpej  * DRP		DMA root pointer, for IOMMU functionality (not on '030)
    187  1.1  thorpej  *
    188  1.1  thorpej  * Selection of root pointer is as follows:
    189  1.1  thorpej  *
    190  1.1  thorpej  *	FC3	FC2	SRE		Root pointer used
    191  1.1  thorpej  *	 0	 0	 0		      CRP
    192  1.1  thorpej  *	 0	 0	 1		      CRP
    193  1.1  thorpej  *	 0	 1	 0		      CRP
    194  1.1  thorpej  *	 0	 1	 1		      SRP
    195  1.1  thorpej  *	 1	 x	 x		      DRP
    196  1.1  thorpej  */
    197  1.1  thorpej struct mmu51_rootptr {
    198  1.1  thorpej 	unsigned long	rp_attr;	/* Lower/Upper Limit and access flags */
    199  1.1  thorpej 	unsigned long	rp_addr;	/* Physical Base Address */
    200  1.1  thorpej };
    201  1.1  thorpej 
    202  1.1  thorpej /*
    203  1.1  thorpej  * 6.1.2 -- PMMU Cache Status (PCSR) (16-bit)
    204  1.1  thorpej  */
    205  1.1  thorpej #define	PCSR51_F	__BIT(15)	/* Flush(ed) */
    206  1.1  thorpej #define	PCSR51_LW	__BIT(14)	/* Lock Warning */
    207  1.1  thorpej #define	PCSR51_TA	__BITS(0,2)	/* Task Alias (not '030) */
    208  1.1  thorpej 
    209  1.1  thorpej /*
    210  1.1  thorpej  * 6.1.3 -- Translation Control (TCR) (32-bit)
    211  1.1  thorpej  */
    212  1.1  thorpej #define	TCR51_E		__BIT(31)	/* Enable translation */
    213  1.1  thorpej #define	TCR51_SRE	__BIT(25)	/* Supervisor Root Enable */
    214  1.1  thorpej #define	TCR51_FCL	__BIT(24)	/* Function Code Lookup */
    215  1.1  thorpej #define	TCR51_PS	__BITS(20,23)	/* Page Size (see below) */
    216  1.1  thorpej #define	TCR51_IS	__BITS(16,19)	/* Initial Shift */
    217  1.1  thorpej #define	TCR51_TIA	__BITS(12,15)	/* Table A Index bits */
    218  1.1  thorpej #define	TCR51_TIB	__BITS(8,11)	/* Table B Index bits */
    219  1.1  thorpej #define	TCR51_TIC	__BITS(4,7)	/* Table C Index bits */
    220  1.1  thorpej #define	TCR51_TID	__BITS(0,3)	/* Table D Index bits */
    221  1.1  thorpej 
    222  1.1  thorpej /*
    223  1.1  thorpej  * Astute readers will note that the value in the PS field is
    224  1.1  thorpej  * log2(PAGE_SIZE).
    225  1.1  thorpej  */
    226  1.1  thorpej #define	TCR51_PS_256	__SHIFTIN(0x8, TCR51_PS)
    227  1.1  thorpej #define	TCR51_PS_512	__SHIFTIN(0x9, TCR51_PS)
    228  1.1  thorpej #define	TCR51_PS_1K	__SHIFTIN(0xa, TCR51_PS)
    229  1.1  thorpej #define	TCR51_PS_2K	__SHIFTIN(0xb, TCR51_PS)
    230  1.1  thorpej #define	TCR51_PS_4K	__SHIFTIN(0xc, TCR51_PS)
    231  1.1  thorpej #define	TCR51_PS_8K	__SHIFTIN(0xd, TCR51_PS)
    232  1.1  thorpej #define	TCR51_PS_16K	__SHIFTIN(0xe, TCR51_PS)
    233  1.1  thorpej #define	TCR51_PS_32K	__SHIFTIN(0xf, TCR51_PS)
    234  1.1  thorpej 
    235  1.1  thorpej /*
    236  1.1  thorpej  * 6.1.4 -- Current Access Level (8-bit)
    237  1.1  thorpej  * 6.1.5 -- Validate Access Level
    238  1.1  thorpej  */
    239  1.1  thorpej #define	CAL51_AL	__BITS(5,7)
    240  1.1  thorpej 
    241  1.1  thorpej /*
    242  1.1  thorpej  * 6.1.6 -- Stack Change Control (8-bit)
    243  1.1  thorpej  */
    244  1.1  thorpej 
    245  1.1  thorpej /*
    246  1.1  thorpej  * 6.1.7 -- Access Control (16-bit)
    247  1.1  thorpej  */
    248  1.1  thorpej #define	AC51_MC		__BIT(7)	/* Module Control */
    249  1.1  thorpej #define	AC51_ALC	__BITS(4,5)	/* Access Level Control */
    250  1.1  thorpej #define	AC51_MDS	__BITS(0,1)	/* Module Descriptor Size */
    251  1.1  thorpej 
    252  1.1  thorpej /*
    253  1.1  thorpej  * 6.1.8 -- PMMU Status Register (PSR) (16-bit)
    254  1.1  thorpej  */
    255  1.1  thorpej #define	PSR51_B		__BIT(15)	/* Bus Error */
    256  1.1  thorpej #define	PSR51_L		__BIT(14)	/* Limit Violation */
    257  1.1  thorpej #define	PSR51_S		__BIT(13)	/* Supervisor Violation */
    258  1.1  thorpej #define	PSR51_A		__BIT(12)	/* Access Level Violation */
    259  1.1  thorpej #define	PSR51_W		__BIT(11)	/* Write Protected */
    260  1.1  thorpej #define	PSR51_I		__BIT(10)	/* Invalid */
    261  1.1  thorpej #define	PSR51_M		__BIT(9)	/* Modified */
    262  1.1  thorpej #define	PSR51_G		__BIT(8)	/* Gate */
    263  1.4   andvar #define	PSR51_C		__BIT(7)	/* Globally Shareable */
    264  1.1  thorpej #define	PSR51_N		__BITS(0,2)	/* Number of levels */
    265  1.1  thorpej 
    266  1.2  thorpej #ifdef _KERNEL
    267  1.3  thorpej extern unsigned int protorp[2];
    268  1.3  thorpej 
    269  1.2  thorpej void	mmu_load_urp51(paddr_t);
    270  1.2  thorpej void	mmu_load_urp20hp(paddr_t);	/* for convenience */
    271  1.2  thorpej #endif /* _KERNEL */
    272  1.2  thorpej 
    273  1.1  thorpej #endif /* _M68K_MMU_51_H_ */
    274