Skip to contentSkip to conversation

Pegasos2 emulation

PATCH Superseded BALATON Zoltan 5 participants 32 messages Mar 10, 2021 – Mar 23, 2021 Arm/Amlogic Meson SoC support

v7 of 11 Superseded Latest is v11 →

lore
Share & tools
lore
#0 lore raw

v7 cover Pegasos2 emulation

Hello,

This is adding a new PPC board called pegasos2. More info on it can be found at:

https://osdn.net/projects/qmiga/wiki/SubprojectPegasos2

Currently it needs a firmware ROM image that I cannot include due to original copyright holder (bPlan) did not release it under a free licence but I have plans to write a replacement in the future. With the original board firmware it can boot MorphOS now as:

qemu-system-ppc -M pegasos2 -cdrom morphos.iso -device ati-vga,romfile="" -serial stdio

then enter "boot cd boot.img" at the firmware "ok" prompt as described in the MorphOS.readme. To boot Linux use same command line with e.g. -cdrom debian-8.11.0-powerpc-netinst.iso then enter
"boot cd install/pegasos"

The last patch adds the actual board code after previous patches adding VT8231 and MV64361 system controller chip emulation.

Regards,
BALATON Zoltan

v7: Fix errp usage in patch 2

v6: Rebased on master, updated commit message about migration change

v5: Changes for review comments from David and Philippe

V4: Rename pegasos2_reset to pegasos2_cpu_reset
Add new files to MAINTAINERS

BALATON Zoltan (7):
vt82c686: Implement control of serial port io ranges via config regs
vt82c686: QOM-ify superio related functionality
vt82c686: Add VT8231_SUPERIO based on VIA_SUPERIO
vt82c686: Introduce abstract TYPE_VIA_ISA and base vt82c686b_isa on it
vt82c686: Add emulation of VT8231 south bridge hw/pci-host: Add emulation of Marvell MV64361 PPC system controller hw/ppc: Add emulation of Genesi/bPlan Pegasos II

Philippe Mathieu-Daudé (1):
hw/isa/Kconfig: Add missing dependency VIA VT82C686 -> APM

 MAINTAINERS                             |  10 +
 default-configs/devices/ppc-softmmu.mak |   2 +
 hw/isa/Kconfig                          |   1 +
 hw/isa/vt82c686.c                       | 517 +++++++++++--
 hw/pci-host/Kconfig                     |   4 +
 hw/pci-host/meson.build                 |   2 +
 hw/pci-host/mv64361.c                   | 966 ++++++++++++++++++++++++
 hw/pci-host/mv643xx.h                   | 918 ++++++++++++++++++++++
 hw/pci-host/trace-events                |   6 +
 hw/ppc/Kconfig                          |   9 +
 hw/ppc/meson.build                      |   2 +
 hw/ppc/pegasos2.c                       | 144 ++++
 include/hw/isa/vt82c686.h               |   2 +-
 include/hw/pci-host/mv64361.h           |   8 +
 include/hw/pci/pci_ids.h                |   4 +-
 15 files changed, 2512 insertions(+), 83 deletions(-)
 create mode 100644 hw/pci-host/mv64361.c
 create mode 100644 hw/pci-host/mv643xx.h
 create mode 100644 hw/ppc/pegasos2.c
 create mode 100644 include/hw/pci-host/mv64361.h
Signature · 1 line
2.21.3
#1 lore raw

PATCH v7 1/8 vt82c686: Implement control of serial port io ranges via config regs

In VIA super south bridge the io ranges of superio components (parallel and serial ports and FDC) can be controlled by superio config registers to set their base address and enable/disable them. This is not easy to implement in QEMU because ISA emulation is only designed to set io base address once on creating the device and io ranges are registered at creation and cannot easily be disabled or moved later.

In this patch we hack around that but only for serial ports because those have a single io range at port base that's relatively easy to handle and it's what guests actually use and set address different than the default.

We do not attempt to handle controlling the parallel and FDC regions because those have multiple io ranges so handling them would be messy and guests either don't change their deafult or don't care. We could even get away with disabling and not emulating them, but since they are already there, this patch leaves them mapped at their default address just in case this could be useful for a guest in the future.

---
 hw/isa/vt82c686.c | 84 +++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 82 insertions(+), 2 deletions(-)
hw/isa/vt82c686.c +82 -2
index 05d084f698..a3353ec5db 100644
@@ -252,8 +252,24 @@ static const TypeInfo vt8231_pm_info = {
 typedef struct SuperIOConfig {
     uint8_t regs[0x100];
     MemoryRegion io;
+    ISASuperIODevice *superio;
+    MemoryRegion *serial_io[SUPERIO_MAX_SERIAL_PORTS];
 } SuperIOConfig;
 
+static MemoryRegion *find_subregion(ISADevice *d, MemoryRegion *parent,
+                                    int offs)
+{
+    MemoryRegion *subregion, *mr = NULL;
+
+    QTAILQ_FOREACH(subregion, &parent->subregions, subregions_link) {
+        if (subregion->addr == offs) {
+            mr = subregion;
+            break;
+        }
+    }
+    return mr;
+}
+
 static void superio_cfg_write(void *opaque, hwaddr addr, uint64_t data,
                               unsigned size)
 {
@@ -279,7 +295,53 @@ static void superio_cfg_write(void *opaque, hwaddr addr, uint64_t data,
     case 0xfd ... 0xff:
         /* ignore write to read only registers */
         return;
-    /* case 0xe6 ... 0xe8: Should set base port of parallel and serial */
+    case 0xe2:
+    {
+        data &= 0x1f;
+        if (data & BIT(2)) { /* Serial port 1 enable */
+            ISADevice *dev = sc->superio->serial[0];
+            if (!memory_region_is_mapped(sc->serial_io[0])) {
+                memory_region_add_subregion(isa_address_space_io(dev),
+                                            dev->ioport_id, sc->serial_io[0]);
+            }
+        } else {
+            MemoryRegion *io = isa_address_space_io(sc->superio->serial[0]);
+            if (memory_region_is_mapped(sc->serial_io[0])) {
+                memory_region_del_subregion(io, sc->serial_io[0]);
+            }
+        }
+        if (data & BIT(3)) { /* Serial port 2 enable */
+            ISADevice *dev = sc->superio->serial[1];
+            if (!memory_region_is_mapped(sc->serial_io[1])) {
+                memory_region_add_subregion(isa_address_space_io(dev),
+                                            dev->ioport_id, sc->serial_io[1]);
+            }
+        } else {
+            MemoryRegion *io = isa_address_space_io(sc->superio->serial[1]);
+            if (memory_region_is_mapped(sc->serial_io[1])) {
+                memory_region_del_subregion(io, sc->serial_io[1]);
+            }
+        }
+        break;
+    }
+    case 0xe7: /* Serial port 1 io base address */
+    {
+        data &= 0xfe;
+        sc->superio->serial[0]->ioport_id = data << 2;
+        if (memory_region_is_mapped(sc->serial_io[0])) {
+            memory_region_set_address(sc->serial_io[0], data << 2);
+        }
+        break;
+    }
+    case 0xe8: /* Serial port 2 io base address */
+    {
+        data &= 0xfe;
+        sc->superio->serial[1]->ioport_id = data << 2;
+        if (memory_region_is_mapped(sc->serial_io[1])) {
+            memory_region_set_address(sc->serial_io[1], data << 2);
+        }
+        break;
+    }
     default:
         qemu_log_mask(LOG_UNIMP,
                       "via_superio_cfg: unimplemented register 0x%x\n", idx);
@@ -385,6 +447,7 @@ static void vt82c686b_realize(PCIDevice *d, Error **errp)
     DeviceState *dev = DEVICE(d);
     ISABus *isa_bus;
     qemu_irq *isa_irq;
+    ISASuperIOClass *ic;
     int i;
 
     qdev_init_gpio_out(dev, &s->cpu_intr, 1);
@@ -394,7 +457,9 @@ static void vt82c686b_realize(PCIDevice *d, Error **errp)
     isa_bus_irqs(isa_bus, i8259_init(isa_bus, *isa_irq));
     i8254_pit_init(isa_bus, 0x40, 0, NULL);
     i8257_dma_init(isa_bus, 0);
-    isa_create_simple(isa_bus, TYPE_VT82C686B_SUPERIO);
+    s->superio_cfg.superio = ISA_SUPERIO(isa_create_simple(isa_bus,
+                                                      TYPE_VT82C686B_SUPERIO));
+    ic = ISA_SUPERIO_GET_CLASS(s->superio_cfg.superio);
     mc146818_rtc_init(isa_bus, 2000, NULL);
 
     for (i = 0; i < PCI_CONFIG_HEADER_SIZE; i++) {
@@ -412,6 +477,21 @@ static void vt82c686b_realize(PCIDevice *d, Error **errp)
      */
     memory_region_add_subregion(isa_bus->address_space_io, 0x3f0,
                                 &s->superio_cfg.io);
+
+    /* Grab io regions of serial devices so we can control them */
+    for (i = 0; i < ic->serial.count; i++) {
+        ISADevice *sd = s->superio_cfg.superio->serial[i];
+        MemoryRegion *io = isa_address_space_io(sd);
+        MemoryRegion *mr = find_subregion(sd, io, sd->ioport_id);
+        if (!mr) {
+            error_setg(errp, "Could not get io region for serial %d", i);
+            return;
+        }
+        s->superio_cfg.serial_io[i] = mr;
+        if (memory_region_is_mapped(mr)) {
+            memory_region_del_subregion(io, mr);
+        }
+    }
 }
 
 static void via_class_init(ObjectClass *klass, void *data)
Signature · 1 line
2.21.3
#2 lore raw

Re: [PATCH v7 1/8] vt82c686: Implement control of serial port io ranges via config regs

ping for review?

Quoted 151 lines · BALATON Zoltan

In VIA super south bridge the io ranges of superio components (parallel and serial ports and FDC) can be controlled by superio config registers to set their base address and enable/disable them. This is not easy to implement in QEMU because ISA emulation is only designed to set io base address once on creating the device and io ranges are registered at creation and cannot easily be disabled or moved later.

In this patch we hack around that but only for serial ports because those have a single io range at port base that's relatively easy to handle and it's what guests actually use and set address different than the default.

We do not attempt to handle controlling the parallel and FDC regions because those have multiple io ranges so handling them would be messy and guests either don't change their deafult or don't care. We could even get away with disabling and not emulating them, but since they are already there, this patch leaves them mapped at their default address just in case this could be useful for a guest in the future.

---
 hw/isa/vt82c686.c | 84 +++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 82 insertions(+), 2 deletions(-)
hw/isa/vt82c686.c +82 -2
index 05d084f698..a3353ec5db 100644
@@ -252,8 +252,24 @@ static const TypeInfo vt8231_pm_info = {
 typedef struct SuperIOConfig {
     uint8_t regs[0x100];
     MemoryRegion io;
+    ISASuperIODevice *superio;
+    MemoryRegion *serial_io[SUPERIO_MAX_SERIAL_PORTS];
 } SuperIOConfig;
 
+static MemoryRegion *find_subregion(ISADevice *d, MemoryRegion *parent,
+                                    int offs)
+{
+    MemoryRegion *subregion, *mr = NULL;
+
+    QTAILQ_FOREACH(subregion, &parent->subregions, subregions_link) {
+        if (subregion->addr == offs) {
+            mr = subregion;
+            break;
+        }
+    }
+    return mr;
+}
+
 static void superio_cfg_write(void *opaque, hwaddr addr, uint64_t data,
                               unsigned size)
 {
@@ -279,7 +295,53 @@ static void superio_cfg_write(void *opaque, hwaddr addr, uint64_t data,
     case 0xfd ... 0xff:
         /* ignore write to read only registers */
         return;
-    /* case 0xe6 ... 0xe8: Should set base port of parallel and serial */
+    case 0xe2:
+    {
+        data &= 0x1f;
+        if (data & BIT(2)) { /* Serial port 1 enable */
+            ISADevice *dev = sc->superio->serial[0];
+            if (!memory_region_is_mapped(sc->serial_io[0])) {
+                memory_region_add_subregion(isa_address_space_io(dev),
+                                            dev->ioport_id, sc->serial_io[0]);
+            }
+        } else {
+            MemoryRegion *io = isa_address_space_io(sc->superio->serial[0]);
+            if (memory_region_is_mapped(sc->serial_io[0])) {
+                memory_region_del_subregion(io, sc->serial_io[0]);
+            }
+        }
+        if (data & BIT(3)) { /* Serial port 2 enable */
+            ISADevice *dev = sc->superio->serial[1];
+            if (!memory_region_is_mapped(sc->serial_io[1])) {
+                memory_region_add_subregion(isa_address_space_io(dev),
+                                            dev->ioport_id, sc->serial_io[1]);
+            }
+        } else {
+            MemoryRegion *io = isa_address_space_io(sc->superio->serial[1]);
+            if (memory_region_is_mapped(sc->serial_io[1])) {
+                memory_region_del_subregion(io, sc->serial_io[1]);
+            }
+        }
+        break;
+    }
+    case 0xe7: /* Serial port 1 io base address */
+    {
+        data &= 0xfe;
+        sc->superio->serial[0]->ioport_id = data << 2;
+        if (memory_region_is_mapped(sc->serial_io[0])) {
+            memory_region_set_address(sc->serial_io[0], data << 2);
+        }
+        break;
+    }
+    case 0xe8: /* Serial port 2 io base address */
+    {
+        data &= 0xfe;
+        sc->superio->serial[1]->ioport_id = data << 2;
+        if (memory_region_is_mapped(sc->serial_io[1])) {
+            memory_region_set_address(sc->serial_io[1], data << 2);
+        }
+        break;
+    }
     default:
         qemu_log_mask(LOG_UNIMP,
                       "via_superio_cfg: unimplemented register 0x%x\n", idx);
@@ -385,6 +447,7 @@ static void vt82c686b_realize(PCIDevice *d, Error **errp)
     DeviceState *dev = DEVICE(d);
     ISABus *isa_bus;
     qemu_irq *isa_irq;
+    ISASuperIOClass *ic;
     int i;
 
     qdev_init_gpio_out(dev, &s->cpu_intr, 1);
@@ -394,7 +457,9 @@ static void vt82c686b_realize(PCIDevice *d, Error **errp)
     isa_bus_irqs(isa_bus, i8259_init(isa_bus, *isa_irq));
     i8254_pit_init(isa_bus, 0x40, 0, NULL);
     i8257_dma_init(isa_bus, 0);
-    isa_create_simple(isa_bus, TYPE_VT82C686B_SUPERIO);
+    s->superio_cfg.superio = ISA_SUPERIO(isa_create_simple(isa_bus,
+                                                      TYPE_VT82C686B_SUPERIO));
+    ic = ISA_SUPERIO_GET_CLASS(s->superio_cfg.superio);
     mc146818_rtc_init(isa_bus, 2000, NULL);
 
     for (i = 0; i < PCI_CONFIG_HEADER_SIZE; i++) {
@@ -412,6 +477,21 @@ static void vt82c686b_realize(PCIDevice *d, Error **errp)
      */
     memory_region_add_subregion(isa_bus->address_space_io, 0x3f0,
                                 &s->superio_cfg.io);
+
+    /* Grab io regions of serial devices so we can control them */
+    for (i = 0; i < ic->serial.count; i++) {
+        ISADevice *sd = s->superio_cfg.superio->serial[i];
+        MemoryRegion *io = isa_address_space_io(sd);
+        MemoryRegion *mr = find_subregion(sd, io, sd->ioport_id);
+        if (!mr) {
+            error_setg(errp, "Could not get io region for serial %d", i);
+            return;
+        }
+        s->superio_cfg.serial_io[i] = mr;
+        if (memory_region_is_mapped(mr)) {
+            memory_region_del_subregion(io, mr);
+        }
+    }
 }
 
 static void via_class_init(ObjectClass *klass, void *data)
#3 lore raw

Re: [PATCH v7 1/8] vt82c686: Implement control of serial port io ranges via config regs

Quoted 1 line · Philippe Mathieu-Daudé

ping for review?

I'm not sure who you're asking for a review from.

Quoted 154 lines · BALATON Zoltan
Quoted 151 lines

In VIA super south bridge the io ranges of superio components (parallel and serial ports and FDC) can be controlled by superio config registers to set their base address and enable/disable them. This is not easy to implement in QEMU because ISA emulation is only designed to set io base address once on creating the device and io ranges are registered at creation and cannot easily be disabled or moved later.

In this patch we hack around that but only for serial ports because those have a single io range at port base that's relatively easy to handle and it's what guests actually use and set address different than the default.

We do not attempt to handle controlling the parallel and FDC regions because those have multiple io ranges so handling them would be messy and guests either don't change their deafult or don't care. We could even get away with disabling and not emulating them, but since they are already there, this patch leaves them mapped at their default address just in case this could be useful for a guest in the future.

---
 hw/isa/vt82c686.c | 84 +++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 82 insertions(+), 2 deletions(-)
hw/isa/vt82c686.c +82 -2
index 05d084f698..a3353ec5db 100644
@@ -252,8 +252,24 @@ static const TypeInfo vt8231_pm_info = {
 typedef struct SuperIOConfig {
     uint8_t regs[0x100];
     MemoryRegion io;
+    ISASuperIODevice *superio;
+    MemoryRegion *serial_io[SUPERIO_MAX_SERIAL_PORTS];
 } SuperIOConfig;
 
+static MemoryRegion *find_subregion(ISADevice *d, MemoryRegion *parent,
+                                    int offs)
+{
+    MemoryRegion *subregion, *mr = NULL;
+
+    QTAILQ_FOREACH(subregion, &parent->subregions, subregions_link) {
+        if (subregion->addr == offs) {
+            mr = subregion;
+            break;
+        }
+    }
+    return mr;
+}
+
 static void superio_cfg_write(void *opaque, hwaddr addr, uint64_t data,
                               unsigned size)
 {
@@ -279,7 +295,53 @@ static void superio_cfg_write(void *opaque, hwaddr addr, uint64_t data,
     case 0xfd ... 0xff:
         /* ignore write to read only registers */
         return;
-    /* case 0xe6 ... 0xe8: Should set base port of parallel and serial */
+    case 0xe2:
+    {
+        data &= 0x1f;
+        if (data & BIT(2)) { /* Serial port 1 enable */
+            ISADevice *dev = sc->superio->serial[0];
+            if (!memory_region_is_mapped(sc->serial_io[0])) {
+                memory_region_add_subregion(isa_address_space_io(dev),
+                                            dev->ioport_id, sc->serial_io[0]);
+            }
+        } else {
+            MemoryRegion *io = isa_address_space_io(sc->superio->serial[0]);
+            if (memory_region_is_mapped(sc->serial_io[0])) {
+                memory_region_del_subregion(io, sc->serial_io[0]);
+            }
+        }
+        if (data & BIT(3)) { /* Serial port 2 enable */
+            ISADevice *dev = sc->superio->serial[1];
+            if (!memory_region_is_mapped(sc->serial_io[1])) {
+                memory_region_add_subregion(isa_address_space_io(dev),
+                                            dev->ioport_id, sc->serial_io[1]);
+            }
+        } else {
+            MemoryRegion *io = isa_address_space_io(sc->superio->serial[1]);
+            if (memory_region_is_mapped(sc->serial_io[1])) {
+                memory_region_del_subregion(io, sc->serial_io[1]);
+            }
+        }
+        break;
+    }
+    case 0xe7: /* Serial port 1 io base address */
+    {
+        data &= 0xfe;
+        sc->superio->serial[0]->ioport_id = data << 2;
+        if (memory_region_is_mapped(sc->serial_io[0])) {
+            memory_region_set_address(sc->serial_io[0], data << 2);
+        }
+        break;
+    }
+    case 0xe8: /* Serial port 2 io base address */
+    {
+        data &= 0xfe;
+        sc->superio->serial[1]->ioport_id = data << 2;
+        if (memory_region_is_mapped(sc->serial_io[1])) {
+            memory_region_set_address(sc->serial_io[1], data << 2);
+        }
+        break;
+    }
     default:
         qemu_log_mask(LOG_UNIMP,
                       "via_superio_cfg: unimplemented register 0x%x\n", idx);
@@ -385,6 +447,7 @@ static void vt82c686b_realize(PCIDevice *d, Error **errp)
     DeviceState *dev = DEVICE(d);
     ISABus *isa_bus;
     qemu_irq *isa_irq;
+    ISASuperIOClass *ic;
     int i;
 
     qdev_init_gpio_out(dev, &s->cpu_intr, 1);
@@ -394,7 +457,9 @@ static void vt82c686b_realize(PCIDevice *d, Error **errp)
     isa_bus_irqs(isa_bus, i8259_init(isa_bus, *isa_irq));
     i8254_pit_init(isa_bus, 0x40, 0, NULL);
     i8257_dma_init(isa_bus, 0);
-    isa_create_simple(isa_bus, TYPE_VT82C686B_SUPERIO);
+    s->superio_cfg.superio = ISA_SUPERIO(isa_create_simple(isa_bus,
+                                                      TYPE_VT82C686B_SUPERIO));
+    ic = ISA_SUPERIO_GET_CLASS(s->superio_cfg.superio);
     mc146818_rtc_init(isa_bus, 2000, NULL);
 
     for (i = 0; i < PCI_CONFIG_HEADER_SIZE; i++) {
@@ -412,6 +477,21 @@ static void vt82c686b_realize(PCIDevice *d, Error **errp)
      */
     memory_region_add_subregion(isa_bus->address_space_io, 0x3f0,
                                 &s->superio_cfg.io);
+
+    /* Grab io regions of serial devices so we can control them */
+    for (i = 0; i < ic->serial.count; i++) {
+        ISADevice *sd = s->superio_cfg.superio->serial[i];
+        MemoryRegion *io = isa_address_space_io(sd);
+        MemoryRegion *mr = find_subregion(sd, io, sd->ioport_id);
+        if (!mr) {
+            error_setg(errp, "Could not get io region for serial %d", i);
+            return;
+        }
+        s->superio_cfg.serial_io[i] = mr;
+        if (memory_region_is_mapped(mr)) {
+            memory_region_del_subregion(io, mr);
+        }
+    }
 }
 
 static void via_class_init(ObjectClass *klass, void *data)
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#4 lore raw

Re: [PATCH v7 1/8] vt82c686: Implement control of serial port io ranges via config regs

In reply to BALATON Zoltan
Quoted 13 lines · BALATON Zoltan

In VIA super south bridge the io ranges of superio components (parallel and serial ports and FDC) can be controlled by superio config registers to set their base address and enable/disable them. This is not easy to implement in QEMU because ISA emulation is only designed to set io base address once on creating the device and io ranges are registered at creation and cannot easily be disabled or moved later.

In this patch we hack around that but only for serial ports because those have a single io range at port base that's relatively easy to handle and it's what guests actually use and set address different than the default.

Quoted 8 lines

We do not attempt to handle controlling the parallel and FDC regions because those have multiple io ranges so handling them would be messy and guests either don't change their deafult or don't care. We could even get away with disabling and not emulating them, but since they are already there, this patch leaves them mapped at their default address just in case this could be useful for a guest in the future.

Could this patch be reviewed now please? I've dropped it from later versions to avoid this holding back the series but now that it won't be in 6.0 I'd like to go back to this. This is implementing the behaviour of the real hardware better than the unsettable default value we have as a replacement. That approach also works for the guests I've tried (MorphOS and Linux) but if we can do better than why not do it?

Regards,
BALATON Zoltan

Quoted 130 lines

---
hw/isa/vt82c686.c | 84 +++++++++++++++++++++++++++++++++++++++++++++--

1 file changed, 82 insertions(+), 2 deletions(-)
hw/isa/vt82c686.c +82 -2
index 05d084f698..a3353ec5db 100644
@@ -252,8 +252,24 @@ static const TypeInfo vt8231_pm_info = {
 typedef struct SuperIOConfig {
    uint8_t regs[0x100];
    MemoryRegion io;
+    ISASuperIODevice *superio;
+    MemoryRegion *serial_io[SUPERIO_MAX_SERIAL_PORTS];
 } SuperIOConfig;
 
+static MemoryRegion *find_subregion(ISADevice *d, MemoryRegion *parent,
+                                    int offs)
+{
+    MemoryRegion *subregion, *mr = NULL;
+
+    QTAILQ_FOREACH(subregion, &parent->subregions, subregions_link) {
+        if (subregion->addr == offs) {
+            mr = subregion;
+            break;
+        }
+    }
+    return mr;
+}
+
 static void superio_cfg_write(void *opaque, hwaddr addr, uint64_t data,
                              unsigned size)
 {
@@ -279,7 +295,53 @@ static void superio_cfg_write(void *opaque, hwaddr addr, uint64_t data,
    case 0xfd ... 0xff:
        /* ignore write to read only registers */
        return;
-    /* case 0xe6 ... 0xe8: Should set base port of parallel and serial */
+    case 0xe2:
+    {
+        data &= 0x1f;
+        if (data & BIT(2)) { /* Serial port 1 enable */
+            ISADevice *dev = sc->superio->serial[0];
+            if (!memory_region_is_mapped(sc->serial_io[0])) {
+                memory_region_add_subregion(isa_address_space_io(dev),
+                                            dev->ioport_id, sc->serial_io[0]);
+            }
+        } else {
+            MemoryRegion *io = isa_address_space_io(sc->superio->serial[0]);
+            if (memory_region_is_mapped(sc->serial_io[0])) {
+                memory_region_del_subregion(io, sc->serial_io[0]);
+            }
+        }
+        if (data & BIT(3)) { /* Serial port 2 enable */
+            ISADevice *dev = sc->superio->serial[1];
+            if (!memory_region_is_mapped(sc->serial_io[1])) {
+                memory_region_add_subregion(isa_address_space_io(dev),
+                                            dev->ioport_id, sc->serial_io[1]);
+            }
+        } else {
+            MemoryRegion *io = isa_address_space_io(sc->superio->serial[1]);
+            if (memory_region_is_mapped(sc->serial_io[1])) {
+                memory_region_del_subregion(io, sc->serial_io[1]);
+            }
+        }
+        break;
+    }
+    case 0xe7: /* Serial port 1 io base address */
+    {
+        data &= 0xfe;
+        sc->superio->serial[0]->ioport_id = data << 2;
+        if (memory_region_is_mapped(sc->serial_io[0])) {
+            memory_region_set_address(sc->serial_io[0], data << 2);
+        }
+        break;
+    }
+    case 0xe8: /* Serial port 2 io base address */
+    {
+        data &= 0xfe;
+        sc->superio->serial[1]->ioport_id = data << 2;
+        if (memory_region_is_mapped(sc->serial_io[1])) {
+            memory_region_set_address(sc->serial_io[1], data << 2);
+        }
+        break;
+    }
    default:
        qemu_log_mask(LOG_UNIMP,
                      "via_superio_cfg: unimplemented register 0x%x\n", idx);
@@ -385,6 +447,7 @@ static void vt82c686b_realize(PCIDevice *d, Error **errp)
    DeviceState *dev = DEVICE(d);
    ISABus *isa_bus;
    qemu_irq *isa_irq;
+    ISASuperIOClass *ic;
    int i;
 
    qdev_init_gpio_out(dev, &s->cpu_intr, 1);
@@ -394,7 +457,9 @@ static void vt82c686b_realize(PCIDevice *d, Error **errp)
    isa_bus_irqs(isa_bus, i8259_init(isa_bus, *isa_irq));
    i8254_pit_init(isa_bus, 0x40, 0, NULL);
    i8257_dma_init(isa_bus, 0);
-    isa_create_simple(isa_bus, TYPE_VT82C686B_SUPERIO);
+    s->superio_cfg.superio = ISA_SUPERIO(isa_create_simple(isa_bus,
+                                                      TYPE_VT82C686B_SUPERIO));
+    ic = ISA_SUPERIO_GET_CLASS(s->superio_cfg.superio);
    mc146818_rtc_init(isa_bus, 2000, NULL);
 
    for (i = 0; i < PCI_CONFIG_HEADER_SIZE; i++) {
@@ -412,6 +477,21 @@ static void vt82c686b_realize(PCIDevice *d, Error **errp)
     */
    memory_region_add_subregion(isa_bus->address_space_io, 0x3f0,
                                &s->superio_cfg.io);
+
+    /* Grab io regions of serial devices so we can control them */
+    for (i = 0; i < ic->serial.count; i++) {
+        ISADevice *sd = s->superio_cfg.superio->serial[i];
+        MemoryRegion *io = isa_address_space_io(sd);
+        MemoryRegion *mr = find_subregion(sd, io, sd->ioport_id);
+        if (!mr) {
+            error_setg(errp, "Could not get io region for serial %d", i);
+            return;
+        }
+        s->superio_cfg.serial_io[i] = mr;
+        if (memory_region_is_mapped(mr)) {
+            memory_region_del_subregion(io, mr);
+        }
+    }
 }
 
 static void via_class_init(ObjectClass *klass, void *data)
#5 lore raw

Re: [PATCH v7 1/8] vt82c686: Implement control of serial port io ranges via config regs

Quoted 21 lines · BALATON Zoltan
Quoted 20 lines · BALATON Zoltan

In VIA super south bridge the io ranges of superio components (parallel and serial ports and FDC) can be controlled by superio config registers to set their base address and enable/disable them. This is not easy to implement in QEMU because ISA emulation is only designed to set io base address once on creating the device and io ranges are registered at creation and cannot easily be disabled or moved later.

In this patch we hack around that but only for serial ports because those have a single io range at port base that's relatively easy to handle and it's what guests actually use and set address different than the default.

We do not attempt to handle controlling the parallel and FDC regions because those have multiple io ranges so handling them would be messy and guests either don't change their deafult or don't care. We could even get away with disabling and not emulating them, but since they are already there, this patch leaves them mapped at their default address just in case this could be useful for a guest in the future.

Quoted 3 lines
Quoted 1 line

Could this patch be reviewed now please? I've dropped it from later versions to avoid this holding back the series but now that it won't be in 6.0 I'd like to go back to this. This is implementing the behaviour of the real hardware better than the unsettable default value we have as a replacement. That approach also works for the guests I've tried (MorphOS and Linux) but if we can do better than why not do it?

Do bear in mind that several people have already looked at this patch and haven't felt comfortable enough to review it, and I've also said in a previous email that this isn't the right approach. Given that the ISA bus partly uses the ioport address to reference the device, manually moving the memory regions around for devices on the bus without the ISA bus seeing those changes is going to cause issues.

IIRC the ability to dynamically change the standard ISA addresses was present in several motherboards from that era, and given that this functionality hasn't been implemented in QEMU this already tells us that no firmware is currently is using it.

I don't understand why using the hard-coded addresses in the v10 is a problem here? The addresses you added in the comments representing the programmed values are the standard ISA device addresses, so if those are what the firmware is programming then there will be no change. You also reported that it works fine with both your MorphOS and Linux test images, indicating that neither of these guest OSs require the feature.

If you find a guest OS that needs the functionality then certainly we can talk about trying to come up with a solution, but for me the extra complexity of this approach and the fact that you're overriding the management of the device by the ISA bus is why I haven't given it a R-B tag (I should add that my R-B for v10 using the hard-coded ISA addresses still stands).

ATB,

Mark.

#6 lore raw

Re: [PATCH v7 1/8] vt82c686: Implement control of serial port io ranges via config regs

Quoted 22 lines · Mark Cave-Ayland
Quoted 21 lines · BALATON Zoltan
Quoted 20 lines · BALATON Zoltan

In VIA super south bridge the io ranges of superio components (parallel and serial ports and FDC) can be controlled by superio config registers to set their base address and enable/disable them. This is not easy to implement in QEMU because ISA emulation is only designed to set io base address once on creating the device and io ranges are registered at creation and cannot easily be disabled or moved later.

In this patch we hack around that but only for serial ports because those have a single io range at port base that's relatively easy to handle and it's what guests actually use and set address different than the default.

We do not attempt to handle controlling the parallel and FDC regions because those have multiple io ranges so handling them would be messy and guests either don't change their deafult or don't care. We could even get away with disabling and not emulating them, but since they are already there, this patch leaves them mapped at their default address just in case this could be useful for a guest in the future.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Could this patch be reviewed now please? I've dropped it from later versions to avoid this holding back the series but now that it won't be in 6.0 I'd like to go back to this. This is implementing the behaviour of the real hardware better than the unsettable default value we have as a replacement. That approach also works for the guests I've tried (MorphOS and Linux) but if we can do better than why not do it?

Do bear in mind that several people have already looked at this patch and haven't felt comfortable enough to review it, and I've also said in a

I haven't heard back from many people (mostly only Philippe and you and maybe David looked at it but I did not expect him to review it as it's not his area) so I had the impression nobody cared or had time to look at it. That's why I've raised this again to get a clear answer about it. Now that at least you dislike this patch it's good enough reason to drop it for now and go with the default value instead until a guest is found to need this functionality.

Quoted 1 line

previous email that this isn't the right approach. Given that the ISA bus partly uses the ioport address to reference the device, manually moving the memory regions around for devices on the bus without the ISA bus seeing those changes is going to cause issues.

The ioport_id you refer to is only used to print device name so the only issue is that the device may be currently mapped to a different address than its name might suggest when you query it but that should not break any functionality so maybe only cosmetic. The current ISA bus emulation in QEMU does not care about ISA devices after they are created, they are just initialised once and then the bus seems to forget about them. At least there are no functions to enable/disable or control them afterwards, only to register them at startup. So it's static and does not allow dynamically changing devices like we have in these VTxxx chips. (By the way, this is the same problem via-ide has that required hacks instead of actually emulating what the chip does because we can't have both ISA IDE and PCI IDE as the ISA one cannot be moved or disabled once created.) That's what this patch tried to circumvent at least for serial ports but without completly changing ISA emulation which might be a better approach but well beyond the effort I'm willing to put into this.

Quoted 1 line

IIRC the ability to dynamically change the standard ISA addresses was present in several motherboards from that era, and given that this functionality hasn't been implemented in QEMU this already tells us that no firmware is currently is using it.

QEMU only supports SeaBIOS and on PC the ports are usually at their default address at startup so it's probably not firmware but guests that could change it. I don't know what other BIOSes might do as those don't run on QEMU. But these VTxxx chips are not used on PC machine models. The fuloong2e PMON and pegasos2 SmartFirtmware seem to poke the regs enabling and setting port address of these at startup (otherwise the chip seems to start without these enabled) so I've tried to emulate that. On pegasos2 it even uses different than usual standard value (as it only has one serial port) and guests boot with that so we can use that default. It's not exactly how the real device works but satisfies guests that rely on firmware to set up these and don't touch it later.

Quoted 1 line

I don't understand why using the hard-coded addresses in the v10 is a problem here? The addresses you added in the comments representing the programmed values are the standard ISA device addresses, so if those are what the firmware is programming then there will be no change. You also reported that it works fine with both your MorphOS and Linux test images, indicating that neither of these guest OSs require the feature.

For now the default address will do until a guest is found actually needing this. I just wanted to salvage this patch before dismissing it without a good reason.

Quoted 1 line

If you find a guest OS that needs the functionality then certainly we can talk about trying to come up with a solution, but for me the extra complexity of this approach and the fact that you're overriding the management of the device by the ISA bus is why I haven't given it a R-B tag (I should add that my R-B for v10 using the hard-coded ISA addresses still stands).

OK then forget it, at least this is a clear vote against this patch and if others don't care that means it should be dropped. Thanks for explaining it again.

Regards,
BALATON Zoltan

#7 lore raw

PATCH v7 2/8 vt82c686: QOM-ify superio related functionality

In reply to BALATON Zoltan

Collect superio functionality and its controlling config registers handling in an abstract VIA_SUPERIO class that is a subclass of ISA_SUPERIO and put vt82c686b specific parts in a subclass of this abstract class.

---
 hw/isa/vt82c686.c         | 242 ++++++++++++++++++++++++--------------
 include/hw/isa/vt82c686.h |   1 -
 2 files changed, 152 insertions(+), 91 deletions(-)
hw/isa/vt82c686.c +152 -90
index a3353ec5db..e89dbf43da 100644
@@ -249,12 +249,21 @@ static const TypeInfo vt8231_pm_info = {
 };
 
 
-typedef struct SuperIOConfig {
+#define TYPE_VIA_SUPERIO "via-superio"
+OBJECT_DECLARE_SIMPLE_TYPE(ViaSuperIOState, VIA_SUPERIO)
+
+struct ViaSuperIOState {
+    ISASuperIODevice superio;
     uint8_t regs[0x100];
+    const MemoryRegionOps *io_ops;
     MemoryRegion io;
-    ISASuperIODevice *superio;
     MemoryRegion *serial_io[SUPERIO_MAX_SERIAL_PORTS];
-} SuperIOConfig;
+};
+
+static inline void via_superio_io_enable(ViaSuperIOState *s, bool enable)
+{
+    memory_region_set_enabled(&s->io, enable);
+}
 
 static MemoryRegion *find_subregion(ISADevice *d, MemoryRegion *parent,
                                     int offs)
@@ -270,10 +279,78 @@ static MemoryRegion *find_subregion(ISADevice *d, MemoryRegion *parent,
     return mr;
 }
 
-static void superio_cfg_write(void *opaque, hwaddr addr, uint64_t data,
-                              unsigned size)
+static void via_superio_realize(DeviceState *d, Error **errp)
+{
+    ViaSuperIOState *s = VIA_SUPERIO(d);
+    ISASuperIOClass *ic = ISA_SUPERIO_GET_CLASS(s);
+    Error *local_err = NULL;
+    int i;
+
+    assert(s->io_ops);
+    ic->parent_realize(d, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        return;
+    }
+    /* Grab io regions of serial devices so we can control them */
+    for (i = 0; i < ic->serial.count; i++) {
+        ISADevice *sd = s->superio.serial[i];
+        MemoryRegion *io = isa_address_space_io(sd);
+        MemoryRegion *mr = find_subregion(sd, io, sd->ioport_id);
+        if (!mr) {
+            error_setg(errp, "Could not get io region for serial %d", i);
+            return;
+        }
+        s->serial_io[i] = mr;
+    }
+
+    memory_region_init_io(&s->io, OBJECT(d), s->io_ops, s, "via-superio", 2);
+    memory_region_set_enabled(&s->io, false);
+    /* The floppy also uses 0x3f0 and 0x3f1 but this seems to work anyway */
+    memory_region_add_subregion(isa_address_space_io(ISA_DEVICE(s)), 0x3f0,
+                                &s->io);
+}
+
+static uint64_t via_superio_cfg_read(void *opaque, hwaddr addr, unsigned size)
+{
+    ViaSuperIOState *sc = opaque;
+    uint8_t idx = sc->regs[0];
+    uint8_t val = sc->regs[idx];
+
+    if (addr == 0) {
+        return idx;
+    }
+    if (addr == 1 && idx == 0) {
+        val = 0; /* reading reg 0 where we store index value */
+    }
+    trace_via_superio_read(idx, val);
+    return val;
+}
+
+static void via_superio_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    ISASuperIOClass *sc = ISA_SUPERIO_CLASS(klass);
+
+    sc->parent_realize = dc->realize;
+    dc->realize = via_superio_realize;
+}
+
+static const TypeInfo via_superio_info = {
+    .name          = TYPE_VIA_SUPERIO,
+    .parent        = TYPE_ISA_SUPERIO,
+    .instance_size = sizeof(ViaSuperIOState),
+    .class_size    = sizeof(ISASuperIOClass),
+    .class_init    = via_superio_class_init,
+    .abstract      = true,
+};
+
+#define TYPE_VT82C686B_SUPERIO "vt82c686b-superio"
+
+static void vt82c686b_superio_cfg_write(void *opaque, hwaddr addr,
+                                        uint64_t data, unsigned size)
 {
-    SuperIOConfig *sc = opaque;
+    ViaSuperIOState *sc = opaque;
     uint8_t idx = sc->regs[0];
 
     if (addr == 0) { /* config index register */
@@ -295,29 +372,29 @@ static void superio_cfg_write(void *opaque, hwaddr addr, uint64_t data,
     case 0xfd ... 0xff:
         /* ignore write to read only registers */
         return;
-    case 0xe2:
+    case 0xe2: /* Function select */
     {
         data &= 0x1f;
         if (data & BIT(2)) { /* Serial port 1 enable */
-            ISADevice *dev = sc->superio->serial[0];
+            ISADevice *dev = sc->superio.serial[0];
             if (!memory_region_is_mapped(sc->serial_io[0])) {
                 memory_region_add_subregion(isa_address_space_io(dev),
                                             dev->ioport_id, sc->serial_io[0]);
             }
         } else {
-            MemoryRegion *io = isa_address_space_io(sc->superio->serial[0]);
+            MemoryRegion *io = isa_address_space_io(sc->superio.serial[0]);
             if (memory_region_is_mapped(sc->serial_io[0])) {
                 memory_region_del_subregion(io, sc->serial_io[0]);
             }
         }
         if (data & BIT(3)) { /* Serial port 2 enable */
-            ISADevice *dev = sc->superio->serial[1];
+            ISADevice *dev = sc->superio.serial[1];
             if (!memory_region_is_mapped(sc->serial_io[1])) {
                 memory_region_add_subregion(isa_address_space_io(dev),
                                             dev->ioport_id, sc->serial_io[1]);
             }
         } else {
-            MemoryRegion *io = isa_address_space_io(sc->superio->serial[1]);
+            MemoryRegion *io = isa_address_space_io(sc->superio.serial[1]);
             if (memory_region_is_mapped(sc->serial_io[1])) {
                 memory_region_del_subregion(io, sc->serial_io[1]);
             }
@@ -327,7 +404,7 @@ static void superio_cfg_write(void *opaque, hwaddr addr, uint64_t data,
     case 0xe7: /* Serial port 1 io base address */
     {
         data &= 0xfe;
-        sc->superio->serial[0]->ioport_id = data << 2;
+        sc->superio.serial[0]->ioport_id = data << 2;
         if (memory_region_is_mapped(sc->serial_io[0])) {
             memory_region_set_address(sc->serial_io[0], data << 2);
         }
@@ -336,7 +413,7 @@ static void superio_cfg_write(void *opaque, hwaddr addr, uint64_t data,
     case 0xe8: /* Serial port 2 io base address */
     {
         data &= 0xfe;
-        sc->superio->serial[1]->ioport_id = data << 2;
+        sc->superio.serial[1]->ioport_id = data << 2;
         if (memory_region_is_mapped(sc->serial_io[1])) {
             memory_region_set_address(sc->serial_io[1], data << 2);
         }
@@ -350,25 +427,9 @@ static void superio_cfg_write(void *opaque, hwaddr addr, uint64_t data,
     sc->regs[idx] = data;
 }
 
-static uint64_t superio_cfg_read(void *opaque, hwaddr addr, unsigned size)
-{
-    SuperIOConfig *sc = opaque;
-    uint8_t idx = sc->regs[0];
-    uint8_t val = sc->regs[idx];
-
-    if (addr == 0) {
-        return idx;
-    }
-    if (addr == 1 && idx == 0) {
-        val = 0; /* reading reg 0 where we store index value */
-    }
-    trace_via_superio_read(idx, val);
-    return val;
-}
-
-static const MemoryRegionOps superio_cfg_ops = {
-    .read = superio_cfg_read,
-    .write = superio_cfg_write,
+static const MemoryRegionOps vt82c686b_superio_cfg_ops = {
+    .read = via_superio_cfg_read,
+    .write = vt82c686b_superio_cfg_write,
     .endianness = DEVICE_NATIVE_ENDIAN,
     .impl = {
         .min_access_size = 1,
@@ -376,13 +437,66 @@ static const MemoryRegionOps superio_cfg_ops = {
     },
 };
 
+static void vt82c686b_superio_reset(DeviceState *dev)
+{
+    ViaSuperIOState *s = VIA_SUPERIO(dev);
+
+    memset(s->regs, 0, sizeof(s->regs));
+    /* Device ID */
+    vt82c686b_superio_cfg_write(s, 0, 0xe0, 1);
+    vt82c686b_superio_cfg_write(s, 1, 0x3c, 1);
+    /* Function select - all disabled */
+    vt82c686b_superio_cfg_write(s, 0, 0xe2, 1);
+    vt82c686b_superio_cfg_write(s, 1, 0x03, 1);
+    /* Floppy ctrl base addr */
+    vt82c686b_superio_cfg_write(s, 0, 0xe3, 1);
+    vt82c686b_superio_cfg_write(s, 1, 0xfc, 1);
+    /* Parallel port base addr */
+    vt82c686b_superio_cfg_write(s, 0, 0xe6, 1);
+    vt82c686b_superio_cfg_write(s, 1, 0xde, 1);
+    /* Serial port 1 base addr */
+    vt82c686b_superio_cfg_write(s, 0, 0xe7, 1);
+    vt82c686b_superio_cfg_write(s, 1, 0xfe, 1);
+    /* Serial port 2 base addr */
+    vt82c686b_superio_cfg_write(s, 0, 0xe8, 1);
+    vt82c686b_superio_cfg_write(s, 1, 0xbe, 1);
+
+    vt82c686b_superio_cfg_write(s, 0, 0, 1);
+}
+
+static void vt82c686b_superio_init(Object *obj)
+{
+    VIA_SUPERIO(obj)->io_ops = &vt82c686b_superio_cfg_ops;
+}
+
+static void vt82c686b_superio_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    ISASuperIOClass *sc = ISA_SUPERIO_CLASS(klass);
+
+    dc->reset = vt82c686b_superio_reset;
+    sc->serial.count = 2;
+    sc->parallel.count = 1;
+    sc->ide.count = 0; /* emulated by via-ide */
+    sc->floppy.count = 1;
+}
+
+static const TypeInfo vt82c686b_superio_info = {
+    .name          = TYPE_VT82C686B_SUPERIO,
+    .parent        = TYPE_VIA_SUPERIO,
+    .instance_size = sizeof(ViaSuperIOState),
+    .instance_init = vt82c686b_superio_init,
+    .class_size    = sizeof(ISASuperIOClass),
+    .class_init    = vt82c686b_superio_class_init,
+};
+
 
 OBJECT_DECLARE_SIMPLE_TYPE(VT82C686BISAState, VT82C686B_ISA)
 
 struct VT82C686BISAState {
     PCIDevice dev;
     qemu_irq cpu_intr;
-    SuperIOConfig superio_cfg;
+    ViaSuperIOState *via_sio;
 };
 
 static void via_isa_request_i8259_irq(void *opaque, int irq, int level)
@@ -400,7 +514,7 @@ static void vt82c686b_write_config(PCIDevice *d, uint32_t addr,
     pci_default_write_config(d, addr, val, len);
     if (addr == 0x85) {
         /* BIT(1): enable or disable superio config io ports */
-        memory_region_set_enabled(&s->superio_cfg.io, val & BIT(1));
+        via_superio_io_enable(s->via_sio, val & BIT(1));
     }
 }
 
@@ -432,13 +546,6 @@ static void vt82c686b_isa_reset(DeviceState *dev)
     pci_conf[0x5a] = 0x04; /* KBC/RTC Control*/
     pci_conf[0x5f] = 0x04;
     pci_conf[0x77] = 0x10; /* GPIO Control 1/2/3/4 */
-
-    s->superio_cfg.regs[0xe0] = 0x3c; /* Device ID */
-    s->superio_cfg.regs[0xe2] = 0x03; /* Function select */
-    s->superio_cfg.regs[0xe3] = 0xfc; /* Floppy ctrl base addr */
-    s->superio_cfg.regs[0xe6] = 0xde; /* Parallel port base addr */
-    s->superio_cfg.regs[0xe7] = 0xfe; /* Serial port 1 base addr */
-    s->superio_cfg.regs[0xe8] = 0xbe; /* Serial port 2 base addr */
 }
 
 static void vt82c686b_realize(PCIDevice *d, Error **errp)
@@ -447,7 +554,6 @@ static void vt82c686b_realize(PCIDevice *d, Error **errp)
     DeviceState *dev = DEVICE(d);
     ISABus *isa_bus;
     qemu_irq *isa_irq;
-    ISASuperIOClass *ic;
     int i;
 
     qdev_init_gpio_out(dev, &s->cpu_intr, 1);
@@ -457,9 +563,8 @@ static void vt82c686b_realize(PCIDevice *d, Error **errp)
     isa_bus_irqs(isa_bus, i8259_init(isa_bus, *isa_irq));
     i8254_pit_init(isa_bus, 0x40, 0, NULL);
     i8257_dma_init(isa_bus, 0);
-    s->superio_cfg.superio = ISA_SUPERIO(isa_create_simple(isa_bus,
-                                                      TYPE_VT82C686B_SUPERIO));
-    ic = ISA_SUPERIO_GET_CLASS(s->superio_cfg.superio);
+    s->via_sio = VIA_SUPERIO(isa_create_simple(isa_bus,
+                                               TYPE_VT82C686B_SUPERIO));
     mc146818_rtc_init(isa_bus, 2000, NULL);
 
     for (i = 0; i < PCI_CONFIG_HEADER_SIZE; i++) {
@@ -467,31 +572,6 @@ static void vt82c686b_realize(PCIDevice *d, Error **errp)
             d->wmask[i] = 0;
         }
     }
-
-    memory_region_init_io(&s->superio_cfg.io, OBJECT(d), &superio_cfg_ops,
-                          &s->superio_cfg, "superio_cfg", 2);
-    memory_region_set_enabled(&s->superio_cfg.io, false);
-    /*
-     * The floppy also uses 0x3f0 and 0x3f1.
-     * But we do not emulate a floppy, so just set it here.
-     */
-    memory_region_add_subregion(isa_bus->address_space_io, 0x3f0,
-                                &s->superio_cfg.io);
-
-    /* Grab io regions of serial devices so we can control them */
-    for (i = 0; i < ic->serial.count; i++) {
-        ISADevice *sd = s->superio_cfg.superio->serial[i];
-        MemoryRegion *io = isa_address_space_io(sd);
-        MemoryRegion *mr = find_subregion(sd, io, sd->ioport_id);
-        if (!mr) {
-            error_setg(errp, "Could not get io region for serial %d", i);
-            return;
-        }
-        s->superio_cfg.serial_io[i] = mr;
-        if (memory_region_is_mapped(mr)) {
-            memory_region_del_subregion(io, mr);
-        }
-    }
 }
 
 static void via_class_init(ObjectClass *klass, void *data)
@@ -527,32 +607,14 @@ static const TypeInfo via_info = {
 };
 
 
-static void vt82c686b_superio_class_init(ObjectClass *klass, void *data)
-{
-    ISASuperIOClass *sc = ISA_SUPERIO_CLASS(klass);
-
-    sc->serial.count = 2;
-    sc->parallel.count = 1;
-    sc->ide.count = 0;
-    sc->floppy.count = 1;
-}
-
-static const TypeInfo via_superio_info = {
-    .name          = TYPE_VT82C686B_SUPERIO,
-    .parent        = TYPE_ISA_SUPERIO,
-    .instance_size = sizeof(ISASuperIODevice),
-    .class_size    = sizeof(ISASuperIOClass),
-    .class_init    = vt82c686b_superio_class_init,
-};
-
-
 static void vt82c686b_register_types(void)
 {
     type_register_static(&via_pm_info);
     type_register_static(&vt82c686b_pm_info);
     type_register_static(&vt8231_pm_info);
-    type_register_static(&via_info);
     type_register_static(&via_superio_info);
+    type_register_static(&vt82c686b_superio_info);
+    type_register_static(&via_info);
 }
 
 type_init(vt82c686b_register_types)
include/hw/isa/vt82c686.h +0 -1
index 9b6d610e83..0692b9a527 100644
@@ -2,7 +2,6 @@
 #define HW_VT82C686_H
 
 #define TYPE_VT82C686B_ISA "vt82c686b-isa"
-#define TYPE_VT82C686B_SUPERIO "vt82c686b-superio"
 #define TYPE_VT82C686B_PM "vt82c686b-pm"
 #define TYPE_VT8231_PM "vt8231-pm"
 #define TYPE_VIA_AC97 "via-ac97"
Signature · 1 line
2.21.3
#8 lore raw

Re: [PATCH v7 2/8] vt82c686: QOM-ify superio related functionality

Quoted 59 lines · BALATON Zoltan

Collect superio functionality and its controlling config registers handling in an abstract VIA_SUPERIO class that is a subclass of ISA_SUPERIO and put vt82c686b specific parts in a subclass of this abstract class.

---
 hw/isa/vt82c686.c         | 242 ++++++++++++++++++++++++--------------
 include/hw/isa/vt82c686.h |   1 -
 2 files changed, 152 insertions(+), 91 deletions(-)
hw/isa/vt82c686.c +25 -5
index a3353ec5db..e89dbf43da 100644
@@ -249,12 +249,21 @@ static const TypeInfo vt8231_pm_info = {
 };
 
 
-typedef struct SuperIOConfig {
+#define TYPE_VIA_SUPERIO "via-superio"
+OBJECT_DECLARE_SIMPLE_TYPE(ViaSuperIOState, VIA_SUPERIO)
+
+struct ViaSuperIOState {
+    ISASuperIODevice superio;
     uint8_t regs[0x100];
+    const MemoryRegionOps *io_ops;
     MemoryRegion io;
-    ISASuperIODevice *superio;
     MemoryRegion *serial_io[SUPERIO_MAX_SERIAL_PORTS];
-} SuperIOConfig;
+};
+
+static inline void via_superio_io_enable(ViaSuperIOState *s, bool enable)
+{
+    memory_region_set_enabled(&s->io, enable);
+}
 
 static MemoryRegion *find_subregion(ISADevice *d, MemoryRegion *parent,
                                     int offs)
@@ -270,10 +279,78 @@ static MemoryRegion *find_subregion(ISADevice *d, MemoryRegion *parent,
     return mr;
 }
 
-static void superio_cfg_write(void *opaque, hwaddr addr, uint64_t data,
-                              unsigned size)
+static void via_superio_realize(DeviceState *d, Error **errp)
+{
+    ViaSuperIOState *s = VIA_SUPERIO(d);
+    ISASuperIOClass *ic = ISA_SUPERIO_GET_CLASS(s);
+    Error *local_err = NULL;
+    int i;
+
+    assert(s->io_ops);
+    ic->parent_realize(d, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        return;
+    }

hw/isa/vt82c686.c static MemoryRegion *find_subregion(ISADevice *d, MemoryRegion *parent, · line 304

Quoted 10 lines
hw/isa/vt82c686.c +10 -0
+    /* Grab io regions of serial devices so we can control them */
+    for (i = 0; i < ic->serial.count; i++) {
+        ISADevice *sd = s->superio.serial[i];
+        MemoryRegion *io = isa_address_space_io(sd);
+        MemoryRegion *mr = find_subregion(sd, io, sd->ioport_id);
+        if (!mr) {
+            error_setg(errp, "Could not get io region for serial %d", i);
+            return;
+        }
+        s->serial_io[i] = mr;

Don't we need to memory_region_ref(mr) here?

Quoted 326 lines
hw/isa/vt82c686.c +117 -85
+    }
+
+    memory_region_init_io(&s->io, OBJECT(d), s->io_ops, s, "via-superio", 2);
+    memory_region_set_enabled(&s->io, false);
+    /* The floppy also uses 0x3f0 and 0x3f1 but this seems to work anyway */
+    memory_region_add_subregion(isa_address_space_io(ISA_DEVICE(s)), 0x3f0,
+                                &s->io);
+}
+
+static uint64_t via_superio_cfg_read(void *opaque, hwaddr addr, unsigned size)
+{
+    ViaSuperIOState *sc = opaque;
+    uint8_t idx = sc->regs[0];
+    uint8_t val = sc->regs[idx];
+
+    if (addr == 0) {
+        return idx;
+    }
+    if (addr == 1 && idx == 0) {
+        val = 0; /* reading reg 0 where we store index value */
+    }
+    trace_via_superio_read(idx, val);
+    return val;
+}
+
+static void via_superio_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    ISASuperIOClass *sc = ISA_SUPERIO_CLASS(klass);
+
+    sc->parent_realize = dc->realize;
+    dc->realize = via_superio_realize;
+}
+
+static const TypeInfo via_superio_info = {
+    .name          = TYPE_VIA_SUPERIO,
+    .parent        = TYPE_ISA_SUPERIO,
+    .instance_size = sizeof(ViaSuperIOState),
+    .class_size    = sizeof(ISASuperIOClass),
+    .class_init    = via_superio_class_init,
+    .abstract      = true,
+};
+
+#define TYPE_VT82C686B_SUPERIO "vt82c686b-superio"
+
+static void vt82c686b_superio_cfg_write(void *opaque, hwaddr addr,
+                                        uint64_t data, unsigned size)
 {
-    SuperIOConfig *sc = opaque;
+    ViaSuperIOState *sc = opaque;
     uint8_t idx = sc->regs[0];
 
     if (addr == 0) { /* config index register */
@@ -295,29 +372,29 @@ static void superio_cfg_write(void *opaque, hwaddr addr, uint64_t data,
     case 0xfd ... 0xff:
         /* ignore write to read only registers */
         return;
-    case 0xe2:
+    case 0xe2: /* Function select */
     {
         data &= 0x1f;
         if (data & BIT(2)) { /* Serial port 1 enable */
-            ISADevice *dev = sc->superio->serial[0];
+            ISADevice *dev = sc->superio.serial[0];
             if (!memory_region_is_mapped(sc->serial_io[0])) {
                 memory_region_add_subregion(isa_address_space_io(dev),
                                             dev->ioport_id, sc->serial_io[0]);
             }
         } else {
-            MemoryRegion *io = isa_address_space_io(sc->superio->serial[0]);
+            MemoryRegion *io = isa_address_space_io(sc->superio.serial[0]);
             if (memory_region_is_mapped(sc->serial_io[0])) {
                 memory_region_del_subregion(io, sc->serial_io[0]);
             }
         }
         if (data & BIT(3)) { /* Serial port 2 enable */
-            ISADevice *dev = sc->superio->serial[1];
+            ISADevice *dev = sc->superio.serial[1];
             if (!memory_region_is_mapped(sc->serial_io[1])) {
                 memory_region_add_subregion(isa_address_space_io(dev),
                                             dev->ioport_id, sc->serial_io[1]);
             }
         } else {
-            MemoryRegion *io = isa_address_space_io(sc->superio->serial[1]);
+            MemoryRegion *io = isa_address_space_io(sc->superio.serial[1]);
             if (memory_region_is_mapped(sc->serial_io[1])) {
                 memory_region_del_subregion(io, sc->serial_io[1]);
             }
@@ -327,7 +404,7 @@ static void superio_cfg_write(void *opaque, hwaddr addr, uint64_t data,
     case 0xe7: /* Serial port 1 io base address */
     {
         data &= 0xfe;
-        sc->superio->serial[0]->ioport_id = data << 2;
+        sc->superio.serial[0]->ioport_id = data << 2;
         if (memory_region_is_mapped(sc->serial_io[0])) {
             memory_region_set_address(sc->serial_io[0], data << 2);
         }
@@ -336,7 +413,7 @@ static void superio_cfg_write(void *opaque, hwaddr addr, uint64_t data,
     case 0xe8: /* Serial port 2 io base address */
     {
         data &= 0xfe;
-        sc->superio->serial[1]->ioport_id = data << 2;
+        sc->superio.serial[1]->ioport_id = data << 2;
         if (memory_region_is_mapped(sc->serial_io[1])) {
             memory_region_set_address(sc->serial_io[1], data << 2);
         }
@@ -350,25 +427,9 @@ static void superio_cfg_write(void *opaque, hwaddr addr, uint64_t data,
     sc->regs[idx] = data;
 }
 
-static uint64_t superio_cfg_read(void *opaque, hwaddr addr, unsigned size)
-{
-    SuperIOConfig *sc = opaque;
-    uint8_t idx = sc->regs[0];
-    uint8_t val = sc->regs[idx];
-
-    if (addr == 0) {
-        return idx;
-    }
-    if (addr == 1 && idx == 0) {
-        val = 0; /* reading reg 0 where we store index value */
-    }
-    trace_via_superio_read(idx, val);
-    return val;
-}
-
-static const MemoryRegionOps superio_cfg_ops = {
-    .read = superio_cfg_read,
-    .write = superio_cfg_write,
+static const MemoryRegionOps vt82c686b_superio_cfg_ops = {
+    .read = via_superio_cfg_read,
+    .write = vt82c686b_superio_cfg_write,
     .endianness = DEVICE_NATIVE_ENDIAN,
     .impl = {
         .min_access_size = 1,
@@ -376,13 +437,66 @@ static const MemoryRegionOps superio_cfg_ops = {
     },
 };
 
+static void vt82c686b_superio_reset(DeviceState *dev)
+{
+    ViaSuperIOState *s = VIA_SUPERIO(dev);
+
+    memset(s->regs, 0, sizeof(s->regs));
+    /* Device ID */
+    vt82c686b_superio_cfg_write(s, 0, 0xe0, 1);
+    vt82c686b_superio_cfg_write(s, 1, 0x3c, 1);
+    /* Function select - all disabled */
+    vt82c686b_superio_cfg_write(s, 0, 0xe2, 1);
+    vt82c686b_superio_cfg_write(s, 1, 0x03, 1);
+    /* Floppy ctrl base addr */
+    vt82c686b_superio_cfg_write(s, 0, 0xe3, 1);
+    vt82c686b_superio_cfg_write(s, 1, 0xfc, 1);
+    /* Parallel port base addr */
+    vt82c686b_superio_cfg_write(s, 0, 0xe6, 1);
+    vt82c686b_superio_cfg_write(s, 1, 0xde, 1);
+    /* Serial port 1 base addr */
+    vt82c686b_superio_cfg_write(s, 0, 0xe7, 1);
+    vt82c686b_superio_cfg_write(s, 1, 0xfe, 1);
+    /* Serial port 2 base addr */
+    vt82c686b_superio_cfg_write(s, 0, 0xe8, 1);
+    vt82c686b_superio_cfg_write(s, 1, 0xbe, 1);
+
+    vt82c686b_superio_cfg_write(s, 0, 0, 1);
+}
+
+static void vt82c686b_superio_init(Object *obj)
+{
+    VIA_SUPERIO(obj)->io_ops = &vt82c686b_superio_cfg_ops;
+}
+
+static void vt82c686b_superio_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    ISASuperIOClass *sc = ISA_SUPERIO_CLASS(klass);
+
+    dc->reset = vt82c686b_superio_reset;
+    sc->serial.count = 2;
+    sc->parallel.count = 1;
+    sc->ide.count = 0; /* emulated by via-ide */
+    sc->floppy.count = 1;
+}
+
+static const TypeInfo vt82c686b_superio_info = {
+    .name          = TYPE_VT82C686B_SUPERIO,
+    .parent        = TYPE_VIA_SUPERIO,
+    .instance_size = sizeof(ViaSuperIOState),
+    .instance_init = vt82c686b_superio_init,
+    .class_size    = sizeof(ISASuperIOClass),
+    .class_init    = vt82c686b_superio_class_init,
+};
+
 
 OBJECT_DECLARE_SIMPLE_TYPE(VT82C686BISAState, VT82C686B_ISA)
 
 struct VT82C686BISAState {
     PCIDevice dev;
     qemu_irq cpu_intr;
-    SuperIOConfig superio_cfg;
+    ViaSuperIOState *via_sio;
 };
 
 static void via_isa_request_i8259_irq(void *opaque, int irq, int level)
@@ -400,7 +514,7 @@ static void vt82c686b_write_config(PCIDevice *d, uint32_t addr,
     pci_default_write_config(d, addr, val, len);
     if (addr == 0x85) {
         /* BIT(1): enable or disable superio config io ports */
-        memory_region_set_enabled(&s->superio_cfg.io, val & BIT(1));
+        via_superio_io_enable(s->via_sio, val & BIT(1));
     }
 }
 
@@ -432,13 +546,6 @@ static void vt82c686b_isa_reset(DeviceState *dev)
     pci_conf[0x5a] = 0x04; /* KBC/RTC Control*/
     pci_conf[0x5f] = 0x04;
     pci_conf[0x77] = 0x10; /* GPIO Control 1/2/3/4 */
-
-    s->superio_cfg.regs[0xe0] = 0x3c; /* Device ID */
-    s->superio_cfg.regs[0xe2] = 0x03; /* Function select */
-    s->superio_cfg.regs[0xe3] = 0xfc; /* Floppy ctrl base addr */
-    s->superio_cfg.regs[0xe6] = 0xde; /* Parallel port base addr */
-    s->superio_cfg.regs[0xe7] = 0xfe; /* Serial port 1 base addr */
-    s->superio_cfg.regs[0xe8] = 0xbe; /* Serial port 2 base addr */
 }
 
 static void vt82c686b_realize(PCIDevice *d, Error **errp)
@@ -447,7 +554,6 @@ static void vt82c686b_realize(PCIDevice *d, Error **errp)
     DeviceState *dev = DEVICE(d);
     ISABus *isa_bus;
     qemu_irq *isa_irq;
-    ISASuperIOClass *ic;
     int i;
 
     qdev_init_gpio_out(dev, &s->cpu_intr, 1);
@@ -457,9 +563,8 @@ static void vt82c686b_realize(PCIDevice *d, Error **errp)
     isa_bus_irqs(isa_bus, i8259_init(isa_bus, *isa_irq));
     i8254_pit_init(isa_bus, 0x40, 0, NULL);
     i8257_dma_init(isa_bus, 0);
-    s->superio_cfg.superio = ISA_SUPERIO(isa_create_simple(isa_bus,
-                                                      TYPE_VT82C686B_SUPERIO));
-    ic = ISA_SUPERIO_GET_CLASS(s->superio_cfg.superio);
+    s->via_sio = VIA_SUPERIO(isa_create_simple(isa_bus,
+                                               TYPE_VT82C686B_SUPERIO));
     mc146818_rtc_init(isa_bus, 2000, NULL);
 
     for (i = 0; i < PCI_CONFIG_HEADER_SIZE; i++) {
@@ -467,31 +572,6 @@ static void vt82c686b_realize(PCIDevice *d, Error **errp)
             d->wmask[i] = 0;
         }
     }
-
-    memory_region_init_io(&s->superio_cfg.io, OBJECT(d), &superio_cfg_ops,
-                          &s->superio_cfg, "superio_cfg", 2);
-    memory_region_set_enabled(&s->superio_cfg.io, false);
-    /*
-     * The floppy also uses 0x3f0 and 0x3f1.
-     * But we do not emulate a floppy, so just set it here.
-     */
-    memory_region_add_subregion(isa_bus->address_space_io, 0x3f0,
-                                &s->superio_cfg.io);
-
-    /* Grab io regions of serial devices so we can control them */
-    for (i = 0; i < ic->serial.count; i++) {
-        ISADevice *sd = s->superio_cfg.superio->serial[i];
-        MemoryRegion *io = isa_address_space_io(sd);
-        MemoryRegion *mr = find_subregion(sd, io, sd->ioport_id);
-        if (!mr) {
-            error_setg(errp, "Could not get io region for serial %d", i);
-            return;
-        }
-        s->superio_cfg.serial_io[i] = mr;
-        if (memory_region_is_mapped(mr)) {
-            memory_region_del_subregion(io, mr);
-        }
-    }
 }
 
 static void via_class_init(ObjectClass *klass, void *data)
@@ -527,32 +607,14 @@ static const TypeInfo via_info = {
 };
 
 
-static void vt82c686b_superio_class_init(ObjectClass *klass, void *data)
-{
-    ISASuperIOClass *sc = ISA_SUPERIO_CLASS(klass);
-
-    sc->serial.count = 2;
-    sc->parallel.count = 1;
-    sc->ide.count = 0;
-    sc->floppy.count = 1;
-}
-
-static const TypeInfo via_superio_info = {
-    .name          = TYPE_VT82C686B_SUPERIO,
-    .parent        = TYPE_ISA_SUPERIO,
-    .instance_size = sizeof(ISASuperIODevice),
-    .class_size    = sizeof(ISASuperIOClass),
-    .class_init    = vt82c686b_superio_class_init,
-};
-
-
 static void vt82c686b_register_types(void)
 {
     type_register_static(&via_pm_info);
     type_register_static(&vt82c686b_pm_info);
     type_register_static(&vt8231_pm_info);
-    type_register_static(&via_info);
     type_register_static(&via_superio_info);
+    type_register_static(&vt82c686b_superio_info);
+    type_register_static(&via_info);
 }
 
 type_init(vt82c686b_register_types)
include/hw/isa/vt82c686.h +0 -1
index 9b6d610e83..0692b9a527 100644
@@ -2,7 +2,6 @@
 #define HW_VT82C686_H
 
 #define TYPE_VT82C686B_ISA "vt82c686b-isa"
-#define TYPE_VT82C686B_SUPERIO "vt82c686b-superio"
 #define TYPE_VT82C686B_PM "vt82c686b-pm"
 #define TYPE_VT8231_PM "vt8231-pm"
 #define TYPE_VIA_AC97 "via-ac97"
#9 lore raw

Re: [PATCH v7 2/8] vt82c686: QOM-ify superio related functionality

Quoted 64 lines · Philippe Mathieu-Daudé
Quoted 63 lines · BALATON Zoltan

Collect superio functionality and its controlling config registers handling in an abstract VIA_SUPERIO class that is a subclass of ISA_SUPERIO and put vt82c686b specific parts in a subclass of this abstract class.

---
 hw/isa/vt82c686.c         | 242 ++++++++++++++++++++++++--------------
 include/hw/isa/vt82c686.h |   1 -
 2 files changed, 152 insertions(+), 91 deletions(-)
hw/isa/vt82c686.c +29 -5
index a3353ec5db..e89dbf43da 100644
@@ -249,12 +249,21 @@ static const TypeInfo vt8231_pm_info = {
 };
 
 
-typedef struct SuperIOConfig {
+#define TYPE_VIA_SUPERIO "via-superio"
+OBJECT_DECLARE_SIMPLE_TYPE(ViaSuperIOState, VIA_SUPERIO)
+
+struct ViaSuperIOState {
+    ISASuperIODevice superio;
     uint8_t regs[0x100];
+    const MemoryRegionOps *io_ops;
     MemoryRegion io;
-    ISASuperIODevice *superio;
     MemoryRegion *serial_io[SUPERIO_MAX_SERIAL_PORTS];
-} SuperIOConfig;
+};
+
+static inline void via_superio_io_enable(ViaSuperIOState *s, bool enable)
+{
+    memory_region_set_enabled(&s->io, enable);
+}
 
 static MemoryRegion *find_subregion(ISADevice *d, MemoryRegion *parent,
                                     int offs)
@@ -270,10 +279,78 @@ static MemoryRegion *find_subregion(ISADevice *d, MemoryRegion *parent,
     return mr;
 }
 
-static void superio_cfg_write(void *opaque, hwaddr addr, uint64_t data,
-                              unsigned size)
+static void via_superio_realize(DeviceState *d, Error **errp)
+{
+    ViaSuperIOState *s = VIA_SUPERIO(d);
+    ISASuperIOClass *ic = ISA_SUPERIO_GET_CLASS(s);
+    Error *local_err = NULL;
+    int i;
+
+    assert(s->io_ops);
+    ic->parent_realize(d, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        return;
+    }
+    /* Grab io regions of serial devices so we can control them */
+    for (i = 0; i < ic->serial.count; i++) {
+        ISADevice *sd = s->superio.serial[i];
+        MemoryRegion *io = isa_address_space_io(sd);
Quoted 8 lines

hw/isa/vt82c686.c static MemoryRegion *find_subregion(ISADevice *d, MemoryRegion *parent, · line 304

Quoted 6 lines
hw/isa/vt82c686.c +6 -0
+        MemoryRegion *mr = find_subregion(sd, io, sd->ioport_id);
+        if (!mr) {
+            error_setg(errp, "Could not get io region for serial %d", i);
+            return;
+        }
+        s->serial_io[i] = mr;

Don't we need to memory_region_ref(mr) here?

I don't think so. The ISA device still owns the memory region, we just snatch it to be able to enable/disable and move it around but otherwise don't take it over from the device. The memory region would be destroyed with the device and after that we don't want to keep the memory region as that's not useful without the device. (This is all theoretical though as in practice the device is created at startup and never destroyed until exit.) If we increased ref count here we would also have to decrease it somewhere but since the serial device is child of this south bridge it should not go away before via-superio so no separate reference should be needed here. We own ISASuperIO which owns the isa-serial which owns the memory region so it should stay there during the lifetime of this object without increasing ref count.

Regards,
BALATON Zoltan

Quoted 328 lines
Quoted 326 lines
hw/isa/vt82c686.c +117 -85
+    }
+
+    memory_region_init_io(&s->io, OBJECT(d), s->io_ops, s, "via-superio", 2);
+    memory_region_set_enabled(&s->io, false);
+    /* The floppy also uses 0x3f0 and 0x3f1 but this seems to work anyway */
+    memory_region_add_subregion(isa_address_space_io(ISA_DEVICE(s)), 0x3f0,
+                                &s->io);
+}
+
+static uint64_t via_superio_cfg_read(void *opaque, hwaddr addr, unsigned size)
+{
+    ViaSuperIOState *sc = opaque;
+    uint8_t idx = sc->regs[0];
+    uint8_t val = sc->regs[idx];
+
+    if (addr == 0) {
+        return idx;
+    }
+    if (addr == 1 && idx == 0) {
+        val = 0; /* reading reg 0 where we store index value */
+    }
+    trace_via_superio_read(idx, val);
+    return val;
+}
+
+static void via_superio_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    ISASuperIOClass *sc = ISA_SUPERIO_CLASS(klass);
+
+    sc->parent_realize = dc->realize;
+    dc->realize = via_superio_realize;
+}
+
+static const TypeInfo via_superio_info = {
+    .name          = TYPE_VIA_SUPERIO,
+    .parent        = TYPE_ISA_SUPERIO,
+    .instance_size = sizeof(ViaSuperIOState),
+    .class_size    = sizeof(ISASuperIOClass),
+    .class_init    = via_superio_class_init,
+    .abstract      = true,
+};
+
+#define TYPE_VT82C686B_SUPERIO "vt82c686b-superio"
+
+static void vt82c686b_superio_cfg_write(void *opaque, hwaddr addr,
+                                        uint64_t data, unsigned size)
 {
-    SuperIOConfig *sc = opaque;
+    ViaSuperIOState *sc = opaque;
     uint8_t idx = sc->regs[0];
 
     if (addr == 0) { /* config index register */
@@ -295,29 +372,29 @@ static void superio_cfg_write(void *opaque, hwaddr addr, uint64_t data,
     case 0xfd ... 0xff:
         /* ignore write to read only registers */
         return;
-    case 0xe2:
+    case 0xe2: /* Function select */
     {
         data &= 0x1f;
         if (data & BIT(2)) { /* Serial port 1 enable */
-            ISADevice *dev = sc->superio->serial[0];
+            ISADevice *dev = sc->superio.serial[0];
             if (!memory_region_is_mapped(sc->serial_io[0])) {
                 memory_region_add_subregion(isa_address_space_io(dev),
                                             dev->ioport_id, sc->serial_io[0]);
             }
         } else {
-            MemoryRegion *io = isa_address_space_io(sc->superio->serial[0]);
+            MemoryRegion *io = isa_address_space_io(sc->superio.serial[0]);
             if (memory_region_is_mapped(sc->serial_io[0])) {
                 memory_region_del_subregion(io, sc->serial_io[0]);
             }
         }
         if (data & BIT(3)) { /* Serial port 2 enable */
-            ISADevice *dev = sc->superio->serial[1];
+            ISADevice *dev = sc->superio.serial[1];
             if (!memory_region_is_mapped(sc->serial_io[1])) {
                 memory_region_add_subregion(isa_address_space_io(dev),
                                             dev->ioport_id, sc->serial_io[1]);
             }
         } else {
-            MemoryRegion *io = isa_address_space_io(sc->superio->serial[1]);
+            MemoryRegion *io = isa_address_space_io(sc->superio.serial[1]);
             if (memory_region_is_mapped(sc->serial_io[1])) {
                 memory_region_del_subregion(io, sc->serial_io[1]);
             }
@@ -327,7 +404,7 @@ static void superio_cfg_write(void *opaque, hwaddr addr, uint64_t data,
     case 0xe7: /* Serial port 1 io base address */
     {
         data &= 0xfe;
-        sc->superio->serial[0]->ioport_id = data << 2;
+        sc->superio.serial[0]->ioport_id = data << 2;
         if (memory_region_is_mapped(sc->serial_io[0])) {
             memory_region_set_address(sc->serial_io[0], data << 2);
         }
@@ -336,7 +413,7 @@ static void superio_cfg_write(void *opaque, hwaddr addr, uint64_t data,
     case 0xe8: /* Serial port 2 io base address */
     {
         data &= 0xfe;
-        sc->superio->serial[1]->ioport_id = data << 2;
+        sc->superio.serial[1]->ioport_id = data << 2;
         if (memory_region_is_mapped(sc->serial_io[1])) {
             memory_region_set_address(sc->serial_io[1], data << 2);
         }
@@ -350,25 +427,9 @@ static void superio_cfg_write(void *opaque, hwaddr addr, uint64_t data,
     sc->regs[idx] = data;
 }
 
-static uint64_t superio_cfg_read(void *opaque, hwaddr addr, unsigned size)
-{
-    SuperIOConfig *sc = opaque;
-    uint8_t idx = sc->regs[0];
-    uint8_t val = sc->regs[idx];
-
-    if (addr == 0) {
-        return idx;
-    }
-    if (addr == 1 && idx == 0) {
-        val = 0; /* reading reg 0 where we store index value */
-    }
-    trace_via_superio_read(idx, val);
-    return val;
-}
-
-static const MemoryRegionOps superio_cfg_ops = {
-    .read = superio_cfg_read,
-    .write = superio_cfg_write,
+static const MemoryRegionOps vt82c686b_superio_cfg_ops = {
+    .read = via_superio_cfg_read,
+    .write = vt82c686b_superio_cfg_write,
     .endianness = DEVICE_NATIVE_ENDIAN,
     .impl = {
         .min_access_size = 1,
@@ -376,13 +437,66 @@ static const MemoryRegionOps superio_cfg_ops = {
     },
 };
 
+static void vt82c686b_superio_reset(DeviceState *dev)
+{
+    ViaSuperIOState *s = VIA_SUPERIO(dev);
+
+    memset(s->regs, 0, sizeof(s->regs));
+    /* Device ID */
+    vt82c686b_superio_cfg_write(s, 0, 0xe0, 1);
+    vt82c686b_superio_cfg_write(s, 1, 0x3c, 1);
+    /* Function select - all disabled */
+    vt82c686b_superio_cfg_write(s, 0, 0xe2, 1);
+    vt82c686b_superio_cfg_write(s, 1, 0x03, 1);
+    /* Floppy ctrl base addr */
+    vt82c686b_superio_cfg_write(s, 0, 0xe3, 1);
+    vt82c686b_superio_cfg_write(s, 1, 0xfc, 1);
+    /* Parallel port base addr */
+    vt82c686b_superio_cfg_write(s, 0, 0xe6, 1);
+    vt82c686b_superio_cfg_write(s, 1, 0xde, 1);
+    /* Serial port 1 base addr */
+    vt82c686b_superio_cfg_write(s, 0, 0xe7, 1);
+    vt82c686b_superio_cfg_write(s, 1, 0xfe, 1);
+    /* Serial port 2 base addr */
+    vt82c686b_superio_cfg_write(s, 0, 0xe8, 1);
+    vt82c686b_superio_cfg_write(s, 1, 0xbe, 1);
+
+    vt82c686b_superio_cfg_write(s, 0, 0, 1);
+}
+
+static void vt82c686b_superio_init(Object *obj)
+{
+    VIA_SUPERIO(obj)->io_ops = &vt82c686b_superio_cfg_ops;
+}
+
+static void vt82c686b_superio_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    ISASuperIOClass *sc = ISA_SUPERIO_CLASS(klass);
+
+    dc->reset = vt82c686b_superio_reset;
+    sc->serial.count = 2;
+    sc->parallel.count = 1;
+    sc->ide.count = 0; /* emulated by via-ide */
+    sc->floppy.count = 1;
+}
+
+static const TypeInfo vt82c686b_superio_info = {
+    .name          = TYPE_VT82C686B_SUPERIO,
+    .parent        = TYPE_VIA_SUPERIO,
+    .instance_size = sizeof(ViaSuperIOState),
+    .instance_init = vt82c686b_superio_init,
+    .class_size    = sizeof(ISASuperIOClass),
+    .class_init    = vt82c686b_superio_class_init,
+};
+
 
 OBJECT_DECLARE_SIMPLE_TYPE(VT82C686BISAState, VT82C686B_ISA)
 
 struct VT82C686BISAState {
     PCIDevice dev;
     qemu_irq cpu_intr;
-    SuperIOConfig superio_cfg;
+    ViaSuperIOState *via_sio;
 };
 
 static void via_isa_request_i8259_irq(void *opaque, int irq, int level)
@@ -400,7 +514,7 @@ static void vt82c686b_write_config(PCIDevice *d, uint32_t addr,
     pci_default_write_config(d, addr, val, len);
     if (addr == 0x85) {
         /* BIT(1): enable or disable superio config io ports */
-        memory_region_set_enabled(&s->superio_cfg.io, val & BIT(1));
+        via_superio_io_enable(s->via_sio, val & BIT(1));
     }
 }
 
@@ -432,13 +546,6 @@ static void vt82c686b_isa_reset(DeviceState *dev)
     pci_conf[0x5a] = 0x04; /* KBC/RTC Control*/
     pci_conf[0x5f] = 0x04;
     pci_conf[0x77] = 0x10; /* GPIO Control 1/2/3/4 */
-
-    s->superio_cfg.regs[0xe0] = 0x3c; /* Device ID */
-    s->superio_cfg.regs[0xe2] = 0x03; /* Function select */
-    s->superio_cfg.regs[0xe3] = 0xfc; /* Floppy ctrl base addr */
-    s->superio_cfg.regs[0xe6] = 0xde; /* Parallel port base addr */
-    s->superio_cfg.regs[0xe7] = 0xfe; /* Serial port 1 base addr */
-    s->superio_cfg.regs[0xe8] = 0xbe; /* Serial port 2 base addr */
 }
 
 static void vt82c686b_realize(PCIDevice *d, Error **errp)
@@ -447,7 +554,6 @@ static void vt82c686b_realize(PCIDevice *d, Error **errp)
     DeviceState *dev = DEVICE(d);
     ISABus *isa_bus;
     qemu_irq *isa_irq;
-    ISASuperIOClass *ic;
     int i;
 
     qdev_init_gpio_out(dev, &s->cpu_intr, 1);
@@ -457,9 +563,8 @@ static void vt82c686b_realize(PCIDevice *d, Error **errp)
     isa_bus_irqs(isa_bus, i8259_init(isa_bus, *isa_irq));
     i8254_pit_init(isa_bus, 0x40, 0, NULL);
     i8257_dma_init(isa_bus, 0);
-    s->superio_cfg.superio = ISA_SUPERIO(isa_create_simple(isa_bus,
-                                                      TYPE_VT82C686B_SUPERIO));
-    ic = ISA_SUPERIO_GET_CLASS(s->superio_cfg.superio);
+    s->via_sio = VIA_SUPERIO(isa_create_simple(isa_bus,
+                                               TYPE_VT82C686B_SUPERIO));
     mc146818_rtc_init(isa_bus, 2000, NULL);
 
     for (i = 0; i < PCI_CONFIG_HEADER_SIZE; i++) {
@@ -467,31 +572,6 @@ static void vt82c686b_realize(PCIDevice *d, Error **errp)
             d->wmask[i] = 0;
         }
     }
-
-    memory_region_init_io(&s->superio_cfg.io, OBJECT(d), &superio_cfg_ops,
-                          &s->superio_cfg, "superio_cfg", 2);
-    memory_region_set_enabled(&s->superio_cfg.io, false);
-    /*
-     * The floppy also uses 0x3f0 and 0x3f1.
-     * But we do not emulate a floppy, so just set it here.
-     */
-    memory_region_add_subregion(isa_bus->address_space_io, 0x3f0,
-                                &s->superio_cfg.io);
-
-    /* Grab io regions of serial devices so we can control them */
-    for (i = 0; i < ic->serial.count; i++) {
-        ISADevice *sd = s->superio_cfg.superio->serial[i];
-        MemoryRegion *io = isa_address_space_io(sd);
-        MemoryRegion *mr = find_subregion(sd, io, sd->ioport_id);
-        if (!mr) {
-            error_setg(errp, "Could not get io region for serial %d", i);
-            return;
-        }
-        s->superio_cfg.serial_io[i] = mr;
-        if (memory_region_is_mapped(mr)) {
-            memory_region_del_subregion(io, mr);
-        }
-    }
 }
 
 static void via_class_init(ObjectClass *klass, void *data)
@@ -527,32 +607,14 @@ static const TypeInfo via_info = {
 };
 
 
-static void vt82c686b_superio_class_init(ObjectClass *klass, void *data)
-{
-    ISASuperIOClass *sc = ISA_SUPERIO_CLASS(klass);
-
-    sc->serial.count = 2;
-    sc->parallel.count = 1;
-    sc->ide.count = 0;
-    sc->floppy.count = 1;
-}
-
-static const TypeInfo via_superio_info = {
-    .name          = TYPE_VT82C686B_SUPERIO,
-    .parent        = TYPE_ISA_SUPERIO,
-    .instance_size = sizeof(ISASuperIODevice),
-    .class_size    = sizeof(ISASuperIOClass),
-    .class_init    = vt82c686b_superio_class_init,
-};
-
-
 static void vt82c686b_register_types(void)
 {
     type_register_static(&via_pm_info);
     type_register_static(&vt82c686b_pm_info);
     type_register_static(&vt8231_pm_info);
-    type_register_static(&via_info);
     type_register_static(&via_superio_info);
+    type_register_static(&vt82c686b_superio_info);
+    type_register_static(&via_info);
 }
 
 type_init(vt82c686b_register_types)
include/hw/isa/vt82c686.h +0 -1
index 9b6d610e83..0692b9a527 100644
@@ -2,7 +2,6 @@
 #define HW_VT82C686_H
 
 #define TYPE_VT82C686B_ISA "vt82c686b-isa"
-#define TYPE_VT82C686B_SUPERIO "vt82c686b-superio"
 #define TYPE_VT82C686B_PM "vt82c686b-pm"
 #define TYPE_VT8231_PM "vt8231-pm"
 #define TYPE_VIA_AC97 "via-ac97"
#10 lore raw

PATCH v7 3/8 vt82c686: Add VT8231_SUPERIO based on VIA_SUPERIO

In reply to BALATON Zoltan

The VT8231 south bridge is very similar to VT82C686B but there are some differences in register addresses and functionality, e.g. the VT8231 only has one serial port. This commit adds VT8231_SUPERIO subclass based on the abstract VIA_SUPERIO class to emulate the superio part of VT8231.

---
 hw/isa/vt82c686.c | 121 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 121 insertions(+)
hw/isa/vt82c686.c +121 -0
index e89dbf43da..8131cb42a9 100644
@@ -491,6 +491,126 @@ static const TypeInfo vt82c686b_superio_info = {
 };
 
 
+#define TYPE_VT8231_SUPERIO "vt8231-superio"
+
+static void vt8231_superio_cfg_write(void *opaque, hwaddr addr,
+                                     uint64_t data, unsigned size)
+{
+    ViaSuperIOState *sc = opaque;
+    uint8_t idx = sc->regs[0];
+
+    if (addr == 0) { /* config index register */
+        sc->regs[0] = data;
+        return;
+    }
+
+    /* config data register */
+    trace_via_superio_write(idx, data);
+    switch (idx) {
+    case 0x00 ... 0xdf:
+    case 0xe7 ... 0xef:
+    case 0xf0 ... 0xf1:
+    case 0xf5:
+    case 0xf8:
+    case 0xfd:
+        /* ignore write to read only registers */
+        return;
+    case 0xf2: /* Function select */
+    {
+        data &= 0x17;
+        if (data & BIT(2)) { /* Serial port enable */
+            ISADevice *dev = sc->superio.serial[0];
+            if (!memory_region_is_mapped(sc->serial_io[0])) {
+                memory_region_add_subregion(isa_address_space_io(dev),
+                                            dev->ioport_id, sc->serial_io[0]);
+            }
+        } else {
+            MemoryRegion *io = isa_address_space_io(sc->superio.serial[0]);
+            if (memory_region_is_mapped(sc->serial_io[0])) {
+                memory_region_del_subregion(io, sc->serial_io[0]);
+            }
+        }
+        break;
+    }
+    case 0xf4: /* Serial port io base address */
+    {
+        data &= 0xfe;
+        sc->superio.serial[0]->ioport_id = data << 2;
+        if (memory_region_is_mapped(sc->serial_io[0])) {
+            memory_region_set_address(sc->serial_io[0], data << 2);
+        }
+        break;
+    }
+    default:
+        qemu_log_mask(LOG_UNIMP,
+                      "via_superio_cfg: unimplemented register 0x%x\n", idx);
+        break;
+    }
+    sc->regs[idx] = data;
+}
+
+static const MemoryRegionOps vt8231_superio_cfg_ops = {
+    .read = via_superio_cfg_read,
+    .write = vt8231_superio_cfg_write,
+    .endianness = DEVICE_NATIVE_ENDIAN,
+    .impl = {
+        .min_access_size = 1,
+        .max_access_size = 1,
+    },
+};
+
+static void vt8231_superio_reset(DeviceState *dev)
+{
+    ViaSuperIOState *s = VIA_SUPERIO(dev);
+
+    memset(s->regs, 0, sizeof(s->regs));
+    /* Device ID */
+    s->regs[0xf0] = 0x3c;
+    /* Device revision */
+    s->regs[0xf1] = 0x01;
+    /* Function select - all disabled */
+    vt8231_superio_cfg_write(s, 0, 0xf2, 1);
+    vt8231_superio_cfg_write(s, 1, 0x03, 1);
+    /* Serial port base addr */
+    vt8231_superio_cfg_write(s, 0, 0xf4, 1);
+    vt8231_superio_cfg_write(s, 1, 0xfe, 1);
+    /* Parallel port base addr */
+    vt8231_superio_cfg_write(s, 0, 0xf6, 1);
+    vt8231_superio_cfg_write(s, 1, 0xde, 1);
+    /* Floppy ctrl base addr */
+    vt8231_superio_cfg_write(s, 0, 0xf7, 1);
+    vt8231_superio_cfg_write(s, 1, 0xfc, 1);
+
+    vt8231_superio_cfg_write(s, 0, 0, 1);
+}
+
+static void vt8231_superio_init(Object *obj)
+{
+    VIA_SUPERIO(obj)->io_ops = &vt8231_superio_cfg_ops;
+}
+
+static void vt8231_superio_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    ISASuperIOClass *sc = ISA_SUPERIO_CLASS(klass);
+
+    dc->reset = vt8231_superio_reset;
+    sc->serial.count = 1;
+    sc->parallel.count = 1;
+    sc->ide.count = 0; /* emulated by via-ide */
+    sc->floppy.count = 1;
+}
+
+static const TypeInfo vt8231_superio_info = {
+    .name          = TYPE_VT8231_SUPERIO,
+    .parent        = TYPE_VIA_SUPERIO,
+    .instance_size = sizeof(ViaSuperIOState),
+    .instance_init = vt8231_superio_init,
+    .class_size    = sizeof(ISASuperIOClass),
+    .class_init    = vt8231_superio_class_init,
+};
+
+
 OBJECT_DECLARE_SIMPLE_TYPE(VT82C686BISAState, VT82C686B_ISA)
 
 struct VT82C686BISAState {
@@ -614,6 +734,7 @@ static void vt82c686b_register_types(void)
     type_register_static(&vt8231_pm_info);
     type_register_static(&via_superio_info);
     type_register_static(&vt82c686b_superio_info);
+    type_register_static(&vt8231_superio_info);
     type_register_static(&via_info);
 }
 
Signature · 1 line
2.21.3
#11 lore raw

PATCH v7 4/8 vt82c686: Introduce abstract TYPE_VIA_ISA and base vt82c686b_isa on it

In reply to BALATON Zoltan

To allow reusing ISA bridge emulation for vt8231_isa move the device state of vt82c686b_isa emulation in an abstract via_isa class. This change breaks migration back compatibility but this is not an issue for Fuloong2E machine which is not versioned or migration supported.

---
 hw/isa/vt82c686.c        | 70 ++++++++++++++++++++++------------------
 include/hw/pci/pci_ids.h |  2 +-
 2 files changed, 40 insertions(+), 32 deletions(-)
hw/isa/vt82c686.c +39 -31
index 8131cb42a9..fddbc974bd 100644
@@ -611,24 +611,48 @@ static const TypeInfo vt8231_superio_info = {
 };
 
 
-OBJECT_DECLARE_SIMPLE_TYPE(VT82C686BISAState, VT82C686B_ISA)
+#define TYPE_VIA_ISA "via-isa"
+OBJECT_DECLARE_SIMPLE_TYPE(ViaISAState, VIA_ISA)
 
-struct VT82C686BISAState {
+struct ViaISAState {
     PCIDevice dev;
     qemu_irq cpu_intr;
     ViaSuperIOState *via_sio;
 };
 
+static const VMStateDescription vmstate_via = {
+    .name = "via-isa",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .fields = (VMStateField[]) {
+        VMSTATE_PCI_DEVICE(dev, ViaISAState),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
+static const TypeInfo via_isa_info = {
+    .name          = TYPE_VIA_ISA,
+    .parent        = TYPE_PCI_DEVICE,
+    .instance_size = sizeof(ViaISAState),
+    .abstract      = true,
+    .interfaces    = (InterfaceInfo[]) {
+        { INTERFACE_CONVENTIONAL_PCI_DEVICE },
+        { },
+    },
+};
+
 static void via_isa_request_i8259_irq(void *opaque, int irq, int level)
 {
-    VT82C686BISAState *s = opaque;
+    ViaISAState *s = opaque;
     qemu_set_irq(s->cpu_intr, level);
 }
 
+/* TYPE_VT82C686B_ISA */
+
 static void vt82c686b_write_config(PCIDevice *d, uint32_t addr,
                                    uint32_t val, int len)
 {
-    VT82C686BISAState *s = VT82C686B_ISA(d);
+    ViaISAState *s = VIA_ISA(d);
 
     trace_via_isa_write(addr, val, len);
     pci_default_write_config(d, addr, val, len);
@@ -638,19 +662,9 @@ static void vt82c686b_write_config(PCIDevice *d, uint32_t addr,
     }
 }
 
-static const VMStateDescription vmstate_via = {
-    .name = "vt82c686b",
-    .version_id = 1,
-    .minimum_version_id = 1,
-    .fields = (VMStateField[]) {
-        VMSTATE_PCI_DEVICE(dev, VT82C686BISAState),
-        VMSTATE_END_OF_LIST()
-    }
-};
-
 static void vt82c686b_isa_reset(DeviceState *dev)
 {
-    VT82C686BISAState *s = VT82C686B_ISA(dev);
+    ViaISAState *s = VIA_ISA(dev);
     uint8_t *pci_conf = s->dev.config;
 
     pci_set_long(pci_conf + PCI_CAPABILITY_LIST, 0x000000c0);
@@ -670,7 +684,7 @@ static void vt82c686b_isa_reset(DeviceState *dev)
 
 static void vt82c686b_realize(PCIDevice *d, Error **errp)
 {
-    VT82C686BISAState *s = VT82C686B_ISA(d);
+    ViaISAState *s = VIA_ISA(d);
     DeviceState *dev = DEVICE(d);
     ISABus *isa_bus;
     qemu_irq *isa_irq;
@@ -694,7 +708,7 @@ static void vt82c686b_realize(PCIDevice *d, Error **errp)
     }
 }
 
-static void via_class_init(ObjectClass *klass, void *data)
+static void vt82c686b_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
@@ -702,28 +716,21 @@ static void via_class_init(ObjectClass *klass, void *data)
     k->realize = vt82c686b_realize;
     k->config_write = vt82c686b_write_config;
     k->vendor_id = PCI_VENDOR_ID_VIA;
-    k->device_id = PCI_DEVICE_ID_VIA_ISA_BRIDGE;
+    k->device_id = PCI_DEVICE_ID_VIA_82C686B_ISA;
     k->class_id = PCI_CLASS_BRIDGE_ISA;
     k->revision = 0x40;
     dc->reset = vt82c686b_isa_reset;
     dc->desc = "ISA bridge";
     dc->vmsd = &vmstate_via;
-    /*
-     * Reason: part of VIA VT82C686 southbridge, needs to be wired up,
-     * e.g. by mips_fuloong2e_init()
-     */
+    /* Reason: part of VIA VT82C686 southbridge, needs to be wired up */
     dc->user_creatable = false;
 }
 
-static const TypeInfo via_info = {
+static const TypeInfo vt82c686b_isa_info = {
     .name          = TYPE_VT82C686B_ISA,
-    .parent        = TYPE_PCI_DEVICE,
-    .instance_size = sizeof(VT82C686BISAState),
-    .class_init    = via_class_init,
-    .interfaces = (InterfaceInfo[]) {
-        { INTERFACE_CONVENTIONAL_PCI_DEVICE },
-        { },
-    },
+    .parent        = TYPE_VIA_ISA,
+    .instance_size = sizeof(ViaISAState),
+    .class_init    = vt82c686b_class_init,
 };
 
 
@@ -735,7 +742,8 @@ static void vt82c686b_register_types(void)
     type_register_static(&via_superio_info);
     type_register_static(&vt82c686b_superio_info);
     type_register_static(&vt8231_superio_info);
-    type_register_static(&via_info);
+    type_register_static(&via_isa_info);
+    type_register_static(&vt82c686b_isa_info);
 }
 
 type_init(vt82c686b_register_types)
include/hw/pci/pci_ids.h +1 -1
index ea28dcc850..aa3f67eaa4 100644
@@ -204,7 +204,7 @@
 #define PCI_VENDOR_ID_XILINX             0x10ee
 
 #define PCI_VENDOR_ID_VIA                0x1106
-#define PCI_DEVICE_ID_VIA_ISA_BRIDGE     0x0686
+#define PCI_DEVICE_ID_VIA_82C686B_ISA    0x0686
 #define PCI_DEVICE_ID_VIA_IDE            0x0571
 #define PCI_DEVICE_ID_VIA_UHCI           0x3038
 #define PCI_DEVICE_ID_VIA_82C686B_PM     0x3057
Signature · 1 line
2.21.3
#12 lore raw

PATCH v7 5/8 vt82c686: Add emulation of VT8231 south bridge

In reply to BALATON Zoltan

Add emulation of VT8231 south bridge ISA part based on the similar VT82C686B but implemented in a separate subclass that holds the differences while reusing parts that can be shared.

---
 hw/isa/vt82c686.c         | 84 +++++++++++++++++++++++++++++++++++++++
 include/hw/isa/vt82c686.h |  1 +
 include/hw/pci/pci_ids.h  |  1 +
 3 files changed, 86 insertions(+)
hw/isa/vt82c686.c +84 -0
index fddbc974bd..51d9eff0ff 100644
@@ -8,6 +8,9 @@
  *
  * Contributions after 2012-01-13 are licensed under the terms of the
  * GNU GPL, version 2 or (at your option) any later version.
+ *
+ * VT8231 south bridge support and general clean up to allow it
+ * Copyright (c) 2018-2020 BALATON Zoltan
  */
 
 #include "qemu/osdep.h"
@@ -733,6 +736,86 @@ static const TypeInfo vt82c686b_isa_info = {
     .class_init    = vt82c686b_class_init,
 };
 
+/* TYPE_VT8231_ISA */
+
+static void vt8231_write_config(PCIDevice *d, uint32_t addr,
+                                uint32_t val, int len)
+{
+    ViaISAState *s = VIA_ISA(d);
+
+    trace_via_isa_write(addr, val, len);
+    pci_default_write_config(d, addr, val, len);
+    if (addr == 0x50) {
+        /* BIT(2): enable or disable superio config io ports */
+        via_superio_io_enable(s->via_sio, val & BIT(2));
+    }
+}
+
+static void vt8231_isa_reset(DeviceState *dev)
+{
+    ViaISAState *s = VIA_ISA(dev);
+    uint8_t *pci_conf = s->dev.config;
+
+    pci_set_long(pci_conf + PCI_CAPABILITY_LIST, 0x000000c0);
+    pci_set_word(pci_conf + PCI_COMMAND, PCI_COMMAND_IO | PCI_COMMAND_MEMORY |
+                 PCI_COMMAND_MASTER | PCI_COMMAND_SPECIAL);
+    pci_set_word(pci_conf + PCI_STATUS, PCI_STATUS_DEVSEL_MEDIUM);
+
+    pci_conf[0x58] = 0x40; /* Miscellaneous Control 0 */
+    pci_conf[0x67] = 0x08; /* Fast IR Config */
+    pci_conf[0x6b] = 0x01; /* Fast IR I/O Base */
+}
+
+static void vt8231_realize(PCIDevice *d, Error **errp)
+{
+    ViaISAState *s = VIA_ISA(d);
+    DeviceState *dev = DEVICE(d);
+    ISABus *isa_bus;
+    qemu_irq *isa_irq;
+    int i;
+
+    qdev_init_gpio_out(dev, &s->cpu_intr, 1);
+    isa_irq = qemu_allocate_irqs(via_isa_request_i8259_irq, s, 1);
+    isa_bus = isa_bus_new(dev, get_system_memory(), pci_address_space_io(d),
+                          &error_fatal);
+    isa_bus_irqs(isa_bus, i8259_init(isa_bus, *isa_irq));
+    i8254_pit_init(isa_bus, 0x40, 0, NULL);
+    i8257_dma_init(isa_bus, 0);
+    s->via_sio = VIA_SUPERIO(isa_create_simple(isa_bus, TYPE_VT8231_SUPERIO));
+    mc146818_rtc_init(isa_bus, 2000, NULL);
+
+    for (i = 0; i < PCI_CONFIG_HEADER_SIZE; i++) {
+        if (i < PCI_COMMAND || i >= PCI_REVISION_ID) {
+            d->wmask[i] = 0;
+        }
+    }
+}
+
+static void vt8231_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+    k->realize = vt8231_realize;
+    k->config_write = vt8231_write_config;
+    k->vendor_id = PCI_VENDOR_ID_VIA;
+    k->device_id = PCI_DEVICE_ID_VIA_8231_ISA;
+    k->class_id = PCI_CLASS_BRIDGE_ISA;
+    k->revision = 0x10;
+    dc->reset = vt8231_isa_reset;
+    dc->desc = "ISA bridge";
+    dc->vmsd = &vmstate_via;
+    /* Reason: part of VIA VT8231 southbridge, needs to be wired up */
+    dc->user_creatable = false;
+}
+
+static const TypeInfo vt8231_isa_info = {
+    .name          = TYPE_VT8231_ISA,
+    .parent        = TYPE_VIA_ISA,
+    .instance_size = sizeof(ViaISAState),
+    .class_init    = vt8231_class_init,
+};
+
 
 static void vt82c686b_register_types(void)
 {
@@ -744,6 +827,7 @@ static void vt82c686b_register_types(void)
     type_register_static(&vt8231_superio_info);
     type_register_static(&via_isa_info);
     type_register_static(&vt82c686b_isa_info);
+    type_register_static(&vt8231_isa_info);
 }
 
 type_init(vt82c686b_register_types)
include/hw/isa/vt82c686.h +1 -0
index 0692b9a527..0f01aaa471 100644
@@ -3,6 +3,7 @@
 
 #define TYPE_VT82C686B_ISA "vt82c686b-isa"
 #define TYPE_VT82C686B_PM "vt82c686b-pm"
+#define TYPE_VT8231_ISA "vt8231-isa"
 #define TYPE_VT8231_PM "vt8231-pm"
 #define TYPE_VIA_AC97 "via-ac97"
 #define TYPE_VIA_MC97 "via-mc97"
include/hw/pci/pci_ids.h +1 -0
index aa3f67eaa4..ac0c23ebc7 100644
@@ -210,6 +210,7 @@
 #define PCI_DEVICE_ID_VIA_82C686B_PM     0x3057
 #define PCI_DEVICE_ID_VIA_AC97           0x3058
 #define PCI_DEVICE_ID_VIA_MC97           0x3068
+#define PCI_DEVICE_ID_VIA_8231_ISA       0x8231
 #define PCI_DEVICE_ID_VIA_8231_PM        0x8235
 
 #define PCI_VENDOR_ID_MARVELL            0x11ab
Signature · 1 line
2.21.3
#13 lore raw

PATCH v7 6/8 hw/isa/Kconfig: Add missing dependency VIA VT82C686 -> APM

In reply to BALATON Zoltan

From: Philippe Mathieu-Daudé <[email protected]>

TYPE_VIA_PM calls apm_init() in via_pm_realize(), so requires APM to be selected.

---
 hw/isa/Kconfig | 1 +
 1 file changed, 1 insertion(+)
hw/isa/Kconfig +1 -0
index c7f07854f7..9c026d0c51 100644
@@ -47,6 +47,7 @@ config VT82C686
     select ACPI_SMBUS
     select SERIAL_ISA
     select FDC
+    select APM
 
 config SMC37C669
     bool
Signature · 1 line
2.21.3
#14 lore raw

PATCH v7 7/8 hw/pci-host: Add emulation of Marvell MV64361 PPC system controller

In reply to BALATON Zoltan

The Marvell Discovery II aka. MV64361 is a PowerPC system controller chip that is used on the pegasos2 PPC board. This adds emulation of it that models the device enough to boot guests on this board. The mv643xx.h header with register definitions is taken from Linux 4.15.10 only fixing white space errors, removing not needed parts and changing formatting for QEMU coding style.

---
 hw/pci-host/Kconfig           |   4 +
 hw/pci-host/meson.build       |   2 +
 hw/pci-host/mv64361.c         | 966 ++++++++++++++++++++++++++++++++++
 hw/pci-host/mv643xx.h         | 918 ++++++++++++++++++++++++++++++++
 hw/pci-host/trace-events      |   6 +
 include/hw/pci-host/mv64361.h |   8 +
 include/hw/pci/pci_ids.h      |   1 +
 7 files changed, 1905 insertions(+)
 create mode 100644 hw/pci-host/mv64361.c
 create mode 100644 hw/pci-host/mv643xx.h
 create mode 100644 include/hw/pci-host/mv64361.h
hw/pci-host/Kconfig +4 -0
index 2ccc96f02c..79c20bf28b 100644
@@ -72,3 +72,7 @@ config REMOTE_PCIHOST
 config SH_PCI
     bool
     select PCI
+
+config MV64361
+    bool
+    select PCI
hw/pci-host/meson.build +2 -0
index 87a896973e..34b3538beb 100644
@@ -19,6 +19,8 @@ pci_ss.add(when: 'CONFIG_GRACKLE_PCI', if_true: files('grackle.c'))
 pci_ss.add(when: 'CONFIG_UNIN_PCI', if_true: files('uninorth.c'))
 # PowerPC E500 boards
 pci_ss.add(when: 'CONFIG_PPCE500_PCI', if_true: files('ppce500.c'))
+# Pegasos2
+pci_ss.add(when: 'CONFIG_MV64361', if_true: files('mv64361.c'))
 
 # ARM devices
 pci_ss.add(when: 'CONFIG_VERSATILE_PCI', if_true: files('versatile.c'))
hw/pci-host/mv64361.c new file +966 -0

966 lines not on this page · raw message

hw/pci-host/mv643xx.h new file +918 -0

918 lines not on this page · raw message

hw/pci-host/trace-events +6 -0
index 7d8063ac42..dac86ad3f0 100644
@@ -3,6 +3,12 @@
 # grackle.c
 grackle_set_irq(int irq_num, int level) "set_irq num %d level %d"
 
+# mv64361.c
+mv64361_region_map(const char *name, uint64_t poffs, uint64_t size, uint64_t moffs) "Mapping %s 0x%"PRIx64"+0x%"PRIx64" @ 0x%"PRIx64
+mv64361_region_enable(const char *op, int num) "Should %s region %d"
+mv64361_reg_read(uint64_t addr, uint32_t val) "0x%"PRIx64" -> 0x%x"
+mv64361_reg_write(uint64_t addr, uint64_t val) "0x%"PRIx64" <- 0x%"PRIx64
+
 # sabre.c
 sabre_set_request(int irq_num) "request irq %d"
 sabre_clear_request(int irq_num) "clear request irq %d"
include/hw/pci-host/mv64361.h new file +8 -0
new file mode 100644
index 0000000000..9cdb35cb3c
@@ -0,0 +1,8 @@
+#ifndef MV64361_H
+#define MV64361_H
+
+#define TYPE_MV64361 "mv64361"
+
+PCIBus *mv64361_get_pci_bus(DeviceState *dev, int n);
+
+#endif
include/hw/pci/pci_ids.h +1 -0
index ac0c23ebc7..5c14681b82 100644
@@ -214,6 +214,7 @@
 #define PCI_DEVICE_ID_VIA_8231_PM        0x8235
 
 #define PCI_VENDOR_ID_MARVELL            0x11ab
+#define PCI_DEVICE_ID_MARVELL_MV6436X    0x6460
 
 #define PCI_VENDOR_ID_SILICON_MOTION     0x126f
 #define PCI_DEVICE_ID_SM501              0x0501
Signature · 1 line
2.21.3
#15 lore raw

PATCH v7 8/8 hw/ppc: Add emulation of Genesi/bPlan Pegasos II

In reply to BALATON Zoltan

Add new machine called pegasos2 emulating the Genesi/bPlan Pegasos II, a PowerPC board based on the Marvell MV64361 system controller and the VIA VT8231 integrated south bridge/superio chips. It can run Linux, AmigaOS and a wide range of MorphOS versions. Currently a firmware ROM image is needed to boot and only MorphOS has a video driver to produce graphics output. Linux could work too but distros that supported this machine don't include usual video drivers so those only run with serial console for now.

---
 MAINTAINERS                             |  10 ++
 default-configs/devices/ppc-softmmu.mak |   2 +
 hw/ppc/Kconfig                          |   9 ++
 hw/ppc/meson.build                      |   2 +
 hw/ppc/pegasos2.c                       | 144 ++++++++++++++++++++++++
 5 files changed, 167 insertions(+)
 create mode 100644 hw/ppc/pegasos2.c
MAINTAINERS +10 -0
index f22d83c178..c363b6ad1e 100644
@@ -1345,6 +1345,16 @@ F: pc-bios/canyonlands.dt[sb]
 F: pc-bios/u-boot-sam460ex-20100605.bin
 F: roms/u-boot-sam460ex
 
+pegasos2
+M: BALATON Zoltan <[email protected]>
+R: David Gibson <[email protected]>
+L: [email protected]
+S: Maintained
+F: hw/ppc/pegasos2.c
+F: hw/pci-host/mv64361.c
+F: hw/pci-host/mv643xx.h
+F: include/hw/pci-host/mv64361.h
+
 RISC-V Machines
 ---------------
 OpenTitan
default-configs/devices/ppc-softmmu.mak +2 -0
index 61b78b844d..4535993d8d 100644
@@ -14,5 +14,7 @@ CONFIG_SAM460EX=y
 CONFIG_MAC_OLDWORLD=y
 CONFIG_MAC_NEWWORLD=y
 
+CONFIG_PEGASOS2=y
+
 # For PReP
 CONFIG_PREP=y
hw/ppc/Kconfig +9 -0
index d11dc30509..e51e0e5e5a 100644
@@ -68,6 +68,15 @@ config SAM460EX
     select USB_OHCI
     select FDT_PPC
 
+config PEGASOS2
+    bool
+    select MV64361
+    select VT82C686
+    select IDE_VIA
+    select SMBUS_EEPROM
+# This should come with VT82C686
+    select ACPI_X86
+
 config PREP
     bool
     imply PCI_DEVICES
hw/ppc/meson.build +2 -0
index 218631c883..86d6f379d1 100644
@@ -78,5 +78,7 @@ ppc_ss.add(when: 'CONFIG_E500', if_true: files(
 ))
 # PowerPC 440 Xilinx ML507 reference board.
 ppc_ss.add(when: 'CONFIG_VIRTEX', if_true: files('virtex_ml507.c'))
+# Pegasos2
+ppc_ss.add(when: 'CONFIG_PEGASOS2', if_true: files('pegasos2.c'))
 
 hw_arch += {'ppc': ppc_ss}
hw/ppc/pegasos2.c new file +144 -0

144 lines not on this page · raw message

Signature · 1 line
2.21.3
#16 lore raw
In reply to BALATON Zoltan
Quoted 1 line · BALATON Zoltan

Hello,

I've started posting this series well in advance to get it into 6.0 and yet it seems like it may be missing it due to organisational issues (no real complaints were found with patches but Philippe seems to like more review that does not seem to happen as nobody is interested). Looks like David is waiting for an ack from Philippe but will be away next week so if this is not resolved now it may be too late on Monday. To avoid that:

David, could you please send an ack before you leave for the last two patches so it could get committed via some other tree while you're away?

Philippe, if you can't ack the vt82c686 patches now are you OK with taking the whole series via your tree before the freeze? That would give you some more days to review and it could always be reverted during the freeze but if it's not merged now I'll have to wait until the summer to get it in again which would be another long delay. I don't think this will get more reviews unless it's in master and people can start using and testing it better.

Thank you,
BALATON Zoltan

Quoted 66 lines

This is adding a new PPC board called pegasos2. More info on it can be found at:

https://osdn.net/projects/qmiga/wiki/SubprojectPegasos2

Currently it needs a firmware ROM image that I cannot include due to original copyright holder (bPlan) did not release it under a free licence but I have plans to write a replacement in the future. With the original board firmware it can boot MorphOS now as:

qemu-system-ppc -M pegasos2 -cdrom morphos.iso -device ati-vga,romfile="" -serial stdio

then enter "boot cd boot.img" at the firmware "ok" prompt as described in the MorphOS.readme. To boot Linux use same command line with e.g. -cdrom debian-8.11.0-powerpc-netinst.iso then enter
"boot cd install/pegasos"

The last patch adds the actual board code after previous patches adding VT8231 and MV64361 system controller chip emulation.

Regards,
BALATON Zoltan

v7: Fix errp usage in patch 2

v6: Rebased on master, updated commit message about migration change

v5: Changes for review comments from David and Philippe

V4: Rename pegasos2_reset to pegasos2_cpu_reset
Add new files to MAINTAINERS

BALATON Zoltan (7):
vt82c686: Implement control of serial port io ranges via config regs
vt82c686: QOM-ify superio related functionality
vt82c686: Add VT8231_SUPERIO based on VIA_SUPERIO
vt82c686: Introduce abstract TYPE_VIA_ISA and base vt82c686b_isa on it
vt82c686: Add emulation of VT8231 south bridge
hw/pci-host: Add emulation of Marvell MV64361 PPC system controller hw/ppc: Add emulation of Genesi/bPlan Pegasos II

Philippe Mathieu-Daudé (1):
hw/isa/Kconfig: Add missing dependency VIA VT82C686 -> APM

MAINTAINERS                             |  10 +
default-configs/devices/ppc-softmmu.mak |   2 +
hw/isa/Kconfig                          |   1 +
hw/isa/vt82c686.c                       | 517 +++++++++++--
hw/pci-host/Kconfig                     |   4 +
hw/pci-host/meson.build                 |   2 +
hw/pci-host/mv64361.c                   | 966 ++++++++++++++++++++++++
hw/pci-host/mv643xx.h                   | 918 ++++++++++++++++++++++
hw/pci-host/trace-events                |   6 +
hw/ppc/Kconfig                          |   9 +
hw/ppc/meson.build                      |   2 +
hw/ppc/pegasos2.c                       | 144 ++++
include/hw/isa/vt82c686.h               |   2 +-
include/hw/pci-host/mv64361.h           |   8 +
include/hw/pci/pci_ids.h                |   4 +-
15 files changed, 2512 insertions(+), 83 deletions(-)

create mode 100644 hw/pci-host/mv64361.c
create mode 100644 hw/pci-host/mv643xx.h
create mode 100644 hw/ppc/pegasos2.c
create mode 100644 include/hw/pci-host/mv64361.h

#17 lore raw
Quoted 8 lines · BALATON Zoltan
Quoted 1 line · BALATON Zoltan

Hello,

I've started posting this series well in advance to get it into 6.0 and yet it seems like it may be missing it due to organisational issues (no real complaints were found with patches but Philippe seems to like more review that does not seem to happen as nobody is interested). Looks like David is waiting for an ack from Philippe but will be away next week so if this is not resolved now it may be too late on Monday. To avoid that:

David, could you please send an ack before you leave for the last two patches so it could get committed via some other tree while you're away?

Philippe, if you can't ack the vt82c686 patches now are you OK with taking the whole series via your tree before the freeze? That would give you some more days to review and it could always be reverted during the freeze but if it's not merged now I'll have to wait until the summer to get it in again which would be another long delay. I don't think this will get more reviews unless it's in master and people can start using and testing it better.

Hello,

Since David seems to be away for this week before seeing my mail asking for an ack from him, now this can only get in by Philippe or Peter. (David said before he'd be OK with the series if Philippe acked it so I think that can count as an implicit ack and it could always be reverted before the releease.)

Philippe, do you have anything against this to get merged now? If not please send a pull or ack it so it has a chance to be in 6.0 or tell if you still intend to do anything about it before the freeze. This series was on the list since January and the remaining parts you did not take are here since February 22nd and the version after your first review since two weeks so it would be nice to sort this out and not block it any further without a good reason.

Regards,
BALATON Zoltan

Quoted 67 lines
Quoted 66 lines

This is adding a new PPC board called pegasos2. More info on it can be found at:

https://osdn.net/projects/qmiga/wiki/SubprojectPegasos2

Currently it needs a firmware ROM image that I cannot include due to original copyright holder (bPlan) did not release it under a free licence but I have plans to write a replacement in the future. With the original board firmware it can boot MorphOS now as:

qemu-system-ppc -M pegasos2 -cdrom morphos.iso -device ati-vga,romfile="" -serial stdio

then enter "boot cd boot.img" at the firmware "ok" prompt as described in the MorphOS.readme. To boot Linux use same command line with e.g. -cdrom debian-8.11.0-powerpc-netinst.iso then enter
"boot cd install/pegasos"

The last patch adds the actual board code after previous patches adding VT8231 and MV64361 system controller chip emulation.

Regards,
BALATON Zoltan

v7: Fix errp usage in patch 2

v6: Rebased on master, updated commit message about migration change

v5: Changes for review comments from David and Philippe

V4: Rename pegasos2_reset to pegasos2_cpu_reset
Add new files to MAINTAINERS

BALATON Zoltan (7):
vt82c686: Implement control of serial port io ranges via config regs
vt82c686: QOM-ify superio related functionality
vt82c686: Add VT8231_SUPERIO based on VIA_SUPERIO
vt82c686: Introduce abstract TYPE_VIA_ISA and base vt82c686b_isa on it
vt82c686: Add emulation of VT8231 south bridge
hw/pci-host: Add emulation of Marvell MV64361 PPC system controller hw/ppc: Add emulation of Genesi/bPlan Pegasos II

Philippe Mathieu-Daudé (1):
hw/isa/Kconfig: Add missing dependency VIA VT82C686 -> APM

MAINTAINERS                             |  10 +
default-configs/devices/ppc-softmmu.mak |   2 +
hw/isa/Kconfig                          |   1 +
hw/isa/vt82c686.c                       | 517 +++++++++++--
hw/pci-host/Kconfig                     |   4 +
hw/pci-host/meson.build                 |   2 +
hw/pci-host/mv64361.c                   | 966 ++++++++++++++++++++++++
hw/pci-host/mv643xx.h                   | 918 ++++++++++++++++++++++
hw/pci-host/trace-events                |   6 +
hw/ppc/Kconfig                          |   9 +
hw/ppc/meson.build                      |   2 +
hw/ppc/pegasos2.c                       | 144 ++++
include/hw/isa/vt82c686.h               |   2 +-
include/hw/pci-host/mv64361.h           |   8 +
include/hw/pci/pci_ids.h                |   4 +-
15 files changed, 2512 insertions(+), 83 deletions(-)

create mode 100644 hw/pci-host/mv64361.c
create mode 100644 hw/pci-host/mv643xx.h
create mode 100644 hw/ppc/pegasos2.c
create mode 100644 include/hw/pci-host/mv64361.h

#18 lore raw

Le 15/03/2021 à 13:33, BALATON Zoltan a écrit :

Quoted 26 lines · BALATON Zoltan
Quoted 9 lines · BALATON Zoltan
Quoted 1 line

Hello,

I've started posting this series well in advance to get it into 6.0 and yet it seems like it may be missing it due to organisational issues (no real complaints were found with patches but Philippe seems to like more review that does not seem to happen as nobody is interested). Looks like David is waiting for an ack from Philippe but will be away next week so if this is not resolved now it may be too late on Monday. To avoid that:

Quoted 8 lines

David, could you please send an ack before you leave for the last two patches so it could get committed via some other tree while you're away?

Philippe, if you can't ack the vt82c686 patches now are you OK with taking the whole series via your tree before the freeze? That would give you some more days to review and it could always be reverted during the freeze but if it's not merged now I'll have to wait until the summer to get it in again which would be another long delay. I don't think this will get more reviews unless it's in master and people can start using and testing it better.

Hello,

Since David seems to be away for this week before seeing my mail asking for an ack from him, now this can only get in by Philippe or Peter. (David said before he'd be OK with the series if Philippe acked it so I think that can count as an implicit ack and it could always be reverted before the releease.)

Quoted 5 lines

Philippe, do you have anything against this to get merged now? If not please send a pull or ack it so it has a chance to be in 6.0 or tell if you still intend to do anything about it before the freeze. This series was on the list since January and the remaining parts you did not take are here since February 22nd and the version after your first review since two weeks so it would be nice to sort this out and not block it any further without a good reason.

Pegasos looks like a New World PowerMac, so perhaps Mark can help?

Thanks,
Laurent

#19 lore raw
Quoted 27 lines · Laurent Vivier

Le 15/03/2021 à 13:33, BALATON Zoltan a écrit :

Quoted 26 lines · BALATON Zoltan
Quoted 9 lines · BALATON Zoltan
Quoted 1 line

Hello,

I've started posting this series well in advance to get it into 6.0 and yet it seems like it may be missing it due to organisational issues (no real complaints were found with patches but Philippe seems to like more review that does not seem to happen as nobody is interested). Looks like David is waiting for an ack from Philippe but will be away next week so if this is not resolved now it may be too late on Monday. To avoid that:

Quoted 8 lines

David, could you please send an ack before you leave for the last two patches so it could get committed via some other tree while you're away?

Philippe, if you can't ack the vt82c686 patches now are you OK with taking the whole series via your tree before the freeze? That would give you some more days to review and it could always be reverted during the freeze but if it's not merged now I'll have to wait until the summer to get it in again which would be another long delay. I don't think this will get more reviews unless it's in master and people can start using and testing it better.

Hello,

Since David seems to be away for this week before seeing my mail asking for an ack from him, now this can only get in by Philippe or Peter. (David said before he'd be OK with the series if Philippe acked it so I think that can count as an implicit ack and it could always be reverted before the releease.)

Quoted 7 lines
Quoted 5 lines

Philippe, do you have anything against this to get merged now? If not please send a pull or ack it so it has a chance to be in 6.0 or tell if you still intend to do anything about it before the freeze. This series was on the list since January and the remaining parts you did not take are here since February 22nd and the version after your first review since two weeks so it would be nice to sort this out and not block it any further without a good reason.

Pegasos looks like a New World PowerMac, so perhaps Mark can help?

The PPC part is mostly reviewed. The problem is the first patch:
"vt82c686: Implement control of serial port io ranges via config regs".

I don't understand it. Zoltan said Paolo isn't acking it because he doesn't mind. I prefer to be cautious and think than Paolo is rather too busy.

Laurent, Peter, can you have a look at it?

Thanks,

Phil.

#20 lore raw

Le 16/03/2021 à 12:49, Philippe Mathieu-Daudé a écrit :

Quoted 34 lines · Laurent Vivier
Quoted 33 lines

Le 15/03/2021 à 13:33, BALATON Zoltan a écrit :

Quoted 31 lines · BALATON Zoltan
Quoted 9 lines · BALATON Zoltan
Quoted 1 line

Hello,

I've started posting this series well in advance to get it into 6.0 and yet it seems like it may be missing it due to organisational issues (no real complaints were found with patches but Philippe seems to like more review that does not seem to happen as nobody is interested). Looks like David is waiting for an ack from Philippe but will be away next week so if this is not resolved now it may be too late on Monday. To avoid that:

Quoted 8 lines

David, could you please send an ack before you leave for the last two patches so it could get committed via some other tree while you're away?

Philippe, if you can't ack the vt82c686 patches now are you OK with taking the whole series via your tree before the freeze? That would give you some more days to review and it could always be reverted during the freeze but if it's not merged now I'll have to wait until the summer to get it in again which would be another long delay. I don't think this will get more reviews unless it's in master and people can start using and testing it better.

Hello,

Since David seems to be away for this week before seeing my mail asking for an ack from him, now this can only get in by Philippe or Peter. (David said before he'd be OK with the series if Philippe acked it so I think that can count as an implicit ack and it could always be reverted before the releease.)

Philippe, do you have anything against this to get merged now? If not please send a pull or ack it so it has a chance to be in 6.0 or tell if you still intend to do anything about it before the freeze. This series was on the list since January and the remaining parts you did not take are here since February 22nd and the version after your first review since two weeks so it would be nice to sort this out and not block it any further without a good reason.

Quoted 4 lines
Quoted 1 line

Pegasos looks like a New World PowerMac, so perhaps Mark can help?

The PPC part is mostly reviewed. The problem is the first patch:
"vt82c686: Implement control of serial port io ranges via config regs".

vt82c686.c is a Fuloong 2E file, why Fuloong 2E maintainers are not involved in the review?

Thanks,
Laurent

#21 lore raw
Quoted 35 lines · Laurent Vivier

Le 16/03/2021 à 12:49, Philippe Mathieu-Daudé a écrit :

Quoted 34 lines · Laurent Vivier
Quoted 33 lines

Le 15/03/2021 à 13:33, BALATON Zoltan a écrit :

Quoted 31 lines · BALATON Zoltan
Quoted 9 lines · BALATON Zoltan
Quoted 1 line

Hello,

I've started posting this series well in advance to get it into 6.0 and yet it seems like it may be missing it due to organisational issues (no real complaints were found with patches but Philippe seems to like more review that does not seem to happen as nobody is interested). Looks like David is waiting for an ack from Philippe but will be away next week so if this is not resolved now it may be too late on Monday. To avoid that:

Quoted 8 lines

David, could you please send an ack before you leave for the last two patches so it could get committed via some other tree while you're away?

Philippe, if you can't ack the vt82c686 patches now are you OK with taking the whole series via your tree before the freeze? That would give you some more days to review and it could always be reverted during the freeze but if it's not merged now I'll have to wait until the summer to get it in again which would be another long delay. I don't think this will get more reviews unless it's in master and people can start using and testing it better.

Hello,

Since David seems to be away for this week before seeing my mail asking for an ack from him, now this can only get in by Philippe or Peter. (David said before he'd be OK with the series if Philippe acked it so I think that can count as an implicit ack and it could always be reverted before the releease.)

Philippe, do you have anything against this to get merged now? If not please send a pull or ack it so it has a chance to be in 6.0 or tell if you still intend to do anything about it before the freeze. This series was on the list since January and the remaining parts you did not take are here since February 22nd and the version after your first review since two weeks so it would be nice to sort this out and not block it any further without a good reason.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Pegasos looks like a New World PowerMac, so perhaps Mark can help?

The PPC part is mostly reviewed. The problem is the first patch:
"vt82c686: Implement control of serial port io ranges via config regs".

vt82c686.c is a Fuloong 2E file, why Fuloong 2E maintainers are not involved in the review?

Philippe is MIPS maintainer and he was involved and reviewed most patches. Huacai did not respond much and Jiaxun's email adress is constantly stripped by the list so whenrver I add him it will be lost the next time. He seems to be more interested in Fuloong 3 anyway so did not respond much either.

All in all I think there's just not enough interest in these machines/devices so my stance is that if it does not break anything just take it now and then we'll have enough time for further review, fixing or reverting during the freeze. Whereas if this is kept pushing back then nothing will happen with them for the next 2-3 months then we'll be back to here and miss the next release as well.

Regards,
BALATON Zoltan

#22 lore raw

Le 16/03/2021 à 13:24, BALATON Zoltan a écrit :

Quoted 46 lines · Laurent Vivier
Quoted 38 lines

Le 16/03/2021 à 12:49, Philippe Mathieu-Daudé a écrit :

Quoted 37 lines · Laurent Vivier
Quoted 36 lines

Le 15/03/2021 à 13:33, BALATON Zoltan a écrit :

Quoted 34 lines · BALATON Zoltan
Quoted 12 lines · BALATON Zoltan
Quoted 1 line

Hello,

I've started posting this series well in advance to get it into 6.0 and yet it seems like it may be missing it due to organisational issues (no real complaints were found with patches but Philippe seems to like more review that does not seem to happen as nobody is interested). Looks like David is waiting for an ack from Philippe but will be away next week so if this is not resolved now it may be too late on Monday. To avoid that:

David, could you please send an ack before you leave for the last two patches so it could get committed via some other tree while you're away?

Quoted 6 lines

Philippe, if you can't ack the vt82c686 patches now are you OK with taking the whole series via your tree before the freeze? That would give you some more days to review and it could always be reverted during the freeze but if it's not merged now I'll have to wait until the summer to get it
in again which would be another long delay. I don't think this will get more reviews unless it's in master and people can start using and testing it better.

Hello,

Since David seems to be away for this week before seeing my mail asking for an ack from him, now this can only get in by Philippe or Peter. (David said before he'd be OK with the series if Philippe
acked it so I think that can count as an implicit ack and it could always be reverted before the releease.)

Philippe, do you have anything against this to get merged now? If not please send a pull or ack it so it has a chance to be in 6.0 or tell if you still intend to do anything about it before the freeze. This series was on the list since January and the remaining parts you did not take are here
since February 22nd and the version after your first review since two weeks so it would be nice to sort this out and not block it any further without a good reason.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Pegasos looks like a New World PowerMac, so perhaps Mark can help?

The PPC part is mostly reviewed. The problem is the first patch:
"vt82c686: Implement control of serial port io ranges via config regs".

vt82c686.c is a Fuloong 2E file, why Fuloong 2E maintainers are not involved in the review?

Quoted 8 lines

Philippe is MIPS maintainer and he was involved and reviewed most patches. Huacai did not respond much and Jiaxun's email adress is constantly stripped by the list so whenrver I add him it will be lost the next time. He seems to be more interested in Fuloong 3 anyway so did not respond much either.

All in all I think there's just not enough interest in these machines/devices so my stance is that if it does not break anything just take it now and then we'll have enough time for further review, fixing or reverting during the freeze. Whereas if this is kept pushing back then nothing will happen with them for the next 2-3 months then we'll be back to here and miss the next release as well.

The PATCH 1 doesn't seem to be needed to have a working Pegasos 2 machine, does it?

If the problem is only with the first patch perhaps you can remove it to have it merged and come back later with a cleaner implementation (it is presented to be a hack)?

I think PATCH 6 can already be merged, and PATCH 2 can be done outside of the series as a pre-requisite.

Then it will be easier to manage a series only adding devices for your new machine.

Thanks,
Laurent

#23 lore raw
Quoted 51 lines · Laurent Vivier

Le 16/03/2021 à 13:24, BALATON Zoltan a écrit :

Quoted 50 lines · Laurent Vivier
Quoted 38 lines

Le 16/03/2021 à 12:49, Philippe Mathieu-Daudé a écrit :

Quoted 37 lines · Laurent Vivier
Quoted 36 lines

Le 15/03/2021 à 13:33, BALATON Zoltan a écrit :

Quoted 34 lines · BALATON Zoltan
Quoted 12 lines · BALATON Zoltan
Quoted 1 line

Hello,

I've started posting this series well in advance to get it into 6.0 and yet it seems like it may be missing it due to organisational issues (no real complaints were found with patches but Philippe seems to like more review that does not seem to happen as nobody is interested). Looks like David is waiting for an ack from Philippe but will be away next week so if this is not resolved now it may be too late on Monday. To avoid that:

David, could you please send an ack before you leave for the last two patches so it could get committed via some other tree while you're away?

Quoted 6 lines

Philippe, if you can't ack the vt82c686 patches now are you OK with taking the whole series via your tree before the freeze? That would give you some more days to review and it could always be reverted during the freeze but if it's not merged now I'll have to wait until the summer to get it
in again which would be another long delay. I don't think this will get more reviews unless it's in master and people can start using and testing it better.

Hello,

Since David seems to be away for this week before seeing my mail asking for an ack from him, now this can only get in by Philippe or Peter. (David said before he'd be OK with the series if Philippe
acked it so I think that can count as an implicit ack and it could always be reverted before the releease.)

Philippe, do you have anything against this to get merged now? If not please send a pull or ack it so it has a chance to be in 6.0 or tell if you still intend to do anything about it before the freeze. This series was on the list since January and the remaining parts you did not take are here
since February 22nd and the version after your first review since two weeks so it would be nice to sort this out and not block it any further without a good reason.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Pegasos looks like a New World PowerMac, so perhaps Mark can help?

The PPC part is mostly reviewed. The problem is the first patch:
"vt82c686: Implement control of serial port io ranges via config regs".

vt82c686.c is a Fuloong 2E file, why Fuloong 2E maintainers are not involved in the review?

Philippe is MIPS maintainer and he was involved and reviewed most patches. Huacai did not respond much and Jiaxun's email adress is constantly stripped by the list so whenrver I add him it will be lost the next time. He seems to be more interested in Fuloong 3 anyway so did not respond much either.

Quoted 6 lines
Quoted 4 lines

All in all I think there's just not enough interest in these machines/devices so my stance is that if it does not break anything just take it now and then we'll have enough time for further review, fixing or reverting during the freeze. Whereas if this is kept pushing back then nothing will happen with them for the next 2-3 months then we'll be back to here and miss the next release as well.

The PATCH 1 doesn't seem to be needed to have a working Pegasos 2 machine, does it?

It is needed (as well as all other patches in the series). Patch 1 is needed for getting serial output which is the only way to communicate with the Pegasos2 firmware so it's really hard to boot anything without it.

Quoted 2 lines

If the problem is only with the first patch perhaps you can remove it to have it merged and come back later with a cleaner implementation (it is presented to be a hack)?

I'll try to explain it again in another message but there's no cleaner solution available without much more work than I want to take up. To do it a more cleaner way ISA emulation would need to be QOM'ified that I won't do. This solution is a hack in that it pokes the isa-serial device from a superclass but there's no easier and cleaner way to do it so this should be good enough for now and it has the lowest chance to break anything else.

Quoted 3 lines

I think PATCH 6 can already be merged, and PATCH 2 can be done outside of the series as a pre-requisite.

Then it will be easier to manage a series only adding devices for your new machine.

It's all or nothing I'm afraid as all these pathces are needed for pegasos2 to work so taking only a few of them won't let users use it in 6.0.

Regards,
BALATON Zoltan

#24 lore raw
Quoted 3 lines · BALATON Zoltan
Quoted 1 line

The PATCH 1 doesn't seem to be needed to have a working Pegasos 2 machine, does it?

It is needed (as well as all other patches in the series). Patch 1 is needed for getting serial output which is the only way to communicate with the Pegasos2 firmware so it's really hard to boot anything without it.

Just having a quick look at patch 1: presumably the issue here is that the Pegasos 2 firmware moves the serial ports to a different address on startup. If you know what that address is, then why not simply change the serial port base address(es) on the SuperIO device from the default?

ATB,

Mark.

#25 lore raw
Quoted 6 lines · Mark Cave-Ayland
Quoted 3 lines · BALATON Zoltan
Quoted 1 line

The PATCH 1 doesn't seem to be needed to have a working Pegasos 2 machine, does it?

It is needed (as well as all other patches in the series). Patch 1 is needed for getting serial output which is the only way to communicate with the Pegasos2 firmware so it's really hard to boot anything without it.

Just having a quick look at patch 1: presumably the issue here is that the Pegasos 2 firmware moves the serial ports to a different address on startup. If you know what that address is, then why not simply change the serial port base address(es) on the SuperIO device from the default?

I had that as first version but other guests may expect the serial at the default address or set it up differently and we can emulate the device more fully this way that works with all guests which is also more like the device works. So putting it at a default address would be a step back. I can attempt that if this approach cannot be used but so far nobody said so.

Regards,
BALATON Zoltan

#26 lore raw
Quoted 9 lines · BALATON Zoltan
Quoted 6 lines · Mark Cave-Ayland
Quoted 3 lines · BALATON Zoltan
Quoted 1 line

The PATCH 1 doesn't seem to be needed to have a working Pegasos 2 machine, does it?

It is needed (as well as all other patches in the series). Patch 1 is needed for getting serial output which is the only way to communicate with the Pegasos2 firmware so it's really hard to boot anything without it.

Just having a quick look at patch 1: presumably the issue here is that the Pegasos 2 firmware moves the serial ports to a different address on startup. If you know what that address is, then why not simply change the serial port base address(es) on the SuperIO device from the default?

I had that as first version but other guests may expect the serial at the default address or set it up differently and we can emulate the device more fully this way that works with all guests which is also more like the device works. So putting it at a default address would be a step back. I can attempt that if this approach cannot be used but so far nobody said so.

That would certainly be my first choice, as swapping out the memory regions within the ISA bus without its knowledge is likely to cause problems (I can see ioport_id being incorrect for one).

Do the guest OSs actually use this feature at all? I don't think I've ever seen such registers being used within QEMU, OSs tend to simply relocate the IO space base address using the BAR if required.

If Linux/MorphOS work with a fixed address then that's good enough for now: the code should look something like this:

    dev = qdev_new(TYPE_SUPER_IO);
    serial_dev = object_resolve_path_component(OBJECT(dev), "serial0"));
    qdev_prop_set_uint32(dev, "iobase", 0x1234);
    qdev_realise_and_unref(dev, &error_fatal);

ATB,

Mark.

#27 lore raw
Quoted 5 lines · Mark Cave-Ayland
Quoted 4 lines · BALATON Zoltan
Quoted 3 lines · Mark Cave-Ayland
Quoted 2 lines · BALATON Zoltan
Quoted 1 line

The PATCH 1 doesn't seem to be needed to have a working Pegasos 2 machine, does it?

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

It is needed (as well as all other patches in the series). Patch 1 is needed for getting serial output which is the only way to communicate with the Pegasos2 firmware so it's really hard to boot anything without it.

Just having a quick look at patch 1: presumably the issue here is that the Pegasos 2 firmware moves the serial ports to a different address on startup. If you know what that address is, then why not simply change the serial port base address(es) on the SuperIO device from the default?

I had that as first version but other guests may expect the serial at the default address or set it up differently and we can emulate the device more fully this way that works with all guests which is also more like the device works. So putting it at a default address would be a step back. I can attempt that if this approach cannot be used but so far nobody said so.

That would certainly be my first choice, as swapping out the memory regions within the ISA bus without its knowledge is likely to cause problems (I can see ioport_id being incorrect for one).

Did you check what's that used for? Unlikely to cause any problems other than displaying initial value of port address instead of current address in device ID but that could be argued about if an ID should change or stay the same as initially. Easily fixable either way.

Quoted 1 line

Do the guest OSs actually use this feature at all? I don't think I've ever seen such registers being used within QEMU, OSs tend to simply relocate the IO space base address using the BAR if required.

The ISA devices don't have io BAR, they are relocatable _within_ ISA IO space by the config registers of the VIA superio chip. But the two guests that currently boot (MorphOS and Linux) don't seems to change default set by the firmware so we can go with the firmware defaults which is less correct than actually emulating what the chip does but whatever. (AmigaOS may also boot but has no gfx driver so can't really check at the moment.)

Quoted 6 lines

If Linux/MorphOS work with a fixed address then that's good enough for now: the code should look something like this:

   dev = qdev_new(TYPE_SUPER_IO);
   serial_dev = object_resolve_path_component(OBJECT(dev), "serial0"));
   qdev_prop_set_uint32(dev, "iobase", 0x1234);
   qdev_realise_and_unref(dev, &error_fatal);

I've sent a v8 dropping patch 1 and setting a default but using the callback ISA superio has for this for that which is a bit cleaner IMO.

Could this turned into a pull request by somebody now?

Regards,
BALATON Zoltan

#28 lore raw
Quoted 20 lines · BALATON Zoltan
Quoted 5 lines · Mark Cave-Ayland
Quoted 4 lines · BALATON Zoltan
Quoted 3 lines · Mark Cave-Ayland
Quoted 2 lines · BALATON Zoltan
Quoted 1 line

The PATCH 1 doesn't seem to be needed to have a working Pegasos 2 machine, does it?

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

It is needed (as well as all other patches in the series). Patch 1 is needed for getting serial output which is the only way to communicate with the Pegasos2 firmware so it's really hard to boot anything without it.

Just having a quick look at patch 1: presumably the issue here is that the Pegasos 2 firmware moves the serial ports to a different address on startup. If you know what that address is, then why not simply change the serial port base address(es) on the SuperIO device from the default?

I had that as first version but other guests may expect the serial at the default address or set it up differently and we can emulate the device more fully this way that works with all guests which is also more like the device works. So putting it at a default address would be a step back. I can attempt that if this approach cannot be used but so far nobody said so.

That would certainly be my first choice, as swapping out the memory regions within the ISA bus without its knowledge is likely to cause problems (I can see ioport_id being incorrect for one).

Did you check what's that used for? Unlikely to cause any problems other than displaying initial value of port address instead of current address in device ID but that could be argued about if an ID should change or stay the same as initially. Easily fixable either way.

Quoted 1 line

Do the guest OSs actually use this feature at all? I don't think I've ever seen such registers being used within QEMU, OSs tend to simply relocate the IO space base address using the BAR if required.

The ISA devices don't have io BAR, they are relocatable _within_ ISA IO space by the config registers of the VIA superio chip. But the two guests that currently boot (MorphOS and Linux) don't seems to change default set by the firmware so we can go with the firmware defaults which is less correct than actually emulating what the chip does but whatever. (AmigaOS may also boot but has no gfx driver so can't really check at the moment.)

Quoted 8 lines
Quoted 6 lines

If Linux/MorphOS work with a fixed address then that's good enough for now: the code should look something like this:

   dev = qdev_new(TYPE_SUPER_IO);
   serial_dev = object_resolve_path_component(OBJECT(dev), "serial0"));
   qdev_prop_set_uint32(dev, "iobase", 0x1234);
   qdev_realise_and_unref(dev, &error_fatal);

I've sent a v8 dropping patch 1 and setting a default but using the callback

And v9 replacing patch 5 with latest that applies on master that has changed while I was sending the previous version...

Quoted 8 lines

ISA superio has for this for that which is a bit cleaner IMO.

Could this turned into a pull request by somebody now?

Regards,
BALATON Zoltan

#29 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 34 lines · Philippe Mathieu-Daudé
Quoted 33 lines · Laurent Vivier

Le 15/03/2021 à 13:33, BALATON Zoltan a écrit :

Quoted 31 lines · BALATON Zoltan
Quoted 9 lines · BALATON Zoltan
Quoted 1 line

Hello,

I've started posting this series well in advance to get it into 6.0 and yet it seems like it may be missing it due to organisational issues (no real complaints were found with patches but Philippe seems to like more review that does not seem to happen as nobody is interested). Looks like David is waiting for an ack from Philippe but will be away next week so if this is not resolved now it may be too late on Monday. To avoid that:

Quoted 8 lines

David, could you please send an ack before you leave for the last two patches so it could get committed via some other tree while you're away?

Philippe, if you can't ack the vt82c686 patches now are you OK with taking the whole series via your tree before the freeze? That would give you some more days to review and it could always be reverted during the freeze but if it's not merged now I'll have to wait until the summer to get it in again which would be another long delay. I don't think this will get more reviews unless it's in master and people can start using and testing it better.

Hello,

Since David seems to be away for this week before seeing my mail asking for an ack from him, now this can only get in by Philippe or Peter. (David said before he'd be OK with the series if Philippe acked it so I think that can count as an implicit ack and it could always be reverted before the releease.)

Philippe, do you have anything against this to get merged now? If not please send a pull or ack it so it has a chance to be in 6.0 or tell if you still intend to do anything about it before the freeze. This series was on the list since January and the remaining parts you did not take are here since February 22nd and the version after your first review since two weeks so it would be nice to sort this out and not block it any further without a good reason.

Quoted 8 lines
Quoted 1 line

Pegasos looks like a New World PowerMac, so perhaps Mark can help?

The PPC part is mostly reviewed. The problem is the first patch:
"vt82c686: Implement control of serial port io ranges via config regs".

I don't understand it. Zoltan said Paolo isn't acking it because he doesn't mind. I prefer to be cautious and think than Paolo is rather too busy.

Can you just send a pull request then and Paolo could nack it or comment on that. If he does not, then this should be OK as it does not touch anything else than vt82c686 so it also should not break anything else.

Basically what the patch does is have a via-superio class that inherits from TYPE_ISA_SUPERIO that creates the ISA devices, among others isa-serial ports. Then the device grabs the memory regions for these serial devices to be able to change their state and address on config register writes. It only does that for serial devices not for parallel and floppy because those have more than one memory region and would not be easy to handle so those are not configurable but left at their default address. We need configurability for serial port because on pegasos2 there's only one serial port and it's set to a non-standard address by the firmware. Fuloong2e used to put these at default address and the firmware did not touch it, we now more properly emulate the chip and allow changing the address which the firmware leaves at the default but on pegasos that would not work.

The resulting model is not so bad as we only access memory region owned by child device (via-superio sets memory region of isa-serial that's created by its superclass isa superio and this is only needed because there's no other interface and one cannot be easily added without possibly breaking something due to other ISA devices that have multiple memory regions). So I think this is the simplest and least invasive solution that shoul be enough for now until ISA device emulation is QOM'ified which is a task I don't want to take up as it's way more work I'd put in and has a possibility to break stuff I don't have a way or time to test so unless somebody does that there's no other easy way to solve this problem.

Regards,
BALATON Zoltan

#30 lore raw
In reply to Philippe Mathieu-Daudé

Another arrempt to explain patch 1. This is the via-superio class that's a subclass of ISA superio:

https://github.com/patchew-project/qemu/blob/ca5d88d2fee0016f939e91ae8b32c18e682064fa/hw/isa/vt82c686.c#L255

#define TYPE_VIA_SUPERIO "via-superio" OBJECT_DECLARE_SIMPLE_TYPE(ViaSuperIOState, VIA_SUPERIO)

struct ViaSuperIOState {
    ISASuperIODevice superio;
    uint8_t regs[0x100];
    const MemoryRegionOps *io_ops;
    MemoryRegion io;
    MemoryRegion *serial_io[SUPERIO_MAX_SERIAL_PORTS];
};

[...]

static void via_superio_realize(DeviceState *d, Error **errp)

{
    ViaSuperIOState *s = VIA_SUPERIO(d);
    ISASuperIOClass *ic = ISA_SUPERIO_GET_CLASS(s);
    Error *local_err = NULL;
    int i;

    assert(s->io_ops);
    ic->parent_realize(d, &local_err);
    if (local_err) {
        error_propagate(errp, local_err);
        return;
    }
    /* Grab io regions of serial devices so we can control them */
    for (i = 0; i < ic->serial.count; i++) {
        ISADevice *sd = s->superio.serial[i];
        MemoryRegion *io = isa_address_space_io(sd);
        MemoryRegion *mr = find_subregion(sd, io, sd->ioport_id);
        if (!mr) {
            error_setg(errp, "Could not get io region for serial %d", i);
            return;
        }
        s->serial_io[i] = mr;
    }

    memory_region_init_io(&s->io, OBJECT(d), s->io_ops, s, "via-superio", 2);
    memory_region_set_enabled(&s->io, false);
    /* The floppy also uses 0x3f0 and 0x3f1 but this seems to work anyway */
    memory_region_add_subregion(isa_address_space_io(ISA_DEVICE(s)), 0x3f0,
                                &s->io);
}

In realize we grab pointers to the MemoryRegions of the isa-serial devices created by the ISA superio class. This is ISA superio:

https://github.com/patchew-project/qemu/blob/ca5d88d2fee0016f939e91ae8b32c18e682064fa/include/hw/isa/superio.h#L23

#define SUPERIO_MAX_SERIAL_PORTS 4

struct ISASuperIODevice {
    /*< private >*/
    ISADevice parent_obj;
    /*< public >*/

    ISADevice *parallel[MAX_PARALLEL_PORTS];
    ISADevice *serial[SUPERIO_MAX_SERIAL_PORTS];
    ISADevice *floppy;
    ISADevice *kbc;
    ISADevice *ide;
};

The serial members we access are even public so this should be OK (other models to that too) but we need to get their MemoryRegion as we need to configure that based on VIA superio registers. ISADevice is defined in:

https://github.com/patchew-project/qemu/blob/patchew/cover.1615345138.git.balaton%40eik.bme.hu/include/hw/isa/isa.h

but it does not store a reference to its memory regions:

struct ISADevice {
    /*< private >*/
    DeviceState parent_obj;
    /*< public >*/

    int8_t isairq[2];      /* -1 = unassigned */
    int nirqs;
    int ioport_id;
};

only an ioport_id which is the address of its first io region so we have to get the actual MemoryRegion based on that. This works for isa-serial that has a single mem region but would not for parallel or FDC that have multiple regions. Those are created with isa_register_portio_list() I think but we don't care about parallel and FDC only about serial.

This may be possible to clean up but that would need changes to ISA emulation that I don't want to change so the patch tries to achieve what's needed without changing how ISA devices are emulated currently. I think the solution proposed in patch 1 is relatively clean and by not changing anything than vt82c686 it avoids any possible breakage to other machines using ISA devices so unless there's a reason not to accept it this should solve the problem and allow pegasos2 firmware to boot.

Regards,
BALATON Zoltan

#31 lore raw
In reply to Laurent Vivier
Quoted 27 lines · Laurent Vivier

Le 15/03/2021 à 13:33, BALATON Zoltan a écrit :

Quoted 26 lines · BALATON Zoltan
Quoted 9 lines · BALATON Zoltan
Quoted 1 line

Hello,

I've started posting this series well in advance to get it into 6.0 and yet it seems like it may be missing it due to organisational issues (no real complaints were found with patches but Philippe seems to like more review that does not seem to happen as nobody is interested). Looks like David is waiting for an ack from Philippe but will be away next week so if this is not resolved now it may be too late on Monday. To avoid that:

Quoted 8 lines

David, could you please send an ack before you leave for the last two patches so it could get committed via some other tree while you're away?

Philippe, if you can't ack the vt82c686 patches now are you OK with taking the whole series via your tree before the freeze? That would give you some more days to review and it could always be reverted during the freeze but if it's not merged now I'll have to wait until the summer to get it in again which would be another long delay. I don't think this will get more reviews unless it's in master and people can start using and testing it better.

Hello,

Since David seems to be away for this week before seeing my mail asking for an ack from him, now this can only get in by Philippe or Peter. (David said before he'd be OK with the series if Philippe acked it so I think that can count as an implicit ack and it could always be reverted before the releease.)

Quoted 7 lines
Quoted 5 lines

Philippe, do you have anything against this to get merged now? If not please send a pull or ack it so it has a chance to be in 6.0 or tell if you still intend to do anything about it before the freeze. This series was on the list since January and the remaining parts you did not take are here since February 22nd and the version after your first review since two weeks so it would be nice to sort this out and not block it any further without a good reason.

Pegasos looks like a New World PowerMac, so perhaps Mark can help?

The pegasos2 is more like a MIPS machine or a PC with a PPC than a PowerMac at the hardware level even if it implements similar specs like PowerMacs so not sure how much knowledge about Macs would help here. Besides we had a disagreement with Mark about what level of perfectness is needed for new QEMU devices so he stayed away from these. That said if anyone has a comment feel free to share, it probably has missed 6.0 now anyway. But I'll try to do everything needed to squeeze it in if that's still possible.

Regards,
BALATON Zoltan