Statistics
| Branch: | Revision:

root / hw / ide / isa.c @ b072a3c8

History | View | Annotate | Download (3.8 kB)

1 ec82026c Gerd Hoffmann
/*
2 ec82026c Gerd Hoffmann
 * QEMU IDE Emulation: ISA Bus support.
3 ec82026c Gerd Hoffmann
 *
4 ec82026c Gerd Hoffmann
 * Copyright (c) 2003 Fabrice Bellard
5 ec82026c Gerd Hoffmann
 * Copyright (c) 2006 Openedhand Ltd.
6 ec82026c Gerd Hoffmann
 *
7 ec82026c Gerd Hoffmann
 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 ec82026c Gerd Hoffmann
 * of this software and associated documentation files (the "Software"), to deal
9 ec82026c Gerd Hoffmann
 * in the Software without restriction, including without limitation the rights
10 ec82026c Gerd Hoffmann
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 ec82026c Gerd Hoffmann
 * copies of the Software, and to permit persons to whom the Software is
12 ec82026c Gerd Hoffmann
 * furnished to do so, subject to the following conditions:
13 ec82026c Gerd Hoffmann
 *
14 ec82026c Gerd Hoffmann
 * The above copyright notice and this permission notice shall be included in
15 ec82026c Gerd Hoffmann
 * all copies or substantial portions of the Software.
16 ec82026c Gerd Hoffmann
 *
17 ec82026c Gerd Hoffmann
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 ec82026c Gerd Hoffmann
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 ec82026c Gerd Hoffmann
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 ec82026c Gerd Hoffmann
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 ec82026c Gerd Hoffmann
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 ec82026c Gerd Hoffmann
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 ec82026c Gerd Hoffmann
 * THE SOFTWARE.
24 ec82026c Gerd Hoffmann
 */
25 59f2a787 Gerd Hoffmann
#include <hw/hw.h>
26 59f2a787 Gerd Hoffmann
#include <hw/pc.h>
27 dea21e97 Gerd Hoffmann
#include <hw/isa.h>
28 ec82026c Gerd Hoffmann
#include "block.h"
29 ec82026c Gerd Hoffmann
#include "dma.h"
30 59f2a787 Gerd Hoffmann
31 59f2a787 Gerd Hoffmann
#include <hw/ide/internal.h>
32 ec82026c Gerd Hoffmann
33 ec82026c Gerd Hoffmann
/***********************************************************/
34 ec82026c Gerd Hoffmann
/* ISA IDE definitions */
35 ec82026c Gerd Hoffmann
36 cebbe6d4 Gerd Hoffmann
typedef struct ISAIDEState {
37 dea21e97 Gerd Hoffmann
    ISADevice dev;
38 1f850f10 Gerd Hoffmann
    IDEBus    bus;
39 dea21e97 Gerd Hoffmann
    uint32_t  iobase;
40 dea21e97 Gerd Hoffmann
    uint32_t  iobase2;
41 dea21e97 Gerd Hoffmann
    uint32_t  isairq;
42 dea21e97 Gerd Hoffmann
    qemu_irq  irq;
43 cebbe6d4 Gerd Hoffmann
} ISAIDEState;
44 cebbe6d4 Gerd Hoffmann
45 4a643563 Blue Swirl
static void isa_ide_reset(DeviceState *d)
46 4a643563 Blue Swirl
{
47 4a643563 Blue Swirl
    ISAIDEState *s = container_of(d, ISAIDEState, dev.qdev);
48 4a643563 Blue Swirl
49 4a643563 Blue Swirl
    ide_bus_reset(&s->bus);
50 4a643563 Blue Swirl
}
51 4a643563 Blue Swirl
52 200ab5e2 Juan Quintela
static const VMStateDescription vmstate_ide_isa = {
53 200ab5e2 Juan Quintela
    .name = "isa-ide",
54 200ab5e2 Juan Quintela
    .version_id = 3,
55 200ab5e2 Juan Quintela
    .minimum_version_id = 0,
56 200ab5e2 Juan Quintela
    .minimum_version_id_old = 0,
57 200ab5e2 Juan Quintela
    .fields      = (VMStateField []) {
58 200ab5e2 Juan Quintela
        VMSTATE_IDE_BUS(bus, ISAIDEState),
59 200ab5e2 Juan Quintela
        VMSTATE_IDE_DRIVES(bus.ifs, ISAIDEState),
60 200ab5e2 Juan Quintela
        VMSTATE_END_OF_LIST()
61 200ab5e2 Juan Quintela
    }
62 200ab5e2 Juan Quintela
};
63 cebbe6d4 Gerd Hoffmann
64 dea21e97 Gerd Hoffmann
static int isa_ide_initfn(ISADevice *dev)
65 ec82026c Gerd Hoffmann
{
66 dea21e97 Gerd Hoffmann
    ISAIDEState *s = DO_UPCAST(ISAIDEState, dev, dev);
67 dea21e97 Gerd Hoffmann
68 3835510f Gleb Natapov
    ide_bus_new(&s->bus, &s->dev.qdev, 0);
69 4a91d3b3 Richard Henderson
    ide_init_ioport(&s->bus, dev, s->iobase, s->iobase2);
70 dea21e97 Gerd Hoffmann
    isa_init_irq(dev, &s->irq, s->isairq);
71 57234ee4 Markus Armbruster
    ide_init2(&s->bus, s->irq);
72 0be71e32 Alex Williamson
    vmstate_register(&dev->qdev, 0, &vmstate_ide_isa, s);
73 dea21e97 Gerd Hoffmann
    return 0;
74 dea21e97 Gerd Hoffmann
};
75 dea21e97 Gerd Hoffmann
76 48a18b3c Hervé Poussineau
ISADevice *isa_ide_init(ISABus *bus, int iobase, int iobase2, int isairq,
77 57c88866 Markus Armbruster
                        DriveInfo *hd0, DriveInfo *hd1)
78 dea21e97 Gerd Hoffmann
{
79 dea21e97 Gerd Hoffmann
    ISADevice *dev;
80 cebbe6d4 Gerd Hoffmann
    ISAIDEState *s;
81 ec82026c Gerd Hoffmann
82 48a18b3c Hervé Poussineau
    dev = isa_create(bus, "isa-ide");
83 dea21e97 Gerd Hoffmann
    qdev_prop_set_uint32(&dev->qdev, "iobase",  iobase);
84 dea21e97 Gerd Hoffmann
    qdev_prop_set_uint32(&dev->qdev, "iobase2", iobase2);
85 dea21e97 Gerd Hoffmann
    qdev_prop_set_uint32(&dev->qdev, "irq",     isairq);
86 5c17ca25 Markus Armbruster
    if (qdev_init(&dev->qdev) < 0)
87 57c88866 Markus Armbruster
        return NULL;
88 ec82026c Gerd Hoffmann
89 dea21e97 Gerd Hoffmann
    s = DO_UPCAST(ISAIDEState, dev, dev);
90 dea21e97 Gerd Hoffmann
    if (hd0)
91 1f850f10 Gerd Hoffmann
        ide_create_drive(&s->bus, 0, hd0);
92 dea21e97 Gerd Hoffmann
    if (hd1)
93 1f850f10 Gerd Hoffmann
        ide_create_drive(&s->bus, 1, hd1);
94 57c88866 Markus Armbruster
    return dev;
95 dea21e97 Gerd Hoffmann
}
96 dea21e97 Gerd Hoffmann
97 39bffca2 Anthony Liguori
static Property isa_ide_properties[] = {
98 39bffca2 Anthony Liguori
    DEFINE_PROP_HEX32("iobase",  ISAIDEState, iobase,  0x1f0),
99 39bffca2 Anthony Liguori
    DEFINE_PROP_HEX32("iobase2", ISAIDEState, iobase2, 0x3f6),
100 39bffca2 Anthony Liguori
    DEFINE_PROP_UINT32("irq",    ISAIDEState, isairq,  14),
101 39bffca2 Anthony Liguori
    DEFINE_PROP_END_OF_LIST(),
102 39bffca2 Anthony Liguori
};
103 39bffca2 Anthony Liguori
104 8f04ee08 Anthony Liguori
static void isa_ide_class_initfn(ObjectClass *klass, void *data)
105 8f04ee08 Anthony Liguori
{
106 39bffca2 Anthony Liguori
    DeviceClass *dc = DEVICE_CLASS(klass);
107 8f04ee08 Anthony Liguori
    ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
108 8f04ee08 Anthony Liguori
    ic->init = isa_ide_initfn;
109 39bffca2 Anthony Liguori
    dc->fw_name = "ide";
110 39bffca2 Anthony Liguori
    dc->reset = isa_ide_reset;
111 39bffca2 Anthony Liguori
    dc->props = isa_ide_properties;
112 8f04ee08 Anthony Liguori
}
113 8f04ee08 Anthony Liguori
114 39bffca2 Anthony Liguori
static TypeInfo isa_ide_info = {
115 39bffca2 Anthony Liguori
    .name          = "isa-ide",
116 39bffca2 Anthony Liguori
    .parent        = TYPE_ISA_DEVICE,
117 39bffca2 Anthony Liguori
    .instance_size = sizeof(ISAIDEState),
118 39bffca2 Anthony Liguori
    .class_init    = isa_ide_class_initfn,
119 dea21e97 Gerd Hoffmann
};
120 dea21e97 Gerd Hoffmann
121 83f7d43a Andreas Färber
static void isa_ide_register_types(void)
122 dea21e97 Gerd Hoffmann
{
123 39bffca2 Anthony Liguori
    type_register_static(&isa_ide_info);
124 ec82026c Gerd Hoffmann
}
125 dea21e97 Gerd Hoffmann
126 83f7d43a Andreas Färber
type_init(isa_ide_register_types)