How to create bridge device, bus, and pci device.
As we all know, the "device and bus" architecture in qemu is that, a pci
device should attach to a pci bus, and a pci bus should add to a bridge
device, and the bridge device should link to main-system-bus.
To realize this, four important functions are introduced:
1. qdev_bridge_create() to create a bridge device named "s390-bridge-dev".
2. qbus_create() to create a pci bus named "s390-pci-bus" and attach
"s390-pci-bus" to "s390-bridge-dev".
3. s390_pci_bus_init() is used by coder to assign a bridge device and a pci bus,
it will call qdev_bridge_create() and qbus_create().
4. qdev_device_add() to create a pci device and attach it to designated bus.
The following codes are telling how to realize this in detail.
I. Define TypeInfo in test_pci.c file.
static void s390_pci_dev_class_init(ObjectClass *kclass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(kclass);
dc->bus_type = TYPE_S390_PCI_BUS;
}
static const TypeInfo s390_bridge_dev_info = {
.name = TYPE_S390_BRIDGE_DEV,
.parent = TYPE_SYS_BUS_DEVICE,
.class_init = s390_bridge_dev_class_init,
}
static const TypeInfo s390_pci_bus_info = {
.name = TYPE_S390_PCI_BUS,
.parent = TYPE_BUS,
}
static const TypeInfo s390_pci_dev_info = {
.name = TYPE_S390_PCI_DEV,
.parent = TYPE_DEVICE,
.class_init = s390_pci_dev_class_init,
};
II. Define macro in test_pci.h file.
#define TYPE_S390_BRIDGE_DEV "s390-bridge-dev"
#d