From 6783ecf144c80f526c844cade3bf5593fba9e446 Mon Sep 17 00:00:00 2001 From: Peter Maydell Date: Thu, 27 Jun 2013 12:03:44 +0100 Subject: [PATCH 01/55] hw: Avoid use of QOM type name macros in VMStateDescriptions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The name field in a VMStateDescription is part of the migration state versioning, so changing it will break migration. It's therefore a bad idea to use a QOM typename macro to initialize it, because in general we're free to rename QOM types as part of code refactoring and cleanup. For the handful of devices that were doing this by mistake, replace the QOM typenames with the corresponding literal strings. Signed-off-by: Peter Maydell [AF: Use TYPE_PVSCSI for TypeInfo instead] Signed-off-by: Andreas Färber --- hw/i2c/exynos4210_i2c.c | 2 +- hw/scsi/vmw_pvscsi.c | 4 ++-- hw/timer/imx_epit.c | 2 +- hw/timer/imx_gpt.c | 2 +- hw/usb/ccid-card-passthru.c | 2 +- hw/usb/dev-smartcard-reader.c | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/hw/i2c/exynos4210_i2c.c b/hw/i2c/exynos4210_i2c.c index 52bffa5010..42f5e89496 100644 --- a/hw/i2c/exynos4210_i2c.c +++ b/hw/i2c/exynos4210_i2c.c @@ -271,7 +271,7 @@ static const MemoryRegionOps exynos4210_i2c_ops = { }; static const VMStateDescription exynos4210_i2c_vmstate = { - .name = TYPE_EXYNOS4_I2C, + .name = "exynos4210.i2c", .version_id = 1, .minimum_version_id = 1, .fields = (VMStateField[]) { diff --git a/hw/scsi/vmw_pvscsi.c b/hw/scsi/vmw_pvscsi.c index 97d3aa3e6f..e1074e1d8d 100644 --- a/hw/scsi/vmw_pvscsi.c +++ b/hw/scsi/vmw_pvscsi.c @@ -1136,7 +1136,7 @@ pvscsi_post_load(void *opaque, int version_id) } static const VMStateDescription vmstate_pvscsi = { - .name = TYPE_PVSCSI, + .name = "pvscsi", .version_id = 0, .minimum_version_id = 0, .minimum_version_id_old = 0, @@ -1201,7 +1201,7 @@ static void pvscsi_class_init(ObjectClass *klass, void *data) } static const TypeInfo pvscsi_info = { - .name = "pvscsi", + .name = TYPE_PVSCSI, .parent = TYPE_PCI_DEVICE, .instance_size = sizeof(PVSCSIState), .class_init = pvscsi_class_init, diff --git a/hw/timer/imx_epit.c b/hw/timer/imx_epit.c index e24e0c4916..117dc7bcbb 100644 --- a/hw/timer/imx_epit.c +++ b/hw/timer/imx_epit.c @@ -370,7 +370,7 @@ static const MemoryRegionOps imx_epit_ops = { }; static const VMStateDescription vmstate_imx_timer_epit = { - .name = TYPE_IMX_EPIT, + .name = "imx.epit", .version_id = 2, .minimum_version_id = 2, .minimum_version_id_old = 2, diff --git a/hw/timer/imx_gpt.c b/hw/timer/imx_gpt.c index 97fbebbe80..87db0e195c 100644 --- a/hw/timer/imx_gpt.c +++ b/hw/timer/imx_gpt.c @@ -142,7 +142,7 @@ typedef struct { } IMXGPTState; static const VMStateDescription vmstate_imx_timer_gpt = { - .name = TYPE_IMX_GPT, + .name = "imx.gpt", .version_id = 3, .minimum_version_id = 3, .minimum_version_id_old = 3, diff --git a/hw/usb/ccid-card-passthru.c b/hw/usb/ccid-card-passthru.c index 01c7e6f20d..5f01ff1e16 100644 --- a/hw/usb/ccid-card-passthru.c +++ b/hw/usb/ccid-card-passthru.c @@ -364,7 +364,7 @@ static int passthru_exitfn(CCIDCardState *base) } static VMStateDescription passthru_vmstate = { - .name = PASSTHRU_DEV_NAME, + .name = "ccid-card-passthru", .version_id = 1, .minimum_version_id = 1, .fields = (VMStateField[]) { diff --git a/hw/usb/dev-smartcard-reader.c b/hw/usb/dev-smartcard-reader.c index 125cc2c221..b33eb25b39 100644 --- a/hw/usb/dev-smartcard-reader.c +++ b/hw/usb/dev-smartcard-reader.c @@ -1397,7 +1397,7 @@ static VMStateDescription usb_device_vmstate = { }; static VMStateDescription ccid_vmstate = { - .name = CCID_DEV_NAME, + .name = "usb-ccid", .version_id = 1, .minimum_version_id = 1, .post_load = ccid_post_load, From 567a3c9e7f98f698d1aeb73e32ca614086b63837 Mon Sep 17 00:00:00 2001 From: Peter Crosthwaite Date: Mon, 24 Jun 2013 16:50:30 +1000 Subject: [PATCH 02/55] net/e1000: QOM Upcast Sweep MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Define and use standard QOM cast macro. Remove usages of DO_UPCAST() and direct -> style upcasting. Signed-off-by: Peter Crosthwaite Signed-off-by: Andreas Färber --- hw/net/e1000.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/hw/net/e1000.c b/hw/net/e1000.c index 5f04f135af..061b9cf603 100644 --- a/hw/net/e1000.c +++ b/hw/net/e1000.c @@ -138,6 +138,11 @@ typedef struct E1000State_st { uint32_t compat_flags; } E1000State; +#define TYPE_E1000 "e1000" + +#define E1000(obj) \ + OBJECT_CHECK(E1000State, (obj), TYPE_E1000) + #define defreg(x) x = (E1000_##x>>2) enum { defreg(CTRL), defreg(EECD), defreg(EERD), defreg(GPRC), @@ -1298,7 +1303,7 @@ e1000_cleanup(NetClientState *nc) static void pci_e1000_uninit(PCIDevice *dev) { - E1000State *d = DO_UPCAST(E1000State, dev, dev); + E1000State *d = E1000(dev); qemu_del_timer(d->autoneg_timer); qemu_free_timer(d->autoneg_timer); @@ -1318,7 +1323,8 @@ static NetClientInfo net_e1000_info = { static int pci_e1000_init(PCIDevice *pci_dev) { - E1000State *d = DO_UPCAST(E1000State, dev, pci_dev); + DeviceState *dev = DEVICE(pci_dev); + E1000State *d = E1000(pci_dev); uint8_t *pci_conf; uint16_t checksum = 0; int i; @@ -1349,11 +1355,11 @@ static int pci_e1000_init(PCIDevice *pci_dev) d->eeprom_data[EEPROM_CHECKSUM_REG] = checksum; d->nic = qemu_new_nic(&net_e1000_info, &d->conf, - object_get_typename(OBJECT(d)), d->dev.qdev.id, d); + object_get_typename(OBJECT(d)), dev->id, d); qemu_format_nic_info_str(qemu_get_queue(d->nic), macaddr); - add_boot_device_path(d->conf.bootindex, &pci_dev->qdev, "/ethernet-phy@0"); + add_boot_device_path(d->conf.bootindex, dev, "/ethernet-phy@0"); d->autoneg_timer = qemu_new_timer_ms(vm_clock, e1000_autoneg_timer, d); @@ -1362,7 +1368,7 @@ static int pci_e1000_init(PCIDevice *pci_dev) static void qdev_e1000_reset(DeviceState *dev) { - E1000State *d = DO_UPCAST(E1000State, dev.qdev, dev); + E1000State *d = E1000(dev); e1000_reset(d); } @@ -1392,7 +1398,7 @@ static void e1000_class_init(ObjectClass *klass, void *data) } static const TypeInfo e1000_info = { - .name = "e1000", + .name = TYPE_E1000, .parent = TYPE_PCI_DEVICE, .instance_size = sizeof(E1000State), .class_init = e1000_class_init, From b08340d52b51ab57ba525043dbc83e67ecfcaa23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Sun, 30 Jun 2013 12:55:52 +0200 Subject: [PATCH 03/55] net/e1000: QOM parent field cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace direct uses of E1000State::dev field with QOM casts and rename it to parent_obj. Acked-by: Peter Crosthwaite Signed-off-by: Andreas Färber --- hw/net/e1000.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/hw/net/e1000.c b/hw/net/e1000.c index 061b9cf603..b952d8d0f3 100644 --- a/hw/net/e1000.c +++ b/hw/net/e1000.c @@ -85,7 +85,10 @@ enum { }; typedef struct E1000State_st { - PCIDevice dev; + /*< private >*/ + PCIDevice parent_obj; + /*< public >*/ + NICState *nic; NICConf conf; MemoryRegion mmio; @@ -245,6 +248,8 @@ static const uint32_t mac_reg_init[] = { static void set_interrupt_cause(E1000State *s, int index, uint32_t val) { + PCIDevice *d = PCI_DEVICE(s); + if (val && (E1000_DEVID >= E1000_DEV_ID_82547EI_MOBILE)) { /* Only for 8257x */ val |= E1000_ICR_INT_ASSERTED; @@ -261,7 +266,7 @@ set_interrupt_cause(E1000State *s, int index, uint32_t val) */ s->mac_reg[ICS] = val; - qemu_set_irq(s->dev.irq[0], (s->mac_reg[IMS] & s->mac_reg[ICR]) != 0); + qemu_set_irq(d->irq[0], (s->mac_reg[IMS] & s->mac_reg[ICR]) != 0); } static void @@ -558,6 +563,7 @@ xmit_seg(E1000State *s) static void process_tx_desc(E1000State *s, struct e1000_tx_desc *dp) { + PCIDevice *d = PCI_DEVICE(s); uint32_t txd_lower = le32_to_cpu(dp->lower.data); uint32_t dtype = txd_lower & (E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D); unsigned int split_size = txd_lower & 0xffff, bytes, sz, op; @@ -615,7 +621,7 @@ process_tx_desc(E1000State *s, struct e1000_tx_desc *dp) bytes = msh - tp->size; bytes = MIN(sizeof(tp->data) - tp->size, bytes); - pci_dma_read(&s->dev, addr, tp->data + tp->size, bytes); + pci_dma_read(d, addr, tp->data + tp->size, bytes); sz = tp->size + bytes; if (sz >= tp->hdr_len && tp->size < tp->hdr_len) { memmove(tp->header, tp->data, tp->hdr_len); @@ -633,7 +639,7 @@ process_tx_desc(E1000State *s, struct e1000_tx_desc *dp) DBGOUT(TXERR, "TCP segmentation error\n"); } else { split_size = MIN(sizeof(tp->data) - tp->size, split_size); - pci_dma_read(&s->dev, addr, tp->data + tp->size, split_size); + pci_dma_read(d, addr, tp->data + tp->size, split_size); tp->size += split_size; } @@ -652,6 +658,7 @@ process_tx_desc(E1000State *s, struct e1000_tx_desc *dp) static uint32_t txdesc_writeback(E1000State *s, dma_addr_t base, struct e1000_tx_desc *dp) { + PCIDevice *d = PCI_DEVICE(s); uint32_t txd_upper, txd_lower = le32_to_cpu(dp->lower.data); if (!(txd_lower & (E1000_TXD_CMD_RS|E1000_TXD_CMD_RPS))) @@ -659,7 +666,7 @@ txdesc_writeback(E1000State *s, dma_addr_t base, struct e1000_tx_desc *dp) txd_upper = (le32_to_cpu(dp->upper.data) | E1000_TXD_STAT_DD) & ~(E1000_TXD_STAT_EC | E1000_TXD_STAT_LC | E1000_TXD_STAT_TU); dp->upper.data = cpu_to_le32(txd_upper); - pci_dma_write(&s->dev, base + ((char *)&dp->upper - (char *)dp), + pci_dma_write(d, base + ((char *)&dp->upper - (char *)dp), &dp->upper, sizeof(dp->upper)); return E1000_ICR_TXDW; } @@ -675,6 +682,7 @@ static uint64_t tx_desc_base(E1000State *s) static void start_xmit(E1000State *s) { + PCIDevice *d = PCI_DEVICE(s); dma_addr_t base; struct e1000_tx_desc desc; uint32_t tdh_start = s->mac_reg[TDH], cause = E1000_ICS_TXQE; @@ -687,7 +695,7 @@ start_xmit(E1000State *s) while (s->mac_reg[TDH] != s->mac_reg[TDT]) { base = tx_desc_base(s) + sizeof(struct e1000_tx_desc) * s->mac_reg[TDH]; - pci_dma_read(&s->dev, base, &desc, sizeof(desc)); + pci_dma_read(d, base, &desc, sizeof(desc)); DBGOUT(TX, "index %d: %p : %x %x\n", s->mac_reg[TDH], (void *)(intptr_t)desc.buffer_addr, desc.lower.data, @@ -820,6 +828,7 @@ static ssize_t e1000_receive(NetClientState *nc, const uint8_t *buf, size_t size) { E1000State *s = qemu_get_nic_opaque(nc); + PCIDevice *d = PCI_DEVICE(s); struct e1000_rx_desc desc; dma_addr_t base; unsigned int n, rdt; @@ -879,7 +888,7 @@ e1000_receive(NetClientState *nc, const uint8_t *buf, size_t size) desc_size = s->rxbuf_size; } base = rx_desc_base(s) + sizeof(desc) * s->mac_reg[RDH]; - pci_dma_read(&s->dev, base, &desc, sizeof(desc)); + pci_dma_read(d, base, &desc, sizeof(desc)); desc.special = vlan_special; desc.status |= (vlan_status | E1000_RXD_STAT_DD); if (desc.buffer_addr) { @@ -888,7 +897,7 @@ e1000_receive(NetClientState *nc, const uint8_t *buf, size_t size) if (copy_size > s->rxbuf_size) { copy_size = s->rxbuf_size; } - pci_dma_write(&s->dev, le64_to_cpu(desc.buffer_addr), + pci_dma_write(d, le64_to_cpu(desc.buffer_addr), buf + desc_offset + vlan_offset, copy_size); } desc_offset += desc_size; @@ -903,7 +912,7 @@ e1000_receive(NetClientState *nc, const uint8_t *buf, size_t size) } else { // as per intel docs; skip descriptors with null buf addr DBGOUT(RX, "Null RX descriptor!!\n"); } - pci_dma_write(&s->dev, base, &desc, sizeof(desc)); + pci_dma_write(d, base, &desc, sizeof(desc)); if (++s->mac_reg[RDH] * sizeof(desc) >= s->mac_reg[RDLEN]) s->mac_reg[RDH] = 0; @@ -1189,7 +1198,7 @@ static const VMStateDescription vmstate_e1000 = { .pre_save = e1000_pre_save, .post_load = e1000_post_load, .fields = (VMStateField []) { - VMSTATE_PCI_DEVICE(dev, E1000State), + VMSTATE_PCI_DEVICE(parent_obj, E1000State), VMSTATE_UNUSED_TEST(is_version_1, 4), /* was instance id */ VMSTATE_UNUSED(4), /* Was mmio_base. */ VMSTATE_UINT32(rxbuf_size, E1000State), @@ -1330,7 +1339,7 @@ static int pci_e1000_init(PCIDevice *pci_dev) int i; uint8_t *macaddr; - pci_conf = d->dev.config; + pci_conf = pci_dev->config; /* TODO: RST# value should be 0, PCI spec 6.2.4 */ pci_conf[PCI_CACHE_LINE_SIZE] = 0x10; @@ -1339,9 +1348,9 @@ static int pci_e1000_init(PCIDevice *pci_dev) e1000_mmio_setup(d); - pci_register_bar(&d->dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, &d->mmio); + pci_register_bar(pci_dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, &d->mmio); - pci_register_bar(&d->dev, 1, PCI_BASE_ADDRESS_SPACE_IO, &d->io); + pci_register_bar(pci_dev, 1, PCI_BASE_ADDRESS_SPACE_IO, &d->io); memmove(d->eeprom_data, e1000_eeprom_template, sizeof e1000_eeprom_template); From 39257515888a3fbaa7061c4c2aeeadfe1b9c3c15 Mon Sep 17 00:00:00 2001 From: Peter Crosthwaite Date: Mon, 24 Jun 2013 16:51:15 +1000 Subject: [PATCH 04/55] net/rtl8139: QOM Upcast Sweep MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Define and use standard QOM cast macro. Remove usages of DO_UPCAST() and direct -> style upcasting. Signed-off-by: Peter Crosthwaite Signed-off-by: Andreas Färber --- hw/net/rtl8139.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/hw/net/rtl8139.c b/hw/net/rtl8139.c index a00ff581dc..7f89d5a022 100644 --- a/hw/net/rtl8139.c +++ b/hw/net/rtl8139.c @@ -92,6 +92,11 @@ static inline GCC_FMT_ATTR(1, 2) int DPRINTF(const char *fmt, ...) } #endif +#define TYPE_RTL8139 "rtl8139" + +#define RTL8139(obj) \ + OBJECT_CHECK(RTL8139State, (obj), TYPE_RTL8139) + /* Symbolic offsets to registers. */ enum RTL8139_registers { MAC0 = 0, /* Ethernet hardware address. */ @@ -1197,7 +1202,7 @@ static void rtl8139_reset_rxring(RTL8139State *s, uint32_t bufferSize) static void rtl8139_reset(DeviceState *d) { - RTL8139State *s = container_of(d, RTL8139State, dev.qdev); + RTL8139State *s = RTL8139(d); int i; /* restore MAC address */ @@ -1364,6 +1369,8 @@ static const VMStateDescription vmstate_tally_counters = { static void rtl8139_ChipCmd_write(RTL8139State *s, uint32_t val) { + DeviceState *d = DEVICE(s); + val &= 0xff; DPRINTF("ChipCmd write val=0x%08x\n", val); @@ -1371,7 +1378,7 @@ static void rtl8139_ChipCmd_write(RTL8139State *s, uint32_t val) if (val & CmdReset) { DPRINTF("ChipCmd reset\n"); - rtl8139_reset(&s->dev.qdev); + rtl8139_reset(d); } if (val & CmdRxEnb) { @@ -1525,6 +1532,8 @@ static uint32_t rtl8139_BasicModeStatus_read(RTL8139State *s) static void rtl8139_Cfg9346_write(RTL8139State *s, uint32_t val) { + DeviceState *d = DEVICE(s); + val &= 0xff; DPRINTF("Cfg9346 write val=0x%02x\n", val); @@ -1544,7 +1553,7 @@ static void rtl8139_Cfg9346_write(RTL8139State *s, uint32_t val) } else if (opmode == 0x40) { /* Reset. */ val = 0; - rtl8139_reset(&s->dev.qdev); + rtl8139_reset(d); } s->Cfg9346 = val; @@ -3439,7 +3448,7 @@ static void rtl8139_cleanup(NetClientState *nc) static void pci_rtl8139_uninit(PCIDevice *dev) { - RTL8139State *s = DO_UPCAST(RTL8139State, dev, dev); + RTL8139State *s = RTL8139(dev); memory_region_destroy(&s->bar_io); memory_region_destroy(&s->bar_mem); @@ -3477,7 +3486,8 @@ static NetClientInfo net_rtl8139_info = { static int pci_rtl8139_init(PCIDevice *dev) { - RTL8139State * s = DO_UPCAST(RTL8139State, dev, dev); + RTL8139State *s = RTL8139(dev); + DeviceState *d = DEVICE(dev); uint8_t *pci_conf; pci_conf = s->dev.config; @@ -3507,7 +3517,7 @@ static int pci_rtl8139_init(PCIDevice *dev) s->eeprom.contents[9] = s->conf.macaddr.a[4] | s->conf.macaddr.a[5] << 8; s->nic = qemu_new_nic(&net_rtl8139_info, &s->conf, - object_get_typename(OBJECT(dev)), dev->qdev.id, s); + object_get_typename(OBJECT(dev)), d->id, s); qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a); s->cplus_txbuffer = NULL; @@ -3518,7 +3528,7 @@ static int pci_rtl8139_init(PCIDevice *dev) s->timer = qemu_new_timer_ns(vm_clock, rtl8139_timer, s); rtl8139_set_next_tctr_time(s, qemu_get_clock_ns(vm_clock)); - add_boot_device_path(s->conf.bootindex, &dev->qdev, "/ethernet-phy@0"); + add_boot_device_path(s->conf.bootindex, d, "/ethernet-phy@0"); return 0; } @@ -3546,7 +3556,7 @@ static void rtl8139_class_init(ObjectClass *klass, void *data) } static const TypeInfo rtl8139_info = { - .name = "rtl8139", + .name = TYPE_RTL8139, .parent = TYPE_PCI_DEVICE, .instance_size = sizeof(RTL8139State), .class_init = rtl8139_class_init, From 88a411a8a09102b89ea52fe2511265edd3393cf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Sun, 30 Jun 2013 13:09:00 +0200 Subject: [PATCH 05/55] net/rtl8139: QOM parent field cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace direct uses of RTL8139State::dev with QOM casts and rename it to parent_obj. Acked-by: Peter Crosthwaite Signed-off-by: Andreas Färber --- hw/net/rtl8139.c | 88 +++++++++++++++++++++++++++--------------------- 1 file changed, 49 insertions(+), 39 deletions(-) diff --git a/hw/net/rtl8139.c b/hw/net/rtl8139.c index 7f89d5a022..65520340fc 100644 --- a/hw/net/rtl8139.c +++ b/hw/net/rtl8139.c @@ -433,7 +433,10 @@ typedef struct RTL8139TallyCounters static void RTL8139TallyCounters_clear(RTL8139TallyCounters* counters); typedef struct RTL8139State { - PCIDevice dev; + /*< private >*/ + PCIDevice parent_obj; + /*< public >*/ + uint8_t phys[8]; /* mac address */ uint8_t mult[8]; /* multicast mask array */ @@ -706,13 +709,14 @@ static void prom9346_set_wire(RTL8139State *s, int eecs, int eesk, int eedi) static void rtl8139_update_irq(RTL8139State *s) { + PCIDevice *d = PCI_DEVICE(s); int isr; isr = (s->IntrStatus & s->IntrMask) & 0xffff; DPRINTF("Set IRQ to %d (%04x %04x)\n", isr ? 1 : 0, s->IntrStatus, s->IntrMask); - qemu_set_irq(s->dev.irq[0], (isr != 0)); + qemu_set_irq(d->irq[0], (isr != 0)); } static int rtl8139_RxWrap(RTL8139State *s) @@ -743,6 +747,8 @@ static int rtl8139_cp_transmitter_enabled(RTL8139State *s) static void rtl8139_write_buffer(RTL8139State *s, const void *buf, int size) { + PCIDevice *d = PCI_DEVICE(s); + if (s->RxBufAddr + size > s->RxBufferSize) { int wrapped = MOD2(s->RxBufAddr + size, s->RxBufferSize); @@ -754,14 +760,14 @@ static void rtl8139_write_buffer(RTL8139State *s, const void *buf, int size) if (size > wrapped) { - pci_dma_write(&s->dev, s->RxBuf + s->RxBufAddr, + pci_dma_write(d, s->RxBuf + s->RxBufAddr, buf, size-wrapped); } /* reset buffer pointer */ s->RxBufAddr = 0; - pci_dma_write(&s->dev, s->RxBuf + s->RxBufAddr, + pci_dma_write(d, s->RxBuf + s->RxBufAddr, buf + (size-wrapped), wrapped); s->RxBufAddr = wrapped; @@ -771,7 +777,7 @@ static void rtl8139_write_buffer(RTL8139State *s, const void *buf, int size) } /* non-wrapping path or overwrapping enabled */ - pci_dma_write(&s->dev, s->RxBuf + s->RxBufAddr, buf, size); + pci_dma_write(d, s->RxBuf + s->RxBufAddr, buf, size); s->RxBufAddr += size; } @@ -814,6 +820,7 @@ static int rtl8139_can_receive(NetClientState *nc) static ssize_t rtl8139_do_receive(NetClientState *nc, const uint8_t *buf, size_t size_, int do_interrupt) { RTL8139State *s = qemu_get_nic_opaque(nc); + PCIDevice *d = PCI_DEVICE(s); /* size is the length of the buffer passed to the driver */ int size = size_; const uint8_t *dot1q_buf = NULL; @@ -978,13 +985,13 @@ static ssize_t rtl8139_do_receive(NetClientState *nc, const uint8_t *buf, size_t uint32_t val, rxdw0,rxdw1,rxbufLO,rxbufHI; - pci_dma_read(&s->dev, cplus_rx_ring_desc, &val, 4); + pci_dma_read(d, cplus_rx_ring_desc, &val, 4); rxdw0 = le32_to_cpu(val); - pci_dma_read(&s->dev, cplus_rx_ring_desc+4, &val, 4); + pci_dma_read(d, cplus_rx_ring_desc+4, &val, 4); rxdw1 = le32_to_cpu(val); - pci_dma_read(&s->dev, cplus_rx_ring_desc+8, &val, 4); + pci_dma_read(d, cplus_rx_ring_desc+8, &val, 4); rxbufLO = le32_to_cpu(val); - pci_dma_read(&s->dev, cplus_rx_ring_desc+12, &val, 4); + pci_dma_read(d, cplus_rx_ring_desc+12, &val, 4); rxbufHI = le32_to_cpu(val); DPRINTF("+++ C+ mode RX descriptor %d %08x %08x %08x %08x\n", @@ -1052,12 +1059,12 @@ static ssize_t rtl8139_do_receive(NetClientState *nc, const uint8_t *buf, size_t /* receive/copy to target memory */ if (dot1q_buf) { - pci_dma_write(&s->dev, rx_addr, buf, 2 * ETHER_ADDR_LEN); - pci_dma_write(&s->dev, rx_addr + 2 * ETHER_ADDR_LEN, + pci_dma_write(d, rx_addr, buf, 2 * ETHER_ADDR_LEN); + pci_dma_write(d, rx_addr + 2 * ETHER_ADDR_LEN, buf + 2 * ETHER_ADDR_LEN + VLAN_HLEN, size - 2 * ETHER_ADDR_LEN); } else { - pci_dma_write(&s->dev, rx_addr, buf, size); + pci_dma_write(d, rx_addr, buf, size); } if (s->CpCmd & CPlusRxChkSum) @@ -1067,7 +1074,7 @@ static ssize_t rtl8139_do_receive(NetClientState *nc, const uint8_t *buf, size_t /* write checksum */ val = cpu_to_le32(crc32(0, buf, size_)); - pci_dma_write(&s->dev, rx_addr+size, (uint8_t *)&val, 4); + pci_dma_write(d, rx_addr+size, (uint8_t *)&val, 4); /* first segment of received packet flag */ #define CP_RX_STATUS_FS (1<<29) @@ -1113,9 +1120,9 @@ static ssize_t rtl8139_do_receive(NetClientState *nc, const uint8_t *buf, size_t /* update ring data */ val = cpu_to_le32(rxdw0); - pci_dma_write(&s->dev, cplus_rx_ring_desc, (uint8_t *)&val, 4); + pci_dma_write(d, cplus_rx_ring_desc, (uint8_t *)&val, 4); val = cpu_to_le32(rxdw1); - pci_dma_write(&s->dev, cplus_rx_ring_desc+4, (uint8_t *)&val, 4); + pci_dma_write(d, cplus_rx_ring_desc+4, (uint8_t *)&val, 4); /* update tally counter */ ++s->tally_counters.RxOk; @@ -1298,49 +1305,50 @@ static void RTL8139TallyCounters_clear(RTL8139TallyCounters* counters) static void RTL8139TallyCounters_dma_write(RTL8139State *s, dma_addr_t tc_addr) { + PCIDevice *d = PCI_DEVICE(s); RTL8139TallyCounters *tally_counters = &s->tally_counters; uint16_t val16; uint32_t val32; uint64_t val64; val64 = cpu_to_le64(tally_counters->TxOk); - pci_dma_write(&s->dev, tc_addr + 0, (uint8_t *)&val64, 8); + pci_dma_write(d, tc_addr + 0, (uint8_t *)&val64, 8); val64 = cpu_to_le64(tally_counters->RxOk); - pci_dma_write(&s->dev, tc_addr + 8, (uint8_t *)&val64, 8); + pci_dma_write(d, tc_addr + 8, (uint8_t *)&val64, 8); val64 = cpu_to_le64(tally_counters->TxERR); - pci_dma_write(&s->dev, tc_addr + 16, (uint8_t *)&val64, 8); + pci_dma_write(d, tc_addr + 16, (uint8_t *)&val64, 8); val32 = cpu_to_le32(tally_counters->RxERR); - pci_dma_write(&s->dev, tc_addr + 24, (uint8_t *)&val32, 4); + pci_dma_write(d, tc_addr + 24, (uint8_t *)&val32, 4); val16 = cpu_to_le16(tally_counters->MissPkt); - pci_dma_write(&s->dev, tc_addr + 28, (uint8_t *)&val16, 2); + pci_dma_write(d, tc_addr + 28, (uint8_t *)&val16, 2); val16 = cpu_to_le16(tally_counters->FAE); - pci_dma_write(&s->dev, tc_addr + 30, (uint8_t *)&val16, 2); + pci_dma_write(d, tc_addr + 30, (uint8_t *)&val16, 2); val32 = cpu_to_le32(tally_counters->Tx1Col); - pci_dma_write(&s->dev, tc_addr + 32, (uint8_t *)&val32, 4); + pci_dma_write(d, tc_addr + 32, (uint8_t *)&val32, 4); val32 = cpu_to_le32(tally_counters->TxMCol); - pci_dma_write(&s->dev, tc_addr + 36, (uint8_t *)&val32, 4); + pci_dma_write(d, tc_addr + 36, (uint8_t *)&val32, 4); val64 = cpu_to_le64(tally_counters->RxOkPhy); - pci_dma_write(&s->dev, tc_addr + 40, (uint8_t *)&val64, 8); + pci_dma_write(d, tc_addr + 40, (uint8_t *)&val64, 8); val64 = cpu_to_le64(tally_counters->RxOkBrd); - pci_dma_write(&s->dev, tc_addr + 48, (uint8_t *)&val64, 8); + pci_dma_write(d, tc_addr + 48, (uint8_t *)&val64, 8); val32 = cpu_to_le32(tally_counters->RxOkMul); - pci_dma_write(&s->dev, tc_addr + 56, (uint8_t *)&val32, 4); + pci_dma_write(d, tc_addr + 56, (uint8_t *)&val32, 4); val16 = cpu_to_le16(tally_counters->TxAbt); - pci_dma_write(&s->dev, tc_addr + 60, (uint8_t *)&val16, 2); + pci_dma_write(d, tc_addr + 60, (uint8_t *)&val16, 2); val16 = cpu_to_le16(tally_counters->TxUndrn); - pci_dma_write(&s->dev, tc_addr + 62, (uint8_t *)&val16, 2); + pci_dma_write(d, tc_addr + 62, (uint8_t *)&val16, 2); } /* Loads values of tally counters from VM state file */ @@ -1830,13 +1838,14 @@ static int rtl8139_transmit_one(RTL8139State *s, int descriptor) DPRINTF("+++ transmitting from descriptor %d\n", descriptor); + PCIDevice *d = PCI_DEVICE(s); int txsize = s->TxStatus[descriptor] & 0x1fff; uint8_t txbuffer[0x2000]; DPRINTF("+++ transmit reading %d bytes from host memory at 0x%08x\n", txsize, s->TxAddr[descriptor]); - pci_dma_read(&s->dev, s->TxAddr[descriptor], txbuffer, txsize); + pci_dma_read(d, s->TxAddr[descriptor], txbuffer, txsize); /* Mark descriptor as transferred */ s->TxStatus[descriptor] |= TxHostOwns; @@ -1955,6 +1964,7 @@ static int rtl8139_cplus_transmit_one(RTL8139State *s) return 0 ; } + PCIDevice *d = PCI_DEVICE(s); int descriptor = s->currCPlusTxDesc; dma_addr_t cplus_tx_ring_desc = rtl8139_addr64(s->TxAddr[0], s->TxAddr[1]); @@ -1968,13 +1978,13 @@ static int rtl8139_cplus_transmit_one(RTL8139State *s) uint32_t val, txdw0,txdw1,txbufLO,txbufHI; - pci_dma_read(&s->dev, cplus_tx_ring_desc, (uint8_t *)&val, 4); + pci_dma_read(d, cplus_tx_ring_desc, (uint8_t *)&val, 4); txdw0 = le32_to_cpu(val); - pci_dma_read(&s->dev, cplus_tx_ring_desc+4, (uint8_t *)&val, 4); + pci_dma_read(d, cplus_tx_ring_desc+4, (uint8_t *)&val, 4); txdw1 = le32_to_cpu(val); - pci_dma_read(&s->dev, cplus_tx_ring_desc+8, (uint8_t *)&val, 4); + pci_dma_read(d, cplus_tx_ring_desc+8, (uint8_t *)&val, 4); txbufLO = le32_to_cpu(val); - pci_dma_read(&s->dev, cplus_tx_ring_desc+12, (uint8_t *)&val, 4); + pci_dma_read(d, cplus_tx_ring_desc+12, (uint8_t *)&val, 4); txbufHI = le32_to_cpu(val); DPRINTF("+++ C+ mode TX descriptor %d %08x %08x %08x %08x\n", descriptor, @@ -2081,7 +2091,7 @@ static int rtl8139_cplus_transmit_one(RTL8139State *s) DMA_ADDR_FMT" to offset %d\n", txsize, tx_addr, s->cplus_txbuffer_offset); - pci_dma_read(&s->dev, tx_addr, + pci_dma_read(d, tx_addr, s->cplus_txbuffer + s->cplus_txbuffer_offset, txsize); s->cplus_txbuffer_offset += txsize; @@ -2109,7 +2119,7 @@ static int rtl8139_cplus_transmit_one(RTL8139State *s) /* update ring data */ val = cpu_to_le32(txdw0); - pci_dma_write(&s->dev, cplus_tx_ring_desc, (uint8_t *)&val, 4); + pci_dma_write(d, cplus_tx_ring_desc, (uint8_t *)&val, 4); /* Now decide if descriptor being processed is holding the last segment of packet */ if (txdw0 & CP_TX_LS) @@ -3282,7 +3292,7 @@ static const VMStateDescription vmstate_rtl8139 = { .post_load = rtl8139_post_load, .pre_save = rtl8139_pre_save, .fields = (VMStateField []) { - VMSTATE_PCI_DEVICE(dev, RTL8139State), + VMSTATE_PCI_DEVICE(parent_obj, RTL8139State), VMSTATE_PARTIAL_BUFFER(phys, RTL8139State, 6), VMSTATE_BUFFER(mult, RTL8139State), VMSTATE_UINT32_ARRAY(TxStatus, RTL8139State, 4), @@ -3490,7 +3500,7 @@ static int pci_rtl8139_init(PCIDevice *dev) DeviceState *d = DEVICE(dev); uint8_t *pci_conf; - pci_conf = s->dev.config; + pci_conf = dev->config; pci_conf[PCI_INTERRUPT_PIN] = 1; /* interrupt pin A */ /* TODO: start of capability list, but no capability * list bit in status register, and offset 0xdc seems unused. */ @@ -3500,8 +3510,8 @@ static int pci_rtl8139_init(PCIDevice *dev) "rtl8139", 0x100); memory_region_init_io(&s->bar_mem, OBJECT(s), &rtl8139_mmio_ops, s, "rtl8139", 0x100); - pci_register_bar(&s->dev, 0, PCI_BASE_ADDRESS_SPACE_IO, &s->bar_io); - pci_register_bar(&s->dev, 1, PCI_BASE_ADDRESS_SPACE_MEMORY, &s->bar_mem); + pci_register_bar(dev, 0, PCI_BASE_ADDRESS_SPACE_IO, &s->bar_io); + pci_register_bar(dev, 1, PCI_BASE_ADDRESS_SPACE_MEMORY, &s->bar_mem); qemu_macaddr_default_if_unset(&s->conf.macaddr); From 1f8c79468594cc059eac7a26d37fba48107cb2e4 Mon Sep 17 00:00:00 2001 From: Peter Crosthwaite Date: Mon, 24 Jun 2013 16:52:00 +1000 Subject: [PATCH 06/55] net/pcnet-pci: QOM Upcast Sweep MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Define and use standard QOM cast macro. Remove usages of DO_UPCAST() and direct -> style upcasting. Signed-off-by: Peter Crosthwaite [AF: Renamed parent field, renamed from PC_NET to PCNET] Signed-off-by: Andreas Färber --- hw/net/pcnet-pci.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/hw/net/pcnet-pci.c b/hw/net/pcnet-pci.c index f4a5aef426..6ef28f77a2 100644 --- a/hw/net/pcnet-pci.c +++ b/hw/net/pcnet-pci.c @@ -43,9 +43,16 @@ //#define PCNET_DEBUG_TMD //#define PCNET_DEBUG_MATCH +#define TYPE_PCI_PCNET "pcnet" + +#define PCI_PCNET(obj) \ + OBJECT_CHECK(PCIPCNetState, (obj), TYPE_PCI_PCNET) typedef struct { - PCIDevice pci_dev; + /*< private >*/ + PCIDevice parent_obj; + /*< public >*/ + PCNetState state; MemoryRegion io_bar; } PCIPCNetState; @@ -236,7 +243,7 @@ static const VMStateDescription vmstate_pci_pcnet = { .minimum_version_id = 2, .minimum_version_id_old = 2, .fields = (VMStateField []) { - VMSTATE_PCI_DEVICE(pci_dev, PCIPCNetState), + VMSTATE_PCI_DEVICE(parent_obj, PCIPCNetState), VMSTATE_STRUCT(state, PCIPCNetState, 0, vmstate_pcnet, PCNetState), VMSTATE_END_OF_LIST() } @@ -273,7 +280,7 @@ static void pci_pcnet_cleanup(NetClientState *nc) static void pci_pcnet_uninit(PCIDevice *dev) { - PCIPCNetState *d = DO_UPCAST(PCIPCNetState, pci_dev, dev); + PCIPCNetState *d = PCI_PCNET(dev); memory_region_destroy(&d->state.mmio); memory_region_destroy(&d->io_bar); @@ -293,7 +300,7 @@ static NetClientInfo net_pci_pcnet_info = { static int pci_pcnet_init(PCIDevice *pci_dev) { - PCIPCNetState *d = DO_UPCAST(PCIPCNetState, pci_dev, pci_dev); + PCIPCNetState *d = PCI_PCNET(pci_dev); PCNetState *s = &d->state; uint8_t *pci_conf; @@ -329,12 +336,12 @@ static int pci_pcnet_init(PCIDevice *pci_dev) s->phys_mem_write = pci_physical_memory_write; s->dma_opaque = pci_dev; - return pcnet_common_init(&pci_dev->qdev, s, &net_pci_pcnet_info); + return pcnet_common_init(DEVICE(pci_dev), s, &net_pci_pcnet_info); } static void pci_reset(DeviceState *dev) { - PCIPCNetState *d = DO_UPCAST(PCIPCNetState, pci_dev.qdev, dev); + PCIPCNetState *d = PCI_PCNET(dev); pcnet_h_reset(&d->state); } @@ -362,7 +369,7 @@ static void pcnet_class_init(ObjectClass *klass, void *data) } static const TypeInfo pcnet_info = { - .name = "pcnet", + .name = TYPE_PCI_PCNET, .parent = TYPE_PCI_DEVICE, .instance_size = sizeof(PCIPCNetState), .class_init = pcnet_class_init, From 37034575d23a06447e4f44ab365afec6b198c53f Mon Sep 17 00:00:00 2001 From: Peter Crosthwaite Date: Mon, 24 Jun 2013 16:52:45 +1000 Subject: [PATCH 07/55] usb/hcd-xhci: QOM Upcast Sweep MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Define and use standard QOM cast macro. Remove usages of DO_UPCAST() and direct -> style upcasting. Signed-off-by: Peter Crosthwaite [AF: Dropped usb_xhci_init() DeviceState argument and renamed variable] Signed-off-by: Andreas Färber --- hw/usb/hcd-xhci.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c index d7a54fd53f..05668867c2 100644 --- a/hw/usb/hcd-xhci.c +++ b/hw/usb/hcd-xhci.c @@ -482,6 +482,11 @@ struct XHCIState { XHCIRing cmd_ring; }; +#define TYPE_XHCI "nec-usb-xhci" + +#define XHCI(obj) \ + OBJECT_CHECK(XHCIState, (obj), TYPE_XHCI) + typedef struct XHCIEvRingSeg { uint32_t addr_low; uint32_t addr_high; @@ -2681,7 +2686,7 @@ static void xhci_port_reset(XHCIPort *port) static void xhci_reset(DeviceState *dev) { - XHCIState *xhci = DO_UPCAST(XHCIState, pci_dev.qdev, dev); + XHCIState *xhci = XHCI(dev); int i; trace_usb_xhci_reset(); @@ -2926,6 +2931,7 @@ static void xhci_oper_write(void *ptr, hwaddr reg, uint64_t val, unsigned size) { XHCIState *xhci = ptr; + DeviceState *d = DEVICE(ptr); trace_usb_xhci_oper_write(reg, val); @@ -2939,7 +2945,7 @@ static void xhci_oper_write(void *ptr, hwaddr reg, xhci->usbcmd = val & 0xc0f; xhci_mfwrap_update(xhci); if (val & USBCMD_HCRST) { - xhci_reset(&xhci->pci_dev.qdev); + xhci_reset(d); } xhci_intx_update(xhci); break; @@ -3265,8 +3271,9 @@ static USBBusOps xhci_bus_ops = { .wakeup_endpoint = xhci_wakeup_endpoint, }; -static void usb_xhci_init(XHCIState *xhci, DeviceState *dev) +static void usb_xhci_init(XHCIState *xhci) { + DeviceState *dev = DEVICE(xhci); XHCIPort *port; int i, usbports, speedmask; @@ -3281,7 +3288,7 @@ static void usb_xhci_init(XHCIState *xhci, DeviceState *dev) usbports = MAX(xhci->numports_2, xhci->numports_3); xhci->numports = xhci->numports_2 + xhci->numports_3; - usb_bus_new(&xhci->bus, &xhci_bus_ops, &xhci->pci_dev.qdev); + usb_bus_new(&xhci->bus, &xhci_bus_ops, dev); for (i = 0; i < usbports; i++) { speedmask = 0; @@ -3313,14 +3320,14 @@ static int usb_xhci_initfn(struct PCIDevice *dev) { int i, ret; - XHCIState *xhci = DO_UPCAST(XHCIState, pci_dev, dev); + XHCIState *xhci = XHCI(dev); xhci->pci_dev.config[PCI_CLASS_PROG] = 0x30; /* xHCI */ xhci->pci_dev.config[PCI_INTERRUPT_PIN] = 0x01; /* interrupt pin 1 */ xhci->pci_dev.config[PCI_CACHE_LINE_SIZE] = 0x10; xhci->pci_dev.config[0x60] = 0x30; /* release number */ - usb_xhci_init(xhci, &dev->qdev); + usb_xhci_init(xhci); if (xhci->numintrs > MAXINTRS) { xhci->numintrs = MAXINTRS; @@ -3581,7 +3588,7 @@ static void xhci_class_init(ObjectClass *klass, void *data) } static const TypeInfo xhci_info = { - .name = "nec-usb-xhci", + .name = TYPE_XHCI, .parent = TYPE_PCI_DEVICE, .instance_size = sizeof(XHCIState), .class_init = xhci_class_init, From 9b7d3334d062e8c9e4f1b0ad3df35abb08cd8bf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Sun, 30 Jun 2013 13:38:41 +0200 Subject: [PATCH 08/55] usb/hcd-xhci: QOM parent field cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace direct uses of XHCIState::pci_dev with QOM casts and rename it to parent_obj. Acked-by: Peter Crosthwaite Signed-off-by: Andreas Färber --- hw/usb/hcd-xhci.c | 83 +++++++++++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 35 deletions(-) diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c index 05668867c2..9ba3e3e86d 100644 --- a/hw/usb/hcd-xhci.c +++ b/hw/usb/hcd-xhci.c @@ -443,7 +443,10 @@ typedef struct XHCIInterrupter { } XHCIInterrupter; struct XHCIState { - PCIDevice pci_dev; + /*< private >*/ + PCIDevice parent_obj; + /*< public >*/ + USBBus bus; qemu_irq irq; MemoryRegion mem; @@ -659,7 +662,7 @@ static inline void xhci_dma_read_u32s(XHCIState *xhci, dma_addr_t addr, assert((len % sizeof(uint32_t)) == 0); - pci_dma_read(&xhci->pci_dev, addr, buf, len); + pci_dma_read(PCI_DEVICE(xhci), addr, buf, len); for (i = 0; i < (len / sizeof(uint32_t)); i++) { buf[i] = le32_to_cpu(buf[i]); @@ -677,7 +680,7 @@ static inline void xhci_dma_write_u32s(XHCIState *xhci, dma_addr_t addr, for (i = 0; i < (len / sizeof(uint32_t)); i++) { tmp[i] = cpu_to_le32(buf[i]); } - pci_dma_write(&xhci->pci_dev, addr, tmp, len); + pci_dma_write(PCI_DEVICE(xhci), addr, tmp, len); } static XHCIPort *xhci_lookup_port(XHCIState *xhci, struct USBPort *uport) @@ -704,10 +707,11 @@ static XHCIPort *xhci_lookup_port(XHCIState *xhci, struct USBPort *uport) static void xhci_intx_update(XHCIState *xhci) { + PCIDevice *pci_dev = PCI_DEVICE(xhci); int level = 0; - if (msix_enabled(&xhci->pci_dev) || - msi_enabled(&xhci->pci_dev)) { + if (msix_enabled(pci_dev) || + msi_enabled(pci_dev)) { return; } @@ -723,9 +727,10 @@ static void xhci_intx_update(XHCIState *xhci) static void xhci_msix_update(XHCIState *xhci, int v) { + PCIDevice *pci_dev = PCI_DEVICE(xhci); bool enabled; - if (!msix_enabled(&xhci->pci_dev)) { + if (!msix_enabled(pci_dev)) { return; } @@ -736,17 +741,19 @@ static void xhci_msix_update(XHCIState *xhci, int v) if (enabled) { trace_usb_xhci_irq_msix_use(v); - msix_vector_use(&xhci->pci_dev, v); + msix_vector_use(pci_dev, v); xhci->intr[v].msix_used = true; } else { trace_usb_xhci_irq_msix_unuse(v); - msix_vector_unuse(&xhci->pci_dev, v); + msix_vector_unuse(pci_dev, v); xhci->intr[v].msix_used = false; } } static void xhci_intr_raise(XHCIState *xhci, int v) { + PCIDevice *pci_dev = PCI_DEVICE(xhci); + xhci->intr[v].erdp_low |= ERDP_EHB; xhci->intr[v].iman |= IMAN_IP; xhci->usbsts |= USBSTS_EINT; @@ -759,15 +766,15 @@ static void xhci_intr_raise(XHCIState *xhci, int v) return; } - if (msix_enabled(&xhci->pci_dev)) { + if (msix_enabled(pci_dev)) { trace_usb_xhci_irq_msix(v); - msix_notify(&xhci->pci_dev, v); + msix_notify(pci_dev, v); return; } - if (msi_enabled(&xhci->pci_dev)) { + if (msi_enabled(pci_dev)) { trace_usb_xhci_irq_msi(v); - msi_notify(&xhci->pci_dev, v); + msi_notify(pci_dev, v); return; } @@ -790,6 +797,7 @@ static void xhci_die(XHCIState *xhci) static void xhci_write_event(XHCIState *xhci, XHCIEvent *event, int v) { + PCIDevice *pci_dev = PCI_DEVICE(xhci); XHCIInterrupter *intr = &xhci->intr[v]; XHCITRB ev_trb; dma_addr_t addr; @@ -808,7 +816,7 @@ static void xhci_write_event(XHCIState *xhci, XHCIEvent *event, int v) ev_trb.status, ev_trb.control); addr = intr->er_start + TRB_SIZE*intr->er_ep_idx; - pci_dma_write(&xhci->pci_dev, addr, &ev_trb, TRB_SIZE); + pci_dma_write(pci_dev, addr, &ev_trb, TRB_SIZE); intr->er_ep_idx++; if (intr->er_ep_idx >= intr->er_size) { @@ -955,9 +963,11 @@ static void xhci_ring_init(XHCIState *xhci, XHCIRing *ring, static TRBType xhci_ring_fetch(XHCIState *xhci, XHCIRing *ring, XHCITRB *trb, dma_addr_t *addr) { + PCIDevice *pci_dev = PCI_DEVICE(xhci); + while (1) { TRBType type; - pci_dma_read(&xhci->pci_dev, ring->dequeue, trb, TRB_SIZE); + pci_dma_read(pci_dev, ring->dequeue, trb, TRB_SIZE); trb->addr = ring->dequeue; trb->ccs = ring->ccs; le64_to_cpus(&trb->parameter); @@ -990,6 +1000,7 @@ static TRBType xhci_ring_fetch(XHCIState *xhci, XHCIRing *ring, XHCITRB *trb, static int xhci_ring_chain_length(XHCIState *xhci, const XHCIRing *ring) { + PCIDevice *pci_dev = PCI_DEVICE(xhci); XHCITRB trb; int length = 0; dma_addr_t dequeue = ring->dequeue; @@ -999,7 +1010,7 @@ static int xhci_ring_chain_length(XHCIState *xhci, const XHCIRing *ring) while (1) { TRBType type; - pci_dma_read(&xhci->pci_dev, dequeue, &trb, TRB_SIZE); + pci_dma_read(pci_dev, dequeue, &trb, TRB_SIZE); le64_to_cpus(&trb.parameter); le32_to_cpus(&trb.status); le32_to_cpus(&trb.control); @@ -1051,7 +1062,7 @@ static void xhci_er_reset(XHCIState *xhci, int v) return; } dma_addr_t erstba = xhci_addr64(intr->erstba_low, intr->erstba_high); - pci_dma_read(&xhci->pci_dev, erstba, &seg, sizeof(seg)); + pci_dma_read(PCI_DEVICE(xhci), erstba, &seg, sizeof(seg)); le32_to_cpus(&seg.addr_low); le32_to_cpus(&seg.addr_high); le32_to_cpus(&seg.size); @@ -1526,7 +1537,7 @@ static int xhci_xfer_create_sgl(XHCITransfer *xfer, int in_xfer) int i; xfer->int_req = false; - pci_dma_sglist_init(&xfer->sgl, &xhci->pci_dev, xfer->trb_count); + pci_dma_sglist_init(&xfer->sgl, PCI_DEVICE(xhci), xfer->trb_count); for (i = 0; i < xfer->trb_count; i++) { XHCITRB *trb = &xfer->trbs[i]; dma_addr_t addr; @@ -2111,7 +2122,7 @@ static TRBCCode xhci_address_slot(XHCIState *xhci, unsigned int slotid, assert(slotid >= 1 && slotid <= xhci->numslots); dcbaap = xhci_addr64(xhci->dcbaap_low, xhci->dcbaap_high); - poctx = ldq_le_pci_dma(&xhci->pci_dev, dcbaap + 8*slotid); + poctx = ldq_le_pci_dma(PCI_DEVICE(xhci), dcbaap + 8 * slotid); ictx = xhci_mask64(pictx); octx = xhci_mask64(poctx); @@ -2432,7 +2443,7 @@ static TRBCCode xhci_get_port_bandwidth(XHCIState *xhci, uint64_t pctx) /* TODO: actually implement real values here */ bw_ctx[0] = 0; memset(&bw_ctx[1], 80, xhci->numports); /* 80% */ - pci_dma_write(&xhci->pci_dev, ctx, bw_ctx, sizeof(bw_ctx)); + pci_dma_write(PCI_DEVICE(xhci), ctx, bw_ctx, sizeof(bw_ctx)); return CC_SUCCESS; } @@ -2455,11 +2466,12 @@ static uint32_t xhci_nec_challenge(uint32_t hi, uint32_t lo) static void xhci_via_challenge(XHCIState *xhci, uint64_t addr) { + PCIDevice *pci_dev = PCI_DEVICE(xhci); uint32_t buf[8]; uint32_t obuf[8]; dma_addr_t paddr = xhci_mask64(addr); - pci_dma_read(&xhci->pci_dev, paddr, &buf, 32); + pci_dma_read(pci_dev, paddr, &buf, 32); memcpy(obuf, buf, sizeof(obuf)); @@ -2475,7 +2487,7 @@ static void xhci_via_challenge(XHCIState *xhci, uint64_t addr) obuf[7] = obuf[2] ^ obuf[3] ^ 0x65866593; } - pci_dma_write(&xhci->pci_dev, paddr, &obuf, 32); + pci_dma_write(pci_dev, paddr, &obuf, 32); } static void xhci_process_commands(XHCIState *xhci) @@ -3322,10 +3334,10 @@ static int usb_xhci_initfn(struct PCIDevice *dev) XHCIState *xhci = XHCI(dev); - xhci->pci_dev.config[PCI_CLASS_PROG] = 0x30; /* xHCI */ - xhci->pci_dev.config[PCI_INTERRUPT_PIN] = 0x01; /* interrupt pin 1 */ - xhci->pci_dev.config[PCI_CACHE_LINE_SIZE] = 0x10; - xhci->pci_dev.config[0x60] = 0x30; /* release number */ + dev->config[PCI_CLASS_PROG] = 0x30; /* xHCI */ + dev->config[PCI_INTERRUPT_PIN] = 0x01; /* interrupt pin 1 */ + dev->config[PCI_CACHE_LINE_SIZE] = 0x10; + dev->config[0x60] = 0x30; /* release number */ usb_xhci_init(xhci); @@ -3347,7 +3359,7 @@ static int usb_xhci_initfn(struct PCIDevice *dev) xhci->mfwrap_timer = qemu_new_timer_ns(vm_clock, xhci_mfwrap_timer, xhci); - xhci->irq = xhci->pci_dev.irq[0]; + xhci->irq = dev->irq[0]; memory_region_init(&xhci->mem, OBJECT(xhci), "xhci", LEN_REGS); memory_region_init_io(&xhci->mem_cap, OBJECT(xhci), &xhci_cap_ops, xhci, @@ -3373,18 +3385,18 @@ static int usb_xhci_initfn(struct PCIDevice *dev) memory_region_add_subregion(&xhci->mem, offset, &port->mem); } - pci_register_bar(&xhci->pci_dev, 0, + pci_register_bar(dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY|PCI_BASE_ADDRESS_MEM_TYPE_64, &xhci->mem); - ret = pcie_endpoint_cap_init(&xhci->pci_dev, 0xa0); + ret = pcie_endpoint_cap_init(dev, 0xa0); assert(ret >= 0); if (xhci->flags & (1 << XHCI_FLAG_USE_MSI)) { - msi_init(&xhci->pci_dev, 0x70, xhci->numintrs, true, false); + msi_init(dev, 0x70, xhci->numintrs, true, false); } if (xhci->flags & (1 << XHCI_FLAG_USE_MSI_X)) { - msix_init(&xhci->pci_dev, xhci->numintrs, + msix_init(dev, xhci->numintrs, &xhci->mem, 0, OFF_MSIX_TABLE, &xhci->mem, 0, OFF_MSIX_PBA, 0x90); @@ -3396,6 +3408,7 @@ static int usb_xhci_initfn(struct PCIDevice *dev) static int usb_xhci_post_load(void *opaque, int version_id) { XHCIState *xhci = opaque; + PCIDevice *pci_dev = PCI_DEVICE(xhci); XHCISlot *slot; XHCIEPContext *epctx; dma_addr_t dcbaap, pctx; @@ -3411,7 +3424,7 @@ static int usb_xhci_post_load(void *opaque, int version_id) continue; } slot->ctx = - xhci_mask64(ldq_le_pci_dma(&xhci->pci_dev, dcbaap + 8*slotid)); + xhci_mask64(ldq_le_pci_dma(pci_dev, dcbaap + 8 * slotid)); xhci_dma_read_u32s(xhci, slot->ctx, slot_ctx, sizeof(slot_ctx)); slot->uport = xhci_lookup_uport(xhci, slot_ctx); assert(slot->uport && slot->uport->dev); @@ -3436,9 +3449,9 @@ static int usb_xhci_post_load(void *opaque, int version_id) for (intr = 0; intr < xhci->numintrs; intr++) { if (xhci->intr[intr].msix_used) { - msix_vector_use(&xhci->pci_dev, intr); + msix_vector_use(pci_dev, intr); } else { - msix_vector_unuse(&xhci->pci_dev, intr); + msix_vector_unuse(pci_dev, intr); } } @@ -3531,8 +3544,8 @@ static const VMStateDescription vmstate_xhci = { .version_id = 1, .post_load = usb_xhci_post_load, .fields = (VMStateField[]) { - VMSTATE_PCIE_DEVICE(pci_dev, XHCIState), - VMSTATE_MSIX(pci_dev, XHCIState), + VMSTATE_PCIE_DEVICE(parent_obj, XHCIState), + VMSTATE_MSIX(parent_obj, XHCIState), VMSTATE_STRUCT_VARRAY_UINT32(ports, XHCIState, numports, 1, vmstate_xhci_port, XHCIPort), From 71186c867caab48d093fe2c8ae7d8f23d59b0aed Mon Sep 17 00:00:00 2001 From: Peter Crosthwaite Date: Mon, 24 Jun 2013 16:53:30 +1000 Subject: [PATCH 09/55] scsi/lsi53c895a: QOM Upcast Sweep MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Define and use standard QOM cast macro. Remove usages of DO_UPCAST() and direct -> style upcasting. Signed-off-by: Peter Crosthwaite Signed-off-by: Andreas Färber --- hw/scsi/lsi53c895a.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/hw/scsi/lsi53c895a.c b/hw/scsi/lsi53c895a.c index 2c17ae5f25..dae467cee2 100644 --- a/hw/scsi/lsi53c895a.c +++ b/hw/scsi/lsi53c895a.c @@ -275,6 +275,11 @@ typedef struct { uint32_t script_ram[2048]; } LSIState; +#define TYPE_LSI53C895A "lsi53c895a" + +#define LSI53C895A(obj) \ + OBJECT_CHECK(LSIState, (obj), TYPE_LSI53C895A) + static inline int lsi_irq_on_rsl(LSIState *s) { return (s->sien0 & LSI_SIST0_RSL) && (s->scid & LSI_SCID_RRE); @@ -653,7 +658,7 @@ static void lsi_request_free(LSIState *s, lsi_request *p) static void lsi_request_cancelled(SCSIRequest *req) { - LSIState *s = DO_UPCAST(LSIState, dev.qdev, req->bus->qbus.parent); + LSIState *s = LSI53C895A(req->bus->qbus.parent); lsi_request *p = req->hba_private; req->hba_private = NULL; @@ -692,7 +697,7 @@ static int lsi_queue_req(LSIState *s, SCSIRequest *req, uint32_t len) /* Callback to indicate that the SCSI layer has completed a command. */ static void lsi_command_complete(SCSIRequest *req, uint32_t status, size_t resid) { - LSIState *s = DO_UPCAST(LSIState, dev.qdev, req->bus->qbus.parent); + LSIState *s = LSI53C895A(req->bus->qbus.parent); int out; out = (s->sstat1 & PHASE_MASK) == PHASE_DO; @@ -717,7 +722,7 @@ static void lsi_command_complete(SCSIRequest *req, uint32_t status, size_t resid /* Callback to indicate that the SCSI layer has completed a transfer. */ static void lsi_transfer_data(SCSIRequest *req, uint32_t len) { - LSIState *s = DO_UPCAST(LSIState, dev.qdev, req->bus->qbus.parent); + LSIState *s = LSI53C895A(req->bus->qbus.parent); int out; assert(req->hba_private); @@ -1726,7 +1731,7 @@ static void lsi_reg_writeb(LSIState *s, int offset, uint8_t val) lsi_execute_script(s); } if (val & LSI_ISTAT0_SRST) { - qdev_reset_all(&s->dev.qdev); + qdev_reset_all(DEVICE(s)); } break; case 0x16: /* MBOX0 */ @@ -1960,7 +1965,7 @@ static const MemoryRegionOps lsi_io_ops = { static void lsi_scsi_reset(DeviceState *dev) { - LSIState *s = DO_UPCAST(LSIState, dev.qdev, dev); + LSIState *s = LSI53C895A(dev); lsi_soft_reset(s); } @@ -2061,7 +2066,7 @@ static const VMStateDescription vmstate_lsi_scsi = { static void lsi_scsi_uninit(PCIDevice *d) { - LSIState *s = DO_UPCAST(LSIState, dev, d); + LSIState *s = LSI53C895A(d); memory_region_destroy(&s->mmio_io); memory_region_destroy(&s->ram_io); @@ -2080,7 +2085,8 @@ static const struct SCSIBusInfo lsi_scsi_info = { static int lsi_scsi_init(PCIDevice *dev) { - LSIState *s = DO_UPCAST(LSIState, dev, dev); + LSIState *s = LSI53C895A(dev); + DeviceState *d = DEVICE(dev); uint8_t *pci_conf; pci_conf = s->dev.config; @@ -2102,8 +2108,8 @@ static int lsi_scsi_init(PCIDevice *dev) pci_register_bar(&s->dev, 2, PCI_BASE_ADDRESS_SPACE_MEMORY, &s->ram_io); QTAILQ_INIT(&s->queue); - scsi_bus_new(&s->bus, &dev->qdev, &lsi_scsi_info, NULL); - if (!dev->qdev.hotplugged) { + scsi_bus_new(&s->bus, d, &lsi_scsi_info, NULL); + if (!d->hotplugged) { return scsi_bus_legacy_handle_cmdline(&s->bus); } return 0; @@ -2125,7 +2131,7 @@ static void lsi_class_init(ObjectClass *klass, void *data) } static const TypeInfo lsi_info = { - .name = "lsi53c895a", + .name = TYPE_LSI53C895A, .parent = TYPE_PCI_DEVICE, .instance_size = sizeof(LSIState), .class_init = lsi_class_init, From 725eec7043bd010856899461817ccd2599a09362 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Sun, 30 Jun 2013 13:52:22 +0200 Subject: [PATCH 10/55] scsi/lsi53c895a: QOM parent field cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace direct uses of LSIState::dev with QOM casts and rename it to parent_obj. Acked-by: Peter Crosthwaite Signed-off-by: Andreas Färber --- hw/scsi/lsi53c895a.c | 46 ++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/hw/scsi/lsi53c895a.c b/hw/scsi/lsi53c895a.c index dae467cee2..e11224fe88 100644 --- a/hw/scsi/lsi53c895a.c +++ b/hw/scsi/lsi53c895a.c @@ -184,7 +184,10 @@ typedef struct lsi_request { } lsi_request; typedef struct { - PCIDevice dev; + /*< private >*/ + PCIDevice parent_obj; + /*< public >*/ + MemoryRegion mmio_io; MemoryRegion ram_io; MemoryRegion io_io; @@ -387,7 +390,7 @@ static inline uint32_t read_dword(LSIState *s, uint32_t addr) { uint32_t buf; - pci_dma_read(&s->dev, addr, &buf, 4); + pci_dma_read(PCI_DEVICE(s), addr, &buf, 4); return cpu_to_le32(buf); } @@ -398,6 +401,7 @@ static void lsi_stop_script(LSIState *s) static void lsi_update_irq(LSIState *s) { + PCIDevice *d = PCI_DEVICE(s); int level; static int last_level; lsi_request *p; @@ -429,7 +433,7 @@ static void lsi_update_irq(LSIState *s) level, s->dstat, s->sist1, s->sist0); last_level = level; } - qemu_set_irq(s->dev.irq[0], level); + qemu_set_irq(d->irq[0], level); if (!level && lsi_irq_on_rsl(s) && !(s->scntl1 & LSI_SCNTL1_CON)) { DPRINTF("Handled IRQs & disconnected, looking for pending " @@ -525,6 +529,7 @@ static void lsi_bad_selection(LSIState *s, uint32_t id) /* Initiate a SCSI layer data transfer. */ static void lsi_do_dma(LSIState *s, int out) { + PCIDevice *pci_dev; uint32_t count; dma_addr_t addr; SCSIDevice *dev; @@ -536,6 +541,7 @@ static void lsi_do_dma(LSIState *s, int out) return; } + pci_dev = PCI_DEVICE(s); dev = s->current->req->dev; assert(dev); @@ -561,9 +567,9 @@ static void lsi_do_dma(LSIState *s, int out) } /* ??? Set SFBR to first data byte. */ if (out) { - pci_dma_read(&s->dev, addr, s->current->dma_buf, count); + pci_dma_read(pci_dev, addr, s->current->dma_buf, count); } else { - pci_dma_write(&s->dev, addr, s->current->dma_buf, count); + pci_dma_write(pci_dev, addr, s->current->dma_buf, count); } s->current->dma_len -= count; if (s->current->dma_len == 0) { @@ -758,7 +764,7 @@ static void lsi_do_command(LSIState *s) DPRINTF("Send command len=%d\n", s->dbc); if (s->dbc > 16) s->dbc = 16; - pci_dma_read(&s->dev, s->dnad, buf, s->dbc); + pci_dma_read(PCI_DEVICE(s), s->dnad, buf, s->dbc); s->sfbr = buf[0]; s->command_complete = 0; @@ -809,7 +815,7 @@ static void lsi_do_status(LSIState *s) s->dbc = 1; status = s->status; s->sfbr = status; - pci_dma_write(&s->dev, s->dnad, &status, 1); + pci_dma_write(PCI_DEVICE(s), s->dnad, &status, 1); lsi_set_phase(s, PHASE_MI); s->msg_action = 1; lsi_add_msg_byte(s, 0); /* COMMAND COMPLETE */ @@ -823,7 +829,7 @@ static void lsi_do_msgin(LSIState *s) len = s->msg_len; if (len > s->dbc) len = s->dbc; - pci_dma_write(&s->dev, s->dnad, s->msg, len); + pci_dma_write(PCI_DEVICE(s), s->dnad, s->msg, len); /* Linux drivers rely on the last byte being in the SIDL. */ s->sidl = s->msg[len - 1]; s->msg_len -= len; @@ -855,7 +861,7 @@ static void lsi_do_msgin(LSIState *s) static uint8_t lsi_get_msgbyte(LSIState *s) { uint8_t data; - pci_dma_read(&s->dev, s->dnad, &data, 1); + pci_dma_read(PCI_DEVICE(s), s->dnad, &data, 1); s->dnad++; s->dbc--; return data; @@ -1001,14 +1007,15 @@ static inline int32_t sxt24(int32_t n) #define LSI_BUF_SIZE 4096 static void lsi_memcpy(LSIState *s, uint32_t dest, uint32_t src, int count) { + PCIDevice *d = PCI_DEVICE(s); int n; uint8_t buf[LSI_BUF_SIZE]; DPRINTF("memcpy dest 0x%08x src 0x%08x count %d\n", dest, src, count); while (count) { n = (count > LSI_BUF_SIZE) ? LSI_BUF_SIZE : count; - pci_dma_read(&s->dev, src, buf, n); - pci_dma_write(&s->dev, dest, buf, n); + pci_dma_read(d, src, buf, n); + pci_dma_write(d, dest, buf, n); src += n; dest += n; count -= n; @@ -1034,6 +1041,7 @@ static void lsi_wait_reselect(LSIState *s) static void lsi_execute_script(LSIState *s) { + PCIDevice *pci_dev = PCI_DEVICE(s); uint32_t insn; uint32_t addr, addr_high; int opcode; @@ -1076,7 +1084,7 @@ again: /* 32-bit Table indirect */ offset = sxt24(addr); - pci_dma_read(&s->dev, s->dsa + offset, buf, 8); + pci_dma_read(pci_dev, s->dsa + offset, buf, 8); /* byte count is stored in bits 0:23 only */ s->dbc = cpu_to_le32(buf[0]) & 0xffffff; s->rbc = s->dbc; @@ -1435,7 +1443,7 @@ again: n = (insn & 7); reg = (insn >> 16) & 0xff; if (insn & (1 << 24)) { - pci_dma_read(&s->dev, addr, data, n); + pci_dma_read(pci_dev, addr, data, n); DPRINTF("Load reg 0x%x size %d addr 0x%08x = %08x\n", reg, n, addr, *(int *)data); for (i = 0; i < n; i++) { @@ -1446,7 +1454,7 @@ again: for (i = 0; i < n; i++) { data[i] = lsi_reg_readb(s, reg + i); } - pci_dma_write(&s->dev, addr, data, n); + pci_dma_write(pci_dev, addr, data, n); } } } @@ -1988,7 +1996,7 @@ static const VMStateDescription vmstate_lsi_scsi = { .minimum_version_id_old = 0, .pre_save = lsi_pre_save, .fields = (VMStateField []) { - VMSTATE_PCI_DEVICE(dev, LSIState), + VMSTATE_PCI_DEVICE(parent_obj, LSIState), VMSTATE_INT32(carry, LSIState), VMSTATE_INT32(status, LSIState), @@ -2089,7 +2097,7 @@ static int lsi_scsi_init(PCIDevice *dev) DeviceState *d = DEVICE(dev); uint8_t *pci_conf; - pci_conf = s->dev.config; + pci_conf = dev->config; /* PCI latency timer = 255 */ pci_conf[PCI_LATENCY_TIMER] = 0xff; @@ -2103,9 +2111,9 @@ static int lsi_scsi_init(PCIDevice *dev) memory_region_init_io(&s->io_io, OBJECT(s), &lsi_io_ops, s, "lsi-io", 256); - pci_register_bar(&s->dev, 0, PCI_BASE_ADDRESS_SPACE_IO, &s->io_io); - pci_register_bar(&s->dev, 1, 0, &s->mmio_io); - pci_register_bar(&s->dev, 2, PCI_BASE_ADDRESS_SPACE_MEMORY, &s->ram_io); + pci_register_bar(dev, 0, PCI_BASE_ADDRESS_SPACE_IO, &s->io_io); + pci_register_bar(dev, 1, 0, &s->mmio_io); + pci_register_bar(dev, 2, PCI_BASE_ADDRESS_SPACE_MEMORY, &s->ram_io); QTAILQ_INIT(&s->queue); scsi_bus_new(&s->bus, d, &lsi_scsi_info, NULL); From c79e16ae044d265674ef43dfdd694c8fd0f49e19 Mon Sep 17 00:00:00 2001 From: Peter Crosthwaite Date: Mon, 24 Jun 2013 16:54:15 +1000 Subject: [PATCH 11/55] scsi/megasas: QOM Upcast Sweep MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Define and use standard QOM cast macro. Remove usages of DO_UPCAST() and direct -> style upcasting. Signed-off-by: Peter Crosthwaite Signed-off-by: Andreas Färber --- hw/scsi/megasas.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/hw/scsi/megasas.c b/hw/scsi/megasas.c index 45d0c77c49..0f2a722096 100644 --- a/hw/scsi/megasas.c +++ b/hw/scsi/megasas.c @@ -108,6 +108,11 @@ typedef struct MegasasState { SCSIBus bus; } MegasasState; +#define TYPE_MEGASAS "megasas" + +#define MEGASAS(obj) \ + OBJECT_CHECK(MegasasState, (obj), TYPE_MEGASAS) + #define MEGASAS_INTR_DISABLED_MASK 0xFFFFFFFF static bool megasas_intr_enabled(MegasasState *s) @@ -2039,7 +2044,7 @@ static void megasas_soft_reset(MegasasState *s) static void megasas_scsi_reset(DeviceState *dev) { - MegasasState *s = DO_UPCAST(MegasasState, dev.qdev, dev); + MegasasState *s = MEGASAS(dev); megasas_soft_reset(s); } @@ -2064,7 +2069,7 @@ static const VMStateDescription vmstate_megasas = { static void megasas_scsi_uninit(PCIDevice *d) { - MegasasState *s = DO_UPCAST(MegasasState, dev, d); + MegasasState *s = MEGASAS(d); #ifdef USE_MSIX msix_uninit(&s->dev, &s->mmio_io); @@ -2087,7 +2092,7 @@ static const struct SCSIBusInfo megasas_scsi_info = { static int megasas_scsi_init(PCIDevice *dev) { - MegasasState *s = DO_UPCAST(MegasasState, dev, dev); + MegasasState *s = MEGASAS(dev); uint8_t *pci_conf; int i, bar_type; @@ -2158,7 +2163,7 @@ static int megasas_scsi_init(PCIDevice *dev) s->frames[i].state = s; } - scsi_bus_new(&s->bus, &dev->qdev, &megasas_scsi_info, NULL); + scsi_bus_new(&s->bus, DEVICE(dev), &megasas_scsi_info, NULL); scsi_bus_legacy_handle_cmdline(&s->bus); return 0; } @@ -2198,7 +2203,7 @@ static void megasas_class_init(ObjectClass *oc, void *data) } static const TypeInfo megasas_info = { - .name = "megasas", + .name = TYPE_MEGASAS, .parent = TYPE_PCI_DEVICE, .instance_size = sizeof(MegasasState), .class_init = megasas_class_init, From 52190c1e0a95440e906f3bb7e7c17823f3eac8c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Sun, 30 Jun 2013 14:02:53 +0200 Subject: [PATCH 12/55] scsi/megasas: QOM parent field cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace direct uses of MegasasState::dev with QOM casts and rename it to parent_obj. Acked-by: Peter Crosthwaite Signed-off-by: Andreas Färber --- hw/scsi/megasas.c | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/hw/scsi/megasas.c b/hw/scsi/megasas.c index 0f2a722096..55d5b73606 100644 --- a/hw/scsi/megasas.c +++ b/hw/scsi/megasas.c @@ -70,7 +70,10 @@ typedef struct MegasasCmd { } MegasasCmd; typedef struct MegasasState { - PCIDevice dev; + /*< private >*/ + PCIDevice parent_obj; + /*< public >*/ + MemoryRegion mmio_io; MemoryRegion port_io; MemoryRegion queue_io; @@ -237,7 +240,7 @@ static int megasas_map_sgl(MegasasState *s, MegasasCmd *cmd, union mfi_sgl *sgl) MEGASAS_MAX_SGE); return iov_count; } - pci_dma_sglist_init(&cmd->qsg, &s->dev, iov_count); + pci_dma_sglist_init(&cmd->qsg, PCI_DEVICE(s), iov_count); for (i = 0; i < iov_count; i++) { dma_addr_t iov_pa, iov_size_p; @@ -498,6 +501,7 @@ static MegasasCmd *megasas_enqueue_frame(MegasasState *s, static void megasas_complete_frame(MegasasState *s, uint64_t context) { + PCIDevice *pci_dev = PCI_DEVICE(s); int tail, queue_offset; /* Decrement busy count */ @@ -526,12 +530,12 @@ static void megasas_complete_frame(MegasasState *s, uint64_t context) /* Notify HBA */ s->doorbell++; if (s->doorbell == 1) { - if (msix_enabled(&s->dev)) { + if (msix_enabled(pci_dev)) { trace_megasas_msix_raise(0); - msix_notify(&s->dev, 0); + msix_notify(pci_dev, 0); } else { trace_megasas_irq_raise(); - qemu_irq_raise(s->dev.irq[0]); + qemu_irq_raise(pci_dev->irq[0]); } } } else { @@ -633,7 +637,7 @@ static int megasas_map_dcmd(MegasasState *s, MegasasCmd *cmd) } iov_pa = megasas_sgl_get_addr(cmd, &cmd->frame->dcmd.sgl); iov_size = megasas_sgl_get_len(cmd, &cmd->frame->dcmd.sgl); - pci_dma_sglist_init(&cmd->qsg, &s->dev, 1); + pci_dma_sglist_init(&cmd->qsg, PCI_DEVICE(s), 1); qemu_sglist_add(&cmd->qsg, iov_pa, iov_size); cmd->iov_size = iov_size; return cmd->iov_size; @@ -660,6 +664,7 @@ static void megasas_finish_dcmd(MegasasCmd *cmd, uint32_t iov_size) static int megasas_ctrl_get_info(MegasasState *s, MegasasCmd *cmd) { + PCIDevice *pci_dev = PCI_DEVICE(s); struct mfi_ctrl_info info; size_t dcmd_size = sizeof(info); BusChild *kid; @@ -710,11 +715,11 @@ static int megasas_ctrl_get_info(MegasasState *s, MegasasCmd *cmd) memcpy(info.image_component[0].build_date, __DATE__, 11); memcpy(info.image_component[0].build_time, __TIME__, 8); info.image_component_count = 1; - if (s->dev.has_rom) { + if (pci_dev->has_rom) { uint8_t biosver[32]; uint8_t *ptr; - ptr = memory_region_get_ram_ptr(&s->dev.rom); + ptr = memory_region_get_ram_ptr(&pci_dev->rom); memcpy(biosver, ptr + 0x41, 31); memcpy(info.image_component[1].name, "BIOS", 4); memcpy(info.image_component[1].version, biosver, @@ -1905,6 +1910,7 @@ static void megasas_mmio_write(void *opaque, hwaddr addr, uint64_t val, unsigned size) { MegasasState *s = opaque; + PCIDevice *pci_dev = PCI_DEVICE(s); uint64_t frame_addr; uint32_t frame_count; int i; @@ -1928,9 +1934,9 @@ static void megasas_mmio_write(void *opaque, hwaddr addr, break; case MFI_OMSK: s->intr_mask = val; - if (!megasas_intr_enabled(s) && !msix_enabled(&s->dev)) { + if (!megasas_intr_enabled(s) && !msix_enabled(pci_dev)) { trace_megasas_irq_lower(); - qemu_irq_lower(s->dev.irq[0]); + qemu_irq_lower(pci_dev->irq[0]); } if (megasas_intr_enabled(s)) { trace_megasas_intr_enabled(); @@ -1944,9 +1950,9 @@ static void megasas_mmio_write(void *opaque, hwaddr addr, /* Update reply queue pointer */ trace_megasas_qf_update(s->reply_queue_head, s->busy); stl_le_phys(s->producer_pa, s->reply_queue_head); - if (!msix_enabled(&s->dev)) { + if (!msix_enabled(pci_dev)) { trace_megasas_irq_lower(); - qemu_irq_lower(s->dev.irq[0]); + qemu_irq_lower(pci_dev->irq[0]); } } break; @@ -2055,7 +2061,7 @@ static const VMStateDescription vmstate_megasas = { .minimum_version_id = 0, .minimum_version_id_old = 0, .fields = (VMStateField[]) { - VMSTATE_PCI_DEVICE(dev, MegasasState), + VMSTATE_PCI_DEVICE(parent_obj, MegasasState), VMSTATE_INT32(fw_state, MegasasState), VMSTATE_INT32(intr_mask, MegasasState), @@ -2072,7 +2078,7 @@ static void megasas_scsi_uninit(PCIDevice *d) MegasasState *s = MEGASAS(d); #ifdef USE_MSIX - msix_uninit(&s->dev, &s->mmio_io); + msix_uninit(d, &s->mmio_io); #endif memory_region_destroy(&s->mmio_io); memory_region_destroy(&s->port_io); @@ -2096,7 +2102,7 @@ static int megasas_scsi_init(PCIDevice *dev) uint8_t *pci_conf; int i, bar_type; - pci_conf = s->dev.config; + pci_conf = dev->config; /* PCI latency timer = 0 */ pci_conf[PCI_LATENCY_TIMER] = 0; @@ -2113,7 +2119,7 @@ static int megasas_scsi_init(PCIDevice *dev) #ifdef USE_MSIX /* MSI-X support is currently broken */ if (megasas_use_msix(s) && - msix_init(&s->dev, 15, &s->mmio_io, 0, 0x2000)) { + msix_init(dev, 15, &s->mmio_io, 0, 0x2000)) { s->flags &= ~MEGASAS_MASK_USE_MSIX; } #else @@ -2121,12 +2127,12 @@ static int megasas_scsi_init(PCIDevice *dev) #endif bar_type = PCI_BASE_ADDRESS_SPACE_MEMORY | PCI_BASE_ADDRESS_MEM_TYPE_64; - pci_register_bar(&s->dev, 0, bar_type, &s->mmio_io); - pci_register_bar(&s->dev, 2, PCI_BASE_ADDRESS_SPACE_IO, &s->port_io); - pci_register_bar(&s->dev, 3, bar_type, &s->queue_io); + pci_register_bar(dev, 0, bar_type, &s->mmio_io); + pci_register_bar(dev, 2, PCI_BASE_ADDRESS_SPACE_IO, &s->port_io); + pci_register_bar(dev, 3, bar_type, &s->queue_io); if (megasas_use_msix(s)) { - msix_vector_use(&s->dev, 0); + msix_vector_use(dev, 0); } if (!s->sas_addr) { From 3a15effe00b5bd223d5932c8d67c9525914a1526 Mon Sep 17 00:00:00 2001 From: Peter Crosthwaite Date: Mon, 24 Jun 2013 16:55:00 +1000 Subject: [PATCH 13/55] scsi/esp-pci: QOM Upcast Sweep MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Define and use standard QOM cast macro. Remove usages of DO_UPCAST() and direct -> style upcasting. Signed-off-by: Peter Crosthwaite Signed-off-by: Andreas Färber --- hw/scsi/esp-pci.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/hw/scsi/esp-pci.c b/hw/scsi/esp-pci.c index 8f97c5a6e2..ab1fa85f08 100644 --- a/hw/scsi/esp-pci.c +++ b/hw/scsi/esp-pci.c @@ -31,6 +31,9 @@ #define TYPE_AM53C974_DEVICE "am53c974" +#define PCI_ESP(obj) \ + OBJECT_CHECK(PCIESPState, (obj), TYPE_AM53C974_DEVICE) + #define DMA_CMD 0x0 #define DMA_STC 0x1 #define DMA_SPA 0x2 @@ -288,7 +291,7 @@ static const MemoryRegionOps esp_pci_io_ops = { static void esp_pci_hard_reset(DeviceState *dev) { - PCIESPState *pci = DO_UPCAST(PCIESPState, dev.qdev, dev); + PCIESPState *pci = PCI_ESP(dev); esp_hard_reset(&pci->esp); pci->dma_regs[DMA_CMD] &= ~(DMA_CMD_DIR | DMA_CMD_INTE_D | DMA_CMD_INTE_P | DMA_CMD_MDL | DMA_CMD_DIAG | DMA_CMD_MASK); @@ -336,7 +339,8 @@ static const struct SCSIBusInfo esp_pci_scsi_info = { static int esp_pci_scsi_init(PCIDevice *dev) { - PCIESPState *pci = DO_UPCAST(PCIESPState, dev, dev); + PCIESPState *pci = PCI_ESP(dev); + DeviceState *d = DEVICE(dev); ESPState *s = &pci->esp; uint8_t *pci_conf; @@ -355,8 +359,8 @@ static int esp_pci_scsi_init(PCIDevice *dev) pci_register_bar(&pci->dev, 0, PCI_BASE_ADDRESS_SPACE_IO, &pci->io); s->irq = pci->dev.irq[0]; - scsi_bus_new(&s->bus, &dev->qdev, &esp_pci_scsi_info, NULL); - if (!dev->qdev.hotplugged) { + scsi_bus_new(&s->bus, d, &esp_pci_scsi_info, NULL); + if (!d->hotplugged) { return scsi_bus_legacy_handle_cmdline(&s->bus); } return 0; @@ -364,7 +368,7 @@ static int esp_pci_scsi_init(PCIDevice *dev) static void esp_pci_scsi_uninit(PCIDevice *d) { - PCIESPState *pci = DO_UPCAST(PCIESPState, dev, d); + PCIESPState *pci = PCI_ESP(d); memory_region_destroy(&pci->io); } From 4e5dcc774a4003e313b6eec823067b3980b0bc91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Sun, 30 Jun 2013 14:07:49 +0200 Subject: [PATCH 14/55] scsi/esp-pci: QOM parent field cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace direct uses of PCIESPState::dev with QOM casts and rename it to parent_obj. Acked-by: Peter Crosthwaite Signed-off-by: Andreas Färber --- hw/scsi/esp-pci.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/hw/scsi/esp-pci.c b/hw/scsi/esp-pci.c index ab1fa85f08..6cdfd5338e 100644 --- a/hw/scsi/esp-pci.c +++ b/hw/scsi/esp-pci.c @@ -60,7 +60,10 @@ #define SBAC_STATUS 0x1000 typedef struct PCIESPState { - PCIDevice dev; + /*< private >*/ + PCIDevice parent_obj; + /*< public >*/ + MemoryRegion io; uint32_t dma_regs[8]; uint32_t sbac; @@ -260,7 +263,7 @@ static void esp_pci_dma_memory_rw(PCIESPState *pci, uint8_t *buf, int len, len = pci->dma_regs[DMA_WBC]; } - pci_dma_rw(&pci->dev, addr, buf, len, dir); + pci_dma_rw(PCI_DEVICE(pci), addr, buf, len, dir); /* update status registers */ pci->dma_regs[DMA_WBC] -= len; @@ -309,7 +312,7 @@ static const VMStateDescription vmstate_esp_pci_scsi = { .minimum_version_id = 0, .minimum_version_id_old = 0, .fields = (VMStateField[]) { - VMSTATE_PCI_DEVICE(dev, PCIESPState), + VMSTATE_PCI_DEVICE(parent_obj, PCIESPState), VMSTATE_BUFFER_UNSAFE(dma_regs, PCIESPState, 0, 8 * sizeof(uint32_t)), VMSTATE_STRUCT(esp, PCIESPState, 0, vmstate_esp, ESPState), VMSTATE_END_OF_LIST() @@ -344,7 +347,7 @@ static int esp_pci_scsi_init(PCIDevice *dev) ESPState *s = &pci->esp; uint8_t *pci_conf; - pci_conf = pci->dev.config; + pci_conf = dev->config; /* Interrupt pin A */ pci_conf[PCI_INTERRUPT_PIN] = 0x01; @@ -356,8 +359,8 @@ static int esp_pci_scsi_init(PCIDevice *dev) memory_region_init_io(&pci->io, OBJECT(pci), &esp_pci_io_ops, pci, "esp-io", 0x80); - pci_register_bar(&pci->dev, 0, PCI_BASE_ADDRESS_SPACE_IO, &pci->io); - s->irq = pci->dev.irq[0]; + pci_register_bar(dev, 0, PCI_BASE_ADDRESS_SPACE_IO, &pci->io); + s->irq = dev->irq[0]; scsi_bus_new(&s->bus, d, &esp_pci_scsi_info, NULL); if (!d->hotplugged) { From fd58922cf4ea09c8dbd2d46dd61e50e6559bf447 Mon Sep 17 00:00:00 2001 From: Peter Crosthwaite Date: Mon, 24 Jun 2013 16:55:45 +1000 Subject: [PATCH 15/55] ide/ich: QOM Upcast Sweep MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Define and use standard QOM cast macro. Remove usages of DO_UPCAST() and direct -> style upcasting. Signed-off-by: Peter Crosthwaite [AF: Renamed to TYPE_ICH9_AHCI and used typedef in pci_ich9_reset()] Signed-off-by: Andreas Färber --- hw/ide/ahci.h | 5 +++++ hw/ide/ich.c | 10 +++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/hw/ide/ahci.h b/hw/ide/ahci.h index 341a5711ee..f997c673b2 100644 --- a/hw/ide/ahci.h +++ b/hw/ide/ahci.h @@ -305,6 +305,11 @@ typedef struct AHCIPCIState { AHCIState ahci; } AHCIPCIState; +#define TYPE_ICH9_AHCI "ich9-ahci" + +#define ICH_AHCI(obj) \ + OBJECT_CHECK(AHCIPCIState, (obj), TYPE_ICH9_AHCI) + extern const VMStateDescription vmstate_ahci; #define VMSTATE_AHCI(_field, _state) { \ diff --git a/hw/ide/ich.c b/hw/ide/ich.c index 6c0c0c2935..a6f78dcadf 100644 --- a/hw/ide/ich.c +++ b/hw/ide/ich.c @@ -92,7 +92,7 @@ static const VMStateDescription vmstate_ich9_ahci = { static void pci_ich9_reset(DeviceState *dev) { - struct AHCIPCIState *d = DO_UPCAST(struct AHCIPCIState, card.qdev, dev); + AHCIPCIState *d = ICH_AHCI(dev); ahci_reset(&d->ahci); } @@ -102,9 +102,9 @@ static int pci_ich9_ahci_init(PCIDevice *dev) struct AHCIPCIState *d; int sata_cap_offset; uint8_t *sata_cap; - d = DO_UPCAST(struct AHCIPCIState, card, dev); + d = ICH_AHCI(dev); - ahci_init(&d->ahci, &dev->qdev, pci_get_address_space(dev), 6); + ahci_init(&d->ahci, DEVICE(dev), pci_get_address_space(dev), 6); pci_config_set_prog_interface(d->card.config, AHCI_PROGMODE_MAJOR_REV_1); @@ -141,7 +141,7 @@ static int pci_ich9_ahci_init(PCIDevice *dev) static void pci_ich9_uninit(PCIDevice *dev) { struct AHCIPCIState *d; - d = DO_UPCAST(struct AHCIPCIState, card, dev); + d = ICH_AHCI(dev); msi_uninit(dev); ahci_uninit(&d->ahci); @@ -163,7 +163,7 @@ static void ich_ahci_class_init(ObjectClass *klass, void *data) } static const TypeInfo ich_ahci_info = { - .name = "ich9-ahci", + .name = TYPE_ICH9_AHCI, .parent = TYPE_PCI_DEVICE, .instance_size = sizeof(AHCIPCIState), .class_init = ich_ahci_class_init, From 0d3aea5603215b872b6580662d27860eecd6ca24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Sun, 30 Jun 2013 14:19:24 +0200 Subject: [PATCH 16/55] ide/ich: QOM parent field cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace direct uses of AHCIPCIState::card with QOM casts and rename it to parent_obj. Acked-by: Peter Crosthwaite Signed-off-by: Andreas Färber --- hw/ide/ahci.c | 11 ++++++----- hw/ide/ahci.h | 5 ++++- hw/ide/ich.c | 22 +++++++++++----------- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c index 1d863b5784..f295732599 100644 --- a/hw/ide/ahci.c +++ b/hw/ide/ahci.c @@ -117,12 +117,13 @@ static uint32_t ahci_port_read(AHCIState *s, int port, int offset) static void ahci_irq_raise(AHCIState *s, AHCIDevice *dev) { - struct AHCIPCIState *d = container_of(s, AHCIPCIState, ahci); + AHCIPCIState *d = container_of(s, AHCIPCIState, ahci); + PCIDevice *pci_dev = PCI_DEVICE(d); DPRINTF(0, "raise irq\n"); - if (msi_enabled(&d->card)) { - msi_notify(&d->card, 0); + if (msi_enabled(pci_dev)) { + msi_notify(pci_dev, 0); } else { qemu_irq_raise(s->irq); } @@ -130,11 +131,11 @@ static void ahci_irq_raise(AHCIState *s, AHCIDevice *dev) static void ahci_irq_lower(AHCIState *s, AHCIDevice *dev) { - struct AHCIPCIState *d = container_of(s, AHCIPCIState, ahci); + AHCIPCIState *d = container_of(s, AHCIPCIState, ahci); DPRINTF(0, "lower irq\n"); - if (!msi_enabled(&d->card)) { + if (!msi_enabled(PCI_DEVICE(d))) { qemu_irq_lower(s->irq); } } diff --git a/hw/ide/ahci.h b/hw/ide/ahci.h index f997c673b2..20e412c240 100644 --- a/hw/ide/ahci.h +++ b/hw/ide/ahci.h @@ -301,7 +301,10 @@ typedef struct AHCIState { } AHCIState; typedef struct AHCIPCIState { - PCIDevice card; + /*< private >*/ + PCIDevice parent_obj; + /*< public >*/ + AHCIState ahci; } AHCIPCIState; diff --git a/hw/ide/ich.c b/hw/ide/ich.c index a6f78dcadf..4eb5488993 100644 --- a/hw/ide/ich.c +++ b/hw/ide/ich.c @@ -84,7 +84,7 @@ static const VMStateDescription vmstate_ich9_ahci = { .unmigratable = 1, /* Still buggy under I/O load */ .version_id = 1, .fields = (VMStateField []) { - VMSTATE_PCI_DEVICE(card, AHCIPCIState), + VMSTATE_PCI_DEVICE(parent_obj, AHCIPCIState), VMSTATE_AHCI(ahci, AHCIPCIState), VMSTATE_END_OF_LIST() }, @@ -106,30 +106,30 @@ static int pci_ich9_ahci_init(PCIDevice *dev) ahci_init(&d->ahci, DEVICE(dev), pci_get_address_space(dev), 6); - pci_config_set_prog_interface(d->card.config, AHCI_PROGMODE_MAJOR_REV_1); + pci_config_set_prog_interface(dev->config, AHCI_PROGMODE_MAJOR_REV_1); - d->card.config[PCI_CACHE_LINE_SIZE] = 0x08; /* Cache line size */ - d->card.config[PCI_LATENCY_TIMER] = 0x00; /* Latency timer */ - pci_config_set_interrupt_pin(d->card.config, 1); + dev->config[PCI_CACHE_LINE_SIZE] = 0x08; /* Cache line size */ + dev->config[PCI_LATENCY_TIMER] = 0x00; /* Latency timer */ + pci_config_set_interrupt_pin(dev->config, 1); /* XXX Software should program this register */ - d->card.config[0x90] = 1 << 6; /* Address Map Register - AHCI mode */ + dev->config[0x90] = 1 << 6; /* Address Map Register - AHCI mode */ msi_init(dev, 0x50, 1, true, false); - d->ahci.irq = d->card.irq[0]; + d->ahci.irq = dev->irq[0]; - pci_register_bar(&d->card, ICH9_IDP_BAR, PCI_BASE_ADDRESS_SPACE_IO, + pci_register_bar(dev, ICH9_IDP_BAR, PCI_BASE_ADDRESS_SPACE_IO, &d->ahci.idp); - pci_register_bar(&d->card, ICH9_MEM_BAR, PCI_BASE_ADDRESS_SPACE_MEMORY, + pci_register_bar(dev, ICH9_MEM_BAR, PCI_BASE_ADDRESS_SPACE_MEMORY, &d->ahci.mem); - sata_cap_offset = pci_add_capability(&d->card, PCI_CAP_ID_SATA, + sata_cap_offset = pci_add_capability(dev, PCI_CAP_ID_SATA, ICH9_SATA_CAP_OFFSET, SATA_CAP_SIZE); if (sata_cap_offset < 0) { return sata_cap_offset; } - sata_cap = d->card.config + sata_cap_offset; + sata_cap = dev->config + sata_cap_offset; pci_set_word(sata_cap + SATA_CAP_REV, 0x10); pci_set_long(sata_cap + SATA_CAP_BAR, (ICH9_IDP_BAR + 0x4) | (ICH9_IDP_INDEX_LOG2 << 4)); From 74e445f6492b315c18e96daa6acb4d50405a0ad9 Mon Sep 17 00:00:00 2001 From: Peter Crosthwaite Date: Mon, 24 Jun 2013 16:57:14 +1000 Subject: [PATCH 17/55] acpi/piix4: QOM Upcast Sweep MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Define and use standard QOM cast macro. Remove usages of DO_UPCAST() and direct -> style upcasting. Signed-off-by: Peter Crosthwaite Signed-off-by: Andreas Färber --- hw/acpi/piix4.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c index 948ea8795b..5cd286ea24 100644 --- a/hw/acpi/piix4.c +++ b/hw/acpi/piix4.c @@ -96,6 +96,11 @@ typedef struct PIIX4PMState { Notifier cpu_added_notifier; } PIIX4PMState; +#define TYPE_PIIX4_PM "PIIX4_PM" + +#define PIIX4_PM(obj) \ + OBJECT_CHECK(PIIX4PMState, (obj), TYPE_PIIX4_PM) + static void piix4_acpi_system_hot_add_init(MemoryRegion *parent, PCIBus *bus, PIIX4PMState *s); @@ -300,7 +305,7 @@ static const VMStateDescription vmstate_acpi = { static void acpi_piix_eject_slot(PIIX4PMState *s, unsigned slots) { BusChild *kid, *next; - BusState *bus = qdev_get_parent_bus(&s->dev.qdev); + BusState *bus = qdev_get_parent_bus(DEVICE(s)); int slot = ffs(slots) - 1; bool slot_free = true; @@ -326,8 +331,7 @@ static void acpi_piix_eject_slot(PIIX4PMState *s, unsigned slots) static void piix4_update_hotplug(PIIX4PMState *s) { - PCIDevice *dev = &s->dev; - BusState *bus = qdev_get_parent_bus(&dev->qdev); + BusState *bus = qdev_get_parent_bus(DEVICE(s)); BusChild *kid, *next; /* Execute any pending removes during reset */ @@ -396,7 +400,7 @@ static void piix4_pm_machine_ready(Notifier *n, void *opaque) static int piix4_pm_initfn(PCIDevice *dev) { - PIIX4PMState *s = DO_UPCAST(PIIX4PMState, dev, dev); + PIIX4PMState *s = PIIX4_PM(dev); uint8_t *pci_conf; pci_conf = s->dev.config; @@ -419,7 +423,7 @@ static int piix4_pm_initfn(PCIDevice *dev) pci_conf[0x90] = s->smb_io_base | 1; pci_conf[0x91] = s->smb_io_base >> 8; pci_conf[0xd2] = 0x09; - pm_smbus_init(&s->dev.qdev, &s->smb); + pm_smbus_init(DEVICE(dev), &s->smb); memory_region_set_enabled(&s->smb.io, pci_conf[0xd2] & 1); memory_region_add_subregion(pci_address_space_io(dev), s->smb_io_base, &s->smb.io); @@ -450,18 +454,18 @@ i2c_bus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base, qemu_irq sci_irq, qemu_irq smi_irq, int kvm_enabled, FWCfgState *fw_cfg) { - PCIDevice *dev; + DeviceState *dev; PIIX4PMState *s; - dev = pci_create(bus, devfn, "PIIX4_PM"); - qdev_prop_set_uint32(&dev->qdev, "smb_io_base", smb_io_base); + dev = DEVICE(pci_create(bus, devfn, TYPE_PIIX4_PM)); + qdev_prop_set_uint32(dev, "smb_io_base", smb_io_base); - s = DO_UPCAST(PIIX4PMState, dev, dev); + s = PIIX4_PM(dev); s->irq = sci_irq; s->smi_irq = smi_irq; s->kvm_enabled = kvm_enabled; - qdev_init_nofail(&dev->qdev); + qdev_init_nofail(dev); if (fw_cfg) { uint8_t suspend[6] = {128, 0, 0, 129, 128, 128}; @@ -501,7 +505,7 @@ static void piix4_pm_class_init(ObjectClass *klass, void *data) } static const TypeInfo piix4_pm_info = { - .name = "PIIX4_PM", + .name = TYPE_PIIX4_PM, .parent = TYPE_PCI_DEVICE, .instance_size = sizeof(PIIX4PMState), .class_init = piix4_pm_class_init, @@ -679,7 +683,7 @@ static void piix4_acpi_system_hot_add_init(MemoryRegion *parent, "acpi-pci-hotplug", PCI_HOTPLUG_SIZE); memory_region_add_subregion(parent, PCI_HOTPLUG_ADDR, &s->io_pci); - pci_bus_hotplug(bus, piix4_device_hotplug, &s->dev.qdev); + pci_bus_hotplug(bus, piix4_device_hotplug, DEVICE(s)); qemu_for_each_cpu(piix4_init_cpu_status, &s->gpe_cpu); memory_region_init_io(&s->io_cpu, OBJECT(s), &cpu_hotplug_ops, s, @@ -705,8 +709,7 @@ static int piix4_device_hotplug(DeviceState *qdev, PCIDevice *dev, PCIHotplugState state) { int slot = PCI_SLOT(dev->devfn); - PIIX4PMState *s = DO_UPCAST(PIIX4PMState, dev, - PCI_DEVICE(qdev)); + PIIX4PMState *s = PIIX4_PM(qdev); /* Don't send event when device is enabled during qemu machine creation: * it is present on boot, no hotplug event is necessary. We do send an From 6a6b5580bd03fc7326716ebb36b1f42ebfc0a967 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Sun, 30 Jun 2013 14:40:37 +0200 Subject: [PATCH 18/55] acpi/piix4: QOM parent field cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace direct uses of PIIX4PMState::dev with QOM casts and rename it to parent_obj. Acked-by: Peter Crosthwaite Signed-off-by: Andreas Färber --- hw/acpi/piix4.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c index 5cd286ea24..c88569061c 100644 --- a/hw/acpi/piix4.c +++ b/hw/acpi/piix4.c @@ -64,7 +64,9 @@ typedef struct CPUStatus { } CPUStatus; typedef struct PIIX4PMState { - PCIDevice dev; + /*< private >*/ + PCIDevice parent_obj; + /*< public >*/ MemoryRegion io; MemoryRegion io_gpe; @@ -135,11 +137,12 @@ static void pm_tmr_timer(ACPIREGS *ar) static void apm_ctrl_changed(uint32_t val, void *arg) { PIIX4PMState *s = arg; + PCIDevice *d = PCI_DEVICE(s); /* ACPI specs 3.0, 4.7.2.5 */ acpi_pm1_cnt_update(&s->ar, val == ACPI_ENABLE, val == ACPI_DISABLE); - if (s->dev.config[0x5b] & (1 << 1)) { + if (d->config[0x5b] & (1 << 1)) { if (s->smi_irq) { qemu_irq_raise(s->smi_irq); } @@ -148,24 +151,27 @@ static void apm_ctrl_changed(uint32_t val, void *arg) static void pm_io_space_update(PIIX4PMState *s) { + PCIDevice *d = PCI_DEVICE(s); uint32_t pm_io_base; - pm_io_base = le32_to_cpu(*(uint32_t *)(s->dev.config + 0x40)); + pm_io_base = le32_to_cpu(*(uint32_t *)(d->config + 0x40)); pm_io_base &= 0xffc0; memory_region_transaction_begin(); - memory_region_set_enabled(&s->io, s->dev.config[0x80] & 1); + memory_region_set_enabled(&s->io, d->config[0x80] & 1); memory_region_set_address(&s->io, pm_io_base); memory_region_transaction_commit(); } static void smbus_io_space_update(PIIX4PMState *s) { - s->smb_io_base = le32_to_cpu(*(uint32_t *)(s->dev.config + 0x90)); + PCIDevice *d = PCI_DEVICE(s); + + s->smb_io_base = le32_to_cpu(*(uint32_t *)(d->config + 0x90)); s->smb_io_base &= 0xffc0; memory_region_transaction_begin(); - memory_region_set_enabled(&s->smb.io, s->dev.config[0xd2] & 1); + memory_region_set_enabled(&s->smb.io, d->config[0xd2] & 1); memory_region_set_address(&s->smb.io, s->smb_io_base); memory_region_transaction_commit(); } @@ -244,7 +250,7 @@ static int acpi_load_old(QEMUFile *f, void *opaque, int version_id) int ret, i; uint16_t temp; - ret = pci_device_load(&s->dev, f); + ret = pci_device_load(PCI_DEVICE(s), f); if (ret < 0) { return ret; } @@ -288,7 +294,7 @@ static const VMStateDescription vmstate_acpi = { .load_state_old = acpi_load_old, .post_load = vmstate_acpi_post_load, .fields = (VMStateField []) { - VMSTATE_PCI_DEVICE(dev, PIIX4PMState), + VMSTATE_PCI_DEVICE(parent_obj, PIIX4PMState), VMSTATE_UINT16(ar.pm1.evt.sts, PIIX4PMState), VMSTATE_UINT16(ar.pm1.evt.en, PIIX4PMState), VMSTATE_UINT16(ar.pm1.cnt.cnt, PIIX4PMState), @@ -359,7 +365,8 @@ static void piix4_update_hotplug(PIIX4PMState *s) static void piix4_reset(void *opaque) { PIIX4PMState *s = opaque; - uint8_t *pci_conf = s->dev.config; + PCIDevice *d = PCI_DEVICE(s); + uint8_t *pci_conf = d->config; pci_conf[0x58] = 0; pci_conf[0x59] = 0; @@ -387,10 +394,11 @@ static void piix4_pm_powerdown_req(Notifier *n, void *opaque) static void piix4_pm_machine_ready(Notifier *n, void *opaque) { PIIX4PMState *s = container_of(n, PIIX4PMState, machine_ready); - MemoryRegion *io_as = pci_address_space_io(&s->dev); + PCIDevice *d = PCI_DEVICE(s); + MemoryRegion *io_as = pci_address_space_io(d); uint8_t *pci_conf; - pci_conf = s->dev.config; + pci_conf = d->config; pci_conf[0x5f] = 0x10 | (memory_region_present(io_as, 0x378) ? 0x80 : 0); pci_conf[0x63] = 0x60; @@ -403,7 +411,7 @@ static int piix4_pm_initfn(PCIDevice *dev) PIIX4PMState *s = PIIX4_PM(dev); uint8_t *pci_conf; - pci_conf = s->dev.config; + pci_conf = dev->config; pci_conf[0x06] = 0x80; pci_conf[0x07] = 0x02; pci_conf[0x09] = 0x00; From 40108d0a6d1e59aa5904298874753fe0cb420a64 Mon Sep 17 00:00:00 2001 From: Peter Crosthwaite Date: Mon, 24 Jun 2013 16:58:00 +1000 Subject: [PATCH 19/55] misc/pci-testdev: QOM Upcast Sweep MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Define and use standard QOM cast macro. Remove usages of DO_UPCAST() and direct -> style upcasting. Signed-off-by: Peter Crosthwaite [AF: Replaced another DO_UPCAST()] Signed-off-by: Andreas Färber --- hw/misc/pci-testdev.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/hw/misc/pci-testdev.c b/hw/misc/pci-testdev.c index 8b0b73f9c4..3fb15c0da2 100644 --- a/hw/misc/pci-testdev.c +++ b/hw/misc/pci-testdev.c @@ -83,6 +83,11 @@ typedef struct PCITestDevState { int current; } PCITestDevState; +#define TYPE_PCI_TEST_DEV "pci-testdev" + +#define PCI_TEST_DEV(obj) \ + OBJECT_CHECK(PCITestDevState, (obj), TYPE_PCI_TEST_DEV) + #define IOTEST_IS_MEM(i) (strcmp(IOTEST_TYPE(i), "portio")) #define IOTEST_REGION(d, i) (IOTEST_IS_MEM(i) ? &(d)->mmio : &(d)->portio) #define IOTEST_SIZE(i) (IOTEST_IS_MEM(i) ? IOTEST_MEMSIZE : IOTEST_IOSIZE) @@ -227,7 +232,7 @@ static const MemoryRegionOps pci_testdev_pio_ops = { static int pci_testdev_init(PCIDevice *pci_dev) { - PCITestDevState *d = DO_UPCAST(PCITestDevState, dev, pci_dev); + PCITestDevState *d = PCI_TEST_DEV(pci_dev); uint8_t *pci_conf; char *name; int r, i; @@ -274,7 +279,7 @@ static int pci_testdev_init(PCIDevice *pci_dev) static void pci_testdev_uninit(PCIDevice *dev) { - PCITestDevState *d = DO_UPCAST(PCITestDevState, dev, dev); + PCITestDevState *d = PCI_TEST_DEV(dev); int i; pci_testdev_reset(d); @@ -291,7 +296,7 @@ pci_testdev_uninit(PCIDevice *dev) static void qdev_pci_testdev_reset(DeviceState *dev) { - PCITestDevState *d = DO_UPCAST(PCITestDevState, dev.qdev, dev); + PCITestDevState *d = PCI_TEST_DEV(dev); pci_testdev_reset(d); } @@ -311,7 +316,7 @@ static void pci_testdev_class_init(ObjectClass *klass, void *data) } static const TypeInfo pci_testdev_info = { - .name = "pci-testdev", + .name = TYPE_PCI_TEST_DEV, .parent = TYPE_PCI_DEVICE, .instance_size = sizeof(PCITestDevState), .class_init = pci_testdev_class_init, From 6d27a4099e46132768256b686ebf522844a180b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Sun, 30 Jun 2013 14:48:56 +0200 Subject: [PATCH 20/55] misc/pci-testdev: QOM parent field cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace direct uses of PCITestDevState::dev with QOM casts and rename it to parent_obj. Acked-by: Peter Crosthwaite Signed-off-by: Andreas Färber --- hw/misc/pci-testdev.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/hw/misc/pci-testdev.c b/hw/misc/pci-testdev.c index 3fb15c0da2..d69ff3364d 100644 --- a/hw/misc/pci-testdev.c +++ b/hw/misc/pci-testdev.c @@ -76,7 +76,10 @@ enum { #define IOTEST_ACCESS_WIDTH (sizeof(uint8_t)) typedef struct PCITestDevState { - PCIDevice dev; + /*< private >*/ + PCIDevice parent_obj; + /*< public >*/ + MemoryRegion mmio; MemoryRegion portio; IOTest *tests; @@ -237,7 +240,7 @@ static int pci_testdev_init(PCIDevice *pci_dev) char *name; int r, i; - pci_conf = d->dev.config; + pci_conf = pci_dev->config; pci_conf[PCI_INTERRUPT_PIN] = 0; /* no interrupt pin */ @@ -245,8 +248,8 @@ static int pci_testdev_init(PCIDevice *pci_dev) "pci-testdev-mmio", IOTEST_MEMSIZE * 2); memory_region_init_io(&d->portio, OBJECT(d), &pci_testdev_pio_ops, d, "pci-testdev-portio", IOTEST_IOSIZE * 2); - pci_register_bar(&d->dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, &d->mmio); - pci_register_bar(&d->dev, 1, PCI_BASE_ADDRESS_SPACE_IO, &d->portio); + pci_register_bar(pci_dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, &d->mmio); + pci_register_bar(pci_dev, 1, PCI_BASE_ADDRESS_SPACE_IO, &d->portio); d->current = -1; d->tests = g_malloc0(IOTEST_MAX * sizeof *d->tests); From 39d4598763a01816feb828be4633ada780a63886 Mon Sep 17 00:00:00 2001 From: Peter Crosthwaite Date: Mon, 24 Jun 2013 16:58:45 +1000 Subject: [PATCH 21/55] display/vmware_vga: QOM casting sweep MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Define and use standard QOM cast macro. Remove usages of DO_UPCAST() and direct -> style casting. Signed-off-by: Peter Crosthwaite [AF: Renamed to TYPE_VMWARE_VGA and VMWARE_VGA()] Signed-off-by: Andreas Färber --- hw/display/vmware_vga.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/hw/display/vmware_vga.c b/hw/display/vmware_vga.c index 714908f44c..32637e7ba8 100644 --- a/hw/display/vmware_vga.c +++ b/hw/display/vmware_vga.c @@ -81,6 +81,11 @@ struct vmsvga_state_s { int redraw_fifo_first, redraw_fifo_last; }; +#define TYPE_VMWARE_SVGA "vmware-svga" + +#define VMWARE_SVGA(obj) \ + OBJECT_CHECK(struct pci_vmsvga_state_s, (obj), TYPE_VMWARE_SVGA) + struct pci_vmsvga_state_s { PCIDevice card; struct vmsvga_state_s chip; @@ -1092,8 +1097,7 @@ static void vmsvga_update_display(void *opaque) static void vmsvga_reset(DeviceState *dev) { - struct pci_vmsvga_state_s *pci = - DO_UPCAST(struct pci_vmsvga_state_s, card.qdev, dev); + struct pci_vmsvga_state_s *pci = VMWARE_SVGA(dev); struct vmsvga_state_s *s = &pci->chip; s->index = 0; @@ -1250,8 +1254,7 @@ static const MemoryRegionOps vmsvga_io_ops = { static int pci_vmsvga_initfn(PCIDevice *dev) { - struct pci_vmsvga_state_s *s = - DO_UPCAST(struct pci_vmsvga_state_s, card, dev); + struct pci_vmsvga_state_s *s = VMWARE_SVGA(dev); s->card.config[PCI_CACHE_LINE_SIZE] = 0x08; /* Cache line size */ s->card.config[PCI_LATENCY_TIMER] = 0x40; /* Latency timer */ @@ -1303,7 +1306,7 @@ static void vmsvga_class_init(ObjectClass *klass, void *data) } static const TypeInfo vmsvga_info = { - .name = "vmware-svga", + .name = TYPE_VMWARE_SVGA, .parent = TYPE_PCI_DEVICE, .instance_size = sizeof(struct pci_vmsvga_state_s), .class_init = vmsvga_class_init, From af21c7403902d5073851ea10371d0761f48e39d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Sun, 30 Jun 2013 15:01:36 +0200 Subject: [PATCH 22/55] display/vmware_vga: QOM parent field cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace direct uses of pci_vmsvga_state_s::card with QOM casts and rename it to parent_obj. Acked-by: Peter Crosthwaite Signed-off-by: Andreas Färber --- hw/display/vmware_vga.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/hw/display/vmware_vga.c b/hw/display/vmware_vga.c index 32637e7ba8..3536cded92 100644 --- a/hw/display/vmware_vga.c +++ b/hw/display/vmware_vga.c @@ -87,7 +87,10 @@ struct vmsvga_state_s { OBJECT_CHECK(struct pci_vmsvga_state_s, (obj), TYPE_VMWARE_SVGA) struct pci_vmsvga_state_s { - PCIDevice card; + /*< private >*/ + PCIDevice parent_obj; + /*< public >*/ + struct vmsvga_state_s chip; MemoryRegion io_bar; }; @@ -792,7 +795,7 @@ static uint32_t vmsvga_value_read(void *opaque, uint32_t address) case SVGA_REG_FB_START: { struct pci_vmsvga_state_s *pci_vmsvga = container_of(s, struct pci_vmsvga_state_s, chip); - ret = pci_get_bar_addr(&pci_vmsvga->card, 1); + ret = pci_get_bar_addr(PCI_DEVICE(pci_vmsvga), 1); break; } @@ -828,7 +831,7 @@ static uint32_t vmsvga_value_read(void *opaque, uint32_t address) case SVGA_REG_MEM_START: { struct pci_vmsvga_state_s *pci_vmsvga = container_of(s, struct pci_vmsvga_state_s, chip); - ret = pci_get_bar_addr(&pci_vmsvga->card, 2); + ret = pci_get_bar_addr(PCI_DEVICE(pci_vmsvga), 2); break; } @@ -1176,7 +1179,7 @@ static const VMStateDescription vmstate_vmware_vga = { .minimum_version_id = 0, .minimum_version_id_old = 0, .fields = (VMStateField[]) { - VMSTATE_PCI_DEVICE(card, struct pci_vmsvga_state_s), + VMSTATE_PCI_DEVICE(parent_obj, struct pci_vmsvga_state_s), VMSTATE_STRUCT(chip, struct pci_vmsvga_state_s, 0, vmstate_vmware_vga_internal, struct vmsvga_state_s), VMSTATE_END_OF_LIST() @@ -1256,21 +1259,21 @@ static int pci_vmsvga_initfn(PCIDevice *dev) { struct pci_vmsvga_state_s *s = VMWARE_SVGA(dev); - s->card.config[PCI_CACHE_LINE_SIZE] = 0x08; /* Cache line size */ - s->card.config[PCI_LATENCY_TIMER] = 0x40; /* Latency timer */ - s->card.config[PCI_INTERRUPT_LINE] = 0xff; /* End */ + dev->config[PCI_CACHE_LINE_SIZE] = 0x08; + dev->config[PCI_LATENCY_TIMER] = 0x40; + dev->config[PCI_INTERRUPT_LINE] = 0xff; /* End */ memory_region_init_io(&s->io_bar, NULL, &vmsvga_io_ops, &s->chip, "vmsvga-io", 0x10); memory_region_set_flush_coalesced(&s->io_bar); - pci_register_bar(&s->card, 0, PCI_BASE_ADDRESS_SPACE_IO, &s->io_bar); + pci_register_bar(dev, 0, PCI_BASE_ADDRESS_SPACE_IO, &s->io_bar); vmsvga_init(DEVICE(dev), &s->chip, pci_address_space(dev), pci_address_space_io(dev)); - pci_register_bar(&s->card, 1, PCI_BASE_ADDRESS_MEM_PREFETCH, + pci_register_bar(dev, 1, PCI_BASE_ADDRESS_MEM_PREFETCH, &s->chip.vga.vram); - pci_register_bar(&s->card, 2, PCI_BASE_ADDRESS_MEM_PREFETCH, + pci_register_bar(dev, 2, PCI_BASE_ADDRESS_MEM_PREFETCH, &s->chip.fifo_ram); if (!dev->rom_bar) { From eb3fedf3d4b1a3ed2a31def23e972aa0c3669fff Mon Sep 17 00:00:00 2001 From: Peter Crosthwaite Date: Mon, 24 Jun 2013 16:59:29 +1000 Subject: [PATCH 23/55] misc/ivshmem: QOM Upcast Sweep MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Define and use standard QOM cast macro. Remove usages of DO_UPCAST() and direct -> style upcasting. Signed-off-by: Peter Crosthwaite [AF: Simplified casts and converted two more DO_UPCAST()s] Signed-off-by: Andreas Färber --- hw/misc/ivshmem.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c index 3594b84259..5df29c1670 100644 --- a/hw/misc/ivshmem.c +++ b/hw/misc/ivshmem.c @@ -48,6 +48,10 @@ #define IVSHMEM_DPRINTF(fmt, ...) #endif +#define TYPE_IVSHMEM "ivshmem" +#define IVSHMEM(obj) \ + OBJECT_CHECK(IVShmemState, (obj), TYPE_IVSHMEM) + typedef struct Peer { int nb_eventfds; EventNotifier *eventfds; @@ -341,7 +345,7 @@ static void create_shared_memory_BAR(IVShmemState *s, int fd) { memory_region_init_ram_ptr(&s->ivshmem, OBJECT(s), "ivshmem.bar2", s->ivshmem_size, ptr); - vmstate_register_ram(&s->ivshmem, &s->dev.qdev); + vmstate_register_ram(&s->ivshmem, DEVICE(s)); memory_region_add_subregion(&s->bar, 0, &s->ivshmem); /* region for shared memory */ @@ -469,7 +473,7 @@ static void ivshmem_read(void *opaque, const uint8_t * buf, int flags) incoming_fd, 0); memory_region_init_ram_ptr(&s->ivshmem, OBJECT(s), "ivshmem.bar2", s->ivshmem_size, map_ptr); - vmstate_register_ram(&s->ivshmem, &s->dev.qdev); + vmstate_register_ram(&s->ivshmem, DEVICE(s)); IVSHMEM_DPRINTF("guest h/w addr = %" PRIu64 ", size = %" PRIu64 "\n", s->ivshmem_offset, s->ivshmem_size); @@ -534,7 +538,7 @@ static void ivshmem_use_msix(IVShmemState * s) static void ivshmem_reset(DeviceState *d) { - IVShmemState *s = DO_UPCAST(IVShmemState, dev.qdev, d); + IVShmemState *s = IVSHMEM(d); s->intrstatus = 0; ivshmem_use_msix(s); @@ -639,7 +643,7 @@ static void ivshmem_write_config(PCIDevice *pci_dev, uint32_t address, static int pci_ivshmem_init(PCIDevice *dev) { - IVShmemState *s = DO_UPCAST(IVShmemState, dev, dev); + IVShmemState *s = IVSHMEM(dev); uint8_t *pci_conf; if (s->sizearg == NULL) @@ -648,7 +652,7 @@ static int pci_ivshmem_init(PCIDevice *dev) s->ivshmem_size = ivshmem_get_size(s); } - register_savevm(&s->dev.qdev, "ivshmem", 0, 0, ivshmem_save, ivshmem_load, + register_savevm(DEVICE(dev), "ivshmem", 0, 0, ivshmem_save, ivshmem_load, dev); /* IRQFD requires MSI */ @@ -771,7 +775,7 @@ static int pci_ivshmem_init(PCIDevice *dev) static void pci_ivshmem_uninit(PCIDevice *dev) { - IVShmemState *s = DO_UPCAST(IVShmemState, dev, dev); + IVShmemState *s = IVSHMEM(dev); if (s->migration_blocker) { migrate_del_blocker(s->migration_blocker); @@ -780,10 +784,10 @@ static void pci_ivshmem_uninit(PCIDevice *dev) memory_region_destroy(&s->ivshmem_mmio); memory_region_del_subregion(&s->bar, &s->ivshmem); - vmstate_unregister_ram(&s->ivshmem, &s->dev.qdev); + vmstate_unregister_ram(&s->ivshmem, DEVICE(dev)); memory_region_destroy(&s->ivshmem); memory_region_destroy(&s->bar); - unregister_savevm(&dev->qdev, "ivshmem", s); + unregister_savevm(DEVICE(dev), "ivshmem", s); } static Property ivshmem_properties[] = { @@ -813,7 +817,7 @@ static void ivshmem_class_init(ObjectClass *klass, void *data) } static const TypeInfo ivshmem_info = { - .name = "ivshmem", + .name = TYPE_IVSHMEM, .parent = TYPE_PCI_DEVICE, .instance_size = sizeof(IVShmemState), .class_init = ivshmem_class_init, From b7578eaadd71fd7a9101875a32d64a52149d78e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Sun, 30 Jun 2013 15:15:15 +0200 Subject: [PATCH 24/55] misc/ivshmem: QOM parent field cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace direct uses of IVShmemState::dev with QOM casts and rename it to parent_obj. Acked-by: Peter Crosthwaite Signed-off-by: Andreas Färber --- hw/misc/ivshmem.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c index 5df29c1670..4a74856c95 100644 --- a/hw/misc/ivshmem.c +++ b/hw/misc/ivshmem.c @@ -63,7 +63,10 @@ typedef struct EventfdEntry { } EventfdEntry; typedef struct IVShmemState { - PCIDevice dev; + /*< private >*/ + PCIDevice parent_obj; + /*< public >*/ + uint32_t intrmask; uint32_t intrstatus; uint32_t doorbell; @@ -120,6 +123,7 @@ static inline bool is_power_of_two(uint64_t x) { /* accessing registers - based on rtl8139 */ static void ivshmem_update_irq(IVShmemState *s, int val) { + PCIDevice *d = PCI_DEVICE(s); int isr; isr = (s->intrstatus & s->intrmask) & 0xffffffff; @@ -129,7 +133,7 @@ static void ivshmem_update_irq(IVShmemState *s, int val) isr ? 1 : 0, s->intrstatus, s->intrmask); } - qemu_set_irq(s->dev.irq[0], (isr != 0)); + qemu_set_irq(d->irq[0], (isr != 0)); } static void ivshmem_IntrMask_write(IVShmemState *s, uint32_t val) @@ -300,7 +304,7 @@ static CharDriverState* create_eventfd_chr_device(void * opaque, EventNotifier * /* if MSI is supported we need multiple interrupts */ if (ivshmem_has_feature(s, IVSHMEM_MSI)) { - s->eventfd_table[vector].pdev = &s->dev; + s->eventfd_table[vector].pdev = PCI_DEVICE(s); s->eventfd_table[vector].vector = vector; qemu_chr_add_handlers(chr, ivshmem_can_receive, fake_irqfd, @@ -349,7 +353,7 @@ static void create_shared_memory_BAR(IVShmemState *s, int fd) { memory_region_add_subregion(&s->bar, 0, &s->ivshmem); /* region for shared memory */ - pci_register_bar(&s->dev, 2, s->ivshmem_attr, &s->bar); + pci_register_bar(PCI_DEVICE(s), 2, s->ivshmem_attr, &s->bar); } static void ivshmem_add_eventfd(IVShmemState *s, int posn, int i) @@ -525,14 +529,15 @@ static void ivshmem_read(void *opaque, const uint8_t * buf, int flags) * we just enable all vectors on init and after reset. */ static void ivshmem_use_msix(IVShmemState * s) { + PCIDevice *d = PCI_DEVICE(s); int i; - if (!msix_present(&s->dev)) { + if (!msix_present(d)) { return; } for (i = 0; i < s->vectors; i++) { - msix_vector_use(&s->dev, i); + msix_vector_use(d, i); } } @@ -573,7 +578,7 @@ static uint64_t ivshmem_get_size(IVShmemState * s) { static void ivshmem_setup_msi(IVShmemState * s) { - if (msix_init_exclusive_bar(&s->dev, s->vectors, 1)) { + if (msix_init_exclusive_bar(PCI_DEVICE(s), s->vectors, 1)) { IVSHMEM_DPRINTF("msix initialization failed\n"); exit(1); } @@ -589,12 +594,13 @@ static void ivshmem_setup_msi(IVShmemState * s) static void ivshmem_save(QEMUFile* f, void *opaque) { IVShmemState *proxy = opaque; + PCIDevice *pci_dev = PCI_DEVICE(proxy); IVSHMEM_DPRINTF("ivshmem_save\n"); - pci_device_save(&proxy->dev, f); + pci_device_save(pci_dev, f); if (ivshmem_has_feature(proxy, IVSHMEM_MSI)) { - msix_save(&proxy->dev, f); + msix_save(pci_dev, f); } else { qemu_put_be32(f, proxy->intrstatus); qemu_put_be32(f, proxy->intrmask); @@ -607,6 +613,7 @@ static int ivshmem_load(QEMUFile* f, void *opaque, int version_id) IVSHMEM_DPRINTF("ivshmem_load\n"); IVShmemState *proxy = opaque; + PCIDevice *pci_dev = PCI_DEVICE(proxy); int ret; if (version_id > 0) { @@ -618,13 +625,13 @@ static int ivshmem_load(QEMUFile* f, void *opaque, int version_id) return -EINVAL; } - ret = pci_device_load(&proxy->dev, f); + ret = pci_device_load(pci_dev, f); if (ret) { return ret; } if (ivshmem_has_feature(proxy, IVSHMEM_MSI)) { - msix_load(&proxy->dev, f); + msix_load(pci_dev, f); ivshmem_use_msix(proxy); } else { proxy->intrstatus = qemu_get_be32(f); @@ -682,7 +689,7 @@ static int pci_ivshmem_init(PCIDevice *dev) migrate_add_blocker(s->migration_blocker); } - pci_conf = s->dev.config; + pci_conf = dev->config; pci_conf[PCI_COMMAND] = PCI_COMMAND_IO | PCI_COMMAND_MEMORY; pci_config_set_interrupt_pin(pci_conf, 1); @@ -693,7 +700,7 @@ static int pci_ivshmem_init(PCIDevice *dev) "ivshmem-mmio", IVSHMEM_REG_BAR_SIZE); /* region for registers*/ - pci_register_bar(&s->dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, + pci_register_bar(dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, &s->ivshmem_mmio); memory_region_init(&s->bar, OBJECT(s), "ivshmem-bar2-container", s->ivshmem_size); @@ -727,7 +734,7 @@ static int pci_ivshmem_init(PCIDevice *dev) /* allocate/initialize space for interrupt handling */ s->peers = g_malloc0(s->nb_peers * sizeof(Peer)); - pci_register_bar(&s->dev, 2, s->ivshmem_attr, &s->bar); + pci_register_bar(dev, 2, s->ivshmem_attr, &s->bar); s->eventfd_chr = g_malloc0(s->vectors * sizeof(CharDriverState *)); @@ -768,7 +775,7 @@ static int pci_ivshmem_init(PCIDevice *dev) } - s->dev.config_write = ivshmem_write_config; + dev->config_write = ivshmem_write_config; return 0; } From 51a3fe996ba20eca0abfad2b783f27967d759d28 Mon Sep 17 00:00:00 2001 From: Peter Crosthwaite Date: Mon, 24 Jun 2013 17:00:14 +1000 Subject: [PATCH 25/55] xen/xen_platform: QOM casting sweep MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Define and use standard QOM cast macro. Remove usages of DO_UPCAST() and direct -> style upcasting. Signed-off-by: Peter Crosthwaite [AF: Dropped opaque casts] Signed-off-by: Andreas Färber --- hw/xen/xen_platform.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/hw/xen/xen_platform.c b/hw/xen/xen_platform.c index 15d7cf0f6c..52a7279ac5 100644 --- a/hw/xen/xen_platform.c +++ b/hw/xen/xen_platform.c @@ -62,6 +62,10 @@ typedef struct PCIXenPlatformState { int log_buffer_off; } PCIXenPlatformState; +#define TYPE_XEN_PLATFORM "xen-platform" +#define XEN_PLATFORM(obj) \ + OBJECT_CHECK(PCIXenPlatformState, (obj), TYPE_XEN_PLATFORM) + #define XEN_PLATFORM_IOPORT 0x10 /* Send bytes to syslog */ @@ -88,7 +92,7 @@ static void unplug_nic(PCIBus *b, PCIDevice *d, void *o) if (pci_get_word(d->config + PCI_CLASS_DEVICE) == PCI_CLASS_NETWORK_ETHERNET && strcmp(d->name, "xen-pci-passthrough") != 0) { - qdev_free(&d->qdev); + qdev_free(DEVICE(d)); } } @@ -103,7 +107,7 @@ static void unplug_disks(PCIBus *b, PCIDevice *d, void *o) if (pci_get_word(d->config + PCI_CLASS_DEVICE) == PCI_CLASS_STORAGE_IDE && strcmp(d->name, "xen-pci-passthrough") != 0) { - qdev_unplug(&(d->qdev), NULL); + qdev_unplug(DEVICE(d), NULL); } } @@ -376,7 +380,7 @@ static const VMStateDescription vmstate_xen_platform = { static int xen_platform_initfn(PCIDevice *dev) { - PCIXenPlatformState *d = DO_UPCAST(PCIXenPlatformState, pci_dev, dev); + PCIXenPlatformState *d = XEN_PLATFORM(dev); uint8_t *pci_conf; pci_conf = d->pci_dev.config; @@ -402,7 +406,7 @@ static int xen_platform_initfn(PCIDevice *dev) static void platform_reset(DeviceState *dev) { - PCIXenPlatformState *s = DO_UPCAST(PCIXenPlatformState, pci_dev.qdev, dev); + PCIXenPlatformState *s = XEN_PLATFORM(dev); platform_fixed_ioport_reset(s); } @@ -425,7 +429,7 @@ static void xen_platform_class_init(ObjectClass *klass, void *data) } static const TypeInfo xen_platform_info = { - .name = "xen-platform", + .name = TYPE_XEN_PLATFORM, .parent = TYPE_PCI_DEVICE, .instance_size = sizeof(PCIXenPlatformState), .class_init = xen_platform_class_init, From dc4aa51ba8bbef7edf4a104a5a6029a76a68600e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Sun, 30 Jun 2013 15:20:05 +0200 Subject: [PATCH 26/55] xen/xen_platform: QOM parent field cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace direct uses of PCIXenPlatformState::pci_dev field with QOM casts and rename it to parent_obj. Acked-by: Peter Crosthwaite Signed-off-by: Andreas Färber --- hw/xen/xen_platform.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/hw/xen/xen_platform.c b/hw/xen/xen_platform.c index 52a7279ac5..6a8ba7e9aa 100644 --- a/hw/xen/xen_platform.c +++ b/hw/xen/xen_platform.c @@ -49,7 +49,10 @@ #define PFFLAG_ROM_LOCK 1 /* Sets whether ROM memory area is RW or RO */ typedef struct PCIXenPlatformState { - PCIDevice pci_dev; + /*< private >*/ + PCIDevice parent_obj; + /*< public >*/ + MemoryRegion fixed_io; MemoryRegion bar; MemoryRegion mmio_bar; @@ -121,7 +124,8 @@ static void platform_fixed_ioport_writew(void *opaque, uint32_t addr, uint32_t v PCIXenPlatformState *s = opaque; switch (addr) { - case 0: + case 0: { + PCIDevice *pci_dev = PCI_DEVICE(s); /* Unplug devices. Value is a bitmask of which devices to unplug, with bit 0 the IDE devices, bit 1 the network devices, and bit 2 the non-primary-master IDE devices. */ @@ -129,16 +133,17 @@ static void platform_fixed_ioport_writew(void *opaque, uint32_t addr, uint32_t v DPRINTF("unplug disks\n"); bdrv_drain_all(); bdrv_flush_all(); - pci_unplug_disks(s->pci_dev.bus); + pci_unplug_disks(pci_dev->bus); } if (val & UNPLUG_ALL_NICS) { DPRINTF("unplug nics\n"); - pci_unplug_nics(s->pci_dev.bus); + pci_unplug_nics(pci_dev->bus); } if (val & UNPLUG_AUX_IDE_DISKS) { DPRINTF("unplug auxiliary disks not supported\n"); } break; + } case 2: switch (val) { case 1: @@ -372,7 +377,7 @@ static const VMStateDescription vmstate_xen_platform = { .minimum_version_id_old = 4, .post_load = xen_platform_post_load, .fields = (VMStateField []) { - VMSTATE_PCI_DEVICE(pci_dev, PCIXenPlatformState), + VMSTATE_PCI_DEVICE(parent_obj, PCIXenPlatformState), VMSTATE_UINT8(flags, PCIXenPlatformState), VMSTATE_END_OF_LIST() } @@ -383,7 +388,7 @@ static int xen_platform_initfn(PCIDevice *dev) PCIXenPlatformState *d = XEN_PLATFORM(dev); uint8_t *pci_conf; - pci_conf = d->pci_dev.config; + pci_conf = dev->config; pci_set_word(pci_conf + PCI_COMMAND, PCI_COMMAND_IO | PCI_COMMAND_MEMORY); @@ -392,11 +397,11 @@ static int xen_platform_initfn(PCIDevice *dev) pci_conf[PCI_INTERRUPT_PIN] = 1; platform_ioport_bar_setup(d); - pci_register_bar(&d->pci_dev, 0, PCI_BASE_ADDRESS_SPACE_IO, &d->bar); + pci_register_bar(dev, 0, PCI_BASE_ADDRESS_SPACE_IO, &d->bar); /* reserve 16MB mmio address for share memory*/ platform_mmio_setup(d); - pci_register_bar(&d->pci_dev, 1, PCI_BASE_ADDRESS_MEM_PREFETCH, + pci_register_bar(dev, 1, PCI_BASE_ADDRESS_MEM_PREFETCH, &d->mmio_bar); platform_fixed_ioport_init(d); From ce7243986fe69be831ec893127282fa5a045c985 Mon Sep 17 00:00:00 2001 From: Hu Tao Date: Mon, 1 Jul 2013 18:18:17 +0800 Subject: [PATCH 27/55] sysbus: Document SysBusDeviceClass::init and realize semantics MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Hu Tao [AF: Syntax and wording changes] Signed-off-by: Andreas Färber --- include/hw/sysbus.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/hw/sysbus.h b/include/hw/sysbus.h index 7c2e3163fb..8c17165cf2 100644 --- a/include/hw/sysbus.h +++ b/include/hw/sysbus.h @@ -23,8 +23,20 @@ typedef struct SysBusDevice SysBusDevice; #define SYS_BUS_DEVICE_GET_CLASS(obj) \ OBJECT_GET_CLASS(SysBusDeviceClass, (obj), TYPE_SYS_BUS_DEVICE) +/** + * SysBusDeviceClass: + * @init: Callback function invoked when the #DeviceState.realized property + * is changed to %true. Deprecated, new types inheriting directly from + * TYPE_SYS_BUS_DEVICE should use #DeviceClass.realize instead, new leaf + * types should consult their respective parent type. + * + * SysBusDeviceClass is not overriding #DeviceClass.realize, so derived + * classes overriding it are not required to invoke its implementation. + */ typedef struct SysBusDeviceClass { + /*< private >*/ DeviceClass parent_class; + /*< public >*/ int (*init)(SysBusDevice *dev); } SysBusDeviceClass; From 1aa0c0c748ad05cde80b4d6f2907a70bc4089883 Mon Sep 17 00:00:00 2001 From: Hu Tao Date: Mon, 1 Jul 2013 18:18:18 +0800 Subject: [PATCH 28/55] ohci: QOM'ify some more MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Introduce type constant and avoid DO_UPCAST(). Signed-off-by: Hu Tao [AF: Avoid remaining OHCIPCIState::pci_dev uses, rename parent fields] Signed-off-by: Andreas Färber --- hw/usb/hcd-ohci.c | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/hw/usb/hcd-ohci.c b/hw/usb/hcd-ohci.c index a096ecf214..7da256409c 100644 --- a/hw/usb/hcd-ohci.c +++ b/hw/usb/hcd-ohci.c @@ -1843,35 +1843,46 @@ static int usb_ohci_init(OHCIState *ohci, DeviceState *dev, return 0; } +#define TYPE_PCI_OHCI "pci-ohci" +#define PCI_OHCI(obj) OBJECT_CHECK(OHCIPCIState, (obj), TYPE_PCI_OHCI) + typedef struct { - PCIDevice pci_dev; + /*< private >*/ + PCIDevice parent_obj; + /*< public >*/ + OHCIState state; char *masterbus; uint32_t num_ports; uint32_t firstport; } OHCIPCIState; -static int usb_ohci_initfn_pci(struct PCIDevice *dev) +static int usb_ohci_initfn_pci(PCIDevice *dev) { - OHCIPCIState *ohci = DO_UPCAST(OHCIPCIState, pci_dev, dev); + OHCIPCIState *ohci = PCI_OHCI(dev); - ohci->pci_dev.config[PCI_CLASS_PROG] = 0x10; /* OHCI */ - ohci->pci_dev.config[PCI_INTERRUPT_PIN] = 0x01; /* interrupt pin A */ + dev->config[PCI_CLASS_PROG] = 0x10; /* OHCI */ + dev->config[PCI_INTERRUPT_PIN] = 0x01; /* interrupt pin A */ - if (usb_ohci_init(&ohci->state, &dev->qdev, ohci->num_ports, 0, + if (usb_ohci_init(&ohci->state, DEVICE(dev), ohci->num_ports, 0, ohci->masterbus, ohci->firstport, pci_get_address_space(dev)) != 0) { return -1; } - ohci->state.irq = ohci->pci_dev.irq[0]; + ohci->state.irq = dev->irq[0]; - /* TODO: avoid cast below by using dev */ - pci_register_bar(&ohci->pci_dev, 0, 0, &ohci->state.mem); + pci_register_bar(dev, 0, 0, &ohci->state.mem); return 0; } +#define TYPE_SYSBUS_OHCI "sysbus-ohci" +#define SYSBUS_OHCI(obj) OBJECT_CHECK(OHCISysBusState, (obj), TYPE_SYSBUS_OHCI) + typedef struct { - SysBusDevice busdev; + /*< private >*/ + SysBusDevice parent_obj; + /*< public >*/ + OHCIState ohci; uint32_t num_ports; dma_addr_t dma_offset; @@ -1879,10 +1890,10 @@ typedef struct { static int ohci_init_pxa(SysBusDevice *dev) { - OHCISysBusState *s = FROM_SYSBUS(OHCISysBusState, dev); + OHCISysBusState *s = SYSBUS_OHCI(dev); /* Cannot fail as we pass NULL for masterbus */ - usb_ohci_init(&s->ohci, &dev->qdev, s->num_ports, s->dma_offset, NULL, 0, + usb_ohci_init(&s->ohci, DEVICE(dev), s->num_ports, s->dma_offset, NULL, 0, &address_space_memory); sysbus_init_irq(dev, &s->ohci.irq); sysbus_init_mmio(dev, &s->ohci.mem); @@ -1912,7 +1923,7 @@ static void ohci_pci_class_init(ObjectClass *klass, void *data) } static const TypeInfo ohci_pci_info = { - .name = "pci-ohci", + .name = TYPE_PCI_OHCI, .parent = TYPE_PCI_DEVICE, .instance_size = sizeof(OHCIPCIState), .class_init = ohci_pci_class_init, @@ -1935,7 +1946,7 @@ static void ohci_sysbus_class_init(ObjectClass *klass, void *data) } static const TypeInfo ohci_sysbus_info = { - .name = "sysbus-ohci", + .name = TYPE_SYSBUS_OHCI, .parent = TYPE_SYS_BUS_DEVICE, .instance_size = sizeof(OHCISysBusState), .class_init = ohci_sysbus_class_init, From 457215ec6a3acc020d357b958eb513ef944abc93 Mon Sep 17 00:00:00 2001 From: Hu Tao Date: Mon, 1 Jul 2013 18:18:19 +0800 Subject: [PATCH 29/55] ohci: Use QOM realize for OHCI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Hu Tao Signed-off-by: Andreas Färber --- hw/usb/hcd-ohci.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/hw/usb/hcd-ohci.c b/hw/usb/hcd-ohci.c index 7da256409c..2bab8ffb75 100644 --- a/hw/usb/hcd-ohci.c +++ b/hw/usb/hcd-ohci.c @@ -1888,17 +1888,16 @@ typedef struct { dma_addr_t dma_offset; } OHCISysBusState; -static int ohci_init_pxa(SysBusDevice *dev) +static void ohci_realize_pxa(DeviceState *dev, Error **errp) { OHCISysBusState *s = SYSBUS_OHCI(dev); + SysBusDevice *sbd = SYS_BUS_DEVICE(dev); /* Cannot fail as we pass NULL for masterbus */ - usb_ohci_init(&s->ohci, DEVICE(dev), s->num_ports, s->dma_offset, NULL, 0, + usb_ohci_init(&s->ohci, dev, s->num_ports, s->dma_offset, NULL, 0, &address_space_memory); - sysbus_init_irq(dev, &s->ohci.irq); - sysbus_init_mmio(dev, &s->ohci.mem); - - return 0; + sysbus_init_irq(sbd, &s->ohci.irq); + sysbus_init_mmio(sbd, &s->ohci.mem); } static Property ohci_pci_properties[] = { @@ -1938,9 +1937,8 @@ static Property ohci_sysbus_properties[] = { static void ohci_sysbus_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - SysBusDeviceClass *sbc = SYS_BUS_DEVICE_CLASS(klass); - sbc->init = ohci_init_pxa; + dc->realize = ohci_realize_pxa; dc->desc = "OHCI USB Controller"; dc->props = ohci_sysbus_properties; } From 2aedfa464909c887564c65fb3a51c020d71e0b78 Mon Sep 17 00:00:00 2001 From: Hu Tao Date: Mon, 1 Jul 2013 18:18:21 +0800 Subject: [PATCH 30/55] i440fx: Use type-safe cast instead of direct access of parent dev MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Hu Tao [AF: Converted remaining accesses and renamed to parent_obj] Signed-off-by: Andreas Färber --- hw/pci-host/piix.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/hw/pci-host/piix.c b/hw/pci-host/piix.c index 870e38810c..541c8b7e20 100644 --- a/hw/pci-host/piix.c +++ b/hw/pci-host/piix.c @@ -87,7 +87,10 @@ typedef struct PIIX3State { OBJECT_CHECK(PCII440FXState, (obj), TYPE_I440FX_PCI_DEVICE) struct PCII440FXState { - PCIDevice dev; + /*< private >*/ + PCIDevice parent_obj; + /*< public >*/ + MemoryRegion *system_memory; MemoryRegion *pci_address_space; MemoryRegion *ram_memory; @@ -121,22 +124,24 @@ static int pci_slot_get_pirq(PCIDevice *pci_dev, int pci_intx) static void i440fx_update_memory_mappings(PCII440FXState *d) { int i; + PCIDevice *pd = PCI_DEVICE(d); memory_region_transaction_begin(); for (i = 0; i < 13; i++) { pam_update(&d->pam_regions[i], i, - d->dev.config[I440FX_PAM + ((i + 1) / 2)]); + pd->config[I440FX_PAM + ((i + 1) / 2)]); } - smram_update(&d->smram_region, d->dev.config[I440FX_SMRAM], d->smm_enabled); + smram_update(&d->smram_region, pd->config[I440FX_SMRAM], d->smm_enabled); memory_region_transaction_commit(); } static void i440fx_set_smm(int val, void *arg) { PCII440FXState *d = arg; + PCIDevice *pd = PCI_DEVICE(d); memory_region_transaction_begin(); - smram_set_smm(&d->smm_enabled, val, d->dev.config[I440FX_SMRAM], + smram_set_smm(&d->smm_enabled, val, pd->config[I440FX_SMRAM], &d->smram_region); memory_region_transaction_commit(); } @@ -158,9 +163,10 @@ static void i440fx_write_config(PCIDevice *dev, static int i440fx_load_old(QEMUFile* f, void *opaque, int version_id) { PCII440FXState *d = opaque; + PCIDevice *pd = PCI_DEVICE(d); int ret, i; - ret = pci_device_load(&d->dev, f); + ret = pci_device_load(pd, f); if (ret < 0) return ret; i440fx_update_memory_mappings(d); @@ -191,7 +197,7 @@ static const VMStateDescription vmstate_i440fx = { .load_state_old = i440fx_load_old, .post_load = i440fx_post_load, .fields = (VMStateField []) { - VMSTATE_PCI_DEVICE(dev, PCII440FXState), + VMSTATE_PCI_DEVICE(parent_obj, PCII440FXState), VMSTATE_UINT8(smm_enabled, PCII440FXState), VMSTATE_END_OF_LIST() } @@ -218,7 +224,7 @@ static int i440fx_initfn(PCIDevice *dev) { PCII440FXState *d = I440FX_PCI_DEVICE(dev); - d->dev.config[I440FX_SMRAM] = 0x02; + dev->config[I440FX_SMRAM] = 0x02; cpu_smm_register(&i440fx_set_smm, d); return 0; @@ -305,9 +311,10 @@ static PCIBus *i440fx_common_init(const char *device_name, *piix3_devfn = piix3->dev.devfn; ram_size = ram_size / 8 / 1024 / 1024; - if (ram_size > 255) + if (ram_size > 255) { ram_size = 255; - (*pi440fx_state)->dev.config[0x57]=ram_size; + } + d->config[0x57] = ram_size; i440fx_update_memory_mappings(f); From a3560fbf012e19c5c9b495cc0d90f2dd4491e09f Mon Sep 17 00:00:00 2001 From: Hu Tao Date: Mon, 1 Jul 2013 18:18:20 +0800 Subject: [PATCH 31/55] i440fx-pcihost: Use QOM realize for i440fx-pcihost MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Hu Tao Signed-off-by: Andreas Färber --- hw/pci-host/piix.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/hw/pci-host/piix.c b/hw/pci-host/piix.c index 541c8b7e20..39088603bb 100644 --- a/hw/pci-host/piix.c +++ b/hw/pci-host/piix.c @@ -203,21 +203,26 @@ static const VMStateDescription vmstate_i440fx = { } }; -static int i440fx_pcihost_initfn(SysBusDevice *dev) +static void i440fx_pcihost_initfn(Object *obj) +{ + PCIHostState *s = PCI_HOST_BRIDGE(obj); + + memory_region_init_io(&s->conf_mem, obj, &pci_host_conf_le_ops, s, + "pci-conf-idx", 4); + memory_region_init_io(&s->data_mem, obj, &pci_host_data_le_ops, s, + "pci-conf-data", 4); +} + +static void i440fx_pcihost_realize(DeviceState *dev, Error **errp) { PCIHostState *s = PCI_HOST_BRIDGE(dev); + SysBusDevice *sbd = SYS_BUS_DEVICE(dev); - memory_region_init_io(&s->conf_mem, OBJECT(dev), &pci_host_conf_le_ops, s, - "pci-conf-idx", 4); - sysbus_add_io(dev, 0xcf8, &s->conf_mem); - sysbus_init_ioports(&s->busdev, 0xcf8, 4); + sysbus_add_io(sbd, 0xcf8, &s->conf_mem); + sysbus_init_ioports(sbd, 0xcf8, 4); - memory_region_init_io(&s->data_mem, OBJECT(dev), &pci_host_data_le_ops, s, - "pci-conf-data", 4); - sysbus_add_io(dev, 0xcfc, &s->data_mem); - sysbus_init_ioports(&s->busdev, 0xcfc, 4); - - return 0; + sysbus_add_io(sbd, 0xcfc, &s->data_mem); + sysbus_init_ioports(sbd, 0xcfc, 4); } static int i440fx_initfn(PCIDevice *dev) @@ -647,11 +652,10 @@ static const char *i440fx_pcihost_root_bus_path(PCIHostState *host_bridge, static void i440fx_pcihost_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); PCIHostBridgeClass *hc = PCI_HOST_BRIDGE_CLASS(klass); hc->root_bus_path = i440fx_pcihost_root_bus_path; - k->init = i440fx_pcihost_initfn; + dc->realize = i440fx_pcihost_realize; dc->fw_name = "pci"; dc->no_user = 1; } @@ -660,6 +664,7 @@ static const TypeInfo i440fx_pcihost_info = { .name = "i440FX-pcihost", .parent = TYPE_PCI_HOST_BRIDGE, .instance_size = sizeof(I440FXState), + .instance_init = i440fx_pcihost_initfn, .class_init = i440fx_pcihost_class_init, }; From ce88812f576a0d5b172f99b253bcdc1dc37f86f2 Mon Sep 17 00:00:00 2001 From: Hu Tao Date: Mon, 1 Jul 2013 18:18:22 +0800 Subject: [PATCH 32/55] q35: Use type-safe cast instead of direct access of parent dev MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit And remove variables if possible. Signed-off-by: Hu Tao [AF: Converted remaining access and renamed to parent_obj] Signed-off-by: Andreas Färber --- hw/i386/pc_q35.c | 4 +++- hw/pci-host/q35.c | 43 ++++++++++++++++++++------------------- include/hw/pci-host/q35.h | 10 +++++++-- 3 files changed, 33 insertions(+), 24 deletions(-) diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c index 6f10246edf..0b1d2e32f7 100644 --- a/hw/i386/pc_q35.c +++ b/hw/i386/pc_q35.c @@ -60,6 +60,7 @@ static void pc_q35_init(QEMUMachineInitArgs *args) const char *boot_device = args->boot_device; ram_addr_t below_4g_mem_size, above_4g_mem_size; Q35PCIHost *q35_host; + PCIHostState *phb; PCIBus *host_bus; PCIDevice *lpc; BusState *idebus[MAX_SATA_PORTS]; @@ -139,7 +140,8 @@ static void pc_q35_init(QEMUMachineInitArgs *args) q35_host->mch.guest_info = guest_info; /* pci */ qdev_init_nofail(DEVICE(q35_host)); - host_bus = q35_host->host.pci.bus; + phb = PCI_HOST_BRIDGE(q35_host); + host_bus = phb->bus; /* create ISA bus */ lpc = pci_create_simple_multifunction(host_bus, PCI_DEVFN(ICH9_LPC_DEV, ICH9_LPC_FUNC), true, diff --git a/hw/pci-host/q35.c b/hw/pci-host/q35.c index 8c3ee535ff..86dd298ac7 100644 --- a/hw/pci-host/q35.c +++ b/hw/pci-host/q35.c @@ -36,28 +36,26 @@ static int q35_host_init(SysBusDevice *dev) { - PCIBus *b; - PCIHostState *pci = FROM_SYSBUS(PCIHostState, dev); - Q35PCIHost *s = Q35_HOST_DEVICE(&dev->qdev); + PCIHostState *pci = PCI_HOST_BRIDGE(dev); + Q35PCIHost *s = Q35_HOST_DEVICE(dev); memory_region_init_io(&pci->conf_mem, OBJECT(pci), &pci_host_conf_le_ops, pci, "pci-conf-idx", 4); sysbus_add_io(dev, MCH_HOST_BRIDGE_CONFIG_ADDR, &pci->conf_mem); - sysbus_init_ioports(&pci->busdev, MCH_HOST_BRIDGE_CONFIG_ADDR, 4); + sysbus_init_ioports(dev, MCH_HOST_BRIDGE_CONFIG_ADDR, 4); memory_region_init_io(&pci->data_mem, OBJECT(pci), &pci_host_data_le_ops, pci, "pci-conf-data", 4); sysbus_add_io(dev, MCH_HOST_BRIDGE_CONFIG_DATA, &pci->data_mem); - sysbus_init_ioports(&pci->busdev, MCH_HOST_BRIDGE_CONFIG_DATA, 4); + sysbus_init_ioports(dev, MCH_HOST_BRIDGE_CONFIG_DATA, 4); - if (pcie_host_init(&s->host) < 0) { + if (pcie_host_init(PCIE_HOST_BRIDGE(s)) < 0) { return -1; } - b = pci_bus_new(&s->host.pci.busdev.qdev, "pcie.0", - s->mch.pci_address_space, s->mch.address_space_io, - 0, TYPE_PCIE_BUS); - s->host.pci.bus = b; - qdev_set_parent_bus(DEVICE(&s->mch), BUS(b)); + pci->bus = pci_bus_new(DEVICE(s), "pcie.0", + s->mch.pci_address_space, s->mch.address_space_io, + 0, TYPE_PCIE_BUS); + qdev_set_parent_bus(DEVICE(&s->mch), BUS(pci->bus)); qdev_init_nofail(DEVICE(&s->mch)); return 0; @@ -71,7 +69,7 @@ static const char *q35_host_root_bus_path(PCIHostState *host_bridge, } static Property mch_props[] = { - DEFINE_PROP_UINT64("MCFG", Q35PCIHost, host.base_addr, + DEFINE_PROP_UINT64("MCFG", Q35PCIHost, parent_obj.base_addr, MCH_HOST_BRIDGE_PCIEXBAR_DEFAULT), DEFINE_PROP_END_OF_LIST(), }; @@ -113,10 +111,9 @@ static const TypeInfo q35_host_info = { /* PCIe MMCFG */ static void mch_update_pciexbar(MCHPCIState *mch) { - PCIDevice *pci_dev = &mch->d; - BusState *bus = qdev_get_parent_bus(&pci_dev->qdev); - DeviceState *qdev = bus->parent; - Q35PCIHost *s = Q35_HOST_DEVICE(qdev); + PCIDevice *pci_dev = PCI_DEVICE(mch); + BusState *bus = qdev_get_parent_bus(DEVICE(mch)); + PCIExpressHost *pehb = PCIE_HOST_BRIDGE(bus->parent); uint64_t pciexbar; int enable; @@ -148,18 +145,19 @@ static void mch_update_pciexbar(MCHPCIState *mch) break; } addr = pciexbar & addr_mask; - pcie_host_mmcfg_update(&s->host, enable, addr, length); + pcie_host_mmcfg_update(pehb, enable, addr, length); } /* PAM */ static void mch_update_pam(MCHPCIState *mch) { + PCIDevice *pd = PCI_DEVICE(mch); int i; memory_region_transaction_begin(); for (i = 0; i < 13; i++) { pam_update(&mch->pam_regions[i], i, - mch->d.config[MCH_HOST_BRIDGE_PAM0 + ((i + 1) / 2)]); + pd->config[MCH_HOST_BRIDGE_PAM0 + ((i + 1) / 2)]); } memory_region_transaction_commit(); } @@ -167,8 +165,10 @@ static void mch_update_pam(MCHPCIState *mch) /* SMRAM */ static void mch_update_smram(MCHPCIState *mch) { + PCIDevice *pd = PCI_DEVICE(mch); + memory_region_transaction_begin(); - smram_update(&mch->smram_region, mch->d.config[MCH_HOST_BRDIGE_SMRAM], + smram_update(&mch->smram_region, pd->config[MCH_HOST_BRDIGE_SMRAM], mch->smm_enabled); memory_region_transaction_commit(); } @@ -176,9 +176,10 @@ static void mch_update_smram(MCHPCIState *mch) static void mch_set_smm(int smm, void *arg) { MCHPCIState *mch = arg; + PCIDevice *pd = PCI_DEVICE(mch); memory_region_transaction_begin(); - smram_set_smm(&mch->smm_enabled, smm, mch->d.config[MCH_HOST_BRDIGE_SMRAM], + smram_set_smm(&mch->smm_enabled, smm, pd->config[MCH_HOST_BRDIGE_SMRAM], &mch->smram_region); memory_region_transaction_commit(); } @@ -228,7 +229,7 @@ static const VMStateDescription vmstate_mch = { .minimum_version_id_old = 1, .post_load = mch_post_load, .fields = (VMStateField []) { - VMSTATE_PCI_DEVICE(d, MCHPCIState), + VMSTATE_PCI_DEVICE(parent_obj, MCHPCIState), VMSTATE_UINT8(smm_enabled, MCHPCIState), VMSTATE_END_OF_LIST() } diff --git a/include/hw/pci-host/q35.h b/include/hw/pci-host/q35.h index b0838319a9..3cb631eeae 100644 --- a/include/hw/pci-host/q35.h +++ b/include/hw/pci-host/q35.h @@ -43,7 +43,10 @@ OBJECT_CHECK(MCHPCIState, (obj), TYPE_MCH_PCI_DEVICE) typedef struct MCHPCIState { - PCIDevice d; + /*< private >*/ + PCIDevice parent_obj; + /*< public >*/ + MemoryRegion *ram_memory; MemoryRegion *pci_address_space; MemoryRegion *system_memory; @@ -59,7 +62,10 @@ typedef struct MCHPCIState { } MCHPCIState; typedef struct Q35PCIHost { - PCIExpressHost host; + /*< private >*/ + PCIExpressHost parent_obj; + /*< public >*/ + MCHPCIState mch; } Q35PCIHost; From 62d92e432f586b2bb99d7824f684df4ebd412ea1 Mon Sep 17 00:00:00 2001 From: Hu Tao Date: Mon, 1 Jul 2013 18:18:23 +0800 Subject: [PATCH 33/55] q35: Use QOM realize for q35 host bridge MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit And split off MemoryRegion initialization into instance_init. Signed-off-by: Hu Tao Signed-off-by: Andreas Färber --- hw/pci-host/q35.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/hw/pci-host/q35.c b/hw/pci-host/q35.c index 86dd298ac7..6b1b3b7ab1 100644 --- a/hw/pci-host/q35.c +++ b/hw/pci-host/q35.c @@ -34,31 +34,27 @@ * Q35 host */ -static int q35_host_init(SysBusDevice *dev) +static void q35_host_realize(DeviceState *dev, Error **errp) { PCIHostState *pci = PCI_HOST_BRIDGE(dev); Q35PCIHost *s = Q35_HOST_DEVICE(dev); + SysBusDevice *sbd = SYS_BUS_DEVICE(dev); - memory_region_init_io(&pci->conf_mem, OBJECT(pci), &pci_host_conf_le_ops, pci, - "pci-conf-idx", 4); - sysbus_add_io(dev, MCH_HOST_BRIDGE_CONFIG_ADDR, &pci->conf_mem); - sysbus_init_ioports(dev, MCH_HOST_BRIDGE_CONFIG_ADDR, 4); + sysbus_add_io(sbd, MCH_HOST_BRIDGE_CONFIG_ADDR, &pci->conf_mem); + sysbus_init_ioports(sbd, MCH_HOST_BRIDGE_CONFIG_ADDR, 4); - memory_region_init_io(&pci->data_mem, OBJECT(pci), &pci_host_data_le_ops, pci, - "pci-conf-data", 4); - sysbus_add_io(dev, MCH_HOST_BRIDGE_CONFIG_DATA, &pci->data_mem); - sysbus_init_ioports(dev, MCH_HOST_BRIDGE_CONFIG_DATA, 4); + sysbus_add_io(sbd, MCH_HOST_BRIDGE_CONFIG_DATA, &pci->data_mem); + sysbus_init_ioports(sbd, MCH_HOST_BRIDGE_CONFIG_DATA, 4); if (pcie_host_init(PCIE_HOST_BRIDGE(s)) < 0) { - return -1; + error_setg(errp, "failed to initialize pcie host"); + return; } pci->bus = pci_bus_new(DEVICE(s), "pcie.0", s->mch.pci_address_space, s->mch.address_space_io, 0, TYPE_PCIE_BUS); qdev_set_parent_bus(DEVICE(&s->mch), BUS(pci->bus)); qdev_init_nofail(DEVICE(&s->mch)); - - return 0; } static const char *q35_host_root_bus_path(PCIHostState *host_bridge, @@ -77,11 +73,10 @@ static Property mch_props[] = { static void q35_host_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); PCIHostBridgeClass *hc = PCI_HOST_BRIDGE_CLASS(klass); hc->root_bus_path = q35_host_root_bus_path; - k->init = q35_host_init; + dc->realize = q35_host_realize; dc->props = mch_props; dc->fw_name = "pci"; } @@ -89,6 +84,12 @@ static void q35_host_class_init(ObjectClass *klass, void *data) static void q35_host_initfn(Object *obj) { Q35PCIHost *s = Q35_HOST_DEVICE(obj); + PCIHostState *phb = PCI_HOST_BRIDGE(obj); + + memory_region_init_io(&phb->conf_mem, obj, &pci_host_conf_le_ops, phb, + "pci-conf-idx", 4); + memory_region_init_io(&phb->data_mem, obj, &pci_host_data_le_ops, phb, + "pci-conf-data", 4); object_initialize(&s->mch, TYPE_MCH_PCI_DEVICE); object_property_add_child(OBJECT(s), "mch", OBJECT(&s->mch), NULL); From dd3be7420774f7dc8f37a96ca24d07f0b6f31b3b Mon Sep 17 00:00:00 2001 From: Hu Tao Date: Mon, 1 Jul 2013 18:18:24 +0800 Subject: [PATCH 34/55] fdc: QOM'ify some more MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Introduce type constant and avoid DO_UPCAST(), container_of(), and use DEVICE() to avoid accessing parent qdev directly. Signed-off-by: Hu Tao [AF: Renamed parent field and avoided repeated SYS_BUS_DEVICE() casts] Signed-off-by: Andreas Färber --- hw/block/fdc.c | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/hw/block/fdc.c b/hw/block/fdc.c index cdc00e59c5..e5242bf931 100644 --- a/hw/block/fdc.c +++ b/hw/block/fdc.c @@ -544,8 +544,14 @@ struct FDCtrl { uint8_t timer1; }; +#define TYPE_SYSBUS_FDC "sysbus-fdc" +#define SYSBUS_FDC(obj) OBJECT_CHECK(FDCtrlSysBus, (obj), TYPE_SYSBUS_FDC) + typedef struct FDCtrlSysBus { - SysBusDevice busdev; + /*< private >*/ + SysBusDevice parent_obj; + /*< public >*/ + struct FDCtrl state; } FDCtrlSysBus; @@ -773,7 +779,7 @@ static const VMStateDescription vmstate_fdc = { static void fdctrl_external_reset_sysbus(DeviceState *d) { - FDCtrlSysBus *sys = container_of(d, FDCtrlSysBus, busdev.qdev); + FDCtrlSysBus *sys = SYSBUS_FDC(d); FDCtrl *s = &sys->state; fdctrl_reset(s, 0); @@ -2047,10 +2053,11 @@ void fdctrl_init_sysbus(qemu_irq irq, int dma_chann, { FDCtrl *fdctrl; DeviceState *dev; + SysBusDevice *sbd; FDCtrlSysBus *sys; - dev = qdev_create(NULL, "sysbus-fdc"); - sys = DO_UPCAST(FDCtrlSysBus, busdev.qdev, dev); + dev = qdev_create(NULL, TYPE_SYSBUS_FDC); + sys = SYSBUS_FDC(dev); fdctrl = &sys->state; fdctrl->dma_chann = dma_chann; /* FIXME */ if (fds[0]) { @@ -2060,8 +2067,9 @@ void fdctrl_init_sysbus(qemu_irq irq, int dma_chann, qdev_prop_set_drive_nofail(dev, "driveB", fds[1]->bdrv); } qdev_init_nofail(dev); - sysbus_connect_irq(&sys->busdev, 0, irq); - sysbus_mmio_map(&sys->busdev, 0, mmio_base); + sbd = SYS_BUS_DEVICE(dev); + sysbus_connect_irq(sbd, 0, irq); + sysbus_mmio_map(sbd, 0, mmio_base); } void sun4m_fdctrl_init(qemu_irq irq, hwaddr io_base, @@ -2075,9 +2083,9 @@ void sun4m_fdctrl_init(qemu_irq irq, hwaddr io_base, qdev_prop_set_drive_nofail(dev, "drive", fds[0]->bdrv); } qdev_init_nofail(dev); - sys = DO_UPCAST(FDCtrlSysBus, busdev.qdev, dev); - sysbus_connect_irq(&sys->busdev, 0, irq); - sysbus_mmio_map(&sys->busdev, 0, io_base); + sys = SYSBUS_FDC(dev); + sysbus_connect_irq(SYS_BUS_DEVICE(sys), 0, irq); + sysbus_mmio_map(SYS_BUS_DEVICE(sys), 0, io_base); *fdc_tc = qdev_get_gpio_in(dev, 0); } @@ -2145,7 +2153,7 @@ static void isabus_fdc_realize(DeviceState *dev, Error **errp) static int sysbus_fdc_init1(SysBusDevice *dev) { - FDCtrlSysBus *sys = DO_UPCAST(FDCtrlSysBus, busdev, dev); + FDCtrlSysBus *sys = SYSBUS_FDC(dev); FDCtrl *fdctrl = &sys->state; int ret; @@ -2153,10 +2161,10 @@ static int sysbus_fdc_init1(SysBusDevice *dev) "fdc", 0x08); sysbus_init_mmio(dev, &fdctrl->iomem); sysbus_init_irq(dev, &fdctrl->irq); - qdev_init_gpio_in(&dev->qdev, fdctrl_handle_tc, 1); + qdev_init_gpio_in(DEVICE(dev), fdctrl_handle_tc, 1); fdctrl->dma_chann = -1; - qdev_set_legacy_instance_id(&dev->qdev, 0 /* io */, 2); /* FIXME */ + qdev_set_legacy_instance_id(DEVICE(dev), 0 /* io */, 2); /* FIXME */ ret = fdctrl_init_common(fdctrl); return ret; @@ -2164,16 +2172,17 @@ static int sysbus_fdc_init1(SysBusDevice *dev) static int sun4m_fdc_init1(SysBusDevice *dev) { - FDCtrl *fdctrl = &(FROM_SYSBUS(FDCtrlSysBus, dev)->state); + FDCtrlSysBus *sys = SYSBUS_FDC(dev); + FDCtrl *fdctrl = &sys->state; memory_region_init_io(&fdctrl->iomem, OBJECT(dev), &fdctrl_mem_strict_ops, fdctrl, "fdctrl", 0x08); sysbus_init_mmio(dev, &fdctrl->iomem); sysbus_init_irq(dev, &fdctrl->irq); - qdev_init_gpio_in(&dev->qdev, fdctrl_handle_tc, 1); + qdev_init_gpio_in(DEVICE(dev), fdctrl_handle_tc, 1); fdctrl->sun4m = 1; - qdev_set_legacy_instance_id(&dev->qdev, 0 /* io */, 2); /* FIXME */ + qdev_set_legacy_instance_id(DEVICE(dev), 0 /* io */, 2); /* FIXME */ return fdctrl_init_common(fdctrl); } @@ -2254,7 +2263,7 @@ static void sysbus_fdc_class_init(ObjectClass *klass, void *data) } static const TypeInfo sysbus_fdc_info = { - .name = "sysbus-fdc", + .name = TYPE_SYSBUS_FDC, .parent = TYPE_SYS_BUS_DEVICE, .instance_size = sizeof(FDCtrlSysBus), .class_init = sysbus_fdc_class_init, From f1b44f0e4191547888ff9750988a4f3e7ca9c60e Mon Sep 17 00:00:00 2001 From: Hu Tao Date: Mon, 1 Jul 2013 18:18:26 +0800 Subject: [PATCH 35/55] pflash-cfi01: QOM'ify some more MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Introduce type constant and replace FROM_SYSBUS(). Signed-off-by: Hu Tao [AF: Renamed parent field] Signed-off-by: Andreas Färber --- hw/block/pflash_cfi01.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c index 6898a257d9..bfcccdd88e 100644 --- a/hw/block/pflash_cfi01.c +++ b/hw/block/pflash_cfi01.c @@ -60,8 +60,14 @@ do { \ #define DPRINTF(fmt, ...) do { } while (0) #endif +#define TYPE_CFI_PFLASH01 "cfi.pflash01" +#define CFI_PFLASH01(obj) OBJECT_CHECK(pflash_t, (obj), TYPE_CFI_PFLASH01) + struct pflash_t { - SysBusDevice busdev; + /*< private >*/ + SysBusDevice parent_obj; + /*< public >*/ + BlockDriverState *bs; uint32_t nb_blocs; uint64_t sector_len; @@ -565,7 +571,7 @@ static const MemoryRegionOps pflash_cfi01_ops_le = { static int pflash_cfi01_init(SysBusDevice *dev) { - pflash_t *pfl = FROM_SYSBUS(typeof(*pfl), dev); + pflash_t *pfl = CFI_PFLASH01(dev); uint64_t total_len; int ret; @@ -720,7 +726,7 @@ static void pflash_cfi01_class_init(ObjectClass *klass, void *data) static const TypeInfo pflash_cfi01_info = { - .name = "cfi.pflash01", + .name = TYPE_CFI_PFLASH01, .parent = TYPE_SYS_BUS_DEVICE, .instance_size = sizeof(struct pflash_t), .class_init = pflash_cfi01_class_init, @@ -741,10 +747,7 @@ pflash_t *pflash_cfi01_register(hwaddr base, uint16_t id0, uint16_t id1, uint16_t id2, uint16_t id3, int be) { - DeviceState *dev = qdev_create(NULL, "cfi.pflash01"); - SysBusDevice *busdev = SYS_BUS_DEVICE(dev); - pflash_t *pfl = (pflash_t *)object_dynamic_cast(OBJECT(dev), - "cfi.pflash01"); + DeviceState *dev = qdev_create(NULL, TYPE_CFI_PFLASH01); if (bs && qdev_prop_set_drive(dev, "drive", bs)) { abort(); @@ -760,8 +763,8 @@ pflash_t *pflash_cfi01_register(hwaddr base, qdev_prop_set_string(dev, "name", name); qdev_init_nofail(dev); - sysbus_mmio_map(busdev, 0, base); - return pfl; + sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base); + return CFI_PFLASH01(dev); } MemoryRegion *pflash_cfi01_get_memory(pflash_t *fl) From 3509c396d2894b4dc40a2e33d7c2f795508d7328 Mon Sep 17 00:00:00 2001 From: Hu Tao Date: Mon, 1 Jul 2013 18:18:28 +0800 Subject: [PATCH 36/55] pflash-cfi02: QOM'ify some more MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Introduce type constant and replace FROM_SYSBUS(). Signed-off-by: Hu Tao [AF: Renamed parent field] Signed-off-by: Andreas Färber --- hw/block/pflash_cfi02.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c index d6cd3da46e..d8381ddbfc 100644 --- a/hw/block/pflash_cfi02.c +++ b/hw/block/pflash_cfi02.c @@ -55,8 +55,14 @@ do { \ #define PFLASH_LAZY_ROMD_THRESHOLD 42 +#define TYPE_CFI_PFLASH02 "cfi.pflash02" +#define CFI_PFLASH02(obj) OBJECT_CHECK(pflash_t, (obj), TYPE_CFI_PFLASH02) + struct pflash_t { - SysBusDevice busdev; + /*< private >*/ + SysBusDevice parent_obj; + /*< public >*/ + BlockDriverState *bs; uint32_t sector_len; uint32_t nb_blocs; @@ -588,7 +594,7 @@ static const MemoryRegionOps pflash_cfi02_ops_le = { static int pflash_cfi02_init(SysBusDevice *dev) { - pflash_t *pfl = FROM_SYSBUS(typeof(*pfl), dev); + pflash_t *pfl = CFI_PFLASH02(dev); uint32_t chip_len; int ret; @@ -737,7 +743,7 @@ static void pflash_cfi02_class_init(ObjectClass *klass, void *data) } static const TypeInfo pflash_cfi02_info = { - .name = "cfi.pflash02", + .name = TYPE_CFI_PFLASH02, .parent = TYPE_SYS_BUS_DEVICE, .instance_size = sizeof(struct pflash_t), .class_init = pflash_cfi02_class_init, @@ -760,10 +766,7 @@ pflash_t *pflash_cfi02_register(hwaddr base, uint16_t unlock_addr0, uint16_t unlock_addr1, int be) { - DeviceState *dev = qdev_create(NULL, "cfi.pflash02"); - SysBusDevice *busdev = SYS_BUS_DEVICE(dev); - pflash_t *pfl = (pflash_t *)object_dynamic_cast(OBJECT(dev), - "cfi.pflash02"); + DeviceState *dev = qdev_create(NULL, TYPE_CFI_PFLASH02); if (bs && qdev_prop_set_drive(dev, "drive", bs)) { abort(); @@ -782,6 +785,6 @@ pflash_t *pflash_cfi02_register(hwaddr base, qdev_prop_set_string(dev, "name", name); qdev_init_nofail(dev); - sysbus_mmio_map(busdev, 0, base); - return pfl; + sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base); + return CFI_PFLASH02(dev); } From b3b162c3cfb88a57390fef581c1be99648d6d8ab Mon Sep 17 00:00:00 2001 From: Hu Tao Date: Mon, 1 Jul 2013 18:18:30 +0800 Subject: [PATCH 37/55] ahci: QOM'ify some more MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Introduce type constant and avoid DO_UPCAST(). Signed-off-by: Hu Tao [AF: Renamed parent field] Signed-off-by: Andreas Färber --- hw/ide/ahci.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c index f295732599..d76e6eb9bf 100644 --- a/hw/ide/ahci.c +++ b/hw/ide/ahci.c @@ -1286,8 +1286,14 @@ const VMStateDescription vmstate_ahci = { }, }; +#define TYPE_SYSBUS_AHCI "sysbus-ahci" +#define SYSBUS_AHCI(obj) OBJECT_CHECK(SysbusAHCIState, (obj), TYPE_SYSBUS_AHCI) + typedef struct SysbusAHCIState { - SysBusDevice busdev; + /*< private >*/ + SysBusDevice parent_obj; + /*< public >*/ + AHCIState ahci; uint32_t num_ports; } SysbusAHCIState; @@ -1303,15 +1309,15 @@ static const VMStateDescription vmstate_sysbus_ahci = { static void sysbus_ahci_reset(DeviceState *dev) { - SysbusAHCIState *s = DO_UPCAST(SysbusAHCIState, busdev.qdev, dev); + SysbusAHCIState *s = SYSBUS_AHCI(dev); ahci_reset(&s->ahci); } static int sysbus_ahci_init(SysBusDevice *dev) { - SysbusAHCIState *s = FROM_SYSBUS(SysbusAHCIState, dev); - ahci_init(&s->ahci, &dev->qdev, NULL, s->num_ports); + SysbusAHCIState *s = SYSBUS_AHCI(dev); + ahci_init(&s->ahci, DEVICE(dev), NULL, s->num_ports); sysbus_init_mmio(dev, &s->ahci.mem); sysbus_init_irq(dev, &s->ahci.irq); @@ -1335,7 +1341,7 @@ static void sysbus_ahci_class_init(ObjectClass *klass, void *data) } static const TypeInfo sysbus_ahci_info = { - .name = "sysbus-ahci", + .name = TYPE_SYSBUS_AHCI, .parent = TYPE_SYS_BUS_DEVICE, .instance_size = sizeof(SysbusAHCIState), .class_init = sysbus_ahci_class_init, From 2ce92a1102be22e2bb82267351834713b8c31542 Mon Sep 17 00:00:00 2001 From: Hu Tao Date: Mon, 1 Jul 2013 18:18:32 +0800 Subject: [PATCH 38/55] fwcfg: QOM'ify some more MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use type constant if possible and avoid DO_UPCAST(). Signed-off-by: Hu Tao [AF: Renamed parent field] Signed-off-by: Andreas Färber --- hw/nvram/fw_cfg.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c index e455282365..8e39111360 100644 --- a/hw/nvram/fw_cfg.c +++ b/hw/nvram/fw_cfg.c @@ -35,6 +35,7 @@ #define TYPE_FW_CFG "fw_cfg" #define FW_CFG_NAME "fw_cfg" #define FW_CFG_PATH "/machine/" FW_CFG_NAME +#define FW_CFG(obj) OBJECT_CHECK(FWCfgState, (obj), TYPE_FW_CFG) typedef struct FWCfgEntry { uint32_t len; @@ -44,7 +45,10 @@ typedef struct FWCfgEntry { } FWCfgEntry; struct FWCfgState { - SysBusDevice busdev; + /*< private >*/ + SysBusDevice parent_obj; + /*< public >*/ + MemoryRegion ctl_iomem, data_iomem, comb_iomem; uint32_t ctl_iobase, data_iobase; FWCfgEntry entries[2][FW_CFG_MAX_ENTRY]; @@ -326,7 +330,7 @@ static const MemoryRegionOps fw_cfg_comb_mem_ops = { static void fw_cfg_reset(DeviceState *d) { - FWCfgState *s = DO_UPCAST(FWCfgState, busdev.qdev, d); + FWCfgState *s = FW_CFG(d); fw_cfg_select(s, 0); } @@ -489,12 +493,12 @@ FWCfgState *fw_cfg_init(uint32_t ctl_port, uint32_t data_port, SysBusDevice *d; FWCfgState *s; - dev = qdev_create(NULL, "fw_cfg"); + dev = qdev_create(NULL, TYPE_FW_CFG); qdev_prop_set_uint32(dev, "ctl_iobase", ctl_port); qdev_prop_set_uint32(dev, "data_iobase", data_port); d = SYS_BUS_DEVICE(dev); - s = DO_UPCAST(FWCfgState, busdev.qdev, dev); + s = FW_CFG(dev); assert(!object_resolve_path(FW_CFG_PATH, NULL)); @@ -524,7 +528,7 @@ FWCfgState *fw_cfg_init(uint32_t ctl_port, uint32_t data_port, static int fw_cfg_init1(SysBusDevice *dev) { - FWCfgState *s = FROM_SYSBUS(FWCfgState, dev); + FWCfgState *s = FW_CFG(dev); memory_region_init_io(&s->ctl_iomem, OBJECT(s), &fw_cfg_ctl_mem_ops, s, "fwcfg.ctl", FW_CFG_SIZE); @@ -557,8 +561,7 @@ static Property fw_cfg_properties[] = { FWCfgState *fw_cfg_find(void) { - return OBJECT_CHECK(FWCfgState, object_resolve_path(FW_CFG_PATH, NULL), - TYPE_FW_CFG); + return FW_CFG(object_resolve_path(FW_CFG_PATH, NULL)); } static void fw_cfg_class_init(ObjectClass *klass, void *data) From a71c7ec529adcd36fed5bb570a167ae2f9771750 Mon Sep 17 00:00:00 2001 From: Hu Tao Date: Mon, 1 Jul 2013 18:18:34 +0800 Subject: [PATCH 39/55] scsi/esp: QOM'ify some more MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Introduce type constant and avoid DO_UPCAST(). Signed-off-by: Hu Tao [AF: Renamed parent field] Signed-off-by: Andreas Färber --- hw/scsi/esp.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c index c6166c5cc2..1a2d72ca19 100644 --- a/hw/scsi/esp.c +++ b/hw/scsi/esp.c @@ -578,8 +578,14 @@ const VMStateDescription vmstate_esp = { } }; +#define TYPE_ESP "esp" +#define ESP(obj) OBJECT_CHECK(SysBusESPState, (obj), TYPE_ESP) + typedef struct { - SysBusDevice busdev; + /*< private >*/ + SysBusDevice parent_obj; + /*< public >*/ + MemoryRegion iomem; uint32_t it_shift; ESPState esp; @@ -623,8 +629,8 @@ void esp_init(hwaddr espaddr, int it_shift, SysBusESPState *sysbus; ESPState *esp; - dev = qdev_create(NULL, "esp"); - sysbus = DO_UPCAST(SysBusESPState, busdev.qdev, dev); + dev = qdev_create(NULL, TYPE_ESP); + sysbus = ESP(dev); esp = &sysbus->esp; esp->dma_memory_read = dma_memory_read; esp->dma_memory_write = dma_memory_write; @@ -652,8 +658,7 @@ static const struct SCSIBusInfo esp_scsi_info = { static void sysbus_esp_gpio_demux(void *opaque, int irq, int level) { - DeviceState *d = opaque; - SysBusESPState *sysbus = container_of(d, SysBusESPState, busdev.qdev); + SysBusESPState *sysbus = ESP(opaque); ESPState *s = &sysbus->esp; switch (irq) { @@ -668,7 +673,7 @@ static void sysbus_esp_gpio_demux(void *opaque, int irq, int level) static int sysbus_esp_init(SysBusDevice *dev) { - SysBusESPState *sysbus = FROM_SYSBUS(SysBusESPState, dev); + SysBusESPState *sysbus = ESP(dev); ESPState *s = &sysbus->esp; sysbus_init_irq(dev, &s->irq); @@ -687,7 +692,7 @@ static int sysbus_esp_init(SysBusDevice *dev) static void sysbus_esp_hard_reset(DeviceState *dev) { - SysBusESPState *sysbus = DO_UPCAST(SysBusESPState, busdev.qdev, dev); + SysBusESPState *sysbus = ESP(dev); esp_hard_reset(&sysbus->esp); } @@ -713,7 +718,7 @@ static void sysbus_esp_class_init(ObjectClass *klass, void *data) } static const TypeInfo sysbus_esp_info = { - .name = "esp", + .name = TYPE_ESP, .parent = TYPE_SYS_BUS_DEVICE, .instance_size = sizeof(SysBusESPState), .class_init = sysbus_esp_class_init, From 02f9a6f5da74251e1e5685ae57643d45c3fb6c30 Mon Sep 17 00:00:00 2001 From: Hu Tao Date: Mon, 1 Jul 2013 18:18:36 +0800 Subject: [PATCH 40/55] hpet: QOM'ify some more MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Introduce type constant, avoid FROM_SYSBUS(). Signed-off-by: Hu Tao [AF: Renamed parent field and renamed variable] Signed-off-by: Andreas Färber --- hw/timer/hpet.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/hw/timer/hpet.c b/hw/timer/hpet.c index 90bd5846b9..228598f345 100644 --- a/hw/timer/hpet.c +++ b/hw/timer/hpet.c @@ -42,6 +42,9 @@ #define HPET_MSI_SUPPORT 0 +#define TYPE_HPET "hpet" +#define HPET(obj) OBJECT_CHECK(HPETState, (obj), TYPE_HPET) + struct HPETState; typedef struct HPETTimer { /* timers */ uint8_t tn; /*timer number*/ @@ -59,7 +62,10 @@ typedef struct HPETTimer { /* timers */ } HPETTimer; typedef struct HPETState { - SysBusDevice busdev; + /*< private >*/ + SysBusDevice parent_obj; + /*< public >*/ + MemoryRegion iomem; uint64_t hpet_offset; qemu_irq irqs[HPET_NUM_IRQ_ROUTES]; @@ -634,7 +640,8 @@ static const MemoryRegionOps hpet_ram_ops = { static void hpet_reset(DeviceState *d) { - HPETState *s = FROM_SYSBUS(HPETState, SYS_BUS_DEVICE(d)); + HPETState *s = HPET(d); + SysBusDevice *sbd = SYS_BUS_DEVICE(d); int i; for (i = 0; i < s->num_timers; i++) { @@ -657,7 +664,7 @@ static void hpet_reset(DeviceState *d) s->hpet_offset = 0ULL; s->config = 0ULL; hpet_cfg.hpet[s->hpet_id].event_timer_block_id = (uint32_t)s->capability; - hpet_cfg.hpet[s->hpet_id].address = SYS_BUS_DEVICE(d)->mmio[0].addr; + hpet_cfg.hpet[s->hpet_id].address = sbd->mmio[0].addr; /* to document that the RTC lowers its output on reset as well */ s->rtc_irq_level = 0; @@ -665,7 +672,7 @@ static void hpet_reset(DeviceState *d) static void hpet_handle_legacy_irq(void *opaque, int n, int level) { - HPETState *s = FROM_SYSBUS(HPETState, opaque); + HPETState *s = HPET(opaque); if (n == HPET_LEGACY_PIT_INT) { if (!hpet_in_legacy_mode(s)) { @@ -681,7 +688,7 @@ static void hpet_handle_legacy_irq(void *opaque, int n, int level) static int hpet_init(SysBusDevice *dev) { - HPETState *s = FROM_SYSBUS(HPETState, dev); + HPETState *s = HPET(dev); int i; HPETTimer *timer; @@ -746,7 +753,7 @@ static void hpet_device_class_init(ObjectClass *klass, void *data) } static const TypeInfo hpet_device_info = { - .name = "hpet", + .name = TYPE_HPET, .parent = TYPE_SYS_BUS_DEVICE, .instance_size = sizeof(HPETState), .class_init = hpet_device_class_init, From 98bdc0d7ff93f2ab39c0634c744cc7f4a8ac7399 Mon Sep 17 00:00:00 2001 From: Hu Tao Date: Mon, 1 Jul 2013 18:18:38 +0800 Subject: [PATCH 41/55] kvm/clock: QOM'ify some more MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Introduce type constant and avoid FROM_SYSBUS(). Signed-off-by: Hu Tao [AF: Renamed parent field] Signed-off-by: Andreas Färber --- hw/i386/kvm/clock.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/hw/i386/kvm/clock.c b/hw/i386/kvm/clock.c index 1022d67178..62654584d6 100644 --- a/hw/i386/kvm/clock.c +++ b/hw/i386/kvm/clock.c @@ -22,8 +22,14 @@ #include #include +#define TYPE_KVM_CLOCK "kvmclock" +#define KVM_CLOCK(obj) OBJECT_CHECK(KVMClockState, (obj), TYPE_KVM_CLOCK) + typedef struct KVMClockState { + /*< private >*/ SysBusDevice busdev; + /*< public >*/ + uint64_t clock; bool clock_valid; } KVMClockState; @@ -87,7 +93,7 @@ static void kvmclock_vm_state_change(void *opaque, int running, static int kvmclock_init(SysBusDevice *dev) { - KVMClockState *s = FROM_SYSBUS(KVMClockState, dev); + KVMClockState *s = KVM_CLOCK(dev); qemu_add_vm_change_state_handler(kvmclock_vm_state_change, s); return 0; @@ -115,7 +121,7 @@ static void kvmclock_class_init(ObjectClass *klass, void *data) } static const TypeInfo kvmclock_info = { - .name = "kvmclock", + .name = TYPE_KVM_CLOCK, .parent = TYPE_SYS_BUS_DEVICE, .instance_size = sizeof(KVMClockState), .class_init = kvmclock_class_init, @@ -129,7 +135,7 @@ void kvmclock_create(void) if (kvm_enabled() && cpu->env.features[FEAT_KVM] & ((1ULL << KVM_FEATURE_CLOCKSOURCE) | (1ULL << KVM_FEATURE_CLOCKSOURCE2))) { - sysbus_create_simple("kvmclock", -1, NULL); + sysbus_create_simple(TYPE_KVM_CLOCK, -1, NULL); } } From 940194c2369e50d91d1abf6f36d43853eea5e539 Mon Sep 17 00:00:00 2001 From: Hu Tao Date: Mon, 1 Jul 2013 18:18:25 +0800 Subject: [PATCH 42/55] fdc: Use QOM realize for fdc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Hu Tao [AF: Renamed SysBusDevice variable] Signed-off-by: Andreas Färber --- hw/block/fdc.c | 67 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 43 insertions(+), 24 deletions(-) diff --git a/hw/block/fdc.c b/hw/block/fdc.c index e5242bf931..9a983fbc5a 100644 --- a/hw/block/fdc.c +++ b/hw/block/fdc.c @@ -2151,39 +2151,58 @@ static void isabus_fdc_realize(DeviceState *dev, Error **errp) add_boot_device_path(isa->bootindexB, dev, "/floppy@1"); } -static int sysbus_fdc_init1(SysBusDevice *dev) +static void sysbus_fdc_initfn(Object *obj) { - FDCtrlSysBus *sys = SYSBUS_FDC(dev); + FDCtrlSysBus *sys = SYSBUS_FDC(obj); FDCtrl *fdctrl = &sys->state; - int ret; - memory_region_init_io(&fdctrl->iomem, OBJECT(sys), &fdctrl_mem_ops, fdctrl, + memory_region_init_io(&fdctrl->iomem, obj, &fdctrl_mem_ops, fdctrl, "fdc", 0x08); - sysbus_init_mmio(dev, &fdctrl->iomem); - sysbus_init_irq(dev, &fdctrl->irq); - qdev_init_gpio_in(DEVICE(dev), fdctrl_handle_tc, 1); - fdctrl->dma_chann = -1; - - qdev_set_legacy_instance_id(DEVICE(dev), 0 /* io */, 2); /* FIXME */ - ret = fdctrl_init_common(fdctrl); - - return ret; } -static int sun4m_fdc_init1(SysBusDevice *dev) +static void sysbus_fdc_realize(DeviceState *dev, Error **errp) { FDCtrlSysBus *sys = SYSBUS_FDC(dev); FDCtrl *fdctrl = &sys->state; + SysBusDevice *b = SYS_BUS_DEVICE(dev); - memory_region_init_io(&fdctrl->iomem, OBJECT(dev), &fdctrl_mem_strict_ops, + sysbus_init_mmio(b, &fdctrl->iomem); + sysbus_init_irq(b, &fdctrl->irq); + qdev_init_gpio_in(dev, fdctrl_handle_tc, 1); + fdctrl->dma_chann = -1; + + qdev_set_legacy_instance_id(dev, 0 /* io */, 2); /* FIXME */ + if (fdctrl_init_common(fdctrl) < 0) { + error_setg(errp, "Floppy init failed."); + return; + } +} + +static void sun4m_fdc_initfn(Object *obj) +{ + FDCtrlSysBus *sys = SYSBUS_FDC(obj); + FDCtrl *fdctrl = &sys->state; + + memory_region_init_io(&fdctrl->iomem, obj, &fdctrl_mem_strict_ops, fdctrl, "fdctrl", 0x08); - sysbus_init_mmio(dev, &fdctrl->iomem); - sysbus_init_irq(dev, &fdctrl->irq); - qdev_init_gpio_in(DEVICE(dev), fdctrl_handle_tc, 1); +} + +static void sun4m_fdc_realize(DeviceState *dev, Error **errp) +{ + FDCtrlSysBus *sys = SYSBUS_FDC(dev); + FDCtrl *fdctrl = &sys->state; + SysBusDevice *sbd = SYS_BUS_DEVICE(dev); + + sysbus_init_mmio(sbd, &fdctrl->iomem); + sysbus_init_irq(sbd, &fdctrl->irq); + qdev_init_gpio_in(dev, fdctrl_handle_tc, 1); fdctrl->sun4m = 1; - qdev_set_legacy_instance_id(DEVICE(dev), 0 /* io */, 2); /* FIXME */ - return fdctrl_init_common(fdctrl); + qdev_set_legacy_instance_id(dev, 0 /* io */, 2); /* FIXME */ + if (fdctrl_init_common(fdctrl) < 0) { + error_setg(errp, "Floppy init failed."); + return; + } } FDriveType isa_fdc_get_drive_type(ISADevice *fdc, int i) @@ -2254,9 +2273,8 @@ static Property sysbus_fdc_properties[] = { static void sysbus_fdc_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); - k->init = sysbus_fdc_init1; + dc->realize = sysbus_fdc_realize; dc->reset = fdctrl_external_reset_sysbus; dc->vmsd = &vmstate_sysbus_fdc; dc->props = sysbus_fdc_properties; @@ -2266,6 +2284,7 @@ static const TypeInfo sysbus_fdc_info = { .name = TYPE_SYSBUS_FDC, .parent = TYPE_SYS_BUS_DEVICE, .instance_size = sizeof(FDCtrlSysBus), + .instance_init = sysbus_fdc_initfn, .class_init = sysbus_fdc_class_init, }; @@ -2277,9 +2296,8 @@ static Property sun4m_fdc_properties[] = { static void sun4m_fdc_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); - k->init = sun4m_fdc_init1; + dc->realize = sun4m_fdc_realize; dc->reset = fdctrl_external_reset_sysbus; dc->vmsd = &vmstate_sysbus_fdc; dc->props = sun4m_fdc_properties; @@ -2289,6 +2307,7 @@ static const TypeInfo sun4m_fdc_info = { .name = "SUNW,fdtwo", .parent = TYPE_SYS_BUS_DEVICE, .instance_size = sizeof(FDCtrlSysBus), + .instance_init = sun4m_fdc_initfn, .class_init = sun4m_fdc_class_init, }; From a3ef7a61e3706ba81e31a8092b966d6aeae5333e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Wed, 17 Jul 2013 14:14:41 +0200 Subject: [PATCH 43/55] fdc: Improve error propagation for QOM realize MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rename fdctrl_init_common() to fdctrl_realize_common() and let fdctrl_connect_drives() propagate an Error through it. Reviewed-by: Hu Tao Reviewed-by: Stefan Hajnoczi Signed-off-by: Andreas Färber --- hw/block/fdc.c | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/hw/block/fdc.c b/hw/block/fdc.c index 9a983fbc5a..d32f6ba411 100644 --- a/hw/block/fdc.c +++ b/hw/block/fdc.c @@ -1997,7 +1997,7 @@ static const BlockDevOps fdctrl_block_ops = { }; /* Init functions */ -static int fdctrl_connect_drives(FDCtrl *fdctrl) +static void fdctrl_connect_drives(FDCtrl *fdctrl, Error **errp) { unsigned int i; FDrive *drive; @@ -2008,12 +2008,12 @@ static int fdctrl_connect_drives(FDCtrl *fdctrl) if (drive->bs) { if (bdrv_get_on_error(drive->bs, 0) != BLOCKDEV_ON_ERROR_ENOSPC) { - error_report("fdc doesn't support drive option werror"); - return -1; + error_setg(errp, "fdc doesn't support drive option werror"); + return; } if (bdrv_get_on_error(drive->bs, 1) != BLOCKDEV_ON_ERROR_REPORT) { - error_report("fdc doesn't support drive option rerror"); - return -1; + error_setg(errp, "fdc doesn't support drive option rerror"); + return; } } @@ -2023,7 +2023,6 @@ static int fdctrl_connect_drives(FDCtrl *fdctrl) bdrv_set_dev_ops(drive->bs, &fdctrl_block_ops, drive); } } - return 0; } ISADevice *fdctrl_init_isa(ISABus *bus, DriveInfo **fds) @@ -2089,7 +2088,7 @@ void sun4m_fdctrl_init(qemu_irq irq, hwaddr io_base, *fdc_tc = qdev_get_gpio_in(dev, 0); } -static int fdctrl_init_common(FDCtrl *fdctrl) +static void fdctrl_realize_common(FDCtrl *fdctrl, Error **errp) { int i, j; static int command_tables_inited = 0; @@ -2110,15 +2109,16 @@ static int fdctrl_init_common(FDCtrl *fdctrl) fdctrl->fifo = qemu_memalign(512, FD_SECTOR_LEN); fdctrl->fifo_size = 512; fdctrl->result_timer = qemu_new_timer_ns(vm_clock, - fdctrl_result_timer, fdctrl); + fdctrl_result_timer, fdctrl); fdctrl->version = 0x90; /* Intel 82078 controller */ fdctrl->config = FD_CONFIG_EIS | FD_CONFIG_EFIFO; /* Implicit seek, polling & FIFO enabled */ fdctrl->num_floppies = MAX_FD; - if (fdctrl->dma_chann != -1) + if (fdctrl->dma_chann != -1) { DMA_register_channel(fdctrl->dma_chann, &fdctrl_transfer_handler, fdctrl); - return fdctrl_connect_drives(fdctrl); + } + fdctrl_connect_drives(fdctrl, errp); } static const MemoryRegionPortio fdc_portio_list[] = { @@ -2132,7 +2132,7 @@ static void isabus_fdc_realize(DeviceState *dev, Error **errp) ISADevice *isadev = ISA_DEVICE(dev); FDCtrlISABus *isa = ISA_FDC(dev); FDCtrl *fdctrl = &isa->state; - int ret; + Error *err = NULL; isa_register_portio_list(isadev, isa->iobase, fdc_portio_list, fdctrl, "fdc"); @@ -2141,9 +2141,9 @@ static void isabus_fdc_realize(DeviceState *dev, Error **errp) fdctrl->dma_chann = isa->dma; qdev_set_legacy_instance_id(dev, isa->iobase, 2); - ret = fdctrl_init_common(fdctrl); - if (ret < 0) { - error_setg(errp, "Floppy init failed."); + fdctrl_realize_common(fdctrl, &err); + if (err != NULL) { + error_propagate(errp, err); return; } @@ -2165,6 +2165,7 @@ static void sysbus_fdc_realize(DeviceState *dev, Error **errp) FDCtrlSysBus *sys = SYSBUS_FDC(dev); FDCtrl *fdctrl = &sys->state; SysBusDevice *b = SYS_BUS_DEVICE(dev); + Error *err = NULL; sysbus_init_mmio(b, &fdctrl->iomem); sysbus_init_irq(b, &fdctrl->irq); @@ -2172,8 +2173,9 @@ static void sysbus_fdc_realize(DeviceState *dev, Error **errp) fdctrl->dma_chann = -1; qdev_set_legacy_instance_id(dev, 0 /* io */, 2); /* FIXME */ - if (fdctrl_init_common(fdctrl) < 0) { - error_setg(errp, "Floppy init failed."); + fdctrl_realize_common(fdctrl, &err); + if (err != NULL) { + error_propagate(errp, err); return; } } @@ -2192,6 +2194,7 @@ static void sun4m_fdc_realize(DeviceState *dev, Error **errp) FDCtrlSysBus *sys = SYSBUS_FDC(dev); FDCtrl *fdctrl = &sys->state; SysBusDevice *sbd = SYS_BUS_DEVICE(dev); + Error *err = NULL; sysbus_init_mmio(sbd, &fdctrl->iomem); sysbus_init_irq(sbd, &fdctrl->irq); @@ -2199,8 +2202,9 @@ static void sun4m_fdc_realize(DeviceState *dev, Error **errp) fdctrl->sun4m = 1; qdev_set_legacy_instance_id(dev, 0 /* io */, 2); /* FIXME */ - if (fdctrl_init_common(fdctrl) < 0) { - error_setg(errp, "Floppy init failed."); + fdctrl_realize_common(fdctrl, &err); + if (err != NULL) { + error_propagate(errp, err); return; } } From e40b5f3e0efe49ec138ea5e3710f6dd6527e5f49 Mon Sep 17 00:00:00 2001 From: Hu Tao Date: Mon, 1 Jul 2013 18:18:27 +0800 Subject: [PATCH 44/55] pflash_cfi01: Use QOM realize for pflash_cfi01 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Hu Tao [AF: Renamed argument] Signed-off-by: Andreas Färber --- hw/block/pflash_cfi01.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c index bfcccdd88e..2bcd7318bc 100644 --- a/hw/block/pflash_cfi01.c +++ b/hw/block/pflash_cfi01.c @@ -569,7 +569,7 @@ static const MemoryRegionOps pflash_cfi01_ops_le = { .endianness = DEVICE_NATIVE_ENDIAN, }; -static int pflash_cfi01_init(SysBusDevice *dev) +static void pflash_cfi01_realize(DeviceState *dev, Error **errp) { pflash_t *pfl = CFI_PFLASH01(dev); uint64_t total_len; @@ -590,7 +590,7 @@ static int pflash_cfi01_init(SysBusDevice *dev) pfl->name, total_len); vmstate_register_ram(&pfl->mem, DEVICE(pfl)); pfl->storage = memory_region_get_ram_ptr(&pfl->mem); - sysbus_init_mmio(dev, &pfl->mem); + sysbus_init_mmio(SYS_BUS_DEVICE(dev), &pfl->mem); if (pfl->bs) { /* read the initial flash content */ @@ -599,7 +599,8 @@ static int pflash_cfi01_init(SysBusDevice *dev) if (ret < 0) { vmstate_unregister_ram(&pfl->mem, DEVICE(pfl)); memory_region_destroy(&pfl->mem); - return 1; + error_setg(errp, "failed to read the initial flash content"); + return; } } @@ -696,8 +697,6 @@ static int pflash_cfi01_init(SysBusDevice *dev) pfl->cfi_table[0x3c] = 0x00; pfl->cfi_table[0x3f] = 0x01; /* Number of protection fields */ - - return 0; } static Property pflash_cfi01_properties[] = { @@ -717,9 +716,8 @@ static Property pflash_cfi01_properties[] = { static void pflash_cfi01_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); - k->init = pflash_cfi01_init; + dc->realize = pflash_cfi01_realize; dc->props = pflash_cfi01_properties; dc->vmsd = &vmstate_pflash; } From da3bd64234dc6c77091a0fb8a2612668dbaffd37 Mon Sep 17 00:00:00 2001 From: Hu Tao Date: Mon, 1 Jul 2013 18:18:29 +0800 Subject: [PATCH 45/55] pflash_cfi02: Use QOM realize for pflash_cfi02 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Hu Tao Signed-off-by: Andreas Färber --- hw/block/pflash_cfi02.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c index d8381ddbfc..9fc02e3d64 100644 --- a/hw/block/pflash_cfi02.c +++ b/hw/block/pflash_cfi02.c @@ -592,7 +592,7 @@ static const MemoryRegionOps pflash_cfi02_ops_le = { .endianness = DEVICE_NATIVE_ENDIAN, }; -static int pflash_cfi02_init(SysBusDevice *dev) +static void pflash_cfi02_realize(DeviceState *dev, Error **errp) { pflash_t *pfl = CFI_PFLASH02(dev); uint32_t chip_len; @@ -616,14 +616,16 @@ static int pflash_cfi02_init(SysBusDevice *dev) /* read the initial flash content */ ret = bdrv_read(pfl->bs, 0, pfl->storage, chip_len >> 9); if (ret < 0) { - g_free(pfl); - return 1; + vmstate_unregister_ram(&pfl->orig_mem, DEVICE(pfl)); + memory_region_destroy(&pfl->orig_mem); + error_setg(errp, "failed to read the initial flash content"); + return; } } pflash_setup_mappings(pfl); pfl->rom_mode = 1; - sysbus_init_mmio(dev, &pfl->mem); + sysbus_init_mmio(SYS_BUS_DEVICE(dev), &pfl->mem); if (pfl->bs) { pfl->ro = bdrv_is_read_only(pfl->bs); @@ -712,8 +714,6 @@ static int pflash_cfi02_init(SysBusDevice *dev) pfl->cfi_table[0x3b] = 0x00; pfl->cfi_table[0x3c] = 0x00; - - return 0; } static Property pflash_cfi02_properties[] = { @@ -736,9 +736,8 @@ static Property pflash_cfi02_properties[] = { static void pflash_cfi02_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); - k->init = pflash_cfi02_init; + dc->realize = pflash_cfi02_realize; dc->props = pflash_cfi02_properties; } From 7acb423fcfd8fbf75f672de70ab945a24cc31ef5 Mon Sep 17 00:00:00 2001 From: Hu Tao Date: Mon, 1 Jul 2013 18:18:31 +0800 Subject: [PATCH 46/55] ahci: Use QOM realize for ahci MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Hu Tao [AF: Avoided repeated SYS_BUS_DEVICE() casts] Signed-off-by: Andreas Färber --- hw/ide/ahci.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c index d76e6eb9bf..419adde0ea 100644 --- a/hw/ide/ahci.c +++ b/hw/ide/ahci.c @@ -1314,14 +1314,15 @@ static void sysbus_ahci_reset(DeviceState *dev) ahci_reset(&s->ahci); } -static int sysbus_ahci_init(SysBusDevice *dev) +static void sysbus_ahci_realize(DeviceState *dev, Error **errp) { + SysBusDevice *sbd = SYS_BUS_DEVICE(dev); SysbusAHCIState *s = SYSBUS_AHCI(dev); - ahci_init(&s->ahci, DEVICE(dev), NULL, s->num_ports); - sysbus_init_mmio(dev, &s->ahci.mem); - sysbus_init_irq(dev, &s->ahci.irq); - return 0; + ahci_init(&s->ahci, dev, NULL, s->num_ports); + + sysbus_init_mmio(sbd, &s->ahci.mem); + sysbus_init_irq(sbd, &s->ahci.irq); } static Property sysbus_ahci_properties[] = { @@ -1331,10 +1332,9 @@ static Property sysbus_ahci_properties[] = { static void sysbus_ahci_class_init(ObjectClass *klass, void *data) { - SysBusDeviceClass *sbc = SYS_BUS_DEVICE_CLASS(klass); DeviceClass *dc = DEVICE_CLASS(klass); - sbc->init = sysbus_ahci_init; + dc->realize = sysbus_ahci_realize; dc->vmsd = &vmstate_sysbus_ahci; dc->props = sysbus_ahci_properties; dc->reset = sysbus_ahci_reset; From 563839557c05f6f946bedebc381406b146af61f6 Mon Sep 17 00:00:00 2001 From: Hu Tao Date: Mon, 1 Jul 2013 18:18:33 +0800 Subject: [PATCH 47/55] fw_cfg: Use QOM realize for fw_cfg MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Hu Tao [AF: Moved sysbus_init_mmio() to instance_init, renamed variable] Signed-off-by: Andreas Färber --- hw/nvram/fw_cfg.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c index 8e39111360..0a35015b9e 100644 --- a/hw/nvram/fw_cfg.c +++ b/hw/nvram/fw_cfg.c @@ -526,31 +526,38 @@ FWCfgState *fw_cfg_init(uint32_t ctl_port, uint32_t data_port, return s; } -static int fw_cfg_init1(SysBusDevice *dev) +static void fw_cfg_initfn(Object *obj) { - FWCfgState *s = FW_CFG(dev); + SysBusDevice *sbd = SYS_BUS_DEVICE(obj); + FWCfgState *s = FW_CFG(obj); memory_region_init_io(&s->ctl_iomem, OBJECT(s), &fw_cfg_ctl_mem_ops, s, "fwcfg.ctl", FW_CFG_SIZE); - sysbus_init_mmio(dev, &s->ctl_iomem); + sysbus_init_mmio(sbd, &s->ctl_iomem); memory_region_init_io(&s->data_iomem, OBJECT(s), &fw_cfg_data_mem_ops, s, "fwcfg.data", FW_CFG_DATA_SIZE); - sysbus_init_mmio(dev, &s->data_iomem); + sysbus_init_mmio(sbd, &s->data_iomem); /* In case ctl and data overlap: */ memory_region_init_io(&s->comb_iomem, OBJECT(s), &fw_cfg_comb_mem_ops, s, "fwcfg", FW_CFG_SIZE); +} + +static void fw_cfg_realize(DeviceState *dev, Error **errp) +{ + FWCfgState *s = FW_CFG(dev); + SysBusDevice *sbd = SYS_BUS_DEVICE(dev); + if (s->ctl_iobase + 1 == s->data_iobase) { - sysbus_add_io(dev, s->ctl_iobase, &s->comb_iomem); + sysbus_add_io(sbd, s->ctl_iobase, &s->comb_iomem); } else { if (s->ctl_iobase) { - sysbus_add_io(dev, s->ctl_iobase, &s->ctl_iomem); + sysbus_add_io(sbd, s->ctl_iobase, &s->ctl_iomem); } if (s->data_iobase) { - sysbus_add_io(dev, s->data_iobase, &s->data_iomem); + sysbus_add_io(sbd, s->data_iobase, &s->data_iomem); } } - return 0; } static Property fw_cfg_properties[] = { @@ -567,9 +574,8 @@ FWCfgState *fw_cfg_find(void) static void fw_cfg_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); - k->init = fw_cfg_init1; + dc->realize = fw_cfg_realize; dc->no_user = 1; dc->reset = fw_cfg_reset; dc->vmsd = &vmstate_fw_cfg; @@ -580,6 +586,7 @@ static const TypeInfo fw_cfg_info = { .name = TYPE_FW_CFG, .parent = TYPE_SYS_BUS_DEVICE, .instance_size = sizeof(FWCfgState), + .instance_init = fw_cfg_initfn, .class_init = fw_cfg_class_init, }; From b09318cac65df015b9b0990791f02b894cc57d33 Mon Sep 17 00:00:00 2001 From: Hu Tao Date: Mon, 1 Jul 2013 18:18:35 +0800 Subject: [PATCH 48/55] scsi/esp: Use QOM realize for scsi esp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Hu Tao [AF: Drop sysbus_esp_init()] Signed-off-by: Andreas Färber --- hw/scsi/esp.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c index 1a2d72ca19..c24b6326ce 100644 --- a/hw/scsi/esp.c +++ b/hw/scsi/esp.c @@ -671,23 +671,27 @@ static void sysbus_esp_gpio_demux(void *opaque, int irq, int level) } } -static int sysbus_esp_init(SysBusDevice *dev) +static void sysbus_esp_realize(DeviceState *dev, Error **errp) { + SysBusDevice *sbd = SYS_BUS_DEVICE(dev); SysBusESPState *sysbus = ESP(dev); ESPState *s = &sysbus->esp; - sysbus_init_irq(dev, &s->irq); + sysbus_init_irq(sbd, &s->irq); assert(sysbus->it_shift != -1); s->chip_id = TCHI_FAS100A; memory_region_init_io(&sysbus->iomem, OBJECT(sysbus), &sysbus_esp_mem_ops, sysbus, "esp", ESP_REGS << sysbus->it_shift); - sysbus_init_mmio(dev, &sysbus->iomem); + sysbus_init_mmio(sbd, &sysbus->iomem); - qdev_init_gpio_in(&dev->qdev, sysbus_esp_gpio_demux, 2); + qdev_init_gpio_in(dev, sysbus_esp_gpio_demux, 2); - scsi_bus_new(&s->bus, &dev->qdev, &esp_scsi_info, NULL); - return scsi_bus_legacy_handle_cmdline(&s->bus); + scsi_bus_new(&s->bus, dev, &esp_scsi_info, NULL); + if (scsi_bus_legacy_handle_cmdline(&s->bus) < 0) { + error_setg(errp, "Handling legacy SCSI command line failed"); + return; + } } static void sysbus_esp_hard_reset(DeviceState *dev) @@ -710,9 +714,8 @@ static const VMStateDescription vmstate_sysbus_esp_scsi = { static void sysbus_esp_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); - k->init = sysbus_esp_init; + dc->realize = sysbus_esp_realize; dc->reset = sysbus_esp_hard_reset; dc->vmsd = &vmstate_sysbus_esp_scsi; } From 22d6aa03fd87ba5f219d26bc1810646d0f95842a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Sun, 21 Jul 2013 12:20:15 +0200 Subject: [PATCH 49/55] megasas: Legacy command line handling fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Only apply legacy command line handling when the device has not been hot-plugged. Propagate failure of legacy command line handling. Cc: qemu-stable@nongnu.org Acked-by: Paolo Bonzini Signed-off-by: Andreas Färber --- hw/scsi/megasas.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hw/scsi/megasas.c b/hw/scsi/megasas.c index 55d5b73606..2ae434683e 100644 --- a/hw/scsi/megasas.c +++ b/hw/scsi/megasas.c @@ -2098,6 +2098,7 @@ static const struct SCSIBusInfo megasas_scsi_info = { static int megasas_scsi_init(PCIDevice *dev) { + DeviceState *d = DEVICE(dev); MegasasState *s = MEGASAS(dev); uint8_t *pci_conf; int i, bar_type; @@ -2170,7 +2171,9 @@ static int megasas_scsi_init(PCIDevice *dev) } scsi_bus_new(&s->bus, DEVICE(dev), &megasas_scsi_info, NULL); - scsi_bus_legacy_handle_cmdline(&s->bus); + if (!d->hotplugged) { + return scsi_bus_legacy_handle_cmdline(&s->bus); + } return 0; } From caad4eb345dc5119d326b8af08452cc0f90f8548 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Sun, 21 Jul 2013 12:16:34 +0200 Subject: [PATCH 50/55] scsi: Improve error propagation for scsi_bus_legacy_handle_cmdline() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Let scsi_bus_legacy_add_drive() and scsi_bus_legacy_handle_cmdline() return an Error**. Prepare qdev initfns for QOM realize error model. Signed-off-by: Andreas Färber --- hw/pci/pci-hotplug-old.c | 2 +- hw/scsi/esp-pci.c | 7 ++++++- hw/scsi/esp.c | 6 ++++-- hw/scsi/lsi53c895a.c | 7 ++++++- hw/scsi/megasas.c | 7 ++++++- hw/scsi/scsi-bus.c | 22 +++++++++++++++------- hw/scsi/spapr_vscsi.c | 7 ++++++- hw/scsi/virtio-scsi.c | 7 ++++++- hw/usb/dev-storage.c | 4 +++- include/hw/scsi/scsi.h | 4 ++-- 10 files changed, 55 insertions(+), 18 deletions(-) diff --git a/hw/pci/pci-hotplug-old.c b/hw/pci/pci-hotplug-old.c index 8077289756..619fe473e8 100644 --- a/hw/pci/pci-hotplug-old.c +++ b/hw/pci/pci-hotplug-old.c @@ -127,7 +127,7 @@ static int scsi_hot_add(Monitor *mon, DeviceState *adapter, dinfo->unit = qemu_opt_get_number(dinfo->opts, "unit", -1); dinfo->bus = scsibus->busnr; scsidev = scsi_bus_legacy_add_drive(scsibus, dinfo->bdrv, dinfo->unit, - false, -1, NULL); + false, -1, NULL, NULL); if (!scsidev) { return -1; } diff --git a/hw/scsi/esp-pci.c b/hw/scsi/esp-pci.c index 6cdfd5338e..2ac21d4487 100644 --- a/hw/scsi/esp-pci.c +++ b/hw/scsi/esp-pci.c @@ -346,6 +346,7 @@ static int esp_pci_scsi_init(PCIDevice *dev) DeviceState *d = DEVICE(dev); ESPState *s = &pci->esp; uint8_t *pci_conf; + Error *err = NULL; pci_conf = dev->config; @@ -364,7 +365,11 @@ static int esp_pci_scsi_init(PCIDevice *dev) scsi_bus_new(&s->bus, d, &esp_pci_scsi_info, NULL); if (!d->hotplugged) { - return scsi_bus_legacy_handle_cmdline(&s->bus); + scsi_bus_legacy_handle_cmdline(&s->bus, &err); + if (err != NULL) { + error_free(err); + return -1; + } } return 0; } diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c index c24b6326ce..94639b8391 100644 --- a/hw/scsi/esp.c +++ b/hw/scsi/esp.c @@ -676,6 +676,7 @@ static void sysbus_esp_realize(DeviceState *dev, Error **errp) SysBusDevice *sbd = SYS_BUS_DEVICE(dev); SysBusESPState *sysbus = ESP(dev); ESPState *s = &sysbus->esp; + Error *err = NULL; sysbus_init_irq(sbd, &s->irq); assert(sysbus->it_shift != -1); @@ -688,8 +689,9 @@ static void sysbus_esp_realize(DeviceState *dev, Error **errp) qdev_init_gpio_in(dev, sysbus_esp_gpio_demux, 2); scsi_bus_new(&s->bus, dev, &esp_scsi_info, NULL); - if (scsi_bus_legacy_handle_cmdline(&s->bus) < 0) { - error_setg(errp, "Handling legacy SCSI command line failed"); + scsi_bus_legacy_handle_cmdline(&s->bus, &err); + if (err != NULL) { + error_propagate(errp, err); return; } } diff --git a/hw/scsi/lsi53c895a.c b/hw/scsi/lsi53c895a.c index e11224fe88..776e31abbe 100644 --- a/hw/scsi/lsi53c895a.c +++ b/hw/scsi/lsi53c895a.c @@ -2096,6 +2096,7 @@ static int lsi_scsi_init(PCIDevice *dev) LSIState *s = LSI53C895A(dev); DeviceState *d = DEVICE(dev); uint8_t *pci_conf; + Error *err = NULL; pci_conf = dev->config; @@ -2118,7 +2119,11 @@ static int lsi_scsi_init(PCIDevice *dev) scsi_bus_new(&s->bus, d, &lsi_scsi_info, NULL); if (!d->hotplugged) { - return scsi_bus_legacy_handle_cmdline(&s->bus); + scsi_bus_legacy_handle_cmdline(&s->bus, &err); + if (err != NULL) { + error_free(err); + return -1; + } } return 0; } diff --git a/hw/scsi/megasas.c b/hw/scsi/megasas.c index 2ae434683e..eb52164f6d 100644 --- a/hw/scsi/megasas.c +++ b/hw/scsi/megasas.c @@ -2102,6 +2102,7 @@ static int megasas_scsi_init(PCIDevice *dev) MegasasState *s = MEGASAS(dev); uint8_t *pci_conf; int i, bar_type; + Error *err = NULL; pci_conf = dev->config; @@ -2172,7 +2173,11 @@ static int megasas_scsi_init(PCIDevice *dev) scsi_bus_new(&s->bus, DEVICE(dev), &megasas_scsi_info, NULL); if (!d->hotplugged) { - return scsi_bus_legacy_handle_cmdline(&s->bus); + scsi_bus_legacy_handle_cmdline(&s->bus, &err); + if (err != NULL) { + error_free(err); + return -1; + } } return 0; } diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c index a92b7c1de4..b5a863aa5c 100644 --- a/hw/scsi/scsi-bus.c +++ b/hw/scsi/scsi-bus.c @@ -209,10 +209,11 @@ static int scsi_qdev_exit(DeviceState *qdev) /* handle legacy '-drive if=scsi,...' cmd line args */ SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv, int unit, bool removable, int bootindex, - const char *serial) + const char *serial, Error **errp) { const char *driver; DeviceState *dev; + Error *err = NULL; driver = bdrv_is_sg(bdrv) ? "scsi-generic" : "scsi-disk"; dev = qdev_create(&bus->qbus, driver); @@ -227,19 +228,25 @@ SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv, qdev_prop_set_string(dev, "serial", serial); } if (qdev_prop_set_drive(dev, "drive", bdrv) < 0) { + error_setg(errp, "Setting drive property failed"); qdev_free(dev); return NULL; } - if (qdev_init(dev) < 0) + object_property_set_bool(OBJECT(dev), true, "realized", &err); + if (err != NULL) { + error_propagate(errp, err); + qdev_free(dev); return NULL; + } return SCSI_DEVICE(dev); } -int scsi_bus_legacy_handle_cmdline(SCSIBus *bus) +void scsi_bus_legacy_handle_cmdline(SCSIBus *bus, Error **errp) { Location loc; DriveInfo *dinfo; - int res = 0, unit; + int unit; + Error *err = NULL; loc_push_none(&loc); for (unit = 0; unit <= bus->info->max_target; unit++) { @@ -248,13 +255,14 @@ int scsi_bus_legacy_handle_cmdline(SCSIBus *bus) continue; } qemu_opts_loc_restore(dinfo->opts); - if (!scsi_bus_legacy_add_drive(bus, dinfo->bdrv, unit, false, -1, NULL)) { - res = -1; + scsi_bus_legacy_add_drive(bus, dinfo->bdrv, unit, false, -1, NULL, + &err); + if (err != NULL) { + error_propagate(errp, err); break; } } loc_pop(&loc); - return res; } static int32_t scsi_invalid_field(SCSIRequest *req, uint8_t *buf) diff --git a/hw/scsi/spapr_vscsi.c b/hw/scsi/spapr_vscsi.c index e8978bfef1..55b44b9910 100644 --- a/hw/scsi/spapr_vscsi.c +++ b/hw/scsi/spapr_vscsi.c @@ -912,12 +912,17 @@ static void spapr_vscsi_reset(VIOsPAPRDevice *dev) static int spapr_vscsi_init(VIOsPAPRDevice *dev) { VSCSIState *s = VIO_SPAPR_VSCSI_DEVICE(dev); + Error *err = NULL; dev->crq.SendFunc = vscsi_do_crq; scsi_bus_new(&s->bus, &dev->qdev, &vscsi_scsi_info, NULL); if (!dev->qdev.hotplugged) { - scsi_bus_legacy_handle_cmdline(&s->bus); + scsi_bus_legacy_handle_cmdline(&s->bus, &err); + if (err != NULL) { + error_free(err); + return -1; + } } return 0; diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c index 712f0ade22..42cb73bb4e 100644 --- a/hw/scsi/virtio-scsi.c +++ b/hw/scsi/virtio-scsi.c @@ -619,6 +619,7 @@ static int virtio_scsi_device_init(VirtIODevice *vdev) VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(vdev); VirtIOSCSI *s = VIRTIO_SCSI(vdev); static int virtio_scsi_id; + Error *err = NULL; int ret; ret = virtio_scsi_common_init(vs); @@ -629,7 +630,11 @@ static int virtio_scsi_device_init(VirtIODevice *vdev) scsi_bus_new(&s->bus, qdev, &virtio_scsi_scsi_info, vdev->bus_name); if (!qdev->hotplugged) { - scsi_bus_legacy_handle_cmdline(&s->bus); + scsi_bus_legacy_handle_cmdline(&s->bus, &err); + if (err != NULL) { + error_free(err); + return -1; + } } register_savevm(qdev, "virtio-scsi", virtio_scsi_id++, 1, diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c index fe914ab005..1954811ec4 100644 --- a/hw/usb/dev-storage.c +++ b/hw/usb/dev-storage.c @@ -595,6 +595,7 @@ static int usb_msd_initfn_storage(USBDevice *dev) MSDState *s = DO_UPCAST(MSDState, dev, dev); BlockDriverState *bs = s->conf.bs; SCSIDevice *scsi_dev; + Error *err = NULL; if (!bs) { error_report("drive property not set"); @@ -619,7 +620,8 @@ static int usb_msd_initfn_storage(USBDevice *dev) usb_desc_init(dev); scsi_bus_new(&s->bus, &s->dev.qdev, &usb_msd_scsi_info_storage, NULL); scsi_dev = scsi_bus_legacy_add_drive(&s->bus, bs, 0, !!s->removable, - s->conf.bootindex, dev->serial); + s->conf.bootindex, dev->serial, + &err); if (!scsi_dev) { return -1; } diff --git a/include/hw/scsi/scsi.h b/include/hw/scsi/scsi.h index 9786e00642..87865313eb 100644 --- a/include/hw/scsi/scsi.h +++ b/include/hw/scsi/scsi.h @@ -162,8 +162,8 @@ static inline SCSIBus *scsi_bus_from_device(SCSIDevice *d) SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv, int unit, bool removable, int bootindex, - const char *serial); -int scsi_bus_legacy_handle_cmdline(SCSIBus *bus); + const char *serial, Error **errp); +void scsi_bus_legacy_handle_cmdline(SCSIBus *bus, Error **errp); /* * Predefined sense codes From 726887ef44d5a822cd76e4fedd269b038869b698 Mon Sep 17 00:00:00 2001 From: Hu Tao Date: Mon, 1 Jul 2013 18:18:37 +0800 Subject: [PATCH 51/55] hpet: Use QOM realize for hpet MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Hu Tao [AF: Avoided SYS_BUS_DEVICE() in loop] Signed-off-by: Andreas Färber --- hw/timer/hpet.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/hw/timer/hpet.c b/hw/timer/hpet.c index 228598f345..648b38362d 100644 --- a/hw/timer/hpet.c +++ b/hw/timer/hpet.c @@ -686,8 +686,19 @@ static void hpet_handle_legacy_irq(void *opaque, int n, int level) } } -static int hpet_init(SysBusDevice *dev) +static void hpet_init(Object *obj) { + SysBusDevice *sbd = SYS_BUS_DEVICE(obj); + HPETState *s = HPET(obj); + + /* HPET Area */ + memory_region_init_io(&s->iomem, obj, &hpet_ram_ops, s, "hpet", 0x400); + sysbus_init_mmio(sbd, &s->iomem); +} + +static void hpet_realize(DeviceState *dev, Error **errp) +{ + SysBusDevice *sbd = SYS_BUS_DEVICE(dev); HPETState *s = HPET(dev); int i; HPETTimer *timer; @@ -698,14 +709,14 @@ static int hpet_init(SysBusDevice *dev) } if (hpet_cfg.count == 8) { - fprintf(stderr, "Only 8 instances of HPET is allowed\n"); - return -1; + error_setg(errp, "Only 8 instances of HPET is allowed"); + return; } s->hpet_id = hpet_cfg.count++; for (i = 0; i < HPET_NUM_IRQ_ROUTES; i++) { - sysbus_init_irq(dev, &s->irqs[i]); + sysbus_init_irq(sbd, &s->irqs[i]); } if (s->num_timers < HPET_MIN_TIMERS) { @@ -725,13 +736,8 @@ static int hpet_init(SysBusDevice *dev) s->capability |= (s->num_timers - 1) << HPET_ID_NUM_TIM_SHIFT; s->capability |= ((HPET_CLK_PERIOD) << 32); - qdev_init_gpio_in(&dev->qdev, hpet_handle_legacy_irq, 2); - qdev_init_gpio_out(&dev->qdev, &s->pit_enabled, 1); - - /* HPET Area */ - memory_region_init_io(&s->iomem, OBJECT(s), &hpet_ram_ops, s, "hpet", 0x400); - sysbus_init_mmio(dev, &s->iomem); - return 0; + qdev_init_gpio_in(dev, hpet_handle_legacy_irq, 2); + qdev_init_gpio_out(dev, &s->pit_enabled, 1); } static Property hpet_device_properties[] = { @@ -743,9 +749,8 @@ static Property hpet_device_properties[] = { static void hpet_device_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); - k->init = hpet_init; + dc->realize = hpet_realize; dc->no_user = 1; dc->reset = hpet_reset; dc->vmsd = &vmstate_hpet; @@ -756,6 +761,7 @@ static const TypeInfo hpet_device_info = { .name = TYPE_HPET, .parent = TYPE_SYS_BUS_DEVICE, .instance_size = sizeof(HPETState), + .instance_init = hpet_init, .class_init = hpet_device_class_init, }; From 913bc63844395f07e317dbc1a5b38612cc75ebec Mon Sep 17 00:00:00 2001 From: Hu Tao Date: Mon, 1 Jul 2013 18:18:39 +0800 Subject: [PATCH 52/55] kvm/clock: Use QOM realize for kvmclock MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Hu Tao Signed-off-by: Andreas Färber --- hw/i386/kvm/clock.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/hw/i386/kvm/clock.c b/hw/i386/kvm/clock.c index 62654584d6..e89e2f768e 100644 --- a/hw/i386/kvm/clock.c +++ b/hw/i386/kvm/clock.c @@ -91,12 +91,11 @@ static void kvmclock_vm_state_change(void *opaque, int running, } } -static int kvmclock_init(SysBusDevice *dev) +static void kvmclock_realize(DeviceState *dev, Error **errp) { KVMClockState *s = KVM_CLOCK(dev); qemu_add_vm_change_state_handler(kvmclock_vm_state_change, s); - return 0; } static const VMStateDescription kvmclock_vmsd = { @@ -113,9 +112,8 @@ static const VMStateDescription kvmclock_vmsd = { static void kvmclock_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); - k->init = kvmclock_init; + dc->realize = kvmclock_realize; dc->no_user = 1; dc->vmsd = &kvmclock_vmsd; } From c118d44b6a6977e4019fe1da82f5c333dbbedcfa Mon Sep 17 00:00:00 2001 From: Hu Tao Date: Mon, 1 Jul 2013 18:18:40 +0800 Subject: [PATCH 53/55] kvmvapic: Use QOM realize MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Hu Tao [AF: Renamed variable] Signed-off-by: Andreas Färber --- hw/i386/kvmvapic.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/hw/i386/kvmvapic.c b/hw/i386/kvmvapic.c index ccd089a40e..365b2197a1 100644 --- a/hw/i386/kvmvapic.c +++ b/hw/i386/kvmvapic.c @@ -703,19 +703,18 @@ static const MemoryRegionOps vapic_ops = { .endianness = DEVICE_NATIVE_ENDIAN, }; -static int vapic_init(SysBusDevice *dev) +static void vapic_realize(DeviceState *dev, Error **errp) { + SysBusDevice *sbd = SYS_BUS_DEVICE(dev); VAPICROMState *s = VAPIC(dev); memory_region_init_io(&s->io, OBJECT(s), &vapic_ops, s, "kvmvapic", 2); - sysbus_add_io(dev, VAPIC_IO_PORT, &s->io); - sysbus_init_ioports(dev, VAPIC_IO_PORT, 2); + sysbus_add_io(sbd, VAPIC_IO_PORT, &s->io); + sysbus_init_ioports(sbd, VAPIC_IO_PORT, 2); option_rom[nb_option_roms].name = "kvmvapic.bin"; option_rom[nb_option_roms].bootindex = -1; nb_option_roms++; - - return 0; } static void do_vapic_enable(void *data) @@ -812,13 +811,12 @@ static const VMStateDescription vmstate_vapic = { static void vapic_class_init(ObjectClass *klass, void *data) { - SysBusDeviceClass *sc = SYS_BUS_DEVICE_CLASS(klass); DeviceClass *dc = DEVICE_CLASS(klass); dc->no_user = 1; dc->reset = vapic_reset; dc->vmsd = &vmstate_vapic; - sc->init = vapic_init; + dc->realize = vapic_realize; } static const TypeInfo vapic_type = { From f5ba752371b2fc493fdef05cb7e3141161fd1fab Mon Sep 17 00:00:00 2001 From: Hu Tao Date: Mon, 1 Jul 2013 18:18:41 +0800 Subject: [PATCH 54/55] ioapic: Use QOM realize for ioapic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Hu Tao [AF: Tweaked error message] Signed-off-by: Andreas Färber --- hw/intc/ioapic_common.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/hw/intc/ioapic_common.c b/hw/intc/ioapic_common.c index 5c5bb3caaa..6b705c1546 100644 --- a/hw/intc/ioapic_common.c +++ b/hw/intc/ioapic_common.c @@ -57,23 +57,22 @@ static int ioapic_dispatch_post_load(void *opaque, int version_id) return 0; } -static int ioapic_init_common(SysBusDevice *dev) +static void ioapic_common_realize(DeviceState *dev, Error **errp) { IOAPICCommonState *s = IOAPIC_COMMON(dev); IOAPICCommonClass *info; static int ioapic_no; if (ioapic_no >= MAX_IOAPICS) { - return -1; + error_setg(errp, "Only %d ioapics allowed", MAX_IOAPICS); + return; } info = IOAPIC_COMMON_GET_CLASS(s); info->init(s, ioapic_no); - sysbus_init_mmio(&s->busdev, &s->io_memory); + sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->io_memory); ioapic_no++; - - return 0; } static const VMStateDescription vmstate_ioapic_common = { @@ -95,10 +94,9 @@ static const VMStateDescription vmstate_ioapic_common = { static void ioapic_common_class_init(ObjectClass *klass, void *data) { - SysBusDeviceClass *sc = SYS_BUS_DEVICE_CLASS(klass); DeviceClass *dc = DEVICE_CLASS(klass); - sc->init = ioapic_init_common; + dc->realize = ioapic_common_realize; dc->vmsd = &vmstate_ioapic_common; dc->no_user = 1; } From 52785d99513e4f5d8c3d94f4362ff54aba88f33c Mon Sep 17 00:00:00 2001 From: Hu Tao Date: Mon, 1 Jul 2013 18:18:42 +0800 Subject: [PATCH 55/55] isa-bus: Drop isabus_bridge_init() since it does nothing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This works since commit 4ce5dae88ecf2bafa0cd663de7e923728b1b3672. Signed-off-by: Hu Tao [AF: Edited] Signed-off-by: Andreas Färber --- hw/isa/isa-bus.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/hw/isa/isa-bus.c b/hw/isa/isa-bus.c index cfd610c681..9e104eb9a7 100644 --- a/hw/isa/isa-bus.c +++ b/hw/isa/isa-bus.c @@ -192,18 +192,10 @@ static void isabus_dev_print(Monitor *mon, DeviceState *dev, int indent) } } -static int isabus_bridge_init(SysBusDevice *dev) -{ - /* nothing */ - return 0; -} - static void isabus_bridge_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); - k->init = isabus_bridge_init; dc->fw_name = "isa"; dc->no_user = 1; }