2009-09-15 23:23:34 +04: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
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
2016-01-26 21:17:09 +03:00
|
|
|
#include "qemu/osdep.h"
|
2016-06-22 20:11:19 +03:00
|
|
|
#include "hw/hw.h"
|
2012-12-17 21:20:04 +04: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 11:01:28 +03:00
|
|
|
#include "qapi/error.h"
|
2012-12-17 21:20:00 +04:00
|
|
|
#include "qemu/error-report.h"
|
2016-06-22 20:11:19 +03:00
|
|
|
#include "hw/ide/internal.h"
|
2014-10-07 15:59:13 +04:00
|
|
|
#include "sysemu/block-backend.h"
|
2012-12-17 21:20:04 +04:00
|
|
|
#include "sysemu/blockdev.h"
|
2013-02-05 20:06:20 +04:00
|
|
|
#include "hw/block/block.h"
|
2012-12-17 21:20:04 +04:00
|
|
|
#include "sysemu/sysemu.h"
|
2014-10-07 12:00:29 +04:00
|
|
|
#include "qapi/visitor.h"
|
2009-09-15 23:23:34 +04:00
|
|
|
|
|
|
|
/* --------------------------------- */
|
|
|
|
|
2010-12-08 14:34:59 +03:00
|
|
|
static char *idebus_get_fw_dev_path(DeviceState *dev);
|
|
|
|
|
2012-03-28 20:01:36 +04:00
|
|
|
static Property ide_props[] = {
|
|
|
|
DEFINE_PROP_UINT32("unit", IDEDevice, unit, -1),
|
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
2012-05-02 11:00:20 +04: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 23:23:34 +04:00
|
|
|
};
|
|
|
|
|
2013-08-23 22:18:50 +04:00
|
|
|
void ide_bus_new(IDEBus *idebus, size_t idebus_size, DeviceState *dev,
|
|
|
|
int bus_id, int max_units)
|
2009-09-15 23:23:34 +04:00
|
|
|
{
|
2013-08-24 02:02:27 +04:00
|
|
|
qbus_create_inplace(idebus, idebus_size, TYPE_IDE_BUS, dev, NULL);
|
2010-12-08 14:34:58 +03:00
|
|
|
idebus->bus_id = bus_id;
|
2013-05-06 17:58:04 +04:00
|
|
|
idebus->max_units = max_units;
|
2009-09-15 23:23:34 +04:00
|
|
|
}
|
|
|
|
|
2010-12-08 14:34:59 +03:00
|
|
|
static char *idebus_get_fw_dev_path(DeviceState *dev)
|
|
|
|
{
|
|
|
|
char path[30];
|
|
|
|
|
2014-08-15 15:32:37 +04:00
|
|
|
snprintf(path, sizeof(path), "%s@%x", qdev_fw_name(dev),
|
2010-12-08 14:34:59 +03: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 15:09:44 +04:00
|
|
|
return g_strdup(path);
|
2010-12-08 14:34:59 +03:00
|
|
|
}
|
|
|
|
|
2011-12-10 01:02:56 +04:00
|
|
|
static int ide_qdev_init(DeviceState *qdev)
|
2009-09-15 23:23:34 +04:00
|
|
|
{
|
2011-12-16 23:41:12 +04:00
|
|
|
IDEDevice *dev = IDE_DEVICE(qdev);
|
|
|
|
IDEDeviceClass *dc = IDE_DEVICE_GET_CLASS(dev);
|
2009-09-15 23:23:34 +04:00
|
|
|
IDEBus *bus = DO_UPCAST(IDEBus, qbus, qdev->parent_bus);
|
|
|
|
|
2014-10-07 15:59:18 +04:00
|
|
|
if (!dev->conf.blk) {
|
2010-06-28 10:36:53 +04:00
|
|
|
error_report("No drive specified");
|
2009-09-15 23:23:34 +04:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
if (dev->unit == -1) {
|
|
|
|
dev->unit = bus->master ? 1 : 0;
|
|
|
|
}
|
2013-05-06 17:58:04 +04:00
|
|
|
|
|
|
|
if (dev->unit >= bus->max_units) {
|
|
|
|
error_report("Can't create IDE unit %d, bus supports only %d units",
|
|
|
|
dev->unit, bus->max_units);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2009-09-15 23:23:34 +04:00
|
|
|
switch (dev->unit) {
|
|
|
|
case 0:
|
|
|
|
if (bus->master) {
|
2010-06-28 10:36:53 +04:00
|
|
|
error_report("IDE unit %d is in use", dev->unit);
|
2009-09-15 23:23:34 +04:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
bus->master = dev;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if (bus->slave) {
|
2010-06-28 10:36:53 +04:00
|
|
|
error_report("IDE unit %d is in use", dev->unit);
|
2009-09-15 23:23:34 +04:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
bus->slave = dev;
|
|
|
|
break;
|
|
|
|
default:
|
2010-06-28 10:36:53 +04:00
|
|
|
error_report("Invalid IDE unit %d", dev->unit);
|
2009-09-15 23:23:34 +04:00
|
|
|
goto err;
|
|
|
|
}
|
2011-12-16 23:41:12 +04:00
|
|
|
return dc->init(dev);
|
2009-09-15 23:23:34 +04:00
|
|
|
|
|
|
|
err:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
IDEDevice *ide_create_drive(IDEBus *bus, int unit, DriveInfo *drive)
|
|
|
|
{
|
|
|
|
DeviceState *dev;
|
|
|
|
|
2011-05-16 17:04:56 +04:00
|
|
|
dev = qdev_create(&bus->qbus, drive->media_cd ? "ide-cd" : "ide-hd");
|
2009-09-15 23:23:34 +04:00
|
|
|
qdev_prop_set_uint32(dev, "unit", unit);
|
2015-12-10 19:29:15 +03:00
|
|
|
qdev_prop_set_drive(dev, "drive", blk_by_legacy_dinfo(drive),
|
|
|
|
&error_fatal);
|
2010-06-25 20:53:22 +04:00
|
|
|
qdev_init_nofail(dev);
|
2009-09-15 23:23:34 +04:00
|
|
|
return DO_UPCAST(IDEDevice, qdev, dev);
|
|
|
|
}
|
|
|
|
|
2012-07-10 13:12:38 +04:00
|
|
|
int ide_get_geometry(BusState *bus, int unit,
|
|
|
|
int16_t *cyls, int8_t *heads, int8_t *secs)
|
2010-06-24 21:58:20 +04:00
|
|
|
{
|
2012-07-10 13:12:38 +04:00
|
|
|
IDEState *s = &DO_UPCAST(IDEBus, qbus, bus)->ifs[unit];
|
|
|
|
|
2014-10-07 15:59:18 +04:00
|
|
|
if (s->drive_kind != IDE_HD || !s->blk) {
|
2012-07-10 13:12:38 +04: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 21:58:20 +04:00
|
|
|
}
|
|
|
|
|
2009-09-15 23:23:34 +04:00
|
|
|
/* --------------------------------- */
|
|
|
|
|
|
|
|
typedef struct IDEDrive {
|
|
|
|
IDEDevice dev;
|
|
|
|
} IDEDrive;
|
|
|
|
|
2011-05-16 17:04:52 +04:00
|
|
|
static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind)
|
2009-09-15 23:23:34 +04:00
|
|
|
{
|
|
|
|
IDEBus *bus = DO_UPCAST(IDEBus, qbus, dev->qdev.parent_bus);
|
2010-06-01 22:32:32 +04:00
|
|
|
IDEState *s = bus->ifs + dev->unit;
|
2014-08-12 06:12:54 +04:00
|
|
|
Error *err = NULL;
|
2010-06-01 22:32:32 +04:00
|
|
|
|
2013-02-08 17:06:14 +04:00
|
|
|
if (dev->conf.discard_granularity == -1) {
|
|
|
|
dev->conf.discard_granularity = 512;
|
|
|
|
} else if (dev->conf.discard_granularity &&
|
|
|
|
dev->conf.discard_granularity != 512) {
|
2011-05-19 12:58:19 +04:00
|
|
|
error_report("discard_granularity must be 512 for ide");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-02-16 14:47:58 +03:00
|
|
|
blkconf_blocksizes(&dev->conf);
|
2014-12-03 15:21:32 +03:00
|
|
|
if (dev->conf.logical_block_size != 512) {
|
|
|
|
error_report("logical_block_size must be 512 for IDE");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-07-11 17:08:37 +04:00
|
|
|
blkconf_serial(&dev->conf, &dev->serial);
|
2014-08-12 06:12:54 +04:00
|
|
|
if (kind != IDE_CD) {
|
2016-01-25 22:34:40 +03:00
|
|
|
blkconf_geometry(&dev->conf, &dev->chs_trans, 65535, 16, 255, &err);
|
2014-08-12 06:12:54 +04:00
|
|
|
if (err) {
|
2015-02-12 15:55:05 +03:00
|
|
|
error_report_err(err);
|
2014-08-12 06:12:54 +04:00
|
|
|
return -1;
|
|
|
|
}
|
2012-07-10 13:12:44 +04:00
|
|
|
}
|
2016-06-23 16:12:35 +03:00
|
|
|
blkconf_apply_backend_options(&dev->conf);
|
2012-07-10 13:12:44 +04:00
|
|
|
|
2014-10-07 15:59:18 +04:00
|
|
|
if (ide_init_drive(s, dev->conf.blk, kind,
|
2012-07-11 17:08:37 +04:00
|
|
|
dev->version, dev->serial, dev->model, dev->wwn,
|
2012-07-10 13:12:44 +04:00
|
|
|
dev->conf.cyls, dev->conf.heads, dev->conf.secs,
|
2012-07-10 13:12:48 +04:00
|
|
|
dev->chs_trans) < 0) {
|
2010-06-28 21:07:51 +04:00
|
|
|
return -1;
|
|
|
|
}
|
2010-06-01 22:32:32 +04:00
|
|
|
|
2010-06-01 22:32:33 +04:00
|
|
|
if (!dev->version) {
|
2011-08-21 07:09:37 +04:00
|
|
|
dev->version = g_strdup(s->version);
|
2010-06-01 22:32:33 +04:00
|
|
|
}
|
2010-06-01 22:32:32 +04:00
|
|
|
if (!dev->serial) {
|
2011-08-21 07:09:37 +04:00
|
|
|
dev->serial = g_strdup(s->drive_serial_str);
|
2010-06-01 22:32:32 +04:00
|
|
|
}
|
2010-12-08 14:35:05 +03:00
|
|
|
|
|
|
|
add_boot_device_path(dev->conf.bootindex, &dev->qdev,
|
|
|
|
dev->unit ? "/disk@1" : "/disk@0");
|
|
|
|
|
2009-09-15 23:23:34 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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 16:48:55 +03:00
|
|
|
static void ide_dev_get_bootindex(Object *obj, Visitor *v, const char *name,
|
|
|
|
void *opaque, Error **errp)
|
2014-10-07 12:00:29 +04: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 16:48:54 +03:00
|
|
|
visit_type_int32(v, name, &d->conf.bootindex, errp);
|
2014-10-07 12:00:29 +04: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 16:48:55 +03:00
|
|
|
static void ide_dev_set_bootindex(Object *obj, Visitor *v, const char *name,
|
|
|
|
void *opaque, Error **errp)
|
2014-10-07 12:00:29 +04:00
|
|
|
{
|
|
|
|
IDEDevice *d = IDE_DEVICE(obj);
|
|
|
|
int32_t boot_index;
|
|
|
|
Error *local_err = NULL;
|
|
|
|
|
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 16:48:54 +03:00
|
|
|
visit_type_int32(v, name, &boot_index, &local_err);
|
2014-10-07 12:00:29 +04:00
|
|
|
if (local_err) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
/* 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 12:00:35 +04:00
|
|
|
if (d->unit != -1) {
|
|
|
|
add_boot_device_path(d->conf.bootindex, &d->qdev,
|
|
|
|
d->unit ? "/disk@1" : "/disk@0");
|
|
|
|
}
|
2014-10-07 12:00:29 +04:00
|
|
|
out:
|
2016-06-14 00:57:56 +03:00
|
|
|
error_propagate(errp, local_err);
|
2014-10-07 12:00:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ide_dev_instance_init(Object *obj)
|
|
|
|
{
|
|
|
|
object_property_add(obj, "bootindex", "int32",
|
|
|
|
ide_dev_get_bootindex,
|
|
|
|
ide_dev_set_bootindex, NULL, NULL, NULL);
|
2014-10-07 12:00:35 +04:00
|
|
|
object_property_set_int(obj, -1, "bootindex", NULL);
|
2014-10-07 12:00:29 +04:00
|
|
|
}
|
|
|
|
|
2011-05-16 17:04:52 +04:00
|
|
|
static int ide_hd_initfn(IDEDevice *dev)
|
|
|
|
{
|
|
|
|
return ide_dev_initfn(dev, IDE_HD);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ide_cd_initfn(IDEDevice *dev)
|
|
|
|
{
|
|
|
|
return ide_dev_initfn(dev, IDE_CD);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ide_drive_initfn(IDEDevice *dev)
|
|
|
|
{
|
2014-10-07 15:59:18 +04:00
|
|
|
DriveInfo *dinfo = blk_legacy_dinfo(dev->conf.blk);
|
2011-05-16 17:04:56 +04:00
|
|
|
|
2014-10-07 15:59:22 +04:00
|
|
|
return ide_dev_initfn(dev, dinfo && dinfo->media_cd ? IDE_CD : IDE_HD);
|
2011-05-16 17:04:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#define DEFINE_IDE_DEV_PROPERTIES() \
|
|
|
|
DEFINE_BLOCK_PROPERTIES(IDEDrive, dev.conf), \
|
2016-06-29 18:41:35 +03:00
|
|
|
DEFINE_BLOCK_ERROR_PROPERTIES(IDEDrive, dev.conf), \
|
2011-05-16 17:04:52 +04:00
|
|
|
DEFINE_PROP_STRING("ver", IDEDrive, dev.version), \
|
2014-02-08 14:01:53 +04:00
|
|
|
DEFINE_PROP_UINT64("wwn", IDEDrive, dev.wwn, 0), \
|
2012-03-13 00:05:09 +04:00
|
|
|
DEFINE_PROP_STRING("serial", IDEDrive, dev.serial),\
|
|
|
|
DEFINE_PROP_STRING("model", IDEDrive, dev.model)
|
2011-05-16 17:04:52 +04:00
|
|
|
|
2011-12-08 07:34:16 +04:00
|
|
|
static Property ide_hd_properties[] = {
|
|
|
|
DEFINE_IDE_DEV_PROPERTIES(),
|
2012-07-10 13:12:44 +04:00
|
|
|
DEFINE_BLOCK_CHS_PROPERTIES(IDEDrive, dev.conf),
|
2012-07-10 13:12:48 +04:00
|
|
|
DEFINE_PROP_BIOS_CHS_TRANS("bios-chs-trans",
|
|
|
|
IDEDrive, dev.chs_trans, BIOS_ATA_TRANSLATION_AUTO),
|
2011-12-08 07:34:16 +04:00
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
2011-12-16 23:41:12 +04:00
|
|
|
static void ide_hd_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
2011-12-08 07:34:16 +04:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2011-12-16 23:41:12 +04:00
|
|
|
IDEDeviceClass *k = IDE_DEVICE_CLASS(klass);
|
|
|
|
k->init = ide_hd_initfn;
|
2011-12-08 07:34:16 +04:00
|
|
|
dc->fw_name = "drive";
|
|
|
|
dc->desc = "virtual IDE disk";
|
|
|
|
dc->props = ide_hd_properties;
|
2011-12-16 23:41:12 +04:00
|
|
|
}
|
|
|
|
|
2013-01-10 19:19:07 +04:00
|
|
|
static const TypeInfo ide_hd_info = {
|
2011-12-08 07:34:16 +04: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 23:23:34 +04:00
|
|
|
};
|
|
|
|
|
2011-12-16 23:41:12 +04:00
|
|
|
static void ide_cd_class_init(ObjectClass *klass, void *data)
|
2009-09-15 23:23:34 +04:00
|
|
|
{
|
2011-12-08 07:34:16 +04:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2011-12-16 23:41:12 +04:00
|
|
|
IDEDeviceClass *k = IDE_DEVICE_CLASS(klass);
|
|
|
|
k->init = ide_cd_initfn;
|
2011-12-08 07:34:16 +04:00
|
|
|
dc->fw_name = "drive";
|
|
|
|
dc->desc = "virtual IDE CD-ROM";
|
|
|
|
dc->props = ide_cd_properties;
|
2011-12-16 23:41:12 +04:00
|
|
|
}
|
2011-05-16 17:04:52 +04:00
|
|
|
|
2013-01-10 19:19:07 +04:00
|
|
|
static const TypeInfo ide_cd_info = {
|
2011-12-08 07:34:16 +04:00
|
|
|
.name = "ide-cd",
|
|
|
|
.parent = TYPE_IDE_DEVICE,
|
|
|
|
.instance_size = sizeof(IDEDrive),
|
|
|
|
.class_init = ide_cd_class_init,
|
|
|
|
};
|
|
|
|
|
|
|
|
static Property ide_drive_properties[] = {
|
|
|
|
DEFINE_IDE_DEV_PROPERTIES(),
|
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
2011-12-16 23:41:12 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static void ide_drive_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
2011-12-08 07:34:16 +04:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2011-12-16 23:41:12 +04:00
|
|
|
IDEDeviceClass *k = IDE_DEVICE_CLASS(klass);
|
|
|
|
k->init = ide_drive_initfn;
|
2011-12-08 07:34:16 +04:00
|
|
|
dc->fw_name = "drive";
|
|
|
|
dc->desc = "virtual IDE disk or CD-ROM (legacy)";
|
|
|
|
dc->props = ide_drive_properties;
|
2011-12-16 23:41:12 +04:00
|
|
|
}
|
|
|
|
|
2013-01-10 19:19:07 +04:00
|
|
|
static const TypeInfo ide_drive_info = {
|
2011-12-08 07:34:16 +04:00
|
|
|
.name = "ide-drive",
|
|
|
|
.parent = TYPE_IDE_DEVICE,
|
|
|
|
.instance_size = sizeof(IDEDrive),
|
|
|
|
.class_init = ide_drive_class_init,
|
2011-12-16 23:41:12 +04:00
|
|
|
};
|
|
|
|
|
2011-12-08 07:34:16 +04:00
|
|
|
static void ide_device_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *k = DEVICE_CLASS(klass);
|
|
|
|
k->init = ide_qdev_init;
|
2013-07-29 18:17:45 +04:00
|
|
|
set_bit(DEVICE_CATEGORY_STORAGE, k->categories);
|
2012-05-02 11:00:20 +04:00
|
|
|
k->bus_type = TYPE_IDE_BUS;
|
2012-03-28 20:12:47 +04:00
|
|
|
k->props = ide_props;
|
2011-12-08 07:34:16 +04:00
|
|
|
}
|
|
|
|
|
2013-01-10 19:19:07 +04:00
|
|
|
static const TypeInfo ide_device_type_info = {
|
2011-12-16 23:41:12 +04:00
|
|
|
.name = TYPE_IDE_DEVICE,
|
|
|
|
.parent = TYPE_DEVICE,
|
|
|
|
.instance_size = sizeof(IDEDevice),
|
|
|
|
.abstract = true,
|
|
|
|
.class_size = sizeof(IDEDeviceClass),
|
2011-12-08 07:34:16 +04:00
|
|
|
.class_init = ide_device_class_init,
|
2014-10-07 12:00:29 +04:00
|
|
|
.instance_init = ide_dev_instance_init,
|
2011-12-16 23:41:12 +04:00
|
|
|
};
|
|
|
|
|
2012-02-09 18:20:55 +04:00
|
|
|
static void ide_register_types(void)
|
2011-12-16 23:41:12 +04:00
|
|
|
{
|
2012-05-02 11:00:20 +04:00
|
|
|
type_register_static(&ide_bus_info);
|
2011-12-08 07:34:16 +04:00
|
|
|
type_register_static(&ide_hd_info);
|
|
|
|
type_register_static(&ide_cd_info);
|
|
|
|
type_register_static(&ide_drive_info);
|
2011-12-16 23:41:12 +04:00
|
|
|
type_register_static(&ide_device_type_info);
|
2009-09-15 23:23:34 +04:00
|
|
|
}
|
2012-02-09 18:20:55 +04:00
|
|
|
|
|
|
|
type_init(ide_register_types)
|