Skip to contentSkip to conversation

Add i.MX 8M Plus EVK machine

PATCH Superseded Bernhard Beschow 3 participants 50 messages Feb 4, 2025 – Feb 23, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover Add i.MX 8M Plus EVK machine

This series adds a new aarch64 machine to QEMU: i.MX 8M Plus EVK [1]. It allows for running Linux distributions such as Buildroot (freescale_imx8mpevk_defconfig) and Arch Linux [2] via direct kernel boot. U-Boot does not work yet. I plan to use this machine myself and I also want to make it available to a bigger audience, so I propose to add it to QEMU. My goal would be to have it added for 10.0.

The series is structured as follows: The first three patches fix some issues in device models reused by the new machine. Patches 4-17 add the machine step by step which includes documentation. The last patch adds an I²C RTC which I'd like to use along with the new machine.

I've based some code on existing one (see "Based on" in file headers) and I'm unsure how to handle the licensing and attribution correctly -- advice welcome.

v2:
* Rebase onto master, eliminating some patches from the series
* Initialize ROM with memory_region_init_rom() (Zoltan)
* Mark the machine as "Maintained" (Peter)
* Do not select TEST_DEVICES (Peter)
* Have separate sources for the two clock tree modules (Peter)
* Make PCI devices attach to the correct bus (Peter)
* Avoid adding documentation that is removed later (Zoltan) Instead, document Buildroot process in the first place and change it slightly.
* Drop TCA6416 device model (Phil, Dmitrii)
* Add pca955* Kconfig cleanup patch

[1] https://www.nxp.com/design/design-center/development-boards-and-designs/8MPLUSLPD4-EVK
[2] https://archlinuxarm.org/platforms/armv8/generic

Bernhard Beschow (18):
hw/usb/hcd-dwc3: Align global registers size with Linux hw/pci-host/designware: Prevent device attachment on internal PCIe
root bus
hw/gpio/pca955*: Move Kconfig switches next to implementations hw/arm: Add i.MX 8M Plus EVK board
hw/arm/fsl-imx8mp: Implement clock tree hw/arm/fsl-imx8mp: Add SNVS
hw/arm/fsl-imx8mp: Add USDHC storage controllers hw/arm/fsl-imx8mp: Add PCIe support
hw/arm/fsl-imx8mp: Add GPIO controllers hw/arm/fsl-imx8mp: Add I2C controllers hw/arm/fsl-imx8mp: Add SPI controllers hw/arm/fsl-imx8mp: Add watchdog support hw/arm/fsl-imx8mp: Implement gneral purpose timers hw/arm/fsl-imx8mp: Add Ethernet controller hw/arm/fsl-imx8mp: Add USB support
hw/arm/fsl-imx8mp: Add boot ROM
hw/arm/fsl-imx8mp: Add on-chip RAM
hw/rtc: Add Ricoh RS5C372 RTC emulation

 MAINTAINERS                         |  15 +
 docs/system/arm/imx8mp-evk.rst      |  72 +++
 docs/system/target-arm.rst          |   1 +
 include/hw/arm/fsl-imx8mp.h         | 285 +++++++++++
 include/hw/misc/imx8mp_analog.h     |  81 +++
 include/hw/misc/imx8mp_ccm.h        |  30 ++
 include/hw/pci-host/designware.h    |   7 +
 include/hw/pci-host/fsl_imx8m_phy.h |  27 +
 include/hw/timer/imx_gpt.h          |   1 +
 include/hw/usb/hcd-dwc3.h           |   2 +-
 hw/arm/fsl-imx8mp.c                 | 736 ++++++++++++++++++++++++++++
 hw/arm/imx8mp-evk.c                 |  74 +++
 hw/misc/imx8mp_analog.c             | 160 ++++++
 hw/misc/imx8mp_ccm.c                | 175 +++++++
 hw/pci-host/designware.c            |  18 +-
 hw/pci-host/fsl_imx8m_phy.c         |  88 ++++
 hw/rtc/rs5c372.c                    | 227 +++++++++
 hw/timer/imx_gpt.c                  |  25 +
 hw/usb/hcd-dwc3.c                   |   5 +
 hw/arm/Kconfig                      |  24 +
 hw/arm/meson.build                  |   2 +
 hw/gpio/Kconfig                     |  10 +
 hw/misc/Kconfig                     |  14 +-
 hw/misc/meson.build                 |   2 +
 hw/pci-host/Kconfig                 |   3 +
 hw/pci-host/meson.build             |   1 +
 hw/rtc/Kconfig                      |   5 +
 hw/rtc/meson.build                  |   1 +
 hw/rtc/trace-events                 |   4 +
 pc-bios/imx8mp-boot.rom             | Bin 0 -> 258048 bytes
 pc-bios/meson.build                 |   1 +
 31 files changed, 2086 insertions(+), 10 deletions(-)
 create mode 100644 docs/system/arm/imx8mp-evk.rst
 create mode 100644 include/hw/arm/fsl-imx8mp.h
 create mode 100644 include/hw/misc/imx8mp_analog.h
 create mode 100644 include/hw/misc/imx8mp_ccm.h
 create mode 100644 include/hw/pci-host/fsl_imx8m_phy.h
 create mode 100644 hw/arm/fsl-imx8mp.c
 create mode 100644 hw/arm/imx8mp-evk.c
 create mode 100644 hw/misc/imx8mp_analog.c
 create mode 100644 hw/misc/imx8mp_ccm.c
 create mode 100644 hw/pci-host/fsl_imx8m_phy.c
 create mode 100644 hw/rtc/rs5c372.c
 create mode 100644 pc-bios/imx8mp-boot.rom
Signature · 1 line
2.48.1
#1 lore raw

PATCH v2 1/18 hw/usb/hcd-dwc3: Align global registers size with Linux

While at it add missing GUSB2RHBCTL register as found in i.MX 8M Plus reference manual.

---
 include/hw/usb/hcd-dwc3.h | 2 +-
 hw/usb/hcd-dwc3.c         | 5 +++++
 2 files changed, 6 insertions(+), 1 deletion(-)
include/hw/usb/hcd-dwc3.h +1 -1
index f752a27e94..dbdf12b21d 100644
@@ -35,7 +35,7 @@
 #define USB_DWC3(obj) \
      OBJECT_CHECK(USBDWC3, (obj), TYPE_USB_DWC3)
 
-#define USB_DWC3_R_MAX ((0x530 / 4) + 1)
+#define USB_DWC3_R_MAX (0x600 / 4)
 #define DWC3_SIZE 0x10000
 
 typedef struct USBDWC3 {
hw/usb/hcd-dwc3.c +5 -0
index 9ce9ba0b04..0bceee2712 100644
@@ -343,6 +343,8 @@ REG32(GFLADJ, 0x530)
     FIELD(GFLADJ, GFLADJ_REFCLK_FLADJ, 8, 14)
     FIELD(GFLADJ, GFLADJ_30MHZ_SDBND_SEL, 7, 1)
     FIELD(GFLADJ, GFLADJ_30MHZ, 0, 6)
+REG32(GUSB2RHBCTL, 0x540)
+    FIELD(GUSB2RHBCTL, OVRD_L1TIMEOUT, 0, 4)
 
 #define DWC3_GLOBAL_OFFSET 0xC100
 static void reset_csr(USBDWC3 * s)
@@ -560,6 +562,9 @@ static const RegisterAccessInfo usb_dwc3_regs_info[] = {
         .rsvd = 0x40,
         .ro = 0x400040,
         .unimp = 0xffffffff,
+    },{ .name = "GUSB2RHBCTL",  .addr = A_GUSB2RHBCTL,
+        .rsvd = 0xfffffff0,
+        .unimp = 0xffffffff,
     }
 };
 
Signature · 1 line
2.48.1
#2 lore raw

PATCH v2 2/18 hw/pci-host/designware: Prevent device attachment on internal PCIe root bus

In reply to Bernhard Beschow

On the real device, the PCIe root bus is only connected to a PCIe bridge and does not allow for direct attachment of devices. Doing so in QEMU results in no PCI devices being detected by Linux. Instead, PCI devices should plug into the secondary PCIe bus spawned by the internal PCIe bridge.

Unfortunately, QEMU defaults to plugging devices into the PCIe root bus. To work around this, every PCI device created on the command line needs an extra bus=dw-pcie option which is error prone. Fix that by marking the PCIe root bus as full which makes QEMU decend into the child PCIe bus.

---
 include/hw/pci-host/designware.h |  7 +++++++
 hw/pci-host/designware.c         | 18 +++++++++++++++++-
 2 files changed, 24 insertions(+), 1 deletion(-)
include/hw/pci-host/designware.h +7 -0
index bf8b278978..a35a3bd06c 100644
@@ -25,12 +25,19 @@
 #include "hw/pci/pci_bridge.h"
 #include "qom/object.h"
 
+#define TYPE_DESIGNWARE_PCIE_ROOT_BUS "designware-pcie-root-BUS"
+OBJECT_DECLARE_SIMPLE_TYPE(DesignwarePCIERootBus, DESIGNWARE_PCIE_ROOT_BUS)
+
 #define TYPE_DESIGNWARE_PCIE_HOST "designware-pcie-host"
 OBJECT_DECLARE_SIMPLE_TYPE(DesignwarePCIEHost, DESIGNWARE_PCIE_HOST)
 
 #define TYPE_DESIGNWARE_PCIE_ROOT "designware-pcie-root"
 OBJECT_DECLARE_SIMPLE_TYPE(DesignwarePCIERoot, DESIGNWARE_PCIE_ROOT)
 
+struct DesignwarePCIERootBus {
+    PCIBus parent;
+};
+
 typedef struct DesignwarePCIEViewport {
     DesignwarePCIERoot *root;
 
hw/pci-host/designware.c +17 -1
index 3e8c36e6a7..c07740bfaa 100644
@@ -55,6 +55,17 @@
 #define DESIGNWARE_PCIE_ATU_DEVFN(x)               (((x) >> 16) & 0xff)
 #define DESIGNWARE_PCIE_ATU_UPPER_TARGET           0x91C
 
+static void designware_pcie_root_bus_class_init(ObjectClass *klass, void *data)
+{
+    BusClass *k = BUS_CLASS(klass);
+
+    /*
+     * Designware has only a single root complex. Enforce the limit on the
+     * parent bus
+     */
+    k->max_dev = 1;
+}
+
 static DesignwarePCIEHost *
 designware_pcie_root_to_host(DesignwarePCIERoot *root)
 {
@@ -699,7 +710,7 @@ static void designware_pcie_host_realize(DeviceState *dev, Error **errp)
                                      &s->pci.memory,
                                      &s->pci.io,
                                      0, 4,
-                                     TYPE_PCIE_BUS);
+                                     TYPE_DESIGNWARE_PCIE_ROOT_BUS);
     pci->bus->flags |= PCI_BUS_EXTENDED_CONFIG_SPACE;
 
     memory_region_init(&s->pci.address_space_root,
@@ -754,6 +765,11 @@ static void designware_pcie_host_init(Object *obj)
 
 static const TypeInfo designware_pcie_types[] = {
     {
+        .name           = TYPE_DESIGNWARE_PCIE_ROOT_BUS,
+        .parent         = TYPE_PCIE_BUS,
+        .instance_size  = sizeof(DesignwarePCIERootBus),
+        .class_init     = designware_pcie_root_bus_class_init,
+    }, {
         .name           = TYPE_DESIGNWARE_PCIE_HOST,
         .parent         = TYPE_PCI_HOST_BRIDGE,
         .instance_size  = sizeof(DesignwarePCIEHost),
Signature · 1 line
2.48.1
Reviewed-by on v2 2/18
#3 lore raw

Re: [PATCH v2 02/18] hw/pci-host/designware: Prevent device attachment on internal PCIe root bus

Quoted 49 lines · Bernhard Beschow

On the real device, the PCIe root bus is only connected to a PCIe bridge and does not allow for direct attachment of devices. Doing so in QEMU results in no PCI devices being detected by Linux. Instead, PCI devices should plug into the secondary PCIe bus spawned by the internal PCIe bridge.

Unfortunately, QEMU defaults to plugging devices into the PCIe root bus. To work around this, every PCI device created on the command line needs an extra bus=dw-pcie option which is error prone. Fix that by marking the PCIe root bus as full which makes QEMU decend into the child PCIe bus.

---
 include/hw/pci-host/designware.h |  7 +++++++
 hw/pci-host/designware.c         | 18 +++++++++++++++++-
 2 files changed, 24 insertions(+), 1 deletion(-)
include/hw/pci-host/designware.h +7 -0
index bf8b278978..a35a3bd06c 100644
@@ -25,12 +25,19 @@
 #include "hw/pci/pci_bridge.h"
 #include "qom/object.h"
 
+#define TYPE_DESIGNWARE_PCIE_ROOT_BUS "designware-pcie-root-BUS"
+OBJECT_DECLARE_SIMPLE_TYPE(DesignwarePCIERootBus, DESIGNWARE_PCIE_ROOT_BUS)
+
 #define TYPE_DESIGNWARE_PCIE_HOST "designware-pcie-host"
 OBJECT_DECLARE_SIMPLE_TYPE(DesignwarePCIEHost, DESIGNWARE_PCIE_HOST)
 
 #define TYPE_DESIGNWARE_PCIE_ROOT "designware-pcie-root"
 OBJECT_DECLARE_SIMPLE_TYPE(DesignwarePCIERoot, DESIGNWARE_PCIE_ROOT)
 
+struct DesignwarePCIERootBus {
+    PCIBus parent;
+};
+
 typedef struct DesignwarePCIEViewport {
     DesignwarePCIERoot *root;
 
hw/pci-host/designware.c +0 -0
index 3e8c36e6a7..c07740bfaa 100644
@@ -55,6 +55,17 @@
 #define DESIGNWARE_PCIE_ATU_DEVFN(x)               (((x) >> 16) & 0xff)
 #define DESIGNWARE_PCIE_ATU_UPPER_TARGET           0x91C
 

hw/pci-host/designware.c line 67

Quoted 10 lines
hw/pci-host/designware.c +10 -0
+static void designware_pcie_root_bus_class_init(ObjectClass *klass, void *data)
+{
+    BusClass *k = BUS_CLASS(klass);
+
+    /*
+     * Designware has only a single root complex. Enforce the limit on the
+     * parent bus
+     */
+    k->max_dev = 1;
+}

This seems to be what we do in at least one other PCI host controller, so

thanks
-- PMM

#4 lore raw

PATCH v2 3/18 hw/gpio/pca955*: Move Kconfig switches next to implementations

In reply to Bernhard Beschow

While at it and since they are user-creatable, build them when CONFIG_I2C_DEVICES is set.

---
 hw/gpio/Kconfig | 10 ++++++++++
 hw/misc/Kconfig |  8 --------
 2 files changed, 10 insertions(+), 8 deletions(-)
hw/gpio/Kconfig +10 -0
index c423e10f59..007048c688 100644
@@ -16,6 +16,16 @@ config SIFIVE_GPIO
 config STM32L4X5_GPIO
     bool
 
+config PCA9552
+    bool
+    depends on I2C
+    default y if I2C_DEVICES
+
+config PCA9554
+    bool
+    depends on I2C
+    default y if I2C_DEVICES
+
 config PCF8574
     bool
     depends on I2C
hw/misc/Kconfig +0 -8
index 8f9ce2f68c..4271e2f4ac 100644
@@ -30,14 +30,6 @@ config EDU
     default y if TEST_DEVICES
     depends on PCI && MSI_NONBROKEN
 
-config PCA9552
-    bool
-    depends on I2C
-
-config PCA9554
-    bool
-    depends on I2C
-
 config I2C_ECHO
     bool
     default y if TEST_DEVICES
Signature · 1 line
2.48.1
#5 lore raw

Re: [PATCH v2 03/18] hw/gpio/pca955*: Move Kconfig switches next to implementations

Quoted 3 lines · Bernhard Beschow

While at it and since they are user-creatable, build them when CONFIG_I2C_DEVICES is set.

The patch subject says this is just a rearrangement of the Kconfig stanzas with no behaviour change, but then the commit message body includes one.

If you want to build these when CONFIG_I2C_DEVICES is set, that should be its own patch that does that.

(The move of the Kconfig bits to hw/gpio is fixing a bug in 6328d8ffa6cb9d ("misc/pca955*: Move models under hw/gpio"), which moved the code but forgot to move the Kconfig sections.)

Separately, it's unclear to me how worthwhile it is to add these to CONFIG_I2C_DEVICES, because they're GPIO devices, which means there's not much you can do with them as a user:
as far as I know you can't wire the output/input GPIO lines up to anything. We have the device models mainly for boards which provide them, so that guest code that expects to see them doesn't fall over on bootup, and because the board model code does have the APIs to wire up the GPIO lines.

thanks
-- PMM

#6 lore raw

Re: [PATCH v2 03/18] hw/gpio/pca955*: Move Kconfig switches next to implementations

Am 17. Februar 2025 13:35:04 UTC schrieb Peter Maydell <[email protected]>:

Quoted 9 lines · Bernhard Beschow
Quoted 3 lines

While at it and since they are user-creatable, build them when CONFIG_I2C_DEVICES is set.

The patch subject says this is just a rearrangement of the Kconfig stanzas with no behaviour change, but then the commit message body includes one.

Quoted 6 lines

If you want to build these when CONFIG_I2C_DEVICES is set, that should be its own patch that does that.

(The move of the Kconfig bits to hw/gpio is fixing a bug in 6328d8ffa6cb9d ("misc/pca955*: Move models under hw/gpio"), which moved the code but forgot to move the Kconfig sections.)

Okay, I'll split the patch and use above commit message.

Quoted 9 lines

Separately, it's unclear to me how worthwhile it is to add these to CONFIG_I2C_DEVICES, because they're GPIO devices, which means there's not much you can do with them as a user:
as far as I know you can't wire the output/input GPIO lines up to anything. We have the device models mainly for boards which provide them, so that guest code that expects to see them doesn't fall over on bootup, and because the board model code does have the APIs to wire up the GPIO lines.

It's basically to satisfy Linux which will clog the i2c bus if such a GPIO expander is configured in the DTB but missing in the emulation (it will defer probing which will never make progress). Once it is its own patch we can decide separately how to proceed with it, e.g. dropping.

Best regards,
Bernhard

Quoted 3 lines

thanks
-- PMM

#7 lore raw

Re: [PATCH v2 03/18] hw/gpio/pca955*: Move Kconfig switches next to implementations

Quoted 32 lines · Bernhard Beschow

Am 17. Februar 2025 13:35:04 UTC schrieb Peter Maydell <[email protected]>:

Quoted 9 lines · Bernhard Beschow
Quoted 3 lines

While at it and since they are user-creatable, build them when CONFIG_I2C_DEVICES is set.

The patch subject says this is just a rearrangement of the Kconfig stanzas with no behaviour change, but then the commit message body includes one.

Quoted 6 lines

If you want to build these when CONFIG_I2C_DEVICES is set, that should be its own patch that does that.

(The move of the Kconfig bits to hw/gpio is fixing a bug in 6328d8ffa6cb9d ("misc/pca955*: Move models under hw/gpio"), which moved the code but forgot to move the Kconfig sections.)

Okay, I'll split the patch and use above commit message.

Quoted 9 lines

Separately, it's unclear to me how worthwhile it is to add these to CONFIG_I2C_DEVICES, because they're GPIO devices, which means there's not much you can do with them as a user:
as far as I know you can't wire the output/input GPIO lines up to anything. We have the device models mainly for boards which provide them, so that guest code that expects to see them doesn't fall over on bootup, and because the board model code does have the APIs to wire up the GPIO lines.

Quoted 1 line

It's basically to satisfy Linux which will clog the i2c bus if such a GPIO expander is configured in the DTB but missing in the emulation (it will defer probing which will never make progress). Once it is its own patch we can decide separately how to proceed with it, e.g. dropping.

If Linux wants to see it because it's in the dtb for the hardware it sounds like the right answer is that we should create it in the board code, which we can do without adding it to CONFIG_I2C_DEVICES, because we can make the board code's Kconfig do "select PCA9552", like the aspeed board does already.

thanks
-- PMM

#8 lore raw

Re: [PATCH v2 03/18] hw/gpio/pca955*: Move Kconfig switches next to implementations

Am 18. Februar 2025 10:33:26 UTC schrieb Peter Maydell <[email protected]>:

Quoted 33 lines · Bernhard Beschow
Quoted 32 lines

Am 17. Februar 2025 13:35:04 UTC schrieb Peter Maydell <[email protected]>:

Quoted 9 lines · Bernhard Beschow
Quoted 3 lines

While at it and since they are user-creatable, build them when CONFIG_I2C_DEVICES is set.

The patch subject says this is just a rearrangement of the Kconfig stanzas with no behaviour change, but then the commit message body includes one.

Quoted 6 lines

If you want to build these when CONFIG_I2C_DEVICES is set, that should be its own patch that does that.

(The move of the Kconfig bits to hw/gpio is fixing a bug in 6328d8ffa6cb9d ("misc/pca955*: Move models under hw/gpio"), which moved the code but forgot to move the Kconfig sections.)

Okay, I'll split the patch and use above commit message.

Quoted 9 lines

Separately, it's unclear to me how worthwhile it is to add these to CONFIG_I2C_DEVICES, because they're GPIO devices, which means there's not much you can do with them as a user:
as far as I know you can't wire the output/input GPIO lines up to anything. We have the device models mainly for boards which provide them, so that guest code that expects to see them doesn't fall over on bootup, and because the board model code does have the APIs to wire up the GPIO lines.

Quoted 8 lines
Quoted 1 line

It's basically to satisfy Linux which will clog the i2c bus if such a GPIO expander is configured in the DTB but missing in the emulation (it will defer probing which will never make progress). Once it is its own patch we can decide separately how to proceed with it, e.g. dropping.

If Linux wants to see it because it's in the dtb for the hardware it sounds like the right answer is that we should create it in the board code, which we can do without adding it to CONFIG_I2C_DEVICES, because we can make the board code's Kconfig do "select PCA9552", like the aspeed board does already.

These devices are primarily intended for modeling our custom hardware on the command line, for the purpose explained in [1]. While the real imx8mp-evk has a tca6416, I'd rather avoid creating it in board code, even if there was a model for it in QEMU. The reason is that the machine works fine without it as is, and that omitting hardcoded peripherals seems to increase the utility of the machine because it allows users to customize their machines without hardcoded peripherals getting into their way.

Since the two device models in this patch work by chance if other machines select them I'm fine with not implying CONFIG_I2C_DEVICES.

Best regards,
Bernhard

[1] https://lore.kernel.org/qemu-devel/[email protected]/

Quoted 3 lines

thanks
-- PMM

#9 lore raw

PATCH v2 4/18 hw/arm: Add i.MX 8M Plus EVK board

In reply to Bernhard Beschow

As a first step, implement the bare minimum: CPUs, RAM, interrupt controller, serial. All other devices of the A53 memory map are represented as TYPE_UNIMPLEMENTED_DEVICE, i.e. the whole memory map is provided. This allows for running Linux without it crashing due to invalid memory accesses.

---
 MAINTAINERS                    |   9 +
 docs/system/arm/imx8mp-evk.rst |  56 +++++
 docs/system/target-arm.rst     |   1 +
 include/hw/arm/fsl-imx8mp.h    | 189 +++++++++++++++++
 hw/arm/fsl-imx8mp.c            | 371 +++++++++++++++++++++++++++++++++
 hw/arm/imx8mp-evk.c            |  55 +++++
 hw/arm/Kconfig                 |  12 ++
 hw/arm/meson.build             |   2 +
 8 files changed, 695 insertions(+)
 create mode 100644 docs/system/arm/imx8mp-evk.rst
 create mode 100644 include/hw/arm/fsl-imx8mp.h
 create mode 100644 hw/arm/fsl-imx8mp.c
 create mode 100644 hw/arm/imx8mp-evk.c
MAINTAINERS +9 -0
index 0cf37fce7b..8db59114bc 100644
@@ -820,6 +820,15 @@ F: hw/pci-host/designware.c
 F: include/hw/pci-host/designware.h
 F: docs/system/arm/mcimx7d-sabre.rst
 
+MCIMX8MP-EVK / i.MX8MP
+M: Bernhard Beschow <[email protected]>
+L: [email protected]
+S: Maintained
+F: hw/arm/imx8mp-evk.c
+F: hw/arm/fsl-imx8mp.c
+F: include/hw/arm/fsl-imx8mp.h
+F: docs/system/arm/imx8mp-evk.rst
+
 MPS2 / MPS3
 M: Peter Maydell <[email protected]>
 L: [email protected]
docs/system/arm/imx8mp-evk.rst new file +56 -0

56 lines not on this page · raw message

docs/system/target-arm.rst +1 -0
index 9aaa9c414c..a43ec8f10e 100644
@@ -95,6 +95,7 @@ Board-specific documentation
    arm/imx25-pdk
    arm/mcimx6ul-evk
    arm/mcimx7d-sabre
+   arm/imx8mp-evk
    arm/orangepi
    arm/raspi
    arm/collie
include/hw/arm/fsl-imx8mp.h new file +189 -0

189 lines not on this page · raw message

hw/arm/fsl-imx8mp.c new file +371 -0

371 lines not on this page · raw message

hw/arm/imx8mp-evk.c new file +55 -0

55 lines not on this page · raw message

hw/arm/Kconfig +12 -0
index 256013ca80..e22916df57 100644
@@ -577,6 +577,18 @@ config FSL_IMX7
     select OR_IRQ
     select UNIMP
 
+config FSL_IMX8MP
+    bool
+    select ARM_GIC
+    select IMX
+    select UNIMP
+
+config FSL_IMX8MP_EVK
+    bool
+    default y
+    depends on TCG && AARCH64
+    select FSL_IMX8MP
+
 config ARM_SMMUV3
     bool
 
hw/arm/meson.build +2 -0
index 490234b3b8..79750ae7b1 100644
@@ -53,6 +53,8 @@ arm_ss.add(when: 'CONFIG_MSF2', if_true: files('msf2-soc.c'))
 arm_ss.add(when: 'CONFIG_MUSCA', if_true: files('musca.c'))
 arm_ss.add(when: 'CONFIG_ARMSSE', if_true: files('armsse.c'))
 arm_ss.add(when: 'CONFIG_FSL_IMX7', if_true: files('fsl-imx7.c', 'mcimx7d-sabre.c'))
+arm_ss.add(when: 'CONFIG_FSL_IMX8MP', if_true: files('fsl-imx8mp.c'))
+arm_ss.add(when: 'CONFIG_FSL_IMX8MP_EVK', if_true: files('imx8mp-evk.c'))
 arm_ss.add(when: 'CONFIG_ARM_SMMUV3', if_true: files('smmuv3.c'))
 arm_ss.add(when: 'CONFIG_FSL_IMX6UL', if_true: files('fsl-imx6ul.c', 'mcimx6ul-evk.c'))
 arm_ss.add(when: 'CONFIG_NRF51_SOC', if_true: files('nrf51_soc.c'))
Signature · 1 line
2.48.1
#10 lore raw

Re: [PATCH v2 04/18] hw/arm: Add i.MX 8M Plus EVK board

Quoted 14 lines · Bernhard Beschow

As a first step, implement the bare minimum: CPUs, RAM, interrupt controller, serial. All other devices of the A53 memory map are represented as TYPE_UNIMPLEMENTED_DEVICE, i.e. the whole memory map is provided. This allows for running Linux without it crashing due to invalid memory accesses.

---

docs/system/arm/imx8mp-evk.rst line 6

Quoted 6 lines
docs/system/arm/imx8mp-evk.rst new file +6 -0
@@ -0,0 +1,56 @@
+NXP i.MX 8M Plus Evaluation Kit (``imx8mp-evk``)
+================================================
+
+The QEMU i.MX 8M Plus EVK board emulation is intended to emulate a plain i.MX 8M
+Plus system on chip (SoC). All peripherals the real board has such as flash and
+I2C devices are intended to be added via configuration, e.g. command line.

Why do this? If they're on the real hardware board, we should be creating them by default in the machine model in QEMU. Command line options are for devices that are optional and pluggable by the user on the hardware.

docs/system/arm/imx8mp-evk.rst line 13

Quoted 6 lines
docs/system/arm/imx8mp-evk.rst new file +6 -0
+Supported devices
+-----------------
+
+The ``imx8mp-evk`` machine implements the following devices:
+
+ * Up to 4 Cortex-A53 Cores

"cores"

Quoted 16 lines
docs/system/arm/imx8mp-evk.rst new file +16 -0
+ * Generic Interrupt Controller (GICv3)
+ * 4 UARTs
+
+Boot options
+------------
+
+The ``imx8mp-evk`` machine can start using the standard -kernel functionality
+for loading a Linux kernel.
+
+Direct Linux Kernel Boot
+''''''''''''''''''''''''
+
+Probably the easiest way to get started with a whole Linux system on the machine
+is to generate an image with Buildroot. Version 2024.11.1 is tested at the time
+of writing and involves two steps. First run the following commands in the
+toplevel directory of the Buildroot source tree:

docs/system/arm/imx8mp-evk.rst line 39

Quoted 10 lines
docs/system/arm/imx8mp-evk.rst new file +10 -0
+
+.. code-block:: bash
+
+  $ echo "BR2_TARGET_ROOTFS_CPIO=y" >> configs/freescale_imx8mpevk_defconfig
+  $ make freescale_imx8mpevk_defconfig
+  $ make
+
+Once finished successfully there is an ``output/image`` subfolder. Navigate into
+it patch the device tree needs to be patched with the following commands which
+will remove the ``cpu-idle-states`` properties from CPU nodes:

This sentence seems to be confused in the middle -- cut-and-paste error ?

Quoted 6 lines
docs/system/arm/imx8mp-evk.rst new file +6 -0
+
+.. code-block:: bash
+
+  $ dtc imx8mp-evk.dtb | sed '/cpu-idle-states/d' > imx8mp-evk-patched.dts
+  $ dtc imx8mp-evk-patched.dts -o imx8mp-evk-patched.dtb
+

docs/system/arm/imx8mp-evk.rst

Quoted 10 lines
docs/system/arm/imx8mp-evk.rst new file +9 -0
+Now that everything is prepared the newly built image can be run in the QEMU
+``imx8mp-evk`` machine:
 
+#define NAME_SIZE 20
+
+static void fsl_imx8mp_init(Object *obj)
+{
+    MachineState *ms = MACHINE(qdev_get_machine());
+    FslImx8mpState *s = FSL_IMX8MP(obj);
+    char name[NAME_SIZE];

Better than fixed sized char arrays for object names is to use
g_autofree char *name = g_strdup_printf("cpu%d", i);
inside the block of each for() loop etc.

Quoted 34 lines
docs/system/arm/imx8mp-evk.rst new file +34 -0
+    int i;
+
+    for (i = 0; i < MIN(ms->smp.cpus, FSL_IMX8MP_NUM_CPUS); i++) {
+        snprintf(name, NAME_SIZE, "cpu%d", i);
+        object_initialize_child(obj, name, &s->cpu[i],
+                                ARM_CPU_TYPE_NAME("cortex-a53"));
+    }
+
+    object_initialize_child(obj, "gic", &s->gic, TYPE_ARM_GICV3);
+
+    for (i = 0; i < FSL_IMX8MP_NUM_UARTS; i++) {
+        snprintf(name, NAME_SIZE, "uart%d", i + 1);
+        object_initialize_child(obj, name, &s->uart[i], TYPE_IMX_SERIAL);
+    }
+}
+
+static void fsl_imx8mp_realize(DeviceState *dev, Error **errp)
+{
+    MachineState *ms = MACHINE(qdev_get_machine());
+    FslImx8mpState *s = FSL_IMX8MP(dev);
+    DeviceState *gicdev = DEVICE(&s->gic);
+    int i;
+
+    if (ms->smp.cpus > FSL_IMX8MP_NUM_CPUS) {
+        error_setg(errp, "%s: Only %d CPUs are supported (%d requested)",
+                   TYPE_FSL_IMX8MP, FSL_IMX8MP_NUM_CPUS, ms->smp.cpus);
+        return;
+    }
+
+    /* CPUs */
+    for (i = 0; i < ms->smp.cpus; i++) {
+        /* On uniprocessor, the CBAR is set to 0 */
+        if (ms->smp.cpus > 1) {
+            object_property_set_int(OBJECT(&s->cpu[i]), "reset-cbar",

docs/system/arm/imx8mp-evk.rst

Quoted 10 lines
docs/system/arm/imx8mp-evk.rst new file +10 -0
+                                    fsl_imx8mp_memmap[FSL_IMX8MP_GIC_DIST].addr,
+                                    &error_abort);
+        }
+
+        /*
+         * Magic value from Linux output: "arch_timer: cp15 timer(s) running at
+         * 8.00MHz (phys)".
+         */
+        object_property_set_int(OBJECT(&s->cpu[i]), "cntfrq", 8000000,
+                                &error_abort);

This is the CNTFRQ value in Hz. The datasheet actually tells you this, so we don't need to call it a magic number (section 4.11.4.1.6.4 of the i.MX 8M Plus Applications Processor Reference Manual says the base frequency of the system counter is 8MHz).

(Incidentally the memory mapped system counter is a stock Arm IP block and I have about 60% of a model of it, I just haven't needed to upstream it yet because in practice no guest software really tries to mess with it. If we turn out to need it for this SoC that would be a reason for me to clean it up and send it out. But I suspect we don't need it in practice.)

thanks
-- PMM

#11 lore raw

Re: [PATCH v2 04/18] hw/arm: Add i.MX 8M Plus EVK board

Am 10. Februar 2025 17:30:01 UTC schrieb Peter Maydell <[email protected]>:

Quoted 12 lines · Bernhard Beschow
Quoted 8 lines

As a first step, implement the bare minimum: CPUs, RAM, interrupt controller, serial. All other devices of the A53 memory map are represented as TYPE_UNIMPLEMENTED_DEVICE, i.e. the whole memory map is provided. This allows for running Linux without it crashing due to invalid memory accesses.

---

Quoted 14 lines

docs/system/arm/imx8mp-evk.rst line 6

Quoted 9 lines
docs/system/arm/imx8mp-evk.rst new file +6 -0
@@ -0,0 +1,56 @@
+NXP i.MX 8M Plus Evaluation Kit (``imx8mp-evk``)
+================================================
+
+The QEMU i.MX 8M Plus EVK board emulation is intended to emulate a plain i.MX 8M
+Plus system on chip (SoC). All peripherals the real board has such as flash and
+I2C devices are intended to be added via configuration, e.g. command line.

Why do this? If they're on the real hardware board, we should be creating them by default in the machine model in QEMU. Command line options are for devices that are optional and pluggable by the user on the hardware.

My goal is to be able to model a custom, proprietary machine which runs in a CI. In order to avoid peripherals getting in the way, the idea is to have a machine which essentially exposes the plain SoC, and allow users to "decorate" it themselves. Is an EVK machine the wrong approach for this? Are there any other ways to achieve this, e.g. with -nodefaults?

Quoted 9 lines

docs/system/arm/imx8mp-evk.rst line 13

Quoted 7 lines
docs/system/arm/imx8mp-evk.rst new file +6 -0
+Supported devices
+-----------------
+
+The ``imx8mp-evk`` machine implements the following devices:
+
+ * Up to 4 Cortex-A53 Cores

"cores"

Fixed in v3.

Quoted 22 lines
Quoted 22 lines
docs/system/arm/imx8mp-evk.rst new file +21 -0
+ * Generic Interrupt Controller (GICv3)
+ * 4 UARTs
+
+Boot options
+------------
+
+The ``imx8mp-evk`` machine can start using the standard -kernel functionality
+for loading a Linux kernel.
+
+Direct Linux Kernel Boot
+''''''''''''''''''''''''
+
+Probably the easiest way to get started with a whole Linux system on the machine
+is to generate an image with Buildroot. Version 2024.11.1 is tested at the time
+of writing and involves two steps. First run the following commands in the
+toplevel directory of the Buildroot source tree:
+
+.. code-block:: bash
+
+  $ echo "BR2_TARGET_ROOTFS_CPIO=y" >> configs/freescale_imx8mpevk_defconfig
+  $ make freescale_imx8mpevk_defconfig
Quoted 8 lines

docs/system/arm/imx8mp-evk.rst line 39

Quoted 5 lines
docs/system/arm/imx8mp-evk.rst new file +5 -0
+  $ make
+
+Once finished successfully there is an ``output/image`` subfolder. Navigate into
+it patch the device tree needs to be patched with the following commands which
+will remove the ``cpu-idle-states`` properties from CPU nodes:

This sentence seems to be confused in the middle -- cut-and-paste error ?

Yeah, probably. Fixed in v3.

Quoted 10 lines
Quoted 9 lines
docs/system/arm/imx8mp-evk.rst new file +8 -0
+
+.. code-block:: bash
+
+  $ dtc imx8mp-evk.dtb | sed '/cpu-idle-states/d' > imx8mp-evk-patched.dts
+  $ dtc imx8mp-evk-patched.dts -o imx8mp-evk-patched.dtb
+
+Now that everything is prepared the newly built image can be run in the QEMU
+``imx8mp-evk`` machine:
Quoted 12 lines

docs/system/arm/imx8mp-evk.rst line 53

Quoted 7 lines
docs/system/arm/imx8mp-evk.rst new file +7 -0
+#define NAME_SIZE 20
+
+static void fsl_imx8mp_init(Object *obj)
+{
+    MachineState *ms = MACHINE(qdev_get_machine());
+    FslImx8mpState *s = FSL_IMX8MP(obj);
+    char name[NAME_SIZE];

Better than fixed sized char arrays for object names is to use
g_autofree char *name = g_strdup_printf("cpu%d", i);
inside the block of each for() loop etc.

Will fix for v3, touching subsequent patches.

Quoted 42 lines
Quoted 42 lines
docs/system/arm/imx8mp-evk.rst new file +41 -0
+    int i;
+
+    for (i = 0; i < MIN(ms->smp.cpus, FSL_IMX8MP_NUM_CPUS); i++) {
+        snprintf(name, NAME_SIZE, "cpu%d", i);
+        object_initialize_child(obj, name, &s->cpu[i],
+                                ARM_CPU_TYPE_NAME("cortex-a53"));
+    }
+
+    object_initialize_child(obj, "gic", &s->gic, TYPE_ARM_GICV3);
+
+    for (i = 0; i < FSL_IMX8MP_NUM_UARTS; i++) {
+        snprintf(name, NAME_SIZE, "uart%d", i + 1);
+        object_initialize_child(obj, name, &s->uart[i], TYPE_IMX_SERIAL);
+    }
+}
+
+static void fsl_imx8mp_realize(DeviceState *dev, Error **errp)
+{
+    MachineState *ms = MACHINE(qdev_get_machine());
+    FslImx8mpState *s = FSL_IMX8MP(dev);
+    DeviceState *gicdev = DEVICE(&s->gic);
+    int i;
+
+    if (ms->smp.cpus > FSL_IMX8MP_NUM_CPUS) {
+        error_setg(errp, "%s: Only %d CPUs are supported (%d requested)",
+                   TYPE_FSL_IMX8MP, FSL_IMX8MP_NUM_CPUS, ms->smp.cpus);
+        return;
+    }
+
+    /* CPUs */
+    for (i = 0; i < ms->smp.cpus; i++) {
+        /* On uniprocessor, the CBAR is set to 0 */
+        if (ms->smp.cpus > 1) {
+            object_property_set_int(OBJECT(&s->cpu[i]), "reset-cbar",
+                                    fsl_imx8mp_memmap[FSL_IMX8MP_GIC_DIST].addr,
+                                    &error_abort);
+        }
+
+        /*
+         * Magic value from Linux output: "arch_timer: cp15 timer(s) running at
+         * 8.00MHz (phys)".
Quoted 8 lines

docs/system/arm/imx8mp-evk.rst

Quoted 3 lines
docs/system/arm/imx8mp-evk.rst new file +3 -0
+         */
+        object_property_set_int(OBJECT(&s->cpu[i]), "cntfrq", 8000000,
+                                &error_abort);

This is the CNTFRQ value in Hz. The datasheet actually tells you this, so we don't need to call it a magic number (section 4.11.4.1.6.4 of the i.MX 8M Plus Applications Processor Reference Manual says the base frequency of the system counter is 8MHz).

Ah, so then it's the "nxp,sysctr-timer"-compatible counter in the device tree? I've stared my own implementation but didn't see the relation to the cp15 timer. Thanks for clarifying this. I'd comment: 'CNTFID0 base frequency in Hz'.

Quoted 7 lines

(Incidentally the memory mapped system counter is a stock Arm IP block and I have about 60% of a model of it, I just haven't needed to upstream it yet because in practice no guest software really tries to mess with it. If we turn out to need it for this SoC that would be a reason for me to clean it up and send it out. But I suspect we don't need it in practice.)

The ugly workaround for the cpu-idle-states above is actually related to this counter, IIUC. I suppose that QEMU doesn't support these idle states, it only seems to support WFI. But if it did, then this counter would wake up the CPUs (if I'm not mistaken, I'm no expert here). It would be nice to be able to boot the machine via U-Boot, and I wonder if that could fix the idle states when there are PSCI handlers in the secure world. Again, this probably also requires the counter implementation. Looking into U-Boot, TF-A, and OP-TEE is on my plan, but right now I'm focusing on direct kernel boot.

Best regards,
Bernhard

Quoted 3 lines

thanks
-- PMM

#12 lore raw

Re: [PATCH v2 04/18] hw/arm: Add i.MX 8M Plus EVK board

Quoted 31 lines · Bernhard Beschow

Am 10. Februar 2025 17:30:01 UTC schrieb Peter Maydell <[email protected]>:

Quoted 12 lines · Bernhard Beschow
Quoted 8 lines

As a first step, implement the bare minimum: CPUs, RAM, interrupt controller, serial. All other devices of the A53 memory map are represented as TYPE_UNIMPLEMENTED_DEVICE, i.e. the whole memory map is provided. This allows for running Linux without it crashing due to invalid memory accesses.

---

Quoted 14 lines

docs/system/arm/imx8mp-evk.rst line 6

Quoted 9 lines
docs/system/arm/imx8mp-evk.rst new file +6 -0
@@ -0,0 +1,56 @@
+NXP i.MX 8M Plus Evaluation Kit (``imx8mp-evk``)
+================================================
+
+The QEMU i.MX 8M Plus EVK board emulation is intended to emulate a plain i.MX 8M
+Plus system on chip (SoC). All peripherals the real board has such as flash and
+I2C devices are intended to be added via configuration, e.g. command line.

Why do this? If they're on the real hardware board, we should be creating them by default in the machine model in QEMU. Command line options are for devices that are optional and pluggable by the user on the hardware.

Quoted 1 line

My goal is to be able to model a custom, proprietary machine which runs in a CI. In order to avoid peripherals getting in the way, the idea is to have a machine which essentially exposes the plain SoC, and allow users to "decorate" it themselves. Is an EVK machine the wrong approach for this? Are there any other ways to achieve this, e.g. with -nodefaults?

That's not really a usage model QEMU currently supports. We generally speaking model what the actual hardware does. In the same way, if you were running CI on the real EVK board your CI would have to deal with those devices being present.

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
docs/system/arm/imx8mp-evk.rst new file +6 -0
+        /*
+         * Magic value from Linux output: "arch_timer: cp15 timer(s) running at
+         * 8.00MHz (phys)".
+         */
+        object_property_set_int(OBJECT(&s->cpu[i]), "cntfrq", 8000000,
+                                &error_abort);
Quoted 8 lines
Quoted 4 lines

This is the CNTFRQ value in Hz. The datasheet actually tells you this, so we don't need to call it a magic number (section 4.11.4.1.6.4 of the i.MX 8M Plus Applications Processor Reference Manual says the base frequency of the system counter is 8MHz).

Ah, so then it's the "nxp,sysctr-timer"-compatible counter in the device tree? I've stared my own implementation but didn't see the relation to the cp15 timer. Thanks for clarifying this.

Yeah; I haven't actually checked carefully whether there are NXP specifics here, as that device-tree compat string suggests. But it's almost certainly the same general principle:
there's a memory-mapped system counter which is the global source of the system count, and each CPU consumes that count and uses it to feed its generic timers and counters. So if you mess with the enable on the memory mapped system counter then this causes the CPU's timers/counters to stop ticking.

I modelled this similarly to the in-tree M-profile sse-counter and sse-timer, where you link the timer to the counter and there's an API that lets the timer know when the counter is enabled/disabled, changes frequency, etc. This needs changes to the timer and counter code in the CPU itself. (You can get away without doing this if you assume that the guest code never tries to actually disable the system counter or pick a non-default frequency, which is typically true:
it will just want to set it up to a single standard config and then leave it alone.)

Quoted 8 lines
Quoted 6 lines

(Incidentally the memory mapped system counter is a stock Arm IP block and I have about 60% of a model of it, I just haven't needed to upstream it yet because in practice no guest software really tries to mess with it. If we turn out to need it for this SoC that would be a reason for me to clean it up and send it out. But I suspect we don't need it in practice.)

The ugly workaround for the cpu-idle-states above is actually related to this counter, IIUC. I suppose that QEMU doesn't support these idle states, it only seems to support WFI. But if it did, then this counter would wake up the CPUs (if I'm not mistaken, I'm no expert here). It would be nice to be able to boot the machine via U-Boot, and I wonder if that could fix the idle states when there are PSCI handlers in the secure world. Again, this probably also requires the counter implementation. Looking into U-Boot, TF-A, and OP-TEE is on my plan, but right now I'm focusing on direct kernel boot.

Hmm, if the system counter can generate interrupts then it might be different from the Arm IP block in that respect. I'd have to check the datasheet. Anyway, as you suggest this is all something we can postpone until we need to care about running EL3 firmware in the guest.

thanks
-- PMM

#13 lore raw

Re: [PATCH v2 04/18] hw/arm: Add i.MX 8M Plus EVK board

Am 11. Februar 2025 10:06:19 UTC schrieb Peter Maydell <[email protected]>:

Quoted 32 lines · Bernhard Beschow
Quoted 31 lines

Am 10. Februar 2025 17:30:01 UTC schrieb Peter Maydell <[email protected]>:

Quoted 26 lines · Bernhard Beschow
Quoted 14 lines

As a first step, implement the bare minimum: CPUs, RAM, interrupt controller, serial. All other devices of the A53 memory map are represented as TYPE_UNIMPLEMENTED_DEVICE, i.e. the whole memory map is provided. This allows for running Linux without it crashing due to invalid memory accesses.

---

docs/system/arm/imx8mp-evk.rst line 6

Quoted 6 lines
docs/system/arm/imx8mp-evk.rst new file +6 -0
@@ -0,0 +1,56 @@
+NXP i.MX 8M Plus Evaluation Kit (``imx8mp-evk``)
+================================================
+
+The QEMU i.MX 8M Plus EVK board emulation is intended to emulate a plain i.MX 8M
+Plus system on chip (SoC). All peripherals the real board has such as flash and
+I2C devices are intended to be added via configuration, e.g. command line.

Why do this? If they're on the real hardware board, we should be creating them by default in the machine model in QEMU. Command line options are for devices that are optional and pluggable by the user on the hardware.

Quoted 4 lines
Quoted 1 line

My goal is to be able to model a custom, proprietary machine which runs in a CI. In order to avoid peripherals getting in the way, the idea is to have a machine which essentially exposes the plain SoC, and allow users to "decorate" it themselves. Is an EVK machine the wrong approach for this? Are there any other ways to achieve this, e.g. with -nodefaults?

That's not really a usage model QEMU currently supports. We generally speaking model what the actual hardware does.

Why not support such usage model? The machine in this series works amazingly well for our purposes. If modeling a concrete board implies hardcoding peripherals, would modeling an artificial "board" which just contains the SoC work instead? IOW should I drop the "-evk" suffix from the machine and claim it only models the SoC?

Quoted 20 lines

In the same way,
if you were running CI on the real EVK board your CI would have to deal with those devices being present.

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
docs/system/arm/imx8mp-evk.rst new file +6 -0
+        /*
+         * Magic value from Linux output: "arch_timer: cp15 timer(s) running at
+         * 8.00MHz (phys)".
+         */
+        object_property_set_int(OBJECT(&s->cpu[i]), "cntfrq", 8000000,
+                                &error_abort);
Quoted 8 lines
Quoted 4 lines

This is the CNTFRQ value in Hz. The datasheet actually tells you this, so we don't need to call it a magic number (section 4.11.4.1.6.4 of the i.MX 8M Plus Applications Processor Reference Manual says the base frequency of the system counter is 8MHz).

Ah, so then it's the "nxp,sysctr-timer"-compatible counter in the device tree? I've stared my own implementation but didn't see the relation to the cp15 timer. Thanks for clarifying this.

Quoted 8 lines

Yeah; I haven't actually checked carefully whether there are NXP specifics here, as that device-tree compat string suggests. But it's almost certainly the same general principle:
there's a memory-mapped system counter which is the global source of the system count, and each CPU consumes that count and uses it to feed its generic timers and counters. So if you mess with the enable on the memory mapped system counter then this causes the CPU's timers/counters to stop ticking.

Yeah, this also is how I understand the documentation of the system counter in the reference manual.

Quoted 11 lines

I modelled this similarly to the in-tree M-profile sse-counter and sse-timer, where you link the timer to the counter and there's an API that lets the timer know when the counter is enabled/disabled, changes frequency, etc. This needs changes to the timer and counter code in the CPU itself. (You can get away without doing this if you assume that the guest code never tries to actually disable the system counter or pick a non-default frequency, which is typically true:
it will just want to set it up to a single standard config and then leave it alone.)

I have this implementation which puts the focus more on waking up the CPUs via the IRQ: <https://github.com/shentok/qemu/commit/1aa0887a5ff926572ab40b39fe5a087acb3ff249> The IRQ fires but doesn't wake any CPU in case of direct kernel boot since the IRQ is masked in EL1 (rich OS mode) and EL3 isn't set up.

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

(Incidentally the memory mapped system counter is a stock Arm IP block and I have about 60% of a model of it, I just haven't needed to upstream it yet because in practice no guest software really tries to mess with it. If we turn out to need it for this SoC that would be a reason for me to clean it up and send it out. But I suspect we don't need it in practice.)

Quoted 7 lines
Quoted 1 line

The ugly workaround for the cpu-idle-states above is actually related to this counter, IIUC. I suppose that QEMU doesn't support these idle states, it only seems to support WFI. But if it did, then this counter would wake up the CPUs (if I'm not mistaken, I'm no expert here). It would be nice to be able to boot the machine via U-Boot, and I wonder if that could fix the idle states when there are PSCI handlers in the secure world. Again, this probably also requires the counter implementation. Looking into U-Boot, TF-A, and OP-TEE is on my plan, but right now I'm focusing on direct kernel boot.

Hmm, if the system counter can generate interrupts then it might be different from the Arm IP block in that respect. I'd have to check the datasheet. Anyway, as you suggest this is all something we can postpone until we need to care about running EL3 firmware in the guest.

Yeah, this would probably work with U-Boot then. But for direct kernel boot we'd need support beyond WFI directly in QEMU -- which is currently missing, right?

Best regards,
Bernhard

Quoted 3 lines

thanks
-- PMM

#14 lore raw

Re: [PATCH v2 04/18] hw/arm: Add i.MX 8M Plus EVK board

In reply to Peter Maydell

Am 10. Februar 2025 17:30:01 UTC schrieb Peter Maydell <[email protected]>:

Quoted 12 lines · Bernhard Beschow
Quoted 8 lines

As a first step, implement the bare minimum: CPUs, RAM, interrupt controller, serial. All other devices of the A53 memory map are represented as TYPE_UNIMPLEMENTED_DEVICE, i.e. the whole memory map is provided. This allows for running Linux without it crashing due to invalid memory accesses.

---

Quoted 14 lines

docs/system/arm/imx8mp-evk.rst line 6

Quoted 9 lines
docs/system/arm/imx8mp-evk.rst new file +6 -0
@@ -0,0 +1,56 @@
+NXP i.MX 8M Plus Evaluation Kit (``imx8mp-evk``)
+================================================
+
+The QEMU i.MX 8M Plus EVK board emulation is intended to emulate a plain i.MX 8M
+Plus system on chip (SoC). All peripherals the real board has such as flash and
+I2C devices are intended to be added via configuration, e.g. command line.

Why do this? If they're on the real hardware board, we should be creating them by default in the machine model in QEMU. Command line options are for devices that are optional and pluggable by the user on the hardware.

I'll rephrase the board description to be similar to the mcimx7d-sabre machine. In fact, I've modeled this machine like it.

Best regards,
Bernhard

Quoted 121 lines

docs/system/arm/imx8mp-evk.rst line 13

Quoted 7 lines
docs/system/arm/imx8mp-evk.rst new file +6 -0
+Supported devices
+-----------------
+
+The ``imx8mp-evk`` machine implements the following devices:
+
+ * Up to 4 Cortex-A53 Cores

"cores"

Quoted 16 lines
docs/system/arm/imx8mp-evk.rst new file +16 -0
+ * Generic Interrupt Controller (GICv3)
+ * 4 UARTs
+
+Boot options
+------------
+
+The ``imx8mp-evk`` machine can start using the standard -kernel functionality
+for loading a Linux kernel.
+
+Direct Linux Kernel Boot
+''''''''''''''''''''''''
+
+Probably the easiest way to get started with a whole Linux system on the machine
+is to generate an image with Buildroot. Version 2024.11.1 is tested at the time
+of writing and involves two steps. First run the following commands in the
+toplevel directory of the Buildroot source tree:

docs/system/arm/imx8mp-evk.rst line 39

Quoted 10 lines
docs/system/arm/imx8mp-evk.rst new file +10 -0
+
+.. code-block:: bash
+
+  $ echo "BR2_TARGET_ROOTFS_CPIO=y" >> configs/freescale_imx8mpevk_defconfig
+  $ make freescale_imx8mpevk_defconfig
+  $ make
+
+Once finished successfully there is an ``output/image`` subfolder. Navigate into
+it patch the device tree needs to be patched with the following commands which
+will remove the ``cpu-idle-states`` properties from CPU nodes:

This sentence seems to be confused in the middle -- cut-and-paste error ?

Quoted 6 lines
docs/system/arm/imx8mp-evk.rst new file +6 -0
+
+.. code-block:: bash
+
+  $ dtc imx8mp-evk.dtb | sed '/cpu-idle-states/d' > imx8mp-evk-patched.dts
+  $ dtc imx8mp-evk-patched.dts -o imx8mp-evk-patched.dtb
+

docs/system/arm/imx8mp-evk.rst

Quoted 10 lines
docs/system/arm/imx8mp-evk.rst new file +9 -0
+Now that everything is prepared the newly built image can be run in the QEMU
+``imx8mp-evk`` machine:
 
+#define NAME_SIZE 20
+
+static void fsl_imx8mp_init(Object *obj)
+{
+    MachineState *ms = MACHINE(qdev_get_machine());
+    FslImx8mpState *s = FSL_IMX8MP(obj);
+    char name[NAME_SIZE];

Better than fixed sized char arrays for object names is to use
g_autofree char *name = g_strdup_printf("cpu%d", i);
inside the block of each for() loop etc.

Quoted 34 lines
docs/system/arm/imx8mp-evk.rst new file +34 -0
+    int i;
+
+    for (i = 0; i < MIN(ms->smp.cpus, FSL_IMX8MP_NUM_CPUS); i++) {
+        snprintf(name, NAME_SIZE, "cpu%d", i);
+        object_initialize_child(obj, name, &s->cpu[i],
+                                ARM_CPU_TYPE_NAME("cortex-a53"));
+    }
+
+    object_initialize_child(obj, "gic", &s->gic, TYPE_ARM_GICV3);
+
+    for (i = 0; i < FSL_IMX8MP_NUM_UARTS; i++) {
+        snprintf(name, NAME_SIZE, "uart%d", i + 1);
+        object_initialize_child(obj, name, &s->uart[i], TYPE_IMX_SERIAL);
+    }
+}
+
+static void fsl_imx8mp_realize(DeviceState *dev, Error **errp)
+{
+    MachineState *ms = MACHINE(qdev_get_machine());
+    FslImx8mpState *s = FSL_IMX8MP(dev);
+    DeviceState *gicdev = DEVICE(&s->gic);
+    int i;
+
+    if (ms->smp.cpus > FSL_IMX8MP_NUM_CPUS) {
+        error_setg(errp, "%s: Only %d CPUs are supported (%d requested)",
+                   TYPE_FSL_IMX8MP, FSL_IMX8MP_NUM_CPUS, ms->smp.cpus);
+        return;
+    }
+
+    /* CPUs */
+    for (i = 0; i < ms->smp.cpus; i++) {
+        /* On uniprocessor, the CBAR is set to 0 */
+        if (ms->smp.cpus > 1) {
+            object_property_set_int(OBJECT(&s->cpu[i]), "reset-cbar",

docs/system/arm/imx8mp-evk.rst

Quoted 10 lines
docs/system/arm/imx8mp-evk.rst new file +10 -0
+                                    fsl_imx8mp_memmap[FSL_IMX8MP_GIC_DIST].addr,
+                                    &error_abort);
+        }
+
+        /*
+         * Magic value from Linux output: "arch_timer: cp15 timer(s) running at
+         * 8.00MHz (phys)".
+         */
+        object_property_set_int(OBJECT(&s->cpu[i]), "cntfrq", 8000000,
+                                &error_abort);

This is the CNTFRQ value in Hz. The datasheet actually tells you this, so we don't need to call it a magic number (section 4.11.4.1.6.4 of the i.MX 8M Plus Applications Processor Reference Manual says the base frequency of the system counter is 8MHz).

(Incidentally the memory mapped system counter is a stock Arm IP block and I have about 60% of a model of it, I just haven't needed to upstream it yet because in practice no guest software really tries to mess with it. If we turn out to need it for this SoC that would be a reason for me to clean it up and send it out. But I suspect we don't need it in practice.)

thanks
-- PMM

#15 lore raw

PATCH v2 5/18 hw/arm/fsl-imx8mp: Implement clock tree

In reply to Bernhard Beschow

Fixes quite a few stack traces during the Linux boot process. Also provides the clocks for devices added later, e.g. enet1.

---
 MAINTAINERS                     |   2 +
 docs/system/arm/imx8mp-evk.rst  |   1 +
 include/hw/arm/fsl-imx8mp.h     |   4 +
 include/hw/misc/imx8mp_analog.h |  81 +++++++++++++++
 include/hw/misc/imx8mp_ccm.h    |  30 ++++++
 hw/arm/fsl-imx8mp.c             |  20 ++++
 hw/misc/imx8mp_analog.c         | 160 +++++++++++++++++++++++++++++
 hw/misc/imx8mp_ccm.c            | 175 ++++++++++++++++++++++++++++++++
 hw/arm/Kconfig                  |   2 +
 hw/misc/Kconfig                 |   6 ++
 hw/misc/meson.build             |   2 +
 11 files changed, 483 insertions(+)
 create mode 100644 include/hw/misc/imx8mp_analog.h
 create mode 100644 include/hw/misc/imx8mp_ccm.h
 create mode 100644 hw/misc/imx8mp_analog.c
 create mode 100644 hw/misc/imx8mp_ccm.c
MAINTAINERS +2 -0
index 8db59114bc..5b5b0d0bed 100644
@@ -826,7 +826,9 @@ L: [email protected]
 S: Maintained
 F: hw/arm/imx8mp-evk.c
 F: hw/arm/fsl-imx8mp.c
+F: hw/misc/imx8mp_*.c
 F: include/hw/arm/fsl-imx8mp.h
+F: include/hw/misc/imx8mp_*.h
 F: docs/system/arm/imx8mp-evk.rst
 
 MPS2 / MPS3
docs/system/arm/imx8mp-evk.rst +1 -0
index a9c1fab390..e5039fc8c4 100644
@@ -13,6 +13,7 @@ The ``imx8mp-evk`` machine implements the following devices:
  * Up to 4 Cortex-A53 Cores
  * Generic Interrupt Controller (GICv3)
  * 4 UARTs
+ * Clock Tree
 
 Boot options
 ------------
include/hw/arm/fsl-imx8mp.h +4 -0
index 57e23d1b69..ce5188e7f2 100644
@@ -12,6 +12,8 @@
 #include "cpu.h"
 #include "hw/char/imx_serial.h"
 #include "hw/intc/arm_gicv3_common.h"
+#include "hw/misc/imx8mp_analog.h"
+#include "hw/misc/imx8mp_ccm.h"
 #include "qom/object.h"
 #include "qemu/units.h"
 
@@ -32,6 +34,8 @@ struct FslImx8mpState {
 
     ARMCPU             cpu[FSL_IMX8MP_NUM_CPUS];
     GICv3State         gic;
+    IMX8MPCCMState     ccm;
+    IMX8MPAnalogState  analog;
     IMXSerialState     uart[FSL_IMX8MP_NUM_UARTS];
 };
 
include/hw/misc/imx8mp_analog.h new file +81 -0

81 lines not on this page · raw message

include/hw/misc/imx8mp_ccm.h new file +30 -0
new file mode 100644
index 0000000000..685c8582ff
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2025 Bernhard Beschow <[email protected]>
+ *
+ * i.MX 8M Plus CCM IP block emulation code
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef IMX8MP_CCM_H
+#define IMX8MP_CCM_H
+
+#include "hw/misc/imx_ccm.h"
+#include "qom/object.h"
+
+enum IMX8MPCCMRegisters {
+    CCM_MAX = 0xc6fc / sizeof(uint32_t) + 1,
+};
+
+#define TYPE_IMX8MP_CCM "imx8mp.ccm"
+OBJECT_DECLARE_SIMPLE_TYPE(IMX8MPCCMState, IMX8MP_CCM)
+
+struct IMX8MPCCMState {
+    IMXCCMState parent_obj;
+
+    MemoryRegion iomem;
+
+    uint32_t ccm[CCM_MAX];
+};
+
+#endif /* IMX8MP_CCM_H */
hw/arm/fsl-imx8mp.c +20 -0
index 0836d82ca0..a1a8843b3b 100644
@@ -200,6 +200,10 @@ static void fsl_imx8mp_init(Object *obj)
 
     object_initialize_child(obj, "gic", &s->gic, TYPE_ARM_GICV3);
 
+    object_initialize_child(obj, "ccm", &s->ccm, TYPE_IMX8MP_CCM);
+
+    object_initialize_child(obj, "analog", &s->analog, TYPE_IMX8MP_ANALOG);
+
     for (i = 0; i < FSL_IMX8MP_NUM_UARTS; i++) {
         snprintf(name, NAME_SIZE, "uart%d", i + 1);
         object_initialize_child(obj, name, &s->uart[i], TYPE_IMX_SERIAL);
@@ -308,6 +312,20 @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp)
         }
     }
 
+    /* CCM */
+    if (!sysbus_realize(SYS_BUS_DEVICE(&s->ccm), errp)) {
+        return;
+    }
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->ccm), 0,
+                    fsl_imx8mp_memmap[FSL_IMX8MP_CCM].addr);
+
+    /* Analog */
+    if (!sysbus_realize(SYS_BUS_DEVICE(&s->analog), errp)) {
+        return;
+    }
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->analog), 0,
+                    fsl_imx8mp_memmap[FSL_IMX8MP_ANA_PLL].addr);
+
     /* UARTs */
     for (i = 0; i < FSL_IMX8MP_NUM_UARTS; i++) {
         static const struct {
@@ -333,6 +351,8 @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp)
     /* Unimplemented devices */
     for (i = 0; i < ARRAY_SIZE(fsl_imx8mp_memmap); i++) {
         switch (i) {
+        case FSL_IMX8MP_ANA_PLL:
+        case FSL_IMX8MP_CCM:
         case FSL_IMX8MP_GIC_DIST:
         case FSL_IMX8MP_GIC_REDIST:
         case FSL_IMX8MP_RAM:
hw/misc/imx8mp_analog.c new file +160 -0

160 lines not on this page · raw message

hw/misc/imx8mp_ccm.c new file +175 -0

175 lines not on this page · raw message

hw/arm/Kconfig +2 -0
index e22916df57..0079c51734 100644
@@ -580,6 +580,8 @@ config FSL_IMX7
 config FSL_IMX8MP
     bool
     select ARM_GIC
+    select FSL_IMX8MP_ANALOG
+    select FSL_IMX8MP_CCM
     select IMX
     select UNIMP
 
hw/misc/Kconfig +6 -0
index 4271e2f4ac..82bd68b4bb 100644
@@ -78,6 +78,12 @@ config IMX
     select SSI
     select USB_EHCI_SYSBUS
 
+config FSL_IMX8MP_ANALOG
+    bool
+
+config FSL_IMX8MP_CCM
+    bool
+
 config STM32_RCC
     bool
 
hw/misc/meson.build +2 -0
index 55f493521b..f9285cf2f1 100644
@@ -55,6 +55,8 @@ system_ss.add(when: 'CONFIG_AXP2XX_PMU', if_true: files('axp2xx.c'))
 system_ss.add(when: 'CONFIG_REALVIEW', if_true: files('arm_sysctl.c'))
 system_ss.add(when: 'CONFIG_ECCMEMCTL', if_true: files('eccmemctl.c'))
 system_ss.add(when: 'CONFIG_EXYNOS4', if_true: files('exynos4210_pmu.c', 'exynos4210_clk.c', 'exynos4210_rng.c'))
+system_ss.add(when: 'CONFIG_FSL_IMX8MP_ANALOG', if_true: files('imx8mp_analog.c'))
+system_ss.add(when: 'CONFIG_FSL_IMX8MP_CCM', if_true: files('imx8mp_ccm.c'))
 system_ss.add(when: 'CONFIG_IMX', if_true: files(
   'imx25_ccm.c',
   'imx31_ccm.c',
Signature · 1 line
2.48.1
#16 lore raw

Re: [PATCH v2 05/18] hw/arm/fsl-imx8mp: Implement clock tree

Am 4. Februar 2025 09:20:59 UTC schrieb Bernhard Beschow <[email protected]>:

Quoted 394 lines

Fixes quite a few stack traces during the Linux boot process. Also provides the clocks for devices added later, e.g. enet1.

---

MAINTAINERS                     |   2 +
docs/system/arm/imx8mp-evk.rst  |   1 +
include/hw/arm/fsl-imx8mp.h     |   4 +
include/hw/misc/imx8mp_analog.h |  81 +++++++++++++++
include/hw/misc/imx8mp_ccm.h    |  30 ++++++
hw/arm/fsl-imx8mp.c             |  20 ++++
hw/misc/imx8mp_analog.c         | 160 +++++++++++++++++++++++++++++
hw/misc/imx8mp_ccm.c            | 175 ++++++++++++++++++++++++++++++++
hw/arm/Kconfig                  |   2 +
hw/misc/Kconfig                 |   6 ++
hw/misc/meson.build             |   2 +
11 files changed, 483 insertions(+)

create mode 100644 include/hw/misc/imx8mp_analog.h create mode 100644 include/hw/misc/imx8mp_ccm.h create mode 100644 hw/misc/imx8mp_analog.c create mode 100644 hw/misc/imx8mp_ccm.c

MAINTAINERS +0 -0
index 8db59114bc..5b5b0d0bed 100644
@@ -826,7 +826,9 @@ L: [email protected]

S: Maintained
F: hw/arm/imx8mp-evk.c
F: hw/arm/fsl-imx8mp.c
+F: hw/misc/imx8mp_*.c
F: include/hw/arm/fsl-imx8mp.h
+F: include/hw/misc/imx8mp_*.h
F: docs/system/arm/imx8mp-evk.rst

MPS2 / MPS3

docs/system/arm/imx8mp-evk.rst +1 -0
index a9c1fab390..e5039fc8c4 100644
@@ -13,6 +13,7 @@ The ``imx8mp-evk`` machine implements the following devices:
 * Up to 4 Cortex-A53 Cores
 * Generic Interrupt Controller (GICv3)
 * 4 UARTs
+ * Clock Tree
 

Boot options
------------

include/hw/arm/fsl-imx8mp.h +4 -0
index 57e23d1b69..ce5188e7f2 100644
@@ -12,6 +12,8 @@
 #include "cpu.h"
 #include "hw/char/imx_serial.h"
 #include "hw/intc/arm_gicv3_common.h"
+#include "hw/misc/imx8mp_analog.h"
+#include "hw/misc/imx8mp_ccm.h"
 #include "qom/object.h"
 #include "qemu/units.h"
 
@@ -32,6 +34,8 @@ struct FslImx8mpState {
 
    ARMCPU             cpu[FSL_IMX8MP_NUM_CPUS];
    GICv3State         gic;
+    IMX8MPCCMState     ccm;
+    IMX8MPAnalogState  analog;
    IMXSerialState     uart[FSL_IMX8MP_NUM_UARTS];
 };
 
include/hw/misc/imx8mp_analog.h new file +81 -0
new file mode 100644
index 0000000000..955f03215a
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2025 Bernhard Beschow <[email protected]>
+ *
+ * i.MX8MP ANALOG IP block emulation code
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef IMX8MP_ANALOG_H
+#define IMX8MP_ANALOG_H
+
+#include "qom/object.h"
+#include "hw/sysbus.h"
+
+enum IMX8MPAnalogRegisters {
+    ANALOG_AUDIO_PLL1_GEN_CTRL = 0x000 / 4,
+    ANALOG_AUDIO_PLL1_FDIV_CTL0 = 0x004 / 4,
+    ANALOG_AUDIO_PLL1_FDIV_CTL1 = 0x008 / 4,
+    ANALOG_AUDIO_PLL1_SSCG_CTRL = 0x00c / 4,
+    ANALOG_AUDIO_PLL1_MNIT_CTRL = 0x010 / 4,
+    ANALOG_AUDIO_PLL2_GEN_CTRL = 0x014 / 4,
+    ANALOG_AUDIO_PLL2_FDIV_CTL0 = 0x018 / 4,
+    ANALOG_AUDIO_PLL2_FDIV_CTL1 = 0x01c / 4,
+    ANALOG_AUDIO_PLL2_SSCG_CTRL = 0x020 / 4,
+    ANALOG_AUDIO_PLL2_MNIT_CTRL = 0x024 / 4,
+    ANALOG_VIDEO_PLL1_GEN_CTRL = 0x028 / 4,
+    ANALOG_VIDEO_PLL1_FDIV_CTL0 = 0x02c / 4,
+    ANALOG_VIDEO_PLL1_FDIV_CTL1 = 0x030 / 4,
+    ANALOG_VIDEO_PLL1_SSCG_CTRL = 0x034 / 4,
+    ANALOG_VIDEO_PLL1_MNIT_CTRL = 0x038 / 4,
+    ANALOG_DRAM_PLL_GEN_CTRL = 0x050 / 4,
+    ANALOG_DRAM_PLL_FDIV_CTL0 = 0x054 / 4,
+    ANALOG_DRAM_PLL_FDIV_CTL1 = 0x058 / 4,
+    ANALOG_DRAM_PLL_SSCG_CTRL = 0x05c / 4,
+    ANALOG_DRAM_PLL_MNIT_CTRL = 0x060 / 4,
+    ANALOG_GPU_PLL_GEN_CTRL = 0x064 / 4,
+    ANALOG_GPU_PLL_FDIV_CTL0 = 0x068 / 4,
+    ANALOG_GPU_PLL_LOCKD_CTRL = 0x06c / 4,
+    ANALOG_GPU_PLL_MNIT_CTRL = 0x070 / 4,
+    ANALOG_VPU_PLL_GEN_CTRL = 0x074 / 4,
+    ANALOG_VPU_PLL_FDIV_CTL0 = 0x078 / 4,
+    ANALOG_VPU_PLL_LOCKD_CTRL = 0x07c / 4,
+    ANALOG_VPU_PLL_MNIT_CTRL = 0x080 / 4,
+    ANALOG_ARM_PLL_GEN_CTRL = 0x084 / 4,
+    ANALOG_ARM_PLL_FDIV_CTL0 = 0x088 / 4,
+    ANALOG_ARM_PLL_LOCKD_CTRL = 0x08c / 4,
+    ANALOG_ARM_PLL_MNIT_CTRL = 0x090 / 4,
+    ANALOG_SYS_PLL1_GEN_CTRL = 0x094 / 4,
+    ANALOG_SYS_PLL1_FDIV_CTL0 = 0x098 / 4,
+    ANALOG_SYS_PLL1_LOCKD_CTRL = 0x09c / 4,
+    ANALOG_SYS_PLL1_MNIT_CTRL = 0x100 / 4,
+    ANALOG_SYS_PLL2_GEN_CTRL = 0x104 / 4,
+    ANALOG_SYS_PLL2_FDIV_CTL0 = 0x108 / 4,
+    ANALOG_SYS_PLL2_LOCKD_CTRL = 0x10c / 4,
+    ANALOG_SYS_PLL2_MNIT_CTRL = 0x110 / 4,
+    ANALOG_SYS_PLL3_GEN_CTRL = 0x114 / 4,
+    ANALOG_SYS_PLL3_FDIV_CTL0 = 0x118 / 4,
+    ANALOG_SYS_PLL3_LOCKD_CTRL = 0x11c / 4,
+    ANALOG_SYS_PLL3_MNIT_CTRL = 0x120 / 4,
+    ANALOG_OSC_MISC_CFG = 0x124 / 4,
+    ANALOG_ANAMIX_PLL_MNIT_CTL = 0x128 / 4,
+
+    ANALOG_DIGPROG = 0x800 / 4,
+    ANALOG_MAX,
+};
+
+#define TYPE_IMX8MP_ANALOG "imx8mp.analog"
+OBJECT_DECLARE_SIMPLE_TYPE(IMX8MPAnalogState, IMX8MP_ANALOG)
+
+struct IMX8MPAnalogState {
+    SysBusDevice parent_obj;
+
+    struct {
+        MemoryRegion container;
+        MemoryRegion analog;
+    } mmio;
+
+    uint32_t analog[ANALOG_MAX];
+};
+
+#endif /* IMX8MP_ANALOG_H */
include/hw/misc/imx8mp_ccm.h new file +30 -0
new file mode 100644
index 0000000000..685c8582ff
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2025 Bernhard Beschow <[email protected]>
+ *
+ * i.MX 8M Plus CCM IP block emulation code
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef IMX8MP_CCM_H
+#define IMX8MP_CCM_H
+
+#include "hw/misc/imx_ccm.h"
+#include "qom/object.h"
+
+enum IMX8MPCCMRegisters {
+    CCM_MAX = 0xc6fc / sizeof(uint32_t) + 1,
+};
+
+#define TYPE_IMX8MP_CCM "imx8mp.ccm"
+OBJECT_DECLARE_SIMPLE_TYPE(IMX8MPCCMState, IMX8MP_CCM)
+
+struct IMX8MPCCMState {
+    IMXCCMState parent_obj;
+
+    MemoryRegion iomem;
+
+    uint32_t ccm[CCM_MAX];
+};
+
+#endif /* IMX8MP_CCM_H */
hw/arm/fsl-imx8mp.c +20 -0
index 0836d82ca0..a1a8843b3b 100644
@@ -200,6 +200,10 @@ static void fsl_imx8mp_init(Object *obj)
 
    object_initialize_child(obj, "gic", &s->gic, TYPE_ARM_GICV3);
 
+    object_initialize_child(obj, "ccm", &s->ccm, TYPE_IMX8MP_CCM);
+
+    object_initialize_child(obj, "analog", &s->analog, TYPE_IMX8MP_ANALOG);
+
    for (i = 0; i < FSL_IMX8MP_NUM_UARTS; i++) {
        snprintf(name, NAME_SIZE, "uart%d", i + 1);
        object_initialize_child(obj, name, &s->uart[i], TYPE_IMX_SERIAL);
@@ -308,6 +312,20 @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp)
        }
    }
 
+    /* CCM */
+    if (!sysbus_realize(SYS_BUS_DEVICE(&s->ccm), errp)) {
+        return;
+    }
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->ccm), 0,
+                    fsl_imx8mp_memmap[FSL_IMX8MP_CCM].addr);
+
+    /* Analog */
+    if (!sysbus_realize(SYS_BUS_DEVICE(&s->analog), errp)) {
+        return;
+    }
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->analog), 0,
+                    fsl_imx8mp_memmap[FSL_IMX8MP_ANA_PLL].addr);
+
    /* UARTs */
    for (i = 0; i < FSL_IMX8MP_NUM_UARTS; i++) {
        static const struct {
@@ -333,6 +351,8 @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp)
    /* Unimplemented devices */
    for (i = 0; i < ARRAY_SIZE(fsl_imx8mp_memmap); i++) {
        switch (i) {
+        case FSL_IMX8MP_ANA_PLL:
+        case FSL_IMX8MP_CCM:
        case FSL_IMX8MP_GIC_DIST:
        case FSL_IMX8MP_GIC_REDIST:
        case FSL_IMX8MP_RAM:
hw/misc/imx8mp_analog.c new file +150 -0
new file mode 100644
index 0000000000..71333b3e9e
@@ -0,0 +1,160 @@
+/*
+ * Copyright (c) 2025 Bernhard Beschow <[email protected]>
+ *
+ * i.MX 8M Plus ANALOG IP block emulation code
+ *
+ * Based on hw/misc/imx7_ccm.c
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/log.h"
+
+#include "hw/misc/imx8mp_analog.h"
+#include "migration/vmstate.h"
+
+#define ANALOG_PLL_LOCK BIT(31)
+
+static void imx8mp_analog_reset(DeviceState *dev)
+{
+    IMX8MPAnalogState *s = IMX8MP_ANALOG(dev);
+
+    memset(s->analog, 0, sizeof(s->analog));
+
+    s->analog[ANALOG_AUDIO_PLL1_GEN_CTRL] = 0x00002010;
+    s->analog[ANALOG_AUDIO_PLL1_FDIV_CTL0] = 0x00145032;
+    s->analog[ANALOG_AUDIO_PLL1_FDIV_CTL1] = 0x00000000;
+    s->analog[ANALOG_AUDIO_PLL1_SSCG_CTRL] = 0x00000000;
+    s->analog[ANALOG_AUDIO_PLL1_MNIT_CTRL] = 0x00100103;
+    s->analog[ANALOG_AUDIO_PLL2_GEN_CTRL] = 0x00002010;
+    s->analog[ANALOG_AUDIO_PLL2_FDIV_CTL0] = 0x00145032;
+    s->analog[ANALOG_AUDIO_PLL2_FDIV_CTL1] = 0x00000000;
+    s->analog[ANALOG_AUDIO_PLL2_SSCG_CTRL] = 0x00000000;
+    s->analog[ANALOG_AUDIO_PLL2_MNIT_CTRL] = 0x00100103;
+    s->analog[ANALOG_VIDEO_PLL1_GEN_CTRL] = 0x00002010;
+    s->analog[ANALOG_VIDEO_PLL1_FDIV_CTL0] = 0x00145032;
+    s->analog[ANALOG_VIDEO_PLL1_FDIV_CTL1] = 0x00000000;
+    s->analog[ANALOG_VIDEO_PLL1_SSCG_CTRL] = 0x00000000;
+    s->analog[ANALOG_VIDEO_PLL1_MNIT_CTRL] = 0x00100103;
+    s->analog[ANALOG_DRAM_PLL_GEN_CTRL] = 0x00002010;
+    s->analog[ANALOG_DRAM_PLL_FDIV_CTL0] = 0x0012c032;
+    s->analog[ANALOG_DRAM_PLL_FDIV_CTL1] = 0x00000000;
+    s->analog[ANALOG_DRAM_PLL_SSCG_CTRL] = 0x00000000;
+    s->analog[ANALOG_DRAM_PLL_MNIT_CTRL] = 0x00100103;
+    s->analog[ANALOG_GPU_PLL_GEN_CTRL] = 0x00000810;
+    s->analog[ANALOG_GPU_PLL_FDIV_CTL0] = 0x000c8031;
+    s->analog[ANALOG_GPU_PLL_LOCKD_CTRL] = 0x0010003f;
+    s->analog[ANALOG_GPU_PLL_MNIT_CTRL] = 0x00280081;
+    s->analog[ANALOG_VPU_PLL_GEN_CTRL] = 0x00000810;
+    s->analog[ANALOG_VPU_PLL_FDIV_CTL0] = 0x0012c032;
+    s->analog[ANALOG_VPU_PLL_LOCKD_CTRL] = 0x0010003f;
+    s->analog[ANALOG_VPU_PLL_MNIT_CTRL] = 0x00280081;
+    s->analog[ANALOG_ARM_PLL_GEN_CTRL] = 0x00000810;
+    s->analog[ANALOG_ARM_PLL_FDIV_CTL0] = 0x000fa031;
+    s->analog[ANALOG_ARM_PLL_LOCKD_CTRL] = 0x0010003f;
+    s->analog[ANALOG_ARM_PLL_MNIT_CTRL] = 0x00280081;
+    s->analog[ANALOG_SYS_PLL1_GEN_CTRL] = 0x0aaaa810;
+    s->analog[ANALOG_SYS_PLL1_FDIV_CTL0] = 0x00190032;
+    s->analog[ANALOG_SYS_PLL1_LOCKD_CTRL] = 0x0010003f;
+    s->analog[ANALOG_SYS_PLL1_MNIT_CTRL] = 0x00280081;
+    s->analog[ANALOG_SYS_PLL2_GEN_CTRL] = 0x0aaaa810;
+    s->analog[ANALOG_SYS_PLL2_FDIV_CTL0] = 0x000fa031;
+    s->analog[ANALOG_SYS_PLL2_LOCKD_CTRL] = 0x0010003f;
+    s->analog[ANALOG_SYS_PLL2_MNIT_CTRL] = 0x00280081;
+    s->analog[ANALOG_SYS_PLL3_GEN_CTRL] = 0x00000810;
+    s->analog[ANALOG_SYS_PLL3_FDIV_CTL0] = 0x000fa031;
+    s->analog[ANALOG_SYS_PLL3_LOCKD_CTRL] = 0x0010003f;
+    s->analog[ANALOG_SYS_PLL3_MNIT_CTRL] = 0x00280081;
+    s->analog[ANALOG_OSC_MISC_CFG] = 0x00000000;
+    s->analog[ANALOG_ANAMIX_PLL_MNIT_CTL] = 0x00000000;
+    s->analog[ANALOG_DIGPROG] = 0x00824010;
+
+    /* all PLLs need to be locked */
+    s->analog[ANALOG_AUDIO_PLL1_GEN_CTRL] |= ANALOG_PLL_LOCK;
+    s->analog[ANALOG_AUDIO_PLL2_GEN_CTRL] |= ANALOG_PLL_LOCK;
+    s->analog[ANALOG_VIDEO_PLL1_GEN_CTRL] |= ANALOG_PLL_LOCK;
+    s->analog[ANALOG_DRAM_PLL_GEN_CTRL] |= ANALOG_PLL_LOCK;
+    s->analog[ANALOG_GPU_PLL_GEN_CTRL] |= ANALOG_PLL_LOCK;
+    s->analog[ANALOG_VPU_PLL_GEN_CTRL] |= ANALOG_PLL_LOCK;
+    s->analog[ANALOG_ARM_PLL_GEN_CTRL] |= ANALOG_PLL_LOCK;
+    s->analog[ANALOG_SYS_PLL1_GEN_CTRL] |= ANALOG_PLL_LOCK;
+    s->analog[ANALOG_SYS_PLL2_GEN_CTRL] |= ANALOG_PLL_LOCK;
+    s->analog[ANALOG_SYS_PLL3_GEN_CTRL] |= ANALOG_PLL_LOCK;
+}
+
+static uint64_t imx8mp_analog_read(void *opaque, hwaddr offset, unsigned size)
+{
+    IMX8MPAnalogState *s = opaque;
+
+    return s->analog[offset >> 2];
+}
+
+static void imx8mp_analog_write(void *opaque, hwaddr offset,
+                                uint64_t value, unsigned size)
+{
+    IMX8MPAnalogState *s = opaque;
+
+    if (offset >> 2 == ANALOG_DIGPROG) {
+        qemu_log_mask(LOG_GUEST_ERROR,
+                      "Guest write to read-only ANALOG_DIGPROG register\n");
+    } else {
+        s->analog[offset >> 2] = value;
+    }
+}
+
+static const struct MemoryRegionOps imx8mp_analog_ops = {
+    .read = imx8mp_analog_read,
+    .write = imx8mp_analog_write,
+    .endianness = DEVICE_NATIVE_ENDIAN,
+    .impl = {
+        .min_access_size = 4,
+        .max_access_size = 4,
+        .unaligned = false,
+    },
+};
+
+static void imx8mp_analog_init(Object *obj)
+{
+    IMX8MPAnalogState *s = IMX8MP_ANALOG(obj);
+    SysBusDevice *sd = SYS_BUS_DEVICE(obj);
+
+    memory_region_init(&s->mmio.container, obj, TYPE_IMX8MP_ANALOG, 0x10000);
+
+    memory_region_init_io(&s->mmio.analog, obj, &imx8mp_analog_ops, s,
+                          TYPE_IMX8MP_ANALOG, sizeof(s->analog));
+    memory_region_add_subregion(&s->mmio.container, 0, &s->mmio.analog);
+
+    sysbus_init_mmio(sd, &s->mmio.container);
+}
+
+static const VMStateDescription vmstate_imx8mp_analog = {
+    .name = TYPE_IMX8MP_ANALOG,
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .fields = (const VMStateField[]) {
+        VMSTATE_UINT32_ARRAY(analog, IMX8MPAnalogState, ANALOG_MAX),
+        VMSTATE_END_OF_LIST()
+    },
+};
+
+static void imx8mp_analog_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    device_class_set_legacy_reset(dc, imx8mp_analog_reset);
+    dc->vmsd  = &vmstate_imx8mp_analog;
+    dc->desc  = "i.MX 8M Plus Analog Module";
+}
+
+static const TypeInfo imx8mp_ccm_types[] = {

hw/misc/imx8mp_analog.c line 160

Quoted 10 lines
hw/misc/imx8mp_analog.c new file +10 -0
+    {
+        .name          = TYPE_IMX8MP_ANALOG,
+        .parent        = TYPE_SYS_BUS_DEVICE,
+        .instance_size = sizeof(IMX8MPAnalogState),
+        .instance_init = imx8mp_analog_init,
+        .class_init    = imx8mp_analog_class_init,
+    }
+};
+
+DEFINE_TYPES(imx8mp_ccm_types);

s/imx8mp_ccm_types/imx8mp_analog_types/ will be fixed in next iteration

Quoted 224 lines
hw/misc/imx8mp_ccm.c new file +175 -0
new file mode 100644
index 0000000000..7c869ff86b
@@ -0,0 +1,175 @@
+/*
+ * Copyright (c) 2025 Bernhard Beschow <[email protected]>
+ *
+ * i.MX 8M Plus CCM IP block emulation code
+ *
+ * Based on hw/misc/imx7_ccm.c
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/log.h"
+
+#include "hw/misc/imx8mp_ccm.h"
+#include "migration/vmstate.h"
+
+#include "trace.h"
+
+#define CKIH_FREQ 16000000 /* 16MHz crystal input */
+
+static void imx8mp_ccm_reset(DeviceState *dev)
+{
+    IMX8MPCCMState *s = IMX8MP_CCM(dev);
+
+    memset(s->ccm, 0, sizeof(s->ccm));
+}
+
+#define CCM_INDEX(offset)   (((offset) & ~(hwaddr)0xF) / sizeof(uint32_t))
+#define CCM_BITOP(offset)   ((offset) & (hwaddr)0xF)
+
+enum {
+    CCM_BITOP_NONE = 0x00,
+    CCM_BITOP_SET  = 0x04,
+    CCM_BITOP_CLR  = 0x08,
+    CCM_BITOP_TOG  = 0x0C,
+};
+
+static uint64_t imx8mp_set_clr_tog_read(void *opaque, hwaddr offset,
+                                        unsigned size)
+{
+    const uint32_t *mmio = opaque;
+
+    return mmio[CCM_INDEX(offset)];
+}
+
+static void imx8mp_set_clr_tog_write(void *opaque, hwaddr offset,
+                                     uint64_t value, unsigned size)
+{
+    const uint8_t  bitop = CCM_BITOP(offset);
+    const uint32_t index = CCM_INDEX(offset);
+    uint32_t *mmio = opaque;
+
+    switch (bitop) {
+    case CCM_BITOP_NONE:
+        mmio[index]  = value;
+        break;
+    case CCM_BITOP_SET:
+        mmio[index] |= value;
+        break;
+    case CCM_BITOP_CLR:
+        mmio[index] &= ~value;
+        break;
+    case CCM_BITOP_TOG:
+        mmio[index] ^= value;
+        break;
+    };
+}
+
+static const struct MemoryRegionOps imx8mp_set_clr_tog_ops = {
+    .read = imx8mp_set_clr_tog_read,
+    .write = imx8mp_set_clr_tog_write,
+    .endianness = DEVICE_NATIVE_ENDIAN,
+    .impl = {
+        /*
+         * Our device would not work correctly if the guest was doing
+         * unaligned access. This might not be a limitation on the real
+         * device but in practice there is no reason for a guest to access
+         * this device unaligned.
+         */
+        .min_access_size = 4,
+        .max_access_size = 4,
+        .unaligned = false,
+    },
+};
+
+static void imx8mp_ccm_init(Object *obj)
+{
+    SysBusDevice *sd = SYS_BUS_DEVICE(obj);
+    IMX8MPCCMState *s = IMX8MP_CCM(obj);
+
+    memory_region_init_io(&s->iomem,
+                          obj,
+                          &imx8mp_set_clr_tog_ops,
+                          s->ccm,
+                          TYPE_IMX8MP_CCM ".ccm",
+                          sizeof(s->ccm));
+
+    sysbus_init_mmio(sd, &s->iomem);
+}
+
+static const VMStateDescription vmstate_imx8mp_ccm = {
+    .name = TYPE_IMX8MP_CCM,
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .fields = (const VMStateField[]) {
+        VMSTATE_UINT32_ARRAY(ccm, IMX8MPCCMState, CCM_MAX),
+        VMSTATE_END_OF_LIST()
+    },
+};
+
+static uint32_t imx8mp_ccm_get_clock_frequency(IMXCCMState *dev, IMXClk clock)
+{
+    /*
+     * This function is "consumed" by GPT emulation code. Some clocks
+     * have fixed frequencies and we can provide requested frequency
+     * easily. However for CCM provided clocks (like IPG) each GPT
+     * timer can have its own clock root.
+     * This means we need additional information when calling this
+     * function to know the requester's identity.
+     */
+    uint32_t freq = 0;
+
+    switch (clock) {
+    case CLK_NONE:
+        break;
+    case CLK_32k:
+        freq = CKIL_FREQ;
+        break;
+    case CLK_HIGH:
+        freq = CKIH_FREQ;
+        break;
+    case CLK_IPG:
+    case CLK_IPG_HIGH:
+        /*
+         * For now we don't have a way to figure out the device this
+         * function is called for. Until then the IPG derived clocks
+         * are left unimplemented.
+         */
+        qemu_log_mask(LOG_GUEST_ERROR, "[%s]%s: Clock %d Not implemented\n",
+                      TYPE_IMX8MP_CCM, __func__, clock);
+        break;
+    default:
+        qemu_log_mask(LOG_GUEST_ERROR, "[%s]%s: unsupported clock %d\n",
+                      TYPE_IMX8MP_CCM, __func__, clock);
+        break;
+    }
+
+    trace_ccm_clock_freq(clock, freq);
+
+    return freq;
+}
+
+static void imx8mp_ccm_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    IMXCCMClass *ccm = IMX_CCM_CLASS(klass);
+
+    device_class_set_legacy_reset(dc, imx8mp_ccm_reset);
+    dc->vmsd  = &vmstate_imx8mp_ccm;
+    dc->desc  = "i.MX 8M Plus Clock Control Module";
+
+    ccm->get_clock_frequency = imx8mp_ccm_get_clock_frequency;
+}
+
+static const TypeInfo imx8mp_ccm_types[] = {
+    {
+        .name          = TYPE_IMX8MP_CCM,
+        .parent        = TYPE_IMX_CCM,
+        .instance_size = sizeof(IMX8MPCCMState),
+        .instance_init = imx8mp_ccm_init,
+        .class_init    = imx8mp_ccm_class_init,
+    },
+};
+
+DEFINE_TYPES(imx8mp_ccm_types);
hw/arm/Kconfig +0 -0
index e22916df57..0079c51734 100644
@@ -580,6 +580,8 @@ config FSL_IMX7

config FSL_IMX8MP
bool
select ARM_GIC

hw/arm/Kconfig +2 -0
+    select FSL_IMX8MP_ANALOG
+    select FSL_IMX8MP_CCM
    select IMX
    select UNIMP
hw/misc/Kconfig +6 -0
index 4271e2f4ac..82bd68b4bb 100644
@@ -78,6 +78,12 @@ config IMX
    select SSI
    select USB_EHCI_SYSBUS
 
+config FSL_IMX8MP_ANALOG
+    bool
+
+config FSL_IMX8MP_CCM
+    bool
+

config STM32_RCC
bool

hw/misc/meson.build +2 -0
index 55f493521b..f9285cf2f1 100644
@@ -55,6 +55,8 @@ system_ss.add(when: 'CONFIG_AXP2XX_PMU', if_true: files('axp2xx.c'))
 system_ss.add(when: 'CONFIG_REALVIEW', if_true: files('arm_sysctl.c'))
 system_ss.add(when: 'CONFIG_ECCMEMCTL', if_true: files('eccmemctl.c'))
 system_ss.add(when: 'CONFIG_EXYNOS4', if_true: files('exynos4210_pmu.c', 'exynos4210_clk.c', 'exynos4210_rng.c'))
+system_ss.add(when: 'CONFIG_FSL_IMX8MP_ANALOG', if_true: files('imx8mp_analog.c'))
+system_ss.add(when: 'CONFIG_FSL_IMX8MP_CCM', if_true: files('imx8mp_ccm.c'))

system_ss.add(when: 'CONFIG_IMX', if_true: files(
'imx25_ccm.c',
'imx31_ccm.c',

#17 lore raw

PATCH v2 6/18 hw/arm/fsl-imx8mp: Add SNVS

In reply to Bernhard Beschow

SNVS contains an RTC which allows Linux to deal correctly with time. This is particularly useful when handling persistent storage which will be done in the next patch.

---
 docs/system/arm/imx8mp-evk.rst |  1 +
 include/hw/arm/fsl-imx8mp.h    |  2 ++
 hw/arm/fsl-imx8mp.c            | 10 ++++++++++
 3 files changed, 13 insertions(+)
docs/system/arm/imx8mp-evk.rst +1 -0
index e5039fc8c4..8f1237c74e 100644
@@ -13,6 +13,7 @@ The ``imx8mp-evk`` machine implements the following devices:
  * Up to 4 Cortex-A53 Cores
  * Generic Interrupt Controller (GICv3)
  * 4 UARTs
+ * Secure Non-Volatile Storage (SNVS) including an RTC
  * Clock Tree
 
 Boot options
include/hw/arm/fsl-imx8mp.h +2 -0
index ce5188e7f2..26e24e99a1 100644
@@ -12,6 +12,7 @@
 #include "cpu.h"
 #include "hw/char/imx_serial.h"
 #include "hw/intc/arm_gicv3_common.h"
+#include "hw/misc/imx7_snvs.h"
 #include "hw/misc/imx8mp_analog.h"
 #include "hw/misc/imx8mp_ccm.h"
 #include "qom/object.h"
@@ -36,6 +37,7 @@ struct FslImx8mpState {
     GICv3State         gic;
     IMX8MPCCMState     ccm;
     IMX8MPAnalogState  analog;
+    IMX7SNVSState      snvs;
     IMXSerialState     uart[FSL_IMX8MP_NUM_UARTS];
 };
 
hw/arm/fsl-imx8mp.c +10 -0
index a1a8843b3b..32ca76c671 100644
@@ -204,6 +204,8 @@ static void fsl_imx8mp_init(Object *obj)
 
     object_initialize_child(obj, "analog", &s->analog, TYPE_IMX8MP_ANALOG);
 
+    object_initialize_child(obj, "snvs", &s->snvs, TYPE_IMX7_SNVS);
+
     for (i = 0; i < FSL_IMX8MP_NUM_UARTS; i++) {
         snprintf(name, NAME_SIZE, "uart%d", i + 1);
         object_initialize_child(obj, name, &s->uart[i], TYPE_IMX_SERIAL);
@@ -348,6 +350,13 @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp)
                            qdev_get_gpio_in(gicdev, serial_table[i].irq));
     }
 
+    /* SNVS */
+    if (!sysbus_realize(SYS_BUS_DEVICE(&s->snvs), errp)) {
+        return;
+    }
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->snvs), 0,
+                    fsl_imx8mp_memmap[FSL_IMX8MP_SNVS_HP].addr);
+
     /* Unimplemented devices */
     for (i = 0; i < ARRAY_SIZE(fsl_imx8mp_memmap); i++) {
         switch (i) {
@@ -356,6 +365,7 @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp)
         case FSL_IMX8MP_GIC_DIST:
         case FSL_IMX8MP_GIC_REDIST:
         case FSL_IMX8MP_RAM:
+        case FSL_IMX8MP_SNVS_HP:
         case FSL_IMX8MP_UART1 ... FSL_IMX8MP_UART4:
             /* device implemented and treated above */
             break;
Signature · 1 line
2.48.1
#18 lore raw

PATCH v2 7/18 hw/arm/fsl-imx8mp: Add USDHC storage controllers

In reply to Bernhard Beschow

The USDHC emulation allows for running real-world images such as those generated by Buildroot. Convert the board documentation accordingly instead of running a Linux kernel with ephemeral storage.

---
 docs/system/arm/imx8mp-evk.rst | 16 +++++++++++-----
 include/hw/arm/fsl-imx8mp.h    |  7 +++++++
 hw/arm/fsl-imx8mp.c            | 28 ++++++++++++++++++++++++++++
 hw/arm/imx8mp-evk.c            | 18 ++++++++++++++++++
 hw/arm/Kconfig                 |  1 +
 5 files changed, 65 insertions(+), 5 deletions(-)
docs/system/arm/imx8mp-evk.rst +11 -5
index 8f1237c74e..475c42d76a 100644
@@ -13,6 +13,7 @@ The ``imx8mp-evk`` machine implements the following devices:
  * Up to 4 Cortex-A53 Cores
  * Generic Interrupt Controller (GICv3)
  * 4 UARTs
+ * 3 USDHC Storage Controllers
  * Secure Non-Volatile Storage (SNVS) including an RTC
  * Clock Tree
 
@@ -27,17 +28,22 @@ Direct Linux Kernel Boot
 
 Probably the easiest way to get started with a whole Linux system on the machine
 is to generate an image with Buildroot. Version 2024.11.1 is tested at the time
-of writing and involves two steps. First run the following commands in the
+of writing and involves three steps. First run the following commands in the
 toplevel directory of the Buildroot source tree:
 
 .. code-block:: bash
 
-  $ echo "BR2_TARGET_ROOTFS_CPIO=y" >> configs/freescale_imx8mpevk_defconfig
   $ make freescale_imx8mpevk_defconfig
   $ make
 
 Once finished successfully there is an ``output/image`` subfolder. Navigate into
-it patch the device tree needs to be patched with the following commands which
+it and resize the SD card image to a power of two:
+
+.. code-block:: bash
+
+  $ qemu-img resize sdcard.img 256M
+
+Finally, the device tree needs to be patched with the following commands which
 will remove the ``cpu-idle-states`` properties from CPU nodes:
 
 .. code-block:: bash
@@ -54,5 +60,5 @@ Now that everything is prepared the newly built image can be run in the QEMU
       -display none -serial null -serial stdio \
       -kernel Image \
       -dtb imx8mp-evk-patched.dtb \
-      -initrd rootfs.cpio \
-      -append "root=/dev/ram"
+      -append "root=/dev/mmcblk2p2" \
+      -drive file=sdcard.img,if=sd,bus=2,format=raw,id=mmcblk2
include/hw/arm/fsl-imx8mp.h +7 -0
index 26e24e99a1..349d55ca88 100644
@@ -15,6 +15,7 @@
 #include "hw/misc/imx7_snvs.h"
 #include "hw/misc/imx8mp_analog.h"
 #include "hw/misc/imx8mp_ccm.h"
+#include "hw/sd/sdhci.h"
 #include "qom/object.h"
 #include "qemu/units.h"
 
@@ -28,6 +29,7 @@ enum FslImx8mpConfiguration {
     FSL_IMX8MP_NUM_CPUS         = 4,
     FSL_IMX8MP_NUM_IRQS         = 160,
     FSL_IMX8MP_NUM_UARTS        = 4,
+    FSL_IMX8MP_NUM_USDHCS       = 3,
 };
 
 struct FslImx8mpState {
@@ -39,6 +41,7 @@ struct FslImx8mpState {
     IMX8MPAnalogState  analog;
     IMX7SNVSState      snvs;
     IMXSerialState     uart[FSL_IMX8MP_NUM_UARTS];
+    SDHCIState         usdhc[FSL_IMX8MP_NUM_USDHCS];
 };
 
 enum FslImx8mpMemoryRegions {
@@ -184,6 +187,10 @@ enum FslImx8mpMemoryRegions {
 };
 
 enum FslImx8mpIrqs {
+    FSL_IMX8MP_USDHC1_IRQ   = 22,
+    FSL_IMX8MP_USDHC2_IRQ   = 23,
+    FSL_IMX8MP_USDHC3_IRQ   = 24,
+
     FSL_IMX8MP_UART1_IRQ    = 26,
     FSL_IMX8MP_UART2_IRQ    = 27,
     FSL_IMX8MP_UART3_IRQ    = 28,
hw/arm/fsl-imx8mp.c +28 -0
index 32ca76c671..3e9fedf988 100644
@@ -210,6 +210,11 @@ static void fsl_imx8mp_init(Object *obj)
         snprintf(name, NAME_SIZE, "uart%d", i + 1);
         object_initialize_child(obj, name, &s->uart[i], TYPE_IMX_SERIAL);
     }
+
+    for (i = 0; i < FSL_IMX8MP_NUM_USDHCS; i++) {
+        snprintf(name, NAME_SIZE, "usdhc%d", i + 1);
+        object_initialize_child(obj, name, &s->usdhc[i], TYPE_IMX_USDHC);
+    }
 }
 
 static void fsl_imx8mp_realize(DeviceState *dev, Error **errp)
@@ -350,6 +355,28 @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp)
                            qdev_get_gpio_in(gicdev, serial_table[i].irq));
     }
 
+    /* USDHCs */
+    for (i = 0; i < FSL_IMX8MP_NUM_USDHCS; i++) {
+        static const struct {
+            hwaddr addr;
+            unsigned int irq;
+        } usdhc_table[FSL_IMX8MP_NUM_USDHCS] = {
+            { fsl_imx8mp_memmap[FSL_IMX8MP_USDHC1].addr, FSL_IMX8MP_USDHC1_IRQ },
+            { fsl_imx8mp_memmap[FSL_IMX8MP_USDHC2].addr, FSL_IMX8MP_USDHC2_IRQ },
+            { fsl_imx8mp_memmap[FSL_IMX8MP_USDHC3].addr, FSL_IMX8MP_USDHC3_IRQ },
+        };
+
+        object_property_set_uint(OBJECT(&s->usdhc[i]), "vendor",
+                                 SDHCI_VENDOR_IMX, &error_abort);
+        if (!sysbus_realize(SYS_BUS_DEVICE(&s->usdhc[i]), errp)) {
+            return;
+        }
+
+        sysbus_mmio_map(SYS_BUS_DEVICE(&s->usdhc[i]), 0, usdhc_table[i].addr);
+        sysbus_connect_irq(SYS_BUS_DEVICE(&s->usdhc[i]), 0,
+                           qdev_get_gpio_in(gicdev, usdhc_table[i].irq));
+    }
+
     /* SNVS */
     if (!sysbus_realize(SYS_BUS_DEVICE(&s->snvs), errp)) {
         return;
@@ -367,6 +394,7 @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp)
         case FSL_IMX8MP_RAM:
         case FSL_IMX8MP_SNVS_HP:
         case FSL_IMX8MP_UART1 ... FSL_IMX8MP_UART4:
+        case FSL_IMX8MP_USDHC1 ... FSL_IMX8MP_USDHC3:
             /* device implemented and treated above */
             break;
 
hw/arm/imx8mp-evk.c +18 -0
index 2756d4c21c..27d9e9e8ee 100644
@@ -11,6 +11,7 @@
 #include "hw/arm/boot.h"
 #include "hw/arm/fsl-imx8mp.h"
 #include "hw/boards.h"
+#include "hw/qdev-properties.h"
 #include "system/qtest.h"
 #include "qemu/error-report.h"
 #include "qapi/error.h"
@@ -40,6 +41,23 @@ static void imx8mp_evk_init(MachineState *machine)
     memory_region_add_subregion(get_system_memory(), FSL_IMX8MP_RAM_START,
                                 machine->ram);
 
+    for (int i = 0; i < FSL_IMX8MP_NUM_USDHCS; i++) {
+        BusState *bus;
+        DeviceState *carddev;
+        BlockBackend *blk;
+        DriveInfo *di = drive_get(IF_SD, i, 0);
+
+        if (!di) {
+            continue;
+        }
+
+        blk = blk_by_legacy_dinfo(di);
+        bus = qdev_get_child_bus(DEVICE(&s->usdhc[i]), "sd-bus");
+        carddev = qdev_new(TYPE_SD_CARD);
+        qdev_prop_set_drive_err(carddev, "drive", blk, &error_fatal);
+        qdev_realize_and_unref(carddev, bus, &error_fatal);
+    }
+
     if (!qtest_enabled()) {
         arm_load_kernel(&s->cpu[0], machine, &boot_info);
     }
hw/arm/Kconfig +1 -0
index 0079c51734..7af8337354 100644
@@ -583,6 +583,7 @@ config FSL_IMX8MP
     select FSL_IMX8MP_ANALOG
     select FSL_IMX8MP_CCM
     select IMX
+    select SDHCI
     select UNIMP
 
 config FSL_IMX8MP_EVK
Signature · 1 line
2.48.1
Reviewed-by on v2 7/18
#19 lore raw

Re: [PATCH v2 07/18] hw/arm/fsl-imx8mp: Add USDHC storage controllers

Quoted 5 lines · Bernhard Beschow

The USDHC emulation allows for running real-world images such as those generated by Buildroot. Convert the board documentation accordingly instead of running a Linux kernel with ephemeral storage.

Quoted 8 lines
---
 docs/system/arm/imx8mp-evk.rst | 16 +++++++++++-----
 include/hw/arm/fsl-imx8mp.h    |  7 +++++++
 hw/arm/fsl-imx8mp.c            | 28 ++++++++++++++++++++++++++++
 hw/arm/imx8mp-evk.c            | 18 ++++++++++++++++++
 hw/arm/Kconfig                 |  1 +
 5 files changed, 65 insertions(+), 5 deletions(-)

thanks
-- PMM

#20 lore raw

PATCH v2 8/18 hw/arm/fsl-imx8mp: Add PCIe support

In reply to Bernhard Beschow

Linux checks for the PLLs in the PHY to be locked, so implement a model emulating that.

---
 MAINTAINERS                         |  2 +
 docs/system/arm/imx8mp-evk.rst      |  1 +
 include/hw/arm/fsl-imx8mp.h         | 10 ++++
 include/hw/pci-host/fsl_imx8m_phy.h | 27 +++++++++
 hw/arm/fsl-imx8mp.c                 | 30 ++++++++++
 hw/pci-host/fsl_imx8m_phy.c         | 88 +++++++++++++++++++++++++++++
 hw/arm/Kconfig                      |  3 +
 hw/pci-host/Kconfig                 |  3 +
 hw/pci-host/meson.build             |  1 +
 9 files changed, 165 insertions(+)
 create mode 100644 include/hw/pci-host/fsl_imx8m_phy.h
 create mode 100644 hw/pci-host/fsl_imx8m_phy.c
MAINTAINERS +2 -0
index 5b5b0d0bed..94af3d90e4 100644
@@ -827,8 +827,10 @@ S: Maintained
 F: hw/arm/imx8mp-evk.c
 F: hw/arm/fsl-imx8mp.c
 F: hw/misc/imx8mp_*.c
+F: hw/pci-host/fsl_imx8m_phy.c
 F: include/hw/arm/fsl-imx8mp.h
 F: include/hw/misc/imx8mp_*.h
+F: include/hw/pci-host/fsl_imx8m_phy.h
 F: docs/system/arm/imx8mp-evk.rst
 
 MPS2 / MPS3
docs/system/arm/imx8mp-evk.rst +1 -0
index 475c42d76a..39df695df7 100644
@@ -14,6 +14,7 @@ The ``imx8mp-evk`` machine implements the following devices:
  * Generic Interrupt Controller (GICv3)
  * 4 UARTs
  * 3 USDHC Storage Controllers
+ * 1 Designware PCI Express Controller
  * Secure Non-Volatile Storage (SNVS) including an RTC
  * Clock Tree
 
include/hw/arm/fsl-imx8mp.h +10 -0
index 349d55ca88..4c70c887a8 100644
@@ -15,6 +15,8 @@
 #include "hw/misc/imx7_snvs.h"
 #include "hw/misc/imx8mp_analog.h"
 #include "hw/misc/imx8mp_ccm.h"
+#include "hw/pci-host/designware.h"
+#include "hw/pci-host/fsl_imx8m_phy.h"
 #include "hw/sd/sdhci.h"
 #include "qom/object.h"
 #include "qemu/units.h"
@@ -42,6 +44,8 @@ struct FslImx8mpState {
     IMX7SNVSState      snvs;
     IMXSerialState     uart[FSL_IMX8MP_NUM_UARTS];
     SDHCIState         usdhc[FSL_IMX8MP_NUM_USDHCS];
+    DesignwarePCIEHost pcie;
+    FslImx8mPciePhyState   pcie_phy;
 };
 
 enum FslImx8mpMemoryRegions {
@@ -197,6 +201,12 @@ enum FslImx8mpIrqs {
     FSL_IMX8MP_UART4_IRQ    = 29,
     FSL_IMX8MP_UART5_IRQ    = 30,
     FSL_IMX8MP_UART6_IRQ    = 16,
+
+    FSL_IMX8MP_PCI_INTA_IRQ = 126,
+    FSL_IMX8MP_PCI_INTB_IRQ = 125,
+    FSL_IMX8MP_PCI_INTC_IRQ = 124,
+    FSL_IMX8MP_PCI_INTD_IRQ = 123,
+    FSL_IMX8MP_PCI_MSI_IRQ  = 140,
 };
 
 #endif /* FSL_IMX8MP_H */
include/hw/pci-host/fsl_imx8m_phy.h new file +27 -0
new file mode 100644
index 0000000000..385a904fff
@@ -0,0 +1,27 @@
+/*
+ * i.MX8 PCIe PHY emulation
+ *
+ * Copyright (c) 2025 Bernhard Beschow <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef HW_PCIHOST_FSLIMX8MPCIEPHY_H
+#define HW_PCIHOST_FSLIMX8MPCIEPHY_H
+
+#include "hw/sysbus.h"
+#include "qom/object.h"
+#include "exec/memory.h"
+
+#define TYPE_FSL_IMX8M_PCIE_PHY "fsl-imx8m-pcie-phy"
+
+OBJECT_DECLARE_SIMPLE_TYPE(FslImx8mPciePhyState, FSL_IMX8M_PCIE_PHY)
+
+struct FslImx8mPciePhyState {
+    SysBusDevice parent_obj;
+
+    MemoryRegion iomem;
+    uint8_t data[0x800];
+};
+
+#endif
hw/arm/fsl-imx8mp.c +30 -0
index 3e9fedf988..faa6ada183 100644
@@ -215,6 +215,10 @@ static void fsl_imx8mp_init(Object *obj)
         snprintf(name, NAME_SIZE, "usdhc%d", i + 1);
         object_initialize_child(obj, name, &s->usdhc[i], TYPE_IMX_USDHC);
     }
+
+    object_initialize_child(obj, "pcie", &s->pcie, TYPE_DESIGNWARE_PCIE_HOST);
+    object_initialize_child(obj, "pcie_phy", &s->pcie_phy,
+                            TYPE_FSL_IMX8M_PCIE_PHY);
 }
 
 static void fsl_imx8mp_realize(DeviceState *dev, Error **errp)
@@ -384,6 +388,30 @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp)
     sysbus_mmio_map(SYS_BUS_DEVICE(&s->snvs), 0,
                     fsl_imx8mp_memmap[FSL_IMX8MP_SNVS_HP].addr);
 
+    /* PCIe */
+    if (!sysbus_realize(SYS_BUS_DEVICE(&s->pcie), errp)) {
+        return;
+    }
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->pcie), 0,
+                    fsl_imx8mp_memmap[FSL_IMX8MP_PCIE1].addr);
+
+    sysbus_connect_irq(SYS_BUS_DEVICE(&s->pcie), 0,
+                       qdev_get_gpio_in(gicdev, FSL_IMX8MP_PCI_INTA_IRQ));
+    sysbus_connect_irq(SYS_BUS_DEVICE(&s->pcie), 1,
+                       qdev_get_gpio_in(gicdev, FSL_IMX8MP_PCI_INTB_IRQ));
+    sysbus_connect_irq(SYS_BUS_DEVICE(&s->pcie), 2,
+                       qdev_get_gpio_in(gicdev, FSL_IMX8MP_PCI_INTC_IRQ));
+    sysbus_connect_irq(SYS_BUS_DEVICE(&s->pcie), 3,
+                       qdev_get_gpio_in(gicdev, FSL_IMX8MP_PCI_INTD_IRQ));
+    sysbus_connect_irq(SYS_BUS_DEVICE(&s->pcie), 4,
+                       qdev_get_gpio_in(gicdev, FSL_IMX8MP_PCI_MSI_IRQ));
+
+    if (!sysbus_realize(SYS_BUS_DEVICE(&s->pcie_phy), errp)) {
+        return;
+    }
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->pcie_phy), 0,
+                    fsl_imx8mp_memmap[FSL_IMX8MP_PCIE_PHY1].addr);
+
     /* Unimplemented devices */
     for (i = 0; i < ARRAY_SIZE(fsl_imx8mp_memmap); i++) {
         switch (i) {
@@ -391,6 +419,8 @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp)
         case FSL_IMX8MP_CCM:
         case FSL_IMX8MP_GIC_DIST:
         case FSL_IMX8MP_GIC_REDIST:
+        case FSL_IMX8MP_PCIE1:
+        case FSL_IMX8MP_PCIE_PHY1:
         case FSL_IMX8MP_RAM:
         case FSL_IMX8MP_SNVS_HP:
         case FSL_IMX8MP_UART1 ... FSL_IMX8MP_UART4:
hw/pci-host/fsl_imx8m_phy.c new file +88 -0

88 lines not on this page · raw message

hw/arm/Kconfig +3 -0
index 7af8337354..f1e140a29d 100644
@@ -579,10 +579,13 @@ config FSL_IMX7
 
 config FSL_IMX8MP
     bool
+    imply PCI_DEVICES
     select ARM_GIC
     select FSL_IMX8MP_ANALOG
     select FSL_IMX8MP_CCM
     select IMX
+    select PCI_EXPRESS_DESIGNWARE
+    select PCI_EXPRESS_FSL_IMX8M_PHY
     select SDHCI
     select UNIMP
 
hw/pci-host/Kconfig +3 -0
index c91880b237..35c0415242 100644
@@ -99,6 +99,9 @@ config ASTRO
     bool
     select PCI
 
+config PCI_EXPRESS_FSL_IMX8M_PHY
+    bool
+
 config GT64120
     bool
     select PCI
hw/pci-host/meson.build +1 -0
index 3001e93a43..937a0f72ac 100644
@@ -28,6 +28,7 @@ pci_ss.add(when: 'CONFIG_ARTICIA', if_true: files('articia.c'))
 pci_ss.add(when: 'CONFIG_MV64361', if_true: files('mv64361.c'))
 
 # ARM devices
+pci_ss.add(when: 'CONFIG_PCI_EXPRESS_FSL_IMX8M_PHY', if_true: files('fsl_imx8m_phy.c'))
 pci_ss.add(when: 'CONFIG_VERSATILE_PCI', if_true: files('versatile.c'))
 
 # HPPA devices
Signature · 1 line
2.48.1
#21 lore raw

Re: [PATCH v2 08/18] hw/arm/fsl-imx8mp: Add PCIe support

Quoted 7 lines · Bernhard Beschow

Linux checks for the PLLs in the PHY to be locked, so implement a model emulating that.

---

hw/pci-host/fsl_imx8m_phy.c line 66

Quoted 7 lines
hw/pci-host/fsl_imx8m_phy.c new file +7 -0
+static const VMStateDescription fsl_imx8m_pcie_phy_vmstate = {
+    .name = "fsl-imx8m-pcie-phy",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .fields = (const VMStateField[]) {
+        VMSTATE_UINT8_ARRAY(data, FslImx8mPciePhyState,
+                            ARRAY_SIZE(((FslImx8mPciePhyState *)NULL)->data)),

Use a defined constant for the number of array elements, please. We don't do this thing with ARRAY_SIZE of a cast NULL pointer anywhere else in the codebase.

hw/pci-host/fsl_imx8m_phy.c line 77

Quoted 11 lines
hw/pci-host/fsl_imx8m_phy.c new file +11 -0
+        VMSTATE_END_OF_LIST()
+    }
+};
+
+static void fsl_imx8m_pcie_phy_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    dc->realize = fsl_imx8m_pcie_phy_realize;
+    dc->vmsd = &fsl_imx8m_pcie_phy_vmstate;
+}

This is missing the reset method.

thanks
-- PMM

#22 lore raw

Re: [PATCH v2 08/18] hw/arm/fsl-imx8mp: Add PCIe support

Am 17. Februar 2025 13:40:48 UTC schrieb Peter Maydell <[email protected]>:

Quoted 16 lines · Bernhard Beschow
Quoted 7 lines

Linux checks for the PLLs in the PHY to be locked, so implement a model emulating that.

---

hw/pci-host/fsl_imx8m_phy.c line 66

Quoted 7 lines
hw/pci-host/fsl_imx8m_phy.c new file +7 -0
+static const VMStateDescription fsl_imx8m_pcie_phy_vmstate = {
+    .name = "fsl-imx8m-pcie-phy",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .fields = (const VMStateField[]) {
+        VMSTATE_UINT8_ARRAY(data, FslImx8mPciePhyState,
+                            ARRAY_SIZE(((FslImx8mPciePhyState *)NULL)->data)),
Quoted 3 lines

Use a defined constant for the number of array elements, please. We don't do this thing with ARRAY_SIZE of a cast NULL pointer anywhere else in the codebase.

Ack -- will change to a named constant. I think I took inspiration from <https://gitlab.com/qemu-project/qemu/-/blob/v9.2.1/hw/scsi/vmw_pvscsi.c?ref_type=tags#L1276>

Quoted 14 lines

hw/pci-host/fsl_imx8m_phy.c line 77

Quoted 12 lines
hw/pci-host/fsl_imx8m_phy.c new file +11 -0
+        VMSTATE_END_OF_LIST()
+    }
+};
+
+static void fsl_imx8m_pcie_phy_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    dc->realize = fsl_imx8m_pcie_phy_realize;
+    dc->vmsd = &fsl_imx8m_pcie_phy_vmstate;
+}

This is missing the reset method.

Indeed. I'll add it.

Thanks for the review,
Bernhard

Quoted 3 lines

thanks
-- PMM

#23 lore raw

PATCH v2 9/18 hw/arm/fsl-imx8mp: Add GPIO controllers

In reply to Bernhard Beschow
---
 docs/system/arm/imx8mp-evk.rst |  1 +
 include/hw/arm/fsl-imx8mp.h    | 14 +++++++++
 hw/arm/fsl-imx8mp.c            | 55 ++++++++++++++++++++++++++++++++++
 3 files changed, 70 insertions(+)
docs/system/arm/imx8mp-evk.rst +1 -0
index 39df695df7..a89aad6f92 100644
@@ -15,6 +15,7 @@ The ``imx8mp-evk`` machine implements the following devices:
  * 4 UARTs
  * 3 USDHC Storage Controllers
  * 1 Designware PCI Express Controller
+ * 5 GPIO Controllers
  * Secure Non-Volatile Storage (SNVS) including an RTC
  * Clock Tree
 
include/hw/arm/fsl-imx8mp.h +14 -0
index 4c70c887a8..18ea52d083 100644
@@ -11,6 +11,7 @@
 
 #include "cpu.h"
 #include "hw/char/imx_serial.h"
+#include "hw/gpio/imx_gpio.h"
 #include "hw/intc/arm_gicv3_common.h"
 #include "hw/misc/imx7_snvs.h"
 #include "hw/misc/imx8mp_analog.h"
@@ -29,6 +30,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(FslImx8mpState, FSL_IMX8MP)
 
 enum FslImx8mpConfiguration {
     FSL_IMX8MP_NUM_CPUS         = 4,
+    FSL_IMX8MP_NUM_GPIOS        = 5,
     FSL_IMX8MP_NUM_IRQS         = 160,
     FSL_IMX8MP_NUM_UARTS        = 4,
     FSL_IMX8MP_NUM_USDHCS       = 3,
@@ -39,6 +41,7 @@ struct FslImx8mpState {
 
     ARMCPU             cpu[FSL_IMX8MP_NUM_CPUS];
     GICv3State         gic;
+    IMXGPIOState       gpio[FSL_IMX8MP_NUM_GPIOS];
     IMX8MPCCMState     ccm;
     IMX8MPAnalogState  analog;
     IMX7SNVSState      snvs;
@@ -202,6 +205,17 @@ enum FslImx8mpIrqs {
     FSL_IMX8MP_UART5_IRQ    = 30,
     FSL_IMX8MP_UART6_IRQ    = 16,
 
+    FSL_IMX8MP_GPIO1_LOW_IRQ  = 64,
+    FSL_IMX8MP_GPIO1_HIGH_IRQ = 65,
+    FSL_IMX8MP_GPIO2_LOW_IRQ  = 66,
+    FSL_IMX8MP_GPIO2_HIGH_IRQ = 67,
+    FSL_IMX8MP_GPIO3_LOW_IRQ  = 68,
+    FSL_IMX8MP_GPIO3_HIGH_IRQ = 69,
+    FSL_IMX8MP_GPIO4_LOW_IRQ  = 70,
+    FSL_IMX8MP_GPIO4_HIGH_IRQ = 71,
+    FSL_IMX8MP_GPIO5_LOW_IRQ  = 72,
+    FSL_IMX8MP_GPIO5_HIGH_IRQ = 73,
+
     FSL_IMX8MP_PCI_INTA_IRQ = 126,
     FSL_IMX8MP_PCI_INTB_IRQ = 125,
     FSL_IMX8MP_PCI_INTC_IRQ = 124,
hw/arm/fsl-imx8mp.c +55 -0

73 lines not on this page · raw message

Signature · 1 line
2.48.1
#25 lore raw

PATCH v2 10/18 hw/arm/fsl-imx8mp: Add I2C controllers

In reply to Bernhard Beschow
---
 docs/system/arm/imx8mp-evk.rst |  1 +
 include/hw/arm/fsl-imx8mp.h    | 11 +++++++++++
 hw/arm/fsl-imx8mp.c            | 29 +++++++++++++++++++++++++++++
 hw/arm/Kconfig                 |  2 ++
 4 files changed, 43 insertions(+)
docs/system/arm/imx8mp-evk.rst +1 -0
index a89aad6f92..e63c5b7118 100644
@@ -16,6 +16,7 @@ The ``imx8mp-evk`` machine implements the following devices:
  * 3 USDHC Storage Controllers
  * 1 Designware PCI Express Controller
  * 5 GPIO Controllers
+ * 6 I2C Controllers
  * Secure Non-Volatile Storage (SNVS) including an RTC
  * Clock Tree
 
include/hw/arm/fsl-imx8mp.h +11 -0
index 18ea52d083..2590056627 100644
@@ -12,6 +12,7 @@
 #include "cpu.h"
 #include "hw/char/imx_serial.h"
 #include "hw/gpio/imx_gpio.h"
+#include "hw/i2c/imx_i2c.h"
 #include "hw/intc/arm_gicv3_common.h"
 #include "hw/misc/imx7_snvs.h"
 #include "hw/misc/imx8mp_analog.h"
@@ -31,6 +32,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(FslImx8mpState, FSL_IMX8MP)
 enum FslImx8mpConfiguration {
     FSL_IMX8MP_NUM_CPUS         = 4,
     FSL_IMX8MP_NUM_GPIOS        = 5,
+    FSL_IMX8MP_NUM_I2CS         = 6,
     FSL_IMX8MP_NUM_IRQS         = 160,
     FSL_IMX8MP_NUM_UARTS        = 4,
     FSL_IMX8MP_NUM_USDHCS       = 3,
@@ -45,6 +47,7 @@ struct FslImx8mpState {
     IMX8MPCCMState     ccm;
     IMX8MPAnalogState  analog;
     IMX7SNVSState      snvs;
+    IMXI2CState        i2c[FSL_IMX8MP_NUM_I2CS];
     IMXSerialState     uart[FSL_IMX8MP_NUM_UARTS];
     SDHCIState         usdhc[FSL_IMX8MP_NUM_USDHCS];
     DesignwarePCIEHost pcie;
@@ -205,6 +208,11 @@ enum FslImx8mpIrqs {
     FSL_IMX8MP_UART5_IRQ    = 30,
     FSL_IMX8MP_UART6_IRQ    = 16,
 
+    FSL_IMX8MP_I2C1_IRQ     = 35,
+    FSL_IMX8MP_I2C2_IRQ     = 36,
+    FSL_IMX8MP_I2C3_IRQ     = 37,
+    FSL_IMX8MP_I2C4_IRQ     = 38,
+
     FSL_IMX8MP_GPIO1_LOW_IRQ  = 64,
     FSL_IMX8MP_GPIO1_HIGH_IRQ = 65,
     FSL_IMX8MP_GPIO2_LOW_IRQ  = 66,
@@ -216,6 +224,9 @@ enum FslImx8mpIrqs {
     FSL_IMX8MP_GPIO5_LOW_IRQ  = 72,
     FSL_IMX8MP_GPIO5_HIGH_IRQ = 73,
 
+    FSL_IMX8MP_I2C5_IRQ     = 76,
+    FSL_IMX8MP_I2C6_IRQ     = 77,
+
     FSL_IMX8MP_PCI_INTA_IRQ = 126,
     FSL_IMX8MP_PCI_INTB_IRQ = 125,
     FSL_IMX8MP_PCI_INTC_IRQ = 124,
hw/arm/fsl-imx8mp.c +29 -0
index 13910dc44a..1971c76aaa 100644
@@ -211,6 +211,11 @@ static void fsl_imx8mp_init(Object *obj)
         object_initialize_child(obj, name, &s->uart[i], TYPE_IMX_SERIAL);
     }
 
+    for (i = 0; i < FSL_IMX8MP_NUM_I2CS; i++) {
+        snprintf(name, NAME_SIZE, "i2c%d", i + 1);
+        object_initialize_child(obj, name, &s->i2c[i], TYPE_IMX_I2C);
+    }
+
     for (i = 0; i < FSL_IMX8MP_NUM_GPIOS; i++) {
         snprintf(name, NAME_SIZE, "gpio%d", i + 1);
         object_initialize_child(obj, name, &s->gpio[i], TYPE_IMX_GPIO);
@@ -364,6 +369,29 @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp)
                            qdev_get_gpio_in(gicdev, serial_table[i].irq));
     }
 
+    /* I2Cs */
+    for (i = 0; i < FSL_IMX8MP_NUM_I2CS; i++) {
+        static const struct {
+            hwaddr addr;
+            unsigned int irq;
+        } i2c_table[FSL_IMX8MP_NUM_I2CS] = {
+            { fsl_imx8mp_memmap[FSL_IMX8MP_I2C1].addr, FSL_IMX8MP_I2C1_IRQ },
+            { fsl_imx8mp_memmap[FSL_IMX8MP_I2C2].addr, FSL_IMX8MP_I2C2_IRQ },
+            { fsl_imx8mp_memmap[FSL_IMX8MP_I2C3].addr, FSL_IMX8MP_I2C3_IRQ },
+            { fsl_imx8mp_memmap[FSL_IMX8MP_I2C4].addr, FSL_IMX8MP_I2C4_IRQ },
+            { fsl_imx8mp_memmap[FSL_IMX8MP_I2C5].addr, FSL_IMX8MP_I2C5_IRQ },
+            { fsl_imx8mp_memmap[FSL_IMX8MP_I2C6].addr, FSL_IMX8MP_I2C6_IRQ },
+        };
+
+        if (!sysbus_realize(SYS_BUS_DEVICE(&s->i2c[i]), errp)) {
+            return;
+        }
+
+        sysbus_mmio_map(SYS_BUS_DEVICE(&s->i2c[i]), 0, i2c_table[i].addr);
+        sysbus_connect_irq(SYS_BUS_DEVICE(&s->i2c[i]), 0,
+                           qdev_get_gpio_in(gicdev, i2c_table[i].irq));
+    }
+
     /* GPIOs */
     for (i = 0; i < FSL_IMX8MP_NUM_GPIOS; i++) {
         static const struct {
@@ -474,6 +502,7 @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp)
         case FSL_IMX8MP_GIC_DIST:
         case FSL_IMX8MP_GIC_REDIST:
         case FSL_IMX8MP_GPIO1 ... FSL_IMX8MP_GPIO5:
+        case FSL_IMX8MP_I2C1 ... FSL_IMX8MP_I2C6:
         case FSL_IMX8MP_PCIE1:
         case FSL_IMX8MP_PCIE_PHY1:
         case FSL_IMX8MP_RAM:
hw/arm/Kconfig +2 -0
index f1e140a29d..4a8695f22a 100644
@@ -579,11 +579,13 @@ config FSL_IMX7
 
 config FSL_IMX8MP
     bool
+    imply I2C_DEVICES
     imply PCI_DEVICES
     select ARM_GIC
     select FSL_IMX8MP_ANALOG
     select FSL_IMX8MP_CCM
     select IMX
+    select IMX_I2C
     select PCI_EXPRESS_DESIGNWARE
     select PCI_EXPRESS_FSL_IMX8M_PHY
     select SDHCI
Signature · 1 line
2.48.1
Reviewed-by on v2 10/18
#26 lore raw

Re: [PATCH v2 10/18] hw/arm/fsl-imx8mp: Add I2C controllers

Quoted 8 lines · Bernhard Beschow
---
 docs/system/arm/imx8mp-evk.rst |  1 +
 include/hw/arm/fsl-imx8mp.h    | 11 +++++++++++
 hw/arm/fsl-imx8mp.c            | 29 +++++++++++++++++++++++++++++
 hw/arm/Kconfig                 |  2 ++
 4 files changed, 43 insertions(+)

thanks
-- PMM

#27 lore raw

PATCH v2 11/18 hw/arm/fsl-imx8mp: Add SPI controllers

In reply to Bernhard Beschow
---
 docs/system/arm/imx8mp-evk.rst |  1 +
 include/hw/arm/fsl-imx8mp.h    |  8 ++++++++
 hw/arm/fsl-imx8mp.c            | 26 ++++++++++++++++++++++++++
 3 files changed, 35 insertions(+)
docs/system/arm/imx8mp-evk.rst +1 -0
index e63c5b7118..eb7df2059f 100644
@@ -17,6 +17,7 @@ The ``imx8mp-evk`` machine implements the following devices:
  * 1 Designware PCI Express Controller
  * 5 GPIO Controllers
  * 6 I2C Controllers
+ * 3 SPI Controllers
  * Secure Non-Volatile Storage (SNVS) including an RTC
  * Clock Tree
 
include/hw/arm/fsl-imx8mp.h +8 -0
index 2590056627..296a87eb50 100644
@@ -20,6 +20,7 @@
 #include "hw/pci-host/designware.h"
 #include "hw/pci-host/fsl_imx8m_phy.h"
 #include "hw/sd/sdhci.h"
+#include "hw/ssi/imx_spi.h"
 #include "qom/object.h"
 #include "qemu/units.h"
 
@@ -31,6 +32,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(FslImx8mpState, FSL_IMX8MP)
 
 enum FslImx8mpConfiguration {
     FSL_IMX8MP_NUM_CPUS         = 4,
+    FSL_IMX8MP_NUM_ECSPIS       = 3,
     FSL_IMX8MP_NUM_GPIOS        = 5,
     FSL_IMX8MP_NUM_I2CS         = 6,
     FSL_IMX8MP_NUM_IRQS         = 160,
@@ -47,6 +49,7 @@ struct FslImx8mpState {
     IMX8MPCCMState     ccm;
     IMX8MPAnalogState  analog;
     IMX7SNVSState      snvs;
+    IMXSPIState        spi[FSL_IMX8MP_NUM_ECSPIS];
     IMXI2CState        i2c[FSL_IMX8MP_NUM_I2CS];
     IMXSerialState     uart[FSL_IMX8MP_NUM_UARTS];
     SDHCIState         usdhc[FSL_IMX8MP_NUM_USDHCS];
@@ -208,6 +211,11 @@ enum FslImx8mpIrqs {
     FSL_IMX8MP_UART5_IRQ    = 30,
     FSL_IMX8MP_UART6_IRQ    = 16,
 
+    FSL_IMX8MP_ECSPI1_IRQ   = 31,
+    FSL_IMX8MP_ECSPI2_IRQ   = 32,
+    FSL_IMX8MP_ECSPI3_IRQ   = 33,
+    FSL_IMX8MP_ECSPI4_IRQ   = 34,
+
     FSL_IMX8MP_I2C1_IRQ     = 35,
     FSL_IMX8MP_I2C2_IRQ     = 36,
     FSL_IMX8MP_I2C3_IRQ     = 37,
hw/arm/fsl-imx8mp.c +26 -0
index 1971c76aaa..fa39dfd2da 100644
@@ -226,6 +226,11 @@ static void fsl_imx8mp_init(Object *obj)
         object_initialize_child(obj, name, &s->usdhc[i], TYPE_IMX_USDHC);
     }
 
+    for (i = 0; i < FSL_IMX8MP_NUM_ECSPIS; i++) {
+        snprintf(name, NAME_SIZE, "spi%d", i + 1);
+        object_initialize_child(obj, name, &s->spi[i], TYPE_IMX_SPI);
+    }
+
     object_initialize_child(obj, "pcie", &s->pcie, TYPE_DESIGNWARE_PCIE_HOST);
     object_initialize_child(obj, "pcie_phy", &s->pcie_phy,
                             TYPE_FSL_IMX8M_PCIE_PHY);
@@ -463,6 +468,26 @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp)
                            qdev_get_gpio_in(gicdev, usdhc_table[i].irq));
     }
 
+    /* ECSPIs */
+    for (i = 0; i < FSL_IMX8MP_NUM_ECSPIS; i++) {
+        static const struct {
+            hwaddr addr;
+            unsigned int irq;
+        } spi_table[FSL_IMX8MP_NUM_ECSPIS] = {
+            { fsl_imx8mp_memmap[FSL_IMX8MP_ECSPI1].addr, FSL_IMX8MP_ECSPI1_IRQ },
+            { fsl_imx8mp_memmap[FSL_IMX8MP_ECSPI2].addr, FSL_IMX8MP_ECSPI2_IRQ },
+            { fsl_imx8mp_memmap[FSL_IMX8MP_ECSPI3].addr, FSL_IMX8MP_ECSPI3_IRQ },
+        };
+
+        if (!sysbus_realize(SYS_BUS_DEVICE(&s->spi[i]), errp)) {
+            return;
+        }
+
+        sysbus_mmio_map(SYS_BUS_DEVICE(&s->spi[i]), 0, spi_table[i].addr);
+        sysbus_connect_irq(SYS_BUS_DEVICE(&s->spi[i]), 0,
+                           qdev_get_gpio_in(gicdev, spi_table[i].irq));
+    }
+
     /* SNVS */
     if (!sysbus_realize(SYS_BUS_DEVICE(&s->snvs), errp)) {
         return;
@@ -502,6 +527,7 @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp)
         case FSL_IMX8MP_GIC_DIST:
         case FSL_IMX8MP_GIC_REDIST:
         case FSL_IMX8MP_GPIO1 ... FSL_IMX8MP_GPIO5:
+        case FSL_IMX8MP_ECSPI1 ... FSL_IMX8MP_ECSPI3:
         case FSL_IMX8MP_I2C1 ... FSL_IMX8MP_I2C6:
         case FSL_IMX8MP_PCIE1:
         case FSL_IMX8MP_PCIE_PHY1:
Signature · 1 line
2.48.1
#29 lore raw

PATCH v2 12/18 hw/arm/fsl-imx8mp: Add watchdog support

In reply to Bernhard Beschow
---
 docs/system/arm/imx8mp-evk.rst |  1 +
 include/hw/arm/fsl-imx8mp.h    |  7 +++++++
 hw/arm/fsl-imx8mp.c            | 28 ++++++++++++++++++++++++++++
 hw/arm/Kconfig                 |  1 +
 4 files changed, 37 insertions(+)
docs/system/arm/imx8mp-evk.rst +1 -0
index eb7df2059f..15514055b5 100644
@@ -18,6 +18,7 @@ The ``imx8mp-evk`` machine implements the following devices:
  * 5 GPIO Controllers
  * 6 I2C Controllers
  * 3 SPI Controllers
+ * 3 Watchdogs
  * Secure Non-Volatile Storage (SNVS) including an RTC
  * Clock Tree
 
include/hw/arm/fsl-imx8mp.h +7 -0
index 296a87eb50..dfbdc6ac7f 100644
@@ -21,6 +21,7 @@
 #include "hw/pci-host/fsl_imx8m_phy.h"
 #include "hw/sd/sdhci.h"
 #include "hw/ssi/imx_spi.h"
+#include "hw/watchdog/wdt_imx2.h"
 #include "qom/object.h"
 #include "qemu/units.h"
 
@@ -38,6 +39,7 @@ enum FslImx8mpConfiguration {
     FSL_IMX8MP_NUM_IRQS         = 160,
     FSL_IMX8MP_NUM_UARTS        = 4,
     FSL_IMX8MP_NUM_USDHCS       = 3,
+    FSL_IMX8MP_NUM_WDTS         = 3,
 };
 
 struct FslImx8mpState {
@@ -53,6 +55,7 @@ struct FslImx8mpState {
     IMXI2CState        i2c[FSL_IMX8MP_NUM_I2CS];
     IMXSerialState     uart[FSL_IMX8MP_NUM_UARTS];
     SDHCIState         usdhc[FSL_IMX8MP_NUM_USDHCS];
+    IMX2WdtState       wdt[FSL_IMX8MP_NUM_WDTS];
     DesignwarePCIEHost pcie;
     FslImx8mPciePhyState   pcie_phy;
 };
@@ -235,6 +238,10 @@ enum FslImx8mpIrqs {
     FSL_IMX8MP_I2C5_IRQ     = 76,
     FSL_IMX8MP_I2C6_IRQ     = 77,
 
+    FSL_IMX8MP_WDOG1_IRQ    = 78,
+    FSL_IMX8MP_WDOG2_IRQ    = 79,
+    FSL_IMX8MP_WDOG3_IRQ    = 10,
+
     FSL_IMX8MP_PCI_INTA_IRQ = 126,
     FSL_IMX8MP_PCI_INTB_IRQ = 125,
     FSL_IMX8MP_PCI_INTC_IRQ = 124,
hw/arm/fsl-imx8mp.c +28 -0
index fa39dfd2da..6646f1c8b4 100644
@@ -231,6 +231,11 @@ static void fsl_imx8mp_init(Object *obj)
         object_initialize_child(obj, name, &s->spi[i], TYPE_IMX_SPI);
     }
 
+    for (i = 0; i < FSL_IMX8MP_NUM_WDTS; i++) {
+        snprintf(name, NAME_SIZE, "wdt%d", i);
+        object_initialize_child(obj, name, &s->wdt[i], TYPE_IMX2_WDT);
+    }
+
     object_initialize_child(obj, "pcie", &s->pcie, TYPE_DESIGNWARE_PCIE_HOST);
     object_initialize_child(obj, "pcie_phy", &s->pcie_phy,
                             TYPE_FSL_IMX8M_PCIE_PHY);
@@ -495,6 +500,28 @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp)
     sysbus_mmio_map(SYS_BUS_DEVICE(&s->snvs), 0,
                     fsl_imx8mp_memmap[FSL_IMX8MP_SNVS_HP].addr);
 
+    /* Watchdogs */
+    for (i = 0; i < FSL_IMX8MP_NUM_WDTS; i++) {
+        static const struct {
+            hwaddr addr;
+            unsigned int irq;
+        } wdog_table[FSL_IMX8MP_NUM_WDTS] = {
+            { fsl_imx8mp_memmap[FSL_IMX8MP_WDOG1].addr, FSL_IMX8MP_WDOG1_IRQ },
+            { fsl_imx8mp_memmap[FSL_IMX8MP_WDOG2].addr, FSL_IMX8MP_WDOG2_IRQ },
+            { fsl_imx8mp_memmap[FSL_IMX8MP_WDOG3].addr, FSL_IMX8MP_WDOG3_IRQ },
+        };
+
+        object_property_set_bool(OBJECT(&s->wdt[i]), "pretimeout-support",
+                                 true, &error_abort);
+        if (!sysbus_realize(SYS_BUS_DEVICE(&s->wdt[i]), errp)) {
+            return;
+        }
+
+        sysbus_mmio_map(SYS_BUS_DEVICE(&s->wdt[i]), 0, wdog_table[i].addr);
+        sysbus_connect_irq(SYS_BUS_DEVICE(&s->wdt[i]), 0,
+                           qdev_get_gpio_in(gicdev, wdog_table[i].irq));
+    }
+
     /* PCIe */
     if (!sysbus_realize(SYS_BUS_DEVICE(&s->pcie), errp)) {
         return;
@@ -535,6 +562,7 @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp)
         case FSL_IMX8MP_SNVS_HP:
         case FSL_IMX8MP_UART1 ... FSL_IMX8MP_UART4:
         case FSL_IMX8MP_USDHC1 ... FSL_IMX8MP_USDHC3:
+        case FSL_IMX8MP_WDOG1 ... FSL_IMX8MP_WDOG3:
             /* device implemented and treated above */
             break;
 
hw/arm/Kconfig +1 -0
index 4a8695f22a..71102ac0a9 100644
@@ -590,6 +590,7 @@ config FSL_IMX8MP
     select PCI_EXPRESS_FSL_IMX8M_PHY
     select SDHCI
     select UNIMP
+    select WDT_IMX2
 
 config FSL_IMX8MP_EVK
     bool
Signature · 1 line
2.48.1
#31 lore raw

PATCH v2 13/18 hw/arm/fsl-imx8mp: Implement gneral purpose timers

In reply to Bernhard Beschow
---
 docs/system/arm/imx8mp-evk.rst |  1 +
 include/hw/arm/fsl-imx8mp.h    | 11 +++++++
 include/hw/timer/imx_gpt.h     |  1 +
 hw/arm/fsl-imx8mp.c            | 53 ++++++++++++++++++++++++++++++++++
 hw/timer/imx_gpt.c             | 25 ++++++++++++++++
 hw/arm/Kconfig                 |  1 +
 6 files changed, 92 insertions(+)
docs/system/arm/imx8mp-evk.rst +1 -0
index 15514055b5..9293cabb85 100644
@@ -19,6 +19,7 @@ The ``imx8mp-evk`` machine implements the following devices:
  * 6 I2C Controllers
  * 3 SPI Controllers
  * 3 Watchdogs
+ * 6 General Purpose Timers
  * Secure Non-Volatile Storage (SNVS) including an RTC
  * Clock Tree
 
include/hw/arm/fsl-imx8mp.h +11 -0
index dfbdc6ac7f..975887751b 100644
@@ -17,10 +17,12 @@
 #include "hw/misc/imx7_snvs.h"
 #include "hw/misc/imx8mp_analog.h"
 #include "hw/misc/imx8mp_ccm.h"
+#include "hw/or-irq.h"
 #include "hw/pci-host/designware.h"
 #include "hw/pci-host/fsl_imx8m_phy.h"
 #include "hw/sd/sdhci.h"
 #include "hw/ssi/imx_spi.h"
+#include "hw/timer/imx_gpt.h"
 #include "hw/watchdog/wdt_imx2.h"
 #include "qom/object.h"
 #include "qemu/units.h"
@@ -35,6 +37,7 @@ enum FslImx8mpConfiguration {
     FSL_IMX8MP_NUM_CPUS         = 4,
     FSL_IMX8MP_NUM_ECSPIS       = 3,
     FSL_IMX8MP_NUM_GPIOS        = 5,
+    FSL_IMX8MP_NUM_GPTS         = 6,
     FSL_IMX8MP_NUM_I2CS         = 6,
     FSL_IMX8MP_NUM_IRQS         = 160,
     FSL_IMX8MP_NUM_UARTS        = 4,
@@ -47,6 +50,7 @@ struct FslImx8mpState {
 
     ARMCPU             cpu[FSL_IMX8MP_NUM_CPUS];
     GICv3State         gic;
+    IMXGPTState        gpt[FSL_IMX8MP_NUM_GPTS];
     IMXGPIOState       gpio[FSL_IMX8MP_NUM_GPIOS];
     IMX8MPCCMState     ccm;
     IMX8MPAnalogState  analog;
@@ -58,6 +62,7 @@ struct FslImx8mpState {
     IMX2WdtState       wdt[FSL_IMX8MP_NUM_WDTS];
     DesignwarePCIEHost pcie;
     FslImx8mPciePhyState   pcie_phy;
+    OrIRQState         gpt5_gpt6_irq;
 };
 
 enum FslImx8mpMemoryRegions {
@@ -224,6 +229,12 @@ enum FslImx8mpIrqs {
     FSL_IMX8MP_I2C3_IRQ     = 37,
     FSL_IMX8MP_I2C4_IRQ     = 38,
 
+    FSL_IMX8MP_GPT1_IRQ      = 55,
+    FSL_IMX8MP_GPT2_IRQ      = 54,
+    FSL_IMX8MP_GPT3_IRQ      = 53,
+    FSL_IMX8MP_GPT4_IRQ      = 52,
+    FSL_IMX8MP_GPT5_GPT6_IRQ = 51,
+
     FSL_IMX8MP_GPIO1_LOW_IRQ  = 64,
     FSL_IMX8MP_GPIO1_HIGH_IRQ = 65,
     FSL_IMX8MP_GPIO2_LOW_IRQ  = 66,
include/hw/timer/imx_gpt.h +1 -0
index 5a1230da35..5488f7e4df 100644
@@ -80,6 +80,7 @@
 #define TYPE_IMX6_GPT "imx6.gpt"
 #define TYPE_IMX6UL_GPT "imx6ul.gpt"
 #define TYPE_IMX7_GPT "imx7.gpt"
+#define TYPE_IMX8MP_GPT "imx8mp.gpt"
 
 #define TYPE_IMX_GPT TYPE_IMX25_GPT
 
hw/arm/fsl-imx8mp.c +53 -0

65 lines not on this page · raw message

hw/timer/imx_gpt.c +25 -0
index 11eca9fa4d..200a89225b 100644
@@ -126,6 +126,17 @@ static const IMXClk imx7_gpt_clocks[] = {
     CLK_NONE,      /* 111 not defined */
 };
 
+static const IMXClk imx8mp_gpt_clocks[] = {
+    CLK_NONE,      /* 000 No clock source */
+    CLK_IPG,       /* 001 ipg_clk, 532MHz */
+    CLK_IPG_HIGH,  /* 010 ipg_clk_highfreq */
+    CLK_EXT,       /* 011 External clock */
+    CLK_32k,       /* 100 ipg_clk_32k */
+    CLK_HIGH,      /* 101 ipg_clk_16M */
+    CLK_NONE,      /* 110 not defined */
+    CLK_NONE,      /* 111 not defined */
+};
+
 /* Must be called from within ptimer_transaction_begin/commit block */
 static void imx_gpt_set_freq(IMXGPTState *s)
 {
@@ -552,6 +563,13 @@ static void imx7_gpt_init(Object *obj)
     s->clocks = imx7_gpt_clocks;
 }
 
+static void imx8mp_gpt_init(Object *obj)
+{
+    IMXGPTState *s = IMX_GPT(obj);
+
+    s->clocks = imx8mp_gpt_clocks;
+}
+
 static const TypeInfo imx25_gpt_info = {
     .name = TYPE_IMX25_GPT,
     .parent = TYPE_SYS_BUS_DEVICE,
@@ -584,6 +602,12 @@ static const TypeInfo imx7_gpt_info = {
     .instance_init = imx7_gpt_init,
 };
 
+static const TypeInfo imx8mp_gpt_info = {
+    .name = TYPE_IMX8MP_GPT,
+    .parent = TYPE_IMX25_GPT,
+    .instance_init = imx8mp_gpt_init,
+};
+
 static void imx_gpt_register_types(void)
 {
     type_register_static(&imx25_gpt_info);
@@ -591,6 +615,7 @@ static void imx_gpt_register_types(void)
     type_register_static(&imx6_gpt_info);
     type_register_static(&imx6ul_gpt_info);
     type_register_static(&imx7_gpt_info);
+    type_register_static(&imx8mp_gpt_info);
 }
 
 type_init(imx_gpt_register_types)
hw/arm/Kconfig +1 -0
index 71102ac0a9..f2859f6a88 100644
@@ -586,6 +586,7 @@ config FSL_IMX8MP
     select FSL_IMX8MP_CCM
     select IMX
     select IMX_I2C
+    select OR_IRQ
     select PCI_EXPRESS_DESIGNWARE
     select PCI_EXPRESS_FSL_IMX8M_PHY
     select SDHCI
Signature · 1 line
2.48.1
Reviewed-by on v2 13/18
#32 lore raw

Re: [PATCH v2 13/18] hw/arm/fsl-imx8mp: Implement gneral purpose timers

Quoted 10 lines · Bernhard Beschow
---
 docs/system/arm/imx8mp-evk.rst |  1 +
 include/hw/arm/fsl-imx8mp.h    | 11 +++++++
 include/hw/timer/imx_gpt.h     |  1 +
 hw/arm/fsl-imx8mp.c            | 53 ++++++++++++++++++++++++++++++++++
 hw/timer/imx_gpt.c             | 25 ++++++++++++++++
 hw/arm/Kconfig                 |  1 +
 6 files changed, 92 insertions(+)

Typo in the subject: "general". Otherwise

thanks
-- PMM

#33 lore raw

Re: [PATCH v2 13/18] hw/arm/fsl-imx8mp: Implement gneral purpose timers

Am 6. Februar 2025 17:29:16 UTC schrieb Peter Maydell <[email protected]>:

Quoted 12 lines · Bernhard Beschow
Quoted 10 lines
---
 docs/system/arm/imx8mp-evk.rst |  1 +
 include/hw/arm/fsl-imx8mp.h    | 11 +++++++
 include/hw/timer/imx_gpt.h     |  1 +
 hw/arm/fsl-imx8mp.c            | 53 ++++++++++++++++++++++++++++++++++
 hw/timer/imx_gpt.c             | 25 ++++++++++++++++
 hw/arm/Kconfig                 |  1 +
 6 files changed, 92 insertions(+)
Quoted 1 line

Typo in the subject: "general". Otherwise

Will be fixed in v3.

Quoted 2 lines

Thanks,
Bernhard

Quoted 3 lines

thanks
-- PMM

#34 lore raw

PATCH v2 14/18 hw/arm/fsl-imx8mp: Add Ethernet controller

In reply to Bernhard Beschow

The i.MX 8M Plus SoC actually has two ethernet controllers, the usual ENET one and a Designware one. There is no device model for the latter, so only add the ENET one.

---
 docs/system/arm/imx8mp-evk.rst |  1 +
 include/hw/arm/fsl-imx8mp.h    |  8 ++++++++
 hw/arm/fsl-imx8mp.c            | 24 ++++++++++++++++++++++++
 hw/arm/imx8mp-evk.c            |  1 +
 hw/arm/Kconfig                 |  1 +
 5 files changed, 35 insertions(+)
docs/system/arm/imx8mp-evk.rst +1 -0
index 9293cabb85..4109387b6e 100644
@@ -15,6 +15,7 @@ The ``imx8mp-evk`` machine implements the following devices:
  * 4 UARTs
  * 3 USDHC Storage Controllers
  * 1 Designware PCI Express Controller
+ * 1 Ethernet Controller
  * 5 GPIO Controllers
  * 6 I2C Controllers
  * 3 SPI Controllers
include/hw/arm/fsl-imx8mp.h +8 -0
index 975887751b..e292c31a3d 100644
@@ -17,6 +17,7 @@
 #include "hw/misc/imx7_snvs.h"
 #include "hw/misc/imx8mp_analog.h"
 #include "hw/misc/imx8mp_ccm.h"
+#include "hw/net/imx_fec.h"
 #include "hw/or-irq.h"
 #include "hw/pci-host/designware.h"
 #include "hw/pci-host/fsl_imx8m_phy.h"
@@ -58,11 +59,15 @@ struct FslImx8mpState {
     IMXSPIState        spi[FSL_IMX8MP_NUM_ECSPIS];
     IMXI2CState        i2c[FSL_IMX8MP_NUM_I2CS];
     IMXSerialState     uart[FSL_IMX8MP_NUM_UARTS];
+    IMXFECState        enet;
     SDHCIState         usdhc[FSL_IMX8MP_NUM_USDHCS];
     IMX2WdtState       wdt[FSL_IMX8MP_NUM_WDTS];
     DesignwarePCIEHost pcie;
     FslImx8mPciePhyState   pcie_phy;
     OrIRQState         gpt5_gpt6_irq;
+
+    uint32_t           phy_num;
+    bool               phy_connected;
 };
 
 enum FslImx8mpMemoryRegions {
@@ -253,6 +258,9 @@ enum FslImx8mpIrqs {
     FSL_IMX8MP_WDOG2_IRQ    = 79,
     FSL_IMX8MP_WDOG3_IRQ    = 10,
 
+    FSL_IMX8MP_ENET1_MAC_IRQ    = 118,
+    FSL_IMX6_ENET1_MAC_1588_IRQ = 121,
+
     FSL_IMX8MP_PCI_INTA_IRQ = 126,
     FSL_IMX8MP_PCI_INTB_IRQ = 125,
     FSL_IMX8MP_PCI_INTC_IRQ = 124,
hw/arm/fsl-imx8mp.c +24 -0
index 43395df628..665123cf9c 100644
@@ -243,6 +243,8 @@ static void fsl_imx8mp_init(Object *obj)
         object_initialize_child(obj, name, &s->wdt[i], TYPE_IMX2_WDT);
     }
 
+    object_initialize_child(obj, "eth0", &s->enet, TYPE_IMX_ENET);
+
     object_initialize_child(obj, "pcie", &s->pcie, TYPE_DESIGNWARE_PCIE_HOST);
     object_initialize_child(obj, "pcie_phy", &s->pcie_phy,
                             TYPE_FSL_IMX8M_PCIE_PHY);
@@ -546,6 +548,21 @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp)
                            qdev_get_gpio_in(gicdev, spi_table[i].irq));
     }
 
+    /* ENET1 */
+    object_property_set_uint(OBJECT(&s->enet), "phy-num", s->phy_num,
+                             &error_abort);
+    object_property_set_uint(OBJECT(&s->enet), "tx-ring-num", 3, &error_abort);
+    qemu_configure_nic_device(DEVICE(&s->enet), true, NULL);
+    if (!sysbus_realize(SYS_BUS_DEVICE(&s->enet), errp)) {
+        return;
+    }
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->enet), 0,
+                    fsl_imx8mp_memmap[FSL_IMX8MP_ENET1].addr);
+    sysbus_connect_irq(SYS_BUS_DEVICE(&s->enet), 0,
+                       qdev_get_gpio_in(gicdev, FSL_IMX8MP_ENET1_MAC_IRQ));
+    sysbus_connect_irq(SYS_BUS_DEVICE(&s->enet), 1,
+                       qdev_get_gpio_in(gicdev, FSL_IMX6_ENET1_MAC_1588_IRQ));
+
     /* SNVS */
     if (!sysbus_realize(SYS_BUS_DEVICE(&s->snvs), errp)) {
         return;
@@ -608,6 +625,7 @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp)
         case FSL_IMX8MP_GIC_REDIST:
         case FSL_IMX8MP_GPIO1 ... FSL_IMX8MP_GPIO5:
         case FSL_IMX8MP_ECSPI1 ... FSL_IMX8MP_ECSPI3:
+        case FSL_IMX8MP_ENET1:
         case FSL_IMX8MP_I2C1 ... FSL_IMX8MP_I2C6:
         case FSL_IMX8MP_PCIE1:
         case FSL_IMX8MP_PCIE_PHY1:
@@ -628,10 +646,16 @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp)
     }
 }
 
+static const Property fsl_imx8mp_properties[] = {
+    DEFINE_PROP_UINT32("fec1-phy-num", FslImx8mpState, phy_num, 0),
+    DEFINE_PROP_BOOL("fec1-phy-connected", FslImx8mpState, phy_connected, true),
+};
+
 static void fsl_imx8mp_class_init(ObjectClass *oc, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(oc);
 
+    device_class_set_props(dc, fsl_imx8mp_properties);
     dc->realize = fsl_imx8mp_realize;
 
     dc->desc = "i.MX 8M Plus SoC";
hw/arm/imx8mp-evk.c +1 -0
index 27d9e9e8ee..e1a7892fd7 100644
@@ -36,6 +36,7 @@ static void imx8mp_evk_init(MachineState *machine)
 
     s = FSL_IMX8MP(object_new(TYPE_FSL_IMX8MP));
     object_property_add_child(OBJECT(machine), "soc", OBJECT(s));
+    object_property_set_uint(OBJECT(s), "fec1-phy-num", 1, &error_fatal);
     qdev_realize(DEVICE(s), NULL, &error_fatal);
 
     memory_region_add_subregion(get_system_memory(), FSL_IMX8MP_RAM_START,
hw/arm/Kconfig +1 -0
index f2859f6a88..7767a8725a 100644
@@ -585,6 +585,7 @@ config FSL_IMX8MP
     select FSL_IMX8MP_ANALOG
     select FSL_IMX8MP_CCM
     select IMX
+    select IMX_FEC
     select IMX_I2C
     select OR_IRQ
     select PCI_EXPRESS_DESIGNWARE
Signature · 1 line
2.48.1
Reviewed-by on v2 14/18
#35 lore raw

Re: [PATCH v2 14/18] hw/arm/fsl-imx8mp: Add Ethernet controller

Quoted 5 lines · Bernhard Beschow

The i.MX 8M Plus SoC actually has two ethernet controllers, the usual ENET one and a Designware one. There is no device model for the latter, so only add the ENET one.

Quoted 9 lines
---
 docs/system/arm/imx8mp-evk.rst |  1 +
 include/hw/arm/fsl-imx8mp.h    |  8 ++++++++
 hw/arm/fsl-imx8mp.c            | 24 ++++++++++++++++++++++++
 hw/arm/imx8mp-evk.c            |  1 +
 hw/arm/Kconfig                 |  1 +
 5 files changed, 35 insertions(+)

thanks
-- PMM

#36 lore raw

PATCH v2 15/18 hw/arm/fsl-imx8mp: Add USB support

In reply to Bernhard Beschow

Split the USB MMIO regions to better keep track of the implemented vs. unimplemented regions.

---
 docs/system/arm/imx8mp-evk.rst |  1 +
 include/hw/arm/fsl-imx8mp.h    | 12 +++++++++++
 hw/arm/fsl-imx8mp.c            | 37 ++++++++++++++++++++++++++++++++--
 hw/arm/Kconfig                 |  1 +
 4 files changed, 49 insertions(+), 2 deletions(-)
docs/system/arm/imx8mp-evk.rst +1 -0
index 4109387b6e..b3d657be10 100644
@@ -16,6 +16,7 @@ The ``imx8mp-evk`` machine implements the following devices:
  * 3 USDHC Storage Controllers
  * 1 Designware PCI Express Controller
  * 1 Ethernet Controller
+ * 2 Designware USB 3 Controllers
  * 5 GPIO Controllers
  * 6 I2C Controllers
  * 3 SPI Controllers
include/hw/arm/fsl-imx8mp.h +12 -0
index e292c31a3d..5247e972b8 100644
@@ -24,6 +24,7 @@
 #include "hw/sd/sdhci.h"
 #include "hw/ssi/imx_spi.h"
 #include "hw/timer/imx_gpt.h"
+#include "hw/usb/hcd-dwc3.h"
 #include "hw/watchdog/wdt_imx2.h"
 #include "qom/object.h"
 #include "qemu/units.h"
@@ -42,6 +43,7 @@ enum FslImx8mpConfiguration {
     FSL_IMX8MP_NUM_I2CS         = 6,
     FSL_IMX8MP_NUM_IRQS         = 160,
     FSL_IMX8MP_NUM_UARTS        = 4,
+    FSL_IMX8MP_NUM_USBS         = 2,
     FSL_IMX8MP_NUM_USDHCS       = 3,
     FSL_IMX8MP_NUM_WDTS         = 3,
 };
@@ -62,6 +64,7 @@ struct FslImx8mpState {
     IMXFECState        enet;
     SDHCIState         usdhc[FSL_IMX8MP_NUM_USDHCS];
     IMX2WdtState       wdt[FSL_IMX8MP_NUM_WDTS];
+    USBDWC3            usb[FSL_IMX8MP_NUM_USBS];
     DesignwarePCIEHost pcie;
     FslImx8mPciePhyState   pcie_phy;
     OrIRQState         gpt5_gpt6_irq;
@@ -199,6 +202,12 @@ enum FslImx8mpMemoryRegions {
     FSL_IMX8MP_UART4,
     FSL_IMX8MP_USB1,
     FSL_IMX8MP_USB2,
+    FSL_IMX8MP_USB1_DEV,
+    FSL_IMX8MP_USB2_DEV,
+    FSL_IMX8MP_USB1_OTG,
+    FSL_IMX8MP_USB2_OTG,
+    FSL_IMX8MP_USB1_GLUE,
+    FSL_IMX8MP_USB2_GLUE,
     FSL_IMX8MP_USDHC1,
     FSL_IMX8MP_USDHC2,
     FSL_IMX8MP_USDHC3,
@@ -234,6 +243,9 @@ enum FslImx8mpIrqs {
     FSL_IMX8MP_I2C3_IRQ     = 37,
     FSL_IMX8MP_I2C4_IRQ     = 38,
 
+    FSL_IMX8MP_USB1_IRQ     = 40,
+    FSL_IMX8MP_USB2_IRQ     = 41,
+
     FSL_IMX8MP_GPT1_IRQ      = 55,
     FSL_IMX8MP_GPT2_IRQ      = 54,
     FSL_IMX8MP_GPT3_IRQ      = 53,
hw/arm/fsl-imx8mp.c +35 -2
index 665123cf9c..14d696957a 100644
@@ -40,8 +40,14 @@ static const struct {
     [FSL_IMX8MP_VPU_VC8000E_ENCODER] = { 0x38320000, 2 * MiB, "vpu_vc8000e_encoder" },
     [FSL_IMX8MP_VPU_G2_DECODER] = { 0x38310000, 2 * MiB, "vpu_g2_decoder" },
     [FSL_IMX8MP_VPU_G1_DECODER] = { 0x38300000, 2 * MiB, "vpu_g1_decoder" },
-    [FSL_IMX8MP_USB2] = { 0x38200000, 1 * MiB, "usb2" },
-    [FSL_IMX8MP_USB1] = { 0x38100000, 1 * MiB, "usb1" },
+    [FSL_IMX8MP_USB2_GLUE] = { 0x382f0000, 0x100, "usb2_glue" },
+    [FSL_IMX8MP_USB2_OTG] = { 0x3820cc00, 0x100, "usb2_otg" },
+    [FSL_IMX8MP_USB2_DEV] = { 0x3820c700, 0x500, "usb2_dev" },
+    [FSL_IMX8MP_USB2] = { 0x38200000, 0xc700, "usb2" },
+    [FSL_IMX8MP_USB1_GLUE] = { 0x381f0000, 0x100, "usb1_glue" },
+    [FSL_IMX8MP_USB1_OTG] = { 0x3810cc00, 0x100, "usb1_otg" },
+    [FSL_IMX8MP_USB1_DEV] = { 0x3810c700, 0x500, "usb1_dev" },
+    [FSL_IMX8MP_USB1] = { 0x38100000, 0xc700, "usb1" },
     [FSL_IMX8MP_GPU2D] = { 0x38008000, 32 * KiB, "gpu2d" },
     [FSL_IMX8MP_GPU3D] = { 0x38000000, 32 * KiB, "gpu3d" },
     [FSL_IMX8MP_QSPI1_RX_BUFFER] = { 0x34000000, 32 * MiB, "qspi1_rx_buffer" },
@@ -233,6 +239,11 @@ static void fsl_imx8mp_init(Object *obj)
         object_initialize_child(obj, name, &s->usdhc[i], TYPE_IMX_USDHC);
     }
 
+    for (i = 0; i < FSL_IMX8MP_NUM_USBS; i++) {
+        snprintf(name, NAME_SIZE, "usb%d", i);
+        object_initialize_child(obj, name, &s->usb[i], TYPE_USB_DWC3);
+    }
+
     for (i = 0; i < FSL_IMX8MP_NUM_ECSPIS; i++) {
         snprintf(name, NAME_SIZE, "spi%d", i + 1);
         object_initialize_child(obj, name, &s->spi[i], TYPE_IMX_SPI);
@@ -528,6 +539,27 @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp)
                            qdev_get_gpio_in(gicdev, usdhc_table[i].irq));
     }
 
+    /* USBs */
+    for (i = 0; i < FSL_IMX8MP_NUM_USBS; i++) {
+        static const struct {
+            hwaddr addr;
+            unsigned int irq;
+        } usb_table[FSL_IMX8MP_NUM_USBS] = {
+            { fsl_imx8mp_memmap[FSL_IMX8MP_USB1].addr, FSL_IMX8MP_USB1_IRQ },
+            { fsl_imx8mp_memmap[FSL_IMX8MP_USB2].addr, FSL_IMX8MP_USB2_IRQ },
+        };
+
+        qdev_prop_set_uint32(DEVICE(&s->usb[i].sysbus_xhci), "p2", 1);
+        qdev_prop_set_uint32(DEVICE(&s->usb[i].sysbus_xhci), "p3", 1);
+        qdev_prop_set_uint32(DEVICE(&s->usb[i].sysbus_xhci), "slots", 2);
+        if (!sysbus_realize(SYS_BUS_DEVICE(&s->usb[i]), errp)) {
+            return;
+        }
+        sysbus_mmio_map(SYS_BUS_DEVICE(&s->usb[i]), 0, usb_table[i].addr);
+        sysbus_connect_irq(SYS_BUS_DEVICE(&s->usb[i].sysbus_xhci), 0,
+                           qdev_get_gpio_in(gicdev, usb_table[i].irq));
+    }
+
     /* ECSPIs */
     for (i = 0; i < FSL_IMX8MP_NUM_ECSPIS; i++) {
         static const struct {
@@ -632,6 +664,7 @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp)
         case FSL_IMX8MP_RAM:
         case FSL_IMX8MP_SNVS_HP:
         case FSL_IMX8MP_UART1 ... FSL_IMX8MP_UART4:
+        case FSL_IMX8MP_USB1 ... FSL_IMX8MP_USB2:
         case FSL_IMX8MP_USDHC1 ... FSL_IMX8MP_USDHC3:
         case FSL_IMX8MP_WDOG1 ... FSL_IMX8MP_WDOG3:
             /* device implemented and treated above */
hw/arm/Kconfig +1 -0
index 7767a8725a..6daa9c651f 100644
@@ -592,6 +592,7 @@ config FSL_IMX8MP
     select PCI_EXPRESS_FSL_IMX8M_PHY
     select SDHCI
     select UNIMP
+    select USB_DWC3
     select WDT_IMX2
 
 config FSL_IMX8MP_EVK
Signature · 1 line
2.48.1
Reviewed-by on v2 15/18
#37 lore raw

Re: [PATCH v2 15/18] hw/arm/fsl-imx8mp: Add USB support

Quoted 11 lines · Bernhard Beschow

Split the USB MMIO regions to better keep track of the implemented vs. unimplemented regions.

---
 docs/system/arm/imx8mp-evk.rst |  1 +
 include/hw/arm/fsl-imx8mp.h    | 12 +++++++++++
 hw/arm/fsl-imx8mp.c            | 37 ++++++++++++++++++++++++++++++++--
 hw/arm/Kconfig                 |  1 +
 4 files changed, 49 insertions(+), 2 deletions(-)

thanks
-- PMM

#38 lore raw

PATCH v2 16/18 hw/arm/fsl-imx8mp: Add boot ROM

In reply to Bernhard Beschow

On a real device, the boot ROM contains the very first instructions the CPU executes. Also, U-Boot calls into the ROM to determine the boot device. While we're not actually implementing this here, let's create the infrastructure and add a dummy ROM with all zeros. This allows for implementing a ROM later without touching the source code and even allows for users to provide their own ROMs.

The imx8mp-boot.rom was created with
dd if=/dev/zero of=imx8mp-boot.rom bs=1 count=258048.

---
 MAINTAINERS                 |   1 +
 include/hw/arm/fsl-imx8mp.h |   1 +
 hw/arm/fsl-imx8mp.c         |  18 ++++++++++++++++++
 pc-bios/imx8mp-boot.rom     | Bin 0 -> 258048 bytes
 pc-bios/meson.build         |   1 +
 5 files changed, 21 insertions(+)
 create mode 100644 pc-bios/imx8mp-boot.rom
MAINTAINERS +1 -0
index 94af3d90e4..ee837a3f6e 100644
@@ -831,6 +831,7 @@ F: hw/pci-host/fsl_imx8m_phy.c
 F: include/hw/arm/fsl-imx8mp.h
 F: include/hw/misc/imx8mp_*.h
 F: include/hw/pci-host/fsl_imx8m_phy.h
+F: pc-bios/imx8mp*
 F: docs/system/arm/imx8mp-evk.rst
 
 MPS2 / MPS3
include/hw/arm/fsl-imx8mp.h +1 -0
index 5247e972b8..4dbe30f524 100644
@@ -68,6 +68,7 @@ struct FslImx8mpState {
     DesignwarePCIEHost pcie;
     FslImx8mPciePhyState   pcie_phy;
     OrIRQState         gpt5_gpt6_irq;
+    MemoryRegion       boot_rom;
 
     uint32_t           phy_num;
     bool               phy_connected;
hw/arm/fsl-imx8mp.c +18 -0
index 14d696957a..6439639110 100644
@@ -9,12 +9,14 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/datadir.h"
 #include "exec/address-spaces.h"
 #include "hw/arm/bsa.h"
 #include "hw/arm/fsl-imx8mp.h"
 #include "hw/intc/arm_gicv3.h"
 #include "hw/misc/unimp.h"
 #include "hw/boards.h"
+#include "hw/loader.h"
 #include "system/system.h"
 #include "target/arm/cpu-qom.h"
 #include "qapi/qmp/qlist.h"
@@ -266,6 +268,7 @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp)
     MachineState *ms = MACHINE(qdev_get_machine());
     FslImx8mpState *s = FSL_IMX8MP(dev);
     DeviceState *gicdev = DEVICE(&s->gic);
+    g_autofree char *filename = NULL;
     int i;
 
     if (ms->smp.cpus > FSL_IMX8MP_NUM_CPUS) {
@@ -648,10 +651,25 @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp)
     sysbus_mmio_map(SYS_BUS_DEVICE(&s->pcie_phy), 0,
                     fsl_imx8mp_memmap[FSL_IMX8MP_PCIE_PHY1].addr);
 
+    /* ROM memory */
+    if (!memory_region_init_rom(&s->boot_rom, OBJECT(dev),
+                                fsl_imx8mp_memmap[FSL_IMX8MP_BOOT_ROM].name,
+                                fsl_imx8mp_memmap[FSL_IMX8MP_BOOT_ROM].size,
+                                errp)) {
+        return;
+    }
+    filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, "imx8mp-boot.rom");
+    load_image_size(filename, memory_region_get_ram_ptr(&s->boot_rom),
+                    memory_region_size(&s->boot_rom));
+    memory_region_add_subregion(get_system_memory(),
+                                fsl_imx8mp_memmap[FSL_IMX8MP_BOOT_ROM].addr,
+                                &s->boot_rom);
+
     /* Unimplemented devices */
     for (i = 0; i < ARRAY_SIZE(fsl_imx8mp_memmap); i++) {
         switch (i) {
         case FSL_IMX8MP_ANA_PLL:
+        case FSL_IMX8MP_BOOT_ROM:
         case FSL_IMX8MP_CCM:
         case FSL_IMX8MP_GIC_DIST:
         case FSL_IMX8MP_GIC_REDIST:
pc-bios/imx8mp-boot.rom new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..5324b5eed200e723d048f8476e4d96d45622fd4d
GIT binary patch
pc-bios/meson.build +1 -0
index b68b29cc7d..64d3286fdd 100644
@@ -60,6 +60,7 @@ blobs = [
   'efi-virtio.rom',
   'efi-e1000e.rom',
   'efi-vmxnet3.rom',
+  'imx8mp-boot.rom',
   'qemu-nsis.bmp',
   'multiboot.bin',
   'multiboot_dma.bin',
Signature · 1 line
2.48.1
#39 lore raw

Re: [PATCH v2 16/18] hw/arm/fsl-imx8mp: Add boot ROM

Quoted 9 lines · Bernhard Beschow

On a real device, the boot ROM contains the very first instructions the CPU executes. Also, U-Boot calls into the ROM to determine the boot device. While we're not actually implementing this here, let's create the infrastructure and add a dummy ROM with all zeros. This allows for implementing a ROM later without touching the source code and even allows for users to provide their own ROMs.

The imx8mp-boot.rom was created with
dd if=/dev/zero of=imx8mp-boot.rom bs=1 count=258048.

If it's all zeroes, we don't need to commit it to git as a binary, we can generate it at build time. (We should avoid having binaries in git as much as we can manage.)

thanks
-- PMM

#40 lore raw

Re: [PATCH v2 16/18] hw/arm/fsl-imx8mp: Add boot ROM

Am 17. Februar 2025 13:28:42 UTC schrieb Peter Maydell <[email protected]>:

Quoted 8 lines · Bernhard Beschow
Quoted 7 lines

On a real device, the boot ROM contains the very first instructions the CPU executes. Also, U-Boot calls into the ROM to determine the boot device. While we're not actually implementing this here, let's create the infrastructure and add a dummy ROM with all zeros. This allows for implementing a ROM later without touching the source code and even allows for users to provide their own ROMs.

Quoted 6 lines
Quoted 2 lines

The imx8mp-boot.rom was created with
dd if=/dev/zero of=imx8mp-boot.rom bs=1 count=258048.

If it's all zeroes, we don't need to commit it to git as a binary, we can generate it at build time. (We should avoid having binaries in git as much as we can manage.)

I went with this solution since it trivially works on any build platform. Any idea how to generate the file in a portable way?

Thanks,
Bernhard

Quoted 3 lines

thanks
-- PMM

#41 lore raw

Re: [PATCH v2 16/18] hw/arm/fsl-imx8mp: Add boot ROM

Am 17. Februar 2025 22:48:23 UTC schrieb Bernhard Beschow <[email protected]>:

Quoted 11 lines

Am 17. Februar 2025 13:28:42 UTC schrieb Peter Maydell <[email protected]>:

Quoted 8 lines · Bernhard Beschow
Quoted 7 lines

On a real device, the boot ROM contains the very first instructions the CPU executes. Also, U-Boot calls into the ROM to determine the boot device. While we're not actually implementing this here, let's create the infrastructure and add a dummy ROM with all zeros. This allows for implementing a ROM later without touching the source code and even allows for users to provide their own ROMs.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

The imx8mp-boot.rom was created with
dd if=/dev/zero of=imx8mp-boot.rom bs=1 count=258048.

If it's all zeroes, we don't need to commit it to git as a binary, we can generate it at build time. (We should avoid having binaries in git as much as we can manage.)

I went with this solution since it trivially works on any build platform. Any idea how to generate the file in a portable way?

Besides this question, the compressed size of the file in Git is just 276 bytes:

  $ git hash-object pc-bios/imx8mp-boot.rom
  5324b5eed200e723d048f8476e4d96d45622fd4d
  $ git verify-pack -v .git/objects/pack/pack-*.idx | grep 5324b5eed2
  5324b5eed200e723d048f8476e4d96d45622fd4d blob   258048 276 787647

Is it really worth generating it during the build process?

Best regards,
Bernhard

Quoted 7 lines

Thanks,
Bernhard

Quoted 3 lines

thanks
-- PMM

#42 lore raw

PATCH v2 17/18 hw/arm/fsl-imx8mp: Add on-chip RAM

In reply to Bernhard Beschow
---
 include/hw/arm/fsl-imx8mp.h |  1 +
 hw/arm/fsl-imx8mp.c         | 11 +++++++++++
 2 files changed, 12 insertions(+)
include/hw/arm/fsl-imx8mp.h +1 -0
index 4dbe30f524..03f057c7db 100644
@@ -69,6 +69,7 @@ struct FslImx8mpState {
     FslImx8mPciePhyState   pcie_phy;
     OrIRQState         gpt5_gpt6_irq;
     MemoryRegion       boot_rom;
+    MemoryRegion       ocram;
 
     uint32_t           phy_num;
     bool               phy_connected;
hw/arm/fsl-imx8mp.c +11 -0
index 6439639110..e0dfe06e15 100644
@@ -665,6 +665,16 @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp)
                                 fsl_imx8mp_memmap[FSL_IMX8MP_BOOT_ROM].addr,
                                 &s->boot_rom);
 
+    /* On-Chip RAM */
+    if (!memory_region_init_ram(&s->ocram, NULL, "imx8mp.ocram",
+                                fsl_imx8mp_memmap[FSL_IMX8MP_OCRAM].size,
+                                errp)) {
+        return;
+    }
+    memory_region_add_subregion(get_system_memory(),
+                                fsl_imx8mp_memmap[FSL_IMX8MP_OCRAM].addr,
+                                &s->ocram);
+
     /* Unimplemented devices */
     for (i = 0; i < ARRAY_SIZE(fsl_imx8mp_memmap); i++) {
         switch (i) {
@@ -677,6 +687,7 @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp)
         case FSL_IMX8MP_ECSPI1 ... FSL_IMX8MP_ECSPI3:
         case FSL_IMX8MP_ENET1:
         case FSL_IMX8MP_I2C1 ... FSL_IMX8MP_I2C6:
+        case FSL_IMX8MP_OCRAM:
         case FSL_IMX8MP_PCIE1:
         case FSL_IMX8MP_PCIE_PHY1:
         case FSL_IMX8MP_RAM:
Signature · 1 line
2.48.1
#44 lore raw

PATCH v2 18/18 hw/rtc: Add Ricoh RS5C372 RTC emulation

In reply to Bernhard Beschow

The implementation just allows Linux to determine date and time.

---
 MAINTAINERS         |   1 +
 hw/rtc/rs5c372.c    | 227 ++++++++++++++++++++++++++++++++++++++++++++
 hw/rtc/Kconfig      |   5 +
 hw/rtc/meson.build  |   1 +
 hw/rtc/trace-events |   4 +
 5 files changed, 238 insertions(+)
 create mode 100644 hw/rtc/rs5c372.c
MAINTAINERS +1 -0
index ee837a3f6e..d87435adba 100644
@@ -828,6 +828,7 @@ F: hw/arm/imx8mp-evk.c
 F: hw/arm/fsl-imx8mp.c
 F: hw/misc/imx8mp_*.c
 F: hw/pci-host/fsl_imx8m_phy.c
+F: hw/rtc/rs5c372.c
 F: include/hw/arm/fsl-imx8mp.h
 F: include/hw/misc/imx8mp_*.h
 F: include/hw/pci-host/fsl_imx8m_phy.h
hw/rtc/rs5c372.c new file +227 -0

227 lines not on this page · raw message

hw/rtc/Kconfig +5 -0
index 2fe04ec1d0..315b0e4ecc 100644
@@ -26,3 +26,8 @@ config GOLDFISH_RTC
 
 config LS7A_RTC
     bool
+
+config RS5C372_RTC
+    bool
+    depends on I2C
+    default y if I2C_DEVICES
hw/rtc/meson.build +1 -0
index 8ecc2d792c..6c87864dc0 100644
@@ -13,3 +13,4 @@ system_ss.add(when: 'CONFIG_GOLDFISH_RTC', if_true: files('goldfish_rtc.c'))
 system_ss.add(when: 'CONFIG_LS7A_RTC', if_true: files('ls7a_rtc.c'))
 system_ss.add(when: 'CONFIG_ALLWINNER_H3', if_true: files('allwinner-rtc.c'))
 system_ss.add(when: 'CONFIG_MC146818RTC', if_true: files('mc146818rtc.c'))
+system_ss.add(when: 'CONFIG_RS5C372_RTC', if_true: files('rs5c372.c'))
hw/rtc/trace-events +4 -0
index 8012afe102..b9f2852d35 100644
@@ -35,3 +35,7 @@ m48txx_nvram_mem_write(uint32_t addr, uint32_t value) "mem write addr:0x%04x val
 # goldfish_rtc.c
 goldfish_rtc_read(uint64_t addr, uint64_t value) "addr 0x%02" PRIx64 " value 0x%08" PRIx64
 goldfish_rtc_write(uint64_t addr, uint64_t value) "addr 0x%02" PRIx64 " value 0x%08" PRIx64
+
+# rs5c372.c
+rs5c372_recv(uint32_t addr, uint8_t value) "[0x%" PRIx32 "] -> 0x%02" PRIx8
+rs5c372_send(uint32_t addr, uint8_t value) "[0x%" PRIx32 "] <- 0x%02" PRIx8
Signature · 1 line
2.48.1
#45 lore raw

Re: [PATCH v2 18/18] hw/rtc: Add Ricoh RS5C372 RTC emulation

Quoted 4 lines · Bernhard Beschow

The implementation just allows Linux to determine date and time.

Quoted 8 lines
---
 MAINTAINERS         |   1 +
 hw/rtc/rs5c372.c    | 227 ++++++++++++++++++++++++++++++++++++++++++++
 hw/rtc/Kconfig      |   5 +
 hw/rtc/meson.build  |   1 +
 hw/rtc/trace-events |   4 +
 5 files changed, 238 insertions(+)
 create mode 100644 hw/rtc/rs5c372.c

Should there be a patch after this one that adds this device to your board ?

thanks
-- PMM

#46 lore raw

Re: [PATCH v2 18/18] hw/rtc: Add Ricoh RS5C372 RTC emulation

Am 6. Februar 2025 17:32:31 UTC schrieb Peter Maydell <[email protected]>:

Quoted 14 lines · Bernhard Beschow
Quoted 4 lines

The implementation just allows Linux to determine date and time.

Quoted 8 lines
---
 MAINTAINERS         |   1 +
 hw/rtc/rs5c372.c    | 227 ++++++++++++++++++++++++++++++++++++++++++++
 hw/rtc/Kconfig      |   5 +
 hw/rtc/meson.build  |   1 +
 hw/rtc/trace-events |   4 +
 5 files changed, 238 insertions(+)
 create mode 100644 hw/rtc/rs5c372.c
Quoted 2 lines

Should there be a patch after this one that adds this device to your board ?

As per Kconfig the board selects I2C_DEVICES and this device is "default y if I2C_DEVICES". I've deliberately not hardcoded this device to the board to make it emulate a plain i.MX 8M Plus SoC (see also board documentation).

Best regards,
Bernhard

Quoted 3 lines

thanks
-- PMM

#47 lore raw

Re: [PATCH v2 18/18] hw/rtc: Add Ricoh RS5C372 RTC emulation

Quoted 17 lines · Bernhard Beschow

Am 6. Februar 2025 17:32:31 UTC schrieb Peter Maydell <[email protected]>:

Quoted 14 lines · Bernhard Beschow
Quoted 12 lines

The implementation just allows Linux to determine date and time.

---
  MAINTAINERS         |   1 +
  hw/rtc/rs5c372.c    | 227 ++++++++++++++++++++++++++++++++++++++++++++
  hw/rtc/Kconfig      |   5 +
  hw/rtc/meson.build  |   1 +
  hw/rtc/trace-events |   4 +
  5 files changed, 238 insertions(+)

create mode 100644 hw/rtc/rs5c372.c

Quoted 4 lines
Quoted 2 lines

Should there be a patch after this one that adds this device to your board ?

As per Kconfig the board selects I2C_DEVICES and this device is "default y if I2C_DEVICES". I've deliberately not hardcoded this device to the board to make it emulate a plain i.MX 8M Plus SoC (see also board documentation).

Then maybe add a test to be sure it is not bitroting?

#48 lore raw

Re: [PATCH v2 18/18] hw/rtc: Add Ricoh RS5C372 RTC emulation

Am 10. Februar 2025 14:26:00 UTC schrieb "Philippe Mathieu-Daudé" <[email protected]>:

Quoted 18 lines · Bernhard Beschow
Quoted 17 lines

Am 6. Februar 2025 17:32:31 UTC schrieb Peter Maydell <[email protected]>:

Quoted 14 lines · Bernhard Beschow
Quoted 12 lines

The implementation just allows Linux to determine date and time.

---
  MAINTAINERS         |   1 +
  hw/rtc/rs5c372.c    | 227 ++++++++++++++++++++++++++++++++++++++++++++
  hw/rtc/Kconfig      |   5 +
  hw/rtc/meson.build  |   1 +
  hw/rtc/trace-events |   4 +
  5 files changed, 238 insertions(+)

create mode 100644 hw/rtc/rs5c372.c

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

Should there be a patch after this one that adds this device to your board ?

As per Kconfig the board selects I2C_DEVICES and this device is "default y if I2C_DEVICES". I've deliberately not hardcoded this device to the board to make it emulate a plain i.MX 8M Plus SoC (see also board documentation).

Then maybe add a test to be sure it is not bitroting?

Good idea. I haven't written a test in QEMU yet but I could certainly draw some inspiration from ds1338-test.c. This may take an iteration longer but won't be forgotten.

Best regards,
Bernhard

#49 lore raw

Re: [PATCH v2 18/18] hw/rtc: Add Ricoh RS5C372 RTC emulation

Am 10. Februar 2025 22:48:24 UTC schrieb Bernhard Beschow <[email protected]>:

Quoted 21 lines

Am 10. Februar 2025 14:26:00 UTC schrieb "Philippe Mathieu-Daudé" <[email protected]>:

Quoted 18 lines · Bernhard Beschow
Quoted 17 lines

Am 6. Februar 2025 17:32:31 UTC schrieb Peter Maydell <[email protected]>:

Quoted 14 lines · Bernhard Beschow
Quoted 12 lines

The implementation just allows Linux to determine date and time.

---
  MAINTAINERS         |   1 +
  hw/rtc/rs5c372.c    | 227 ++++++++++++++++++++++++++++++++++++++++++++
  hw/rtc/Kconfig      |   5 +
  hw/rtc/meson.build  |   1 +
  hw/rtc/trace-events |   4 +
  5 files changed, 238 insertions(+)

create mode 100644 hw/rtc/rs5c372.c

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

Should there be a patch after this one that adds this device to your board ?

As per Kconfig the board selects I2C_DEVICES and this device is "default y if I2C_DEVICES". I've deliberately not hardcoded this device to the board to make it emulate a plain i.MX 8M Plus SoC (see also board documentation).

Then maybe add a test to be sure it is not bitroting?

Good idea. I haven't written a test in QEMU yet but I could certainly draw some inspiration from ds1338-test.c. This may take an iteration longer but won't be forgotten.

There will be a test similar to ds1338-test.c in v3.

Quoted 3 lines

Best regards,
Bernhard