Commit 9d07d7579bcaf01e05c511c63d091ed2ac310091

Authored by Paul Brook
1 parent 9be5dafe

PCI network qdev conversion

Signed-off-by: Paul Brook <paul@codesourcery.com>
hw/e1000.c
@@ -1051,20 +1051,14 @@ pci_e1000_uninit(PCIDevice *dev) @@ -1051,20 +1051,14 @@ pci_e1000_uninit(PCIDevice *dev)
1051 return 0; 1051 return 0;
1052 } 1052 }
1053 1053
1054 -PCIDevice *  
1055 -pci_e1000_init(PCIBus *bus, NICInfo *nd, int devfn) 1054 +static void pci_e1000_init(PCIDevice *pci_dev)
1056 { 1055 {
1057 - E1000State *d; 1056 + E1000State *d = (E1000State *)pci_dev;
1058 uint8_t *pci_conf; 1057 uint8_t *pci_conf;
1059 uint16_t checksum = 0; 1058 uint16_t checksum = 0;
1060 static const char info_str[] = "e1000"; 1059 static const char info_str[] = "e1000";
1061 int i; 1060 int i;
1062 -  
1063 - d = (E1000State *)pci_register_device(bus, "e1000",  
1064 - sizeof(E1000State), devfn, NULL, NULL);  
1065 -  
1066 - if (!d)  
1067 - return NULL; 1061 + uint8_t macaddr[6];
1068 1062
1069 pci_conf = d->dev.config; 1063 pci_conf = d->dev.config;
1070 1064
@@ -1089,8 +1083,9 @@ pci_e1000_init(PCIBus *bus, NICInfo *nd, int devfn) @@ -1089,8 +1083,9 @@ pci_e1000_init(PCIBus *bus, NICInfo *nd, int devfn)
1089 1083
1090 memmove(d->eeprom_data, e1000_eeprom_template, 1084 memmove(d->eeprom_data, e1000_eeprom_template,
1091 sizeof e1000_eeprom_template); 1085 sizeof e1000_eeprom_template);
  1086 + qdev_get_macaddr(&d->dev.qdev, macaddr);
1092 for (i = 0; i < 3; i++) 1087 for (i = 0; i < 3; i++)
1093 - d->eeprom_data[i] = (nd->macaddr[2*i+1]<<8) | nd->macaddr[2*i]; 1088 + d->eeprom_data[i] = (macaddr[2*i+1]<<8) | macaddr[2*i];
1094 for (i = 0; i < EEPROM_CHECKSUM_REG; i++) 1089 for (i = 0; i < EEPROM_CHECKSUM_REG; i++)
1095 checksum += d->eeprom_data[i]; 1090 checksum += d->eeprom_data[i];
1096 checksum = (uint16_t) EEPROM_SUM - checksum; 1091 checksum = (uint16_t) EEPROM_SUM - checksum;
@@ -1103,15 +1098,20 @@ pci_e1000_init(PCIBus *bus, NICInfo *nd, int devfn) @@ -1103,15 +1098,20 @@ pci_e1000_init(PCIBus *bus, NICInfo *nd, int devfn)
1103 d->rxbuf_min_shift = 1; 1098 d->rxbuf_min_shift = 1;
1104 memset(&d->tx, 0, sizeof d->tx); 1099 memset(&d->tx, 0, sizeof d->tx);
1105 1100
1106 - d->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name, 1101 + d->vc = qdev_get_vlan_client(&d->dev.qdev,
1107 e1000_receive, e1000_can_receive, 1102 e1000_receive, e1000_can_receive,
1108 e1000_cleanup, d); 1103 e1000_cleanup, d);
1109 d->vc->link_status_changed = e1000_set_link_status; 1104 d->vc->link_status_changed = e1000_set_link_status;
1110 1105
1111 - qemu_format_nic_info_str(d->vc, nd->macaddr); 1106 + qemu_format_nic_info_str(d->vc, macaddr);
1112 1107
1113 register_savevm(info_str, -1, 2, nic_save, nic_load, d); 1108 register_savevm(info_str, -1, 2, nic_save, nic_load, d);
1114 d->dev.unregister = pci_e1000_uninit; 1109 d->dev.unregister = pci_e1000_uninit;
  1110 +}
1115 1111
1116 - return (PCIDevice *)d; 1112 +static void e1000_register_devices(void)
  1113 +{
  1114 + pci_qdev_register("e1000", sizeof(E1000State), pci_e1000_init);
1117 } 1115 }
  1116 +
  1117 +device_init(e1000_register_devices)
hw/eepro100.c
@@ -1728,19 +1728,13 @@ static int pci_nic_uninit(PCIDevice *dev) @@ -1728,19 +1728,13 @@ static int pci_nic_uninit(PCIDevice *dev)
1728 return 0; 1728 return 0;
1729 } 1729 }
1730 1730
1731 -static PCIDevice *nic_init(PCIBus * bus, NICInfo * nd, uint32_t device) 1731 +static void nic_init(PCIDevice *pci_dev, uint32_t device)
1732 { 1732 {
1733 - PCIEEPRO100State *d; 1733 + PCIEEPRO100State *d = (PCIEEPRO100State *)pci_dev;
1734 EEPRO100State *s; 1734 EEPRO100State *s;
1735 1735
1736 logout("\n"); 1736 logout("\n");
1737 1737
1738 - d = (PCIEEPRO100State *) pci_register_device(bus, nd->model,  
1739 - sizeof(PCIEEPRO100State), -1,  
1740 - NULL, NULL);  
1741 - if (!d)  
1742 - return NULL;  
1743 -  
1744 d->dev.unregister = pci_nic_uninit; 1738 d->dev.unregister = pci_nic_uninit;
1745 1739
1746 s = &d->eepro100; 1740 s = &d->eepro100;
@@ -1765,13 +1759,13 @@ static PCIDevice *nic_init(PCIBus * bus, NICInfo * nd, uint32_t device) @@ -1765,13 +1759,13 @@ static PCIDevice *nic_init(PCIBus * bus, NICInfo * nd, uint32_t device)
1765 pci_register_io_region(&d->dev, 2, PCI_FLASH_SIZE, PCI_ADDRESS_SPACE_MEM, 1759 pci_register_io_region(&d->dev, 2, PCI_FLASH_SIZE, PCI_ADDRESS_SPACE_MEM,
1766 pci_mmio_map); 1760 pci_mmio_map);
1767 1761
1768 - memcpy(s->macaddr, nd->macaddr, 6); 1762 + qdev_get_macaddr(&d->dev.qdev, s->macaddr);
1769 logout("macaddr: %s\n", nic_dump(&s->macaddr[0], 6)); 1763 logout("macaddr: %s\n", nic_dump(&s->macaddr[0], 6));
1770 assert(s->region[1] == 0); 1764 assert(s->region[1] == 0);
1771 1765
1772 nic_reset(s); 1766 nic_reset(s);
1773 1767
1774 - s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name, 1768 + s->vc = qdev_get_vlan_client(&d->dev.qdev,
1775 nic_receive, nic_can_receive, 1769 nic_receive, nic_can_receive,
1776 nic_cleanup, s); 1770 nic_cleanup, s);
1777 1771
@@ -1780,22 +1774,31 @@ static PCIDevice *nic_init(PCIBus * bus, NICInfo * nd, uint32_t device) @@ -1780,22 +1774,31 @@ static PCIDevice *nic_init(PCIBus * bus, NICInfo * nd, uint32_t device)
1780 qemu_register_reset(nic_reset, s); 1774 qemu_register_reset(nic_reset, s);
1781 1775
1782 register_savevm(s->vc->model, -1, 3, nic_save, nic_load, s); 1776 register_savevm(s->vc->model, -1, 3, nic_save, nic_load, s);
1783 - return (PCIDevice *)d;  
1784 } 1777 }
1785 1778
1786 -PCIDevice *pci_i82551_init(PCIBus * bus, NICInfo * nd, int devfn) 1779 +static void pci_i82551_init(PCIDevice *dev)
  1780 +{
  1781 + nic_init(dev, i82551);
  1782 +}
  1783 +
  1784 +static void pci_i82557b_init(PCIDevice *dev)
1787 { 1785 {
1788 - return nic_init(bus, nd, i82551); 1786 + nic_init(dev, i82557B);
1789 } 1787 }
1790 1788
1791 -PCIDevice *pci_i82557b_init(PCIBus * bus, NICInfo * nd, int devfn) 1789 +static void pci_i82559er_init(PCIDevice *dev)
1792 { 1790 {
1793 - return nic_init(bus, nd, i82557B); 1791 + nic_init(dev, i82559ER);
1794 } 1792 }
1795 1793
1796 -PCIDevice *pci_i82559er_init(PCIBus * bus, NICInfo * nd, int devfn) 1794 +static void eepro100_register_devices(void)
1797 { 1795 {
1798 - return nic_init(bus, nd, i82559ER); 1796 + pci_qdev_register("i82551", sizeof(PCIEEPRO100State),
  1797 + pci_i82551_init);
  1798 + pci_qdev_register("i82557b", sizeof(PCIEEPRO100State),
  1799 + pci_i82557b_init);
  1800 + pci_qdev_register("i82559er", sizeof(PCIEEPRO100State),
  1801 + pci_i82559er_init);
1799 } 1802 }
1800 1803
1801 -/* eof */ 1804 +device_init(eepro100_register_devices)
hw/ne2000.c
@@ -800,19 +800,12 @@ static void ne2000_cleanup(VLANClientState *vc) @@ -800,19 +800,12 @@ static void ne2000_cleanup(VLANClientState *vc)
800 unregister_savevm("ne2000", s); 800 unregister_savevm("ne2000", s);
801 } 801 }
802 802
803 -PCIDevice *pci_ne2000_init(PCIBus *bus, NICInfo *nd, int devfn) 803 +static void pci_ne2000_init(PCIDevice *pci_dev)
804 { 804 {
805 - PCINE2000State *d; 805 + PCINE2000State *d = (PCINE2000State *)pci_dev;
806 NE2000State *s; 806 NE2000State *s;
807 uint8_t *pci_conf; 807 uint8_t *pci_conf;
808 808
809 - d = (PCINE2000State *)pci_register_device(bus,  
810 - "NE2000", sizeof(PCINE2000State),  
811 - devfn,  
812 - NULL, NULL);  
813 - if (!d)  
814 - return NULL;  
815 -  
816 pci_conf = d->dev.config; 809 pci_conf = d->dev.config;
817 pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_REALTEK); 810 pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_REALTEK);
818 pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_REALTEK_8029); 811 pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_REALTEK_8029);
@@ -825,15 +818,20 @@ PCIDevice *pci_ne2000_init(PCIBus *bus, NICInfo *nd, int devfn) @@ -825,15 +818,20 @@ PCIDevice *pci_ne2000_init(PCIBus *bus, NICInfo *nd, int devfn)
825 s = &d->ne2000; 818 s = &d->ne2000;
826 s->irq = d->dev.irq[0]; 819 s->irq = d->dev.irq[0];
827 s->pci_dev = (PCIDevice *)d; 820 s->pci_dev = (PCIDevice *)d;
828 - memcpy(s->macaddr, nd->macaddr, 6); 821 + qdev_get_macaddr(&d->dev.qdev, s->macaddr);
829 ne2000_reset(s); 822 ne2000_reset(s);
830 - s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name, 823 + s->vc = qdev_get_vlan_client(&d->dev.qdev,
831 ne2000_receive, ne2000_can_receive, 824 ne2000_receive, ne2000_can_receive,
832 ne2000_cleanup, s); 825 ne2000_cleanup, s);
833 826
834 qemu_format_nic_info_str(s->vc, s->macaddr); 827 qemu_format_nic_info_str(s->vc, s->macaddr);
835 828
836 register_savevm("ne2000", -1, 3, ne2000_save, ne2000_load, s); 829 register_savevm("ne2000", -1, 3, ne2000_save, ne2000_load, s);
  830 +}
837 831
838 - return (PCIDevice *)d; 832 +static void ne2000_register_devices(void)
  833 +{
  834 + pci_qdev_register("ne2k_pci", sizeof(PCINE2000State), pci_ne2000_init);
839 } 835 }
  836 +
  837 +device_init(ne2000_register_devices)
hw/pci.c
@@ -799,17 +799,15 @@ static const char * const pci_nic_models[] = { @@ -799,17 +799,15 @@ static const char * const pci_nic_models[] = {
799 NULL 799 NULL
800 }; 800 };
801 801
802 -typedef PCIDevice *(*PCINICInitFn)(PCIBus *, NICInfo *, int);  
803 -  
804 -static PCINICInitFn pci_nic_init_fns[] = {  
805 - pci_ne2000_init,  
806 - pci_i82551_init,  
807 - pci_i82557b_init,  
808 - pci_i82559er_init,  
809 - pci_rtl8139_init,  
810 - pci_e1000_init,  
811 - pci_pcnet_init,  
812 - virtio_net_init, 802 +static const char * const pci_nic_names[] = {
  803 + "ne2k_pci",
  804 + "i82551",
  805 + "i82557b",
  806 + "i82559er",
  807 + "rtl8139",
  808 + "e1000",
  809 + "pcnet",
  810 + "virtio_net",
813 NULL 811 NULL
814 }; 812 };
815 813
@@ -817,18 +815,21 @@ static PCINICInitFn pci_nic_init_fns[] = { @@ -817,18 +815,21 @@ static PCINICInitFn pci_nic_init_fns[] = {
817 PCIDevice *pci_nic_init(PCIBus *bus, NICInfo *nd, int devfn, 815 PCIDevice *pci_nic_init(PCIBus *bus, NICInfo *nd, int devfn,
818 const char *default_model) 816 const char *default_model)
819 { 817 {
820 - PCIDevice *pci_dev; 818 + DeviceState *dev;
821 int i; 819 int i;
822 820
823 qemu_check_nic_model_list(nd, pci_nic_models, default_model); 821 qemu_check_nic_model_list(nd, pci_nic_models, default_model);
824 822
825 - for (i = 0; pci_nic_models[i]; i++) 823 + for (i = 0; pci_nic_models[i]; i++) {
826 if (strcmp(nd->model, pci_nic_models[i]) == 0) { 824 if (strcmp(nd->model, pci_nic_models[i]) == 0) {
827 - pci_dev = pci_nic_init_fns[i](bus, nd, devfn);  
828 - if (pci_dev)  
829 - nd->private = pci_dev;  
830 - return pci_dev; 825 + dev = qdev_create(bus, pci_nic_names[i]);
  826 + qdev_set_prop_int(dev, "devfn", devfn);
  827 + qdev_set_netdev(dev, nd);
  828 + qdev_init(dev);
  829 + nd->private = dev;
  830 + return (PCIDevice *)dev;
831 } 831 }
  832 + }
832 833
833 return NULL; 834 return NULL;
834 } 835 }
hw/pci.h
@@ -239,26 +239,6 @@ void usb_uhci_piix4_init(PCIBus *bus, int devfn); @@ -239,26 +239,6 @@ void usb_uhci_piix4_init(PCIBus *bus, int devfn);
239 /* usb-ohci.c */ 239 /* usb-ohci.c */
240 void usb_ohci_init_pci(struct PCIBus *bus, int num_ports, int devfn); 240 void usb_ohci_init_pci(struct PCIBus *bus, int num_ports, int devfn);
241 241
242 -/* eepro100.c */  
243 -  
244 -PCIDevice *pci_i82551_init(PCIBus *bus, NICInfo *nd, int devfn);  
245 -PCIDevice *pci_i82557b_init(PCIBus *bus, NICInfo *nd, int devfn);  
246 -PCIDevice *pci_i82559er_init(PCIBus *bus, NICInfo *nd, int devfn);  
247 -  
248 -/* ne2000.c */  
249 -  
250 -PCIDevice *pci_ne2000_init(PCIBus *bus, NICInfo *nd, int devfn);  
251 -  
252 -/* rtl8139.c */  
253 -  
254 -PCIDevice *pci_rtl8139_init(PCIBus *bus, NICInfo *nd, int devfn);  
255 -  
256 -/* e1000.c */  
257 -PCIDevice *pci_e1000_init(PCIBus *bus, NICInfo *nd, int devfn);  
258 -  
259 -/* pcnet.c */  
260 -PCIDevice *pci_pcnet_init(PCIBus *bus, NICInfo *nd, int devfn);  
261 -  
262 /* prep_pci.c */ 242 /* prep_pci.c */
263 PCIBus *pci_prep_init(qemu_irq *pic); 243 PCIBus *pci_prep_init(qemu_irq *pic);
264 244
hw/pcnet.c
@@ -35,7 +35,7 @@ @@ -35,7 +35,7 @@
35 * http://www.ibiblio.org/pub/historic-linux/early-ports/Sparc/NCR/NCR92C990.txt 35 * http://www.ibiblio.org/pub/historic-linux/early-ports/Sparc/NCR/NCR92C990.txt
36 */ 36 */
37 37
38 -#include "hw.h" 38 +#include "sysbus.h"
39 #include "pci.h" 39 #include "pci.h"
40 #include "net.h" 40 #include "net.h"
41 #include "qemu-timer.h" 41 #include "qemu-timer.h"
@@ -60,22 +60,20 @@ @@ -60,22 +60,20 @@
60 typedef struct PCNetState_st PCNetState; 60 typedef struct PCNetState_st PCNetState;
61 61
62 struct PCNetState_st { 62 struct PCNetState_st {
63 - PCIDevice dev;  
64 PCIDevice *pci_dev; 63 PCIDevice *pci_dev;
65 VLANClientState *vc; 64 VLANClientState *vc;
66 - NICInfo *nd; 65 + uint8_t macaddr[6];
67 QEMUTimer *poll_timer; 66 QEMUTimer *poll_timer;
68 - int mmio_index, rap, isr, lnkst; 67 + int rap, isr, lnkst;
69 uint32_t rdra, tdra; 68 uint32_t rdra, tdra;
70 uint8_t prom[16]; 69 uint8_t prom[16];
71 uint16_t csr[128]; 70 uint16_t csr[128];
72 uint16_t bcr[32]; 71 uint16_t bcr[32];
73 uint64_t timer; 72 uint64_t timer;
74 - int xmit_pos, recv_pos; 73 + int mmio_index, xmit_pos, recv_pos;
75 uint8_t buffer[4096]; 74 uint8_t buffer[4096];
76 int tx_busy; 75 int tx_busy;
77 qemu_irq irq; 76 qemu_irq irq;
78 - qemu_irq *reset_irq;  
79 void (*phys_mem_read)(void *dma_opaque, target_phys_addr_t addr, 77 void (*phys_mem_read)(void *dma_opaque, target_phys_addr_t addr,
80 uint8_t *buf, int len, int do_bswap); 78 uint8_t *buf, int len, int do_bswap);
81 void (*phys_mem_write)(void *dma_opaque, target_phys_addr_t addr, 79 void (*phys_mem_write)(void *dma_opaque, target_phys_addr_t addr,
@@ -84,6 +82,16 @@ struct PCNetState_st { @@ -84,6 +82,16 @@ struct PCNetState_st {
84 int looptest; 82 int looptest;
85 }; 83 };
86 84
  85 +typedef struct {
  86 + PCIDevice pci_dev;
  87 + PCNetState state;
  88 +} PCIPCNetState;
  89 +
  90 +typedef struct {
  91 + SysBusDevice busdev;
  92 + PCNetState state;
  93 +} SysBusPCNetState;
  94 +
87 struct qemu_ether_header { 95 struct qemu_ether_header {
88 uint8_t ether_dhost[6]; 96 uint8_t ether_dhost[6];
89 uint8_t ether_shost[6]; 97 uint8_t ether_shost[6];
@@ -1593,8 +1601,7 @@ static void pcnet_h_reset(void *opaque) @@ -1593,8 +1601,7 @@ static void pcnet_h_reset(void *opaque)
1593 1601
1594 /* Initialize the PROM */ 1602 /* Initialize the PROM */
1595 1603
1596 - if (s->nd)  
1597 - memcpy(s->prom, s->nd->macaddr, 6); 1604 + memcpy(s->prom, s->macaddr, 6);
1598 s->prom[12] = s->prom[13] = 0x00; 1605 s->prom[12] = s->prom[13] = 0x00;
1599 s->prom[14] = s->prom[15] = 0x57; 1606 s->prom[14] = s->prom[15] = 0x57;
1600 1607
@@ -1754,7 +1761,7 @@ static uint32_t pcnet_ioport_readl(void *opaque, uint32_t addr) @@ -1754,7 +1761,7 @@ static uint32_t pcnet_ioport_readl(void *opaque, uint32_t addr)
1754 static void pcnet_ioport_map(PCIDevice *pci_dev, int region_num, 1761 static void pcnet_ioport_map(PCIDevice *pci_dev, int region_num,
1755 uint32_t addr, uint32_t size, int type) 1762 uint32_t addr, uint32_t size, int type)
1756 { 1763 {
1757 - PCNetState *d = (PCNetState *)pci_dev; 1764 + PCNetState *d = &((PCIPCNetState *)pci_dev)->state;
1758 1765
1759 #ifdef PCNET_DEBUG_IO 1766 #ifdef PCNET_DEBUG_IO
1760 printf("pcnet_ioport_map addr=0x%04x size=0x%04x\n", addr, size); 1767 printf("pcnet_ioport_map addr=0x%04x size=0x%04x\n", addr, size);
@@ -1938,23 +1945,17 @@ static void pcnet_common_cleanup(PCNetState *d) @@ -1938,23 +1945,17 @@ static void pcnet_common_cleanup(PCNetState *d)
1938 qemu_free_timer(d->poll_timer); 1945 qemu_free_timer(d->poll_timer);
1939 } 1946 }
1940 1947
1941 -static void pcnet_common_init(PCNetState *d, NICInfo *nd, NetCleanup *cleanup) 1948 +static void pcnet_common_init(DeviceState *dev, PCNetState *s,
  1949 + NetCleanup *cleanup)
1942 { 1950 {
1943 - d->poll_timer = qemu_new_timer(vm_clock, pcnet_poll_timer, d);  
1944 -  
1945 - d->nd = nd;  
1946 -  
1947 - if (nd && nd->vlan) {  
1948 - d->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,  
1949 - pcnet_receive, pcnet_can_receive,  
1950 - cleanup, d);  
1951 -  
1952 - qemu_format_nic_info_str(d->vc, d->nd->macaddr);  
1953 - } else {  
1954 - d->vc = NULL;  
1955 - }  
1956 - pcnet_h_reset(d);  
1957 - register_savevm("pcnet", -1, 2, pcnet_save, pcnet_load, d); 1951 + s->poll_timer = qemu_new_timer(vm_clock, pcnet_poll_timer, s);
  1952 +
  1953 + qdev_get_macaddr(dev, s->macaddr);
  1954 + s->vc = qdev_get_vlan_client(dev,
  1955 + pcnet_receive, pcnet_can_receive,
  1956 + cleanup, s);
  1957 + pcnet_h_reset(s);
  1958 + register_savevm("pcnet", -1, 2, pcnet_save, pcnet_load, s);
1958 } 1959 }
1959 1960
1960 /* PCI interface */ 1961 /* PCI interface */
@@ -1974,13 +1975,13 @@ static CPUReadMemoryFunc *pcnet_mmio_read[] = { @@ -1974,13 +1975,13 @@ static CPUReadMemoryFunc *pcnet_mmio_read[] = {
1974 static void pcnet_mmio_map(PCIDevice *pci_dev, int region_num, 1975 static void pcnet_mmio_map(PCIDevice *pci_dev, int region_num,
1975 uint32_t addr, uint32_t size, int type) 1976 uint32_t addr, uint32_t size, int type)
1976 { 1977 {
1977 - PCNetState *d = (PCNetState *)pci_dev; 1978 + PCIPCNetState *d = (PCIPCNetState *)pci_dev;
1978 1979
1979 #ifdef PCNET_DEBUG_IO 1980 #ifdef PCNET_DEBUG_IO
1980 printf("pcnet_mmio_map addr=0x%08x 0x%08x\n", addr, size); 1981 printf("pcnet_mmio_map addr=0x%08x 0x%08x\n", addr, size);
1981 #endif 1982 #endif
1982 1983
1983 - cpu_register_physical_memory(addr, PCNET_PNPMMIO_SIZE, d->mmio_index); 1984 + cpu_register_physical_memory(addr, PCNET_PNPMMIO_SIZE, d->state.mmio_index);
1984 } 1985 }
1985 1986
1986 static void pci_physical_memory_write(void *dma_opaque, target_phys_addr_t addr, 1987 static void pci_physical_memory_write(void *dma_opaque, target_phys_addr_t addr,
@@ -2004,16 +2005,17 @@ static void pci_pcnet_cleanup(VLANClientState *vc) @@ -2004,16 +2005,17 @@ static void pci_pcnet_cleanup(VLANClientState *vc)
2004 2005
2005 static int pci_pcnet_uninit(PCIDevice *dev) 2006 static int pci_pcnet_uninit(PCIDevice *dev)
2006 { 2007 {
2007 - PCNetState *d = (PCNetState *)dev; 2008 + PCIPCNetState *d = (PCIPCNetState *)dev;
2008 2009
2009 - cpu_unregister_io_memory(d->mmio_index); 2010 + cpu_unregister_io_memory(d->state.mmio_index);
2010 2011
2011 return 0; 2012 return 0;
2012 } 2013 }
2013 2014
2014 -PCIDevice *pci_pcnet_init(PCIBus *bus, NICInfo *nd, int devfn) 2015 +static void pci_pcnet_init(PCIDevice *pci_dev)
2015 { 2016 {
2016 - PCNetState *d; 2017 + PCIPCNetState *d = (PCIPCNetState *)pci_dev;
  2018 + PCNetState *s = &d->state;
2017 uint8_t *pci_conf; 2019 uint8_t *pci_conf;
2018 2020
2019 #if 0 2021 #if 0
@@ -2021,14 +2023,9 @@ PCIDevice *pci_pcnet_init(PCIBus *bus, NICInfo *nd, int devfn) @@ -2021,14 +2023,9 @@ PCIDevice *pci_pcnet_init(PCIBus *bus, NICInfo *nd, int devfn)
2021 sizeof(struct pcnet_RMD), sizeof(struct pcnet_TMD)); 2023 sizeof(struct pcnet_RMD), sizeof(struct pcnet_TMD));
2022 #endif 2024 #endif
2023 2025
2024 - d = (PCNetState *)pci_register_device(bus, "PCNet", sizeof(PCNetState),  
2025 - devfn, NULL, NULL);  
2026 - if (!d)  
2027 - return NULL;  
2028 -  
2029 - d->dev.unregister = pci_pcnet_uninit; 2026 + pci_dev->unregister = pci_pcnet_uninit;
2030 2027
2031 - pci_conf = d->dev.config; 2028 + pci_conf = pci_dev->config;
2032 2029
2033 pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_AMD); 2030 pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_AMD);
2034 pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_AMD_LANCE); 2031 pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_AMD_LANCE);
@@ -2047,8 +2044,8 @@ PCIDevice *pci_pcnet_init(PCIBus *bus, NICInfo *nd, int devfn) @@ -2047,8 +2044,8 @@ PCIDevice *pci_pcnet_init(PCIBus *bus, NICInfo *nd, int devfn)
2047 pci_conf[0x3f] = 0xff; 2044 pci_conf[0x3f] = 0xff;
2048 2045
2049 /* Handler for memory-mapped I/O */ 2046 /* Handler for memory-mapped I/O */
2050 - d->mmio_index =  
2051 - cpu_register_io_memory(0, pcnet_mmio_read, pcnet_mmio_write, d); 2047 + s->mmio_index =
  2048 + cpu_register_io_memory(0, pcnet_mmio_read, pcnet_mmio_write, &d->state);
2052 2049
2053 pci_register_io_region((PCIDevice *)d, 0, PCNET_IOPORT_SIZE, 2050 pci_register_io_region((PCIDevice *)d, 0, PCNET_IOPORT_SIZE,
2054 PCI_ADDRESS_SPACE_IO, pcnet_ioport_map); 2051 PCI_ADDRESS_SPACE_IO, pcnet_ioport_map);
@@ -2056,14 +2053,12 @@ PCIDevice *pci_pcnet_init(PCIBus *bus, NICInfo *nd, int devfn) @@ -2056,14 +2053,12 @@ PCIDevice *pci_pcnet_init(PCIBus *bus, NICInfo *nd, int devfn)
2056 pci_register_io_region((PCIDevice *)d, 1, PCNET_PNPMMIO_SIZE, 2053 pci_register_io_region((PCIDevice *)d, 1, PCNET_PNPMMIO_SIZE,
2057 PCI_ADDRESS_SPACE_MEM, pcnet_mmio_map); 2054 PCI_ADDRESS_SPACE_MEM, pcnet_mmio_map);
2058 2055
2059 - d->irq = d->dev.irq[0];  
2060 - d->phys_mem_read = pci_physical_memory_read;  
2061 - d->phys_mem_write = pci_physical_memory_write;  
2062 - d->pci_dev = &d->dev; 2056 + s->irq = pci_dev->irq[0];
  2057 + s->phys_mem_read = pci_physical_memory_read;
  2058 + s->phys_mem_write = pci_physical_memory_write;
  2059 + s->pci_dev = pci_dev;
2063 2060
2064 - pcnet_common_init(d, nd, pci_pcnet_cleanup);  
2065 -  
2066 - return (PCIDevice *)d; 2061 + pcnet_common_init(&pci_dev->qdev, s, pci_pcnet_cleanup);
2067 } 2062 }
2068 2063
2069 /* SPARC32 interface */ 2064 /* SPARC32 interface */
@@ -2117,37 +2112,37 @@ static void lance_cleanup(VLANClientState *vc) @@ -2117,37 +2112,37 @@ static void lance_cleanup(VLANClientState *vc)
2117 PCNetState *d = vc->opaque; 2112 PCNetState *d = vc->opaque;
2118 2113
2119 pcnet_common_cleanup(d); 2114 pcnet_common_cleanup(d);
2120 -  
2121 - qemu_free_irqs(d->reset_irq);  
2122 -  
2123 - cpu_unregister_io_memory(d->mmio_index);  
2124 -  
2125 - qemu_free(d);  
2126 } 2115 }
2127 2116
2128 -void lance_init(NICInfo *nd, target_phys_addr_t leaddr, void *dma_opaque,  
2129 - qemu_irq irq, qemu_irq *reset) 2117 +static void lance_init(SysBusDevice *dev)
2130 { 2118 {
2131 - PCNetState *d;  
2132 -  
2133 - qemu_check_nic_model(nd, "lance"); 2119 + SysBusPCNetState *d = FROM_SYSBUS(SysBusPCNetState, dev);
  2120 + PCNetState *s = &d->state;
2134 2121
2135 - d = qemu_mallocz(sizeof(PCNetState));  
2136 -  
2137 - d->mmio_index = 2122 + s->mmio_index =
2138 cpu_register_io_memory(0, lance_mem_read, lance_mem_write, d); 2123 cpu_register_io_memory(0, lance_mem_read, lance_mem_write, d);
2139 2124
2140 - d->dma_opaque = dma_opaque; 2125 + s->dma_opaque = qdev_get_prop_ptr(&dev->qdev, "dma");
  2126 +
  2127 + qdev_init_irq_sink(&dev->qdev, parent_lance_reset, 1);
2141 2128
2142 - d->reset_irq = qemu_allocate_irqs(parent_lance_reset, d, 1);  
2143 - *reset = *d->reset_irq; 2129 + sysbus_init_mmio(dev, 4, s->mmio_index);
2144 2130
2145 - cpu_register_physical_memory(leaddr, 4, d->mmio_index); 2131 + sysbus_init_irq(dev, &s->irq);
2146 2132
2147 - d->irq = irq;  
2148 - d->phys_mem_read = ledma_memory_read;  
2149 - d->phys_mem_write = ledma_memory_write; 2133 + s->phys_mem_read = ledma_memory_read;
  2134 + s->phys_mem_write = ledma_memory_write;
2150 2135
2151 - pcnet_common_init(d, nd, lance_cleanup); 2136 + pcnet_common_init(&dev->qdev, s, lance_cleanup);
2152 } 2137 }
2153 #endif /* TARGET_SPARC */ 2138 #endif /* TARGET_SPARC */
  2139 +
  2140 +static void pcnet_register_devices(void)
  2141 +{
  2142 + pci_qdev_register("pcnet", sizeof(PCIPCNetState), pci_pcnet_init);
  2143 +#if defined (TARGET_SPARC) && !defined(TARGET_SPARC64)
  2144 + sysbus_register_dev("lance", sizeof(SysBusPCNetState), lance_init);
  2145 +#endif
  2146 +}
  2147 +
  2148 +device_init(pcnet_register_devices)
hw/qdev.c
@@ -26,6 +26,7 @@ @@ -26,6 +26,7 @@
26 inherit from a particular bus (e.g. PCI or I2C) rather than 26 inherit from a particular bus (e.g. PCI or I2C) rather than
27 this API directly. */ 27 this API directly. */
28 28
  29 +#include "net.h"
29 #include "qdev.h" 30 #include "qdev.h"
30 #include "sysemu.h" 31 #include "sysemu.h"
31 32
@@ -135,6 +136,12 @@ void qdev_set_prop_ptr(DeviceState *dev, const char *name, void *value) @@ -135,6 +136,12 @@ void qdev_set_prop_ptr(DeviceState *dev, const char *name, void *value)
135 prop->value.ptr = value; 136 prop->value.ptr = value;
136 } 137 }
137 138
  139 +void qdev_set_netdev(DeviceState *dev, NICInfo *nd)
  140 +{
  141 + assert(!dev->nd);
  142 + dev->nd = nd;
  143 +}
  144 +
138 145
139 qemu_irq qdev_get_irq_sink(DeviceState *dev, int n) 146 qemu_irq qdev_get_irq_sink(DeviceState *dev, int n)
140 { 147 {
@@ -225,6 +232,24 @@ void qdev_connect_gpio_out(DeviceState * dev, int n, qemu_irq pin) @@ -225,6 +232,24 @@ void qdev_connect_gpio_out(DeviceState * dev, int n, qemu_irq pin)
225 dev->gpio_out[n] = pin; 232 dev->gpio_out[n] = pin;
226 } 233 }
227 234
  235 +VLANClientState *qdev_get_vlan_client(DeviceState *dev,
  236 + IOReadHandler *fd_read,
  237 + IOCanRWHandler *fd_can_read,
  238 + NetCleanup *cleanup,
  239 + void *opaque)
  240 +{
  241 + NICInfo *nd = dev->nd;
  242 + assert(nd);
  243 + return qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
  244 + fd_read, fd_can_read, cleanup, opaque);
  245 +}
  246 +
  247 +
  248 +void qdev_get_macaddr(DeviceState *dev, uint8_t *macaddr)
  249 +{
  250 + memcpy(macaddr, dev->nd->macaddr, 6);
  251 +}
  252 +
228 static int next_block_unit[IF_COUNT]; 253 static int next_block_unit[IF_COUNT];
229 254
230 /* Get a block device. This should only be used for single-drive devices 255 /* Get a block device. This should only be used for single-drive devices
hw/qdev.h
@@ -24,6 +24,7 @@ struct DeviceState @@ -24,6 +24,7 @@ struct DeviceState
24 int num_gpio_in; 24 int num_gpio_in;
25 qemu_irq *gpio_in; 25 qemu_irq *gpio_in;
26 ChildBusList *child_bus; 26 ChildBusList *child_bus;
  27 + NICInfo *nd;
27 }; 28 };
28 29
29 /*** Board API. This should go away once we have a machine config file. ***/ 30 /*** Board API. This should go away once we have a machine config file. ***/
@@ -34,6 +35,7 @@ void qdev_init(DeviceState *dev); @@ -34,6 +35,7 @@ void qdev_init(DeviceState *dev);
34 /* Set properties between creation and init. */ 35 /* Set properties between creation and init. */
35 void qdev_set_prop_int(DeviceState *dev, const char *name, int value); 36 void qdev_set_prop_int(DeviceState *dev, const char *name, int value);
36 void qdev_set_prop_ptr(DeviceState *dev, const char *name, void *value); 37 void qdev_set_prop_ptr(DeviceState *dev, const char *name, void *value);
  38 +void qdev_set_netdev(DeviceState *dev, NICInfo *nd);
37 39
38 qemu_irq qdev_get_irq_sink(DeviceState *dev, int n); 40 qemu_irq qdev_get_irq_sink(DeviceState *dev, int n);
39 qemu_irq qdev_get_gpio_in(DeviceState *dev, int n); 41 qemu_irq qdev_get_gpio_in(DeviceState *dev, int n);
hw/rtl8139.c
@@ -3441,19 +3441,12 @@ static int pci_rtl8139_uninit(PCIDevice *dev) @@ -3441,19 +3441,12 @@ static int pci_rtl8139_uninit(PCIDevice *dev)
3441 return 0; 3441 return 0;
3442 } 3442 }
3443 3443
3444 -PCIDevice *pci_rtl8139_init(PCIBus *bus, NICInfo *nd, int devfn) 3444 +static void pci_rtl8139_init(PCIDevice *dev)
3445 { 3445 {
3446 - PCIRTL8139State *d; 3446 + PCIRTL8139State *d = (PCIRTL8139State *)dev;
3447 RTL8139State *s; 3447 RTL8139State *s;
3448 uint8_t *pci_conf; 3448 uint8_t *pci_conf;
3449 3449
3450 - d = (PCIRTL8139State *)pci_register_device(bus,  
3451 - "RTL8139", sizeof(PCIRTL8139State),  
3452 - devfn,  
3453 - NULL, NULL);  
3454 - if (!d)  
3455 - return NULL;  
3456 -  
3457 d->dev.unregister = pci_rtl8139_uninit; 3450 d->dev.unregister = pci_rtl8139_uninit;
3458 3451
3459 pci_conf = d->dev.config; 3452 pci_conf = d->dev.config;
@@ -3479,9 +3472,9 @@ PCIDevice *pci_rtl8139_init(PCIBus *bus, NICInfo *nd, int devfn) @@ -3479,9 +3472,9 @@ PCIDevice *pci_rtl8139_init(PCIBus *bus, NICInfo *nd, int devfn)
3479 PCI_ADDRESS_SPACE_MEM, rtl8139_mmio_map); 3472 PCI_ADDRESS_SPACE_MEM, rtl8139_mmio_map);
3480 3473
3481 s->pci_dev = (PCIDevice *)d; 3474 s->pci_dev = (PCIDevice *)d;
3482 - memcpy(s->macaddr, nd->macaddr, 6); 3475 + qdev_get_macaddr(&dev->qdev, s->macaddr);
3483 rtl8139_reset(s); 3476 rtl8139_reset(s);
3484 - s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name, 3477 + s->vc = qdev_get_vlan_client(&dev->qdev,
3485 rtl8139_receive, rtl8139_can_receive, 3478 rtl8139_receive, rtl8139_can_receive,
3486 rtl8139_cleanup, s); 3479 rtl8139_cleanup, s);
3487 3480
@@ -3499,5 +3492,11 @@ PCIDevice *pci_rtl8139_init(PCIBus *bus, NICInfo *nd, int devfn) @@ -3499,5 +3492,11 @@ PCIDevice *pci_rtl8139_init(PCIBus *bus, NICInfo *nd, int devfn)
3499 qemu_mod_timer(s->timer, 3492 qemu_mod_timer(s->timer,
3500 rtl8139_get_next_tctr_time(s,qemu_get_clock(vm_clock))); 3493 rtl8139_get_next_tctr_time(s,qemu_get_clock(vm_clock)));
3501 #endif /* RTL8139_ONBOARD_TIMER */ 3494 #endif /* RTL8139_ONBOARD_TIMER */
3502 - return (PCIDevice *)d;  
3503 } 3495 }
  3496 +
  3497 +static void rtl8139_register_devices(void)
  3498 +{
  3499 + pci_qdev_register("rtl8139", sizeof(PCIRTL8139State), pci_rtl8139_init);
  3500 +}
  3501 +
  3502 +device_init(rtl8139_register_devices)
hw/sun4m.c
@@ -21,7 +21,7 @@ @@ -21,7 +21,7 @@
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE. 22 * THE SOFTWARE.
23 */ 23 */
24 -#include "hw.h" 24 +#include "sysbus.h"
25 #include "qemu-timer.h" 25 #include "qemu-timer.h"
26 #include "sun4m.h" 26 #include "sun4m.h"
27 #include "nvram.h" 27 #include "nvram.h"
@@ -364,6 +364,24 @@ static unsigned long sun4m_load_kernel(const char *kernel_filename, @@ -364,6 +364,24 @@ static unsigned long sun4m_load_kernel(const char *kernel_filename,
364 return kernel_size; 364 return kernel_size;
365 } 365 }
366 366
  367 +static void lance_init(NICInfo *nd, target_phys_addr_t leaddr,
  368 + void *dma_opaque, qemu_irq irq, qemu_irq *reset)
  369 +{
  370 + DeviceState *dev;
  371 + SysBusDevice *s;
  372 +
  373 + qemu_check_nic_model(&nd_table[0], "lance");
  374 +
  375 + dev = qdev_create(NULL, "lance");
  376 + qdev_set_netdev(dev, nd);
  377 + qdev_set_prop_ptr(dev, "dma", dma_opaque);
  378 + qdev_init(dev);
  379 + s = sysbus_from_qdev(dev);
  380 + sysbus_mmio_map(s, 0, leaddr);
  381 + sysbus_connect_irq(s, 0, irq);
  382 + *reset = qdev_get_irq_sink(dev, 0);
  383 +}
  384 +
367 static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, ram_addr_t RAM_size, 385 static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, ram_addr_t RAM_size,
368 const char *boot_device, 386 const char *boot_device,
369 const char *kernel_filename, 387 const char *kernel_filename,
hw/sun4m.h
@@ -62,10 +62,6 @@ void cs_init(target_phys_addr_t base, int irq, void *intctl); @@ -62,10 +62,6 @@ void cs_init(target_phys_addr_t base, int irq, void *intctl);
62 /* sparc32_dma.c */ 62 /* sparc32_dma.c */
63 #include "sparc32_dma.h" 63 #include "sparc32_dma.h"
64 64
65 -/* pcnet.c */  
66 -void lance_init(NICInfo *nd, target_phys_addr_t leaddr, void *dma_opaque,  
67 - qemu_irq irq, qemu_irq *reset);  
68 -  
69 /* eccmemctl.c */ 65 /* eccmemctl.c */
70 void *ecc_init(target_phys_addr_t base, qemu_irq irq, uint32_t version); 66 void *ecc_init(target_phys_addr_t base, qemu_irq irq, uint32_t version);
71 67
@@ -127,4 +127,11 @@ void net_host_device_remove(Monitor *mon, int vlan_id, const char *device); @@ -127,4 +127,11 @@ void net_host_device_remove(Monitor *mon, int vlan_id, const char *device);
127 #define SMBD_COMMAND "/usr/sbin/smbd" 127 #define SMBD_COMMAND "/usr/sbin/smbd"
128 #endif 128 #endif
129 129
  130 +void qdev_get_macaddr(DeviceState *dev, uint8_t *macaddr);
  131 +VLANClientState *qdev_get_vlan_client(DeviceState *dev,
  132 + IOReadHandler *fd_read,
  133 + IOCanRWHandler *fd_can_read,
  134 + NetCleanup *cleanup,
  135 + void *opaque);
  136 +
130 #endif 137 #endif