blob: 27ff1f7f662536da824f812838dc9200bdef6a20 [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"
Paolo Bonzini9c17d612012-12-17 18:20:04 +010021#include "sysemu/dma.h"
Markus Armbrusterda34e652016-03-14 09:01:28 +010022#include "qapi/error.h"
Markus Armbruster2ae16a62019-08-12 07:23:32 +020023#include "qapi/qapi-types-block.h"
Paolo Bonzini1de7afc2012-12-17 18:20:00 +010024#include "qemu/error-report.h"
Markus Armbrusterdb725812019-08-12 07:23:50 +020025#include "qemu/main-loop.h"
Markus Armbruster0b8fa322019-05-23 16:35:07 +020026#include "qemu/module.h"
Markus Armbrustera9c94272016-06-22 19:11:19 +020027#include "hw/ide/internal.h"
Markus Armbrustera27bd6c2019-08-12 07:23:51 +020028#include "hw/qdev-properties.h"
Markus Armbrusterfa1d36d2014-10-07 13:59:13 +020029#include "sysemu/block-backend.h"
Paolo Bonzini9c17d612012-12-17 18:20:04 +010030#include "sysemu/blockdev.h"
Paolo Bonzini0d09e412013-02-05 17:06:20 +010031#include "hw/block/block.h"
Paolo Bonzini9c17d612012-12-17 18:20:04 +010032#include "sysemu/sysemu.h"
Markus Armbruster54d31232019-08-12 07:23:59 +020033#include "sysemu/runstate.h"
Gonglei45563632014-10-07 16:00:29 +080034#include "qapi/visitor.h"
Gerd Hoffmannda4d0412009-09-15 19:23:34 +000035
36/* --------------------------------- */
37
Gleb Natapovdc1a46b2010-12-08 13:34:59 +020038static char *idebus_get_fw_dev_path(DeviceState *dev);
Markus Armbrusterb69c3c22020-05-05 17:29:24 +020039static void idebus_unrealize(BusState *qdev);
Gleb Natapovdc1a46b2010-12-08 13:34:59 +020040
Paolo Bonzini3cb75a72012-03-28 18:01:36 +020041static Property ide_props[] = {
42 DEFINE_PROP_UINT32("unit", IDEDevice, unit, -1),
43 DEFINE_PROP_END_OF_LIST(),
44};
45
Anthony Liguori0d936922012-05-02 09:00:20 +020046static void ide_bus_class_init(ObjectClass *klass, void *data)
47{
48 BusClass *k = BUS_CLASS(klass);
49
50 k->get_fw_dev_path = idebus_get_fw_dev_path;
Li Qiang44a109c2017-03-15 20:50:14 -040051 k->unrealize = idebus_unrealize;
Anthony Liguori0d936922012-05-02 09:00:20 +020052}
53
Markus Armbrusterb69c3c22020-05-05 17:29:24 +020054static void idebus_unrealize(BusState *bus)
Ashijeet Acharyaca441412016-09-27 22:23:32 +053055{
Li Qiang44a109c2017-03-15 20:50:14 -040056 IDEBus *ibus = IDE_BUS(bus);
Ashijeet Acharyaca441412016-09-27 22:23:32 +053057
Li Qiang44a109c2017-03-15 20:50:14 -040058 if (ibus->vmstate) {
59 qemu_del_vm_change_state_handler(ibus->vmstate);
Ashijeet Acharyaca441412016-09-27 22:23:32 +053060 }
61}
62
Anthony Liguori0d936922012-05-02 09:00:20 +020063static const TypeInfo ide_bus_info = {
64 .name = TYPE_IDE_BUS,
65 .parent = TYPE_BUS,
66 .instance_size = sizeof(IDEBus),
67 .class_init = ide_bus_class_init,
Gerd Hoffmannda4d0412009-09-15 19:23:34 +000068};
69
Andreas Färberc6baf942013-08-23 20:18:50 +020070void ide_bus_new(IDEBus *idebus, size_t idebus_size, DeviceState *dev,
71 int bus_id, int max_units)
Gerd Hoffmannda4d0412009-09-15 19:23:34 +000072{
Andreas Färberfb17dfe2013-08-24 00:02:27 +020073 qbus_create_inplace(idebus, idebus_size, TYPE_IDE_BUS, dev, NULL);
Gleb Natapov38355102010-12-08 13:34:58 +020074 idebus->bus_id = bus_id;
Kevin Wolf0ee20e62013-05-06 15:58:04 +020075 idebus->max_units = max_units;
Gerd Hoffmannda4d0412009-09-15 19:23:34 +000076}
77
Gleb Natapovdc1a46b2010-12-08 13:34:59 +020078static char *idebus_get_fw_dev_path(DeviceState *dev)
79{
80 char path[30];
81
Markus Armbruster28fa7132014-08-15 13:32:37 +020082 snprintf(path, sizeof(path), "%s@%x", qdev_fw_name(dev),
Gleb Natapovdc1a46b2010-12-08 13:34:59 +020083 ((IDEBus*)dev->parent_bus)->bus_id);
84
Jim Meyeringa5cf8262012-10-04 13:09:44 +020085 return g_strdup(path);
Gleb Natapovdc1a46b2010-12-08 13:34:59 +020086}
87
Mao Zhongyi794939e2017-09-18 22:05:13 +080088static void ide_qdev_realize(DeviceState *qdev, Error **errp)
Gerd Hoffmannda4d0412009-09-15 19:23:34 +000089{
Anthony Liguorid1482112011-12-16 13:41:12 -060090 IDEDevice *dev = IDE_DEVICE(qdev);
91 IDEDeviceClass *dc = IDE_DEVICE_GET_CLASS(dev);
Gerd Hoffmannda4d0412009-09-15 19:23:34 +000092 IDEBus *bus = DO_UPCAST(IDEBus, qbus, qdev->parent_bus);
93
Gerd Hoffmannda4d0412009-09-15 19:23:34 +000094 if (dev->unit == -1) {
95 dev->unit = bus->master ? 1 : 0;
96 }
Kevin Wolf0ee20e62013-05-06 15:58:04 +020097
98 if (dev->unit >= bus->max_units) {
Mao Zhongyi794939e2017-09-18 22:05:13 +080099 error_setg(errp, "Can't create IDE unit %d, bus supports only %d units",
Kevin Wolf0ee20e62013-05-06 15:58:04 +0200100 dev->unit, bus->max_units);
Mao Zhongyi794939e2017-09-18 22:05:13 +0800101 return;
Kevin Wolf0ee20e62013-05-06 15:58:04 +0200102 }
103
Gerd Hoffmannda4d0412009-09-15 19:23:34 +0000104 switch (dev->unit) {
105 case 0:
106 if (bus->master) {
Mao Zhongyi794939e2017-09-18 22:05:13 +0800107 error_setg(errp, "IDE unit %d is in use", dev->unit);
108 return;
Gerd Hoffmannda4d0412009-09-15 19:23:34 +0000109 }
110 bus->master = dev;
111 break;
112 case 1:
113 if (bus->slave) {
Mao Zhongyi794939e2017-09-18 22:05:13 +0800114 error_setg(errp, "IDE unit %d is in use", dev->unit);
115 return;
Gerd Hoffmannda4d0412009-09-15 19:23:34 +0000116 }
117 bus->slave = dev;
118 break;
119 default:
Mao Zhongyi794939e2017-09-18 22:05:13 +0800120 error_setg(errp, "Invalid IDE unit %d", dev->unit);
121 return;
Gerd Hoffmannda4d0412009-09-15 19:23:34 +0000122 }
Mao Zhongyi794939e2017-09-18 22:05:13 +0800123 dc->realize(dev, errp);
Gerd Hoffmannda4d0412009-09-15 19:23:34 +0000124}
125
Gerd Hoffmannda4d0412009-09-15 19:23:34 +0000126IDEDevice *ide_create_drive(IDEBus *bus, int unit, DriveInfo *drive)
127{
128 DeviceState *dev;
129
Markus Armbruster3e80f692020-06-10 07:31:58 +0200130 dev = qdev_new(drive->media_cd ? "ide-cd" : "ide-hd");
Gerd Hoffmannda4d0412009-09-15 19:23:34 +0000131 qdev_prop_set_uint32(dev, "unit", unit);
Markus Armbruster934df912020-06-22 11:42:24 +0200132 qdev_prop_set_drive_err(dev, "drive", blk_by_legacy_dinfo(drive),
133 &error_fatal);
Markus Armbruster3e80f692020-06-10 07:31:58 +0200134 qdev_realize_and_unref(dev, &bus->qbus, &error_fatal);
Gerd Hoffmannda4d0412009-09-15 19:23:34 +0000135 return DO_UPCAST(IDEDevice, qdev, dev);
136}
137
Markus Armbruster91390462012-07-10 11:12:38 +0200138int ide_get_geometry(BusState *bus, int unit,
139 int16_t *cyls, int8_t *heads, int8_t *secs)
Markus Armbrusterc0897e02010-06-24 19:58:20 +0200140{
Markus Armbruster91390462012-07-10 11:12:38 +0200141 IDEState *s = &DO_UPCAST(IDEBus, qbus, bus)->ifs[unit];
142
Markus Armbruster4be74632014-10-07 13:59:18 +0200143 if (s->drive_kind != IDE_HD || !s->blk) {
Markus Armbruster91390462012-07-10 11:12:38 +0200144 return -1;
145 }
146
147 *cyls = s->cylinders;
148 *heads = s->heads;
149 *secs = s->sectors;
150 return 0;
151}
152
153int ide_get_bios_chs_trans(BusState *bus, int unit)
154{
155 return DO_UPCAST(IDEBus, qbus, bus)->ifs[unit].chs_trans;
Markus Armbrusterc0897e02010-06-24 19:58:20 +0200156}
157
Gerd Hoffmannda4d0412009-09-15 19:23:34 +0000158/* --------------------------------- */
159
160typedef struct IDEDrive {
161 IDEDevice dev;
162} IDEDrive;
163
Mao Zhongyi794939e2017-09-18 22:05:13 +0800164static void ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind, Error **errp)
Gerd Hoffmannda4d0412009-09-15 19:23:34 +0000165{
166 IDEBus *bus = DO_UPCAST(IDEBus, qbus, dev->qdev.parent_bus);
Markus Armbruster6ced55a2010-06-01 20:32:32 +0200167 IDEState *s = bus->ifs + dev->unit;
Kevin Wolf947231a2017-07-11 14:04:08 +0200168 int ret;
Markus Armbruster6ced55a2010-06-01 20:32:32 +0200169
Kevin Wolf67c75f32016-07-14 15:49:42 +0200170 if (!dev->conf.blk) {
171 if (kind != IDE_CD) {
Mao Zhongyi794939e2017-09-18 22:05:13 +0800172 error_setg(errp, "No drive specified");
173 return;
Kevin Wolf67c75f32016-07-14 15:49:42 +0200174 } else {
175 /* Anonymous BlockBackend for an empty drive */
Kevin Wolfd861ab32019-04-25 14:25:10 +0200176 dev->conf.blk = blk_new(qemu_get_aio_context(), 0, BLK_PERM_ALL);
Kevin Wolf947231a2017-07-11 14:04:08 +0200177 ret = blk_attach_dev(dev->conf.blk, &dev->qdev);
178 assert(ret == 0);
Kevin Wolf67c75f32016-07-14 15:49:42 +0200179 }
180 }
181
Paolo Bonzini215e47b2013-02-08 14:06:14 +0100182 if (dev->conf.discard_granularity == -1) {
183 dev->conf.discard_granularity = 512;
184 } else if (dev->conf.discard_granularity &&
185 dev->conf.discard_granularity != 512) {
Mao Zhongyi794939e2017-09-18 22:05:13 +0800186 error_setg(errp, "discard_granularity must be 512 for ide");
187 return;
Christoph Hellwigd353fb72011-05-19 10:58:19 +0200188 }
189
Roman Kaganc56ee922020-05-29 01:55:10 +0300190 if (!blkconf_blocksizes(&dev->conf, errp)) {
191 return;
192 }
193
Kevin Wolfd2005182014-12-03 13:21:32 +0100194 if (dev->conf.logical_block_size != 512) {
Mao Zhongyi794939e2017-09-18 22:05:13 +0800195 error_setg(errp, "logical_block_size must be 512 for IDE");
196 return;
Kevin Wolfd2005182014-12-03 13:21:32 +0100197 }
198
Fam Zheng5ff5efb2014-08-12 10:12:54 +0800199 if (kind != IDE_CD) {
Mao Zhongyiceff3e12017-11-22 11:08:45 +0800200 if (!blkconf_geometry(&dev->conf, &dev->chs_trans, 65535, 16, 255,
201 errp)) {
Mao Zhongyi794939e2017-09-18 22:05:13 +0800202 return;
Fam Zheng5ff5efb2014-08-12 10:12:54 +0800203 }
Markus Armbrusterba801962012-07-10 11:12:44 +0200204 }
Mao Zhongyiceff3e12017-11-22 11:08:45 +0800205 if (!blkconf_apply_backend_options(&dev->conf, kind == IDE_CD,
206 kind != IDE_CD, errp)) {
Mao Zhongyi794939e2017-09-18 22:05:13 +0800207 return;
Kevin Wolfa17c17a2017-01-24 13:43:31 +0100208 }
Markus Armbrusterba801962012-07-10 11:12:44 +0200209
Markus Armbruster4be74632014-10-07 13:59:18 +0200210 if (ide_init_drive(s, dev->conf.blk, kind,
Markus Armbruster911525d2012-07-11 15:08:37 +0200211 dev->version, dev->serial, dev->model, dev->wwn,
Markus Armbrusterba801962012-07-10 11:12:44 +0200212 dev->conf.cyls, dev->conf.heads, dev->conf.secs,
Mao Zhongyi794939e2017-09-18 22:05:13 +0800213 dev->chs_trans, errp) < 0) {
214 return;
Markus Armbrusterc4d74df2010-06-28 19:07:51 +0200215 }
Markus Armbruster6ced55a2010-06-01 20:32:32 +0200216
Markus Armbruster03432402010-06-01 20:32:33 +0200217 if (!dev->version) {
Anthony Liguori7267c092011-08-20 22:09:37 -0500218 dev->version = g_strdup(s->version);
Markus Armbruster03432402010-06-01 20:32:33 +0200219 }
Markus Armbruster6ced55a2010-06-01 20:32:32 +0200220 if (!dev->serial) {
Anthony Liguori7267c092011-08-20 22:09:37 -0500221 dev->serial = g_strdup(s->drive_serial_str);
Markus Armbruster6ced55a2010-06-01 20:32:32 +0200222 }
Gleb Natapov1ca4d092010-12-08 13:35:05 +0200223
224 add_boot_device_path(dev->conf.bootindex, &dev->qdev,
225 dev->unit ? "/disk@1" : "/disk@0");
Sam Eiderman71f571a2019-10-16 19:41:42 +0300226
227 add_boot_device_lchs(&dev->qdev, dev->unit ? "/disk@1" : "/disk@0",
228 dev->conf.lcyls,
229 dev->conf.lheads,
230 dev->conf.lsecs);
Gerd Hoffmannda4d0412009-09-15 19:23:34 +0000231}
232
Eric Blaked7bce992016-01-29 06:48:55 -0700233static void ide_dev_get_bootindex(Object *obj, Visitor *v, const char *name,
234 void *opaque, Error **errp)
Gonglei45563632014-10-07 16:00:29 +0800235{
236 IDEDevice *d = IDE_DEVICE(obj);
237
Eric Blake51e72bc2016-01-29 06:48:54 -0700238 visit_type_int32(v, name, &d->conf.bootindex, errp);
Gonglei45563632014-10-07 16:00:29 +0800239}
240
Eric Blaked7bce992016-01-29 06:48:55 -0700241static void ide_dev_set_bootindex(Object *obj, Visitor *v, const char *name,
242 void *opaque, Error **errp)
Gonglei45563632014-10-07 16:00:29 +0800243{
244 IDEDevice *d = IDE_DEVICE(obj);
245 int32_t boot_index;
246 Error *local_err = NULL;
247
Markus Armbruster14217032020-07-07 18:05:47 +0200248 if (!visit_type_int32(v, name, &boot_index, errp)) {
249 return;
Gonglei45563632014-10-07 16:00:29 +0800250 }
251 /* check whether bootindex is present in fw_boot_order list */
252 check_boot_index(boot_index, &local_err);
253 if (local_err) {
254 goto out;
255 }
256 /* change bootindex to a new one */
257 d->conf.bootindex = boot_index;
258
Gongleid2b186f2014-10-07 16:00:35 +0800259 if (d->unit != -1) {
260 add_boot_device_path(d->conf.bootindex, &d->qdev,
261 d->unit ? "/disk@1" : "/disk@0");
262 }
Gonglei45563632014-10-07 16:00:29 +0800263out:
Eduardo Habkost621ff942016-06-13 18:57:56 -0300264 error_propagate(errp, local_err);
Gonglei45563632014-10-07 16:00:29 +0800265}
266
267static void ide_dev_instance_init(Object *obj)
268{
269 object_property_add(obj, "bootindex", "int32",
270 ide_dev_get_bootindex,
Markus Armbrusterd2623122020-05-05 17:29:22 +0200271 ide_dev_set_bootindex, NULL, NULL);
Markus Armbruster5325cc32020-07-07 18:05:54 +0200272 object_property_set_int(obj, "bootindex", -1, NULL);
Gonglei45563632014-10-07 16:00:29 +0800273}
274
Mao Zhongyi794939e2017-09-18 22:05:13 +0800275static void ide_hd_realize(IDEDevice *dev, Error **errp)
Markus Armbruster1f56e322011-05-16 15:04:52 +0200276{
Mao Zhongyi794939e2017-09-18 22:05:13 +0800277 ide_dev_initfn(dev, IDE_HD, errp);
Markus Armbruster1f56e322011-05-16 15:04:52 +0200278}
279
Mao Zhongyi794939e2017-09-18 22:05:13 +0800280static void ide_cd_realize(IDEDevice *dev, Error **errp)
Markus Armbruster1f56e322011-05-16 15:04:52 +0200281{
Mao Zhongyi794939e2017-09-18 22:05:13 +0800282 ide_dev_initfn(dev, IDE_CD, errp);
Markus Armbruster1f56e322011-05-16 15:04:52 +0200283}
284
Mao Zhongyi794939e2017-09-18 22:05:13 +0800285static void ide_drive_realize(IDEDevice *dev, Error **errp)
Markus Armbruster1f56e322011-05-16 15:04:52 +0200286{
Kevin Wolf67c75f32016-07-14 15:49:42 +0200287 DriveInfo *dinfo = NULL;
288
John Snow7d601332019-10-09 18:43:03 -0400289 warn_report("'ide-drive' is deprecated, "
290 "please use 'ide-hd' or 'ide-cd' instead");
291
Kevin Wolf67c75f32016-07-14 15:49:42 +0200292 if (dev->conf.blk) {
293 dinfo = blk_legacy_dinfo(dev->conf.blk);
294 }
Markus Armbruster95b5edc2011-05-16 15:04:56 +0200295
Mao Zhongyi794939e2017-09-18 22:05:13 +0800296 ide_dev_initfn(dev, dinfo && dinfo->media_cd ? IDE_CD : IDE_HD, errp);
Markus Armbruster1f56e322011-05-16 15:04:52 +0200297}
298
299#define DEFINE_IDE_DEV_PROPERTIES() \
Markus Armbruster1f56e322011-05-16 15:04:52 +0200300 DEFINE_BLOCK_PROPERTIES(IDEDrive, dev.conf), \
Kevin Wolf8c398252016-06-29 17:41:35 +0200301 DEFINE_BLOCK_ERROR_PROPERTIES(IDEDrive, dev.conf), \
Markus Armbruster1f56e322011-05-16 15:04:52 +0200302 DEFINE_PROP_STRING("ver", IDEDrive, dev.version), \
Sam Eiderman8e6a1742019-10-16 19:41:37 +0300303 DEFINE_PROP_UINT64("wwn", IDEDrive, dev.wwn, 0), \
Floris Bos27e0c9a2012-03-12 21:05:09 +0100304 DEFINE_PROP_STRING("serial", IDEDrive, dev.serial),\
305 DEFINE_PROP_STRING("model", IDEDrive, dev.model)
Markus Armbruster1f56e322011-05-16 15:04:52 +0200306
Anthony Liguori39bffca2011-12-07 21:34:16 -0600307static Property ide_hd_properties[] = {
308 DEFINE_IDE_DEV_PROPERTIES(),
Markus Armbrusterba801962012-07-10 11:12:44 +0200309 DEFINE_BLOCK_CHS_PROPERTIES(IDEDrive, dev.conf),
Markus Armbruster6e6f61a2012-07-10 11:12:48 +0200310 DEFINE_PROP_BIOS_CHS_TRANS("bios-chs-trans",
311 IDEDrive, dev.chs_trans, BIOS_ATA_TRANSLATION_AUTO),
Daniel P. Berrange3b19f452017-10-04 12:40:08 +0100312 DEFINE_PROP_UINT16("rotation_rate", IDEDrive, dev.rotation_rate, 0),
Anthony Liguori39bffca2011-12-07 21:34:16 -0600313 DEFINE_PROP_END_OF_LIST(),
314};
315
Anthony Liguorid1482112011-12-16 13:41:12 -0600316static void ide_hd_class_init(ObjectClass *klass, void *data)
317{
Anthony Liguori39bffca2011-12-07 21:34:16 -0600318 DeviceClass *dc = DEVICE_CLASS(klass);
Anthony Liguorid1482112011-12-16 13:41:12 -0600319 IDEDeviceClass *k = IDE_DEVICE_CLASS(klass);
Mao Zhongyi794939e2017-09-18 22:05:13 +0800320
321 k->realize = ide_hd_realize;
Anthony Liguori39bffca2011-12-07 21:34:16 -0600322 dc->fw_name = "drive";
Mao Zhongyi794939e2017-09-18 22:05:13 +0800323 dc->desc = "virtual IDE disk";
Marc-André Lureau4f67d302020-01-10 19:30:32 +0400324 device_class_set_props(dc, ide_hd_properties);
Anthony Liguorid1482112011-12-16 13:41:12 -0600325}
326
Andreas Färber8c43a6f2013-01-10 16:19:07 +0100327static const TypeInfo ide_hd_info = {
Anthony Liguori39bffca2011-12-07 21:34:16 -0600328 .name = "ide-hd",
329 .parent = TYPE_IDE_DEVICE,
330 .instance_size = sizeof(IDEDrive),
331 .class_init = ide_hd_class_init,
332};
333
334static Property ide_cd_properties[] = {
335 DEFINE_IDE_DEV_PROPERTIES(),
336 DEFINE_PROP_END_OF_LIST(),
Gerd Hoffmannda4d0412009-09-15 19:23:34 +0000337};
338
Anthony Liguorid1482112011-12-16 13:41:12 -0600339static void ide_cd_class_init(ObjectClass *klass, void *data)
340{
Anthony Liguori39bffca2011-12-07 21:34:16 -0600341 DeviceClass *dc = DEVICE_CLASS(klass);
Anthony Liguorid1482112011-12-16 13:41:12 -0600342 IDEDeviceClass *k = IDE_DEVICE_CLASS(klass);
Mao Zhongyi794939e2017-09-18 22:05:13 +0800343
344 k->realize = ide_cd_realize;
Anthony Liguori39bffca2011-12-07 21:34:16 -0600345 dc->fw_name = "drive";
Mao Zhongyi794939e2017-09-18 22:05:13 +0800346 dc->desc = "virtual IDE CD-ROM";
Marc-André Lureau4f67d302020-01-10 19:30:32 +0400347 device_class_set_props(dc, ide_cd_properties);
Anthony Liguorid1482112011-12-16 13:41:12 -0600348}
349
Andreas Färber8c43a6f2013-01-10 16:19:07 +0100350static const TypeInfo ide_cd_info = {
Anthony Liguori39bffca2011-12-07 21:34:16 -0600351 .name = "ide-cd",
352 .parent = TYPE_IDE_DEVICE,
353 .instance_size = sizeof(IDEDrive),
354 .class_init = ide_cd_class_init,
355};
356
357static Property ide_drive_properties[] = {
358 DEFINE_IDE_DEV_PROPERTIES(),
359 DEFINE_PROP_END_OF_LIST(),
Anthony Liguorid1482112011-12-16 13:41:12 -0600360};
361
362static void ide_drive_class_init(ObjectClass *klass, void *data)
363{
Anthony Liguori39bffca2011-12-07 21:34:16 -0600364 DeviceClass *dc = DEVICE_CLASS(klass);
Anthony Liguorid1482112011-12-16 13:41:12 -0600365 IDEDeviceClass *k = IDE_DEVICE_CLASS(klass);
Mao Zhongyi794939e2017-09-18 22:05:13 +0800366
367 k->realize = ide_drive_realize;
Anthony Liguori39bffca2011-12-07 21:34:16 -0600368 dc->fw_name = "drive";
Mao Zhongyi794939e2017-09-18 22:05:13 +0800369 dc->desc = "virtual IDE disk or CD-ROM (legacy)";
Marc-André Lureau4f67d302020-01-10 19:30:32 +0400370 device_class_set_props(dc, ide_drive_properties);
Anthony Liguorid1482112011-12-16 13:41:12 -0600371}
372
Andreas Färber8c43a6f2013-01-10 16:19:07 +0100373static const TypeInfo ide_drive_info = {
Anthony Liguori39bffca2011-12-07 21:34:16 -0600374 .name = "ide-drive",
375 .parent = TYPE_IDE_DEVICE,
376 .instance_size = sizeof(IDEDrive),
377 .class_init = ide_drive_class_init,
Anthony Liguorid1482112011-12-16 13:41:12 -0600378};
379
Anthony Liguori39bffca2011-12-07 21:34:16 -0600380static void ide_device_class_init(ObjectClass *klass, void *data)
381{
382 DeviceClass *k = DEVICE_CLASS(klass);
Mao Zhongyi794939e2017-09-18 22:05:13 +0800383 k->realize = ide_qdev_realize;
Marcel Apfelbaum125ee0e2013-07-29 17:17:45 +0300384 set_bit(DEVICE_CATEGORY_STORAGE, k->categories);
Anthony Liguori0d936922012-05-02 09:00:20 +0200385 k->bus_type = TYPE_IDE_BUS;
Marc-André Lureau4f67d302020-01-10 19:30:32 +0400386 device_class_set_props(k, ide_props);
Anthony Liguori39bffca2011-12-07 21:34:16 -0600387}
388
Andreas Färber8c43a6f2013-01-10 16:19:07 +0100389static const TypeInfo ide_device_type_info = {
Anthony Liguorid1482112011-12-16 13:41:12 -0600390 .name = TYPE_IDE_DEVICE,
391 .parent = TYPE_DEVICE,
392 .instance_size = sizeof(IDEDevice),
393 .abstract = true,
394 .class_size = sizeof(IDEDeviceClass),
Anthony Liguori39bffca2011-12-07 21:34:16 -0600395 .class_init = ide_device_class_init,
Gonglei45563632014-10-07 16:00:29 +0800396 .instance_init = ide_dev_instance_init,
Anthony Liguorid1482112011-12-16 13:41:12 -0600397};
398
Andreas Färber83f7d432012-02-09 15:20:55 +0100399static void ide_register_types(void)
Gerd Hoffmannda4d0412009-09-15 19:23:34 +0000400{
Anthony Liguori0d936922012-05-02 09:00:20 +0200401 type_register_static(&ide_bus_info);
Anthony Liguori39bffca2011-12-07 21:34:16 -0600402 type_register_static(&ide_hd_info);
403 type_register_static(&ide_cd_info);
404 type_register_static(&ide_drive_info);
Anthony Liguorid1482112011-12-16 13:41:12 -0600405 type_register_static(&ide_device_type_info);
Gerd Hoffmannda4d0412009-09-15 19:23:34 +0000406}
Andreas Färber83f7d432012-02-09 15:20:55 +0100407
408type_init(ide_register_types)