1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun /* iommu.h: Definitions for the sun4m IOMMU.
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
5*4882a593Smuzhiyun */
6*4882a593Smuzhiyun #ifndef _SPARC_IOMMU_H
7*4882a593Smuzhiyun #define _SPARC_IOMMU_H
8*4882a593Smuzhiyun
9*4882a593Smuzhiyun #include <asm/page.h>
10*4882a593Smuzhiyun #include <asm/bitext.h>
11*4882a593Smuzhiyun
12*4882a593Smuzhiyun /* The iommu handles all virtual to physical address translations
13*4882a593Smuzhiyun * that occur between the SBUS and physical memory. Access by
14*4882a593Smuzhiyun * the cpu to IO registers and similar go over the mbus so are
15*4882a593Smuzhiyun * translated by the on chip SRMMU. The iommu and the srmmu do
16*4882a593Smuzhiyun * not need to have the same translations at all, in fact most
17*4882a593Smuzhiyun * of the time the translations they handle are a disjunct set.
18*4882a593Smuzhiyun * Basically the iommu handles all dvma sbus activity.
19*4882a593Smuzhiyun */
20*4882a593Smuzhiyun
21*4882a593Smuzhiyun /* The IOMMU registers occupy three pages in IO space. */
22*4882a593Smuzhiyun struct iommu_regs {
23*4882a593Smuzhiyun /* First page */
24*4882a593Smuzhiyun volatile unsigned long control; /* IOMMU control */
25*4882a593Smuzhiyun volatile unsigned long base; /* Physical base of iopte page table */
26*4882a593Smuzhiyun volatile unsigned long _unused1[3];
27*4882a593Smuzhiyun volatile unsigned long tlbflush; /* write only */
28*4882a593Smuzhiyun volatile unsigned long pageflush; /* write only */
29*4882a593Smuzhiyun volatile unsigned long _unused2[1017];
30*4882a593Smuzhiyun /* Second page */
31*4882a593Smuzhiyun volatile unsigned long afsr; /* Async-fault status register */
32*4882a593Smuzhiyun volatile unsigned long afar; /* Async-fault physical address */
33*4882a593Smuzhiyun volatile unsigned long _unused3[2];
34*4882a593Smuzhiyun volatile unsigned long sbuscfg0; /* SBUS configuration registers, per-slot */
35*4882a593Smuzhiyun volatile unsigned long sbuscfg1;
36*4882a593Smuzhiyun volatile unsigned long sbuscfg2;
37*4882a593Smuzhiyun volatile unsigned long sbuscfg3;
38*4882a593Smuzhiyun volatile unsigned long mfsr; /* Memory-fault status register */
39*4882a593Smuzhiyun volatile unsigned long mfar; /* Memory-fault physical address */
40*4882a593Smuzhiyun volatile unsigned long _unused4[1014];
41*4882a593Smuzhiyun /* Third page */
42*4882a593Smuzhiyun volatile unsigned long mid; /* IOMMU module-id */
43*4882a593Smuzhiyun };
44*4882a593Smuzhiyun
45*4882a593Smuzhiyun #define IOMMU_CTRL_IMPL 0xf0000000 /* Implementation */
46*4882a593Smuzhiyun #define IOMMU_CTRL_VERS 0x0f000000 /* Version */
47*4882a593Smuzhiyun #define IOMMU_CTRL_RNGE 0x0000001c /* Mapping RANGE */
48*4882a593Smuzhiyun #define IOMMU_RNGE_16MB 0x00000000 /* 0xff000000 -> 0xffffffff */
49*4882a593Smuzhiyun #define IOMMU_RNGE_32MB 0x00000004 /* 0xfe000000 -> 0xffffffff */
50*4882a593Smuzhiyun #define IOMMU_RNGE_64MB 0x00000008 /* 0xfc000000 -> 0xffffffff */
51*4882a593Smuzhiyun #define IOMMU_RNGE_128MB 0x0000000c /* 0xf8000000 -> 0xffffffff */
52*4882a593Smuzhiyun #define IOMMU_RNGE_256MB 0x00000010 /* 0xf0000000 -> 0xffffffff */
53*4882a593Smuzhiyun #define IOMMU_RNGE_512MB 0x00000014 /* 0xe0000000 -> 0xffffffff */
54*4882a593Smuzhiyun #define IOMMU_RNGE_1GB 0x00000018 /* 0xc0000000 -> 0xffffffff */
55*4882a593Smuzhiyun #define IOMMU_RNGE_2GB 0x0000001c /* 0x80000000 -> 0xffffffff */
56*4882a593Smuzhiyun #define IOMMU_CTRL_ENAB 0x00000001 /* IOMMU Enable */
57*4882a593Smuzhiyun
58*4882a593Smuzhiyun #define IOMMU_AFSR_ERR 0x80000000 /* LE, TO, or BE asserted */
59*4882a593Smuzhiyun #define IOMMU_AFSR_LE 0x40000000 /* SBUS reports error after transaction */
60*4882a593Smuzhiyun #define IOMMU_AFSR_TO 0x20000000 /* Write access took more than 12.8 us. */
61*4882a593Smuzhiyun #define IOMMU_AFSR_BE 0x10000000 /* Write access received error acknowledge */
62*4882a593Smuzhiyun #define IOMMU_AFSR_SIZE 0x0e000000 /* Size of transaction causing error */
63*4882a593Smuzhiyun #define IOMMU_AFSR_S 0x01000000 /* Sparc was in supervisor mode */
64*4882a593Smuzhiyun #define IOMMU_AFSR_RESV 0x00f00000 /* Reserver, forced to 0x8 by hardware */
65*4882a593Smuzhiyun #define IOMMU_AFSR_ME 0x00080000 /* Multiple errors occurred */
66*4882a593Smuzhiyun #define IOMMU_AFSR_RD 0x00040000 /* A read operation was in progress */
67*4882a593Smuzhiyun #define IOMMU_AFSR_FAV 0x00020000 /* IOMMU afar has valid contents */
68*4882a593Smuzhiyun
69*4882a593Smuzhiyun #define IOMMU_SBCFG_SAB30 0x00010000 /* Phys-address bit 30 when bypass enabled */
70*4882a593Smuzhiyun #define IOMMU_SBCFG_BA16 0x00000004 /* Slave supports 16 byte bursts */
71*4882a593Smuzhiyun #define IOMMU_SBCFG_BA8 0x00000002 /* Slave supports 8 byte bursts */
72*4882a593Smuzhiyun #define IOMMU_SBCFG_BYPASS 0x00000001 /* Bypass IOMMU, treat all addresses
73*4882a593Smuzhiyun produced by this device as pure
74*4882a593Smuzhiyun physical. */
75*4882a593Smuzhiyun
76*4882a593Smuzhiyun #define IOMMU_MFSR_ERR 0x80000000 /* One or more of PERR1 or PERR0 */
77*4882a593Smuzhiyun #define IOMMU_MFSR_S 0x01000000 /* Sparc was in supervisor mode */
78*4882a593Smuzhiyun #define IOMMU_MFSR_CPU 0x00800000 /* CPU transaction caused parity error */
79*4882a593Smuzhiyun #define IOMMU_MFSR_ME 0x00080000 /* Multiple parity errors occurred */
80*4882a593Smuzhiyun #define IOMMU_MFSR_PERR 0x00006000 /* high bit indicates parity error occurred
81*4882a593Smuzhiyun on the even word of the access, low bit
82*4882a593Smuzhiyun indicated odd word caused the parity error */
83*4882a593Smuzhiyun #define IOMMU_MFSR_BM 0x00001000 /* Error occurred while in boot mode */
84*4882a593Smuzhiyun #define IOMMU_MFSR_C 0x00000800 /* Address causing error was marked cacheable */
85*4882a593Smuzhiyun #define IOMMU_MFSR_RTYP 0x000000f0 /* Memory request transaction type */
86*4882a593Smuzhiyun
87*4882a593Smuzhiyun #define IOMMU_MID_SBAE 0x001f0000 /* SBus arbitration enable */
88*4882a593Smuzhiyun #define IOMMU_MID_SE 0x00100000 /* Enables SCSI/ETHERNET arbitration */
89*4882a593Smuzhiyun #define IOMMU_MID_SB3 0x00080000 /* Enable SBUS device 3 arbitration */
90*4882a593Smuzhiyun #define IOMMU_MID_SB2 0x00040000 /* Enable SBUS device 2 arbitration */
91*4882a593Smuzhiyun #define IOMMU_MID_SB1 0x00020000 /* Enable SBUS device 1 arbitration */
92*4882a593Smuzhiyun #define IOMMU_MID_SB0 0x00010000 /* Enable SBUS device 0 arbitration */
93*4882a593Smuzhiyun #define IOMMU_MID_MID 0x0000000f /* Module-id, hardcoded to 0x8 */
94*4882a593Smuzhiyun
95*4882a593Smuzhiyun /* The format of an iopte in the page tables */
96*4882a593Smuzhiyun #define IOPTE_PAGE 0x07ffff00 /* Physical page number (PA[30:12]) */
97*4882a593Smuzhiyun #define IOPTE_CACHE 0x00000080 /* Cached (in vme IOCACHE or Viking/MXCC) */
98*4882a593Smuzhiyun #define IOPTE_WRITE 0x00000004 /* Writeable */
99*4882a593Smuzhiyun #define IOPTE_VALID 0x00000002 /* IOPTE is valid */
100*4882a593Smuzhiyun #define IOPTE_WAZ 0x00000001 /* Write as zeros */
101*4882a593Smuzhiyun
102*4882a593Smuzhiyun struct iommu_struct {
103*4882a593Smuzhiyun struct iommu_regs __iomem *regs;
104*4882a593Smuzhiyun iopte_t *page_table;
105*4882a593Smuzhiyun /* For convenience */
106*4882a593Smuzhiyun unsigned long start; /* First managed virtual address */
107*4882a593Smuzhiyun unsigned long end; /* Last managed virtual address */
108*4882a593Smuzhiyun
109*4882a593Smuzhiyun struct bit_map usemap;
110*4882a593Smuzhiyun };
111*4882a593Smuzhiyun
iommu_invalidate(struct iommu_regs __iomem * regs)112*4882a593Smuzhiyun static inline void iommu_invalidate(struct iommu_regs __iomem *regs)
113*4882a593Smuzhiyun {
114*4882a593Smuzhiyun sbus_writel(0, ®s->tlbflush);
115*4882a593Smuzhiyun }
116*4882a593Smuzhiyun
iommu_invalidate_page(struct iommu_regs __iomem * regs,unsigned long ba)117*4882a593Smuzhiyun static inline void iommu_invalidate_page(struct iommu_regs __iomem *regs, unsigned long ba)
118*4882a593Smuzhiyun {
119*4882a593Smuzhiyun sbus_writel(ba & PAGE_MASK, ®s->pageflush);
120*4882a593Smuzhiyun }
121*4882a593Smuzhiyun
122*4882a593Smuzhiyun #endif /* !(_SPARC_IOMMU_H) */
123