Introduce a Clipper-specific subclass of TyphoonClass, and set the pci_map_irq_fn class member in the subclass init.
Since the board must provide the PCI IRQ mapping to the Typhoon, mark the base Typhoon type as abstract. Eliminate the pci_map_irq_fn parameter of typhoon_init(). Note: This commit brings us closer to the splitting of typhoon_init() into instance_init and realize hooks. Signed-off-by: Yodel Eldar <[email protected]> --- hw/alpha/alpha_sys.h | 4 +++- hw/alpha/dp264.c | 19 +++++++++++++++++-- hw/alpha/typhoon.c | 9 ++++++--- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/hw/alpha/alpha_sys.h b/hw/alpha/alpha_sys.h index 794a47127d..fdfe96dcb4 100644 --- a/hw/alpha/alpha_sys.h +++ b/hw/alpha/alpha_sys.h @@ -13,11 +13,13 @@ typedef struct TyphoonClass { PCIHostBridgeClass parent_class; + + pci_map_irq_fn sys_map_irq; } TyphoonClass; OBJECT_DECLARE_TYPE(TyphoonState, TyphoonClass, TYPHOON_PCI_HOST_BRIDGE) -PCIBus *typhoon_init(pci_map_irq_fn, uint8_t devfn_min, TyphoonState *); +PCIBus *typhoon_init(uint8_t devfn_min, TyphoonState *); #define TYPHOON_PROP_RAM "ram" diff --git a/hw/alpha/dp264.c b/hw/alpha/dp264.c index a7fc137e70..8c3c8fec67 100644 --- a/hw/alpha/dp264.c +++ b/hw/alpha/dp264.c @@ -21,6 +21,8 @@ #define TYPE_CLIPPER_MACHINE MACHINE_TYPE_NAME("clipper") OBJECT_DECLARE_SIMPLE_TYPE(ClipperMachineState, CLIPPER_MACHINE) +#define TYPE_TYPHOON_PCIHOST_CLIPPER "typhoon-pcihost-clipper" + struct ClipperMachineState { MachineState parent_obj; @@ -72,7 +74,7 @@ static void clipper_init(MachineState *machine) uint64_t kernel_entry, kernel_low, kernel_high; unsigned int smp_cpus = machine->smp.cpus; - Object * const typhoon_obj = object_new(TYPE_TYPHOON_PCI_HOST_BRIDGE); + Object * const typhoon_obj = object_new(TYPE_TYPHOON_PCIHOST_CLIPPER); TyphoonState * const typhoon = TYPHOON_PCI_HOST_BRIDGE(typhoon_obj); cms->typhoon = typhoon; object_property_add_child(OBJECT(machine), "typhoon", typhoon_obj); @@ -109,7 +111,7 @@ static void clipper_init(MachineState *machine) * Init the chipset. Because we're using CLIPPER IRQ mappings, * the minimum PCI device IdSel is 1. */ - pci_bus = typhoon_init(clipper_pci_map_irq, PCI_DEVFN(1, 0), typhoon); + pci_bus = typhoon_init(PCI_DEVFN(1, 0), typhoon); /* * Init the PCI -> ISA bridge. @@ -251,6 +253,14 @@ static void clipper_machine_init(ObjectClass *oc, const void *data) mc->default_nic = "e1000"; } +static void typhoon_pcihost_clipper_class_init(ObjectClass *oc, + const void *data) +{ + TyphoonClass *tc = TYPHOON_PCI_HOST_BRIDGE_CLASS(oc); + + tc->sys_map_irq = clipper_pci_map_irq; +} + static const TypeInfo clipper_types[] = { { .name = TYPE_CLIPPER_MACHINE, @@ -258,6 +268,11 @@ static const TypeInfo clipper_types[] = { .instance_size = sizeof(ClipperMachineState), .class_init = clipper_machine_init, }, + { + .name = TYPE_TYPHOON_PCIHOST_CLIPPER, + .parent = TYPE_TYPHOON_PCI_HOST_BRIDGE, + .class_init = typhoon_pcihost_clipper_class_init, + }, }; DEFINE_TYPES(clipper_types); diff --git a/hw/alpha/typhoon.c b/hw/alpha/typhoon.c index 8745025319..b261dd7bc5 100644 --- a/hw/alpha/typhoon.c +++ b/hw/alpha/typhoon.c @@ -833,15 +833,17 @@ static void typhoon_alarm_timer(void *opaque) cpu_interrupt(CPU(s->cchip.cpu[cpu]), CPU_INTERRUPT_TIMER); } -PCIBus *typhoon_init(pci_map_irq_fn sys_map_irq, uint8_t devfn_min, - TyphoonState *s) +PCIBus *typhoon_init(uint8_t devfn_min, TyphoonState *s) { + TyphoonClass *tc = TYPHOON_PCI_HOST_BRIDGE_GET_CLASS(s); MemoryRegion *addr_space = get_system_memory(); DeviceState *dev = DEVICE(s); PCIHostState *phb; PCIBus *b; int i; + assert(tc->sys_map_irq != NULL); + phb = PCI_HOST_BRIDGE(dev); s->cchip.misc = 0x800000000ull; /* Revision: Typhoon. */ @@ -899,7 +901,7 @@ PCIBus *typhoon_init(pci_map_irq_fn sys_map_irq, uint8_t devfn_min, &s->pchip.reg_io); b = pci_register_root_bus(dev, "pci", - typhoon_set_irq, sys_map_irq, s, + typhoon_set_irq, tc->sys_map_irq, s, &s->pchip.reg_mem, &s->pchip.reg_io, devfn_min, 64, TYPE_PCI_BUS); phb->bus = b; @@ -978,6 +980,7 @@ static const TypeInfo typhoon_pcihost_info = { .instance_init = typhoon_pcihost_init, .class_size = sizeof(TyphoonClass), .class_init = typhoon_pcihost_class_init, + .abstract = true, }; static void typhoon_iommu_memory_region_class_init(ObjectClass *klass, -- 2.53.0
