2009-09-15 21:23:34 +02:00
|
|
|
/*
|
|
|
|
* ide bus support for qdev.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2009 Gerd Hoffmann <kraxel@redhat.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2020-10-23 14:44:24 +02:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2009-09-15 21:23:34 +02:00
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2019-05-23 16:35:07 +02:00
|
|
|
|
2016-01-26 19:17:09 +01:00
|
|
|
#include "qemu/osdep.h"
|
2012-12-17 18:20:04 +01:00
|
|
|
#include "sysemu/dma.h"
|
include/qemu/osdep.h: Don't include qapi/error.h
Commit 57cb38b included qapi/error.h into qemu/osdep.h to get the
Error typedef. Since then, we've moved to include qemu/osdep.h
everywhere. Its file comment explains: "To avoid getting into
possible circular include dependencies, this file should not include
any other QEMU headers, with the exceptions of config-host.h,
compiler.h, os-posix.h and os-win32.h, all of which are doing a
similar job to this file and are under similar constraints."
qapi/error.h doesn't do a similar job, and it doesn't adhere to
similar constraints: it includes qapi-types.h. That's in excess of
100KiB of crap most .c files don't actually need.
Add the typedef to qemu/typedefs.h, and include that instead of
qapi/error.h. Include qapi/error.h in .c files that need it and don't
get it now. Include qapi-types.h in qom/object.h for uint16List.
Update scripts/clean-includes accordingly. Update it further to match
reality: replace config.h by config-target.h, add sysemu/os-posix.h,
sysemu/os-win32.h. Update the list of includes in the qemu/osdep.h
comment quoted above similarly.
This reduces the number of objects depending on qapi/error.h from "all
of them" to less than a third. Unfortunately, the number depending on
qapi-types.h shrinks only a little. More work is needed for that one.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
[Fix compilation without the spice devel packages. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-03-14 09:01:28 +01:00
|
|
|
#include "qapi/error.h"
|
2019-08-12 07:23:32 +02:00
|
|
|
#include "qapi/qapi-types-block.h"
|
2012-12-17 18:20:00 +01:00
|
|
|
#include "qemu/error-report.h"
|
Include qemu/main-loop.h less
In my "build everything" tree, changing qemu/main-loop.h triggers a
recompile of some 5600 out of 6600 objects (not counting tests and
objects that don't depend on qemu/osdep.h). It includes block/aio.h,
which in turn includes qemu/event_notifier.h, qemu/notify.h,
qemu/processor.h, qemu/qsp.h, qemu/queue.h, qemu/thread-posix.h,
qemu/thread.h, qemu/timer.h, and a few more.
Include qemu/main-loop.h only where it's needed. Touching it now
recompiles only some 1700 objects. For block/aio.h and
qemu/event_notifier.h, these numbers drop from 5600 to 2800. For the
others, they shrink only slightly.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20190812052359.30071-21-armbru@redhat.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
2019-08-12 07:23:50 +02:00
|
|
|
#include "qemu/main-loop.h"
|
2019-05-23 16:35:07 +02:00
|
|
|
#include "qemu/module.h"
|
2016-06-22 19:11:19 +02:00
|
|
|
#include "hw/ide/internal.h"
|
2019-08-12 07:23:51 +02:00
|
|
|
#include "hw/qdev-properties.h"
|
2020-12-11 23:05:12 +01:00
|
|
|
#include "hw/qdev-properties-system.h"
|
2014-10-07 13:59:13 +02:00
|
|
|
#include "sysemu/block-backend.h"
|
2012-12-17 18:20:04 +01:00
|
|
|
#include "sysemu/blockdev.h"
|
2013-02-05 17:06:20 +01:00
|
|
|
#include "hw/block/block.h"
|
2012-12-17 18:20:04 +01:00
|
|
|
#include "sysemu/sysemu.h"
|
2019-08-12 07:23:59 +02:00
|
|
|
#include "sysemu/runstate.h"
|
2014-10-07 10:00:29 +02:00
|
|
|
#include "qapi/visitor.h"
|
2009-09-15 21:23:34 +02:00
|
|
|
|
|
|
|
/* --------------------------------- */
|
|
|
|
|
2010-12-08 12:34:59 +01:00
|
|
|
static char *idebus_get_fw_dev_path(DeviceState *dev);
|
qdev: Unrealize must not fail
Devices may have component devices and buses.
Device realization may fail. Realization is recursive: a device's
realize() method realizes its components, and device_set_realized()
realizes its buses (which should in turn realize the devices on that
bus, except bus_set_realized() doesn't implement that, yet).
When realization of a component or bus fails, we need to roll back:
unrealize everything we realized so far. If any of these unrealizes
failed, the device would be left in an inconsistent state. Must not
happen.
device_set_realized() lets it happen: it ignores errors in the roll
back code starting at label child_realize_fail.
Since realization is recursive, unrealization must be recursive, too.
But how could a partly failed unrealize be rolled back? We'd have to
re-realize, which can fail. This design is fundamentally broken.
device_set_realized() does not roll back at all. Instead, it keeps
unrealizing, ignoring further errors.
It can screw up even for a device with no buses: if the lone
dc->unrealize() fails, it still unregisters vmstate, and calls
listeners' unrealize() callback.
bus_set_realized() does not roll back either. Instead, it stops
unrealizing.
Fortunately, no unrealize method can fail, as we'll see below.
To fix the design error, drop parameter @errp from all the unrealize
methods.
Any unrealize method that uses @errp now needs an update. This leads
us to unrealize() methods that can fail. Merely passing it to another
unrealize method cannot cause failure, though. Here are the ones that
do other things with @errp:
* virtio_serial_device_unrealize()
Fails when qbus_set_hotplug_handler() fails, but still does all the
other work. On failure, the device would stay realized with its
resources completely gone. Oops. Can't happen, because
qbus_set_hotplug_handler() can't actually fail here. Pass
&error_abort to qbus_set_hotplug_handler() instead.
* hw/ppc/spapr_drc.c's unrealize()
Fails when object_property_del() fails, but all the other work is
already done. On failure, the device would stay realized with its
vmstate registration gone. Oops. Can't happen, because
object_property_del() can't actually fail here. Pass &error_abort
to object_property_del() instead.
* spapr_phb_unrealize()
Fails and bails out when remove_drcs() fails, but other work is
already done. On failure, the device would stay realized with some
of its resources gone. Oops. remove_drcs() fails only when
chassis_from_bus()'s object_property_get_uint() fails, and it can't
here. Pass &error_abort to remove_drcs() instead.
Therefore, no unrealize method can fail before this patch.
device_set_realized()'s recursive unrealization via bus uses
object_property_set_bool(). Can't drop @errp there, so pass
&error_abort.
We similarly unrealize with object_property_set_bool() elsewhere,
always ignoring errors. Pass &error_abort instead.
Several unrealize methods no longer handle errors from other unrealize
methods: virtio_9p_device_unrealize(),
virtio_input_device_unrealize(), scsi_qdev_unrealize(), ...
Much of the deleted error handling looks wrong anyway.
One unrealize methods no longer ignore such errors:
usb_ehci_pci_exit().
Several realize methods no longer ignore errors when rolling back:
v9fs_device_realize_common(), pci_qdev_unrealize(),
spapr_phb_realize(), usb_qdev_realize(), vfio_ccw_realize(),
virtio_device_realize().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200505152926.18877-17-armbru@redhat.com>
2020-05-05 17:29:24 +02:00
|
|
|
static void idebus_unrealize(BusState *qdev);
|
2010-12-08 12:34:59 +01:00
|
|
|
|
2012-03-28 18:01:36 +02:00
|
|
|
static Property ide_props[] = {
|
|
|
|
DEFINE_PROP_UINT32("unit", IDEDevice, unit, -1),
|
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
2012-05-02 09:00:20 +02:00
|
|
|
static void ide_bus_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
BusClass *k = BUS_CLASS(klass);
|
|
|
|
|
|
|
|
k->get_fw_dev_path = idebus_get_fw_dev_path;
|
2017-03-16 01:50:14 +01:00
|
|
|
k->unrealize = idebus_unrealize;
|
2012-05-02 09:00:20 +02:00
|
|
|
}
|
|
|
|
|
qdev: Unrealize must not fail
Devices may have component devices and buses.
Device realization may fail. Realization is recursive: a device's
realize() method realizes its components, and device_set_realized()
realizes its buses (which should in turn realize the devices on that
bus, except bus_set_realized() doesn't implement that, yet).
When realization of a component or bus fails, we need to roll back:
unrealize everything we realized so far. If any of these unrealizes
failed, the device would be left in an inconsistent state. Must not
happen.
device_set_realized() lets it happen: it ignores errors in the roll
back code starting at label child_realize_fail.
Since realization is recursive, unrealization must be recursive, too.
But how could a partly failed unrealize be rolled back? We'd have to
re-realize, which can fail. This design is fundamentally broken.
device_set_realized() does not roll back at all. Instead, it keeps
unrealizing, ignoring further errors.
It can screw up even for a device with no buses: if the lone
dc->unrealize() fails, it still unregisters vmstate, and calls
listeners' unrealize() callback.
bus_set_realized() does not roll back either. Instead, it stops
unrealizing.
Fortunately, no unrealize method can fail, as we'll see below.
To fix the design error, drop parameter @errp from all the unrealize
methods.
Any unrealize method that uses @errp now needs an update. This leads
us to unrealize() methods that can fail. Merely passing it to another
unrealize method cannot cause failure, though. Here are the ones that
do other things with @errp:
* virtio_serial_device_unrealize()
Fails when qbus_set_hotplug_handler() fails, but still does all the
other work. On failure, the device would stay realized with its
resources completely gone. Oops. Can't happen, because
qbus_set_hotplug_handler() can't actually fail here. Pass
&error_abort to qbus_set_hotplug_handler() instead.
* hw/ppc/spapr_drc.c's unrealize()
Fails when object_property_del() fails, but all the other work is
already done. On failure, the device would stay realized with its
vmstate registration gone. Oops. Can't happen, because
object_property_del() can't actually fail here. Pass &error_abort
to object_property_del() instead.
* spapr_phb_unrealize()
Fails and bails out when remove_drcs() fails, but other work is
already done. On failure, the device would stay realized with some
of its resources gone. Oops. remove_drcs() fails only when
chassis_from_bus()'s object_property_get_uint() fails, and it can't
here. Pass &error_abort to remove_drcs() instead.
Therefore, no unrealize method can fail before this patch.
device_set_realized()'s recursive unrealization via bus uses
object_property_set_bool(). Can't drop @errp there, so pass
&error_abort.
We similarly unrealize with object_property_set_bool() elsewhere,
always ignoring errors. Pass &error_abort instead.
Several unrealize methods no longer handle errors from other unrealize
methods: virtio_9p_device_unrealize(),
virtio_input_device_unrealize(), scsi_qdev_unrealize(), ...
Much of the deleted error handling looks wrong anyway.
One unrealize methods no longer ignore such errors:
usb_ehci_pci_exit().
Several realize methods no longer ignore errors when rolling back:
v9fs_device_realize_common(), pci_qdev_unrealize(),
spapr_phb_realize(), usb_qdev_realize(), vfio_ccw_realize(),
virtio_device_realize().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200505152926.18877-17-armbru@redhat.com>
2020-05-05 17:29:24 +02:00
|
|
|
static void idebus_unrealize(BusState *bus)
|
2016-09-27 18:53:32 +02:00
|
|
|
{
|
2017-03-16 01:50:14 +01:00
|
|
|
IDEBus *ibus = IDE_BUS(bus);
|
2016-09-27 18:53:32 +02:00
|
|
|
|
2017-03-16 01:50:14 +01:00
|
|
|
if (ibus->vmstate) {
|
|
|
|
qemu_del_vm_change_state_handler(ibus->vmstate);
|
2016-09-27 18:53:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-02 09:00:20 +02:00
|
|
|
static const TypeInfo ide_bus_info = {
|
|
|
|
.name = TYPE_IDE_BUS,
|
|
|
|
.parent = TYPE_BUS,
|
|
|
|
.instance_size = sizeof(IDEBus),
|
|
|
|
.class_init = ide_bus_class_init,
|
2009-09-15 21:23:34 +02:00
|
|
|
};
|
|
|
|
|
2013-08-23 20:18:50 +02:00
|
|
|
void ide_bus_new(IDEBus *idebus, size_t idebus_size, DeviceState *dev,
|
|
|
|
int bus_id, int max_units)
|
2009-09-15 21:23:34 +02:00
|
|
|
{
|
2013-08-24 00:02:27 +02:00
|
|
|
qbus_create_inplace(idebus, idebus_size, TYPE_IDE_BUS, dev, NULL);
|
2010-12-08 12:34:58 +01:00
|
|
|
idebus->bus_id = bus_id;
|
2013-05-06 15:58:04 +02:00
|
|
|
idebus->max_units = max_units;
|
2009-09-15 21:23:34 +02:00
|
|
|
}
|
|
|
|
|
2010-12-08 12:34:59 +01:00
|
|
|
static char *idebus_get_fw_dev_path(DeviceState *dev)
|
|
|
|
{
|
|
|
|
char path[30];
|
|
|
|
|
2014-08-15 13:32:37 +02:00
|
|
|
snprintf(path, sizeof(path), "%s@%x", qdev_fw_name(dev),
|
2010-12-08 12:34:59 +01:00
|
|
|
((IDEBus*)dev->parent_bus)->bus_id);
|
|
|
|
|
scsi, pci, qdev, isa-bus, sysbus: don't let *_get_fw_dev_path return NULL
Use g_strdup rather than strdup, because the sole caller
(qdev_get_fw_dev_path_helper) assumes it gets non-NULL, and dereferences
it. Besides, in that caller, the allocated buffer is already freed with
g_free, so it's better to allocate with a matching g_strdup.
In one case, (scsi-bus.c) it was trivial, so I replaced an snprintf+
g_strdup combination with an equivalent g_strdup_printf use.
Signed-off-by: Jim Meyering <meyering@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-10-04 13:09:44 +02:00
|
|
|
return g_strdup(path);
|
2010-12-08 12:34:59 +01:00
|
|
|
}
|
|
|
|
|
2017-09-18 16:05:13 +02:00
|
|
|
static void ide_qdev_realize(DeviceState *qdev, Error **errp)
|
2009-09-15 21:23:34 +02:00
|
|
|
{
|
2011-12-16 20:41:12 +01:00
|
|
|
IDEDevice *dev = IDE_DEVICE(qdev);
|
|
|
|
IDEDeviceClass *dc = IDE_DEVICE_GET_CLASS(dev);
|
2009-09-15 21:23:34 +02:00
|
|
|
IDEBus *bus = DO_UPCAST(IDEBus, qbus, qdev->parent_bus);
|
|
|
|
|
|
|
|
if (dev->unit == -1) {
|
|
|
|
dev->unit = bus->master ? 1 : 0;
|
|
|
|
}
|
2013-05-06 15:58:04 +02:00
|
|
|
|
|
|
|
if (dev->unit >= bus->max_units) {
|
2017-09-18 16:05:13 +02:00
|
|
|
error_setg(errp, "Can't create IDE unit %d, bus supports only %d units",
|
2013-05-06 15:58:04 +02:00
|
|
|
dev->unit, bus->max_units);
|
2017-09-18 16:05:13 +02:00
|
|
|
return;
|
2013-05-06 15:58:04 +02:00
|
|
|
}
|
|
|
|
|
2009-09-15 21:23:34 +02:00
|
|
|
switch (dev->unit) {
|
|
|
|
case 0:
|
|
|
|
if (bus->master) {
|
2017-09-18 16:05:13 +02:00
|
|
|
error_setg(errp, "IDE unit %d is in use", dev->unit);
|
|
|
|
return;
|
2009-09-15 21:23:34 +02:00
|
|
|
}
|
|
|
|
bus->master = dev;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if (bus->slave) {
|
2017-09-18 16:05:13 +02:00
|
|
|
error_setg(errp, "IDE unit %d is in use", dev->unit);
|
|
|
|
return;
|
2009-09-15 21:23:34 +02:00
|
|
|
}
|
|
|
|
bus->slave = dev;
|
|
|
|
break;
|
|
|
|
default:
|
2017-09-18 16:05:13 +02:00
|
|
|
error_setg(errp, "Invalid IDE unit %d", dev->unit);
|
|
|
|
return;
|
2009-09-15 21:23:34 +02:00
|
|
|
}
|
2017-09-18 16:05:13 +02:00
|
|
|
dc->realize(dev, errp);
|
2009-09-15 21:23:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
IDEDevice *ide_create_drive(IDEBus *bus, int unit, DriveInfo *drive)
|
|
|
|
{
|
|
|
|
DeviceState *dev;
|
|
|
|
|
qdev: Convert uses of qdev_create() with Coccinelle
This is the transformation explained in the commit before previous.
Takes care of just one pattern that needs conversion. More to come in
this series.
Coccinelle script:
@ depends on !(file in "hw/arm/highbank.c")@
expression bus, type_name, dev, expr;
@@
- dev = qdev_create(bus, type_name);
+ dev = qdev_new(type_name);
... when != dev = expr
- qdev_init_nofail(dev);
+ qdev_realize_and_unref(dev, bus, &error_fatal);
@@
expression bus, type_name, dev, expr;
identifier DOWN;
@@
- dev = DOWN(qdev_create(bus, type_name));
+ dev = DOWN(qdev_new(type_name));
... when != dev = expr
- qdev_init_nofail(DEVICE(dev));
+ qdev_realize_and_unref(DEVICE(dev), bus, &error_fatal);
@@
expression bus, type_name, expr;
identifier dev;
@@
- DeviceState *dev = qdev_create(bus, type_name);
+ DeviceState *dev = qdev_new(type_name);
... when != dev = expr
- qdev_init_nofail(dev);
+ qdev_realize_and_unref(dev, bus, &error_fatal);
@@
expression bus, type_name, dev, expr, errp;
symbol true;
@@
- dev = qdev_create(bus, type_name);
+ dev = qdev_new(type_name);
... when != dev = expr
- object_property_set_bool(OBJECT(dev), true, "realized", errp);
+ qdev_realize_and_unref(dev, bus, errp);
@@
expression bus, type_name, expr, errp;
identifier dev;
symbol true;
@@
- DeviceState *dev = qdev_create(bus, type_name);
+ DeviceState *dev = qdev_new(type_name);
... when != dev = expr
- object_property_set_bool(OBJECT(dev), true, "realized", errp);
+ qdev_realize_and_unref(dev, bus, errp);
The first rule exempts hw/arm/highbank.c, because it matches along two
control flow paths there, with different @type_name. Covered by the
next commit's manual conversions.
Missing #include "qapi/error.h" added manually.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-10-armbru@redhat.com>
[Conflicts in hw/misc/empty_slot.c and hw/sparc/leon3.c resolved]
2020-06-10 07:31:58 +02:00
|
|
|
dev = qdev_new(drive->media_cd ? "ide-cd" : "ide-hd");
|
2009-09-15 21:23:34 +02:00
|
|
|
qdev_prop_set_uint32(dev, "unit", unit);
|
qdev: Make qdev_prop_set_drive() match the other helpers
qdev_prop_set_drive() can fail. None of the other qdev_prop_set_FOO()
can; they abort on error.
To clean up this inconsistency, rename qdev_prop_set_drive() to
qdev_prop_set_drive_err(), and create a qdev_prop_set_drive() that
aborts on error.
Coccinelle script to update callers:
@ depends on !(file in "hw/core/qdev-properties-system.c")@
expression dev, name, value;
symbol error_abort;
@@
- qdev_prop_set_drive(dev, name, value, &error_abort);
+ qdev_prop_set_drive(dev, name, value);
@@
expression dev, name, value, errp;
@@
- qdev_prop_set_drive(dev, name, value, errp);
+ qdev_prop_set_drive_err(dev, name, value, errp);
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20200622094227.1271650-14-armbru@redhat.com>
2020-06-22 11:42:24 +02:00
|
|
|
qdev_prop_set_drive_err(dev, "drive", blk_by_legacy_dinfo(drive),
|
|
|
|
&error_fatal);
|
qdev: Convert uses of qdev_create() with Coccinelle
This is the transformation explained in the commit before previous.
Takes care of just one pattern that needs conversion. More to come in
this series.
Coccinelle script:
@ depends on !(file in "hw/arm/highbank.c")@
expression bus, type_name, dev, expr;
@@
- dev = qdev_create(bus, type_name);
+ dev = qdev_new(type_name);
... when != dev = expr
- qdev_init_nofail(dev);
+ qdev_realize_and_unref(dev, bus, &error_fatal);
@@
expression bus, type_name, dev, expr;
identifier DOWN;
@@
- dev = DOWN(qdev_create(bus, type_name));
+ dev = DOWN(qdev_new(type_name));
... when != dev = expr
- qdev_init_nofail(DEVICE(dev));
+ qdev_realize_and_unref(DEVICE(dev), bus, &error_fatal);
@@
expression bus, type_name, expr;
identifier dev;
@@
- DeviceState *dev = qdev_create(bus, type_name);
+ DeviceState *dev = qdev_new(type_name);
... when != dev = expr
- qdev_init_nofail(dev);
+ qdev_realize_and_unref(dev, bus, &error_fatal);
@@
expression bus, type_name, dev, expr, errp;
symbol true;
@@
- dev = qdev_create(bus, type_name);
+ dev = qdev_new(type_name);
... when != dev = expr
- object_property_set_bool(OBJECT(dev), true, "realized", errp);
+ qdev_realize_and_unref(dev, bus, errp);
@@
expression bus, type_name, expr, errp;
identifier dev;
symbol true;
@@
- DeviceState *dev = qdev_create(bus, type_name);
+ DeviceState *dev = qdev_new(type_name);
... when != dev = expr
- object_property_set_bool(OBJECT(dev), true, "realized", errp);
+ qdev_realize_and_unref(dev, bus, errp);
The first rule exempts hw/arm/highbank.c, because it matches along two
control flow paths there, with different @type_name. Covered by the
next commit's manual conversions.
Missing #include "qapi/error.h" added manually.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-10-armbru@redhat.com>
[Conflicts in hw/misc/empty_slot.c and hw/sparc/leon3.c resolved]
2020-06-10 07:31:58 +02:00
|
|
|
qdev_realize_and_unref(dev, &bus->qbus, &error_fatal);
|
2009-09-15 21:23:34 +02:00
|
|
|
return DO_UPCAST(IDEDevice, qdev, dev);
|
|
|
|
}
|
|
|
|
|
2012-07-10 11:12:38 +02:00
|
|
|
int ide_get_geometry(BusState *bus, int unit,
|
|
|
|
int16_t *cyls, int8_t *heads, int8_t *secs)
|
2010-06-24 19:58:20 +02:00
|
|
|
{
|
2012-07-10 11:12:38 +02:00
|
|
|
IDEState *s = &DO_UPCAST(IDEBus, qbus, bus)->ifs[unit];
|
|
|
|
|
2014-10-07 13:59:18 +02:00
|
|
|
if (s->drive_kind != IDE_HD || !s->blk) {
|
2012-07-10 11:12:38 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*cyls = s->cylinders;
|
|
|
|
*heads = s->heads;
|
|
|
|
*secs = s->sectors;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ide_get_bios_chs_trans(BusState *bus, int unit)
|
|
|
|
{
|
|
|
|
return DO_UPCAST(IDEBus, qbus, bus)->ifs[unit].chs_trans;
|
2010-06-24 19:58:20 +02:00
|
|
|
}
|
|
|
|
|
2009-09-15 21:23:34 +02:00
|
|
|
/* --------------------------------- */
|
|
|
|
|
|
|
|
typedef struct IDEDrive {
|
|
|
|
IDEDevice dev;
|
|
|
|
} IDEDrive;
|
|
|
|
|
2017-09-18 16:05:13 +02:00
|
|
|
static void ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind, Error **errp)
|
2009-09-15 21:23:34 +02:00
|
|
|
{
|
|
|
|
IDEBus *bus = DO_UPCAST(IDEBus, qbus, dev->qdev.parent_bus);
|
2010-06-01 20:32:32 +02:00
|
|
|
IDEState *s = bus->ifs + dev->unit;
|
2017-07-11 14:04:08 +02:00
|
|
|
int ret;
|
2010-06-01 20:32:32 +02:00
|
|
|
|
2016-07-14 15:49:42 +02:00
|
|
|
if (!dev->conf.blk) {
|
|
|
|
if (kind != IDE_CD) {
|
2017-09-18 16:05:13 +02:00
|
|
|
error_setg(errp, "No drive specified");
|
|
|
|
return;
|
2016-07-14 15:49:42 +02:00
|
|
|
} else {
|
|
|
|
/* Anonymous BlockBackend for an empty drive */
|
2019-04-25 14:25:10 +02:00
|
|
|
dev->conf.blk = blk_new(qemu_get_aio_context(), 0, BLK_PERM_ALL);
|
2017-07-11 14:04:08 +02:00
|
|
|
ret = blk_attach_dev(dev->conf.blk, &dev->qdev);
|
|
|
|
assert(ret == 0);
|
2016-07-14 15:49:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-08 14:06:14 +01:00
|
|
|
if (dev->conf.discard_granularity == -1) {
|
|
|
|
dev->conf.discard_granularity = 512;
|
|
|
|
} else if (dev->conf.discard_granularity &&
|
|
|
|
dev->conf.discard_granularity != 512) {
|
2017-09-18 16:05:13 +02:00
|
|
|
error_setg(errp, "discard_granularity must be 512 for ide");
|
|
|
|
return;
|
2011-05-19 10:58:19 +02:00
|
|
|
}
|
|
|
|
|
2020-05-29 00:55:10 +02:00
|
|
|
if (!blkconf_blocksizes(&dev->conf, errp)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-12-03 13:21:32 +01:00
|
|
|
if (dev->conf.logical_block_size != 512) {
|
2017-09-18 16:05:13 +02:00
|
|
|
error_setg(errp, "logical_block_size must be 512 for IDE");
|
|
|
|
return;
|
2014-12-03 13:21:32 +01:00
|
|
|
}
|
|
|
|
|
2014-08-12 04:12:54 +02:00
|
|
|
if (kind != IDE_CD) {
|
2017-11-22 04:08:45 +01:00
|
|
|
if (!blkconf_geometry(&dev->conf, &dev->chs_trans, 65535, 16, 255,
|
|
|
|
errp)) {
|
2017-09-18 16:05:13 +02:00
|
|
|
return;
|
2014-08-12 04:12:54 +02:00
|
|
|
}
|
2012-07-10 11:12:44 +02:00
|
|
|
}
|
2017-11-22 04:08:45 +01:00
|
|
|
if (!blkconf_apply_backend_options(&dev->conf, kind == IDE_CD,
|
|
|
|
kind != IDE_CD, errp)) {
|
2017-09-18 16:05:13 +02:00
|
|
|
return;
|
2017-01-24 13:43:31 +01:00
|
|
|
}
|
2012-07-10 11:12:44 +02:00
|
|
|
|
2014-10-07 13:59:18 +02:00
|
|
|
if (ide_init_drive(s, dev->conf.blk, kind,
|
2012-07-11 15:08:37 +02:00
|
|
|
dev->version, dev->serial, dev->model, dev->wwn,
|
2012-07-10 11:12:44 +02:00
|
|
|
dev->conf.cyls, dev->conf.heads, dev->conf.secs,
|
2017-09-18 16:05:13 +02:00
|
|
|
dev->chs_trans, errp) < 0) {
|
|
|
|
return;
|
2010-06-28 19:07:51 +02:00
|
|
|
}
|
2010-06-01 20:32:32 +02:00
|
|
|
|
2010-06-01 20:32:33 +02:00
|
|
|
if (!dev->version) {
|
2011-08-21 05:09:37 +02:00
|
|
|
dev->version = g_strdup(s->version);
|
2010-06-01 20:32:33 +02:00
|
|
|
}
|
2010-06-01 20:32:32 +02:00
|
|
|
if (!dev->serial) {
|
2011-08-21 05:09:37 +02:00
|
|
|
dev->serial = g_strdup(s->drive_serial_str);
|
2010-06-01 20:32:32 +02:00
|
|
|
}
|
2010-12-08 12:35:05 +01:00
|
|
|
|
|
|
|
add_boot_device_path(dev->conf.bootindex, &dev->qdev,
|
|
|
|
dev->unit ? "/disk@1" : "/disk@0");
|
2019-10-16 18:41:42 +02:00
|
|
|
|
|
|
|
add_boot_device_lchs(&dev->qdev, dev->unit ? "/disk@1" : "/disk@0",
|
|
|
|
dev->conf.lcyls,
|
|
|
|
dev->conf.lheads,
|
|
|
|
dev->conf.lsecs);
|
2009-09-15 21:23:34 +02:00
|
|
|
}
|
|
|
|
|
qom: Swap 'name' next to visitor in ObjectPropertyAccessor
Similar to the previous patch, it's nice to have all functions
in the tree that involve a visitor and a name for conversion to
or from QAPI to consistently stick the 'name' parameter next
to the Visitor parameter.
Done by manually changing include/qom/object.h and qom/object.c,
then running this Coccinelle script and touching up the fallout
(Coccinelle insisted on adding some trailing whitespace).
@ rule1 @
identifier fn;
typedef Object, Visitor, Error;
identifier obj, v, opaque, name, errp;
@@
void fn
- (Object *obj, Visitor *v, void *opaque, const char *name,
+ (Object *obj, Visitor *v, const char *name, void *opaque,
Error **errp) { ... }
@@
identifier rule1.fn;
expression obj, v, opaque, name, errp;
@@
fn(obj, v,
- opaque, name,
+ name, opaque,
errp)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-20-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 14:48:55 +01:00
|
|
|
static void ide_dev_get_bootindex(Object *obj, Visitor *v, const char *name,
|
|
|
|
void *opaque, Error **errp)
|
2014-10-07 10:00:29 +02:00
|
|
|
{
|
|
|
|
IDEDevice *d = IDE_DEVICE(obj);
|
|
|
|
|
qapi: Swap visit_* arguments for consistent 'name' placement
JSON uses "name":value, but many of our visitor interfaces were
called with visit_type_FOO(v, &value, name, errp). This can be
a bit confusing to have to mentally swap the parameter order to
match JSON order. It's particularly bad for visit_start_struct(),
where the 'name' parameter is smack in the middle of the
otherwise-related group of 'obj, kind, size' parameters! It's
time to do a global swap of the parameter ordering, so that the
'name' parameter is always immediately after the Visitor argument.
Additional reason in favor of the swap: the existing include/qjson.h
prefers listing 'name' first in json_prop_*(), and I have plans to
unify that file with the qapi visitors; listing 'name' first in
qapi will minimize churn to the (admittedly few) qjson.h clients.
Later patches will then fix docs, object.h, visitor-impl.h, and
those clients to match.
Done by first patching scripts/qapi*.py by hand to make generated
files do what I want, then by running the following Coccinelle
script to affect the rest of the code base:
$ spatch --sp-file script `git grep -l '\bvisit_' -- '**/*.[ch]'`
I then had to apply some touchups (Coccinelle insisted on TAB
indentation in visitor.h, and botched the signature of
visit_type_enum() by rewriting 'const char *const strings[]' to
the syntactically invalid 'const char*const[] strings'). The
movement of parameters is sufficient to provoke compiler errors
if any callers were missed.
// Part 1: Swap declaration order
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_start_struct
-(TV v, TObj OBJ, T1 ARG1, const char *name, T2 ARG2, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type bool, TV, T1;
identifier ARG1;
@@
bool visit_optional
-(TV v, T1 ARG1, const char *name)
+(TV v, const char *name, T1 ARG1)
{ ... }
@@
type TV, TErr, TObj, T1;
identifier OBJ, ARG1;
@@
void visit_get_next_type
-(TV v, TObj OBJ, T1 ARG1, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, TErr errp)
{ ... }
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_type_enum
-(TV v, TObj OBJ, T1 ARG1, T2 ARG2, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type TV, TErr, TObj;
identifier OBJ;
identifier VISIT_TYPE =~ "^visit_type_";
@@
void VISIT_TYPE
-(TV v, TObj OBJ, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, TErr errp)
{ ... }
// Part 2: swap caller order
@@
expression V, NAME, OBJ, ARG1, ARG2, ERR;
identifier VISIT_TYPE =~ "^visit_type_";
@@
(
-visit_start_struct(V, OBJ, ARG1, NAME, ARG2, ERR)
+visit_start_struct(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-visit_optional(V, ARG1, NAME)
+visit_optional(V, NAME, ARG1)
|
-visit_get_next_type(V, OBJ, ARG1, NAME, ERR)
+visit_get_next_type(V, NAME, OBJ, ARG1, ERR)
|
-visit_type_enum(V, OBJ, ARG1, ARG2, NAME, ERR)
+visit_type_enum(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-VISIT_TYPE(V, OBJ, NAME, ERR)
+VISIT_TYPE(V, NAME, OBJ, ERR)
)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-19-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 14:48:54 +01:00
|
|
|
visit_type_int32(v, name, &d->conf.bootindex, errp);
|
2014-10-07 10:00:29 +02:00
|
|
|
}
|
|
|
|
|
qom: Swap 'name' next to visitor in ObjectPropertyAccessor
Similar to the previous patch, it's nice to have all functions
in the tree that involve a visitor and a name for conversion to
or from QAPI to consistently stick the 'name' parameter next
to the Visitor parameter.
Done by manually changing include/qom/object.h and qom/object.c,
then running this Coccinelle script and touching up the fallout
(Coccinelle insisted on adding some trailing whitespace).
@ rule1 @
identifier fn;
typedef Object, Visitor, Error;
identifier obj, v, opaque, name, errp;
@@
void fn
- (Object *obj, Visitor *v, void *opaque, const char *name,
+ (Object *obj, Visitor *v, const char *name, void *opaque,
Error **errp) { ... }
@@
identifier rule1.fn;
expression obj, v, opaque, name, errp;
@@
fn(obj, v,
- opaque, name,
+ name, opaque,
errp)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-20-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 14:48:55 +01:00
|
|
|
static void ide_dev_set_bootindex(Object *obj, Visitor *v, const char *name,
|
|
|
|
void *opaque, Error **errp)
|
2014-10-07 10:00:29 +02:00
|
|
|
{
|
|
|
|
IDEDevice *d = IDE_DEVICE(obj);
|
|
|
|
int32_t boot_index;
|
|
|
|
Error *local_err = NULL;
|
|
|
|
|
2020-07-07 18:05:47 +02:00
|
|
|
if (!visit_type_int32(v, name, &boot_index, errp)) {
|
|
|
|
return;
|
2014-10-07 10:00:29 +02:00
|
|
|
}
|
|
|
|
/* check whether bootindex is present in fw_boot_order list */
|
|
|
|
check_boot_index(boot_index, &local_err);
|
|
|
|
if (local_err) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
/* change bootindex to a new one */
|
|
|
|
d->conf.bootindex = boot_index;
|
|
|
|
|
2014-10-07 10:00:35 +02:00
|
|
|
if (d->unit != -1) {
|
|
|
|
add_boot_device_path(d->conf.bootindex, &d->qdev,
|
|
|
|
d->unit ? "/disk@1" : "/disk@0");
|
|
|
|
}
|
2014-10-07 10:00:29 +02:00
|
|
|
out:
|
2016-06-13 23:57:56 +02:00
|
|
|
error_propagate(errp, local_err);
|
2014-10-07 10:00:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ide_dev_instance_init(Object *obj)
|
|
|
|
{
|
|
|
|
object_property_add(obj, "bootindex", "int32",
|
|
|
|
ide_dev_get_bootindex,
|
qom: Drop parameter @errp of object_property_add() & friends
The only way object_property_add() can fail is when a property with
the same name already exists. Since our property names are all
hardcoded, failure is a programming error, and the appropriate way to
handle it is passing &error_abort.
Same for its variants, except for object_property_add_child(), which
additionally fails when the child already has a parent. Parentage is
also under program control, so this is a programming error, too.
We have a bit over 500 callers. Almost half of them pass
&error_abort, slightly fewer ignore errors, one test case handles
errors, and the remaining few callers pass them to their own callers.
The previous few commits demonstrated once again that ignoring
programming errors is a bad idea.
Of the few ones that pass on errors, several violate the Error API.
The Error ** argument must be NULL, &error_abort, &error_fatal, or a
pointer to a variable containing NULL. Passing an argument of the
latter kind twice without clearing it in between is wrong: if the
first call sets an error, it no longer points to NULL for the second
call. ich9_pm_add_properties(), sparc32_ledma_realize(),
sparc32_dma_realize(), xilinx_axidma_realize(), xilinx_enet_realize()
are wrong that way.
When the one appropriate choice of argument is &error_abort, letting
users pick the argument is a bad idea.
Drop parameter @errp and assert the preconditions instead.
There's one exception to "duplicate property name is a programming
error": the way object_property_add() implements the magic (and
undocumented) "automatic arrayification". Don't drop @errp there.
Instead, rename object_property_add() to object_property_try_add(),
and add the obvious wrapper object_property_add().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200505152926.18877-15-armbru@redhat.com>
[Two semantic rebase conflicts resolved]
2020-05-05 17:29:22 +02:00
|
|
|
ide_dev_set_bootindex, NULL, NULL);
|
qom: Put name parameter before value / visitor parameter
The object_property_set_FOO() setters take property name and value in
an unusual order:
void object_property_set_FOO(Object *obj, FOO_TYPE value,
const char *name, Error **errp)
Having to pass value before name feels grating. Swap them.
Same for object_property_set(), object_property_get(), and
object_property_parse().
Convert callers with this Coccinelle script:
@@
identifier fun = {
object_property_get, object_property_parse, object_property_set_str,
object_property_set_link, object_property_set_bool,
object_property_set_int, object_property_set_uint, object_property_set,
object_property_set_qobject
};
expression obj, v, name, errp;
@@
- fun(obj, v, name, errp)
+ fun(obj, name, v, errp)
Chokes on hw/arm/musicpal.c's lcd_refresh() with the unhelpful error
message "no position information". Convert that one manually.
Fails to convert hw/arm/armsse.c, because Coccinelle gets confused by
ARMSSE being used both as typedef and function-like macro there.
Convert manually.
Fails to convert hw/rx/rx-gdbsim.c, because Coccinelle gets confused
by RXCPU being used both as typedef and function-like macro there.
Convert manually. The other files using RXCPU that way don't need
conversion.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20200707160613.848843-27-armbru@redhat.com>
[Straightforwad conflict with commit 2336172d9b "audio: set default
value for pcspk.iobase property" resolved]
2020-07-07 18:05:54 +02:00
|
|
|
object_property_set_int(obj, "bootindex", -1, NULL);
|
2014-10-07 10:00:29 +02:00
|
|
|
}
|
|
|
|
|
2017-09-18 16:05:13 +02:00
|
|
|
static void ide_hd_realize(IDEDevice *dev, Error **errp)
|
2011-05-16 15:04:52 +02:00
|
|
|
{
|
2017-09-18 16:05:13 +02:00
|
|
|
ide_dev_initfn(dev, IDE_HD, errp);
|
2011-05-16 15:04:52 +02:00
|
|
|
}
|
|
|
|
|
2017-09-18 16:05:13 +02:00
|
|
|
static void ide_cd_realize(IDEDevice *dev, Error **errp)
|
2011-05-16 15:04:52 +02:00
|
|
|
{
|
2017-09-18 16:05:13 +02:00
|
|
|
ide_dev_initfn(dev, IDE_CD, errp);
|
2011-05-16 15:04:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#define DEFINE_IDE_DEV_PROPERTIES() \
|
|
|
|
DEFINE_BLOCK_PROPERTIES(IDEDrive, dev.conf), \
|
2016-06-29 17:41:35 +02:00
|
|
|
DEFINE_BLOCK_ERROR_PROPERTIES(IDEDrive, dev.conf), \
|
2011-05-16 15:04:52 +02:00
|
|
|
DEFINE_PROP_STRING("ver", IDEDrive, dev.version), \
|
2019-10-16 18:41:37 +02:00
|
|
|
DEFINE_PROP_UINT64("wwn", IDEDrive, dev.wwn, 0), \
|
2012-03-12 21:05:09 +01:00
|
|
|
DEFINE_PROP_STRING("serial", IDEDrive, dev.serial),\
|
|
|
|
DEFINE_PROP_STRING("model", IDEDrive, dev.model)
|
2011-05-16 15:04:52 +02:00
|
|
|
|
2011-12-08 04:34:16 +01:00
|
|
|
static Property ide_hd_properties[] = {
|
|
|
|
DEFINE_IDE_DEV_PROPERTIES(),
|
2012-07-10 11:12:44 +02:00
|
|
|
DEFINE_BLOCK_CHS_PROPERTIES(IDEDrive, dev.conf),
|
2012-07-10 11:12:48 +02:00
|
|
|
DEFINE_PROP_BIOS_CHS_TRANS("bios-chs-trans",
|
|
|
|
IDEDrive, dev.chs_trans, BIOS_ATA_TRANSLATION_AUTO),
|
2017-10-04 13:40:08 +02:00
|
|
|
DEFINE_PROP_UINT16("rotation_rate", IDEDrive, dev.rotation_rate, 0),
|
2011-12-08 04:34:16 +01:00
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
2011-12-16 20:41:12 +01:00
|
|
|
static void ide_hd_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2011-12-16 20:41:12 +01:00
|
|
|
IDEDeviceClass *k = IDE_DEVICE_CLASS(klass);
|
2017-09-18 16:05:13 +02:00
|
|
|
|
|
|
|
k->realize = ide_hd_realize;
|
2011-12-08 04:34:16 +01:00
|
|
|
dc->fw_name = "drive";
|
2017-09-18 16:05:13 +02:00
|
|
|
dc->desc = "virtual IDE disk";
|
2020-01-10 16:30:32 +01:00
|
|
|
device_class_set_props(dc, ide_hd_properties);
|
2011-12-16 20:41:12 +01:00
|
|
|
}
|
|
|
|
|
2013-01-10 16:19:07 +01:00
|
|
|
static const TypeInfo ide_hd_info = {
|
2011-12-08 04:34:16 +01:00
|
|
|
.name = "ide-hd",
|
|
|
|
.parent = TYPE_IDE_DEVICE,
|
|
|
|
.instance_size = sizeof(IDEDrive),
|
|
|
|
.class_init = ide_hd_class_init,
|
|
|
|
};
|
|
|
|
|
|
|
|
static Property ide_cd_properties[] = {
|
|
|
|
DEFINE_IDE_DEV_PROPERTIES(),
|
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
2009-09-15 21:23:34 +02:00
|
|
|
};
|
|
|
|
|
2011-12-16 20:41:12 +01:00
|
|
|
static void ide_cd_class_init(ObjectClass *klass, void *data)
|
2009-09-15 21:23:34 +02:00
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2011-12-16 20:41:12 +01:00
|
|
|
IDEDeviceClass *k = IDE_DEVICE_CLASS(klass);
|
2017-09-18 16:05:13 +02:00
|
|
|
|
|
|
|
k->realize = ide_cd_realize;
|
2011-12-08 04:34:16 +01:00
|
|
|
dc->fw_name = "drive";
|
2017-09-18 16:05:13 +02:00
|
|
|
dc->desc = "virtual IDE CD-ROM";
|
2020-01-10 16:30:32 +01:00
|
|
|
device_class_set_props(dc, ide_cd_properties);
|
2011-12-16 20:41:12 +01:00
|
|
|
}
|
2011-05-16 15:04:52 +02:00
|
|
|
|
2013-01-10 16:19:07 +01:00
|
|
|
static const TypeInfo ide_cd_info = {
|
2011-12-08 04:34:16 +01:00
|
|
|
.name = "ide-cd",
|
|
|
|
.parent = TYPE_IDE_DEVICE,
|
|
|
|
.instance_size = sizeof(IDEDrive),
|
|
|
|
.class_init = ide_cd_class_init,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void ide_device_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *k = DEVICE_CLASS(klass);
|
2017-09-18 16:05:13 +02:00
|
|
|
k->realize = ide_qdev_realize;
|
2013-07-29 16:17:45 +02:00
|
|
|
set_bit(DEVICE_CATEGORY_STORAGE, k->categories);
|
2012-05-02 09:00:20 +02:00
|
|
|
k->bus_type = TYPE_IDE_BUS;
|
2020-01-10 16:30:32 +01:00
|
|
|
device_class_set_props(k, ide_props);
|
2011-12-08 04:34:16 +01:00
|
|
|
}
|
|
|
|
|
2013-01-10 16:19:07 +01:00
|
|
|
static const TypeInfo ide_device_type_info = {
|
2011-12-16 20:41:12 +01:00
|
|
|
.name = TYPE_IDE_DEVICE,
|
|
|
|
.parent = TYPE_DEVICE,
|
|
|
|
.instance_size = sizeof(IDEDevice),
|
|
|
|
.abstract = true,
|
|
|
|
.class_size = sizeof(IDEDeviceClass),
|
2011-12-08 04:34:16 +01:00
|
|
|
.class_init = ide_device_class_init,
|
2014-10-07 10:00:29 +02:00
|
|
|
.instance_init = ide_dev_instance_init,
|
2011-12-16 20:41:12 +01:00
|
|
|
};
|
|
|
|
|
2012-02-09 15:20:55 +01:00
|
|
|
static void ide_register_types(void)
|
2011-12-16 20:41:12 +01:00
|
|
|
{
|
2012-05-02 09:00:20 +02:00
|
|
|
type_register_static(&ide_bus_info);
|
2011-12-08 04:34:16 +01:00
|
|
|
type_register_static(&ide_hd_info);
|
|
|
|
type_register_static(&ide_cd_info);
|
2011-12-16 20:41:12 +01:00
|
|
|
type_register_static(&ide_device_type_info);
|
2009-09-15 21:23:34 +02:00
|
|
|
}
|
2012-02-09 15:20:55 +01:00
|
|
|
|
|
|
|
type_init(ide_register_types)
|