@@ -368,7 +368,8 @@ static const MemoryRegionOps rcr_ops = {
},
};
-static void pci_piix3_realize(PCIDevice *dev, Error **errp)
+static void pci_piix_realize(PCIDevice *dev, const char *uhci_type,
+ Error **errp)
{
PIIXState *d = PIIX_PCI_DEVICE(dev);
PCIBus *pci_bus = pci_get_bus(dev);
@@ -408,8 +409,7 @@ static void pci_piix3_realize(PCIDevice *dev, Error **errp)
/* USB */
if (d->has_usb) {
- object_initialize_child(OBJECT(dev), "uhci", &d->uhci,
- TYPE_PIIX3_USB_UHCI);
+ object_initialize_child(OBJECT(dev), "uhci", &d->uhci, uhci_type);
qdev_prop_set_int32(DEVICE(&d->uhci), "addr", dev->devfn + 2);
if (!qdev_realize(DEVICE(&d->uhci), BUS(pci_bus), errp)) {
return;
@@ -507,7 +507,7 @@ static void piix3_realize(PCIDevice *dev, Error **errp)
PIIXState *piix3 = PIIX_PCI_DEVICE(dev);
PCIBus *pci_bus = pci_get_bus(dev);
- pci_piix3_realize(dev, errp);
+ pci_piix_realize(dev, TYPE_PIIX3_USB_UHCI, errp);
if (*errp) {
return;
}
@@ -537,7 +537,7 @@ static void piix3_xen_realize(PCIDevice *dev, Error **errp)
PIIXState *piix3 = PIIX_PCI_DEVICE(dev);
PCIBus *pci_bus = pci_get_bus(dev);
- pci_piix3_realize(dev, errp);
+ pci_piix_realize(dev, TYPE_PIIX3_USB_UHCI, errp);
if (*errp) {
return;
}
@@ -568,71 +568,24 @@ static const TypeInfo piix3_xen_info = {
static void piix4_realize(PCIDevice *dev, Error **errp)
{
+ ERRP_GUARD();
PIIXState *s = PIIX_PCI_DEVICE(dev);
PCIBus *pci_bus = pci_get_bus(dev);
ISABus *isa_bus;
- isa_bus = isa_bus_new(DEVICE(dev), pci_address_space(dev),
- pci_address_space_io(dev), errp);
- if (!isa_bus) {
- return;
- }
-
- memory_region_init_io(&s->rcr_mem, OBJECT(dev), &rcr_ops, s,
- "piix-reset-control", 1);
- memory_region_add_subregion_overlap(pci_address_space_io(dev),
- PIIX_RCR_IOPORT, &s->rcr_mem, 1);
-
- /* initialize i8259 pic */
- if (!qdev_realize(DEVICE(&s->pic), BUS(isa_bus), errp)) {
+ pci_piix_realize(dev, TYPE_PIIX4_USB_UHCI, errp);
+ if (*errp) {
return;
}
- /* initialize ISA irqs */
- isa_bus_irqs(isa_bus, s->pic.in_irqs);
+ isa_bus = ISA_BUS(qdev_get_child_bus(DEVICE(dev), "isa.0"));
/* initialize pit */
i8254_pit_init(isa_bus, 0x40, 0, NULL);
- /* DMA */
- i8257_dma_init(isa_bus, 0);
-
/* RTC */
- qdev_prop_set_int32(DEVICE(&s->rtc), "base_year", 2000);
- if (!qdev_realize(DEVICE(&s->rtc), BUS(isa_bus), errp)) {
- return;
- }
s->rtc.irq = qdev_get_gpio_in(DEVICE(&s->pic), s->rtc.isairq);
- /* IDE */
- qdev_prop_set_int32(DEVICE(&s->ide), "addr", dev->devfn + 1);
- if (!qdev_realize(DEVICE(&s->ide), BUS(pci_bus), errp)) {
- return;
- }
-
- /* USB */
- if (s->has_usb) {
- object_initialize_child(OBJECT(dev), "uhci", &s->uhci,
- TYPE_PIIX4_USB_UHCI);
- qdev_prop_set_int32(DEVICE(&s->uhci), "addr", dev->devfn + 2);
- if (!qdev_realize(DEVICE(&s->uhci), BUS(pci_bus), errp)) {
- return;
- }
- }
-
- /* ACPI controller */
- if (s->has_acpi) {
- object_initialize_child(OBJECT(s), "pm", &s->pm, TYPE_PIIX4_PM);
- qdev_prop_set_int32(DEVICE(&s->pm), "addr", dev->devfn + 3);
- qdev_prop_set_uint32(DEVICE(&s->pm), "smb_io_base", s->smb_io_base);
- qdev_prop_set_bit(DEVICE(&s->pm), "smm-enabled", s->smm_enabled);
- if (!qdev_realize(DEVICE(&s->pm), BUS(pci_bus), errp)) {
- return;
- }
- qdev_connect_gpio_out(DEVICE(&s->pm), 0,
- qdev_get_gpio_in(DEVICE(&s->pic), 9));
- }
-
pci_bus_irqs(pci_bus, piix4_set_irq, piix4_pci_slot_get_pirq, s,
PIIX_NUM_PIRQS);
}
Resolves duplicate code. Signed-off-by: Bernhard Beschow <shentey@gmail.com> --- hw/isa/piix.c | 65 +++++++-------------------------------------------- 1 file changed, 9 insertions(+), 56 deletions(-)