spapr-pci: Convert to QOM realize

This converts the old-style SysBusDevice::init() callback to a new-style
DeviceClass::realize() callback.

As a part of conversion, this replaces fprintf(stderr) with error_setg()
as realize() does not "return" any value, instead it puts the extended
error into **errp.

Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Reviewed-by: Mike Day <ncmike@ncultra.org>
Signed-off-by: Andreas Färber <afaerber@suse.de>
This commit is contained in:
Alexey Kardashevskiy 2013-11-21 15:08:55 +11:00 committed by Andreas Färber
parent fb0e843a11
commit c6ba42f6bc

View file

@ -505,9 +505,9 @@ static AddressSpace *spapr_pci_dma_iommu(PCIBus *bus, void *opaque, int devfn)
return &phb->iommu_as; return &phb->iommu_as;
} }
static int spapr_phb_init(SysBusDevice *s) static void spapr_phb_realize(DeviceState *dev, Error **errp)
{ {
DeviceState *dev = DEVICE(s); SysBusDevice *s = SYS_BUS_DEVICE(dev);
sPAPRPHBState *sphb = SPAPR_PCI_HOST_BRIDGE(s); sPAPRPHBState *sphb = SPAPR_PCI_HOST_BRIDGE(s);
PCIHostState *phb = PCI_HOST_BRIDGE(s); PCIHostState *phb = PCI_HOST_BRIDGE(s);
const char *busname; const char *busname;
@ -521,9 +521,9 @@ static int spapr_phb_init(SysBusDevice *s)
if ((sphb->buid != -1) || (sphb->dma_liobn != -1) if ((sphb->buid != -1) || (sphb->dma_liobn != -1)
|| (sphb->mem_win_addr != -1) || (sphb->mem_win_addr != -1)
|| (sphb->io_win_addr != -1)) { || (sphb->io_win_addr != -1)) {
fprintf(stderr, "Either \"index\" or other parameters must" error_setg(errp, "Either \"index\" or other parameters must"
" be specified for PAPR PHB, not both\n"); " be specified for PAPR PHB, not both");
return -1; return;
} }
sphb->buid = SPAPR_PCI_BASE_BUID + sphb->index; sphb->buid = SPAPR_PCI_BASE_BUID + sphb->index;
@ -536,28 +536,28 @@ static int spapr_phb_init(SysBusDevice *s)
} }
if (sphb->buid == -1) { if (sphb->buid == -1) {
fprintf(stderr, "BUID not specified for PHB\n"); error_setg(errp, "BUID not specified for PHB");
return -1; return;
} }
if (sphb->dma_liobn == -1) { if (sphb->dma_liobn == -1) {
fprintf(stderr, "LIOBN not specified for PHB\n"); error_setg(errp, "LIOBN not specified for PHB");
return -1; return;
} }
if (sphb->mem_win_addr == -1) { if (sphb->mem_win_addr == -1) {
fprintf(stderr, "Memory window address not specified for PHB\n"); error_setg(errp, "Memory window address not specified for PHB");
return -1; return;
} }
if (sphb->io_win_addr == -1) { if (sphb->io_win_addr == -1) {
fprintf(stderr, "IO window address not specified for PHB\n"); error_setg(errp, "IO window address not specified for PHB");
return -1; return;
} }
if (find_phb(spapr, sphb->buid)) { if (find_phb(spapr, sphb->buid)) {
fprintf(stderr, "PCI host bridges must have unique BUIDs\n"); error_setg(errp, "PCI host bridges must have unique BUIDs");
return -1; return;
} }
sphb->dtbusname = g_strdup_printf("pci@%" PRIx64, sphb->buid); sphb->dtbusname = g_strdup_printf("pci@%" PRIx64, sphb->buid);
@ -624,8 +624,9 @@ static int spapr_phb_init(SysBusDevice *s)
sphb->tcet = spapr_tce_new_table(dev, sphb->dma_liobn, sphb->tcet = spapr_tce_new_table(dev, sphb->dma_liobn,
sphb->dma_window_size); sphb->dma_window_size);
if (!sphb->tcet) { if (!sphb->tcet) {
fprintf(stderr, "Unable to create TCE table for %s\n", sphb->dtbusname); error_setg(errp, "Unable to create TCE table for %s",
return -1; sphb->dtbusname);
return;
} }
address_space_init(&sphb->iommu_as, spapr_tce_get_iommu(sphb->tcet), address_space_init(&sphb->iommu_as, spapr_tce_get_iommu(sphb->tcet),
sphb->dtbusname); sphb->dtbusname);
@ -642,13 +643,12 @@ static int spapr_phb_init(SysBusDevice *s)
irq = spapr_allocate_lsi(0); irq = spapr_allocate_lsi(0);
if (!irq) { if (!irq) {
return -1; error_setg(errp, "spapr_allocate_lsi failed");
return;
} }
sphb->lsi_table[i].irq = irq; sphb->lsi_table[i].irq = irq;
} }
return 0;
} }
static void spapr_phb_reset(DeviceState *qdev) static void spapr_phb_reset(DeviceState *qdev)
@ -731,11 +731,10 @@ static const char *spapr_phb_root_bus_path(PCIHostState *host_bridge,
static void spapr_phb_class_init(ObjectClass *klass, void *data) static void spapr_phb_class_init(ObjectClass *klass, void *data)
{ {
PCIHostBridgeClass *hc = PCI_HOST_BRIDGE_CLASS(klass); PCIHostBridgeClass *hc = PCI_HOST_BRIDGE_CLASS(klass);
SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);
DeviceClass *dc = DEVICE_CLASS(klass); DeviceClass *dc = DEVICE_CLASS(klass);
hc->root_bus_path = spapr_phb_root_bus_path; hc->root_bus_path = spapr_phb_root_bus_path;
sdc->init = spapr_phb_init; dc->realize = spapr_phb_realize;
dc->props = spapr_phb_properties; dc->props = spapr_phb_properties;
dc->reset = spapr_phb_reset; dc->reset = spapr_phb_reset;
dc->vmsd = &vmstate_spapr_pci; dc->vmsd = &vmstate_spapr_pci;