xref: /openbmc/qemu/hw/arm/fsl-imx8mp.c (revision fe9d41a734822506499c0c3ed7cc5d79e20c8723)
1a4eefc69SBernhard Beschow /*
2a4eefc69SBernhard Beschow  * i.MX 8M Plus SoC Implementation
3a4eefc69SBernhard Beschow  *
4a4eefc69SBernhard Beschow  * Based on hw/arm/fsl-imx6.c
5a4eefc69SBernhard Beschow  *
6a4eefc69SBernhard Beschow  * Copyright (c) 2024, Bernhard Beschow <shentey@gmail.com>
7a4eefc69SBernhard Beschow  *
8a4eefc69SBernhard Beschow  * SPDX-License-Identifier: GPL-2.0-or-later
9a4eefc69SBernhard Beschow  */
10a4eefc69SBernhard Beschow 
11a4eefc69SBernhard Beschow #include "qemu/osdep.h"
12a4eefc69SBernhard Beschow #include "exec/address-spaces.h"
13a4eefc69SBernhard Beschow #include "hw/arm/bsa.h"
14a4eefc69SBernhard Beschow #include "hw/arm/fsl-imx8mp.h"
15a4eefc69SBernhard Beschow #include "hw/intc/arm_gicv3.h"
16a4eefc69SBernhard Beschow #include "hw/misc/unimp.h"
17a4eefc69SBernhard Beschow #include "hw/boards.h"
18a4eefc69SBernhard Beschow #include "system/system.h"
19a4eefc69SBernhard Beschow #include "target/arm/cpu-qom.h"
20a4eefc69SBernhard Beschow #include "qapi/error.h"
21a4eefc69SBernhard Beschow #include "qobject/qlist.h"
22a4eefc69SBernhard Beschow 
23a4eefc69SBernhard Beschow static const struct {
24a4eefc69SBernhard Beschow     hwaddr addr;
25a4eefc69SBernhard Beschow     size_t size;
26a4eefc69SBernhard Beschow     const char *name;
27a4eefc69SBernhard Beschow } fsl_imx8mp_memmap[] = {
28a4eefc69SBernhard Beschow     [FSL_IMX8MP_RAM] = { FSL_IMX8MP_RAM_START, FSL_IMX8MP_RAM_SIZE_MAX, "ram" },
29a4eefc69SBernhard Beschow     [FSL_IMX8MP_DDR_PHY_BROADCAST] = { 0x3dc00000, 4 * MiB, "ddr_phy_broadcast" },
30a4eefc69SBernhard Beschow     [FSL_IMX8MP_DDR_PERF_MON] = { 0x3d800000, 4 * MiB, "ddr_perf_mon" },
31a4eefc69SBernhard Beschow     [FSL_IMX8MP_DDR_CTL] = { 0x3d400000, 4 * MiB, "ddr_ctl" },
32a4eefc69SBernhard Beschow     [FSL_IMX8MP_DDR_BLK_CTRL] = { 0x3d000000, 1 * MiB, "ddr_blk_ctrl" },
33a4eefc69SBernhard Beschow     [FSL_IMX8MP_DDR_PHY] = { 0x3c000000, 16 * MiB, "ddr_phy" },
34a4eefc69SBernhard Beschow     [FSL_IMX8MP_AUDIO_DSP] = { 0x3b000000, 16 * MiB, "audio_dsp" },
35a4eefc69SBernhard Beschow     [FSL_IMX8MP_GIC_DIST] = { 0x38800000, 512 * KiB, "gic_dist" },
36a4eefc69SBernhard Beschow     [FSL_IMX8MP_GIC_REDIST] = { 0x38880000, 512 * KiB, "gic_redist" },
37a4eefc69SBernhard Beschow     [FSL_IMX8MP_NPU] = { 0x38500000, 2 * MiB, "npu" },
38a4eefc69SBernhard Beschow     [FSL_IMX8MP_VPU] = { 0x38340000, 2 * MiB, "vpu" },
39a4eefc69SBernhard Beschow     [FSL_IMX8MP_VPU_BLK_CTRL] = { 0x38330000, 2 * MiB, "vpu_blk_ctrl" },
40a4eefc69SBernhard Beschow     [FSL_IMX8MP_VPU_VC8000E_ENCODER] = { 0x38320000, 2 * MiB, "vpu_vc8000e_encoder" },
41a4eefc69SBernhard Beschow     [FSL_IMX8MP_VPU_G2_DECODER] = { 0x38310000, 2 * MiB, "vpu_g2_decoder" },
42a4eefc69SBernhard Beschow     [FSL_IMX8MP_VPU_G1_DECODER] = { 0x38300000, 2 * MiB, "vpu_g1_decoder" },
434226c39fSBernhard Beschow     [FSL_IMX8MP_USB2_GLUE] = { 0x382f0000, 0x100, "usb2_glue" },
444226c39fSBernhard Beschow     [FSL_IMX8MP_USB2_OTG] = { 0x3820cc00, 0x100, "usb2_otg" },
454226c39fSBernhard Beschow     [FSL_IMX8MP_USB2_DEV] = { 0x3820c700, 0x500, "usb2_dev" },
464226c39fSBernhard Beschow     [FSL_IMX8MP_USB2] = { 0x38200000, 0xc700, "usb2" },
474226c39fSBernhard Beschow     [FSL_IMX8MP_USB1_GLUE] = { 0x381f0000, 0x100, "usb1_glue" },
484226c39fSBernhard Beschow     [FSL_IMX8MP_USB1_OTG] = { 0x3810cc00, 0x100, "usb1_otg" },
494226c39fSBernhard Beschow     [FSL_IMX8MP_USB1_DEV] = { 0x3810c700, 0x500, "usb1_dev" },
504226c39fSBernhard Beschow     [FSL_IMX8MP_USB1] = { 0x38100000, 0xc700, "usb1" },
51a4eefc69SBernhard Beschow     [FSL_IMX8MP_GPU2D] = { 0x38008000, 32 * KiB, "gpu2d" },
52a4eefc69SBernhard Beschow     [FSL_IMX8MP_GPU3D] = { 0x38000000, 32 * KiB, "gpu3d" },
53a4eefc69SBernhard Beschow     [FSL_IMX8MP_QSPI1_RX_BUFFER] = { 0x34000000, 32 * MiB, "qspi1_rx_buffer" },
54a4eefc69SBernhard Beschow     [FSL_IMX8MP_PCIE1] = { 0x33800000, 4 * MiB, "pcie1" },
55a4eefc69SBernhard Beschow     [FSL_IMX8MP_QSPI1_TX_BUFFER] = { 0x33008000, 32 * KiB, "qspi1_tx_buffer" },
56a4eefc69SBernhard Beschow     [FSL_IMX8MP_APBH_DMA] = { 0x33000000, 32 * KiB, "apbh_dma" },
57a4eefc69SBernhard Beschow 
58a4eefc69SBernhard Beschow     /* AIPS-5 Begin */
59a4eefc69SBernhard Beschow     [FSL_IMX8MP_MU_3_B] = { 0x30e90000, 64 * KiB, "mu_3_b" },
60a4eefc69SBernhard Beschow     [FSL_IMX8MP_MU_3_A] = { 0x30e80000, 64 * KiB, "mu_3_a" },
61a4eefc69SBernhard Beschow     [FSL_IMX8MP_MU_2_B] = { 0x30e70000, 64 * KiB, "mu_2_b" },
62a4eefc69SBernhard Beschow     [FSL_IMX8MP_MU_2_A] = { 0x30e60000, 64 * KiB, "mu_2_a" },
63a4eefc69SBernhard Beschow     [FSL_IMX8MP_EDMA_CHANNELS] = { 0x30e40000, 128 * KiB, "edma_channels" },
64a4eefc69SBernhard Beschow     [FSL_IMX8MP_EDMA_MANAGEMENT_PAGE] = { 0x30e30000, 64 * KiB, "edma_management_page" },
65a4eefc69SBernhard Beschow     [FSL_IMX8MP_AUDIO_BLK_CTRL] = { 0x30e20000, 64 * KiB, "audio_blk_ctrl" },
66a4eefc69SBernhard Beschow     [FSL_IMX8MP_SDMA2] = { 0x30e10000, 64 * KiB, "sdma2" },
67a4eefc69SBernhard Beschow     [FSL_IMX8MP_SDMA3] = { 0x30e00000, 64 * KiB, "sdma3" },
68a4eefc69SBernhard Beschow     [FSL_IMX8MP_AIPS5_CONFIGURATION] = { 0x30df0000, 64 * KiB, "aips5_configuration" },
69a4eefc69SBernhard Beschow     [FSL_IMX8MP_SPBA2] = { 0x30cf0000, 64 * KiB, "spba2" },
70a4eefc69SBernhard Beschow     [FSL_IMX8MP_AUDIO_XCVR_RX] = { 0x30cc0000, 64 * KiB, "audio_xcvr_rx" },
71a4eefc69SBernhard Beschow     [FSL_IMX8MP_HDMI_TX_AUDLNK_MSTR] = { 0x30cb0000, 64 * KiB, "hdmi_tx_audlnk_mstr" },
72a4eefc69SBernhard Beschow     [FSL_IMX8MP_PDM] = { 0x30ca0000, 64 * KiB, "pdm" },
73a4eefc69SBernhard Beschow     [FSL_IMX8MP_ASRC] = { 0x30c90000, 64 * KiB, "asrc" },
74a4eefc69SBernhard Beschow     [FSL_IMX8MP_SAI7] = { 0x30c80000, 64 * KiB, "sai7" },
75a4eefc69SBernhard Beschow     [FSL_IMX8MP_SAI6] = { 0x30c60000, 64 * KiB, "sai6" },
76a4eefc69SBernhard Beschow     [FSL_IMX8MP_SAI5] = { 0x30c50000, 64 * KiB, "sai5" },
77a4eefc69SBernhard Beschow     [FSL_IMX8MP_SAI3] = { 0x30c30000, 64 * KiB, "sai3" },
78a4eefc69SBernhard Beschow     [FSL_IMX8MP_SAI2] = { 0x30c20000, 64 * KiB, "sai2" },
79a4eefc69SBernhard Beschow     [FSL_IMX8MP_SAI1] = { 0x30c10000, 64 * KiB, "sai1" },
80a4eefc69SBernhard Beschow     /* AIPS-5 End */
81a4eefc69SBernhard Beschow 
82a4eefc69SBernhard Beschow     /* AIPS-4 Begin */
83a4eefc69SBernhard Beschow     [FSL_IMX8MP_HDMI_TX] = { 0x32fc0000, 128 * KiB, "hdmi_tx" },
84a4eefc69SBernhard Beschow     [FSL_IMX8MP_TZASC] = { 0x32f80000, 64 * KiB, "tzasc" },
85a4eefc69SBernhard Beschow     [FSL_IMX8MP_HSIO_BLK_CTL] = { 0x32f10000, 64 * KiB, "hsio_blk_ctl" },
86a4eefc69SBernhard Beschow     [FSL_IMX8MP_PCIE_PHY1] = { 0x32f00000, 64 * KiB, "pcie_phy1" },
87a4eefc69SBernhard Beschow     [FSL_IMX8MP_MEDIA_BLK_CTL] = { 0x32ec0000, 64 * KiB, "media_blk_ctl" },
88a4eefc69SBernhard Beschow     [FSL_IMX8MP_LCDIF2] = { 0x32e90000, 64 * KiB, "lcdif2" },
89a4eefc69SBernhard Beschow     [FSL_IMX8MP_LCDIF1] = { 0x32e80000, 64 * KiB, "lcdif1" },
90a4eefc69SBernhard Beschow     [FSL_IMX8MP_MIPI_DSI1] = { 0x32e60000, 64 * KiB, "mipi_dsi1" },
91a4eefc69SBernhard Beschow     [FSL_IMX8MP_MIPI_CSI2] = { 0x32e50000, 64 * KiB, "mipi_csi2" },
92a4eefc69SBernhard Beschow     [FSL_IMX8MP_MIPI_CSI1] = { 0x32e40000, 64 * KiB, "mipi_csi1" },
93a4eefc69SBernhard Beschow     [FSL_IMX8MP_IPS_DEWARP] = { 0x32e30000, 64 * KiB, "ips_dewarp" },
94a4eefc69SBernhard Beschow     [FSL_IMX8MP_ISP2] = { 0x32e20000, 64 * KiB, "isp2" },
95a4eefc69SBernhard Beschow     [FSL_IMX8MP_ISP1] = { 0x32e10000, 64 * KiB, "isp1" },
96a4eefc69SBernhard Beschow     [FSL_IMX8MP_ISI] = { 0x32e00000, 64 * KiB, "isi" },
97a4eefc69SBernhard Beschow     [FSL_IMX8MP_AIPS4_CONFIGURATION] = { 0x32df0000, 64 * KiB, "aips4_configuration" },
98a4eefc69SBernhard Beschow     /* AIPS-4 End */
99a4eefc69SBernhard Beschow 
100a4eefc69SBernhard Beschow     [FSL_IMX8MP_INTERCONNECT] = { 0x32700000, 1 * MiB, "interconnect" },
101a4eefc69SBernhard Beschow 
102a4eefc69SBernhard Beschow     /* AIPS-3 Begin */
103a4eefc69SBernhard Beschow     [FSL_IMX8MP_ENET2_TSN] = { 0x30bf0000, 64 * KiB, "enet2_tsn" },
104a4eefc69SBernhard Beschow     [FSL_IMX8MP_ENET1] = { 0x30be0000, 64 * KiB, "enet1" },
105a4eefc69SBernhard Beschow     [FSL_IMX8MP_SDMA1] = { 0x30bd0000, 64 * KiB, "sdma1" },
106a4eefc69SBernhard Beschow     [FSL_IMX8MP_QSPI] = { 0x30bb0000, 64 * KiB, "qspi" },
107a4eefc69SBernhard Beschow     [FSL_IMX8MP_USDHC3] = { 0x30b60000, 64 * KiB, "usdhc3" },
108a4eefc69SBernhard Beschow     [FSL_IMX8MP_USDHC2] = { 0x30b50000, 64 * KiB, "usdhc2" },
109a4eefc69SBernhard Beschow     [FSL_IMX8MP_USDHC1] = { 0x30b40000, 64 * KiB, "usdhc1" },
110a4eefc69SBernhard Beschow     [FSL_IMX8MP_I2C6] = { 0x30ae0000, 64 * KiB, "i2c6" },
111a4eefc69SBernhard Beschow     [FSL_IMX8MP_I2C5] = { 0x30ad0000, 64 * KiB, "i2c5" },
112a4eefc69SBernhard Beschow     [FSL_IMX8MP_SEMAPHORE_HS] = { 0x30ac0000, 64 * KiB, "semaphore_hs" },
113a4eefc69SBernhard Beschow     [FSL_IMX8MP_MU_1_B] = { 0x30ab0000, 64 * KiB, "mu_1_b" },
114a4eefc69SBernhard Beschow     [FSL_IMX8MP_MU_1_A] = { 0x30aa0000, 64 * KiB, "mu_1_a" },
115a4eefc69SBernhard Beschow     [FSL_IMX8MP_AUD_IRQ_STEER] = { 0x30a80000, 64 * KiB, "aud_irq_steer" },
116a4eefc69SBernhard Beschow     [FSL_IMX8MP_UART4] = { 0x30a60000, 64 * KiB, "uart4" },
117a4eefc69SBernhard Beschow     [FSL_IMX8MP_I2C4] = { 0x30a50000, 64 * KiB, "i2c4" },
118a4eefc69SBernhard Beschow     [FSL_IMX8MP_I2C3] = { 0x30a40000, 64 * KiB, "i2c3" },
119a4eefc69SBernhard Beschow     [FSL_IMX8MP_I2C2] = { 0x30a30000, 64 * KiB, "i2c2" },
120a4eefc69SBernhard Beschow     [FSL_IMX8MP_I2C1] = { 0x30a20000, 64 * KiB, "i2c1" },
121a4eefc69SBernhard Beschow     [FSL_IMX8MP_AIPS3_CONFIGURATION] = { 0x309f0000, 64 * KiB, "aips3_configuration" },
122a4eefc69SBernhard Beschow     [FSL_IMX8MP_CAAM] = { 0x30900000, 256 * KiB, "caam" },
123a4eefc69SBernhard Beschow     [FSL_IMX8MP_SPBA1] = { 0x308f0000, 64 * KiB, "spba1" },
124a4eefc69SBernhard Beschow     [FSL_IMX8MP_FLEXCAN2] = { 0x308d0000, 64 * KiB, "flexcan2" },
125a4eefc69SBernhard Beschow     [FSL_IMX8MP_FLEXCAN1] = { 0x308c0000, 64 * KiB, "flexcan1" },
126a4eefc69SBernhard Beschow     [FSL_IMX8MP_UART2] = { 0x30890000, 64 * KiB, "uart2" },
127a4eefc69SBernhard Beschow     [FSL_IMX8MP_UART3] = { 0x30880000, 64 * KiB, "uart3" },
128a4eefc69SBernhard Beschow     [FSL_IMX8MP_UART1] = { 0x30860000, 64 * KiB, "uart1" },
129a4eefc69SBernhard Beschow     [FSL_IMX8MP_ECSPI3] = { 0x30840000, 64 * KiB, "ecspi3" },
130a4eefc69SBernhard Beschow     [FSL_IMX8MP_ECSPI2] = { 0x30830000, 64 * KiB, "ecspi2" },
131a4eefc69SBernhard Beschow     [FSL_IMX8MP_ECSPI1] = { 0x30820000, 64 * KiB, "ecspi1" },
132a4eefc69SBernhard Beschow     /* AIPS-3 End */
133a4eefc69SBernhard Beschow 
134a4eefc69SBernhard Beschow     /* AIPS-2 Begin */
135a4eefc69SBernhard Beschow     [FSL_IMX8MP_QOSC] = { 0x307f0000, 64 * KiB, "qosc" },
136a4eefc69SBernhard Beschow     [FSL_IMX8MP_PERFMON2] = { 0x307d0000, 64 * KiB, "perfmon2" },
137a4eefc69SBernhard Beschow     [FSL_IMX8MP_PERFMON1] = { 0x307c0000, 64 * KiB, "perfmon1" },
138a4eefc69SBernhard Beschow     [FSL_IMX8MP_GPT4] = { 0x30700000, 64 * KiB, "gpt4" },
139a4eefc69SBernhard Beschow     [FSL_IMX8MP_GPT5] = { 0x306f0000, 64 * KiB, "gpt5" },
140a4eefc69SBernhard Beschow     [FSL_IMX8MP_GPT6] = { 0x306e0000, 64 * KiB, "gpt6" },
141a4eefc69SBernhard Beschow     [FSL_IMX8MP_SYSCNT_CTRL] = { 0x306c0000, 64 * KiB, "syscnt_ctrl" },
142a4eefc69SBernhard Beschow     [FSL_IMX8MP_SYSCNT_CMP] = { 0x306b0000, 64 * KiB, "syscnt_cmp" },
143a4eefc69SBernhard Beschow     [FSL_IMX8MP_SYSCNT_RD] = { 0x306a0000, 64 * KiB, "syscnt_rd" },
144a4eefc69SBernhard Beschow     [FSL_IMX8MP_PWM4] = { 0x30690000, 64 * KiB, "pwm4" },
145a4eefc69SBernhard Beschow     [FSL_IMX8MP_PWM3] = { 0x30680000, 64 * KiB, "pwm3" },
146a4eefc69SBernhard Beschow     [FSL_IMX8MP_PWM2] = { 0x30670000, 64 * KiB, "pwm2" },
147a4eefc69SBernhard Beschow     [FSL_IMX8MP_PWM1] = { 0x30660000, 64 * KiB, "pwm1" },
148a4eefc69SBernhard Beschow     [FSL_IMX8MP_AIPS2_CONFIGURATION] = { 0x305f0000, 64 * KiB, "aips2_configuration" },
149a4eefc69SBernhard Beschow     /* AIPS-2 End */
150a4eefc69SBernhard Beschow 
151a4eefc69SBernhard Beschow     /* AIPS-1 Begin */
152a4eefc69SBernhard Beschow     [FSL_IMX8MP_CSU] = { 0x303e0000, 64 * KiB, "csu" },
153a4eefc69SBernhard Beschow     [FSL_IMX8MP_RDC] = { 0x303d0000, 64 * KiB, "rdc" },
154a4eefc69SBernhard Beschow     [FSL_IMX8MP_SEMAPHORE2] = { 0x303c0000, 64 * KiB, "semaphore2" },
155a4eefc69SBernhard Beschow     [FSL_IMX8MP_SEMAPHORE1] = { 0x303b0000, 64 * KiB, "semaphore1" },
156a4eefc69SBernhard Beschow     [FSL_IMX8MP_GPC] = { 0x303a0000, 64 * KiB, "gpc" },
157a4eefc69SBernhard Beschow     [FSL_IMX8MP_SRC] = { 0x30390000, 64 * KiB, "src" },
158a4eefc69SBernhard Beschow     [FSL_IMX8MP_CCM] = { 0x30380000, 64 * KiB, "ccm" },
159a4eefc69SBernhard Beschow     [FSL_IMX8MP_SNVS_HP] = { 0x30370000, 64 * KiB, "snvs_hp" },
160a4eefc69SBernhard Beschow     [FSL_IMX8MP_ANA_PLL] = { 0x30360000, 64 * KiB, "ana_pll" },
161a4eefc69SBernhard Beschow     [FSL_IMX8MP_OCOTP_CTRL] = { 0x30350000, 64 * KiB, "ocotp_ctrl" },
162a4eefc69SBernhard Beschow     [FSL_IMX8MP_IOMUXC_GPR] = { 0x30340000, 64 * KiB, "iomuxc_gpr" },
163a4eefc69SBernhard Beschow     [FSL_IMX8MP_IOMUXC] = { 0x30330000, 64 * KiB, "iomuxc" },
164a4eefc69SBernhard Beschow     [FSL_IMX8MP_GPT3] = { 0x302f0000, 64 * KiB, "gpt3" },
165a4eefc69SBernhard Beschow     [FSL_IMX8MP_GPT2] = { 0x302e0000, 64 * KiB, "gpt2" },
166a4eefc69SBernhard Beschow     [FSL_IMX8MP_GPT1] = { 0x302d0000, 64 * KiB, "gpt1" },
167a4eefc69SBernhard Beschow     [FSL_IMX8MP_WDOG3] = { 0x302a0000, 64 * KiB, "wdog3" },
168a4eefc69SBernhard Beschow     [FSL_IMX8MP_WDOG2] = { 0x30290000, 64 * KiB, "wdog2" },
169a4eefc69SBernhard Beschow     [FSL_IMX8MP_WDOG1] = { 0x30280000, 64 * KiB, "wdog1" },
170a4eefc69SBernhard Beschow     [FSL_IMX8MP_ANA_OSC] = { 0x30270000, 64 * KiB, "ana_osc" },
171a4eefc69SBernhard Beschow     [FSL_IMX8MP_ANA_TSENSOR] = { 0x30260000, 64 * KiB, "ana_tsensor" },
172a4eefc69SBernhard Beschow     [FSL_IMX8MP_GPIO5] = { 0x30240000, 64 * KiB, "gpio5" },
173a4eefc69SBernhard Beschow     [FSL_IMX8MP_GPIO4] = { 0x30230000, 64 * KiB, "gpio4" },
174a4eefc69SBernhard Beschow     [FSL_IMX8MP_GPIO3] = { 0x30220000, 64 * KiB, "gpio3" },
175a4eefc69SBernhard Beschow     [FSL_IMX8MP_GPIO2] = { 0x30210000, 64 * KiB, "gpio2" },
176a4eefc69SBernhard Beschow     [FSL_IMX8MP_GPIO1] = { 0x30200000, 64 * KiB, "gpio1" },
177a4eefc69SBernhard Beschow     [FSL_IMX8MP_AIPS1_CONFIGURATION] = { 0x301f0000, 64 * KiB, "aips1_configuration" },
178a4eefc69SBernhard Beschow     /* AIPS-1 End */
179a4eefc69SBernhard Beschow 
180a4eefc69SBernhard Beschow     [FSL_IMX8MP_A53_DAP] = { 0x28000000, 16 * MiB, "a53_dap" },
181a4eefc69SBernhard Beschow     [FSL_IMX8MP_PCIE1_MEM] = { 0x18000000, 128 * MiB, "pcie1_mem" },
182a4eefc69SBernhard Beschow     [FSL_IMX8MP_QSPI_MEM] = { 0x08000000, 256 * MiB, "qspi_mem" },
183a4eefc69SBernhard Beschow     [FSL_IMX8MP_OCRAM] = { 0x00900000, 576 * KiB, "ocram" },
184a4eefc69SBernhard Beschow     [FSL_IMX8MP_TCM_DTCM] = { 0x00800000, 128 * KiB, "tcm_dtcm" },
185a4eefc69SBernhard Beschow     [FSL_IMX8MP_TCM_ITCM] = { 0x007e0000, 128 * KiB, "tcm_itcm" },
186a4eefc69SBernhard Beschow     [FSL_IMX8MP_OCRAM_S] = { 0x00180000, 36 * KiB, "ocram_s" },
187a4eefc69SBernhard Beschow     [FSL_IMX8MP_CAAM_MEM] = { 0x00100000, 32 * KiB, "caam_mem" },
188a4eefc69SBernhard Beschow     [FSL_IMX8MP_BOOT_ROM_PROTECTED] = { 0x0003f000, 4 * KiB, "boot_rom_protected" },
189a4eefc69SBernhard Beschow     [FSL_IMX8MP_BOOT_ROM] = { 0x00000000, 252 * KiB, "boot_rom" },
190a4eefc69SBernhard Beschow };
191a4eefc69SBernhard Beschow 
fsl_imx8mp_init(Object * obj)192a4eefc69SBernhard Beschow static void fsl_imx8mp_init(Object *obj)
193a4eefc69SBernhard Beschow {
194a4eefc69SBernhard Beschow     MachineState *ms = MACHINE(qdev_get_machine());
195a4eefc69SBernhard Beschow     FslImx8mpState *s = FSL_IMX8MP(obj);
196a4eefc69SBernhard Beschow     int i;
197a4eefc69SBernhard Beschow 
198a4eefc69SBernhard Beschow     for (i = 0; i < MIN(ms->smp.cpus, FSL_IMX8MP_NUM_CPUS); i++) {
199a4eefc69SBernhard Beschow         g_autofree char *name = g_strdup_printf("cpu%d", i);
200a4eefc69SBernhard Beschow         object_initialize_child(obj, name, &s->cpu[i],
201a4eefc69SBernhard Beschow                                 ARM_CPU_TYPE_NAME("cortex-a53"));
202a4eefc69SBernhard Beschow     }
203a4eefc69SBernhard Beschow 
204a4eefc69SBernhard Beschow     object_initialize_child(obj, "gic", &s->gic, TYPE_ARM_GICV3);
205a4eefc69SBernhard Beschow 
20686c2dff9SBernhard Beschow     object_initialize_child(obj, "ccm", &s->ccm, TYPE_IMX8MP_CCM);
20786c2dff9SBernhard Beschow 
20886c2dff9SBernhard Beschow     object_initialize_child(obj, "analog", &s->analog, TYPE_IMX8MP_ANALOG);
20986c2dff9SBernhard Beschow 
210487967beSBernhard Beschow     object_initialize_child(obj, "snvs", &s->snvs, TYPE_IMX7_SNVS);
211487967beSBernhard Beschow 
212a4eefc69SBernhard Beschow     for (i = 0; i < FSL_IMX8MP_NUM_UARTS; i++) {
213a4eefc69SBernhard Beschow         g_autofree char *name = g_strdup_printf("uart%d", i + 1);
214a4eefc69SBernhard Beschow         object_initialize_child(obj, name, &s->uart[i], TYPE_IMX_SERIAL);
215a4eefc69SBernhard Beschow     }
216a81193c3SBernhard Beschow 
217f8b26121SBernhard Beschow     for (i = 0; i < FSL_IMX8MP_NUM_GPTS; i++) {
218f8b26121SBernhard Beschow         g_autofree char *name = g_strdup_printf("gpt%d", i + 1);
219f8b26121SBernhard Beschow         object_initialize_child(obj, name, &s->gpt[i], TYPE_IMX8MP_GPT);
220f8b26121SBernhard Beschow     }
221f8b26121SBernhard Beschow     object_initialize_child(obj, "gpt5-gpt6-irq", &s->gpt5_gpt6_irq,
222f8b26121SBernhard Beschow                             TYPE_OR_IRQ);
223f8b26121SBernhard Beschow 
224764f18afSBernhard Beschow     for (i = 0; i < FSL_IMX8MP_NUM_I2CS; i++) {
225764f18afSBernhard Beschow         g_autofree char *name = g_strdup_printf("i2c%d", i + 1);
226764f18afSBernhard Beschow         object_initialize_child(obj, name, &s->i2c[i], TYPE_IMX_I2C);
227764f18afSBernhard Beschow     }
228764f18afSBernhard Beschow 
229a17c1d93SBernhard Beschow     for (i = 0; i < FSL_IMX8MP_NUM_GPIOS; i++) {
230a17c1d93SBernhard Beschow         g_autofree char *name = g_strdup_printf("gpio%d", i + 1);
231a17c1d93SBernhard Beschow         object_initialize_child(obj, name, &s->gpio[i], TYPE_IMX_GPIO);
232a17c1d93SBernhard Beschow     }
233a17c1d93SBernhard Beschow 
234a81193c3SBernhard Beschow     for (i = 0; i < FSL_IMX8MP_NUM_USDHCS; i++) {
235a81193c3SBernhard Beschow         g_autofree char *name = g_strdup_printf("usdhc%d", i + 1);
236a81193c3SBernhard Beschow         object_initialize_child(obj, name, &s->usdhc[i], TYPE_IMX_USDHC);
237a81193c3SBernhard Beschow     }
238fd1deb53SBernhard Beschow 
2394226c39fSBernhard Beschow     for (i = 0; i < FSL_IMX8MP_NUM_USBS; i++) {
2404226c39fSBernhard Beschow         g_autofree char *name = g_strdup_printf("usb%d", i);
2414226c39fSBernhard Beschow         object_initialize_child(obj, name, &s->usb[i], TYPE_USB_DWC3);
2424226c39fSBernhard Beschow     }
2434226c39fSBernhard Beschow 
24406908a84SBernhard Beschow     for (i = 0; i < FSL_IMX8MP_NUM_ECSPIS; i++) {
24506908a84SBernhard Beschow         g_autofree char *name = g_strdup_printf("spi%d", i + 1);
24606908a84SBernhard Beschow         object_initialize_child(obj, name, &s->spi[i], TYPE_IMX_SPI);
24706908a84SBernhard Beschow     }
24806908a84SBernhard Beschow 
2491ac21eb8SBernhard Beschow     for (i = 0; i < FSL_IMX8MP_NUM_WDTS; i++) {
2501ac21eb8SBernhard Beschow         g_autofree char *name = g_strdup_printf("wdt%d", i);
2511ac21eb8SBernhard Beschow         object_initialize_child(obj, name, &s->wdt[i], TYPE_IMX2_WDT);
2521ac21eb8SBernhard Beschow     }
2531ac21eb8SBernhard Beschow 
2540c105b26SBernhard Beschow     object_initialize_child(obj, "eth0", &s->enet, TYPE_IMX_ENET);
2550c105b26SBernhard Beschow 
256fd1deb53SBernhard Beschow     object_initialize_child(obj, "pcie", &s->pcie, TYPE_DESIGNWARE_PCIE_HOST);
257fd1deb53SBernhard Beschow     object_initialize_child(obj, "pcie_phy", &s->pcie_phy,
258fd1deb53SBernhard Beschow                             TYPE_FSL_IMX8M_PCIE_PHY);
259a4eefc69SBernhard Beschow }
260a4eefc69SBernhard Beschow 
fsl_imx8mp_realize(DeviceState * dev,Error ** errp)261a4eefc69SBernhard Beschow static void fsl_imx8mp_realize(DeviceState *dev, Error **errp)
262a4eefc69SBernhard Beschow {
263a4eefc69SBernhard Beschow     MachineState *ms = MACHINE(qdev_get_machine());
264a4eefc69SBernhard Beschow     FslImx8mpState *s = FSL_IMX8MP(dev);
265a4eefc69SBernhard Beschow     DeviceState *gicdev = DEVICE(&s->gic);
266a4eefc69SBernhard Beschow     int i;
267a4eefc69SBernhard Beschow 
268a4eefc69SBernhard Beschow     if (ms->smp.cpus > FSL_IMX8MP_NUM_CPUS) {
269a4eefc69SBernhard Beschow         error_setg(errp, "%s: Only %d CPUs are supported (%d requested)",
270a4eefc69SBernhard Beschow                    TYPE_FSL_IMX8MP, FSL_IMX8MP_NUM_CPUS, ms->smp.cpus);
271a4eefc69SBernhard Beschow         return;
272a4eefc69SBernhard Beschow     }
273a4eefc69SBernhard Beschow 
274a4eefc69SBernhard Beschow     /* CPUs */
275a4eefc69SBernhard Beschow     for (i = 0; i < ms->smp.cpus; i++) {
276a4eefc69SBernhard Beschow         /* On uniprocessor, the CBAR is set to 0 */
277a4eefc69SBernhard Beschow         if (ms->smp.cpus > 1) {
278a4eefc69SBernhard Beschow             object_property_set_int(OBJECT(&s->cpu[i]), "reset-cbar",
279a4eefc69SBernhard Beschow                                     fsl_imx8mp_memmap[FSL_IMX8MP_GIC_DIST].addr,
280a4eefc69SBernhard Beschow                                     &error_abort);
281a4eefc69SBernhard Beschow         }
282a4eefc69SBernhard Beschow 
283a4eefc69SBernhard Beschow         /*
284a4eefc69SBernhard Beschow          * CNTFID0 base frequency in Hz of system counter
285a4eefc69SBernhard Beschow          */
286a4eefc69SBernhard Beschow         object_property_set_int(OBJECT(&s->cpu[i]), "cntfrq", 8000000,
287a4eefc69SBernhard Beschow                                 &error_abort);
288a4eefc69SBernhard Beschow 
289a4eefc69SBernhard Beschow         if (i) {
290a4eefc69SBernhard Beschow             /*
291a4eefc69SBernhard Beschow              * Secondary CPUs start in powered-down state (and can be
292a4eefc69SBernhard Beschow              * powered up via the SRC system reset controller)
293a4eefc69SBernhard Beschow              */
294a4eefc69SBernhard Beschow             object_property_set_bool(OBJECT(&s->cpu[i]), "start-powered-off",
295a4eefc69SBernhard Beschow                                      true, &error_abort);
296a4eefc69SBernhard Beschow         }
297a4eefc69SBernhard Beschow 
298a4eefc69SBernhard Beschow         if (!qdev_realize(DEVICE(&s->cpu[i]), NULL, errp)) {
299a4eefc69SBernhard Beschow             return;
300a4eefc69SBernhard Beschow         }
301a4eefc69SBernhard Beschow     }
302a4eefc69SBernhard Beschow 
303a4eefc69SBernhard Beschow     /* GIC */
304a4eefc69SBernhard Beschow     {
305a4eefc69SBernhard Beschow         SysBusDevice *gicsbd = SYS_BUS_DEVICE(&s->gic);
306a4eefc69SBernhard Beschow         QList *redist_region_count;
307a4eefc69SBernhard Beschow 
308a4eefc69SBernhard Beschow         qdev_prop_set_uint32(gicdev, "num-cpu", ms->smp.cpus);
309a4eefc69SBernhard Beschow         qdev_prop_set_uint32(gicdev, "num-irq",
310a4eefc69SBernhard Beschow                              FSL_IMX8MP_NUM_IRQS + GIC_INTERNAL);
311a4eefc69SBernhard Beschow         redist_region_count = qlist_new();
312a4eefc69SBernhard Beschow         qlist_append_int(redist_region_count, ms->smp.cpus);
313a4eefc69SBernhard Beschow         qdev_prop_set_array(gicdev, "redist-region-count", redist_region_count);
314a4eefc69SBernhard Beschow         object_property_set_link(OBJECT(&s->gic), "sysmem",
315a4eefc69SBernhard Beschow                                  OBJECT(get_system_memory()), &error_fatal);
316a4eefc69SBernhard Beschow         if (!sysbus_realize(gicsbd, errp)) {
317a4eefc69SBernhard Beschow             return;
318a4eefc69SBernhard Beschow         }
319a4eefc69SBernhard Beschow         sysbus_mmio_map(gicsbd, 0, fsl_imx8mp_memmap[FSL_IMX8MP_GIC_DIST].addr);
320a4eefc69SBernhard Beschow         sysbus_mmio_map(gicsbd, 1, fsl_imx8mp_memmap[FSL_IMX8MP_GIC_REDIST].addr);
321a4eefc69SBernhard Beschow 
322a4eefc69SBernhard Beschow         /*
323a4eefc69SBernhard Beschow          * Wire the outputs from each CPU's generic timer and the GICv3
324a4eefc69SBernhard Beschow          * maintenance interrupt signal to the appropriate GIC PPI inputs, and
325a4eefc69SBernhard Beschow          * the GIC's IRQ/FIQ interrupt outputs to the CPU's inputs.
326a4eefc69SBernhard Beschow          */
327a4eefc69SBernhard Beschow         for (i = 0; i < ms->smp.cpus; i++) {
328a4eefc69SBernhard Beschow             DeviceState *cpudev = DEVICE(&s->cpu[i]);
329a4eefc69SBernhard Beschow             int intidbase = FSL_IMX8MP_NUM_IRQS + i * GIC_INTERNAL;
330a4eefc69SBernhard Beschow             qemu_irq irq;
331a4eefc69SBernhard Beschow 
332a4eefc69SBernhard Beschow             /*
333a4eefc69SBernhard Beschow              * Mapping from the output timer irq lines from the CPU to the
334a4eefc69SBernhard Beschow              * GIC PPI inputs.
335a4eefc69SBernhard Beschow              */
336a4eefc69SBernhard Beschow             static const int timer_irqs[] = {
337a4eefc69SBernhard Beschow                 [GTIMER_PHYS] = ARCH_TIMER_NS_EL1_IRQ,
338a4eefc69SBernhard Beschow                 [GTIMER_VIRT] = ARCH_TIMER_VIRT_IRQ,
339a4eefc69SBernhard Beschow                 [GTIMER_HYP]  = ARCH_TIMER_NS_EL2_IRQ,
340a4eefc69SBernhard Beschow                 [GTIMER_SEC]  = ARCH_TIMER_S_EL1_IRQ,
341a4eefc69SBernhard Beschow             };
342a4eefc69SBernhard Beschow 
343a4eefc69SBernhard Beschow             for (int j = 0; j < ARRAY_SIZE(timer_irqs); j++) {
344a4eefc69SBernhard Beschow                 irq = qdev_get_gpio_in(gicdev, intidbase + timer_irqs[j]);
345a4eefc69SBernhard Beschow                 qdev_connect_gpio_out(cpudev, j, irq);
346a4eefc69SBernhard Beschow             }
347a4eefc69SBernhard Beschow 
348a4eefc69SBernhard Beschow             irq = qdev_get_gpio_in(gicdev, intidbase + ARCH_GIC_MAINT_IRQ);
349a4eefc69SBernhard Beschow             qdev_connect_gpio_out_named(cpudev, "gicv3-maintenance-interrupt",
350a4eefc69SBernhard Beschow                                         0, irq);
351a4eefc69SBernhard Beschow 
352a4eefc69SBernhard Beschow             irq = qdev_get_gpio_in(gicdev, intidbase + VIRTUAL_PMU_IRQ);
353a4eefc69SBernhard Beschow             qdev_connect_gpio_out_named(cpudev, "pmu-interrupt", 0, irq);
354a4eefc69SBernhard Beschow 
355a4eefc69SBernhard Beschow             sysbus_connect_irq(gicsbd, i,
356a4eefc69SBernhard Beschow                                qdev_get_gpio_in(cpudev, ARM_CPU_IRQ));
357a4eefc69SBernhard Beschow             sysbus_connect_irq(gicsbd, i + ms->smp.cpus,
358a4eefc69SBernhard Beschow                                qdev_get_gpio_in(cpudev, ARM_CPU_FIQ));
359a4eefc69SBernhard Beschow         }
360a4eefc69SBernhard Beschow     }
361a4eefc69SBernhard Beschow 
36286c2dff9SBernhard Beschow     /* CCM */
36386c2dff9SBernhard Beschow     if (!sysbus_realize(SYS_BUS_DEVICE(&s->ccm), errp)) {
36486c2dff9SBernhard Beschow         return;
36586c2dff9SBernhard Beschow     }
36686c2dff9SBernhard Beschow     sysbus_mmio_map(SYS_BUS_DEVICE(&s->ccm), 0,
36786c2dff9SBernhard Beschow                     fsl_imx8mp_memmap[FSL_IMX8MP_CCM].addr);
36886c2dff9SBernhard Beschow 
36986c2dff9SBernhard Beschow     /* Analog */
37086c2dff9SBernhard Beschow     if (!sysbus_realize(SYS_BUS_DEVICE(&s->analog), errp)) {
37186c2dff9SBernhard Beschow         return;
37286c2dff9SBernhard Beschow     }
37386c2dff9SBernhard Beschow     sysbus_mmio_map(SYS_BUS_DEVICE(&s->analog), 0,
37486c2dff9SBernhard Beschow                     fsl_imx8mp_memmap[FSL_IMX8MP_ANA_PLL].addr);
37586c2dff9SBernhard Beschow 
376a4eefc69SBernhard Beschow     /* UARTs */
377a4eefc69SBernhard Beschow     for (i = 0; i < FSL_IMX8MP_NUM_UARTS; i++) {
378a4eefc69SBernhard Beschow         struct {
379a4eefc69SBernhard Beschow             hwaddr addr;
380a4eefc69SBernhard Beschow             unsigned int irq;
381a4eefc69SBernhard Beschow         } serial_table[FSL_IMX8MP_NUM_UARTS] = {
382a4eefc69SBernhard Beschow             { fsl_imx8mp_memmap[FSL_IMX8MP_UART1].addr, FSL_IMX8MP_UART1_IRQ },
383a4eefc69SBernhard Beschow             { fsl_imx8mp_memmap[FSL_IMX8MP_UART2].addr, FSL_IMX8MP_UART2_IRQ },
384a4eefc69SBernhard Beschow             { fsl_imx8mp_memmap[FSL_IMX8MP_UART3].addr, FSL_IMX8MP_UART3_IRQ },
385a4eefc69SBernhard Beschow             { fsl_imx8mp_memmap[FSL_IMX8MP_UART4].addr, FSL_IMX8MP_UART4_IRQ },
386a4eefc69SBernhard Beschow         };
387a4eefc69SBernhard Beschow 
388a4eefc69SBernhard Beschow         qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", serial_hd(i));
389a4eefc69SBernhard Beschow         if (!sysbus_realize(SYS_BUS_DEVICE(&s->uart[i]), errp)) {
390a4eefc69SBernhard Beschow             return;
391a4eefc69SBernhard Beschow         }
392a4eefc69SBernhard Beschow 
393a4eefc69SBernhard Beschow         sysbus_mmio_map(SYS_BUS_DEVICE(&s->uart[i]), 0, serial_table[i].addr);
394a4eefc69SBernhard Beschow         sysbus_connect_irq(SYS_BUS_DEVICE(&s->uart[i]), 0,
395a4eefc69SBernhard Beschow                            qdev_get_gpio_in(gicdev, serial_table[i].irq));
396a4eefc69SBernhard Beschow     }
397a4eefc69SBernhard Beschow 
398f8b26121SBernhard Beschow     /* GPTs */
399f8b26121SBernhard Beschow     object_property_set_int(OBJECT(&s->gpt5_gpt6_irq), "num-lines", 2,
400f8b26121SBernhard Beschow                             &error_abort);
401f8b26121SBernhard Beschow     if (!qdev_realize(DEVICE(&s->gpt5_gpt6_irq), NULL, errp)) {
402f8b26121SBernhard Beschow         return;
403f8b26121SBernhard Beschow     }
404f8b26121SBernhard Beschow 
405f8b26121SBernhard Beschow     qdev_connect_gpio_out(DEVICE(&s->gpt5_gpt6_irq), 0,
406f8b26121SBernhard Beschow                           qdev_get_gpio_in(gicdev, FSL_IMX8MP_GPT5_GPT6_IRQ));
407f8b26121SBernhard Beschow 
408f8b26121SBernhard Beschow     for (i = 0; i < FSL_IMX8MP_NUM_GPTS; i++) {
409f8b26121SBernhard Beschow         hwaddr gpt_addrs[FSL_IMX8MP_NUM_GPTS] = {
410f8b26121SBernhard Beschow             fsl_imx8mp_memmap[FSL_IMX8MP_GPT1].addr,
411f8b26121SBernhard Beschow             fsl_imx8mp_memmap[FSL_IMX8MP_GPT2].addr,
412f8b26121SBernhard Beschow             fsl_imx8mp_memmap[FSL_IMX8MP_GPT3].addr,
413f8b26121SBernhard Beschow             fsl_imx8mp_memmap[FSL_IMX8MP_GPT4].addr,
414f8b26121SBernhard Beschow             fsl_imx8mp_memmap[FSL_IMX8MP_GPT5].addr,
415f8b26121SBernhard Beschow             fsl_imx8mp_memmap[FSL_IMX8MP_GPT6].addr,
416f8b26121SBernhard Beschow         };
417f8b26121SBernhard Beschow 
418f8b26121SBernhard Beschow         s->gpt[i].ccm = IMX_CCM(&s->ccm);
419f8b26121SBernhard Beschow 
420f8b26121SBernhard Beschow         if (!sysbus_realize(SYS_BUS_DEVICE(&s->gpt[i]), errp)) {
421f8b26121SBernhard Beschow             return;
422f8b26121SBernhard Beschow         }
423f8b26121SBernhard Beschow 
424f8b26121SBernhard Beschow         sysbus_mmio_map(SYS_BUS_DEVICE(&s->gpt[i]), 0, gpt_addrs[i]);
425f8b26121SBernhard Beschow 
426f8b26121SBernhard Beschow         if (i < FSL_IMX8MP_NUM_GPTS - 2) {
427f8b26121SBernhard Beschow             static const unsigned int gpt_irqs[FSL_IMX8MP_NUM_GPTS - 2] = {
428f8b26121SBernhard Beschow                 FSL_IMX8MP_GPT1_IRQ,
429f8b26121SBernhard Beschow                 FSL_IMX8MP_GPT2_IRQ,
430f8b26121SBernhard Beschow                 FSL_IMX8MP_GPT3_IRQ,
431f8b26121SBernhard Beschow                 FSL_IMX8MP_GPT4_IRQ,
432f8b26121SBernhard Beschow             };
433f8b26121SBernhard Beschow 
434f8b26121SBernhard Beschow             sysbus_connect_irq(SYS_BUS_DEVICE(&s->gpt[i]), 0,
435f8b26121SBernhard Beschow                                qdev_get_gpio_in(gicdev, gpt_irqs[i]));
436f8b26121SBernhard Beschow         } else {
437f8b26121SBernhard Beschow             int irq = i - FSL_IMX8MP_NUM_GPTS + 2;
438f8b26121SBernhard Beschow 
439f8b26121SBernhard Beschow             sysbus_connect_irq(SYS_BUS_DEVICE(&s->gpt[i]), 0,
440f8b26121SBernhard Beschow                                qdev_get_gpio_in(DEVICE(&s->gpt5_gpt6_irq), irq));
441f8b26121SBernhard Beschow         }
442f8b26121SBernhard Beschow     }
443f8b26121SBernhard Beschow 
444764f18afSBernhard Beschow     /* I2Cs */
445764f18afSBernhard Beschow     for (i = 0; i < FSL_IMX8MP_NUM_I2CS; i++) {
446764f18afSBernhard Beschow         struct {
447764f18afSBernhard Beschow             hwaddr addr;
448764f18afSBernhard Beschow             unsigned int irq;
449764f18afSBernhard Beschow         } i2c_table[FSL_IMX8MP_NUM_I2CS] = {
450764f18afSBernhard Beschow             { fsl_imx8mp_memmap[FSL_IMX8MP_I2C1].addr, FSL_IMX8MP_I2C1_IRQ },
451764f18afSBernhard Beschow             { fsl_imx8mp_memmap[FSL_IMX8MP_I2C2].addr, FSL_IMX8MP_I2C2_IRQ },
452764f18afSBernhard Beschow             { fsl_imx8mp_memmap[FSL_IMX8MP_I2C3].addr, FSL_IMX8MP_I2C3_IRQ },
453764f18afSBernhard Beschow             { fsl_imx8mp_memmap[FSL_IMX8MP_I2C4].addr, FSL_IMX8MP_I2C4_IRQ },
454764f18afSBernhard Beschow             { fsl_imx8mp_memmap[FSL_IMX8MP_I2C5].addr, FSL_IMX8MP_I2C5_IRQ },
455764f18afSBernhard Beschow             { fsl_imx8mp_memmap[FSL_IMX8MP_I2C6].addr, FSL_IMX8MP_I2C6_IRQ },
456764f18afSBernhard Beschow         };
457764f18afSBernhard Beschow 
458764f18afSBernhard Beschow         if (!sysbus_realize(SYS_BUS_DEVICE(&s->i2c[i]), errp)) {
459764f18afSBernhard Beschow             return;
460764f18afSBernhard Beschow         }
461764f18afSBernhard Beschow 
462764f18afSBernhard Beschow         sysbus_mmio_map(SYS_BUS_DEVICE(&s->i2c[i]), 0, i2c_table[i].addr);
463764f18afSBernhard Beschow         sysbus_connect_irq(SYS_BUS_DEVICE(&s->i2c[i]), 0,
464764f18afSBernhard Beschow                            qdev_get_gpio_in(gicdev, i2c_table[i].irq));
465764f18afSBernhard Beschow     }
466764f18afSBernhard Beschow 
467a17c1d93SBernhard Beschow     /* GPIOs */
468a17c1d93SBernhard Beschow     for (i = 0; i < FSL_IMX8MP_NUM_GPIOS; i++) {
469a17c1d93SBernhard Beschow         struct {
470a17c1d93SBernhard Beschow             hwaddr addr;
471a17c1d93SBernhard Beschow             unsigned int irq_low;
472a17c1d93SBernhard Beschow             unsigned int irq_high;
473a17c1d93SBernhard Beschow         } gpio_table[FSL_IMX8MP_NUM_GPIOS] = {
474a17c1d93SBernhard Beschow             {
475a17c1d93SBernhard Beschow                 fsl_imx8mp_memmap[FSL_IMX8MP_GPIO1].addr,
476a17c1d93SBernhard Beschow                 FSL_IMX8MP_GPIO1_LOW_IRQ,
477a17c1d93SBernhard Beschow                 FSL_IMX8MP_GPIO1_HIGH_IRQ
478a17c1d93SBernhard Beschow             },
479a17c1d93SBernhard Beschow             {
480a17c1d93SBernhard Beschow                 fsl_imx8mp_memmap[FSL_IMX8MP_GPIO2].addr,
481a17c1d93SBernhard Beschow                 FSL_IMX8MP_GPIO2_LOW_IRQ,
482a17c1d93SBernhard Beschow                 FSL_IMX8MP_GPIO2_HIGH_IRQ
483a17c1d93SBernhard Beschow             },
484a17c1d93SBernhard Beschow             {
485a17c1d93SBernhard Beschow                 fsl_imx8mp_memmap[FSL_IMX8MP_GPIO3].addr,
486a17c1d93SBernhard Beschow                 FSL_IMX8MP_GPIO3_LOW_IRQ,
487a17c1d93SBernhard Beschow                 FSL_IMX8MP_GPIO3_HIGH_IRQ
488a17c1d93SBernhard Beschow             },
489a17c1d93SBernhard Beschow             {
490a17c1d93SBernhard Beschow                 fsl_imx8mp_memmap[FSL_IMX8MP_GPIO4].addr,
491a17c1d93SBernhard Beschow                 FSL_IMX8MP_GPIO4_LOW_IRQ,
492a17c1d93SBernhard Beschow                 FSL_IMX8MP_GPIO4_HIGH_IRQ
493a17c1d93SBernhard Beschow             },
494a17c1d93SBernhard Beschow             {
495a17c1d93SBernhard Beschow                 fsl_imx8mp_memmap[FSL_IMX8MP_GPIO5].addr,
496a17c1d93SBernhard Beschow                 FSL_IMX8MP_GPIO5_LOW_IRQ,
497a17c1d93SBernhard Beschow                 FSL_IMX8MP_GPIO5_HIGH_IRQ
498a17c1d93SBernhard Beschow             },
499a17c1d93SBernhard Beschow         };
500a17c1d93SBernhard Beschow 
501a17c1d93SBernhard Beschow         object_property_set_bool(OBJECT(&s->gpio[i]), "has-edge-sel", true,
502a17c1d93SBernhard Beschow                                  &error_abort);
503a17c1d93SBernhard Beschow         object_property_set_bool(OBJECT(&s->gpio[i]), "has-upper-pin-irq",
504a17c1d93SBernhard Beschow                                  true, &error_abort);
505a17c1d93SBernhard Beschow         if (!sysbus_realize(SYS_BUS_DEVICE(&s->gpio[i]), errp)) {
506a17c1d93SBernhard Beschow             return;
507a17c1d93SBernhard Beschow         }
508a17c1d93SBernhard Beschow 
509a17c1d93SBernhard Beschow         sysbus_mmio_map(SYS_BUS_DEVICE(&s->gpio[i]), 0, gpio_table[i].addr);
510a17c1d93SBernhard Beschow         sysbus_connect_irq(SYS_BUS_DEVICE(&s->gpio[i]), 0,
511a17c1d93SBernhard Beschow                            qdev_get_gpio_in(gicdev, gpio_table[i].irq_low));
512a17c1d93SBernhard Beschow         sysbus_connect_irq(SYS_BUS_DEVICE(&s->gpio[i]), 1,
513a17c1d93SBernhard Beschow                            qdev_get_gpio_in(gicdev, gpio_table[i].irq_high));
514a17c1d93SBernhard Beschow     }
515a17c1d93SBernhard Beschow 
516a81193c3SBernhard Beschow     /* USDHCs */
517a81193c3SBernhard Beschow     for (i = 0; i < FSL_IMX8MP_NUM_USDHCS; i++) {
518a81193c3SBernhard Beschow         struct {
519a81193c3SBernhard Beschow             hwaddr addr;
520a81193c3SBernhard Beschow             unsigned int irq;
521a81193c3SBernhard Beschow         } usdhc_table[FSL_IMX8MP_NUM_USDHCS] = {
522a81193c3SBernhard Beschow             { fsl_imx8mp_memmap[FSL_IMX8MP_USDHC1].addr, FSL_IMX8MP_USDHC1_IRQ },
523a81193c3SBernhard Beschow             { fsl_imx8mp_memmap[FSL_IMX8MP_USDHC2].addr, FSL_IMX8MP_USDHC2_IRQ },
524a81193c3SBernhard Beschow             { fsl_imx8mp_memmap[FSL_IMX8MP_USDHC3].addr, FSL_IMX8MP_USDHC3_IRQ },
525a81193c3SBernhard Beschow         };
526a81193c3SBernhard Beschow 
527a81193c3SBernhard Beschow         if (!sysbus_realize(SYS_BUS_DEVICE(&s->usdhc[i]), errp)) {
528a81193c3SBernhard Beschow             return;
529a81193c3SBernhard Beschow         }
530a81193c3SBernhard Beschow 
531a81193c3SBernhard Beschow         sysbus_mmio_map(SYS_BUS_DEVICE(&s->usdhc[i]), 0, usdhc_table[i].addr);
532a81193c3SBernhard Beschow         sysbus_connect_irq(SYS_BUS_DEVICE(&s->usdhc[i]), 0,
533a81193c3SBernhard Beschow                            qdev_get_gpio_in(gicdev, usdhc_table[i].irq));
534a81193c3SBernhard Beschow     }
535a81193c3SBernhard Beschow 
5364226c39fSBernhard Beschow     /* USBs */
5374226c39fSBernhard Beschow     for (i = 0; i < FSL_IMX8MP_NUM_USBS; i++) {
5384226c39fSBernhard Beschow         struct {
5394226c39fSBernhard Beschow             hwaddr addr;
5404226c39fSBernhard Beschow             unsigned int irq;
5414226c39fSBernhard Beschow         } usb_table[FSL_IMX8MP_NUM_USBS] = {
5424226c39fSBernhard Beschow             { fsl_imx8mp_memmap[FSL_IMX8MP_USB1].addr, FSL_IMX8MP_USB1_IRQ },
5434226c39fSBernhard Beschow             { fsl_imx8mp_memmap[FSL_IMX8MP_USB2].addr, FSL_IMX8MP_USB2_IRQ },
5444226c39fSBernhard Beschow         };
5454226c39fSBernhard Beschow 
5464226c39fSBernhard Beschow         qdev_prop_set_uint32(DEVICE(&s->usb[i].sysbus_xhci), "p2", 1);
5474226c39fSBernhard Beschow         qdev_prop_set_uint32(DEVICE(&s->usb[i].sysbus_xhci), "p3", 1);
5484226c39fSBernhard Beschow         qdev_prop_set_uint32(DEVICE(&s->usb[i].sysbus_xhci), "slots", 2);
5494226c39fSBernhard Beschow         if (!sysbus_realize(SYS_BUS_DEVICE(&s->usb[i]), errp)) {
5504226c39fSBernhard Beschow             return;
5514226c39fSBernhard Beschow         }
5524226c39fSBernhard Beschow         sysbus_mmio_map(SYS_BUS_DEVICE(&s->usb[i]), 0, usb_table[i].addr);
5534226c39fSBernhard Beschow         sysbus_connect_irq(SYS_BUS_DEVICE(&s->usb[i].sysbus_xhci), 0,
5544226c39fSBernhard Beschow                            qdev_get_gpio_in(gicdev, usb_table[i].irq));
5554226c39fSBernhard Beschow     }
5564226c39fSBernhard Beschow 
55706908a84SBernhard Beschow     /* ECSPIs */
55806908a84SBernhard Beschow     for (i = 0; i < FSL_IMX8MP_NUM_ECSPIS; i++) {
55906908a84SBernhard Beschow         struct {
56006908a84SBernhard Beschow             hwaddr addr;
56106908a84SBernhard Beschow             unsigned int irq;
56206908a84SBernhard Beschow         } spi_table[FSL_IMX8MP_NUM_ECSPIS] = {
56306908a84SBernhard Beschow             { fsl_imx8mp_memmap[FSL_IMX8MP_ECSPI1].addr, FSL_IMX8MP_ECSPI1_IRQ },
56406908a84SBernhard Beschow             { fsl_imx8mp_memmap[FSL_IMX8MP_ECSPI2].addr, FSL_IMX8MP_ECSPI2_IRQ },
56506908a84SBernhard Beschow             { fsl_imx8mp_memmap[FSL_IMX8MP_ECSPI3].addr, FSL_IMX8MP_ECSPI3_IRQ },
56606908a84SBernhard Beschow         };
56706908a84SBernhard Beschow 
56806908a84SBernhard Beschow         if (!sysbus_realize(SYS_BUS_DEVICE(&s->spi[i]), errp)) {
56906908a84SBernhard Beschow             return;
57006908a84SBernhard Beschow         }
57106908a84SBernhard Beschow 
57206908a84SBernhard Beschow         sysbus_mmio_map(SYS_BUS_DEVICE(&s->spi[i]), 0, spi_table[i].addr);
57306908a84SBernhard Beschow         sysbus_connect_irq(SYS_BUS_DEVICE(&s->spi[i]), 0,
57406908a84SBernhard Beschow                            qdev_get_gpio_in(gicdev, spi_table[i].irq));
57506908a84SBernhard Beschow     }
57606908a84SBernhard Beschow 
5770c105b26SBernhard Beschow     /* ENET1 */
5780c105b26SBernhard Beschow     object_property_set_uint(OBJECT(&s->enet), "phy-num", s->phy_num,
5790c105b26SBernhard Beschow                              &error_abort);
5800c105b26SBernhard Beschow     object_property_set_uint(OBJECT(&s->enet), "tx-ring-num", 3, &error_abort);
5810c105b26SBernhard Beschow     qemu_configure_nic_device(DEVICE(&s->enet), true, NULL);
5820c105b26SBernhard Beschow     if (!sysbus_realize(SYS_BUS_DEVICE(&s->enet), errp)) {
5830c105b26SBernhard Beschow         return;
5840c105b26SBernhard Beschow     }
5850c105b26SBernhard Beschow     sysbus_mmio_map(SYS_BUS_DEVICE(&s->enet), 0,
5860c105b26SBernhard Beschow                     fsl_imx8mp_memmap[FSL_IMX8MP_ENET1].addr);
5870c105b26SBernhard Beschow     sysbus_connect_irq(SYS_BUS_DEVICE(&s->enet), 0,
5880c105b26SBernhard Beschow                        qdev_get_gpio_in(gicdev, FSL_IMX8MP_ENET1_MAC_IRQ));
5890c105b26SBernhard Beschow     sysbus_connect_irq(SYS_BUS_DEVICE(&s->enet), 1,
5900c105b26SBernhard Beschow                        qdev_get_gpio_in(gicdev, FSL_IMX6_ENET1_MAC_1588_IRQ));
5910c105b26SBernhard Beschow 
592487967beSBernhard Beschow     /* SNVS */
593487967beSBernhard Beschow     if (!sysbus_realize(SYS_BUS_DEVICE(&s->snvs), errp)) {
594487967beSBernhard Beschow         return;
595487967beSBernhard Beschow     }
596487967beSBernhard Beschow     sysbus_mmio_map(SYS_BUS_DEVICE(&s->snvs), 0,
597487967beSBernhard Beschow                     fsl_imx8mp_memmap[FSL_IMX8MP_SNVS_HP].addr);
598487967beSBernhard Beschow 
5991ac21eb8SBernhard Beschow     /* Watchdogs */
6001ac21eb8SBernhard Beschow     for (i = 0; i < FSL_IMX8MP_NUM_WDTS; i++) {
6011ac21eb8SBernhard Beschow         struct {
6021ac21eb8SBernhard Beschow             hwaddr addr;
6031ac21eb8SBernhard Beschow             unsigned int irq;
6041ac21eb8SBernhard Beschow         } wdog_table[FSL_IMX8MP_NUM_WDTS] = {
6051ac21eb8SBernhard Beschow             { fsl_imx8mp_memmap[FSL_IMX8MP_WDOG1].addr, FSL_IMX8MP_WDOG1_IRQ },
6061ac21eb8SBernhard Beschow             { fsl_imx8mp_memmap[FSL_IMX8MP_WDOG2].addr, FSL_IMX8MP_WDOG2_IRQ },
6071ac21eb8SBernhard Beschow             { fsl_imx8mp_memmap[FSL_IMX8MP_WDOG3].addr, FSL_IMX8MP_WDOG3_IRQ },
6081ac21eb8SBernhard Beschow         };
6091ac21eb8SBernhard Beschow 
6101ac21eb8SBernhard Beschow         object_property_set_bool(OBJECT(&s->wdt[i]), "pretimeout-support",
6111ac21eb8SBernhard Beschow                                  true, &error_abort);
6121ac21eb8SBernhard Beschow         if (!sysbus_realize(SYS_BUS_DEVICE(&s->wdt[i]), errp)) {
6131ac21eb8SBernhard Beschow             return;
6141ac21eb8SBernhard Beschow         }
6151ac21eb8SBernhard Beschow 
6161ac21eb8SBernhard Beschow         sysbus_mmio_map(SYS_BUS_DEVICE(&s->wdt[i]), 0, wdog_table[i].addr);
6171ac21eb8SBernhard Beschow         sysbus_connect_irq(SYS_BUS_DEVICE(&s->wdt[i]), 0,
6181ac21eb8SBernhard Beschow                            qdev_get_gpio_in(gicdev, wdog_table[i].irq));
6191ac21eb8SBernhard Beschow     }
6201ac21eb8SBernhard Beschow 
621fd1deb53SBernhard Beschow     /* PCIe */
622fd1deb53SBernhard Beschow     if (!sysbus_realize(SYS_BUS_DEVICE(&s->pcie), errp)) {
623fd1deb53SBernhard Beschow         return;
624fd1deb53SBernhard Beschow     }
625fd1deb53SBernhard Beschow     sysbus_mmio_map(SYS_BUS_DEVICE(&s->pcie), 0,
626fd1deb53SBernhard Beschow                     fsl_imx8mp_memmap[FSL_IMX8MP_PCIE1].addr);
627fd1deb53SBernhard Beschow 
628fd1deb53SBernhard Beschow     sysbus_connect_irq(SYS_BUS_DEVICE(&s->pcie), 0,
629fd1deb53SBernhard Beschow                        qdev_get_gpio_in(gicdev, FSL_IMX8MP_PCI_INTA_IRQ));
630fd1deb53SBernhard Beschow     sysbus_connect_irq(SYS_BUS_DEVICE(&s->pcie), 1,
631fd1deb53SBernhard Beschow                        qdev_get_gpio_in(gicdev, FSL_IMX8MP_PCI_INTB_IRQ));
632fd1deb53SBernhard Beschow     sysbus_connect_irq(SYS_BUS_DEVICE(&s->pcie), 2,
633fd1deb53SBernhard Beschow                        qdev_get_gpio_in(gicdev, FSL_IMX8MP_PCI_INTC_IRQ));
634fd1deb53SBernhard Beschow     sysbus_connect_irq(SYS_BUS_DEVICE(&s->pcie), 3,
635fd1deb53SBernhard Beschow                        qdev_get_gpio_in(gicdev, FSL_IMX8MP_PCI_INTD_IRQ));
636fd1deb53SBernhard Beschow     sysbus_connect_irq(SYS_BUS_DEVICE(&s->pcie), 4,
637fd1deb53SBernhard Beschow                        qdev_get_gpio_in(gicdev, FSL_IMX8MP_PCI_MSI_IRQ));
638fd1deb53SBernhard Beschow 
639fd1deb53SBernhard Beschow     if (!sysbus_realize(SYS_BUS_DEVICE(&s->pcie_phy), errp)) {
640fd1deb53SBernhard Beschow         return;
641fd1deb53SBernhard Beschow     }
642fd1deb53SBernhard Beschow     sysbus_mmio_map(SYS_BUS_DEVICE(&s->pcie_phy), 0,
643fd1deb53SBernhard Beschow                     fsl_imx8mp_memmap[FSL_IMX8MP_PCIE_PHY1].addr);
644fd1deb53SBernhard Beschow 
6451aaf3478SBernhard Beschow     /* On-Chip RAM */
6461aaf3478SBernhard Beschow     if (!memory_region_init_ram(&s->ocram, NULL, "imx8mp.ocram",
6471aaf3478SBernhard Beschow                                 fsl_imx8mp_memmap[FSL_IMX8MP_OCRAM].size,
6481aaf3478SBernhard Beschow                                 errp)) {
6491aaf3478SBernhard Beschow         return;
6501aaf3478SBernhard Beschow     }
6511aaf3478SBernhard Beschow     memory_region_add_subregion(get_system_memory(),
6521aaf3478SBernhard Beschow                                 fsl_imx8mp_memmap[FSL_IMX8MP_OCRAM].addr,
6531aaf3478SBernhard Beschow                                 &s->ocram);
6541aaf3478SBernhard Beschow 
655a4eefc69SBernhard Beschow     /* Unimplemented devices */
656a4eefc69SBernhard Beschow     for (i = 0; i < ARRAY_SIZE(fsl_imx8mp_memmap); i++) {
657a4eefc69SBernhard Beschow         switch (i) {
65886c2dff9SBernhard Beschow         case FSL_IMX8MP_ANA_PLL:
65986c2dff9SBernhard Beschow         case FSL_IMX8MP_CCM:
660a4eefc69SBernhard Beschow         case FSL_IMX8MP_GIC_DIST:
661a4eefc69SBernhard Beschow         case FSL_IMX8MP_GIC_REDIST:
662a17c1d93SBernhard Beschow         case FSL_IMX8MP_GPIO1 ... FSL_IMX8MP_GPIO5:
66306908a84SBernhard Beschow         case FSL_IMX8MP_ECSPI1 ... FSL_IMX8MP_ECSPI3:
6640c105b26SBernhard Beschow         case FSL_IMX8MP_ENET1:
665764f18afSBernhard Beschow         case FSL_IMX8MP_I2C1 ... FSL_IMX8MP_I2C6:
6661aaf3478SBernhard Beschow         case FSL_IMX8MP_OCRAM:
667fd1deb53SBernhard Beschow         case FSL_IMX8MP_PCIE1:
668fd1deb53SBernhard Beschow         case FSL_IMX8MP_PCIE_PHY1:
669a4eefc69SBernhard Beschow         case FSL_IMX8MP_RAM:
670487967beSBernhard Beschow         case FSL_IMX8MP_SNVS_HP:
671a4eefc69SBernhard Beschow         case FSL_IMX8MP_UART1 ... FSL_IMX8MP_UART4:
6724226c39fSBernhard Beschow         case FSL_IMX8MP_USB1 ... FSL_IMX8MP_USB2:
673a81193c3SBernhard Beschow         case FSL_IMX8MP_USDHC1 ... FSL_IMX8MP_USDHC3:
6741ac21eb8SBernhard Beschow         case FSL_IMX8MP_WDOG1 ... FSL_IMX8MP_WDOG3:
675a4eefc69SBernhard Beschow             /* device implemented and treated above */
676a4eefc69SBernhard Beschow             break;
677a4eefc69SBernhard Beschow 
678a4eefc69SBernhard Beschow         default:
679a4eefc69SBernhard Beschow             create_unimplemented_device(fsl_imx8mp_memmap[i].name,
680a4eefc69SBernhard Beschow                                         fsl_imx8mp_memmap[i].addr,
681a4eefc69SBernhard Beschow                                         fsl_imx8mp_memmap[i].size);
682a4eefc69SBernhard Beschow             break;
683a4eefc69SBernhard Beschow         }
684a4eefc69SBernhard Beschow     }
685a4eefc69SBernhard Beschow }
686a4eefc69SBernhard Beschow 
6870c105b26SBernhard Beschow static const Property fsl_imx8mp_properties[] = {
6880c105b26SBernhard Beschow     DEFINE_PROP_UINT32("fec1-phy-num", FslImx8mpState, phy_num, 0),
6890c105b26SBernhard Beschow     DEFINE_PROP_BOOL("fec1-phy-connected", FslImx8mpState, phy_connected, true),
6900c105b26SBernhard Beschow };
6910c105b26SBernhard Beschow 
fsl_imx8mp_class_init(ObjectClass * oc,void * data)692a4eefc69SBernhard Beschow static void fsl_imx8mp_class_init(ObjectClass *oc, void *data)
693a4eefc69SBernhard Beschow {
694a4eefc69SBernhard Beschow     DeviceClass *dc = DEVICE_CLASS(oc);
695a4eefc69SBernhard Beschow 
6960c105b26SBernhard Beschow     device_class_set_props(dc, fsl_imx8mp_properties);
697a4eefc69SBernhard Beschow     dc->realize = fsl_imx8mp_realize;
698a4eefc69SBernhard Beschow 
699a4eefc69SBernhard Beschow     dc->desc = "i.MX 8M Plus SoC";
700a4eefc69SBernhard Beschow }
701a4eefc69SBernhard Beschow 
702a4eefc69SBernhard Beschow static const TypeInfo fsl_imx8mp_types[] = {
703a4eefc69SBernhard Beschow     {
704a4eefc69SBernhard Beschow         .name = TYPE_FSL_IMX8MP,
705*26c1c41eSBernhard Beschow         .parent = TYPE_SYS_BUS_DEVICE,
706a4eefc69SBernhard Beschow         .instance_size = sizeof(FslImx8mpState),
707a4eefc69SBernhard Beschow         .instance_init = fsl_imx8mp_init,
708a4eefc69SBernhard Beschow         .class_init = fsl_imx8mp_class_init,
709a4eefc69SBernhard Beschow     },
710a4eefc69SBernhard Beschow };
711a4eefc69SBernhard Beschow 
712a4eefc69SBernhard Beschow DEFINE_TYPES(fsl_imx8mp_types)
713