Skip to contentSkip to conversation

Add emulation of AmigaOne XE board

PATCH Superseded BALATON Zoltan 4 participants 9 messages Oct 14, 2023 – Oct 24, 2023 Arm/Amlogic Meson SoC support

v3 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v3 cover Add emulation of AmigaOne XE board

Changes in v3:
- Update values, comment and commit message in patch 1 again

Changes in v2:
- Update comment and commit message in patch 1 (Mark)
- Fix irq mapping in patch 2 (Volker)

Regards,
BALATON Zoltan

BALATON Zoltan (3):
via-ide: Fix legacy mode emulation hw/pci-host: Add emulation of Mai Logic Articia S hw/ppc: Add emulation of AmigaOne XE board

 MAINTAINERS                             |   8 +
 configs/devices/ppc-softmmu/default.mak |   1 +
 hw/ide/via.c                            |  41 +++-
 hw/pci-host/Kconfig                     |   5 +
 hw/pci-host/articia.c                   | 293 ++++++++++++++++++++++++
 hw/pci-host/meson.build                 |   2 +
 hw/ppc/Kconfig                          |   7 +
 hw/ppc/amigaone.c                       | 164 +++++++++++++
 hw/ppc/meson.build                      |   2 +
 include/hw/pci-host/articia.h           |  17 ++
 10 files changed, 535 insertions(+), 5 deletions(-)
 create mode 100644 hw/pci-host/articia.c
 create mode 100644 hw/ppc/amigaone.c
 create mode 100644 include/hw/pci-host/articia.h
Signature · 1 line
2.30.9
#1 lore raw

PATCH v3 1/3 via-ide: Fix legacy mode emulation

The initial value for BARs were set in reset method for emulating legacy mode at start but this does not work because PCI code resets BARs after calling device reset method. Remove this ineffective default to avoid confusion.

Instead move setting the BARs to a callback on writing the PCI config regsiter that sets legacy mode (which firmwares needing this mode seem to do). This does not fully emulate what the data sheet says (which is not very clear on this) but it implements enough to allow both modes as used by firmwares and guests on machines we emulate.

---
 hw/ide/via.c | 41 ++++++++++++++++++++++++++++++++++++-----
 1 file changed, 36 insertions(+), 5 deletions(-)
hw/ide/via.c +36 -5
index fff23803a6..ca9a3b8f49 100644
@@ -132,11 +132,6 @@ static void via_ide_reset(DeviceState *dev)
     pci_set_word(pci_conf + PCI_STATUS, PCI_STATUS_FAST_BACK |
                  PCI_STATUS_DEVSEL_MEDIUM);
 
-    pci_set_long(pci_conf + PCI_BASE_ADDRESS_0, 0x000001f0);
-    pci_set_long(pci_conf + PCI_BASE_ADDRESS_1, 0x000003f4);
-    pci_set_long(pci_conf + PCI_BASE_ADDRESS_2, 0x00000170);
-    pci_set_long(pci_conf + PCI_BASE_ADDRESS_3, 0x00000374);
-    pci_set_long(pci_conf + PCI_BASE_ADDRESS_4, 0x0000cc01); /* BMIBA: 20-23h */
     pci_set_long(pci_conf + PCI_INTERRUPT_LINE, 0x0000010e);
 
     /* IDE chip enable, IDE configuration 1/2, IDE FIFO Configuration*/
@@ -159,6 +154,41 @@ static void via_ide_reset(DeviceState *dev)
     pci_set_long(pci_conf + 0xc0, 0x00020001);
 }
 
+static void via_ide_cfg_write(PCIDevice *pd, uint32_t addr,
+                              uint32_t val, int len)
+{
+    pci_default_write_config(pd, addr, val, len);
+    /*
+     * Bits 0 and 2 of the PCI programming interface register are documented to
+     * select between legacy and native mode for the two IDE channels. when the
+     * guest selects legacy mode we reset the PCI BARs to legacy ports which is
+     * their default value. We don't care about setting each channel separately
+     * as no guest is known to do or need that. Also only do this when BARs are
+     * unset when writing this register as logs from real hardware show that
+     * setting legacy mode after BARs were set will still use ports set by BARs
+     * not ISA ports (e.g. pegasos2 Linux does this after firmware set native
+     * mode and programmed BARs). But if 0x8a is written righr after reset
+     * without setting BARs then we want legacy ports (this is done by the
+     * AmigaOne firmware). We can't set these in via_ide_reset() because PCI
+     * code clears BARs after calling device reset method.
+     */
+    if (addr == PCI_CLASS_PROG && val == 0x8a &&
+        pci_get_long(pd->config + PCI_BASE_ADDRESS_0) ==
+        PCI_BASE_ADDRESS_SPACE_IO) {
+        pci_set_long(pd->config + PCI_BASE_ADDRESS_0, 0x1f0
+                     | PCI_BASE_ADDRESS_SPACE_IO);
+        pci_set_long(pd->config + PCI_BASE_ADDRESS_1, 0x3f4
+                     | PCI_BASE_ADDRESS_SPACE_IO);
+        pci_set_long(pd->config + PCI_BASE_ADDRESS_2, 0x170
+                     | PCI_BASE_ADDRESS_SPACE_IO);
+        pci_set_long(pd->config + PCI_BASE_ADDRESS_3, 0x374
+                     | PCI_BASE_ADDRESS_SPACE_IO);
+        /* BMIBA: 20-23h */
+        pci_set_long(pd->config + PCI_BASE_ADDRESS_4, 0xcc00
+                     | PCI_BASE_ADDRESS_SPACE_IO);
+    }
+}
+
 static void via_ide_realize(PCIDevice *dev, Error **errp)
 {
     PCIIDEState *d = PCI_IDE(dev);
@@ -221,6 +251,7 @@ static void via_ide_class_init(ObjectClass *klass, void *data)
     /* Reason: only works as function of VIA southbridge */
     dc->user_creatable = false;
 
+    k->config_write = via_ide_cfg_write;
     k->realize = via_ide_realize;
     k->exit = via_ide_exitfn;
     k->vendor_id = PCI_VENDOR_ID_VIA;
Signature · 1 line
2.30.9
#3 lore raw

PATCH v3 2/3 hw/pci-host: Add emulation of Mai Logic Articia S

In reply to BALATON Zoltan

The Articia S is a generic chipset supporting several different CPUs that were among others used on some PPC boards. This is a minimal emulation of the parts needed for emulating the AmigaOne board.

---
 hw/pci-host/Kconfig           |   5 +
 hw/pci-host/articia.c         | 293 ++++++++++++++++++++++++++++++++++
 hw/pci-host/meson.build       |   2 +
 include/hw/pci-host/articia.h |  17 ++
 4 files changed, 317 insertions(+)
 create mode 100644 hw/pci-host/articia.c
 create mode 100644 include/hw/pci-host/articia.h
hw/pci-host/Kconfig +5 -0
index a07070eddf..33014c80a4 100644
@@ -73,6 +73,11 @@ config SH_PCI
     bool
     select PCI
 
+config ARTICIA
+    bool
+    select PCI
+    select I8259
+
 config MV64361
     bool
     select PCI
hw/pci-host/articia.c new file +293 -0

293 lines not on this page · raw message

hw/pci-host/meson.build +2 -0
index 64eada76fe..40de48eb7f 100644
@@ -20,6 +20,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'))
+# AmigaOne
+pci_ss.add(when: 'CONFIG_ARTICIA', if_true: files('articia.c'))
 # Pegasos2
 pci_ss.add(when: 'CONFIG_MV64361', if_true: files('mv64361.c'))
 
include/hw/pci-host/articia.h new file +17 -0
new file mode 100644
index 0000000000..529c240274
@@ -0,0 +1,17 @@
+/*
+ * Mai Logic Articia S emulation
+ *
+ * Copyright (c) 2023 BALATON Zoltan
+ *
+ * This work is licensed under the GNU GPL license version 2 or later.
+ *
+ */
+
+#ifndef ARTICIA_H
+#define ARTICIA_H
+
+#define TYPE_ARTICIA "articia"
+#define TYPE_ARTICIA_PCI_HOST "articia-pci-host"
+#define TYPE_ARTICIA_PCI_BRIDGE "articia-pci-bridge"
+
+#endif
Signature · 1 line
2.30.9
#4 lore raw

PATCH v3 3/3 hw/ppc: Add emulation of AmigaOne XE board

In reply to BALATON Zoltan

The AmigaOne is a rebranded MAI Teron board that uses U-Boot firmware with patches to support AmigaOS and is very similar to pegasos2 so can be easily emulated sharing most code with pegasos2. The reason to emulate it is that AmigaOS comes in different versions for AmigaOne and PegasosII which only have drivers for one machine and firmware so these only run on the specific machine. Adding this board allows another AmigaOS version to be used reusing already existing peagasos2 emulation. (The AmigaOne was the first of these boards so likely most widespread which then inspired Pegasos that was later replaced with PegasosII due to problems with Articia S, so these have a lot of similarity. Pegasos mainly ran MorphOS while the PegasosII version of AmigaOS was added later and therefore less common than the AmigaOne version.)

---
 MAINTAINERS                             |   8 ++
 configs/devices/ppc-softmmu/default.mak |   1 +
 hw/ppc/Kconfig                          |   7 +
 hw/ppc/amigaone.c                       | 164 ++++++++++++++++++++++++
 hw/ppc/meson.build                      |   2 +
 5 files changed, 182 insertions(+)
 create mode 100644 hw/ppc/amigaone.c
MAINTAINERS +8 -0
index ceea4c2bf2..ca405bc1bc 100644
@@ -1510,6 +1510,14 @@ F: hw/pci-host/mv64361.c
 F: hw/pci-host/mv643xx.h
 F: include/hw/pci-host/mv64361.h
 
+amigaone
+M: BALATON Zoltan <[email protected]>
+L: [email protected]
+S: Maintained
+F: hw/ppc/amigaone.c
+F: hw/pci-host/articia.c
+F: include/hw/pci-host/articia.h
+
 Virtual Open Firmware (VOF)
 M: Alexey Kardashevskiy <[email protected]>
 R: David Gibson <[email protected]>
configs/devices/ppc-softmmu/default.mak +1 -0
index a887f5438b..b85fd2bcd7 100644
@@ -14,6 +14,7 @@ CONFIG_SAM460EX=y
 CONFIG_MAC_OLDWORLD=y
 CONFIG_MAC_NEWWORLD=y
 
+CONFIG_AMIGAONE=y
 CONFIG_PEGASOS2=y
 
 # For PReP
hw/ppc/Kconfig +7 -0
index 5dfbf47ef5..56f0475a8e 100644
@@ -69,6 +69,13 @@ config SAM460EX
     select USB_OHCI
     select FDT_PPC
 
+config AMIGAONE
+    bool
+    imply ATI_VGA
+    select ARTICIA
+    select VT82C686
+    select SMBUS_EEPROM
+
 config PEGASOS2
     bool
     imply ATI_VGA
hw/ppc/amigaone.c new file +164 -0

164 lines not on this page · raw message

hw/ppc/meson.build +2 -0
index 7c2c52434a..0f76f4cce4 100644
@@ -81,6 +81,8 @@ 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'))
+# a1xe
+ppc_ss.add(when: 'CONFIG_AMIGAONE', if_true: files('amigaone.c'))
 # Pegasos2
 ppc_ss.add(when: 'CONFIG_PEGASOS2', if_true: files('pegasos2.c'))
 
Signature · 1 line
2.30.9
#2 lore raw

Re: [PATCH v3 1/3] via-ide: Fix legacy mode emulation

In reply to BALATON Zoltan
Quoted 75 lines · BALATON Zoltan

The initial value for BARs were set in reset method for emulating legacy mode at start but this does not work because PCI code resets BARs after calling device reset method. Remove this ineffective default to avoid confusion.

Instead move setting the BARs to a callback on writing the PCI config regsiter that sets legacy mode (which firmwares needing this mode seem to do). This does not fully emulate what the data sheet says (which is not very clear on this) but it implements enough to allow both modes as used by firmwares and guests on machines we emulate.

---
  hw/ide/via.c | 41 ++++++++++++++++++++++++++++++++++++-----
  1 file changed, 36 insertions(+), 5 deletions(-)
hw/ide/via.c +35 -5
index fff23803a6..ca9a3b8f49 100644
@@ -132,11 +132,6 @@ static void via_ide_reset(DeviceState *dev)
      pci_set_word(pci_conf + PCI_STATUS, PCI_STATUS_FAST_BACK |
                   PCI_STATUS_DEVSEL_MEDIUM);
 
-    pci_set_long(pci_conf + PCI_BASE_ADDRESS_0, 0x000001f0);
-    pci_set_long(pci_conf + PCI_BASE_ADDRESS_1, 0x000003f4);
-    pci_set_long(pci_conf + PCI_BASE_ADDRESS_2, 0x00000170);
-    pci_set_long(pci_conf + PCI_BASE_ADDRESS_3, 0x00000374);
-    pci_set_long(pci_conf + PCI_BASE_ADDRESS_4, 0x0000cc01); /* BMIBA: 20-23h */
      pci_set_long(pci_conf + PCI_INTERRUPT_LINE, 0x0000010e);
 
      /* IDE chip enable, IDE configuration 1/2, IDE FIFO Configuration*/
@@ -159,6 +154,41 @@ static void via_ide_reset(DeviceState *dev)
      pci_set_long(pci_conf + 0xc0, 0x00020001);
  }
 
+static void via_ide_cfg_write(PCIDevice *pd, uint32_t addr,
+                              uint32_t val, int len)
+{
+    pci_default_write_config(pd, addr, val, len);
+    /*
+     * Bits 0 and 2 of the PCI programming interface register are documented to
+     * select between legacy and native mode for the two IDE channels. when the
+     * guest selects legacy mode we reset the PCI BARs to legacy ports which is
+     * their default value. We don't care about setting each channel separately
+     * as no guest is known to do or need that. Also only do this when BARs are
+     * unset when writing this register as logs from real hardware show that
+     * setting legacy mode after BARs were set will still use ports set by BARs
+     * not ISA ports (e.g. pegasos2 Linux does this after firmware set native
+     * mode and programmed BARs). But if 0x8a is written righr after reset
+     * without setting BARs then we want legacy ports (this is done by the
+     * AmigaOne firmware). We can't set these in via_ide_reset() because PCI
+     * code clears BARs after calling device reset method.
+     */
+    if (addr == PCI_CLASS_PROG && val == 0x8a &&
+        pci_get_long(pd->config + PCI_BASE_ADDRESS_0) ==
+        PCI_BASE_ADDRESS_SPACE_IO) {
+        pci_set_long(pd->config + PCI_BASE_ADDRESS_0, 0x1f0
+                     | PCI_BASE_ADDRESS_SPACE_IO);
+        pci_set_long(pd->config + PCI_BASE_ADDRESS_1, 0x3f4
+                     | PCI_BASE_ADDRESS_SPACE_IO);
+        pci_set_long(pd->config + PCI_BASE_ADDRESS_2, 0x170
+                     | PCI_BASE_ADDRESS_SPACE_IO);
+        pci_set_long(pd->config + PCI_BASE_ADDRESS_3, 0x374
+                     | PCI_BASE_ADDRESS_SPACE_IO);
+        /* BMIBA: 20-23h */
+        pci_set_long(pd->config + PCI_BASE_ADDRESS_4, 0xcc00
+                     | PCI_BASE_ADDRESS_SPACE_IO);
+    }
+}
+
  static void via_ide_realize(PCIDevice *dev, Error **errp)
  {
      PCIIDEState *d = PCI_IDE(dev);

hw/ide/via.c static void via_ide_class_init(ObjectClass *klass, void *data) · line 257

Quoted 7 lines
hw/ide/via.c +1 -0
@@ -221,6 +251,7 @@ static void via_ide_class_init(ObjectClass *klass, void *data)
      /* Reason: only works as function of VIA southbridge */
      dc->user_creatable = false;
 
+    k->config_write = via_ide_cfg_write;
      k->realize = via_ide_realize;
      k->exit = via_ide_exitfn;
      k->vendor_id = PCI_VENDOR_ID_VIA;

Just posting the references to the v2 thread with the portio_list*() PoC explaining how this better models real hardware and how it forms the basis of future improvements so it can be found against v3 in Patchew:

https://lists.gnu.org/archive/html/qemu-devel/2023-10/msg04448.html
https://lists.gnu.org/archive/html/qemu-devel/2023-10/msg04449.html

ATB,

Mark.

#5 lore raw
In reply to BALATON Zoltan
Quoted 7 lines · BALATON Zoltan

Changes in v3:
- Update values, comment and commit message in patch 1 again

Changes in v2:
- Update comment and commit message in patch 1 (Mark)
- Fix irq mapping in patch 2 (Volker)

Quoted 7 lines

Regards,
BALATON Zoltan

BALATON Zoltan (3):
via-ide: Fix legacy mode emulation hw/pci-host: Add emulation of Mai Logic Articia S hw/ppc: Add emulation of AmigaOne XE board

Nick, Daniel, Cédric,

Patch 1 is not related to PPC and is still debated but just to make sure we don't get too close to freeze again I ask about patch 2 and 3 in the maintime. Not sure who will merge this series at the end but if you can give an Acked-by for the last two patches maybe Philippe can take care of the series or is any of you plan to take it via ppc?

Regards,
BALATON Zoltan

Quoted 16 lines
MAINTAINERS                             |   8 +
configs/devices/ppc-softmmu/default.mak |   1 +
hw/ide/via.c                            |  41 +++-
hw/pci-host/Kconfig                     |   5 +
hw/pci-host/articia.c                   | 293 ++++++++++++++++++++++++
hw/pci-host/meson.build                 |   2 +
hw/ppc/Kconfig                          |   7 +
hw/ppc/amigaone.c                       | 164 +++++++++++++
hw/ppc/meson.build                      |   2 +
include/hw/pci-host/articia.h           |  17 ++
10 files changed, 535 insertions(+), 5 deletions(-)

create mode 100644 hw/pci-host/articia.c create mode 100644 hw/ppc/amigaone.c
create mode 100644 include/hw/pci-host/articia.h

#6 lore raw
Quoted 16 lines · BALATON Zoltan
Quoted 7 lines · BALATON Zoltan

Changes in v3:
- Update values, comment and commit message in patch 1 again

Changes in v2:
- Update comment and commit message in patch 1 (Mark)
- Fix irq mapping in patch 2 (Volker)

Quoted 7 lines

Regards,
BALATON Zoltan

BALATON Zoltan (3):
via-ide: Fix legacy mode emulation hw/pci-host: Add emulation of Mai Logic Articia S hw/ppc: Add emulation of AmigaOne XE board

Quoted 7 lines

Nick, Daniel, Cédric,

Patch 1 is not related to PPC and is still debated but just to make sure we don't get too close to freeze again I ask about patch 2 and 3 in the maintime. Not sure who will merge this series at the end but if you can give an Acked-by for the last two patches maybe Philippe can take care of the series or is any of you plan to take it via ppc?

Hey,

I could take patch 2/3 via ppc tree, although I don't know much about platform and pci so some review/ack would be good.

I guess you could submit the Amiga stuff yourself too if you wanted, you have much better understanding of it and I don't really know how to test either (other than a few of the free to download installer images for one or two of those OSes).

Thanks,
Nick

Quoted 20 lines

Regards,
BALATON Zoltan

Quoted 16 lines
MAINTAINERS                             |   8 +
configs/devices/ppc-softmmu/default.mak |   1 +
hw/ide/via.c                            |  41 +++-
hw/pci-host/Kconfig                     |   5 +
hw/pci-host/articia.c                   | 293 ++++++++++++++++++++++++
hw/pci-host/meson.build                 |   2 +
hw/ppc/Kconfig                          |   7 +
hw/ppc/amigaone.c                       | 164 +++++++++++++
hw/ppc/meson.build                      |   2 +
include/hw/pci-host/articia.h           |  17 ++
10 files changed, 535 insertions(+), 5 deletions(-)

create mode 100644 hw/pci-host/articia.c create mode 100644 hw/ppc/amigaone.c
create mode 100644 include/hw/pci-host/articia.h

#8 lore raw
In reply to BALATON Zoltan
Quoted 11 lines · BALATON Zoltan
Quoted 10 lines · BALATON Zoltan

Changes in v3:
- Update values, comment and commit message in patch 1 again

Changes in v2:
- Update comment and commit message in patch 1 (Mark)
- Fix irq mapping in patch 2 (Volker)

Regards,
BALATON Zoltan

Quoted 8 lines
Quoted 4 lines

BALATON Zoltan (3):
 via-ide: Fix legacy mode emulation hw/pci-host: Add emulation of Mai Logic Articia S hw/ppc: Add emulation of AmigaOne XE board

Nick, Daniel, Cédric,

Patch 1 is not related to PPC and is still debated but just to make sure we don't get too close to freeze again I ask about patch 2 and 3 in the maintime. Not sure who will merge this series at the end but if you can give an Acked-by for the last two patches maybe Philippe can take care of the series or is any of you plan to take it via ppc?

ppc should be in Nick's hands now, Daniel and I as backups.

What would help is to propose avocado tests for the machines you maintain. Avocado can do many things, like downloading a .zip to extract a kernel.

Thanks,

C.

#7 lore raw
In reply to Nicholas Piggin
Quoted 27 lines · Nicholas Piggin
Quoted 16 lines · BALATON Zoltan
Quoted 7 lines · BALATON Zoltan

Changes in v3:
- Update values, comment and commit message in patch 1 again

Changes in v2:
- Update comment and commit message in patch 1 (Mark)
- Fix irq mapping in patch 2 (Volker)

Quoted 7 lines

Regards,
BALATON Zoltan

BALATON Zoltan (3):
via-ide: Fix legacy mode emulation hw/pci-host: Add emulation of Mai Logic Articia S hw/ppc: Add emulation of AmigaOne XE board

Quoted 7 lines

Nick, Daniel, Cédric,

Patch 1 is not related to PPC and is still debated but just to make sure we don't get too close to freeze again I ask about patch 2 and 3 in the maintime. Not sure who will merge this series at the end but if you can give an Acked-by for the last two patches maybe Philippe can take care of the series or is any of you plan to take it via ppc?

Hey,

Quoted 7 lines

I could take patch 2/3 via ppc tree, although I don't know much about platform and pci so some review/ack would be good.

I guess you could submit the Amiga stuff yourself too if you wanted, you have much better understanding of it and I don't really know how to test either (other than a few of the free to download installer images for one or two of those OSes).

I can't send pull requests, don't have a signing key and never did that. So far it worked by submitting patches and the ppc maintainer merging them so I'd stay with that work flow. I'm listed as maintainer so if there's some problem with these machines I'll look to fix them and I try to make sure these work so you'd only need to do usual integration testing before pull and don't have to take responsibility for these machines otherwise.

Currently Mark wanted an alternative approach instead of patch 1 which was tested so just waiting for him to finalise that then remaining patch 2-4 from latest version of this series (v5) should apply but I can resubmit that as v6 with a Based-on: tag if that helps.

I don't know who will metge Mark's series, Philippe seems to have some IDE patches queued so maybe he can take that too then might as well take this series if you give an Acked-by for it.

Regards,
BALATON Zoltan