blob: 9f80503faae88c61b89ab9d04ab2c88a36117aac [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 */
Gerd Hoffmann59f2a782009-08-20 15:22:26 +020025#include <hw/hw.h>
Paolo Bonzini0d09e412013-02-05 17:06:20 +010026#include <hw/i386/pc.h>
27#include <hw/isa/isa.h>
Markus Armbruster4be74632014-10-07 13:59:18 +020028#include "sysemu/block-backend.h"
Paolo Bonzini9c17d612012-12-17 18:20:04 +010029#include "sysemu/dma.h"
Gerd Hoffmann59f2a782009-08-20 15:22:26 +020030
31#include <hw/ide/internal.h>
Gerd Hoffmannec820262009-08-20 15:22:19 +020032
33/***********************************************************/
34/* ISA IDE definitions */
35
Andreas Färber2f126882013-04-27 22:18:41 +020036#define TYPE_ISA_IDE "isa-ide"
37#define ISA_IDE(obj) OBJECT_CHECK(ISAIDEState, (obj), TYPE_ISA_IDE)
38
Gerd Hoffmanncebbe6d2009-08-20 15:22:24 +020039typedef struct ISAIDEState {
Andreas Färber2f126882013-04-27 22:18:41 +020040 ISADevice parent_obj;
41
Gerd Hoffmann1f850f12009-09-16 22:25:30 +020042 IDEBus bus;
Gerd Hoffmanndea21e92009-09-15 20:05:00 +000043 uint32_t iobase;
44 uint32_t iobase2;
45 uint32_t isairq;
46 qemu_irq irq;
Gerd Hoffmanncebbe6d2009-08-20 15:22:24 +020047} ISAIDEState;
48
Blue Swirl4a643562009-11-07 14:13:05 +000049static void isa_ide_reset(DeviceState *d)
50{
Andreas Färber2f126882013-04-27 22:18:41 +020051 ISAIDEState *s = ISA_IDE(d);
Blue Swirl4a643562009-11-07 14:13:05 +000052
53 ide_bus_reset(&s->bus);
54}
55
Juan Quintela200ab5e2009-10-07 19:01:50 +020056static const VMStateDescription vmstate_ide_isa = {
57 .name = "isa-ide",
58 .version_id = 3,
59 .minimum_version_id = 0,
Juan Quintelad49805a2014-04-16 15:32:32 +020060 .fields = (VMStateField[]) {
Juan Quintela200ab5e2009-10-07 19:01:50 +020061 VMSTATE_IDE_BUS(bus, ISAIDEState),
62 VMSTATE_IDE_DRIVES(bus.ifs, ISAIDEState),
63 VMSTATE_END_OF_LIST()
64 }
65};
Gerd Hoffmanncebbe6d2009-08-20 15:22:24 +020066
Andreas Färberdb895a12012-11-25 02:37:14 +010067static void isa_ide_realizefn(DeviceState *dev, Error **errp)
Gerd Hoffmannec820262009-08-20 15:22:19 +020068{
Andreas Färberdb895a12012-11-25 02:37:14 +010069 ISADevice *isadev = ISA_DEVICE(dev);
Andreas Färber2f126882013-04-27 22:18:41 +020070 ISAIDEState *s = ISA_IDE(dev);
Gerd Hoffmanndea21e92009-09-15 20:05:00 +000071
Andreas Färberc6baf942013-08-23 20:18:50 +020072 ide_bus_new(&s->bus, sizeof(s->bus), dev, 0, 2);
Andreas Färberdb895a12012-11-25 02:37:14 +010073 ide_init_ioport(&s->bus, isadev, s->iobase, s->iobase2);
74 isa_init_irq(isadev, &s->irq, s->isairq);
Markus Armbruster57234ee2010-06-01 20:32:29 +020075 ide_init2(&s->bus, s->irq);
Andreas Färberdb895a12012-11-25 02:37:14 +010076 vmstate_register(dev, 0, &vmstate_ide_isa, s);
Paolo Bonzinid32c76b2015-02-23 11:18:02 -050077 ide_register_restart_cb(&s->bus);
78}
Gerd Hoffmanndea21e92009-09-15 20:05:00 +000079
Hervé Poussineau48a18b32011-12-15 22:09:51 +010080ISADevice *isa_ide_init(ISABus *bus, int iobase, int iobase2, int isairq,
Markus Armbruster57c88862010-06-24 19:59:29 +020081 DriveInfo *hd0, DriveInfo *hd1)
Gerd Hoffmanndea21e92009-09-15 20:05:00 +000082{
Andreas Färber2f126882013-04-27 22:18:41 +020083 DeviceState *dev;
84 ISADevice *isadev;
Gerd Hoffmanncebbe6d2009-08-20 15:22:24 +020085 ISAIDEState *s;
Gerd Hoffmannec820262009-08-20 15:22:19 +020086
Andreas Färber2f126882013-04-27 22:18:41 +020087 isadev = isa_create(bus, TYPE_ISA_IDE);
88 dev = DEVICE(isadev);
89 qdev_prop_set_uint32(dev, "iobase", iobase);
90 qdev_prop_set_uint32(dev, "iobase2", iobase2);
91 qdev_prop_set_uint32(dev, "irq", isairq);
Markus Armbrustere25b89e2015-02-04 18:33:02 +010092 qdev_init_nofail(dev);
Gerd Hoffmannec820262009-08-20 15:22:19 +020093
Andreas Färber2f126882013-04-27 22:18:41 +020094 s = ISA_IDE(dev);
95 if (hd0) {
Gerd Hoffmann1f850f12009-09-16 22:25:30 +020096 ide_create_drive(&s->bus, 0, hd0);
Andreas Färber2f126882013-04-27 22:18:41 +020097 }
98 if (hd1) {
Gerd Hoffmann1f850f12009-09-16 22:25:30 +020099 ide_create_drive(&s->bus, 1, hd1);
Andreas Färber2f126882013-04-27 22:18:41 +0200100 }
101 return isadev;
Gerd Hoffmannec820262009-08-20 15:22:19 +0200102}
Gerd Hoffmanndea21e92009-09-15 20:05:00 +0000103
Anthony Liguori39bffca2011-12-07 21:34:16 -0600104static Property isa_ide_properties[] = {
Paolo Bonzinic7bcc852014-02-08 11:01:53 +0100105 DEFINE_PROP_UINT32("iobase", ISAIDEState, iobase, 0x1f0),
106 DEFINE_PROP_UINT32("iobase2", ISAIDEState, iobase2, 0x3f6),
Anthony Liguori39bffca2011-12-07 21:34:16 -0600107 DEFINE_PROP_UINT32("irq", ISAIDEState, isairq, 14),
108 DEFINE_PROP_END_OF_LIST(),
109};
110
Anthony Liguori8f04ee02011-12-04 11:52:49 -0600111static void isa_ide_class_initfn(ObjectClass *klass, void *data)
112{
Anthony Liguori39bffca2011-12-07 21:34:16 -0600113 DeviceClass *dc = DEVICE_CLASS(klass);
Andreas Färberdb895a12012-11-25 02:37:14 +0100114
115 dc->realize = isa_ide_realizefn;
Anthony Liguori39bffca2011-12-07 21:34:16 -0600116 dc->fw_name = "ide";
117 dc->reset = isa_ide_reset;
118 dc->props = isa_ide_properties;
Marcel Apfelbaum125ee0e2013-07-29 17:17:45 +0300119 set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
Anthony Liguori8f04ee02011-12-04 11:52:49 -0600120}
121
Andreas Färber8c43a6f2013-01-10 16:19:07 +0100122static const TypeInfo isa_ide_info = {
Andreas Färber2f126882013-04-27 22:18:41 +0200123 .name = TYPE_ISA_IDE,
Anthony Liguori39bffca2011-12-07 21:34:16 -0600124 .parent = TYPE_ISA_DEVICE,
125 .instance_size = sizeof(ISAIDEState),
126 .class_init = isa_ide_class_initfn,
Gerd Hoffmanndea21e92009-09-15 20:05:00 +0000127};
128
Andreas Färber83f7d432012-02-09 15:20:55 +0100129static void isa_ide_register_types(void)
Gerd Hoffmanndea21e92009-09-15 20:05:00 +0000130{
Anthony Liguori39bffca2011-12-07 21:34:16 -0600131 type_register_static(&isa_ide_info);
Gerd Hoffmanndea21e92009-09-15 20:05:00 +0000132}
133
Andreas Färber83f7d432012-02-09 15:20:55 +0100134type_init(isa_ide_register_types)