2007-10-29 00:42:18 +01:00
|
|
|
/*
|
|
|
|
* PowerMac MacIO device emulation
|
|
|
|
*
|
|
|
|
* Copyright (c) 2005-2007 Fabrice Bellard
|
|
|
|
* Copyright (c) 2007 Jocelyn Mayer
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
2013-02-04 15:40:22 +01:00
|
|
|
#include "hw/hw.h"
|
|
|
|
#include "hw/ppc/mac.h"
|
|
|
|
#include "hw/pci/pci.h"
|
|
|
|
#include "hw/mac_dbdma.h"
|
|
|
|
#include "hw/escc.h"
|
2007-10-29 00:42:18 +01:00
|
|
|
|
2013-01-24 00:03:55 +01:00
|
|
|
#define TYPE_MACIO "macio"
|
|
|
|
#define MACIO(obj) OBJECT_CHECK(MacIOState, (obj), TYPE_MACIO)
|
|
|
|
|
2011-12-21 23:14:09 +01:00
|
|
|
typedef struct MacIOState
|
|
|
|
{
|
2013-01-24 00:03:55 +01:00
|
|
|
/*< private >*/
|
2011-12-21 23:14:09 +01:00
|
|
|
PCIDevice parent;
|
2013-01-24 00:03:55 +01:00
|
|
|
/*< public >*/
|
|
|
|
|
2011-08-08 15:09:17 +02:00
|
|
|
MemoryRegion bar;
|
2013-01-24 00:04:02 +01:00
|
|
|
CUDAState cuda;
|
2013-01-24 00:04:01 +01:00
|
|
|
void *dbdma;
|
2011-08-08 15:09:17 +02:00
|
|
|
MemoryRegion *pic_mem;
|
|
|
|
MemoryRegion *escc_mem;
|
2011-12-21 23:14:09 +01:00
|
|
|
} MacIOState;
|
2007-10-29 00:42:18 +01:00
|
|
|
|
2013-01-24 00:04:00 +01:00
|
|
|
#define OLDWORLD_MACIO(obj) \
|
|
|
|
OBJECT_CHECK(OldWorldMacIOState, (obj), TYPE_OLDWORLD_MACIO)
|
|
|
|
|
|
|
|
typedef struct OldWorldMacIOState {
|
|
|
|
/*< private >*/
|
|
|
|
MacIOState parent_obj;
|
|
|
|
/*< public >*/
|
|
|
|
|
2013-01-24 00:04:02 +01:00
|
|
|
qemu_irq irqs[3];
|
2013-01-24 00:04:01 +01:00
|
|
|
|
2013-01-24 00:04:00 +01:00
|
|
|
MacIONVRAMState nvram;
|
2013-01-24 00:04:01 +01:00
|
|
|
MACIOIDEState ide;
|
2013-01-24 00:04:00 +01:00
|
|
|
} OldWorldMacIOState;
|
|
|
|
|
2013-01-24 00:04:01 +01:00
|
|
|
#define NEWWORLD_MACIO(obj) \
|
|
|
|
OBJECT_CHECK(NewWorldMacIOState, (obj), TYPE_NEWWORLD_MACIO)
|
|
|
|
|
|
|
|
typedef struct NewWorldMacIOState {
|
|
|
|
/*< private >*/
|
|
|
|
MacIOState parent_obj;
|
|
|
|
/*< public >*/
|
2013-01-24 00:04:02 +01:00
|
|
|
qemu_irq irqs[5];
|
2013-01-24 00:04:01 +01:00
|
|
|
MACIOIDEState ide[2];
|
|
|
|
} NewWorldMacIOState;
|
|
|
|
|
2011-12-21 23:14:09 +01:00
|
|
|
static void macio_bar_setup(MacIOState *macio_state)
|
2007-10-29 00:42:18 +01:00
|
|
|
{
|
2011-08-08 15:09:17 +02:00
|
|
|
MemoryRegion *bar = &macio_state->bar;
|
2007-10-29 00:42:18 +01:00
|
|
|
|
2011-08-08 15:09:17 +02:00
|
|
|
if (macio_state->escc_mem) {
|
|
|
|
memory_region_add_subregion(bar, 0x13000, macio_state->escc_mem);
|
2009-01-12 18:40:23 +01:00
|
|
|
}
|
2007-10-29 00:42:18 +01:00
|
|
|
}
|
|
|
|
|
2013-01-24 00:03:57 +01:00
|
|
|
static int macio_common_initfn(PCIDevice *d)
|
2011-12-21 23:14:09 +01:00
|
|
|
{
|
2013-01-24 00:03:56 +01:00
|
|
|
MacIOState *s = MACIO(d);
|
2013-01-24 00:04:02 +01:00
|
|
|
SysBusDevice *sysbus_dev;
|
|
|
|
int ret;
|
2013-01-24 00:03:56 +01:00
|
|
|
|
2011-12-21 23:14:09 +01:00
|
|
|
d->config[0x3d] = 0x01; // interrupt on pin 1
|
2013-01-24 00:03:56 +01:00
|
|
|
|
2013-01-24 00:04:02 +01:00
|
|
|
ret = qdev_init(DEVICE(&s->cuda));
|
|
|
|
if (ret < 0) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
sysbus_dev = SYS_BUS_DEVICE(&s->cuda);
|
|
|
|
memory_region_add_subregion(&s->bar, 0x16000,
|
|
|
|
sysbus_mmio_get_region(sysbus_dev, 0));
|
|
|
|
|
2013-01-24 00:03:56 +01:00
|
|
|
macio_bar_setup(s);
|
|
|
|
pci_register_bar(d, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, &s->bar);
|
|
|
|
|
2011-12-21 23:14:09 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-01-24 00:03:57 +01:00
|
|
|
static int macio_oldworld_initfn(PCIDevice *d)
|
|
|
|
{
|
|
|
|
MacIOState *s = MACIO(d);
|
2013-01-24 00:04:00 +01:00
|
|
|
OldWorldMacIOState *os = OLDWORLD_MACIO(d);
|
|
|
|
SysBusDevice *sysbus_dev;
|
2013-01-24 00:03:57 +01:00
|
|
|
int ret = macio_common_initfn(d);
|
|
|
|
if (ret < 0) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-01-24 00:04:02 +01:00
|
|
|
sysbus_dev = SYS_BUS_DEVICE(&s->cuda);
|
|
|
|
sysbus_connect_irq(sysbus_dev, 0, os->irqs[0]);
|
|
|
|
|
2013-01-24 00:04:00 +01:00
|
|
|
ret = qdev_init(DEVICE(&os->nvram));
|
|
|
|
if (ret < 0) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
sysbus_dev = SYS_BUS_DEVICE(&os->nvram);
|
|
|
|
memory_region_add_subregion(&s->bar, 0x60000,
|
|
|
|
sysbus_mmio_get_region(sysbus_dev, 0));
|
|
|
|
pmac_format_nvram_partition(&os->nvram, os->nvram.size);
|
|
|
|
|
2013-01-24 00:03:57 +01:00
|
|
|
if (s->pic_mem) {
|
|
|
|
/* Heathrow PIC */
|
|
|
|
memory_region_add_subregion(&s->bar, 0x00000, s->pic_mem);
|
|
|
|
}
|
|
|
|
|
2013-01-24 00:04:01 +01:00
|
|
|
sysbus_dev = SYS_BUS_DEVICE(&os->ide);
|
2013-01-24 00:04:02 +01:00
|
|
|
sysbus_connect_irq(sysbus_dev, 0, os->irqs[1]);
|
|
|
|
sysbus_connect_irq(sysbus_dev, 1, os->irqs[2]);
|
2013-01-24 00:04:01 +01:00
|
|
|
macio_ide_register_dma(&os->ide, s->dbdma, 0x16);
|
|
|
|
ret = qdev_init(DEVICE(&os->ide));
|
|
|
|
if (ret < 0) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-01-24 00:03:57 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-01-24 00:04:00 +01:00
|
|
|
static void macio_oldworld_init(Object *obj)
|
|
|
|
{
|
2013-01-24 00:04:01 +01:00
|
|
|
MacIOState *s = MACIO(obj);
|
2013-01-24 00:04:00 +01:00
|
|
|
OldWorldMacIOState *os = OLDWORLD_MACIO(obj);
|
|
|
|
DeviceState *dev;
|
|
|
|
|
2013-01-24 00:04:01 +01:00
|
|
|
qdev_init_gpio_out(DEVICE(obj), os->irqs, ARRAY_SIZE(os->irqs));
|
|
|
|
|
2013-01-24 00:04:00 +01:00
|
|
|
object_initialize(&os->nvram, TYPE_MACIO_NVRAM);
|
|
|
|
dev = DEVICE(&os->nvram);
|
|
|
|
qdev_prop_set_uint32(dev, "size", 0x2000);
|
|
|
|
qdev_prop_set_uint32(dev, "it_shift", 4);
|
2013-01-24 00:04:01 +01:00
|
|
|
|
|
|
|
object_initialize(&os->ide, TYPE_MACIO_IDE);
|
|
|
|
qdev_set_parent_bus(DEVICE(&os->ide), sysbus_get_default());
|
|
|
|
memory_region_add_subregion(&s->bar, 0x1f000 + (1 * 0x1000), &os->ide.mem);
|
|
|
|
object_property_add_child(obj, "ide", OBJECT(&os->ide), NULL);
|
2013-01-24 00:04:00 +01:00
|
|
|
}
|
|
|
|
|
2013-01-24 00:03:57 +01:00
|
|
|
static int macio_newworld_initfn(PCIDevice *d)
|
|
|
|
{
|
|
|
|
MacIOState *s = MACIO(d);
|
2013-01-24 00:04:01 +01:00
|
|
|
NewWorldMacIOState *ns = NEWWORLD_MACIO(d);
|
|
|
|
SysBusDevice *sysbus_dev;
|
2013-01-24 00:03:57 +01:00
|
|
|
int ret = macio_common_initfn(d);
|
|
|
|
if (ret < 0) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-01-24 00:04:02 +01:00
|
|
|
sysbus_dev = SYS_BUS_DEVICE(&s->cuda);
|
|
|
|
sysbus_connect_irq(sysbus_dev, 0, ns->irqs[0]);
|
|
|
|
|
2013-01-24 00:03:57 +01:00
|
|
|
if (s->pic_mem) {
|
|
|
|
/* OpenPIC */
|
|
|
|
memory_region_add_subregion(&s->bar, 0x40000, s->pic_mem);
|
|
|
|
}
|
|
|
|
|
2013-01-24 00:04:01 +01:00
|
|
|
sysbus_dev = SYS_BUS_DEVICE(&ns->ide[0]);
|
2013-01-24 00:04:02 +01:00
|
|
|
sysbus_connect_irq(sysbus_dev, 0, ns->irqs[1]);
|
|
|
|
sysbus_connect_irq(sysbus_dev, 1, ns->irqs[2]);
|
2013-01-24 00:04:01 +01:00
|
|
|
macio_ide_register_dma(&ns->ide[0], s->dbdma, 0x16);
|
|
|
|
ret = qdev_init(DEVICE(&ns->ide[0]));
|
|
|
|
if (ret < 0) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
sysbus_dev = SYS_BUS_DEVICE(&ns->ide[1]);
|
2013-01-24 00:04:02 +01:00
|
|
|
sysbus_connect_irq(sysbus_dev, 0, ns->irqs[3]);
|
|
|
|
sysbus_connect_irq(sysbus_dev, 1, ns->irqs[4]);
|
2013-02-24 21:46:11 +01:00
|
|
|
macio_ide_register_dma(&ns->ide[1], s->dbdma, 0x1a);
|
2013-01-24 00:04:01 +01:00
|
|
|
ret = qdev_init(DEVICE(&ns->ide[1]));
|
|
|
|
if (ret < 0) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-01-24 00:03:57 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-01-24 00:04:01 +01:00
|
|
|
static void macio_newworld_init(Object *obj)
|
|
|
|
{
|
|
|
|
MacIOState *s = MACIO(obj);
|
|
|
|
NewWorldMacIOState *ns = NEWWORLD_MACIO(obj);
|
|
|
|
int i;
|
|
|
|
gchar *name;
|
|
|
|
|
|
|
|
qdev_init_gpio_out(DEVICE(obj), ns->irqs, ARRAY_SIZE(ns->irqs));
|
|
|
|
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
object_initialize(&ns->ide[i], TYPE_MACIO_IDE);
|
|
|
|
qdev_set_parent_bus(DEVICE(&ns->ide[i]), sysbus_get_default());
|
|
|
|
memory_region_add_subregion(&s->bar, 0x1f000 + ((i + 1) * 0x1000),
|
|
|
|
&ns->ide[i].mem);
|
|
|
|
name = g_strdup_printf("ide[%i]", i);
|
|
|
|
object_property_add_child(obj, name, OBJECT(&ns->ide[i]), NULL);
|
|
|
|
g_free(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-24 00:03:55 +01:00
|
|
|
static void macio_instance_init(Object *obj)
|
|
|
|
{
|
|
|
|
MacIOState *s = MACIO(obj);
|
2013-01-24 00:04:01 +01:00
|
|
|
MemoryRegion *dbdma_mem;
|
2013-01-24 00:03:55 +01:00
|
|
|
|
|
|
|
memory_region_init(&s->bar, "macio", 0x80000);
|
2013-01-24 00:04:01 +01:00
|
|
|
|
2013-01-24 00:04:02 +01:00
|
|
|
object_initialize(&s->cuda, TYPE_CUDA);
|
|
|
|
qdev_set_parent_bus(DEVICE(&s->cuda), sysbus_get_default());
|
|
|
|
object_property_add_child(obj, "cuda", OBJECT(&s->cuda), NULL);
|
|
|
|
|
2013-01-24 00:04:01 +01:00
|
|
|
s->dbdma = DBDMA_init(&dbdma_mem);
|
|
|
|
memory_region_add_subregion(&s->bar, 0x08000, dbdma_mem);
|
2013-01-24 00:03:55 +01:00
|
|
|
}
|
|
|
|
|
2013-01-24 00:03:57 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-12-04 19:22:06 +01:00
|
|
|
static void macio_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
|
|
|
|
|
|
|
|
k->vendor_id = PCI_VENDOR_ID_APPLE;
|
|
|
|
k->class_id = PCI_CLASS_OTHERS << 8;
|
|
|
|
}
|
|
|
|
|
2013-01-24 00:03:57 +01:00
|
|
|
static const TypeInfo macio_oldworld_type_info = {
|
|
|
|
.name = TYPE_OLDWORLD_MACIO,
|
|
|
|
.parent = TYPE_MACIO,
|
2013-01-24 00:04:00 +01:00
|
|
|
.instance_size = sizeof(OldWorldMacIOState),
|
|
|
|
.instance_init = macio_oldworld_init,
|
2013-01-24 00:03:57 +01:00
|
|
|
.class_init = macio_oldworld_class_init,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const TypeInfo macio_newworld_type_info = {
|
|
|
|
.name = TYPE_NEWWORLD_MACIO,
|
|
|
|
.parent = TYPE_MACIO,
|
2013-01-24 00:04:01 +01:00
|
|
|
.instance_size = sizeof(NewWorldMacIOState),
|
|
|
|
.instance_init = macio_newworld_init,
|
2013-01-24 00:03:57 +01:00
|
|
|
.class_init = macio_newworld_class_init,
|
|
|
|
};
|
|
|
|
|
2013-01-24 00:03:55 +01:00
|
|
|
static const TypeInfo macio_type_info = {
|
|
|
|
.name = TYPE_MACIO,
|
2011-12-08 04:34:16 +01:00
|
|
|
.parent = TYPE_PCI_DEVICE,
|
|
|
|
.instance_size = sizeof(MacIOState),
|
2013-01-24 00:03:55 +01:00
|
|
|
.instance_init = macio_instance_init,
|
2013-01-24 00:03:57 +01:00
|
|
|
.abstract = true,
|
2011-12-08 04:34:16 +01:00
|
|
|
.class_init = macio_class_init,
|
2011-12-21 23:14:09 +01:00
|
|
|
};
|
|
|
|
|
2012-02-09 15:20:55 +01:00
|
|
|
static void macio_register_types(void)
|
2011-12-21 23:14:09 +01:00
|
|
|
{
|
2013-01-24 00:03:55 +01:00
|
|
|
type_register_static(&macio_type_info);
|
2013-01-24 00:03:57 +01:00
|
|
|
type_register_static(&macio_oldworld_type_info);
|
|
|
|
type_register_static(&macio_newworld_type_info);
|
2011-12-21 23:14:09 +01:00
|
|
|
}
|
|
|
|
|
2012-02-09 15:20:55 +01:00
|
|
|
type_init(macio_register_types)
|
2011-12-21 23:14:09 +01:00
|
|
|
|
2013-01-24 00:03:57 +01:00
|
|
|
void macio_init(PCIDevice *d,
|
2013-01-24 00:04:01 +01:00
|
|
|
MemoryRegion *pic_mem,
|
2013-01-24 00:03:57 +01:00
|
|
|
MemoryRegion *escc_mem)
|
2007-10-29 00:42:18 +01:00
|
|
|
{
|
2013-01-24 00:03:57 +01:00
|
|
|
MacIOState *macio_state = MACIO(d);
|
2007-10-29 00:42:18 +01:00
|
|
|
|
2011-08-08 15:09:17 +02:00
|
|
|
macio_state->pic_mem = pic_mem;
|
|
|
|
macio_state->escc_mem = escc_mem;
|
2007-10-29 00:42:18 +01:00
|
|
|
/* Note: this code is strongly inspirated from the corresponding code
|
|
|
|
in PearPC */
|
2009-01-26 16:37:35 +01:00
|
|
|
|
2013-01-24 00:03:56 +01:00
|
|
|
qdev_init_nofail(DEVICE(d));
|
2007-10-29 00:42:18 +01:00
|
|
|
}
|