xref: /openbsd/sys/arch/m88k/include/mmu.h (revision 2df76cc2)
1*2df76cc2Sguenther /*	$OpenBSD: mmu.h,v 1.16 2014/03/29 18:09:29 guenther Exp $ */
23180e169Smiod 
33180e169Smiod /*
43180e169Smiod  * This file bears almost no resemblance to the original m68k file,
53180e169Smiod  * so the following copyright notice is questionable, but we are
63180e169Smiod  * nice people.
73180e169Smiod  */
83180e169Smiod 
93180e169Smiod /*
103180e169Smiod  * Copyright (c) 1988 University of Utah.
113180e169Smiod  * Copyright (c) 1982, 1986, 1990, 1993
123180e169Smiod  *	The Regents of the University of California.  All rights reserved.
133180e169Smiod  *
143180e169Smiod  * This code is derived from software contributed to Berkeley by
153180e169Smiod  * the Systems Programming Group of the University of Utah Computer
163180e169Smiod  * Science Department.
173180e169Smiod  *
183180e169Smiod  * Redistribution and use in source and binary forms, with or without
193180e169Smiod  * modification, are permitted provided that the following conditions
203180e169Smiod  * are met:
213180e169Smiod  * 1. Redistributions of source code must retain the above copyright
223180e169Smiod  *    notice, this list of conditions and the following disclaimer.
233180e169Smiod  * 2. Redistributions in binary form must reproduce the above copyright
243180e169Smiod  *    notice, this list of conditions and the following disclaimer in the
253180e169Smiod  *    documentation and/or other materials provided with the distribution.
263180e169Smiod  * 3. Neither the name of the University nor the names of its contributors
273180e169Smiod  *    may be used to endorse or promote products derived from this software
283180e169Smiod  *    without specific prior written permission.
293180e169Smiod  *
303180e169Smiod  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
313180e169Smiod  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
323180e169Smiod  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
333180e169Smiod  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
343180e169Smiod  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
353180e169Smiod  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
363180e169Smiod  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
373180e169Smiod  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
383180e169Smiod  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
393180e169Smiod  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
403180e169Smiod  * SUCH DAMAGE.
413180e169Smiod  *
423180e169Smiod  * from: Utah $Hdr: pte.h 1.13 92/01/20$
433180e169Smiod  *
443180e169Smiod  *	@(#)pte.h	8.1 (Berkeley) 6/10/93
453180e169Smiod  */
463180e169Smiod 
472fa72412Spirofti #ifndef	_M88K_MMU_H_
482fa72412Spirofti #define	_M88K_MMU_H_
493180e169Smiod 
503180e169Smiod /*
513180e169Smiod  * Parameters which determine the 'geometry' of the m88K page tables in memory.
523180e169Smiod  */
533180e169Smiod 
543180e169Smiod #define SDT_BITS	10		/* M88K segment table size bits */
553180e169Smiod #define PDT_BITS	10		/* M88K page table size bits */
563180e169Smiod #define PG_BITS		PAGE_SHIFT	/* M88K hardware page size bits */
573180e169Smiod 
583180e169Smiod /*
593180e169Smiod  * Common fields for APR, SDT and PTE
603180e169Smiod  */
613180e169Smiod 
623180e169Smiod /* address frame */
633180e169Smiod #define	PG_FRAME	0xfffff000
643180e169Smiod #define	PG_SHIFT	PG_BITS
653180e169Smiod #define	PG_PFNUM(x)	(((x) & PG_FRAME) >> PG_SHIFT)
663180e169Smiod 
673180e169Smiod /* cache control bits */
683180e169Smiod #define	CACHE_DFL	0x00000000
693180e169Smiod #define	CACHE_INH	0x00000040	/* cache inhibit */
703180e169Smiod #define	CACHE_GLOBAL	0x00000080	/* global scope */
713180e169Smiod #define	CACHE_WT	0x00000200	/* write through */
723180e169Smiod 
733180e169Smiod #define	CACHE_MASK	(CACHE_INH | CACHE_GLOBAL | CACHE_WT)
743180e169Smiod 
753180e169Smiod /*
763180e169Smiod  * Area descriptors
773180e169Smiod  */
783180e169Smiod 
79c0c4242bSmiod typedef	uint32_t	apr_t;
80e35741c2Smiod 
813180e169Smiod #define	APR_V		0x00000001	/* valid bit */
823180e169Smiod 
833180e169Smiod /*
843180e169Smiod  * 88200 PATC (TLB)
853180e169Smiod  */
863180e169Smiod 
873180e169Smiod #define PATC_ENTRIES	56
883180e169Smiod 
893180e169Smiod /*
903180e169Smiod  * Segment table entries
913180e169Smiod  */
923180e169Smiod 
93c0c4242bSmiod typedef uint32_t	sdt_entry_t;
943180e169Smiod 
953180e169Smiod #define	SG_V		0x00000001
963180e169Smiod #define	SG_NV		0x00000000
973180e169Smiod #define	SG_PROT		0x00000004
983180e169Smiod #define	SG_RO		0x00000004
993180e169Smiod #define	SG_RW		0x00000000
1003180e169Smiod #define	SG_SO		0x00000100
1013180e169Smiod 
1023180e169Smiod #define	SDT_VALID(sdt)	(*(sdt) & SG_V)
1033180e169Smiod #define	SDT_SUP(sdt)	(*(sdt) & SG_SO)
1043180e169Smiod #define	SDT_WP(sdt)	(*(sdt) & SG_PROT)
1053180e169Smiod 
1063180e169Smiod /*
1073180e169Smiod  * Page table entries
1083180e169Smiod  */
1093180e169Smiod 
110c0c4242bSmiod typedef uint32_t	pt_entry_t;
1113180e169Smiod 
1123180e169Smiod #define	PG_V		0x00000001
1133180e169Smiod #define	PG_NV		0x00000000
1143180e169Smiod #define	PG_PROT		0x00000004
1153180e169Smiod #define	PG_U		0x00000008
1163180e169Smiod #define	PG_M		0x00000010
117b097573bSmiod #define	PG_M_U		0x00000018
1183180e169Smiod #define	PG_RO		0x00000004
1193180e169Smiod #define	PG_RW		0x00000000
1203180e169Smiod #define	PG_SO		0x00000100
1213180e169Smiod #define	PG_W		0x00000020	/* XXX unused but reserved field */
1223180e169Smiod #define	PG_U0		0x00000400	/* U0 bit for M88110 */
1233180e169Smiod #define	PG_U1		0x00000800	/* U1 bit for M88110 */
1243180e169Smiod 
1253180e169Smiod #define	PDT_VALID(pte)	(*(pte) & PG_V)
1263180e169Smiod #define	PDT_SUP(pte)	(*(pte) & PG_SO)
1273180e169Smiod #define	PDT_WP(pte)	(*(pte) & PG_PROT)
1283180e169Smiod 
1293180e169Smiod /*
1303180e169Smiod  * Number of entries in a page table.
1313180e169Smiod  */
1323180e169Smiod 
1333180e169Smiod #define	SDT_ENTRIES	(1<<(SDT_BITS))
1343180e169Smiod #define PDT_ENTRIES	(1<<(PDT_BITS))
1353180e169Smiod 
1363180e169Smiod /*
1373180e169Smiod  * Size in bytes of a single page table.
1383180e169Smiod  */
1393180e169Smiod 
1403180e169Smiod #define SDT_SIZE	(sizeof(sdt_entry_t) * SDT_ENTRIES)
1413180e169Smiod #define PDT_SIZE	(sizeof(pt_entry_t) * PDT_ENTRIES)
1423180e169Smiod 
1433180e169Smiod /*
1443180e169Smiod  * Shifts and masks
1453180e169Smiod  */
1463180e169Smiod 
1473180e169Smiod #define SDT_SHIFT	(PDT_BITS + PG_BITS)
1483180e169Smiod #define PDT_SHIFT	(PG_BITS)
1493180e169Smiod 
1503180e169Smiod #define SDT_MASK	(((1 << SDT_BITS) - 1) << SDT_SHIFT)
1513180e169Smiod #define PDT_MASK	(((1 << PDT_BITS) - 1) << PDT_SHIFT)
1523180e169Smiod 
1533180e169Smiod #define	SDTIDX(va)	(((va) & SDT_MASK) >> SDT_SHIFT)
1543180e169Smiod #define	PDTIDX(va)	(((va) & PDT_MASK) >> PDT_SHIFT)
1553180e169Smiod 
1563180e169Smiod /*
157c0c4242bSmiod  * BATC entries
1583180e169Smiod  */
1593180e169Smiod 
160c0c4242bSmiod #define	BATC_V		0x00000001
161c0c4242bSmiod #define	BATC_PROT	0x00000002
162c0c4242bSmiod #define	BATC_INH	0x00000004
163c0c4242bSmiod #define	BATC_GLOBAL	0x00000008
164c0c4242bSmiod #define	BATC_WT		0x00000010
165c0c4242bSmiod #define	BATC_SO		0x00000020
166c0c4242bSmiod 
167c0c4242bSmiod typedef uint32_t	batc_t;
168c0c4242bSmiod 
169b3edb888Smiod /* 8820x fixed size BATC */
1703180e169Smiod #define	BATC_BLKSHIFT	19
1713180e169Smiod #define	BATC_BLKBYTES	(1 << BATC_BLKSHIFT)
1723180e169Smiod #define	BATC_BLKMASK	(BATC_BLKBYTES-1)
173b3edb888Smiod /* number of programmable BATC entries */
1743180e169Smiod #define	BATC_MAX	8
1753180e169Smiod 
1763180e169Smiod /* physical and logical block address */
1773180e169Smiod #define	BATC_PSHIFT	6
178b3edb888Smiod #define	BATC_VSHIFT	19
1793180e169Smiod 
180b3edb888Smiod #define	trunc_batc(a)	((a) & ~BATC_BLKMASK)
181b3edb888Smiod #define	round_batc(a)	trunc_batc((a) + BATC_BLKBYTES - 1)
1823180e169Smiod 
1833180e169Smiod static pt_entry_t invalidate_pte(pt_entry_t *);
1843180e169Smiod static __inline__ pt_entry_t
invalidate_pte(pt_entry_t * pte)1853180e169Smiod invalidate_pte(pt_entry_t *pte)
1863180e169Smiod {
1873180e169Smiod 	pt_entry_t oldpte;
1883180e169Smiod 
1893180e169Smiod 	oldpte = PG_NV;
190*2df76cc2Sguenther 	__asm__ volatile
1910b514a07Smiod 	    ("xmem %0, %2, %%r0" : "+r"(oldpte), "+m"(*pte) : "r"(pte));
1923180e169Smiod 	return oldpte;
1933180e169Smiod }
1943180e169Smiod 
1952fa72412Spirofti #endif /* __M88K_MMU_H__ */
196