aboutsummaryrefslogtreecommitdiffstats
path: root/hw/nubus
diff options
context:
space:
mode:
Diffstat (limited to 'hw/nubus')
-rw-r--r--hw/nubus/Kconfig2
-rw-r--r--hw/nubus/mac-nubus-bridge.c63
-rw-r--r--hw/nubus/meson.build7
-rw-r--r--hw/nubus/nubus-bridge.c53
-rw-r--r--hw/nubus/nubus-bus.c188
-rw-r--r--hw/nubus/nubus-device.c120
-rw-r--r--hw/nubus/trace-events7
-rw-r--r--hw/nubus/trace.h1
8 files changed, 441 insertions, 0 deletions
diff --git a/hw/nubus/Kconfig b/hw/nubus/Kconfig
new file mode 100644
index 000000000..8fb8b2218
--- /dev/null
+++ b/hw/nubus/Kconfig
@@ -0,0 +1,2 @@
+config NUBUS
+ bool
diff --git a/hw/nubus/mac-nubus-bridge.c b/hw/nubus/mac-nubus-bridge.c
new file mode 100644
index 000000000..a0da5a8b2
--- /dev/null
+++ b/hw/nubus/mac-nubus-bridge.c
@@ -0,0 +1,63 @@
+/*
+ * QEMU Macintosh Nubus
+ *
+ * Copyright (c) 2013-2018 Laurent Vivier <laurent@vivier.eu>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#include "qemu/osdep.h"
+#include "hw/sysbus.h"
+#include "hw/nubus/mac-nubus-bridge.h"
+
+
+static void mac_nubus_bridge_init(Object *obj)
+{
+ MacNubusBridge *s = MAC_NUBUS_BRIDGE(obj);
+ NubusBridge *nb = NUBUS_BRIDGE(obj);
+ SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
+ NubusBus *bus = &nb->bus;
+
+ /* Macintosh only has slots 0x9 to 0xe available */
+ bus->slot_available_mask = MAKE_64BIT_MASK(MAC_NUBUS_FIRST_SLOT,
+ MAC_NUBUS_SLOT_NB);
+
+ /* Aliases for slots 0x9 to 0xe */
+ memory_region_init_alias(&s->super_slot_alias, obj, "super-slot-alias",
+ &bus->nubus_mr,
+ MAC_NUBUS_FIRST_SLOT * NUBUS_SUPER_SLOT_SIZE,
+ MAC_NUBUS_SLOT_NB * NUBUS_SUPER_SLOT_SIZE);
+
+ memory_region_init_alias(&s->slot_alias, obj, "slot-alias",
+ &bus->nubus_mr,
+ NUBUS_SLOT_BASE +
+ MAC_NUBUS_FIRST_SLOT * NUBUS_SLOT_SIZE,
+ MAC_NUBUS_SLOT_NB * NUBUS_SLOT_SIZE);
+
+ sysbus_init_mmio(sbd, &s->super_slot_alias);
+ sysbus_init_mmio(sbd, &s->slot_alias);
+}
+
+static void mac_nubus_bridge_class_init(ObjectClass *klass, void *data)
+{
+ DeviceClass *dc = DEVICE_CLASS(klass);
+
+ dc->desc = "Nubus bridge";
+}
+
+static const TypeInfo mac_nubus_bridge_info = {
+ .name = TYPE_MAC_NUBUS_BRIDGE,
+ .parent = TYPE_NUBUS_BRIDGE,
+ .instance_init = mac_nubus_bridge_init,
+ .instance_size = sizeof(MacNubusBridge),
+ .class_init = mac_nubus_bridge_class_init,
+};
+
+static void mac_nubus_bridge_register_types(void)
+{
+ type_register_static(&mac_nubus_bridge_info);
+}
+
+type_init(mac_nubus_bridge_register_types)
diff --git a/hw/nubus/meson.build b/hw/nubus/meson.build
new file mode 100644
index 000000000..9287c633a
--- /dev/null
+++ b/hw/nubus/meson.build
@@ -0,0 +1,7 @@
+nubus_ss = ss.source_set()
+nubus_ss.add(files('nubus-device.c'))
+nubus_ss.add(files('nubus-bus.c'))
+nubus_ss.add(files('nubus-bridge.c'))
+nubus_ss.add(when: 'CONFIG_Q800', if_true: files('mac-nubus-bridge.c'))
+
+softmmu_ss.add_all(when: 'CONFIG_NUBUS', if_true: nubus_ss)
diff --git a/hw/nubus/nubus-bridge.c b/hw/nubus/nubus-bridge.c
new file mode 100644
index 000000000..a42c86080
--- /dev/null
+++ b/hw/nubus/nubus-bridge.c
@@ -0,0 +1,53 @@
+/*
+ * QEMU Nubus
+ *
+ * Copyright (c) 2013-2018 Laurent Vivier <laurent@vivier.eu>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#include "qemu/osdep.h"
+#include "hw/sysbus.h"
+#include "hw/nubus/nubus.h"
+
+
+static void nubus_bridge_init(Object *obj)
+{
+ NubusBridge *s = NUBUS_BRIDGE(obj);
+ NubusBus *bus = &s->bus;
+
+ qbus_init(bus, sizeof(s->bus), TYPE_NUBUS_BUS, DEVICE(s), NULL);
+
+ qdev_init_gpio_out(DEVICE(s), bus->irqs, NUBUS_IRQS);
+}
+
+static Property nubus_bridge_properties[] = {
+ DEFINE_PROP_UINT16("slot-available-mask", NubusBridge,
+ bus.slot_available_mask, 0xffff),
+ DEFINE_PROP_END_OF_LIST()
+};
+
+static void nubus_bridge_class_init(ObjectClass *klass, void *data)
+{
+ DeviceClass *dc = DEVICE_CLASS(klass);
+
+ dc->fw_name = "nubus";
+ device_class_set_props(dc, nubus_bridge_properties);
+}
+
+static const TypeInfo nubus_bridge_info = {
+ .name = TYPE_NUBUS_BRIDGE,
+ .parent = TYPE_SYS_BUS_DEVICE,
+ .instance_init = nubus_bridge_init,
+ .instance_size = sizeof(NubusBridge),
+ .class_init = nubus_bridge_class_init,
+};
+
+static void nubus_register_types(void)
+{
+ type_register_static(&nubus_bridge_info);
+}
+
+type_init(nubus_register_types)
diff --git a/hw/nubus/nubus-bus.c b/hw/nubus/nubus-bus.c
new file mode 100644
index 000000000..07c279bde
--- /dev/null
+++ b/hw/nubus/nubus-bus.c
@@ -0,0 +1,188 @@
+/*
+ * QEMU Macintosh Nubus
+ *
+ * Copyright (c) 2013-2018 Laurent Vivier <laurent@vivier.eu>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+/*
+ * References:
+ * Nubus Specification (TI)
+ * http://www.bitsavers.org/pdf/ti/nubus/2242825-0001_NuBus_Spec1983.pdf
+ *
+ * Designing Cards and Drivers for the Macintosh Family (Apple)
+ */
+
+#include "qemu/osdep.h"
+#include "hw/nubus/nubus.h"
+#include "qapi/error.h"
+#include "trace.h"
+
+
+static NubusBus *nubus_find(void)
+{
+ /* Returns NULL unless there is exactly one nubus device */
+ return NUBUS_BUS(object_resolve_path_type("", TYPE_NUBUS_BUS, NULL));
+}
+
+static MemTxResult nubus_slot_write(void *opaque, hwaddr addr, uint64_t val,
+ unsigned size, MemTxAttrs attrs)
+{
+ trace_nubus_slot_write(addr, val, size);
+ return MEMTX_DECODE_ERROR;
+}
+
+static MemTxResult nubus_slot_read(void *opaque, hwaddr addr, uint64_t *data,
+ unsigned size, MemTxAttrs attrs)
+{
+ trace_nubus_slot_read(addr, size);
+ return MEMTX_DECODE_ERROR;
+}
+
+static const MemoryRegionOps nubus_slot_ops = {
+ .read_with_attrs = nubus_slot_read,
+ .write_with_attrs = nubus_slot_write,
+ .endianness = DEVICE_BIG_ENDIAN,
+ .valid = {
+ .min_access_size = 1,
+ .max_access_size = 4,
+ },
+};
+
+static MemTxResult nubus_super_slot_write(void *opaque, hwaddr addr,
+ uint64_t val, unsigned size,
+ MemTxAttrs attrs)
+{
+ trace_nubus_super_slot_write(addr, val, size);
+ return MEMTX_DECODE_ERROR;
+}
+
+static MemTxResult nubus_super_slot_read(void *opaque, hwaddr addr,
+ uint64_t *data, unsigned size,
+ MemTxAttrs attrs)
+{
+ trace_nubus_super_slot_read(addr, size);
+ return MEMTX_DECODE_ERROR;
+}
+
+static const MemoryRegionOps nubus_super_slot_ops = {
+ .read_with_attrs = nubus_super_slot_read,
+ .write_with_attrs = nubus_super_slot_write,
+ .endianness = DEVICE_BIG_ENDIAN,
+ .valid = {
+ .min_access_size = 1,
+ .max_access_size = 4,
+ },
+};
+
+static void nubus_unrealize(BusState *bus)
+{
+ NubusBus *nubus = NUBUS_BUS(bus);
+
+ address_space_destroy(&nubus->nubus_as);
+}
+
+static void nubus_realize(BusState *bus, Error **errp)
+{
+ NubusBus *nubus = NUBUS_BUS(bus);
+
+ if (!nubus_find()) {
+ error_setg(errp, "at most one %s device is permitted", TYPE_NUBUS_BUS);
+ return;
+ }
+
+ address_space_init(&nubus->nubus_as, &nubus->nubus_mr, "nubus");
+}
+
+static void nubus_init(Object *obj)
+{
+ NubusBus *nubus = NUBUS_BUS(obj);
+
+ memory_region_init(&nubus->nubus_mr, obj, "nubus", 0x100000000);
+
+ memory_region_init_io(&nubus->super_slot_io, obj, &nubus_super_slot_ops,
+ nubus, "nubus-super-slots",
+ (NUBUS_SUPER_SLOT_NB + 1) * NUBUS_SUPER_SLOT_SIZE);
+ memory_region_add_subregion(&nubus->nubus_mr, 0x0, &nubus->super_slot_io);
+
+ memory_region_init_io(&nubus->slot_io, obj, &nubus_slot_ops,
+ nubus, "nubus-slots",
+ NUBUS_SLOT_NB * NUBUS_SLOT_SIZE);
+ memory_region_add_subregion(&nubus->nubus_mr,
+ (NUBUS_SUPER_SLOT_NB + 1) *
+ NUBUS_SUPER_SLOT_SIZE, &nubus->slot_io);
+
+ nubus->slot_available_mask = MAKE_64BIT_MASK(NUBUS_FIRST_SLOT,
+ NUBUS_SLOT_NB);
+}
+
+static char *nubus_get_dev_path(DeviceState *dev)
+{
+ NubusDevice *nd = NUBUS_DEVICE(dev);
+ BusState *bus = qdev_get_parent_bus(dev);
+ char *p = qdev_get_dev_path(bus->parent);
+
+ if (p) {
+ char *ret = g_strdup_printf("%s/%s/%02x", p, bus->name, nd->slot);
+ g_free(p);
+ return ret;
+ } else {
+ return g_strdup_printf("%s/%02x", bus->name, nd->slot);
+ }
+}
+
+static bool nubus_check_address(BusState *bus, DeviceState *dev, Error **errp)
+{
+ NubusDevice *nd = NUBUS_DEVICE(dev);
+ NubusBus *nubus = NUBUS_BUS(bus);
+
+ if (nd->slot == -1) {
+ /* No slot specified, find first available free slot */
+ int s = ctz32(nubus->slot_available_mask);
+ if (s != 32) {
+ nd->slot = s;
+ } else {
+ error_setg(errp, "Cannot register nubus card, no free slot "
+ "available");
+ return false;
+ }
+ } else {
+ /* Slot specified, make sure the slot is available */
+ if (!(nubus->slot_available_mask & BIT(nd->slot))) {
+ error_setg(errp, "Cannot register nubus card, slot %d is "
+ "unavailable or already occupied", nd->slot);
+ return false;
+ }
+ }
+
+ nubus->slot_available_mask &= ~BIT(nd->slot);
+ return true;
+}
+
+static void nubus_class_init(ObjectClass *oc, void *data)
+{
+ BusClass *bc = BUS_CLASS(oc);
+
+ bc->realize = nubus_realize;
+ bc->unrealize = nubus_unrealize;
+ bc->check_address = nubus_check_address;
+ bc->get_dev_path = nubus_get_dev_path;
+}
+
+static const TypeInfo nubus_bus_info = {
+ .name = TYPE_NUBUS_BUS,
+ .parent = TYPE_BUS,
+ .instance_size = sizeof(NubusBus),
+ .instance_init = nubus_init,
+ .class_init = nubus_class_init,
+};
+
+static void nubus_register_types(void)
+{
+ type_register_static(&nubus_bus_info);
+}
+
+type_init(nubus_register_types)
diff --git a/hw/nubus/nubus-device.c b/hw/nubus/nubus-device.c
new file mode 100644
index 000000000..0f1852f67
--- /dev/null
+++ b/hw/nubus/nubus-device.c
@@ -0,0 +1,120 @@
+/*
+ * QEMU Macintosh Nubus
+ *
+ * Copyright (c) 2013-2018 Laurent Vivier <laurent@vivier.eu>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/datadir.h"
+#include "hw/irq.h"
+#include "hw/loader.h"
+#include "hw/nubus/nubus.h"
+#include "qapi/error.h"
+#include "qemu/error-report.h"
+
+
+void nubus_set_irq(NubusDevice *nd, int level)
+{
+ NubusBus *nubus = NUBUS_BUS(qdev_get_parent_bus(DEVICE(nd)));
+
+ qemu_set_irq(nubus->irqs[nd->slot], level);
+}
+
+static void nubus_device_realize(DeviceState *dev, Error **errp)
+{
+ NubusBus *nubus = NUBUS_BUS(qdev_get_parent_bus(dev));
+ NubusDevice *nd = NUBUS_DEVICE(dev);
+ char *name, *path;
+ hwaddr slot_offset;
+ int64_t size;
+ int ret;
+
+ /* Super */
+ slot_offset = nd->slot * NUBUS_SUPER_SLOT_SIZE;
+
+ name = g_strdup_printf("nubus-super-slot-%x", nd->slot);
+ memory_region_init(&nd->super_slot_mem, OBJECT(dev), name,
+ NUBUS_SUPER_SLOT_SIZE);
+ memory_region_add_subregion(&nubus->super_slot_io, slot_offset,
+ &nd->super_slot_mem);
+ g_free(name);
+
+ /* Normal */
+ slot_offset = nd->slot * NUBUS_SLOT_SIZE;
+
+ name = g_strdup_printf("nubus-slot-%x", nd->slot);
+ memory_region_init(&nd->slot_mem, OBJECT(dev), name, NUBUS_SLOT_SIZE);
+ memory_region_add_subregion(&nubus->slot_io, slot_offset,
+ &nd->slot_mem);
+ g_free(name);
+
+ /* Declaration ROM */
+ if (nd->romfile != NULL) {
+ path = qemu_find_file(QEMU_FILE_TYPE_BIOS, nd->romfile);
+ if (path == NULL) {
+ path = g_strdup(nd->romfile);
+ }
+
+ size = get_image_size(path);
+ if (size < 0) {
+ error_setg(errp, "failed to find romfile \"%s\"", nd->romfile);
+ g_free(path);
+ return;
+ } else if (size == 0) {
+ error_setg(errp, "romfile \"%s\" is empty", nd->romfile);
+ g_free(path);
+ return;
+ } else if (size > NUBUS_DECL_ROM_MAX_SIZE) {
+ error_setg(errp, "romfile \"%s\" too large (maximum size 128K)",
+ nd->romfile);
+ g_free(path);
+ return;
+ }
+
+ name = g_strdup_printf("nubus-slot-%x-declaration-rom", nd->slot);
+ memory_region_init_rom(&nd->decl_rom, OBJECT(dev), name, size,
+ &error_abort);
+ ret = load_image_mr(path, &nd->decl_rom);
+ g_free(path);
+ if (ret < 0) {
+ error_setg(errp, "could not load romfile \"%s\"", nd->romfile);
+ return;
+ }
+ memory_region_add_subregion(&nd->slot_mem, NUBUS_SLOT_SIZE - size,
+ &nd->decl_rom);
+ }
+}
+
+static Property nubus_device_properties[] = {
+ DEFINE_PROP_INT32("slot", NubusDevice, slot, -1),
+ DEFINE_PROP_STRING("romfile", NubusDevice, romfile),
+ DEFINE_PROP_END_OF_LIST()
+};
+
+static void nubus_device_class_init(ObjectClass *oc, void *data)
+{
+ DeviceClass *dc = DEVICE_CLASS(oc);
+
+ dc->realize = nubus_device_realize;
+ dc->bus_type = TYPE_NUBUS_BUS;
+ device_class_set_props(dc, nubus_device_properties);
+}
+
+static const TypeInfo nubus_device_type_info = {
+ .name = TYPE_NUBUS_DEVICE,
+ .parent = TYPE_DEVICE,
+ .abstract = true,
+ .instance_size = sizeof(NubusDevice),
+ .class_init = nubus_device_class_init,
+};
+
+static void nubus_register_types(void)
+{
+ type_register_static(&nubus_device_type_info);
+}
+
+type_init(nubus_register_types)
diff --git a/hw/nubus/trace-events b/hw/nubus/trace-events
new file mode 100644
index 000000000..e31833d69
--- /dev/null
+++ b/hw/nubus/trace-events
@@ -0,0 +1,7 @@
+# See docs/devel/tracing.txt for syntax documentation.
+
+# nubus-bus.c
+nubus_slot_read(uint64_t addr, int size) "reading unassigned addr 0x%"PRIx64 " size %d"
+nubus_slot_write(uint64_t addr, uint64_t val, int size) "writing unassigned addr 0x%"PRIx64 " value 0x%"PRIx64 " size %d"
+nubus_super_slot_read(uint64_t addr, int size) "reading unassigned addr 0x%"PRIx64 " size %d"
+nubus_super_slot_write(uint64_t addr, uint64_t val, int size) "writing unassigned addr 0x%"PRIx64 " value 0x%"PRIx64 " size %d"
diff --git a/hw/nubus/trace.h b/hw/nubus/trace.h
new file mode 100644
index 000000000..3749420da
--- /dev/null
+++ b/hw/nubus/trace.h
@@ -0,0 +1 @@
+#include "trace/trace-hw_nubus.h"