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