}
#endif /* RTL8139_ONBOARD_TIMER */
-void pci_rtl8139_init(PCIBus *bus, NICInfo *nd, int devfn)
+static void rtl8139_cleanup(VLANClientState *vc)
{
- PCIRTL8139State *d;
+ RTL8139State *s = vc->opaque;
+
+ if (s->cplus_txbuffer) {
+ qemu_free(s->cplus_txbuffer);
+ s->cplus_txbuffer = NULL;
+ }
+
+#ifdef RTL8139_ONBOARD_TIMER
+ qemu_del_timer(s->timer);
+ qemu_free_timer(s->timer);
+#endif
+
+ unregister_savevm("rtl8139", s);
+}
+
+static int pci_rtl8139_uninit(PCIDevice *dev)
+{
+ PCIRTL8139State *d = (PCIRTL8139State *)dev;
+ RTL8139State *s = &d->rtl8139;
+
+ cpu_unregister_io_memory(s->rtl8139_mmio_io_addr);
+
+ return 0;
+}
+
+static void pci_rtl8139_init(PCIDevice *dev)
+{
+ PCIRTL8139State *d = (PCIRTL8139State *)dev;
RTL8139State *s;
uint8_t *pci_conf;
- d = (PCIRTL8139State *)pci_register_device(bus,
- "RTL8139", sizeof(PCIRTL8139State),
- devfn,
- NULL, NULL);
+ d->dev.unregister = pci_rtl8139_uninit;
+
pci_conf = d->dev.config;
pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_REALTEK);
pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_REALTEK_8139);
pci_conf[0x04] = 0x05; /* command = I/O space, Bus Master */
pci_conf[0x08] = RTL8139_PCI_REVID; /* PCI revision ID; >=0x20 is for 8139C+ */
- pci_conf[0x0a] = 0x00; /* ethernet network controller */
- pci_conf[0x0b] = 0x02;
- pci_conf[0x0e] = 0x00; /* header_type */
+ pci_config_set_class(pci_conf, PCI_CLASS_NETWORK_ETHERNET);
+ pci_conf[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_NORMAL; /* header_type */
pci_conf[0x3d] = 1; /* interrupt pin 0 */
pci_conf[0x34] = 0xdc;
PCI_ADDRESS_SPACE_MEM, rtl8139_mmio_map);
s->pci_dev = (PCIDevice *)d;
- memcpy(s->macaddr, nd->macaddr, 6);
+ qdev_get_macaddr(&dev->qdev, s->macaddr);
rtl8139_reset(s);
- s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
- rtl8139_receive, rtl8139_can_receive, s);
+ s->vc = qdev_get_vlan_client(&dev->qdev,
+ rtl8139_receive, rtl8139_can_receive,
+ rtl8139_cleanup, s);
qemu_format_nic_info_str(s->vc, s->macaddr);
rtl8139_get_next_tctr_time(s,qemu_get_clock(vm_clock)));
#endif /* RTL8139_ONBOARD_TIMER */
}
+
+static void rtl8139_register_devices(void)
+{
+ pci_qdev_register("rtl8139", sizeof(PCIRTL8139State), pci_rtl8139_init);
+}
+
+device_init(rtl8139_register_devices)