All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/20] nubus: bus, device, bridge, IRQ and address space improvements
@ 2021-09-12  7:48 Mark Cave-Ayland
  2021-09-12  7:48 ` [PATCH 01/20] nubus-device: rename slot_nb variable to slot Mark Cave-Ayland
                   ` (20 more replies)
  0 siblings, 21 replies; 47+ messages in thread
From: Mark Cave-Ayland @ 2021-09-12  7:48 UTC (permalink / raw)
  To: qemu-devel, laurent

This patchset is the next set of changes required to boot MacOS on the q800 machine. The
main aim of these patches is to improve the Nubus support so that devices can be plugged
into the Nubus from the command line i.e.

    -device nubus-macfb[,romfile=decl.rom]

At the moment the only device that can be plugged into the Nubus is the macfb framebuffer
however with these changes it is possible to take a ROM from a real Nubus card and
attempt to use it in QEMU, and also allow for future interfaces such as virtio.

Patches 1 to 6 move the logic which manages bus addresses from the NubusDevice into
the NubusBus itself, including the introduction of a bitmap to manage available
slots on the bus.

Patches 7 and 8 change the handling for unassigned (empty) slots to generate a bus
fault and add trace events to allow logging of empty slot accesses during Nubus
enumeration.

Patches 9 to 11 remove the existing stubs for generating the format block (the epilogue
of the Nubus device embedded ROM consisting of metadata and a checksum) and replace them
with a romfile device property to allow the entire Nubus ROM to be loaded from a file
into the ROM area, similar to a PCI option ROM.

Patch 12 moves the Nubus into its own separate address space whilst patches 13 to 17
update the NubusBridge (and MacNubusBridge) devices to allow machines to map the
required slots from the Nubus address space using sysbus_mmio_map().

Finally patches 18 to 20 add support for Nubus IRQs and wire them up appropriately for
the q800 machine through VIA2, which is required for the next set of macfb updates.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>


Mark Cave-Ayland (20):
  nubus-device: rename slot_nb variable to slot
  nubus-device: expose separate super slot memory region
  nubus-device: add device slot parameter
  nubus: use bitmap to manage available slots
  nubus: move slot bitmap checks from NubusDevice realize() to BusClass
    check_address()
  nubus: implement BusClass get_dev_path()
  nubus: add trace-events for unassigned slot accesses
  nubus: generate bus error when attempting to access empty slots
  macfb: don't register declaration ROM
  nubus-device: remove nubus_register_rom() and
    nubus_register_format_block()
  nubus-device: add romfile property for loading declaration ROMs
  nubus: move nubus to its own 32-bit address space
  nubus-bridge: introduce separate NubusBridge structure
  mac-nubus-bridge: rename MacNubusState to MacNubusBridge
  nubus: move NubusBus from mac-nubus-bridge to nubus-bridge
  nubus-bridge: embed the NubusBus object directly within nubus-bridge
  nubus-bridge: make slot_available_mask a qdev property
  nubus: add support for slot IRQs
  q800: wire up nubus IRQs
  q800: configure nubus available slots for Quadra 800

 hw/display/macfb.c                  |   6 -
 hw/m68k/q800.c                      |  24 ++-
 hw/nubus/mac-nubus-bridge.c         |  28 +++-
 hw/nubus/nubus-bridge.c             |  23 ++-
 hw/nubus/nubus-bus.c                | 117 +++++++++++---
 hw/nubus/nubus-device.c             | 226 ++++++++--------------------
 hw/nubus/trace-events               |   7 +
 hw/nubus/trace.h                    |   1 +
 include/hw/nubus/mac-nubus-bridge.h |   9 +-
 include/hw/nubus/nubus.h            |  47 +++---
 meson.build                         |   1 +
 11 files changed, 263 insertions(+), 226 deletions(-)
 create mode 100644 hw/nubus/trace-events
 create mode 100644 hw/nubus/trace.h

-- 
2.20.1



^ permalink raw reply	[flat|nested] 47+ messages in thread

* [PATCH 01/20] nubus-device: rename slot_nb variable to slot
  2021-09-12  7:48 [PATCH 00/20] nubus: bus, device, bridge, IRQ and address space improvements Mark Cave-Ayland
@ 2021-09-12  7:48 ` Mark Cave-Ayland
  2021-09-12 15:09   ` Philippe Mathieu-Daudé
  2021-09-12  7:48 ` [PATCH 02/20] nubus-device: expose separate super slot memory region Mark Cave-Ayland
                   ` (19 subsequent siblings)
  20 siblings, 1 reply; 47+ messages in thread
From: Mark Cave-Ayland @ 2021-09-12  7:48 UTC (permalink / raw)
  To: qemu-devel, laurent

This is in preparation for creating a qdev property of the same name.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
 hw/nubus/nubus-device.c  | 14 +++++++-------
 include/hw/nubus/nubus.h |  2 +-
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/hw/nubus/nubus-device.c b/hw/nubus/nubus-device.c
index ffe78a8823..be01269563 100644
--- a/hw/nubus/nubus-device.c
+++ b/hw/nubus/nubus-device.c
@@ -87,7 +87,7 @@ static void nubus_register_format_block(NubusDevice *dev)
     char *fblock_name;
 
     fblock_name = g_strdup_printf("nubus-slot-%d-format-block",
-                                  dev->slot_nb);
+                                  dev->slot);
 
     hwaddr fblock_offset = memory_region_size(&dev->slot_mem) - FBLOCK_SIZE;
     memory_region_init_io(&dev->fblock_io, NULL, &nubus_format_block_ops,
@@ -142,7 +142,7 @@ void nubus_register_rom(NubusDevice *dev, const uint8_t *rom, uint32_t size,
     /* ROM */
 
     dev->rom = rom;
-    rom_name = g_strdup_printf("nubus-slot-%d-rom", dev->slot_nb);
+    rom_name = g_strdup_printf("nubus-slot-%d-rom", dev->slot);
     memory_region_init_io(&dev->rom_io, NULL, &mac_nubus_rom_ops,
                           dev, rom_name, size);
     memory_region_set_readonly(&dev->rom_io, true);
@@ -167,12 +167,12 @@ static void nubus_device_realize(DeviceState *dev, Error **errp)
         return;
     }
 
-    nd->slot_nb = nubus->current_slot++;
-    name = g_strdup_printf("nubus-slot-%d", nd->slot_nb);
+    nd->slot = nubus->current_slot++;
+    name = g_strdup_printf("nubus-slot-%d", nd->slot);
 
-    if (nd->slot_nb < NUBUS_FIRST_SLOT) {
+    if (nd->slot < NUBUS_FIRST_SLOT) {
         /* Super */
-        slot_offset = (nd->slot_nb - 6) * NUBUS_SUPER_SLOT_SIZE;
+        slot_offset = (nd->slot - 6) * NUBUS_SUPER_SLOT_SIZE;
 
         memory_region_init(&nd->slot_mem, OBJECT(dev), name,
                            NUBUS_SUPER_SLOT_SIZE);
@@ -180,7 +180,7 @@ static void nubus_device_realize(DeviceState *dev, Error **errp)
                                     &nd->slot_mem);
     } else {
         /* Normal */
-        slot_offset = nd->slot_nb * NUBUS_SLOT_SIZE;
+        slot_offset = nd->slot * NUBUS_SLOT_SIZE;
 
         memory_region_init(&nd->slot_mem, OBJECT(dev), name, NUBUS_SLOT_SIZE);
         memory_region_add_subregion(&nubus->slot_io, slot_offset,
diff --git a/include/hw/nubus/nubus.h b/include/hw/nubus/nubus.h
index e2b5cf260b..424309dd73 100644
--- a/include/hw/nubus/nubus.h
+++ b/include/hw/nubus/nubus.h
@@ -42,7 +42,7 @@ struct NubusBus {
 struct NubusDevice {
     DeviceState qdev;
 
-    int slot_nb;
+    int slot;
     MemoryRegion slot_mem;
 
     /* Format Block */
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [PATCH 02/20] nubus-device: expose separate super slot memory region
  2021-09-12  7:48 [PATCH 00/20] nubus: bus, device, bridge, IRQ and address space improvements Mark Cave-Ayland
  2021-09-12  7:48 ` [PATCH 01/20] nubus-device: rename slot_nb variable to slot Mark Cave-Ayland
@ 2021-09-12  7:48 ` Mark Cave-Ayland
  2021-09-12 15:50   ` Philippe Mathieu-Daudé
  2021-09-12  7:48 ` [PATCH 03/20] nubus-device: add device slot parameter Mark Cave-Ayland
                   ` (18 subsequent siblings)
  20 siblings, 1 reply; 47+ messages in thread
From: Mark Cave-Ayland @ 2021-09-12  7:48 UTC (permalink / raw)
  To: qemu-devel, laurent

According to "Designing Cards and Drivers for the Macintosh Family" each physical
nubus slot can access 2 separate address ranges: a super slot memory region which
is 256MB and a standard slot memory region which is 16MB.

Currently a Nubus device uses the physical slot number to determine whether it is
using a standard slot memory region or a super slot memory region rather than
exposing both memory regions for use as required.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
 hw/nubus/nubus-device.c  | 36 ++++++++++++++++++------------------
 include/hw/nubus/nubus.h |  1 +
 2 files changed, 19 insertions(+), 18 deletions(-)

diff --git a/hw/nubus/nubus-device.c b/hw/nubus/nubus-device.c
index be01269563..36203848e5 100644
--- a/hw/nubus/nubus-device.c
+++ b/hw/nubus/nubus-device.c
@@ -168,26 +168,26 @@ static void nubus_device_realize(DeviceState *dev, Error **errp)
     }
 
     nd->slot = nubus->current_slot++;
-    name = g_strdup_printf("nubus-slot-%d", nd->slot);
-
-    if (nd->slot < NUBUS_FIRST_SLOT) {
-        /* Super */
-        slot_offset = (nd->slot - 6) * NUBUS_SUPER_SLOT_SIZE;
-
-        memory_region_init(&nd->slot_mem, OBJECT(dev), name,
-                           NUBUS_SUPER_SLOT_SIZE);
-        memory_region_add_subregion(&nubus->super_slot_io, slot_offset,
-                                    &nd->slot_mem);
-    } else {
-        /* Normal */
-        slot_offset = nd->slot * NUBUS_SLOT_SIZE;
-
-        memory_region_init(&nd->slot_mem, OBJECT(dev), name, NUBUS_SLOT_SIZE);
-        memory_region_add_subregion(&nubus->slot_io, slot_offset,
-                                    &nd->slot_mem);
-    }
 
+    /* Super */
+    slot_offset = (nd->slot - 6) * 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);
+
     nubus_register_format_block(nd);
 }
 
diff --git a/include/hw/nubus/nubus.h b/include/hw/nubus/nubus.h
index 424309dd73..89b0976aaa 100644
--- a/include/hw/nubus/nubus.h
+++ b/include/hw/nubus/nubus.h
@@ -43,6 +43,7 @@ struct NubusDevice {
     DeviceState qdev;
 
     int slot;
+    MemoryRegion super_slot_mem;
     MemoryRegion slot_mem;
 
     /* Format Block */
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [PATCH 03/20] nubus-device: add device slot parameter
  2021-09-12  7:48 [PATCH 00/20] nubus: bus, device, bridge, IRQ and address space improvements Mark Cave-Ayland
  2021-09-12  7:48 ` [PATCH 01/20] nubus-device: rename slot_nb variable to slot Mark Cave-Ayland
  2021-09-12  7:48 ` [PATCH 02/20] nubus-device: expose separate super slot memory region Mark Cave-Ayland
@ 2021-09-12  7:48 ` Mark Cave-Ayland
  2021-09-12 15:15   ` Philippe Mathieu-Daudé
  2021-09-12  7:48 ` [PATCH 04/20] nubus: use bitmap to manage available slots Mark Cave-Ayland
                   ` (17 subsequent siblings)
  20 siblings, 1 reply; 47+ messages in thread
From: Mark Cave-Ayland @ 2021-09-12  7:48 UTC (permalink / raw)
  To: qemu-devel, laurent

This prepares for allowing Nubus devices to be placed in a specific slot instead
of always being auto-allocated by the bus itself.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
 hw/nubus/nubus-device.c  | 6 ++++++
 include/hw/nubus/nubus.h | 2 +-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/hw/nubus/nubus-device.c b/hw/nubus/nubus-device.c
index 36203848e5..c1832f73da 100644
--- a/hw/nubus/nubus-device.c
+++ b/hw/nubus/nubus-device.c
@@ -191,12 +191,18 @@ static void nubus_device_realize(DeviceState *dev, Error **errp)
     nubus_register_format_block(nd);
 }
 
+static Property nubus_device_properties[] = {
+    DEFINE_PROP_INT32("slot", NubusDevice, slot, -1),
+    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 = {
diff --git a/include/hw/nubus/nubus.h b/include/hw/nubus/nubus.h
index 89b0976aaa..357f621d15 100644
--- a/include/hw/nubus/nubus.h
+++ b/include/hw/nubus/nubus.h
@@ -42,7 +42,7 @@ struct NubusBus {
 struct NubusDevice {
     DeviceState qdev;
 
-    int slot;
+    int32_t slot;
     MemoryRegion super_slot_mem;
     MemoryRegion slot_mem;
 
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [PATCH 04/20] nubus: use bitmap to manage available slots
  2021-09-12  7:48 [PATCH 00/20] nubus: bus, device, bridge, IRQ and address space improvements Mark Cave-Ayland
                   ` (2 preceding siblings ...)
  2021-09-12  7:48 ` [PATCH 03/20] nubus-device: add device slot parameter Mark Cave-Ayland
@ 2021-09-12  7:48 ` Mark Cave-Ayland
  2021-09-12 17:48   ` Philippe Mathieu-Daudé
  2021-09-12  7:48 ` [PATCH 05/20] nubus: move slot bitmap checks from NubusDevice realize() to BusClass check_address() Mark Cave-Ayland
                   ` (16 subsequent siblings)
  20 siblings, 1 reply; 47+ messages in thread
From: Mark Cave-Ayland @ 2021-09-12  7:48 UTC (permalink / raw)
  To: qemu-devel, laurent

Convert nubus_device_realize() to use a bitmap to manage available slots to allow
for future Nubus devices to be plugged into arbitrary slots from the command line.

Update mac_nubus_bridge_init() to only allow slots 0x9 to 0xe on a Macintosh
machines as documented in "Desigining Cards and Drivers for the Macintosh Family".

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
 hw/nubus/mac-nubus-bridge.c |  3 +++
 hw/nubus/nubus-bus.c        |  2 +-
 hw/nubus/nubus-device.c     | 33 +++++++++++++++++++++++++++------
 include/hw/nubus/nubus.h    |  4 ++--
 4 files changed, 33 insertions(+), 9 deletions(-)

diff --git a/hw/nubus/mac-nubus-bridge.c b/hw/nubus/mac-nubus-bridge.c
index 7c329300b8..6e78f4c0b3 100644
--- a/hw/nubus/mac-nubus-bridge.c
+++ b/hw/nubus/mac-nubus-bridge.c
@@ -18,6 +18,9 @@ static void mac_nubus_bridge_init(Object *obj)
 
     s->bus = NUBUS_BUS(qbus_create(TYPE_NUBUS_BUS, DEVICE(s), NULL));
 
+    /* Macintosh only has slots 0x9 to 0xe available */
+    s->bus->slot_available_mask = 0x7e00;
+
     sysbus_init_mmio(sbd, &s->bus->super_slot_io);
     sysbus_init_mmio(sbd, &s->bus->slot_io);
 }
diff --git a/hw/nubus/nubus-bus.c b/hw/nubus/nubus-bus.c
index 5c13452308..f6d3655f51 100644
--- a/hw/nubus/nubus-bus.c
+++ b/hw/nubus/nubus-bus.c
@@ -84,7 +84,7 @@ static void nubus_init(Object *obj)
                           nubus, "nubus-slots",
                           NUBUS_SLOT_NB * NUBUS_SLOT_SIZE);
 
-    nubus->current_slot = NUBUS_FIRST_SLOT;
+    nubus->slot_available_mask = 0xffff;
 }
 
 static void nubus_class_init(ObjectClass *oc, void *data)
diff --git a/hw/nubus/nubus-device.c b/hw/nubus/nubus-device.c
index c1832f73da..f9f614cc01 100644
--- a/hw/nubus/nubus-device.c
+++ b/hw/nubus/nubus-device.c
@@ -160,14 +160,35 @@ static void nubus_device_realize(DeviceState *dev, Error **errp)
     NubusDevice *nd = NUBUS_DEVICE(dev);
     char *name;
     hwaddr slot_offset;
-
-    if (nubus->current_slot < NUBUS_FIRST_SLOT ||
-            nubus->current_slot > NUBUS_LAST_SLOT) {
-        error_setg(errp, "Cannot register nubus card, not enough slots");
-        return;
+    uint16_t s;
+
+    if (nd->slot == -1) {
+        /* No slot specified, find first available free slot */
+        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;
+        }
+    } else {
+        /* Slot specified, make sure the slot is available */
+        if (nd->slot < NUBUS_FIRST_SLOT || nd->slot > NUBUS_LAST_SLOT) {
+            error_setg(errp, "Cannot register nubus card, slot must be "
+                             "between %d and %d", NUBUS_FIRST_SLOT,
+                             NUBUS_LAST_SLOT);
+            return;
+        }
+
+        if (!(nubus->slot_available_mask & (1UL << nd->slot))) {
+            error_setg(errp, "Cannot register nubus card, slot %d is "
+                             "unavailable or already occupied", nd->slot);
+            return;
+        }
     }
 
-    nd->slot = nubus->current_slot++;
+    nubus->slot_available_mask &= ~(1UL << nd->slot);
 
     /* Super */
     slot_offset = (nd->slot - 6) * NUBUS_SUPER_SLOT_SIZE;
diff --git a/include/hw/nubus/nubus.h b/include/hw/nubus/nubus.h
index 357f621d15..8ff4736259 100644
--- a/include/hw/nubus/nubus.h
+++ b/include/hw/nubus/nubus.h
@@ -19,7 +19,7 @@
 #define NUBUS_SLOT_SIZE       0x01000000
 #define NUBUS_SLOT_NB         0xF
 
-#define NUBUS_FIRST_SLOT      0x9
+#define NUBUS_FIRST_SLOT      0x0
 #define NUBUS_LAST_SLOT       0xF
 
 #define TYPE_NUBUS_DEVICE "nubus-device"
@@ -36,7 +36,7 @@ struct NubusBus {
     MemoryRegion super_slot_io;
     MemoryRegion slot_io;
 
-    int current_slot;
+    uint32_t slot_available_mask;
 };
 
 struct NubusDevice {
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [PATCH 05/20] nubus: move slot bitmap checks from NubusDevice realize() to BusClass check_address()
  2021-09-12  7:48 [PATCH 00/20] nubus: bus, device, bridge, IRQ and address space improvements Mark Cave-Ayland
                   ` (3 preceding siblings ...)
  2021-09-12  7:48 ` [PATCH 04/20] nubus: use bitmap to manage available slots Mark Cave-Ayland
@ 2021-09-12  7:48 ` Mark Cave-Ayland
  2021-09-12  7:49 ` [PATCH 06/20] nubus: implement BusClass get_dev_path() Mark Cave-Ayland
                   ` (15 subsequent siblings)
  20 siblings, 0 replies; 47+ messages in thread
From: Mark Cave-Ayland @ 2021-09-12  7:48 UTC (permalink / raw)
  To: qemu-devel, laurent

Allow Nubus to manage the slot allocations itself using the BusClass check_address()
virtual function rather than managing this during NubusDevice realize().

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
 hw/nubus/nubus-bus.c    | 37 +++++++++++++++++++++++++++++++++++++
 hw/nubus/nubus-device.c | 29 -----------------------------
 2 files changed, 37 insertions(+), 29 deletions(-)

diff --git a/hw/nubus/nubus-bus.c b/hw/nubus/nubus-bus.c
index f6d3655f51..c59867632d 100644
--- a/hw/nubus/nubus-bus.c
+++ b/hw/nubus/nubus-bus.c
@@ -87,11 +87,48 @@ static void nubus_init(Object *obj)
     nubus->slot_available_mask = 0xffff;
 }
 
+static bool nubus_check_address(BusState *bus, DeviceState *dev, Error **errp)
+{
+    NubusDevice *nd = NUBUS_DEVICE(dev);
+    NubusBus *nubus = NUBUS_BUS(bus);
+    uint16_t s;
+
+    if (nd->slot == -1) {
+        /* No slot specified, find first available free slot */
+        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 (nd->slot < NUBUS_FIRST_SLOT || nd->slot > NUBUS_LAST_SLOT) {
+            error_setg(errp, "Cannot register nubus card, slot must be "
+                             "between %d and %d", NUBUS_FIRST_SLOT,
+                             NUBUS_LAST_SLOT);
+            return false;
+        }
+
+        if (!(nubus->slot_available_mask & (1UL << nd->slot))) {
+            error_setg(errp, "Cannot register nubus card, slot %d is "
+                             "unavailable or already occupied", nd->slot);
+            return false;
+        }
+    }
+
+    nubus->slot_available_mask &= ~(1UL << nd->slot);
+    return true;
+}
+
 static void nubus_class_init(ObjectClass *oc, void *data)
 {
     BusClass *bc = BUS_CLASS(oc);
 
     bc->realize = nubus_realize;
+    bc->check_address = nubus_check_address;
 }
 
 static const TypeInfo nubus_bus_info = {
diff --git a/hw/nubus/nubus-device.c b/hw/nubus/nubus-device.c
index f9f614cc01..7a32c8c95b 100644
--- a/hw/nubus/nubus-device.c
+++ b/hw/nubus/nubus-device.c
@@ -160,35 +160,6 @@ static void nubus_device_realize(DeviceState *dev, Error **errp)
     NubusDevice *nd = NUBUS_DEVICE(dev);
     char *name;
     hwaddr slot_offset;
-    uint16_t s;
-
-    if (nd->slot == -1) {
-        /* No slot specified, find first available free slot */
-        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;
-        }
-    } else {
-        /* Slot specified, make sure the slot is available */
-        if (nd->slot < NUBUS_FIRST_SLOT || nd->slot > NUBUS_LAST_SLOT) {
-            error_setg(errp, "Cannot register nubus card, slot must be "
-                             "between %d and %d", NUBUS_FIRST_SLOT,
-                             NUBUS_LAST_SLOT);
-            return;
-        }
-
-        if (!(nubus->slot_available_mask & (1UL << nd->slot))) {
-            error_setg(errp, "Cannot register nubus card, slot %d is "
-                             "unavailable or already occupied", nd->slot);
-            return;
-        }
-    }
-
-    nubus->slot_available_mask &= ~(1UL << nd->slot);
 
     /* Super */
     slot_offset = (nd->slot - 6) * NUBUS_SUPER_SLOT_SIZE;
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [PATCH 06/20] nubus: implement BusClass get_dev_path()
  2021-09-12  7:48 [PATCH 00/20] nubus: bus, device, bridge, IRQ and address space improvements Mark Cave-Ayland
                   ` (4 preceding siblings ...)
  2021-09-12  7:48 ` [PATCH 05/20] nubus: move slot bitmap checks from NubusDevice realize() to BusClass check_address() Mark Cave-Ayland
@ 2021-09-12  7:49 ` Mark Cave-Ayland
  2021-09-12 15:16   ` Philippe Mathieu-Daudé
  2021-09-12  7:49 ` [PATCH 07/20] nubus: add trace-events for unassigned slot accesses Mark Cave-Ayland
                   ` (14 subsequent siblings)
  20 siblings, 1 reply; 47+ messages in thread
From: Mark Cave-Ayland @ 2021-09-12  7:49 UTC (permalink / raw)
  To: qemu-devel, laurent

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
 hw/nubus/nubus-bus.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/hw/nubus/nubus-bus.c b/hw/nubus/nubus-bus.c
index c59867632d..f5ce899933 100644
--- a/hw/nubus/nubus-bus.c
+++ b/hw/nubus/nubus-bus.c
@@ -87,6 +87,21 @@ static void nubus_init(Object *obj)
     nubus->slot_available_mask = 0xffff;
 }
 
+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);
@@ -129,6 +144,7 @@ static void nubus_class_init(ObjectClass *oc, void *data)
 
     bc->realize = nubus_realize;
     bc->check_address = nubus_check_address;
+    bc->get_dev_path = nubus_get_dev_path;
 }
 
 static const TypeInfo nubus_bus_info = {
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [PATCH 07/20] nubus: add trace-events for unassigned slot accesses
  2021-09-12  7:48 [PATCH 00/20] nubus: bus, device, bridge, IRQ and address space improvements Mark Cave-Ayland
                   ` (5 preceding siblings ...)
  2021-09-12  7:49 ` [PATCH 06/20] nubus: implement BusClass get_dev_path() Mark Cave-Ayland
@ 2021-09-12  7:49 ` Mark Cave-Ayland
  2021-09-12 15:18   ` Philippe Mathieu-Daudé
  2021-09-12  7:49 ` [PATCH 08/20] nubus: generate bus error when attempting to access empty slots Mark Cave-Ayland
                   ` (13 subsequent siblings)
  20 siblings, 1 reply; 47+ messages in thread
From: Mark Cave-Ayland @ 2021-09-12  7:49 UTC (permalink / raw)
  To: qemu-devel, laurent

These allow tracing of the Nubus enumeration process by the guest OS.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
 hw/nubus/nubus-bus.c  | 10 +++++++---
 hw/nubus/trace-events |  7 +++++++
 hw/nubus/trace.h      |  1 +
 meson.build           |  1 +
 4 files changed, 16 insertions(+), 3 deletions(-)
 create mode 100644 hw/nubus/trace-events
 create mode 100644 hw/nubus/trace.h

diff --git a/hw/nubus/nubus-bus.c b/hw/nubus/nubus-bus.c
index f5ce899933..e250abfda0 100644
--- a/hw/nubus/nubus-bus.c
+++ b/hw/nubus/nubus-bus.c
@@ -11,6 +11,7 @@
 #include "qemu/osdep.h"
 #include "hw/nubus/nubus.h"
 #include "qapi/error.h"
+#include "trace.h"
 
 
 static NubusBus *nubus_find(void)
@@ -23,12 +24,13 @@ static void nubus_slot_write(void *opaque, hwaddr addr, uint64_t val,
                              unsigned int size)
 {
     /* read only */
+    trace_nubus_slot_write(addr, val, size);
 }
 
-
 static uint64_t nubus_slot_read(void *opaque, hwaddr addr,
                                 unsigned int size)
 {
+    trace_nubus_slot_read(addr, size);
     return 0;
 }
 
@@ -38,7 +40,7 @@ static const MemoryRegionOps nubus_slot_ops = {
     .endianness = DEVICE_BIG_ENDIAN,
     .valid = {
         .min_access_size = 1,
-        .max_access_size = 1,
+        .max_access_size = 4,
     },
 };
 
@@ -46,11 +48,13 @@ static void nubus_super_slot_write(void *opaque, hwaddr addr, uint64_t val,
                                    unsigned int size)
 {
     /* read only */
+    trace_nubus_super_slot_write(addr, val, size);
 }
 
 static uint64_t nubus_super_slot_read(void *opaque, hwaddr addr,
                                       unsigned int size)
 {
+    trace_nubus_super_slot_read(addr, size);
     return 0;
 }
 
@@ -60,7 +64,7 @@ static const MemoryRegionOps nubus_super_slot_ops = {
     .endianness = DEVICE_BIG_ENDIAN,
     .valid = {
         .min_access_size = 1,
-        .max_access_size = 1,
+        .max_access_size = 4,
     },
 };
 
diff --git a/hw/nubus/trace-events b/hw/nubus/trace-events
new file mode 100644
index 0000000000..e31833d694
--- /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 0000000000..3749420da1
--- /dev/null
+++ b/hw/nubus/trace.h
@@ -0,0 +1 @@
+#include "trace/trace-hw_nubus.h"
diff --git a/meson.build b/meson.build
index 7e58e6279b..727ac5a19d 100644
--- a/meson.build
+++ b/meson.build
@@ -2135,6 +2135,7 @@ if have_system
     'hw/misc/macio',
     'hw/net',
     'hw/net/can',
+    'hw/nubus',
     'hw/nvme',
     'hw/nvram',
     'hw/pci',
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [PATCH 08/20] nubus: generate bus error when attempting to access empty slots
  2021-09-12  7:48 [PATCH 00/20] nubus: bus, device, bridge, IRQ and address space improvements Mark Cave-Ayland
                   ` (6 preceding siblings ...)
  2021-09-12  7:49 ` [PATCH 07/20] nubus: add trace-events for unassigned slot accesses Mark Cave-Ayland
@ 2021-09-12  7:49 ` Mark Cave-Ayland
  2021-09-12 15:19   ` Philippe Mathieu-Daudé
  2021-09-12  7:49 ` [PATCH 09/20] macfb: don't register declaration ROM Mark Cave-Ayland
                   ` (12 subsequent siblings)
  20 siblings, 1 reply; 47+ messages in thread
From: Mark Cave-Ayland @ 2021-09-12  7:49 UTC (permalink / raw)
  To: qemu-devel, laurent

According to "Designing Cards and Drivers for the Macintosh Family" any attempt
to access an unimplemented address location on Nubus generates a bus error. MacOS
uses a custom bus error handler to detect empty Nubus slots, and with the current
implementation assumes that all slots are occupied as the Nubus transactions
never fail.

Switch nubus_slot_ops and nubus_super_slot_ops over to use {read,write}_with_attrs
and hard-code them to return MEMTX_DECODE_ERROR so that unoccupied Nubus slots
will generate the expected bus error.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
 hw/nubus/nubus-bus.c | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/hw/nubus/nubus-bus.c b/hw/nubus/nubus-bus.c
index e250abfda0..8a3731cab6 100644
--- a/hw/nubus/nubus-bus.c
+++ b/hw/nubus/nubus-bus.c
@@ -20,23 +20,23 @@ static NubusBus *nubus_find(void)
     return NUBUS_BUS(object_resolve_path_type("", TYPE_NUBUS_BUS, NULL));
 }
 
-static void nubus_slot_write(void *opaque, hwaddr addr, uint64_t val,
-                             unsigned int size)
+static MemTxResult nubus_slot_write(void *opaque, hwaddr addr, uint64_t val,
+                                    unsigned size, MemTxAttrs attrs)
 {
-    /* read only */
     trace_nubus_slot_write(addr, val, size);
+    return MEMTX_DECODE_ERROR;
 }
 
-static uint64_t nubus_slot_read(void *opaque, hwaddr addr,
-                                unsigned int size)
+static MemTxResult nubus_slot_read(void *opaque, hwaddr addr, uint64_t *data,
+                                   unsigned size, MemTxAttrs attrs)
 {
     trace_nubus_slot_read(addr, size);
-    return 0;
+    return MEMTX_DECODE_ERROR;
 }
 
 static const MemoryRegionOps nubus_slot_ops = {
-    .read  = nubus_slot_read,
-    .write = nubus_slot_write,
+    .read_with_attrs  = nubus_slot_read,
+    .write_with_attrs = nubus_slot_write,
     .endianness = DEVICE_BIG_ENDIAN,
     .valid = {
         .min_access_size = 1,
@@ -44,23 +44,25 @@ static const MemoryRegionOps nubus_slot_ops = {
     },
 };
 
-static void nubus_super_slot_write(void *opaque, hwaddr addr, uint64_t val,
-                                   unsigned int size)
+static MemTxResult nubus_super_slot_write(void *opaque, hwaddr addr,
+                                          uint64_t val, unsigned size,
+                                          MemTxAttrs attrs)
 {
-    /* read only */
     trace_nubus_super_slot_write(addr, val, size);
+    return MEMTX_DECODE_ERROR;
 }
 
-static uint64_t nubus_super_slot_read(void *opaque, hwaddr addr,
-                                      unsigned int size)
+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 0;
+    return MEMTX_DECODE_ERROR;
 }
 
 static const MemoryRegionOps nubus_super_slot_ops = {
-    .read  = nubus_super_slot_read,
-    .write = nubus_super_slot_write,
+    .read_with_attrs = nubus_super_slot_read,
+    .write_with_attrs = nubus_super_slot_write,
     .endianness = DEVICE_BIG_ENDIAN,
     .valid = {
         .min_access_size = 1,
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [PATCH 09/20] macfb: don't register declaration ROM
  2021-09-12  7:48 [PATCH 00/20] nubus: bus, device, bridge, IRQ and address space improvements Mark Cave-Ayland
                   ` (7 preceding siblings ...)
  2021-09-12  7:49 ` [PATCH 08/20] nubus: generate bus error when attempting to access empty slots Mark Cave-Ayland
@ 2021-09-12  7:49 ` Mark Cave-Ayland
  2021-09-12  7:49 ` [PATCH 10/20] nubus-device: remove nubus_register_rom() and nubus_register_format_block() Mark Cave-Ayland
                   ` (11 subsequent siblings)
  20 siblings, 0 replies; 47+ messages in thread
From: Mark Cave-Ayland @ 2021-09-12  7:49 UTC (permalink / raw)
  To: qemu-devel, laurent

The macfb device is an on-board framebuffer and so is initialised by the
system declaration ROM included within the MacOS toolbox ROM.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
 hw/display/macfb.c | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/hw/display/macfb.c b/hw/display/macfb.c
index d8183b9bbd..76808b69cc 100644
--- a/hw/display/macfb.c
+++ b/hw/display/macfb.c
@@ -383,10 +383,6 @@ static void macfb_sysbus_realize(DeviceState *dev, Error **errp)
     sysbus_init_mmio(SYS_BUS_DEVICE(s), &ms->mem_vram);
 }
 
-const uint8_t macfb_rom[] = {
-    255, 0, 0, 0,
-};
-
 static void macfb_nubus_realize(DeviceState *dev, Error **errp)
 {
     NubusDevice *nd = NUBUS_DEVICE(dev);
@@ -399,8 +395,6 @@ static void macfb_nubus_realize(DeviceState *dev, Error **errp)
     macfb_common_realize(dev, ms, errp);
     memory_region_add_subregion(&nd->slot_mem, DAFB_BASE, &ms->mem_ctrl);
     memory_region_add_subregion(&nd->slot_mem, VIDEO_BASE, &ms->mem_vram);
-
-    nubus_register_rom(nd, macfb_rom, sizeof(macfb_rom), 1, 9, 0xf);
 }
 
 static void macfb_sysbus_reset(DeviceState *d)
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [PATCH 10/20] nubus-device: remove nubus_register_rom() and nubus_register_format_block()
  2021-09-12  7:48 [PATCH 00/20] nubus: bus, device, bridge, IRQ and address space improvements Mark Cave-Ayland
                   ` (8 preceding siblings ...)
  2021-09-12  7:49 ` [PATCH 09/20] macfb: don't register declaration ROM Mark Cave-Ayland
@ 2021-09-12  7:49 ` Mark Cave-Ayland
  2021-09-12  7:49 ` [PATCH 11/20] nubus-device: add romfile property for loading declaration ROMs Mark Cave-Ayland
                   ` (10 subsequent siblings)
  20 siblings, 0 replies; 47+ messages in thread
From: Mark Cave-Ayland @ 2021-09-12  7:49 UTC (permalink / raw)
  To: qemu-devel, laurent

Since there is no need to generate a dummy declaration ROM, remove both
nubus_register_rom() and nubus_register_format_block(). These will shortly be
replaced with a mechanism to optionally load a declaration ROM from disk to
allow real images to be used within QEMU.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
 hw/nubus/nubus-device.c  | 143 ---------------------------------------
 include/hw/nubus/nubus.h |  19 ------
 2 files changed, 162 deletions(-)

diff --git a/hw/nubus/nubus-device.c b/hw/nubus/nubus-device.c
index 7a32c8c95b..9c1992ceb0 100644
--- a/hw/nubus/nubus-device.c
+++ b/hw/nubus/nubus-device.c
@@ -13,147 +13,6 @@
 #include "qapi/error.h"
 
 
-/* The Format Block Structure */
-
-#define FBLOCK_DIRECTORY_OFFSET 0
-#define FBLOCK_LENGTH           4
-#define FBLOCK_CRC              8
-#define FBLOCK_REVISION_LEVEL   12
-#define FBLOCK_FORMAT           13
-#define FBLOCK_TEST_PATTERN     14
-#define FBLOCK_RESERVED         18
-#define FBLOCK_BYTE_LANES       19
-
-#define FBLOCK_SIZE             20
-#define FBLOCK_PATTERN_VAL      0x5a932bc7
-
-static uint64_t nubus_fblock_read(void *opaque, hwaddr addr, unsigned int size)
-{
-    NubusDevice *dev = opaque;
-    uint64_t val;
-
-#define BYTE(v, b) (((v) >> (24 - 8 * (b))) & 0xff)
-    switch (addr) {
-    case FBLOCK_BYTE_LANES:
-        val = dev->byte_lanes;
-        val |= (val ^ 0xf) << 4;
-        break;
-    case FBLOCK_RESERVED:
-        val = 0x00;
-        break;
-    case FBLOCK_TEST_PATTERN...FBLOCK_TEST_PATTERN + 3:
-        val = BYTE(FBLOCK_PATTERN_VAL, addr - FBLOCK_TEST_PATTERN);
-        break;
-    case FBLOCK_FORMAT:
-        val = dev->rom_format;
-        break;
-    case FBLOCK_REVISION_LEVEL:
-        val = dev->rom_rev;
-        break;
-    case FBLOCK_CRC...FBLOCK_CRC + 3:
-        val = BYTE(dev->rom_crc, addr - FBLOCK_CRC);
-        break;
-    case FBLOCK_LENGTH...FBLOCK_LENGTH + 3:
-        val = BYTE(dev->rom_length, addr - FBLOCK_LENGTH);
-        break;
-    case FBLOCK_DIRECTORY_OFFSET...FBLOCK_DIRECTORY_OFFSET + 3:
-        val = BYTE(dev->directory_offset, addr - FBLOCK_DIRECTORY_OFFSET);
-        break;
-    default:
-        val = 0;
-        break;
-    }
-    return val;
-}
-
-static void nubus_fblock_write(void *opaque, hwaddr addr, uint64_t val,
-                               unsigned int size)
-{
-    /* read only */
-}
-
-static const MemoryRegionOps nubus_format_block_ops = {
-    .read = nubus_fblock_read,
-    .write = nubus_fblock_write,
-    .endianness = DEVICE_BIG_ENDIAN,
-    .valid = {
-        .min_access_size = 1,
-        .max_access_size = 1,
-    }
-};
-
-static void nubus_register_format_block(NubusDevice *dev)
-{
-    char *fblock_name;
-
-    fblock_name = g_strdup_printf("nubus-slot-%d-format-block",
-                                  dev->slot);
-
-    hwaddr fblock_offset = memory_region_size(&dev->slot_mem) - FBLOCK_SIZE;
-    memory_region_init_io(&dev->fblock_io, NULL, &nubus_format_block_ops,
-                          dev, fblock_name, FBLOCK_SIZE);
-    memory_region_add_subregion(&dev->slot_mem, fblock_offset,
-                                &dev->fblock_io);
-
-    g_free(fblock_name);
-}
-
-static void mac_nubus_rom_write(void *opaque, hwaddr addr, uint64_t val,
-                                       unsigned int size)
-{
-    /* read only */
-}
-
-static uint64_t mac_nubus_rom_read(void *opaque, hwaddr addr,
-                                    unsigned int size)
-{
-    NubusDevice *dev = opaque;
-
-    return dev->rom[addr];
-}
-
-static const MemoryRegionOps mac_nubus_rom_ops = {
-    .read  = mac_nubus_rom_read,
-    .write = mac_nubus_rom_write,
-    .endianness = DEVICE_BIG_ENDIAN,
-    .valid = {
-        .min_access_size = 1,
-        .max_access_size = 1,
-    },
-};
-
-
-void nubus_register_rom(NubusDevice *dev, const uint8_t *rom, uint32_t size,
-                        int revision, int format, uint8_t byte_lanes)
-{
-    hwaddr rom_offset;
-    char *rom_name;
-
-    /* FIXME : really compute CRC */
-    dev->rom_length = 0;
-    dev->rom_crc = 0;
-
-    dev->rom_rev = revision;
-    dev->rom_format = format;
-
-    dev->byte_lanes = byte_lanes;
-    dev->directory_offset = -size;
-
-    /* ROM */
-
-    dev->rom = rom;
-    rom_name = g_strdup_printf("nubus-slot-%d-rom", dev->slot);
-    memory_region_init_io(&dev->rom_io, NULL, &mac_nubus_rom_ops,
-                          dev, rom_name, size);
-    memory_region_set_readonly(&dev->rom_io, true);
-
-    rom_offset = memory_region_size(&dev->slot_mem) - FBLOCK_SIZE +
-                 dev->directory_offset;
-    memory_region_add_subregion(&dev->slot_mem, rom_offset, &dev->rom_io);
-
-    g_free(rom_name);
-}
-
 static void nubus_device_realize(DeviceState *dev, Error **errp)
 {
     NubusBus *nubus = NUBUS_BUS(qdev_get_parent_bus(dev));
@@ -179,8 +38,6 @@ static void nubus_device_realize(DeviceState *dev, Error **errp)
     memory_region_add_subregion(&nubus->slot_io, slot_offset,
                                 &nd->slot_mem);
     g_free(name);
-
-    nubus_register_format_block(nd);
 }
 
 static Property nubus_device_properties[] = {
diff --git a/include/hw/nubus/nubus.h b/include/hw/nubus/nubus.h
index 8ff4736259..87a97516c7 100644
--- a/include/hw/nubus/nubus.h
+++ b/include/hw/nubus/nubus.h
@@ -45,25 +45,6 @@ struct NubusDevice {
     int32_t slot;
     MemoryRegion super_slot_mem;
     MemoryRegion slot_mem;
-
-    /* Format Block */
-
-    MemoryRegion fblock_io;
-
-    uint32_t rom_length;
-    uint32_t rom_crc;
-    uint8_t rom_rev;
-    uint8_t rom_format;
-    uint8_t byte_lanes;
-    int32_t directory_offset;
-
-    /* ROM */
-
-    MemoryRegion rom_io;
-    const uint8_t *rom;
 };
 
-void nubus_register_rom(NubusDevice *dev, const uint8_t *rom, uint32_t size,
-                        int revision, int format, uint8_t byte_lanes);
-
 #endif
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [PATCH 11/20] nubus-device: add romfile property for loading declaration ROMs
  2021-09-12  7:48 [PATCH 00/20] nubus: bus, device, bridge, IRQ and address space improvements Mark Cave-Ayland
                   ` (9 preceding siblings ...)
  2021-09-12  7:49 ` [PATCH 10/20] nubus-device: remove nubus_register_rom() and nubus_register_format_block() Mark Cave-Ayland
@ 2021-09-12  7:49 ` Mark Cave-Ayland
  2021-09-12 17:39   ` Philippe Mathieu-Daudé
  2021-09-12  7:49 ` [PATCH 12/20] nubus: move nubus to its own 32-bit address space Mark Cave-Ayland
                   ` (9 subsequent siblings)
  20 siblings, 1 reply; 47+ messages in thread
From: Mark Cave-Ayland @ 2021-09-12  7:49 UTC (permalink / raw)
  To: qemu-devel, laurent

The declaration ROM is located at the top-most address of the standard slot
space.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
 hw/nubus/nubus-device.c  | 43 +++++++++++++++++++++++++++++++++++++++-
 include/hw/nubus/nubus.h |  5 +++++
 2 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/hw/nubus/nubus-device.c b/hw/nubus/nubus-device.c
index 9c1992ceb0..98a4c6bb33 100644
--- a/hw/nubus/nubus-device.c
+++ b/hw/nubus/nubus-device.c
@@ -9,16 +9,21 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/datadir.h"
+#include "hw/loader.h"
 #include "hw/nubus/nubus.h"
 #include "qapi/error.h"
+#include "qemu/error-report.h"
 
 
 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;
+    char *name, *path;
     hwaddr slot_offset;
+    int64_t size;
+    int ret;
 
     /* Super */
     slot_offset = (nd->slot - 6) * NUBUS_SUPER_SLOT_SIZE;
@@ -38,10 +43,46 @@ static void nubus_device_realize(DeviceState *dev, Error **errp)
     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 64K)",
+                       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_fatal);
+        ret = load_image_mr(path, &nd->decl_rom);
+        g_free(path);
+        if (ret < 0) {
+            warn_report("nubus-device: could not load prom '%s'", nd->romfile);
+        }
+        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()
 };
 
diff --git a/include/hw/nubus/nubus.h b/include/hw/nubus/nubus.h
index 87a97516c7..42f4c9dbb8 100644
--- a/include/hw/nubus/nubus.h
+++ b/include/hw/nubus/nubus.h
@@ -39,12 +39,17 @@ struct NubusBus {
     uint32_t slot_available_mask;
 };
 
+#define NUBUS_DECL_ROM_MAX_SIZE    0xffff
+
 struct NubusDevice {
     DeviceState qdev;
 
     int32_t slot;
     MemoryRegion super_slot_mem;
     MemoryRegion slot_mem;
+
+    char *romfile;
+    MemoryRegion decl_rom;
 };
 
 #endif
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [PATCH 12/20] nubus: move nubus to its own 32-bit address space
  2021-09-12  7:48 [PATCH 00/20] nubus: bus, device, bridge, IRQ and address space improvements Mark Cave-Ayland
                   ` (10 preceding siblings ...)
  2021-09-12  7:49 ` [PATCH 11/20] nubus-device: add romfile property for loading declaration ROMs Mark Cave-Ayland
@ 2021-09-12  7:49 ` Mark Cave-Ayland
  2021-09-12 15:22   ` Philippe Mathieu-Daudé
  2021-09-12  7:49 ` [PATCH 13/20] nubus-bridge: introduce separate NubusBridge structure Mark Cave-Ayland
                   ` (8 subsequent siblings)
  20 siblings, 1 reply; 47+ messages in thread
From: Mark Cave-Ayland @ 2021-09-12  7:49 UTC (permalink / raw)
  To: qemu-devel, laurent

According to "Designing Cards and Drivers for the Macintosh Family" the Nubus
has its own 32-bit address space based upon physical slot addressing.

Move Nubus to its own 32-bit address space and then use memory region aliases
to map available slot and super slot ranges into the q800 system address
space via the Macintosh Nubus bridge.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
 hw/m68k/q800.c                      |  8 +++-----
 hw/nubus/mac-nubus-bridge.c         | 15 +++++++++++++--
 hw/nubus/nubus-bus.c                | 18 ++++++++++++++++++
 hw/nubus/nubus-device.c             |  2 +-
 include/hw/nubus/mac-nubus-bridge.h |  2 ++
 include/hw/nubus/nubus.h            | 10 +++++++---
 6 files changed, 44 insertions(+), 11 deletions(-)

diff --git a/hw/m68k/q800.c b/hw/m68k/q800.c
index 5ba87f789c..0a0051a296 100644
--- a/hw/m68k/q800.c
+++ b/hw/m68k/q800.c
@@ -67,9 +67,6 @@
 #define ASC_BASE              (IO_BASE + 0x14000)
 #define SWIM_BASE             (IO_BASE + 0x1E000)
 
-#define NUBUS_SUPER_SLOT_BASE 0x60000000
-#define NUBUS_SLOT_BASE       0xf0000000
-
 #define SONIC_PROM_SIZE       0x1000
 
 /*
@@ -396,8 +393,9 @@ static void q800_init(MachineState *machine)
 
     dev = qdev_new(TYPE_MAC_NUBUS_BRIDGE);
     sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
-    sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, NUBUS_SUPER_SLOT_BASE);
-    sysbus_mmio_map(SYS_BUS_DEVICE(dev), 1, NUBUS_SLOT_BASE);
+    sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, 9 * NUBUS_SUPER_SLOT_SIZE);
+    sysbus_mmio_map(SYS_BUS_DEVICE(dev), 1, NUBUS_SLOT_BASE +
+                                            9 * NUBUS_SLOT_SIZE);
 
     nubus = MAC_NUBUS_BRIDGE(dev)->bus;
 
diff --git a/hw/nubus/mac-nubus-bridge.c b/hw/nubus/mac-nubus-bridge.c
index 6e78f4c0b3..7c01c8a06b 100644
--- a/hw/nubus/mac-nubus-bridge.c
+++ b/hw/nubus/mac-nubus-bridge.c
@@ -21,8 +21,19 @@ static void mac_nubus_bridge_init(Object *obj)
     /* Macintosh only has slots 0x9 to 0xe available */
     s->bus->slot_available_mask = 0x7e00;
 
-    sysbus_init_mmio(sbd, &s->bus->super_slot_io);
-    sysbus_init_mmio(sbd, &s->bus->slot_io);
+    /* Aliases for slots 0x9 to 0xe */
+    memory_region_init_alias(&s->super_slot_alias, obj, "super-slot-alias",
+                             &s->bus->nubus_mr,
+                             9 * NUBUS_SUPER_SLOT_SIZE,
+                             6 * NUBUS_SUPER_SLOT_SIZE);
+
+    memory_region_init_alias(&s->slot_alias, obj, "slot-alias",
+                             &s->bus->nubus_mr,
+                             NUBUS_SLOT_BASE + 9 * NUBUS_SLOT_SIZE,
+                             6 * 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)
diff --git a/hw/nubus/nubus-bus.c b/hw/nubus/nubus-bus.c
index 8a3731cab6..5fc0d375f6 100644
--- a/hw/nubus/nubus-bus.c
+++ b/hw/nubus/nubus-bus.c
@@ -70,25 +70,42 @@ static const MemoryRegionOps nubus_super_slot_ops = {
     },
 };
 
+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 * 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 * NUBUS_SUPER_SLOT_SIZE,
+                                &nubus->slot_io);
 
     nubus->slot_available_mask = 0xffff;
 }
@@ -149,6 +166,7 @@ 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;
 }
diff --git a/hw/nubus/nubus-device.c b/hw/nubus/nubus-device.c
index 98a4c6bb33..f316eb7789 100644
--- a/hw/nubus/nubus-device.c
+++ b/hw/nubus/nubus-device.c
@@ -26,7 +26,7 @@ static void nubus_device_realize(DeviceState *dev, Error **errp)
     int ret;
 
     /* Super */
-    slot_offset = (nd->slot - 6) * NUBUS_SUPER_SLOT_SIZE;
+    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,
diff --git a/include/hw/nubus/mac-nubus-bridge.h b/include/hw/nubus/mac-nubus-bridge.h
index 36aa098dd4..650fd24eab 100644
--- a/include/hw/nubus/mac-nubus-bridge.h
+++ b/include/hw/nubus/mac-nubus-bridge.h
@@ -19,6 +19,8 @@ struct MacNubusState {
     SysBusDevice sysbus_dev;
 
     NubusBus *bus;
+    MemoryRegion super_slot_alias;
+    MemoryRegion slot_alias;
 };
 
 #endif
diff --git a/include/hw/nubus/nubus.h b/include/hw/nubus/nubus.h
index 42f4c9dbb8..ecd6340d85 100644
--- a/include/hw/nubus/nubus.h
+++ b/include/hw/nubus/nubus.h
@@ -14,13 +14,14 @@
 #include "qom/object.h"
 
 #define NUBUS_SUPER_SLOT_SIZE 0x10000000U
-#define NUBUS_SUPER_SLOT_NB   0x9
+#define NUBUS_SUPER_SLOT_NB   0xf
 
+#define NUBUS_SLOT_BASE       (NUBUS_SUPER_SLOT_SIZE * NUBUS_SUPER_SLOT_NB)
 #define NUBUS_SLOT_SIZE       0x01000000
-#define NUBUS_SLOT_NB         0xF
+#define NUBUS_SLOT_NB         0xf
 
 #define NUBUS_FIRST_SLOT      0x0
-#define NUBUS_LAST_SLOT       0xF
+#define NUBUS_LAST_SLOT       0xf
 
 #define TYPE_NUBUS_DEVICE "nubus-device"
 OBJECT_DECLARE_SIMPLE_TYPE(NubusDevice, NUBUS_DEVICE)
@@ -33,6 +34,9 @@ OBJECT_DECLARE_SIMPLE_TYPE(NubusBus, NUBUS_BUS)
 struct NubusBus {
     BusState qbus;
 
+    AddressSpace nubus_as;
+    MemoryRegion nubus_mr;
+
     MemoryRegion super_slot_io;
     MemoryRegion slot_io;
 
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [PATCH 13/20] nubus-bridge: introduce separate NubusBridge structure
  2021-09-12  7:48 [PATCH 00/20] nubus: bus, device, bridge, IRQ and address space improvements Mark Cave-Ayland
                   ` (11 preceding siblings ...)
  2021-09-12  7:49 ` [PATCH 12/20] nubus: move nubus to its own 32-bit address space Mark Cave-Ayland
@ 2021-09-12  7:49 ` Mark Cave-Ayland
  2021-09-12 15:23   ` Philippe Mathieu-Daudé
  2021-09-12  7:49 ` [PATCH 14/20] mac-nubus-bridge: rename MacNubusState to MacNubusBridge Mark Cave-Ayland
                   ` (7 subsequent siblings)
  20 siblings, 1 reply; 47+ messages in thread
From: Mark Cave-Ayland @ 2021-09-12  7:49 UTC (permalink / raw)
  To: qemu-devel, laurent

This is to allow the Nubus bridge to store its own additional state. Also update
the comment in the file header to reflect that nubus-bridge is not specific to
the Macintosh.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
 hw/nubus/nubus-bridge.c             | 4 ++--
 include/hw/nubus/mac-nubus-bridge.h | 2 +-
 include/hw/nubus/nubus.h            | 6 ++++++
 3 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/hw/nubus/nubus-bridge.c b/hw/nubus/nubus-bridge.c
index cd8c6a91eb..95662568c5 100644
--- a/hw/nubus/nubus-bridge.c
+++ b/hw/nubus/nubus-bridge.c
@@ -1,5 +1,5 @@
 /*
- * QEMU Macintosh Nubus
+ * QEMU Nubus
  *
  * Copyright (c) 2013-2018 Laurent Vivier <laurent@vivier.eu>
  *
@@ -22,7 +22,7 @@ static void nubus_bridge_class_init(ObjectClass *klass, void *data)
 static const TypeInfo nubus_bridge_info = {
     .name          = TYPE_NUBUS_BRIDGE,
     .parent        = TYPE_SYS_BUS_DEVICE,
-    .instance_size = sizeof(SysBusDevice),
+    .instance_size = sizeof(NubusBridge),
     .class_init    = nubus_bridge_class_init,
 };
 
diff --git a/include/hw/nubus/mac-nubus-bridge.h b/include/hw/nubus/mac-nubus-bridge.h
index 650fd24eab..7365038966 100644
--- a/include/hw/nubus/mac-nubus-bridge.h
+++ b/include/hw/nubus/mac-nubus-bridge.h
@@ -16,7 +16,7 @@
 OBJECT_DECLARE_SIMPLE_TYPE(MacNubusState, MAC_NUBUS_BRIDGE)
 
 struct MacNubusState {
-    SysBusDevice sysbus_dev;
+    NubusBridge parent_obj;
 
     NubusBus *bus;
     MemoryRegion super_slot_alias;
diff --git a/include/hw/nubus/nubus.h b/include/hw/nubus/nubus.h
index ecd6340d85..e4381b3e18 100644
--- a/include/hw/nubus/nubus.h
+++ b/include/hw/nubus/nubus.h
@@ -10,6 +10,7 @@
 #define HW_NUBUS_NUBUS_H
 
 #include "hw/qdev-properties.h"
+#include "hw/sysbus.h"
 #include "exec/address-spaces.h"
 #include "qom/object.h"
 
@@ -30,6 +31,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(NubusDevice, NUBUS_DEVICE)
 OBJECT_DECLARE_SIMPLE_TYPE(NubusBus, NUBUS_BUS)
 
 #define TYPE_NUBUS_BRIDGE "nubus-bridge"
+OBJECT_DECLARE_SIMPLE_TYPE(NubusBridge, NUBUS_BRIDGE);
 
 struct NubusBus {
     BusState qbus;
@@ -56,4 +58,8 @@ struct NubusDevice {
     MemoryRegion decl_rom;
 };
 
+struct NubusBridge {
+    SysBusDevice parent_obj;
+};
+
 #endif
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [PATCH 14/20] mac-nubus-bridge: rename MacNubusState to MacNubusBridge
  2021-09-12  7:48 [PATCH 00/20] nubus: bus, device, bridge, IRQ and address space improvements Mark Cave-Ayland
                   ` (12 preceding siblings ...)
  2021-09-12  7:49 ` [PATCH 13/20] nubus-bridge: introduce separate NubusBridge structure Mark Cave-Ayland
@ 2021-09-12  7:49 ` Mark Cave-Ayland
  2021-09-12 15:23   ` Philippe Mathieu-Daudé
  2021-09-12  7:49 ` [PATCH 15/20] nubus: move NubusBus from mac-nubus-bridge to nubus-bridge Mark Cave-Ayland
                   ` (6 subsequent siblings)
  20 siblings, 1 reply; 47+ messages in thread
From: Mark Cave-Ayland @ 2021-09-12  7:49 UTC (permalink / raw)
  To: qemu-devel, laurent

This better reflects that the mac-nubus-bridge device is derived from the
nubus-bridge device, and that the structure represents the state of the bridge
device and not the Nubus itself. Also update the comment in the file header to
reflect that mac-nubus-bridge is specific to the Macintosh.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
 hw/nubus/mac-nubus-bridge.c         | 8 +++++---
 include/hw/nubus/mac-nubus-bridge.h | 4 ++--
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/hw/nubus/mac-nubus-bridge.c b/hw/nubus/mac-nubus-bridge.c
index 7c01c8a06b..def1d2d313 100644
--- a/hw/nubus/mac-nubus-bridge.c
+++ b/hw/nubus/mac-nubus-bridge.c
@@ -1,5 +1,7 @@
 /*
- *  Copyright (c) 2013-2018 Laurent Vivier <laurent@vivier.eu>
+ * 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.
@@ -13,7 +15,7 @@
 
 static void mac_nubus_bridge_init(Object *obj)
 {
-    MacNubusState *s = MAC_NUBUS_BRIDGE(obj);
+    MacNubusBridge *s = MAC_NUBUS_BRIDGE(obj);
     SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
 
     s->bus = NUBUS_BUS(qbus_create(TYPE_NUBUS_BUS, DEVICE(s), NULL));
@@ -47,7 +49,7 @@ 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(MacNubusState),
+    .instance_size = sizeof(MacNubusBridge),
     .class_init    = mac_nubus_bridge_class_init,
 };
 
diff --git a/include/hw/nubus/mac-nubus-bridge.h b/include/hw/nubus/mac-nubus-bridge.h
index 7365038966..d9bb11db31 100644
--- a/include/hw/nubus/mac-nubus-bridge.h
+++ b/include/hw/nubus/mac-nubus-bridge.h
@@ -13,9 +13,9 @@
 #include "qom/object.h"
 
 #define TYPE_MAC_NUBUS_BRIDGE "mac-nubus-bridge"
-OBJECT_DECLARE_SIMPLE_TYPE(MacNubusState, MAC_NUBUS_BRIDGE)
+OBJECT_DECLARE_SIMPLE_TYPE(MacNubusBridge, MAC_NUBUS_BRIDGE)
 
-struct MacNubusState {
+struct MacNubusBridge {
     NubusBridge parent_obj;
 
     NubusBus *bus;
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [PATCH 15/20] nubus: move NubusBus from mac-nubus-bridge to nubus-bridge
  2021-09-12  7:48 [PATCH 00/20] nubus: bus, device, bridge, IRQ and address space improvements Mark Cave-Ayland
                   ` (13 preceding siblings ...)
  2021-09-12  7:49 ` [PATCH 14/20] mac-nubus-bridge: rename MacNubusState to MacNubusBridge Mark Cave-Ayland
@ 2021-09-12  7:49 ` Mark Cave-Ayland
  2021-09-12 15:25   ` Philippe Mathieu-Daudé
  2021-09-12  7:49 ` [PATCH 16/20] nubus-bridge: embed the NubusBus object directly within nubus-bridge Mark Cave-Ayland
                   ` (5 subsequent siblings)
  20 siblings, 1 reply; 47+ messages in thread
From: Mark Cave-Ayland @ 2021-09-12  7:49 UTC (permalink / raw)
  To: qemu-devel, laurent

Now that Nubus has its own address space rather than mapping directly into the
system bus, move the Nubus reference from MacNubusBridge to NubusBridge.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
 hw/m68k/q800.c                      | 2 +-
 hw/nubus/mac-nubus-bridge.c         | 9 ++++-----
 hw/nubus/nubus-bridge.c             | 9 +++++++++
 include/hw/nubus/mac-nubus-bridge.h | 1 -
 include/hw/nubus/nubus.h            | 2 ++
 5 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/hw/m68k/q800.c b/hw/m68k/q800.c
index 0a0051a296..46befe0898 100644
--- a/hw/m68k/q800.c
+++ b/hw/m68k/q800.c
@@ -397,7 +397,7 @@ static void q800_init(MachineState *machine)
     sysbus_mmio_map(SYS_BUS_DEVICE(dev), 1, NUBUS_SLOT_BASE +
                                             9 * NUBUS_SLOT_SIZE);
 
-    nubus = MAC_NUBUS_BRIDGE(dev)->bus;
+    nubus = NUBUS_BRIDGE(dev)->bus;
 
     /* framebuffer in nubus slot #9 */
 
diff --git a/hw/nubus/mac-nubus-bridge.c b/hw/nubus/mac-nubus-bridge.c
index def1d2d313..c16cfc4ab3 100644
--- a/hw/nubus/mac-nubus-bridge.c
+++ b/hw/nubus/mac-nubus-bridge.c
@@ -16,21 +16,20 @@
 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);
 
-    s->bus = NUBUS_BUS(qbus_create(TYPE_NUBUS_BUS, DEVICE(s), NULL));
-
     /* Macintosh only has slots 0x9 to 0xe available */
-    s->bus->slot_available_mask = 0x7e00;
+    nb->bus->slot_available_mask = 0x7e00;
 
     /* Aliases for slots 0x9 to 0xe */
     memory_region_init_alias(&s->super_slot_alias, obj, "super-slot-alias",
-                             &s->bus->nubus_mr,
+                             &nb->bus->nubus_mr,
                              9 * NUBUS_SUPER_SLOT_SIZE,
                              6 * NUBUS_SUPER_SLOT_SIZE);
 
     memory_region_init_alias(&s->slot_alias, obj, "slot-alias",
-                             &s->bus->nubus_mr,
+                             &nb->bus->nubus_mr,
                              NUBUS_SLOT_BASE + 9 * NUBUS_SLOT_SIZE,
                              6 * NUBUS_SLOT_SIZE);
 
diff --git a/hw/nubus/nubus-bridge.c b/hw/nubus/nubus-bridge.c
index 95662568c5..3b68d4435c 100644
--- a/hw/nubus/nubus-bridge.c
+++ b/hw/nubus/nubus-bridge.c
@@ -12,6 +12,14 @@
 #include "hw/sysbus.h"
 #include "hw/nubus/nubus.h"
 
+
+static void nubus_bridge_init(Object *obj)
+{
+    NubusBridge *s = NUBUS_BRIDGE(obj);
+
+    s->bus = NUBUS_BUS(qbus_create(TYPE_NUBUS_BUS, DEVICE(s), NULL));
+}
+
 static void nubus_bridge_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
@@ -22,6 +30,7 @@ static void nubus_bridge_class_init(ObjectClass *klass, void *data)
 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,
 };
diff --git a/include/hw/nubus/mac-nubus-bridge.h b/include/hw/nubus/mac-nubus-bridge.h
index d9bb11db31..45ec610d52 100644
--- a/include/hw/nubus/mac-nubus-bridge.h
+++ b/include/hw/nubus/mac-nubus-bridge.h
@@ -18,7 +18,6 @@ OBJECT_DECLARE_SIMPLE_TYPE(MacNubusBridge, MAC_NUBUS_BRIDGE)
 struct MacNubusBridge {
     NubusBridge parent_obj;
 
-    NubusBus *bus;
     MemoryRegion super_slot_alias;
     MemoryRegion slot_alias;
 };
diff --git a/include/hw/nubus/nubus.h b/include/hw/nubus/nubus.h
index e4381b3e18..b62c7e1077 100644
--- a/include/hw/nubus/nubus.h
+++ b/include/hw/nubus/nubus.h
@@ -60,6 +60,8 @@ struct NubusDevice {
 
 struct NubusBridge {
     SysBusDevice parent_obj;
+
+    NubusBus *bus;
 };
 
 #endif
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [PATCH 16/20] nubus-bridge: embed the NubusBus object directly within nubus-bridge
  2021-09-12  7:48 [PATCH 00/20] nubus: bus, device, bridge, IRQ and address space improvements Mark Cave-Ayland
                   ` (14 preceding siblings ...)
  2021-09-12  7:49 ` [PATCH 15/20] nubus: move NubusBus from mac-nubus-bridge to nubus-bridge Mark Cave-Ayland
@ 2021-09-12  7:49 ` Mark Cave-Ayland
  2021-09-12 15:26   ` Philippe Mathieu-Daudé
  2021-09-12 17:43   ` Philippe Mathieu-Daudé
  2021-09-12  7:49 ` [PATCH 17/20] nubus-bridge: make slot_available_mask a qdev property Mark Cave-Ayland
                   ` (4 subsequent siblings)
  20 siblings, 2 replies; 47+ messages in thread
From: Mark Cave-Ayland @ 2021-09-12  7:49 UTC (permalink / raw)
  To: qemu-devel, laurent

Since nubus-bridge is a container for NubusBus then it should be embedded
directly within the bridge device using qbus_create_inplace().

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
 hw/m68k/q800.c              | 2 +-
 hw/nubus/mac-nubus-bridge.c | 7 ++++---
 hw/nubus/nubus-bridge.c     | 3 ++-
 include/hw/nubus/nubus.h    | 2 +-
 4 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/hw/m68k/q800.c b/hw/m68k/q800.c
index 46befe0898..e34df1a829 100644
--- a/hw/m68k/q800.c
+++ b/hw/m68k/q800.c
@@ -397,7 +397,7 @@ static void q800_init(MachineState *machine)
     sysbus_mmio_map(SYS_BUS_DEVICE(dev), 1, NUBUS_SLOT_BASE +
                                             9 * NUBUS_SLOT_SIZE);
 
-    nubus = NUBUS_BRIDGE(dev)->bus;
+    nubus = &NUBUS_BRIDGE(dev)->bus;
 
     /* framebuffer in nubus slot #9 */
 
diff --git a/hw/nubus/mac-nubus-bridge.c b/hw/nubus/mac-nubus-bridge.c
index c16cfc4ab3..c23d5d508d 100644
--- a/hw/nubus/mac-nubus-bridge.c
+++ b/hw/nubus/mac-nubus-bridge.c
@@ -18,18 +18,19 @@ 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 */
-    nb->bus->slot_available_mask = 0x7e00;
+    bus->slot_available_mask = 0x7e00;
 
     /* Aliases for slots 0x9 to 0xe */
     memory_region_init_alias(&s->super_slot_alias, obj, "super-slot-alias",
-                             &nb->bus->nubus_mr,
+                             &bus->nubus_mr,
                              9 * NUBUS_SUPER_SLOT_SIZE,
                              6 * NUBUS_SUPER_SLOT_SIZE);
 
     memory_region_init_alias(&s->slot_alias, obj, "slot-alias",
-                             &nb->bus->nubus_mr,
+                             &bus->nubus_mr,
                              NUBUS_SLOT_BASE + 9 * NUBUS_SLOT_SIZE,
                              6 * NUBUS_SLOT_SIZE);
 
diff --git a/hw/nubus/nubus-bridge.c b/hw/nubus/nubus-bridge.c
index 3b68d4435c..1adda7f5a6 100644
--- a/hw/nubus/nubus-bridge.c
+++ b/hw/nubus/nubus-bridge.c
@@ -16,8 +16,9 @@
 static void nubus_bridge_init(Object *obj)
 {
     NubusBridge *s = NUBUS_BRIDGE(obj);
+    NubusBus *bus = &s->bus;
 
-    s->bus = NUBUS_BUS(qbus_create(TYPE_NUBUS_BUS, DEVICE(s), NULL));
+    qbus_create_inplace(bus, sizeof(s->bus), TYPE_NUBUS_BUS, DEVICE(s), NULL);
 }
 
 static void nubus_bridge_class_init(ObjectClass *klass, void *data)
diff --git a/include/hw/nubus/nubus.h b/include/hw/nubus/nubus.h
index b62c7e1077..503ebf0c1c 100644
--- a/include/hw/nubus/nubus.h
+++ b/include/hw/nubus/nubus.h
@@ -61,7 +61,7 @@ struct NubusDevice {
 struct NubusBridge {
     SysBusDevice parent_obj;
 
-    NubusBus *bus;
+    NubusBus bus;
 };
 
 #endif
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [PATCH 17/20] nubus-bridge: make slot_available_mask a qdev property
  2021-09-12  7:48 [PATCH 00/20] nubus: bus, device, bridge, IRQ and address space improvements Mark Cave-Ayland
                   ` (15 preceding siblings ...)
  2021-09-12  7:49 ` [PATCH 16/20] nubus-bridge: embed the NubusBus object directly within nubus-bridge Mark Cave-Ayland
@ 2021-09-12  7:49 ` Mark Cave-Ayland
  2021-09-12  7:49 ` [PATCH 18/20] nubus: add support for slot IRQs Mark Cave-Ayland
                   ` (3 subsequent siblings)
  20 siblings, 0 replies; 47+ messages in thread
From: Mark Cave-Ayland @ 2021-09-12  7:49 UTC (permalink / raw)
  To: qemu-devel, laurent

This is to allow Macintosh machines to further specify which slots are available
since the number of addressable slots may not match the number of physical slots
present in the machine.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
 hw/nubus/nubus-bridge.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/hw/nubus/nubus-bridge.c b/hw/nubus/nubus-bridge.c
index 1adda7f5a6..2c7c4ee121 100644
--- a/hw/nubus/nubus-bridge.c
+++ b/hw/nubus/nubus-bridge.c
@@ -21,11 +21,18 @@ static void nubus_bridge_init(Object *obj)
     qbus_create_inplace(bus, sizeof(s->bus), TYPE_NUBUS_BUS, DEVICE(s), NULL);
 }
 
+static Property nubus_bridge_properties[] = {
+    DEFINE_PROP_UINT32("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 = {
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [PATCH 18/20] nubus: add support for slot IRQs
  2021-09-12  7:48 [PATCH 00/20] nubus: bus, device, bridge, IRQ and address space improvements Mark Cave-Ayland
                   ` (16 preceding siblings ...)
  2021-09-12  7:49 ` [PATCH 17/20] nubus-bridge: make slot_available_mask a qdev property Mark Cave-Ayland
@ 2021-09-12  7:49 ` Mark Cave-Ayland
  2021-09-12 16:00   ` Philippe Mathieu-Daudé
  2021-09-12  7:49 ` [PATCH 19/20] q800: wire up nubus IRQs Mark Cave-Ayland
                   ` (2 subsequent siblings)
  20 siblings, 1 reply; 47+ messages in thread
From: Mark Cave-Ayland @ 2021-09-12  7:49 UTC (permalink / raw)
  To: qemu-devel, laurent

Each Nubus slot has an IRQ line that can be used to request service from the
CPU. Connect the IRQs to the Nubus bridge so that they can be wired up using qdev
gpios accordingly, and introduce a new nubus_set_irq() function that can be used
by Nubus devices to control the slot IRQ.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
 hw/nubus/nubus-bridge.c  | 2 ++
 hw/nubus/nubus-device.c  | 8 ++++++++
 include/hw/nubus/nubus.h | 6 ++++++
 3 files changed, 16 insertions(+)

diff --git a/hw/nubus/nubus-bridge.c b/hw/nubus/nubus-bridge.c
index 2c7c4ee121..0366d925a9 100644
--- a/hw/nubus/nubus-bridge.c
+++ b/hw/nubus/nubus-bridge.c
@@ -19,6 +19,8 @@ static void nubus_bridge_init(Object *obj)
     NubusBus *bus = &s->bus;
 
     qbus_create_inplace(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[] = {
diff --git a/hw/nubus/nubus-device.c b/hw/nubus/nubus-device.c
index f316eb7789..67ab281943 100644
--- a/hw/nubus/nubus-device.c
+++ b/hw/nubus/nubus-device.c
@@ -10,12 +10,20 @@
 
 #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));
diff --git a/include/hw/nubus/nubus.h b/include/hw/nubus/nubus.h
index 503ebf0c1c..2b9c4c77ac 100644
--- a/include/hw/nubus/nubus.h
+++ b/include/hw/nubus/nubus.h
@@ -24,6 +24,8 @@
 #define NUBUS_FIRST_SLOT      0x0
 #define NUBUS_LAST_SLOT       0xf
 
+#define NUBUS_IRQS            16
+
 #define TYPE_NUBUS_DEVICE "nubus-device"
 OBJECT_DECLARE_SIMPLE_TYPE(NubusDevice, NUBUS_DEVICE)
 
@@ -43,6 +45,8 @@ struct NubusBus {
     MemoryRegion slot_io;
 
     uint32_t slot_available_mask;
+
+    qemu_irq irqs[NUBUS_IRQS];
 };
 
 #define NUBUS_DECL_ROM_MAX_SIZE    0xffff
@@ -58,6 +62,8 @@ struct NubusDevice {
     MemoryRegion decl_rom;
 };
 
+void nubus_set_irq(NubusDevice *nd, int level);
+
 struct NubusBridge {
     SysBusDevice parent_obj;
 
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [PATCH 19/20] q800: wire up nubus IRQs
  2021-09-12  7:48 [PATCH 00/20] nubus: bus, device, bridge, IRQ and address space improvements Mark Cave-Ayland
                   ` (17 preceding siblings ...)
  2021-09-12  7:49 ` [PATCH 18/20] nubus: add support for slot IRQs Mark Cave-Ayland
@ 2021-09-12  7:49 ` Mark Cave-Ayland
  2021-09-12  7:49 ` [PATCH 20/20] q800: configure nubus available slots for Quadra 800 Mark Cave-Ayland
  2021-09-12 15:47 ` [PATCH 00/20] nubus: bus, device, bridge, IRQ and address space improvements Philippe Mathieu-Daudé
  20 siblings, 0 replies; 47+ messages in thread
From: Mark Cave-Ayland @ 2021-09-12  7:49 UTC (permalink / raw)
  To: qemu-devel, laurent

Nubus IRQs are routed to the CPU through the VIA2 device so wire up the IRQs
using gpios accordingly.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
 hw/m68k/q800.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/hw/m68k/q800.c b/hw/m68k/q800.c
index e34df1a829..fbc45a301f 100644
--- a/hw/m68k/q800.c
+++ b/hw/m68k/q800.c
@@ -396,6 +396,11 @@ static void q800_init(MachineState *machine)
     sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, 9 * NUBUS_SUPER_SLOT_SIZE);
     sysbus_mmio_map(SYS_BUS_DEVICE(dev), 1, NUBUS_SLOT_BASE +
                                             9 * NUBUS_SLOT_SIZE);
+    for (i = 0; i < VIA2_NUBUS_IRQ_NB; i++) {
+        qdev_connect_gpio_out(dev, 9 + i,
+                              qdev_get_gpio_in_named(via2_dev, "nubus-irq",
+                                                     VIA2_NUBUS_IRQ_9 + i));
+    }
 
     nubus = &NUBUS_BRIDGE(dev)->bus;
 
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 47+ messages in thread

* [PATCH 20/20] q800: configure nubus available slots for Quadra 800
  2021-09-12  7:48 [PATCH 00/20] nubus: bus, device, bridge, IRQ and address space improvements Mark Cave-Ayland
                   ` (18 preceding siblings ...)
  2021-09-12  7:49 ` [PATCH 19/20] q800: wire up nubus IRQs Mark Cave-Ayland
@ 2021-09-12  7:49 ` Mark Cave-Ayland
  2021-09-12 15:47 ` [PATCH 00/20] nubus: bus, device, bridge, IRQ and address space improvements Philippe Mathieu-Daudé
  20 siblings, 0 replies; 47+ messages in thread
From: Mark Cave-Ayland @ 2021-09-12  7:49 UTC (permalink / raw)
  To: qemu-devel, laurent

Slot 0x9 is reserved for use by the in-built framebuffer whilst only slots
0xc, 0xd and 0xe physically exist on the Quadra 800.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
 hw/m68k/q800.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/hw/m68k/q800.c b/hw/m68k/q800.c
index fbc45a301f..65c80421c6 100644
--- a/hw/m68k/q800.c
+++ b/hw/m68k/q800.c
@@ -78,6 +78,13 @@
 
 #define MAC_CLOCK  3686418
 
+/*
+ * Slot 0x9 is reserved for use by the in-built framebuffer whilst only
+ * slots 0xc, 0xd and 0xe physically exist on the Quadra 800
+ */
+#define Q800_NUBUS_SLOTS_AVAILABLE    ((1UL << 0x9) | (1UL << 0xc) | \
+                                       (1UL << 0xd) | (1UL << 0xe))
+
 /*
  * The GLUE (General Logic Unit) is an Apple custom integrated circuit chip
  * that performs a variety of functions (RAM management, clock generation, ...).
@@ -392,6 +399,8 @@ static void q800_init(MachineState *machine)
     /* NuBus */
 
     dev = qdev_new(TYPE_MAC_NUBUS_BRIDGE);
+    qdev_prop_set_uint32(dev, "slot-available-mask",
+                         Q800_NUBUS_SLOTS_AVAILABLE);
     sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
     sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, 9 * NUBUS_SUPER_SLOT_SIZE);
     sysbus_mmio_map(SYS_BUS_DEVICE(dev), 1, NUBUS_SLOT_BASE +
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 47+ messages in thread

* Re: [PATCH 01/20] nubus-device: rename slot_nb variable to slot
  2021-09-12  7:48 ` [PATCH 01/20] nubus-device: rename slot_nb variable to slot Mark Cave-Ayland
@ 2021-09-12 15:09   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 47+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-12 15:09 UTC (permalink / raw)
  To: Mark Cave-Ayland, qemu-devel, laurent

Hi Mark,

On 9/12/21 9:48 AM, Mark Cave-Ayland wrote:
> This is in preparation for creating a qdev property of the same name.
> 
> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
> ---
>  hw/nubus/nubus-device.c  | 14 +++++++-------
>  include/hw/nubus/nubus.h |  2 +-
>  2 files changed, 8 insertions(+), 8 deletions(-)

I suppose you are on a new setup. Consider re-adding
scripts/git.orderfile ;)

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PATCH 03/20] nubus-device: add device slot parameter
  2021-09-12  7:48 ` [PATCH 03/20] nubus-device: add device slot parameter Mark Cave-Ayland
@ 2021-09-12 15:15   ` Philippe Mathieu-Daudé
  2021-09-12 16:43     ` Mark Cave-Ayland
  0 siblings, 1 reply; 47+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-12 15:15 UTC (permalink / raw)
  To: Mark Cave-Ayland, qemu-devel, laurent

On 9/12/21 9:48 AM, Mark Cave-Ayland wrote:
> This prepares for allowing Nubus devices to be placed in a specific slot instead
> of always being auto-allocated by the bus itself.
> 
> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
> ---
>  hw/nubus/nubus-device.c  | 6 ++++++
>  include/hw/nubus/nubus.h | 2 +-
>  2 files changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/nubus/nubus-device.c b/hw/nubus/nubus-device.c
> index 36203848e5..c1832f73da 100644
> --- a/hw/nubus/nubus-device.c
> +++ b/hw/nubus/nubus-device.c
> @@ -191,12 +191,18 @@ static void nubus_device_realize(DeviceState *dev, Error **errp)
>      nubus_register_format_block(nd);
>  }
>  
> +static Property nubus_device_properties[] = {
> +    DEFINE_PROP_INT32("slot", NubusDevice, slot, -1),
> +    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);

Can we reorder this after #4 where you sanity check 'slot'
in nubus_device_realize()? First sanity check, then expose
the property.


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PATCH 06/20] nubus: implement BusClass get_dev_path()
  2021-09-12  7:49 ` [PATCH 06/20] nubus: implement BusClass get_dev_path() Mark Cave-Ayland
@ 2021-09-12 15:16   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 47+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-12 15:16 UTC (permalink / raw)
  To: Mark Cave-Ayland, qemu-devel, laurent

On 9/12/21 9:49 AM, Mark Cave-Ayland wrote:
> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
> ---
>  hw/nubus/nubus-bus.c | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PATCH 07/20] nubus: add trace-events for unassigned slot accesses
  2021-09-12  7:49 ` [PATCH 07/20] nubus: add trace-events for unassigned slot accesses Mark Cave-Ayland
@ 2021-09-12 15:18   ` Philippe Mathieu-Daudé
  2021-09-12 16:45     ` Mark Cave-Ayland
  0 siblings, 1 reply; 47+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-12 15:18 UTC (permalink / raw)
  To: Mark Cave-Ayland, qemu-devel, laurent

On 9/12/21 9:49 AM, Mark Cave-Ayland wrote:
> These allow tracing of the Nubus enumeration process by the guest OS.
> 
> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
> ---
>  hw/nubus/nubus-bus.c  | 10 +++++++---
>  hw/nubus/trace-events |  7 +++++++
>  hw/nubus/trace.h      |  1 +
>  meson.build           |  1 +
>  4 files changed, 16 insertions(+), 3 deletions(-)
>  create mode 100644 hw/nubus/trace-events
>  create mode 100644 hw/nubus/trace.h

> @@ -38,7 +40,7 @@ static const MemoryRegionOps nubus_slot_ops = {
>      .endianness = DEVICE_BIG_ENDIAN,
>      .valid = {
>          .min_access_size = 1,
> -        .max_access_size = 1,
> +        .max_access_size = 4,
>      },
>  };

This patch does a bit more that what is described.

> @@ -60,7 +64,7 @@ static const MemoryRegionOps nubus_super_slot_ops = {
>      .endianness = DEVICE_BIG_ENDIAN,
>      .valid = {
>          .min_access_size = 1,
> -        .max_access_size = 1,
> +        .max_access_size = 4,
>      },
>  };


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PATCH 08/20] nubus: generate bus error when attempting to access empty slots
  2021-09-12  7:49 ` [PATCH 08/20] nubus: generate bus error when attempting to access empty slots Mark Cave-Ayland
@ 2021-09-12 15:19   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 47+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-12 15:19 UTC (permalink / raw)
  To: Mark Cave-Ayland, qemu-devel, laurent

On 9/12/21 9:49 AM, Mark Cave-Ayland wrote:
> According to "Designing Cards and Drivers for the Macintosh Family" any attempt
> to access an unimplemented address location on Nubus generates a bus error. MacOS
> uses a custom bus error handler to detect empty Nubus slots, and with the current
> implementation assumes that all slots are occupied as the Nubus transactions
> never fail.
> 
> Switch nubus_slot_ops and nubus_super_slot_ops over to use {read,write}_with_attrs
> and hard-code them to return MEMTX_DECODE_ERROR so that unoccupied Nubus slots
> will generate the expected bus error.
> 
> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
> ---
>  hw/nubus/nubus-bus.c | 34 ++++++++++++++++++----------------
>  1 file changed, 18 insertions(+), 16 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PATCH 12/20] nubus: move nubus to its own 32-bit address space
  2021-09-12  7:49 ` [PATCH 12/20] nubus: move nubus to its own 32-bit address space Mark Cave-Ayland
@ 2021-09-12 15:22   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 47+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-12 15:22 UTC (permalink / raw)
  To: Mark Cave-Ayland, qemu-devel, laurent

On 9/12/21 9:49 AM, Mark Cave-Ayland wrote:
> According to "Designing Cards and Drivers for the Macintosh Family" the Nubus
> has its own 32-bit address space based upon physical slot addressing.
> 
> Move Nubus to its own 32-bit address space and then use memory region aliases
> to map available slot and super slot ranges into the q800 system address
> space via the Macintosh Nubus bridge.
> 
> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
> ---
>  hw/m68k/q800.c                      |  8 +++-----
>  hw/nubus/mac-nubus-bridge.c         | 15 +++++++++++++--
>  hw/nubus/nubus-bus.c                | 18 ++++++++++++++++++
>  hw/nubus/nubus-device.c             |  2 +-
>  include/hw/nubus/mac-nubus-bridge.h |  2 ++
>  include/hw/nubus/nubus.h            | 10 +++++++---
>  6 files changed, 44 insertions(+), 11 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PATCH 13/20] nubus-bridge: introduce separate NubusBridge structure
  2021-09-12  7:49 ` [PATCH 13/20] nubus-bridge: introduce separate NubusBridge structure Mark Cave-Ayland
@ 2021-09-12 15:23   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 47+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-12 15:23 UTC (permalink / raw)
  To: Mark Cave-Ayland, qemu-devel, laurent

On 9/12/21 9:49 AM, Mark Cave-Ayland wrote:
> This is to allow the Nubus bridge to store its own additional state. Also update
> the comment in the file header to reflect that nubus-bridge is not specific to
> the Macintosh.
> 
> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
> ---
>  hw/nubus/nubus-bridge.c             | 4 ++--
>  include/hw/nubus/mac-nubus-bridge.h | 2 +-
>  include/hw/nubus/nubus.h            | 6 ++++++
>  3 files changed, 9 insertions(+), 3 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PATCH 14/20] mac-nubus-bridge: rename MacNubusState to MacNubusBridge
  2021-09-12  7:49 ` [PATCH 14/20] mac-nubus-bridge: rename MacNubusState to MacNubusBridge Mark Cave-Ayland
@ 2021-09-12 15:23   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 47+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-12 15:23 UTC (permalink / raw)
  To: Mark Cave-Ayland, qemu-devel, laurent

On 9/12/21 9:49 AM, Mark Cave-Ayland wrote:
> This better reflects that the mac-nubus-bridge device is derived from the
> nubus-bridge device, and that the structure represents the state of the bridge
> device and not the Nubus itself. Also update the comment in the file header to
> reflect that mac-nubus-bridge is specific to the Macintosh.
> 
> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
> ---
>  hw/nubus/mac-nubus-bridge.c         | 8 +++++---
>  include/hw/nubus/mac-nubus-bridge.h | 4 ++--
>  2 files changed, 7 insertions(+), 5 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PATCH 15/20] nubus: move NubusBus from mac-nubus-bridge to nubus-bridge
  2021-09-12  7:49 ` [PATCH 15/20] nubus: move NubusBus from mac-nubus-bridge to nubus-bridge Mark Cave-Ayland
@ 2021-09-12 15:25   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 47+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-12 15:25 UTC (permalink / raw)
  To: Mark Cave-Ayland, qemu-devel, laurent

On 9/12/21 9:49 AM, Mark Cave-Ayland wrote:
> Now that Nubus has its own address space rather than mapping directly into the
> system bus, move the Nubus reference from MacNubusBridge to NubusBridge.
> 
> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
> ---
>  hw/m68k/q800.c                      | 2 +-
>  hw/nubus/mac-nubus-bridge.c         | 9 ++++-----
>  hw/nubus/nubus-bridge.c             | 9 +++++++++
>  include/hw/nubus/mac-nubus-bridge.h | 1 -
>  include/hw/nubus/nubus.h            | 2 ++
>  5 files changed, 16 insertions(+), 7 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PATCH 16/20] nubus-bridge: embed the NubusBus object directly within nubus-bridge
  2021-09-12  7:49 ` [PATCH 16/20] nubus-bridge: embed the NubusBus object directly within nubus-bridge Mark Cave-Ayland
@ 2021-09-12 15:26   ` Philippe Mathieu-Daudé
  2021-09-12 17:43   ` Philippe Mathieu-Daudé
  1 sibling, 0 replies; 47+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-12 15:26 UTC (permalink / raw)
  To: Mark Cave-Ayland, qemu-devel, laurent

On 9/12/21 9:49 AM, Mark Cave-Ayland wrote:
> Since nubus-bridge is a container for NubusBus then it should be embedded
> directly within the bridge device using qbus_create_inplace().
> 
> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
> ---
>  hw/m68k/q800.c              | 2 +-
>  hw/nubus/mac-nubus-bridge.c | 7 ++++---
>  hw/nubus/nubus-bridge.c     | 3 ++-
>  include/hw/nubus/nubus.h    | 2 +-
>  4 files changed, 8 insertions(+), 6 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PATCH 00/20] nubus: bus, device, bridge, IRQ and address space improvements
  2021-09-12  7:48 [PATCH 00/20] nubus: bus, device, bridge, IRQ and address space improvements Mark Cave-Ayland
                   ` (19 preceding siblings ...)
  2021-09-12  7:49 ` [PATCH 20/20] q800: configure nubus available slots for Quadra 800 Mark Cave-Ayland
@ 2021-09-12 15:47 ` Philippe Mathieu-Daudé
  2021-09-12 16:56   ` Mark Cave-Ayland
  20 siblings, 1 reply; 47+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-12 15:47 UTC (permalink / raw)
  To: Mark Cave-Ayland, qemu-devel, laurent

Hi Mark,

On 9/12/21 9:48 AM, Mark Cave-Ayland wrote:
> This patchset is the next set of changes required to boot MacOS on the q800 machine. The
> main aim of these patches is to improve the Nubus support so that devices can be plugged
> into the Nubus from the command line i.e.
> 
>     -device nubus-macfb[,romfile=decl.rom]
> 
> At the moment the only device that can be plugged into the Nubus is the macfb framebuffer
> however with these changes it is possible to take a ROM from a real Nubus card and
> attempt to use it in QEMU, and also allow for future interfaces such as virtio.
> 
> Patches 1 to 6 move the logic which manages bus addresses from the NubusDevice into
> the NubusBus itself, including the introduction of a bitmap to manage available
> slots on the bus.
> 
> Patches 7 and 8 change the handling for unassigned (empty) slots to generate a bus
> fault and add trace events to allow logging of empty slot accesses during Nubus
> enumeration.
> 
> Patches 9 to 11 remove the existing stubs for generating the format block (the epilogue
> of the Nubus device embedded ROM consisting of metadata and a checksum) and replace them
> with a romfile device property to allow the entire Nubus ROM to be loaded from a file
> into the ROM area, similar to a PCI option ROM.
> 
> Patch 12 moves the Nubus into its own separate address space whilst patches 13 to 17
> update the NubusBridge (and MacNubusBridge) devices to allow machines to map the
> required slots from the Nubus address space using sysbus_mmio_map().
> 
> Finally patches 18 to 20 add support for Nubus IRQs and wire them up appropriately for
> the q800 machine through VIA2, which is required for the next set of macfb updates.

Some questions:

- TYPE_NUBUS_BRIDGE is not abstract. So far, beside
  TYPE_MAC_NUBUS_BRIDGE, no other code use it. Could it
  be use as it? If so, shouldn't the code in
  mac_nubus_bridge_init() be moved to nubus_bridge_realize(),
  creating the slot alias regions generically using the
  slot range from slot_available_mask or using another
  property?

- Why is "slot-available-mask" a bridge device property and
  not a bus one?

Regards,

Phil.


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PATCH 02/20] nubus-device: expose separate super slot memory region
  2021-09-12  7:48 ` [PATCH 02/20] nubus-device: expose separate super slot memory region Mark Cave-Ayland
@ 2021-09-12 15:50   ` Philippe Mathieu-Daudé
  2021-09-12 17:20     ` Mark Cave-Ayland
  0 siblings, 1 reply; 47+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-12 15:50 UTC (permalink / raw)
  To: Mark Cave-Ayland, qemu-devel, laurent

On 9/12/21 9:48 AM, Mark Cave-Ayland wrote:
> According to "Designing Cards and Drivers for the Macintosh Family" each physical
> nubus slot can access 2 separate address ranges: a super slot memory region which
> is 256MB and a standard slot memory region which is 16MB.
> 
> Currently a Nubus device uses the physical slot number to determine whether it is
> using a standard slot memory region or a super slot memory region rather than
> exposing both memory regions for use as required.
> 
> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
> ---
>  hw/nubus/nubus-device.c  | 36 ++++++++++++++++++------------------
>  include/hw/nubus/nubus.h |  1 +
>  2 files changed, 19 insertions(+), 18 deletions(-)
> 
> diff --git a/hw/nubus/nubus-device.c b/hw/nubus/nubus-device.c
> index be01269563..36203848e5 100644
> --- a/hw/nubus/nubus-device.c
> +++ b/hw/nubus/nubus-device.c
> @@ -168,26 +168,26 @@ static void nubus_device_realize(DeviceState *dev, Error **errp)
>      }
>  
>      nd->slot = nubus->current_slot++;
> -    name = g_strdup_printf("nubus-slot-%d", nd->slot);
> -
> -    if (nd->slot < NUBUS_FIRST_SLOT) {
> -        /* Super */
> -        slot_offset = (nd->slot - 6) * NUBUS_SUPER_SLOT_SIZE;
> -
> -        memory_region_init(&nd->slot_mem, OBJECT(dev), name,
> -                           NUBUS_SUPER_SLOT_SIZE);
> -        memory_region_add_subregion(&nubus->super_slot_io, slot_offset,
> -                                    &nd->slot_mem);
> -    } else {
> -        /* Normal */
> -        slot_offset = nd->slot * NUBUS_SLOT_SIZE;
> -
> -        memory_region_init(&nd->slot_mem, OBJECT(dev), name, NUBUS_SLOT_SIZE);
> -        memory_region_add_subregion(&nubus->slot_io, slot_offset,
> -                                    &nd->slot_mem);
> -    }
>  
> +    /* Super */
> +    slot_offset = (nd->slot - 6) * 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);

I'd rather use "nubus-standard-slot-%x" or "nubus-normal-slot-%x"
to differentiate from super-bus. (This also applies to variable
names and trace events in this series).

Anyway,
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PATCH 18/20] nubus: add support for slot IRQs
  2021-09-12  7:49 ` [PATCH 18/20] nubus: add support for slot IRQs Mark Cave-Ayland
@ 2021-09-12 16:00   ` Philippe Mathieu-Daudé
  2021-09-12 17:05     ` Mark Cave-Ayland
  0 siblings, 1 reply; 47+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-12 16:00 UTC (permalink / raw)
  To: Mark Cave-Ayland, qemu-devel, laurent

On 9/12/21 9:49 AM, Mark Cave-Ayland wrote:
> Each Nubus slot has an IRQ line that can be used to request service from the
> CPU. Connect the IRQs to the Nubus bridge so that they can be wired up using qdev
> gpios accordingly, and introduce a new nubus_set_irq() function that can be used
> by Nubus devices to control the slot IRQ.
> 
> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
> ---
>  hw/nubus/nubus-bridge.c  | 2 ++
>  hw/nubus/nubus-device.c  | 8 ++++++++
>  include/hw/nubus/nubus.h | 6 ++++++
>  3 files changed, 16 insertions(+)
> 
> diff --git a/hw/nubus/nubus-bridge.c b/hw/nubus/nubus-bridge.c
> index 2c7c4ee121..0366d925a9 100644
> --- a/hw/nubus/nubus-bridge.c
> +++ b/hw/nubus/nubus-bridge.c
> @@ -19,6 +19,8 @@ static void nubus_bridge_init(Object *obj)
>      NubusBus *bus = &s->bus;
>  
>      qbus_create_inplace(bus, sizeof(s->bus), TYPE_NUBUS_BUS, DEVICE(s), NULL);
> +
> +    qdev_init_gpio_out(DEVICE(s), bus->irqs, NUBUS_IRQS);
>  }

I'm confused, the IRQs belong to the bus, but you create them
on the bridge device (I know, the bus is not a qdev)...

>  static Property nubus_bridge_properties[] = {
> diff --git a/hw/nubus/nubus-device.c b/hw/nubus/nubus-device.c
> index f316eb7789..67ab281943 100644
> --- a/hw/nubus/nubus-device.c
> +++ b/hw/nubus/nubus-device.c
> @@ -10,12 +10,20 @@
>  
>  #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));
> diff --git a/include/hw/nubus/nubus.h b/include/hw/nubus/nubus.h
> index 503ebf0c1c..2b9c4c77ac 100644
> --- a/include/hw/nubus/nubus.h
> +++ b/include/hw/nubus/nubus.h
> @@ -24,6 +24,8 @@
>  #define NUBUS_FIRST_SLOT      0x0
>  #define NUBUS_LAST_SLOT       0xf
>  
> +#define NUBUS_IRQS            16
> +
>  #define TYPE_NUBUS_DEVICE "nubus-device"
>  OBJECT_DECLARE_SIMPLE_TYPE(NubusDevice, NUBUS_DEVICE)
>  
> @@ -43,6 +45,8 @@ struct NubusBus {
>      MemoryRegion slot_io;
>  
>      uint32_t slot_available_mask;
> +
> +    qemu_irq irqs[NUBUS_IRQS];
>  };
>  
>  #define NUBUS_DECL_ROM_MAX_SIZE    0xffff
> @@ -58,6 +62,8 @@ struct NubusDevice {
>      MemoryRegion decl_rom;
>  };
>  
> +void nubus_set_irq(NubusDevice *nd, int level);

... then the API only involves a device and a bus, the
bridge is hidden.


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PATCH 03/20] nubus-device: add device slot parameter
  2021-09-12 15:15   ` Philippe Mathieu-Daudé
@ 2021-09-12 16:43     ` Mark Cave-Ayland
  0 siblings, 0 replies; 47+ messages in thread
From: Mark Cave-Ayland @ 2021-09-12 16:43 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel, laurent

On 12/09/2021 16:15, Philippe Mathieu-Daudé wrote:

> On 9/12/21 9:48 AM, Mark Cave-Ayland wrote:
>> This prepares for allowing Nubus devices to be placed in a specific slot instead
>> of always being auto-allocated by the bus itself.
>>
>> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
>> ---
>>   hw/nubus/nubus-device.c  | 6 ++++++
>>   include/hw/nubus/nubus.h | 2 +-
>>   2 files changed, 7 insertions(+), 1 deletion(-)
>>
>> diff --git a/hw/nubus/nubus-device.c b/hw/nubus/nubus-device.c
>> index 36203848e5..c1832f73da 100644
>> --- a/hw/nubus/nubus-device.c
>> +++ b/hw/nubus/nubus-device.c
>> @@ -191,12 +191,18 @@ static void nubus_device_realize(DeviceState *dev, Error **errp)
>>       nubus_register_format_block(nd);
>>   }
>>   
>> +static Property nubus_device_properties[] = {
>> +    DEFINE_PROP_INT32("slot", NubusDevice, slot, -1),
>> +    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);
> 
> Can we reorder this after #4 where you sanity check 'slot'
> in nubus_device_realize()? First sanity check, then expose
> the property.

The slot number is already being checked at this point to ensure that it lies between 
NUBUS_FIRST_SLOT and NUBUS_LAST_SLOT (see the change to NUBUS_FIRST_SLOT in patch 4). 
Note that patch 4 also converts the range 0x9-0xf to the equivalent bitmask to ensure 
there should be no change in the available slots.


ATB,

Mark.


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PATCH 07/20] nubus: add trace-events for unassigned slot accesses
  2021-09-12 15:18   ` Philippe Mathieu-Daudé
@ 2021-09-12 16:45     ` Mark Cave-Ayland
  0 siblings, 0 replies; 47+ messages in thread
From: Mark Cave-Ayland @ 2021-09-12 16:45 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel, laurent

On 12/09/2021 16:18, Philippe Mathieu-Daudé wrote:

> On 9/12/21 9:49 AM, Mark Cave-Ayland wrote:
>> These allow tracing of the Nubus enumeration process by the guest OS.
>>
>> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
>> ---
>>   hw/nubus/nubus-bus.c  | 10 +++++++---
>>   hw/nubus/trace-events |  7 +++++++
>>   hw/nubus/trace.h      |  1 +
>>   meson.build           |  1 +
>>   4 files changed, 16 insertions(+), 3 deletions(-)
>>   create mode 100644 hw/nubus/trace-events
>>   create mode 100644 hw/nubus/trace.h
> 
>> @@ -38,7 +40,7 @@ static const MemoryRegionOps nubus_slot_ops = {
>>       .endianness = DEVICE_BIG_ENDIAN,
>>       .valid = {
>>           .min_access_size = 1,
>> -        .max_access_size = 1,
>> +        .max_access_size = 4,
>>       },
>>   };
> 
> This patch does a bit more that what is described.

Ah oops - presumably one of the OSs I was testing was probing with 32-bit accesses 
instead of 8-bit accesses and I made the adjustment to ensure the bus enumeration for 
empty slots appeared in the trace events.

I'll update the commit message accordingly.

>> @@ -60,7 +64,7 @@ static const MemoryRegionOps nubus_super_slot_ops = {
>>       .endianness = DEVICE_BIG_ENDIAN,
>>       .valid = {
>>           .min_access_size = 1,
>> -        .max_access_size = 1,
>> +        .max_access_size = 4,
>>       },
>>   };


ATB,

Mark.


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PATCH 00/20] nubus: bus, device, bridge, IRQ and address space improvements
  2021-09-12 15:47 ` [PATCH 00/20] nubus: bus, device, bridge, IRQ and address space improvements Philippe Mathieu-Daudé
@ 2021-09-12 16:56   ` Mark Cave-Ayland
  0 siblings, 0 replies; 47+ messages in thread
From: Mark Cave-Ayland @ 2021-09-12 16:56 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel, laurent

On 12/09/2021 16:47, Philippe Mathieu-Daudé wrote:

> On 9/12/21 9:48 AM, Mark Cave-Ayland wrote:
>> This patchset is the next set of changes required to boot MacOS on the q800 machine. The
>> main aim of these patches is to improve the Nubus support so that devices can be plugged
>> into the Nubus from the command line i.e.
>>
>>      -device nubus-macfb[,romfile=decl.rom]
>>
>> At the moment the only device that can be plugged into the Nubus is the macfb framebuffer
>> however with these changes it is possible to take a ROM from a real Nubus card and
>> attempt to use it in QEMU, and also allow for future interfaces such as virtio.
>>
>> Patches 1 to 6 move the logic which manages bus addresses from the NubusDevice into
>> the NubusBus itself, including the introduction of a bitmap to manage available
>> slots on the bus.
>>
>> Patches 7 and 8 change the handling for unassigned (empty) slots to generate a bus
>> fault and add trace events to allow logging of empty slot accesses during Nubus
>> enumeration.
>>
>> Patches 9 to 11 remove the existing stubs for generating the format block (the epilogue
>> of the Nubus device embedded ROM consisting of metadata and a checksum) and replace them
>> with a romfile device property to allow the entire Nubus ROM to be loaded from a file
>> into the ROM area, similar to a PCI option ROM.
>>
>> Patch 12 moves the Nubus into its own separate address space whilst patches 13 to 17
>> update the NubusBridge (and MacNubusBridge) devices to allow machines to map the
>> required slots from the Nubus address space using sysbus_mmio_map().
>>
>> Finally patches 18 to 20 add support for Nubus IRQs and wire them up appropriately for
>> the q800 machine through VIA2, which is required for the next set of macfb updates.

Thanks for the review so far :)

> Some questions:
> 
> - TYPE_NUBUS_BRIDGE is not abstract. So far, beside
>    TYPE_MAC_NUBUS_BRIDGE, no other code use it. Could it
>    be use as it? If so, shouldn't the code in
>    mac_nubus_bridge_init() be moved to nubus_bridge_realize(),
>    creating the slot alias regions generically using the
>    slot range from slot_available_mask or using another
>    property?

Not yet, but Nubus was available on non-Apple machines. Given that TYPE_NUBUS_BRIDGE 
and TYPE_MAC_NUBUS_BRIDGE are already there, it seems a shame to prevent anyone who 
wanted to experiment with Nubus in other ways by hard-coding in the Macintosh 
restrictions.

> - Why is "slot-available-mask" a bridge device property and
>    not a bus one?

Architecturally a Nubus always has 16 slots with 1 IRQ per slot (you can compare this 
with PCI always having 32 slots with 4 possible IRQs per slot). In the Macintosh 
design Apple restricted the available address space by mapping a partial address 
range onto the CPU bus, so I'd argue that this is an implementation property of the 
bridge. And of course device properties already exist which helps make things easier 
too :)


ATB,

Mark.


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PATCH 18/20] nubus: add support for slot IRQs
  2021-09-12 16:00   ` Philippe Mathieu-Daudé
@ 2021-09-12 17:05     ` Mark Cave-Ayland
  0 siblings, 0 replies; 47+ messages in thread
From: Mark Cave-Ayland @ 2021-09-12 17:05 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel, laurent

On 12/09/2021 17:00, Philippe Mathieu-Daudé wrote:

> On 9/12/21 9:49 AM, Mark Cave-Ayland wrote:
>> Each Nubus slot has an IRQ line that can be used to request service from the
>> CPU. Connect the IRQs to the Nubus bridge so that they can be wired up using qdev
>> gpios accordingly, and introduce a new nubus_set_irq() function that can be used
>> by Nubus devices to control the slot IRQ.
>>
>> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
>> ---
>>   hw/nubus/nubus-bridge.c  | 2 ++
>>   hw/nubus/nubus-device.c  | 8 ++++++++
>>   include/hw/nubus/nubus.h | 6 ++++++
>>   3 files changed, 16 insertions(+)
>>
>> diff --git a/hw/nubus/nubus-bridge.c b/hw/nubus/nubus-bridge.c
>> index 2c7c4ee121..0366d925a9 100644
>> --- a/hw/nubus/nubus-bridge.c
>> +++ b/hw/nubus/nubus-bridge.c
>> @@ -19,6 +19,8 @@ static void nubus_bridge_init(Object *obj)
>>       NubusBus *bus = &s->bus;
>>   
>>       qbus_create_inplace(bus, sizeof(s->bus), TYPE_NUBUS_BUS, DEVICE(s), NULL);
>> +
>> +    qdev_init_gpio_out(DEVICE(s), bus->irqs, NUBUS_IRQS);
>>   }
> 
> I'm confused, the IRQs belong to the bus, but you create them
> on the bridge device (I know, the bus is not a qdev)...

Following on the same logic from my previous mail: the IRQs already exist as physical 
lines within the bus, but they are published (i.e. connected) via the bridge to the 
CPU. This also allows the use of GPIOs to wire up the Nubus without having to devise 
a whole new set of Nubus infrastructure just for interrupts.

Certainly this feels different when you compare with PCI, but then I'd also argue 
that the existing PCI code predates QOM/qdev and if it were written today it would be 
done differently.

>>   static Property nubus_bridge_properties[] = {
>> diff --git a/hw/nubus/nubus-device.c b/hw/nubus/nubus-device.c
>> index f316eb7789..67ab281943 100644
>> --- a/hw/nubus/nubus-device.c
>> +++ b/hw/nubus/nubus-device.c
>> @@ -10,12 +10,20 @@
>>   
>>   #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));
>> diff --git a/include/hw/nubus/nubus.h b/include/hw/nubus/nubus.h
>> index 503ebf0c1c..2b9c4c77ac 100644
>> --- a/include/hw/nubus/nubus.h
>> +++ b/include/hw/nubus/nubus.h
>> @@ -24,6 +24,8 @@
>>   #define NUBUS_FIRST_SLOT      0x0
>>   #define NUBUS_LAST_SLOT       0xf
>>   
>> +#define NUBUS_IRQS            16
>> +
>>   #define TYPE_NUBUS_DEVICE "nubus-device"
>>   OBJECT_DECLARE_SIMPLE_TYPE(NubusDevice, NUBUS_DEVICE)
>>   
>> @@ -43,6 +45,8 @@ struct NubusBus {
>>       MemoryRegion slot_io;
>>   
>>       uint32_t slot_available_mask;
>> +
>> +    qemu_irq irqs[NUBUS_IRQS];
>>   };
>>   
>>   #define NUBUS_DECL_ROM_MAX_SIZE    0xffff
>> @@ -58,6 +62,8 @@ struct NubusDevice {
>>       MemoryRegion decl_rom;
>>   };
>>   
>> +void nubus_set_irq(NubusDevice *nd, int level);
> 
> ... then the API only involves a device and a bus, the
> bridge is hidden.

That's correct. All a Nubus device cares about is being able to raise and lower its 
IRQ line: the routing between the Nubus and the CPU is delegated to the Nubus bridge.


ATB,

Mark.


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PATCH 02/20] nubus-device: expose separate super slot memory region
  2021-09-12 15:50   ` Philippe Mathieu-Daudé
@ 2021-09-12 17:20     ` Mark Cave-Ayland
  2021-09-12 17:31       ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 47+ messages in thread
From: Mark Cave-Ayland @ 2021-09-12 17:20 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel, laurent

On 12/09/2021 16:50, Philippe Mathieu-Daudé wrote:

> On 9/12/21 9:48 AM, Mark Cave-Ayland wrote:
>> According to "Designing Cards and Drivers for the Macintosh Family" each physical
>> nubus slot can access 2 separate address ranges: a super slot memory region which
>> is 256MB and a standard slot memory region which is 16MB.
>>
>> Currently a Nubus device uses the physical slot number to determine whether it is
>> using a standard slot memory region or a super slot memory region rather than
>> exposing both memory regions for use as required.
>>
>> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
>> ---
>>   hw/nubus/nubus-device.c  | 36 ++++++++++++++++++------------------
>>   include/hw/nubus/nubus.h |  1 +
>>   2 files changed, 19 insertions(+), 18 deletions(-)
>>
>> diff --git a/hw/nubus/nubus-device.c b/hw/nubus/nubus-device.c
>> index be01269563..36203848e5 100644
>> --- a/hw/nubus/nubus-device.c
>> +++ b/hw/nubus/nubus-device.c
>> @@ -168,26 +168,26 @@ static void nubus_device_realize(DeviceState *dev, Error **errp)
>>       }
>>   
>>       nd->slot = nubus->current_slot++;
>> -    name = g_strdup_printf("nubus-slot-%d", nd->slot);
>> -
>> -    if (nd->slot < NUBUS_FIRST_SLOT) {
>> -        /* Super */
>> -        slot_offset = (nd->slot - 6) * NUBUS_SUPER_SLOT_SIZE;
>> -
>> -        memory_region_init(&nd->slot_mem, OBJECT(dev), name,
>> -                           NUBUS_SUPER_SLOT_SIZE);
>> -        memory_region_add_subregion(&nubus->super_slot_io, slot_offset,
>> -                                    &nd->slot_mem);
>> -    } else {
>> -        /* Normal */
>> -        slot_offset = nd->slot * NUBUS_SLOT_SIZE;
>> -
>> -        memory_region_init(&nd->slot_mem, OBJECT(dev), name, NUBUS_SLOT_SIZE);
>> -        memory_region_add_subregion(&nubus->slot_io, slot_offset,
>> -                                    &nd->slot_mem);
>> -    }
>>   
>> +    /* Super */
>> +    slot_offset = (nd->slot - 6) * 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);
> 
> I'd rather use "nubus-standard-slot-%x" or "nubus-normal-slot-%x"
> to differentiate from super-bus. (This also applies to variable
> names and trace events in this series).

I can see how this may seem ambiguous, however in "Designing Cards and Drivers for 
the Macintosh Family" the documentation always refers to "slot" as a standard slot so 
there shouldn't be any confusion for developers here.

> Anyway,
> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>


ATB,

Mark.


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PATCH 02/20] nubus-device: expose separate super slot memory region
  2021-09-12 17:20     ` Mark Cave-Ayland
@ 2021-09-12 17:31       ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 47+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-12 17:31 UTC (permalink / raw)
  To: Mark Cave-Ayland, qemu-devel, laurent

On 9/12/21 7:20 PM, Mark Cave-Ayland wrote:
> On 12/09/2021 16:50, Philippe Mathieu-Daudé wrote:
> 
>> On 9/12/21 9:48 AM, Mark Cave-Ayland wrote:
>>> According to "Designing Cards and Drivers for the Macintosh Family"
>>> each physical
>>> nubus slot can access 2 separate address ranges: a super slot memory
>>> region which
>>> is 256MB and a standard slot memory region which is 16MB.
>>>
>>> Currently a Nubus device uses the physical slot number to determine
>>> whether it is
>>> using a standard slot memory region or a super slot memory region
>>> rather than
>>> exposing both memory regions for use as required.
>>>
>>> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
>>> ---
>>>   hw/nubus/nubus-device.c  | 36 ++++++++++++++++++------------------
>>>   include/hw/nubus/nubus.h |  1 +
>>>   2 files changed, 19 insertions(+), 18 deletions(-)
>>>
>>> diff --git a/hw/nubus/nubus-device.c b/hw/nubus/nubus-device.c
>>> index be01269563..36203848e5 100644
>>> --- a/hw/nubus/nubus-device.c
>>> +++ b/hw/nubus/nubus-device.c
>>> @@ -168,26 +168,26 @@ static void nubus_device_realize(DeviceState
>>> *dev, Error **errp)
>>>       }
>>>         nd->slot = nubus->current_slot++;
>>> -    name = g_strdup_printf("nubus-slot-%d", nd->slot);
>>> -
>>> -    if (nd->slot < NUBUS_FIRST_SLOT) {
>>> -        /* Super */
>>> -        slot_offset = (nd->slot - 6) * NUBUS_SUPER_SLOT_SIZE;
>>> -
>>> -        memory_region_init(&nd->slot_mem, OBJECT(dev), name,
>>> -                           NUBUS_SUPER_SLOT_SIZE);
>>> -        memory_region_add_subregion(&nubus->super_slot_io, slot_offset,
>>> -                                    &nd->slot_mem);
>>> -    } else {
>>> -        /* Normal */
>>> -        slot_offset = nd->slot * NUBUS_SLOT_SIZE;
>>> -
>>> -        memory_region_init(&nd->slot_mem, OBJECT(dev), name,
>>> NUBUS_SLOT_SIZE);
>>> -        memory_region_add_subregion(&nubus->slot_io, slot_offset,
>>> -                                    &nd->slot_mem);
>>> -    }
>>>   +    /* Super */
>>> +    slot_offset = (nd->slot - 6) * 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);
>>
>> I'd rather use "nubus-standard-slot-%x" or "nubus-normal-slot-%x"
>> to differentiate from super-bus. (This also applies to variable
>> names and trace events in this series).
> 
> I can see how this may seem ambiguous, however in "Designing Cards and
> Drivers for the Macintosh Family" the documentation always refers to
> "slot" as a standard slot so there shouldn't be any confusion for
> developers here.

OK, fine then.

>> Anyway,
>> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PATCH 11/20] nubus-device: add romfile property for loading declaration ROMs
  2021-09-12  7:49 ` [PATCH 11/20] nubus-device: add romfile property for loading declaration ROMs Mark Cave-Ayland
@ 2021-09-12 17:39   ` Philippe Mathieu-Daudé
  2021-09-14 20:23     ` Mark Cave-Ayland
  0 siblings, 1 reply; 47+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-12 17:39 UTC (permalink / raw)
  To: Mark Cave-Ayland, qemu-devel, laurent

On 9/12/21 9:49 AM, Mark Cave-Ayland wrote:
> The declaration ROM is located at the top-most address of the standard slot
> space.
> 
> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
> ---
>  hw/nubus/nubus-device.c  | 43 +++++++++++++++++++++++++++++++++++++++-
>  include/hw/nubus/nubus.h |  5 +++++
>  2 files changed, 47 insertions(+), 1 deletion(-)

> +    /* Declaration ROM */

> +        } else if (size > NUBUS_DECL_ROM_MAX_SIZE) {

I'd check for >= and define as (64 * KiB).

> +            error_setg(errp, "romfile \"%s\" too large (maximum size 64K)",
> +                       nd->romfile);
> +            g_free(path);
> +            return;
> +        }

> diff --git a/include/hw/nubus/nubus.h b/include/hw/nubus/nubus.h
> index 87a97516c7..42f4c9dbb8 100644
> --- a/include/hw/nubus/nubus.h
> +++ b/include/hw/nubus/nubus.h
> @@ -39,12 +39,17 @@ struct NubusBus {
>      uint32_t slot_available_mask;
>  };
>  
> +#define NUBUS_DECL_ROM_MAX_SIZE    0xffff


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PATCH 16/20] nubus-bridge: embed the NubusBus object directly within nubus-bridge
  2021-09-12  7:49 ` [PATCH 16/20] nubus-bridge: embed the NubusBus object directly within nubus-bridge Mark Cave-Ayland
  2021-09-12 15:26   ` Philippe Mathieu-Daudé
@ 2021-09-12 17:43   ` Philippe Mathieu-Daudé
  2021-09-14 20:26     ` Mark Cave-Ayland
  1 sibling, 1 reply; 47+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-12 17:43 UTC (permalink / raw)
  To: Mark Cave-Ayland, qemu-devel, laurent

On 9/12/21 9:49 AM, Mark Cave-Ayland wrote:
> Since nubus-bridge is a container for NubusBus then it should be embedded
> directly within the bridge device using qbus_create_inplace().
> 
> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
> ---
>  hw/m68k/q800.c              | 2 +-
>  hw/nubus/mac-nubus-bridge.c | 7 ++++---
>  hw/nubus/nubus-bridge.c     | 3 ++-
>  include/hw/nubus/nubus.h    | 2 +-
>  4 files changed, 8 insertions(+), 6 deletions(-)

> diff --git a/hw/nubus/mac-nubus-bridge.c b/hw/nubus/mac-nubus-bridge.c
> index c16cfc4ab3..c23d5d508d 100644
> --- a/hw/nubus/mac-nubus-bridge.c
> +++ b/hw/nubus/mac-nubus-bridge.c
> @@ -18,18 +18,19 @@ 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 */
> -    nb->bus->slot_available_mask = 0x7e00;
> +    bus->slot_available_mask = 0x7e00;

Re-reading I'd use MAKE_64BIT_MASK(9, 6)
or eventually MAKE_64BIT_MASK(9, 0xe - 0x6 + 1).


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PATCH 04/20] nubus: use bitmap to manage available slots
  2021-09-12  7:48 ` [PATCH 04/20] nubus: use bitmap to manage available slots Mark Cave-Ayland
@ 2021-09-12 17:48   ` Philippe Mathieu-Daudé
  2021-09-14 20:27     ` Mark Cave-Ayland
  0 siblings, 1 reply; 47+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-12 17:48 UTC (permalink / raw)
  To: Mark Cave-Ayland, qemu-devel, laurent

On 9/12/21 9:48 AM, Mark Cave-Ayland wrote:
> Convert nubus_device_realize() to use a bitmap to manage available slots to allow
> for future Nubus devices to be plugged into arbitrary slots from the command line.
> 
> Update mac_nubus_bridge_init() to only allow slots 0x9 to 0xe on a Macintosh
> machines as documented in "Desigining Cards and Drivers for the Macintosh Family".
> 
> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
> ---
>  hw/nubus/mac-nubus-bridge.c |  3 +++
>  hw/nubus/nubus-bus.c        |  2 +-
>  hw/nubus/nubus-device.c     | 33 +++++++++++++++++++++++++++------
>  include/hw/nubus/nubus.h    |  4 ++--
>  4 files changed, 33 insertions(+), 9 deletions(-)
> 
> diff --git a/hw/nubus/mac-nubus-bridge.c b/hw/nubus/mac-nubus-bridge.c
> index 7c329300b8..6e78f4c0b3 100644
> --- a/hw/nubus/mac-nubus-bridge.c
> +++ b/hw/nubus/mac-nubus-bridge.c
> @@ -18,6 +18,9 @@ static void mac_nubus_bridge_init(Object *obj)
>  
>      s->bus = NUBUS_BUS(qbus_create(TYPE_NUBUS_BUS, DEVICE(s), NULL));
>  
> +    /* Macintosh only has slots 0x9 to 0xe available */
> +    s->bus->slot_available_mask = 0x7e00;

So MAKE_64BIT_MASK(9, 6),

>      sysbus_init_mmio(sbd, &s->bus->super_slot_io);
>      sysbus_init_mmio(sbd, &s->bus->slot_io);
>  }
> diff --git a/hw/nubus/nubus-bus.c b/hw/nubus/nubus-bus.c
> index 5c13452308..f6d3655f51 100644
> --- a/hw/nubus/nubus-bus.c
> +++ b/hw/nubus/nubus-bus.c
> @@ -84,7 +84,7 @@ static void nubus_init(Object *obj)
>                            nubus, "nubus-slots",
>                            NUBUS_SLOT_NB * NUBUS_SLOT_SIZE);
>  
> -    nubus->current_slot = NUBUS_FIRST_SLOT;
> +    nubus->slot_available_mask = 0xffff;

and MAKE_64BIT_MASK(0, 16)?

>  }


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PATCH 11/20] nubus-device: add romfile property for loading declaration ROMs
  2021-09-12 17:39   ` Philippe Mathieu-Daudé
@ 2021-09-14 20:23     ` Mark Cave-Ayland
  2021-09-15  8:16       ` Mark Cave-Ayland
  0 siblings, 1 reply; 47+ messages in thread
From: Mark Cave-Ayland @ 2021-09-14 20:23 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel, laurent

On 12/09/2021 18:39, Philippe Mathieu-Daudé wrote:

> On 9/12/21 9:49 AM, Mark Cave-Ayland wrote:
>> The declaration ROM is located at the top-most address of the standard slot
>> space.
>>
>> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
>> ---
>>   hw/nubus/nubus-device.c  | 43 +++++++++++++++++++++++++++++++++++++++-
>>   include/hw/nubus/nubus.h |  5 +++++
>>   2 files changed, 47 insertions(+), 1 deletion(-)
> 
>> +    /* Declaration ROM */
> 
>> +        } else if (size > NUBUS_DECL_ROM_MAX_SIZE) {
> 
> I'd check for >= and define as (64 * KiB).

That's a good idea - I'll update this for the v2.

>> +            error_setg(errp, "romfile \"%s\" too large (maximum size 64K)",
>> +                       nd->romfile);
>> +            g_free(path);
>> +            return;
>> +        }
> 
>> diff --git a/include/hw/nubus/nubus.h b/include/hw/nubus/nubus.h
>> index 87a97516c7..42f4c9dbb8 100644
>> --- a/include/hw/nubus/nubus.h
>> +++ b/include/hw/nubus/nubus.h
>> @@ -39,12 +39,17 @@ struct NubusBus {
>>       uint32_t slot_available_mask;
>>   };
>>   
>> +#define NUBUS_DECL_ROM_MAX_SIZE    0xffff


ATB,

Mark.


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PATCH 16/20] nubus-bridge: embed the NubusBus object directly within nubus-bridge
  2021-09-12 17:43   ` Philippe Mathieu-Daudé
@ 2021-09-14 20:26     ` Mark Cave-Ayland
  0 siblings, 0 replies; 47+ messages in thread
From: Mark Cave-Ayland @ 2021-09-14 20:26 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel, laurent

On 12/09/2021 18:43, Philippe Mathieu-Daudé wrote:

> On 9/12/21 9:49 AM, Mark Cave-Ayland wrote:
>> Since nubus-bridge is a container for NubusBus then it should be embedded
>> directly within the bridge device using qbus_create_inplace().
>>
>> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
>> ---
>>   hw/m68k/q800.c              | 2 +-
>>   hw/nubus/mac-nubus-bridge.c | 7 ++++---
>>   hw/nubus/nubus-bridge.c     | 3 ++-
>>   include/hw/nubus/nubus.h    | 2 +-
>>   4 files changed, 8 insertions(+), 6 deletions(-)
> 
>> diff --git a/hw/nubus/mac-nubus-bridge.c b/hw/nubus/mac-nubus-bridge.c
>> index c16cfc4ab3..c23d5d508d 100644
>> --- a/hw/nubus/mac-nubus-bridge.c
>> +++ b/hw/nubus/mac-nubus-bridge.c
>> @@ -18,18 +18,19 @@ 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 */
>> -    nb->bus->slot_available_mask = 0x7e00;
>> +    bus->slot_available_mask = 0x7e00;
> 
> Re-reading I'd use MAKE_64BIT_MASK(9, 6)
> or eventually MAKE_64BIT_MASK(9, 0xe - 0x6 + 1).

Thanks, I'll go for MAKE_64BIT_MASK(9, 6) here in v2.


ATB,

Mark.


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PATCH 04/20] nubus: use bitmap to manage available slots
  2021-09-12 17:48   ` Philippe Mathieu-Daudé
@ 2021-09-14 20:27     ` Mark Cave-Ayland
  0 siblings, 0 replies; 47+ messages in thread
From: Mark Cave-Ayland @ 2021-09-14 20:27 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel, laurent

On 12/09/2021 18:48, Philippe Mathieu-Daudé wrote:

> On 9/12/21 9:48 AM, Mark Cave-Ayland wrote:
>> Convert nubus_device_realize() to use a bitmap to manage available slots to allow
>> for future Nubus devices to be plugged into arbitrary slots from the command line.
>>
>> Update mac_nubus_bridge_init() to only allow slots 0x9 to 0xe on a Macintosh
>> machines as documented in "Desigining Cards and Drivers for the Macintosh Family".
>>
>> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
>> ---
>>   hw/nubus/mac-nubus-bridge.c |  3 +++
>>   hw/nubus/nubus-bus.c        |  2 +-
>>   hw/nubus/nubus-device.c     | 33 +++++++++++++++++++++++++++------
>>   include/hw/nubus/nubus.h    |  4 ++--
>>   4 files changed, 33 insertions(+), 9 deletions(-)
>>
>> diff --git a/hw/nubus/mac-nubus-bridge.c b/hw/nubus/mac-nubus-bridge.c
>> index 7c329300b8..6e78f4c0b3 100644
>> --- a/hw/nubus/mac-nubus-bridge.c
>> +++ b/hw/nubus/mac-nubus-bridge.c
>> @@ -18,6 +18,9 @@ static void mac_nubus_bridge_init(Object *obj)
>>   
>>       s->bus = NUBUS_BUS(qbus_create(TYPE_NUBUS_BUS, DEVICE(s), NULL));
>>   
>> +    /* Macintosh only has slots 0x9 to 0xe available */
>> +    s->bus->slot_available_mask = 0x7e00;
> 
> So MAKE_64BIT_MASK(9, 6),
> 
>>       sysbus_init_mmio(sbd, &s->bus->super_slot_io);
>>       sysbus_init_mmio(sbd, &s->bus->slot_io);
>>   }
>> diff --git a/hw/nubus/nubus-bus.c b/hw/nubus/nubus-bus.c
>> index 5c13452308..f6d3655f51 100644
>> --- a/hw/nubus/nubus-bus.c
>> +++ b/hw/nubus/nubus-bus.c
>> @@ -84,7 +84,7 @@ static void nubus_init(Object *obj)
>>                             nubus, "nubus-slots",
>>                             NUBUS_SLOT_NB * NUBUS_SLOT_SIZE);
>>   
>> -    nubus->current_slot = NUBUS_FIRST_SLOT;
>> +    nubus->slot_available_mask = 0xffff;
> 
> and MAKE_64BIT_MASK(0, 16)?
> 
>>   }

I'll convert these over to use MAKE_64BIT_MASK too :)


ATB,

Mark.


^ permalink raw reply	[flat|nested] 47+ messages in thread

* Re: [PATCH 11/20] nubus-device: add romfile property for loading declaration ROMs
  2021-09-14 20:23     ` Mark Cave-Ayland
@ 2021-09-15  8:16       ` Mark Cave-Ayland
  0 siblings, 0 replies; 47+ messages in thread
From: Mark Cave-Ayland @ 2021-09-15  8:16 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel, laurent

On 14/09/2021 21:23, Mark Cave-Ayland wrote:

> On 12/09/2021 18:39, Philippe Mathieu-Daudé wrote:
> 
>> On 9/12/21 9:49 AM, Mark Cave-Ayland wrote:
>>> The declaration ROM is located at the top-most address of the standard slot
>>> space.
>>>
>>> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
>>> ---
>>>   hw/nubus/nubus-device.c  | 43 +++++++++++++++++++++++++++++++++++++++-
>>>   include/hw/nubus/nubus.h |  5 +++++
>>>   2 files changed, 47 insertions(+), 1 deletion(-)
>>
>>> +    /* Declaration ROM */
>>
>>> +        } else if (size > NUBUS_DECL_ROM_MAX_SIZE) {
>>
>> I'd check for >= and define as (64 * KiB).
> 
> That's a good idea - I'll update this for the v2.

And in fact it looks like it is possible to embed multi-function MacOS drivers in the 
declaration ROM so I'll keep the > and increase the maximum size to 128K which should 
give plenty of breathing space for binary drivers.

>>> +            error_setg(errp, "romfile \"%s\" too large (maximum size 64K)",
>>> +                       nd->romfile);
>>> +            g_free(path);
>>> +            return;
>>> +        }
>>
>>> diff --git a/include/hw/nubus/nubus.h b/include/hw/nubus/nubus.h
>>> index 87a97516c7..42f4c9dbb8 100644
>>> --- a/include/hw/nubus/nubus.h
>>> +++ b/include/hw/nubus/nubus.h
>>> @@ -39,12 +39,17 @@ struct NubusBus {
>>>       uint32_t slot_available_mask;
>>>   };
>>> +#define NUBUS_DECL_ROM_MAX_SIZE    0xffff


ATB,

Mark.


^ permalink raw reply	[flat|nested] 47+ messages in thread

end of thread, other threads:[~2021-09-15  8:17 UTC | newest]

Thread overview: 47+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-12  7:48 [PATCH 00/20] nubus: bus, device, bridge, IRQ and address space improvements Mark Cave-Ayland
2021-09-12  7:48 ` [PATCH 01/20] nubus-device: rename slot_nb variable to slot Mark Cave-Ayland
2021-09-12 15:09   ` Philippe Mathieu-Daudé
2021-09-12  7:48 ` [PATCH 02/20] nubus-device: expose separate super slot memory region Mark Cave-Ayland
2021-09-12 15:50   ` Philippe Mathieu-Daudé
2021-09-12 17:20     ` Mark Cave-Ayland
2021-09-12 17:31       ` Philippe Mathieu-Daudé
2021-09-12  7:48 ` [PATCH 03/20] nubus-device: add device slot parameter Mark Cave-Ayland
2021-09-12 15:15   ` Philippe Mathieu-Daudé
2021-09-12 16:43     ` Mark Cave-Ayland
2021-09-12  7:48 ` [PATCH 04/20] nubus: use bitmap to manage available slots Mark Cave-Ayland
2021-09-12 17:48   ` Philippe Mathieu-Daudé
2021-09-14 20:27     ` Mark Cave-Ayland
2021-09-12  7:48 ` [PATCH 05/20] nubus: move slot bitmap checks from NubusDevice realize() to BusClass check_address() Mark Cave-Ayland
2021-09-12  7:49 ` [PATCH 06/20] nubus: implement BusClass get_dev_path() Mark Cave-Ayland
2021-09-12 15:16   ` Philippe Mathieu-Daudé
2021-09-12  7:49 ` [PATCH 07/20] nubus: add trace-events for unassigned slot accesses Mark Cave-Ayland
2021-09-12 15:18   ` Philippe Mathieu-Daudé
2021-09-12 16:45     ` Mark Cave-Ayland
2021-09-12  7:49 ` [PATCH 08/20] nubus: generate bus error when attempting to access empty slots Mark Cave-Ayland
2021-09-12 15:19   ` Philippe Mathieu-Daudé
2021-09-12  7:49 ` [PATCH 09/20] macfb: don't register declaration ROM Mark Cave-Ayland
2021-09-12  7:49 ` [PATCH 10/20] nubus-device: remove nubus_register_rom() and nubus_register_format_block() Mark Cave-Ayland
2021-09-12  7:49 ` [PATCH 11/20] nubus-device: add romfile property for loading declaration ROMs Mark Cave-Ayland
2021-09-12 17:39   ` Philippe Mathieu-Daudé
2021-09-14 20:23     ` Mark Cave-Ayland
2021-09-15  8:16       ` Mark Cave-Ayland
2021-09-12  7:49 ` [PATCH 12/20] nubus: move nubus to its own 32-bit address space Mark Cave-Ayland
2021-09-12 15:22   ` Philippe Mathieu-Daudé
2021-09-12  7:49 ` [PATCH 13/20] nubus-bridge: introduce separate NubusBridge structure Mark Cave-Ayland
2021-09-12 15:23   ` Philippe Mathieu-Daudé
2021-09-12  7:49 ` [PATCH 14/20] mac-nubus-bridge: rename MacNubusState to MacNubusBridge Mark Cave-Ayland
2021-09-12 15:23   ` Philippe Mathieu-Daudé
2021-09-12  7:49 ` [PATCH 15/20] nubus: move NubusBus from mac-nubus-bridge to nubus-bridge Mark Cave-Ayland
2021-09-12 15:25   ` Philippe Mathieu-Daudé
2021-09-12  7:49 ` [PATCH 16/20] nubus-bridge: embed the NubusBus object directly within nubus-bridge Mark Cave-Ayland
2021-09-12 15:26   ` Philippe Mathieu-Daudé
2021-09-12 17:43   ` Philippe Mathieu-Daudé
2021-09-14 20:26     ` Mark Cave-Ayland
2021-09-12  7:49 ` [PATCH 17/20] nubus-bridge: make slot_available_mask a qdev property Mark Cave-Ayland
2021-09-12  7:49 ` [PATCH 18/20] nubus: add support for slot IRQs Mark Cave-Ayland
2021-09-12 16:00   ` Philippe Mathieu-Daudé
2021-09-12 17:05     ` Mark Cave-Ayland
2021-09-12  7:49 ` [PATCH 19/20] q800: wire up nubus IRQs Mark Cave-Ayland
2021-09-12  7:49 ` [PATCH 20/20] q800: configure nubus available slots for Quadra 800 Mark Cave-Ayland
2021-09-12 15:47 ` [PATCH 00/20] nubus: bus, device, bridge, IRQ and address space improvements Philippe Mathieu-Daudé
2021-09-12 16:56   ` Mark Cave-Ayland

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.