Statistics
| Branch: | Revision:

root / hw / sun4m_iommu.c @ 78ced65e

History | View | Annotate | Download (12.8 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 87ecb68b pbrook
#include "sun4m.h"
26 5f750b2e Blue Swirl
#include "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 420557e8 bellard
#define IOPTE_WRITE         0x00000004 /* Writeable */
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 66321a11 bellard
    uint32_t regs[IOMMU_NREGS];
132 c227f099 Anthony Liguori
    target_phys_addr_t iostart;
133 7fbfb139 blueswir1
    uint32_t version;
134 ff403da6 blueswir1
    qemu_irq irq;
135 420557e8 bellard
} IOMMUState;
136 420557e8 bellard
137 c227f099 Anthony Liguori
static uint32_t iommu_mem_readl(void *opaque, target_phys_addr_t addr)
138 420557e8 bellard
{
139 420557e8 bellard
    IOMMUState *s = opaque;
140 c227f099 Anthony Liguori
    target_phys_addr_t saddr;
141 ff403da6 blueswir1
    uint32_t ret;
142 420557e8 bellard
143 8da3ff18 pbrook
    saddr = addr >> 2;
144 420557e8 bellard
    switch (saddr) {
145 420557e8 bellard
    default:
146 ff403da6 blueswir1
        ret = s->regs[saddr];
147 ff403da6 blueswir1
        break;
148 ff403da6 blueswir1
    case IOMMU_AFAR:
149 ff403da6 blueswir1
    case IOMMU_AFSR:
150 ff403da6 blueswir1
        ret = s->regs[saddr];
151 ff403da6 blueswir1
        qemu_irq_lower(s->irq);
152 f930d07e blueswir1
        break;
153 420557e8 bellard
    }
154 97bf4851 Blue Swirl
    trace_sun4m_iommu_mem_readl(saddr, ret);
155 ff403da6 blueswir1
    return ret;
156 420557e8 bellard
}
157 420557e8 bellard
158 c227f099 Anthony Liguori
static void iommu_mem_writel(void *opaque, target_phys_addr_t addr,
159 5ad6bb97 blueswir1
                             uint32_t val)
160 420557e8 bellard
{
161 420557e8 bellard
    IOMMUState *s = opaque;
162 c227f099 Anthony Liguori
    target_phys_addr_t saddr;
163 420557e8 bellard
164 8da3ff18 pbrook
    saddr = addr >> 2;
165 97bf4851 Blue Swirl
    trace_sun4m_iommu_mem_writel(saddr, val);
166 420557e8 bellard
    switch (saddr) {
167 4e3b1ea1 bellard
    case IOMMU_CTRL:
168 f930d07e blueswir1
        switch (val & IOMMU_CTRL_RNGE) {
169 f930d07e blueswir1
        case IOMMU_RNGE_16MB:
170 f930d07e blueswir1
            s->iostart = 0xffffffffff000000ULL;
171 f930d07e blueswir1
            break;
172 f930d07e blueswir1
        case IOMMU_RNGE_32MB:
173 f930d07e blueswir1
            s->iostart = 0xfffffffffe000000ULL;
174 f930d07e blueswir1
            break;
175 f930d07e blueswir1
        case IOMMU_RNGE_64MB:
176 f930d07e blueswir1
            s->iostart = 0xfffffffffc000000ULL;
177 f930d07e blueswir1
            break;
178 f930d07e blueswir1
        case IOMMU_RNGE_128MB:
179 f930d07e blueswir1
            s->iostart = 0xfffffffff8000000ULL;
180 f930d07e blueswir1
            break;
181 f930d07e blueswir1
        case IOMMU_RNGE_256MB:
182 f930d07e blueswir1
            s->iostart = 0xfffffffff0000000ULL;
183 f930d07e blueswir1
            break;
184 f930d07e blueswir1
        case IOMMU_RNGE_512MB:
185 f930d07e blueswir1
            s->iostart = 0xffffffffe0000000ULL;
186 f930d07e blueswir1
            break;
187 f930d07e blueswir1
        case IOMMU_RNGE_1GB:
188 f930d07e blueswir1
            s->iostart = 0xffffffffc0000000ULL;
189 f930d07e blueswir1
            break;
190 f930d07e blueswir1
        default:
191 f930d07e blueswir1
        case IOMMU_RNGE_2GB:
192 f930d07e blueswir1
            s->iostart = 0xffffffff80000000ULL;
193 f930d07e blueswir1
            break;
194 f930d07e blueswir1
        }
195 97bf4851 Blue Swirl
        trace_sun4m_iommu_mem_writel_ctrl(s->iostart);
196 7fbfb139 blueswir1
        s->regs[saddr] = ((val & IOMMU_CTRL_MASK) | s->version);
197 f930d07e blueswir1
        break;
198 4e3b1ea1 bellard
    case IOMMU_BASE:
199 f930d07e blueswir1
        s->regs[saddr] = val & IOMMU_BASE_MASK;
200 f930d07e blueswir1
        break;
201 4e3b1ea1 bellard
    case IOMMU_TLBFLUSH:
202 97bf4851 Blue Swirl
        trace_sun4m_iommu_mem_writel_tlbflush(val);
203 f930d07e blueswir1
        s->regs[saddr] = val & IOMMU_TLBFLUSH_MASK;
204 f930d07e blueswir1
        break;
205 4e3b1ea1 bellard
    case IOMMU_PGFLUSH:
206 97bf4851 Blue Swirl
        trace_sun4m_iommu_mem_writel_pgflush(val);
207 f930d07e blueswir1
        s->regs[saddr] = val & IOMMU_PGFLUSH_MASK;
208 f930d07e blueswir1
        break;
209 ff403da6 blueswir1
    case IOMMU_AFAR:
210 ff403da6 blueswir1
        s->regs[saddr] = val;
211 ff403da6 blueswir1
        qemu_irq_lower(s->irq);
212 ff403da6 blueswir1
        break;
213 7b169687 blueswir1
    case IOMMU_AER:
214 7b169687 blueswir1
        s->regs[saddr] = (val & IOMMU_AER_MASK) | IOMMU_AER_EN_P0_ARB;
215 7b169687 blueswir1
        break;
216 c52428fc blueswir1
    case IOMMU_AFSR:
217 c52428fc blueswir1
        s->regs[saddr] = (val & IOMMU_AFSR_MASK) | IOMMU_AFSR_RESV;
218 ff403da6 blueswir1
        qemu_irq_lower(s->irq);
219 c52428fc blueswir1
        break;
220 4e3b1ea1 bellard
    case IOMMU_SBCFG0:
221 4e3b1ea1 bellard
    case IOMMU_SBCFG1:
222 4e3b1ea1 bellard
    case IOMMU_SBCFG2:
223 4e3b1ea1 bellard
    case IOMMU_SBCFG3:
224 f930d07e blueswir1
        s->regs[saddr] = val & IOMMU_SBCFG_MASK;
225 f930d07e blueswir1
        break;
226 4e3b1ea1 bellard
    case IOMMU_ARBEN:
227 4e3b1ea1 bellard
        // XXX implement SBus probing: fault when reading unmapped
228 4e3b1ea1 bellard
        // addresses, fault cause and address stored to MMU/IOMMU
229 f930d07e blueswir1
        s->regs[saddr] = (val & IOMMU_ARBEN_MASK) | IOMMU_MID;
230 f930d07e blueswir1
        break;
231 e5e38121 blueswir1
    case IOMMU_MASK_ID:
232 e5e38121 blueswir1
        s->regs[saddr] |= val & IOMMU_MASK_ID_MASK;
233 e5e38121 blueswir1
        break;
234 420557e8 bellard
    default:
235 f930d07e blueswir1
        s->regs[saddr] = val;
236 f930d07e blueswir1
        break;
237 420557e8 bellard
    }
238 420557e8 bellard
}
239 420557e8 bellard
240 d60efc6b Blue Swirl
static CPUReadMemoryFunc * const iommu_mem_read[3] = {
241 7c560456 blueswir1
    NULL,
242 7c560456 blueswir1
    NULL,
243 7c560456 blueswir1
    iommu_mem_readl,
244 420557e8 bellard
};
245 420557e8 bellard
246 d60efc6b Blue Swirl
static CPUWriteMemoryFunc * const iommu_mem_write[3] = {
247 7c560456 blueswir1
    NULL,
248 7c560456 blueswir1
    NULL,
249 7c560456 blueswir1
    iommu_mem_writel,
250 420557e8 bellard
};
251 420557e8 bellard
252 c227f099 Anthony Liguori
static uint32_t iommu_page_get_flags(IOMMUState *s, target_phys_addr_t addr)
253 420557e8 bellard
{
254 5e3b100b blueswir1
    uint32_t ret;
255 c227f099 Anthony Liguori
    target_phys_addr_t iopte;
256 c227f099 Anthony Liguori
    target_phys_addr_t 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 5e3b100b blueswir1
    cpu_physical_memory_read(iopte, (uint8_t *)&ret, 4);
262 748e4993 blueswir1
    tswap32s(&ret);
263 97bf4851 Blue Swirl
    trace_sun4m_iommu_page_get_flags(pa, iopte, ret);
264 981a2e99 blueswir1
    return ret;
265 a917d384 pbrook
}
266 a917d384 pbrook
267 c227f099 Anthony Liguori
static target_phys_addr_t iommu_translate_pa(target_phys_addr_t addr,
268 5dcb6b91 blueswir1
                                             uint32_t pte)
269 a917d384 pbrook
{
270 c227f099 Anthony Liguori
    target_phys_addr_t pa;
271 5dcb6b91 blueswir1
272 8b0de438 blueswir1
    pa = ((pte & IOPTE_PAGE) << 4) + (addr & ~IOMMU_PAGE_MASK);
273 97bf4851 Blue Swirl
    trace_sun4m_iommu_translate_pa(addr, pa, pte);
274 66321a11 bellard
    return pa;
275 420557e8 bellard
}
276 420557e8 bellard
277 c227f099 Anthony Liguori
static void iommu_bad_addr(IOMMUState *s, target_phys_addr_t addr,
278 5ad6bb97 blueswir1
                           int is_write)
279 225d4be7 blueswir1
{
280 97bf4851 Blue Swirl
    trace_sun4m_iommu_bad_addr(addr);
281 5ad6bb97 blueswir1
    s->regs[IOMMU_AFSR] = IOMMU_AFSR_ERR | IOMMU_AFSR_LE | IOMMU_AFSR_RESV |
282 225d4be7 blueswir1
        IOMMU_AFSR_FAV;
283 225d4be7 blueswir1
    if (!is_write)
284 225d4be7 blueswir1
        s->regs[IOMMU_AFSR] |= IOMMU_AFSR_RD;
285 225d4be7 blueswir1
    s->regs[IOMMU_AFAR] = addr;
286 ff403da6 blueswir1
    qemu_irq_raise(s->irq);
287 225d4be7 blueswir1
}
288 225d4be7 blueswir1
289 c227f099 Anthony Liguori
void sparc_iommu_memory_rw(void *opaque, target_phys_addr_t addr,
290 67e999be bellard
                           uint8_t *buf, int len, int is_write)
291 a917d384 pbrook
{
292 5dcb6b91 blueswir1
    int l;
293 5dcb6b91 blueswir1
    uint32_t flags;
294 c227f099 Anthony Liguori
    target_phys_addr_t page, phys_addr;
295 a917d384 pbrook
296 a917d384 pbrook
    while (len > 0) {
297 8b0de438 blueswir1
        page = addr & IOMMU_PAGE_MASK;
298 8b0de438 blueswir1
        l = (page + IOMMU_PAGE_SIZE) - addr;
299 a917d384 pbrook
        if (l > len)
300 a917d384 pbrook
            l = len;
301 a917d384 pbrook
        flags = iommu_page_get_flags(opaque, page);
302 225d4be7 blueswir1
        if (!(flags & IOPTE_VALID)) {
303 225d4be7 blueswir1
            iommu_bad_addr(opaque, page, is_write);
304 a917d384 pbrook
            return;
305 225d4be7 blueswir1
        }
306 22548760 blueswir1
        phys_addr = iommu_translate_pa(addr, flags);
307 a917d384 pbrook
        if (is_write) {
308 225d4be7 blueswir1
            if (!(flags & IOPTE_WRITE)) {
309 225d4be7 blueswir1
                iommu_bad_addr(opaque, page, is_write);
310 a917d384 pbrook
                return;
311 225d4be7 blueswir1
            }
312 a5cdf952 blueswir1
            cpu_physical_memory_write(phys_addr, buf, l);
313 a917d384 pbrook
        } else {
314 a5cdf952 blueswir1
            cpu_physical_memory_read(phys_addr, buf, l);
315 a917d384 pbrook
        }
316 a917d384 pbrook
        len -= l;
317 a917d384 pbrook
        buf += l;
318 a917d384 pbrook
        addr += l;
319 a917d384 pbrook
    }
320 a917d384 pbrook
}
321 a917d384 pbrook
322 db3c9e08 Blue Swirl
static const VMStateDescription vmstate_iommu = {
323 db3c9e08 Blue Swirl
    .name ="iommu",
324 db3c9e08 Blue Swirl
    .version_id = 2,
325 db3c9e08 Blue Swirl
    .minimum_version_id = 2,
326 db3c9e08 Blue Swirl
    .minimum_version_id_old = 2,
327 db3c9e08 Blue Swirl
    .fields      = (VMStateField []) {
328 db3c9e08 Blue Swirl
        VMSTATE_UINT32_ARRAY(regs, IOMMUState, IOMMU_NREGS),
329 db3c9e08 Blue Swirl
        VMSTATE_UINT64(iostart, IOMMUState),
330 db3c9e08 Blue Swirl
        VMSTATE_END_OF_LIST()
331 db3c9e08 Blue Swirl
    }
332 db3c9e08 Blue Swirl
};
333 e80cfcfc bellard
334 1a522e8a Blue Swirl
static void iommu_reset(DeviceState *d)
335 e80cfcfc bellard
{
336 1a522e8a Blue Swirl
    IOMMUState *s = container_of(d, IOMMUState, busdev.qdev);
337 e80cfcfc bellard
338 66321a11 bellard
    memset(s->regs, 0, IOMMU_NREGS * 4);
339 e80cfcfc bellard
    s->iostart = 0;
340 7fbfb139 blueswir1
    s->regs[IOMMU_CTRL] = s->version;
341 7fbfb139 blueswir1
    s->regs[IOMMU_ARBEN] = IOMMU_MID;
342 5ad6bb97 blueswir1
    s->regs[IOMMU_AFSR] = IOMMU_AFSR_RESV;
343 7b169687 blueswir1
    s->regs[IOMMU_AER] = IOMMU_AER_EN_P0_ARB | IOMMU_AER_EN_P1_ARB;
344 e5e38121 blueswir1
    s->regs[IOMMU_MASK_ID] = IOMMU_TS_MASK;
345 e80cfcfc bellard
}
346 e80cfcfc bellard
347 81a322d4 Gerd Hoffmann
static int iommu_init1(SysBusDevice *dev)
348 5f750b2e Blue Swirl
{
349 5f750b2e Blue Swirl
    IOMMUState *s = FROM_SYSBUS(IOMMUState, dev);
350 5f750b2e Blue Swirl
    int io;
351 420557e8 bellard
352 5f750b2e Blue Swirl
    sysbus_init_irq(dev, &s->irq);
353 420557e8 bellard
354 5f750b2e Blue Swirl
    io = cpu_register_io_memory(iommu_mem_read, iommu_mem_write, s);
355 5f750b2e Blue Swirl
    sysbus_init_mmio(dev, IOMMU_NREGS * sizeof(uint32_t), io);
356 3b46e624 ths
357 81a322d4 Gerd Hoffmann
    return 0;
358 420557e8 bellard
}
359 5f750b2e Blue Swirl
360 5f750b2e Blue Swirl
static SysBusDeviceInfo iommu_info = {
361 5f750b2e Blue Swirl
    .init = iommu_init1,
362 5f750b2e Blue Swirl
    .qdev.name  = "iommu",
363 5f750b2e Blue Swirl
    .qdev.size  = sizeof(IOMMUState),
364 1a522e8a Blue Swirl
    .qdev.vmsd  = &vmstate_iommu,
365 1a522e8a Blue Swirl
    .qdev.reset = iommu_reset,
366 ee6847d1 Gerd Hoffmann
    .qdev.props = (Property[]) {
367 668724a7 Gerd Hoffmann
        DEFINE_PROP_HEX32("version", IOMMUState, version, 0),
368 668724a7 Gerd Hoffmann
        DEFINE_PROP_END_OF_LIST(),
369 5f750b2e Blue Swirl
    }
370 5f750b2e Blue Swirl
};
371 5f750b2e Blue Swirl
372 5f750b2e Blue Swirl
static void iommu_register_devices(void)
373 5f750b2e Blue Swirl
{
374 5f750b2e Blue Swirl
    sysbus_register_withprop(&iommu_info);
375 5f750b2e Blue Swirl
}
376 5f750b2e Blue Swirl
377 5f750b2e Blue Swirl
device_init(iommu_register_devices)