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