* [PULL 01/10] hw/m68k/irqc: Pass CPU using QOM link property
2023-11-02 10:05 [PULL 00/10] m68k patches Thomas Huth
@ 2023-11-02 10:05 ` Thomas Huth
2023-11-02 10:05 ` [PULL 02/10] hw/m68k/mcf5206: " Thomas Huth
` (9 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Thomas Huth @ 2023-11-02 10:05 UTC (permalink / raw)
To: qemu-devel, Stefan Hajnoczi; +Cc: Philippe Mathieu-Daudé
From: Philippe Mathieu-Daudé <philmd@linaro.org>
Avoid the interrupt controller directly access the 'first_cpu'
global. Pass 'cpu' from the board code.
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Thomas Huth <huth@tuxfamily.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-ID: <20231024083010.12453-2-philmd@linaro.org>
Signed-off-by: Thomas Huth <huth@tuxfamily.org>
---
hw/intc/m68k_irqc.c | 10 +++++++++-
hw/m68k/virt.c | 2 ++
include/hw/intc/m68k_irqc.h | 1 +
3 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/hw/intc/m68k_irqc.c b/hw/intc/m68k_irqc.c
index 0c515e4ecb..e09705eeaf 100644
--- a/hw/intc/m68k_irqc.c
+++ b/hw/intc/m68k_irqc.c
@@ -11,6 +11,7 @@
#include "cpu.h"
#include "migration/vmstate.h"
#include "monitor/monitor.h"
+#include "hw/qdev-properties.h"
#include "hw/nmi.h"
#include "hw/intc/intc.h"
#include "hw/intc/m68k_irqc.h"
@@ -35,7 +36,7 @@ static void m68k_irqc_print_info(InterruptStatsProvider *obj, Monitor *mon)
static void m68k_set_irq(void *opaque, int irq, int level)
{
M68KIRQCState *s = opaque;
- M68kCPU *cpu = M68K_CPU(first_cpu);
+ M68kCPU *cpu = M68K_CPU(s->cpu);
int i;
if (level) {
@@ -85,12 +86,19 @@ static const VMStateDescription vmstate_m68k_irqc = {
}
};
+static Property m68k_irqc_properties[] = {
+ DEFINE_PROP_LINK("m68k-cpu", M68KIRQCState, cpu,
+ TYPE_M68K_CPU, ArchCPU *),
+ DEFINE_PROP_END_OF_LIST(),
+};
+
static void m68k_irqc_class_init(ObjectClass *oc, void *data)
{
DeviceClass *dc = DEVICE_CLASS(oc);
NMIClass *nc = NMI_CLASS(oc);
InterruptStatsProviderClass *ic = INTERRUPT_STATS_PROVIDER_CLASS(oc);
+ device_class_set_props(dc, m68k_irqc_properties);
nc->nmi_monitor_handler = m68k_nmi;
dc->reset = m68k_irqc_reset;
dc->vmsd = &vmstate_m68k_irqc;
diff --git a/hw/m68k/virt.c b/hw/m68k/virt.c
index 2dd3c99894..e7dc188855 100644
--- a/hw/m68k/virt.c
+++ b/hw/m68k/virt.c
@@ -155,6 +155,8 @@ static void virt_init(MachineState *machine)
/* IRQ Controller */
irqc_dev = qdev_new(TYPE_M68K_IRQC);
+ object_property_set_link(OBJECT(irqc_dev), "m68k-cpu",
+ OBJECT(cpu), &error_abort);
sysbus_realize_and_unref(SYS_BUS_DEVICE(irqc_dev), &error_fatal);
/*
diff --git a/include/hw/intc/m68k_irqc.h b/include/hw/intc/m68k_irqc.h
index ef91f21812..693e33b0aa 100644
--- a/include/hw/intc/m68k_irqc.h
+++ b/include/hw/intc/m68k_irqc.h
@@ -33,6 +33,7 @@ typedef struct M68KIRQCState {
SysBusDevice parent_obj;
uint8_t ipr;
+ ArchCPU *cpu;
/* statistics */
uint64_t stats_irq_count[M68K_IRQC_LEVEL_NUM];
--
2.41.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PULL 02/10] hw/m68k/mcf5206: Pass CPU using QOM link property
2023-11-02 10:05 [PULL 00/10] m68k patches Thomas Huth
2023-11-02 10:05 ` [PULL 01/10] hw/m68k/irqc: Pass CPU using QOM link property Thomas Huth
@ 2023-11-02 10:05 ` Thomas Huth
2023-11-02 10:05 ` [PULL 03/10] hw/m68k/mcf_intc: Expose MMIO region via SysBus API Thomas Huth
` (8 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Thomas Huth @ 2023-11-02 10:05 UTC (permalink / raw)
To: qemu-devel, Stefan Hajnoczi; +Cc: Philippe Mathieu-Daudé
From: Philippe Mathieu-Daudé <philmd@linaro.org>
Avoid the interrupt controller directly access the first cpu via
the qemu_get_cpu() call. Pass it as argument to mcf5206_init()
from the board code.
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Thomas Huth <huth@tuxfamily.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-ID: <20231024083010.12453-3-philmd@linaro.org>
Signed-off-by: Thomas Huth <huth@tuxfamily.org>
---
hw/m68k/an5206.c | 6 ++++--
hw/m68k/mcf5206.c | 9 ++++++++-
2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/hw/m68k/an5206.c b/hw/m68k/an5206.c
index 11ae4c9795..1e8e64f8bd 100644
--- a/hw/m68k/an5206.c
+++ b/hw/m68k/an5206.c
@@ -20,12 +20,14 @@
#define AN5206_MBAR_ADDR 0x10000000
#define AN5206_RAMBAR_ADDR 0x20000000
-static void mcf5206_init(MemoryRegion *sysmem, uint32_t base)
+static void mcf5206_init(M68kCPU *cpu, MemoryRegion *sysmem, uint32_t base)
{
DeviceState *dev;
SysBusDevice *s;
dev = qdev_new(TYPE_MCF5206_MBAR);
+ object_property_set_link(OBJECT(dev), "m68k-cpu",
+ OBJECT(cpu), &error_abort);
s = SYS_BUS_DEVICE(dev);
sysbus_realize_and_unref(s, &error_fatal);
@@ -60,7 +62,7 @@ static void an5206_init(MachineState *machine)
memory_region_init_ram(sram, NULL, "an5206.sram", 512, &error_fatal);
memory_region_add_subregion(address_space_mem, AN5206_RAMBAR_ADDR, sram);
- mcf5206_init(address_space_mem, AN5206_MBAR_ADDR);
+ mcf5206_init(cpu, address_space_mem, AN5206_MBAR_ADDR);
/* Load kernel. */
if (!kernel_filename) {
diff --git a/hw/m68k/mcf5206.c b/hw/m68k/mcf5206.c
index 2ab1b4f059..f920ca2ceb 100644
--- a/hw/m68k/mcf5206.c
+++ b/hw/m68k/mcf5206.c
@@ -10,6 +10,7 @@
#include "qemu/error-report.h"
#include "qemu/log.h"
#include "cpu.h"
+#include "hw/qdev-properties.h"
#include "hw/boards.h"
#include "hw/irq.h"
#include "hw/m68k/mcf.h"
@@ -601,13 +602,19 @@ static void mcf5206_mbar_realize(DeviceState *dev, Error **errp)
s->timer[1] = m5206_timer_init(s->pic[10]);
s->uart[0] = mcf_uart_init(s->pic[12], serial_hd(0));
s->uart[1] = mcf_uart_init(s->pic[13], serial_hd(1));
- s->cpu = M68K_CPU(qemu_get_cpu(0));
}
+static Property mcf5206_mbar_properties[] = {
+ DEFINE_PROP_LINK("m68k-cpu", m5206_mbar_state, cpu,
+ TYPE_M68K_CPU, M68kCPU *),
+ DEFINE_PROP_END_OF_LIST(),
+};
+
static void mcf5206_mbar_class_init(ObjectClass *oc, void *data)
{
DeviceClass *dc = DEVICE_CLASS(oc);
+ device_class_set_props(dc, mcf5206_mbar_properties);
set_bit(DEVICE_CATEGORY_MISC, dc->categories);
dc->desc = "MCF5206 system integration module";
dc->realize = mcf5206_mbar_realize;
--
2.41.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PULL 03/10] hw/m68k/mcf_intc: Expose MMIO region via SysBus API
2023-11-02 10:05 [PULL 00/10] m68k patches Thomas Huth
2023-11-02 10:05 ` [PULL 01/10] hw/m68k/irqc: Pass CPU using QOM link property Thomas Huth
2023-11-02 10:05 ` [PULL 02/10] hw/m68k/mcf5206: " Thomas Huth
@ 2023-11-02 10:05 ` Thomas Huth
2023-11-02 10:05 ` [PULL 04/10] hw/m68k/mcf_intc: Pass CPU using QOM link property Thomas Huth
` (7 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Thomas Huth @ 2023-11-02 10:05 UTC (permalink / raw)
To: qemu-devel, Stefan Hajnoczi; +Cc: Philippe Mathieu-Daudé
From: Philippe Mathieu-Daudé <philmd@linaro.org>
QOM objects shouldn't access each other internals fields
except using the QOM API.
Here the caller of mcf_intc_init() access the MMIO region from
the MCF_INTC state. Avoid that by exposing that region via
sysbus_init_mmio(), then get it with sysbus_mmio_get_region().
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Tested-by: Thomas Huth <huth@tuxfamily.org>
Reviewed-by: Thomas Huth <huth@tuxfamily.org>
Message-ID: <20231024083010.12453-4-philmd@linaro.org>
Signed-off-by: Thomas Huth <huth@tuxfamily.org>
---
hw/m68k/mcf_intc.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/hw/m68k/mcf_intc.c b/hw/m68k/mcf_intc.c
index 4cd30188c0..1f74ea0e14 100644
--- a/hw/m68k/mcf_intc.c
+++ b/hw/m68k/mcf_intc.c
@@ -173,6 +173,7 @@ static void mcf_intc_instance_init(Object *obj)
mcf_intc_state *s = MCF_INTC(obj);
memory_region_init_io(&s->iomem, obj, &mcf_intc_ops, s, "mcf", 0x100);
+ sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->iomem);
}
static void mcf_intc_class_init(ObjectClass *oc, void *data)
@@ -211,7 +212,8 @@ qemu_irq *mcf_intc_init(MemoryRegion *sysmem,
s = MCF_INTC(dev);
s->cpu = cpu;
- memory_region_add_subregion(sysmem, base, &s->iomem);
+ memory_region_add_subregion(sysmem, base,
+ sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 0));
return qemu_allocate_irqs(mcf_intc_set_irq, s, 64);
}
--
2.41.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PULL 04/10] hw/m68k/mcf_intc: Pass CPU using QOM link property
2023-11-02 10:05 [PULL 00/10] m68k patches Thomas Huth
` (2 preceding siblings ...)
2023-11-02 10:05 ` [PULL 03/10] hw/m68k/mcf_intc: Expose MMIO region via SysBus API Thomas Huth
@ 2023-11-02 10:05 ` Thomas Huth
2023-11-02 10:05 ` [PULL 05/10] hw/m68k/next-cube: Do not open-code sysbus_create_simple() Thomas Huth
` (6 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Thomas Huth @ 2023-11-02 10:05 UTC (permalink / raw)
To: qemu-devel, Stefan Hajnoczi; +Cc: Philippe Mathieu-Daudé
From: Philippe Mathieu-Daudé <philmd@linaro.org>
QOM objects shouldn't access each other internals fields
except using the QOM API.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Tested-by: Thomas Huth <huth@tuxfamily.org>
Reviewed-by: Thomas Huth <huth@tuxfamily.org>
Message-ID: <20231024083010.12453-5-philmd@linaro.org>
Signed-off-by: Thomas Huth <huth@tuxfamily.org>
---
hw/m68k/mcf_intc.c | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/hw/m68k/mcf_intc.c b/hw/m68k/mcf_intc.c
index 1f74ea0e14..1d3b34e18c 100644
--- a/hw/m68k/mcf_intc.c
+++ b/hw/m68k/mcf_intc.c
@@ -14,6 +14,7 @@
#include "hw/irq.h"
#include "hw/sysbus.h"
#include "hw/m68k/mcf.h"
+#include "hw/qdev-properties.h"
#include "qom/object.h"
#define TYPE_MCF_INTC "mcf-intc"
@@ -176,10 +177,17 @@ static void mcf_intc_instance_init(Object *obj)
sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->iomem);
}
+static Property mcf_intc_properties[] = {
+ DEFINE_PROP_LINK("m68k-cpu", mcf_intc_state, cpu,
+ TYPE_M68K_CPU, M68kCPU *),
+ DEFINE_PROP_END_OF_LIST(),
+};
+
static void mcf_intc_class_init(ObjectClass *oc, void *data)
{
DeviceClass *dc = DEVICE_CLASS(oc);
+ device_class_set_props(dc, mcf_intc_properties);
set_bit(DEVICE_CATEGORY_MISC, dc->categories);
dc->reset = mcf_intc_reset;
}
@@ -204,16 +212,13 @@ qemu_irq *mcf_intc_init(MemoryRegion *sysmem,
M68kCPU *cpu)
{
DeviceState *dev;
- mcf_intc_state *s;
dev = qdev_new(TYPE_MCF_INTC);
+ object_property_set_link(OBJECT(dev), "m68k-cpu",
+ OBJECT(cpu), &error_abort);
sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
-
- s = MCF_INTC(dev);
- s->cpu = cpu;
-
memory_region_add_subregion(sysmem, base,
sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 0));
- return qemu_allocate_irqs(mcf_intc_set_irq, s, 64);
+ return qemu_allocate_irqs(mcf_intc_set_irq, dev, 64);
}
--
2.41.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PULL 05/10] hw/m68k/next-cube: Do not open-code sysbus_create_simple()
2023-11-02 10:05 [PULL 00/10] m68k patches Thomas Huth
` (3 preceding siblings ...)
2023-11-02 10:05 ` [PULL 04/10] hw/m68k/mcf_intc: Pass CPU using QOM link property Thomas Huth
@ 2023-11-02 10:05 ` Thomas Huth
2023-11-02 10:05 ` [PULL 06/10] hw/m68k/virt: " Thomas Huth
` (5 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Thomas Huth @ 2023-11-02 10:05 UTC (permalink / raw)
To: qemu-devel, Stefan Hajnoczi; +Cc: Philippe Mathieu-Daudé
From: Philippe Mathieu-Daudé <philmd@linaro.org>
Mechanical change using the following coccinelle script:
@@
identifier dev;
identifier sbd;
expression qom_type;
expression addr;
@@
- dev = qdev_new(qom_type);
- sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
- sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr);
+ dev = sysbus_create_simple(qom_type, addr, NULL);
then manually removing the 'dev' variable to avoid:
error: variable 'dev' set but not used [-Werror,-Wunused-but-set-variable]
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Thomas Huth <huth@tuxfamily.org>
Message-ID: <20231024083010.12453-6-philmd@linaro.org>
Signed-off-by: Thomas Huth <huth@tuxfamily.org>
---
hw/m68k/next-cube.c | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/hw/m68k/next-cube.c b/hw/m68k/next-cube.c
index 5d244b3b95..d17e6be8e1 100644
--- a/hw/m68k/next-cube.c
+++ b/hw/m68k/next-cube.c
@@ -950,7 +950,6 @@ static void next_cube_init(MachineState *machine)
MemoryRegion *bmapm2 = g_new(MemoryRegion, 1);
MemoryRegion *sysmem = get_system_memory();
const char *bios_name = machine->firmware ?: ROM_FILE;
- DeviceState *dev;
DeviceState *pcdev;
/* Initialize the cpu core */
@@ -974,9 +973,7 @@ static void next_cube_init(MachineState *machine)
memory_region_add_subregion(sysmem, 0x04000000, machine->ram);
/* Framebuffer */
- dev = qdev_new(TYPE_NEXTFB);
- sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
- sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, 0x0B000000);
+ sysbus_create_simple(TYPE_NEXTFB, 0x0B000000, NULL);
/* MMIO */
sysbus_mmio_map(SYS_BUS_DEVICE(pcdev), 0, 0x02000000);
@@ -993,9 +990,7 @@ static void next_cube_init(MachineState *machine)
memory_region_add_subregion(sysmem, 0x820c0000, bmapm2);
/* KBD */
- dev = qdev_new(TYPE_NEXTKBD);
- sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
- sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, 0x0200e000);
+ sysbus_create_simple(TYPE_NEXTKBD, 0x0200e000, NULL);
/* Load ROM here */
/* still not sure if the rom should also be mapped at 0x0*/
--
2.41.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PULL 06/10] hw/m68k/virt: Do not open-code sysbus_create_simple()
2023-11-02 10:05 [PULL 00/10] m68k patches Thomas Huth
` (4 preceding siblings ...)
2023-11-02 10:05 ` [PULL 05/10] hw/m68k/next-cube: Do not open-code sysbus_create_simple() Thomas Huth
@ 2023-11-02 10:05 ` Thomas Huth
2023-11-02 10:05 ` [PULL 07/10] hw/char/mcf_uart: Have mcf_uart_create() return DeviceState Thomas Huth
` (4 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Thomas Huth @ 2023-11-02 10:05 UTC (permalink / raw)
To: qemu-devel, Stefan Hajnoczi; +Cc: Philippe Mathieu-Daudé
From: Philippe Mathieu-Daudé <philmd@linaro.org>
Mechanical change using the following coccinelle script:
@@
identifier dev;
expression qom_type;
expression addr;
expression irq;
@@
- dev = qdev_new(qom_type);
- sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
- sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr);
- sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, irq);
+ dev = sysbus_create_simple(qom_type, addr, irq);
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Thomas Huth <huth@tuxfamily.org>
Message-ID: <20231024083010.12453-7-philmd@linaro.org>
Signed-off-by: Thomas Huth <huth@tuxfamily.org>
---
hw/m68k/virt.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/hw/m68k/virt.c b/hw/m68k/virt.c
index e7dc188855..2e49e262ee 100644
--- a/hw/m68k/virt.c
+++ b/hw/m68k/virt.c
@@ -201,11 +201,8 @@ static void virt_init(MachineState *machine)
sysbus_connect_irq(sysbus, 0, PIC_GPIO(VIRT_GF_TTY_IRQ_BASE));
/* virt controller */
- dev = qdev_new(TYPE_VIRT_CTRL);
- sysbus = SYS_BUS_DEVICE(dev);
- sysbus_realize_and_unref(sysbus, &error_fatal);
- sysbus_mmio_map(sysbus, 0, VIRT_CTRL_MMIO_BASE);
- sysbus_connect_irq(sysbus, 0, PIC_GPIO(VIRT_CTRL_IRQ_BASE));
+ dev = sysbus_create_simple(TYPE_VIRT_CTRL, VIRT_CTRL_MMIO_BASE,
+ PIC_GPIO(VIRT_CTRL_IRQ_BASE));
/* virtio-mmio */
io_base = VIRT_VIRTIO_MMIO_BASE;
--
2.41.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PULL 07/10] hw/char/mcf_uart: Have mcf_uart_create() return DeviceState
2023-11-02 10:05 [PULL 00/10] m68k patches Thomas Huth
` (5 preceding siblings ...)
2023-11-02 10:05 ` [PULL 06/10] hw/m68k/virt: " Thomas Huth
@ 2023-11-02 10:05 ` Thomas Huth
2023-11-02 10:05 ` [PULL 08/10] hw/m68k/next-cube: Mirror BIOS to address 0 Thomas Huth
` (3 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Thomas Huth @ 2023-11-02 10:05 UTC (permalink / raw)
To: qemu-devel, Stefan Hajnoczi; +Cc: Philippe Mathieu-Daudé
From: Philippe Mathieu-Daudé <philmd@linaro.org>
There is no point in having mcf_uart_init() demote the DeviceState
pointer and return a void one. Directly return the real typedef.
mcf_uart_init() do both init + realize: rename as mcf_uart_create().
Similarly, mcf_uart_mm_init() do init / realize / mmap: rename as
mcf_uart_create_mmap().
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-ID: <20231019104929.16517-1-philmd@linaro.org>
Signed-off-by: Thomas Huth <huth@tuxfamily.org>
---
hw/char/mcf_uart.c | 13 +++++++------
hw/m68k/mcf5206.c | 6 +++---
hw/m68k/mcf5208.c | 6 +++---
include/hw/m68k/mcf.h | 4 ++--
4 files changed, 15 insertions(+), 14 deletions(-)
diff --git a/hw/char/mcf_uart.c b/hw/char/mcf_uart.c
index 6fa4ac502c..f9cbc9bdc4 100644
--- a/hw/char/mcf_uart.c
+++ b/hw/char/mcf_uart.c
@@ -342,25 +342,26 @@ static void mcf_uart_register(void)
type_init(mcf_uart_register)
-void *mcf_uart_init(qemu_irq irq, Chardev *chrdrv)
+DeviceState *mcf_uart_create(qemu_irq irq, Chardev *chrdrv)
{
- DeviceState *dev;
+ DeviceState *dev;
dev = qdev_new(TYPE_MCF_UART);
if (chrdrv) {
qdev_prop_set_chr(dev, "chardev", chrdrv);
}
sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
-
sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, irq);
return dev;
}
-void mcf_uart_mm_init(hwaddr base, qemu_irq irq, Chardev *chrdrv)
+DeviceState *mcf_uart_create_mmap(hwaddr base, qemu_irq irq, Chardev *chrdrv)
{
- DeviceState *dev;
+ DeviceState *dev;
- dev = mcf_uart_init(irq, chrdrv);
+ dev = mcf_uart_create(irq, chrdrv);
sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base);
+
+ return dev;
}
diff --git a/hw/m68k/mcf5206.c b/hw/m68k/mcf5206.c
index f920ca2ceb..a46a23538d 100644
--- a/hw/m68k/mcf5206.c
+++ b/hw/m68k/mcf5206.c
@@ -168,7 +168,7 @@ typedef struct {
MemoryRegion iomem;
qemu_irq *pic;
m5206_timer_state *timer[2];
- void *uart[2];
+ DeviceState *uart[2];
uint8_t scr;
uint8_t icr[14];
uint16_t imr; /* 1 == interrupt is masked. */
@@ -600,8 +600,8 @@ static void mcf5206_mbar_realize(DeviceState *dev, Error **errp)
s->pic = qemu_allocate_irqs(m5206_mbar_set_irq, s, 14);
s->timer[0] = m5206_timer_init(s->pic[9]);
s->timer[1] = m5206_timer_init(s->pic[10]);
- s->uart[0] = mcf_uart_init(s->pic[12], serial_hd(0));
- s->uart[1] = mcf_uart_init(s->pic[13], serial_hd(1));
+ s->uart[0] = mcf_uart_create(s->pic[12], serial_hd(0));
+ s->uart[1] = mcf_uart_create(s->pic[13], serial_hd(1));
}
static Property mcf5206_mbar_properties[] = {
diff --git a/hw/m68k/mcf5208.c b/hw/m68k/mcf5208.c
index be1033f84f..d22d8536db 100644
--- a/hw/m68k/mcf5208.c
+++ b/hw/m68k/mcf5208.c
@@ -261,9 +261,9 @@ static void mcf5208evb_init(MachineState *machine)
/* Internal peripherals. */
pic = mcf_intc_init(address_space_mem, 0xfc048000, cpu);
- mcf_uart_mm_init(0xfc060000, pic[26], serial_hd(0));
- mcf_uart_mm_init(0xfc064000, pic[27], serial_hd(1));
- mcf_uart_mm_init(0xfc068000, pic[28], serial_hd(2));
+ mcf_uart_create_mmap(0xfc060000, pic[26], serial_hd(0));
+ mcf_uart_create_mmap(0xfc064000, pic[27], serial_hd(1));
+ mcf_uart_create_mmap(0xfc068000, pic[28], serial_hd(2));
mcf5208_sys_init(address_space_mem, pic);
diff --git a/include/hw/m68k/mcf.h b/include/hw/m68k/mcf.h
index 8cbd587bbf..5d9f876ffe 100644
--- a/include/hw/m68k/mcf.h
+++ b/include/hw/m68k/mcf.h
@@ -10,8 +10,8 @@ uint64_t mcf_uart_read(void *opaque, hwaddr addr,
unsigned size);
void mcf_uart_write(void *opaque, hwaddr addr,
uint64_t val, unsigned size);
-void *mcf_uart_init(qemu_irq irq, Chardev *chr);
-void mcf_uart_mm_init(hwaddr base, qemu_irq irq, Chardev *chr);
+DeviceState *mcf_uart_create(qemu_irq irq, Chardev *chr);
+DeviceState *mcf_uart_create_mmap(hwaddr base, qemu_irq irq, Chardev *chr);
/* mcf_intc.c */
qemu_irq *mcf_intc_init(struct MemoryRegion *sysmem,
--
2.41.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PULL 08/10] hw/m68k/next-cube: Mirror BIOS to address 0
2023-11-02 10:05 [PULL 00/10] m68k patches Thomas Huth
` (6 preceding siblings ...)
2023-11-02 10:05 ` [PULL 07/10] hw/char/mcf_uart: Have mcf_uart_create() return DeviceState Thomas Huth
@ 2023-11-02 10:05 ` Thomas Huth
2023-11-02 10:05 ` [PULL 09/10] m68k: Instantiate the ESP SCSI controller for the NeXTcube machine Thomas Huth
` (2 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Thomas Huth @ 2023-11-02 10:05 UTC (permalink / raw)
To: qemu-devel, Stefan Hajnoczi; +Cc: Philippe Mathieu-Daudé
The ROM is also available at address 0, so add a proper mirror
for this address.
Acked-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Message-ID: <20230930132351.30282-2-huth@tuxfamily.org>
Signed-off-by: Thomas Huth <huth@tuxfamily.org>
---
hw/m68k/next-cube.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/hw/m68k/next-cube.c b/hw/m68k/next-cube.c
index d17e6be8e1..2c94c6a9c2 100644
--- a/hw/m68k/next-cube.c
+++ b/hw/m68k/next-cube.c
@@ -945,6 +945,7 @@ static void next_cube_init(MachineState *machine)
M68kCPU *cpu;
CPUM68KState *env;
MemoryRegion *rom = g_new(MemoryRegion, 1);
+ MemoryRegion *rom2 = g_new(MemoryRegion, 1);
MemoryRegion *dmamem = g_new(MemoryRegion, 1);
MemoryRegion *bmapm1 = g_new(MemoryRegion, 1);
MemoryRegion *bmapm2 = g_new(MemoryRegion, 1);
@@ -993,9 +994,10 @@ static void next_cube_init(MachineState *machine)
sysbus_create_simple(TYPE_NEXTKBD, 0x0200e000, NULL);
/* Load ROM here */
- /* still not sure if the rom should also be mapped at 0x0*/
memory_region_init_rom(rom, NULL, "next.rom", 0x20000, &error_fatal);
memory_region_add_subregion(sysmem, 0x01000000, rom);
+ memory_region_init_alias(rom2, NULL, "next.rom2", rom, 0x0, 0x20000);
+ memory_region_add_subregion(sysmem, 0x0, rom2);
if (load_image_targphys(bios_name, 0x01000000, 0x20000) < 8) {
if (!qtest_enabled()) {
error_report("Failed to load firmware '%s'.", bios_name);
--
2.41.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PULL 09/10] m68k: Instantiate the ESP SCSI controller for the NeXTcube machine
2023-11-02 10:05 [PULL 00/10] m68k patches Thomas Huth
` (7 preceding siblings ...)
2023-11-02 10:05 ` [PULL 08/10] hw/m68k/next-cube: Mirror BIOS to address 0 Thomas Huth
@ 2023-11-02 10:05 ` Thomas Huth
2023-11-02 10:05 ` [PULL 10/10] tests/avocado/machine_m68k_nextcube: Fix the download URL for the ROM image Thomas Huth
2023-11-03 1:31 ` [PULL 00/10] m68k patches Stefan Hajnoczi
10 siblings, 0 replies; 12+ messages in thread
From: Thomas Huth @ 2023-11-02 10:05 UTC (permalink / raw)
To: qemu-devel, Stefan Hajnoczi; +Cc: Philippe Mathieu-Daudé
The NeXTcube uses a NCR 53C90 SCSI interface for its disks, so we should
be able to use the ESP controller from QEMU here. The code here has been
basically taken from Bryce Lanham's GSoC 2011 contribution, except for
the next_scsi_init() function which has been rewritte as a replacement
for the esp_init() function (that has been removed quite a while ago).
Note that SCSI is not working yet. The ESP code likely needs some more
fixes first and there still might be some bugs left in they way we wire
it up for the NeXT-Cube machine.
Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Message-ID: <20230930132351.30282-4-huth@tuxfamily.org>
Signed-off-by: Thomas Huth <huth@tuxfamily.org>
---
hw/m68k/next-cube.c | 117 +++++++++++++++++++++++++++++++++++++++++---
1 file changed, 110 insertions(+), 7 deletions(-)
diff --git a/hw/m68k/next-cube.c b/hw/m68k/next-cube.c
index 2c94c6a9c2..fabd861941 100644
--- a/hw/m68k/next-cube.c
+++ b/hw/m68k/next-cube.c
@@ -90,10 +90,13 @@ struct NeXTPC {
uint32_t scr1;
uint32_t scr2;
- uint8_t scsi_csr_1;
- uint8_t scsi_csr_2;
uint32_t int_mask;
uint32_t int_status;
+ uint8_t scsi_csr_1;
+ uint8_t scsi_csr_2;
+
+ qemu_irq scsi_reset;
+ qemu_irq scsi_dma;
NextRtc rtc;
};
@@ -466,7 +469,7 @@ static void scr_writeb(NeXTPC *s, hwaddr addr, uint32_t value)
DPRINTF("SCSICSR FIFO Flush\n");
/* will have to add another irq to the esp if this is needed */
/* esp_puflush_fifo(esp_g); */
- /* qemu_irq_pulse(s->scsi_dma); */
+ qemu_irq_pulse(s->scsi_dma);
}
if (value & SCSICSR_ENABLE) {
@@ -486,9 +489,9 @@ static void scr_writeb(NeXTPC *s, hwaddr addr, uint32_t value)
if (value & SCSICSR_RESET) {
DPRINTF("SCSICSR Reset\n");
/* I think this should set DMADIR. CPUDMA and INTMASK to 0 */
- /* qemu_irq_raise(s->scsi_reset); */
- /* s->scsi_csr_1 &= ~(SCSICSR_INTMASK |0x80|0x1); */
-
+ qemu_irq_raise(s->scsi_reset);
+ s->scsi_csr_1 &= ~(SCSICSR_INTMASK | 0x80 | 0x1);
+ qemu_irq_lower(s->scsi_reset);
}
if (value & SCSICSR_DMADIR) {
DPRINTF("SCSICSR DMAdir\n");
@@ -496,10 +499,11 @@ static void scr_writeb(NeXTPC *s, hwaddr addr, uint32_t value)
if (value & SCSICSR_CPUDMA) {
DPRINTF("SCSICSR CPUDMA\n");
/* qemu_irq_raise(s->scsi_dma); */
-
s->int_status |= 0x4000000;
} else {
+ /* fprintf(stderr,"SCSICSR CPUDMA disabled\n"); */
s->int_status &= ~(0x4000000);
+ /* qemu_irq_lower(s->scsi_dma); */
}
if (value & SCSICSR_INTMASK) {
DPRINTF("SCSICSR INTMASK\n");
@@ -828,6 +832,103 @@ static void next_irq(void *opaque, int number, int level)
}
}
+static void nextdma_write(void *opaque, uint8_t *buf, int size, int type)
+{
+ uint32_t base_addr;
+ int irq = 0;
+ uint8_t align = 16;
+ NeXTState *next_state = NEXT_MACHINE(qdev_get_machine());
+
+ if (type == NEXTDMA_ENRX || type == NEXTDMA_ENTX) {
+ align = 32;
+ }
+ /* Most DMA is supposedly 16 byte aligned */
+ if ((size % align) != 0) {
+ size -= size % align;
+ size += align;
+ }
+
+ /*
+ * prom sets the dma start using initbuf while the bootloader uses next
+ * so we check to see if initbuf is 0
+ */
+ if (next_state->dma[type].next_initbuf == 0) {
+ base_addr = next_state->dma[type].next;
+ } else {
+ base_addr = next_state->dma[type].next_initbuf;
+ }
+
+ cpu_physical_memory_write(base_addr, buf, size);
+
+ next_state->dma[type].next_initbuf = 0;
+
+ /* saved limit is checked to calculate packet size by both, rom and netbsd */
+ next_state->dma[type].saved_limit = (next_state->dma[type].next + size);
+ next_state->dma[type].saved_next = (next_state->dma[type].next);
+
+ /*
+ * 32 bytes under savedbase seems to be some kind of register
+ * of which the purpose is unknown as of yet
+ */
+ /* stl_phys(s->rx_dma.base-32,0xFFFFFFFF); */
+
+ if (!(next_state->dma[type].csr & DMA_SUPDATE)) {
+ next_state->dma[type].next = next_state->dma[type].start;
+ next_state->dma[type].limit = next_state->dma[type].stop;
+ }
+
+ /* Set dma registers and raise an irq */
+ next_state->dma[type].csr |= DMA_COMPLETE; /* DON'T CHANGE THIS! */
+
+ switch (type) {
+ case NEXTDMA_SCSI:
+ irq = NEXT_SCSI_DMA_I;
+ break;
+ }
+
+ next_irq(opaque, irq, 1);
+ next_irq(opaque, irq, 0);
+}
+
+static void nextscsi_read(void *opaque, uint8_t *buf, int len)
+{
+ DPRINTF("SCSI READ: %x\n", len);
+ abort();
+}
+
+static void nextscsi_write(void *opaque, uint8_t *buf, int size)
+{
+ DPRINTF("SCSI WRITE: %i\n", size);
+ nextdma_write(opaque, buf, size, NEXTDMA_SCSI);
+}
+
+static void next_scsi_init(DeviceState *pcdev, M68kCPU *cpu)
+{
+ struct NeXTPC *next_pc = NEXT_PC(pcdev);
+ DeviceState *dev;
+ SysBusDevice *sysbusdev;
+ SysBusESPState *sysbus_esp;
+ ESPState *esp;
+
+ dev = qdev_new(TYPE_SYSBUS_ESP);
+ sysbus_esp = SYSBUS_ESP(dev);
+ esp = &sysbus_esp->esp;
+ esp->dma_memory_read = nextscsi_read;
+ esp->dma_memory_write = nextscsi_write;
+ esp->dma_opaque = pcdev;
+ sysbus_esp->it_shift = 0;
+ esp->dma_enabled = 1;
+ sysbusdev = SYS_BUS_DEVICE(dev);
+ sysbus_realize_and_unref(sysbusdev, &error_fatal);
+ sysbus_connect_irq(sysbusdev, 0, qdev_get_gpio_in(pcdev, NEXT_SCSI_I));
+ sysbus_mmio_map(sysbusdev, 0, 0x2114000);
+
+ next_pc->scsi_reset = qdev_get_gpio_in(dev, 0);
+ next_pc->scsi_dma = qdev_get_gpio_in(dev, 1);
+
+ scsi_bus_legacy_handle_cmdline(&esp->bus);
+}
+
static void next_escc_init(DeviceState *pcdev)
{
DeviceState *dev;
@@ -1021,6 +1122,7 @@ static void next_cube_init(MachineState *machine)
/* TODO: */
/* Network */
/* SCSI */
+ next_scsi_init(pcdev, cpu);
/* DMA */
memory_region_init_io(dmamem, NULL, &dma_ops, machine, "next.dma", 0x5000);
@@ -1033,6 +1135,7 @@ static void next_machine_class_init(ObjectClass *oc, void *data)
mc->desc = "NeXT Cube";
mc->init = next_cube_init;
+ mc->block_default_type = IF_SCSI;
mc->default_ram_size = RAM_SIZE;
mc->default_ram_id = "next.ram";
mc->default_cpu_type = M68K_CPU_TYPE_NAME("m68040");
--
2.41.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PULL 10/10] tests/avocado/machine_m68k_nextcube: Fix the download URL for the ROM image
2023-11-02 10:05 [PULL 00/10] m68k patches Thomas Huth
` (8 preceding siblings ...)
2023-11-02 10:05 ` [PULL 09/10] m68k: Instantiate the ESP SCSI controller for the NeXTcube machine Thomas Huth
@ 2023-11-02 10:05 ` Thomas Huth
2023-11-03 1:31 ` [PULL 00/10] m68k patches Stefan Hajnoczi
10 siblings, 0 replies; 12+ messages in thread
From: Thomas Huth @ 2023-11-02 10:05 UTC (permalink / raw)
To: qemu-devel, Stefan Hajnoczi; +Cc: Philippe Mathieu-Daudé
If Avocado has to fetch this asset, the download fails with a 403 HTTP
error. Use a different URL to fix the issue.
Message-ID: <20231101201934.27637-1-huth@tuxfamily.org>
Signed-off-by: Thomas Huth <huth@tuxfamily.org>
---
tests/avocado/machine_m68k_nextcube.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tests/avocado/machine_m68k_nextcube.py b/tests/avocado/machine_m68k_nextcube.py
index d6da2fbb01..f1205d7fc0 100644
--- a/tests/avocado/machine_m68k_nextcube.py
+++ b/tests/avocado/machine_m68k_nextcube.py
@@ -30,8 +30,8 @@ class NextCubeMachine(QemuSystemTest):
timeout = 15
def check_bootrom_framebuffer(self, screenshot_path):
- rom_url = ('http://www.nextcomputers.org/NeXTfiles/Software/ROM_Files/'
- '68040_Non-Turbo_Chipset/Rev_2.5_v66.BIN')
+ rom_url = ('https://sourceforge.net/p/previous/code/1350/tree/'
+ 'trunk/src/Rev_2.5_v66.BIN?format=raw')
rom_hash = 'b3534796abae238a0111299fc406a9349f7fee24'
rom_path = self.fetch_asset(rom_url, asset_hash=rom_hash)
--
2.41.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PULL 00/10] m68k patches
2023-11-02 10:05 [PULL 00/10] m68k patches Thomas Huth
` (9 preceding siblings ...)
2023-11-02 10:05 ` [PULL 10/10] tests/avocado/machine_m68k_nextcube: Fix the download URL for the ROM image Thomas Huth
@ 2023-11-03 1:31 ` Stefan Hajnoczi
10 siblings, 0 replies; 12+ messages in thread
From: Stefan Hajnoczi @ 2023-11-03 1:31 UTC (permalink / raw)
To: Thomas Huth; +Cc: qemu-devel, Stefan Hajnoczi, Philippe Mathieu-Daudé
[-- Attachment #1: Type: text/plain, Size: 115 bytes --]
Applied, thanks.
Please update the changelog at https://wiki.qemu.org/ChangeLog/8.2 for any user-visible changes.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread