Skip to contentSkip to conversation

q800: fix I/O memory map

PATCH Superseded Laurent Vivier 2 participants 3 messages Nov 2, 2019 – Nov 4, 2019

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 q800: fix I/O memory map

Linux kernel 5.4 will introduce a new memory map for SWIM device. (aee6bff1c325 ("m68k: mac: Revisit floppy disc controller base addresses"))

Until this release all MMIO are mapped between 0x50f00000 and 0x50f40000, but it appears that for real hardware 0x50f00000 is not the base address:
the MMIO region spans 0x50000000 through 0x60000000, and 0x50040000 through 0x54000000 is repeated images of 0x50000000 to 0x50040000.

Fixed: 04e7ca8d0f ("hw/m68k: define Macintosh Quadra 800")

---

Notes:
v2: add some constant definitions
allocate a bloc of memory to stores all I/O MemoryRegion

 hw/m68k/q800.c | 40 ++++++++++++++++++++++++++++++++--------
 1 file changed, 32 insertions(+), 8 deletions(-)
hw/m68k/q800.c +32 -8
index 2b4842f8c6..822bd13d36 100644
@@ -60,14 +60,19 @@
 #define MACH_MAC        3
 #define Q800_MAC_CPU_ID 2
 
-#define VIA_BASE              0x50f00000
-#define SONIC_PROM_BASE       0x50f08000
-#define SONIC_BASE            0x50f0a000
-#define SCC_BASE              0x50f0c020
-#define ESP_BASE              0x50f10000
-#define ESP_PDMA              0x50f10100
-#define ASC_BASE              0x50F14000
-#define SWIM_BASE             0x50F1E000
+#define IO_BASE               0x50000000
+#define IO_SLICE              0x00040000
+#define IO_SIZE               0x04000000
+
+#define VIA_BASE              (IO_BASE + 0x00000)
+#define SONIC_PROM_BASE       (IO_BASE + 0x08000)
+#define SONIC_BASE            (IO_BASE + 0x0a000)
+#define SCC_BASE              (IO_BASE + 0x0c020)
+#define ESP_BASE              (IO_BASE + 0x10000)
+#define ESP_PDMA              (IO_BASE + 0x10100)
+#define ASC_BASE              (IO_BASE + 0x14000)
+#define SWIM_BASE             (IO_BASE + 0x1E000)
+
 #define NUBUS_SUPER_SLOT_BASE 0x60000000
 #define NUBUS_SLOT_BASE       0xf0000000
 
@@ -135,6 +140,9 @@ static void q800_init(MachineState *machine)
     int32_t initrd_size;
     MemoryRegion *rom;
     MemoryRegion *ram;
+    MemoryRegion *io;
+    const int io_slice_nb = (IO_SIZE / IO_SLICE) - 1;
+    int i;
     ram_addr_t ram_size = machine->ram_size;
     const char *kernel_filename = machine->kernel_filename;
     const char *initrd_filename = machine->initrd_filename;
@@ -163,10 +171,26 @@ static void q800_init(MachineState *machine)
     cpu = M68K_CPU(cpu_create(machine->cpu_type));
     qemu_register_reset(main_cpu_reset, cpu);
 
+    /* RAM */
     ram = g_malloc(sizeof(*ram));
     memory_region_init_ram(ram, NULL, "m68k_mac.ram", ram_size, &error_abort);
     memory_region_add_subregion(get_system_memory(), 0, ram);
 
+    /*
+     * Memory from IO_BASE to IO_BASE + IO_SLICE is repeated
+     * from IO_BASE + IO_SLICE to IO_BASE + IO_SIZE
+     */
+    io = g_new(MemoryRegion, io_slice_nb);
+    for (i = 0; i < io_slice_nb; i++) {
+        char *name = g_strdup_printf("mac_m68k.io[%d]", i + 1);
+
+        memory_region_init_alias(io + i, NULL, name, get_system_memory(),
+                                 IO_BASE, IO_SLICE);
+        memory_region_add_subregion(get_system_memory(),
+                                    IO_BASE + (i + 1) * IO_SLICE, io + i);
+        g_free(name);
+    }
+
     /* IRQ Glue */
 
     irq = g_new0(GLUEState, 1);
Signature · 1 line
2.21.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 30 lines · Laurent Vivier

Linux kernel 5.4 will introduce a new memory map for SWIM device. (aee6bff1c325 ("m68k: mac: Revisit floppy disc controller base addresses"))

Until this release all MMIO are mapped between 0x50f00000 and 0x50f40000, but it appears that for real hardware 0x50f00000 is not the base address:
the MMIO region spans 0x50000000 through 0x60000000, and 0x50040000 through 0x54000000 is repeated images of 0x50000000 to 0x50040000.

Fixed: 04e7ca8d0f ("hw/m68k: define Macintosh Quadra 800")

---

Notes:
v2: add some constant definitions
allocate a bloc of memory to stores all I/O MemoryRegion

  hw/m68k/q800.c | 40 ++++++++++++++++++++++++++++++++--------
  1 file changed, 32 insertions(+), 8 deletions(-)
hw/m68k/q800.c +0 -3
index 2b4842f8c6..822bd13d36 100644
@@ -60,14 +60,19 @@
  #define MACH_MAC        3
  #define Q800_MAC_CPU_ID 2
 
-#define VIA_BASE              0x50f00000
-#define SONIC_PROM_BASE       0x50f08000
-#define SONIC_BASE            0x50f0a000

hw/m68k/q800.c line 67

Quoted 10 lines
hw/m68k/q800.c +5 -5
-#define SCC_BASE              0x50f0c020
-#define ESP_BASE              0x50f10000
-#define ESP_PDMA              0x50f10100
-#define ASC_BASE              0x50F14000
-#define SWIM_BASE             0x50F1E000
+#define IO_BASE               0x50000000
+#define IO_SLICE              0x00040000
+#define IO_SIZE               0x04000000
+
+#define VIA_BASE              (IO_BASE + 0x00000)

Good idea.

Quoted 29 lines
hw/m68k/q800.c +12 -0
+#define SONIC_PROM_BASE       (IO_BASE + 0x08000)
+#define SONIC_BASE            (IO_BASE + 0x0a000)
+#define SCC_BASE              (IO_BASE + 0x0c020)
+#define ESP_BASE              (IO_BASE + 0x10000)
+#define ESP_PDMA              (IO_BASE + 0x10100)
+#define ASC_BASE              (IO_BASE + 0x14000)
+#define SWIM_BASE             (IO_BASE + 0x1E000)
+
  #define NUBUS_SUPER_SLOT_BASE 0x60000000
  #define NUBUS_SLOT_BASE       0xf0000000
 
@@ -135,6 +140,9 @@ static void q800_init(MachineState *machine)
      int32_t initrd_size;
      MemoryRegion *rom;
      MemoryRegion *ram;
+    MemoryRegion *io;
+    const int io_slice_nb = (IO_SIZE / IO_SLICE) - 1;
+    int i;
      ram_addr_t ram_size = machine->ram_size;
      const char *kernel_filename = machine->kernel_filename;
      const char *initrd_filename = machine->initrd_filename;
@@ -163,10 +171,26 @@ static void q800_init(MachineState *machine)
      cpu = M68K_CPU(cpu_create(machine->cpu_type));
      qemu_register_reset(main_cpu_reset, cpu);
 
+    /* RAM */
      ram = g_malloc(sizeof(*ram));
      memory_region_init_ram(ram, NULL, "m68k_mac.ram", ram_size, &error_abort);
      memory_region_add_subregion(get_system_memory(), 0, ram);

hw/m68k/q800.c static void q800_init(MachineState *machine) · line 187

Quoted 10 lines
hw/m68k/q800.c +9 -0
 
+    /*
+     * Memory from IO_BASE to IO_BASE + IO_SLICE is repeated
+     * from IO_BASE + IO_SLICE to IO_BASE + IO_SIZE
+     */
+    io = g_new(MemoryRegion, io_slice_nb);
+    for (i = 0; i < io_slice_nb; i++) {
+        char *name = g_strdup_printf("mac_m68k.io[%d]", i + 1);
+
+        memory_region_init_alias(io + i, NULL, name, get_system_memory(),

We usually use &io[i], anyway:

Quoted 10 lines
hw/m68k/q800.c +6 -0
+                                 IO_BASE, IO_SLICE);
+        memory_region_add_subregion(get_system_memory(),
+                                    IO_BASE + (i + 1) * IO_SLICE, io + i);
+        g_free(name);
+    }
+
      /* IRQ Glue */
 
      irq = g_new0(GLUEState, 1);
#2 lore raw

Le 03/11/2019 à 23:30, Philippe Mathieu-Daudé a écrit :

Quoted 77 lines · Laurent Vivier
Quoted 31 lines

Linux kernel 5.4 will introduce a new memory map for SWIM device. (aee6bff1c325 ("m68k: mac: Revisit floppy disc controller base addresses"))

Until this release all MMIO are mapped between 0x50f00000 and 0x50f40000, but it appears that for real hardware 0x50f00000 is not the base address:
the MMIO region spans 0x50000000 through 0x60000000, and 0x50040000 through
0x54000000 is repeated images of 0x50000000 to 0x50040000.

Fixed: 04e7ca8d0f ("hw/m68k: define Macintosh Quadra 800")

---

Notes:
     v2: add some constant definitions
         allocate a bloc of memory to stores all I/O MemoryRegion

  hw/m68k/q800.c | 40 ++++++++++++++++++++++++++++++++--------

  1 file changed, 32 insertions(+), 8 deletions(-)
hw/m68k/q800.c +0 -0
index 2b4842f8c6..822bd13d36 100644
@@ -60,14 +60,19 @@
   #define MACH_MAC        3
   #define Q800_MAC_CPU_ID 2

  -#define VIA_BASE              0x50f00000

hw/m68k/q800.c +0 -2
-#define SONIC_PROM_BASE       0x50f08000
-#define SONIC_BASE            0x50f0a000

hw/m68k/q800.c line 67

Quoted 10 lines
hw/m68k/q800.c +5 -5
-#define SCC_BASE              0x50f0c020
-#define ESP_BASE              0x50f10000
-#define ESP_PDMA              0x50f10100
-#define ASC_BASE              0x50F14000
-#define SWIM_BASE             0x50F1E000
+#define IO_BASE               0x50000000
+#define IO_SLICE              0x00040000
+#define IO_SIZE               0x04000000
+
+#define VIA_BASE              (IO_BASE + 0x00000)

Good idea.

Quoted 32 lines
hw/m68k/q800.c +8 -0
+#define SONIC_PROM_BASE       (IO_BASE + 0x08000)
+#define SONIC_BASE            (IO_BASE + 0x0a000)
+#define SCC_BASE              (IO_BASE + 0x0c020)
+#define ESP_BASE              (IO_BASE + 0x10000)
+#define ESP_PDMA              (IO_BASE + 0x10100)
+#define ASC_BASE              (IO_BASE + 0x14000)
+#define SWIM_BASE             (IO_BASE + 0x1E000)
+

  #define NUBUS_SUPER_SLOT_BASE 0x60000000
  #define NUBUS_SLOT_BASE       0xf0000000
  @@ -135,6 +140,9 @@ static void q800_init(MachineState *machine) int32_t initrd_size;
      MemoryRegion *rom;
      MemoryRegion *ram;
+    MemoryRegion *io;
+    const int io_slice_nb = (IO_SIZE / IO_SLICE) - 1; +    int i;
      ram_addr_t ram_size = machine->ram_size;
      const char *kernel_filename = machine->kernel_filename; const char *initrd_filename = machine->initrd_filename;

hw/m68k/q800.c +0 -0
@@ -163,10 +171,26 @@ static void q800_init(MachineState *machine)
       cpu = M68K_CPU(cpu_create(machine->cpu_type));
       qemu_register_reset(main_cpu_reset, cpu);

  +    /* RAM */
      ram = g_malloc(sizeof(*ram)); memory_region_init_ram(ram, NULL, "m68k_mac.ram", ram_size, &error_abort); memory_region_add_subregion(get_system_memory(), 0, ram); +    /*
+     * Memory from IO_BASE to IO_BASE + IO_SLICE is repeated +     * from IO_BASE + IO_SLICE to IO_BASE + IO_SIZE
+     */

Quoted 8 lines
Quoted 6 lines

+    io = g_new(MemoryRegion, io_slice_nb);
+    for (i = 0; i < io_slice_nb; i++) {
+        char *name = g_strdup_printf("mac_m68k.io[%d]", i + 1); +
+        memory_region_init_alias(io + i, NULL, name, get_system_memory(),

We usually use &io[i], anyway:

ok, I'll update in this way before adding it to my pull request.

Quoted 2 lines

Thanks,
Laurent