blob: 211ebc9ba756b878c463dc91391519275865fec8 [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 */
Markus Armbruster0b8fa322019-05-23 16:35:07 +020025
Peter Maydell53239262016-01-26 18:17:09 +000026#include "qemu/osdep.h"
Markus Armbrustera9c94272016-06-22 19:11:19 +020027#include "hw/isa/isa.h"
Markus Armbrustera27bd6c2019-08-12 07:23:51 +020028#include "hw/qdev-properties.h"
Markus Armbrusterd6454272019-08-12 07:23:45 +020029#include "migration/vmstate.h"
Markus Armbruster96927c72020-06-10 07:32:08 +020030#include "qapi/error.h"
Markus Armbruster0b8fa322019-05-23 16:35:07 +020031#include "qemu/module.h"
Paolo Bonzini9c17d612012-12-17 18:20:04 +010032#include "sysemu/dma.h"
Gerd Hoffmann59f2a782009-08-20 15:22:26 +020033
Philippe Mathieu-Daudé794093e2023-02-09 23:26:36 +010034#include "hw/ide/isa.h"
Eduardo Habkostdb1015e2020-09-03 16:43:22 -040035#include "qom/object.h"
Philippe Mathieu-Daudé03164822024-02-25 18:08:39 +010036#include "ide-internal.h"
Gerd Hoffmannec820262009-08-20 15:22:19 +020037
38/***********************************************************/
39/* ISA IDE definitions */
40
Eduardo Habkostdb1015e2020-09-03 16:43:22 -040041struct ISAIDEState {
Andreas Färber2f126882013-04-27 22:18:41 +020042 ISADevice parent_obj;
43
Gerd Hoffmann1f850f12009-09-16 22:25:30 +020044 IDEBus bus;
Gerd Hoffmanndea21e92009-09-15 20:05:00 +000045 uint32_t iobase;
46 uint32_t iobase2;
Philippe Mathieu-Daudé794093e2023-02-09 23:26:36 +010047 uint32_t irqnum;
Eduardo Habkostdb1015e2020-09-03 16:43:22 -040048};
Gerd Hoffmanncebbe6d2009-08-20 15:22:24 +020049
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,
Richard Henderson8595c052023-12-21 14:16:13 +110061 .fields = (const 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
Peter Maydell82c74ac2021-09-23 13:11:53 +010073 ide_bus_init(&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);
Philippe Mathieu-Daudéc9519632023-02-09 11:27:23 +010075 ide_bus_init_output_irq(&s->bus, isa_get_irq(isadev, s->irqnum));
Juan Quintela1f52c7a2023-10-20 11:07:21 +020076 vmstate_register_any(VMSTATE_IF(dev), &vmstate_ide_isa, s);
Philippe Mathieu-Daudée29b1242023-02-14 16:33:38 +010077 ide_bus_register_restart_cb(&s->bus);
Paolo Bonzinid32c76b2015-02-23 11:18:02 -050078}
Gerd Hoffmanndea21e92009-09-15 20:05:00 +000079
Philippe Mathieu-Daudé794093e2023-02-09 23:26:36 +010080ISADevice *isa_ide_init(ISABus *bus, int iobase, int iobase2, int irqnum,
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
Markus Armbruster96927c72020-06-10 07:32:08 +020087 isadev = isa_new(TYPE_ISA_IDE);
Andreas Färber2f126882013-04-27 22:18:41 +020088 dev = DEVICE(isadev);
89 qdev_prop_set_uint32(dev, "iobase", iobase);
90 qdev_prop_set_uint32(dev, "iobase2", iobase2);
Philippe Mathieu-Daudé794093e2023-02-09 23:26:36 +010091 qdev_prop_set_uint32(dev, "irq", irqnum);
Markus Armbruster96927c72020-06-10 07:32:08 +020092 isa_realize_and_unref(isadev, bus, &error_fatal);
Gerd Hoffmannec820262009-08-20 15:22:19 +020093
Andreas Färber2f126882013-04-27 22:18:41 +020094 s = ISA_IDE(dev);
95 if (hd0) {
Philippe Mathieu-Daudéb6a5ab22023-02-09 11:31:51 +010096 ide_bus_create_drive(&s->bus, 0, hd0);
Andreas Färber2f126882013-04-27 22:18:41 +020097 }
98 if (hd1) {
Philippe Mathieu-Daudéb6a5ab22023-02-09 11:31:51 +010099 ide_bus_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),
Philippe Mathieu-Daudé794093e2023-02-09 23:26:36 +0100107 DEFINE_PROP_UINT32("irq", ISAIDEState, irqnum, 14),
Anthony Liguori39bffca2011-12-07 21:34:16 -0600108 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";
Peter Maydelle3d08142024-09-13 15:31:44 +0100117 device_class_set_legacy_reset(dc, isa_ide_reset);
Marc-André Lureau4f67d302020-01-10 19:30:32 +0400118 device_class_set_props(dc, 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)