blob: eba567c8772b8842e08dbf4e0865afc06e7c0c0d [file] [log] [blame]
Gerd Hoffmannec820262009-08-20 15:22:19 +02001/*
2 * QEMU IDE Emulation: ISA Bus support.
3 *
4 * Copyright (c) 2003 Fabrice Bellard
5 * Copyright (c) 2006 Openedhand Ltd.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
24 */
Peter Maydell53239262016-01-26 18:17:09 +000025#include "qemu/osdep.h"
Gerd Hoffmann59f2a782009-08-20 15:22:26 +020026#include <hw/hw.h>
Paolo Bonzini0d09e412013-02-05 17:06:20 +010027#include <hw/i386/pc.h>
28#include <hw/isa/isa.h>
Markus Armbruster4be74632014-10-07 13:59:18 +020029#include "sysemu/block-backend.h"
Paolo Bonzini9c17d612012-12-17 18:20:04 +010030#include "sysemu/dma.h"
Gerd Hoffmann59f2a782009-08-20 15:22:26 +020031
32#include <hw/ide/internal.h>
Gerd Hoffmannec820262009-08-20 15:22:19 +020033
34/***********************************************************/
35/* ISA IDE definitions */
36
Andreas Färber2f126882013-04-27 22:18:41 +020037#define TYPE_ISA_IDE "isa-ide"
38#define ISA_IDE(obj) OBJECT_CHECK(ISAIDEState, (obj), TYPE_ISA_IDE)
39
Gerd Hoffmanncebbe6d2009-08-20 15:22:24 +020040typedef struct ISAIDEState {
Andreas Färber2f126882013-04-27 22:18:41 +020041 ISADevice parent_obj;
42
Gerd Hoffmann1f850f12009-09-16 22:25:30 +020043 IDEBus bus;
Gerd Hoffmanndea21e92009-09-15 20:05:00 +000044 uint32_t iobase;
45 uint32_t iobase2;
46 uint32_t isairq;
47 qemu_irq irq;
Gerd Hoffmanncebbe6d2009-08-20 15:22:24 +020048} ISAIDEState;
49
Blue Swirl4a643562009-11-07 14:13:05 +000050static void isa_ide_reset(DeviceState *d)
51{
Andreas Färber2f126882013-04-27 22:18:41 +020052 ISAIDEState *s = ISA_IDE(d);
Blue Swirl4a643562009-11-07 14:13:05 +000053
54 ide_bus_reset(&s->bus);
55}
56
Juan Quintela200ab5e2009-10-07 19:01:50 +020057static const VMStateDescription vmstate_ide_isa = {
58 .name = "isa-ide",
59 .version_id = 3,
60 .minimum_version_id = 0,
Juan Quintelad49805a2014-04-16 15:32:32 +020061 .fields = (VMStateField[]) {
Juan Quintela200ab5e2009-10-07 19:01:50 +020062 VMSTATE_IDE_BUS(bus, ISAIDEState),
63 VMSTATE_IDE_DRIVES(bus.ifs, ISAIDEState),
64 VMSTATE_END_OF_LIST()
65 }
66};
Gerd Hoffmanncebbe6d2009-08-20 15:22:24 +020067
Andreas Färberdb895a12012-11-25 02:37:14 +010068static void isa_ide_realizefn(DeviceState *dev, Error **errp)
Gerd Hoffmannec820262009-08-20 15:22:19 +020069{
Andreas Färberdb895a12012-11-25 02:37:14 +010070 ISADevice *isadev = ISA_DEVICE(dev);
Andreas Färber2f126882013-04-27 22:18:41 +020071 ISAIDEState *s = ISA_IDE(dev);
Gerd Hoffmanndea21e92009-09-15 20:05:00 +000072
Andreas Färberc6baf942013-08-23 20:18:50 +020073 ide_bus_new(&s->bus, sizeof(s->bus), dev, 0, 2);
Andreas Färberdb895a12012-11-25 02:37:14 +010074 ide_init_ioport(&s->bus, isadev, s->iobase, s->iobase2);
75 isa_init_irq(isadev, &s->irq, s->isairq);
Markus Armbruster57234ee2010-06-01 20:32:29 +020076 ide_init2(&s->bus, s->irq);
Andreas Färberdb895a12012-11-25 02:37:14 +010077 vmstate_register(dev, 0, &vmstate_ide_isa, s);
Paolo Bonzinid32c76b2015-02-23 11:18:02 -050078 ide_register_restart_cb(&s->bus);
79}
Gerd Hoffmanndea21e92009-09-15 20:05:00 +000080
Hervé Poussineau48a18b32011-12-15 22:09:51 +010081ISADevice *isa_ide_init(ISABus *bus, int iobase, int iobase2, int isairq,
Markus Armbruster57c88862010-06-24 19:59:29 +020082 DriveInfo *hd0, DriveInfo *hd1)
Gerd Hoffmanndea21e92009-09-15 20:05:00 +000083{
Andreas Färber2f126882013-04-27 22:18:41 +020084 DeviceState *dev;
85 ISADevice *isadev;
Gerd Hoffmanncebbe6d2009-08-20 15:22:24 +020086 ISAIDEState *s;
Gerd Hoffmannec820262009-08-20 15:22:19 +020087
Andreas Färber2f126882013-04-27 22:18:41 +020088 isadev = isa_create(bus, TYPE_ISA_IDE);
89 dev = DEVICE(isadev);
90 qdev_prop_set_uint32(dev, "iobase", iobase);
91 qdev_prop_set_uint32(dev, "iobase2", iobase2);
92 qdev_prop_set_uint32(dev, "irq", isairq);
Markus Armbrustere25b89e2015-02-04 18:33:02 +010093 qdev_init_nofail(dev);
Gerd Hoffmannec820262009-08-20 15:22:19 +020094
Andreas Färber2f126882013-04-27 22:18:41 +020095 s = ISA_IDE(dev);
96 if (hd0) {
Gerd Hoffmann1f850f12009-09-16 22:25:30 +020097 ide_create_drive(&s->bus, 0, hd0);
Andreas Färber2f126882013-04-27 22:18:41 +020098 }
99 if (hd1) {
Gerd Hoffmann1f850f12009-09-16 22:25:30 +0200100 ide_create_drive(&s->bus, 1, hd1);
Andreas Färber2f126882013-04-27 22:18:41 +0200101 }
102 return isadev;
Gerd Hoffmannec820262009-08-20 15:22:19 +0200103}
Gerd Hoffmanndea21e92009-09-15 20:05:00 +0000104
Anthony Liguori39bffca2011-12-07 21:34:16 -0600105static Property isa_ide_properties[] = {
Paolo Bonzinic7bcc852014-02-08 11:01:53 +0100106 DEFINE_PROP_UINT32("iobase", ISAIDEState, iobase, 0x1f0),
107 DEFINE_PROP_UINT32("iobase2", ISAIDEState, iobase2, 0x3f6),
Anthony Liguori39bffca2011-12-07 21:34:16 -0600108 DEFINE_PROP_UINT32("irq", ISAIDEState, isairq, 14),
109 DEFINE_PROP_END_OF_LIST(),
110};
111
Anthony Liguori8f04ee02011-12-04 11:52:49 -0600112static void isa_ide_class_initfn(ObjectClass *klass, void *data)
113{
Anthony Liguori39bffca2011-12-07 21:34:16 -0600114 DeviceClass *dc = DEVICE_CLASS(klass);
Andreas Färberdb895a12012-11-25 02:37:14 +0100115
116 dc->realize = isa_ide_realizefn;
Anthony Liguori39bffca2011-12-07 21:34:16 -0600117 dc->fw_name = "ide";
118 dc->reset = isa_ide_reset;
119 dc->props = isa_ide_properties;
Marcel Apfelbaum125ee0e2013-07-29 17:17:45 +0300120 set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
Anthony Liguori8f04ee02011-12-04 11:52:49 -0600121}
122
Andreas Färber8c43a6f2013-01-10 16:19:07 +0100123static const TypeInfo isa_ide_info = {
Andreas Färber2f126882013-04-27 22:18:41 +0200124 .name = TYPE_ISA_IDE,
Anthony Liguori39bffca2011-12-07 21:34:16 -0600125 .parent = TYPE_ISA_DEVICE,
126 .instance_size = sizeof(ISAIDEState),
127 .class_init = isa_ide_class_initfn,
Gerd Hoffmanndea21e92009-09-15 20:05:00 +0000128};
129
Andreas Färber83f7d432012-02-09 15:20:55 +0100130static void isa_ide_register_types(void)
Gerd Hoffmanndea21e92009-09-15 20:05:00 +0000131{
Anthony Liguori39bffca2011-12-07 21:34:16 -0600132 type_register_static(&isa_ide_info);
Gerd Hoffmanndea21e92009-09-15 20:05:00 +0000133}
134
Andreas Färber83f7d432012-02-09 15:20:55 +0100135type_init(isa_ide_register_types)