pci: Validate interfaces on base_class_init

Make sure we don't forget to add the Conventional PCI or PCI
Express interface names on PCI device classes in the future.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Revieed-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Marcel Apfelbaum <marcel@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
This commit is contained in:
Eduardo Habkost 2017-09-27 16:56:35 -03:00 committed by Michael S. Tsirkin
parent 6d7023763e
commit 2fefa16cec

View File

@ -2547,6 +2547,17 @@ static void pci_device_class_init(ObjectClass *klass, void *data)
pc->realize = pci_default_realize; pc->realize = pci_default_realize;
} }
static void pci_device_class_base_init(ObjectClass *klass, void *data)
{
if (!object_class_is_abstract(klass)) {
ObjectClass *conventional =
object_class_dynamic_cast(klass, INTERFACE_CONVENTIONAL_PCI_DEVICE);
ObjectClass *pcie =
object_class_dynamic_cast(klass, INTERFACE_PCIE_DEVICE);
assert(conventional || pcie);
}
}
AddressSpace *pci_device_iommu_address_space(PCIDevice *dev) AddressSpace *pci_device_iommu_address_space(PCIDevice *dev)
{ {
PCIBus *bus = PCI_BUS(dev->bus); PCIBus *bus = PCI_BUS(dev->bus);
@ -2671,6 +2682,7 @@ static const TypeInfo pci_device_type_info = {
.abstract = true, .abstract = true,
.class_size = sizeof(PCIDeviceClass), .class_size = sizeof(PCIDeviceClass),
.class_init = pci_device_class_init, .class_init = pci_device_class_init,
.class_base_init = pci_device_class_base_init,
}; };
static void pci_register_types(void) static void pci_register_types(void)