qdev: update pci device registration.

Makes pci_qdev_register take a PCIDeviceInfo struct instead of a bunch
of parameters.  Also adds config_read and config_write callbacks to
PCIDeviceInfo, so drivers needing these can be converted to the qdev
device API too.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
This commit is contained in:
Gerd Hoffmann 2009-06-30 14:12:07 +02:00 committed by Paul Brook
parent e2b19c85ea
commit 0aab0d3a4a
10 changed files with 103 additions and 36 deletions

View File

@ -1125,9 +1125,15 @@ static void pci_e1000_init(PCIDevice *pci_dev)
e1000_reset(d);
}
static PCIDeviceInfo e1000_info = {
.qdev.name = "e1000",
.qdev.size = sizeof(E1000State),
.init = pci_e1000_init,
};
static void e1000_register_devices(void)
{
pci_qdev_register("e1000", sizeof(E1000State), pci_e1000_init);
pci_qdev_register(&e1000_info);
}
device_init(e1000_register_devices)

View File

@ -1792,14 +1792,27 @@ static void pci_i82559er_init(PCIDevice *dev)
nic_init(dev, i82559ER);
}
static PCIDeviceInfo eepro100_info[] = {
{
.qdev.name = "i82551",
.qdev.size = sizeof(PCIEEPRO100State),
.init = pci_i82551_init,
},{
.qdev.name = "i82557b",
.qdev.size = sizeof(PCIEEPRO100State),
.init = pci_i82557b_init,
},{
.qdev.name = "i82559er",
.qdev.size = sizeof(PCIEEPRO100State),
.init = pci_i82559er_init,
},{
/* end of list */
}
};
static void eepro100_register_devices(void)
{
pci_qdev_register("i82551", sizeof(PCIEEPRO100State),
pci_i82551_init);
pci_qdev_register("i82557b", sizeof(PCIEEPRO100State),
pci_i82557b_init);
pci_qdev_register("i82559er", sizeof(PCIEEPRO100State),
pci_i82559er_init);
pci_qdev_register_many(eepro100_info);
}
device_init(eepro100_register_devices)

View File

@ -2035,9 +2035,15 @@ static void lsi_scsi_init(PCIDevice *dev)
scsi_bus_new(&dev->qdev, lsi_scsi_attach);
}
static PCIDeviceInfo lsi_info = {
.qdev.name = "lsi53c895a",
.qdev.size = sizeof(LSIState),
.init = lsi_scsi_init,
};
static void lsi53c895a_register_devices(void)
{
pci_qdev_register("lsi53c895a", sizeof(LSIState), lsi_scsi_init);
pci_qdev_register(&lsi_info);
}
device_init(lsi53c895a_register_devices);

View File

@ -832,9 +832,15 @@ static void pci_ne2000_init(PCIDevice *pci_dev)
register_savevm("ne2000", -1, 3, ne2000_save, ne2000_load, s);
}
static PCIDeviceInfo ne2000_info = {
.qdev.name = "ne2k_pci",
.qdev.size = sizeof(PCINE2000State),
.init = pci_ne2000_init,
};
static void ne2000_register_devices(void)
{
pci_qdev_register("ne2k_pci", sizeof(PCINE2000State), pci_ne2000_init);
pci_qdev_register(&ne2000_info);
}
device_init(ne2000_register_devices)

View File

@ -874,11 +874,6 @@ PCIBus *pci_bridge_init(PCIBus *bus, int devfn, uint16_t vid, uint16_t did,
return s->bus;
}
typedef struct {
DeviceInfo qdev;
pci_qdev_initfn init;
} PCIDeviceInfo;
static void pci_qdev_init(DeviceState *qdev, DeviceInfo *base)
{
PCIDevice *pci_dev = (PCIDevice *)qdev;
@ -889,25 +884,26 @@ static void pci_qdev_init(DeviceState *qdev, DeviceInfo *base)
bus = FROM_QBUS(PCIBus, qdev_get_parent_bus(qdev));
devfn = qdev_get_prop_int(qdev, "devfn", -1);
pci_dev = do_pci_register_device(pci_dev, bus, "FIXME", devfn,
NULL, NULL);//FIXME:config_read, config_write);
info->config_read, info->config_write);
assert(pci_dev);
info->init(pci_dev);
}
void pci_qdev_register(const char *name, int size, pci_qdev_initfn init)
void pci_qdev_register(PCIDeviceInfo *info)
{
PCIDeviceInfo *info;
info = qemu_mallocz(sizeof(*info));
info->qdev.name = qemu_strdup(name);
info->qdev.size = size;
info->init = init;
info->qdev.init = pci_qdev_init;
info->qdev.bus_type = BUS_TYPE_PCI;
qdev_register(&info->qdev);
}
void pci_qdev_register_many(PCIDeviceInfo *info)
{
while (info->qdev.name) {
pci_qdev_register(info);
info++;
}
}
PCIDevice *pci_create_simple(PCIBus *bus, int devfn, const char *name)
{
DeviceState *dev;

View File

@ -314,7 +314,15 @@ pci_config_set_class(uint8_t *pci_config, uint16_t val)
}
typedef void (*pci_qdev_initfn)(PCIDevice *dev);
void pci_qdev_register(const char *name, int size, pci_qdev_initfn init);
typedef struct {
DeviceInfo qdev;
pci_qdev_initfn init;
PCIConfigReadFunc *config_read;
PCIConfigWriteFunc *config_write;
} PCIDeviceInfo;
void pci_qdev_register(PCIDeviceInfo *info);
void pci_qdev_register_many(PCIDeviceInfo *info);
PCIDevice *pci_create(const char *name, const char *devaddr);
PCIDevice *pci_create_simple(PCIBus *bus, int devfn, const char *name);

View File

@ -2143,9 +2143,15 @@ static void lance_init(SysBusDevice *dev)
}
#endif /* TARGET_SPARC */
static PCIDeviceInfo pcnet_info = {
.qdev.name = "pcnet",
.qdev.size = sizeof(PCIPCNetState),
.init = pci_pcnet_init,
};
static void pcnet_register_devices(void)
{
pci_qdev_register("pcnet", sizeof(PCIPCNetState), pci_pcnet_init);
pci_qdev_register(&pcnet_info);
#if defined (TARGET_SPARC) && !defined(TARGET_SPARC64)
sysbus_register_dev("lance", sizeof(SysBusPCNetState), lance_init);
#endif

View File

@ -3499,9 +3499,15 @@ static void pci_rtl8139_init(PCIDevice *dev)
#endif /* RTL8139_ONBOARD_TIMER */
}
static PCIDeviceInfo rtl8139_info = {
.qdev.name = "rtl8139",
.qdev.size = sizeof(PCIRTL8139State),
.init = pci_rtl8139_init,
};
static void rtl8139_register_devices(void)
{
pci_qdev_register("rtl8139", sizeof(PCIRTL8139State), pci_rtl8139_init);
pci_qdev_register(&rtl8139_info);
}
device_init(rtl8139_register_devices)

View File

@ -153,13 +153,18 @@ static void versatile_pci_host_init(PCIDevice *d)
d->config[0x0D] = 0x10; // latency_timer
}
static PCIDeviceInfo versatile_pci_host_info = {
.qdev.name = "versatile_pci_host",
.qdev.size = sizeof(PCIDevice),
.init = versatile_pci_host_init,
};
static void versatile_pci_register_devices(void)
{
sysbus_register_dev("versatile_pci", sizeof(PCIVPBState), pci_vpb_init);
sysbus_register_dev("realview_pci", sizeof(PCIVPBState),
pci_realview_init);
pci_qdev_register("versatile_pci_host", sizeof(PCIDevice),
versatile_pci_host_init);
pci_qdev_register(&versatile_pci_host_info);
}
device_init(versatile_pci_register_devices)

View File

@ -466,16 +466,31 @@ static void virtio_balloon_init_pci(PCIDevice *pci_dev)
0x00);
}
static PCIDeviceInfo virtio_info[] = {
{
.qdev.name = "virtio-blk-pci",
.qdev.size = sizeof(VirtIOPCIProxy),
.init = virtio_blk_init_pci,
},{
.qdev.name = "virtio-net-pci",
.qdev.size = sizeof(VirtIOPCIProxy),
.init = virtio_net_init_pci,
},{
.qdev.name = "virtio-console-pci",
.qdev.size = sizeof(VirtIOPCIProxy),
.init = virtio_console_init_pci,
},{
.qdev.name = "virtio-balloon-pci",
.qdev.size = sizeof(VirtIOPCIProxy),
.init = virtio_balloon_init_pci,
},{
/* end of list */
}
};
static void virtio_pci_register_devices(void)
{
pci_qdev_register("virtio-blk-pci", sizeof(VirtIOPCIProxy),
virtio_blk_init_pci);
pci_qdev_register("virtio-net-pci", sizeof(VirtIOPCIProxy),
virtio_net_init_pci);
pci_qdev_register("virtio-console-pci", sizeof(VirtIOPCIProxy),
virtio_console_init_pci);
pci_qdev_register("virtio-balloon-pci", sizeof(VirtIOPCIProxy),
virtio_balloon_init_pci);
pci_qdev_register_many(virtio_info);
}
device_init(virtio_pci_register_devices)