xref: /qemu/hw/ide/isa.c (revision 8c43a6f05d5ef3c9484bd2be9d4e818d58e62016)
1ec82026cSGerd Hoffmann /*
2ec82026cSGerd Hoffmann  * QEMU IDE Emulation: ISA Bus support.
3ec82026cSGerd Hoffmann  *
4ec82026cSGerd Hoffmann  * Copyright (c) 2003 Fabrice Bellard
5ec82026cSGerd Hoffmann  * Copyright (c) 2006 Openedhand Ltd.
6ec82026cSGerd Hoffmann  *
7ec82026cSGerd Hoffmann  * Permission is hereby granted, free of charge, to any person obtaining a copy
8ec82026cSGerd Hoffmann  * of this software and associated documentation files (the "Software"), to deal
9ec82026cSGerd Hoffmann  * in the Software without restriction, including without limitation the rights
10ec82026cSGerd Hoffmann  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11ec82026cSGerd Hoffmann  * copies of the Software, and to permit persons to whom the Software is
12ec82026cSGerd Hoffmann  * furnished to do so, subject to the following conditions:
13ec82026cSGerd Hoffmann  *
14ec82026cSGerd Hoffmann  * The above copyright notice and this permission notice shall be included in
15ec82026cSGerd Hoffmann  * all copies or substantial portions of the Software.
16ec82026cSGerd Hoffmann  *
17ec82026cSGerd Hoffmann  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18ec82026cSGerd Hoffmann  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19ec82026cSGerd Hoffmann  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20ec82026cSGerd Hoffmann  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21ec82026cSGerd Hoffmann  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22ec82026cSGerd Hoffmann  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23ec82026cSGerd Hoffmann  * THE SOFTWARE.
24ec82026cSGerd Hoffmann  */
2559f2a787SGerd Hoffmann #include <hw/hw.h>
2659f2a787SGerd Hoffmann #include <hw/pc.h>
27dea21e97SGerd Hoffmann #include <hw/isa.h>
28737e150eSPaolo Bonzini #include "block/block.h"
299c17d615SPaolo Bonzini #include "sysemu/dma.h"
3059f2a787SGerd Hoffmann 
3159f2a787SGerd Hoffmann #include <hw/ide/internal.h>
32ec82026cSGerd Hoffmann 
33ec82026cSGerd Hoffmann /***********************************************************/
34ec82026cSGerd Hoffmann /* ISA IDE definitions */
35ec82026cSGerd Hoffmann 
36cebbe6d4SGerd Hoffmann typedef struct ISAIDEState {
37dea21e97SGerd Hoffmann     ISADevice dev;
381f850f10SGerd Hoffmann     IDEBus    bus;
39dea21e97SGerd Hoffmann     uint32_t  iobase;
40dea21e97SGerd Hoffmann     uint32_t  iobase2;
41dea21e97SGerd Hoffmann     uint32_t  isairq;
42dea21e97SGerd Hoffmann     qemu_irq  irq;
43cebbe6d4SGerd Hoffmann } ISAIDEState;
44cebbe6d4SGerd Hoffmann 
454a643563SBlue Swirl static void isa_ide_reset(DeviceState *d)
464a643563SBlue Swirl {
474a643563SBlue Swirl     ISAIDEState *s = container_of(d, ISAIDEState, dev.qdev);
484a643563SBlue Swirl 
494a643563SBlue Swirl     ide_bus_reset(&s->bus);
504a643563SBlue Swirl }
514a643563SBlue Swirl 
52200ab5e2SJuan Quintela static const VMStateDescription vmstate_ide_isa = {
53200ab5e2SJuan Quintela     .name = "isa-ide",
54200ab5e2SJuan Quintela     .version_id = 3,
55200ab5e2SJuan Quintela     .minimum_version_id = 0,
56200ab5e2SJuan Quintela     .minimum_version_id_old = 0,
57200ab5e2SJuan Quintela     .fields      = (VMStateField []) {
58200ab5e2SJuan Quintela         VMSTATE_IDE_BUS(bus, ISAIDEState),
59200ab5e2SJuan Quintela         VMSTATE_IDE_DRIVES(bus.ifs, ISAIDEState),
60200ab5e2SJuan Quintela         VMSTATE_END_OF_LIST()
61cebbe6d4SGerd Hoffmann     }
62200ab5e2SJuan Quintela };
63cebbe6d4SGerd Hoffmann 
64dea21e97SGerd Hoffmann static int isa_ide_initfn(ISADevice *dev)
65dea21e97SGerd Hoffmann {
66dea21e97SGerd Hoffmann     ISAIDEState *s = DO_UPCAST(ISAIDEState, dev, dev);
67dea21e97SGerd Hoffmann 
683835510fSGleb Natapov     ide_bus_new(&s->bus, &s->dev.qdev, 0);
694a91d3b3SRichard Henderson     ide_init_ioport(&s->bus, dev, s->iobase, s->iobase2);
70dea21e97SGerd Hoffmann     isa_init_irq(dev, &s->irq, s->isairq);
7157234ee4SMarkus Armbruster     ide_init2(&s->bus, s->irq);
720be71e32SAlex Williamson     vmstate_register(&dev->qdev, 0, &vmstate_ide_isa, s);
73dea21e97SGerd Hoffmann     return 0;
74dea21e97SGerd Hoffmann };
75dea21e97SGerd Hoffmann 
7648a18b3cSHervé Poussineau ISADevice *isa_ide_init(ISABus *bus, int iobase, int iobase2, int isairq,
77f455e98cSGerd Hoffmann                         DriveInfo *hd0, DriveInfo *hd1)
78ec82026cSGerd Hoffmann {
79dea21e97SGerd Hoffmann     ISADevice *dev;
80cebbe6d4SGerd Hoffmann     ISAIDEState *s;
81ec82026cSGerd Hoffmann 
8248a18b3cSHervé Poussineau     dev = isa_create(bus, "isa-ide");
83dea21e97SGerd Hoffmann     qdev_prop_set_uint32(&dev->qdev, "iobase",  iobase);
84dea21e97SGerd Hoffmann     qdev_prop_set_uint32(&dev->qdev, "iobase2", iobase2);
85dea21e97SGerd Hoffmann     qdev_prop_set_uint32(&dev->qdev, "irq",     isairq);
865c17ca25SMarkus Armbruster     if (qdev_init(&dev->qdev) < 0)
8757c88866SMarkus Armbruster         return NULL;
88ec82026cSGerd Hoffmann 
89dea21e97SGerd Hoffmann     s = DO_UPCAST(ISAIDEState, dev, dev);
90dea21e97SGerd Hoffmann     if (hd0)
911f850f10SGerd Hoffmann         ide_create_drive(&s->bus, 0, hd0);
92dea21e97SGerd Hoffmann     if (hd1)
931f850f10SGerd Hoffmann         ide_create_drive(&s->bus, 1, hd1);
9457c88866SMarkus Armbruster     return dev;
95ec82026cSGerd Hoffmann }
96dea21e97SGerd Hoffmann 
9739bffca2SAnthony Liguori static Property isa_ide_properties[] = {
98dea21e97SGerd Hoffmann     DEFINE_PROP_HEX32("iobase",  ISAIDEState, iobase,  0x1f0),
99dea21e97SGerd Hoffmann     DEFINE_PROP_HEX32("iobase2", ISAIDEState, iobase2, 0x3f6),
100dea21e97SGerd Hoffmann     DEFINE_PROP_UINT32("irq",    ISAIDEState, isairq,  14),
101dea21e97SGerd Hoffmann     DEFINE_PROP_END_OF_LIST(),
10239bffca2SAnthony Liguori };
10339bffca2SAnthony Liguori 
10439bffca2SAnthony Liguori static void isa_ide_class_initfn(ObjectClass *klass, void *data)
10539bffca2SAnthony Liguori {
10639bffca2SAnthony Liguori     DeviceClass *dc = DEVICE_CLASS(klass);
10739bffca2SAnthony Liguori     ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
10839bffca2SAnthony Liguori     ic->init = isa_ide_initfn;
10939bffca2SAnthony Liguori     dc->fw_name = "ide";
11039bffca2SAnthony Liguori     dc->reset = isa_ide_reset;
11139bffca2SAnthony Liguori     dc->props = isa_ide_properties;
11239bffca2SAnthony Liguori }
11339bffca2SAnthony Liguori 
114*8c43a6f0SAndreas Färber static const TypeInfo isa_ide_info = {
11539bffca2SAnthony Liguori     .name          = "isa-ide",
11639bffca2SAnthony Liguori     .parent        = TYPE_ISA_DEVICE,
11739bffca2SAnthony Liguori     .instance_size = sizeof(ISAIDEState),
11839bffca2SAnthony Liguori     .class_init    = isa_ide_class_initfn,
119dea21e97SGerd Hoffmann };
120dea21e97SGerd Hoffmann 
12183f7d43aSAndreas Färber static void isa_ide_register_types(void)
122dea21e97SGerd Hoffmann {
12339bffca2SAnthony Liguori     type_register_static(&isa_ide_info);
124dea21e97SGerd Hoffmann }
125dea21e97SGerd Hoffmann 
12683f7d43aSAndreas Färber type_init(isa_ide_register_types)
127