diff options
author | Andreas Färber <afaerber@suse.de> | 2013-01-23 23:03:57 +0000 |
---|---|---|
committer | Alexander Graf <agraf@suse.de> | 2013-01-25 22:02:54 +0100 |
commit | d037834a9d3847499e8a146bd1893a5c856411be (patch) | |
tree | 976fdc56cb0ba9f6e66d14cd77b5596ce7b81ab4 /hw/macio.c | |
parent | 7b925079e36cf26ca2e1f8db84b771ddc3d6340c (diff) |
macio: Split MacIO in two
Let the machines create two different types. This prepares to move
knowledge about sub-devices from the machines into the devices.
Signed-off-by: Andreas Färber <afaerber@suse.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
Diffstat (limited to 'hw/macio.c')
-rw-r--r-- | hw/macio.c | 97 |
1 files changed, 70 insertions, 27 deletions
diff --git a/hw/macio.c b/hw/macio.c index 8b4b48d135..0e6fc8d5ff 100644 --- a/hw/macio.c +++ b/hw/macio.c @@ -36,7 +36,6 @@ typedef struct MacIOState PCIDevice parent; /*< public >*/ - int is_oldworld; MemoryRegion bar; MemoryRegion *pic_mem; MemoryRegion *dbdma_mem; @@ -52,15 +51,6 @@ static void macio_bar_setup(MacIOState *macio_state) int i; MemoryRegion *bar = &macio_state->bar; - if (macio_state->pic_mem) { - if (macio_state->is_oldworld) { - /* Heathrow PIC */ - memory_region_add_subregion(bar, 0x00000, macio_state->pic_mem); - } else { - /* OpenPIC */ - memory_region_add_subregion(bar, 0x40000, macio_state->pic_mem); - } - } if (macio_state->dbdma_mem) { memory_region_add_subregion(bar, 0x08000, macio_state->dbdma_mem); } @@ -80,7 +70,7 @@ static void macio_bar_setup(MacIOState *macio_state) macio_nvram_setup_bar(macio_state->nvram, bar, 0x60000); } -static int macio_initfn(PCIDevice *d) +static int macio_common_initfn(PCIDevice *d) { MacIOState *s = MACIO(d); @@ -92,6 +82,38 @@ static int macio_initfn(PCIDevice *d) return 0; } +static int macio_oldworld_initfn(PCIDevice *d) +{ + MacIOState *s = MACIO(d); + int ret = macio_common_initfn(d); + if (ret < 0) { + return ret; + } + + if (s->pic_mem) { + /* Heathrow PIC */ + memory_region_add_subregion(&s->bar, 0x00000, s->pic_mem); + } + + return 0; +} + +static int macio_newworld_initfn(PCIDevice *d) +{ + MacIOState *s = MACIO(d); + int ret = macio_common_initfn(d); + if (ret < 0) { + return ret; + } + + if (s->pic_mem) { + /* OpenPIC */ + memory_region_add_subregion(&s->bar, 0x40000, s->pic_mem); + } + + return 0; +} + static void macio_instance_init(Object *obj) { MacIOState *s = MACIO(obj); @@ -99,44 +121,69 @@ static void macio_instance_init(Object *obj) memory_region_init(&s->bar, "macio", 0x80000); } +static void macio_oldworld_class_init(ObjectClass *oc, void *data) +{ + PCIDeviceClass *pdc = PCI_DEVICE_CLASS(oc); + + pdc->init = macio_oldworld_initfn; + pdc->device_id = PCI_DEVICE_ID_APPLE_343S1201; +} + +static void macio_newworld_class_init(ObjectClass *oc, void *data) +{ + PCIDeviceClass *pdc = PCI_DEVICE_CLASS(oc); + + pdc->init = macio_newworld_initfn; + pdc->device_id = PCI_DEVICE_ID_APPLE_UNI_N_KEYL; +} + static void macio_class_init(ObjectClass *klass, void *data) { PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); - k->init = macio_initfn; k->vendor_id = PCI_VENDOR_ID_APPLE; k->class_id = PCI_CLASS_OTHERS << 8; } +static const TypeInfo macio_oldworld_type_info = { + .name = TYPE_OLDWORLD_MACIO, + .parent = TYPE_MACIO, + .class_init = macio_oldworld_class_init, +}; + +static const TypeInfo macio_newworld_type_info = { + .name = TYPE_NEWWORLD_MACIO, + .parent = TYPE_MACIO, + .class_init = macio_newworld_class_init, +}; + static const TypeInfo macio_type_info = { .name = TYPE_MACIO, .parent = TYPE_PCI_DEVICE, .instance_size = sizeof(MacIOState), .instance_init = macio_instance_init, + .abstract = true, .class_init = macio_class_init, }; static void macio_register_types(void) { type_register_static(&macio_type_info); + type_register_static(&macio_oldworld_type_info); + type_register_static(&macio_newworld_type_info); } type_init(macio_register_types) -void macio_init (PCIBus *bus, int device_id, int is_oldworld, - MemoryRegion *pic_mem, MemoryRegion *dbdma_mem, - MemoryRegion *cuda_mem, void *nvram, - int nb_ide, MemoryRegion **ide_mem, - MemoryRegion *escc_mem) +void macio_init(PCIDevice *d, + MemoryRegion *pic_mem, MemoryRegion *dbdma_mem, + MemoryRegion *cuda_mem, void *nvram, + int nb_ide, MemoryRegion **ide_mem, + MemoryRegion *escc_mem) { - PCIDevice *d; - MacIOState *macio_state; + MacIOState *macio_state = MACIO(d); int i; - d = pci_create(bus, -1, TYPE_MACIO); - - macio_state = MACIO(d); - macio_state->is_oldworld = is_oldworld; macio_state->pic_mem = pic_mem; macio_state->dbdma_mem = dbdma_mem; macio_state->cuda_mem = cuda_mem; @@ -147,12 +194,8 @@ void macio_init (PCIBus *bus, int device_id, int is_oldworld, macio_state->nb_ide = nb_ide; for (i = 0; i < nb_ide; i++) macio_state->ide_mem[i] = ide_mem[i]; - for (; i < 4; i++) - macio_state->ide_mem[i] = NULL; /* Note: this code is strongly inspirated from the corresponding code in PearPC */ - pci_config_set_device_id(d->config, device_id); - qdev_init_nofail(DEVICE(d)); } |