Gerd Hoffmann | da4d041 | 2009-09-15 19:23:34 +0000 | [diff] [blame] | 1 | /* |
| 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 Armbruster | 0b8fa32 | 2019-05-23 16:35:07 +0200 | [diff] [blame^] | 19 | |
Peter Maydell | 5323926 | 2016-01-26 18:17:09 +0000 | [diff] [blame] | 20 | #include "qemu/osdep.h" |
Markus Armbruster | a9c9427 | 2016-06-22 19:11:19 +0200 | [diff] [blame] | 21 | #include "hw/hw.h" |
Paolo Bonzini | 9c17d61 | 2012-12-17 18:20:04 +0100 | [diff] [blame] | 22 | #include "sysemu/dma.h" |
Markus Armbruster | da34e65 | 2016-03-14 09:01:28 +0100 | [diff] [blame] | 23 | #include "qapi/error.h" |
Paolo Bonzini | 1de7afc | 2012-12-17 18:20:00 +0100 | [diff] [blame] | 24 | #include "qemu/error-report.h" |
Markus Armbruster | 0b8fa32 | 2019-05-23 16:35:07 +0200 | [diff] [blame^] | 25 | #include "qemu/module.h" |
Markus Armbruster | a9c9427 | 2016-06-22 19:11:19 +0200 | [diff] [blame] | 26 | #include "hw/ide/internal.h" |
Markus Armbruster | fa1d36d | 2014-10-07 13:59:13 +0200 | [diff] [blame] | 27 | #include "sysemu/block-backend.h" |
Paolo Bonzini | 9c17d61 | 2012-12-17 18:20:04 +0100 | [diff] [blame] | 28 | #include "sysemu/blockdev.h" |
Paolo Bonzini | 0d09e41 | 2013-02-05 17:06:20 +0100 | [diff] [blame] | 29 | #include "hw/block/block.h" |
Paolo Bonzini | 9c17d61 | 2012-12-17 18:20:04 +0100 | [diff] [blame] | 30 | #include "sysemu/sysemu.h" |
Gonglei | 4556363 | 2014-10-07 16:00:29 +0800 | [diff] [blame] | 31 | #include "qapi/visitor.h" |
Gerd Hoffmann | da4d041 | 2009-09-15 19:23:34 +0000 | [diff] [blame] | 32 | |
| 33 | /* --------------------------------- */ |
| 34 | |
Gleb Natapov | dc1a46b | 2010-12-08 13:34:59 +0200 | [diff] [blame] | 35 | static char *idebus_get_fw_dev_path(DeviceState *dev); |
Li Qiang | 44a109c | 2017-03-15 20:50:14 -0400 | [diff] [blame] | 36 | static void idebus_unrealize(BusState *qdev, Error **errp); |
Gleb Natapov | dc1a46b | 2010-12-08 13:34:59 +0200 | [diff] [blame] | 37 | |
Paolo Bonzini | 3cb75a7 | 2012-03-28 18:01:36 +0200 | [diff] [blame] | 38 | static Property ide_props[] = { |
| 39 | DEFINE_PROP_UINT32("unit", IDEDevice, unit, -1), |
| 40 | DEFINE_PROP_END_OF_LIST(), |
| 41 | }; |
| 42 | |
Anthony Liguori | 0d93692 | 2012-05-02 09:00:20 +0200 | [diff] [blame] | 43 | static 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 Qiang | 44a109c | 2017-03-15 20:50:14 -0400 | [diff] [blame] | 48 | k->unrealize = idebus_unrealize; |
Anthony Liguori | 0d93692 | 2012-05-02 09:00:20 +0200 | [diff] [blame] | 49 | } |
| 50 | |
Li Qiang | 44a109c | 2017-03-15 20:50:14 -0400 | [diff] [blame] | 51 | static void idebus_unrealize(BusState *bus, Error **errp) |
Ashijeet Acharya | ca44141 | 2016-09-27 22:23:32 +0530 | [diff] [blame] | 52 | { |
Li Qiang | 44a109c | 2017-03-15 20:50:14 -0400 | [diff] [blame] | 53 | IDEBus *ibus = IDE_BUS(bus); |
Ashijeet Acharya | ca44141 | 2016-09-27 22:23:32 +0530 | [diff] [blame] | 54 | |
Li Qiang | 44a109c | 2017-03-15 20:50:14 -0400 | [diff] [blame] | 55 | if (ibus->vmstate) { |
| 56 | qemu_del_vm_change_state_handler(ibus->vmstate); |
Ashijeet Acharya | ca44141 | 2016-09-27 22:23:32 +0530 | [diff] [blame] | 57 | } |
| 58 | } |
| 59 | |
Anthony Liguori | 0d93692 | 2012-05-02 09:00:20 +0200 | [diff] [blame] | 60 | static 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 Hoffmann | da4d041 | 2009-09-15 19:23:34 +0000 | [diff] [blame] | 65 | }; |
| 66 | |
Andreas Färber | c6baf94 | 2013-08-23 20:18:50 +0200 | [diff] [blame] | 67 | void ide_bus_new(IDEBus *idebus, size_t idebus_size, DeviceState *dev, |
| 68 | int bus_id, int max_units) |
Gerd Hoffmann | da4d041 | 2009-09-15 19:23:34 +0000 | [diff] [blame] | 69 | { |
Andreas Färber | fb17dfe | 2013-08-24 00:02:27 +0200 | [diff] [blame] | 70 | qbus_create_inplace(idebus, idebus_size, TYPE_IDE_BUS, dev, NULL); |
Gleb Natapov | 3835510 | 2010-12-08 13:34:58 +0200 | [diff] [blame] | 71 | idebus->bus_id = bus_id; |
Kevin Wolf | 0ee20e6 | 2013-05-06 15:58:04 +0200 | [diff] [blame] | 72 | idebus->max_units = max_units; |
Gerd Hoffmann | da4d041 | 2009-09-15 19:23:34 +0000 | [diff] [blame] | 73 | } |
| 74 | |
Gleb Natapov | dc1a46b | 2010-12-08 13:34:59 +0200 | [diff] [blame] | 75 | static char *idebus_get_fw_dev_path(DeviceState *dev) |
| 76 | { |
| 77 | char path[30]; |
| 78 | |
Markus Armbruster | 28fa713 | 2014-08-15 13:32:37 +0200 | [diff] [blame] | 79 | snprintf(path, sizeof(path), "%s@%x", qdev_fw_name(dev), |
Gleb Natapov | dc1a46b | 2010-12-08 13:34:59 +0200 | [diff] [blame] | 80 | ((IDEBus*)dev->parent_bus)->bus_id); |
| 81 | |
Jim Meyering | a5cf826 | 2012-10-04 13:09:44 +0200 | [diff] [blame] | 82 | return g_strdup(path); |
Gleb Natapov | dc1a46b | 2010-12-08 13:34:59 +0200 | [diff] [blame] | 83 | } |
| 84 | |
Mao Zhongyi | 794939e | 2017-09-18 22:05:13 +0800 | [diff] [blame] | 85 | static void ide_qdev_realize(DeviceState *qdev, Error **errp) |
Gerd Hoffmann | da4d041 | 2009-09-15 19:23:34 +0000 | [diff] [blame] | 86 | { |
Anthony Liguori | d148211 | 2011-12-16 13:41:12 -0600 | [diff] [blame] | 87 | IDEDevice *dev = IDE_DEVICE(qdev); |
| 88 | IDEDeviceClass *dc = IDE_DEVICE_GET_CLASS(dev); |
Gerd Hoffmann | da4d041 | 2009-09-15 19:23:34 +0000 | [diff] [blame] | 89 | IDEBus *bus = DO_UPCAST(IDEBus, qbus, qdev->parent_bus); |
| 90 | |
Gerd Hoffmann | da4d041 | 2009-09-15 19:23:34 +0000 | [diff] [blame] | 91 | if (dev->unit == -1) { |
| 92 | dev->unit = bus->master ? 1 : 0; |
| 93 | } |
Kevin Wolf | 0ee20e6 | 2013-05-06 15:58:04 +0200 | [diff] [blame] | 94 | |
| 95 | if (dev->unit >= bus->max_units) { |
Mao Zhongyi | 794939e | 2017-09-18 22:05:13 +0800 | [diff] [blame] | 96 | error_setg(errp, "Can't create IDE unit %d, bus supports only %d units", |
Kevin Wolf | 0ee20e6 | 2013-05-06 15:58:04 +0200 | [diff] [blame] | 97 | dev->unit, bus->max_units); |
Mao Zhongyi | 794939e | 2017-09-18 22:05:13 +0800 | [diff] [blame] | 98 | return; |
Kevin Wolf | 0ee20e6 | 2013-05-06 15:58:04 +0200 | [diff] [blame] | 99 | } |
| 100 | |
Gerd Hoffmann | da4d041 | 2009-09-15 19:23:34 +0000 | [diff] [blame] | 101 | switch (dev->unit) { |
| 102 | case 0: |
| 103 | if (bus->master) { |
Mao Zhongyi | 794939e | 2017-09-18 22:05:13 +0800 | [diff] [blame] | 104 | error_setg(errp, "IDE unit %d is in use", dev->unit); |
| 105 | return; |
Gerd Hoffmann | da4d041 | 2009-09-15 19:23:34 +0000 | [diff] [blame] | 106 | } |
| 107 | bus->master = dev; |
| 108 | break; |
| 109 | case 1: |
| 110 | if (bus->slave) { |
Mao Zhongyi | 794939e | 2017-09-18 22:05:13 +0800 | [diff] [blame] | 111 | error_setg(errp, "IDE unit %d is in use", dev->unit); |
| 112 | return; |
Gerd Hoffmann | da4d041 | 2009-09-15 19:23:34 +0000 | [diff] [blame] | 113 | } |
| 114 | bus->slave = dev; |
| 115 | break; |
| 116 | default: |
Mao Zhongyi | 794939e | 2017-09-18 22:05:13 +0800 | [diff] [blame] | 117 | error_setg(errp, "Invalid IDE unit %d", dev->unit); |
| 118 | return; |
Gerd Hoffmann | da4d041 | 2009-09-15 19:23:34 +0000 | [diff] [blame] | 119 | } |
Mao Zhongyi | 794939e | 2017-09-18 22:05:13 +0800 | [diff] [blame] | 120 | dc->realize(dev, errp); |
Gerd Hoffmann | da4d041 | 2009-09-15 19:23:34 +0000 | [diff] [blame] | 121 | } |
| 122 | |
Gerd Hoffmann | da4d041 | 2009-09-15 19:23:34 +0000 | [diff] [blame] | 123 | IDEDevice *ide_create_drive(IDEBus *bus, int unit, DriveInfo *drive) |
| 124 | { |
| 125 | DeviceState *dev; |
| 126 | |
Markus Armbruster | 95b5edc | 2011-05-16 15:04:56 +0200 | [diff] [blame] | 127 | dev = qdev_create(&bus->qbus, drive->media_cd ? "ide-cd" : "ide-hd"); |
Gerd Hoffmann | da4d041 | 2009-09-15 19:23:34 +0000 | [diff] [blame] | 128 | qdev_prop_set_uint32(dev, "unit", unit); |
Markus Armbruster | 6231a6d | 2015-12-10 17:29:15 +0100 | [diff] [blame] | 129 | qdev_prop_set_drive(dev, "drive", blk_by_legacy_dinfo(drive), |
| 130 | &error_fatal); |
Markus Armbruster | fa12fbb | 2010-06-25 18:53:22 +0200 | [diff] [blame] | 131 | qdev_init_nofail(dev); |
Gerd Hoffmann | da4d041 | 2009-09-15 19:23:34 +0000 | [diff] [blame] | 132 | return DO_UPCAST(IDEDevice, qdev, dev); |
| 133 | } |
| 134 | |
Markus Armbruster | 9139046 | 2012-07-10 11:12:38 +0200 | [diff] [blame] | 135 | int ide_get_geometry(BusState *bus, int unit, |
| 136 | int16_t *cyls, int8_t *heads, int8_t *secs) |
Markus Armbruster | c0897e0 | 2010-06-24 19:58:20 +0200 | [diff] [blame] | 137 | { |
Markus Armbruster | 9139046 | 2012-07-10 11:12:38 +0200 | [diff] [blame] | 138 | IDEState *s = &DO_UPCAST(IDEBus, qbus, bus)->ifs[unit]; |
| 139 | |
Markus Armbruster | 4be7463 | 2014-10-07 13:59:18 +0200 | [diff] [blame] | 140 | if (s->drive_kind != IDE_HD || !s->blk) { |
Markus Armbruster | 9139046 | 2012-07-10 11:12:38 +0200 | [diff] [blame] | 141 | return -1; |
| 142 | } |
| 143 | |
| 144 | *cyls = s->cylinders; |
| 145 | *heads = s->heads; |
| 146 | *secs = s->sectors; |
| 147 | return 0; |
| 148 | } |
| 149 | |
| 150 | int ide_get_bios_chs_trans(BusState *bus, int unit) |
| 151 | { |
| 152 | return DO_UPCAST(IDEBus, qbus, bus)->ifs[unit].chs_trans; |
Markus Armbruster | c0897e0 | 2010-06-24 19:58:20 +0200 | [diff] [blame] | 153 | } |
| 154 | |
Gerd Hoffmann | da4d041 | 2009-09-15 19:23:34 +0000 | [diff] [blame] | 155 | /* --------------------------------- */ |
| 156 | |
| 157 | typedef struct IDEDrive { |
| 158 | IDEDevice dev; |
| 159 | } IDEDrive; |
| 160 | |
Mao Zhongyi | 794939e | 2017-09-18 22:05:13 +0800 | [diff] [blame] | 161 | static void ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind, Error **errp) |
Gerd Hoffmann | da4d041 | 2009-09-15 19:23:34 +0000 | [diff] [blame] | 162 | { |
| 163 | IDEBus *bus = DO_UPCAST(IDEBus, qbus, dev->qdev.parent_bus); |
Markus Armbruster | 6ced55a | 2010-06-01 20:32:32 +0200 | [diff] [blame] | 164 | IDEState *s = bus->ifs + dev->unit; |
Kevin Wolf | 947231a | 2017-07-11 14:04:08 +0200 | [diff] [blame] | 165 | int ret; |
Markus Armbruster | 6ced55a | 2010-06-01 20:32:32 +0200 | [diff] [blame] | 166 | |
Kevin Wolf | 67c75f3 | 2016-07-14 15:49:42 +0200 | [diff] [blame] | 167 | if (!dev->conf.blk) { |
| 168 | if (kind != IDE_CD) { |
Mao Zhongyi | 794939e | 2017-09-18 22:05:13 +0800 | [diff] [blame] | 169 | error_setg(errp, "No drive specified"); |
| 170 | return; |
Kevin Wolf | 67c75f3 | 2016-07-14 15:49:42 +0200 | [diff] [blame] | 171 | } else { |
| 172 | /* Anonymous BlockBackend for an empty drive */ |
Kevin Wolf | d861ab3 | 2019-04-25 14:25:10 +0200 | [diff] [blame] | 173 | dev->conf.blk = blk_new(qemu_get_aio_context(), 0, BLK_PERM_ALL); |
Kevin Wolf | 947231a | 2017-07-11 14:04:08 +0200 | [diff] [blame] | 174 | ret = blk_attach_dev(dev->conf.blk, &dev->qdev); |
| 175 | assert(ret == 0); |
Kevin Wolf | 67c75f3 | 2016-07-14 15:49:42 +0200 | [diff] [blame] | 176 | } |
| 177 | } |
| 178 | |
Paolo Bonzini | 215e47b | 2013-02-08 14:06:14 +0100 | [diff] [blame] | 179 | 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 Zhongyi | 794939e | 2017-09-18 22:05:13 +0800 | [diff] [blame] | 183 | error_setg(errp, "discard_granularity must be 512 for ide"); |
| 184 | return; |
Christoph Hellwig | d353fb7 | 2011-05-19 10:58:19 +0200 | [diff] [blame] | 185 | } |
| 186 | |
Ekaterina Tumanova | 0eb28a4 | 2015-02-16 12:47:58 +0100 | [diff] [blame] | 187 | blkconf_blocksizes(&dev->conf); |
Kevin Wolf | d200518 | 2014-12-03 13:21:32 +0100 | [diff] [blame] | 188 | if (dev->conf.logical_block_size != 512) { |
Mao Zhongyi | 794939e | 2017-09-18 22:05:13 +0800 | [diff] [blame] | 189 | error_setg(errp, "logical_block_size must be 512 for IDE"); |
| 190 | return; |
Kevin Wolf | d200518 | 2014-12-03 13:21:32 +0100 | [diff] [blame] | 191 | } |
| 192 | |
Fam Zheng | 5ff5efb | 2014-08-12 10:12:54 +0800 | [diff] [blame] | 193 | if (kind != IDE_CD) { |
Mao Zhongyi | ceff3e1 | 2017-11-22 11:08:45 +0800 | [diff] [blame] | 194 | if (!blkconf_geometry(&dev->conf, &dev->chs_trans, 65535, 16, 255, |
| 195 | errp)) { |
Mao Zhongyi | 794939e | 2017-09-18 22:05:13 +0800 | [diff] [blame] | 196 | return; |
Fam Zheng | 5ff5efb | 2014-08-12 10:12:54 +0800 | [diff] [blame] | 197 | } |
Markus Armbruster | ba80196 | 2012-07-10 11:12:44 +0200 | [diff] [blame] | 198 | } |
Mao Zhongyi | ceff3e1 | 2017-11-22 11:08:45 +0800 | [diff] [blame] | 199 | if (!blkconf_apply_backend_options(&dev->conf, kind == IDE_CD, |
| 200 | kind != IDE_CD, errp)) { |
Mao Zhongyi | 794939e | 2017-09-18 22:05:13 +0800 | [diff] [blame] | 201 | return; |
Kevin Wolf | a17c17a | 2017-01-24 13:43:31 +0100 | [diff] [blame] | 202 | } |
Markus Armbruster | ba80196 | 2012-07-10 11:12:44 +0200 | [diff] [blame] | 203 | |
Markus Armbruster | 4be7463 | 2014-10-07 13:59:18 +0200 | [diff] [blame] | 204 | if (ide_init_drive(s, dev->conf.blk, kind, |
Markus Armbruster | 911525d | 2012-07-11 15:08:37 +0200 | [diff] [blame] | 205 | dev->version, dev->serial, dev->model, dev->wwn, |
Markus Armbruster | ba80196 | 2012-07-10 11:12:44 +0200 | [diff] [blame] | 206 | dev->conf.cyls, dev->conf.heads, dev->conf.secs, |
Mao Zhongyi | 794939e | 2017-09-18 22:05:13 +0800 | [diff] [blame] | 207 | dev->chs_trans, errp) < 0) { |
| 208 | return; |
Markus Armbruster | c4d74df | 2010-06-28 19:07:51 +0200 | [diff] [blame] | 209 | } |
Markus Armbruster | 6ced55a | 2010-06-01 20:32:32 +0200 | [diff] [blame] | 210 | |
Markus Armbruster | 0343240 | 2010-06-01 20:32:33 +0200 | [diff] [blame] | 211 | if (!dev->version) { |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 212 | dev->version = g_strdup(s->version); |
Markus Armbruster | 0343240 | 2010-06-01 20:32:33 +0200 | [diff] [blame] | 213 | } |
Markus Armbruster | 6ced55a | 2010-06-01 20:32:32 +0200 | [diff] [blame] | 214 | if (!dev->serial) { |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 215 | dev->serial = g_strdup(s->drive_serial_str); |
Markus Armbruster | 6ced55a | 2010-06-01 20:32:32 +0200 | [diff] [blame] | 216 | } |
Gleb Natapov | 1ca4d09 | 2010-12-08 13:35:05 +0200 | [diff] [blame] | 217 | |
| 218 | add_boot_device_path(dev->conf.bootindex, &dev->qdev, |
| 219 | dev->unit ? "/disk@1" : "/disk@0"); |
Gerd Hoffmann | da4d041 | 2009-09-15 19:23:34 +0000 | [diff] [blame] | 220 | } |
| 221 | |
Eric Blake | d7bce99 | 2016-01-29 06:48:55 -0700 | [diff] [blame] | 222 | static void ide_dev_get_bootindex(Object *obj, Visitor *v, const char *name, |
| 223 | void *opaque, Error **errp) |
Gonglei | 4556363 | 2014-10-07 16:00:29 +0800 | [diff] [blame] | 224 | { |
| 225 | IDEDevice *d = IDE_DEVICE(obj); |
| 226 | |
Eric Blake | 51e72bc | 2016-01-29 06:48:54 -0700 | [diff] [blame] | 227 | visit_type_int32(v, name, &d->conf.bootindex, errp); |
Gonglei | 4556363 | 2014-10-07 16:00:29 +0800 | [diff] [blame] | 228 | } |
| 229 | |
Eric Blake | d7bce99 | 2016-01-29 06:48:55 -0700 | [diff] [blame] | 230 | static void ide_dev_set_bootindex(Object *obj, Visitor *v, const char *name, |
| 231 | void *opaque, Error **errp) |
Gonglei | 4556363 | 2014-10-07 16:00:29 +0800 | [diff] [blame] | 232 | { |
| 233 | IDEDevice *d = IDE_DEVICE(obj); |
| 234 | int32_t boot_index; |
| 235 | Error *local_err = NULL; |
| 236 | |
Eric Blake | 51e72bc | 2016-01-29 06:48:54 -0700 | [diff] [blame] | 237 | visit_type_int32(v, name, &boot_index, &local_err); |
Gonglei | 4556363 | 2014-10-07 16:00:29 +0800 | [diff] [blame] | 238 | 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 | |
Gonglei | d2b186f | 2014-10-07 16:00:35 +0800 | [diff] [blame] | 249 | if (d->unit != -1) { |
| 250 | add_boot_device_path(d->conf.bootindex, &d->qdev, |
| 251 | d->unit ? "/disk@1" : "/disk@0"); |
| 252 | } |
Gonglei | 4556363 | 2014-10-07 16:00:29 +0800 | [diff] [blame] | 253 | out: |
Eduardo Habkost | 621ff94 | 2016-06-13 18:57:56 -0300 | [diff] [blame] | 254 | error_propagate(errp, local_err); |
Gonglei | 4556363 | 2014-10-07 16:00:29 +0800 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | static 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); |
Gonglei | d2b186f | 2014-10-07 16:00:35 +0800 | [diff] [blame] | 262 | object_property_set_int(obj, -1, "bootindex", NULL); |
Gonglei | 4556363 | 2014-10-07 16:00:29 +0800 | [diff] [blame] | 263 | } |
| 264 | |
Mao Zhongyi | 794939e | 2017-09-18 22:05:13 +0800 | [diff] [blame] | 265 | static void ide_hd_realize(IDEDevice *dev, Error **errp) |
Markus Armbruster | 1f56e32 | 2011-05-16 15:04:52 +0200 | [diff] [blame] | 266 | { |
Mao Zhongyi | 794939e | 2017-09-18 22:05:13 +0800 | [diff] [blame] | 267 | ide_dev_initfn(dev, IDE_HD, errp); |
Markus Armbruster | 1f56e32 | 2011-05-16 15:04:52 +0200 | [diff] [blame] | 268 | } |
| 269 | |
Mao Zhongyi | 794939e | 2017-09-18 22:05:13 +0800 | [diff] [blame] | 270 | static void ide_cd_realize(IDEDevice *dev, Error **errp) |
Markus Armbruster | 1f56e32 | 2011-05-16 15:04:52 +0200 | [diff] [blame] | 271 | { |
Mao Zhongyi | 794939e | 2017-09-18 22:05:13 +0800 | [diff] [blame] | 272 | ide_dev_initfn(dev, IDE_CD, errp); |
Markus Armbruster | 1f56e32 | 2011-05-16 15:04:52 +0200 | [diff] [blame] | 273 | } |
| 274 | |
Mao Zhongyi | 794939e | 2017-09-18 22:05:13 +0800 | [diff] [blame] | 275 | static void ide_drive_realize(IDEDevice *dev, Error **errp) |
Markus Armbruster | 1f56e32 | 2011-05-16 15:04:52 +0200 | [diff] [blame] | 276 | { |
Kevin Wolf | 67c75f3 | 2016-07-14 15:49:42 +0200 | [diff] [blame] | 277 | DriveInfo *dinfo = NULL; |
| 278 | |
| 279 | if (dev->conf.blk) { |
| 280 | dinfo = blk_legacy_dinfo(dev->conf.blk); |
| 281 | } |
Markus Armbruster | 95b5edc | 2011-05-16 15:04:56 +0200 | [diff] [blame] | 282 | |
Mao Zhongyi | 794939e | 2017-09-18 22:05:13 +0800 | [diff] [blame] | 283 | ide_dev_initfn(dev, dinfo && dinfo->media_cd ? IDE_CD : IDE_HD, errp); |
Markus Armbruster | 1f56e32 | 2011-05-16 15:04:52 +0200 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | #define DEFINE_IDE_DEV_PROPERTIES() \ |
Markus Armbruster | 1f56e32 | 2011-05-16 15:04:52 +0200 | [diff] [blame] | 287 | DEFINE_BLOCK_PROPERTIES(IDEDrive, dev.conf), \ |
Kevin Wolf | 8c39825 | 2016-06-29 17:41:35 +0200 | [diff] [blame] | 288 | DEFINE_BLOCK_ERROR_PROPERTIES(IDEDrive, dev.conf), \ |
Markus Armbruster | 1f56e32 | 2011-05-16 15:04:52 +0200 | [diff] [blame] | 289 | DEFINE_PROP_STRING("ver", IDEDrive, dev.version), \ |
Paolo Bonzini | c7bcc85 | 2014-02-08 11:01:53 +0100 | [diff] [blame] | 290 | DEFINE_PROP_UINT64("wwn", IDEDrive, dev.wwn, 0), \ |
Floris Bos | 27e0c9a | 2012-03-12 21:05:09 +0100 | [diff] [blame] | 291 | DEFINE_PROP_STRING("serial", IDEDrive, dev.serial),\ |
| 292 | DEFINE_PROP_STRING("model", IDEDrive, dev.model) |
Markus Armbruster | 1f56e32 | 2011-05-16 15:04:52 +0200 | [diff] [blame] | 293 | |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 294 | static Property ide_hd_properties[] = { |
| 295 | DEFINE_IDE_DEV_PROPERTIES(), |
Markus Armbruster | ba80196 | 2012-07-10 11:12:44 +0200 | [diff] [blame] | 296 | DEFINE_BLOCK_CHS_PROPERTIES(IDEDrive, dev.conf), |
Markus Armbruster | 6e6f61a | 2012-07-10 11:12:48 +0200 | [diff] [blame] | 297 | DEFINE_PROP_BIOS_CHS_TRANS("bios-chs-trans", |
| 298 | IDEDrive, dev.chs_trans, BIOS_ATA_TRANSLATION_AUTO), |
Daniel P. Berrange | 3b19f45 | 2017-10-04 12:40:08 +0100 | [diff] [blame] | 299 | DEFINE_PROP_UINT16("rotation_rate", IDEDrive, dev.rotation_rate, 0), |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 300 | DEFINE_PROP_END_OF_LIST(), |
| 301 | }; |
| 302 | |
Anthony Liguori | d148211 | 2011-12-16 13:41:12 -0600 | [diff] [blame] | 303 | static void ide_hd_class_init(ObjectClass *klass, void *data) |
| 304 | { |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 305 | DeviceClass *dc = DEVICE_CLASS(klass); |
Anthony Liguori | d148211 | 2011-12-16 13:41:12 -0600 | [diff] [blame] | 306 | IDEDeviceClass *k = IDE_DEVICE_CLASS(klass); |
Mao Zhongyi | 794939e | 2017-09-18 22:05:13 +0800 | [diff] [blame] | 307 | |
| 308 | k->realize = ide_hd_realize; |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 309 | dc->fw_name = "drive"; |
Mao Zhongyi | 794939e | 2017-09-18 22:05:13 +0800 | [diff] [blame] | 310 | dc->desc = "virtual IDE disk"; |
| 311 | dc->props = ide_hd_properties; |
Anthony Liguori | d148211 | 2011-12-16 13:41:12 -0600 | [diff] [blame] | 312 | } |
| 313 | |
Andreas Färber | 8c43a6f | 2013-01-10 16:19:07 +0100 | [diff] [blame] | 314 | static const TypeInfo ide_hd_info = { |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 315 | .name = "ide-hd", |
| 316 | .parent = TYPE_IDE_DEVICE, |
| 317 | .instance_size = sizeof(IDEDrive), |
| 318 | .class_init = ide_hd_class_init, |
| 319 | }; |
| 320 | |
| 321 | static Property ide_cd_properties[] = { |
| 322 | DEFINE_IDE_DEV_PROPERTIES(), |
| 323 | DEFINE_PROP_END_OF_LIST(), |
Gerd Hoffmann | da4d041 | 2009-09-15 19:23:34 +0000 | [diff] [blame] | 324 | }; |
| 325 | |
Anthony Liguori | d148211 | 2011-12-16 13:41:12 -0600 | [diff] [blame] | 326 | static void ide_cd_class_init(ObjectClass *klass, void *data) |
| 327 | { |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 328 | DeviceClass *dc = DEVICE_CLASS(klass); |
Anthony Liguori | d148211 | 2011-12-16 13:41:12 -0600 | [diff] [blame] | 329 | IDEDeviceClass *k = IDE_DEVICE_CLASS(klass); |
Mao Zhongyi | 794939e | 2017-09-18 22:05:13 +0800 | [diff] [blame] | 330 | |
| 331 | k->realize = ide_cd_realize; |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 332 | dc->fw_name = "drive"; |
Mao Zhongyi | 794939e | 2017-09-18 22:05:13 +0800 | [diff] [blame] | 333 | dc->desc = "virtual IDE CD-ROM"; |
| 334 | dc->props = ide_cd_properties; |
Anthony Liguori | d148211 | 2011-12-16 13:41:12 -0600 | [diff] [blame] | 335 | } |
| 336 | |
Andreas Färber | 8c43a6f | 2013-01-10 16:19:07 +0100 | [diff] [blame] | 337 | static const TypeInfo ide_cd_info = { |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 338 | .name = "ide-cd", |
| 339 | .parent = TYPE_IDE_DEVICE, |
| 340 | .instance_size = sizeof(IDEDrive), |
| 341 | .class_init = ide_cd_class_init, |
| 342 | }; |
| 343 | |
| 344 | static Property ide_drive_properties[] = { |
| 345 | DEFINE_IDE_DEV_PROPERTIES(), |
| 346 | DEFINE_PROP_END_OF_LIST(), |
Anthony Liguori | d148211 | 2011-12-16 13:41:12 -0600 | [diff] [blame] | 347 | }; |
| 348 | |
| 349 | static void ide_drive_class_init(ObjectClass *klass, void *data) |
| 350 | { |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 351 | DeviceClass *dc = DEVICE_CLASS(klass); |
Anthony Liguori | d148211 | 2011-12-16 13:41:12 -0600 | [diff] [blame] | 352 | IDEDeviceClass *k = IDE_DEVICE_CLASS(klass); |
Mao Zhongyi | 794939e | 2017-09-18 22:05:13 +0800 | [diff] [blame] | 353 | |
| 354 | k->realize = ide_drive_realize; |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 355 | dc->fw_name = "drive"; |
Mao Zhongyi | 794939e | 2017-09-18 22:05:13 +0800 | [diff] [blame] | 356 | dc->desc = "virtual IDE disk or CD-ROM (legacy)"; |
| 357 | dc->props = ide_drive_properties; |
Anthony Liguori | d148211 | 2011-12-16 13:41:12 -0600 | [diff] [blame] | 358 | } |
| 359 | |
Andreas Färber | 8c43a6f | 2013-01-10 16:19:07 +0100 | [diff] [blame] | 360 | static const TypeInfo ide_drive_info = { |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 361 | .name = "ide-drive", |
| 362 | .parent = TYPE_IDE_DEVICE, |
| 363 | .instance_size = sizeof(IDEDrive), |
| 364 | .class_init = ide_drive_class_init, |
Anthony Liguori | d148211 | 2011-12-16 13:41:12 -0600 | [diff] [blame] | 365 | }; |
| 366 | |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 367 | static void ide_device_class_init(ObjectClass *klass, void *data) |
| 368 | { |
| 369 | DeviceClass *k = DEVICE_CLASS(klass); |
Mao Zhongyi | 794939e | 2017-09-18 22:05:13 +0800 | [diff] [blame] | 370 | k->realize = ide_qdev_realize; |
Marcel Apfelbaum | 125ee0e | 2013-07-29 17:17:45 +0300 | [diff] [blame] | 371 | set_bit(DEVICE_CATEGORY_STORAGE, k->categories); |
Anthony Liguori | 0d93692 | 2012-05-02 09:00:20 +0200 | [diff] [blame] | 372 | k->bus_type = TYPE_IDE_BUS; |
Paolo Bonzini | bce5447 | 2012-03-28 18:12:47 +0200 | [diff] [blame] | 373 | k->props = ide_props; |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 374 | } |
| 375 | |
Andreas Färber | 8c43a6f | 2013-01-10 16:19:07 +0100 | [diff] [blame] | 376 | static const TypeInfo ide_device_type_info = { |
Anthony Liguori | d148211 | 2011-12-16 13:41:12 -0600 | [diff] [blame] | 377 | .name = TYPE_IDE_DEVICE, |
| 378 | .parent = TYPE_DEVICE, |
| 379 | .instance_size = sizeof(IDEDevice), |
| 380 | .abstract = true, |
| 381 | .class_size = sizeof(IDEDeviceClass), |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 382 | .class_init = ide_device_class_init, |
Gonglei | 4556363 | 2014-10-07 16:00:29 +0800 | [diff] [blame] | 383 | .instance_init = ide_dev_instance_init, |
Anthony Liguori | d148211 | 2011-12-16 13:41:12 -0600 | [diff] [blame] | 384 | }; |
| 385 | |
Andreas Färber | 83f7d43 | 2012-02-09 15:20:55 +0100 | [diff] [blame] | 386 | static void ide_register_types(void) |
Gerd Hoffmann | da4d041 | 2009-09-15 19:23:34 +0000 | [diff] [blame] | 387 | { |
Anthony Liguori | 0d93692 | 2012-05-02 09:00:20 +0200 | [diff] [blame] | 388 | type_register_static(&ide_bus_info); |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 389 | type_register_static(&ide_hd_info); |
| 390 | type_register_static(&ide_cd_info); |
| 391 | type_register_static(&ide_drive_info); |
Anthony Liguori | d148211 | 2011-12-16 13:41:12 -0600 | [diff] [blame] | 392 | type_register_static(&ide_device_type_info); |
Gerd Hoffmann | da4d041 | 2009-09-15 19:23:34 +0000 | [diff] [blame] | 393 | } |
Andreas Färber | 83f7d43 | 2012-02-09 15:20:55 +0100 | [diff] [blame] | 394 | |
| 395 | type_init(ide_register_types) |