root / hw / dma / sun4m_iommu.c @ 0434e30a
History | View | Annotate | Download (12.9 kB)
1 | 420557e8 | bellard | /*
|
---|---|---|---|
2 | 93c5a32f | Blue Swirl | * QEMU Sun4m iommu emulation
|
3 | 420557e8 | bellard | *
|
4 | 66321a11 | bellard | * Copyright (c) 2003-2005 Fabrice Bellard
|
5 | 5fafdf24 | ths | *
|
6 | 420557e8 | bellard | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | 420557e8 | bellard | * of this software and associated documentation files (the "Software"), to deal
|
8 | 420557e8 | bellard | * in the Software without restriction, including without limitation the rights
|
9 | 420557e8 | bellard | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | 420557e8 | bellard | * copies of the Software, and to permit persons to whom the Software is
|
11 | 420557e8 | bellard | * furnished to do so, subject to the following conditions:
|
12 | 420557e8 | bellard | *
|
13 | 420557e8 | bellard | * The above copyright notice and this permission notice shall be included in
|
14 | 420557e8 | bellard | * all copies or substantial portions of the Software.
|
15 | 420557e8 | bellard | *
|
16 | 420557e8 | bellard | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | 420557e8 | bellard | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | 420557e8 | bellard | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | 420557e8 | bellard | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | 420557e8 | bellard | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | 420557e8 | bellard | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | 420557e8 | bellard | * THE SOFTWARE.
|
23 | 420557e8 | bellard | */
|
24 | 5f750b2e | Blue Swirl | |
25 | 0d09e41a | Paolo Bonzini | #include "hw/sparc/sun4m.h" |
26 | 83c9f4ca | Paolo Bonzini | #include "hw/sysbus.h" |
27 | 97bf4851 | Blue Swirl | #include "trace.h" |
28 | 420557e8 | bellard | |
29 | 93c5a32f | Blue Swirl | /*
|
30 | 93c5a32f | Blue Swirl | * I/O MMU used by Sun4m systems
|
31 | 93c5a32f | Blue Swirl | *
|
32 | 93c5a32f | Blue Swirl | * Chipset docs:
|
33 | 93c5a32f | Blue Swirl | * "Sun-4M System Architecture (revision 2.0) by Chuck Narad", 950-1373-01,
|
34 | 93c5a32f | Blue Swirl | * http://mediacast.sun.com/users/Barton808/media/Sun4M_SystemArchitecture_edited2.pdf
|
35 | 93c5a32f | Blue Swirl | */
|
36 | 93c5a32f | Blue Swirl | |
37 | e5e38121 | blueswir1 | #define IOMMU_NREGS (4*4096/4) |
38 | 4e3b1ea1 | bellard | #define IOMMU_CTRL (0x0000 >> 2) |
39 | 420557e8 | bellard | #define IOMMU_CTRL_IMPL 0xf0000000 /* Implementation */ |
40 | 420557e8 | bellard | #define IOMMU_CTRL_VERS 0x0f000000 /* Version */ |
41 | 420557e8 | bellard | #define IOMMU_CTRL_RNGE 0x0000001c /* Mapping RANGE */ |
42 | 420557e8 | bellard | #define IOMMU_RNGE_16MB 0x00000000 /* 0xff000000 -> 0xffffffff */ |
43 | 420557e8 | bellard | #define IOMMU_RNGE_32MB 0x00000004 /* 0xfe000000 -> 0xffffffff */ |
44 | 420557e8 | bellard | #define IOMMU_RNGE_64MB 0x00000008 /* 0xfc000000 -> 0xffffffff */ |
45 | 420557e8 | bellard | #define IOMMU_RNGE_128MB 0x0000000c /* 0xf8000000 -> 0xffffffff */ |
46 | 420557e8 | bellard | #define IOMMU_RNGE_256MB 0x00000010 /* 0xf0000000 -> 0xffffffff */ |
47 | 420557e8 | bellard | #define IOMMU_RNGE_512MB 0x00000014 /* 0xe0000000 -> 0xffffffff */ |
48 | 420557e8 | bellard | #define IOMMU_RNGE_1GB 0x00000018 /* 0xc0000000 -> 0xffffffff */ |
49 | 420557e8 | bellard | #define IOMMU_RNGE_2GB 0x0000001c /* 0x80000000 -> 0xffffffff */ |
50 | 420557e8 | bellard | #define IOMMU_CTRL_ENAB 0x00000001 /* IOMMU Enable */ |
51 | 4e3b1ea1 | bellard | #define IOMMU_CTRL_MASK 0x0000001d |
52 | 4e3b1ea1 | bellard | |
53 | 4e3b1ea1 | bellard | #define IOMMU_BASE (0x0004 >> 2) |
54 | 4e3b1ea1 | bellard | #define IOMMU_BASE_MASK 0x07fffc00 |
55 | 4e3b1ea1 | bellard | |
56 | 4e3b1ea1 | bellard | #define IOMMU_TLBFLUSH (0x0014 >> 2) |
57 | 4e3b1ea1 | bellard | #define IOMMU_TLBFLUSH_MASK 0xffffffff |
58 | 4e3b1ea1 | bellard | |
59 | 4e3b1ea1 | bellard | #define IOMMU_PGFLUSH (0x0018 >> 2) |
60 | 4e3b1ea1 | bellard | #define IOMMU_PGFLUSH_MASK 0xffffffff |
61 | 4e3b1ea1 | bellard | |
62 | 225d4be7 | blueswir1 | #define IOMMU_AFSR (0x1000 >> 2) |
63 | 225d4be7 | blueswir1 | #define IOMMU_AFSR_ERR 0x80000000 /* LE, TO, or BE asserted */ |
64 | 5ad6bb97 | blueswir1 | #define IOMMU_AFSR_LE 0x40000000 /* SBUS reports error after |
65 | 5ad6bb97 | blueswir1 | transaction */
|
66 | 5ad6bb97 | blueswir1 | #define IOMMU_AFSR_TO 0x20000000 /* Write access took more than |
67 | 5ad6bb97 | blueswir1 | 12.8 us. */
|
68 | 5ad6bb97 | blueswir1 | #define IOMMU_AFSR_BE 0x10000000 /* Write access received error |
69 | 5ad6bb97 | blueswir1 | acknowledge */
|
70 | 225d4be7 | blueswir1 | #define IOMMU_AFSR_SIZE 0x0e000000 /* Size of transaction causing error */ |
71 | 225d4be7 | blueswir1 | #define IOMMU_AFSR_S 0x01000000 /* Sparc was in supervisor mode */ |
72 | 5ad6bb97 | blueswir1 | #define IOMMU_AFSR_RESV 0x00800000 /* Reserved, forced to 0x8 by |
73 | 5ad6bb97 | blueswir1 | hardware */
|
74 | 225d4be7 | blueswir1 | #define IOMMU_AFSR_ME 0x00080000 /* Multiple errors occurred */ |
75 | 225d4be7 | blueswir1 | #define IOMMU_AFSR_RD 0x00040000 /* A read operation was in progress */ |
76 | 225d4be7 | blueswir1 | #define IOMMU_AFSR_FAV 0x00020000 /* IOMMU afar has valid contents */ |
77 | c52428fc | blueswir1 | #define IOMMU_AFSR_MASK 0xff0fffff |
78 | 225d4be7 | blueswir1 | |
79 | 225d4be7 | blueswir1 | #define IOMMU_AFAR (0x1004 >> 2) |
80 | 225d4be7 | blueswir1 | |
81 | 7b169687 | blueswir1 | #define IOMMU_AER (0x1008 >> 2) /* Arbiter Enable Register */ |
82 | 7b169687 | blueswir1 | #define IOMMU_AER_EN_P0_ARB 0x00000001 /* MBus master 0x8 (Always 1) */ |
83 | 7b169687 | blueswir1 | #define IOMMU_AER_EN_P1_ARB 0x00000002 /* MBus master 0x9 */ |
84 | 7b169687 | blueswir1 | #define IOMMU_AER_EN_P2_ARB 0x00000004 /* MBus master 0xa */ |
85 | 7b169687 | blueswir1 | #define IOMMU_AER_EN_P3_ARB 0x00000008 /* MBus master 0xb */ |
86 | 7b169687 | blueswir1 | #define IOMMU_AER_EN_0 0x00010000 /* SBus slot 0 */ |
87 | 7b169687 | blueswir1 | #define IOMMU_AER_EN_1 0x00020000 /* SBus slot 1 */ |
88 | 7b169687 | blueswir1 | #define IOMMU_AER_EN_2 0x00040000 /* SBus slot 2 */ |
89 | 7b169687 | blueswir1 | #define IOMMU_AER_EN_3 0x00080000 /* SBus slot 3 */ |
90 | 7b169687 | blueswir1 | #define IOMMU_AER_EN_F 0x00100000 /* SBus on-board */ |
91 | 7b169687 | blueswir1 | #define IOMMU_AER_SBW 0x80000000 /* S-to-M asynchronous writes */ |
92 | 7b169687 | blueswir1 | #define IOMMU_AER_MASK 0x801f000f |
93 | 7b169687 | blueswir1 | |
94 | 4e3b1ea1 | bellard | #define IOMMU_SBCFG0 (0x1010 >> 2) /* SBUS configration per-slot */ |
95 | 4e3b1ea1 | bellard | #define IOMMU_SBCFG1 (0x1014 >> 2) /* SBUS configration per-slot */ |
96 | 4e3b1ea1 | bellard | #define IOMMU_SBCFG2 (0x1018 >> 2) /* SBUS configration per-slot */ |
97 | 4e3b1ea1 | bellard | #define IOMMU_SBCFG3 (0x101c >> 2) /* SBUS configration per-slot */ |
98 | 5ad6bb97 | blueswir1 | #define IOMMU_SBCFG_SAB30 0x00010000 /* Phys-address bit 30 when |
99 | 5ad6bb97 | blueswir1 | bypass enabled */
|
100 | 4e3b1ea1 | bellard | #define IOMMU_SBCFG_BA16 0x00000004 /* Slave supports 16 byte bursts */ |
101 | 4e3b1ea1 | bellard | #define IOMMU_SBCFG_BA8 0x00000002 /* Slave supports 8 byte bursts */ |
102 | 4e3b1ea1 | bellard | #define IOMMU_SBCFG_BYPASS 0x00000001 /* Bypass IOMMU, treat all addresses |
103 | f930d07e | blueswir1 | produced by this device as pure
|
104 | 4e3b1ea1 | bellard | physical. */
|
105 | 4e3b1ea1 | bellard | #define IOMMU_SBCFG_MASK 0x00010003 |
106 | 4e3b1ea1 | bellard | |
107 | 4e3b1ea1 | bellard | #define IOMMU_ARBEN (0x2000 >> 2) /* SBUS arbitration enable */ |
108 | 4e3b1ea1 | bellard | #define IOMMU_ARBEN_MASK 0x001f0000 |
109 | 4e3b1ea1 | bellard | #define IOMMU_MID 0x00000008 |
110 | 420557e8 | bellard | |
111 | e5e38121 | blueswir1 | #define IOMMU_MASK_ID (0x3018 >> 2) /* Mask ID */ |
112 | e5e38121 | blueswir1 | #define IOMMU_MASK_ID_MASK 0x00ffffff |
113 | e5e38121 | blueswir1 | |
114 | e5e38121 | blueswir1 | #define IOMMU_MSII_MASK 0x26000000 /* microSPARC II mask number */ |
115 | e5e38121 | blueswir1 | #define IOMMU_TS_MASK 0x23000000 /* turboSPARC mask number */ |
116 | e5e38121 | blueswir1 | |
117 | 420557e8 | bellard | /* The format of an iopte in the page tables */
|
118 | 498fbd8a | blueswir1 | #define IOPTE_PAGE 0xffffff00 /* Physical page number (PA[35:12]) */ |
119 | 5ad6bb97 | blueswir1 | #define IOPTE_CACHE 0x00000080 /* Cached (in vme IOCACHE or |
120 | 5ad6bb97 | blueswir1 | Viking/MXCC) */
|
121 | ebabb67a | Stefan Weil | #define IOPTE_WRITE 0x00000004 /* Writable */ |
122 | 420557e8 | bellard | #define IOPTE_VALID 0x00000002 /* IOPTE is valid */ |
123 | 420557e8 | bellard | #define IOPTE_WAZ 0x00000001 /* Write as zeros */ |
124 | 420557e8 | bellard | |
125 | 8b0de438 | blueswir1 | #define IOMMU_PAGE_SHIFT 12 |
126 | 8b0de438 | blueswir1 | #define IOMMU_PAGE_SIZE (1 << IOMMU_PAGE_SHIFT) |
127 | 8b0de438 | blueswir1 | #define IOMMU_PAGE_MASK ~(IOMMU_PAGE_SIZE - 1) |
128 | 420557e8 | bellard | |
129 | 420557e8 | bellard | typedef struct IOMMUState { |
130 | 5f750b2e | Blue Swirl | SysBusDevice busdev; |
131 | d224136c | Avi Kivity | MemoryRegion iomem; |
132 | 66321a11 | bellard | uint32_t regs[IOMMU_NREGS]; |
133 | a8170e5e | Avi Kivity | hwaddr iostart; |
134 | ff403da6 | blueswir1 | qemu_irq irq; |
135 | 149e1ea1 | Blue Swirl | uint32_t version; |
136 | 420557e8 | bellard | } IOMMUState; |
137 | 420557e8 | bellard | |
138 | a8170e5e | Avi Kivity | static uint64_t iommu_mem_read(void *opaque, hwaddr addr, |
139 | d224136c | Avi Kivity | unsigned size)
|
140 | 420557e8 | bellard | { |
141 | 420557e8 | bellard | IOMMUState *s = opaque; |
142 | a8170e5e | Avi Kivity | hwaddr saddr; |
143 | ff403da6 | blueswir1 | uint32_t ret; |
144 | 420557e8 | bellard | |
145 | 8da3ff18 | pbrook | saddr = addr >> 2;
|
146 | 420557e8 | bellard | switch (saddr) {
|
147 | 420557e8 | bellard | default:
|
148 | ff403da6 | blueswir1 | ret = s->regs[saddr]; |
149 | ff403da6 | blueswir1 | break;
|
150 | ff403da6 | blueswir1 | case IOMMU_AFAR:
|
151 | ff403da6 | blueswir1 | case IOMMU_AFSR:
|
152 | ff403da6 | blueswir1 | ret = s->regs[saddr]; |
153 | ff403da6 | blueswir1 | qemu_irq_lower(s->irq); |
154 | f930d07e | blueswir1 | break;
|
155 | 420557e8 | bellard | } |
156 | 97bf4851 | Blue Swirl | trace_sun4m_iommu_mem_readl(saddr, ret); |
157 | ff403da6 | blueswir1 | return ret;
|
158 | 420557e8 | bellard | } |
159 | 420557e8 | bellard | |
160 | a8170e5e | Avi Kivity | static void iommu_mem_write(void *opaque, hwaddr addr, |
161 | d224136c | Avi Kivity | uint64_t val, unsigned size)
|
162 | 420557e8 | bellard | { |
163 | 420557e8 | bellard | IOMMUState *s = opaque; |
164 | a8170e5e | Avi Kivity | hwaddr saddr; |
165 | 420557e8 | bellard | |
166 | 8da3ff18 | pbrook | saddr = addr >> 2;
|
167 | 97bf4851 | Blue Swirl | trace_sun4m_iommu_mem_writel(saddr, val); |
168 | 420557e8 | bellard | switch (saddr) {
|
169 | 4e3b1ea1 | bellard | case IOMMU_CTRL:
|
170 | f930d07e | blueswir1 | switch (val & IOMMU_CTRL_RNGE) {
|
171 | f930d07e | blueswir1 | case IOMMU_RNGE_16MB:
|
172 | f930d07e | blueswir1 | s->iostart = 0xffffffffff000000ULL;
|
173 | f930d07e | blueswir1 | break;
|
174 | f930d07e | blueswir1 | case IOMMU_RNGE_32MB:
|
175 | f930d07e | blueswir1 | s->iostart = 0xfffffffffe000000ULL;
|
176 | f930d07e | blueswir1 | break;
|
177 | f930d07e | blueswir1 | case IOMMU_RNGE_64MB:
|
178 | f930d07e | blueswir1 | s->iostart = 0xfffffffffc000000ULL;
|
179 | f930d07e | blueswir1 | break;
|
180 | f930d07e | blueswir1 | case IOMMU_RNGE_128MB:
|
181 | f930d07e | blueswir1 | s->iostart = 0xfffffffff8000000ULL;
|
182 | f930d07e | blueswir1 | break;
|
183 | f930d07e | blueswir1 | case IOMMU_RNGE_256MB:
|
184 | f930d07e | blueswir1 | s->iostart = 0xfffffffff0000000ULL;
|
185 | f930d07e | blueswir1 | break;
|
186 | f930d07e | blueswir1 | case IOMMU_RNGE_512MB:
|
187 | f930d07e | blueswir1 | s->iostart = 0xffffffffe0000000ULL;
|
188 | f930d07e | blueswir1 | break;
|
189 | f930d07e | blueswir1 | case IOMMU_RNGE_1GB:
|
190 | f930d07e | blueswir1 | s->iostart = 0xffffffffc0000000ULL;
|
191 | f930d07e | blueswir1 | break;
|
192 | f930d07e | blueswir1 | default:
|
193 | f930d07e | blueswir1 | case IOMMU_RNGE_2GB:
|
194 | f930d07e | blueswir1 | s->iostart = 0xffffffff80000000ULL;
|
195 | f930d07e | blueswir1 | break;
|
196 | f930d07e | blueswir1 | } |
197 | 97bf4851 | Blue Swirl | trace_sun4m_iommu_mem_writel_ctrl(s->iostart); |
198 | 7fbfb139 | blueswir1 | s->regs[saddr] = ((val & IOMMU_CTRL_MASK) | s->version); |
199 | f930d07e | blueswir1 | break;
|
200 | 4e3b1ea1 | bellard | case IOMMU_BASE:
|
201 | f930d07e | blueswir1 | s->regs[saddr] = val & IOMMU_BASE_MASK; |
202 | f930d07e | blueswir1 | break;
|
203 | 4e3b1ea1 | bellard | case IOMMU_TLBFLUSH:
|
204 | 97bf4851 | Blue Swirl | trace_sun4m_iommu_mem_writel_tlbflush(val); |
205 | f930d07e | blueswir1 | s->regs[saddr] = val & IOMMU_TLBFLUSH_MASK; |
206 | f930d07e | blueswir1 | break;
|
207 | 4e3b1ea1 | bellard | case IOMMU_PGFLUSH:
|
208 | 97bf4851 | Blue Swirl | trace_sun4m_iommu_mem_writel_pgflush(val); |
209 | f930d07e | blueswir1 | s->regs[saddr] = val & IOMMU_PGFLUSH_MASK; |
210 | f930d07e | blueswir1 | break;
|
211 | ff403da6 | blueswir1 | case IOMMU_AFAR:
|
212 | ff403da6 | blueswir1 | s->regs[saddr] = val; |
213 | ff403da6 | blueswir1 | qemu_irq_lower(s->irq); |
214 | ff403da6 | blueswir1 | break;
|
215 | 7b169687 | blueswir1 | case IOMMU_AER:
|
216 | 7b169687 | blueswir1 | s->regs[saddr] = (val & IOMMU_AER_MASK) | IOMMU_AER_EN_P0_ARB; |
217 | 7b169687 | blueswir1 | break;
|
218 | c52428fc | blueswir1 | case IOMMU_AFSR:
|
219 | c52428fc | blueswir1 | s->regs[saddr] = (val & IOMMU_AFSR_MASK) | IOMMU_AFSR_RESV; |
220 | ff403da6 | blueswir1 | qemu_irq_lower(s->irq); |
221 | c52428fc | blueswir1 | break;
|
222 | 4e3b1ea1 | bellard | case IOMMU_SBCFG0:
|
223 | 4e3b1ea1 | bellard | case IOMMU_SBCFG1:
|
224 | 4e3b1ea1 | bellard | case IOMMU_SBCFG2:
|
225 | 4e3b1ea1 | bellard | case IOMMU_SBCFG3:
|
226 | f930d07e | blueswir1 | s->regs[saddr] = val & IOMMU_SBCFG_MASK; |
227 | f930d07e | blueswir1 | break;
|
228 | 4e3b1ea1 | bellard | case IOMMU_ARBEN:
|
229 | 4e3b1ea1 | bellard | // XXX implement SBus probing: fault when reading unmapped
|
230 | 4e3b1ea1 | bellard | // addresses, fault cause and address stored to MMU/IOMMU
|
231 | f930d07e | blueswir1 | s->regs[saddr] = (val & IOMMU_ARBEN_MASK) | IOMMU_MID; |
232 | f930d07e | blueswir1 | break;
|
233 | e5e38121 | blueswir1 | case IOMMU_MASK_ID:
|
234 | e5e38121 | blueswir1 | s->regs[saddr] |= val & IOMMU_MASK_ID_MASK; |
235 | e5e38121 | blueswir1 | break;
|
236 | 420557e8 | bellard | default:
|
237 | f930d07e | blueswir1 | s->regs[saddr] = val; |
238 | f930d07e | blueswir1 | break;
|
239 | 420557e8 | bellard | } |
240 | 420557e8 | bellard | } |
241 | 420557e8 | bellard | |
242 | d224136c | Avi Kivity | static const MemoryRegionOps iommu_mem_ops = { |
243 | d224136c | Avi Kivity | .read = iommu_mem_read, |
244 | d224136c | Avi Kivity | .write = iommu_mem_write, |
245 | d224136c | Avi Kivity | .endianness = DEVICE_NATIVE_ENDIAN, |
246 | d224136c | Avi Kivity | .valid = { |
247 | d224136c | Avi Kivity | .min_access_size = 4,
|
248 | d224136c | Avi Kivity | .max_access_size = 4,
|
249 | d224136c | Avi Kivity | }, |
250 | 420557e8 | bellard | }; |
251 | 420557e8 | bellard | |
252 | a8170e5e | Avi Kivity | static uint32_t iommu_page_get_flags(IOMMUState *s, hwaddr addr)
|
253 | 420557e8 | bellard | { |
254 | 5e3b100b | blueswir1 | uint32_t ret; |
255 | a8170e5e | Avi Kivity | hwaddr iopte; |
256 | a8170e5e | Avi Kivity | hwaddr pa = addr; |
257 | 420557e8 | bellard | |
258 | 981a2e99 | blueswir1 | iopte = s->regs[IOMMU_BASE] << 4;
|
259 | 66321a11 | bellard | addr &= ~s->iostart; |
260 | 8b0de438 | blueswir1 | iopte += (addr >> (IOMMU_PAGE_SHIFT - 2)) & ~3; |
261 | d2c0bd84 | Paolo Bonzini | ret = ldl_be_phys(iopte); |
262 | 97bf4851 | Blue Swirl | trace_sun4m_iommu_page_get_flags(pa, iopte, ret); |
263 | 981a2e99 | blueswir1 | return ret;
|
264 | a917d384 | pbrook | } |
265 | a917d384 | pbrook | |
266 | a8170e5e | Avi Kivity | static hwaddr iommu_translate_pa(hwaddr addr,
|
267 | 5dcb6b91 | blueswir1 | uint32_t pte) |
268 | a917d384 | pbrook | { |
269 | a8170e5e | Avi Kivity | hwaddr pa; |
270 | 5dcb6b91 | blueswir1 | |
271 | 8b0de438 | blueswir1 | pa = ((pte & IOPTE_PAGE) << 4) + (addr & ~IOMMU_PAGE_MASK);
|
272 | 97bf4851 | Blue Swirl | trace_sun4m_iommu_translate_pa(addr, pa, pte); |
273 | 66321a11 | bellard | return pa;
|
274 | 420557e8 | bellard | } |
275 | 420557e8 | bellard | |
276 | a8170e5e | Avi Kivity | static void iommu_bad_addr(IOMMUState *s, hwaddr addr, |
277 | 5ad6bb97 | blueswir1 | int is_write)
|
278 | 225d4be7 | blueswir1 | { |
279 | 97bf4851 | Blue Swirl | trace_sun4m_iommu_bad_addr(addr); |
280 | 5ad6bb97 | blueswir1 | s->regs[IOMMU_AFSR] = IOMMU_AFSR_ERR | IOMMU_AFSR_LE | IOMMU_AFSR_RESV | |
281 | 225d4be7 | blueswir1 | IOMMU_AFSR_FAV; |
282 | 225d4be7 | blueswir1 | if (!is_write)
|
283 | 225d4be7 | blueswir1 | s->regs[IOMMU_AFSR] |= IOMMU_AFSR_RD; |
284 | 225d4be7 | blueswir1 | s->regs[IOMMU_AFAR] = addr; |
285 | ff403da6 | blueswir1 | qemu_irq_raise(s->irq); |
286 | 225d4be7 | blueswir1 | } |
287 | 225d4be7 | blueswir1 | |
288 | a8170e5e | Avi Kivity | void sparc_iommu_memory_rw(void *opaque, hwaddr addr, |
289 | 67e999be | bellard | uint8_t *buf, int len, int is_write) |
290 | a917d384 | pbrook | { |
291 | 5dcb6b91 | blueswir1 | int l;
|
292 | 5dcb6b91 | blueswir1 | uint32_t flags; |
293 | a8170e5e | Avi Kivity | hwaddr page, phys_addr; |
294 | a917d384 | pbrook | |
295 | a917d384 | pbrook | while (len > 0) { |
296 | 8b0de438 | blueswir1 | page = addr & IOMMU_PAGE_MASK; |
297 | 8b0de438 | blueswir1 | l = (page + IOMMU_PAGE_SIZE) - addr; |
298 | a917d384 | pbrook | if (l > len)
|
299 | a917d384 | pbrook | l = len; |
300 | a917d384 | pbrook | flags = iommu_page_get_flags(opaque, page); |
301 | 225d4be7 | blueswir1 | if (!(flags & IOPTE_VALID)) {
|
302 | 225d4be7 | blueswir1 | iommu_bad_addr(opaque, page, is_write); |
303 | a917d384 | pbrook | return;
|
304 | 225d4be7 | blueswir1 | } |
305 | 22548760 | blueswir1 | phys_addr = iommu_translate_pa(addr, flags); |
306 | a917d384 | pbrook | if (is_write) {
|
307 | 225d4be7 | blueswir1 | if (!(flags & IOPTE_WRITE)) {
|
308 | 225d4be7 | blueswir1 | iommu_bad_addr(opaque, page, is_write); |
309 | a917d384 | pbrook | return;
|
310 | 225d4be7 | blueswir1 | } |
311 | a5cdf952 | blueswir1 | cpu_physical_memory_write(phys_addr, buf, l); |
312 | a917d384 | pbrook | } else {
|
313 | a5cdf952 | blueswir1 | cpu_physical_memory_read(phys_addr, buf, l); |
314 | a917d384 | pbrook | } |
315 | a917d384 | pbrook | len -= l; |
316 | a917d384 | pbrook | buf += l; |
317 | a917d384 | pbrook | addr += l; |
318 | a917d384 | pbrook | } |
319 | a917d384 | pbrook | } |
320 | a917d384 | pbrook | |
321 | db3c9e08 | Blue Swirl | static const VMStateDescription vmstate_iommu = { |
322 | db3c9e08 | Blue Swirl | .name ="iommu",
|
323 | db3c9e08 | Blue Swirl | .version_id = 2,
|
324 | db3c9e08 | Blue Swirl | .minimum_version_id = 2,
|
325 | db3c9e08 | Blue Swirl | .minimum_version_id_old = 2,
|
326 | db3c9e08 | Blue Swirl | .fields = (VMStateField []) { |
327 | db3c9e08 | Blue Swirl | VMSTATE_UINT32_ARRAY(regs, IOMMUState, IOMMU_NREGS), |
328 | db3c9e08 | Blue Swirl | VMSTATE_UINT64(iostart, IOMMUState), |
329 | db3c9e08 | Blue Swirl | VMSTATE_END_OF_LIST() |
330 | db3c9e08 | Blue Swirl | } |
331 | db3c9e08 | Blue Swirl | }; |
332 | e80cfcfc | bellard | |
333 | 1a522e8a | Blue Swirl | static void iommu_reset(DeviceState *d) |
334 | e80cfcfc | bellard | { |
335 | 1a522e8a | Blue Swirl | IOMMUState *s = container_of(d, IOMMUState, busdev.qdev); |
336 | e80cfcfc | bellard | |
337 | 66321a11 | bellard | memset(s->regs, 0, IOMMU_NREGS * 4); |
338 | e80cfcfc | bellard | s->iostart = 0;
|
339 | 7fbfb139 | blueswir1 | s->regs[IOMMU_CTRL] = s->version; |
340 | 7fbfb139 | blueswir1 | s->regs[IOMMU_ARBEN] = IOMMU_MID; |
341 | 5ad6bb97 | blueswir1 | s->regs[IOMMU_AFSR] = IOMMU_AFSR_RESV; |
342 | 7b169687 | blueswir1 | s->regs[IOMMU_AER] = IOMMU_AER_EN_P0_ARB | IOMMU_AER_EN_P1_ARB; |
343 | e5e38121 | blueswir1 | s->regs[IOMMU_MASK_ID] = IOMMU_TS_MASK; |
344 | e80cfcfc | bellard | } |
345 | e80cfcfc | bellard | |
346 | 81a322d4 | Gerd Hoffmann | static int iommu_init1(SysBusDevice *dev) |
347 | 5f750b2e | Blue Swirl | { |
348 | 5f750b2e | Blue Swirl | IOMMUState *s = FROM_SYSBUS(IOMMUState, dev); |
349 | 420557e8 | bellard | |
350 | 5f750b2e | Blue Swirl | sysbus_init_irq(dev, &s->irq); |
351 | 420557e8 | bellard | |
352 | d224136c | Avi Kivity | memory_region_init_io(&s->iomem, &iommu_mem_ops, s, "iommu",
|
353 | d224136c | Avi Kivity | IOMMU_NREGS * sizeof(uint32_t));
|
354 | 750ecd44 | Avi Kivity | sysbus_init_mmio(dev, &s->iomem); |
355 | 3b46e624 | ths | |
356 | 81a322d4 | Gerd Hoffmann | return 0; |
357 | 420557e8 | bellard | } |
358 | 5f750b2e | Blue Swirl | |
359 | 999e12bb | Anthony Liguori | static Property iommu_properties[] = {
|
360 | 999e12bb | Anthony Liguori | DEFINE_PROP_HEX32("version", IOMMUState, version, 0), |
361 | 999e12bb | Anthony Liguori | DEFINE_PROP_END_OF_LIST(), |
362 | 999e12bb | Anthony Liguori | }; |
363 | 999e12bb | Anthony Liguori | |
364 | 999e12bb | Anthony Liguori | static void iommu_class_init(ObjectClass *klass, void *data) |
365 | 999e12bb | Anthony Liguori | { |
366 | 39bffca2 | Anthony Liguori | DeviceClass *dc = DEVICE_CLASS(klass); |
367 | 999e12bb | Anthony Liguori | SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); |
368 | 999e12bb | Anthony Liguori | |
369 | 999e12bb | Anthony Liguori | k->init = iommu_init1; |
370 | 39bffca2 | Anthony Liguori | dc->reset = iommu_reset; |
371 | 39bffca2 | Anthony Liguori | dc->vmsd = &vmstate_iommu; |
372 | 39bffca2 | Anthony Liguori | dc->props = iommu_properties; |
373 | 999e12bb | Anthony Liguori | } |
374 | 999e12bb | Anthony Liguori | |
375 | 8c43a6f0 | Andreas Färber | static const TypeInfo iommu_info = { |
376 | 39bffca2 | Anthony Liguori | .name = "iommu",
|
377 | 39bffca2 | Anthony Liguori | .parent = TYPE_SYS_BUS_DEVICE, |
378 | 39bffca2 | Anthony Liguori | .instance_size = sizeof(IOMMUState),
|
379 | 39bffca2 | Anthony Liguori | .class_init = iommu_class_init, |
380 | 5f750b2e | Blue Swirl | }; |
381 | 5f750b2e | Blue Swirl | |
382 | 83f7d43a | Andreas Färber | static void iommu_register_types(void) |
383 | 5f750b2e | Blue Swirl | { |
384 | 39bffca2 | Anthony Liguori | type_register_static(&iommu_info); |
385 | 5f750b2e | Blue Swirl | } |
386 | 5f750b2e | Blue Swirl | |
387 | 83f7d43a | Andreas Färber | type_init(iommu_register_types) |