18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Definitions for Sun3 custom MMU.
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci#ifndef __SUN3_MMU_H__
68c2ecf20Sopenharmony_ci#define __SUN3_MMU_H__
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#include <linux/types.h>
98c2ecf20Sopenharmony_ci#include <asm/movs.h>
108c2ecf20Sopenharmony_ci#include <asm/sun3-head.h>
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci/* MMU characteristics. */
138c2ecf20Sopenharmony_ci#define SUN3_SEGMAPS_PER_CONTEXT	2048
148c2ecf20Sopenharmony_ci#define SUN3_PMEGS_NUM			256
158c2ecf20Sopenharmony_ci#define SUN3_CONTEXTS_NUM               8
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#define SUN3_PMEG_SIZE_BITS	 17
188c2ecf20Sopenharmony_ci#define SUN3_PMEG_SIZE		 (1 << SUN3_PMEG_SIZE_BITS)
198c2ecf20Sopenharmony_ci#define SUN3_PMEG_MASK		 (SUN3_PMEG_SIZE - 1)
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#define SUN3_PTE_SIZE_BITS       13
228c2ecf20Sopenharmony_ci#define SUN3_PTE_SIZE		 (1 << SUN3_PTE_SIZE_BITS)
238c2ecf20Sopenharmony_ci#define SUN3_PTE_MASK		 (SUN3_PTE_SIZE - 1)
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci#define SUN3_CONTROL_MASK       (0x0FFFFFFC)
268c2ecf20Sopenharmony_ci#define SUN3_INVALID_PMEG	255
278c2ecf20Sopenharmony_ci#define SUN3_INVALID_CONTEXT 255
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci#define AC_IDPROM     0x00000000    /* 34  ID PROM, R/O, byte, 32 bytes      */
308c2ecf20Sopenharmony_ci#define AC_PAGEMAP    0x10000000    /* 3   Pagemap R/W, long                 */
318c2ecf20Sopenharmony_ci#define AC_SEGMAP     0x20000000    /* 3   Segment map, byte                 */
328c2ecf20Sopenharmony_ci#define AC_CONTEXT    0x30000000    /* 34c current mmu-context               */
338c2ecf20Sopenharmony_ci#define AC_SENABLE    0x40000000    /* 34c system dvma/cache/reset enable reg*/
348c2ecf20Sopenharmony_ci#define AC_UDVMA_ENB  0x50000000    /* 34  Not used on Sun boards, byte      */
358c2ecf20Sopenharmony_ci#define AC_BUS_ERROR  0x60000000    /* 34  Cleared on read, byte.            */
368c2ecf20Sopenharmony_ci#define AC_SYNC_ERR   0x60000000    /*   c fault type                        */
378c2ecf20Sopenharmony_ci#define AC_SYNC_VA    0x60000004    /*   c fault virtual address             */
388c2ecf20Sopenharmony_ci#define AC_ASYNC_ERR  0x60000008    /*   c asynchronous fault type           */
398c2ecf20Sopenharmony_ci#define AC_ASYNC_VA   0x6000000c    /*   c async fault virtual address       */
408c2ecf20Sopenharmony_ci#define AC_LEDS       0x70000000    /* 34  Zero turns on LEDs, byte          */
418c2ecf20Sopenharmony_ci#define AC_CACHETAGS  0x80000000    /* 34c direct access to the VAC tags     */
428c2ecf20Sopenharmony_ci#define AC_CACHEDDATA 0x90000000    /* 3 c direct access to the VAC data     */
438c2ecf20Sopenharmony_ci#define AC_UDVMA_MAP  0xD0000000    /* 4   Not used on Sun boards, byte      */
448c2ecf20Sopenharmony_ci#define AC_VME_VECTOR 0xE0000000    /* 4   For non-Autovector VME, byte      */
458c2ecf20Sopenharmony_ci#define AC_BOOT_SCC   0xF0000000    /* 34  bypass to access Zilog 8530. byte.*/
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci#define SUN3_PAGE_CHG_MASK (SUN3_PAGE_PGNUM_MASK \
488c2ecf20Sopenharmony_ci			    | SUN3_PAGE_ACCESSED | SUN3_PAGE_MODIFIED)
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci/* Bus access type within PTE. */
518c2ecf20Sopenharmony_ci#define SUN3_PAGE_TYPE_MASK   (0x0c000000)
528c2ecf20Sopenharmony_ci#define SUN3_PAGE_TYPE_MEMORY (0x00000000)
538c2ecf20Sopenharmony_ci#define SUN3_PAGE_TYPE_IO     (0x04000000)
548c2ecf20Sopenharmony_ci#define SUN3_PAGE_TYPE_VME16  (0x08000000)
558c2ecf20Sopenharmony_ci#define SUN3_PAGE_TYPE_VME32  (0x0c000000)
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci/* Mask for page number within PTE. */
588c2ecf20Sopenharmony_ci#define SUN3_PAGE_PGNUM_MASK (0x0007FFFF)
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci/* Bits within bus-error register. */
618c2ecf20Sopenharmony_ci#define SUN3_BUSERR_WATCHDOG	(0x01)
628c2ecf20Sopenharmony_ci#define SUN3_BUSERR_unused	(0x02)
638c2ecf20Sopenharmony_ci#define SUN3_BUSERR_FPAENERR	(0x04)
648c2ecf20Sopenharmony_ci#define SUN3_BUSERR_FPABERR	(0x08)
658c2ecf20Sopenharmony_ci#define SUN3_BUSERR_VMEBERR	(0x10)
668c2ecf20Sopenharmony_ci#define SUN3_BUSERR_TIMEOUT	(0x20)
678c2ecf20Sopenharmony_ci#define SUN3_BUSERR_PROTERR	(0x40)
688c2ecf20Sopenharmony_ci#define SUN3_BUSERR_INVALID	(0x80)
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci/* Read bus error status register (implicitly clearing it). */
738c2ecf20Sopenharmony_cistatic inline unsigned char sun3_get_buserr(void)
748c2ecf20Sopenharmony_ci{
758c2ecf20Sopenharmony_ci	unsigned char sfc, c;
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci	GET_SFC (sfc);
788c2ecf20Sopenharmony_ci	SET_SFC (FC_CONTROL);
798c2ecf20Sopenharmony_ci	GET_CONTROL_BYTE (AC_BUS_ERROR, c);
808c2ecf20Sopenharmony_ci	SET_SFC (sfc);
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci	return c;
838c2ecf20Sopenharmony_ci}
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ci/* Read segmap from hardware MMU. */
868c2ecf20Sopenharmony_cistatic inline unsigned long sun3_get_segmap(unsigned long addr)
878c2ecf20Sopenharmony_ci{
888c2ecf20Sopenharmony_ci        register unsigned long entry;
898c2ecf20Sopenharmony_ci        unsigned char c, sfc;
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci        GET_SFC (sfc);
928c2ecf20Sopenharmony_ci        SET_SFC (FC_CONTROL);
938c2ecf20Sopenharmony_ci        GET_CONTROL_BYTE (AC_SEGMAP | (addr & SUN3_CONTROL_MASK), c);
948c2ecf20Sopenharmony_ci        SET_SFC (sfc);
958c2ecf20Sopenharmony_ci        entry = c;
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci        return entry;
988c2ecf20Sopenharmony_ci}
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci/* Write segmap to hardware MMU. */
1018c2ecf20Sopenharmony_cistatic inline void sun3_put_segmap(unsigned long addr, unsigned long entry)
1028c2ecf20Sopenharmony_ci{
1038c2ecf20Sopenharmony_ci        unsigned char sfc;
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci        GET_DFC (sfc);
1068c2ecf20Sopenharmony_ci        SET_DFC (FC_CONTROL);
1078c2ecf20Sopenharmony_ci        SET_CONTROL_BYTE (AC_SEGMAP | (addr & SUN3_CONTROL_MASK), entry);
1088c2ecf20Sopenharmony_ci	SET_DFC (sfc);
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci        return;
1118c2ecf20Sopenharmony_ci}
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ci/* Read PTE from hardware MMU. */
1148c2ecf20Sopenharmony_cistatic inline unsigned long sun3_get_pte(unsigned long addr)
1158c2ecf20Sopenharmony_ci{
1168c2ecf20Sopenharmony_ci        register unsigned long entry;
1178c2ecf20Sopenharmony_ci        unsigned char sfc;
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ci        GET_SFC (sfc);
1208c2ecf20Sopenharmony_ci        SET_SFC (FC_CONTROL);
1218c2ecf20Sopenharmony_ci        GET_CONTROL_WORD (AC_PAGEMAP | (addr & SUN3_CONTROL_MASK), entry);
1228c2ecf20Sopenharmony_ci        SET_SFC (sfc);
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ci        return entry;
1258c2ecf20Sopenharmony_ci}
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ci/* Write PTE to hardware MMU. */
1288c2ecf20Sopenharmony_cistatic inline void sun3_put_pte(unsigned long addr, unsigned long entry)
1298c2ecf20Sopenharmony_ci{
1308c2ecf20Sopenharmony_ci        unsigned char sfc;
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_ci        GET_DFC (sfc);
1338c2ecf20Sopenharmony_ci        SET_DFC (FC_CONTROL);
1348c2ecf20Sopenharmony_ci        SET_CONTROL_WORD (AC_PAGEMAP | (addr & SUN3_CONTROL_MASK), entry);
1358c2ecf20Sopenharmony_ci	SET_DFC (sfc);
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ci        return;
1388c2ecf20Sopenharmony_ci}
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_ci/* get current context */
1418c2ecf20Sopenharmony_cistatic inline unsigned char sun3_get_context(void)
1428c2ecf20Sopenharmony_ci{
1438c2ecf20Sopenharmony_ci	unsigned char sfc, c;
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_ci	GET_SFC(sfc);
1468c2ecf20Sopenharmony_ci	SET_SFC(FC_CONTROL);
1478c2ecf20Sopenharmony_ci	GET_CONTROL_BYTE(AC_CONTEXT, c);
1488c2ecf20Sopenharmony_ci	SET_SFC(sfc);
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ci	return c;
1518c2ecf20Sopenharmony_ci}
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_ci/* set alternate context */
1548c2ecf20Sopenharmony_cistatic inline void sun3_put_context(unsigned char c)
1558c2ecf20Sopenharmony_ci{
1568c2ecf20Sopenharmony_ci	unsigned char dfc;
1578c2ecf20Sopenharmony_ci	GET_DFC(dfc);
1588c2ecf20Sopenharmony_ci	SET_DFC(FC_CONTROL);
1598c2ecf20Sopenharmony_ci	SET_CONTROL_BYTE(AC_CONTEXT, c);
1608c2ecf20Sopenharmony_ci	SET_DFC(dfc);
1618c2ecf20Sopenharmony_ci
1628c2ecf20Sopenharmony_ci	return;
1638c2ecf20Sopenharmony_ci}
1648c2ecf20Sopenharmony_ci
1658c2ecf20Sopenharmony_ciextern void __iomem *sun3_ioremap(unsigned long phys, unsigned long size,
1668c2ecf20Sopenharmony_ci			  unsigned long type);
1678c2ecf20Sopenharmony_ci
1688c2ecf20Sopenharmony_ciextern int sun3_map_test(unsigned long addr, char *val);
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_ci#endif	/* !__ASSEMBLY__ */
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_ci#endif	/* !__SUN3_MMU_H__ */
173