Add i.MX 8M Plus EVK machine
Subsystems (2)
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 includes the unreviewed patches of [3] and is structured as follows:
The first four patches fix some issues in device models reused by the new machine. Patches 5-18 add the machine step by step which includes documentation. Patches 19 and 20 add some further device models that I'd like to use with the new machine. The last patch is a fix I created during debugging but I don't rely on it.
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. The TCA6416 emulation is taken from the Xilinx fork where it is used in some cadence machines. Would the respective upstream maintainers be willing to maintain the device model upstream instead?
[1] https://www.nxp.com/design/design-center/development-boards-and-designs/8MPLUSLPD4-EVK
[2] https://archlinuxarm.org/platforms/armv8/generic
[3] https://patchew.org/QEMU/[email protected]/
Supersedes: [email protected]
Bernhard Beschow (21):
hw/char/imx_serial: Fix reset value of UFCR register hw/char/imx_serial: Update all state before restarting ageing timer hw/pci-host/designware: Expose MSI IRQ
hw/usb/hcd-dwc3: Align global registers size with Linux 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
hw/i2c: Import TCA6416 emulation from Xilinx hw/gpio/imx_gpio: Don't clear input GPIO values upon reset
MAINTAINERS | 16 + docs/system/arm/imx8mp-evk.rst | 84 ++++ docs/system/target-arm.rst | 1 + include/hw/arm/fsl-imx6.h | 4 +- include/hw/arm/fsl-imx7.h | 4 +- include/hw/arm/fsl-imx8mp.h | 284 +++++++++++ include/hw/char/imx_serial.h | 2 +- include/hw/misc/imx8mp_ccm.h | 97 ++++ include/hw/pci-host/designware.h | 1 + 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-imx6.c | 13 +- hw/arm/fsl-imx7.c | 13 +- hw/arm/fsl-imx8mp.c | 736 ++++++++++++++++++++++++++++ hw/arm/imx8mp-evk.c | 74 +++ hw/char/imx_serial.c | 7 +- hw/gpio/imx_gpio.c | 1 - hw/gpio/tca6416.c | 122 +++++ hw/misc/imx8mp_ccm.c | 315 ++++++++++++ hw/pci-host/designware.c | 7 +- 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 | 25 + hw/arm/meson.build | 2 + hw/gpio/Kconfig | 5 + hw/gpio/meson.build | 1 + hw/gpio/trace-events | 4 + hw/misc/meson.build | 1 + 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 + 38 files changed, 2195 insertions(+), 14 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_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/gpio/tca6416.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
PATCH 1/21 hw/char/imx_serial: Fix reset value of UFCR register
The value of the UCFR register is respected when echoing characters to the terminal, but its reset value is reserved. Fix the reset value to the one documented in the datasheet.
While at it move the related attribute out of the section of unimplemented registers since its value is actually respected.
--- include/hw/char/imx_serial.h | 2 +- hw/char/imx_serial.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
include/hw/char/imx_serial.h +1 -1
@@ -109,13 +109,13 @@ struct IMXSerialState {uint32_t ucr1;uint32_t ucr2;uint32_t uts1; +uint32_t ufcr;/* * The registers below are implemented just so that the * guest OS sees what it has written */ uint32_t onems; -uint32_t ufcr;uint32_t ubmr;uint32_t ubrc;uint32_t ucr3;
hw/char/imx_serial.c +1 -0
@@ -160,6 +160,7 @@ static void imx_serial_reset(IMXSerialState *s) s->ucr3 =0x700 ; s->ubmr =0 ; s->ubrc =4 ; + s->ufcr =BIT (11 ) |BIT (0 );fifo32_reset (&s->rx_fifo);timer_del (&s->ageing_timer);
Signature · 1 line
2.48.1
PATCH 2/21 hw/char/imx_serial: Update all state before restarting ageing timer
In reply to Bernhard BeschowFixes characters to be "echoed" after each keystroke rather than after every other since imx_serial_rx_fifo_ageing_timer_restart() would see ~UTS1_RXEMPTY only after every other keystroke.
--- hw/char/imx_serial.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
hw/char/imx_serial.c +3 -3
@@ -401,14 +401,14 @@ static void imx_put_data(void *opaque, uint32_t value)if (fifo32_num_used (&s->rx_fifo) >= rxtl) { s->usr1 |=USR1_RRDY ; } - -imx_serial_rx_fifo_ageing_timer_restart (s); - s->usr2 |=USR2_RDR ; s->uts1 &= ~UTS1_RXEMPTY ;if (value &URXD_BRK ) { s->usr2 |=USR2_BRCD ; } + +imx_serial_rx_fifo_ageing_timer_restart (s); +imx_update (s); }
Signature · 1 line
2.48.1
PATCH 3/21 hw/pci-host/designware: Expose MSI IRQ
In reply to Bernhard BeschowFixes INTD and MSI interrupts poking the same IRQ line without keeping track of each other's IRQ level. Furthermore, SoCs such as the i.MX 8M Plus don't share the MSI IRQ with the INTx lines, so expose it as a dedicated pin.
--- include/hw/arm/fsl-imx6.h | 4 +++- include/hw/arm/fsl-imx7.h | 4 +++- include/hw/pci-host/designware.h | 1 + hw/arm/fsl-imx6.c | 13 ++++++++++++- hw/arm/fsl-imx7.c | 13 ++++++++++++- hw/pci-host/designware.c | 7 +++---- hw/arm/Kconfig | 2 ++ 7 files changed, 36 insertions(+), 8 deletions(-)
include/hw/arm/fsl-imx6.h +3 -1
@@ -33,6 +33,7 @@#include "hw/usb/chipidea.h" #include "hw/usb/imx-usb-phy.h" #include "hw/pci-host/designware.h" +#include "hw/or-irq.h" #include "exec/memory.h" #include "cpu.h" #include "qom/object.h"
@@ -73,6 +74,7 @@ struct FslIMX6State {ChipideaState usb[FSL_IMX6_NUM_USBS ];IMXFECState eth;DesignwarePCIEHost pcie; +OrIRQState pcie4_msi_irq;MemoryRegion rom;MemoryRegion caam;MemoryRegion ocram;
@@ -457,7 +459,7 @@ struct FslIMX6State {#define FSL_IMX6_PCIE1_IRQ 120#define FSL_IMX6_PCIE2_IRQ 121#define FSL_IMX6_PCIE3_IRQ 122 -#define FSL_IMX6_PCIE4_IRQ 123 +#define FSL_IMX6_PCIE4_MSI_IRQ 123#define FSL_IMX6_DCIC1_IRQ 124#define FSL_IMX6_DCIC2_IRQ 125#define FSL_IMX6_MLB150_HIGH_IRQ 126
include/hw/arm/fsl-imx7.h +3 -1
@@ -36,6 +36,7 @@#include "hw/net/imx_fec.h" #include "hw/pci-host/designware.h" #include "hw/usb/chipidea.h" +#include "hw/or-irq.h" #include "cpu.h" #include "qom/object.h" #include "qemu/units.h"
@@ -85,6 +86,7 @@ struct FslIMX7State {IMX7GPRState gpr;ChipideaState usb[FSL_IMX7_NUM_USBS ];DesignwarePCIEHost pcie; +OrIRQState pcie4_msi_irq;MemoryRegion rom;MemoryRegion caam;MemoryRegion ocram;
@@ -428,7 +430,7 @@ enum FslIMX7IRQs {FSL_IMX7_PCI_INTA_IRQ =125 ,FSL_IMX7_PCI_INTB_IRQ =124 ,FSL_IMX7_PCI_INTC_IRQ =123 , -FSL_IMX7_PCI_INTD_IRQ =122 , +FSL_IMX7_PCI_INTD_MSI_IRQ =122 , FSL_IMX7_UART7_IRQ = 126,
include/hw/pci-host/designware.h +1 -0
@@ -86,6 +86,7 @@ struct DesignwarePCIEHost {MemoryRegion io;qemu_irq irqs[4 ]; +qemu_irq msi; } pci;MemoryRegion mmio;
hw/arm/fsl-imx6.c +12 -1
@@ -106,6 +106,8 @@ static void fsl_imx6_init(Object *obj)object_initialize_child (obj,"eth" , &s->eth,TYPE_IMX_ENET );object_initialize_child (obj,"pcie" , &s->pcie,TYPE_DESIGNWARE_PCIE_HOST ); +object_initialize_child (obj,"pcie4-msi-irq" , &s->pcie4_msi_irq, +TYPE_OR_IRQ ); }static void fsl_imx6_realize (DeviceState *dev,Error **errp)
@@ -435,14 +437,23 @@ static void fsl_imx6_realize(DeviceState *dev, Error **errp)sysbus_realize (SYS_BUS_DEVICE (&s->pcie), &error_abort);sysbus_mmio_map (SYS_BUS_DEVICE (&s->pcie),0 , FSL_IMX6_PCIe_REG_ADDR); +object_property_set_int (OBJECT (&s->pcie4_msi_irq),"num-lines" ,2 , + &error_abort); +qdev_realize (DEVICE (&s->pcie4_msi_irq),NULL , &error_abort); + + irq =qdev_get_gpio_in (DEVICE (&s->a9mpcore),FSL_IMX6_PCIE4_MSI_IRQ ); +qdev_connect_gpio_out (DEVICE (&s->pcie4_msi_irq),0 , irq); + irq =qdev_get_gpio_in (DEVICE (&s->a9mpcore),FSL_IMX6_PCIE1_IRQ );sysbus_connect_irq (SYS_BUS_DEVICE (&s->pcie),0 , irq); irq =qdev_get_gpio_in (DEVICE (&s->a9mpcore),FSL_IMX6_PCIE2_IRQ );sysbus_connect_irq (SYS_BUS_DEVICE (&s->pcie),1 , irq); irq =qdev_get_gpio_in (DEVICE (&s->a9mpcore),FSL_IMX6_PCIE3_IRQ );sysbus_connect_irq (SYS_BUS_DEVICE (&s->pcie),2 , irq); - irq =qdev_get_gpio_in (DEVICE (&s->a9mpcore),FSL_IMX6_PCIE4_IRQ ); + irq =qdev_get_gpio_in (DEVICE (&s->pcie4_msi_irq),0 );sysbus_connect_irq (SYS_BUS_DEVICE (&s->pcie),3 , irq); + irq =qdev_get_gpio_in (DEVICE (&s->pcie4_msi_irq),1 ); +sysbus_connect_irq (SYS_BUS_DEVICE (&s->pcie),4 , irq);/* * PCIe PHY
hw/arm/fsl-imx7.c +12 -1
@@ -150,6 +150,8 @@ static void fsl_imx7_init(Object *obj)* PCIE */ object_initialize_child (obj,"pcie" , &s->pcie,TYPE_DESIGNWARE_PCIE_HOST ); +object_initialize_child (obj,"pcie4-msi-irq" , &s->pcie4_msi_irq, +TYPE_OR_IRQ );/* * USBs
@@ -597,14 +599,23 @@ static void fsl_imx7_realize(DeviceState *dev, Error **errp)sysbus_realize (SYS_BUS_DEVICE (&s->pcie), &error_abort);sysbus_mmio_map (SYS_BUS_DEVICE (&s->pcie),0 ,FSL_IMX7_PCIE_REG_ADDR ); +object_property_set_int (OBJECT (&s->pcie4_msi_irq),"num-lines" ,2 , + &error_abort); +qdev_realize (DEVICE (&s->pcie4_msi_irq),NULL , &error_abort); + + irq =qdev_get_gpio_in (DEVICE (&s->a7mpcore),FSL_IMX7_PCI_INTD_MSI_IRQ ); +qdev_connect_gpio_out (DEVICE (&s->pcie4_msi_irq),0 , irq); + irq =qdev_get_gpio_in (DEVICE (&s->a7mpcore),FSL_IMX7_PCI_INTA_IRQ );sysbus_connect_irq (SYS_BUS_DEVICE (&s->pcie),0 , irq); irq =qdev_get_gpio_in (DEVICE (&s->a7mpcore),FSL_IMX7_PCI_INTB_IRQ );sysbus_connect_irq (SYS_BUS_DEVICE (&s->pcie),1 , irq); irq =qdev_get_gpio_in (DEVICE (&s->a7mpcore),FSL_IMX7_PCI_INTC_IRQ );sysbus_connect_irq (SYS_BUS_DEVICE (&s->pcie),2 , irq); - irq =qdev_get_gpio_in (DEVICE (&s->a7mpcore),FSL_IMX7_PCI_INTD_IRQ ); + irq =qdev_get_gpio_in (DEVICE (&s->pcie4_msi_irq),0 );sysbus_connect_irq (SYS_BUS_DEVICE (&s->pcie),3 , irq); + irq =qdev_get_gpio_in (DEVICE (&s->pcie4_msi_irq),1 ); +sysbus_connect_irq (SYS_BUS_DEVICE (&s->pcie),4 , irq);/* * USBs
hw/pci-host/designware.c +3 -4
@@ -55,8 +55,6 @@#define DESIGNWARE_PCIE_ATU_DEVFN (x) (((x) >> 16) & 0xff)#define DESIGNWARE_PCIE_ATU_UPPER_TARGET 0x91C -#define DESIGNWARE_PCIE_IRQ_MSI 3 -static DesignwarePCIEHost *designware_pcie_root_to_host (DesignwarePCIERoot *root) {
@@ -90,7 +88,7 @@ static void designware_pcie_root_msi_write(void *opaque, hwaddr addr, root->msi.intr[0 ].status |=BIT (val) & root->msi.intr[0 ].enable;if (root->msi.intr[0 ].status & ~root->msi.intr[0 ].mask) { -qemu_set_irq (host->pci.irqs[DESIGNWARE_PCIE_IRQ_MSI ],1 ); +qemu_set_irq (host->pci.msi,1 ); } }
@@ -335,7 +333,7 @@ static void designware_pcie_root_config_write(PCIDevice *d, uint32_t address,case DESIGNWARE_PCIE_MSI_INTR0_STATUS : root->msi.intr[0 ].status ^= val;if (!root->msi.intr[0 ].status) { -qemu_set_irq (host->pci.irqs[DESIGNWARE_PCIE_IRQ_MSI ],0 ); +qemu_set_irq (host->pci.msi,0 ); }break ;
@@ -680,6 +678,7 @@ static void designware_pcie_host_realize(DeviceState *dev, Error **errp)for (i =0 ; i <ARRAY_SIZE (s->pci.irqs); i++) {sysbus_init_irq (sbd, &s->pci.irqs[i]); } +sysbus_init_irq (sbd, &s->pci.msi); memory_region_init_io(&s->mmio, OBJECT(s),
hw/arm/Kconfig +2 -0
@@ -513,6 +513,7 @@ config FSL_IMX6 select IMX_I2C select IMX_USBPHY select WDT_IMX2 + select OR_IRQ select PL310 # cache controller select PCI_EXPRESS_DESIGNWARE select SDHCI
@@ -571,6 +572,7 @@ config FSL_IMX7 select IMX_FEC select IMX_I2C select WDT_IMX2 + select OR_IRQ select PCI_EXPRESS_DESIGNWARE select SDHCI select UNIMP
Signature · 1 line
2.48.1
PATCH 4/21 hw/usb/hcd-dwc3: Align global registers size with Linux
In reply to Bernhard BeschowWhile 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
@@ -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
@@ -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 0xC100static 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
Re: [PATCH 04/21] hw/usb/hcd-dwc3: Align global registers size with Linux
Quoted 5 lines · Bernhard Beschow
While at it add missing GUSB2RHBCTL register as found in i.MX 8M Plus reference manual.
Signed-off-by Bernhard Beschow <[email protected]>
thanks
-- PMM
PATCH 5/21 hw/arm: Add i.MX 8M Plus EVK board
In reply to Bernhard BeschowAs 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 | 47 +++++ 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 | 13 ++ hw/arm/meson.build | 2 + 8 files changed, 687 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
@@ -819,6 +819,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: Odd Fixes +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 +47 -0
47 lines not on this page · raw message
docs/system/target-arm.rst +1 -0
@@ -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 +13 -0
@@ -577,6 +577,19 @@ config FSL_IMX7 select SDHCI select UNIMP +config FSL_IMX8MP + bool + imply TEST_DEVICES + 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
@@ -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
Re: [PATCH 05/21] hw/arm: Add i.MX 8M Plus EVK board
Quoted 27 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.Signed-off-by Bernhard Beschow <[email protected]>--- MAINTAINERS | 9 + docs/system/arm/imx8mp-evk.rst | 47 +++++ 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 | 13 ++ hw/arm/meson.build | 2 + 8 files changed, 687 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.cMAINTAINERS +0
-0
MAINTAINERS F: hw/pci-host/designware.c · line 825
Quoted 7 lines
MAINTAINERS +4
-0@@ -819,6 +819,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: Odd Fixes
I'd rather we didn't take on a new board model that starts out in the "odd fixes" state. If you don't have enough time to look after it, it seems unlikely that anybody else is going to want to take it over.
Quoted 24 lines
MAINTAINERS +20
-0+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] +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++) {
MAINTAINERS F: hw/pci-host/designware.c
Quoted 10 lines
MAINTAINERS +10
-0+ /* 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 form Linux output: "arch_timer: cp15 timer(s) running at + * 8.00MHz (phys)".
"from"
Quoted 24 lines
MAINTAINERS +18
-0+ */ + object_property_set_int(OBJECT(&s->cpu[i]), "cntfrq", 8000000, + &error_abort); + + if (i) { + /* + * Secondary CPUs start in powered-down state (and can be + * powered up via the SRC system reset controller) + */ + object_property_set_bool(OBJECT(&s->cpu[i]), "start-powered-off", + true, &error_abort); + } + + if (!qdev_realize(DEVICE(&s->cpu[i]), NULL, errp)) { + return; + } + } +hw/arm/Kconfig +0
-0
hw/arm/Kconfig config FSL_IMX7 · line 582
Quoted 6 lines
hw/arm/Kconfig +3
-0@@ -577,6 +577,19 @@ config FSL_IMX7 select SDHCI select UNIMP +config FSL_IMX8MP + bool + imply TEST_DEVICES
Why do we need TEST_DEVICES ?
hw/arm/Kconfig config FSL_IMX7 · line 594
Quoted 12 lines
hw/arm/Kconfig +10
-0+ 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
Looks good otherwise.
thanks
-- PMM
Re: [PATCH 05/21] hw/arm: Add i.MX 8M Plus EVK board
Am 28. Januar 2025 14:29:53 UTC schrieb Peter Maydell <[email protected]>:
Quoted 31 lines · Bernhard Beschow
Quoted 30 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.Signed-off-by Bernhard Beschow <[email protected]>--- MAINTAINERS | 9 + docs/system/arm/imx8mp-evk.rst | 47 +++++ 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 | 13 ++ hw/arm/meson.build | 2 + 8 files changed, 687 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.cMAINTAINERS +0
-0@@ -819,6 +819,15 @@ F: hw/pci-host/designware.c F: include/hw/pci-host/designware.h F: docs/system/arm/mcimx7d-sabre.rst
Quoted 9 lines
MAINTAINERS F: hw/pci-host/designware.c · line 825
Quoted 4 lines
MAINTAINERS +4
-0+MCIMX8MP-EVK / i.MX8MP +M: Bernhard Beschow <[email protected]> +L: [email protected] +S: Odd FixesI'd rather we didn't take on a new board model that starts out in the "odd fixes" state. If you don't have enough time to look after it, it seems unlikely that anybody else is going to want to take it over.
I'd look after it, but I'd also not raise expectations regarding commercial grade support. What state would you suggest?
Quoted 29 lines
Quoted 29 lines
MAINTAINERS +24
-0+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] +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,
Quoted 8 lines
MAINTAINERS
Quoted 6 lines
MAINTAINERS +6
-0+ &error_abort); + } + + /* + * Magic value form Linux output: "arch_timer: cp15 timer(s) running at + * 8.00MHz (phys)"."from"
Will fix.
Quoted 28 lines
Quoted 28 lines
MAINTAINERS +18
-0+ */ + object_property_set_int(OBJECT(&s->cpu[i]), "cntfrq", 8000000, + &error_abort); + + if (i) { + /* + * Secondary CPUs start in powered-down state (and can be + * powered up via the SRC system reset controller) + */ + object_property_set_bool(OBJECT(&s->cpu[i]), "start-powered-off", + true, &error_abort); + } + + if (!qdev_realize(DEVICE(&s->cpu[i]), NULL, errp)) { + return; + } + } +hw/arm/Kconfig +0
-0@@ -577,6 +577,19 @@ config FSL_IMX7 select SDHCI select UNIMP
Quoted 5 lines
hw/arm/Kconfig config FSL_IMX7 · line 582
Quoted 3 lines
hw/arm/Kconfig +3
-0+config FSL_IMX8MP + bool + imply TEST_DEVICESWhy do we need
TEST_DEVICES?
Copied from FSL_IMX7. Will drop.
Quoted 15 lines
hw/arm/Kconfig config FSL_IMX7 · line 594
Quoted 13 lines
hw/arm/Kconfig +10
-0+ select ARM_GIC + select IMX + select UNIMP + +config FSL_IMX8MP_EVK + bool + default y + depends on TCG && AARCH64 + select FSL_IMX8MP + config ARM_SMMUV3 boolLooks good otherwise.
Thanks,
Bernhard
Quoted 3 lines
thanks
-- PMM
Re: [PATCH 05/21] hw/arm: Add i.MX 8M Plus EVK board
Quoted 24 lines · Bernhard Beschow
Am 28. Januar 2025 14:29:53 UTC schrieb Peter Maydell <[email protected]>:
Quoted 10 lines · Bernhard Beschow
Quoted 9 lines
MAINTAINERS +0
-0@@ -819,6 +819,15 @@ F: hw/pci-host/designware.c F: include/hw/pci-host/designware.h F: docs/system/arm/mcimx7d-sabre.rstQuoted 9 lines
MAINTAINERS F: hw/pci-host/designware.c · line 825
Quoted 4 lines
MAINTAINERS +4
-0+MCIMX8MP-EVK / i.MX8MP +M: Bernhard Beschow <[email protected]> +L: [email protected] +S: Odd FixesI'd rather we didn't take on a new board model that starts out in the "odd fixes" state. If you don't have enough time to look after it, it seems unlikely that anybody else is going to want to take it over.
Quoted 3 lines
I'd look after it, but I'd also not raise expectations regarding commercial grade support. What state would you suggest?
That's
Maintained: Someone actually looks after it.
(There's another step above that which is
Supported: Someone is actually paid to look after this.)
thanks
-- PMM
Re: [PATCH 05/21] hw/arm: Add i.MX 8M Plus EVK board
Am 29. Januar 2025 12:17:33 UTC schrieb Peter Maydell <[email protected]>:
Quoted 25 lines · Bernhard Beschow
Quoted 24 lines
Am 28. Januar 2025 14:29:53 UTC schrieb Peter Maydell <[email protected]>:
Quoted 19 lines · Bernhard Beschow
MAINTAINERS F: hw/pci-host/designware.c · line 825
Quoted 13 lines
MAINTAINERS +4
-0@@ -819,6 +819,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: Odd FixesI'd rather we didn't take on a new board model that starts out in the "odd fixes" state. If you don't have enough time to look after it, it seems unlikely that anybody else is going to want to take it over.
Quoted 8 lines
Quoted 3 lines
I'd look after it, but I'd also not raise expectations regarding commercial grade support. What state would you suggest?
That's
Maintained: Someone actually looks after it.
(There's another step above that which is
Supported: Someone is actually paid to look after this.)
Alright, that's what I meant. Will fix.
Best regards,
Bernhard
Quoted 3 lines
thanks
-- PMM
PATCH 6/21 hw/arm/fsl-imx8mp: Implement clock tree
In reply to Bernhard BeschowFixes 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 | 3 + include/hw/misc/imx8mp_ccm.h | 97 ++++++++++ hw/arm/fsl-imx8mp.c | 20 +++ hw/misc/imx8mp_ccm.c | 315 +++++++++++++++++++++++++++++++++ hw/misc/meson.build | 1 + 7 files changed, 439 insertions(+) create mode 100644 include/hw/misc/imx8mp_ccm.h create mode 100644 hw/misc/imx8mp_ccm.c
MAINTAINERS +2 -0
@@ -825,7 +825,9 @@ L: [email protected] S: Odd Fixes 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
@@ -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 +3 -0
@@ -12,6 +12,7 @@#include "cpu.h" #include "hw/char/imx_serial.h" #include "hw/intc/arm_gicv3_common.h" +#include "hw/misc/imx8mp_ccm.h" #include "qom/object.h" #include "qemu/units.h"
@@ -32,6 +33,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_ccm.h new file +97 -0
97 lines not on this page · raw message
hw/arm/fsl-imx8mp.c +20 -0
@@ -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_ccm.c new file +315 -0
315 lines not on this page · raw message
hw/misc/meson.build +1 -0
@@ -65,6 +65,7 @@ system_ss.add(when: 'CONFIG_IMX', if_true: files( 'imx7_src.c', 'imx7_gpr.c', 'imx7_snvs.c', + 'imx8mp_ccm.c', 'imx_ccm.c', 'imx_rngc.c', ))
Signature · 1 line
2.48.1
Re: [PATCH 06/21] hw/arm/fsl-imx8mp: Implement clock tree
Quoted 109 lines · Bernhard Beschow
Fixes quite a few stack traces during the Linux boot process. Also provides the clocks for devices added later, e.g. enet1.
Signed-off-by Bernhard Beschow <[email protected]>--- MAINTAINERS | 2 + docs/system/arm/imx8mp-evk.rst | 1 + include/hw/arm/fsl-imx8mp.h | 3 + include/hw/misc/imx8mp_ccm.h | 97 ++++++++++ hw/arm/fsl-imx8mp.c | 20 +++ hw/misc/imx8mp_ccm.c | 315 +++++++++++++++++++++++++++++++++ hw/misc/meson.build | 1 + 7 files changed, 439 insertions(+) create mode 100644 include/hw/misc/imx8mp_ccm.h create mode 100644 hw/misc/imx8mp_ccm.cinclude/hw/misc/imx8mp_ccm.h new file +87
-0@@ -0,0 +1,97 @@ +/* +* Copyright (c) 2025 Bernhard Beschow <[email protected]> +* +* i.MX8MP CCM, ANALOG IP blocks 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 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, +}; + +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]; +}; + + +#define TYPE_IMX8MP_ANALOG "imx8mp.analog" +OBJECT_DECLARE_SIMPLE_TYPE(IMX8MPAnalogState, IMX8MP_ANALOG) + +struct IMX8MPAnalogState { + IMXCCMState parent_obj;
include/hw/misc/imx8mp_ccm.h line 97
Quoted 10 lines
include/hw/misc/imx8mp_ccm.h new file +10
-0+ +struct { +MemoryRegion container; +MemoryRegion analog; + } mmio; + + uint32_t analog[ANALOG_MAX]; +}; + +#endif /* IMX8MP_CCM_H */
This seems to be implementing two separate devices in a single source file. Generally we prefer one device per file. Is there a reason they can't be split?
thanks
-- PMM
Re: [PATCH 06/21] hw/arm/fsl-imx8mp: Implement clock tree
Am 28. Januar 2025 14:35:14 UTC schrieb Peter Maydell <[email protected]>:
Quoted 116 lines · Bernhard Beschow
Quoted 115 lines
Fixes quite a few stack traces during the Linux boot process. Also provides the clocks for devices added later, e.g. enet1.
Signed-off-by Bernhard Beschow <[email protected]>--- MAINTAINERS | 2 + docs/system/arm/imx8mp-evk.rst | 1 + include/hw/arm/fsl-imx8mp.h | 3 + include/hw/misc/imx8mp_ccm.h | 97 ++++++++++ hw/arm/fsl-imx8mp.c | 20 +++ hw/misc/imx8mp_ccm.c | 315 +++++++++++++++++++++++++++++++++ hw/misc/meson.build | 1 + 7 files changed, 439 insertions(+) create mode 100644 include/hw/misc/imx8mp_ccm.h create mode 100644 hw/misc/imx8mp_ccm.cinclude/hw/misc/imx8mp_ccm.h new file +93
-0@@ -0,0 +1,97 @@ +/* +* Copyright (c) 2025 Bernhard Beschow <[email protected]> +* +* i.MX8MP CCM, ANALOG IP blocks 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 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, +}; + +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]; +}; + + +#define TYPE_IMX8MP_ANALOG "imx8mp.analog" +OBJECT_DECLARE_SIMPLE_TYPE(IMX8MPAnalogState, IMX8MP_ANALOG) + +struct IMX8MPAnalogState { + IMXCCMState parent_obj; + + struct { + MemoryRegion container; + MemoryRegion analog; + } mmio; +
Quoted 8 lines
include/hw/misc/imx8mp_ccm.h line 97
Quoted 4 lines
include/hw/misc/imx8mp_ccm.h new file +4
-0+ uint32_t analog[ANALOG_MAX]; +}; + +#endif /* IMX8MP_CCM_H */ This seems to be implementing two separate devices in a single source file. Generally we prefer one device per file. Is there a reason they can't be split?
I took inspiration from i.mx7 where these two are also implemented in one file, presumably because both share some code. This isn't the case here so I'm more than happy to split.
Best regards,
Bernhard
Quoted 3 lines
thanks
-- PMM
PATCH 7/21 hw/arm/fsl-imx8mp: Add SNVS
In reply to Bernhard BeschowSNVS 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
@@ -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
@@ -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_ccm.h" #include "qom/object.h" #include "qemu/units.h"
@@ -35,6 +36,7 @@ struct FslImx8mpState {GICv3State gic;IMX8MPCCMState ccm;IMX8MPAnalogState analog; +IMX7SNVSState snvs;IMXSerialState uart[FSL_IMX8MP_NUM_UARTS ]; };
hw/arm/fsl-imx8mp.c +10 -0
@@ -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
Re: [PATCH 07/21] hw/arm/fsl-imx8mp: Add SNVS
Quoted 5 lines · 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.
Quoted 7 lines
Signed-off-by Bernhard Beschow <[email protected]>--- 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(+)
thanks
-- PMM
PATCH 8/21 hw/arm/fsl-imx8mp: Add USDHC storage controllers
In reply to Bernhard BeschowThe 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 | 39 +++++++++++++++++++++++----------- 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, 81 insertions(+), 12 deletions(-)
docs/system/arm/imx8mp-evk.rst +27 -12
@@ -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
@@ -25,25 +26,39 @@ for loading a Linux kernel. Direct Linux Kernel Boot '''''''''''''''''''''''' -Linux mainline v6.12 release is tested at the time of writing. To build a Linux -mainline kernel that can be booted by the ``imx8mp-evk`` machine, simply -configure the kernel using the defconfig configuration: +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 three steps. First run the following command in the +toplevel directory of the Buildroot source tree: .. code-block:: bash - $ export ARCH=arm64 - $ export CROSS_COMPILE=aarch64-linux-gnu- - $ make defconfig + $ make freescale_imx8mpevk_defconfig $ make -To boot the newly built Linux kernel in QEMU with the ``imx8mp-evk`` machine, -run: +Once finished successfully there is an ``output/image`` subfolder. Navigate into +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 + + $ 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: .. code-block:: bash $ qemu-system-aarch64 -M imx8mp-evk -smp 4 -m 3G \ -display none -serial null -serial stdio \ - -kernel arch/arm64/boot/Image \ - -dtb arch/arm64/boot/dts/freescale/imx8mp-evk.dtb \ - -initrd /path/to/rootfs.ext4 \ - -append "root=/dev/ram" + -kernel Image \ + -dtb imx8mp-evk-patched.dtb \ + -append "root=/dev/mmcblk2p2" \ + -drive file=sdcard.img,if=sd,bus=2,format=raw,id=mmcblk2
include/hw/arm/fsl-imx8mp.h +7 -0
@@ -14,6 +14,7 @@#include "hw/intc/arm_gicv3_common.h" #include "hw/misc/imx7_snvs.h" #include "hw/misc/imx8mp_ccm.h" +#include "hw/sd/sdhci.h" #include "qom/object.h" #include "qemu/units.h"
@@ -27,6 +28,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 {
@@ -38,6 +40,7 @@ struct FslImx8mpState {IMX8MPAnalogState analog;IMX7SNVSState snvs;IMXSerialState uart[FSL_IMX8MP_NUM_UARTS ]; +SDHCIState usdhc[FSL_IMX8MP_NUM_USDHCS ]; };enum FslImx8mpMemoryRegions {
@@ -183,6 +186,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
@@ -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
@@ -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
@@ -582,6 +582,7 @@ config FSL_IMX8MP imply TEST_DEVICES select ARM_GIC select IMX + select SDHCI select UNIMP config FSL_IMX8MP_EVK
Signature · 1 line
2.48.1
Re: [PATCH 08/21] hw/arm/fsl-imx8mp: Add USDHC storage controllers
Quoted 39 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.
Signed-off-by Bernhard Beschow <[email protected]>---
docs/system/arm/imx8mp-evk.rst | 39 +++++++++++++++++++++++----------- 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, 81 insertions(+), 12 deletions(-)docs/system/arm/imx8mp-evk.rst +1
-0@@ -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@@ -25,25 +26,39 @@ for loading a Linux kernel.Direct Linux Kernel Boot
''''''''''''''''''''''''docs/system/arm/imx8mp-evk.rst +4
-3-Linux mainline v6.12 release is tested at the time of writing. To build a Linux -mainline kernel that can be booted by the ``imx8mp-evk`` machine, simply -configure the kernel using the defconfig configuration: +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 three steps. First run the following command in the +toplevel directory of the Buildroot source tree:.. code-block:: bash
docs/system/arm/imx8mp-evk.rst for loading a Linux kernel. · line 37
Quoted 5 lines
docs/system/arm/imx8mp-evk.rst +1
-3- $ export ARCH=arm64 - $ export CROSS_COMPILE=aarch64-linux-gnu- - $ make defconfig + $ make freescale_imx8mpevk_defconfig $ make
Adding documentation that is removed a few patches later seems unnecessary. Maybe you could keep the bare kernel docs as that could also be useful or not add it in the first place? But if this is already written keeping it may make more sense than dropping it.
Regards,
BALATON Zoltan
Quoted 174 lines
docs/system/arm/imx8mp-evk.rst +17
-2-To boot the newly built Linux kernel in QEMU with the ``imx8mp-evk`` machine, -run: +Once finished successfully there is an ``output/image`` subfolder. Navigate into +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 + + $ 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:.. code-block:: bash
$ qemu-system-aarch64 -M imx8mp-evk -smp 4 -m 3G \ -display none -serial null -serial stdio \docs/system/arm/imx8mp-evk.rst +4
-4- -kernel arch/arm64/boot/Image \ - -dtb arch/arm64/boot/dts/freescale/imx8mp-evk.dtb \ - -initrd /path/to/rootfs.ext4 \ - -append "root=/dev/ram" + -kernel Image \ + -dtb imx8mp-evk-patched.dtb \ + -append "root=/dev/mmcblk2p2" \ + -drive file=sdcard.img,if=sd,bus=2,format=raw,id=mmcblk2include/hw/arm/fsl-imx8mp.h +7
-0@@ -14,6 +14,7 @@#include "hw/intc/arm_gicv3_common.h" #include "hw/misc/imx7_snvs.h" #include "hw/misc/imx8mp_ccm.h" +#include "hw/sd/sdhci.h" #include "qom/object.h" #include "qemu/units.h" @@ -27,6 +28,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 {@@ -38,6 +40,7 @@ struct FslImx8mpState {IMX8MPAnalogState analog;IMX7SNVSState snvs;IMXSerialState uart[FSL_IMX8MP_NUM_UARTS ]; +SDHCIState usdhc[FSL_IMX8MP_NUM_USDHCS ]; };enum FslImx8mpMemoryRegions {@@ -183,6 +186,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@@ -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@@ -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@@ -582,6 +582,7 @@ config FSL_IMX8MP imply TEST_DEVICES select ARM_GIC select IMX + select SDHCI select UNIMPconfig
FSL_IMX8MP_EVK
Re: [PATCH 08/21] hw/arm/fsl-imx8mp: Add USDHC storage controllers
Am 21. Januar 2025 02:52:58 UTC schrieb BALATON Zoltan <[email protected]>:
Quoted 40 lines · Bernhard Beschow
Quoted 39 lines
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.
Signed-off-by Bernhard Beschow <[email protected]>---
docs/system/arm/imx8mp-evk.rst | 39 +++++++++++++++++++++++----------- 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, 81 insertions(+), 12 deletions(-)docs/system/arm/imx8mp-evk.rst +1
-0@@ -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@@ -25,25 +26,39 @@ for loading a Linux kernel.Direct Linux Kernel Boot
''''''''''''''''''''''''docs/system/arm/imx8mp-evk.rst +4
-3-Linux mainline v6.12 release is tested at the time of writing. To build a Linux -mainline kernel that can be booted by the ``imx8mp-evk`` machine, simply -configure the kernel using the defconfig configuration: +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 three steps. First run the following command in the +toplevel directory of the Buildroot source tree:.. code-block:: bash
Quoted 7 lines
docs/system/arm/imx8mp-evk.rst for loading a Linux kernel. · line 37
Quoted 5 lines
docs/system/arm/imx8mp-evk.rst +1
-3- $ export ARCH=arm64 - $ export CROSS_COMPILE=aarch64-linux-gnu- - $ make defconfig + $ make freescale_imx8mpevk_defconfig $ makeAdding documentation that is removed a few patches later seems unnecessary. Maybe you could keep the bare kernel docs as that could also be useful or not add it in the first place? But if this is already written keeping it may make more sense than dropping it.
I'd like the documentation to be complete and easy to follow at the same time. Buildroot achieves both, and allows for generating a cpio initrd instead. So I'd start with that which just requires minor adjustments here.
Best regards,
Bernhard
Quoted 178 lines
Regards,
BALATON ZoltanQuoted 174 lines
docs/system/arm/imx8mp-evk.rst +17
-2-To boot the newly built Linux kernel in QEMU with the ``imx8mp-evk`` machine, -run: +Once finished successfully there is an ``output/image`` subfolder. Navigate into +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 + + $ 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:.. code-block:: bash
$ qemu-system-aarch64 -M imx8mp-evk -smp 4 -m 3G \ -display none -serial null -serial stdio \docs/system/arm/imx8mp-evk.rst +4
-4- -kernel arch/arm64/boot/Image \ - -dtb arch/arm64/boot/dts/freescale/imx8mp-evk.dtb \ - -initrd /path/to/rootfs.ext4 \ - -append "root=/dev/ram" + -kernel Image \ + -dtb imx8mp-evk-patched.dtb \ + -append "root=/dev/mmcblk2p2" \ + -drive file=sdcard.img,if=sd,bus=2,format=raw,id=mmcblk2include/hw/arm/fsl-imx8mp.h +7
-0@@ -14,6 +14,7 @@#include "hw/intc/arm_gicv3_common.h" #include "hw/misc/imx7_snvs.h" #include "hw/misc/imx8mp_ccm.h" +#include "hw/sd/sdhci.h" #include "qom/object.h" #include "qemu/units.h" @@ -27,6 +28,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 {@@ -38,6 +40,7 @@ struct FslImx8mpState {IMX8MPAnalogState analog;IMX7SNVSState snvs;IMXSerialState uart[FSL_IMX8MP_NUM_UARTS ]; +SDHCIState usdhc[FSL_IMX8MP_NUM_USDHCS ]; };enum FslImx8mpMemoryRegions {@@ -183,6 +186,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@@ -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@@ -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@@ -582,6 +582,7 @@ config FSL_IMX8MP imply TEST_DEVICES select ARM_GIC select IMX + select SDHCI select UNIMPconfig
FSL_IMX8MP_EVK
PATCH 9/21 hw/arm/fsl-imx8mp: Add PCIe support
In reply to Bernhard BeschowLinux checks for the PLLs in the PHY to be locked, so implement a model emulating that.
--- MAINTAINERS | 2 + docs/system/arm/imx8mp-evk.rst | 13 +++++ 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, 177 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
@@ -826,8 +826,10 @@ S: Odd Fixes 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 +13 -0
@@ -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
@@ -62,3 +63,15 @@ Now that everything is prepared the newly built image can be run in the QEMU -dtb imx8mp-evk-patched.dtb \ -append "root=/dev/mmcblk2p2" \ -drive file=sdcard.img,if=sd,bus=2,format=raw,id=mmcblk2 + +Using PCI Devices +----------------- + +The PCI Express controller spawns two PCI buses, of which only one can be used. +By default QEMU assigns the wrong bus, so the correct one has to be specified +manually by adding ``bus=dw-pcie``. For example, when adding an Intel e1000 +network card, the command line looks like: + +.. code-block:: bash + + $ qemu-system-aarch64 -M imximp-evk ... -device virtio-net-pci,bus=dw-pcie
include/hw/arm/fsl-imx8mp.h +10 -0
@@ -14,6 +14,8 @@#include "hw/intc/arm_gicv3_common.h" #include "hw/misc/imx7_snvs.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"
@@ -41,6 +43,8 @@ struct FslImx8mpState {IMX7SNVSState snvs;IMXSerialState uart[FSL_IMX8MP_NUM_UARTS ];SDHCIState usdhc[FSL_IMX8MP_NUM_USDHCS ]; +DesignwarePCIEHost pcie; +FslImx8mPciePhyState pcie_phy; };enum FslImx8mpMemoryRegions {
@@ -196,6 +200,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
@@ -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
@@ -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
@@ -579,9 +579,12 @@ config FSL_IMX7 config FSL_IMX8MP bool + imply PCI_DEVICES imply TEST_DEVICES select ARM_GIC select IMX + select PCI_EXPRESS_DESIGNWARE + select PCI_EXPRESS_FSL_IMX8M_PHY select SDHCI select UNIMP
hw/pci-host/Kconfig +3 -0
@@ -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
@@ -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
Re: [PATCH 09/21] hw/arm/fsl-imx8mp: Add PCIe support
Quoted 24 lines · Bernhard Beschow
Linux checks for the PLLs in the PHY to be locked, so implement a model emulating that.
Signed-off-by Bernhard Beschow <[email protected]>docs/system/arm/imx8mp-evk.rst +3
-0@@ -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@@ -62,3 +63,15 @@ Now that everything is prepared the newly built image can be run in the QEMU -dtb imx8mp-evk-patched.dtb \ -append "root=/dev/mmcblk2p2" \ -drive file=sdcard.img,if=sd,bus=2,format=raw,id=mmcblk2 + +Using PCI Devices
docs/system/arm/imx8mp-evk.rst Now that everything is prepared the newly built image can be run in the QEMU · line 77
Quoted 10 lines
docs/system/arm/imx8mp-evk.rst +10
-0+----------------- + +The PCI Express controller spawns two PCI buses, of which only one can be used. +By default QEMU assigns the wrong bus, so the correct one has to be specified +manually by adding ``bus=dw-pcie``. For example, when adding an Intel e1000 +network card, the command line looks like: + +.. code-block:: bash + + $ qemu-system-aarch64 -M imximp-evk ... -device virtio-net-pci,bus=dw-pcie
Why does this happen? Isn't there some way to make QEMU default to using the right bus? Otherwise there's likely to be a lot of user confusion because PCI "doesn't work"...
thanks
-- PMM
Re: [PATCH 09/21] hw/arm/fsl-imx8mp: Add PCIe support
Am 28. Januar 2025 14:33:14 UTC schrieb Peter Maydell <[email protected]>:
Quoted 31 lines · Bernhard Beschow
Quoted 30 lines
Linux checks for the PLLs in the PHY to be locked, so implement a model emulating that.
Signed-off-by Bernhard Beschow <[email protected]>docs/system/arm/imx8mp-evk.rst +9
-0@@ -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@@ -62,3 +63,15 @@ Now that everything is prepared the newly built image can be run in the QEMU -dtb imx8mp-evk-patched.dtb \ -append "root=/dev/mmcblk2p2" \ -drive file=sdcard.img,if=sd,bus=2,format=raw,id=mmcblk2 + +Using PCI Devices +----------------- + +The PCI Express controller spawns two PCI buses, of which only one can be used. +By default QEMU assigns the wrong bus, so the correct one has to be specified +manually by adding ``bus=dw-pcie``. For example, when adding an Intel e1000 +network card, the command line looks like:
Quoted 8 lines
docs/system/arm/imx8mp-evk.rst Now that everything is prepared the newly built image can be run in the QEMU · line 77
Quoted 4 lines
docs/system/arm/imx8mp-evk.rst +4
-0+ +.. code-block:: bash + + $ qemu-system-aarch64 -M imximp-evk ... -device virtio-net-pci,bus=dw-pcieWhy does this happen? Isn't there some way to make QEMU default to using the right bus? Otherwise there's likely to be a lot of user confusion because PCI "doesn't work"...
Yeah, this is really confusing and I forget about it myself. I'd appreciate any hints here.
Best regards,
Bernhard
Quoted 3 lines
thanks
-- PMM
Re: [PATCH 09/21] hw/arm/fsl-imx8mp: Add PCIe support
Quoted 41 lines · Bernhard Beschow
Am 28. Januar 2025 14:33:14 UTC schrieb Peter Maydell <[email protected]>:
Quoted 31 lines · Bernhard Beschow
Quoted 30 lines
Linux checks for the PLLs in the PHY to be locked, so implement a model emulating that.
Signed-off-by Bernhard Beschow <[email protected]>docs/system/arm/imx8mp-evk.rst +9
-0@@ -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@@ -62,3 +63,15 @@ Now that everything is prepared the newly built image can be run in the QEMU -dtb imx8mp-evk-patched.dtb \ -append "root=/dev/mmcblk2p2" \ -drive file=sdcard.img,if=sd,bus=2,format=raw,id=mmcblk2 + +Using PCI Devices +----------------- + +The PCI Express controller spawns two PCI buses, of which only one can be used. +By default QEMU assigns the wrong bus, so the correct one has to be specified +manually by adding ``bus=dw-pcie``. For example, when adding an Intel e1000 +network card, the command line looks like:Quoted 8 lines
docs/system/arm/imx8mp-evk.rst Now that everything is prepared the newly built image can be run in the QEMU · line 77
Quoted 4 lines
docs/system/arm/imx8mp-evk.rst +4
-0+ +.. code-block:: bash + + $ qemu-system-aarch64 -M imximp-evk ... -device virtio-net-pci,bus=dw-pcieWhy does this happen? Isn't there some way to make QEMU default to using the right bus? Otherwise there's likely to be a lot of user confusion because PCI "doesn't work"...
Quoted 1 line
Yeah, this is really confusing and I forget about it myself. I'd appreciate any hints here.
I'm not sure but I think the PCI bus created last will be used by default so maybe swapping the order these are created may help.
Regards,
BALATON Zoltan
Quoted 8 lines
Best regards,
BernhardQuoted 3 lines
thanks
-- PMM
Re: [PATCH 09/21] hw/arm/fsl-imx8mp: Add PCIe support
Am 29. Januar 2025 17:54:46 UTC schrieb BALATON Zoltan <[email protected]>:
Quoted 42 lines · Bernhard Beschow
Quoted 41 lines
Am 28. Januar 2025 14:33:14 UTC schrieb Peter Maydell <[email protected]>:
Quoted 39 lines · Bernhard Beschow
Quoted 24 lines
Linux checks for the PLLs in the PHY to be locked, so implement a model emulating that.
Signed-off-by Bernhard Beschow <[email protected]>docs/system/arm/imx8mp-evk.rst +3
-0@@ -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@@ -62,3 +63,15 @@ Now that everything is prepared the newly built image can be run in the QEMU -dtb imx8mp-evk-patched.dtb \ -append "root=/dev/mmcblk2p2" \ -drive file=sdcard.img,if=sd,bus=2,format=raw,id=mmcblk2 + +Using PCI Devicesdocs/system/arm/imx8mp-evk.rst Now that everything is prepared the newly built image can be run in the QEMU · line 77
Quoted 10 lines
docs/system/arm/imx8mp-evk.rst +10
-0+----------------- + +The PCI Express controller spawns two PCI buses, of which only one can be used. +By default QEMU assigns the wrong bus, so the correct one has to be specified +manually by adding ``bus=dw-pcie``. For example, when adding an Intel e1000 +network card, the command line looks like: + +.. code-block:: bash + + $ qemu-system-aarch64 -M imximp-evk ... -device virtio-net-pci,bus=dw-pcieWhy does this happen? Isn't there some way to make QEMU default to using the right bus? Otherwise there's likely to be a lot of user confusion because PCI "doesn't work"...
Quoted 3 lines
Quoted 1 line
Yeah, this is really confusing and I forget about it myself. I'd appreciate any hints here.
I'm not sure but I think the PCI bus created last will be used by default so maybe swapping the order these are created may help.
Turns out there is BusClass::max_dev which is respected when a parent bus for a user-created device is sought. I'll draw inspiration from pnv_phb4.
Best regards,
Bernhard
Quoted 12 lines
Regards,
BALATON ZoltanQuoted 8 lines
Best regards,
BernhardQuoted 3 lines
thanks
-- PMM
PATCH 10/21 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
@@ -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
@@ -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_ccm.h"
@@ -28,6 +29,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 ,
@@ -38,6 +40,7 @@ struct FslImx8mpState {ARMCPU cpu[FSL_IMX8MP_NUM_CPUS ];GICv3State gic; +IMXGPIOState gpio[FSL_IMX8MP_NUM_GPIOS ];IMX8MPCCMState ccm;IMX8MPAnalogState analog;IMX7SNVSState snvs;
@@ -201,6 +204,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
PATCH 11/21 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
@@ -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
@@ -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_ccm.h"
@@ -30,6 +31,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 ,
@@ -44,6 +46,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;
@@ -204,6 +207,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,
@@ -215,6 +223,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
@@ -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
@@ -581,8 +581,10 @@ config FSL_IMX8MP bool imply PCI_DEVICES imply TEST_DEVICES + imply I2C_DEVICES select ARM_GIC select IMX + select IMX_I2C select PCI_EXPRESS_DESIGNWARE select PCI_EXPRESS_FSL_IMX8M_PHY select SDHCI
Signature · 1 line
2.48.1
PATCH 12/21 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
@@ -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
@@ -19,6 +19,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"
@@ -30,6 +31,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 ,
@@ -46,6 +48,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 ];
@@ -207,6 +210,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
@@ -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
PATCH 13/21 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
@@ -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
@@ -20,6 +20,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"
@@ -37,6 +38,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 {
@@ -52,6 +54,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; };
@@ -234,6 +237,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
@@ -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
@@ -589,6 +589,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
PATCH 14/21 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
@@ -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
@@ -16,10 +16,12 @@#include "hw/intc/arm_gicv3_common.h" #include "hw/misc/imx7_snvs.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"
@@ -34,6 +36,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,
@@ -46,6 +49,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;
@@ -57,6 +61,7 @@ struct FslImx8mpState {IMX2WdtState wdt[FSL_IMX8MP_NUM_WDTS ];DesignwarePCIEHost pcie;FslImx8mPciePhyState pcie_phy; +OrIRQState gpt5_gpt6_irq; };enum FslImx8mpMemoryRegions {
@@ -223,6 +228,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
@@ -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
@@ -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
@@ -585,6 +585,7 @@ config FSL_IMX8MP select ARM_GIC 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
PATCH 15/21 hw/arm/fsl-imx8mp: Add Ethernet controller
In reply to Bernhard BeschowThe 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
@@ -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
@@ -16,6 +16,7 @@#include "hw/intc/arm_gicv3_common.h" #include "hw/misc/imx7_snvs.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"
@@ -57,11 +58,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 {
@@ -252,6 +257,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
@@ -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
@@ -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
@@ -584,6 +584,7 @@ config FSL_IMX8MP imply I2C_DEVICES select ARM_GIC select IMX + select IMX_FEC select IMX_I2C select OR_IRQ select PCI_EXPRESS_DESIGNWARE
Signature · 1 line
2.48.1
PATCH 16/21 hw/arm/fsl-imx8mp: Add USB support
In reply to Bernhard BeschowSplit 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
@@ -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
@@ -23,6 +23,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"
@@ -41,6 +42,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, };
@@ -61,6 +63,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;
@@ -198,6 +201,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,
@@ -233,6 +242,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
@@ -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
@@ -591,6 +591,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
PATCH 17/21 hw/arm/fsl-imx8mp: Add boot ROM
In reply to Bernhard BeschowOn 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 withdd 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
@@ -830,6 +830,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
@@ -67,6 +67,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
@@ -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_ram (&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
pc-bios/meson.build +1 -0
@@ -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
Re: [PATCH 17/21] hw/arm/fsl-imx8mp: Add boot ROM
Quoted 71 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.Signed-off-by Bernhard Beschow <[email protected]>---
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 +0
-0@@ -830,6 +830,7 @@ F: hw/pci-host/fsl_imx8m_phy.cF:
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.rstMPS2 / MPS3
include/hw/arm/fsl-imx8mp.h +1
-0@@ -67,6 +67,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 +3
-0@@ -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 ) {
hw/arm/fsl-imx8mp.c static void fsl_imx8mp_realize(DeviceState *dev, Error **errp) · line 660
Quoted 10 lines
hw/arm/fsl-imx8mp.c +7
-0@@ -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_ram (&s->boot_rom,OBJECT (dev), + fsl_imx8mp_memmap[FSL_IMX8MP_BOOT_ROM ].name, + fsl_imx8mp_memmap[FSL_IMX8MP_BOOT_ROM ].size, + errp)) { +return ; + }
If it's ROM why not memory_region_init_rom?
Regards,
BALATON Zoltan
Quoted 60 lines
hw/arm/fsl-imx8mp.c +8
-0+ 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
-0pc-bios/meson.build +1
-0@@ -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',
Re: [PATCH 17/21] hw/arm/fsl-imx8mp: Add boot ROM
Am 21. Januar 2025 03:00:17 UTC schrieb BALATON Zoltan <[email protected]>:
Quoted 75 lines · Bernhard Beschow
Quoted 74 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.
The imx8mp-boot.rom was created with
dd if=/dev/zero of=imx8mp-boot.rom bs=1 count=258048.Signed-off-by Bernhard Beschow <[email protected]>---
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 +0
-0@@ -830,6 +830,7 @@ F: hw/pci-host/fsl_imx8m_phy.cF:
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.rstMPS2 / MPS3
include/hw/arm/fsl-imx8mp.h +1
-0@@ -67,6 +67,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 +3
-0@@ -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);
Quoted 9 lines
hw/arm/fsl-imx8mp.c static void fsl_imx8mp_realize(DeviceState *dev, Error **errp) · line 660
Quoted 7 lines
hw/arm/fsl-imx8mp.c +7
-0+/* ROM memory */ +if (!memory_region_init_ram (&s->boot_rom,OBJECT (dev), + fsl_imx8mp_memmap[FSL_IMX8MP_BOOT_ROM ].name, + fsl_imx8mp_memmap[FSL_IMX8MP_BOOT_ROM ].size, + errp)) { +return ; + }If it's ROM why not
memory_region_init_rom?
Indeed, this should be memory_region_init_rom(). Will be fixed in next iteration.
Thanks,
Bernhard
Quoted 64 lines
Regards,
BALATON ZoltanQuoted 60 lines
hw/arm/fsl-imx8mp.c +8
-0+ 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
-0pc-bios/meson.build +1
-0@@ -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',
PATCH 18/21 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
@@ -68,6 +68,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
@@ -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
PATCH 19/21 hw/rtc: Add Ricoh RS5C372 RTC emulation
In reply to Bernhard BeschowThe 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
@@ -827,6 +827,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
@@ -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
@@ -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
@@ -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
PATCH 20/21 hw/i2c: Import TCA6416 emulation from Xilinx
In reply to Bernhard BeschowXilinx QEMU implements a TCA6416 device model which may be useful for the broader QEMU community, so upstream it. In the Xilinx fork, the device model gets compiled whenever CONFIG_CADENCE is true, so have it maintained by the "hw/*/cadence_*" maintainers.
The code is based on Xilinx QEMU version xilinx_v2024.2 plus the following modifications:
* Use OBJECT_DECLARE_SIMPLE_TYPE()
* Port from DPRINTF() to trace events
* Follow QEMU conventions for naming of state struct
* Rename type to not contain a ','
* Use DEFINE_TYPES() macro
* Implement under hw/gpio since device is i2c client and gpio provider
* Have dedicated Kconfig switch
--
I have a use for TCA6416 emulation. Question: Are Xilinx Zynq maintainers willing to maintain this device model?
--- MAINTAINERS | 1 + hw/gpio/tca6416.c | 122 +++++++++++++++++++++++++++++++++++++++++++ hw/gpio/Kconfig | 5 ++ hw/gpio/meson.build | 1 + hw/gpio/trace-events | 4 ++ 5 files changed, 133 insertions(+) create mode 100644 hw/gpio/tca6416.c
MAINTAINERS +1 -0
@@ -1030,6 +1030,7 @@ S: Maintained F: hw/*/xilinx_* F: hw/*/cadence_* F: hw/misc/zynq_slcr.c +F: hw/gpio/tca6416.c F: hw/adc/zynq-xadc.c F: include/hw/misc/zynq_slcr.h F: include/hw/adc/zynq-xadc.h
hw/gpio/tca6416.c new file +122 -0
122 lines not on this page · raw message
hw/gpio/Kconfig +5 -0
@@ -20,5 +20,10 @@ config PCF8574 bool depends on I2C +config TCA6416 + bool + depends on I2C + default y if I2C_DEVICES + config ZAURUS_SCOOP bool
hw/gpio/meson.build +1 -0
@@ -18,3 +18,4 @@ system_ss.add(when: 'CONFIG_STM32L4X5_SOC', if_true: files('stm32l4x5_gpio.c')) system_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('aspeed_gpio.c')) system_ss.add(when: 'CONFIG_SIFIVE_GPIO', if_true: files('sifive_gpio.c')) system_ss.add(when: 'CONFIG_PCF8574', if_true: files('pcf8574.c')) +system_ss.add(when: 'CONFIG_TCA6416', if_true: files('tca6416.c'))
hw/gpio/trace-events +4 -0
@@ -46,3 +46,7 @@ stm32l4x5_gpio_read(char *gpio, uint64_t addr) "GPIO%s addr: 0x%" PRIx64 " " stm32l4x5_gpio_write(char *gpio, uint64_t addr, uint64_t data) "GPIO%s addr: 0x%" PRIx64 " val: 0x%" PRIx64 "" stm32l4x5_gpio_update_idr(char *gpio, uint32_t old_idr, uint32_t new_idr) "GPIO%s from: 0x%x to: 0x%x" stm32l4x5_gpio_pins(char *gpio, uint16_t disconnected, uint16_t high) "GPIO%s disconnected pins: 0x%x levels: 0x%x" + +# tca6416.c +tca6416_write(uint8_t value) "0x%02x" +tca6416_read(uint8_t value) "0x%02x"
Signature · 1 line
2.48.1
Re: [PATCH 20/21] hw/i2c: Import TCA6416 emulation from Xilinx
Quoted 78 lines · Bernhard Beschow
Xilinx QEMU implements a TCA6416 device model which may be useful for the broader QEMU community, so upstream it. In the Xilinx fork, the device model gets compiled whenever
CONFIG_CADENCEis true, so have it maintained by the "hw/*/cadence_*" maintainers.The code is based on Xilinx QEMU version xilinx_v2024.2 plus the following modifications:
* UseOBJECT_DECLARE_SIMPLE_TYPE()
* Port fromDPRINTF()to trace events
* Follow QEMU conventions for naming of state struct
* Rename type to not contain a ','
* UseDEFINE_TYPES()macro
* Implement under hw/gpio since device is i2c client and gpio provider
* Have dedicatedKconfigswitchSigned-off-by Bernhard Beschow <[email protected]>--
I have a use for TCA6416 emulation. Question: Are Xilinx Zynq maintainers willing to maintain this device model?
---MAINTAINERS | 1 + hw/gpio/tca6416.c | 122 +++++++++++++++++++++++++++++++++++++++++++ hw/gpio/Kconfig | 5 ++ hw/gpio/meson.build | 1 + hw/gpio/trace-events | 4 ++ 5 files changed, 133 insertions(+)create mode 100644
hw/gpio/tca6416.cMAINTAINERS +0
-0@@ -1030,6 +1030,7 @@ S: MaintainedF: hw/*/xilinx_*
F: hw/*/cadence_*
F:hw/misc/zynq_slcr.c
+F:hw/gpio/tca6416.c
F:hw/adc/zynq-xadc.c
F:include/hw/misc/zynq_slcr.h
F:include/hw/adc/zynq-xadc.hhw/gpio/tca6416.c new file +31
-0@@ -0,0 +1,122 @@ +/* +* QEMU model of TCA6416 16-Bit I/O Expander +* +* Copyright (c) 2018 Xilinx Inc. +* +* Written by Sai Pavan Boddu <[email protected]> +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ +#include "qemu/osdep.h" +#include "hw/i2c/i2c.h" +#include "trace.h" + +#define TYPE_TCA6416 "tca6416" +OBJECT_DECLARE_SIMPLE_TYPE (Tca6416State,TCA6416 )
hw/gpio/tca6416.c line 41
Quoted 10 lines
hw/gpio/tca6416.c new file +10
-0+ +#define IN_PORT0 0 +#define IN_PORT1 1 +#define OUT_PORT0 2 +#define OUT_PORT1 3 +#define POL_INV0 4 +#define POL_INV1 5 +#define CONF_PORT0 6 +#define CONF_PORT1 7 +#define RMAX (CONF_PORT1 + 1)
Maybe make this list an enum? (But also fine as it is.)
Regards,
BALATON Zoltan
Quoted 118 lines
hw/gpio/tca6416.c new file +81
-0+ +enum tca6416_events { +ADDR_DONE , +ADDRESSING , +}; + +struct Tca6416State { +I2CSlave i2c; + +uint8_t addr; +uint8_t state; +uint8_t regs[RMAX ]; +}; + +static uint8_t tca6416_read (I2CSlave *i2c) +{ +Tca6416State *s =TCA6416 (i2c); +uint8_t ret; + + ret = s->regs[s->addr]; +trace_tca6416_read (ret); +return ret; +} + +static int tca6416_write (I2CSlave *i2c,uint8_t data) +{ +Tca6416State *s =TCA6416 (i2c); + +trace_tca6416_write (data); +if (s->state ==ADDRESSING ) { + s->addr = data; + }else { + s->regs[s->addr] = data; + } + +return 0 ; +} + +static void tca6416_realize (DeviceState *dev,Error **errp) +{ +Tca6416State *s =TCA6416 (dev); + + s->regs[CONF_PORT0 ] =0xFF ; + s->regs[CONF_PORT1 ] =0xFF ; +} + +static int tca6416_event (I2CSlave *i2c,enum i2c_event event) +{ +Tca6416State *s =TCA6416 (i2c); + +switch (event) { +case I2C_START_SEND : + s->state =ADDRESSING ; +break ; +default : + s->state =ADDR_DONE ; + }; +return 0 ; +} + +static void tca6416_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +I2CSlaveClass *k =I2C_SLAVE_CLASS (klass); + + dc->realize = tca6416_realize; + k->recv = tca6416_read; + k->send = tca6416_write; + k->event = tca6416_event; +} + +static const TypeInfo tca6416_types[] = { + { + .name =TYPE_TCA6416 , + .parent =TYPE_I2C_SLAVE , + .class_init = tca6416_class_init, + .instance_size =sizeof (Tca6416State), + } +}; + +DEFINE_TYPES (tca6416_types)hw/gpio/Kconfig +5
-0@@ -20,5 +20,10 @@ config PCF8574 bool depends on I2C +config TCA6416 + bool + depends on I2C + default y if I2C_DEVICES +config
ZAURUS_SCOOP
boolhw/gpio/meson.build +1
-0@@ -18,3 +18,4 @@ system_ss.add(when: 'CONFIG_STM32L4X5_SOC', if_true: files('stm32l4x5_gpio.c')) system_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('aspeed_gpio.c')) system_ss.add(when: 'CONFIG_SIFIVE_GPIO', if_true: files('sifive_gpio.c')) system_ss.add(when: 'CONFIG_PCF8574', if_true: files('pcf8574.c')) +system_ss.add(when: 'CONFIG_TCA6416', if_true: files('tca6416.c'))hw/gpio/trace-events +0
-0@@ -46,3 +46,7 @@ stm32l4x5_gpio_read(char *gpio, uint64_t addr) "GPIO%s addr: 0x%" PRIx64 " "
stm32l4x5_gpio_write(char *gpio, uint64_t addr, uint64_t data)"GPIO%s addr: 0x%" PRIx64 " val: 0x%" PRIx64 ""stm32l4x5_gpio_update_idr(char *gpio, uint32_t old_idr, uint32_t new_idr)"GPIO%s from: 0x%x to: 0x%x"stm32l4x5_gpio_pins(char *gpio, uint16_t disconnected, uint16_t high)"GPIO%s disconnected pins: 0x%x levels: 0x%x"hw/gpio/trace-events +4
-0+ +# tca6416.c +tca6416_write(uint8_t value) "0x%02x" +tca6416_read(uint8_t value) "0x%02x"
Re: [PATCH 20/21] hw/i2c: Import TCA6416 emulation from Xilinx
Am 21. Januar 2025 03:07:39 UTC schrieb BALATON Zoltan <[email protected]>:
Quoted 83 lines · Bernhard Beschow
Quoted 82 lines
Xilinx QEMU implements a TCA6416 device model which may be useful for the broader QEMU community, so upstream it. In the Xilinx fork, the device model gets compiled whenever
CONFIG_CADENCEis true, so have it maintained by the "hw/*/cadence_*" maintainers.The code is based on Xilinx QEMU version xilinx_v2024.2 plus the following modifications:
* UseOBJECT_DECLARE_SIMPLE_TYPE()
* Port fromDPRINTF()to trace events
* Follow QEMU conventions for naming of state struct
* Rename type to not contain a ','
* UseDEFINE_TYPES()macro
* Implement under hw/gpio since device is i2c client and gpio provider
* Have dedicatedKconfigswitchSigned-off-by Bernhard Beschow <[email protected]>--
I have a use for TCA6416 emulation. Question: Are Xilinx Zynq maintainers willing to maintain this device model?
---MAINTAINERS | 1 + hw/gpio/tca6416.c | 122 +++++++++++++++++++++++++++++++++++++++++++ hw/gpio/Kconfig | 5 ++ hw/gpio/meson.build | 1 + hw/gpio/trace-events | 4 ++ 5 files changed, 133 insertions(+)create mode 100644
hw/gpio/tca6416.cMAINTAINERS +0
-0@@ -1030,6 +1030,7 @@ S: MaintainedF: hw/*/xilinx_*
F: hw/*/cadence_*
F:hw/misc/zynq_slcr.c
+F:hw/gpio/tca6416.c
F:hw/adc/zynq-xadc.c
F:include/hw/misc/zynq_slcr.h
F:include/hw/adc/zynq-xadc.hhw/gpio/tca6416.c new file +35
-0@@ -0,0 +1,122 @@ +/* +* QEMU model of TCA6416 16-Bit I/O Expander +* +* Copyright (c) 2018 Xilinx Inc. +* +* Written by Sai Pavan Boddu <[email protected]> +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ +#include "qemu/osdep.h" +#include "hw/i2c/i2c.h" +#include "trace.h" + +#define TYPE_TCA6416 "tca6416" +OBJECT_DECLARE_SIMPLE_TYPE(Tca6416State, TCA6416) + +#define IN_PORT0 0 +#define IN_PORT1 1 +#define OUT_PORT0 2
Quoted 8 lines
hw/gpio/tca6416.c line 41
Quoted 6 lines
hw/gpio/tca6416.c new file +6
-0+#define OUT_PORT1 3 +#define POL_INV0 4 +#define POL_INV1 5 +#define CONF_PORT0 6 +#define CONF_PORT1 7 +#define RMAX (CONF_PORT1 + 1)Maybe make this list an enum? (But also fine as it is.)
Good idea indeed. I'd address this once maintainership is clarified.
Best regards,
Bernhard
Quoted 122 lines
Regards,
BALATON ZoltanQuoted 118 lines
hw/gpio/tca6416.c new file +81
-0+ +enum tca6416_events { +ADDR_DONE , +ADDRESSING , +}; + +struct Tca6416State { +I2CSlave i2c; + +uint8_t addr; +uint8_t state; +uint8_t regs[RMAX ]; +}; + +static uint8_t tca6416_read (I2CSlave *i2c) +{ +Tca6416State *s =TCA6416 (i2c); +uint8_t ret; + + ret = s->regs[s->addr]; +trace_tca6416_read (ret); +return ret; +} + +static int tca6416_write (I2CSlave *i2c,uint8_t data) +{ +Tca6416State *s =TCA6416 (i2c); + +trace_tca6416_write (data); +if (s->state ==ADDRESSING ) { + s->addr = data; + }else { + s->regs[s->addr] = data; + } + +return 0 ; +} + +static void tca6416_realize (DeviceState *dev,Error **errp) +{ +Tca6416State *s =TCA6416 (dev); + + s->regs[CONF_PORT0 ] =0xFF ; + s->regs[CONF_PORT1 ] =0xFF ; +} + +static int tca6416_event (I2CSlave *i2c,enum i2c_event event) +{ +Tca6416State *s =TCA6416 (i2c); + +switch (event) { +case I2C_START_SEND : + s->state =ADDRESSING ; +break ; +default : + s->state =ADDR_DONE ; + }; +return 0 ; +} + +static void tca6416_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +I2CSlaveClass *k =I2C_SLAVE_CLASS (klass); + + dc->realize = tca6416_realize; + k->recv = tca6416_read; + k->send = tca6416_write; + k->event = tca6416_event; +} + +static const TypeInfo tca6416_types[] = { + { + .name =TYPE_TCA6416 , + .parent =TYPE_I2C_SLAVE , + .class_init = tca6416_class_init, + .instance_size =sizeof (Tca6416State), + } +}; + +DEFINE_TYPES (tca6416_types)hw/gpio/Kconfig +5
-0@@ -20,5 +20,10 @@ config PCF8574 bool depends on I2C +config TCA6416 + bool + depends on I2C + default y if I2C_DEVICES +config
ZAURUS_SCOOP
boolhw/gpio/meson.build +1
-0@@ -18,3 +18,4 @@ system_ss.add(when: 'CONFIG_STM32L4X5_SOC', if_true: files('stm32l4x5_gpio.c')) system_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('aspeed_gpio.c')) system_ss.add(when: 'CONFIG_SIFIVE_GPIO', if_true: files('sifive_gpio.c')) system_ss.add(when: 'CONFIG_PCF8574', if_true: files('pcf8574.c')) +system_ss.add(when: 'CONFIG_TCA6416', if_true: files('tca6416.c'))hw/gpio/trace-events +0
-0@@ -46,3 +46,7 @@ stm32l4x5_gpio_read(char *gpio, uint64_t addr) "GPIO%s addr: 0x%" PRIx64 " "
stm32l4x5_gpio_write(char *gpio, uint64_t addr, uint64_t data)"GPIO%s addr: 0x%" PRIx64 " val: 0x%" PRIx64 ""stm32l4x5_gpio_update_idr(char *gpio, uint32_t old_idr, uint32_t new_idr)"GPIO%s from: 0x%x to: 0x%x"stm32l4x5_gpio_pins(char *gpio, uint16_t disconnected, uint16_t high)"GPIO%s disconnected pins: 0x%x levels: 0x%x"hw/gpio/trace-events +4
-0+ +# tca6416.c +tca6416_write(uint8_t value) "0x%02x" +tca6416_read(uint8_t value) "0x%02x"
Re: [PATCH 20/21] hw/i2c: Import TCA6416 emulation from Xilinx
In reply to Bernhard BeschowI'm not sure about ownership here, but from an I2C point of view this all looks ok.
Quoted 210 lines · Bernhard Beschow
Xilinx QEMU implements a TCA6416 device model which may be useful for the broader QEMU community, so upstream it. In the Xilinx fork, the device model gets compiled whenever
CONFIG_CADENCEis true, so have it maintained by the "hw/*/cadence_*" maintainers.The code is based on Xilinx QEMU version xilinx_v2024.2 plus the following modifications:
* UseOBJECT_DECLARE_SIMPLE_TYPE()
* Port fromDPRINTF()to trace events
* Follow QEMU conventions for naming of state struct
* Rename type to not contain a ','
* UseDEFINE_TYPES()macro
* Implement under hw/gpio since device is i2c client and gpio provider
* Have dedicatedKconfigswitchSigned-off-by Bernhard Beschow <[email protected]>--
I have a use for TCA6416 emulation. Question: Are Xilinx Zynq maintainers willing to maintain this device model?--- MAINTAINERS | 1 + hw/gpio/tca6416.c | 122 +++++++++++++++++++++++++++++++++++++++++++ hw/gpio/Kconfig | 5 ++ hw/gpio/meson.build | 1 + hw/gpio/trace-events | 4 ++ 5 files changed, 133 insertions(+) create mode 100644 hw/gpio/tca6416.cMAINTAINERS +1
-0@@ -1030,6 +1030,7 @@ S: Maintained F: hw/*/xilinx_* F: hw/*/cadence_* F: hw/misc/zynq_slcr.c +F: hw/gpio/tca6416.c F: hw/adc/zynq-xadc.c F: include/hw/misc/zynq_slcr.h F: include/hw/adc/zynq-xadc.hhw/gpio/tca6416.c new file +122
-0@@ -0,0 +1,122 @@ +/* +* QEMU model of TCA6416 16-Bit I/O Expander +* +* Copyright (c) 2018 Xilinx Inc. +* +* Written by Sai Pavan Boddu <[email protected]> +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ +#include "qemu/osdep.h" +#include "hw/i2c/i2c.h" +#include "trace.h" + +#define TYPE_TCA6416 "tca6416" +OBJECT_DECLARE_SIMPLE_TYPE(Tca6416State, TCA6416) + +#define IN_PORT0 0 +#define IN_PORT1 1 +#define OUT_PORT0 2 +#define OUT_PORT1 3 +#define POL_INV0 4 +#define POL_INV1 5 +#define CONF_PORT0 6 +#define CONF_PORT1 7 +#define RMAX (CONF_PORT1 + 1) + +enum tca6416_events { +ADDR_DONE , +ADDRESSING , +}; + +struct Tca6416State { +I2CSlave i2c; + +uint8_t addr; +uint8_t state; +uint8_t regs[RMAX ]; +}; + +static uint8_t tca6416_read (I2CSlave *i2c) +{ +Tca6416State *s =TCA6416 (i2c); +uint8_t ret; + + ret = s->regs[s->addr]; +trace_tca6416_read (ret); +return ret; +} + +static int tca6416_write (I2CSlave *i2c,uint8_t data) +{ +Tca6416State *s =TCA6416 (i2c); + +trace_tca6416_write (data); +if (s->state ==ADDRESSING ) { + s->addr = data; + }else { + s->regs[s->addr] = data; + } + +return 0 ; +} + +static void tca6416_realize (DeviceState *dev,Error **errp) +{ +Tca6416State *s =TCA6416 (dev); + + s->regs[CONF_PORT0 ] =0xFF ; + s->regs[CONF_PORT1 ] =0xFF ; +} + +static int tca6416_event (I2CSlave *i2c,enum i2c_event event) +{ +Tca6416State *s =TCA6416 (i2c); + +switch (event) { +case I2C_START_SEND : + s->state =ADDRESSING ; +break ; +default : + s->state =ADDR_DONE ; + }; +return 0 ; +} + +static void tca6416_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +I2CSlaveClass *k =I2C_SLAVE_CLASS (klass); + + dc->realize = tca6416_realize; + k->recv = tca6416_read; + k->send = tca6416_write; + k->event = tca6416_event; +} + +static const TypeInfo tca6416_types[] = { + { + .name =TYPE_TCA6416 , + .parent =TYPE_I2C_SLAVE , + .class_init = tca6416_class_init, + .instance_size =sizeof (Tca6416State), + } +}; + +DEFINE_TYPES (tca6416_types)hw/gpio/Kconfig +5
-0@@ -20,5 +20,10 @@ config PCF8574 bool depends on I2C +config TCA6416 + bool + depends on I2C + default y if I2C_DEVICES + config ZAURUS_SCOOP boolhw/gpio/meson.build +1
-0@@ -18,3 +18,4 @@ system_ss.add(when: 'CONFIG_STM32L4X5_SOC', if_true: files('stm32l4x5_gpio.c')) system_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('aspeed_gpio.c')) system_ss.add(when: 'CONFIG_SIFIVE_GPIO', if_true: files('sifive_gpio.c')) system_ss.add(when: 'CONFIG_PCF8574', if_true: files('pcf8574.c')) +system_ss.add(when: 'CONFIG_TCA6416', if_true: files('tca6416.c'))hw/gpio/trace-events +4
-1@@ -46,3 +46,7 @@ stm32l4x5_gpio_read(char *gpio, uint64_t addr) "GPIO%s addr: 0x%" PRIx64 " " stm32l4x5_gpio_write(char *gpio, uint64_t addr, uint64_t data) "GPIO%s addr: 0x%" PRIx64 " val: 0x%" PRIx64 "" stm32l4x5_gpio_update_idr(char *gpio, uint32_t old_idr, uint32_t new_idr) "GPIO%s from: 0x%x to: 0x%x" stm32l4x5_gpio_pins(char *gpio, uint16_t disconnected, uint16_t high) "GPIO%s disconnected pins: 0x%x levels: 0x%x" + +# tca6416.c +tca6416_write(uint8_t value) "0x%02x" +tca6416_read(uint8_t value) "0x%02x" --2.48.1
Re: [PATCH 20/21] hw/i2c: Import TCA6416 emulation from Xilinx
In reply to Bernhard BeschowCc'ing AMD folks
Hi Bernhard,
TL;DR; can't you use the PCF8574 which is a more complete model of I/O expander? (See hw/gpio/pcf8574.c)
Quoted 47 lines · Bernhard Beschow
Xilinx QEMU implements a TCA6416 device model which may be useful for the broader QEMU community, so upstream it. In the Xilinx fork, the device model gets compiled whenever
CONFIG_CADENCEis true, so have it maintained by the "hw/*/cadence_*" maintainers.The code is based on Xilinx QEMU version xilinx_v2024.2 plus the following modifications:
* UseOBJECT_DECLARE_SIMPLE_TYPE()
* Port fromDPRINTF()to trace events
* Follow QEMU conventions for naming of state struct
* Rename type to not contain a ','
* UseDEFINE_TYPES()macro
* Implement under hw/gpio since device is i2c client and gpio provider
* Have dedicatedKconfigswitchSigned-off-by Bernhard Beschow <[email protected]>--
I have a use for TCA6416 emulation. Question: Are Xilinx Zynq maintainers willing to maintain this device model?--- MAINTAINERS | 1 + hw/gpio/tca6416.c | 122 +++++++++++++++++++++++++++++++++++++++++++ hw/gpio/Kconfig | 5 ++ hw/gpio/meson.build | 1 + hw/gpio/trace-events | 4 ++ 5 files changed, 133 insertions(+)create mode 100644
hw/gpio/tca6416.cMAINTAINERS +1
-0@@ -1030,6 +1030,7 @@ S: Maintained F: hw/*/xilinx_* F: hw/*/cadence_* F: hw/misc/zynq_slcr.c +F: hw/gpio/tca6416.c F: hw/adc/zynq-xadc.c F: include/hw/misc/zynq_slcr.h F: include/hw/adc/zynq-xadc.hhw/gpio/tca6416.c new file +0
-0
hw/gpio/tca6416.c line 2
Quoted 2 lines
hw/gpio/tca6416.c new file +2
-0@@ -0,0 +1,122 @@ +/* +* QEMU model of TCA6416 16-Bit I/O Expander
Please add datasheet reference.
Quoted 12 lines
hw/gpio/tca6416.c new file +12
-0+* +* Copyright (c) 2018 Xilinx Inc. +* +* Written by Sai Pavan Boddu <[email protected]> +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +*
hw/gpio/tca6416.c line 24
Quoted 10 lines
hw/gpio/tca6416.c new file +10
-0+* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE.
Sai/Edgar/Francisco, should we update to AMD here? Remove or update the email address? Also, can you Ack the replacement of this license by a SPDX tag?
Quoted 6 lines
hw/gpio/tca6416.c new file +6
-0+*/ +#include "qemu/osdep.h" +#include "hw/i2c/i2c.h" +#include "trace.h" + +#define TYPE_TCA6416 "tca6416"
hw/gpio/tca6416.c line 40
Quoted 10 lines
hw/gpio/tca6416.c new file +10
-0+OBJECT_DECLARE_SIMPLE_TYPE(Tca6416State, TCA6416) + +#define IN_PORT0 0 +#define IN_PORT1 1 +#define OUT_PORT0 2 +#define OUT_PORT1 3 +#define POL_INV0 4 +#define POL_INV1 5 +#define CONF_PORT0 6 +#define CONF_PORT1 7
enum up to here?
Quoted 22 lines
hw/gpio/tca6416.c new file +22
-0+#define RMAX (CONF_PORT1 + 1) + +enum tca6416_events { +ADDR_DONE , +ADDRESSING , +}; + +struct Tca6416State { +I2CSlave i2c; + +uint8_t addr; +uint8_t state; +uint8_t regs[RMAX ]; +}; + +static uint8_t tca6416_read (I2CSlave *i2c) +{ +Tca6416State *s =TCA6416 (i2c); +uint8_t ret; + + ret = s->regs[s->addr]; +trace_tca6416_read (ret);
hw/gpio/tca6416.c line 72
Quoted 10 lines
hw/gpio/tca6416.c new file +10
-0+return ret; +} + +static int tca6416_write (I2CSlave *i2c,uint8_t data) +{ +Tca6416State *s =TCA6416 (i2c); + +trace_tca6416_write (data); +if (s->state ==ADDRESSING ) { + s->addr = data;
I suppose HW masks here.
s->addr = data & 0xf;
hw/gpio/tca6416.c line 74
Quoted 2 lines
hw/gpio/tca6416.c new file +2
-0+ }else { + s->regs[s->addr] = data;
(otherwise this could overflow).
So this device isn't doing anything actually (I'd have expected 1 IRQ and 16 GPIO lines). What is the point, at least in this state?
hw/gpio/tca6416.c line 83
Quoted 9 lines
hw/gpio/tca6416.c new file +9
-0+ } + +return 0 ; +} + +static void tca6416_realize (DeviceState *dev,Error **errp) +{ +Tca6416State *s =TCA6416 (dev); +
Missing:
s->regs[OUT_PORT0] = 0xff;
s->regs[OUT_PORT1] = 0xff;
s->regs[POL_INV0] = 0x00;
s->regs[POL_INV1] = 0x00;hw/gpio/tca6416.c line 85
Quoted 2 lines
hw/gpio/tca6416.c new file +2
-0+ s->regs[CONF_PORT0 ] =0xFF ; + s->regs[CONF_PORT1 ] =0xFF ;
Style is 0xff.
That said, this is not a REALIZE but RESET handler.
Quoted 12 lines
hw/gpio/tca6416.c new file +12
-0+} + +static int tca6416_event (I2CSlave *i2c,enum i2c_event event) +{ +Tca6416State *s =TCA6416 (i2c); + +switch (event) { +case I2C_START_SEND : + s->state =ADDRESSING ; +break ; +default : + s->state =ADDR_DONE ;
hw/gpio/tca6416.c line 107
Quoted 10 lines
hw/gpio/tca6416.c new file +10
-0+ }; +return 0 ; +} + +static void tca6416_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +I2CSlaveClass *k =I2C_SLAVE_CLASS (klass); + + dc->realize = tca6416_realize;
(tca6416_realize is a reset handler).
Please complete:
dc->desc = "TCA6416 I/O Expander";
set_bit(DEVICE_CATEGORY_MISC, dc->categories);No migration state?
Quoted 43 lines
hw/gpio/tca6416.c new file +14
-0+ k->recv = tca6416_read; + k->send = tca6416_write; + k->event = tca6416_event; +}> + +static const TypeInfo tca6416_types[] = { + { + .name =TYPE_TCA6416 , + .parent =TYPE_I2C_SLAVE , + .class_init = tca6416_class_init, + .instance_size =sizeof (Tca6416State), + } +}; + +DEFINE_TYPES (tca6416_types)hw/gpio/Kconfig +5
-0@@ -20,5 +20,10 @@ config PCF8574 bool depends on I2C +config TCA6416 + bool + depends on I2C + default y if I2C_DEVICES + config ZAURUS_SCOOP boolhw/gpio/meson.build +1
-0@@ -18,3 +18,4 @@ system_ss.add(when: 'CONFIG_STM32L4X5_SOC', if_true: files('stm32l4x5_gpio.c')) system_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('aspeed_gpio.c')) system_ss.add(when: 'CONFIG_SIFIVE_GPIO', if_true: files('sifive_gpio.c')) system_ss.add(when: 'CONFIG_PCF8574', if_true: files('pcf8574.c')) +system_ss.add(when: 'CONFIG_TCA6416', if_true: files('tca6416.c'))hw/gpio/trace-events +0
-0
hw/gpio/trace-events stm32l4x5_gpio_read(char *gpio, uint64_t addr) "GPIO%s addr: 0x%" PRIx64 " " · line 51
Quoted 6 lines
hw/gpio/trace-events +3
-0@@ -46,3 +46,7 @@ stm32l4x5_gpio_read(char *gpio, uint64_t addr) "GPIO%s addr: 0x%" PRIx64 " " stm32l4x5_gpio_write(char *gpio, uint64_t addr, uint64_t data) "GPIO%s addr: 0x%" PRIx64 " val: 0x%" PRIx64 "" stm32l4x5_gpio_update_idr(char *gpio, uint32_t old_idr, uint32_t new_idr) "GPIO%s from: 0x%x to: 0x%x" stm32l4x5_gpio_pins(char *gpio, uint16_t disconnected, uint16_t high) "GPIO%s disconnected pins: 0x%x levels: 0x%x" + +# tca6416.c +tca6416_write(uint8_t value) "0x%02x"
"wr 0x%02x"
hw/gpio/trace-events stm32l4x5_gpio_read(char *gpio, uint64_t addr) "GPIO%s addr: 0x%" PRIx64 " " · line 52
Quoted 1 line
hw/gpio/trace-events +1
-0+tca6416_read(uint8_t value) "0x%02x"
"rd ..."
Regards,
Phil.
Re: [PATCH 20/21] hw/i2c: Import TCA6416 emulation from Xilinx
Am 30. Januar 2025 23:05:53 UTC schrieb "Philippe Mathieu-Daudé" <[email protected]>:
Quoted 6 lines
Cc'ing AMD folks
Hi Bernhard,
TL;DR; can't you use the PCF8574 which is a more complete model of I/O expander? (See
hw/gpio/pcf8574.c)
If it is software-compatible then I could use it. I'm modeling a real board whose device tree I'd like to use unchanged, so I don't have much choice. The only reason I need it is because its absence clogs the i2c bus.
Best regards,
Bernhard
Quoted 260 lines · Bernhard Beschow
Quoted 47 lines
Xilinx QEMU implements a TCA6416 device model which may be useful for the broader QEMU community, so upstream it. In the Xilinx fork, the device model gets compiled whenever
CONFIG_CADENCEis true, so have it maintained by the "hw/*/cadence_*" maintainers.The code is based on Xilinx QEMU version xilinx_v2024.2 plus the following modifications:
* UseOBJECT_DECLARE_SIMPLE_TYPE()
* Port fromDPRINTF()to trace events
* Follow QEMU conventions for naming of state struct
* Rename type to not contain a ','
* UseDEFINE_TYPES()macro
* Implement under hw/gpio since device is i2c client and gpio provider
* Have dedicatedKconfigswitchSigned-off-by Bernhard Beschow <[email protected]>--
I have a use for TCA6416 emulation. Question: Are Xilinx Zynq maintainers willing to maintain this device model?--- MAINTAINERS | 1 + hw/gpio/tca6416.c | 122 +++++++++++++++++++++++++++++++++++++++++++ hw/gpio/Kconfig | 5 ++ hw/gpio/meson.build | 1 + hw/gpio/trace-events | 4 ++ 5 files changed, 133 insertions(+)create mode 100644
hw/gpio/tca6416.cMAINTAINERS +1
-0@@ -1030,6 +1030,7 @@ S: Maintained F: hw/*/xilinx_* F: hw/*/cadence_* F: hw/misc/zynq_slcr.c +F: hw/gpio/tca6416.c F: hw/adc/zynq-xadc.c F: include/hw/misc/zynq_slcr.h F: include/hw/adc/zynq-xadc.hhw/gpio/tca6416.c new file +0
-0hw/gpio/tca6416.c line 2
Quoted 2 lines
hw/gpio/tca6416.c new file +2
-0@@ -0,0 +1,122 @@ +/* +* QEMU model of TCA6416 16-Bit I/O Expander Please add datasheet reference.
Quoted 12 lines
hw/gpio/tca6416.c new file +12
-0+* +* Copyright (c) 2018 Xilinx Inc. +* +* Written by Sai Pavan Boddu <[email protected]> +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* hw/gpio/tca6416.c line 24
Quoted 10 lines
hw/gpio/tca6416.c new file +10
-0+* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. Sai/Edgar/Francisco, should we update to AMD here? Remove or update the email address? Also, can you Ack the replacement of this license by a SPDX tag?
Quoted 6 lines
hw/gpio/tca6416.c new file +6
-0+*/ +#include "qemu/osdep.h" +#include "hw/i2c/i2c.h" +#include "trace.h" + +#define TYPE_TCA6416 "tca6416"hw/gpio/tca6416.c line 40
Quoted 10 lines
hw/gpio/tca6416.c new file +10
-0+OBJECT_DECLARE_SIMPLE_TYPE(Tca6416State, TCA6416) + +#define IN_PORT0 0 +#define IN_PORT1 1 +#define OUT_PORT0 2 +#define OUT_PORT1 3 +#define POL_INV0 4 +#define POL_INV1 5 +#define CONF_PORT0 6 +#define CONF_PORT1 7enum up to here?
Quoted 22 lines
hw/gpio/tca6416.c new file +22
-0+#define RMAX (CONF_PORT1 + 1) + +enum tca6416_events { +ADDR_DONE , +ADDRESSING , +}; + +struct Tca6416State { +I2CSlave i2c; + +uint8_t addr; +uint8_t state; +uint8_t regs[RMAX ]; +}; + +static uint8_t tca6416_read (I2CSlave *i2c) +{ +Tca6416State *s =TCA6416 (i2c); +uint8_t ret; + + ret = s->regs[s->addr]; +trace_tca6416_read (ret);hw/gpio/tca6416.c line 72
Quoted 10 lines
hw/gpio/tca6416.c new file +10
-0+return ret; +} + +static int tca6416_write (I2CSlave *i2c,uint8_t data) +{ +Tca6416State *s =TCA6416 (i2c); + +trace_tca6416_write (data); +if (s->state ==ADDRESSING ) { + s->addr = data;I suppose HW masks here.
s->addr = data & 0xf;hw/gpio/tca6416.c line 74
Quoted 2 lines
hw/gpio/tca6416.c new file +2
-0+ }else { + s->regs[s->addr] = data;(otherwise this could overflow).
So this device isn't doing anything actually (I'd have expected 1 IRQ and 16 GPIO lines). What is the point, at least in this state?
hw/gpio/tca6416.c line 83
Quoted 9 lines
hw/gpio/tca6416.c new file +9
-0+ } + +return 0 ; +} + +static void tca6416_realize (DeviceState *dev,Error **errp) +{ +Tca6416State *s =TCA6416 (dev); +Missing:
s->regs[OUT_PORT0] = 0xff; s->regs[OUT_PORT1] = 0xff; s->regs[POL_INV0] = 0x00; s->regs[POL_INV1] = 0x00;hw/gpio/tca6416.c line 85
Quoted 2 lines
hw/gpio/tca6416.c new file +2
-0+ s->regs[CONF_PORT0 ] =0xFF ; + s->regs[CONF_PORT1 ] =0xFF ;Style is
0xff.That said, this is not a REALIZE but RESET handler.
Quoted 12 lines
hw/gpio/tca6416.c new file +12
-0+} + +static int tca6416_event (I2CSlave *i2c,enum i2c_event event) +{ +Tca6416State *s =TCA6416 (i2c); + +switch (event) { +case I2C_START_SEND : + s->state =ADDRESSING ; +break ; +default : + s->state =ADDR_DONE ;hw/gpio/tca6416.c line 107
Quoted 10 lines
hw/gpio/tca6416.c new file +10
-0+ }; +return 0 ; +} + +static void tca6416_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +I2CSlaveClass *k =I2C_SLAVE_CLASS (klass); + + dc->realize = tca6416_realize;(
tca6416_realizeis a reset handler).Please complete:
dc->desc = "TCA6416 I/O Expander"; set_bit(DEVICE_CATEGORY_MISC, dc->categories);No migration state?
Quoted 42 lines
hw/gpio/tca6416.c new file +14
-0+ k->recv = tca6416_read; + k->send = tca6416_write; + k->event = tca6416_event; +}> + +static const TypeInfo tca6416_types[] = { + { + .name =TYPE_TCA6416 , + .parent =TYPE_I2C_SLAVE , + .class_init = tca6416_class_init, + .instance_size =sizeof (Tca6416State), + } +}; + +DEFINE_TYPES (tca6416_types)hw/gpio/Kconfig +4
-0@@ -20,5 +20,10 @@ config PCF8574 bool depends on I2C +config TCA6416 + bool + depends on I2C + default y if I2C_DEVICES + config ZAURUS_SCOOP boolhw/gpio/meson.build +1
-0@@ -18,3 +18,4 @@ system_ss.add(when: 'CONFIG_STM32L4X5_SOC', if_true: files('stm32l4x5_gpio.c')) system_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('aspeed_gpio.c')) system_ss.add(when: 'CONFIG_SIFIVE_GPIO', if_true: files('sifive_gpio.c')) system_ss.add(when: 'CONFIG_PCF8574', if_true: files('pcf8574.c')) +system_ss.add(when: 'CONFIG_TCA6416', if_true: files('tca6416.c'))hw/gpio/trace-events +0
-0hw/gpio/trace-events stm32l4x5_gpio_read(char *gpio, uint64_t addr) "GPIO%s addr: 0x%" PRIx64 " " · line 51
Quoted 6 lines
hw/gpio/trace-events +3
-0@@ -46,3 +46,7 @@ stm32l4x5_gpio_read(char *gpio, uint64_t addr) "GPIO%s addr: 0x%" PRIx64 " " stm32l4x5_gpio_write(char *gpio, uint64_t addr, uint64_t data) "GPIO%s addr: 0x%" PRIx64 " val: 0x%" PRIx64 "" stm32l4x5_gpio_update_idr(char *gpio, uint32_t old_idr, uint32_t new_idr) "GPIO%s from: 0x%x to: 0x%x" stm32l4x5_gpio_pins(char *gpio, uint16_t disconnected, uint16_t high) "GPIO%s disconnected pins: 0x%x levels: 0x%x" + +# tca6416.c +tca6416_write(uint8_t value) "0x%02x""wr 0x%02x"
hw/gpio/trace-events stm32l4x5_gpio_read(char *gpio, uint64_t addr) "GPIO%s addr: 0x%" PRIx64 " " · line 52
Quoted 1 line
hw/gpio/trace-events +1
-0+tca6416_read(uint8_t value) "0x%02x""rd ..."
Regards,
Phil.
Re: [PATCH 20/21] hw/i2c: Import TCA6416 emulation from Xilinx
Quoted 11 lines · Bernhard Beschow
Am 30. Januar 2025 23:05:53 UTC schrieb "Philippe Mathieu-Daudé" <[email protected]>:
Quoted 6 lines
Cc'ing AMD folks
Hi Bernhard,
TL;DR; can't you use the PCF8574 which is a more complete model of I/O expander? (See
hw/gpio/pcf8574.c)If it is software-compatible then I could use it. I'm modeling a real board whose device tree I'd like to use unchanged, so I don't have much choice. The only reason I need it is because its absence clogs the i2c bus.
No clue about compatibility. If you unfortunately need to add it, then please address my comments in the next version.
Quoted 264 lines
Best regards,
BernhardQuoted 260 lines · Bernhard Beschow
Quoted 47 lines
Xilinx QEMU implements a TCA6416 device model which may be useful for the broader QEMU community, so upstream it. In the Xilinx fork, the device model gets compiled whenever
CONFIG_CADENCEis true, so have it maintained by the "hw/*/cadence_*" maintainers.The code is based on Xilinx QEMU version xilinx_v2024.2 plus the following modifications:
* UseOBJECT_DECLARE_SIMPLE_TYPE()
* Port fromDPRINTF()to trace events
* Follow QEMU conventions for naming of state struct
* Rename type to not contain a ','
* UseDEFINE_TYPES()macro
* Implement under hw/gpio since device is i2c client and gpio provider
* Have dedicatedKconfigswitchSigned-off-by Bernhard Beschow <[email protected]>--
I have a use for TCA6416 emulation. Question: Are Xilinx Zynq maintainers willing to maintain this device model?--- MAINTAINERS | 1 + hw/gpio/tca6416.c | 122 +++++++++++++++++++++++++++++++++++++++++++ hw/gpio/Kconfig | 5 ++ hw/gpio/meson.build | 1 + hw/gpio/trace-events | 4 ++ 5 files changed, 133 insertions(+)create mode 100644
hw/gpio/tca6416.cMAINTAINERS +1
-0@@ -1030,6 +1030,7 @@ S: Maintained F: hw/*/xilinx_* F: hw/*/cadence_* F: hw/misc/zynq_slcr.c +F: hw/gpio/tca6416.c F: hw/adc/zynq-xadc.c F: include/hw/misc/zynq_slcr.h F: include/hw/adc/zynq-xadc.hhw/gpio/tca6416.c new file +0
-0hw/gpio/tca6416.c line 2
Quoted 2 lines
hw/gpio/tca6416.c new file +2
-0@@ -0,0 +1,122 @@ +/* +* QEMU model of TCA6416 16-Bit I/O Expander Please add datasheet reference.
Quoted 12 lines
hw/gpio/tca6416.c new file +12
-0+* +* Copyright (c) 2018 Xilinx Inc. +* +* Written by Sai Pavan Boddu <[email protected]> +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* hw/gpio/tca6416.c line 24
Quoted 10 lines
hw/gpio/tca6416.c new file +10
-0+* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. Sai/Edgar/Francisco, should we update to AMD here? Remove or update the email address? Also, can you Ack the replacement of this license by a SPDX tag?
Quoted 6 lines
hw/gpio/tca6416.c new file +6
-0+*/ +#include "qemu/osdep.h" +#include "hw/i2c/i2c.h" +#include "trace.h" + +#define TYPE_TCA6416 "tca6416"hw/gpio/tca6416.c line 40
Quoted 10 lines
hw/gpio/tca6416.c new file +10
-0+OBJECT_DECLARE_SIMPLE_TYPE(Tca6416State, TCA6416) + +#define IN_PORT0 0 +#define IN_PORT1 1 +#define OUT_PORT0 2 +#define OUT_PORT1 3 +#define POL_INV0 4 +#define POL_INV1 5 +#define CONF_PORT0 6 +#define CONF_PORT1 7enum up to here?
Quoted 22 lines
hw/gpio/tca6416.c new file +22
-0+#define RMAX (CONF_PORT1 + 1) + +enum tca6416_events { +ADDR_DONE , +ADDRESSING , +}; + +struct Tca6416State { +I2CSlave i2c; + +uint8_t addr; +uint8_t state; +uint8_t regs[RMAX ]; +}; + +static uint8_t tca6416_read (I2CSlave *i2c) +{ +Tca6416State *s =TCA6416 (i2c); +uint8_t ret; + + ret = s->regs[s->addr]; +trace_tca6416_read (ret);hw/gpio/tca6416.c line 72
Quoted 10 lines
hw/gpio/tca6416.c new file +10
-0+return ret; +} + +static int tca6416_write (I2CSlave *i2c,uint8_t data) +{ +Tca6416State *s =TCA6416 (i2c); + +trace_tca6416_write (data); +if (s->state ==ADDRESSING ) { + s->addr = data;I suppose HW masks here.
s->addr = data & 0xf;hw/gpio/tca6416.c line 74
Quoted 2 lines
hw/gpio/tca6416.c new file +2
-0+ }else { + s->regs[s->addr] = data;(otherwise this could overflow).
So this device isn't doing anything actually (I'd have expected 1 IRQ and 16 GPIO lines). What is the point, at least in this state?
hw/gpio/tca6416.c line 83
Quoted 9 lines
hw/gpio/tca6416.c new file +9
-0+ } + +return 0 ; +} + +static void tca6416_realize (DeviceState *dev,Error **errp) +{ +Tca6416State *s =TCA6416 (dev); +Missing:
s->regs[OUT_PORT0] = 0xff; s->regs[OUT_PORT1] = 0xff; s->regs[POL_INV0] = 0x00; s->regs[POL_INV1] = 0x00;hw/gpio/tca6416.c line 85
Quoted 2 lines
hw/gpio/tca6416.c new file +2
-0+ s->regs[CONF_PORT0 ] =0xFF ; + s->regs[CONF_PORT1 ] =0xFF ;Style is
0xff.That said, this is not a REALIZE but RESET handler.
Quoted 12 lines
hw/gpio/tca6416.c new file +12
-0+} + +static int tca6416_event (I2CSlave *i2c,enum i2c_event event) +{ +Tca6416State *s =TCA6416 (i2c); + +switch (event) { +case I2C_START_SEND : + s->state =ADDRESSING ; +break ; +default : + s->state =ADDR_DONE ;hw/gpio/tca6416.c line 107
Quoted 10 lines
hw/gpio/tca6416.c new file +10
-0+ }; +return 0 ; +} + +static void tca6416_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +I2CSlaveClass *k =I2C_SLAVE_CLASS (klass); + + dc->realize = tca6416_realize;(
tca6416_realizeis a reset handler).Please complete:
dc->desc = "TCA6416 I/O Expander"; set_bit(DEVICE_CATEGORY_MISC, dc->categories);No migration state?
Quoted 42 lines
hw/gpio/tca6416.c new file +14
-0+ k->recv = tca6416_read; + k->send = tca6416_write; + k->event = tca6416_event; +}> + +static const TypeInfo tca6416_types[] = { + { + .name =TYPE_TCA6416 , + .parent =TYPE_I2C_SLAVE , + .class_init = tca6416_class_init, + .instance_size =sizeof (Tca6416State), + } +}; + +DEFINE_TYPES (tca6416_types)hw/gpio/Kconfig +4
-0@@ -20,5 +20,10 @@ config PCF8574 bool depends on I2C +config TCA6416 + bool + depends on I2C + default y if I2C_DEVICES + config ZAURUS_SCOOP boolhw/gpio/meson.build +1
-0@@ -18,3 +18,4 @@ system_ss.add(when: 'CONFIG_STM32L4X5_SOC', if_true: files('stm32l4x5_gpio.c')) system_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('aspeed_gpio.c')) system_ss.add(when: 'CONFIG_SIFIVE_GPIO', if_true: files('sifive_gpio.c')) system_ss.add(when: 'CONFIG_PCF8574', if_true: files('pcf8574.c')) +system_ss.add(when: 'CONFIG_TCA6416', if_true: files('tca6416.c'))hw/gpio/trace-events +0
-0hw/gpio/trace-events stm32l4x5_gpio_read(char *gpio, uint64_t addr) "GPIO%s addr: 0x%" PRIx64 " " · line 51
Quoted 6 lines
hw/gpio/trace-events +3
-0@@ -46,3 +46,7 @@ stm32l4x5_gpio_read(char *gpio, uint64_t addr) "GPIO%s addr: 0x%" PRIx64 " " stm32l4x5_gpio_write(char *gpio, uint64_t addr, uint64_t data) "GPIO%s addr: 0x%" PRIx64 " val: 0x%" PRIx64 "" stm32l4x5_gpio_update_idr(char *gpio, uint32_t old_idr, uint32_t new_idr) "GPIO%s from: 0x%x to: 0x%x" stm32l4x5_gpio_pins(char *gpio, uint16_t disconnected, uint16_t high) "GPIO%s disconnected pins: 0x%x levels: 0x%x" + +# tca6416.c +tca6416_write(uint8_t value) "0x%02x""wr 0x%02x"
hw/gpio/trace-events stm32l4x5_gpio_read(char *gpio, uint64_t addr) "GPIO%s addr: 0x%" PRIx64 " " · line 52
Quoted 1 line
hw/gpio/trace-events +1
-0+tca6416_read(uint8_t value) "0x%02x""rd ..."
Regards,
Phil.
Re: [PATCH 20/21] hw/i2c: Import TCA6416 emulation from Xilinx
Quoted 2 lines · Philippe Mathieu-Daudé
No clue about compatibility. If you unfortunately need to add it, then please address my comments in the next version.
TCA6416 is _way_ more complex device than PCF8574. Basically PCF8574 is shift register directly connected to IO lines, while TCA6416 is more like fully-fledged GPIO controller with output direction, drive strength, interrupt mask configuration etc etc.
In Linux kernel these devices are handled by family-compatible driver
drivers/gpio/gpio-pca953x.c
Closest things by implementation in QEMU source tree are
hw/gpio/pca9552.c and
hw/gpio/pca9554.c
However they are NOT register-compatible with pca953x. I suppose, best decision would be new driver for TCA6416 which eventually should support whole pca953x family of I2C GPIO expanders.
Best regards,
Dmitrii
Re: [PATCH 20/21] hw/i2c: Import TCA6416 emulation from Xilinx
Am 3. Februar 2025 05:42:55 UTC schrieb Dmitriy Sharikhin <[email protected]>:
Quoted 8 lines
Quoted 2 lines · Philippe Mathieu-Daudé
No clue about compatibility. If you unfortunately need to add it, then please address my comments in the next version.
TCA6416 is _way_ more complex device than PCF8574. Basically PCF8574 is shift register directly connected to IO lines, while TCA6416 is more like fully-fledged GPIO controller with output direction, drive strength, interrupt mask configuration etc etc.
Quoted 6 lines
In Linux kernel these devices are handled by family-compatible driver
drivers/gpio/gpio-pca953x.c
Closest things by implementation in QEMU source tree are
hw/gpio/pca9552.cand
hw/gpio/pca9554.c
However they are NOT register-compatible with pca953x.
Thanks Dimitrii for the valuable hint! The pca9552 model works fine for my purposes -- which is just to avoid clogging the i2c bus.
Quoted 3 lines
I suppose, best
decision would be new driver for TCA6416 which eventually should support whole pca953x family of I2C GPIO expanders.
I'll drop this patch then.
Best regards,
Bernhard
Quoted 3 lines
Best regards,
Dmitrii
Re: [PATCH 20/21] hw/i2c: Import TCA6416 emulation from Xilinx
In reply to Dmitriy SharikhinAm 3. Februar 2025 05:42:55 UTC schrieb Dmitriy Sharikhin <[email protected]>:
Quoted 8 lines
Quoted 2 lines · Philippe Mathieu-Daudé
No clue about compatibility. If you unfortunately need to add it, then please address my comments in the next version.
TCA6416 is _way_ more complex device than PCF8574. Basically PCF8574 is shift register directly connected to IO lines, while TCA6416 is more like fully-fledged GPIO controller with output direction, drive strength, interrupt mask configuration etc etc.
Quoted 8 lines
In Linux kernel these devices are handled by family-compatible driver
drivers/gpio/gpio-pca953x.c
Closest things by implementation in QEMU source tree are
hw/gpio/pca9552.cand
hw/gpio/pca9554.c
However they are NOT register-compatible with pca953x. I suppose, best decision would be new driver for TCA6416 which eventually should support whole pca953x family of I2C GPIO expanders.
Just for the record: There has been an attempt to implement it: <https://lore.kernel.org/qemu-devel/[email protected]/>
Quoted 3 lines
Best regards,
Dmitrii
Re: [PATCH 20/21] hw/i2c: Import TCA6416 emulation from Xilinx
In reply to Philippe Mathieu-DaudéAm 2. Februar 2025 17:09:06 UTC schrieb "Philippe Mathieu-Daudé" <[email protected]>:
Quoted 8 lines · Bernhard Beschow
Quoted 7 lines
Am 30. Januar 2025 23:05:53 UTC schrieb "Philippe Mathieu-Daudé" <[email protected]>:
Quoted 4 lines
Cc'ing AMD folks
Hi Bernhard,
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
TL;DR; can't you use the PCF8574 which is a more complete model of I/O expander? (See
hw/gpio/pcf8574.c)If it is software-compatible then I could use it. I'm modeling a real board whose device tree I'd like to use unchanged, so I don't have much choice. The only reason I need it is because its absence clogs the i2c bus.
No clue about compatibility. If you unfortunately need to add it, then please address my comments in the next version.
Sure, I'll link your and Zoltan's comments as todos in the next version.
Best regards,
Bernhard
Quoted 266 lines
Quoted 265 lines
Best regards,
BernhardQuoted 260 lines · Bernhard Beschow
Quoted 47 lines
Xilinx QEMU implements a TCA6416 device model which may be useful for the broader QEMU community, so upstream it. In the Xilinx fork, the device model gets compiled whenever
CONFIG_CADENCEis true, so have it maintained by the "hw/*/cadence_*" maintainers.The code is based on Xilinx QEMU version xilinx_v2024.2 plus the following modifications:
* UseOBJECT_DECLARE_SIMPLE_TYPE()
* Port fromDPRINTF()to trace events
* Follow QEMU conventions for naming of state struct
* Rename type to not contain a ','
* UseDEFINE_TYPES()macro
* Implement under hw/gpio since device is i2c client and gpio provider
* Have dedicatedKconfigswitchSigned-off-by Bernhard Beschow <[email protected]>--
I have a use for TCA6416 emulation. Question: Are Xilinx Zynq maintainers willing to maintain this device model?--- MAINTAINERS | 1 + hw/gpio/tca6416.c | 122 +++++++++++++++++++++++++++++++++++++++++++ hw/gpio/Kconfig | 5 ++ hw/gpio/meson.build | 1 + hw/gpio/trace-events | 4 ++ 5 files changed, 133 insertions(+)create mode 100644
hw/gpio/tca6416.cMAINTAINERS +1
-0@@ -1030,6 +1030,7 @@ S: Maintained F: hw/*/xilinx_* F: hw/*/cadence_* F: hw/misc/zynq_slcr.c +F: hw/gpio/tca6416.c F: hw/adc/zynq-xadc.c F: include/hw/misc/zynq_slcr.h F: include/hw/adc/zynq-xadc.hhw/gpio/tca6416.c new file +0
-0hw/gpio/tca6416.c line 2
Quoted 2 lines
hw/gpio/tca6416.c new file +2
-0@@ -0,0 +1,122 @@ +/* +* QEMU model of TCA6416 16-Bit I/O Expander Please add datasheet reference.
Quoted 12 lines
hw/gpio/tca6416.c new file +12
-0+* +* Copyright (c) 2018 Xilinx Inc. +* +* Written by Sai Pavan Boddu <[email protected]> +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* hw/gpio/tca6416.c line 24
Quoted 10 lines
hw/gpio/tca6416.c new file +10
-0+* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. Sai/Edgar/Francisco, should we update to AMD here? Remove or update the email address? Also, can you Ack the replacement of this license by a SPDX tag?
Quoted 6 lines
hw/gpio/tca6416.c new file +6
-0+*/ +#include "qemu/osdep.h" +#include "hw/i2c/i2c.h" +#include "trace.h" + +#define TYPE_TCA6416 "tca6416"hw/gpio/tca6416.c line 40
Quoted 10 lines
hw/gpio/tca6416.c new file +10
-0+OBJECT_DECLARE_SIMPLE_TYPE(Tca6416State, TCA6416) + +#define IN_PORT0 0 +#define IN_PORT1 1 +#define OUT_PORT0 2 +#define OUT_PORT1 3 +#define POL_INV0 4 +#define POL_INV1 5 +#define CONF_PORT0 6 +#define CONF_PORT1 7enum up to here?
Quoted 22 lines
hw/gpio/tca6416.c new file +22
-0+#define RMAX (CONF_PORT1 + 1) + +enum tca6416_events { +ADDR_DONE , +ADDRESSING , +}; + +struct Tca6416State { +I2CSlave i2c; + +uint8_t addr; +uint8_t state; +uint8_t regs[RMAX ]; +}; + +static uint8_t tca6416_read (I2CSlave *i2c) +{ +Tca6416State *s =TCA6416 (i2c); +uint8_t ret; + + ret = s->regs[s->addr]; +trace_tca6416_read (ret);hw/gpio/tca6416.c line 72
Quoted 10 lines
hw/gpio/tca6416.c new file +10
-0+return ret; +} + +static int tca6416_write (I2CSlave *i2c,uint8_t data) +{ +Tca6416State *s =TCA6416 (i2c); + +trace_tca6416_write (data); +if (s->state ==ADDRESSING ) { + s->addr = data;I suppose HW masks here.
s->addr = data & 0xf;hw/gpio/tca6416.c line 74
Quoted 2 lines
hw/gpio/tca6416.c new file +2
-0+ }else { + s->regs[s->addr] = data;(otherwise this could overflow).
So this device isn't doing anything actually (I'd have expected 1 IRQ and 16 GPIO lines). What is the point, at least in this state?
hw/gpio/tca6416.c line 83
Quoted 9 lines
hw/gpio/tca6416.c new file +9
-0+ } + +return 0 ; +} + +static void tca6416_realize (DeviceState *dev,Error **errp) +{ +Tca6416State *s =TCA6416 (dev); +Missing:
s->regs[OUT_PORT0] = 0xff; s->regs[OUT_PORT1] = 0xff; s->regs[POL_INV0] = 0x00; s->regs[POL_INV1] = 0x00;hw/gpio/tca6416.c line 85
Quoted 2 lines
hw/gpio/tca6416.c new file +2
-0+ s->regs[CONF_PORT0 ] =0xFF ; + s->regs[CONF_PORT1 ] =0xFF ;Style is
0xff.That said, this is not a REALIZE but RESET handler.
Quoted 12 lines
hw/gpio/tca6416.c new file +12
-0+} + +static int tca6416_event (I2CSlave *i2c,enum i2c_event event) +{ +Tca6416State *s =TCA6416 (i2c); + +switch (event) { +case I2C_START_SEND : + s->state =ADDRESSING ; +break ; +default : + s->state =ADDR_DONE ;hw/gpio/tca6416.c line 107
Quoted 10 lines
hw/gpio/tca6416.c new file +10
-0+ }; +return 0 ; +} + +static void tca6416_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +I2CSlaveClass *k =I2C_SLAVE_CLASS (klass); + + dc->realize = tca6416_realize;(
tca6416_realizeis a reset handler).Please complete:
dc->desc = "TCA6416 I/O Expander"; set_bit(DEVICE_CATEGORY_MISC, dc->categories);No migration state?
Quoted 42 lines
hw/gpio/tca6416.c new file +14
-0+ k->recv = tca6416_read; + k->send = tca6416_write; + k->event = tca6416_event; +}> + +static const TypeInfo tca6416_types[] = { + { + .name =TYPE_TCA6416 , + .parent =TYPE_I2C_SLAVE , + .class_init = tca6416_class_init, + .instance_size =sizeof (Tca6416State), + } +}; + +DEFINE_TYPES (tca6416_types)hw/gpio/Kconfig +4
-0@@ -20,5 +20,10 @@ config PCF8574 bool depends on I2C +config TCA6416 + bool + depends on I2C + default y if I2C_DEVICES + config ZAURUS_SCOOP boolhw/gpio/meson.build +1
-0@@ -18,3 +18,4 @@ system_ss.add(when: 'CONFIG_STM32L4X5_SOC', if_true: files('stm32l4x5_gpio.c')) system_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('aspeed_gpio.c')) system_ss.add(when: 'CONFIG_SIFIVE_GPIO', if_true: files('sifive_gpio.c')) system_ss.add(when: 'CONFIG_PCF8574', if_true: files('pcf8574.c')) +system_ss.add(when: 'CONFIG_TCA6416', if_true: files('tca6416.c'))hw/gpio/trace-events +0
-0hw/gpio/trace-events stm32l4x5_gpio_read(char *gpio, uint64_t addr) "GPIO%s addr: 0x%" PRIx64 " " · line 51
Quoted 6 lines
hw/gpio/trace-events +3
-0@@ -46,3 +46,7 @@ stm32l4x5_gpio_read(char *gpio, uint64_t addr) "GPIO%s addr: 0x%" PRIx64 " " stm32l4x5_gpio_write(char *gpio, uint64_t addr, uint64_t data) "GPIO%s addr: 0x%" PRIx64 " val: 0x%" PRIx64 "" stm32l4x5_gpio_update_idr(char *gpio, uint32_t old_idr, uint32_t new_idr) "GPIO%s from: 0x%x to: 0x%x" stm32l4x5_gpio_pins(char *gpio, uint16_t disconnected, uint16_t high) "GPIO%s disconnected pins: 0x%x levels: 0x%x" + +# tca6416.c +tca6416_write(uint8_t value) "0x%02x""wr 0x%02x"
hw/gpio/trace-events stm32l4x5_gpio_read(char *gpio, uint64_t addr) "GPIO%s addr: 0x%" PRIx64 " " · line 52
Quoted 1 line
hw/gpio/trace-events +1
-0+tca6416_read(uint8_t value) "0x%02x""rd ..."
Regards,
Phil.
PATCH 21/21 hw/gpio/imx_gpio: Don't clear input GPIO values upon reset
In reply to Bernhard BeschowInput GPIO values such as a present SD card may get notified before the GPIO controller itself gets reset. Claring the input values thus loses data. Assuming that input GPIO events are only fired when the state changes, the input values shouldn't be reset.
--- hw/gpio/imx_gpio.c | 1 - 1 file changed, 1 deletion(-)
hw/gpio/imx_gpio.c +0 -1
@@ -298,7 +298,6 @@ static void imx_gpio_reset(DeviceState *dev) s->dr =0 ; s->gdir =0 ; - s->psr =0 ; s->icr =0 ; s->imr =0 ; s->isr =0 ;
Signature · 1 line
2.48.1
Re: [PATCH 21/21] hw/gpio/imx_gpio: Don't clear input GPIO values upon reset
Hi,
Quoted 2 lines · Bernhard Beschow
Input GPIO values such as a present SD card may get notified before the GPIO controller itself gets reset. Claring the input values thus loses data. Assuming
^- nit: Clearing
Cheers,
Gustavo
Quoted 20 lines
that input GPIO events are only fired when the state changes, the input values shouldn't be reset.
Signed-off-by Bernhard Beschow <[email protected]>--- hw/gpio/imx_gpio.c | 1 - 1 file changed, 1 deletion(-)hw/gpio/imx_gpio.c +0
-1@@ -298,7 +298,6 @@ static void imx_gpio_reset(DeviceState *dev) s->dr =0 ; s->gdir =0 ; - s->psr =0 ; s->icr =0 ; s->imr =0 ; s->isr =0 ;
Re: [PATCH 21/21] hw/gpio/imx_gpio: Don't clear input GPIO values upon reset
Am 28. Januar 2025 14:33:27 UTC schrieb Gustavo Romero <[email protected]>:
Quoted 9 lines
Hi,
Quoted 2 lines · Bernhard Beschow
Input GPIO values such as a present SD card may get notified before the GPIO controller itself gets reset. Claring the input values thus loses data. Assuming
^- nit: Clearing
Peter asked for a three-way reset in inbound devices while keeping the logic here as is. I'd drop this patch then.
Best regards,
Bernhard
Quoted 23 lines
Cheers,
GustavoQuoted 19 lines
that input GPIO events are only fired when the state changes, the input values shouldn't be reset.
Signed-off-by Bernhard Beschow <[email protected]>--- hw/gpio/imx_gpio.c | 1 - 1 file changed, 1 deletion(-)hw/gpio/imx_gpio.c +0
-1@@ -298,7 +298,6 @@ static void imx_gpio_reset(DeviceState *dev) s->dr =0 ; s->gdir =0 ; - s->psr =0 ; s->icr =0 ; s->imr =0 ; s->isr =0 ;