1 /* $OpenBSD: mmu.h,v 1.16 2014/03/29 18:09:29 guenther Exp $ */ 2 3 /* 4 * This file bears almost no resemblance to the original m68k file, 5 * so the following copyright notice is questionable, but we are 6 * nice people. 7 */ 8 9 /* 10 * Copyright (c) 1988 University of Utah. 11 * Copyright (c) 1982, 1986, 1990, 1993 12 * The Regents of the University of California. All rights reserved. 13 * 14 * This code is derived from software contributed to Berkeley by 15 * the Systems Programming Group of the University of Utah Computer 16 * Science Department. 17 * 18 * Redistribution and use in source and binary forms, with or without 19 * modification, are permitted provided that the following conditions 20 * are met: 21 * 1. Redistributions of source code must retain the above copyright 22 * notice, this list of conditions and the following disclaimer. 23 * 2. Redistributions in binary form must reproduce the above copyright 24 * notice, this list of conditions and the following disclaimer in the 25 * documentation and/or other materials provided with the distribution. 26 * 3. Neither the name of the University nor the names of its contributors 27 * may be used to endorse or promote products derived from this software 28 * without specific prior written permission. 29 * 30 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 31 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 32 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 33 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 34 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 35 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 36 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 37 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 38 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 39 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 40 * SUCH DAMAGE. 41 * 42 * from: Utah $Hdr: pte.h 1.13 92/01/20$ 43 * 44 * @(#)pte.h 8.1 (Berkeley) 6/10/93 45 */ 46 47 #ifndef _M88K_MMU_H_ 48 #define _M88K_MMU_H_ 49 50 /* 51 * Parameters which determine the 'geometry' of the m88K page tables in memory. 52 */ 53 54 #define SDT_BITS 10 /* M88K segment table size bits */ 55 #define PDT_BITS 10 /* M88K page table size bits */ 56 #define PG_BITS PAGE_SHIFT /* M88K hardware page size bits */ 57 58 /* 59 * Common fields for APR, SDT and PTE 60 */ 61 62 /* address frame */ 63 #define PG_FRAME 0xfffff000 64 #define PG_SHIFT PG_BITS 65 #define PG_PFNUM(x) (((x) & PG_FRAME) >> PG_SHIFT) 66 67 /* cache control bits */ 68 #define CACHE_DFL 0x00000000 69 #define CACHE_INH 0x00000040 /* cache inhibit */ 70 #define CACHE_GLOBAL 0x00000080 /* global scope */ 71 #define CACHE_WT 0x00000200 /* write through */ 72 73 #define CACHE_MASK (CACHE_INH | CACHE_GLOBAL | CACHE_WT) 74 75 /* 76 * Area descriptors 77 */ 78 79 typedef uint32_t apr_t; 80 81 #define APR_V 0x00000001 /* valid bit */ 82 83 /* 84 * 88200 PATC (TLB) 85 */ 86 87 #define PATC_ENTRIES 56 88 89 /* 90 * Segment table entries 91 */ 92 93 typedef uint32_t sdt_entry_t; 94 95 #define SG_V 0x00000001 96 #define SG_NV 0x00000000 97 #define SG_PROT 0x00000004 98 #define SG_RO 0x00000004 99 #define SG_RW 0x00000000 100 #define SG_SO 0x00000100 101 102 #define SDT_VALID(sdt) (*(sdt) & SG_V) 103 #define SDT_SUP(sdt) (*(sdt) & SG_SO) 104 #define SDT_WP(sdt) (*(sdt) & SG_PROT) 105 106 /* 107 * Page table entries 108 */ 109 110 typedef uint32_t pt_entry_t; 111 112 #define PG_V 0x00000001 113 #define PG_NV 0x00000000 114 #define PG_PROT 0x00000004 115 #define PG_U 0x00000008 116 #define PG_M 0x00000010 117 #define PG_M_U 0x00000018 118 #define PG_RO 0x00000004 119 #define PG_RW 0x00000000 120 #define PG_SO 0x00000100 121 #define PG_W 0x00000020 /* XXX unused but reserved field */ 122 #define PG_U0 0x00000400 /* U0 bit for M88110 */ 123 #define PG_U1 0x00000800 /* U1 bit for M88110 */ 124 125 #define PDT_VALID(pte) (*(pte) & PG_V) 126 #define PDT_SUP(pte) (*(pte) & PG_SO) 127 #define PDT_WP(pte) (*(pte) & PG_PROT) 128 129 /* 130 * Number of entries in a page table. 131 */ 132 133 #define SDT_ENTRIES (1<<(SDT_BITS)) 134 #define PDT_ENTRIES (1<<(PDT_BITS)) 135 136 /* 137 * Size in bytes of a single page table. 138 */ 139 140 #define SDT_SIZE (sizeof(sdt_entry_t) * SDT_ENTRIES) 141 #define PDT_SIZE (sizeof(pt_entry_t) * PDT_ENTRIES) 142 143 /* 144 * Shifts and masks 145 */ 146 147 #define SDT_SHIFT (PDT_BITS + PG_BITS) 148 #define PDT_SHIFT (PG_BITS) 149 150 #define SDT_MASK (((1 << SDT_BITS) - 1) << SDT_SHIFT) 151 #define PDT_MASK (((1 << PDT_BITS) - 1) << PDT_SHIFT) 152 153 #define SDTIDX(va) (((va) & SDT_MASK) >> SDT_SHIFT) 154 #define PDTIDX(va) (((va) & PDT_MASK) >> PDT_SHIFT) 155 156 /* 157 * BATC entries 158 */ 159 160 #define BATC_V 0x00000001 161 #define BATC_PROT 0x00000002 162 #define BATC_INH 0x00000004 163 #define BATC_GLOBAL 0x00000008 164 #define BATC_WT 0x00000010 165 #define BATC_SO 0x00000020 166 167 typedef uint32_t batc_t; 168 169 /* 8820x fixed size BATC */ 170 #define BATC_BLKSHIFT 19 171 #define BATC_BLKBYTES (1 << BATC_BLKSHIFT) 172 #define BATC_BLKMASK (BATC_BLKBYTES-1) 173 /* number of programmable BATC entries */ 174 #define BATC_MAX 8 175 176 /* physical and logical block address */ 177 #define BATC_PSHIFT 6 178 #define BATC_VSHIFT 19 179 180 #define trunc_batc(a) ((a) & ~BATC_BLKMASK) 181 #define round_batc(a) trunc_batc((a) + BATC_BLKBYTES - 1) 182 183 static pt_entry_t invalidate_pte(pt_entry_t *); 184 static __inline__ pt_entry_t 185 invalidate_pte(pt_entry_t *pte) 186 { 187 pt_entry_t oldpte; 188 189 oldpte = PG_NV; 190 __asm__ volatile 191 ("xmem %0, %2, %%r0" : "+r"(oldpte), "+m"(*pte) : "r"(pte)); 192 return oldpte; 193 } 194 195 #endif /* __M88K_MMU_H__ */ 196