Statistics
| Branch: | Revision:

root / hw / ide / macio.c @ f487b677

History | View | Annotate | Download (9.4 kB)

1 b8842209 Gerd Hoffmann
/*
2 b8842209 Gerd Hoffmann
 * QEMU IDE Emulation: MacIO support.
3 b8842209 Gerd Hoffmann
 *
4 b8842209 Gerd Hoffmann
 * Copyright (c) 2003 Fabrice Bellard
5 b8842209 Gerd Hoffmann
 * Copyright (c) 2006 Openedhand Ltd.
6 b8842209 Gerd Hoffmann
 *
7 b8842209 Gerd Hoffmann
 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 b8842209 Gerd Hoffmann
 * of this software and associated documentation files (the "Software"), to deal
9 b8842209 Gerd Hoffmann
 * in the Software without restriction, including without limitation the rights
10 b8842209 Gerd Hoffmann
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 b8842209 Gerd Hoffmann
 * copies of the Software, and to permit persons to whom the Software is
12 b8842209 Gerd Hoffmann
 * furnished to do so, subject to the following conditions:
13 b8842209 Gerd Hoffmann
 *
14 b8842209 Gerd Hoffmann
 * The above copyright notice and this permission notice shall be included in
15 b8842209 Gerd Hoffmann
 * all copies or substantial portions of the Software.
16 b8842209 Gerd Hoffmann
 *
17 b8842209 Gerd Hoffmann
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 b8842209 Gerd Hoffmann
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 b8842209 Gerd Hoffmann
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 b8842209 Gerd Hoffmann
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 b8842209 Gerd Hoffmann
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 b8842209 Gerd Hoffmann
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 b8842209 Gerd Hoffmann
 * THE SOFTWARE.
24 b8842209 Gerd Hoffmann
 */
25 baec1910 Andreas Färber
#include "hw/hw.h"
26 baec1910 Andreas Färber
#include "hw/ppc/mac.h"
27 0d09e41a Paolo Bonzini
#include "hw/ppc/mac_dbdma.h"
28 737e150e Paolo Bonzini
#include "block/block.h"
29 9c17d615 Paolo Bonzini
#include "sysemu/dma.h"
30 59f2a787 Gerd Hoffmann
31 59f2a787 Gerd Hoffmann
#include <hw/ide/internal.h>
32 b8842209 Gerd Hoffmann
33 b8842209 Gerd Hoffmann
/***********************************************************/
34 b8842209 Gerd Hoffmann
/* MacIO based PowerPC IDE */
35 b8842209 Gerd Hoffmann
36 02c7c992 Blue Swirl
#define MACIO_PAGE_SIZE 4096
37 02c7c992 Blue Swirl
38 b8842209 Gerd Hoffmann
static void pmac_ide_atapi_transfer_cb(void *opaque, int ret)
39 b8842209 Gerd Hoffmann
{
40 b8842209 Gerd Hoffmann
    DBDMA_io *io = opaque;
41 b8842209 Gerd Hoffmann
    MACIOIDEState *m = io->opaque;
42 b8842209 Gerd Hoffmann
    IDEState *s = idebus_active_if(&m->bus);
43 b8842209 Gerd Hoffmann
44 b8842209 Gerd Hoffmann
    if (ret < 0) {
45 b8842209 Gerd Hoffmann
        m->aiocb = NULL;
46 b8842209 Gerd Hoffmann
        qemu_sglist_destroy(&s->sg);
47 b8842209 Gerd Hoffmann
        ide_atapi_io_error(s, ret);
48 a597e79c Christoph Hellwig
        goto done;
49 b8842209 Gerd Hoffmann
    }
50 b8842209 Gerd Hoffmann
51 b8842209 Gerd Hoffmann
    if (s->io_buffer_size > 0) {
52 b8842209 Gerd Hoffmann
        m->aiocb = NULL;
53 b8842209 Gerd Hoffmann
        qemu_sglist_destroy(&s->sg);
54 b8842209 Gerd Hoffmann
55 b8842209 Gerd Hoffmann
        s->packet_transfer_size -= s->io_buffer_size;
56 b8842209 Gerd Hoffmann
57 b8842209 Gerd Hoffmann
        s->io_buffer_index += s->io_buffer_size;
58 b8842209 Gerd Hoffmann
        s->lba += s->io_buffer_index >> 11;
59 b8842209 Gerd Hoffmann
        s->io_buffer_index &= 0x7ff;
60 b8842209 Gerd Hoffmann
    }
61 b8842209 Gerd Hoffmann
62 b8842209 Gerd Hoffmann
    if (s->packet_transfer_size <= 0)
63 b8842209 Gerd Hoffmann
        ide_atapi_cmd_ok(s);
64 b8842209 Gerd Hoffmann
65 b8842209 Gerd Hoffmann
    if (io->len == 0) {
66 a597e79c Christoph Hellwig
        goto done;
67 b8842209 Gerd Hoffmann
    }
68 b8842209 Gerd Hoffmann
69 b8842209 Gerd Hoffmann
    /* launch next transfer */
70 b8842209 Gerd Hoffmann
71 b8842209 Gerd Hoffmann
    s->io_buffer_size = io->len;
72 b8842209 Gerd Hoffmann
73 f487b677 Paolo Bonzini
    qemu_sglist_init(&s->sg, DEVICE(m), io->len / MACIO_PAGE_SIZE + 1,
74 df32fd1c Paolo Bonzini
                     &address_space_memory);
75 b8842209 Gerd Hoffmann
    qemu_sglist_add(&s->sg, io->addr, io->len);
76 b8842209 Gerd Hoffmann
    io->addr += io->len;
77 b8842209 Gerd Hoffmann
    io->len = 0;
78 b8842209 Gerd Hoffmann
79 b8842209 Gerd Hoffmann
    m->aiocb = dma_bdrv_read(s->bs, &s->sg,
80 b8842209 Gerd Hoffmann
                             (int64_t)(s->lba << 2) + (s->io_buffer_index >> 9),
81 b8842209 Gerd Hoffmann
                             pmac_ide_atapi_transfer_cb, io);
82 a597e79c Christoph Hellwig
    return;
83 a597e79c Christoph Hellwig
84 a597e79c Christoph Hellwig
done:
85 a597e79c Christoph Hellwig
    bdrv_acct_done(s->bs, &s->acct);
86 a597e79c Christoph Hellwig
    io->dma_end(opaque);
87 b8842209 Gerd Hoffmann
}
88 b8842209 Gerd Hoffmann
89 b8842209 Gerd Hoffmann
static void pmac_ide_transfer_cb(void *opaque, int ret)
90 b8842209 Gerd Hoffmann
{
91 b8842209 Gerd Hoffmann
    DBDMA_io *io = opaque;
92 b8842209 Gerd Hoffmann
    MACIOIDEState *m = io->opaque;
93 b8842209 Gerd Hoffmann
    IDEState *s = idebus_active_if(&m->bus);
94 b8842209 Gerd Hoffmann
    int n;
95 b8842209 Gerd Hoffmann
    int64_t sector_num;
96 b8842209 Gerd Hoffmann
97 b8842209 Gerd Hoffmann
    if (ret < 0) {
98 b8842209 Gerd Hoffmann
        m->aiocb = NULL;
99 b8842209 Gerd Hoffmann
        qemu_sglist_destroy(&s->sg);
100 b8842209 Gerd Hoffmann
        ide_dma_error(s);
101 a597e79c Christoph Hellwig
        goto done;
102 b8842209 Gerd Hoffmann
    }
103 b8842209 Gerd Hoffmann
104 b8842209 Gerd Hoffmann
    sector_num = ide_get_sector(s);
105 b8842209 Gerd Hoffmann
    if (s->io_buffer_size > 0) {
106 b8842209 Gerd Hoffmann
        m->aiocb = NULL;
107 b8842209 Gerd Hoffmann
        qemu_sglist_destroy(&s->sg);
108 b8842209 Gerd Hoffmann
        n = (s->io_buffer_size + 0x1ff) >> 9;
109 b8842209 Gerd Hoffmann
        sector_num += n;
110 b8842209 Gerd Hoffmann
        ide_set_sector(s, sector_num);
111 b8842209 Gerd Hoffmann
        s->nsector -= n;
112 b8842209 Gerd Hoffmann
    }
113 b8842209 Gerd Hoffmann
114 b8842209 Gerd Hoffmann
    /* end of transfer ? */
115 b8842209 Gerd Hoffmann
    if (s->nsector == 0) {
116 b8842209 Gerd Hoffmann
        s->status = READY_STAT | SEEK_STAT;
117 9cdd03a7 Gerd Hoffmann
        ide_set_irq(s->bus);
118 b8842209 Gerd Hoffmann
    }
119 b8842209 Gerd Hoffmann
120 b8842209 Gerd Hoffmann
    /* end of DMA ? */
121 b8842209 Gerd Hoffmann
    if (io->len == 0) {
122 a597e79c Christoph Hellwig
        goto done;
123 b8842209 Gerd Hoffmann
    }
124 b8842209 Gerd Hoffmann
125 b8842209 Gerd Hoffmann
    /* launch next transfer */
126 b8842209 Gerd Hoffmann
127 b8842209 Gerd Hoffmann
    s->io_buffer_index = 0;
128 b8842209 Gerd Hoffmann
    s->io_buffer_size = io->len;
129 b8842209 Gerd Hoffmann
130 f487b677 Paolo Bonzini
    qemu_sglist_init(&s->sg, DEVICE(m), io->len / MACIO_PAGE_SIZE + 1,
131 df32fd1c Paolo Bonzini
                     &address_space_memory);
132 b8842209 Gerd Hoffmann
    qemu_sglist_add(&s->sg, io->addr, io->len);
133 b8842209 Gerd Hoffmann
    io->addr += io->len;
134 b8842209 Gerd Hoffmann
    io->len = 0;
135 b8842209 Gerd Hoffmann
136 4e1e0051 Christoph Hellwig
    switch (s->dma_cmd) {
137 4e1e0051 Christoph Hellwig
    case IDE_DMA_READ:
138 b8842209 Gerd Hoffmann
        m->aiocb = dma_bdrv_read(s->bs, &s->sg, sector_num,
139 b8842209 Gerd Hoffmann
                                 pmac_ide_transfer_cb, io);
140 4e1e0051 Christoph Hellwig
        break;
141 4e1e0051 Christoph Hellwig
    case IDE_DMA_WRITE:
142 b8842209 Gerd Hoffmann
        m->aiocb = dma_bdrv_write(s->bs, &s->sg, sector_num,
143 b8842209 Gerd Hoffmann
                                  pmac_ide_transfer_cb, io);
144 4e1e0051 Christoph Hellwig
        break;
145 d353fb72 Christoph Hellwig
    case IDE_DMA_TRIM:
146 d353fb72 Christoph Hellwig
        m->aiocb = dma_bdrv_io(s->bs, &s->sg, sector_num,
147 b9b5df6f Aurelien Jarno
                               ide_issue_trim, pmac_ide_transfer_cb, io,
148 43cf8ae6 David Gibson
                               DMA_DIRECTION_TO_DEVICE);
149 d353fb72 Christoph Hellwig
        break;
150 4e1e0051 Christoph Hellwig
    }
151 a597e79c Christoph Hellwig
    return;
152 b9b2008b Paolo Bonzini
153 a597e79c Christoph Hellwig
done:
154 a597e79c Christoph Hellwig
    if (s->dma_cmd == IDE_DMA_READ || s->dma_cmd == IDE_DMA_WRITE) {
155 a597e79c Christoph Hellwig
        bdrv_acct_done(s->bs, &s->acct);
156 a597e79c Christoph Hellwig
    }
157 a597e79c Christoph Hellwig
    io->dma_end(io);
158 b8842209 Gerd Hoffmann
}
159 b8842209 Gerd Hoffmann
160 b8842209 Gerd Hoffmann
static void pmac_ide_transfer(DBDMA_io *io)
161 b8842209 Gerd Hoffmann
{
162 b8842209 Gerd Hoffmann
    MACIOIDEState *m = io->opaque;
163 b8842209 Gerd Hoffmann
    IDEState *s = idebus_active_if(&m->bus);
164 b8842209 Gerd Hoffmann
165 b8842209 Gerd Hoffmann
    s->io_buffer_size = 0;
166 cd8722bb Markus Armbruster
    if (s->drive_kind == IDE_CD) {
167 a597e79c Christoph Hellwig
        bdrv_acct_start(s->bs, &s->acct, io->len, BDRV_ACCT_READ);
168 b8842209 Gerd Hoffmann
        pmac_ide_atapi_transfer_cb(io, 0);
169 b8842209 Gerd Hoffmann
        return;
170 b8842209 Gerd Hoffmann
    }
171 b8842209 Gerd Hoffmann
172 a597e79c Christoph Hellwig
    switch (s->dma_cmd) {
173 a597e79c Christoph Hellwig
    case IDE_DMA_READ:
174 a597e79c Christoph Hellwig
        bdrv_acct_start(s->bs, &s->acct, io->len, BDRV_ACCT_READ);
175 a597e79c Christoph Hellwig
        break;
176 a597e79c Christoph Hellwig
    case IDE_DMA_WRITE:
177 a597e79c Christoph Hellwig
        bdrv_acct_start(s->bs, &s->acct, io->len, BDRV_ACCT_WRITE);
178 a597e79c Christoph Hellwig
        break;
179 a597e79c Christoph Hellwig
    default:
180 a597e79c Christoph Hellwig
        break;
181 a597e79c Christoph Hellwig
    }
182 a597e79c Christoph Hellwig
183 b8842209 Gerd Hoffmann
    pmac_ide_transfer_cb(io, 0);
184 b8842209 Gerd Hoffmann
}
185 b8842209 Gerd Hoffmann
186 b8842209 Gerd Hoffmann
static void pmac_ide_flush(DBDMA_io *io)
187 b8842209 Gerd Hoffmann
{
188 b8842209 Gerd Hoffmann
    MACIOIDEState *m = io->opaque;
189 b8842209 Gerd Hoffmann
190 922453bc Stefan Hajnoczi
    if (m->aiocb) {
191 922453bc Stefan Hajnoczi
        bdrv_drain_all();
192 922453bc Stefan Hajnoczi
    }
193 b8842209 Gerd Hoffmann
}
194 b8842209 Gerd Hoffmann
195 b8842209 Gerd Hoffmann
/* PowerMac IDE memory IO */
196 b8842209 Gerd Hoffmann
static void pmac_ide_writeb (void *opaque,
197 a8170e5e Avi Kivity
                             hwaddr addr, uint32_t val)
198 b8842209 Gerd Hoffmann
{
199 b8842209 Gerd Hoffmann
    MACIOIDEState *d = opaque;
200 b8842209 Gerd Hoffmann
201 b8842209 Gerd Hoffmann
    addr = (addr & 0xFFF) >> 4;
202 b8842209 Gerd Hoffmann
    switch (addr) {
203 b8842209 Gerd Hoffmann
    case 1 ... 7:
204 b8842209 Gerd Hoffmann
        ide_ioport_write(&d->bus, addr, val);
205 b8842209 Gerd Hoffmann
        break;
206 b8842209 Gerd Hoffmann
    case 8:
207 b8842209 Gerd Hoffmann
    case 22:
208 b8842209 Gerd Hoffmann
        ide_cmd_write(&d->bus, 0, val);
209 b8842209 Gerd Hoffmann
        break;
210 b8842209 Gerd Hoffmann
    default:
211 b8842209 Gerd Hoffmann
        break;
212 b8842209 Gerd Hoffmann
    }
213 b8842209 Gerd Hoffmann
}
214 b8842209 Gerd Hoffmann
215 a8170e5e Avi Kivity
static uint32_t pmac_ide_readb (void *opaque,hwaddr addr)
216 b8842209 Gerd Hoffmann
{
217 b8842209 Gerd Hoffmann
    uint8_t retval;
218 b8842209 Gerd Hoffmann
    MACIOIDEState *d = opaque;
219 b8842209 Gerd Hoffmann
220 b8842209 Gerd Hoffmann
    addr = (addr & 0xFFF) >> 4;
221 b8842209 Gerd Hoffmann
    switch (addr) {
222 b8842209 Gerd Hoffmann
    case 1 ... 7:
223 b8842209 Gerd Hoffmann
        retval = ide_ioport_read(&d->bus, addr);
224 b8842209 Gerd Hoffmann
        break;
225 b8842209 Gerd Hoffmann
    case 8:
226 b8842209 Gerd Hoffmann
    case 22:
227 b8842209 Gerd Hoffmann
        retval = ide_status_read(&d->bus, 0);
228 b8842209 Gerd Hoffmann
        break;
229 b8842209 Gerd Hoffmann
    default:
230 b8842209 Gerd Hoffmann
        retval = 0xFF;
231 b8842209 Gerd Hoffmann
        break;
232 b8842209 Gerd Hoffmann
    }
233 b8842209 Gerd Hoffmann
    return retval;
234 b8842209 Gerd Hoffmann
}
235 b8842209 Gerd Hoffmann
236 b8842209 Gerd Hoffmann
static void pmac_ide_writew (void *opaque,
237 a8170e5e Avi Kivity
                             hwaddr addr, uint32_t val)
238 b8842209 Gerd Hoffmann
{
239 b8842209 Gerd Hoffmann
    MACIOIDEState *d = opaque;
240 b8842209 Gerd Hoffmann
241 b8842209 Gerd Hoffmann
    addr = (addr & 0xFFF) >> 4;
242 b8842209 Gerd Hoffmann
    val = bswap16(val);
243 b8842209 Gerd Hoffmann
    if (addr == 0) {
244 b8842209 Gerd Hoffmann
        ide_data_writew(&d->bus, 0, val);
245 b8842209 Gerd Hoffmann
    }
246 b8842209 Gerd Hoffmann
}
247 b8842209 Gerd Hoffmann
248 a8170e5e Avi Kivity
static uint32_t pmac_ide_readw (void *opaque,hwaddr addr)
249 b8842209 Gerd Hoffmann
{
250 b8842209 Gerd Hoffmann
    uint16_t retval;
251 b8842209 Gerd Hoffmann
    MACIOIDEState *d = opaque;
252 b8842209 Gerd Hoffmann
253 b8842209 Gerd Hoffmann
    addr = (addr & 0xFFF) >> 4;
254 b8842209 Gerd Hoffmann
    if (addr == 0) {
255 b8842209 Gerd Hoffmann
        retval = ide_data_readw(&d->bus, 0);
256 b8842209 Gerd Hoffmann
    } else {
257 b8842209 Gerd Hoffmann
        retval = 0xFFFF;
258 b8842209 Gerd Hoffmann
    }
259 b8842209 Gerd Hoffmann
    retval = bswap16(retval);
260 b8842209 Gerd Hoffmann
    return retval;
261 b8842209 Gerd Hoffmann
}
262 b8842209 Gerd Hoffmann
263 b8842209 Gerd Hoffmann
static void pmac_ide_writel (void *opaque,
264 a8170e5e Avi Kivity
                             hwaddr addr, uint32_t val)
265 b8842209 Gerd Hoffmann
{
266 b8842209 Gerd Hoffmann
    MACIOIDEState *d = opaque;
267 b8842209 Gerd Hoffmann
268 b8842209 Gerd Hoffmann
    addr = (addr & 0xFFF) >> 4;
269 b8842209 Gerd Hoffmann
    val = bswap32(val);
270 b8842209 Gerd Hoffmann
    if (addr == 0) {
271 b8842209 Gerd Hoffmann
        ide_data_writel(&d->bus, 0, val);
272 b8842209 Gerd Hoffmann
    }
273 b8842209 Gerd Hoffmann
}
274 b8842209 Gerd Hoffmann
275 a8170e5e Avi Kivity
static uint32_t pmac_ide_readl (void *opaque,hwaddr addr)
276 b8842209 Gerd Hoffmann
{
277 b8842209 Gerd Hoffmann
    uint32_t retval;
278 b8842209 Gerd Hoffmann
    MACIOIDEState *d = opaque;
279 b8842209 Gerd Hoffmann
280 b8842209 Gerd Hoffmann
    addr = (addr & 0xFFF) >> 4;
281 b8842209 Gerd Hoffmann
    if (addr == 0) {
282 b8842209 Gerd Hoffmann
        retval = ide_data_readl(&d->bus, 0);
283 b8842209 Gerd Hoffmann
    } else {
284 b8842209 Gerd Hoffmann
        retval = 0xFFFFFFFF;
285 b8842209 Gerd Hoffmann
    }
286 b8842209 Gerd Hoffmann
    retval = bswap32(retval);
287 b8842209 Gerd Hoffmann
    return retval;
288 b8842209 Gerd Hoffmann
}
289 b8842209 Gerd Hoffmann
290 a348f108 Stefan Weil
static const MemoryRegionOps pmac_ide_ops = {
291 23c5e4ca Avi Kivity
    .old_mmio = {
292 23c5e4ca Avi Kivity
        .write = {
293 23c5e4ca Avi Kivity
            pmac_ide_writeb,
294 23c5e4ca Avi Kivity
            pmac_ide_writew,
295 23c5e4ca Avi Kivity
            pmac_ide_writel,
296 23c5e4ca Avi Kivity
        },
297 23c5e4ca Avi Kivity
        .read = {
298 23c5e4ca Avi Kivity
            pmac_ide_readb,
299 23c5e4ca Avi Kivity
            pmac_ide_readw,
300 23c5e4ca Avi Kivity
            pmac_ide_readl,
301 23c5e4ca Avi Kivity
        },
302 23c5e4ca Avi Kivity
    },
303 23c5e4ca Avi Kivity
    .endianness = DEVICE_NATIVE_ENDIAN,
304 b8842209 Gerd Hoffmann
};
305 b8842209 Gerd Hoffmann
306 44bfa332 Juan Quintela
static const VMStateDescription vmstate_pmac = {
307 44bfa332 Juan Quintela
    .name = "ide",
308 44bfa332 Juan Quintela
    .version_id = 3,
309 44bfa332 Juan Quintela
    .minimum_version_id = 0,
310 44bfa332 Juan Quintela
    .minimum_version_id_old = 0,
311 44bfa332 Juan Quintela
    .fields      = (VMStateField []) {
312 44bfa332 Juan Quintela
        VMSTATE_IDE_BUS(bus, MACIOIDEState),
313 44bfa332 Juan Quintela
        VMSTATE_IDE_DRIVES(bus.ifs, MACIOIDEState),
314 44bfa332 Juan Quintela
        VMSTATE_END_OF_LIST()
315 b8842209 Gerd Hoffmann
    }
316 44bfa332 Juan Quintela
};
317 b8842209 Gerd Hoffmann
318 07a7484e Andreas Färber
static void macio_ide_reset(DeviceState *dev)
319 b8842209 Gerd Hoffmann
{
320 07a7484e Andreas Färber
    MACIOIDEState *d = MACIO_IDE(dev);
321 b8842209 Gerd Hoffmann
322 4a643563 Blue Swirl
    ide_bus_reset(&d->bus);
323 b8842209 Gerd Hoffmann
}
324 b8842209 Gerd Hoffmann
325 07a7484e Andreas Färber
static void macio_ide_realizefn(DeviceState *dev, Error **errp)
326 b8842209 Gerd Hoffmann
{
327 07a7484e Andreas Färber
    MACIOIDEState *s = MACIO_IDE(dev);
328 07a7484e Andreas Färber
329 07a7484e Andreas Färber
    ide_init2(&s->bus, s->irq);
330 07a7484e Andreas Färber
}
331 07a7484e Andreas Färber
332 07a7484e Andreas Färber
static void macio_ide_initfn(Object *obj)
333 07a7484e Andreas Färber
{
334 07a7484e Andreas Färber
    SysBusDevice *d = SYS_BUS_DEVICE(obj);
335 07a7484e Andreas Färber
    MACIOIDEState *s = MACIO_IDE(obj);
336 07a7484e Andreas Färber
337 0ee20e66 Kevin Wolf
    ide_bus_new(&s->bus, DEVICE(obj), 0, 2);
338 07a7484e Andreas Färber
    memory_region_init_io(&s->mem, &pmac_ide_ops, s, "pmac-ide", 0x1000);
339 07a7484e Andreas Färber
    sysbus_init_mmio(d, &s->mem);
340 07a7484e Andreas Färber
    sysbus_init_irq(d, &s->irq);
341 07a7484e Andreas Färber
    sysbus_init_irq(d, &s->dma_irq);
342 07a7484e Andreas Färber
}
343 07a7484e Andreas Färber
344 07a7484e Andreas Färber
static void macio_ide_class_init(ObjectClass *oc, void *data)
345 07a7484e Andreas Färber
{
346 07a7484e Andreas Färber
    DeviceClass *dc = DEVICE_CLASS(oc);
347 07a7484e Andreas Färber
348 07a7484e Andreas Färber
    dc->realize = macio_ide_realizefn;
349 07a7484e Andreas Färber
    dc->reset = macio_ide_reset;
350 07a7484e Andreas Färber
    dc->vmsd = &vmstate_pmac;
351 07a7484e Andreas Färber
}
352 b8842209 Gerd Hoffmann
353 07a7484e Andreas Färber
static const TypeInfo macio_ide_type_info = {
354 07a7484e Andreas Färber
    .name = TYPE_MACIO_IDE,
355 07a7484e Andreas Färber
    .parent = TYPE_SYS_BUS_DEVICE,
356 07a7484e Andreas Färber
    .instance_size = sizeof(MACIOIDEState),
357 07a7484e Andreas Färber
    .instance_init = macio_ide_initfn,
358 07a7484e Andreas Färber
    .class_init = macio_ide_class_init,
359 07a7484e Andreas Färber
};
360 b8842209 Gerd Hoffmann
361 07a7484e Andreas Färber
static void macio_ide_register_types(void)
362 07a7484e Andreas Färber
{
363 07a7484e Andreas Färber
    type_register_static(&macio_ide_type_info);
364 07a7484e Andreas Färber
}
365 b8842209 Gerd Hoffmann
366 07a7484e Andreas Färber
/* hd_table must contain 4 block drivers */
367 07a7484e Andreas Färber
void macio_ide_init_drives(MACIOIDEState *s, DriveInfo **hd_table)
368 07a7484e Andreas Färber
{
369 07a7484e Andreas Färber
    int i;
370 b8842209 Gerd Hoffmann
371 07a7484e Andreas Färber
    for (i = 0; i < 2; i++) {
372 07a7484e Andreas Färber
        if (hd_table[i]) {
373 07a7484e Andreas Färber
            ide_create_drive(&s->bus, i, hd_table[i]);
374 07a7484e Andreas Färber
        }
375 07a7484e Andreas Färber
    }
376 b8842209 Gerd Hoffmann
}
377 07a7484e Andreas Färber
378 07a7484e Andreas Färber
void macio_ide_register_dma(MACIOIDEState *s, void *dbdma, int channel)
379 07a7484e Andreas Färber
{
380 07a7484e Andreas Färber
    DBDMA_register_channel(dbdma, channel, s->dma_irq,
381 07a7484e Andreas Färber
                           pmac_ide_transfer, pmac_ide_flush, s);
382 07a7484e Andreas Färber
}
383 07a7484e Andreas Färber
384 07a7484e Andreas Färber
type_init(macio_ide_register_types)