Commit 4be9f0d1 authored by Anthony Liguori's avatar Anthony Liguori

qdev: make DeviceInfo private

Introduce accessors and remove any code that directly accesses DeviceInfo
members.
Signed-off-by: default avatarAnthony Liguori <aliguori@us.ibm.com>
parent ba02430f
...@@ -1673,6 +1673,7 @@ static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom) ...@@ -1673,6 +1673,7 @@ static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom)
char *path; char *path;
void *ptr; void *ptr;
char name[32]; char name[32];
const VMStateDescription *vmsd;
if (!pdev->romfile) if (!pdev->romfile)
return 0; return 0;
...@@ -1709,10 +1710,13 @@ static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom) ...@@ -1709,10 +1710,13 @@ static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom)
size = 1 << qemu_fls(size); size = 1 << qemu_fls(size);
} }
if (qdev_get_info(&pdev->qdev)->vmsd) vmsd = qdev_get_vmsd(DEVICE(pdev));
snprintf(name, sizeof(name), "%s.rom", qdev_get_info(&pdev->qdev)->vmsd->name);
else if (vmsd) {
snprintf(name, sizeof(name), "%s.rom", vmsd->name);
} else {
snprintf(name, sizeof(name), "%s.rom", object_get_typename(OBJECT(pdev))); snprintf(name, sizeof(name), "%s.rom", object_get_typename(OBJECT(pdev)));
}
pdev->has_rom = true; pdev->has_rom = true;
memory_region_init_ram(&pdev->rom, name, size); memory_region_init_ram(&pdev->rom, name, size);
vmstate_register_ram(&pdev->rom, &pdev->qdev); vmstate_register_ram(&pdev->rom, &pdev->qdev);
...@@ -1953,8 +1957,7 @@ static int pci_qdev_find_recursive(PCIBus *bus, ...@@ -1953,8 +1957,7 @@ static int pci_qdev_find_recursive(PCIBus *bus,
} }
/* roughly check if given qdev is pci device */ /* roughly check if given qdev is pci device */
if (qdev_get_info(qdev)->init == &pci_qdev_init && if (object_dynamic_cast(OBJECT(qdev), TYPE_PCI_DEVICE)) {
qdev->parent_bus->info == &pci_bus_info) {
*pdev = PCI_DEVICE(qdev); *pdev = PCI_DEVICE(qdev);
return 0; return 0;
} }
......
...@@ -1015,7 +1015,7 @@ static Property *qdev_prop_find(DeviceState *dev, const char *name) ...@@ -1015,7 +1015,7 @@ static Property *qdev_prop_find(DeviceState *dev, const char *name)
Property *prop; Property *prop;
/* device properties */ /* device properties */
prop = qdev_prop_walk(qdev_get_info(dev)->props, name); prop = qdev_prop_walk(qdev_get_props(dev), name);
if (prop) if (prop)
return prop; return prop;
...@@ -1221,7 +1221,7 @@ void qdev_prop_set_globals(DeviceState *dev) ...@@ -1221,7 +1221,7 @@ void qdev_prop_set_globals(DeviceState *dev)
QTAILQ_FOREACH(prop, &global_props, next) { QTAILQ_FOREACH(prop, &global_props, next) {
if (strcmp(object_get_typename(OBJECT(dev)), prop->driver) != 0 && if (strcmp(object_get_typename(OBJECT(dev)), prop->driver) != 0 &&
strcmp(qdev_get_info(dev)->bus_info->name, prop->driver) != 0) { strcmp(qdev_get_bus_info(dev)->name, prop->driver) != 0) {
continue; continue;
} }
if (qdev_prop_parse(dev, prop->property, prop->value) != 0) { if (qdev_prop_parse(dev, prop->property, prop->value) != 0) {
......
...@@ -60,11 +60,39 @@ static void qdev_subclass_init(ObjectClass *klass, void *data) ...@@ -60,11 +60,39 @@ static void qdev_subclass_init(ObjectClass *klass, void *data)
} }
} }
DeviceInfo *qdev_get_info(DeviceState *dev) static DeviceInfo *qdev_get_info(DeviceState *dev)
{ {
return DEVICE_GET_CLASS(dev)->info; return DEVICE_GET_CLASS(dev)->info;
} }
const VMStateDescription *qdev_get_vmsd(DeviceState *dev)
{
return qdev_get_info(dev)->vmsd;
}
BusInfo *qdev_get_bus_info(DeviceState *dev)
{
return qdev_get_info(dev)->bus_info;
}
Property *qdev_get_props(DeviceState *dev)
{
return qdev_get_info(dev)->props;
}
const char *qdev_fw_name(DeviceState *dev)
{
DeviceInfo *info = qdev_get_info(dev);
if (info->fw_name) {
return info->fw_name;
} else if (info->alias) {
return info->alias;
}
return object_get_typename(OBJECT(dev));
}
void qdev_register_subclass(DeviceInfo *info, const char *parent) void qdev_register_subclass(DeviceInfo *info, const char *parent)
{ {
TypeInfo type_info = {}; TypeInfo type_info = {};
......
...@@ -405,22 +405,8 @@ void qdev_prop_set_globals(DeviceState *dev); ...@@ -405,22 +405,8 @@ void qdev_prop_set_globals(DeviceState *dev);
void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev, void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev,
Property *prop, const char *value); Property *prop, const char *value);
DeviceInfo *qdev_get_info(DeviceState *dev);
static inline const char *qdev_fw_name(DeviceState *dev)
{
DeviceInfo *info = qdev_get_info(dev);
if (info->fw_name) {
return info->fw_name;
} else if (info->alias) {
return info->alias;
}
return object_get_typename(OBJECT(dev));
}
char *qdev_get_fw_dev_path(DeviceState *dev); char *qdev_get_fw_dev_path(DeviceState *dev);
/* This is a nasty hack to allow passing a NULL bus to qdev_create. */ /* This is a nasty hack to allow passing a NULL bus to qdev_create. */
extern struct BusInfo system_bus_info; extern struct BusInfo system_bus_info;
...@@ -668,4 +654,12 @@ void qdev_machine_init(void); ...@@ -668,4 +654,12 @@ void qdev_machine_init(void);
*/ */
void device_reset(DeviceState *dev); void device_reset(DeviceState *dev);
const VMStateDescription *qdev_get_vmsd(DeviceState *dev);
const char *qdev_fw_name(DeviceState *dev);
BusInfo *qdev_get_bus_info(DeviceState *dev);
Property *qdev_get_props(DeviceState *dev);
#endif #endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment