1*b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
249148020SSam Ravnborg /*
349148020SSam Ravnborg * Definitions for Sun3 custom MMU.
449148020SSam Ravnborg */
549148020SSam Ravnborg #ifndef __SUN3_MMU_H__
649148020SSam Ravnborg #define __SUN3_MMU_H__
749148020SSam Ravnborg
849148020SSam Ravnborg #include <linux/types.h>
949148020SSam Ravnborg #include <asm/movs.h>
1049148020SSam Ravnborg #include <asm/sun3-head.h>
1149148020SSam Ravnborg
1249148020SSam Ravnborg /* MMU characteristics. */
1349148020SSam Ravnborg #define SUN3_SEGMAPS_PER_CONTEXT 2048
1449148020SSam Ravnborg #define SUN3_PMEGS_NUM 256
1549148020SSam Ravnborg #define SUN3_CONTEXTS_NUM 8
1649148020SSam Ravnborg
1749148020SSam Ravnborg #define SUN3_PMEG_SIZE_BITS 17
1849148020SSam Ravnborg #define SUN3_PMEG_SIZE (1 << SUN3_PMEG_SIZE_BITS)
1949148020SSam Ravnborg #define SUN3_PMEG_MASK (SUN3_PMEG_SIZE - 1)
2049148020SSam Ravnborg
2149148020SSam Ravnborg #define SUN3_PTE_SIZE_BITS 13
2249148020SSam Ravnborg #define SUN3_PTE_SIZE (1 << SUN3_PTE_SIZE_BITS)
2349148020SSam Ravnborg #define SUN3_PTE_MASK (SUN3_PTE_SIZE - 1)
2449148020SSam Ravnborg
2549148020SSam Ravnborg #define SUN3_CONTROL_MASK (0x0FFFFFFC)
2649148020SSam Ravnborg #define SUN3_INVALID_PMEG 255
2749148020SSam Ravnborg #define SUN3_INVALID_CONTEXT 255
2849148020SSam Ravnborg
2949148020SSam Ravnborg #define AC_IDPROM 0x00000000 /* 34 ID PROM, R/O, byte, 32 bytes */
3049148020SSam Ravnborg #define AC_PAGEMAP 0x10000000 /* 3 Pagemap R/W, long */
3149148020SSam Ravnborg #define AC_SEGMAP 0x20000000 /* 3 Segment map, byte */
3249148020SSam Ravnborg #define AC_CONTEXT 0x30000000 /* 34c current mmu-context */
3349148020SSam Ravnborg #define AC_SENABLE 0x40000000 /* 34c system dvma/cache/reset enable reg*/
3449148020SSam Ravnborg #define AC_UDVMA_ENB 0x50000000 /* 34 Not used on Sun boards, byte */
3549148020SSam Ravnborg #define AC_BUS_ERROR 0x60000000 /* 34 Cleared on read, byte. */
3649148020SSam Ravnborg #define AC_SYNC_ERR 0x60000000 /* c fault type */
3749148020SSam Ravnborg #define AC_SYNC_VA 0x60000004 /* c fault virtual address */
3849148020SSam Ravnborg #define AC_ASYNC_ERR 0x60000008 /* c asynchronous fault type */
3949148020SSam Ravnborg #define AC_ASYNC_VA 0x6000000c /* c async fault virtual address */
4049148020SSam Ravnborg #define AC_LEDS 0x70000000 /* 34 Zero turns on LEDs, byte */
4149148020SSam Ravnborg #define AC_CACHETAGS 0x80000000 /* 34c direct access to the VAC tags */
4249148020SSam Ravnborg #define AC_CACHEDDATA 0x90000000 /* 3 c direct access to the VAC data */
4349148020SSam Ravnborg #define AC_UDVMA_MAP 0xD0000000 /* 4 Not used on Sun boards, byte */
4449148020SSam Ravnborg #define AC_VME_VECTOR 0xE0000000 /* 4 For non-Autovector VME, byte */
4549148020SSam Ravnborg #define AC_BOOT_SCC 0xF0000000 /* 34 bypass to access Zilog 8530. byte.*/
4649148020SSam Ravnborg
4749148020SSam Ravnborg #define SUN3_PAGE_CHG_MASK (SUN3_PAGE_PGNUM_MASK \
4849148020SSam Ravnborg | SUN3_PAGE_ACCESSED | SUN3_PAGE_MODIFIED)
4949148020SSam Ravnborg
5049148020SSam Ravnborg /* Bus access type within PTE. */
5149148020SSam Ravnborg #define SUN3_PAGE_TYPE_MASK (0x0c000000)
5249148020SSam Ravnborg #define SUN3_PAGE_TYPE_MEMORY (0x00000000)
5349148020SSam Ravnborg #define SUN3_PAGE_TYPE_IO (0x04000000)
5449148020SSam Ravnborg #define SUN3_PAGE_TYPE_VME16 (0x08000000)
5549148020SSam Ravnborg #define SUN3_PAGE_TYPE_VME32 (0x0c000000)
5649148020SSam Ravnborg
5749148020SSam Ravnborg /* Mask for page number within PTE. */
5849148020SSam Ravnborg #define SUN3_PAGE_PGNUM_MASK (0x0007FFFF)
5949148020SSam Ravnborg
6049148020SSam Ravnborg /* Bits within bus-error register. */
6149148020SSam Ravnborg #define SUN3_BUSERR_WATCHDOG (0x01)
6249148020SSam Ravnborg #define SUN3_BUSERR_unused (0x02)
6349148020SSam Ravnborg #define SUN3_BUSERR_FPAENERR (0x04)
6449148020SSam Ravnborg #define SUN3_BUSERR_FPABERR (0x08)
6549148020SSam Ravnborg #define SUN3_BUSERR_VMEBERR (0x10)
6649148020SSam Ravnborg #define SUN3_BUSERR_TIMEOUT (0x20)
6749148020SSam Ravnborg #define SUN3_BUSERR_PROTERR (0x40)
6849148020SSam Ravnborg #define SUN3_BUSERR_INVALID (0x80)
6949148020SSam Ravnborg
7049148020SSam Ravnborg #ifndef __ASSEMBLY__
7149148020SSam Ravnborg
7249148020SSam Ravnborg /* Read bus error status register (implicitly clearing it). */
sun3_get_buserr(void)7349148020SSam Ravnborg static inline unsigned char sun3_get_buserr(void)
7449148020SSam Ravnborg {
7549148020SSam Ravnborg unsigned char sfc, c;
7649148020SSam Ravnborg
7749148020SSam Ravnborg GET_SFC (sfc);
7849148020SSam Ravnborg SET_SFC (FC_CONTROL);
7949148020SSam Ravnborg GET_CONTROL_BYTE (AC_BUS_ERROR, c);
8049148020SSam Ravnborg SET_SFC (sfc);
8149148020SSam Ravnborg
8249148020SSam Ravnborg return c;
8349148020SSam Ravnborg }
8449148020SSam Ravnborg
8549148020SSam Ravnborg /* Read segmap from hardware MMU. */
sun3_get_segmap(unsigned long addr)8649148020SSam Ravnborg static inline unsigned long sun3_get_segmap(unsigned long addr)
8749148020SSam Ravnborg {
8849148020SSam Ravnborg register unsigned long entry;
8949148020SSam Ravnborg unsigned char c, sfc;
9049148020SSam Ravnborg
9149148020SSam Ravnborg GET_SFC (sfc);
9249148020SSam Ravnborg SET_SFC (FC_CONTROL);
9349148020SSam Ravnborg GET_CONTROL_BYTE (AC_SEGMAP | (addr & SUN3_CONTROL_MASK), c);
9449148020SSam Ravnborg SET_SFC (sfc);
9549148020SSam Ravnborg entry = c;
9649148020SSam Ravnborg
9749148020SSam Ravnborg return entry;
9849148020SSam Ravnborg }
9949148020SSam Ravnborg
10049148020SSam Ravnborg /* Write segmap to hardware MMU. */
sun3_put_segmap(unsigned long addr,unsigned long entry)10149148020SSam Ravnborg static inline void sun3_put_segmap(unsigned long addr, unsigned long entry)
10249148020SSam Ravnborg {
10349148020SSam Ravnborg unsigned char sfc;
10449148020SSam Ravnborg
10549148020SSam Ravnborg GET_DFC (sfc);
10649148020SSam Ravnborg SET_DFC (FC_CONTROL);
10749148020SSam Ravnborg SET_CONTROL_BYTE (AC_SEGMAP | (addr & SUN3_CONTROL_MASK), entry);
10849148020SSam Ravnborg SET_DFC (sfc);
10949148020SSam Ravnborg
11049148020SSam Ravnborg return;
11149148020SSam Ravnborg }
11249148020SSam Ravnborg
11349148020SSam Ravnborg /* Read PTE from hardware MMU. */
sun3_get_pte(unsigned long addr)11449148020SSam Ravnborg static inline unsigned long sun3_get_pte(unsigned long addr)
11549148020SSam Ravnborg {
11649148020SSam Ravnborg register unsigned long entry;
11749148020SSam Ravnborg unsigned char sfc;
11849148020SSam Ravnborg
11949148020SSam Ravnborg GET_SFC (sfc);
12049148020SSam Ravnborg SET_SFC (FC_CONTROL);
12149148020SSam Ravnborg GET_CONTROL_WORD (AC_PAGEMAP | (addr & SUN3_CONTROL_MASK), entry);
12249148020SSam Ravnborg SET_SFC (sfc);
12349148020SSam Ravnborg
12449148020SSam Ravnborg return entry;
12549148020SSam Ravnborg }
12649148020SSam Ravnborg
12749148020SSam Ravnborg /* Write PTE to hardware MMU. */
sun3_put_pte(unsigned long addr,unsigned long entry)12849148020SSam Ravnborg static inline void sun3_put_pte(unsigned long addr, unsigned long entry)
12949148020SSam Ravnborg {
13049148020SSam Ravnborg unsigned char sfc;
13149148020SSam Ravnborg
13249148020SSam Ravnborg GET_DFC (sfc);
13349148020SSam Ravnborg SET_DFC (FC_CONTROL);
13449148020SSam Ravnborg SET_CONTROL_WORD (AC_PAGEMAP | (addr & SUN3_CONTROL_MASK), entry);
13549148020SSam Ravnborg SET_DFC (sfc);
13649148020SSam Ravnborg
13749148020SSam Ravnborg return;
13849148020SSam Ravnborg }
13949148020SSam Ravnborg
14049148020SSam Ravnborg /* get current context */
sun3_get_context(void)14149148020SSam Ravnborg static inline unsigned char sun3_get_context(void)
14249148020SSam Ravnborg {
14349148020SSam Ravnborg unsigned char sfc, c;
14449148020SSam Ravnborg
14549148020SSam Ravnborg GET_SFC(sfc);
14649148020SSam Ravnborg SET_SFC(FC_CONTROL);
14749148020SSam Ravnborg GET_CONTROL_BYTE(AC_CONTEXT, c);
14849148020SSam Ravnborg SET_SFC(sfc);
14949148020SSam Ravnborg
15049148020SSam Ravnborg return c;
15149148020SSam Ravnborg }
15249148020SSam Ravnborg
15349148020SSam Ravnborg /* set alternate context */
sun3_put_context(unsigned char c)15449148020SSam Ravnborg static inline void sun3_put_context(unsigned char c)
15549148020SSam Ravnborg {
15649148020SSam Ravnborg unsigned char dfc;
15749148020SSam Ravnborg GET_DFC(dfc);
15849148020SSam Ravnborg SET_DFC(FC_CONTROL);
15949148020SSam Ravnborg SET_CONTROL_BYTE(AC_CONTEXT, c);
16049148020SSam Ravnborg SET_DFC(dfc);
16149148020SSam Ravnborg
16249148020SSam Ravnborg return;
16349148020SSam Ravnborg }
16449148020SSam Ravnborg
16549148020SSam Ravnborg extern void __iomem *sun3_ioremap(unsigned long phys, unsigned long size,
16649148020SSam Ravnborg unsigned long type);
16749148020SSam Ravnborg
16849148020SSam Ravnborg extern int sun3_map_test(unsigned long addr, char *val);
16949148020SSam Ravnborg
17049148020SSam Ravnborg #endif /* !__ASSEMBLY__ */
17149148020SSam Ravnborg
17249148020SSam Ravnborg #endif /* !__SUN3_MMU_H__ */
173