iommureg.h revision 1.21 1 1.21 mrg /* $NetBSD: iommureg.h,v 1.21 2016/08/24 06:34:24 mrg Exp $ */
2 1.1 mrg
3 1.1 mrg /*
4 1.1 mrg * Copyright (c) 1992, 1993
5 1.1 mrg * The Regents of the University of California. All rights reserved.
6 1.1 mrg *
7 1.1 mrg * This software was developed by the Computer Systems Engineering group
8 1.1 mrg * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9 1.1 mrg * contributed to Berkeley.
10 1.1 mrg *
11 1.1 mrg * All advertising materials mentioning features or use of this software
12 1.1 mrg * must display the following acknowledgement:
13 1.1 mrg * This product includes software developed by the University of
14 1.1 mrg * California, Lawrence Berkeley Laboratory.
15 1.1 mrg *
16 1.1 mrg * Redistribution and use in source and binary forms, with or without
17 1.1 mrg * modification, are permitted provided that the following conditions
18 1.1 mrg * are met:
19 1.1 mrg * 1. Redistributions of source code must retain the above copyright
20 1.1 mrg * notice, this list of conditions and the following disclaimer.
21 1.1 mrg * 2. Redistributions in binary form must reproduce the above copyright
22 1.1 mrg * notice, this list of conditions and the following disclaimer in the
23 1.1 mrg * documentation and/or other materials provided with the distribution.
24 1.10 agc * 3. Neither the name of the University nor the names of its contributors
25 1.1 mrg * may be used to endorse or promote products derived from this software
26 1.1 mrg * without specific prior written permission.
27 1.1 mrg *
28 1.1 mrg * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 1.1 mrg * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 1.1 mrg * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 1.1 mrg * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 1.1 mrg * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 1.1 mrg * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 1.1 mrg * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 1.1 mrg * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 1.1 mrg * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 1.1 mrg * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 1.1 mrg * SUCH DAMAGE.
39 1.1 mrg *
40 1.1 mrg * @(#)sbusreg.h 8.1 (Berkeley) 6/11/93
41 1.1 mrg */
42 1.1 mrg
43 1.2 mrg #ifndef _SPARC64_DEV_IOMMUREG_H_
44 1.2 mrg #define _SPARC64_DEV_IOMMUREG_H_
45 1.2 mrg
46 1.1 mrg /*
47 1.1 mrg * UltraSPARC IOMMU registers, common to both the sbus and PCI
48 1.1 mrg * controllers.
49 1.1 mrg */
50 1.1 mrg
51 1.19 mrg /*
52 1.19 mrg * iommu registers - keep iommureg2 aligned with iommureg, so we can always
53 1.19 mrg * use offsetof on iommureg2, regardless of the controller.
54 1.19 mrg */
55 1.1 mrg struct iommureg {
56 1.19 mrg volatile uint64_t iommu_cr; /* IOMMU control register */
57 1.19 mrg volatile uint64_t iommu_tsb; /* IOMMU TSB base register */
58 1.19 mrg volatile uint64_t iommu_flush; /* IOMMU flush register */
59 1.19 mrg };
60 1.19 mrg
61 1.19 mrg /* iommu registers for schizo and newer controllers. */
62 1.19 mrg struct iommureg2 {
63 1.19 mrg volatile uint64_t iommu_cr; /* IOMMU control register */
64 1.19 mrg volatile uint64_t iommu_tsb; /* IOMMU TSB base register */
65 1.19 mrg volatile uint64_t iommu_flush; /* IOMMU flush register */
66 1.21 mrg volatile uint64_t iommu_ctxflush;
67 1.21 mrg volatile uint64_t iommu_reserved[28];
68 1.21 mrg volatile uint64_t iommu_cache_flush;
69 1.21 mrg volatile uint64_t iommu_cache_invalidate;
70 1.21 mrg volatile uint64_t iommu_reserved2[30];
71 1.1 mrg };
72 1.1 mrg
73 1.2 mrg /* streaming buffer registers */
74 1.2 mrg struct iommu_strbuf {
75 1.14 cdi uint64_t strbuf_ctl; /* streaming buffer control reg */
76 1.14 cdi uint64_t strbuf_pgflush; /* streaming buffer page flush */
77 1.14 cdi uint64_t strbuf_flushsync;/* streaming buffer flush sync */
78 1.2 mrg };
79 1.2 mrg
80 1.19 mrg #define IOMMUREG(x) (offsetof(struct iommureg2, x))
81 1.8 eeh #define STRBUFREG(x) (offsetof(struct iommu_strbuf, x))
82 1.19 mrg
83 1.19 mrg #define IOMMUREG_READ(is, reg) \
84 1.19 mrg bus_space_read_8((is)->is_bustag, \
85 1.19 mrg (is)->is_iommu, \
86 1.19 mrg IOMMUREG(reg))
87 1.19 mrg
88 1.19 mrg #define IOMMUREG_WRITE(is, reg, v) \
89 1.19 mrg bus_space_write_8((is)->is_bustag, \
90 1.19 mrg (is)->is_iommu, \
91 1.19 mrg IOMMUREG(reg), \
92 1.19 mrg (v))
93 1.19 mrg
94 1.2 mrg /* streaming buffer control register */
95 1.2 mrg #define STRBUF_EN 0x000000000000000001LL
96 1.2 mrg #define STRBUF_D 0x000000000000000002LL
97 1.2 mrg
98 1.1 mrg /* control register bits */
99 1.1 mrg #define IOMMUCR_TSB1K 0x000000000000000000LL /* Nummber of entries in IOTSB */
100 1.1 mrg #define IOMMUCR_TSB2K 0x000000000000010000LL
101 1.1 mrg #define IOMMUCR_TSB4K 0x000000000000020000LL
102 1.1 mrg #define IOMMUCR_TSB8K 0x000000000000030000LL
103 1.1 mrg #define IOMMUCR_TSB16K 0x000000000000040000LL
104 1.1 mrg #define IOMMUCR_TSB32K 0x000000000000050000LL
105 1.1 mrg #define IOMMUCR_TSB64K 0x000000000000060000LL
106 1.1 mrg #define IOMMUCR_TSB128K 0x000000000000070000LL
107 1.2 mrg #define IOMMUCR_TSBMASK 0xfffffffffffff8ffffLL /* Mask for above */
108 1.1 mrg #define IOMMUCR_8KPG 0x000000000000000000LL /* 8K iommu page size */
109 1.1 mrg #define IOMMUCR_64KPG 0x000000000000000004LL /* 64K iommu page size */
110 1.1 mrg #define IOMMUCR_DE 0x000000000000000002LL /* Diag enable */
111 1.1 mrg #define IOMMUCR_EN 0x000000000000000001LL /* Enable IOMMU */
112 1.1 mrg
113 1.20 palle #define IOMMUCR_FIRE_SE 0x000000000000000400LL /* Snoop enable */
114 1.20 palle #define IOMMUCR_FIRE_CM_EN 0x000000000000000300LL /* Cache mode enable */
115 1.20 palle #define IOMMUCR_FIRE_BE 0x000000000000000002LL /* Bypass enable */
116 1.20 palle #define IOMMUCR_FIRE_TE 0x000000000000000001LL /* Translation enabled */
117 1.20 palle
118 1.1 mrg /*
119 1.1 mrg * IOMMU stuff
120 1.1 mrg */
121 1.1 mrg #define IOTTE_V 0x8000000000000000LL /* Entry valid */
122 1.1 mrg #define IOTTE_64K 0x2000000000000000LL /* 8K or 64K page? */
123 1.1 mrg #define IOTTE_8K 0x0000000000000000LL
124 1.1 mrg #define IOTTE_STREAM 0x1000000000000000LL /* Is page streamable? */
125 1.1 mrg #define IOTTE_LOCAL 0x0800000000000000LL /* Accesses to same bus segment? */
126 1.1 mrg #define IOTTE_PAMASK 0x000001ffffffe000LL /* Let's assume this is correct */
127 1.1 mrg #define IOTTE_C 0x0000000000000010LL /* Accesses to cacheable space */
128 1.9 wiz #define IOTTE_W 0x0000000000000002LL /* Writable */
129 1.5 eeh
130 1.5 eeh /*
131 1.5 eeh * On sun4u each bus controller has a separate IOMMU. The IOMMU has
132 1.5 eeh * a TSB which must be page aligned and physically contiguous. Mappings
133 1.5 eeh * can be of 8K IOMMU pages or 64K IOMMU pages. We use 8K for compatibility
134 1.5 eeh * with the CPU's MMU.
135 1.5 eeh *
136 1.6 eeh * On sysio, psycho, and psycho+, IOMMU TSBs using 8K pages can map the
137 1.6 eeh * following size segments:
138 1.5 eeh *
139 1.5 eeh * VA size VA base TSB size tsbsize
140 1.5 eeh * -------- -------- --------- -------
141 1.5 eeh * 8MB ff800000 8K 0
142 1.5 eeh * 16MB ff000000 16K 1
143 1.5 eeh * 32MB fe000000 32K 2
144 1.5 eeh * 64MB fc000000 64K 3
145 1.5 eeh * 128MB f8000000 128K 4
146 1.5 eeh * 256MB f0000000 256K 5
147 1.5 eeh * 512MB e0000000 512K 6
148 1.5 eeh * 1GB c0000000 1MB 7
149 1.5 eeh *
150 1.6 eeh * Unfortunately, sabres on UltraSPARC IIi and IIe processors does not use
151 1.6 eeh * this scheme to determine the IOVA base address. Instead, bits 31-29 are
152 1.6 eeh * used to check against the Target Address Space register in the IIi and
153 1.12 simonb * the IOMMU is used if they hit. God knows what goes on in the IIe.
154 1.6 eeh *
155 1.5 eeh */
156 1.5 eeh
157 1.1 mrg
158 1.7 eeh #define IOTSB_VEND (u_int)(0xffffffffffffffffLL<<PGSHIFT)
159 1.4 eeh #define IOTSB_VSTART(sz) (u_int)(IOTSB_VEND << ((sz)+10))
160 1.7 eeh #define IOTSB_VSIZE(sz) (u_int)(1 << ((sz)+10+PGSHIFT))
161 1.2 mrg
162 1.1 mrg #define MAKEIOTTE(pa,w,c,s) (((pa)&IOTTE_PAMASK)|((w)?IOTTE_W:0)|((c)?IOTTE_C:0)|((s)?IOTTE_STREAM:0)|(IOTTE_V|IOTTE_8K))
163 1.6 eeh #define IOTSBSLOT(va,sz) ((u_int)(((vaddr_t)(va))-(is->is_dvmabase))>>PGSHIFT)
164 1.1 mrg
165 1.1 mrg /*
166 1.3 mrg * interrupt map stuff. this belongs elsewhere.
167 1.1 mrg */
168 1.1 mrg
169 1.1 mrg #define INTMAP_V 0x080000000LL /* Interrupt valid (enabled) */
170 1.1 mrg #define INTMAP_TID 0x07c000000LL /* UPA target ID mask */
171 1.11 petrov #define INTMAP_TID_SHIFT 26
172 1.2 mrg #define INTMAP_IGN 0x0000007c0LL /* Interrupt group no (sbus only). */
173 1.15 mrg #define INTMAP_IGN_SHIFT 6
174 1.1 mrg #define INTMAP_INO 0x00000003fLL /* Interrupt number */
175 1.1 mrg #define INTMAP_INR (INTMAP_IGN|INTMAP_INO)
176 1.3 mrg #define INTMAP_SBUSSLOT 0x000000018LL /* SBUS slot # */
177 1.3 mrg #define INTMAP_PCIBUS 0x000000010LL /* PCI bus number (A or B) */
178 1.3 mrg #define INTMAP_PCISLOT 0x00000000cLL /* PCI slot # */
179 1.3 mrg #define INTMAP_PCIINT 0x000000003LL /* PCI interrupt #A,#B,#C,#D */
180 1.1 mrg #define INTMAP_OBIO 0x000000020LL /* Onboard device */
181 1.1 mrg #define INTMAP_LSHIFT 11 /* Encode level in vector */
182 1.1 mrg #define INTLEVENCODE(x) (((x)&0x0f)<<INTMAP_LSHIFT)
183 1.1 mrg #define INTLEV(x) (((x)>>INTMAP_LSHIFT)&0x0f)
184 1.1 mrg #define INTVEC(x) ((x)&INTMAP_INR)
185 1.1 mrg #define INTSLOT(x) (((x)>>3)&0x7)
186 1.1 mrg #define INTPRI(x) ((x)&0x7)
187 1.3 mrg #define INTINO(x) ((x)&INTMAP_INO)
188 1.15 mrg #define INTIGN(x) ((x)&INTMAP_IGN)
189 1.3 mrg
190 1.3 mrg #define INTPCI_MAXOBINO 0x16 /* maximum OBIO INO value for PCI */
191 1.3 mrg #define INTPCIOBINOX(x) ((x)&0x1f) /* OBIO ino index (for PCI machines) */
192 1.3 mrg #define INTPCIINOX(x) (((x)&0x1c)>>2) /* PCI ino index */
193 1.2 mrg
194 1.2 mrg #endif /* _SPARC64_DEV_IOMMUREG_H_ */
195