Revision efd6dd45 hw/rtl8139.c

b/hw/rtl8139.c
423 423
static void RTL8139TallyCounters_save(QEMUFile* f, RTL8139TallyCounters *tally_counters);
424 424

  
425 425
typedef struct RTL8139State {
426
    PCIDevice dev;
426 427
    uint8_t phys[8]; /* mac address */
427 428
    uint8_t mult[8]; /* multicast mask array */
428 429

  
......
463 464
    uint16_t CpCmd;
464 465
    uint8_t  TxThresh;
465 466

  
466
    PCIDevice *pci_dev;
467 467
    VLANClientState *vc;
468 468
    uint8_t macaddr[6];
469 469
    int rtl8139_mmio_io_addr;
......
692 692
    DEBUG_PRINT(("RTL8139: Set IRQ to %d (%04x %04x)\n",
693 693
       isr ? 1 : 0, s->IntrStatus, s->IntrMask));
694 694

  
695
    qemu_set_irq(s->pci_dev->irq[0], (isr != 0));
695
    qemu_set_irq(s->dev.irq[0], (isr != 0));
696 696
}
697 697

  
698 698
#define POLYNOMIAL 0x04c11db6
......
3121 3121
    RTL8139State* s=(RTL8139State*)opaque;
3122 3122
    unsigned int i;
3123 3123

  
3124
    pci_device_save(s->pci_dev, f);
3124
    pci_device_save(&s->dev, f);
3125 3125

  
3126 3126
    qemu_put_buffer(f, s->phys, 6);
3127 3127
    qemu_put_buffer(f, s->mult, 8);
......
3215 3215
            return -EINVAL;
3216 3216

  
3217 3217
    if (version_id >= 3) {
3218
        ret = pci_device_load(s->pci_dev, f);
3218
        ret = pci_device_load(&s->dev, f);
3219 3219
        if (ret < 0)
3220 3220
            return ret;
3221 3221
    }
......
3323 3323
/***********************************************************/
3324 3324
/* PCI RTL8139 definitions */
3325 3325

  
3326
typedef struct PCIRTL8139State {
3327
    PCIDevice dev;
3328
    RTL8139State rtl8139;
3329
} PCIRTL8139State;
3330

  
3331 3326
static void rtl8139_mmio_map(PCIDevice *pci_dev, int region_num,
3332 3327
                       uint32_t addr, uint32_t size, int type)
3333 3328
{
3334
    PCIRTL8139State *d = (PCIRTL8139State *)pci_dev;
3335
    RTL8139State *s = &d->rtl8139;
3329
    RTL8139State *s = DO_UPCAST(RTL8139State, dev, pci_dev);
3336 3330

  
3337 3331
    cpu_register_physical_memory(addr + 0, 0x100, s->rtl8139_mmio_io_addr);
3338 3332
}
......
3340 3334
static void rtl8139_ioport_map(PCIDevice *pci_dev, int region_num,
3341 3335
                       uint32_t addr, uint32_t size, int type)
3342 3336
{
3343
    PCIRTL8139State *d = (PCIRTL8139State *)pci_dev;
3344
    RTL8139State *s = &d->rtl8139;
3337
    RTL8139State *s = DO_UPCAST(RTL8139State, dev, pci_dev);
3345 3338

  
3346 3339
    register_ioport_write(addr, 0x100, 1, rtl8139_ioport_writeb, s);
3347 3340
    register_ioport_read( addr, 0x100, 1, rtl8139_ioport_readb,  s);
......
3437 3430

  
3438 3431
static int pci_rtl8139_uninit(PCIDevice *dev)
3439 3432
{
3440
    PCIRTL8139State *d = (PCIRTL8139State *)dev;
3441
    RTL8139State *s = &d->rtl8139;
3433
    RTL8139State *s = DO_UPCAST(RTL8139State, dev, dev);
3442 3434

  
3443 3435
    cpu_unregister_io_memory(s->rtl8139_mmio_io_addr);
3444 3436

  
......
3447 3439

  
3448 3440
static int pci_rtl8139_init(PCIDevice *dev)
3449 3441
{
3450
    PCIRTL8139State *d = (PCIRTL8139State *)dev;
3451
    RTL8139State *s;
3442
    RTL8139State * s = DO_UPCAST(RTL8139State, dev, dev);
3452 3443
    uint8_t *pci_conf;
3453 3444

  
3454
    d->dev.unregister = pci_rtl8139_uninit;
3445
    s->dev.unregister = pci_rtl8139_uninit;
3455 3446

  
3456
    pci_conf = d->dev.config;
3447
    pci_conf = s->dev.config;
3457 3448
    pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_REALTEK);
3458 3449
    pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_REALTEK_8139);
3459 3450
    pci_conf[0x04] = 0x05; /* command = I/O space, Bus Master */
......
3463 3454
    pci_conf[0x3d] = 1;    /* interrupt pin 0 */
3464 3455
    pci_conf[0x34] = 0xdc;
3465 3456

  
3466
    s = &d->rtl8139;
3467

  
3468 3457
    /* I/O handler for memory-mapped I/O */
3469 3458
    s->rtl8139_mmio_io_addr =
3470 3459
    cpu_register_io_memory(rtl8139_mmio_read, rtl8139_mmio_write, s);
3471 3460

  
3472
    pci_register_bar(&d->dev, 0, 0x100,
3461
    pci_register_bar(&s->dev, 0, 0x100,
3473 3462
                           PCI_ADDRESS_SPACE_IO,  rtl8139_ioport_map);
3474 3463

  
3475
    pci_register_bar(&d->dev, 1, 0x100,
3464
    pci_register_bar(&s->dev, 1, 0x100,
3476 3465
                           PCI_ADDRESS_SPACE_MEM, rtl8139_mmio_map);
3477 3466

  
3478
    s->pci_dev = (PCIDevice *)d;
3479 3467
    qdev_get_macaddr(&dev->qdev, s->macaddr);
3480 3468
    qemu_register_reset(rtl8139_reset, s);
3481 3469
    rtl8139_reset(s);
......
3502 3490

  
3503 3491
static PCIDeviceInfo rtl8139_info = {
3504 3492
    .qdev.name = "rtl8139",
3505
    .qdev.size = sizeof(PCIRTL8139State),
3493
    .qdev.size = sizeof(RTL8139State),
3506 3494
    .init      = pci_rtl8139_init,
3507 3495
};
3508 3496

  

Also available in: Unified diff