blob: 9d8502785d290bcd13fb103dc8d4b8d144e54ee2 [file] [log] [blame]
Gerd Hoffmannda4d0412009-09-15 19:23:34 +00001/*
2 * ide bus support for qdev.
3 *
4 * Copyright (c) 2009 Gerd Hoffmann <kraxel@redhat.com>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 */
Markus Armbruster0b8fa322019-05-23 16:35:07 +020019
Peter Maydell53239262016-01-26 18:17:09 +000020#include "qemu/osdep.h"
Markus Armbrustera9c94272016-06-22 19:11:19 +020021#include "hw/hw.h"
Paolo Bonzini9c17d612012-12-17 18:20:04 +010022#include "sysemu/dma.h"
Markus Armbrusterda34e652016-03-14 09:01:28 +010023#include "qapi/error.h"
Paolo Bonzini1de7afc2012-12-17 18:20:00 +010024#include "qemu/error-report.h"
Markus Armbruster0b8fa322019-05-23 16:35:07 +020025#include "qemu/module.h"
Markus Armbrustera9c94272016-06-22 19:11:19 +020026#include "hw/ide/internal.h"
Markus Armbrusterfa1d36d2014-10-07 13:59:13 +020027#include "sysemu/block-backend.h"
Paolo Bonzini9c17d612012-12-17 18:20:04 +010028#include "sysemu/blockdev.h"
Paolo Bonzini0d09e412013-02-05 17:06:20 +010029#include "hw/block/block.h"
Paolo Bonzini9c17d612012-12-17 18:20:04 +010030#include "sysemu/sysemu.h"
Gonglei45563632014-10-07 16:00:29 +080031#include "qapi/visitor.h"
Gerd Hoffmannda4d0412009-09-15 19:23:34 +000032
33/* --------------------------------- */
34
Gleb Natapovdc1a46b2010-12-08 13:34:59 +020035static char *idebus_get_fw_dev_path(DeviceState *dev);
Li Qiang44a109c2017-03-15 20:50:14 -040036static void idebus_unrealize(BusState *qdev, Error **errp);
Gleb Natapovdc1a46b2010-12-08 13:34:59 +020037
Paolo Bonzini3cb75a72012-03-28 18:01:36 +020038static Property ide_props[] = {
39 DEFINE_PROP_UINT32("unit", IDEDevice, unit, -1),
40 DEFINE_PROP_END_OF_LIST(),
41};
42
Anthony Liguori0d936922012-05-02 09:00:20 +020043static void ide_bus_class_init(ObjectClass *klass, void *data)
44{
45 BusClass *k = BUS_CLASS(klass);
46
47 k->get_fw_dev_path = idebus_get_fw_dev_path;
Li Qiang44a109c2017-03-15 20:50:14 -040048 k->unrealize = idebus_unrealize;
Anthony Liguori0d936922012-05-02 09:00:20 +020049}
50
Li Qiang44a109c2017-03-15 20:50:14 -040051static void idebus_unrealize(BusState *bus, Error **errp)
Ashijeet Acharyaca441412016-09-27 22:23:32 +053052{
Li Qiang44a109c2017-03-15 20:50:14 -040053 IDEBus *ibus = IDE_BUS(bus);
Ashijeet Acharyaca441412016-09-27 22:23:32 +053054
Li Qiang44a109c2017-03-15 20:50:14 -040055 if (ibus->vmstate) {
56 qemu_del_vm_change_state_handler(ibus->vmstate);
Ashijeet Acharyaca441412016-09-27 22:23:32 +053057 }
58}
59
Anthony Liguori0d936922012-05-02 09:00:20 +020060static const TypeInfo ide_bus_info = {
61 .name = TYPE_IDE_BUS,
62 .parent = TYPE_BUS,
63 .instance_size = sizeof(IDEBus),
64 .class_init = ide_bus_class_init,
Gerd Hoffmannda4d0412009-09-15 19:23:34 +000065};
66
Andreas Färberc6baf942013-08-23 20:18:50 +020067void ide_bus_new(IDEBus *idebus, size_t idebus_size, DeviceState *dev,
68 int bus_id, int max_units)
Gerd Hoffmannda4d0412009-09-15 19:23:34 +000069{
Andreas Färberfb17dfe2013-08-24 00:02:27 +020070 qbus_create_inplace(idebus, idebus_size, TYPE_IDE_BUS, dev, NULL);
Gleb Natapov38355102010-12-08 13:34:58 +020071 idebus->bus_id = bus_id;
Kevin Wolf0ee20e62013-05-06 15:58:04 +020072 idebus->max_units = max_units;
Gerd Hoffmannda4d0412009-09-15 19:23:34 +000073}
74
Gleb Natapovdc1a46b2010-12-08 13:34:59 +020075static char *idebus_get_fw_dev_path(DeviceState *dev)
76{
77 char path[30];
78
Markus Armbruster28fa7132014-08-15 13:32:37 +020079 snprintf(path, sizeof(path), "%s@%x", qdev_fw_name(dev),
Gleb Natapovdc1a46b2010-12-08 13:34:59 +020080 ((IDEBus*)dev->parent_bus)->bus_id);
81
Jim Meyeringa5cf8262012-10-04 13:09:44 +020082 return g_strdup(path);
Gleb Natapovdc1a46b2010-12-08 13:34:59 +020083}
84
Mao Zhongyi794939e2017-09-18 22:05:13 +080085static void ide_qdev_realize(DeviceState *qdev, Error **errp)
Gerd Hoffmannda4d0412009-09-15 19:23:34 +000086{
Anthony Liguorid1482112011-12-16 13:41:12 -060087 IDEDevice *dev = IDE_DEVICE(qdev);
88 IDEDeviceClass *dc = IDE_DEVICE_GET_CLASS(dev);
Gerd Hoffmannda4d0412009-09-15 19:23:34 +000089 IDEBus *bus = DO_UPCAST(IDEBus, qbus, qdev->parent_bus);
90
Gerd Hoffmannda4d0412009-09-15 19:23:34 +000091 if (dev->unit == -1) {
92 dev->unit = bus->master ? 1 : 0;
93 }
Kevin Wolf0ee20e62013-05-06 15:58:04 +020094
95 if (dev->unit >= bus->max_units) {
Mao Zhongyi794939e2017-09-18 22:05:13 +080096 error_setg(errp, "Can't create IDE unit %d, bus supports only %d units",
Kevin Wolf0ee20e62013-05-06 15:58:04 +020097 dev->unit, bus->max_units);
Mao Zhongyi794939e2017-09-18 22:05:13 +080098 return;
Kevin Wolf0ee20e62013-05-06 15:58:04 +020099 }
100
Gerd Hoffmannda4d0412009-09-15 19:23:34 +0000101 switch (dev->unit) {
102 case 0:
103 if (bus->master) {
Mao Zhongyi794939e2017-09-18 22:05:13 +0800104 error_setg(errp, "IDE unit %d is in use", dev->unit);
105 return;
Gerd Hoffmannda4d0412009-09-15 19:23:34 +0000106 }
107 bus->master = dev;
108 break;
109 case 1:
110 if (bus->slave) {
Mao Zhongyi794939e2017-09-18 22:05:13 +0800111 error_setg(errp, "IDE unit %d is in use", dev->unit);
112 return;
Gerd Hoffmannda4d0412009-09-15 19:23:34 +0000113 }
114 bus->slave = dev;
115 break;
116 default:
Mao Zhongyi794939e2017-09-18 22:05:13 +0800117 error_setg(errp, "Invalid IDE unit %d", dev->unit);
118 return;
Gerd Hoffmannda4d0412009-09-15 19:23:34 +0000119 }
Mao Zhongyi794939e2017-09-18 22:05:13 +0800120 dc->realize(dev, errp);
Gerd Hoffmannda4d0412009-09-15 19:23:34 +0000121}
122
Gerd Hoffmannda4d0412009-09-15 19:23:34 +0000123IDEDevice *ide_create_drive(IDEBus *bus, int unit, DriveInfo *drive)
124{
125 DeviceState *dev;
126
Markus Armbruster95b5edc2011-05-16 15:04:56 +0200127 dev = qdev_create(&bus->qbus, drive->media_cd ? "ide-cd" : "ide-hd");
Gerd Hoffmannda4d0412009-09-15 19:23:34 +0000128 qdev_prop_set_uint32(dev, "unit", unit);
Markus Armbruster6231a6d2015-12-10 17:29:15 +0100129 qdev_prop_set_drive(dev, "drive", blk_by_legacy_dinfo(drive),
130 &error_fatal);
Markus Armbrusterfa12fbb2010-06-25 18:53:22 +0200131 qdev_init_nofail(dev);
Gerd Hoffmannda4d0412009-09-15 19:23:34 +0000132 return DO_UPCAST(IDEDevice, qdev, dev);
133}
134
Markus Armbruster91390462012-07-10 11:12:38 +0200135int ide_get_geometry(BusState *bus, int unit,
136 int16_t *cyls, int8_t *heads, int8_t *secs)
Markus Armbrusterc0897e02010-06-24 19:58:20 +0200137{
Markus Armbruster91390462012-07-10 11:12:38 +0200138 IDEState *s = &DO_UPCAST(IDEBus, qbus, bus)->ifs[unit];
139
Markus Armbruster4be74632014-10-07 13:59:18 +0200140 if (s->drive_kind != IDE_HD || !s->blk) {
Markus Armbruster91390462012-07-10 11:12:38 +0200141 return -1;
142 }
143
144 *cyls = s->cylinders;
145 *heads = s->heads;
146 *secs = s->sectors;
147 return 0;
148}
149
150int ide_get_bios_chs_trans(BusState *bus, int unit)
151{
152 return DO_UPCAST(IDEBus, qbus, bus)->ifs[unit].chs_trans;
Markus Armbrusterc0897e02010-06-24 19:58:20 +0200153}
154
Gerd Hoffmannda4d0412009-09-15 19:23:34 +0000155/* --------------------------------- */
156
157typedef struct IDEDrive {
158 IDEDevice dev;
159} IDEDrive;
160
Mao Zhongyi794939e2017-09-18 22:05:13 +0800161static void ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind, Error **errp)
Gerd Hoffmannda4d0412009-09-15 19:23:34 +0000162{
163 IDEBus *bus = DO_UPCAST(IDEBus, qbus, dev->qdev.parent_bus);
Markus Armbruster6ced55a2010-06-01 20:32:32 +0200164 IDEState *s = bus->ifs + dev->unit;
Kevin Wolf947231a2017-07-11 14:04:08 +0200165 int ret;
Markus Armbruster6ced55a2010-06-01 20:32:32 +0200166
Kevin Wolf67c75f32016-07-14 15:49:42 +0200167 if (!dev->conf.blk) {
168 if (kind != IDE_CD) {
Mao Zhongyi794939e2017-09-18 22:05:13 +0800169 error_setg(errp, "No drive specified");
170 return;
Kevin Wolf67c75f32016-07-14 15:49:42 +0200171 } else {
172 /* Anonymous BlockBackend for an empty drive */
Kevin Wolfd861ab32019-04-25 14:25:10 +0200173 dev->conf.blk = blk_new(qemu_get_aio_context(), 0, BLK_PERM_ALL);
Kevin Wolf947231a2017-07-11 14:04:08 +0200174 ret = blk_attach_dev(dev->conf.blk, &dev->qdev);
175 assert(ret == 0);
Kevin Wolf67c75f32016-07-14 15:49:42 +0200176 }
177 }
178
Paolo Bonzini215e47b2013-02-08 14:06:14 +0100179 if (dev->conf.discard_granularity == -1) {
180 dev->conf.discard_granularity = 512;
181 } else if (dev->conf.discard_granularity &&
182 dev->conf.discard_granularity != 512) {
Mao Zhongyi794939e2017-09-18 22:05:13 +0800183 error_setg(errp, "discard_granularity must be 512 for ide");
184 return;
Christoph Hellwigd353fb72011-05-19 10:58:19 +0200185 }
186
Ekaterina Tumanova0eb28a42015-02-16 12:47:58 +0100187 blkconf_blocksizes(&dev->conf);
Kevin Wolfd2005182014-12-03 13:21:32 +0100188 if (dev->conf.logical_block_size != 512) {
Mao Zhongyi794939e2017-09-18 22:05:13 +0800189 error_setg(errp, "logical_block_size must be 512 for IDE");
190 return;
Kevin Wolfd2005182014-12-03 13:21:32 +0100191 }
192
Fam Zheng5ff5efb2014-08-12 10:12:54 +0800193 if (kind != IDE_CD) {
Mao Zhongyiceff3e12017-11-22 11:08:45 +0800194 if (!blkconf_geometry(&dev->conf, &dev->chs_trans, 65535, 16, 255,
195 errp)) {
Mao Zhongyi794939e2017-09-18 22:05:13 +0800196 return;
Fam Zheng5ff5efb2014-08-12 10:12:54 +0800197 }
Markus Armbrusterba801962012-07-10 11:12:44 +0200198 }
Mao Zhongyiceff3e12017-11-22 11:08:45 +0800199 if (!blkconf_apply_backend_options(&dev->conf, kind == IDE_CD,
200 kind != IDE_CD, errp)) {
Mao Zhongyi794939e2017-09-18 22:05:13 +0800201 return;
Kevin Wolfa17c17a2017-01-24 13:43:31 +0100202 }
Markus Armbrusterba801962012-07-10 11:12:44 +0200203
Markus Armbruster4be74632014-10-07 13:59:18 +0200204 if (ide_init_drive(s, dev->conf.blk, kind,
Markus Armbruster911525d2012-07-11 15:08:37 +0200205 dev->version, dev->serial, dev->model, dev->wwn,
Markus Armbrusterba801962012-07-10 11:12:44 +0200206 dev->conf.cyls, dev->conf.heads, dev->conf.secs,
Mao Zhongyi794939e2017-09-18 22:05:13 +0800207 dev->chs_trans, errp) < 0) {
208 return;
Markus Armbrusterc4d74df2010-06-28 19:07:51 +0200209 }
Markus Armbruster6ced55a2010-06-01 20:32:32 +0200210
Markus Armbruster03432402010-06-01 20:32:33 +0200211 if (!dev->version) {
Anthony Liguori7267c092011-08-20 22:09:37 -0500212 dev->version = g_strdup(s->version);
Markus Armbruster03432402010-06-01 20:32:33 +0200213 }
Markus Armbruster6ced55a2010-06-01 20:32:32 +0200214 if (!dev->serial) {
Anthony Liguori7267c092011-08-20 22:09:37 -0500215 dev->serial = g_strdup(s->drive_serial_str);
Markus Armbruster6ced55a2010-06-01 20:32:32 +0200216 }
Gleb Natapov1ca4d092010-12-08 13:35:05 +0200217
218 add_boot_device_path(dev->conf.bootindex, &dev->qdev,
219 dev->unit ? "/disk@1" : "/disk@0");
Gerd Hoffmannda4d0412009-09-15 19:23:34 +0000220}
221
Eric Blaked7bce992016-01-29 06:48:55 -0700222static void ide_dev_get_bootindex(Object *obj, Visitor *v, const char *name,
223 void *opaque, Error **errp)
Gonglei45563632014-10-07 16:00:29 +0800224{
225 IDEDevice *d = IDE_DEVICE(obj);
226
Eric Blake51e72bc2016-01-29 06:48:54 -0700227 visit_type_int32(v, name, &d->conf.bootindex, errp);
Gonglei45563632014-10-07 16:00:29 +0800228}
229
Eric Blaked7bce992016-01-29 06:48:55 -0700230static void ide_dev_set_bootindex(Object *obj, Visitor *v, const char *name,
231 void *opaque, Error **errp)
Gonglei45563632014-10-07 16:00:29 +0800232{
233 IDEDevice *d = IDE_DEVICE(obj);
234 int32_t boot_index;
235 Error *local_err = NULL;
236
Eric Blake51e72bc2016-01-29 06:48:54 -0700237 visit_type_int32(v, name, &boot_index, &local_err);
Gonglei45563632014-10-07 16:00:29 +0800238 if (local_err) {
239 goto out;
240 }
241 /* check whether bootindex is present in fw_boot_order list */
242 check_boot_index(boot_index, &local_err);
243 if (local_err) {
244 goto out;
245 }
246 /* change bootindex to a new one */
247 d->conf.bootindex = boot_index;
248
Gongleid2b186f2014-10-07 16:00:35 +0800249 if (d->unit != -1) {
250 add_boot_device_path(d->conf.bootindex, &d->qdev,
251 d->unit ? "/disk@1" : "/disk@0");
252 }
Gonglei45563632014-10-07 16:00:29 +0800253out:
Eduardo Habkost621ff942016-06-13 18:57:56 -0300254 error_propagate(errp, local_err);
Gonglei45563632014-10-07 16:00:29 +0800255}
256
257static void ide_dev_instance_init(Object *obj)
258{
259 object_property_add(obj, "bootindex", "int32",
260 ide_dev_get_bootindex,
261 ide_dev_set_bootindex, NULL, NULL, NULL);
Gongleid2b186f2014-10-07 16:00:35 +0800262 object_property_set_int(obj, -1, "bootindex", NULL);
Gonglei45563632014-10-07 16:00:29 +0800263}
264
Mao Zhongyi794939e2017-09-18 22:05:13 +0800265static void ide_hd_realize(IDEDevice *dev, Error **errp)
Markus Armbruster1f56e322011-05-16 15:04:52 +0200266{
Mao Zhongyi794939e2017-09-18 22:05:13 +0800267 ide_dev_initfn(dev, IDE_HD, errp);
Markus Armbruster1f56e322011-05-16 15:04:52 +0200268}
269
Mao Zhongyi794939e2017-09-18 22:05:13 +0800270static void ide_cd_realize(IDEDevice *dev, Error **errp)
Markus Armbruster1f56e322011-05-16 15:04:52 +0200271{
Mao Zhongyi794939e2017-09-18 22:05:13 +0800272 ide_dev_initfn(dev, IDE_CD, errp);
Markus Armbruster1f56e322011-05-16 15:04:52 +0200273}
274
Mao Zhongyi794939e2017-09-18 22:05:13 +0800275static void ide_drive_realize(IDEDevice *dev, Error **errp)
Markus Armbruster1f56e322011-05-16 15:04:52 +0200276{
Kevin Wolf67c75f32016-07-14 15:49:42 +0200277 DriveInfo *dinfo = NULL;
278
279 if (dev->conf.blk) {
280 dinfo = blk_legacy_dinfo(dev->conf.blk);
281 }
Markus Armbruster95b5edc2011-05-16 15:04:56 +0200282
Mao Zhongyi794939e2017-09-18 22:05:13 +0800283 ide_dev_initfn(dev, dinfo && dinfo->media_cd ? IDE_CD : IDE_HD, errp);
Markus Armbruster1f56e322011-05-16 15:04:52 +0200284}
285
286#define DEFINE_IDE_DEV_PROPERTIES() \
Markus Armbruster1f56e322011-05-16 15:04:52 +0200287 DEFINE_BLOCK_PROPERTIES(IDEDrive, dev.conf), \
Kevin Wolf8c398252016-06-29 17:41:35 +0200288 DEFINE_BLOCK_ERROR_PROPERTIES(IDEDrive, dev.conf), \
Markus Armbruster1f56e322011-05-16 15:04:52 +0200289 DEFINE_PROP_STRING("ver", IDEDrive, dev.version), \
Paolo Bonzinic7bcc852014-02-08 11:01:53 +0100290 DEFINE_PROP_UINT64("wwn", IDEDrive, dev.wwn, 0), \
Floris Bos27e0c9a2012-03-12 21:05:09 +0100291 DEFINE_PROP_STRING("serial", IDEDrive, dev.serial),\
292 DEFINE_PROP_STRING("model", IDEDrive, dev.model)
Markus Armbruster1f56e322011-05-16 15:04:52 +0200293
Anthony Liguori39bffca2011-12-07 21:34:16 -0600294static Property ide_hd_properties[] = {
295 DEFINE_IDE_DEV_PROPERTIES(),
Markus Armbrusterba801962012-07-10 11:12:44 +0200296 DEFINE_BLOCK_CHS_PROPERTIES(IDEDrive, dev.conf),
Markus Armbruster6e6f61a2012-07-10 11:12:48 +0200297 DEFINE_PROP_BIOS_CHS_TRANS("bios-chs-trans",
298 IDEDrive, dev.chs_trans, BIOS_ATA_TRANSLATION_AUTO),
Daniel P. Berrange3b19f452017-10-04 12:40:08 +0100299 DEFINE_PROP_UINT16("rotation_rate", IDEDrive, dev.rotation_rate, 0),
Anthony Liguori39bffca2011-12-07 21:34:16 -0600300 DEFINE_PROP_END_OF_LIST(),
301};
302
Anthony Liguorid1482112011-12-16 13:41:12 -0600303static void ide_hd_class_init(ObjectClass *klass, void *data)
304{
Anthony Liguori39bffca2011-12-07 21:34:16 -0600305 DeviceClass *dc = DEVICE_CLASS(klass);
Anthony Liguorid1482112011-12-16 13:41:12 -0600306 IDEDeviceClass *k = IDE_DEVICE_CLASS(klass);
Mao Zhongyi794939e2017-09-18 22:05:13 +0800307
308 k->realize = ide_hd_realize;
Anthony Liguori39bffca2011-12-07 21:34:16 -0600309 dc->fw_name = "drive";
Mao Zhongyi794939e2017-09-18 22:05:13 +0800310 dc->desc = "virtual IDE disk";
311 dc->props = ide_hd_properties;
Anthony Liguorid1482112011-12-16 13:41:12 -0600312}
313
Andreas Färber8c43a6f2013-01-10 16:19:07 +0100314static const TypeInfo ide_hd_info = {
Anthony Liguori39bffca2011-12-07 21:34:16 -0600315 .name = "ide-hd",
316 .parent = TYPE_IDE_DEVICE,
317 .instance_size = sizeof(IDEDrive),
318 .class_init = ide_hd_class_init,
319};
320
321static Property ide_cd_properties[] = {
322 DEFINE_IDE_DEV_PROPERTIES(),
323 DEFINE_PROP_END_OF_LIST(),
Gerd Hoffmannda4d0412009-09-15 19:23:34 +0000324};
325
Anthony Liguorid1482112011-12-16 13:41:12 -0600326static void ide_cd_class_init(ObjectClass *klass, void *data)
327{
Anthony Liguori39bffca2011-12-07 21:34:16 -0600328 DeviceClass *dc = DEVICE_CLASS(klass);
Anthony Liguorid1482112011-12-16 13:41:12 -0600329 IDEDeviceClass *k = IDE_DEVICE_CLASS(klass);
Mao Zhongyi794939e2017-09-18 22:05:13 +0800330
331 k->realize = ide_cd_realize;
Anthony Liguori39bffca2011-12-07 21:34:16 -0600332 dc->fw_name = "drive";
Mao Zhongyi794939e2017-09-18 22:05:13 +0800333 dc->desc = "virtual IDE CD-ROM";
334 dc->props = ide_cd_properties;
Anthony Liguorid1482112011-12-16 13:41:12 -0600335}
336
Andreas Färber8c43a6f2013-01-10 16:19:07 +0100337static const TypeInfo ide_cd_info = {
Anthony Liguori39bffca2011-12-07 21:34:16 -0600338 .name = "ide-cd",
339 .parent = TYPE_IDE_DEVICE,
340 .instance_size = sizeof(IDEDrive),
341 .class_init = ide_cd_class_init,
342};
343
344static Property ide_drive_properties[] = {
345 DEFINE_IDE_DEV_PROPERTIES(),
346 DEFINE_PROP_END_OF_LIST(),
Anthony Liguorid1482112011-12-16 13:41:12 -0600347};
348
349static void ide_drive_class_init(ObjectClass *klass, void *data)
350{
Anthony Liguori39bffca2011-12-07 21:34:16 -0600351 DeviceClass *dc = DEVICE_CLASS(klass);
Anthony Liguorid1482112011-12-16 13:41:12 -0600352 IDEDeviceClass *k = IDE_DEVICE_CLASS(klass);
Mao Zhongyi794939e2017-09-18 22:05:13 +0800353
354 k->realize = ide_drive_realize;
Anthony Liguori39bffca2011-12-07 21:34:16 -0600355 dc->fw_name = "drive";
Mao Zhongyi794939e2017-09-18 22:05:13 +0800356 dc->desc = "virtual IDE disk or CD-ROM (legacy)";
357 dc->props = ide_drive_properties;
Anthony Liguorid1482112011-12-16 13:41:12 -0600358}
359
Andreas Färber8c43a6f2013-01-10 16:19:07 +0100360static const TypeInfo ide_drive_info = {
Anthony Liguori39bffca2011-12-07 21:34:16 -0600361 .name = "ide-drive",
362 .parent = TYPE_IDE_DEVICE,
363 .instance_size = sizeof(IDEDrive),
364 .class_init = ide_drive_class_init,
Anthony Liguorid1482112011-12-16 13:41:12 -0600365};
366
Anthony Liguori39bffca2011-12-07 21:34:16 -0600367static void ide_device_class_init(ObjectClass *klass, void *data)
368{
369 DeviceClass *k = DEVICE_CLASS(klass);
Mao Zhongyi794939e2017-09-18 22:05:13 +0800370 k->realize = ide_qdev_realize;
Marcel Apfelbaum125ee0e2013-07-29 17:17:45 +0300371 set_bit(DEVICE_CATEGORY_STORAGE, k->categories);
Anthony Liguori0d936922012-05-02 09:00:20 +0200372 k->bus_type = TYPE_IDE_BUS;
Paolo Bonzinibce54472012-03-28 18:12:47 +0200373 k->props = ide_props;
Anthony Liguori39bffca2011-12-07 21:34:16 -0600374}
375
Andreas Färber8c43a6f2013-01-10 16:19:07 +0100376static const TypeInfo ide_device_type_info = {
Anthony Liguorid1482112011-12-16 13:41:12 -0600377 .name = TYPE_IDE_DEVICE,
378 .parent = TYPE_DEVICE,
379 .instance_size = sizeof(IDEDevice),
380 .abstract = true,
381 .class_size = sizeof(IDEDeviceClass),
Anthony Liguori39bffca2011-12-07 21:34:16 -0600382 .class_init = ide_device_class_init,
Gonglei45563632014-10-07 16:00:29 +0800383 .instance_init = ide_dev_instance_init,
Anthony Liguorid1482112011-12-16 13:41:12 -0600384};
385
Andreas Färber83f7d432012-02-09 15:20:55 +0100386static void ide_register_types(void)
Gerd Hoffmannda4d0412009-09-15 19:23:34 +0000387{
Anthony Liguori0d936922012-05-02 09:00:20 +0200388 type_register_static(&ide_bus_info);
Anthony Liguori39bffca2011-12-07 21:34:16 -0600389 type_register_static(&ide_hd_info);
390 type_register_static(&ide_cd_info);
391 type_register_static(&ide_drive_info);
Anthony Liguorid1482112011-12-16 13:41:12 -0600392 type_register_static(&ide_device_type_info);
Gerd Hoffmannda4d0412009-09-15 19:23:34 +0000393}
Andreas Färber83f7d432012-02-09 15:20:55 +0100394
395type_init(ide_register_types)