Commit 0aab0d3a4a62505ab7e79ee0a67fe3f04f6dae23

Authored by Gerd Hoffmann
Committed by Paul Brook
1 parent e2b19c85

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>
hw/e1000.c
@@ -1125,9 +1125,15 @@ static void pci_e1000_init(PCIDevice *pci_dev) @@ -1125,9 +1125,15 @@ static void pci_e1000_init(PCIDevice *pci_dev)
1125 e1000_reset(d); 1125 e1000_reset(d);
1126 } 1126 }
1127 1127
  1128 +static PCIDeviceInfo e1000_info = {
  1129 + .qdev.name = "e1000",
  1130 + .qdev.size = sizeof(E1000State),
  1131 + .init = pci_e1000_init,
  1132 +};
  1133 +
1128 static void e1000_register_devices(void) 1134 static void e1000_register_devices(void)
1129 { 1135 {
1130 - pci_qdev_register("e1000", sizeof(E1000State), pci_e1000_init); 1136 + pci_qdev_register(&e1000_info);
1131 } 1137 }
1132 1138
1133 device_init(e1000_register_devices) 1139 device_init(e1000_register_devices)
hw/eepro100.c
@@ -1792,14 +1792,27 @@ static void pci_i82559er_init(PCIDevice *dev) @@ -1792,14 +1792,27 @@ static void pci_i82559er_init(PCIDevice *dev)
1792 nic_init(dev, i82559ER); 1792 nic_init(dev, i82559ER);
1793 } 1793 }
1794 1794
  1795 +static PCIDeviceInfo eepro100_info[] = {
  1796 + {
  1797 + .qdev.name = "i82551",
  1798 + .qdev.size = sizeof(PCIEEPRO100State),
  1799 + .init = pci_i82551_init,
  1800 + },{
  1801 + .qdev.name = "i82557b",
  1802 + .qdev.size = sizeof(PCIEEPRO100State),
  1803 + .init = pci_i82557b_init,
  1804 + },{
  1805 + .qdev.name = "i82559er",
  1806 + .qdev.size = sizeof(PCIEEPRO100State),
  1807 + .init = pci_i82559er_init,
  1808 + },{
  1809 + /* end of list */
  1810 + }
  1811 +};
  1812 +
1795 static void eepro100_register_devices(void) 1813 static void eepro100_register_devices(void)
1796 { 1814 {
1797 - pci_qdev_register("i82551", sizeof(PCIEEPRO100State),  
1798 - pci_i82551_init);  
1799 - pci_qdev_register("i82557b", sizeof(PCIEEPRO100State),  
1800 - pci_i82557b_init);  
1801 - pci_qdev_register("i82559er", sizeof(PCIEEPRO100State),  
1802 - pci_i82559er_init); 1815 + pci_qdev_register_many(eepro100_info);
1803 } 1816 }
1804 1817
1805 device_init(eepro100_register_devices) 1818 device_init(eepro100_register_devices)
hw/lsi53c895a.c
@@ -2035,9 +2035,15 @@ static void lsi_scsi_init(PCIDevice *dev) @@ -2035,9 +2035,15 @@ static void lsi_scsi_init(PCIDevice *dev)
2035 scsi_bus_new(&dev->qdev, lsi_scsi_attach); 2035 scsi_bus_new(&dev->qdev, lsi_scsi_attach);
2036 } 2036 }
2037 2037
  2038 +static PCIDeviceInfo lsi_info = {
  2039 + .qdev.name = "lsi53c895a",
  2040 + .qdev.size = sizeof(LSIState),
  2041 + .init = lsi_scsi_init,
  2042 +};
  2043 +
2038 static void lsi53c895a_register_devices(void) 2044 static void lsi53c895a_register_devices(void)
2039 { 2045 {
2040 - pci_qdev_register("lsi53c895a", sizeof(LSIState), lsi_scsi_init); 2046 + pci_qdev_register(&lsi_info);
2041 } 2047 }
2042 2048
2043 device_init(lsi53c895a_register_devices); 2049 device_init(lsi53c895a_register_devices);
hw/ne2000.c
@@ -832,9 +832,15 @@ static void pci_ne2000_init(PCIDevice *pci_dev) @@ -832,9 +832,15 @@ static void pci_ne2000_init(PCIDevice *pci_dev)
832 register_savevm("ne2000", -1, 3, ne2000_save, ne2000_load, s); 832 register_savevm("ne2000", -1, 3, ne2000_save, ne2000_load, s);
833 } 833 }
834 834
  835 +static PCIDeviceInfo ne2000_info = {
  836 + .qdev.name = "ne2k_pci",
  837 + .qdev.size = sizeof(PCINE2000State),
  838 + .init = pci_ne2000_init,
  839 +};
  840 +
835 static void ne2000_register_devices(void) 841 static void ne2000_register_devices(void)
836 { 842 {
837 - pci_qdev_register("ne2k_pci", sizeof(PCINE2000State), pci_ne2000_init); 843 + pci_qdev_register(&ne2000_info);
838 } 844 }
839 845
840 device_init(ne2000_register_devices) 846 device_init(ne2000_register_devices)
hw/pci.c
@@ -874,11 +874,6 @@ PCIBus *pci_bridge_init(PCIBus *bus, int devfn, uint16_t vid, uint16_t did, @@ -874,11 +874,6 @@ PCIBus *pci_bridge_init(PCIBus *bus, int devfn, uint16_t vid, uint16_t did,
874 return s->bus; 874 return s->bus;
875 } 875 }
876 876
877 -typedef struct {  
878 - DeviceInfo qdev;  
879 - pci_qdev_initfn init;  
880 -} PCIDeviceInfo;  
881 -  
882 static void pci_qdev_init(DeviceState *qdev, DeviceInfo *base) 877 static void pci_qdev_init(DeviceState *qdev, DeviceInfo *base)
883 { 878 {
884 PCIDevice *pci_dev = (PCIDevice *)qdev; 879 PCIDevice *pci_dev = (PCIDevice *)qdev;
@@ -889,25 +884,26 @@ static void pci_qdev_init(DeviceState *qdev, DeviceInfo *base) @@ -889,25 +884,26 @@ static void pci_qdev_init(DeviceState *qdev, DeviceInfo *base)
889 bus = FROM_QBUS(PCIBus, qdev_get_parent_bus(qdev)); 884 bus = FROM_QBUS(PCIBus, qdev_get_parent_bus(qdev));
890 devfn = qdev_get_prop_int(qdev, "devfn", -1); 885 devfn = qdev_get_prop_int(qdev, "devfn", -1);
891 pci_dev = do_pci_register_device(pci_dev, bus, "FIXME", devfn, 886 pci_dev = do_pci_register_device(pci_dev, bus, "FIXME", devfn,
892 - NULL, NULL);//FIXME:config_read, config_write); 887 + info->config_read, info->config_write);
893 assert(pci_dev); 888 assert(pci_dev);
894 info->init(pci_dev); 889 info->init(pci_dev);
895 } 890 }
896 891
897 -void pci_qdev_register(const char *name, int size, pci_qdev_initfn init) 892 +void pci_qdev_register(PCIDeviceInfo *info)
898 { 893 {
899 - PCIDeviceInfo *info;  
900 -  
901 - info = qemu_mallocz(sizeof(*info));  
902 - info->qdev.name = qemu_strdup(name);  
903 - info->qdev.size = size;  
904 - info->init = init;  
905 info->qdev.init = pci_qdev_init; 894 info->qdev.init = pci_qdev_init;
906 info->qdev.bus_type = BUS_TYPE_PCI; 895 info->qdev.bus_type = BUS_TYPE_PCI;
907 -  
908 qdev_register(&info->qdev); 896 qdev_register(&info->qdev);
909 } 897 }
910 898
  899 +void pci_qdev_register_many(PCIDeviceInfo *info)
  900 +{
  901 + while (info->qdev.name) {
  902 + pci_qdev_register(info);
  903 + info++;
  904 + }
  905 +}
  906 +
911 PCIDevice *pci_create_simple(PCIBus *bus, int devfn, const char *name) 907 PCIDevice *pci_create_simple(PCIBus *bus, int devfn, const char *name)
912 { 908 {
913 DeviceState *dev; 909 DeviceState *dev;
hw/pci.h
@@ -314,7 +314,15 @@ pci_config_set_class(uint8_t *pci_config, uint16_t val) @@ -314,7 +314,15 @@ pci_config_set_class(uint8_t *pci_config, uint16_t val)
314 } 314 }
315 315
316 typedef void (*pci_qdev_initfn)(PCIDevice *dev); 316 typedef void (*pci_qdev_initfn)(PCIDevice *dev);
317 -void pci_qdev_register(const char *name, int size, pci_qdev_initfn init); 317 +typedef struct {
  318 + DeviceInfo qdev;
  319 + pci_qdev_initfn init;
  320 + PCIConfigReadFunc *config_read;
  321 + PCIConfigWriteFunc *config_write;
  322 +} PCIDeviceInfo;
  323 +
  324 +void pci_qdev_register(PCIDeviceInfo *info);
  325 +void pci_qdev_register_many(PCIDeviceInfo *info);
318 326
319 PCIDevice *pci_create(const char *name, const char *devaddr); 327 PCIDevice *pci_create(const char *name, const char *devaddr);
320 PCIDevice *pci_create_simple(PCIBus *bus, int devfn, const char *name); 328 PCIDevice *pci_create_simple(PCIBus *bus, int devfn, const char *name);
hw/pcnet.c
@@ -2143,9 +2143,15 @@ static void lance_init(SysBusDevice *dev) @@ -2143,9 +2143,15 @@ static void lance_init(SysBusDevice *dev)
2143 } 2143 }
2144 #endif /* TARGET_SPARC */ 2144 #endif /* TARGET_SPARC */
2145 2145
  2146 +static PCIDeviceInfo pcnet_info = {
  2147 + .qdev.name = "pcnet",
  2148 + .qdev.size = sizeof(PCIPCNetState),
  2149 + .init = pci_pcnet_init,
  2150 +};
  2151 +
2146 static void pcnet_register_devices(void) 2152 static void pcnet_register_devices(void)
2147 { 2153 {
2148 - pci_qdev_register("pcnet", sizeof(PCIPCNetState), pci_pcnet_init); 2154 + pci_qdev_register(&pcnet_info);
2149 #if defined (TARGET_SPARC) && !defined(TARGET_SPARC64) 2155 #if defined (TARGET_SPARC) && !defined(TARGET_SPARC64)
2150 sysbus_register_dev("lance", sizeof(SysBusPCNetState), lance_init); 2156 sysbus_register_dev("lance", sizeof(SysBusPCNetState), lance_init);
2151 #endif 2157 #endif
hw/rtl8139.c
@@ -3499,9 +3499,15 @@ static void pci_rtl8139_init(PCIDevice *dev) @@ -3499,9 +3499,15 @@ static void pci_rtl8139_init(PCIDevice *dev)
3499 #endif /* RTL8139_ONBOARD_TIMER */ 3499 #endif /* RTL8139_ONBOARD_TIMER */
3500 } 3500 }
3501 3501
  3502 +static PCIDeviceInfo rtl8139_info = {
  3503 + .qdev.name = "rtl8139",
  3504 + .qdev.size = sizeof(PCIRTL8139State),
  3505 + .init = pci_rtl8139_init,
  3506 +};
  3507 +
3502 static void rtl8139_register_devices(void) 3508 static void rtl8139_register_devices(void)
3503 { 3509 {
3504 - pci_qdev_register("rtl8139", sizeof(PCIRTL8139State), pci_rtl8139_init); 3510 + pci_qdev_register(&rtl8139_info);
3505 } 3511 }
3506 3512
3507 device_init(rtl8139_register_devices) 3513 device_init(rtl8139_register_devices)
hw/versatile_pci.c
@@ -153,13 +153,18 @@ static void versatile_pci_host_init(PCIDevice *d) @@ -153,13 +153,18 @@ static void versatile_pci_host_init(PCIDevice *d)
153 d->config[0x0D] = 0x10; // latency_timer 153 d->config[0x0D] = 0x10; // latency_timer
154 } 154 }
155 155
  156 +static PCIDeviceInfo versatile_pci_host_info = {
  157 + .qdev.name = "versatile_pci_host",
  158 + .qdev.size = sizeof(PCIDevice),
  159 + .init = versatile_pci_host_init,
  160 +};
  161 +
156 static void versatile_pci_register_devices(void) 162 static void versatile_pci_register_devices(void)
157 { 163 {
158 sysbus_register_dev("versatile_pci", sizeof(PCIVPBState), pci_vpb_init); 164 sysbus_register_dev("versatile_pci", sizeof(PCIVPBState), pci_vpb_init);
159 sysbus_register_dev("realview_pci", sizeof(PCIVPBState), 165 sysbus_register_dev("realview_pci", sizeof(PCIVPBState),
160 pci_realview_init); 166 pci_realview_init);
161 - pci_qdev_register("versatile_pci_host", sizeof(PCIDevice),  
162 - versatile_pci_host_init); 167 + pci_qdev_register(&versatile_pci_host_info);
163 } 168 }
164 169
165 device_init(versatile_pci_register_devices) 170 device_init(versatile_pci_register_devices)
hw/virtio-pci.c
@@ -466,16 +466,31 @@ static void virtio_balloon_init_pci(PCIDevice *pci_dev) @@ -466,16 +466,31 @@ static void virtio_balloon_init_pci(PCIDevice *pci_dev)
466 0x00); 466 0x00);
467 } 467 }
468 468
  469 +static PCIDeviceInfo virtio_info[] = {
  470 + {
  471 + .qdev.name = "virtio-blk-pci",
  472 + .qdev.size = sizeof(VirtIOPCIProxy),
  473 + .init = virtio_blk_init_pci,
  474 + },{
  475 + .qdev.name = "virtio-net-pci",
  476 + .qdev.size = sizeof(VirtIOPCIProxy),
  477 + .init = virtio_net_init_pci,
  478 + },{
  479 + .qdev.name = "virtio-console-pci",
  480 + .qdev.size = sizeof(VirtIOPCIProxy),
  481 + .init = virtio_console_init_pci,
  482 + },{
  483 + .qdev.name = "virtio-balloon-pci",
  484 + .qdev.size = sizeof(VirtIOPCIProxy),
  485 + .init = virtio_balloon_init_pci,
  486 + },{
  487 + /* end of list */
  488 + }
  489 +};
  490 +
469 static void virtio_pci_register_devices(void) 491 static void virtio_pci_register_devices(void)
470 { 492 {
471 - pci_qdev_register("virtio-blk-pci", sizeof(VirtIOPCIProxy),  
472 - virtio_blk_init_pci);  
473 - pci_qdev_register("virtio-net-pci", sizeof(VirtIOPCIProxy),  
474 - virtio_net_init_pci);  
475 - pci_qdev_register("virtio-console-pci", sizeof(VirtIOPCIProxy),  
476 - virtio_console_init_pci);  
477 - pci_qdev_register("virtio-balloon-pci", sizeof(VirtIOPCIProxy),  
478 - virtio_balloon_init_pci); 493 + pci_qdev_register_many(virtio_info);
479 } 494 }
480 495
481 device_init(virtio_pci_register_devices) 496 device_init(virtio_pci_register_devices)