@@ -122,6 +122,7 @@
#define NE2000_MEM_SIZE NE2000_PMEM_END
typedef struct NE2000State {
+ PCIDevice dev;
uint8_t cmd;
uint32_t start;
uint32_t stop;
@@ -771,16 +772,10 @@ void isa_ne2000_init(int base, qemu_irq irq, NICInfo *nd)
/***********************************************************/
/* PCI NE2000 definitions */
-typedef struct PCINE2000State {
- PCIDevice dev;
- NE2000State ne2000;
-} PCINE2000State;
-
static void ne2000_map(PCIDevice *pci_dev, int region_num,
uint32_t addr, uint32_t size, int type)
{
- PCINE2000State *d = (PCINE2000State *)pci_dev;
- NE2000State *s = &d->ne2000;
+ NE2000State *s = DO_UPCAST(NE2000State, dev, pci_dev);
register_ioport_write(addr, 16, 1, ne2000_ioport_write, s);
register_ioport_read(addr, 16, 1, ne2000_ioport_read, s);
@@ -805,25 +800,23 @@ static void ne2000_cleanup(VLANClientState *vc)
static void pci_ne2000_init(PCIDevice *pci_dev)
{
- PCINE2000State *d = (PCINE2000State *)pci_dev;
- NE2000State *s;
+ NE2000State *s = DO_UPCAST(NE2000State, dev, pci_dev);
uint8_t *pci_conf;
- pci_conf = d->dev.config;
+ pci_conf = s->dev.config;
pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_REALTEK);
pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_REALTEK_8029);
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_register_bar(&d->dev, 0, 0x100,
+ pci_register_bar(&s->dev, 0, 0x100,
PCI_ADDRESS_SPACE_IO, ne2000_map);
- s = &d->ne2000;
- s->irq = d->dev.irq[0];
- s->pci_dev = pci_dev;
- qdev_get_macaddr(&d->dev.qdev, s->macaddr);
+ s->irq = s->dev.irq[0];
+ s->pci_dev = &s->dev;
+ qdev_get_macaddr(&s->dev.qdev, s->macaddr);
ne2000_reset(s);
- s->vc = qdev_get_vlan_client(&d->dev.qdev,
+ s->vc = qdev_get_vlan_client(&s->dev.qdev,
ne2000_can_receive, ne2000_receive, NULL,
ne2000_cleanup, s);
@@ -834,7 +827,7 @@ static void pci_ne2000_init(PCIDevice *pci_dev)
static PCIDeviceInfo ne2000_info = {
.qdev.name = "ne2k_pci",
- .qdev.size = sizeof(PCINE2000State),
+ .qdev.size = sizeof(NE2000State),
.init = pci_ne2000_init,
};
Once there, do the right DO_UPCAST instead of cast. Note that we maintain pci_dev field in this case, because there exist ne2000 isa cards. They to diferentiate them is that isa ones don't set this link. Signed-off-by: Juan Quintela <quintela@redhat.com> --- hw/ne2000.c | 27 ++++++++++----------------- 1 files changed, 10 insertions(+), 17 deletions(-)