Home | History | Annotate | Line # | Download | only in include
mmu_40.h revision 1.2
      1  1.2  thorpej /*	$NetBSD: mmu_40.h,v 1.2 2024/01/09 04:16:25 thorpej Exp $	*/
      2  1.1  thorpej 
      3  1.1  thorpej /*-
      4  1.1  thorpej  * Copyright (c) 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 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_40_H_
     33  1.1  thorpej #define	_M68K_MMU_40_H_
     34  1.1  thorpej 
     35  1.1  thorpej /*
     36  1.1  thorpej  * Translation table structures for the 68040 MMU.
     37  1.1  thorpej  *
     38  1.1  thorpej  * The 68040 MMU uses a 3-level tree structure.  The root (L1) and
     39  1.1  thorpej  * and pointer (L2) tables contain the base addresses of the tables
     40  1.1  thorpej  * at the lext level, and the page (L3) tables contain the addresses
     41  1.1  thorpej  * of the page descriptors, which may either contain the address of
     42  1.1  thorpej  * a physical page (4K or 8K) directly, or point to an indirect
     43  1.1  thorpej  * decriptor which points to the physical page.
     44  1.1  thorpej  *
     45  1.1  thorpej  * The L1 and L2 tables contain 128 4-byte descriptors, and are thus 512
     46  1.1  thorpej  * bytes in size.  Each of the 128 L1 descriptors corresponds to a 32MB
     47  1.1  thorpej  * region of address space.  Each of the 128 L2 descriptors corresponds
     48  1.1  thorpej  * to a 256KB region of address space.
     49  1.1  thorpej  *
     50  1.1  thorpej  * For 8K pages, the L3 tables contain 32 4-byte descriptors, and are
     51  1.1  thorpej  * thus 128 bytes in size.
     52  1.1  thorpej  *
     53  1.1  thorpej  *  31          25 24          18 17      13 12                       0
     54  1.1  thorpej  * |              |              |          |                          |
     55  1.1  thorpej  *  11111111111111 22222222222222 3333333333 ..........................
     56  1.1  thorpej  *       Root         Pointer        Page               Page
     57  1.1  thorpej  *       Index         Index         Index             Offset
     58  1.1  thorpej  *
     59  1.1  thorpej  * For 4K pages, the L3 tables contain 64 4-byte descriptors, and are
     60  1.1  thorpej  * thus 256 bytes in size.
     61  1.1  thorpej  *
     62  1.1  thorpej  *  31          25 24          18 17        12 11                     0
     63  1.1  thorpej  * |              |              |            |                        |
     64  1.1  thorpej  *  11111111111111 22222222222222 333333333333 ........................
     65  1.1  thorpej  *       Root         Pointer         Page              Page
     66  1.1  thorpej  *       Index         Index          Index            Offset
     67  1.1  thorpej  *
     68  1.1  thorpej  *                       Logical Address Format
     69  1.1  thorpej  */
     70  1.1  thorpej 
     71  1.1  thorpej #define	LA40_L1_NBITS	7U
     72  1.1  thorpej #define	LA40_L1_SHIFT	25
     73  1.1  thorpej #define	LA40_L2_NBITS	7U
     74  1.1  thorpej #define	LA40_L2_SHIFT	18
     75  1.1  thorpej #define	LA40_L3_NBITS	(32U - LA40_L1_NBITS - LA40_L2_NBITS - PGSHIFT)
     76  1.1  thorpej #define	LA40_L3_SHIFT	PGSHIFT
     77  1.1  thorpej 
     78  1.1  thorpej #define	LA40_L1_COUNT	__BIT(LA40_L1_NBITS)
     79  1.1  thorpej #define	LA40_L2_COUNT	__BIT(LA40_L2_NBITS)
     80  1.1  thorpej #define	LA40_L3_COUNT	__BIT(LA40_L3_NBITS)
     81  1.1  thorpej 
     82  1.1  thorpej #define	LA40_L1_MASK	(__BITS(0,(LA40_L1_NBITS - 1)) << LA40_L1_SHIFT)
     83  1.1  thorpej #define	LA40_L2_MASK	(__BITS(0,(LA40_L2_NBITS - 1)) << LA40_L2_SHIFT)
     84  1.1  thorpej #define	LA40_L3_MASK	(__BITS(0,(LA40_L3_NBITS - 1)) << LA40_L3_SHIFT)
     85  1.1  thorpej 
     86  1.1  thorpej /* N.B. all tables must be aligned to their size */
     87  1.1  thorpej #define	TBL40_L1_SIZE	(LA40_L1_COUNT * sizeof(uint32_t))
     88  1.1  thorpej #define	TBL40_L2_SIZE	(LA40_L2_COUNT * sizeof(uint32_t))
     89  1.1  thorpej #define	TBL40_L3_SIZE	(LA40_L3_COUNT * sizeof(uint32_t))
     90  1.1  thorpej 
     91  1.1  thorpej #define	LA40_RI(va)	__SHIFTOUT((va), LA40_L1_MASK)	/* root index */
     92  1.1  thorpej #define	LA40_PI(va)	__SHIFTOUT((va), LA40_L2_MASK)	/* pointer index */
     93  1.1  thorpej #define	LA40_PGI(va)	__SHIFTOUT((va), LA40_L3_MASK)	/* page index */
     94  1.1  thorpej 
     95  1.1  thorpej #define	LA40_TRUNC_L1(va) (((vaddr_t)(va)) & LA40_L1_MASK)
     96  1.1  thorpej #define	LA40_TRUNC_L2(va) (((vaddr_t)(va)) & (LA40_L1_MASK | LA40_L2_MASK))
     97  1.1  thorpej 
     98  1.1  thorpej /*
     99  1.1  thorpej  * The PTE format for L1 and L2 tables (Upper Tables).
    100  1.1  thorpej  */
    101  1.1  thorpej #define	UTE40_PTA	__BITS(9,31)	/* Pointer Table Address (L1 PTE) */
    102  1.1  thorpej 					/* Page Table Address (L2 PTE) */
    103  1.1  thorpej #define	UTE40_PGTA	__BITS(8 - (13 - PGSHIFT),31)
    104  1.1  thorpej #define	UTE40_U		__BIT(3)	/* Used (referenced) */
    105  1.1  thorpej #define	UTE40_W		__BIT(2)	/* Write Protected */
    106  1.1  thorpej #define	UTE40_UDT	__BITS(0,1)	/* Upper Descriptor Type */
    107  1.1  thorpej 					/* 00 or 01 -- Invalid */
    108  1.1  thorpej 					/* 10 or 11 -- Resident */
    109  1.1  thorpej 
    110  1.1  thorpej #define	UTE40_INVALID	__SHIFTIN(0, UTE_UDT)
    111  1.1  thorpej #define	UTE40_RESIDENT	__SHIFTIN(2, UTE_UDT)
    112  1.1  thorpej 
    113  1.1  thorpej /*
    114  1.1  thorpej  * The PTE format for L3 tables.
    115  1.1  thorpej  *
    116  1.1  thorpej  * Some notes:
    117  1.1  thorpej  *
    118  1.1  thorpej  * - PFLUSH variants that specify non-global entries do not invalidate
    119  1.1  thorpej  *   global entries.  If these PFLUSH variants are not used, then the G
    120  1.1  thorpej  *   bit can be used as a software-defined bit.
    121  1.1  thorpej  *
    122  1.1  thorpej  * - The UR bits are "reserved for use by the user", so can be
    123  1.1  thorpej  *   used as software-defined bits.
    124  1.1  thorpej  *
    125  1.1  thorpej  * - The U0 and U1 "User Page Attribute" bits should *not* be used
    126  1.1  thorpej  *   as software-defined bits; they are reflected on the UPA0 and UPA1
    127  1.1  thorpej  *   CPU signals if an external bus transfer results from the access,
    128  1.1  thorpej  *   meaning that they may have system-specific side-effects.
    129  1.1  thorpej  */
    130  1.1  thorpej #define	PTE40_PGA	__BITS(PGSHIFT,31) /* Page Physical Address */
    131  1.1  thorpej #define	PTE40_UR_x	__BIT(12)	/* User Reserved (extra avail if 8K) */
    132  1.1  thorpej #define	PTE40_UR	__BIT(11)	/* User Reserved */
    133  1.1  thorpej #define	PTE40_G		__BIT(10)	/* Global */
    134  1.1  thorpej #define	PTE40_U1	__BIT(9)	/* User Page Attribute 1 */
    135  1.1  thorpej #define	PTE40_U0	__BIT(8)	/* User Page Attribute 0 */
    136  1.1  thorpej #define	PTE40_S		__BIT(7)	/* Supervisor Protected */
    137  1.1  thorpej #define	PTE40_CM	__BITS(5,6)	/* Cache Mode */
    138  1.1  thorpej 					/* 00 -- write-through */
    139  1.1  thorpej 					/* 01 -- copy-back */
    140  1.1  thorpej 					/* 10 -- non-cacheable, serialized */
    141  1.1  thorpej 					/* 11 -- non-cacheable */
    142  1.1  thorpej #define	PTE40_M		__BIT(4)	/* Modified */
    143  1.1  thorpej #define	PTE40_U		__BIT(3)	/* Used (referenced) */
    144  1.1  thorpej #define	PTE40_W		__BIT(2)	/* Write Protected */
    145  1.1  thorpej #define	PTE40_PDT	__BITS(0,1)	/* Page Descriptor Type */
    146  1.1  thorpej 					/* 00       -- Invalid */
    147  1.1  thorpej 					/* 01 or 11 -- Resident */
    148  1.1  thorpej 					/* 10       -- Indirect */
    149  1.1  thorpej 
    150  1.1  thorpej #define	PTE40_CM_WT	__SHIFTIN(0, PTE40_CM)
    151  1.1  thorpej #define	PTE40_CM_CB	__SHIFTIN(1, PTE40_CM)
    152  1.1  thorpej #define	PTE40_CM_NC_SER	__SHIFTIN(2, PTE40_CM)
    153  1.1  thorpej #define	PTE40_CM_NC	__SHIFTIN(3, PTE40_CM)
    154  1.1  thorpej 
    155  1.1  thorpej #define	PTE40_INVALID	__SHIFTIN(0, PTE40_PDT)
    156  1.1  thorpej #define	PTE40_RESIDENT	__SHIFTIN(1, PTE40_PDT)
    157  1.1  thorpej #define	PTE40_INDIRECT	__SHIFTIN(2, PTE40_PDT)
    158  1.1  thorpej 
    159  1.1  thorpej /*
    160  1.1  thorpej  * MMU registers (and the sections in the 68040 manual that
    161  1.1  thorpej  * describe them).
    162  1.1  thorpej  */
    163  1.1  thorpej 
    164  1.1  thorpej /*
    165  1.1  thorpej  * 3.1.1 -- User and Supervisor Root Pointer Registers (32-bit)
    166  1.1  thorpej  *
    167  1.1  thorpej  * URP and SRP contain the physical address of the L1 table for
    168  1.1  thorpej  * user and supervisor space, respectively.  Bits 8-0 of the address
    169  1.1  thorpej  * must be 0.
    170  1.1  thorpej  */
    171  1.1  thorpej 
    172  1.1  thorpej /*
    173  1.1  thorpej  * 3.1.2 -- Translation Control Register (16-bit)
    174  1.1  thorpej  */
    175  1.1  thorpej #define	TCR40_E		__BIT(15)	/* enable translation */
    176  1.1  thorpej #define	TCR40_P		__BIT(14)	/* page size: 0=4K 1=8K */
    177  1.1  thorpej 
    178  1.1  thorpej /*
    179  1.1  thorpej  * 3.1.3 -- Transparent Translation Registers (32-bit)
    180  1.1  thorpej  *
    181  1.1  thorpej  * There are 2 data translation registers (DTTR0, DTTR1) and 2
    182  1.1  thorpej  * instruction translation registers (ITTR0, ITTR1).
    183  1.1  thorpej  */
    184  1.1  thorpej #define	TTR40_LAB	__BITS(24,31)	/* logical address base */
    185  1.1  thorpej #define	TTR40_LAM	__BITS(16,23)	/* logical address mask */
    186  1.1  thorpej #define	TTR40_E		__BIT(15)	/* enable TTR */
    187  1.1  thorpej #define	TTR40_SFIELD	__BITS(13,14)	/* Supervisor Mode field (see below) */
    188  1.1  thorpej #define	TTR40_U1	PTE40_U1
    189  1.1  thorpej #define	TTR40_U0	PTE40_U0
    190  1.1  thorpej #define	TTR40_CM	PTE40_CM
    191  1.1  thorpej #define	TTR40_W		PTE40_W
    192  1.1  thorpej 
    193  1.1  thorpej #define	TTR40_USER	__SHIFTIN(0, TTR40_SFIELD)
    194  1.1  thorpej #define	TTR40_SUPER	__SHIFTIN(1, TTR40_SFIELD)
    195  1.1  thorpej #define	TTR40_BOTH	__SHIFTIN(2, TTR40_SFIELD)
    196  1.1  thorpej 
    197  1.1  thorpej /*
    198  1.1  thorpej  * 3.1.4 -- MMU Status Register
    199  1.1  thorpej  *
    200  1.1  thorpej  * N.B. If 8K pages are in use, bit 12 of the PA field is **undefined**.
    201  1.1  thorpej  */
    202  1.1  thorpej #define	MMUSR40_PA	PTE40_PGA
    203  1.1  thorpej #define	MMUSR40_B	__BIT(11)	/* bus error */
    204  1.1  thorpej #define	MMUSR40_G	PTE40_G
    205  1.1  thorpej #define	MMUSR40_U1	PTE40_U1
    206  1.1  thorpej #define	MMUSR40_U0	PTE40_U0
    207  1.1  thorpej #define	MMUSR40_S	PTE40_S
    208  1.1  thorpej #define	MMUSR40_CM	PTE40_CM
    209  1.1  thorpej #define	MMUSR40_M	PTE40_M
    210  1.1  thorpej #define	MMUSR40_W	PTE40_W
    211  1.1  thorpej #define	MMUSR40_T	__BIT(1)	/* Transparent Translation hit */
    212  1.1  thorpej #define	MMUSR40_R	PTE40_RESIDENT
    213  1.1  thorpej 
    214  1.2  thorpej #ifdef _KERNEL
    215  1.2  thorpej void	mmu_load_urp40(paddr_t);
    216  1.2  thorpej void	mmu_load_urp60(paddr_t);
    217  1.2  thorpej #endif /* _KERNEL */
    218  1.2  thorpej 
    219  1.1  thorpej #endif /* _M68K_MMU_40_H_ */
    220