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 */
250b8fa32fSMarkus Armbruster
2653239262SPeter Maydell #include "qemu/osdep.h"
27a9c94277SMarkus Armbruster #include "hw/isa/isa.h"
28a27bd6c7SMarkus Armbruster #include "hw/qdev-properties.h"
29d6454270SMarkus Armbruster #include "migration/vmstate.h"
3096927c74SMarkus Armbruster #include "qapi/error.h"
310b8fa32fSMarkus Armbruster #include "qemu/module.h"
3232cad1ffSPhilippe Mathieu-Daudé #include "system/dma.h"
3359f2a787SGerd Hoffmann
34794093e8SPhilippe Mathieu-Daudé #include "hw/ide/isa.h"
35db1015e9SEduardo Habkost #include "qom/object.h"
360316482eSPhilippe Mathieu-Daudé #include "ide-internal.h"
37ec82026cSGerd Hoffmann
38ec82026cSGerd Hoffmann /***********************************************************/
39ec82026cSGerd Hoffmann /* ISA IDE definitions */
40ec82026cSGerd Hoffmann
41db1015e9SEduardo Habkost struct ISAIDEState {
422f12688bSAndreas Färber ISADevice parent_obj;
432f12688bSAndreas Färber
441f850f10SGerd Hoffmann IDEBus bus;
45dea21e97SGerd Hoffmann uint32_t iobase;
46dea21e97SGerd Hoffmann uint32_t iobase2;
47794093e8SPhilippe Mathieu-Daudé uint32_t irqnum;
48db1015e9SEduardo Habkost };
49cebbe6d4SGerd Hoffmann
isa_ide_reset(DeviceState * d)504a643563SBlue Swirl static void isa_ide_reset(DeviceState *d)
514a643563SBlue Swirl {
522f12688bSAndreas Färber ISAIDEState *s = ISA_IDE(d);
534a643563SBlue Swirl
544a643563SBlue Swirl ide_bus_reset(&s->bus);
554a643563SBlue Swirl }
564a643563SBlue Swirl
57200ab5e2SJuan Quintela static const VMStateDescription vmstate_ide_isa = {
58200ab5e2SJuan Quintela .name = "isa-ide",
59200ab5e2SJuan Quintela .version_id = 3,
60200ab5e2SJuan Quintela .minimum_version_id = 0,
618595c054SRichard Henderson .fields = (const VMStateField[]) {
62200ab5e2SJuan Quintela VMSTATE_IDE_BUS(bus, ISAIDEState),
63200ab5e2SJuan Quintela VMSTATE_IDE_DRIVES(bus.ifs, ISAIDEState),
64200ab5e2SJuan Quintela VMSTATE_END_OF_LIST()
65cebbe6d4SGerd Hoffmann }
66200ab5e2SJuan Quintela };
67cebbe6d4SGerd Hoffmann
isa_ide_realizefn(DeviceState * dev,Error ** errp)68db895a1eSAndreas Färber static void isa_ide_realizefn(DeviceState *dev, Error **errp)
69dea21e97SGerd Hoffmann {
70db895a1eSAndreas Färber ISADevice *isadev = ISA_DEVICE(dev);
712f12688bSAndreas Färber ISAIDEState *s = ISA_IDE(dev);
72dea21e97SGerd Hoffmann
7382c74ac4SPeter Maydell ide_bus_init(&s->bus, sizeof(s->bus), dev, 0, 2);
74db895a1eSAndreas Färber ide_init_ioport(&s->bus, isadev, s->iobase, s->iobase2);
75c9519630SPhilippe Mathieu-Daudé ide_bus_init_output_irq(&s->bus, isa_get_irq(isadev, s->irqnum));
761f52c7a8SJuan Quintela vmstate_register_any(VMSTATE_IF(dev), &vmstate_ide_isa, s);
77e29b1246SPhilippe Mathieu-Daudé ide_bus_register_restart_cb(&s->bus);
78d32c76b3SPaolo Bonzini }
79dea21e97SGerd Hoffmann
isa_ide_init(ISABus * bus,int iobase,int iobase2,int irqnum,DriveInfo * hd0,DriveInfo * hd1)80794093e8SPhilippe Mathieu-Daudé ISADevice *isa_ide_init(ISABus *bus, int iobase, int iobase2, int irqnum,
81f455e98cSGerd Hoffmann DriveInfo *hd0, DriveInfo *hd1)
82ec82026cSGerd Hoffmann {
832f12688bSAndreas Färber DeviceState *dev;
842f12688bSAndreas Färber ISADevice *isadev;
85cebbe6d4SGerd Hoffmann ISAIDEState *s;
86ec82026cSGerd Hoffmann
8796927c74SMarkus Armbruster isadev = isa_new(TYPE_ISA_IDE);
882f12688bSAndreas Färber dev = DEVICE(isadev);
892f12688bSAndreas Färber qdev_prop_set_uint32(dev, "iobase", iobase);
902f12688bSAndreas Färber qdev_prop_set_uint32(dev, "iobase2", iobase2);
91794093e8SPhilippe Mathieu-Daudé qdev_prop_set_uint32(dev, "irq", irqnum);
9296927c74SMarkus Armbruster isa_realize_and_unref(isadev, bus, &error_fatal);
93ec82026cSGerd Hoffmann
942f12688bSAndreas Färber s = ISA_IDE(dev);
952f12688bSAndreas Färber if (hd0) {
96b6a5ab27SPhilippe Mathieu-Daudé ide_bus_create_drive(&s->bus, 0, hd0);
972f12688bSAndreas Färber }
982f12688bSAndreas Färber if (hd1) {
99b6a5ab27SPhilippe Mathieu-Daudé ide_bus_create_drive(&s->bus, 1, hd1);
1002f12688bSAndreas Färber }
1012f12688bSAndreas Färber return isadev;
102ec82026cSGerd Hoffmann }
103dea21e97SGerd Hoffmann
104aaa1f1a5SRichard Henderson static const Property isa_ide_properties[] = {
105c7bcc85dSPaolo Bonzini DEFINE_PROP_UINT32("iobase", ISAIDEState, iobase, 0x1f0),
106c7bcc85dSPaolo Bonzini DEFINE_PROP_UINT32("iobase2", ISAIDEState, iobase2, 0x3f6),
107794093e8SPhilippe Mathieu-Daudé DEFINE_PROP_UINT32("irq", ISAIDEState, irqnum, 14),
10839bffca2SAnthony Liguori };
10939bffca2SAnthony Liguori
isa_ide_class_initfn(ObjectClass * klass,const void * data)110*12d1a768SPhilippe Mathieu-Daudé static void isa_ide_class_initfn(ObjectClass *klass, const void *data)
11139bffca2SAnthony Liguori {
11239bffca2SAnthony Liguori DeviceClass *dc = DEVICE_CLASS(klass);
113db895a1eSAndreas Färber
114db895a1eSAndreas Färber dc->realize = isa_ide_realizefn;
11539bffca2SAnthony Liguori dc->fw_name = "ide";
116e3d08143SPeter Maydell device_class_set_legacy_reset(dc, isa_ide_reset);
1174f67d30bSMarc-André Lureau device_class_set_props(dc, isa_ide_properties);
118125ee0edSMarcel Apfelbaum set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
11939bffca2SAnthony Liguori }
12039bffca2SAnthony Liguori
1218c43a6f0SAndreas Färber static const TypeInfo isa_ide_info = {
1222f12688bSAndreas Färber .name = TYPE_ISA_IDE,
12339bffca2SAnthony Liguori .parent = TYPE_ISA_DEVICE,
12439bffca2SAnthony Liguori .instance_size = sizeof(ISAIDEState),
12539bffca2SAnthony Liguori .class_init = isa_ide_class_initfn,
126dea21e97SGerd Hoffmann };
127dea21e97SGerd Hoffmann
isa_ide_register_types(void)12883f7d43aSAndreas Färber static void isa_ide_register_types(void)
129dea21e97SGerd Hoffmann {
13039bffca2SAnthony Liguori type_register_static(&isa_ide_info);
131dea21e97SGerd Hoffmann }
132dea21e97SGerd Hoffmann
13383f7d43aSAndreas Färber type_init(isa_ide_register_types)
134