]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/sparc64/include/iommureg.h
Remove sv_pagesize, originally introduced with r100384.
[FreeBSD/FreeBSD.git] / sys / sparc64 / include / iommureg.h
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 1992, 1993
5  *      The Regents of the University of California.  All rights reserved.
6  *
7  * This software was developed by the Computer Systems Engineering group
8  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9  * contributed to Berkeley.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. Neither the name of the University nor the names of its contributors
20  *    may be used to endorse or promote products derived from this software
21  *    without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  *
35  *      from: @(#)sbusreg.h     8.1 (Berkeley) 6/11/93
36  *      from: NetBSD: iommureg.h,v 1.6 2001/07/20 00:07:13 eeh Exp
37  *
38  * $FreeBSD$
39  */
40
41 #ifndef _MACHINE_IOMMUREG_H_
42 #define _MACHINE_IOMMUREG_H_
43
44 /*
45  * UltraSPARC IOMMU registers, common to both the PCI and SBus
46  * controllers.
47  */
48
49 /* IOMMU registers */
50 #define IMR_CTL         0x0000  /* IOMMU control register */
51 #define IMR_TSB         0x0008  /* IOMMU TSB base register */
52 #define IMR_FLUSH       0x0010  /* IOMMU flush register */
53 /* The TTE Cache is Fire and Oberon only. */
54 #define IMR_CACHE_FLUSH 0x0100  /* IOMMU TTE cache flush address register */
55 #define IMR_CACHE_INVAL 0x0108  /* IOMMU TTE cache invalidate register */
56
57 /* streaming buffer registers */
58 #define ISR_CTL         0x0000  /* streaming buffer control reg */
59 #define ISR_PGFLUSH     0x0008  /* streaming buffer page flush */
60 #define ISR_FLUSHSYNC   0x0010  /* streaming buffer flush sync */
61
62 /* streaming buffer diagnostics registers */
63 #define ISD_DATA_DIAG   0x0000  /* streaming buffer data RAM diag 0..127 */
64 #define ISD_ERROR_DIAG  0x0400  /* streaming buffer error status diag 0..127 */
65 #define ISD_PG_TAG_DIAG 0x0800  /* streaming buffer page tag diag 0..15 */
66 #define ISD_LN_TAG_DIAG 0x0900  /* streaming buffer line tag diag 0..15 */
67
68 /* streaming buffer control register */
69 #define STRBUF_EN               0x0000000000000001UL
70 #define STRBUF_D                0x0000000000000002UL
71 #define STRBUF_RR_DIS           0x0000000000000004UL
72
73 #define IOMMU_MAXADDR(bits)     ((1UL << (bits)) - 1)
74
75 /*
76  * control register bits
77  */
78 /* Nummber of entries in the IOTSB - pre-Fire only */
79 #define IOMMUCR_TSBSZ_MASK      0x0000000000070000UL
80 #define IOMMUCR_TSBSZ_SHIFT     16
81 /* TSB cache snoop enable */
82 #define IOMMUCR_SE              0x0000000000000400UL
83 /* Cache modes - Fire and Oberon */
84 #define IOMMUCR_CM_NC_TLB_TBW   0x0000000000000000UL
85 #define IOMMUCR_CM_LC_NTLB_NTBW 0x0000000000000100UL
86 #define IOMMUCR_CM_LC_TLB_TBW   0x0000000000000200UL
87 #define IOMMUCR_CM_C_TLB_TBW    0x0000000000000300UL
88 /* IOMMU page size - pre-Fire only */
89 #define IOMMUCR_8KPG            0x0000000000000000UL
90 #define IOMMUCR_64KPG           0x0000000000000004UL
91 /* Bypass enable - Fire and Oberon */
92 #define IOMMUCR_BE              0x0000000000000002UL
93 /* Diagnostic mode enable - pre-Fire only */
94 #define IOMMUCR_DE              0x0000000000000002UL
95 /* IOMMU/translation enable */
96 #define IOMMUCR_EN              0x0000000000000001UL
97
98 /*
99  * TSB base register bits
100  */
101  /* TSB base address */
102 #define IOMMUTB_TB_MASK         0x000007ffffffe000UL
103 #define IOMMUTB_TB_SHIFT        13
104 /* IOMMU page size - Fire and Oberon */
105 #define IOMMUTB_8KPG            0x0000000000000000UL
106 #define IOMMUTB_64KPG           0x0000000000000100UL
107 /* Nummber of entries in the IOTSB - Fire and Oberon */
108 #define IOMMUTB_TSBSZ_MASK      0x0000000000000004UL
109 #define IOMMUTB_TSBSZ_SHIFT     0
110
111 /*
112  * TSB size definitions for both control and TSB base register */
113 #define IOMMU_TSB1K             0
114 #define IOMMU_TSB2K             1
115 #define IOMMU_TSB4K             2
116 #define IOMMU_TSB8K             3
117 #define IOMMU_TSB16K            4
118 #define IOMMU_TSB32K            5
119 #define IOMMU_TSB64K            6
120 #define IOMMU_TSB128K           7
121 /* Fire and Oberon */
122 #define IOMMU_TSB256K           8
123 /* Fire and Oberon */
124 #define IOMMU_TSB512K           9
125 #define IOMMU_TSBENTRIES(tsbsz)                                         \
126         ((1 << (tsbsz)) << (IO_PAGE_SHIFT - IOTTE_SHIFT))
127
128 /*
129  * Diagnostic register definitions
130  */
131 #define IOMMU_DTAG_VPNBITS      19
132 #define IOMMU_DTAG_VPNMASK      ((1 << IOMMU_DTAG_VPNBITS) - 1)
133 #define IOMMU_DTAG_VPNSHIFT     13
134 #define IOMMU_DTAG_ERRBITS      3
135 #define IOMMU_DTAG_ERRSHIFT     22
136 #define IOMMU_DTAG_ERRMASK                                              \
137         (((1 << IOMMU_DTAG_ERRBITS) - 1) << IOMMU_DTAG_ERRSHIFT)
138
139 #define IOMMU_DDATA_PGBITS      21
140 #define IOMMU_DDATA_PGMASK      ((1 << IOMMU_DDATA_PGBITS) - 1)
141 #define IOMMU_DDATA_PGSHIFT     13
142 #define IOMMU_DDATA_C           (1 << 28)
143 #define IOMMU_DDATA_V           (1 << 30)
144
145 /*
146  * IOMMU stuff
147  */
148 /* Entry valid */
149 #define IOTTE_V                 0x8000000000000000UL
150 /* Page size - pre-Fire only */
151 #define IOTTE_64K               0x2000000000000000UL
152 #define IOTTE_8K                0x0000000000000000UL
153 /* Streamable page - streaming buffer equipped variants only */
154 #define IOTTE_STREAM            0x1000000000000000UL
155 /* Accesses to the same bus segment - SBus only */
156 #define IOTTE_LOCAL             0x0800000000000000UL
157 /* Physical address mask (based on Oberon) */
158 #define IOTTE_PAMASK            0x00007fffffffe000UL
159 /* Accesses to cacheable space - pre-Fire only */
160 #define IOTTE_C                 0x0000000000000010UL
161 /* Writeable */
162 #define IOTTE_W                 0x0000000000000002UL
163
164 /* log2 of the IOMMU TTE size */
165 #define IOTTE_SHIFT             3
166
167 /* Streaming buffer line size */
168 #define STRBUF_LINESZ           64
169
170 /*
171  * Number of bytes written by a stream buffer flushsync operation to indicate
172  * completion.
173  */
174 #define STRBUF_FLUSHSYNC_NBYTES STRBUF_LINESZ
175
176 /*
177  * On sun4u each bus controller has a separate IOMMU.  The IOMMU has
178  * a TSB which must be page aligned and physically contiguous.  Mappings
179  * can be of 8K IOMMU pages or 64K IOMMU pages.  We use 8K for compatibility
180  * with the CPU's MMU.
181  *
182  * On sysio, psycho, and psycho+, IOMMU TSBs using 8K pages can map the
183  * following size segments:
184  *
185  *      VA size         VA base         TSB size        tsbsize
186  *      --------        --------        ---------       -------
187  *      8MB             ff800000        8K              0
188  *      16MB            ff000000        16K             1
189  *      32MB            fe000000        32K             2
190  *      64MB            fc000000        64K             3
191  *      128MB           f8000000        128K            4
192  *      256MB           f0000000        256K            5
193  *      512MB           e0000000        512K            6
194  *      1GB             c0000000        1MB             7
195  *
196  * Unfortunately, sabres on UltraSPARC IIi and IIe processors does not use
197  * this scheme to determine the IOVA base address.  Instead, bits 31-29 are
198  * used to check against the Target Address Space register in the IIi and
199  * the IOMMU is used if they hit.  God knows what goes on in the IIe.
200  *
201  */
202
203 #define IOTSB_BASESZ            (1024 << IOTTE_SHIFT)
204 #define IOTSB_VEND              (~IO_PAGE_MASK)
205 #define IOTSB_VSTART(sz)        (u_int)(IOTSB_VEND << ((sz) + 10))
206
207 #define MAKEIOTTE(pa, w, c, s)                                          \
208         (((pa) & IOTTE_PAMASK) | ((w) ? IOTTE_W : 0) |                  \
209         ((c) ? IOTTE_C : 0) | ((s) ? IOTTE_STREAM : 0) |                \
210         (IOTTE_V | IOTTE_8K))
211 #define IOTSBSLOT(va)                                                   \
212         ((u_int)(((vm_offset_t)(va)) - (is->is_dvmabase)) >> IO_PAGE_SHIFT)
213
214 #endif /* !_MACHINE_IOMMUREG_H_ */