1 | target-arm queue: mostly aspeed changes from Cédric. | 1 | Hi; here's another Arm pullreq: the big thing in here is |
---|---|---|---|
2 | Bernhard's imx8mp-evk board model; there's also various cleanup | ||
3 | type patches from me, as well as some bugfixes. | ||
2 | 4 | ||
3 | thanks | 5 | thanks |
4 | -- PMM | 6 | -- PMM |
5 | 7 | ||
6 | The following changes since commit 85182c96de61f0b600bbe834d5a23e713162e892: | 8 | The following changes since commit b69801dd6b1eb4d107f7c2f643adf0a4e3ec9124: |
7 | 9 | ||
8 | Merge remote-tracking branch 'remotes/dgilbert/tags/pull-migration-20190912a' into staging (2019-09-13 14:37:48 +0100) | 10 | Merge tag 'for_upstream' of https://git.kernel.org/pub/scm/virt/kvm/mst/qemu into staging (2025-02-22 05:06:39 +0800) |
9 | 11 | ||
10 | are available in the Git repository at: | 12 | are available in the Git repository at: |
11 | 13 | ||
12 | https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20190913 | 14 | https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20250225 |
13 | 15 | ||
14 | for you to fetch changes up to 27a296fce9821e3608d537756cffa6e43a46df3b: | 16 | for you to fetch changes up to 1aaf3478684ff1cd02d1b36c32a00bfac9a5dbd5: |
15 | 17 | ||
16 | qemu-ga: Convert invocation documentation to rST (2019-09-13 16:05:01 +0100) | 18 | hw/arm/fsl-imx8mp: Add on-chip RAM (2025-02-25 17:24:00 +0000) |
17 | 19 | ||
18 | ---------------------------------------------------------------- | 20 | ---------------------------------------------------------------- |
19 | target-arm queue: | 21 | target-arm queue: |
20 | * aspeed: add a GPIO controller to the SoC | 22 | * hw/arm/smmuv3: Fill u.f_cd_fetch.addr for SMMU_EVT_F_CD_FETCH |
21 | * aspeed: Various refactorings | 23 | * hw/arm/virt: Support larger highmem MMIO regions |
22 | * aspeed: Improve DMA controller modelling | 24 | * machine: Centralize -machine dumpdtb option handling and report |
23 | * atomic_template: fix indentation in GEN_ATOMIC_HELPER | 25 | attempt to dump nonexistent DTB as an error |
24 | * qemu-ga: Convert invocation documentation to rST | 26 | * fpu: remove target ifdefs and build it only once |
27 | * target/arm: Refactor to move TCG-only vfp_helper code into tcg/ | ||
28 | * target/arm/hvf: Disable SME feature | ||
29 | * target/arm/hvf: sign extend the data for a load operation when SSE=1 | ||
30 | * hw/misc/npcm_clk: fix buffer-overflow | ||
31 | * hw/arm: Add i.MX 8M Plus EVK board ("imx8mp-evk") | ||
25 | 32 | ||
26 | ---------------------------------------------------------------- | 33 | ---------------------------------------------------------------- |
27 | Christian Svensson (1): | 34 | Bernhard Beschow (16): |
28 | aspeed/smc: Calculate checksum on normal DMA | 35 | hw/usb/hcd-dwc3: Align global registers size with Linux |
36 | hw/pci-host/designware: Prevent device attachment on internal PCIe root bus | ||
37 | hw/gpio/pca955*: Move Kconfig switches next to implementations | ||
38 | hw/arm: Add i.MX 8M Plus EVK board | ||
39 | hw/arm/fsl-imx8mp: Implement clock tree | ||
40 | hw/arm/fsl-imx8mp: Add SNVS | ||
41 | hw/arm/fsl-imx8mp: Add USDHC storage controllers | ||
42 | hw/arm/fsl-imx8mp: Add PCIe support | ||
43 | hw/arm/fsl-imx8mp: Add GPIO controllers | ||
44 | hw/arm/fsl-imx8mp: Add I2C controllers | ||
45 | hw/arm/fsl-imx8mp: Add SPI controllers | ||
46 | hw/arm/fsl-imx8mp: Add watchdog support | ||
47 | hw/arm/fsl-imx8mp: Implement general purpose timers | ||
48 | hw/arm/fsl-imx8mp: Add Ethernet controller | ||
49 | hw/arm/fsl-imx8mp: Add USB support | ||
50 | hw/arm/fsl-imx8mp: Add on-chip RAM | ||
29 | 51 | ||
30 | Cédric Le Goater (7): | 52 | Joelle van Dyne (2): |
31 | aspeed: Remove unused SoC definitions | 53 | target/arm/hvf: Disable SME feature |
32 | aspeed: Use consistent typenames | 54 | target/arm/hvf: sign extend the data for a load operation when SSE=1 |
33 | aspeed/smc: Add support for DMAs | ||
34 | aspeed/smc: Add DMA calibration settings | ||
35 | aspeed/smc: Inject errors in DMA checksum | ||
36 | aspeed/scu: Introduce per-SoC SCU types | ||
37 | aspeed/scu: Introduce a aspeed_scu_get_apb_freq() routine | ||
38 | 55 | ||
39 | Emilio G. Cota (1): | 56 | Matthew R. Ochs (1): |
40 | atomic_template: fix indentation in GEN_ATOMIC_HELPER | 57 | hw/arm/virt: Support larger highmem MMIO regions |
41 | 58 | ||
42 | Peter Maydell (1): | 59 | Nicolin Chen (1): |
43 | qemu-ga: Convert invocation documentation to rST | 60 | hw/arm/smmuv3: Fill u.f_cd_fetch.addr for SMMU_EVT_F_CD_FETCH |
44 | 61 | ||
45 | Rashmica Gupta (2): | 62 | Peter Maydell (22): |
46 | hw/gpio: Add basic Aspeed GPIO model for AST2400 and AST2500 | 63 | monitor/hmp-cmds.c: Clean up hmp_dumpdtb printf |
47 | aspeed: add a GPIO controller to the SoC | 64 | hw/openrisc: Support monitor dumpdtb command |
65 | hw/mips/boston: Check for error return from boston_fdt_filter() | ||
66 | hw/mips/boston: Support dumpdtb monitor commands | ||
67 | hw: Centralize handling of -machine dumpdtb option | ||
68 | hw/core/machine.c: Make -machine dumpdtb=file.dtb with no DTB an error | ||
69 | fpu: Make targets specify floatx80 default Inf at runtime | ||
70 | target/m68k: Avoid using floatx80_infinity global const | ||
71 | target/i386: Avoid using floatx80_infinity global const | ||
72 | fpu: Pass float_status to floatx80_is_infinity() | ||
73 | fpu: Make targets specify whether floatx80 Inf can have Int bit clear | ||
74 | fpu: Pass float_status to floatx80_invalid_encoding() | ||
75 | fpu: Make floatx80 invalid encoding settable at runtime | ||
76 | fpu: Move m68k_denormal fmt flag into floatx80_behaviour | ||
77 | fpu: Always decide no_signaling_nans() at runtime | ||
78 | fpu: Always decide snan_bit_is_one() at runtime | ||
79 | fpu: Don't compile-time disable hardfloat for PPC targets | ||
80 | fpu: Build only once | ||
81 | target/arm: Move TCG-only VFP code into tcg/ subdir | ||
82 | target/arm: Move FPSCR get/set helpers to tcg/vfp_helper.c | ||
83 | target/arm: Move softfloat specific FPCR/FPSR handling to tcg/ | ||
84 | target/arm: Rename vfp_helper.c to vfp_fpscr.c | ||
48 | 85 | ||
49 | Makefile | 24 +- | 86 | Pierrick Bouvier (1): |
50 | hw/gpio/Makefile.objs | 1 + | 87 | hw/misc/npcm_clk: fix buffer-overflow |
51 | accel/tcg/atomic_template.h | 2 +- | ||
52 | include/hw/arm/aspeed_soc.h | 4 +- | ||
53 | include/hw/gpio/aspeed_gpio.h | 100 +++++ | ||
54 | include/hw/misc/aspeed_scu.h | 21 +- | ||
55 | include/hw/ssi/aspeed_smc.h | 7 + | ||
56 | hw/arm/aspeed.c | 2 + | ||
57 | hw/arm/aspeed_soc.c | 63 ++- | ||
58 | hw/gpio/aspeed_gpio.c | 884 ++++++++++++++++++++++++++++++++++++++++++ | ||
59 | hw/misc/aspeed_scu.c | 102 ++--- | ||
60 | hw/ssi/aspeed_smc.c | 335 +++++++++++++++- | ||
61 | hw/timer/aspeed_timer.c | 3 +- | ||
62 | MAINTAINERS | 2 +- | ||
63 | docs/conf.py | 18 +- | ||
64 | docs/interop/conf.py | 7 + | ||
65 | docs/interop/index.rst | 1 + | ||
66 | docs/interop/qemu-ga.rst | 133 +++++++ | ||
67 | qemu-doc.texi | 5 - | ||
68 | qemu-ga.texi | 137 ------- | ||
69 | 20 files changed, 1585 insertions(+), 266 deletions(-) | ||
70 | create mode 100644 include/hw/gpio/aspeed_gpio.h | ||
71 | create mode 100644 hw/gpio/aspeed_gpio.c | ||
72 | create mode 100644 docs/interop/qemu-ga.rst | ||
73 | delete mode 100644 qemu-ga.texi | ||
74 | 88 | ||
89 | MAINTAINERS | 13 + | ||
90 | docs/system/arm/imx8mp-evk.rst | 70 ++++ | ||
91 | docs/system/arm/virt.rst | 4 + | ||
92 | docs/system/target-arm.rst | 1 + | ||
93 | include/fpu/softfloat-helpers.h | 12 + | ||
94 | include/fpu/softfloat-types.h | 51 +++ | ||
95 | include/fpu/softfloat.h | 91 ++--- | ||
96 | include/hw/arm/fsl-imx8mp.h | 284 ++++++++++++++ | ||
97 | include/hw/loader-fit.h | 21 +- | ||
98 | include/hw/misc/imx8mp_analog.h | 81 ++++ | ||
99 | include/hw/misc/imx8mp_ccm.h | 30 ++ | ||
100 | include/hw/openrisc/boot.h | 3 +- | ||
101 | include/hw/pci-host/designware.h | 7 + | ||
102 | include/hw/pci-host/fsl_imx8m_phy.h | 28 ++ | ||
103 | include/hw/timer/imx_gpt.h | 1 + | ||
104 | include/hw/usb/hcd-dwc3.h | 2 +- | ||
105 | include/system/device_tree.h | 2 - | ||
106 | target/arm/internals.h | 9 + | ||
107 | fpu/softfloat.c | 23 +- | ||
108 | hw/arm/boot.c | 2 - | ||
109 | hw/arm/fsl-imx8mp.c | 714 ++++++++++++++++++++++++++++++++++++ | ||
110 | hw/arm/imx8mp-evk.c | 74 ++++ | ||
111 | hw/arm/smmuv3.c | 2 +- | ||
112 | hw/arm/virt.c | 52 ++- | ||
113 | hw/core/loader-fit.c | 38 +- | ||
114 | hw/core/machine.c | 23 ++ | ||
115 | hw/loongarch/virt-fdt-build.c | 1 - | ||
116 | hw/mips/boston.c | 16 +- | ||
117 | hw/misc/imx8mp_analog.c | 160 ++++++++ | ||
118 | hw/misc/imx8mp_ccm.c | 175 +++++++++ | ||
119 | hw/misc/npcm_clk.c | 5 +- | ||
120 | hw/openrisc/boot.c | 8 +- | ||
121 | hw/openrisc/openrisc_sim.c | 2 +- | ||
122 | hw/openrisc/virt.c | 2 +- | ||
123 | hw/pci-host/designware.c | 18 +- | ||
124 | hw/pci-host/fsl_imx8m_phy.c | 98 +++++ | ||
125 | hw/ppc/e500.c | 1 - | ||
126 | hw/ppc/pegasos2.c | 1 - | ||
127 | hw/ppc/pnv.c | 1 - | ||
128 | hw/ppc/spapr.c | 1 - | ||
129 | hw/riscv/boot.c | 2 - | ||
130 | hw/timer/imx_gpt.c | 25 ++ | ||
131 | hw/usb/hcd-dwc3.c | 5 + | ||
132 | monitor/hmp-cmds.c | 2 +- | ||
133 | system/device_tree-stub.c | 5 +- | ||
134 | system/device_tree.c | 22 +- | ||
135 | target/arm/hvf/hvf.c | 16 + | ||
136 | target/arm/tcg-stubs.c | 22 ++ | ||
137 | target/arm/{ => tcg}/vfp_helper.c | 189 +--------- | ||
138 | target/arm/vfp_fpscr.c | 155 ++++++++ | ||
139 | target/hppa/fpu_helper.c | 1 + | ||
140 | target/i386/tcg/fpu_helper.c | 51 +-- | ||
141 | target/m68k/cpu.c | 35 ++ | ||
142 | target/m68k/fpu_helper.c | 2 +- | ||
143 | target/m68k/softfloat.c | 47 +-- | ||
144 | target/sh4/cpu.c | 1 + | ||
145 | fpu/softfloat-parts.c.inc | 27 +- | ||
146 | fpu/softfloat-specialize.c.inc | 29 +- | ||
147 | fpu/meson.build | 2 +- | ||
148 | hw/arm/Kconfig | 24 ++ | ||
149 | hw/arm/meson.build | 2 + | ||
150 | hw/gpio/Kconfig | 8 + | ||
151 | hw/misc/Kconfig | 14 +- | ||
152 | hw/misc/meson.build | 2 + | ||
153 | hw/pci-host/Kconfig | 3 + | ||
154 | hw/pci-host/meson.build | 1 + | ||
155 | target/arm/meson.build | 2 +- | ||
156 | target/arm/tcg/meson.build | 1 + | ||
157 | 68 files changed, 2439 insertions(+), 383 deletions(-) | ||
158 | create mode 100644 docs/system/arm/imx8mp-evk.rst | ||
159 | create mode 100644 include/hw/arm/fsl-imx8mp.h | ||
160 | create mode 100644 include/hw/misc/imx8mp_analog.h | ||
161 | create mode 100644 include/hw/misc/imx8mp_ccm.h | ||
162 | create mode 100644 include/hw/pci-host/fsl_imx8m_phy.h | ||
163 | create mode 100644 hw/arm/fsl-imx8mp.c | ||
164 | create mode 100644 hw/arm/imx8mp-evk.c | ||
165 | create mode 100644 hw/misc/imx8mp_analog.c | ||
166 | create mode 100644 hw/misc/imx8mp_ccm.c | ||
167 | create mode 100644 hw/pci-host/fsl_imx8m_phy.c | ||
168 | rename target/arm/{ => tcg}/vfp_helper.c (90%) | ||
169 | create mode 100644 target/arm/vfp_fpscr.c | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Nicolin Chen <nicolinc@nvidia.com> | ||
1 | 2 | ||
3 | When we fill in the SMMUEventInfo for SMMU_EVT_F_CD_FETCH we write | ||
4 | the address into the f_ste_fetch member of the union, but then when | ||
5 | we come to read it back in smmuv3_record_event() we will (correctly) | ||
6 | be using the f_cd_fetch member. | ||
7 | |||
8 | This is more like a cosmetics fix since the f_cd_fetch and f_ste_fetch are | ||
9 | basically the same field since they are in the exact same union with exact | ||
10 | same type, but it's conceptually wrong. Use the correct union member. | ||
11 | |||
12 | Signed-off-by: Nicolin Chen <nicolinc@nvidia.com> | ||
13 | Message-id: 20250220213832.80289-1-nicolinc@nvidia.com | ||
14 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
15 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
16 | --- | ||
17 | hw/arm/smmuv3.c | 2 +- | ||
18 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
19 | |||
20 | diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c | ||
21 | index XXXXXXX..XXXXXXX 100644 | ||
22 | --- a/hw/arm/smmuv3.c | ||
23 | +++ b/hw/arm/smmuv3.c | ||
24 | @@ -XXX,XX +XXX,XX @@ static int smmu_get_cd(SMMUv3State *s, STE *ste, SMMUTransCfg *cfg, | ||
25 | qemu_log_mask(LOG_GUEST_ERROR, | ||
26 | "Cannot fetch pte at address=0x%"PRIx64"\n", addr); | ||
27 | event->type = SMMU_EVT_F_CD_FETCH; | ||
28 | - event->u.f_ste_fetch.addr = addr; | ||
29 | + event->u.f_cd_fetch.addr = addr; | ||
30 | return -EINVAL; | ||
31 | } | ||
32 | for (i = 0; i < ARRAY_SIZE(buf->word); i++) { | ||
33 | -- | ||
34 | 2.43.0 | diff view generated by jsdifflib |
1 | From: Cédric Le Goater <clg@kaod.org> | 1 | From: "Matthew R. Ochs" <mochs@nvidia.com> |
---|---|---|---|
2 | 2 | ||
3 | The APB frequency can be calculated directly when needed from the | 3 | The MMIO region size required to support virtualized environments with |
4 | HPLL_PARAM and CLK_SEL register values. This removes useless state in | 4 | large PCI BAR regions can exceed the hardcoded limit configured in QEMU. |
5 | the model. | 5 | For example, a VM with multiple NVIDIA Grace-Hopper GPUs passed through |
6 | requires more MMIO memory than the amount provided by VIRT_HIGH_PCIE_MMIO | ||
7 | (currently 512GB). Instead of updating VIRT_HIGH_PCIE_MMIO, introduce a | ||
8 | new parameter, highmem-mmio-size, that specifies the MMIO size required | ||
9 | to support the VM configuration. | ||
6 | 10 | ||
7 | Signed-off-by: Cédric Le Goater <clg@kaod.org> | 11 | Example usage with 1TB MMIO region size: |
8 | Message-id: 20190904070506.1052-11-clg@kaod.org | 12 | -machine virt,gic-version=3,highmem-mmio-size=1T |
13 | |||
14 | Signed-off-by: Matthew R. Ochs <mochs@nvidia.com> | ||
15 | Reviewed-by: Gavin Shan <gshan@redhat.com> | ||
16 | Reviewed-by: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com> | ||
17 | Reviewed-by: Eric Auger <eric.auger@redhat.com> | ||
18 | Reviewed-by: Nicolin Chen <nicolinc@nvidia.com> | ||
19 | Message-id: 20250221145419.1281890-1-mochs@nvidia.com | ||
9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 20 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 21 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
11 | --- | 22 | --- |
12 | include/hw/misc/aspeed_scu.h | 8 +++----- | 23 | docs/system/arm/virt.rst | 4 ++++ |
13 | hw/misc/aspeed_scu.c | 25 +++++++++---------------- | 24 | hw/arm/virt.c | 52 +++++++++++++++++++++++++++++++++++++++- |
14 | hw/timer/aspeed_timer.c | 3 ++- | 25 | 2 files changed, 55 insertions(+), 1 deletion(-) |
15 | 3 files changed, 14 insertions(+), 22 deletions(-) | ||
16 | 26 | ||
17 | diff --git a/include/hw/misc/aspeed_scu.h b/include/hw/misc/aspeed_scu.h | 27 | diff --git a/docs/system/arm/virt.rst b/docs/system/arm/virt.rst |
18 | index XXXXXXX..XXXXXXX 100644 | 28 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/include/hw/misc/aspeed_scu.h | 29 | --- a/docs/system/arm/virt.rst |
20 | +++ b/include/hw/misc/aspeed_scu.h | 30 | +++ b/docs/system/arm/virt.rst |
21 | @@ -XXX,XX +XXX,XX @@ typedef struct AspeedSCUState { | 31 | @@ -XXX,XX +XXX,XX @@ highmem-mmio |
22 | uint32_t hw_strap1; | 32 | Set ``on``/``off`` to enable/disable the high memory region for PCI MMIO. |
23 | uint32_t hw_strap2; | 33 | The default is ``on``. |
24 | uint32_t hw_prot_key; | 34 | |
25 | - | 35 | +highmem-mmio-size |
26 | - uint32_t clkin; | 36 | + Set the high memory region size for PCI MMIO. Must be a power of 2 and |
27 | - uint32_t hpll; | 37 | + greater than or equal to the default size (512G). |
28 | - uint32_t apb_freq; | 38 | + |
29 | } AspeedSCUState; | 39 | gic-version |
30 | 40 | Specify the version of the Generic Interrupt Controller (GIC) to provide. | |
31 | #define AST2400_A0_SILICON_REV 0x02000303U | 41 | Valid values are: |
32 | @@ -XXX,XX +XXX,XX @@ typedef struct AspeedSCUClass { | 42 | diff --git a/hw/arm/virt.c b/hw/arm/virt.c |
33 | SysBusDeviceClass parent_class; | 43 | index XXXXXXX..XXXXXXX 100644 |
34 | 44 | --- a/hw/arm/virt.c | |
35 | const uint32_t *resets; | 45 | +++ b/hw/arm/virt.c |
36 | - uint32_t (*calc_hpll)(AspeedSCUState *s); | 46 | @@ -XXX,XX +XXX,XX @@ |
37 | + uint32_t (*calc_hpll)(AspeedSCUState *s, uint32_t hpll_reg); | 47 | #include "hw/loader.h" |
38 | uint32_t apb_divider; | 48 | #include "qapi/error.h" |
39 | } AspeedSCUClass; | 49 | #include "qemu/bitops.h" |
40 | 50 | +#include "qemu/cutils.h" | |
41 | #define ASPEED_SCU_PROT_KEY 0x1688A8A8 | 51 | #include "qemu/error-report.h" |
42 | 52 | #include "qemu/module.h" | |
43 | +uint32_t aspeed_scu_get_apb_freq(AspeedSCUState *s); | 53 | #include "hw/pci-host/gpex.h" |
54 | @@ -XXX,XX +XXX,XX @@ static const MemMapEntry base_memmap[] = { | ||
55 | [VIRT_MEM] = { GiB, LEGACY_RAMLIMIT_BYTES }, | ||
56 | }; | ||
57 | |||
58 | +/* Update the docs for highmem-mmio-size when changing this default */ | ||
59 | +#define DEFAULT_HIGH_PCIE_MMIO_SIZE_GB 512 | ||
60 | +#define DEFAULT_HIGH_PCIE_MMIO_SIZE (DEFAULT_HIGH_PCIE_MMIO_SIZE_GB * GiB) | ||
44 | + | 61 | + |
45 | /* | 62 | /* |
46 | * Extracted from Aspeed SDK v00.03.21. Fixes and extra definitions | 63 | * Highmem IO Regions: This memory map is floating, located after the RAM. |
47 | * were added. | 64 | * Each MemMapEntry base (GPA) will be dynamically computed, depending on the |
48 | diff --git a/hw/misc/aspeed_scu.c b/hw/misc/aspeed_scu.c | 65 | @@ -XXX,XX +XXX,XX @@ static const MemMapEntry base_memmap[] = { |
49 | index XXXXXXX..XXXXXXX 100644 | 66 | * PA space for one specific region is always reserved, even if the region |
50 | --- a/hw/misc/aspeed_scu.c | 67 | * has been disabled or doesn't fit into the PA space. However, the PA space |
51 | +++ b/hw/misc/aspeed_scu.c | 68 | * for the region won't be reserved in these circumstances with compact layout. |
52 | @@ -XXX,XX +XXX,XX @@ static uint32_t aspeed_scu_get_random(void) | 69 | + * |
53 | return num; | 70 | + * Note that the highmem-mmio-size property will update the high PCIE MMIO size |
71 | + * field in this array. | ||
72 | */ | ||
73 | static MemMapEntry extended_memmap[] = { | ||
74 | /* Additional 64 MB redist region (can contain up to 512 redistributors) */ | ||
75 | [VIRT_HIGH_GIC_REDIST2] = { 0x0, 64 * MiB }, | ||
76 | [VIRT_HIGH_PCIE_ECAM] = { 0x0, 256 * MiB }, | ||
77 | /* Second PCIe window */ | ||
78 | - [VIRT_HIGH_PCIE_MMIO] = { 0x0, 512 * GiB }, | ||
79 | + [VIRT_HIGH_PCIE_MMIO] = { 0x0, DEFAULT_HIGH_PCIE_MMIO_SIZE }, | ||
80 | }; | ||
81 | |||
82 | static const int a15irqmap[] = { | ||
83 | @@ -XXX,XX +XXX,XX @@ static void virt_set_highmem_mmio(Object *obj, bool value, Error **errp) | ||
84 | vms->highmem_mmio = value; | ||
54 | } | 85 | } |
55 | 86 | ||
56 | -static void aspeed_scu_set_apb_freq(AspeedSCUState *s) | 87 | +static void virt_get_highmem_mmio_size(Object *obj, Visitor *v, |
57 | +uint32_t aspeed_scu_get_apb_freq(AspeedSCUState *s) | 88 | + const char *name, void *opaque, |
89 | + Error **errp) | ||
90 | +{ | ||
91 | + uint64_t size = extended_memmap[VIRT_HIGH_PCIE_MMIO].size; | ||
92 | + | ||
93 | + visit_type_size(v, name, &size, errp); | ||
94 | +} | ||
95 | + | ||
96 | +static void virt_set_highmem_mmio_size(Object *obj, Visitor *v, | ||
97 | + const char *name, void *opaque, | ||
98 | + Error **errp) | ||
99 | +{ | ||
100 | + uint64_t size; | ||
101 | + | ||
102 | + if (!visit_type_size(v, name, &size, errp)) { | ||
103 | + return; | ||
104 | + } | ||
105 | + | ||
106 | + if (!is_power_of_2(size)) { | ||
107 | + error_setg(errp, "highmem-mmio-size is not a power of 2"); | ||
108 | + return; | ||
109 | + } | ||
110 | + | ||
111 | + if (size < DEFAULT_HIGH_PCIE_MMIO_SIZE) { | ||
112 | + char *sz = size_to_str(DEFAULT_HIGH_PCIE_MMIO_SIZE); | ||
113 | + error_setg(errp, "highmem-mmio-size cannot be set to a lower value " | ||
114 | + "than the default (%s)", sz); | ||
115 | + g_free(sz); | ||
116 | + return; | ||
117 | + } | ||
118 | + | ||
119 | + extended_memmap[VIRT_HIGH_PCIE_MMIO].size = size; | ||
120 | +} | ||
121 | |||
122 | static bool virt_get_its(Object *obj, Error **errp) | ||
58 | { | 123 | { |
59 | AspeedSCUClass *asc = ASPEED_SCU_GET_CLASS(s); | 124 | @@ -XXX,XX +XXX,XX @@ static void virt_machine_class_init(ObjectClass *oc, void *data) |
60 | + uint32_t hpll = asc->calc_hpll(s, s->regs[HPLL_PARAM]); | 125 | "Set on/off to enable/disable high " |
61 | 126 | "memory region for PCI MMIO"); | |
62 | - s->apb_freq = s->hpll / (SCU_CLK_GET_PCLK_DIV(s->regs[CLK_SEL]) + 1) | 127 | |
63 | + return hpll / (SCU_CLK_GET_PCLK_DIV(s->regs[CLK_SEL]) + 1) | 128 | + object_class_property_add(oc, "highmem-mmio-size", "size", |
64 | / asc->apb_divider; | 129 | + virt_get_highmem_mmio_size, |
65 | } | 130 | + virt_set_highmem_mmio_size, |
66 | 131 | + NULL, NULL); | |
67 | @@ -XXX,XX +XXX,XX @@ static void aspeed_scu_write(void *opaque, hwaddr offset, uint64_t data, | 132 | + object_class_property_set_description(oc, "highmem-mmio-size", |
68 | return; | 133 | + "Set the high memory region size " |
69 | case CLK_SEL: | 134 | + "for PCI MMIO"); |
70 | s->regs[reg] = data; | 135 | + |
71 | - aspeed_scu_set_apb_freq(s); | 136 | object_class_property_add_str(oc, "gic-version", virt_get_gic_version, |
72 | break; | 137 | virt_set_gic_version); |
73 | case HW_STRAP1: | 138 | object_class_property_set_description(oc, "gic-version", |
74 | if (ASPEED_IS_AST2500(s->regs[SILICON_REV])) { | ||
75 | @@ -XXX,XX +XXX,XX @@ static const uint32_t hpll_ast2400_freqs[][4] = { | ||
76 | { 400, 375, 350, 425 }, /* 25MHz */ | ||
77 | }; | ||
78 | |||
79 | -static uint32_t aspeed_2400_scu_calc_hpll(AspeedSCUState *s) | ||
80 | +static uint32_t aspeed_2400_scu_calc_hpll(AspeedSCUState *s, uint32_t hpll_reg) | ||
81 | { | ||
82 | - uint32_t hpll_reg = s->regs[HPLL_PARAM]; | ||
83 | uint8_t freq_select; | ||
84 | bool clk_25m_in; | ||
85 | + uint32_t clkin = aspeed_scu_get_clkin(s); | ||
86 | |||
87 | if (hpll_reg & SCU_AST2400_H_PLL_OFF) { | ||
88 | return 0; | ||
89 | @@ -XXX,XX +XXX,XX @@ static uint32_t aspeed_2400_scu_calc_hpll(AspeedSCUState *s) | ||
90 | multiplier = (2 - od) * ((n + 2) / (d + 1)); | ||
91 | } | ||
92 | |||
93 | - return s->clkin * multiplier; | ||
94 | + return clkin * multiplier; | ||
95 | } | ||
96 | |||
97 | /* HW strapping */ | ||
98 | @@ -XXX,XX +XXX,XX @@ static uint32_t aspeed_2400_scu_calc_hpll(AspeedSCUState *s) | ||
99 | return hpll_ast2400_freqs[clk_25m_in][freq_select] * 1000000; | ||
100 | } | ||
101 | |||
102 | -static uint32_t aspeed_2500_scu_calc_hpll(AspeedSCUState *s) | ||
103 | +static uint32_t aspeed_2500_scu_calc_hpll(AspeedSCUState *s, uint32_t hpll_reg) | ||
104 | { | ||
105 | - uint32_t hpll_reg = s->regs[HPLL_PARAM]; | ||
106 | uint32_t multiplier = 1; | ||
107 | + uint32_t clkin = aspeed_scu_get_clkin(s); | ||
108 | |||
109 | if (hpll_reg & SCU_H_PLL_OFF) { | ||
110 | return 0; | ||
111 | @@ -XXX,XX +XXX,XX @@ static uint32_t aspeed_2500_scu_calc_hpll(AspeedSCUState *s) | ||
112 | multiplier = ((m + 1) / (n + 1)) / (p + 1); | ||
113 | } | ||
114 | |||
115 | - return s->clkin * multiplier; | ||
116 | + return clkin * multiplier; | ||
117 | } | ||
118 | |||
119 | static void aspeed_scu_reset(DeviceState *dev) | ||
120 | @@ -XXX,XX +XXX,XX @@ static void aspeed_scu_reset(DeviceState *dev) | ||
121 | s->regs[HW_STRAP1] = s->hw_strap1; | ||
122 | s->regs[HW_STRAP2] = s->hw_strap2; | ||
123 | s->regs[PROT_KEY] = s->hw_prot_key; | ||
124 | - | ||
125 | - /* | ||
126 | - * All registers are set. Now compute the frequencies of the main clocks | ||
127 | - */ | ||
128 | - s->clkin = aspeed_scu_get_clkin(s); | ||
129 | - s->hpll = asc->calc_hpll(s); | ||
130 | - aspeed_scu_set_apb_freq(s); | ||
131 | } | ||
132 | |||
133 | static uint32_t aspeed_silicon_revs[] = { | ||
134 | diff --git a/hw/timer/aspeed_timer.c b/hw/timer/aspeed_timer.c | ||
135 | index XXXXXXX..XXXXXXX 100644 | ||
136 | --- a/hw/timer/aspeed_timer.c | ||
137 | +++ b/hw/timer/aspeed_timer.c | ||
138 | @@ -XXX,XX +XXX,XX @@ static inline uint32_t calculate_rate(struct AspeedTimer *t) | ||
139 | { | ||
140 | AspeedTimerCtrlState *s = timer_to_ctrl(t); | ||
141 | |||
142 | - return timer_external_clock(t) ? TIMER_CLOCK_EXT_HZ : s->scu->apb_freq; | ||
143 | + return timer_external_clock(t) ? TIMER_CLOCK_EXT_HZ : | ||
144 | + aspeed_scu_get_apb_freq(s->scu); | ||
145 | } | ||
146 | |||
147 | static inline uint32_t calculate_ticks(struct AspeedTimer *t, uint64_t now_ns) | ||
148 | -- | 139 | -- |
149 | 2.20.1 | 140 | 2.43.0 |
150 | |||
151 | diff view generated by jsdifflib |
1 | From: "Emilio G. Cota" <cota@braap.org> | 1 | In hmp_dumpdtb(), we print a message when the command succeeds. This |
---|---|---|---|
2 | message is missing the trailing \n, so the HMP command prompt is | ||
3 | printed immediately after it. We also weren't capitalizing 'DTB', or | ||
4 | quoting the filename in the message. Fix these nits. | ||
2 | 5 | ||
3 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
4 | Signed-off-by: Emilio G. Cota <cota@braap.org> | ||
5 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 7 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
6 | Signed-off-by: Alex Bennée <alex.bennee@linaro.org> | 8 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Message-id: 20250206151214.2947842-2-peter.maydell@linaro.org |
8 | --- | 10 | --- |
9 | accel/tcg/atomic_template.h | 2 +- | 11 | monitor/hmp-cmds.c | 2 +- |
10 | 1 file changed, 1 insertion(+), 1 deletion(-) | 12 | 1 file changed, 1 insertion(+), 1 deletion(-) |
11 | 13 | ||
12 | diff --git a/accel/tcg/atomic_template.h b/accel/tcg/atomic_template.h | 14 | diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c |
13 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/accel/tcg/atomic_template.h | 16 | --- a/monitor/hmp-cmds.c |
15 | +++ b/accel/tcg/atomic_template.h | 17 | +++ b/monitor/hmp-cmds.c |
16 | @@ -XXX,XX +XXX,XX @@ ABI_TYPE ATOMIC_NAME(xchg)(CPUArchState *env, target_ulong addr, | 18 | @@ -XXX,XX +XXX,XX @@ void hmp_dumpdtb(Monitor *mon, const QDict *qdict) |
17 | 19 | return; | |
18 | #define GEN_ATOMIC_HELPER(X) \ | 20 | } |
19 | ABI_TYPE ATOMIC_NAME(X)(CPUArchState *env, target_ulong addr, \ | 21 | |
20 | - ABI_TYPE val EXTRA_ARGS) \ | 22 | - monitor_printf(mon, "dtb dumped to %s", filename); |
21 | + ABI_TYPE val EXTRA_ARGS) \ | 23 | + monitor_printf(mon, "DTB dumped to '%s'\n", filename); |
22 | { \ | 24 | } |
23 | ATOMIC_MMU_DECLS; \ | 25 | #endif |
24 | DATA_TYPE *haddr = ATOMIC_MMU_LOOKUP; \ | ||
25 | -- | 26 | -- |
26 | 2.20.1 | 27 | 2.43.0 |
27 | 28 | ||
28 | 29 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | The openrisc machines don't set MachineState::fdt to point to their | ||
2 | DTB blob. This means that although the command line '-machine | ||
3 | dumpdtb=file.dtb' option works, the equivalent QMP and HMP monitor | ||
4 | commands do not, but instead produce the error "This machine doesn't | ||
5 | have a FDT". | ||
1 | 6 | ||
7 | Set MachineState::fdt in openrisc_load_fdt(), when we write it to | ||
8 | guest memory. | ||
9 | |||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
11 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
12 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
13 | Message-id: 20250206151214.2947842-3-peter.maydell@linaro.org | ||
14 | --- | ||
15 | include/hw/openrisc/boot.h | 3 ++- | ||
16 | hw/openrisc/boot.c | 7 +++++-- | ||
17 | hw/openrisc/openrisc_sim.c | 2 +- | ||
18 | hw/openrisc/virt.c | 2 +- | ||
19 | 4 files changed, 9 insertions(+), 5 deletions(-) | ||
20 | |||
21 | diff --git a/include/hw/openrisc/boot.h b/include/hw/openrisc/boot.h | ||
22 | index XXXXXXX..XXXXXXX 100644 | ||
23 | --- a/include/hw/openrisc/boot.h | ||
24 | +++ b/include/hw/openrisc/boot.h | ||
25 | @@ -XXX,XX +XXX,XX @@ | ||
26 | #define OPENRISC_BOOT_H | ||
27 | |||
28 | #include "exec/cpu-defs.h" | ||
29 | +#include "hw/boards.h" | ||
30 | |||
31 | hwaddr openrisc_load_kernel(ram_addr_t ram_size, | ||
32 | const char *kernel_filename, | ||
33 | @@ -XXX,XX +XXX,XX @@ hwaddr openrisc_load_kernel(ram_addr_t ram_size, | ||
34 | hwaddr openrisc_load_initrd(void *fdt, const char *filename, | ||
35 | hwaddr load_start, uint64_t mem_size); | ||
36 | |||
37 | -uint32_t openrisc_load_fdt(void *fdt, hwaddr load_start, | ||
38 | +uint32_t openrisc_load_fdt(MachineState *ms, void *fdt, hwaddr load_start, | ||
39 | uint64_t mem_size); | ||
40 | |||
41 | #endif /* OPENRISC_BOOT_H */ | ||
42 | diff --git a/hw/openrisc/boot.c b/hw/openrisc/boot.c | ||
43 | index XXXXXXX..XXXXXXX 100644 | ||
44 | --- a/hw/openrisc/boot.c | ||
45 | +++ b/hw/openrisc/boot.c | ||
46 | @@ -XXX,XX +XXX,XX @@ hwaddr openrisc_load_initrd(void *fdt, const char *filename, | ||
47 | return start + size; | ||
48 | } | ||
49 | |||
50 | -uint32_t openrisc_load_fdt(void *fdt, hwaddr load_start, | ||
51 | - uint64_t mem_size) | ||
52 | +uint32_t openrisc_load_fdt(MachineState *ms, void *fdt, | ||
53 | + hwaddr load_start, uint64_t mem_size) | ||
54 | { | ||
55 | uint32_t fdt_addr; | ||
56 | int ret; | ||
57 | @@ -XXX,XX +XXX,XX @@ uint32_t openrisc_load_fdt(void *fdt, hwaddr load_start, | ||
58 | /* copy in the device tree */ | ||
59 | qemu_fdt_dumpdtb(fdt, fdtsize); | ||
60 | |||
61 | + /* Save FDT for dumpdtb monitor command */ | ||
62 | + ms->fdt = fdt; | ||
63 | + | ||
64 | rom_add_blob_fixed_as("fdt", fdt, fdtsize, fdt_addr, | ||
65 | &address_space_memory); | ||
66 | qemu_register_reset_nosnapshotload(qemu_fdt_randomize_seeds, | ||
67 | diff --git a/hw/openrisc/openrisc_sim.c b/hw/openrisc/openrisc_sim.c | ||
68 | index XXXXXXX..XXXXXXX 100644 | ||
69 | --- a/hw/openrisc/openrisc_sim.c | ||
70 | +++ b/hw/openrisc/openrisc_sim.c | ||
71 | @@ -XXX,XX +XXX,XX @@ static void openrisc_sim_init(MachineState *machine) | ||
72 | machine->initrd_filename, | ||
73 | load_addr, machine->ram_size); | ||
74 | } | ||
75 | - boot_info.fdt_addr = openrisc_load_fdt(state->fdt, load_addr, | ||
76 | + boot_info.fdt_addr = openrisc_load_fdt(machine, state->fdt, load_addr, | ||
77 | machine->ram_size); | ||
78 | } | ||
79 | } | ||
80 | diff --git a/hw/openrisc/virt.c b/hw/openrisc/virt.c | ||
81 | index XXXXXXX..XXXXXXX 100644 | ||
82 | --- a/hw/openrisc/virt.c | ||
83 | +++ b/hw/openrisc/virt.c | ||
84 | @@ -XXX,XX +XXX,XX @@ static void openrisc_virt_init(MachineState *machine) | ||
85 | machine->initrd_filename, | ||
86 | load_addr, machine->ram_size); | ||
87 | } | ||
88 | - boot_info.fdt_addr = openrisc_load_fdt(state->fdt, load_addr, | ||
89 | + boot_info.fdt_addr = openrisc_load_fdt(machine, state->fdt, load_addr, | ||
90 | machine->ram_size); | ||
91 | } | ||
92 | } | ||
93 | -- | ||
94 | 2.43.0 | ||
95 | |||
96 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | The function boston_fdt_filter() can return NULL on errors (in which | ||
2 | case it will print an error message). When we call this from the | ||
3 | non-FIT-image codepath, we aren't checking the return value, so we | ||
4 | will plough on with a NULL pointer, and segfault in fdt_totalsize(). | ||
5 | Check for errors here. | ||
1 | 6 | ||
7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
8 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
9 | Message-id: 20250206151214.2947842-4-peter.maydell@linaro.org | ||
10 | --- | ||
11 | hw/mips/boston.c | 4 ++++ | ||
12 | 1 file changed, 4 insertions(+) | ||
13 | |||
14 | diff --git a/hw/mips/boston.c b/hw/mips/boston.c | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/hw/mips/boston.c | ||
17 | +++ b/hw/mips/boston.c | ||
18 | @@ -XXX,XX +XXX,XX @@ static void boston_mach_init(MachineState *machine) | ||
19 | |||
20 | dtb_load_data = boston_fdt_filter(s, dtb_file_data, | ||
21 | NULL, &dtb_vaddr); | ||
22 | + if (!dtb_load_data) { | ||
23 | + /* boston_fdt_filter() already printed the error for us */ | ||
24 | + exit(1); | ||
25 | + } | ||
26 | |||
27 | /* Calculate real fdt size after filter */ | ||
28 | dt_size = fdt_totalsize(dtb_load_data); | ||
29 | -- | ||
30 | 2.43.0 | ||
31 | |||
32 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | The boston machine doesn't set MachineState::fdt to the DTB blob that | |
2 | it has loaded or created, which means that the QMP/HMP dumpdtb | ||
3 | monitor commands don't work. | ||
4 | |||
5 | Setting MachineState::fdt is easy in the non-FIT codepath: we can | ||
6 | simply do so immediately before loading the DTB into guest memory. | ||
7 | The FIT codepath is a bit more awkward as currently the FIT loader | ||
8 | throws away the memory that the FDT was in after it loads it into | ||
9 | guest memory. So we add a void *pfdt argument to load_fit() for it | ||
10 | to store the FDT pointer into. | ||
11 | |||
12 | There is some readjustment required of the pointer handling in | ||
13 | loader-fit.c, so that it applies 'const' only where it should (e.g. | ||
14 | the data pointer we get back from fdt_getprop() is const, because | ||
15 | it's into the middle of the input FDT data, but the pointer that | ||
16 | fit_load_image_alloc() should not be const, because it's freshly | ||
17 | allocated memory that the caller can change if it likes). | ||
18 | |||
19 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
20 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
21 | Message-id: 20250206151214.2947842-5-peter.maydell@linaro.org | ||
22 | --- | ||
23 | include/hw/loader-fit.h | 21 ++++++++++++++++++--- | ||
24 | hw/core/loader-fit.c | 38 +++++++++++++++++++++----------------- | ||
25 | hw/mips/boston.c | 11 +++++++---- | ||
26 | 3 files changed, 46 insertions(+), 24 deletions(-) | ||
27 | |||
28 | diff --git a/include/hw/loader-fit.h b/include/hw/loader-fit.h | ||
29 | index XXXXXXX..XXXXXXX 100644 | ||
30 | --- a/include/hw/loader-fit.h | ||
31 | +++ b/include/hw/loader-fit.h | ||
32 | @@ -XXX,XX +XXX,XX @@ struct fit_loader_match { | ||
33 | struct fit_loader { | ||
34 | const struct fit_loader_match *matches; | ||
35 | hwaddr (*addr_to_phys)(void *opaque, uint64_t addr); | ||
36 | - const void *(*fdt_filter)(void *opaque, const void *fdt, | ||
37 | - const void *match_data, hwaddr *load_addr); | ||
38 | + void *(*fdt_filter)(void *opaque, const void *fdt, | ||
39 | + const void *match_data, hwaddr *load_addr); | ||
40 | const void *(*kernel_filter)(void *opaque, const void *kernel, | ||
41 | hwaddr *load_addr, hwaddr *entry_addr); | ||
42 | }; | ||
43 | |||
44 | -int load_fit(const struct fit_loader *ldr, const char *filename, void *opaque); | ||
45 | +/** | ||
46 | + * load_fit: load a FIT format image | ||
47 | + * @ldr: structure defining board specific properties and hooks | ||
48 | + * @filename: image to load | ||
49 | + * @pfdt: pointer to update with address of FDT blob | ||
50 | + * @opaque: opaque value passed back to the hook functions in @ldr | ||
51 | + * Returns: 0 on success, or a negative errno on failure | ||
52 | + * | ||
53 | + * @pfdt is used to tell the caller about the FDT blob. On return, it | ||
54 | + * has been set to point to the FDT blob, and it is now the caller's | ||
55 | + * responsibility to free that memory with g_free(). Usually the caller | ||
56 | + * will want to pass in &machine->fdt here, to record the FDT blob for | ||
57 | + * the dumpdtb option and QMP/HMP commands. | ||
58 | + */ | ||
59 | +int load_fit(const struct fit_loader *ldr, const char *filename, void **pfdt, | ||
60 | + void *opaque); | ||
61 | |||
62 | #endif /* HW_LOADER_FIT_H */ | ||
63 | diff --git a/hw/core/loader-fit.c b/hw/core/loader-fit.c | ||
64 | index XXXXXXX..XXXXXXX 100644 | ||
65 | --- a/hw/core/loader-fit.c | ||
66 | +++ b/hw/core/loader-fit.c | ||
67 | @@ -XXX,XX +XXX,XX @@ | ||
68 | |||
69 | #define FIT_LOADER_MAX_PATH (128) | ||
70 | |||
71 | -static const void *fit_load_image_alloc(const void *itb, const char *name, | ||
72 | - int *poff, size_t *psz, Error **errp) | ||
73 | +static void *fit_load_image_alloc(const void *itb, const char *name, | ||
74 | + int *poff, size_t *psz, Error **errp) | ||
75 | { | ||
76 | const void *data; | ||
77 | const char *comp; | ||
78 | @@ -XXX,XX +XXX,XX @@ static const void *fit_load_image_alloc(const void *itb, const char *name, | ||
79 | return NULL; | ||
80 | } | ||
81 | |||
82 | - data = g_realloc(uncomp_data, uncomp_len); | ||
83 | + uncomp_data = g_realloc(uncomp_data, uncomp_len); | ||
84 | if (psz) { | ||
85 | *psz = uncomp_len; | ||
86 | } | ||
87 | - return data; | ||
88 | + return uncomp_data; | ||
89 | } | ||
90 | |||
91 | error_setg(errp, "unknown compression '%s'", comp); | ||
92 | @@ -XXX,XX +XXX,XX @@ out: | ||
93 | |||
94 | static int fit_load_fdt(const struct fit_loader *ldr, const void *itb, | ||
95 | int cfg, void *opaque, const void *match_data, | ||
96 | - hwaddr kernel_end, Error **errp) | ||
97 | + hwaddr kernel_end, void **pfdt, Error **errp) | ||
98 | { | ||
99 | ERRP_GUARD(); | ||
100 | Error *err = NULL; | ||
101 | const char *name; | ||
102 | - const void *data; | ||
103 | - const void *load_data; | ||
104 | + void *data; | ||
105 | hwaddr load_addr; | ||
106 | int img_off; | ||
107 | size_t sz; | ||
108 | @@ -XXX,XX +XXX,XX @@ static int fit_load_fdt(const struct fit_loader *ldr, const void *itb, | ||
109 | return 0; | ||
110 | } | ||
111 | |||
112 | - load_data = data = fit_load_image_alloc(itb, name, &img_off, &sz, errp); | ||
113 | + data = fit_load_image_alloc(itb, name, &img_off, &sz, errp); | ||
114 | if (!data) { | ||
115 | error_prepend(errp, "unable to load FDT image from FIT: "); | ||
116 | return -EINVAL; | ||
117 | @@ -XXX,XX +XXX,XX @@ static int fit_load_fdt(const struct fit_loader *ldr, const void *itb, | ||
118 | } | ||
119 | |||
120 | if (ldr->fdt_filter) { | ||
121 | - load_data = ldr->fdt_filter(opaque, data, match_data, &load_addr); | ||
122 | + void *filtered_data; | ||
123 | + | ||
124 | + filtered_data = ldr->fdt_filter(opaque, data, match_data, &load_addr); | ||
125 | + if (filtered_data != data) { | ||
126 | + g_free(data); | ||
127 | + data = filtered_data; | ||
128 | + } | ||
129 | } | ||
130 | |||
131 | load_addr = ldr->addr_to_phys(opaque, load_addr); | ||
132 | - sz = fdt_totalsize(load_data); | ||
133 | - rom_add_blob_fixed(name, load_data, sz, load_addr); | ||
134 | + sz = fdt_totalsize(data); | ||
135 | + rom_add_blob_fixed(name, data, sz, load_addr); | ||
136 | |||
137 | - ret = 0; | ||
138 | + *pfdt = data; | ||
139 | + return 0; | ||
140 | out: | ||
141 | g_free((void *) data); | ||
142 | - if (data != load_data) { | ||
143 | - g_free((void *) load_data); | ||
144 | - } | ||
145 | return ret; | ||
146 | } | ||
147 | |||
148 | @@ -XXX,XX +XXX,XX @@ out: | ||
149 | return ret; | ||
150 | } | ||
151 | |||
152 | -int load_fit(const struct fit_loader *ldr, const char *filename, void *opaque) | ||
153 | +int load_fit(const struct fit_loader *ldr, const char *filename, | ||
154 | + void **pfdt, void *opaque) | ||
155 | { | ||
156 | Error *err = NULL; | ||
157 | const struct fit_loader_match *match; | ||
158 | @@ -XXX,XX +XXX,XX @@ int load_fit(const struct fit_loader *ldr, const char *filename, void *opaque) | ||
159 | goto out; | ||
160 | } | ||
161 | |||
162 | - ret = fit_load_fdt(ldr, itb, cfg_off, opaque, match_data, kernel_end, | ||
163 | + ret = fit_load_fdt(ldr, itb, cfg_off, opaque, match_data, kernel_end, pfdt, | ||
164 | &err); | ||
165 | if (ret) { | ||
166 | error_report_err(err); | ||
167 | diff --git a/hw/mips/boston.c b/hw/mips/boston.c | ||
168 | index XXXXXXX..XXXXXXX 100644 | ||
169 | --- a/hw/mips/boston.c | ||
170 | +++ b/hw/mips/boston.c | ||
171 | @@ -XXX,XX +XXX,XX @@ static void gen_firmware(void *p, hwaddr kernel_entry, hwaddr fdt_addr) | ||
172 | kernel_entry); | ||
173 | } | ||
174 | |||
175 | -static const void *boston_fdt_filter(void *opaque, const void *fdt_orig, | ||
176 | - const void *match_data, hwaddr *load_addr) | ||
177 | +static void *boston_fdt_filter(void *opaque, const void *fdt_orig, | ||
178 | + const void *match_data, hwaddr *load_addr) | ||
179 | { | ||
180 | BostonState *s = BOSTON(opaque); | ||
181 | MachineState *machine = s->mach; | ||
182 | @@ -XXX,XX +XXX,XX @@ static void boston_mach_init(MachineState *machine) | ||
183 | if (kernel_size > 0) { | ||
184 | int dt_size; | ||
185 | g_autofree const void *dtb_file_data = NULL; | ||
186 | - g_autofree const void *dtb_load_data = NULL; | ||
187 | + void *dtb_load_data = NULL; | ||
188 | hwaddr dtb_paddr = QEMU_ALIGN_UP(kernel_high, 64 * KiB); | ||
189 | hwaddr dtb_vaddr = cpu_mips_phys_to_kseg0(NULL, dtb_paddr); | ||
190 | |||
191 | @@ -XXX,XX +XXX,XX @@ static void boston_mach_init(MachineState *machine) | ||
192 | exit(1); | ||
193 | } | ||
194 | |||
195 | + machine->fdt = dtb_load_data; | ||
196 | + | ||
197 | /* Calculate real fdt size after filter */ | ||
198 | dt_size = fdt_totalsize(dtb_load_data); | ||
199 | rom_add_blob_fixed("dtb", dtb_load_data, dt_size, dtb_paddr); | ||
200 | @@ -XXX,XX +XXX,XX @@ static void boston_mach_init(MachineState *machine) | ||
201 | rom_ptr(dtb_paddr, dt_size)); | ||
202 | } else { | ||
203 | /* Try to load file as FIT */ | ||
204 | - fit_err = load_fit(&boston_fit_loader, machine->kernel_filename, s); | ||
205 | + fit_err = load_fit(&boston_fit_loader, machine->kernel_filename, | ||
206 | + &machine->fdt, s); | ||
207 | if (fit_err) { | ||
208 | error_report("unable to load kernel image"); | ||
209 | exit(1); | ||
210 | -- | ||
211 | 2.43.0 | ||
212 | |||
213 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | Currently we handle the 'dumpdtb' machine sub-option ad-hoc in every | |
2 | board model that has an FDT. It's up to the board code to make sure | ||
3 | it calls qemu_fdt_dumpdtb() in the right place. | ||
4 | |||
5 | This means we're inconsistent and often just ignore the user's | ||
6 | command line argument: | ||
7 | * if the board doesn't have an FDT at all | ||
8 | * if the board supports FDT, but there happens not to be one | ||
9 | present (usually because of a missing -fdt option) | ||
10 | |||
11 | This isn't very helpful because it gives the user no clue why their | ||
12 | option was ignored. | ||
13 | |||
14 | However, in order to support the QMP/HMP dumpdtb commands we require | ||
15 | now that every FDT machine stores a pointer to the FDT in | ||
16 | MachineState::fdt. This means we can handle -machine dumpdtb | ||
17 | centrally by calling the qmp_dumpdtb() function, unifying its | ||
18 | handling with the QMP/HMP commands. All the board code calls to | ||
19 | qemu_fdt_dumpdtb() can then be removed. | ||
20 | |||
21 | For this commit we retain the existing behaviour that if there | ||
22 | is no FDT we silently ignore the -machine dumpdtb option. | ||
23 | |||
24 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
25 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
26 | --- | ||
27 | include/system/device_tree.h | 2 -- | ||
28 | hw/arm/boot.c | 2 -- | ||
29 | hw/core/machine.c | 25 +++++++++++++++++++++++++ | ||
30 | hw/loongarch/virt-fdt-build.c | 1 - | ||
31 | hw/mips/boston.c | 1 - | ||
32 | hw/openrisc/boot.c | 1 - | ||
33 | hw/ppc/e500.c | 1 - | ||
34 | hw/ppc/pegasos2.c | 1 - | ||
35 | hw/ppc/pnv.c | 1 - | ||
36 | hw/ppc/spapr.c | 1 - | ||
37 | hw/riscv/boot.c | 2 -- | ||
38 | system/device_tree.c | 15 --------------- | ||
39 | 12 files changed, 25 insertions(+), 28 deletions(-) | ||
40 | |||
41 | diff --git a/include/system/device_tree.h b/include/system/device_tree.h | ||
42 | index XXXXXXX..XXXXXXX 100644 | ||
43 | --- a/include/system/device_tree.h | ||
44 | +++ b/include/system/device_tree.h | ||
45 | @@ -XXX,XX +XXX,XX @@ int qemu_fdt_add_path(void *fdt, const char *path); | ||
46 | sizeof(qdt_tmp)); \ | ||
47 | } while (0) | ||
48 | |||
49 | -void qemu_fdt_dumpdtb(void *fdt, int size); | ||
50 | - | ||
51 | /** | ||
52 | * qemu_fdt_setprop_sized_cells_from_array: | ||
53 | * @fdt: device tree blob | ||
54 | diff --git a/hw/arm/boot.c b/hw/arm/boot.c | ||
55 | index XXXXXXX..XXXXXXX 100644 | ||
56 | --- a/hw/arm/boot.c | ||
57 | +++ b/hw/arm/boot.c | ||
58 | @@ -XXX,XX +XXX,XX @@ int arm_load_dtb(hwaddr addr, const struct arm_boot_info *binfo, | ||
59 | binfo->modify_dtb(binfo, fdt); | ||
60 | } | ||
61 | |||
62 | - qemu_fdt_dumpdtb(fdt, size); | ||
63 | - | ||
64 | /* Put the DTB into the memory map as a ROM image: this will ensure | ||
65 | * the DTB is copied again upon reset, even if addr points into RAM. | ||
66 | */ | ||
67 | diff --git a/hw/core/machine.c b/hw/core/machine.c | ||
68 | index XXXXXXX..XXXXXXX 100644 | ||
69 | --- a/hw/core/machine.c | ||
70 | +++ b/hw/core/machine.c | ||
71 | @@ -XXX,XX +XXX,XX @@ | ||
72 | #include "qemu/error-report.h" | ||
73 | #include "qapi/error.h" | ||
74 | #include "qapi/qapi-visit-machine.h" | ||
75 | +#include "qapi/qapi-commands-machine.h" | ||
76 | #include "qemu/madvise.h" | ||
77 | #include "qom/object_interfaces.h" | ||
78 | #include "system/cpus.h" | ||
79 | @@ -XXX,XX +XXX,XX @@ void qemu_remove_machine_init_done_notifier(Notifier *notify) | ||
80 | notifier_remove(notify); | ||
81 | } | ||
82 | |||
83 | +static void handle_machine_dumpdtb(MachineState *ms) | ||
84 | +{ | ||
85 | + if (!ms->dumpdtb) { | ||
86 | + return; | ||
87 | + } | ||
88 | + if (!ms->fdt) { | ||
89 | + /* Silently ignore dumpdtb option if there is nothing to dump */ | ||
90 | + return; | ||
91 | + } | ||
92 | +#ifdef CONFIG_FDT | ||
93 | + qmp_dumpdtb(ms->dumpdtb, &error_fatal); | ||
94 | + exit(0); | ||
95 | +#else | ||
96 | + error_report("This machine doesn't have an FDT"); | ||
97 | + exit(1); | ||
98 | +#endif | ||
99 | +} | ||
100 | + | ||
101 | void qdev_machine_creation_done(void) | ||
102 | { | ||
103 | cpu_synchronize_all_post_init(); | ||
104 | @@ -XXX,XX +XXX,XX @@ void qdev_machine_creation_done(void) | ||
105 | phase_advance(PHASE_MACHINE_READY); | ||
106 | qdev_assert_realized_properly(); | ||
107 | |||
108 | + /* | ||
109 | + * If the user used -machine dumpdtb=file.dtb to request that we | ||
110 | + * dump the DTB to a file, do it now, and exit. | ||
111 | + */ | ||
112 | + handle_machine_dumpdtb(current_machine); | ||
113 | + | ||
114 | /* TODO: once all bus devices are qdevified, this should be done | ||
115 | * when bus is created by qdev.c */ | ||
116 | /* | ||
117 | diff --git a/hw/loongarch/virt-fdt-build.c b/hw/loongarch/virt-fdt-build.c | ||
118 | index XXXXXXX..XXXXXXX 100644 | ||
119 | --- a/hw/loongarch/virt-fdt-build.c | ||
120 | +++ b/hw/loongarch/virt-fdt-build.c | ||
121 | @@ -XXX,XX +XXX,XX @@ void virt_fdt_setup(LoongArchVirtMachineState *lvms) | ||
122 | * Put the FDT into the memory map as a ROM image: this will ensure | ||
123 | * the FDT is copied again upon reset, even if addr points into RAM. | ||
124 | */ | ||
125 | - qemu_fdt_dumpdtb(machine->fdt, lvms->fdt_size); | ||
126 | rom_add_blob_fixed_as("fdt", machine->fdt, lvms->fdt_size, FDT_BASE, | ||
127 | &address_space_memory); | ||
128 | qemu_register_reset_nosnapshotload(qemu_fdt_randomize_seeds, | ||
129 | diff --git a/hw/mips/boston.c b/hw/mips/boston.c | ||
130 | index XXXXXXX..XXXXXXX 100644 | ||
131 | --- a/hw/mips/boston.c | ||
132 | +++ b/hw/mips/boston.c | ||
133 | @@ -XXX,XX +XXX,XX @@ static void *boston_fdt_filter(void *opaque, const void *fdt_orig, | ||
134 | 1, ram_high_sz); | ||
135 | |||
136 | fdt = g_realloc(fdt, fdt_totalsize(fdt)); | ||
137 | - qemu_fdt_dumpdtb(fdt, fdt_sz); | ||
138 | |||
139 | s->fdt_base = *load_addr; | ||
140 | |||
141 | diff --git a/hw/openrisc/boot.c b/hw/openrisc/boot.c | ||
142 | index XXXXXXX..XXXXXXX 100644 | ||
143 | --- a/hw/openrisc/boot.c | ||
144 | +++ b/hw/openrisc/boot.c | ||
145 | @@ -XXX,XX +XXX,XX @@ uint32_t openrisc_load_fdt(MachineState *ms, void *fdt, | ||
146 | /* Should only fail if we've built a corrupted tree */ | ||
147 | g_assert(ret == 0); | ||
148 | /* copy in the device tree */ | ||
149 | - qemu_fdt_dumpdtb(fdt, fdtsize); | ||
150 | |||
151 | /* Save FDT for dumpdtb monitor command */ | ||
152 | ms->fdt = fdt; | ||
153 | diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c | ||
154 | index XXXXXXX..XXXXXXX 100644 | ||
155 | --- a/hw/ppc/e500.c | ||
156 | +++ b/hw/ppc/e500.c | ||
157 | @@ -XXX,XX +XXX,XX @@ static int ppce500_load_device_tree(PPCE500MachineState *pms, | ||
158 | |||
159 | done: | ||
160 | if (!dry_run) { | ||
161 | - qemu_fdt_dumpdtb(fdt, fdt_size); | ||
162 | cpu_physical_memory_write(addr, fdt, fdt_size); | ||
163 | |||
164 | /* Set machine->fdt for 'dumpdtb' QMP/HMP command */ | ||
165 | diff --git a/hw/ppc/pegasos2.c b/hw/ppc/pegasos2.c | ||
166 | index XXXXXXX..XXXXXXX 100644 | ||
167 | --- a/hw/ppc/pegasos2.c | ||
168 | +++ b/hw/ppc/pegasos2.c | ||
169 | @@ -XXX,XX +XXX,XX @@ static void pegasos2_machine_reset(MachineState *machine, ResetType type) | ||
170 | d[1] = cpu_to_be64(pm->kernel_size - (pm->kernel_entry - pm->kernel_addr)); | ||
171 | qemu_fdt_setprop(fdt, "/chosen", "qemu,boot-kernel", d, sizeof(d)); | ||
172 | |||
173 | - qemu_fdt_dumpdtb(fdt, fdt_totalsize(fdt)); | ||
174 | g_free(pm->fdt_blob); | ||
175 | pm->fdt_blob = fdt; | ||
176 | |||
177 | diff --git a/hw/ppc/pnv.c b/hw/ppc/pnv.c | ||
178 | index XXXXXXX..XXXXXXX 100644 | ||
179 | --- a/hw/ppc/pnv.c | ||
180 | +++ b/hw/ppc/pnv.c | ||
181 | @@ -XXX,XX +XXX,XX @@ static void pnv_reset(MachineState *machine, ResetType type) | ||
182 | _FDT((fdt_pack(fdt))); | ||
183 | } | ||
184 | |||
185 | - qemu_fdt_dumpdtb(fdt, fdt_totalsize(fdt)); | ||
186 | cpu_physical_memory_write(PNV_FDT_ADDR, fdt, fdt_totalsize(fdt)); | ||
187 | |||
188 | /* Update machine->fdt with latest fdt */ | ||
189 | diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c | ||
190 | index XXXXXXX..XXXXXXX 100644 | ||
191 | --- a/hw/ppc/spapr.c | ||
192 | +++ b/hw/ppc/spapr.c | ||
193 | @@ -XXX,XX +XXX,XX @@ static void spapr_machine_reset(MachineState *machine, ResetType type) | ||
194 | 0, fdt_addr, 0); | ||
195 | cpu_physical_memory_write(fdt_addr, fdt, fdt_totalsize(fdt)); | ||
196 | } | ||
197 | - qemu_fdt_dumpdtb(fdt, fdt_totalsize(fdt)); | ||
198 | |||
199 | g_free(spapr->fdt_blob); | ||
200 | spapr->fdt_size = fdt_totalsize(fdt); | ||
201 | diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c | ||
202 | index XXXXXXX..XXXXXXX 100644 | ||
203 | --- a/hw/riscv/boot.c | ||
204 | +++ b/hw/riscv/boot.c | ||
205 | @@ -XXX,XX +XXX,XX @@ void riscv_load_fdt(hwaddr fdt_addr, void *fdt) | ||
206 | uint32_t fdtsize = fdt_totalsize(fdt); | ||
207 | |||
208 | /* copy in the device tree */ | ||
209 | - qemu_fdt_dumpdtb(fdt, fdtsize); | ||
210 | - | ||
211 | rom_add_blob_fixed_as("fdt", fdt, fdtsize, fdt_addr, | ||
212 | &address_space_memory); | ||
213 | qemu_register_reset_nosnapshotload(qemu_fdt_randomize_seeds, | ||
214 | diff --git a/system/device_tree.c b/system/device_tree.c | ||
215 | index XXXXXXX..XXXXXXX 100644 | ||
216 | --- a/system/device_tree.c | ||
217 | +++ b/system/device_tree.c | ||
218 | @@ -XXX,XX +XXX,XX @@ int qemu_fdt_add_path(void *fdt, const char *path) | ||
219 | return retval; | ||
220 | } | ||
221 | |||
222 | -void qemu_fdt_dumpdtb(void *fdt, int size) | ||
223 | -{ | ||
224 | - const char *dumpdtb = current_machine->dumpdtb; | ||
225 | - | ||
226 | - if (dumpdtb) { | ||
227 | - /* Dump the dtb to a file and quit */ | ||
228 | - if (g_file_set_contents(dumpdtb, fdt, size, NULL)) { | ||
229 | - info_report("dtb dumped to %s. Exiting.", dumpdtb); | ||
230 | - exit(0); | ||
231 | - } | ||
232 | - error_report("%s: Failed dumping dtb to %s", __func__, dumpdtb); | ||
233 | - exit(1); | ||
234 | - } | ||
235 | -} | ||
236 | - | ||
237 | int qemu_fdt_setprop_sized_cells_from_array(void *fdt, | ||
238 | const char *node_path, | ||
239 | const char *property, | ||
240 | -- | ||
241 | 2.43.0 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Currently if the user requests via -machine dumpdtb=file.dtb that we | ||
2 | dump the DTB, but the machine doesn't have a DTB, we silently ignore | ||
3 | the option. This is confusing to users, and is a legacy of the old | ||
4 | board-specific implementation of the option, where if the execution | ||
5 | codepath didn't go via a call to qemu_fdt_dumpdtb() we would never | ||
6 | handle the option. | ||
1 | 7 | ||
8 | Now we handle the option in one place in machine.c, we can provide | ||
9 | the user with a useful message if they asked us to dump a DTB when | ||
10 | none exists. qmp_dumpdtb() already produces this error; remove the | ||
11 | logic in handle_machine_dumpdtb() that was there specifically to | ||
12 | avoid hitting it. | ||
13 | |||
14 | While we're here, beef up the error message a bit with a hint, and | ||
15 | make it consistent about "an FDT" rather than "a FDT". (In the | ||
16 | qmp_dumpdtb() case this needs an ERRP_GUARD to make | ||
17 | error_append_hint() work when the caller passes error_fatal.) | ||
18 | |||
19 | Note that the three places where we might report "doesn't have an | ||
20 | FDT" are hit in different situations: | ||
21 | |||
22 | (1) in handle_machine_dumpdtb(), if CONFIG_FDT is not set: this is | ||
23 | because the QEMU binary was built without libfdt at all. The | ||
24 | build system will not let you build with a machine type that | ||
25 | needs an FDT but no libfdt, so here we know both that the machine | ||
26 | doesn't use FDT and that QEMU doesn't have the support: | ||
27 | |||
28 | (2) in the device_tree-stub.c qmp_dumpdtb(): this is used when | ||
29 | we had libfdt at build time but the target architecture didn't | ||
30 | enable any machines which did "select DEVICE_TREE", so here we | ||
31 | know that the machine doesn't use FDT. | ||
32 | |||
33 | (3) in qmp_dumpdtb(), if current_machine->fdt is NULL all we know | ||
34 | is that this machine never set it. That might be because it doesn't | ||
35 | use FDT, or it might be because the user didn't pass an FDT | ||
36 | on the command line and the machine doesn't autogenerate an FDT. | ||
37 | |||
38 | Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2733 | ||
39 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
40 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
41 | Message-id: 20250206151214.2947842-7-peter.maydell@linaro.org | ||
42 | --- | ||
43 | hw/core/machine.c | 6 ++---- | ||
44 | system/device_tree-stub.c | 5 ++++- | ||
45 | system/device_tree.c | 7 ++++++- | ||
46 | 3 files changed, 12 insertions(+), 6 deletions(-) | ||
47 | |||
48 | diff --git a/hw/core/machine.c b/hw/core/machine.c | ||
49 | index XXXXXXX..XXXXXXX 100644 | ||
50 | --- a/hw/core/machine.c | ||
51 | +++ b/hw/core/machine.c | ||
52 | @@ -XXX,XX +XXX,XX @@ static void handle_machine_dumpdtb(MachineState *ms) | ||
53 | if (!ms->dumpdtb) { | ||
54 | return; | ||
55 | } | ||
56 | - if (!ms->fdt) { | ||
57 | - /* Silently ignore dumpdtb option if there is nothing to dump */ | ||
58 | - return; | ||
59 | - } | ||
60 | #ifdef CONFIG_FDT | ||
61 | qmp_dumpdtb(ms->dumpdtb, &error_fatal); | ||
62 | exit(0); | ||
63 | #else | ||
64 | error_report("This machine doesn't have an FDT"); | ||
65 | + error_printf("(this machine type definitely doesn't use FDT, and " | ||
66 | + "this QEMU doesn't have FDT support compiled in)\n"); | ||
67 | exit(1); | ||
68 | #endif | ||
69 | } | ||
70 | diff --git a/system/device_tree-stub.c b/system/device_tree-stub.c | ||
71 | index XXXXXXX..XXXXXXX 100644 | ||
72 | --- a/system/device_tree-stub.c | ||
73 | +++ b/system/device_tree-stub.c | ||
74 | @@ -XXX,XX +XXX,XX @@ | ||
75 | #ifdef CONFIG_FDT | ||
76 | void qmp_dumpdtb(const char *filename, Error **errp) | ||
77 | { | ||
78 | - error_setg(errp, "This machine doesn't have a FDT"); | ||
79 | + ERRP_GUARD(); | ||
80 | + | ||
81 | + error_setg(errp, "This machine doesn't have an FDT"); | ||
82 | + error_append_hint(errp, "(this machine type definitely doesn't use FDT)\n"); | ||
83 | } | ||
84 | #endif | ||
85 | diff --git a/system/device_tree.c b/system/device_tree.c | ||
86 | index XXXXXXX..XXXXXXX 100644 | ||
87 | --- a/system/device_tree.c | ||
88 | +++ b/system/device_tree.c | ||
89 | @@ -XXX,XX +XXX,XX @@ out: | ||
90 | |||
91 | void qmp_dumpdtb(const char *filename, Error **errp) | ||
92 | { | ||
93 | + ERRP_GUARD(); | ||
94 | + | ||
95 | g_autoptr(GError) err = NULL; | ||
96 | uint32_t size; | ||
97 | |||
98 | if (!current_machine->fdt) { | ||
99 | - error_setg(errp, "This machine doesn't have a FDT"); | ||
100 | + error_setg(errp, "This machine doesn't have an FDT"); | ||
101 | + error_append_hint(errp, | ||
102 | + "(Perhaps it doesn't support FDT at all, or perhaps " | ||
103 | + "you need to provide an FDT with the -fdt option?)\n"); | ||
104 | return; | ||
105 | } | ||
106 | |||
107 | -- | ||
108 | 2.43.0 | diff view generated by jsdifflib |
1 | From: Cédric Le Goater <clg@kaod.org> | 1 | Currently we hardcode at compile time whether the floatx80 default |
---|---|---|---|
2 | Infinity value has the explicit integer bit set or not (x86 sets it; | ||
3 | m68k does not). To be able to compile softfloat once for all targets | ||
4 | we'd like to move this setting to runtime. | ||
2 | 5 | ||
3 | When doing calibration, the SPI clock rate in the CE0 Control Register | 6 | Define a new FloatX80Behaviour enum which is a set of flags that |
4 | and the read delay cycles in the Read Timing Compensation Register are | 7 | define the target's floatx80 handling. Initially we define just one |
5 | set using bit[11:4] of the DMA Control Register. | 8 | flag, for whether the default Infinity has the Integer bit set or |
9 | not, but we will expand this in future commits to cover the other | ||
10 | floatx80 target specifics that we currently make compile-time | ||
11 | settings. | ||
6 | 12 | ||
7 | Signed-off-by: Cédric Le Goater <clg@kaod.org> | 13 | Define a new function floatx80_default_inf() which returns the |
8 | Acked-by: Joel Stanley <joel@jms.id.au> | 14 | appropriate default Infinity value of the given sign, and use it in |
9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 15 | the code that was previously directly using the compile-time constant |
10 | Message-id: 20190904070506.1052-7-clg@kaod.org | 16 | floatx80_infinity_{low,high} values when packing an infinity into a |
17 | floatx80. | ||
18 | |||
19 | Since floatx80 is highly unlikely to be supported in any new | ||
20 | architecture, and the existing code is generally written as "default | ||
21 | to like x87, with an ifdef for m68k", we make the default value for | ||
22 | the floatx80 behaviour flags be "what x87 does". This means we only | ||
23 | need to change the m68k target to specify the behaviour flags. | ||
24 | |||
25 | (Other users of floatx80 are the Arm NWFPE emulation, which is | ||
26 | obsolete and probably not actually doing the right thing anyway, and | ||
27 | the PPC xsrqpxp insn. Making the default be "like x87" avoids our | ||
28 | needing to review and test for behaviour changes there.) | ||
29 | |||
30 | We will clean up the remaining uses of the floatx80_infinity global | ||
31 | constant in subsequent commits. | ||
32 | |||
11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 33 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
34 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
35 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
36 | Message-id: 20250224111524.1101196-2-peter.maydell@linaro.org | ||
37 | Message-id: 20250217125055.160887-2-peter.maydell@linaro.org | ||
12 | --- | 38 | --- |
13 | hw/ssi/aspeed_smc.c | 64 ++++++++++++++++++++++++++++++++++++++++++++- | 39 | include/fpu/softfloat-helpers.h | 12 ++++++++++++ |
14 | 1 file changed, 63 insertions(+), 1 deletion(-) | 40 | include/fpu/softfloat-types.h | 13 +++++++++++++ |
41 | include/fpu/softfloat.h | 1 + | ||
42 | fpu/softfloat.c | 7 +++---- | ||
43 | target/m68k/cpu.c | 6 ++++++ | ||
44 | fpu/softfloat-specialize.c.inc | 10 ++++++++++ | ||
45 | 6 files changed, 45 insertions(+), 4 deletions(-) | ||
15 | 46 | ||
16 | diff --git a/hw/ssi/aspeed_smc.c b/hw/ssi/aspeed_smc.c | 47 | diff --git a/include/fpu/softfloat-helpers.h b/include/fpu/softfloat-helpers.h |
17 | index XXXXXXX..XXXXXXX 100644 | 48 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/hw/ssi/aspeed_smc.c | 49 | --- a/include/fpu/softfloat-helpers.h |
19 | +++ b/hw/ssi/aspeed_smc.c | 50 | +++ b/include/fpu/softfloat-helpers.h |
20 | @@ -XXX,XX +XXX,XX @@ | 51 | @@ -XXX,XX +XXX,XX @@ static inline void set_floatx80_rounding_precision(FloatX80RoundPrec val, |
21 | #define CTRL_CMD_MASK 0xff | 52 | status->floatx80_rounding_precision = val; |
22 | #define CTRL_DUMMY_HIGH_SHIFT 14 | ||
23 | #define CTRL_AST2400_SPI_4BYTE (1 << 13) | ||
24 | +#define CE_CTRL_CLOCK_FREQ_SHIFT 8 | ||
25 | +#define CE_CTRL_CLOCK_FREQ_MASK 0xf | ||
26 | +#define CE_CTRL_CLOCK_FREQ(div) \ | ||
27 | + (((div) & CE_CTRL_CLOCK_FREQ_MASK) << CE_CTRL_CLOCK_FREQ_SHIFT) | ||
28 | #define CTRL_DUMMY_LOW_SHIFT 6 /* 2 bits [7:6] */ | ||
29 | #define CTRL_CE_STOP_ACTIVE (1 << 2) | ||
30 | #define CTRL_CMD_MODE_MASK 0x3 | ||
31 | @@ -XXX,XX +XXX,XX @@ | ||
32 | #define DMA_CTRL_DELAY_SHIFT 8 | ||
33 | #define DMA_CTRL_FREQ_MASK 0xf | ||
34 | #define DMA_CTRL_FREQ_SHIFT 4 | ||
35 | -#define DMA_CTRL_MODE (1 << 3) | ||
36 | +#define DMA_CTRL_CALIB (1 << 3) | ||
37 | #define DMA_CTRL_CKSUM (1 << 2) | ||
38 | #define DMA_CTRL_WRITE (1 << 1) | ||
39 | #define DMA_CTRL_ENABLE (1 << 0) | ||
40 | @@ -XXX,XX +XXX,XX @@ static uint64_t aspeed_smc_read(void *opaque, hwaddr addr, unsigned int size) | ||
41 | } | ||
42 | } | 53 | } |
43 | 54 | ||
44 | +static uint8_t aspeed_smc_hclk_divisor(uint8_t hclk_mask) | 55 | +static inline void set_floatx80_behaviour(FloatX80Behaviour b, |
56 | + float_status *status) | ||
45 | +{ | 57 | +{ |
46 | + /* HCLK/1 .. HCLK/16 */ | 58 | + status->floatx80_behaviour = b; |
47 | + const uint8_t hclk_divisors[] = { | ||
48 | + 15, 7, 14, 6, 13, 5, 12, 4, 11, 3, 10, 2, 9, 1, 8, 0 | ||
49 | + }; | ||
50 | + int i; | ||
51 | + | ||
52 | + for (i = 0; i < ARRAY_SIZE(hclk_divisors); i++) { | ||
53 | + if (hclk_mask == hclk_divisors[i]) { | ||
54 | + return i + 1; | ||
55 | + } | ||
56 | + } | ||
57 | + | ||
58 | + qemu_log_mask(LOG_GUEST_ERROR, "invalid HCLK mask %x", hclk_mask); | ||
59 | + return 0; | ||
60 | +} | 59 | +} |
61 | + | 60 | + |
62 | +/* | 61 | static inline void set_float_2nan_prop_rule(Float2NaNPropRule rule, |
63 | + * When doing calibration, the SPI clock rate in the CE0 Control | 62 | float_status *status) |
64 | + * Register and the read delay cycles in the Read Timing Compensation | 63 | { |
65 | + * Register are set using bit[11:4] of the DMA Control Register. | 64 | @@ -XXX,XX +XXX,XX @@ get_floatx80_rounding_precision(const float_status *status) |
66 | + */ | 65 | return status->floatx80_rounding_precision; |
67 | +static void aspeed_smc_dma_calibration(AspeedSMCState *s) | 66 | } |
67 | |||
68 | +static inline FloatX80Behaviour | ||
69 | +get_floatx80_behaviour(const float_status *status) | ||
68 | +{ | 70 | +{ |
69 | + uint8_t delay = | 71 | + return status->floatx80_behaviour; |
70 | + (s->regs[R_DMA_CTRL] >> DMA_CTRL_DELAY_SHIFT) & DMA_CTRL_DELAY_MASK; | ||
71 | + uint8_t hclk_mask = | ||
72 | + (s->regs[R_DMA_CTRL] >> DMA_CTRL_FREQ_SHIFT) & DMA_CTRL_FREQ_MASK; | ||
73 | + uint8_t hclk_div = aspeed_smc_hclk_divisor(hclk_mask); | ||
74 | + uint32_t hclk_shift = (hclk_div - 1) << 2; | ||
75 | + uint8_t cs; | ||
76 | + | ||
77 | + /* | ||
78 | + * The Read Timing Compensation Register values apply to all CS on | ||
79 | + * the SPI bus and only HCLK/1 - HCLK/5 can have tunable delays | ||
80 | + */ | ||
81 | + if (hclk_div && hclk_div < 6) { | ||
82 | + s->regs[s->r_timings] &= ~(0xf << hclk_shift); | ||
83 | + s->regs[s->r_timings] |= delay << hclk_shift; | ||
84 | + } | ||
85 | + | ||
86 | + /* | ||
87 | + * TODO: compute the CS from the DMA address and the segment | ||
88 | + * registers. This is not really a problem for now because the | ||
89 | + * Timing Register values apply to all CS and software uses CS0 to | ||
90 | + * do calibration. | ||
91 | + */ | ||
92 | + cs = 0; | ||
93 | + s->regs[s->r_ctrl0 + cs] &= | ||
94 | + ~(CE_CTRL_CLOCK_FREQ_MASK << CE_CTRL_CLOCK_FREQ_SHIFT); | ||
95 | + s->regs[s->r_ctrl0 + cs] |= CE_CTRL_CLOCK_FREQ(hclk_div); | ||
96 | +} | 72 | +} |
97 | + | 73 | + |
74 | static inline Float2NaNPropRule | ||
75 | get_float_2nan_prop_rule(const float_status *status) | ||
76 | { | ||
77 | diff --git a/include/fpu/softfloat-types.h b/include/fpu/softfloat-types.h | ||
78 | index XXXXXXX..XXXXXXX 100644 | ||
79 | --- a/include/fpu/softfloat-types.h | ||
80 | +++ b/include/fpu/softfloat-types.h | ||
81 | @@ -XXX,XX +XXX,XX @@ typedef enum __attribute__((__packed__)) { | ||
82 | float_ftz_before_rounding = 1, | ||
83 | } FloatFTZDetection; | ||
84 | |||
85 | +/* | ||
86 | + * floatx80 is primarily used by x86 and m68k, and there are | ||
87 | + * differences in the handling, largely related to the explicit | ||
88 | + * Integer bit which floatx80 has and the other float formats do not. | ||
89 | + * These flag values allow specification of the target's requirements | ||
90 | + * and can be ORed together to set floatx80_behaviour. | ||
91 | + */ | ||
92 | +typedef enum __attribute__((__packed__)) { | ||
93 | + /* In the default Infinity value, is the Integer bit 0 ? */ | ||
94 | + floatx80_default_inf_int_bit_is_zero = 1, | ||
95 | +} FloatX80Behaviour; | ||
96 | + | ||
98 | /* | 97 | /* |
99 | * Accumulate the result of the reads to provide a checksum that will | 98 | * Floating Point Status. Individual architectures may maintain |
100 | * be used to validate the read timing settings. | 99 | * several versions of float_status for different functions. The |
101 | @@ -XXX,XX +XXX,XX @@ static void aspeed_smc_dma_checksum(AspeedSMCState *s) | 100 | @@ -XXX,XX +XXX,XX @@ typedef struct float_status { |
102 | return; | 101 | uint16_t float_exception_flags; |
103 | } | 102 | FloatRoundMode float_rounding_mode; |
104 | 103 | FloatX80RoundPrec floatx80_rounding_precision; | |
105 | + if (s->regs[R_DMA_CTRL] & DMA_CTRL_CALIB) { | 104 | + FloatX80Behaviour floatx80_behaviour; |
106 | + aspeed_smc_dma_calibration(s); | 105 | Float2NaNPropRule float_2nan_prop_rule; |
107 | + } | 106 | Float3NaNPropRule float_3nan_prop_rule; |
107 | FloatInfZeroNaNRule float_infzeronan_rule; | ||
108 | diff --git a/include/fpu/softfloat.h b/include/fpu/softfloat.h | ||
109 | index XXXXXXX..XXXXXXX 100644 | ||
110 | --- a/include/fpu/softfloat.h | ||
111 | +++ b/include/fpu/softfloat.h | ||
112 | @@ -XXX,XX +XXX,XX @@ float128 floatx80_to_float128(floatx80, float_status *status); | ||
113 | | The pattern for an extended double-precision inf. | ||
114 | *----------------------------------------------------------------------------*/ | ||
115 | extern const floatx80 floatx80_infinity; | ||
116 | +floatx80 floatx80_default_inf(bool zSign, float_status *status); | ||
117 | |||
118 | /*---------------------------------------------------------------------------- | ||
119 | | Software IEC/IEEE extended double-precision operations. | ||
120 | diff --git a/fpu/softfloat.c b/fpu/softfloat.c | ||
121 | index XXXXXXX..XXXXXXX 100644 | ||
122 | --- a/fpu/softfloat.c | ||
123 | +++ b/fpu/softfloat.c | ||
124 | @@ -XXX,XX +XXX,XX @@ static floatx80 floatx80_round_pack_canonical(FloatParts128 *p, | ||
125 | |||
126 | case float_class_inf: | ||
127 | /* x86 and m68k differ in the setting of the integer bit. */ | ||
128 | - frac = floatx80_infinity_low; | ||
129 | + frac = s->floatx80_behaviour & floatx80_default_inf_int_bit_is_zero ? | ||
130 | + 0 : (1ULL << 63); | ||
131 | exp = fmt->exp_max; | ||
132 | break; | ||
133 | |||
134 | @@ -XXX,XX +XXX,XX @@ floatx80 roundAndPackFloatx80(FloatX80RoundPrec roundingPrecision, bool zSign, | ||
135 | ) { | ||
136 | return packFloatx80( zSign, 0x7FFE, ~ roundMask ); | ||
137 | } | ||
138 | - return packFloatx80(zSign, | ||
139 | - floatx80_infinity_high, | ||
140 | - floatx80_infinity_low); | ||
141 | + return floatx80_default_inf(zSign, status); | ||
142 | } | ||
143 | if ( zExp <= 0 ) { | ||
144 | isTiny = status->tininess_before_rounding | ||
145 | diff --git a/target/m68k/cpu.c b/target/m68k/cpu.c | ||
146 | index XXXXXXX..XXXXXXX 100644 | ||
147 | --- a/target/m68k/cpu.c | ||
148 | +++ b/target/m68k/cpu.c | ||
149 | @@ -XXX,XX +XXX,XX @@ static void m68k_cpu_reset_hold(Object *obj, ResetType type) | ||
150 | set_float_2nan_prop_rule(float_2nan_prop_ab, &env->fp_status); | ||
151 | /* Default NaN: sign bit clear, all frac bits set */ | ||
152 | set_float_default_nan_pattern(0b01111111, &env->fp_status); | ||
153 | + /* | ||
154 | + * m68k-specific floatx80 behaviour: | ||
155 | + * * default Infinity values have a zero Integer bit | ||
156 | + */ | ||
157 | + set_floatx80_behaviour(floatx80_default_inf_int_bit_is_zero, | ||
158 | + &env->fp_status); | ||
159 | |||
160 | nan = floatx80_default_nan(&env->fp_status); | ||
161 | for (i = 0; i < 8; i++) { | ||
162 | diff --git a/fpu/softfloat-specialize.c.inc b/fpu/softfloat-specialize.c.inc | ||
163 | index XXXXXXX..XXXXXXX 100644 | ||
164 | --- a/fpu/softfloat-specialize.c.inc | ||
165 | +++ b/fpu/softfloat-specialize.c.inc | ||
166 | @@ -XXX,XX +XXX,XX @@ floatx80 floatx80_default_nan(float_status *status) | ||
167 | | The pattern for a default generated extended double-precision inf. | ||
168 | *----------------------------------------------------------------------------*/ | ||
169 | |||
170 | +floatx80 floatx80_default_inf(bool zSign, float_status *status) | ||
171 | +{ | ||
172 | + /* | ||
173 | + * Whether the Integer bit is set in the default Infinity is | ||
174 | + * target dependent. | ||
175 | + */ | ||
176 | + bool z = status->floatx80_behaviour & floatx80_default_inf_int_bit_is_zero; | ||
177 | + return packFloatx80(zSign, 0x7fff, z ? 0 : (1ULL << 63)); | ||
178 | +} | ||
108 | + | 179 | + |
109 | while (s->regs[R_DMA_LEN]) { | 180 | #define floatx80_infinity_high 0x7FFF |
110 | data = address_space_ldl_le(&s->flash_as, s->regs[R_DMA_FLASH_ADDR], | 181 | #if defined(TARGET_M68K) |
111 | MEMTXATTRS_UNSPECIFIED, &result); | 182 | #define floatx80_infinity_low UINT64_C(0x0000000000000000) |
112 | -- | 183 | -- |
113 | 2.20.1 | 184 | 2.43.0 |
114 | 185 | ||
115 | 186 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | The global const floatx80_infinity is (unlike all the other | ||
2 | float*_infinity values) target-specific, because whether the explicit | ||
3 | Integer bit is set or not varies between m68k and i386. We want to | ||
4 | be able to compile softfloat once for multiple targets, so we can't | ||
5 | continue to use a single global whose value needs to be different | ||
6 | between targets. | ||
1 | 7 | ||
8 | Replace the direct uses of floatx80_infinity in target/m68k with | ||
9 | calls to the new floatx80_default_inf() function. | ||
10 | |||
11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
12 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
13 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
14 | Message-id: 20250224111524.1101196-3-peter.maydell@linaro.org | ||
15 | Message-id: 20250217125055.160887-3-peter.maydell@linaro.org | ||
16 | --- | ||
17 | target/m68k/softfloat.c | 47 ++++++++++++++--------------------------- | ||
18 | 1 file changed, 16 insertions(+), 31 deletions(-) | ||
19 | |||
20 | diff --git a/target/m68k/softfloat.c b/target/m68k/softfloat.c | ||
21 | index XXXXXXX..XXXXXXX 100644 | ||
22 | --- a/target/m68k/softfloat.c | ||
23 | +++ b/target/m68k/softfloat.c | ||
24 | @@ -XXX,XX +XXX,XX @@ floatx80 floatx80_scale(floatx80 a, floatx80 b, float_status *status) | ||
25 | if ((uint64_t) (aSig << 1)) { | ||
26 | return propagateFloatx80NaN(a, b, status); | ||
27 | } | ||
28 | - return packFloatx80(aSign, floatx80_infinity.high, | ||
29 | - floatx80_infinity.low); | ||
30 | + return floatx80_default_inf(aSign, status); | ||
31 | } | ||
32 | if (aExp == 0) { | ||
33 | if (aSig == 0) { | ||
34 | @@ -XXX,XX +XXX,XX @@ floatx80 floatx80_lognp1(floatx80 a, float_status *status) | ||
35 | float_raise(float_flag_invalid, status); | ||
36 | return floatx80_default_nan(status); | ||
37 | } | ||
38 | - return packFloatx80(0, floatx80_infinity.high, floatx80_infinity.low); | ||
39 | + return floatx80_default_inf(0, status); | ||
40 | } | ||
41 | |||
42 | if (aExp == 0 && aSig == 0) { | ||
43 | @@ -XXX,XX +XXX,XX @@ floatx80 floatx80_lognp1(floatx80 a, float_status *status) | ||
44 | if (aSign && aExp >= one_exp) { | ||
45 | if (aExp == one_exp && aSig == one_sig) { | ||
46 | float_raise(float_flag_divbyzero, status); | ||
47 | - return packFloatx80(aSign, floatx80_infinity.high, | ||
48 | - floatx80_infinity.low); | ||
49 | + return floatx80_default_inf(aSign, status); | ||
50 | } | ||
51 | float_raise(float_flag_invalid, status); | ||
52 | return floatx80_default_nan(status); | ||
53 | @@ -XXX,XX +XXX,XX @@ floatx80 floatx80_logn(floatx80 a, float_status *status) | ||
54 | propagateFloatx80NaNOneArg(a, status); | ||
55 | } | ||
56 | if (aSign == 0) { | ||
57 | - return packFloatx80(0, floatx80_infinity.high, | ||
58 | - floatx80_infinity.low); | ||
59 | + return floatx80_default_inf(0, status); | ||
60 | } | ||
61 | } | ||
62 | |||
63 | @@ -XXX,XX +XXX,XX @@ floatx80 floatx80_logn(floatx80 a, float_status *status) | ||
64 | if (aExp == 0) { | ||
65 | if (aSig == 0) { /* zero */ | ||
66 | float_raise(float_flag_divbyzero, status); | ||
67 | - return packFloatx80(1, floatx80_infinity.high, | ||
68 | - floatx80_infinity.low); | ||
69 | + return floatx80_default_inf(1, status); | ||
70 | } | ||
71 | if ((aSig & one_sig) == 0) { /* denormal */ | ||
72 | normalizeFloatx80Subnormal(aSig, &aExp, &aSig); | ||
73 | @@ -XXX,XX +XXX,XX @@ floatx80 floatx80_log10(floatx80 a, float_status *status) | ||
74 | propagateFloatx80NaNOneArg(a, status); | ||
75 | } | ||
76 | if (aSign == 0) { | ||
77 | - return packFloatx80(0, floatx80_infinity.high, | ||
78 | - floatx80_infinity.low); | ||
79 | + return floatx80_default_inf(0, status); | ||
80 | } | ||
81 | } | ||
82 | |||
83 | if (aExp == 0 && aSig == 0) { | ||
84 | float_raise(float_flag_divbyzero, status); | ||
85 | - return packFloatx80(1, floatx80_infinity.high, | ||
86 | - floatx80_infinity.low); | ||
87 | + return floatx80_default_inf(1, status); | ||
88 | } | ||
89 | |||
90 | if (aSign) { | ||
91 | @@ -XXX,XX +XXX,XX @@ floatx80 floatx80_log2(floatx80 a, float_status *status) | ||
92 | propagateFloatx80NaNOneArg(a, status); | ||
93 | } | ||
94 | if (aSign == 0) { | ||
95 | - return packFloatx80(0, floatx80_infinity.high, | ||
96 | - floatx80_infinity.low); | ||
97 | + return floatx80_default_inf(0, status); | ||
98 | } | ||
99 | } | ||
100 | |||
101 | if (aExp == 0) { | ||
102 | if (aSig == 0) { | ||
103 | float_raise(float_flag_divbyzero, status); | ||
104 | - return packFloatx80(1, floatx80_infinity.high, | ||
105 | - floatx80_infinity.low); | ||
106 | + return floatx80_default_inf(1, status); | ||
107 | } | ||
108 | normalizeFloatx80Subnormal(aSig, &aExp, &aSig); | ||
109 | } | ||
110 | @@ -XXX,XX +XXX,XX @@ floatx80 floatx80_etox(floatx80 a, float_status *status) | ||
111 | if (aSign) { | ||
112 | return packFloatx80(0, 0, 0); | ||
113 | } | ||
114 | - return packFloatx80(0, floatx80_infinity.high, | ||
115 | - floatx80_infinity.low); | ||
116 | + return floatx80_default_inf(0, status); | ||
117 | } | ||
118 | |||
119 | if (aExp == 0 && aSig == 0) { | ||
120 | @@ -XXX,XX +XXX,XX @@ floatx80 floatx80_twotox(floatx80 a, float_status *status) | ||
121 | if (aSign) { | ||
122 | return packFloatx80(0, 0, 0); | ||
123 | } | ||
124 | - return packFloatx80(0, floatx80_infinity.high, | ||
125 | - floatx80_infinity.low); | ||
126 | + return floatx80_default_inf(0, status); | ||
127 | } | ||
128 | |||
129 | if (aExp == 0 && aSig == 0) { | ||
130 | @@ -XXX,XX +XXX,XX @@ floatx80 floatx80_tentox(floatx80 a, float_status *status) | ||
131 | if (aSign) { | ||
132 | return packFloatx80(0, 0, 0); | ||
133 | } | ||
134 | - return packFloatx80(0, floatx80_infinity.high, | ||
135 | - floatx80_infinity.low); | ||
136 | + return floatx80_default_inf(0, status); | ||
137 | } | ||
138 | |||
139 | if (aExp == 0 && aSig == 0) { | ||
140 | @@ -XXX,XX +XXX,XX @@ floatx80 floatx80_atanh(floatx80 a, float_status *status) | ||
141 | if (compact >= 0x3FFF8000) { /* |X| >= 1 */ | ||
142 | if (aExp == one_exp && aSig == one_sig) { /* |X| == 1 */ | ||
143 | float_raise(float_flag_divbyzero, status); | ||
144 | - return packFloatx80(aSign, floatx80_infinity.high, | ||
145 | - floatx80_infinity.low); | ||
146 | + return floatx80_default_inf(aSign, status); | ||
147 | } else { /* |X| > 1 */ | ||
148 | float_raise(float_flag_invalid, status); | ||
149 | return floatx80_default_nan(status); | ||
150 | @@ -XXX,XX +XXX,XX @@ floatx80 floatx80_etoxm1(floatx80 a, float_status *status) | ||
151 | if (aSign) { | ||
152 | return packFloatx80(aSign, one_exp, one_sig); | ||
153 | } | ||
154 | - return packFloatx80(0, floatx80_infinity.high, | ||
155 | - floatx80_infinity.low); | ||
156 | + return floatx80_default_inf(0, status); | ||
157 | } | ||
158 | |||
159 | if (aExp == 0 && aSig == 0) { | ||
160 | @@ -XXX,XX +XXX,XX @@ floatx80 floatx80_sinh(floatx80 a, float_status *status) | ||
161 | if ((uint64_t) (aSig << 1)) { | ||
162 | return propagateFloatx80NaNOneArg(a, status); | ||
163 | } | ||
164 | - return packFloatx80(aSign, floatx80_infinity.high, | ||
165 | - floatx80_infinity.low); | ||
166 | + return floatx80_default_inf(aSign, status); | ||
167 | } | ||
168 | |||
169 | if (aExp == 0 && aSig == 0) { | ||
170 | @@ -XXX,XX +XXX,XX @@ floatx80 floatx80_cosh(floatx80 a, float_status *status) | ||
171 | if ((uint64_t) (aSig << 1)) { | ||
172 | return propagateFloatx80NaNOneArg(a, status); | ||
173 | } | ||
174 | - return packFloatx80(0, floatx80_infinity.high, | ||
175 | - floatx80_infinity.low); | ||
176 | + return floatx80_default_inf(0, status); | ||
177 | } | ||
178 | |||
179 | if (aExp == 0 && aSig == 0) { | ||
180 | -- | ||
181 | 2.43.0 | ||
182 | |||
183 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | The global const floatx80_infinity is (unlike all the other | ||
2 | float*_infinity values) target-specific, because whether the explicit | ||
3 | Integer bit is set or not varies between m68k and i386. We want to | ||
4 | be able to compile softfloat once for multiple targets, so we can't | ||
5 | continue to use a single global whose value needs to be different | ||
6 | between targets. | ||
1 | 7 | ||
8 | Replace the direct uses of floatx80_infinity in target/i386 with | ||
9 | calls to the new floatx80_default_inf() function. Note that because | ||
10 | we can ask the function for either a negative or positive infinity, | ||
11 | we don't need to change the sign of a positive infinity via | ||
12 | floatx80_chs() for the negative-Inf case. | ||
13 | |||
14 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
15 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
16 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
17 | Message-id: 20250224111524.1101196-4-peter.maydell@linaro.org | ||
18 | Message-id: 20250217125055.160887-4-peter.maydell@linaro.org | ||
19 | --- | ||
20 | target/i386/tcg/fpu_helper.c | 7 +++---- | ||
21 | 1 file changed, 3 insertions(+), 4 deletions(-) | ||
22 | |||
23 | diff --git a/target/i386/tcg/fpu_helper.c b/target/i386/tcg/fpu_helper.c | ||
24 | index XXXXXXX..XXXXXXX 100644 | ||
25 | --- a/target/i386/tcg/fpu_helper.c | ||
26 | +++ b/target/i386/tcg/fpu_helper.c | ||
27 | @@ -XXX,XX +XXX,XX @@ void helper_fxtract(CPUX86State *env) | ||
28 | } else if (floatx80_is_infinity(ST0)) { | ||
29 | fpush(env); | ||
30 | ST0 = ST1; | ||
31 | - ST1 = floatx80_infinity; | ||
32 | + ST1 = floatx80_default_inf(0, &env->fp_status); | ||
33 | } else { | ||
34 | int expdif; | ||
35 | |||
36 | @@ -XXX,XX +XXX,XX @@ void helper_fscale(CPUX86State *env) | ||
37 | float_raise(float_flag_invalid, &env->fp_status); | ||
38 | ST0 = floatx80_default_nan(&env->fp_status); | ||
39 | } else { | ||
40 | - ST0 = (floatx80_is_neg(ST0) ? | ||
41 | - floatx80_chs(floatx80_infinity) : | ||
42 | - floatx80_infinity); | ||
43 | + ST0 = floatx80_default_inf(floatx80_is_neg(ST0), | ||
44 | + &env->fp_status); | ||
45 | } | ||
46 | } | ||
47 | } else { | ||
48 | -- | ||
49 | 2.43.0 | ||
50 | |||
51 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Unlike the other float formats, whether a floatx80 value is | ||
2 | considered to be an Infinity is target-dependent. (On x86 if the | ||
3 | explicit integer bit is clear this is a "pseudo-infinity" and not a | ||
4 | valid infinity; m68k does not care about the value of the integer | ||
5 | bit.) | ||
1 | 6 | ||
7 | Currently we select this target-specific logic at compile time with | ||
8 | an ifdef. We're going to want to do this at runtime, so change the | ||
9 | floatx80_is_infinity() function to take a float_status. | ||
10 | |||
11 | This commit doesn't change any logic; we'll do that in the | ||
12 | next commit. | ||
13 | |||
14 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
15 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
16 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
17 | Message-id: 20250224111524.1101196-5-peter.maydell@linaro.org | ||
18 | --- | ||
19 | include/fpu/softfloat.h | 2 +- | ||
20 | target/i386/tcg/fpu_helper.c | 20 +++++++++++--------- | ||
21 | target/m68k/fpu_helper.c | 2 +- | ||
22 | 3 files changed, 13 insertions(+), 11 deletions(-) | ||
23 | |||
24 | diff --git a/include/fpu/softfloat.h b/include/fpu/softfloat.h | ||
25 | index XXXXXXX..XXXXXXX 100644 | ||
26 | --- a/include/fpu/softfloat.h | ||
27 | +++ b/include/fpu/softfloat.h | ||
28 | @@ -XXX,XX +XXX,XX @@ static inline floatx80 floatx80_chs(floatx80 a) | ||
29 | return a; | ||
30 | } | ||
31 | |||
32 | -static inline bool floatx80_is_infinity(floatx80 a) | ||
33 | +static inline bool floatx80_is_infinity(floatx80 a, float_status *status) | ||
34 | { | ||
35 | #if defined(TARGET_M68K) | ||
36 | return (a.high & 0x7fff) == floatx80_infinity.high && !(a.low << 1); | ||
37 | diff --git a/target/i386/tcg/fpu_helper.c b/target/i386/tcg/fpu_helper.c | ||
38 | index XXXXXXX..XXXXXXX 100644 | ||
39 | --- a/target/i386/tcg/fpu_helper.c | ||
40 | +++ b/target/i386/tcg/fpu_helper.c | ||
41 | @@ -XXX,XX +XXX,XX @@ void helper_fpatan(CPUX86State *env) | ||
42 | /* Pass this NaN through. */ | ||
43 | } else if (floatx80_is_zero(ST1) && !arg0_sign) { | ||
44 | /* Pass this zero through. */ | ||
45 | - } else if (((floatx80_is_infinity(ST0) && !floatx80_is_infinity(ST1)) || | ||
46 | + } else if (((floatx80_is_infinity(ST0, &env->fp_status) && | ||
47 | + !floatx80_is_infinity(ST1, &env->fp_status)) || | ||
48 | arg0_exp - arg1_exp >= 80) && | ||
49 | !arg0_sign) { | ||
50 | /* | ||
51 | @@ -XXX,XX +XXX,XX @@ void helper_fpatan(CPUX86State *env) | ||
52 | rexp = pi_exp; | ||
53 | rsig0 = pi_sig_high; | ||
54 | rsig1 = pi_sig_low; | ||
55 | - } else if (floatx80_is_infinity(ST1)) { | ||
56 | - if (floatx80_is_infinity(ST0)) { | ||
57 | + } else if (floatx80_is_infinity(ST1, &env->fp_status)) { | ||
58 | + if (floatx80_is_infinity(ST0, &env->fp_status)) { | ||
59 | if (arg0_sign) { | ||
60 | rexp = pi_34_exp; | ||
61 | rsig0 = pi_34_sig_high; | ||
62 | @@ -XXX,XX +XXX,XX @@ void helper_fpatan(CPUX86State *env) | ||
63 | rexp = pi_2_exp; | ||
64 | rsig0 = pi_2_sig_high; | ||
65 | rsig1 = pi_2_sig_low; | ||
66 | - } else if (floatx80_is_infinity(ST0) || arg0_exp - arg1_exp >= 80) { | ||
67 | + } else if (floatx80_is_infinity(ST0, &env->fp_status) || | ||
68 | + arg0_exp - arg1_exp >= 80) { | ||
69 | /* ST0 is negative. */ | ||
70 | rexp = pi_exp; | ||
71 | rsig0 = pi_sig_high; | ||
72 | @@ -XXX,XX +XXX,XX @@ void helper_fxtract(CPUX86State *env) | ||
73 | } | ||
74 | fpush(env); | ||
75 | ST0 = ST1; | ||
76 | - } else if (floatx80_is_infinity(ST0)) { | ||
77 | + } else if (floatx80_is_infinity(ST0, &env->fp_status)) { | ||
78 | fpush(env); | ||
79 | ST0 = ST1; | ||
80 | ST1 = floatx80_default_inf(0, &env->fp_status); | ||
81 | @@ -XXX,XX +XXX,XX @@ void helper_fyl2x(CPUX86State *env) | ||
82 | } else if (arg0_sign && !floatx80_is_zero(ST0)) { | ||
83 | float_raise(float_flag_invalid, &env->fp_status); | ||
84 | ST1 = floatx80_default_nan(&env->fp_status); | ||
85 | - } else if (floatx80_is_infinity(ST1)) { | ||
86 | + } else if (floatx80_is_infinity(ST1, &env->fp_status)) { | ||
87 | FloatRelation cmp = floatx80_compare(ST0, floatx80_one, | ||
88 | &env->fp_status); | ||
89 | switch (cmp) { | ||
90 | @@ -XXX,XX +XXX,XX @@ void helper_fyl2x(CPUX86State *env) | ||
91 | ST1 = floatx80_default_nan(&env->fp_status); | ||
92 | break; | ||
93 | } | ||
94 | - } else if (floatx80_is_infinity(ST0)) { | ||
95 | + } else if (floatx80_is_infinity(ST0, &env->fp_status)) { | ||
96 | if (floatx80_is_zero(ST1)) { | ||
97 | float_raise(float_flag_invalid, &env->fp_status); | ||
98 | ST1 = floatx80_default_nan(&env->fp_status); | ||
99 | @@ -XXX,XX +XXX,XX @@ void helper_fscale(CPUX86State *env) | ||
100 | float_raise(float_flag_invalid, &env->fp_status); | ||
101 | ST0 = floatx80_silence_nan(ST0, &env->fp_status); | ||
102 | } | ||
103 | - } else if (floatx80_is_infinity(ST1) && | ||
104 | + } else if (floatx80_is_infinity(ST1, &env->fp_status) && | ||
105 | !floatx80_invalid_encoding(ST0) && | ||
106 | !floatx80_is_any_nan(ST0)) { | ||
107 | if (floatx80_is_neg(ST1)) { | ||
108 | - if (floatx80_is_infinity(ST0)) { | ||
109 | + if (floatx80_is_infinity(ST0, &env->fp_status)) { | ||
110 | float_raise(float_flag_invalid, &env->fp_status); | ||
111 | ST0 = floatx80_default_nan(&env->fp_status); | ||
112 | } else { | ||
113 | diff --git a/target/m68k/fpu_helper.c b/target/m68k/fpu_helper.c | ||
114 | index XXXXXXX..XXXXXXX 100644 | ||
115 | --- a/target/m68k/fpu_helper.c | ||
116 | +++ b/target/m68k/fpu_helper.c | ||
117 | @@ -XXX,XX +XXX,XX @@ void HELPER(ftst)(CPUM68KState *env, FPReg *val) | ||
118 | |||
119 | if (floatx80_is_any_nan(val->d)) { | ||
120 | cc |= FPSR_CC_A; | ||
121 | - } else if (floatx80_is_infinity(val->d)) { | ||
122 | + } else if (floatx80_is_infinity(val->d, &env->fp_status)) { | ||
123 | cc |= FPSR_CC_I; | ||
124 | } else if (floatx80_is_zero(val->d)) { | ||
125 | cc |= FPSR_CC_Z; | ||
126 | -- | ||
127 | 2.43.0 | ||
128 | |||
129 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | In Intel terminology, a floatx80 Infinity with the explicit integer | ||
2 | bit clear is a "pseudo-infinity"; for x86 these are not valid | ||
3 | infinity values. m68k is looser and does not care whether the | ||
4 | Integer bit is set or clear in an infinity. | ||
1 | 5 | ||
6 | Move this setting to runtime rather than using an ifdef in | ||
7 | floatx80_is_infinity(). | ||
8 | |||
9 | Since this was the last use of the floatx80_infinity global constant, | ||
10 | we remove it and its definition here. | ||
11 | |||
12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
13 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
14 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
15 | Message-id: 20250224111524.1101196-6-peter.maydell@linaro.org | ||
16 | Message-id: 20250217125055.160887-5-peter.maydell@linaro.org | ||
17 | --- | ||
18 | include/fpu/softfloat-types.h | 5 +++++ | ||
19 | include/fpu/softfloat.h | 18 +++++++++++------- | ||
20 | target/m68k/cpu.c | 4 +++- | ||
21 | fpu/softfloat-specialize.c.inc | 10 ---------- | ||
22 | 4 files changed, 19 insertions(+), 18 deletions(-) | ||
23 | |||
24 | diff --git a/include/fpu/softfloat-types.h b/include/fpu/softfloat-types.h | ||
25 | index XXXXXXX..XXXXXXX 100644 | ||
26 | --- a/include/fpu/softfloat-types.h | ||
27 | +++ b/include/fpu/softfloat-types.h | ||
28 | @@ -XXX,XX +XXX,XX @@ typedef enum __attribute__((__packed__)) { | ||
29 | typedef enum __attribute__((__packed__)) { | ||
30 | /* In the default Infinity value, is the Integer bit 0 ? */ | ||
31 | floatx80_default_inf_int_bit_is_zero = 1, | ||
32 | + /* | ||
33 | + * Are Pseudo-infinities (Inf with the Integer bit zero) valid? | ||
34 | + * If so, floatx80_is_infinity() will return true for them. | ||
35 | + */ | ||
36 | + floatx80_pseudo_inf_valid = 2, | ||
37 | } FloatX80Behaviour; | ||
38 | |||
39 | /* | ||
40 | diff --git a/include/fpu/softfloat.h b/include/fpu/softfloat.h | ||
41 | index XXXXXXX..XXXXXXX 100644 | ||
42 | --- a/include/fpu/softfloat.h | ||
43 | +++ b/include/fpu/softfloat.h | ||
44 | @@ -XXX,XX +XXX,XX @@ float128 floatx80_to_float128(floatx80, float_status *status); | ||
45 | /*---------------------------------------------------------------------------- | ||
46 | | The pattern for an extended double-precision inf. | ||
47 | *----------------------------------------------------------------------------*/ | ||
48 | -extern const floatx80 floatx80_infinity; | ||
49 | floatx80 floatx80_default_inf(bool zSign, float_status *status); | ||
50 | |||
51 | /*---------------------------------------------------------------------------- | ||
52 | @@ -XXX,XX +XXX,XX @@ static inline floatx80 floatx80_chs(floatx80 a) | ||
53 | |||
54 | static inline bool floatx80_is_infinity(floatx80 a, float_status *status) | ||
55 | { | ||
56 | -#if defined(TARGET_M68K) | ||
57 | - return (a.high & 0x7fff) == floatx80_infinity.high && !(a.low << 1); | ||
58 | -#else | ||
59 | - return (a.high & 0x7fff) == floatx80_infinity.high && | ||
60 | - a.low == floatx80_infinity.low; | ||
61 | -#endif | ||
62 | + /* | ||
63 | + * It's target-specific whether the Integer bit is permitted | ||
64 | + * to be 0 in a valid Infinity value. (x86 says no, m68k says yes). | ||
65 | + */ | ||
66 | + bool intbit = a.low >> 63; | ||
67 | + | ||
68 | + if (!intbit && | ||
69 | + !(status->floatx80_behaviour & floatx80_pseudo_inf_valid)) { | ||
70 | + return false; | ||
71 | + } | ||
72 | + return (a.high & 0x7fff) == 0x7fff && !(a.low << 1); | ||
73 | } | ||
74 | |||
75 | static inline bool floatx80_is_neg(floatx80 a) | ||
76 | diff --git a/target/m68k/cpu.c b/target/m68k/cpu.c | ||
77 | index XXXXXXX..XXXXXXX 100644 | ||
78 | --- a/target/m68k/cpu.c | ||
79 | +++ b/target/m68k/cpu.c | ||
80 | @@ -XXX,XX +XXX,XX @@ static void m68k_cpu_reset_hold(Object *obj, ResetType type) | ||
81 | /* | ||
82 | * m68k-specific floatx80 behaviour: | ||
83 | * * default Infinity values have a zero Integer bit | ||
84 | + * * input Infinities may have the Integer bit either 0 or 1 | ||
85 | */ | ||
86 | - set_floatx80_behaviour(floatx80_default_inf_int_bit_is_zero, | ||
87 | + set_floatx80_behaviour(floatx80_default_inf_int_bit_is_zero | | ||
88 | + floatx80_pseudo_inf_valid, | ||
89 | &env->fp_status); | ||
90 | |||
91 | nan = floatx80_default_nan(&env->fp_status); | ||
92 | diff --git a/fpu/softfloat-specialize.c.inc b/fpu/softfloat-specialize.c.inc | ||
93 | index XXXXXXX..XXXXXXX 100644 | ||
94 | --- a/fpu/softfloat-specialize.c.inc | ||
95 | +++ b/fpu/softfloat-specialize.c.inc | ||
96 | @@ -XXX,XX +XXX,XX @@ floatx80 floatx80_default_inf(bool zSign, float_status *status) | ||
97 | return packFloatx80(zSign, 0x7fff, z ? 0 : (1ULL << 63)); | ||
98 | } | ||
99 | |||
100 | -#define floatx80_infinity_high 0x7FFF | ||
101 | -#if defined(TARGET_M68K) | ||
102 | -#define floatx80_infinity_low UINT64_C(0x0000000000000000) | ||
103 | -#else | ||
104 | -#define floatx80_infinity_low UINT64_C(0x8000000000000000) | ||
105 | -#endif | ||
106 | - | ||
107 | -const floatx80 floatx80_infinity | ||
108 | - = make_floatx80_init(floatx80_infinity_high, floatx80_infinity_low); | ||
109 | - | ||
110 | /*---------------------------------------------------------------------------- | ||
111 | | Returns 1 if the half-precision floating-point value `a' is a quiet | ||
112 | | NaN; otherwise returns 0. | ||
113 | -- | ||
114 | 2.43.0 | ||
115 | |||
116 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | The definition of which floatx80 encodings are invalid is | ||
2 | target-specific. Currently we handle this with an ifdef, but we | ||
3 | would like to defer this decision to runtime. In preparation, pass a | ||
4 | float_status argument to floatx80_invalid_encoding(). | ||
1 | 5 | ||
6 | We will change the implementation from ifdef to looking at | ||
7 | the status argument in the following commit. | ||
8 | |||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
10 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
11 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
12 | Message-id: 20250224111524.1101196-7-peter.maydell@linaro.org | ||
13 | --- | ||
14 | include/fpu/softfloat.h | 2 +- | ||
15 | fpu/softfloat.c | 2 +- | ||
16 | target/i386/tcg/fpu_helper.c | 24 +++++++++++++----------- | ||
17 | 3 files changed, 15 insertions(+), 13 deletions(-) | ||
18 | |||
19 | diff --git a/include/fpu/softfloat.h b/include/fpu/softfloat.h | ||
20 | index XXXXXXX..XXXXXXX 100644 | ||
21 | --- a/include/fpu/softfloat.h | ||
22 | +++ b/include/fpu/softfloat.h | ||
23 | @@ -XXX,XX +XXX,XX @@ static inline bool floatx80_unordered_quiet(floatx80 a, floatx80 b, | ||
24 | | pseudo-denormals, which must still be correctly handled as inputs even | ||
25 | | if they are never generated as outputs. | ||
26 | *----------------------------------------------------------------------------*/ | ||
27 | -static inline bool floatx80_invalid_encoding(floatx80 a) | ||
28 | +static inline bool floatx80_invalid_encoding(floatx80 a, float_status *s) | ||
29 | { | ||
30 | #if defined(TARGET_M68K) | ||
31 | /*------------------------------------------------------------------------- | ||
32 | diff --git a/fpu/softfloat.c b/fpu/softfloat.c | ||
33 | index XXXXXXX..XXXXXXX 100644 | ||
34 | --- a/fpu/softfloat.c | ||
35 | +++ b/fpu/softfloat.c | ||
36 | @@ -XXX,XX +XXX,XX @@ static bool floatx80_unpack_canonical(FloatParts128 *p, floatx80 f, | ||
37 | g_assert_not_reached(); | ||
38 | } | ||
39 | |||
40 | - if (unlikely(floatx80_invalid_encoding(f))) { | ||
41 | + if (unlikely(floatx80_invalid_encoding(f, s))) { | ||
42 | float_raise(float_flag_invalid, s); | ||
43 | return false; | ||
44 | } | ||
45 | diff --git a/target/i386/tcg/fpu_helper.c b/target/i386/tcg/fpu_helper.c | ||
46 | index XXXXXXX..XXXXXXX 100644 | ||
47 | --- a/target/i386/tcg/fpu_helper.c | ||
48 | +++ b/target/i386/tcg/fpu_helper.c | ||
49 | @@ -XXX,XX +XXX,XX @@ void helper_f2xm1(CPUX86State *env) | ||
50 | int32_t exp = extractFloatx80Exp(ST0); | ||
51 | bool sign = extractFloatx80Sign(ST0); | ||
52 | |||
53 | - if (floatx80_invalid_encoding(ST0)) { | ||
54 | + if (floatx80_invalid_encoding(ST0, &env->fp_status)) { | ||
55 | float_raise(float_flag_invalid, &env->fp_status); | ||
56 | ST0 = floatx80_default_nan(&env->fp_status); | ||
57 | } else if (floatx80_is_any_nan(ST0)) { | ||
58 | @@ -XXX,XX +XXX,XX @@ void helper_fpatan(CPUX86State *env) | ||
59 | } else if (floatx80_is_signaling_nan(ST1, &env->fp_status)) { | ||
60 | float_raise(float_flag_invalid, &env->fp_status); | ||
61 | ST1 = floatx80_silence_nan(ST1, &env->fp_status); | ||
62 | - } else if (floatx80_invalid_encoding(ST0) || | ||
63 | - floatx80_invalid_encoding(ST1)) { | ||
64 | + } else if (floatx80_invalid_encoding(ST0, &env->fp_status) || | ||
65 | + floatx80_invalid_encoding(ST1, &env->fp_status)) { | ||
66 | float_raise(float_flag_invalid, &env->fp_status); | ||
67 | ST1 = floatx80_default_nan(&env->fp_status); | ||
68 | } else if (floatx80_is_any_nan(ST0)) { | ||
69 | @@ -XXX,XX +XXX,XX @@ void helper_fxtract(CPUX86State *env) | ||
70 | &env->fp_status); | ||
71 | fpush(env); | ||
72 | ST0 = temp.d; | ||
73 | - } else if (floatx80_invalid_encoding(ST0)) { | ||
74 | + } else if (floatx80_invalid_encoding(ST0, &env->fp_status)) { | ||
75 | float_raise(float_flag_invalid, &env->fp_status); | ||
76 | ST0 = floatx80_default_nan(&env->fp_status); | ||
77 | fpush(env); | ||
78 | @@ -XXX,XX +XXX,XX @@ static void helper_fprem_common(CPUX86State *env, bool mod) | ||
79 | env->fpus &= ~0x4700; /* (C3,C2,C1,C0) <-- 0000 */ | ||
80 | if (floatx80_is_zero(ST0) || floatx80_is_zero(ST1) || | ||
81 | exp0 == 0x7fff || exp1 == 0x7fff || | ||
82 | - floatx80_invalid_encoding(ST0) || floatx80_invalid_encoding(ST1)) { | ||
83 | + floatx80_invalid_encoding(ST0, &env->fp_status) || | ||
84 | + floatx80_invalid_encoding(ST1, &env->fp_status)) { | ||
85 | ST0 = floatx80_modrem(ST0, ST1, mod, "ient, &env->fp_status); | ||
86 | } else { | ||
87 | if (exp0 == 0) { | ||
88 | @@ -XXX,XX +XXX,XX @@ void helper_fyl2xp1(CPUX86State *env) | ||
89 | } else if (floatx80_is_signaling_nan(ST1, &env->fp_status)) { | ||
90 | float_raise(float_flag_invalid, &env->fp_status); | ||
91 | ST1 = floatx80_silence_nan(ST1, &env->fp_status); | ||
92 | - } else if (floatx80_invalid_encoding(ST0) || | ||
93 | - floatx80_invalid_encoding(ST1)) { | ||
94 | + } else if (floatx80_invalid_encoding(ST0, &env->fp_status) || | ||
95 | + floatx80_invalid_encoding(ST1, &env->fp_status)) { | ||
96 | float_raise(float_flag_invalid, &env->fp_status); | ||
97 | ST1 = floatx80_default_nan(&env->fp_status); | ||
98 | } else if (floatx80_is_any_nan(ST0)) { | ||
99 | @@ -XXX,XX +XXX,XX @@ void helper_fyl2x(CPUX86State *env) | ||
100 | } else if (floatx80_is_signaling_nan(ST1, &env->fp_status)) { | ||
101 | float_raise(float_flag_invalid, &env->fp_status); | ||
102 | ST1 = floatx80_silence_nan(ST1, &env->fp_status); | ||
103 | - } else if (floatx80_invalid_encoding(ST0) || | ||
104 | - floatx80_invalid_encoding(ST1)) { | ||
105 | + } else if (floatx80_invalid_encoding(ST0, &env->fp_status) || | ||
106 | + floatx80_invalid_encoding(ST1, &env->fp_status)) { | ||
107 | float_raise(float_flag_invalid, &env->fp_status); | ||
108 | ST1 = floatx80_default_nan(&env->fp_status); | ||
109 | } else if (floatx80_is_any_nan(ST0)) { | ||
110 | @@ -XXX,XX +XXX,XX @@ void helper_frndint(CPUX86State *env) | ||
111 | void helper_fscale(CPUX86State *env) | ||
112 | { | ||
113 | uint8_t old_flags = save_exception_flags(env); | ||
114 | - if (floatx80_invalid_encoding(ST1) || floatx80_invalid_encoding(ST0)) { | ||
115 | + if (floatx80_invalid_encoding(ST1, &env->fp_status) || | ||
116 | + floatx80_invalid_encoding(ST0, &env->fp_status)) { | ||
117 | float_raise(float_flag_invalid, &env->fp_status); | ||
118 | ST0 = floatx80_default_nan(&env->fp_status); | ||
119 | } else if (floatx80_is_any_nan(ST1)) { | ||
120 | @@ -XXX,XX +XXX,XX @@ void helper_fscale(CPUX86State *env) | ||
121 | ST0 = floatx80_silence_nan(ST0, &env->fp_status); | ||
122 | } | ||
123 | } else if (floatx80_is_infinity(ST1, &env->fp_status) && | ||
124 | - !floatx80_invalid_encoding(ST0) && | ||
125 | + !floatx80_invalid_encoding(ST0, &env->fp_status) && | ||
126 | !floatx80_is_any_nan(ST0)) { | ||
127 | if (floatx80_is_neg(ST1)) { | ||
128 | if (floatx80_is_infinity(ST0, &env->fp_status)) { | ||
129 | -- | ||
130 | 2.43.0 | ||
131 | |||
132 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Because floatx80 has an explicit integer bit, this permits some | ||
2 | odd encodings where the integer bit is not set correctly for the | ||
3 | floating point value type. In In Intel terminology the | ||
4 | categories are: | ||
5 | exp == 0, int = 0, mantissa == 0 : zeroes | ||
6 | exp == 0, int = 0, mantissa != 0 : denormals | ||
7 | exp == 0, int = 1 : pseudo-denormals | ||
8 | 0 < exp < 0x7fff, int = 0 : unnormals | ||
9 | 0 < exp < 0x7fff, int = 1 : normals | ||
10 | exp == 0x7fff, int = 0, mantissa == 0 : pseudo-infinities | ||
11 | exp == 0x7fff, int = 1, mantissa == 0 : infinities | ||
12 | exp == 0x7fff, int = 0, mantissa != 0 : pseudo-NaNs | ||
13 | exp == 0x7fff, int = 1, mantissa == 0 : NaNs | ||
1 | 14 | ||
15 | The usual IEEE cases of zero, denormal, normal, inf and NaN are always valid. | ||
16 | x87 permits as input also pseudo-denormals. | ||
17 | m68k permits all those and also pseudo-infinities, pseudo-NaNs and unnormals. | ||
18 | |||
19 | Currently we have an ifdef in floatx80_invalid_encoding() to select | ||
20 | the x86 vs m68k behaviour. Add new floatx80_behaviour flags to | ||
21 | select whether pseudo-NaN and unnormal are valid, and use these | ||
22 | (plus the existing pseudo_inf_valid flag) to decide whether these | ||
23 | encodings are invalid at runtime. | ||
24 | |||
25 | We leave pseudo-denormals as always-valid, since both x86 and m68k | ||
26 | accept them. | ||
27 | |||
28 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
29 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
30 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
31 | Message-id: 20250224111524.1101196-8-peter.maydell@linaro.org | ||
32 | Message-id: 20250217125055.160887-6-peter.maydell@linaro.org | ||
33 | --- | ||
34 | include/fpu/softfloat-types.h | 14 ++++++++ | ||
35 | include/fpu/softfloat.h | 68 ++++++++++++++++++----------------- | ||
36 | target/m68k/cpu.c | 28 ++++++++++++++- | ||
37 | 3 files changed, 77 insertions(+), 33 deletions(-) | ||
38 | |||
39 | diff --git a/include/fpu/softfloat-types.h b/include/fpu/softfloat-types.h | ||
40 | index XXXXXXX..XXXXXXX 100644 | ||
41 | --- a/include/fpu/softfloat-types.h | ||
42 | +++ b/include/fpu/softfloat-types.h | ||
43 | @@ -XXX,XX +XXX,XX @@ typedef enum __attribute__((__packed__)) { | ||
44 | /* | ||
45 | * Are Pseudo-infinities (Inf with the Integer bit zero) valid? | ||
46 | * If so, floatx80_is_infinity() will return true for them. | ||
47 | + * If not, floatx80_invalid_encoding will return false for them, | ||
48 | + * and using them as inputs to a float op will raise Invalid. | ||
49 | */ | ||
50 | floatx80_pseudo_inf_valid = 2, | ||
51 | + /* | ||
52 | + * Are Pseudo-NaNs (NaNs where the Integer bit is zero) valid? | ||
53 | + * If not, floatx80_invalid_encoding() will return false for them, | ||
54 | + * and using them as inputs to a float op will raise Invalid. | ||
55 | + */ | ||
56 | + floatx80_pseudo_nan_valid = 4, | ||
57 | + /* | ||
58 | + * Are Unnormals (0 < exp < 0x7fff, Integer bit zero) valid? | ||
59 | + * If not, floatx80_invalid_encoding() will return false for them, | ||
60 | + * and using them as inputs to a float op will raise Invalid. | ||
61 | + */ | ||
62 | + floatx80_unnormal_valid = 8, | ||
63 | } FloatX80Behaviour; | ||
64 | |||
65 | /* | ||
66 | diff --git a/include/fpu/softfloat.h b/include/fpu/softfloat.h | ||
67 | index XXXXXXX..XXXXXXX 100644 | ||
68 | --- a/include/fpu/softfloat.h | ||
69 | +++ b/include/fpu/softfloat.h | ||
70 | @@ -XXX,XX +XXX,XX @@ static inline bool floatx80_unordered_quiet(floatx80 a, floatx80 b, | ||
71 | |||
72 | /*---------------------------------------------------------------------------- | ||
73 | | Return whether the given value is an invalid floatx80 encoding. | ||
74 | -| Invalid floatx80 encodings arise when the integer bit is not set, but | ||
75 | -| the exponent is not zero. The only times the integer bit is permitted to | ||
76 | -| be zero is in subnormal numbers and the value zero. | ||
77 | -| This includes what the Intel software developer's manual calls pseudo-NaNs, | ||
78 | -| pseudo-infinities and un-normal numbers. It does not include | ||
79 | -| pseudo-denormals, which must still be correctly handled as inputs even | ||
80 | -| if they are never generated as outputs. | ||
81 | +| Invalid floatx80 encodings may arise when the integer bit is not set | ||
82 | +| correctly; this is target-specific. In Intel terminology the | ||
83 | +| categories are: | ||
84 | +| exp == 0, int = 0, mantissa == 0 : zeroes | ||
85 | +| exp == 0, int = 0, mantissa != 0 : denormals | ||
86 | +| exp == 0, int = 1 : pseudo-denormals | ||
87 | +| 0 < exp < 0x7fff, int = 0 : unnormals | ||
88 | +| 0 < exp < 0x7fff, int = 1 : normals | ||
89 | +| exp == 0x7fff, int = 0, mantissa == 0 : pseudo-infinities | ||
90 | +| exp == 0x7fff, int = 1, mantissa == 0 : infinities | ||
91 | +| exp == 0x7fff, int = 0, mantissa != 0 : pseudo-NaNs | ||
92 | +| exp == 0x7fff, int = 1, mantissa == 0 : NaNs | ||
93 | +| | ||
94 | +| The usual IEEE cases of zero, denormal, normal, inf and NaN are always valid. | ||
95 | +| x87 permits as input also pseudo-denormals. | ||
96 | +| m68k permits all those and also pseudo-infinities, pseudo-NaNs and unnormals. | ||
97 | +| | ||
98 | +| Since we don't have a target that handles floatx80 but prohibits | ||
99 | +| pseudo-denormals in input, we don't currently have a floatx80_behaviour | ||
100 | +| flag for that case, but instead always accept it. Conveniently this | ||
101 | +| means that all cases with either exponent 0 or the integer bit set are | ||
102 | +| valid for all targets. | ||
103 | *----------------------------------------------------------------------------*/ | ||
104 | static inline bool floatx80_invalid_encoding(floatx80 a, float_status *s) | ||
105 | { | ||
106 | -#if defined(TARGET_M68K) | ||
107 | - /*------------------------------------------------------------------------- | ||
108 | - | With m68k, the explicit integer bit can be zero in the case of: | ||
109 | - | - zeros (exp == 0, mantissa == 0) | ||
110 | - | - denormalized numbers (exp == 0, mantissa != 0) | ||
111 | - | - unnormalized numbers (exp != 0, exp < 0x7FFF) | ||
112 | - | - infinities (exp == 0x7FFF, mantissa == 0) | ||
113 | - | - not-a-numbers (exp == 0x7FFF, mantissa != 0) | ||
114 | - | | ||
115 | - | For infinities and NaNs, the explicit integer bit can be either one or | ||
116 | - | zero. | ||
117 | - | | ||
118 | - | The IEEE 754 standard does not define a zero integer bit. Such a number | ||
119 | - | is an unnormalized number. Hardware does not directly support | ||
120 | - | denormalized and unnormalized numbers, but implicitly supports them by | ||
121 | - | trapping them as unimplemented data types, allowing efficient conversion | ||
122 | - | in software. | ||
123 | - | | ||
124 | - | See "M68000 FAMILY PROGRAMMER’S REFERENCE MANUAL", | ||
125 | - | "1.6 FLOATING-POINT DATA TYPES" | ||
126 | - *------------------------------------------------------------------------*/ | ||
127 | - return false; | ||
128 | -#else | ||
129 | - return (a.low & (1ULL << 63)) == 0 && (a.high & 0x7FFF) != 0; | ||
130 | -#endif | ||
131 | + if ((a.low >> 63) || (a.high & 0x7fff) == 0) { | ||
132 | + /* Anything with the Integer bit set or the exponent 0 is valid */ | ||
133 | + return false; | ||
134 | + } | ||
135 | + | ||
136 | + if ((a.high & 0x7fff) == 0x7fff) { | ||
137 | + if (a.low) { | ||
138 | + return !(s->floatx80_behaviour & floatx80_pseudo_nan_valid); | ||
139 | + } else { | ||
140 | + return !(s->floatx80_behaviour & floatx80_pseudo_inf_valid); | ||
141 | + } | ||
142 | + } else { | ||
143 | + return !(s->floatx80_behaviour & floatx80_unnormal_valid); | ||
144 | + } | ||
145 | } | ||
146 | |||
147 | #define floatx80_zero make_floatx80(0x0000, 0x0000000000000000LL) | ||
148 | diff --git a/target/m68k/cpu.c b/target/m68k/cpu.c | ||
149 | index XXXXXXX..XXXXXXX 100644 | ||
150 | --- a/target/m68k/cpu.c | ||
151 | +++ b/target/m68k/cpu.c | ||
152 | @@ -XXX,XX +XXX,XX @@ static void m68k_cpu_reset_hold(Object *obj, ResetType type) | ||
153 | * m68k-specific floatx80 behaviour: | ||
154 | * * default Infinity values have a zero Integer bit | ||
155 | * * input Infinities may have the Integer bit either 0 or 1 | ||
156 | + * * pseudo-denormals supported for input and output | ||
157 | + * * don't raise Invalid for pseudo-NaN/pseudo-Inf/Unnormal | ||
158 | + * | ||
159 | + * With m68k, the explicit integer bit can be zero in the case of: | ||
160 | + * - zeros (exp == 0, mantissa == 0) | ||
161 | + * - denormalized numbers (exp == 0, mantissa != 0) | ||
162 | + * - unnormalized numbers (exp != 0, exp < 0x7FFF) | ||
163 | + * - infinities (exp == 0x7FFF, mantissa == 0) | ||
164 | + * - not-a-numbers (exp == 0x7FFF, mantissa != 0) | ||
165 | + * | ||
166 | + * For infinities and NaNs, the explicit integer bit can be either one or | ||
167 | + * zero. | ||
168 | + * | ||
169 | + * The IEEE 754 standard does not define a zero integer bit. Such a number | ||
170 | + * is an unnormalized number. Hardware does not directly support | ||
171 | + * denormalized and unnormalized numbers, but implicitly supports them by | ||
172 | + * trapping them as unimplemented data types, allowing efficient conversion | ||
173 | + * in software. | ||
174 | + * | ||
175 | + * See "M68000 FAMILY PROGRAMMER’S REFERENCE MANUAL", | ||
176 | + * "1.6 FLOATING-POINT DATA TYPES" | ||
177 | + * | ||
178 | + * Note though that QEMU's fp emulation does directly handle both | ||
179 | + * denormal and unnormal values, and does not trap to guest software. | ||
180 | */ | ||
181 | set_floatx80_behaviour(floatx80_default_inf_int_bit_is_zero | | ||
182 | - floatx80_pseudo_inf_valid, | ||
183 | + floatx80_pseudo_inf_valid | | ||
184 | + floatx80_pseudo_nan_valid | | ||
185 | + floatx80_unnormal_valid, | ||
186 | &env->fp_status); | ||
187 | |||
188 | nan = floatx80_default_nan(&env->fp_status); | ||
189 | -- | ||
190 | 2.43.0 | ||
191 | |||
192 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Currently we compile-time set an 'm68k_denormal' flag in the FloatFmt | ||
2 | for floatx80 for m68k. This controls our handling of what the Intel | ||
3 | documentation calls a "pseudo-denormal": a value where the exponent | ||
4 | field is zero and the explicit integer bit is set. | ||
1 | 5 | ||
6 | For x86, the x87 FPU is supposed to accept a pseudo-denormal as | ||
7 | input, but never generate one on output. For m68k, these values are | ||
8 | permitted on input and may be produced on output. | ||
9 | |||
10 | Replace the flag in the FloatFmt with a flag indicating whether the | ||
11 | float format has an explicit bit (which will be true for floatx80 for | ||
12 | all targets, and false for every other float type). Then we can gate | ||
13 | the handling of these pseudo-denormals on the setting of a | ||
14 | floatx80_behaviour flag. | ||
15 | |||
16 | As far as I can see from the code we don't actually handle the | ||
17 | x86-mandated "accept on input but don't generate" behaviour, because | ||
18 | the handling in partsN(canonicalize) looked at fmt->m68k_denormal. | ||
19 | So I have added TODO comments to that effect. | ||
20 | |||
21 | This commit doesn't change any behaviour for any target. | ||
22 | |||
23 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
24 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
25 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
26 | Message-id: 20250224111524.1101196-9-peter.maydell@linaro.org | ||
27 | Message-id: 20250217125055.160887-7-peter.maydell@linaro.org | ||
28 | --- | ||
29 | include/fpu/softfloat-types.h | 19 +++++++++++++++++++ | ||
30 | fpu/softfloat.c | 9 ++++----- | ||
31 | target/m68k/cpu.c | 3 ++- | ||
32 | fpu/softfloat-parts.c.inc | 27 ++++++++++++++++++++++++--- | ||
33 | 4 files changed, 49 insertions(+), 9 deletions(-) | ||
34 | |||
35 | diff --git a/include/fpu/softfloat-types.h b/include/fpu/softfloat-types.h | ||
36 | index XXXXXXX..XXXXXXX 100644 | ||
37 | --- a/include/fpu/softfloat-types.h | ||
38 | +++ b/include/fpu/softfloat-types.h | ||
39 | @@ -XXX,XX +XXX,XX @@ typedef enum __attribute__((__packed__)) { | ||
40 | * and using them as inputs to a float op will raise Invalid. | ||
41 | */ | ||
42 | floatx80_unnormal_valid = 8, | ||
43 | + | ||
44 | + /* | ||
45 | + * If the exponent is 0 and the Integer bit is set, Intel call | ||
46 | + * this a "pseudo-denormal"; x86 supports that only on input | ||
47 | + * (treating them as denormals by ignoring the Integer bit). | ||
48 | + * For m68k, the integer bit is considered validly part of the | ||
49 | + * input value when the exponent is 0, and may be 0 or 1, | ||
50 | + * giving extra range. They may also be generated as outputs. | ||
51 | + * (The m68k manual actually calls these values part of the | ||
52 | + * normalized number range, not the denormalized number range.) | ||
53 | + * | ||
54 | + * By default you get the Intel behaviour where the Integer | ||
55 | + * bit is ignored; if this is set then the Integer bit value | ||
56 | + * is honoured, m68k-style. | ||
57 | + * | ||
58 | + * Either way, floatx80_invalid_encoding() will always accept | ||
59 | + * pseudo-denormals. | ||
60 | + */ | ||
61 | + floatx80_pseudo_denormal_valid = 16, | ||
62 | } FloatX80Behaviour; | ||
63 | |||
64 | /* | ||
65 | diff --git a/fpu/softfloat.c b/fpu/softfloat.c | ||
66 | index XXXXXXX..XXXXXXX 100644 | ||
67 | --- a/fpu/softfloat.c | ||
68 | +++ b/fpu/softfloat.c | ||
69 | @@ -XXX,XX +XXX,XX @@ typedef struct { | ||
70 | * round_mask: bits below lsb which must be rounded | ||
71 | * The following optional modifiers are available: | ||
72 | * arm_althp: handle ARM Alternative Half Precision | ||
73 | - * m68k_denormal: explicit integer bit for extended precision may be 1 | ||
74 | + * has_explicit_bit: has an explicit integer bit; this affects whether | ||
75 | + * the float_status floatx80_behaviour handling applies | ||
76 | */ | ||
77 | typedef struct { | ||
78 | int exp_size; | ||
79 | @@ -XXX,XX +XXX,XX @@ typedef struct { | ||
80 | int frac_size; | ||
81 | int frac_shift; | ||
82 | bool arm_althp; | ||
83 | - bool m68k_denormal; | ||
84 | + bool has_explicit_bit; | ||
85 | uint64_t round_mask; | ||
86 | } FloatFmt; | ||
87 | |||
88 | @@ -XXX,XX +XXX,XX @@ static const FloatFmt floatx80_params[3] = { | ||
89 | [floatx80_precision_d] = { FLOATX80_PARAMS(52) }, | ||
90 | [floatx80_precision_x] = { | ||
91 | FLOATX80_PARAMS(64), | ||
92 | -#ifdef TARGET_M68K | ||
93 | - .m68k_denormal = true, | ||
94 | -#endif | ||
95 | + .has_explicit_bit = true, | ||
96 | }, | ||
97 | }; | ||
98 | |||
99 | diff --git a/target/m68k/cpu.c b/target/m68k/cpu.c | ||
100 | index XXXXXXX..XXXXXXX 100644 | ||
101 | --- a/target/m68k/cpu.c | ||
102 | +++ b/target/m68k/cpu.c | ||
103 | @@ -XXX,XX +XXX,XX @@ static void m68k_cpu_reset_hold(Object *obj, ResetType type) | ||
104 | set_floatx80_behaviour(floatx80_default_inf_int_bit_is_zero | | ||
105 | floatx80_pseudo_inf_valid | | ||
106 | floatx80_pseudo_nan_valid | | ||
107 | - floatx80_unnormal_valid, | ||
108 | + floatx80_unnormal_valid | | ||
109 | + floatx80_pseudo_denormal_valid, | ||
110 | &env->fp_status); | ||
111 | |||
112 | nan = floatx80_default_nan(&env->fp_status); | ||
113 | diff --git a/fpu/softfloat-parts.c.inc b/fpu/softfloat-parts.c.inc | ||
114 | index XXXXXXX..XXXXXXX 100644 | ||
115 | --- a/fpu/softfloat-parts.c.inc | ||
116 | +++ b/fpu/softfloat-parts.c.inc | ||
117 | @@ -XXX,XX +XXX,XX @@ static FloatPartsN *partsN(pick_nan_muladd)(FloatPartsN *a, FloatPartsN *b, | ||
118 | static void partsN(canonicalize)(FloatPartsN *p, float_status *status, | ||
119 | const FloatFmt *fmt) | ||
120 | { | ||
121 | + /* | ||
122 | + * It's target-dependent how to handle the case of exponent 0 | ||
123 | + * and Integer bit set. Intel calls these "pseudodenormals", | ||
124 | + * and treats them as if the integer bit was 0, and never | ||
125 | + * produces them on output. This is the default behaviour for QEMU. | ||
126 | + * For m68k, the integer bit is considered validly part of the | ||
127 | + * input value when the exponent is 0, and may be 0 or 1, | ||
128 | + * giving extra range. They may also be generated as outputs. | ||
129 | + * (The m68k manual actually calls these values part of the | ||
130 | + * normalized number range, not the denormalized number range, | ||
131 | + * but that distinction is not important for us, because | ||
132 | + * m68k doesn't care about the input_denormal_used status flag.) | ||
133 | + * floatx80_pseudo_denormal_valid selects the m68k behaviour, | ||
134 | + * which changes both how we canonicalize such a value and | ||
135 | + * how we uncanonicalize results. | ||
136 | + */ | ||
137 | + bool has_pseudo_denormals = fmt->has_explicit_bit && | ||
138 | + (status->floatx80_behaviour & floatx80_pseudo_denormal_valid); | ||
139 | + | ||
140 | if (unlikely(p->exp == 0)) { | ||
141 | if (likely(frac_eqz(p))) { | ||
142 | p->cls = float_class_zero; | ||
143 | @@ -XXX,XX +XXX,XX @@ static void partsN(canonicalize)(FloatPartsN *p, float_status *status, | ||
144 | int shift = frac_normalize(p); | ||
145 | p->cls = float_class_denormal; | ||
146 | p->exp = fmt->frac_shift - fmt->exp_bias | ||
147 | - - shift + !fmt->m68k_denormal; | ||
148 | + - shift + !has_pseudo_denormals; | ||
149 | } | ||
150 | } else if (likely(p->exp < fmt->exp_max) || fmt->arm_althp) { | ||
151 | p->cls = float_class_normal; | ||
152 | @@ -XXX,XX +XXX,XX @@ static void partsN(uncanon_normal)(FloatPartsN *p, float_status *s, | ||
153 | frac_clear(p); | ||
154 | } else { | ||
155 | bool is_tiny = s->tininess_before_rounding || exp < 0; | ||
156 | + bool has_pseudo_denormals = fmt->has_explicit_bit && | ||
157 | + (s->floatx80_behaviour & floatx80_pseudo_denormal_valid); | ||
158 | |||
159 | if (!is_tiny) { | ||
160 | FloatPartsN discard; | ||
161 | is_tiny = !frac_addi(&discard, p, inc); | ||
162 | } | ||
163 | |||
164 | - frac_shrjam(p, !fmt->m68k_denormal - exp); | ||
165 | + frac_shrjam(p, !has_pseudo_denormals - exp); | ||
166 | |||
167 | if (p->frac_lo & round_mask) { | ||
168 | /* Need to recompute round-to-even/round-to-odd. */ | ||
169 | @@ -XXX,XX +XXX,XX @@ static void partsN(uncanon_normal)(FloatPartsN *p, float_status *s, | ||
170 | p->frac_lo &= ~round_mask; | ||
171 | } | ||
172 | |||
173 | - exp = (p->frac_hi & DECOMPOSED_IMPLICIT_BIT) && !fmt->m68k_denormal; | ||
174 | + exp = (p->frac_hi & DECOMPOSED_IMPLICIT_BIT) && !has_pseudo_denormals; | ||
175 | frac_shr(p, frac_shift); | ||
176 | |||
177 | if (is_tiny) { | ||
178 | -- | ||
179 | 2.43.0 | ||
180 | |||
181 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Currently we have a compile-time shortcut where we | ||
2 | return false from no_signaling_nans() on everything except | ||
3 | Xtensa, because we know that's the only target that | ||
4 | might ever set status->no_signaling_nans. | ||
1 | 5 | ||
6 | Remove the ifdef, so we always look at the status flag; | ||
7 | this has no behavioural change, but will be necessary | ||
8 | if we want to build softfloat once for all targets. | ||
9 | |||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
11 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
12 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
13 | Message-id: 20250224111524.1101196-10-peter.maydell@linaro.org | ||
14 | Message-id: 20250217125055.160887-8-peter.maydell@linaro.org | ||
15 | --- | ||
16 | fpu/softfloat-specialize.c.inc | 4 ---- | ||
17 | 1 file changed, 4 deletions(-) | ||
18 | |||
19 | diff --git a/fpu/softfloat-specialize.c.inc b/fpu/softfloat-specialize.c.inc | ||
20 | index XXXXXXX..XXXXXXX 100644 | ||
21 | --- a/fpu/softfloat-specialize.c.inc | ||
22 | +++ b/fpu/softfloat-specialize.c.inc | ||
23 | @@ -XXX,XX +XXX,XX @@ this code that are retained. | ||
24 | */ | ||
25 | static inline bool no_signaling_nans(float_status *status) | ||
26 | { | ||
27 | -#if defined(TARGET_XTENSA) | ||
28 | return status->no_signaling_nans; | ||
29 | -#else | ||
30 | - return false; | ||
31 | -#endif | ||
32 | } | ||
33 | |||
34 | /* Define how the architecture discriminates signaling NaNs. | ||
35 | -- | ||
36 | 2.43.0 | ||
37 | |||
38 | diff view generated by jsdifflib |
1 | From: Rashmica Gupta <rashmica.g@gmail.com> | 1 | Currently we have a compile-time shortcut where we return a hardcode |
---|---|---|---|
2 | value from snan_bit_is_one() on everything except MIPS, because we | ||
3 | know that's the only target that needs to change | ||
4 | status->no_signaling_nans at runtime. | ||
2 | 5 | ||
3 | Signed-off-by: Rashmica Gupta <rashmica.g@gmail.com> | 6 | Remove the ifdef, so we always look at the status flag. This means |
4 | Reviewed-by: Cédric Le Goater <clg@kaod.org> | 7 | we must update the two targets (HPPA and SH4) that were previously |
5 | Signed-off-by: Cédric Le Goater <clg@kaod.org> | 8 | hardcoded to return true so that they set the status flag correctly. |
6 | Message-id: 20190904070506.1052-3-clg@kaod.org | 9 | |
10 | This has no behavioural change, but will be necessary if we want to | ||
11 | build softfloat once for all targets. | ||
12 | |||
7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 13 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
14 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
15 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
16 | Message-id: 20250224111524.1101196-11-peter.maydell@linaro.org | ||
17 | Message-id: 20250217125055.160887-9-peter.maydell@linaro.org | ||
8 | --- | 18 | --- |
9 | include/hw/arm/aspeed_soc.h | 3 +++ | 19 | target/hppa/fpu_helper.c | 1 + |
10 | hw/arm/aspeed_soc.c | 17 +++++++++++++++++ | 20 | target/sh4/cpu.c | 1 + |
11 | 2 files changed, 20 insertions(+) | 21 | fpu/softfloat-specialize.c.inc | 7 ------- |
22 | 3 files changed, 2 insertions(+), 7 deletions(-) | ||
12 | 23 | ||
13 | diff --git a/include/hw/arm/aspeed_soc.h b/include/hw/arm/aspeed_soc.h | 24 | diff --git a/target/hppa/fpu_helper.c b/target/hppa/fpu_helper.c |
14 | index XXXXXXX..XXXXXXX 100644 | 25 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/include/hw/arm/aspeed_soc.h | 26 | --- a/target/hppa/fpu_helper.c |
16 | +++ b/include/hw/arm/aspeed_soc.h | 27 | +++ b/target/hppa/fpu_helper.c |
17 | @@ -XXX,XX +XXX,XX @@ | 28 | @@ -XXX,XX +XXX,XX @@ void HELPER(loaded_fr0)(CPUHPPAState *env) |
18 | #include "hw/watchdog/wdt_aspeed.h" | 29 | set_float_infzeronan_rule(float_infzeronan_dnan_never, &env->fp_status); |
19 | #include "hw/net/ftgmac100.h" | 30 | /* Default NaN: sign bit clear, msb-1 frac bit set */ |
20 | #include "target/arm/cpu.h" | 31 | set_float_default_nan_pattern(0b00100000, &env->fp_status); |
21 | +#include "hw/gpio/aspeed_gpio.h" | 32 | + set_snan_bit_is_one(true, &env->fp_status); |
22 | 33 | /* | |
23 | #define ASPEED_SPIS_NUM 2 | 34 | * "PA-RISC 2.0 Architecture" says it is IMPDEF whether the flushing |
24 | #define ASPEED_WDTS_NUM 3 | 35 | * enabled by FPSR.D happens before or after rounding. We pick "before" |
25 | @@ -XXX,XX +XXX,XX @@ typedef struct AspeedSoCState { | 36 | diff --git a/target/sh4/cpu.c b/target/sh4/cpu.c |
26 | AspeedSDMCState sdmc; | ||
27 | AspeedWDTState wdt[ASPEED_WDTS_NUM]; | ||
28 | FTGMAC100State ftgmac100[ASPEED_MACS_NUM]; | ||
29 | + AspeedGPIOState gpio; | ||
30 | } AspeedSoCState; | ||
31 | |||
32 | #define TYPE_ASPEED_SOC "aspeed-soc" | ||
33 | @@ -XXX,XX +XXX,XX @@ typedef struct AspeedSoCInfo { | ||
34 | int spis_num; | ||
35 | const char *fmc_typename; | ||
36 | const char **spi_typename; | ||
37 | + const char *gpio_typename; | ||
38 | int wdts_num; | ||
39 | const int *irqmap; | ||
40 | const hwaddr *memmap; | ||
41 | diff --git a/hw/arm/aspeed_soc.c b/hw/arm/aspeed_soc.c | ||
42 | index XXXXXXX..XXXXXXX 100644 | 37 | index XXXXXXX..XXXXXXX 100644 |
43 | --- a/hw/arm/aspeed_soc.c | 38 | --- a/target/sh4/cpu.c |
44 | +++ b/hw/arm/aspeed_soc.c | 39 | +++ b/target/sh4/cpu.c |
45 | @@ -XXX,XX +XXX,XX @@ static const AspeedSoCInfo aspeed_socs[] = { | 40 | @@ -XXX,XX +XXX,XX @@ static void superh_cpu_reset_hold(Object *obj, ResetType type) |
46 | .spis_num = 1, | 41 | set_flush_to_zero(1, &env->fp_status); |
47 | .fmc_typename = "aspeed.smc.fmc", | 42 | #endif |
48 | .spi_typename = aspeed_soc_ast2400_typenames, | 43 | set_default_nan_mode(1, &env->fp_status); |
49 | + .gpio_typename = "aspeed.gpio-ast2400", | 44 | + set_snan_bit_is_one(true, &env->fp_status); |
50 | .wdts_num = 2, | 45 | /* sign bit clear, set all frac bits other than msb */ |
51 | .irqmap = aspeed_soc_ast2400_irqmap, | 46 | set_float_default_nan_pattern(0b00111111, &env->fp_status); |
52 | .memmap = aspeed_soc_ast2400_memmap, | 47 | /* |
53 | @@ -XXX,XX +XXX,XX @@ static const AspeedSoCInfo aspeed_socs[] = { | 48 | diff --git a/fpu/softfloat-specialize.c.inc b/fpu/softfloat-specialize.c.inc |
54 | .spis_num = 1, | 49 | index XXXXXXX..XXXXXXX 100644 |
55 | .fmc_typename = "aspeed.smc.fmc", | 50 | --- a/fpu/softfloat-specialize.c.inc |
56 | .spi_typename = aspeed_soc_ast2400_typenames, | 51 | +++ b/fpu/softfloat-specialize.c.inc |
57 | + .gpio_typename = "aspeed.gpio-ast2400", | 52 | @@ -XXX,XX +XXX,XX @@ static inline bool no_signaling_nans(float_status *status) |
58 | .wdts_num = 2, | 53 | * In IEEE 754-1985 this was implementation defined, but in IEEE 754-2008 |
59 | .irqmap = aspeed_soc_ast2400_irqmap, | 54 | * the msb must be zero. MIPS is (so far) unique in supporting both the |
60 | .memmap = aspeed_soc_ast2400_memmap, | 55 | * 2008 revision and backward compatibility with their original choice. |
61 | @@ -XXX,XX +XXX,XX @@ static const AspeedSoCInfo aspeed_socs[] = { | 56 | - * Thus for MIPS we must make the choice at runtime. |
62 | .spis_num = 1, | 57 | */ |
63 | .fmc_typename = "aspeed.smc.fmc", | 58 | static inline bool snan_bit_is_one(float_status *status) |
64 | .spi_typename = aspeed_soc_ast2400_typenames, | 59 | { |
65 | + .gpio_typename = "aspeed.gpio-ast2400", | 60 | -#if defined(TARGET_MIPS) |
66 | .wdts_num = 2, | 61 | return status->snan_bit_is_one; |
67 | .irqmap = aspeed_soc_ast2400_irqmap, | 62 | -#elif defined(TARGET_HPPA) || defined(TARGET_SH4) |
68 | .memmap = aspeed_soc_ast2400_memmap, | 63 | - return 1; |
69 | @@ -XXX,XX +XXX,XX @@ static const AspeedSoCInfo aspeed_socs[] = { | 64 | -#else |
70 | .spis_num = 2, | 65 | - return 0; |
71 | .fmc_typename = "aspeed.smc.ast2500-fmc", | 66 | -#endif |
72 | .spi_typename = aspeed_soc_ast2500_typenames, | ||
73 | + .gpio_typename = "aspeed.gpio-ast2500", | ||
74 | .wdts_num = 3, | ||
75 | .irqmap = aspeed_soc_ast2500_irqmap, | ||
76 | .memmap = aspeed_soc_ast2500_memmap, | ||
77 | @@ -XXX,XX +XXX,XX @@ static void aspeed_soc_init(Object *obj) | ||
78 | |||
79 | sysbus_init_child_obj(obj, "xdma", OBJECT(&s->xdma), sizeof(s->xdma), | ||
80 | TYPE_ASPEED_XDMA); | ||
81 | + | ||
82 | + sysbus_init_child_obj(obj, "gpio", OBJECT(&s->gpio), sizeof(s->gpio), | ||
83 | + sc->info->gpio_typename); | ||
84 | } | 67 | } |
85 | 68 | ||
86 | static void aspeed_soc_realize(DeviceState *dev, Error **errp) | 69 | /*---------------------------------------------------------------------------- |
87 | @@ -XXX,XX +XXX,XX @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp) | ||
88 | sc->info->memmap[ASPEED_XDMA]); | ||
89 | sysbus_connect_irq(SYS_BUS_DEVICE(&s->xdma), 0, | ||
90 | aspeed_soc_get_irq(s, ASPEED_XDMA)); | ||
91 | + | ||
92 | + /* GPIO */ | ||
93 | + object_property_set_bool(OBJECT(&s->gpio), true, "realized", &err); | ||
94 | + if (err) { | ||
95 | + error_propagate(errp, err); | ||
96 | + return; | ||
97 | + } | ||
98 | + sysbus_mmio_map(SYS_BUS_DEVICE(&s->gpio), 0, sc->info->memmap[ASPEED_GPIO]); | ||
99 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->gpio), 0, | ||
100 | + aspeed_soc_get_irq(s, ASPEED_GPIO)); | ||
101 | } | ||
102 | static Property aspeed_soc_properties[] = { | ||
103 | DEFINE_PROP_UINT32("num-cpus", AspeedSoCState, num_cpus, 0), | ||
104 | -- | 70 | -- |
105 | 2.20.1 | 71 | 2.43.0 |
106 | 72 | ||
107 | 73 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | We happen to know that for the PPC target the FP status flags (and in | ||
2 | particular float_flag_inexact) will always be cleared before a | ||
3 | floating point operation, and so can_use_fpu() will always return | ||
4 | false. So we speed things up a little by forcing QEMU_NO_HARDFLOAT | ||
5 | to true on that target. | ||
1 | 6 | ||
7 | We would like to build softfloat once for all targets; that means | ||
8 | removing target-specific ifdefs. Remove the check for TARGET_PPC; | ||
9 | this won't change behaviour because can_use_fpu() will see that | ||
10 | float_flag_inexact is clear and take the softfloat path anyway. | ||
11 | |||
12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
13 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
14 | Message-id: 20250224111524.1101196-12-peter.maydell@linaro.org | ||
15 | Message-id: 20250217125055.160887-10-peter.maydell@linaro.org | ||
16 | --- | ||
17 | fpu/softfloat.c | 2 -- | ||
18 | 1 file changed, 2 deletions(-) | ||
19 | |||
20 | diff --git a/fpu/softfloat.c b/fpu/softfloat.c | ||
21 | index XXXXXXX..XXXXXXX 100644 | ||
22 | --- a/fpu/softfloat.c | ||
23 | +++ b/fpu/softfloat.c | ||
24 | @@ -XXX,XX +XXX,XX @@ GEN_INPUT_FLUSH3(float64_input_flush3, float64) | ||
25 | * the use of hardfloat, since hardfloat relies on the inexact flag being | ||
26 | * already set. | ||
27 | */ | ||
28 | -#if defined(TARGET_PPC) || defined(__FAST_MATH__) | ||
29 | # if defined(__FAST_MATH__) | ||
30 | # warning disabling hardfloat due to -ffast-math: hardfloat requires an exact \ | ||
31 | IEEE implementation | ||
32 | -# endif | ||
33 | # define QEMU_NO_HARDFLOAT 1 | ||
34 | # define QEMU_SOFTFLOAT_ATTR QEMU_FLATTEN | ||
35 | #else | ||
36 | -- | ||
37 | 2.43.0 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Now we have removed all the target-specifics from the softfloat code, | ||
2 | we can switch to building it once for the whole system rather than | ||
3 | once per target. | ||
1 | 4 | ||
5 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
6 | Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
7 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Message-id: 20250224111524.1101196-13-peter.maydell@linaro.org | ||
9 | Message-id: 20250217125055.160887-11-peter.maydell@linaro.org | ||
10 | --- | ||
11 | fpu/softfloat.c | 3 --- | ||
12 | fpu/meson.build | 2 +- | ||
13 | 2 files changed, 1 insertion(+), 4 deletions(-) | ||
14 | |||
15 | diff --git a/fpu/softfloat.c b/fpu/softfloat.c | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/fpu/softfloat.c | ||
18 | +++ b/fpu/softfloat.c | ||
19 | @@ -XXX,XX +XXX,XX @@ this code that are retained. | ||
20 | * version 2 or later. See the COPYING file in the top-level directory. | ||
21 | */ | ||
22 | |||
23 | -/* softfloat (and in particular the code in softfloat-specialize.h) is | ||
24 | - * target-dependent and needs the TARGET_* macros. | ||
25 | - */ | ||
26 | #include "qemu/osdep.h" | ||
27 | #include <math.h> | ||
28 | #include "qemu/bitops.h" | ||
29 | diff --git a/fpu/meson.build b/fpu/meson.build | ||
30 | index XXXXXXX..XXXXXXX 100644 | ||
31 | --- a/fpu/meson.build | ||
32 | +++ b/fpu/meson.build | ||
33 | @@ -1 +1 @@ | ||
34 | -specific_ss.add(when: 'CONFIG_TCG', if_true: files('softfloat.c')) | ||
35 | +common_ss.add(when: 'CONFIG_TCG', if_true: files('softfloat.c')) | ||
36 | -- | ||
37 | 2.43.0 | ||
38 | |||
39 | diff view generated by jsdifflib |
1 | From: Cédric Le Goater <clg@kaod.org> | 1 | Most of the target/arm/vfp_helper.c file is purely TCG helper code, |
---|---|---|---|
2 | guarded by #ifdef CONFIG_TCG. Move this into a new file in | ||
3 | target/arm/tcg/. | ||
2 | 4 | ||
3 | and use a class AspeedSCUClass to define each SoC characteristics. | 5 | This leaves only the code relating to getting and setting the |
6 | FPCR/FPSR/FPSCR in the original file. (Some of this also is | ||
7 | TCG-only, but that needs more careful disentangling.) | ||
4 | 8 | ||
5 | Signed-off-by: Cédric Le Goater <clg@kaod.org> | 9 | Having two vfp_helper.c files might seem a bit confusing, |
6 | Message-id: 20190904070506.1052-10-clg@kaod.org | 10 | but once we've finished moving all the helper code out |
7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 11 | of the old file we are going to rename it to vfp_fpscr.c. |
12 | |||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 13 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
14 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
15 | Message-id: 20250221190957.811948-2-peter.maydell@linaro.org | ||
9 | --- | 16 | --- |
10 | include/hw/misc/aspeed_scu.h | 15 +++++++ | 17 | target/arm/{ => tcg}/vfp_helper.c | 399 +---------- |
11 | hw/arm/aspeed_soc.c | 3 +- | 18 | target/arm/vfp_helper.c | 1109 ----------------------------- |
12 | hw/misc/aspeed_scu.c | 83 ++++++++++++++++++++---------------- | 19 | target/arm/tcg/meson.build | 1 + |
13 | 3 files changed, 64 insertions(+), 37 deletions(-) | 20 | 3 files changed, 4 insertions(+), 1505 deletions(-) |
21 | copy target/arm/{ => tcg}/vfp_helper.c (71%) | ||
14 | 22 | ||
15 | diff --git a/include/hw/misc/aspeed_scu.h b/include/hw/misc/aspeed_scu.h | 23 | diff --git a/target/arm/vfp_helper.c b/target/arm/tcg/vfp_helper.c |
24 | similarity index 71% | ||
25 | copy from target/arm/vfp_helper.c | ||
26 | copy to target/arm/tcg/vfp_helper.c | ||
16 | index XXXXXXX..XXXXXXX 100644 | 27 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/include/hw/misc/aspeed_scu.h | 28 | --- a/target/arm/vfp_helper.c |
18 | +++ b/include/hw/misc/aspeed_scu.h | 29 | +++ b/target/arm/tcg/vfp_helper.c |
19 | @@ -XXX,XX +XXX,XX @@ | 30 | @@ -XXX,XX +XXX,XX @@ |
20 | 31 | #include "internals.h" | |
21 | #define TYPE_ASPEED_SCU "aspeed.scu" | 32 | #include "cpu-features.h" |
22 | #define ASPEED_SCU(obj) OBJECT_CHECK(AspeedSCUState, (obj), TYPE_ASPEED_SCU) | 33 | #include "fpu/softfloat.h" |
23 | +#define TYPE_ASPEED_2400_SCU TYPE_ASPEED_SCU "-ast2400" | 34 | -#ifdef CONFIG_TCG |
24 | +#define TYPE_ASPEED_2500_SCU TYPE_ASPEED_SCU "-ast2500" | 35 | #include "qemu/log.h" |
25 | 36 | -#endif | |
26 | #define ASPEED_SCU_NR_REGS (0x1A8 >> 2) | 37 | - |
27 | 38 | -/* VFP support. We follow the convention used for VFP instructions: | |
28 | @@ -XXX,XX +XXX,XX @@ typedef struct AspeedSCUState { | 39 | - Single precision routines have a "s" suffix, double precision a |
29 | 40 | - "d" suffix. */ | |
30 | extern bool is_supported_silicon_rev(uint32_t silicon_rev); | ||
31 | |||
32 | +#define ASPEED_SCU_CLASS(klass) \ | ||
33 | + OBJECT_CLASS_CHECK(AspeedSCUClass, (klass), TYPE_ASPEED_SCU) | ||
34 | +#define ASPEED_SCU_GET_CLASS(obj) \ | ||
35 | + OBJECT_GET_CLASS(AspeedSCUClass, (obj), TYPE_ASPEED_SCU) | ||
36 | + | ||
37 | +typedef struct AspeedSCUClass { | ||
38 | + SysBusDeviceClass parent_class; | ||
39 | + | ||
40 | + const uint32_t *resets; | ||
41 | + uint32_t (*calc_hpll)(AspeedSCUState *s); | ||
42 | + uint32_t apb_divider; | ||
43 | +} AspeedSCUClass; | ||
44 | + | ||
45 | #define ASPEED_SCU_PROT_KEY 0x1688A8A8 | ||
46 | 41 | ||
47 | /* | 42 | /* |
48 | diff --git a/hw/arm/aspeed_soc.c b/hw/arm/aspeed_soc.c | 43 | - * Set the float_status behaviour to match the Arm defaults: |
44 | - * * tininess-before-rounding | ||
45 | - * * 2-input NaN propagation prefers SNaN over QNaN, and then | ||
46 | - * operand A over operand B (see FPProcessNaNs() pseudocode) | ||
47 | - * * 3-input NaN propagation prefers SNaN over QNaN, and then | ||
48 | - * operand C over A over B (see FPProcessNaNs3() pseudocode, | ||
49 | - * but note that for QEMU muladd is a * b + c, whereas for | ||
50 | - * the pseudocode function the arguments are in the order c, a, b. | ||
51 | - * * 0 * Inf + NaN returns the default NaN if the input NaN is quiet, | ||
52 | - * and the input NaN if it is signalling | ||
53 | - * * Default NaN has sign bit clear, msb frac bit set | ||
54 | + * VFP support. We follow the convention used for VFP instructions: | ||
55 | + * Single precision routines have a "s" suffix, double precision a | ||
56 | + * "d" suffix. | ||
57 | */ | ||
58 | -void arm_set_default_fp_behaviours(float_status *s) | ||
59 | -{ | ||
60 | - set_float_detect_tininess(float_tininess_before_rounding, s); | ||
61 | - set_float_ftz_detection(float_ftz_before_rounding, s); | ||
62 | - set_float_2nan_prop_rule(float_2nan_prop_s_ab, s); | ||
63 | - set_float_3nan_prop_rule(float_3nan_prop_s_cab, s); | ||
64 | - set_float_infzeronan_rule(float_infzeronan_dnan_if_qnan, s); | ||
65 | - set_float_default_nan_pattern(0b01000000, s); | ||
66 | -} | ||
67 | - | ||
68 | -/* | ||
69 | - * Set the float_status behaviour to match the FEAT_AFP | ||
70 | - * FPCR.AH=1 requirements: | ||
71 | - * * tininess-after-rounding | ||
72 | - * * 2-input NaN propagation prefers the first NaN | ||
73 | - * * 3-input NaN propagation prefers a over b over c | ||
74 | - * * 0 * Inf + NaN always returns the input NaN and doesn't | ||
75 | - * set Invalid for a QNaN | ||
76 | - * * default NaN has sign bit set, msb frac bit set | ||
77 | - */ | ||
78 | -void arm_set_ah_fp_behaviours(float_status *s) | ||
79 | -{ | ||
80 | - set_float_detect_tininess(float_tininess_after_rounding, s); | ||
81 | - set_float_ftz_detection(float_ftz_after_rounding, s); | ||
82 | - set_float_2nan_prop_rule(float_2nan_prop_ab, s); | ||
83 | - set_float_3nan_prop_rule(float_3nan_prop_abc, s); | ||
84 | - set_float_infzeronan_rule(float_infzeronan_dnan_never | | ||
85 | - float_infzeronan_suppress_invalid, s); | ||
86 | - set_float_default_nan_pattern(0b11000000, s); | ||
87 | -} | ||
88 | - | ||
89 | -#ifdef CONFIG_TCG | ||
90 | - | ||
91 | -/* Convert host exception flags to vfp form. */ | ||
92 | -static inline uint32_t vfp_exceptbits_from_host(int host_bits, bool ah) | ||
93 | -{ | ||
94 | - uint32_t target_bits = 0; | ||
95 | - | ||
96 | - if (host_bits & float_flag_invalid) { | ||
97 | - target_bits |= FPSR_IOC; | ||
98 | - } | ||
99 | - if (host_bits & float_flag_divbyzero) { | ||
100 | - target_bits |= FPSR_DZC; | ||
101 | - } | ||
102 | - if (host_bits & float_flag_overflow) { | ||
103 | - target_bits |= FPSR_OFC; | ||
104 | - } | ||
105 | - if (host_bits & (float_flag_underflow | float_flag_output_denormal_flushed)) { | ||
106 | - target_bits |= FPSR_UFC; | ||
107 | - } | ||
108 | - if (host_bits & float_flag_inexact) { | ||
109 | - target_bits |= FPSR_IXC; | ||
110 | - } | ||
111 | - if (host_bits & float_flag_input_denormal_flushed) { | ||
112 | - target_bits |= FPSR_IDC; | ||
113 | - } | ||
114 | - /* | ||
115 | - * With FPCR.AH, IDC is set when an input denormal is used, | ||
116 | - * and flushing an output denormal to zero sets both IXC and UFC. | ||
117 | - */ | ||
118 | - if (ah && (host_bits & float_flag_input_denormal_used)) { | ||
119 | - target_bits |= FPSR_IDC; | ||
120 | - } | ||
121 | - if (ah && (host_bits & float_flag_output_denormal_flushed)) { | ||
122 | - target_bits |= FPSR_IXC; | ||
123 | - } | ||
124 | - return target_bits; | ||
125 | -} | ||
126 | - | ||
127 | -static uint32_t vfp_get_fpsr_from_host(CPUARMState *env) | ||
128 | -{ | ||
129 | - uint32_t a32_flags = 0, a64_flags = 0; | ||
130 | - | ||
131 | - a32_flags |= get_float_exception_flags(&env->vfp.fp_status[FPST_A32]); | ||
132 | - a32_flags |= get_float_exception_flags(&env->vfp.fp_status[FPST_STD]); | ||
133 | - /* FZ16 does not generate an input denormal exception. */ | ||
134 | - a32_flags |= (get_float_exception_flags(&env->vfp.fp_status[FPST_A32_F16]) | ||
135 | - & ~float_flag_input_denormal_flushed); | ||
136 | - a32_flags |= (get_float_exception_flags(&env->vfp.fp_status[FPST_STD_F16]) | ||
137 | - & ~float_flag_input_denormal_flushed); | ||
138 | - | ||
139 | - a64_flags |= get_float_exception_flags(&env->vfp.fp_status[FPST_A64]); | ||
140 | - a64_flags |= (get_float_exception_flags(&env->vfp.fp_status[FPST_A64_F16]) | ||
141 | - & ~(float_flag_input_denormal_flushed | float_flag_input_denormal_used)); | ||
142 | - /* | ||
143 | - * We do not merge in flags from FPST_AH or FPST_AH_F16, because | ||
144 | - * they are used for insns that must not set the cumulative exception bits. | ||
145 | - */ | ||
146 | - | ||
147 | - /* | ||
148 | - * Flushing an input denormal *only* because FPCR.FIZ == 1 does | ||
149 | - * not set FPSR.IDC; if FPCR.FZ is also set then this takes | ||
150 | - * precedence and IDC is set (see the FPUnpackBase pseudocode). | ||
151 | - * So squash it unless (FPCR.AH == 0 && FPCR.FZ == 1). | ||
152 | - * We only do this for the a64 flags because FIZ has no effect | ||
153 | - * on AArch32 even if it is set. | ||
154 | - */ | ||
155 | - if ((env->vfp.fpcr & (FPCR_FZ | FPCR_AH)) != FPCR_FZ) { | ||
156 | - a64_flags &= ~float_flag_input_denormal_flushed; | ||
157 | - } | ||
158 | - return vfp_exceptbits_from_host(a64_flags, env->vfp.fpcr & FPCR_AH) | | ||
159 | - vfp_exceptbits_from_host(a32_flags, false); | ||
160 | -} | ||
161 | - | ||
162 | -static void vfp_clear_float_status_exc_flags(CPUARMState *env) | ||
163 | -{ | ||
164 | - /* | ||
165 | - * Clear out all the exception-flag information in the float_status | ||
166 | - * values. The caller should have arranged for env->vfp.fpsr to | ||
167 | - * be the architecturally up-to-date exception flag information first. | ||
168 | - */ | ||
169 | - set_float_exception_flags(0, &env->vfp.fp_status[FPST_A32]); | ||
170 | - set_float_exception_flags(0, &env->vfp.fp_status[FPST_A64]); | ||
171 | - set_float_exception_flags(0, &env->vfp.fp_status[FPST_A32_F16]); | ||
172 | - set_float_exception_flags(0, &env->vfp.fp_status[FPST_A64_F16]); | ||
173 | - set_float_exception_flags(0, &env->vfp.fp_status[FPST_STD]); | ||
174 | - set_float_exception_flags(0, &env->vfp.fp_status[FPST_STD_F16]); | ||
175 | - set_float_exception_flags(0, &env->vfp.fp_status[FPST_AH]); | ||
176 | - set_float_exception_flags(0, &env->vfp.fp_status[FPST_AH_F16]); | ||
177 | -} | ||
178 | - | ||
179 | -static void vfp_sync_and_clear_float_status_exc_flags(CPUARMState *env) | ||
180 | -{ | ||
181 | - /* | ||
182 | - * Synchronize any pending exception-flag information in the | ||
183 | - * float_status values into env->vfp.fpsr, and then clear out | ||
184 | - * the float_status data. | ||
185 | - */ | ||
186 | - env->vfp.fpsr |= vfp_get_fpsr_from_host(env); | ||
187 | - vfp_clear_float_status_exc_flags(env); | ||
188 | -} | ||
189 | - | ||
190 | -static void vfp_set_fpcr_to_host(CPUARMState *env, uint32_t val, uint32_t mask) | ||
191 | -{ | ||
192 | - uint64_t changed = env->vfp.fpcr; | ||
193 | - | ||
194 | - changed ^= val; | ||
195 | - changed &= mask; | ||
196 | - if (changed & (3 << 22)) { | ||
197 | - int i = (val >> 22) & 3; | ||
198 | - switch (i) { | ||
199 | - case FPROUNDING_TIEEVEN: | ||
200 | - i = float_round_nearest_even; | ||
201 | - break; | ||
202 | - case FPROUNDING_POSINF: | ||
203 | - i = float_round_up; | ||
204 | - break; | ||
205 | - case FPROUNDING_NEGINF: | ||
206 | - i = float_round_down; | ||
207 | - break; | ||
208 | - case FPROUNDING_ZERO: | ||
209 | - i = float_round_to_zero; | ||
210 | - break; | ||
211 | - } | ||
212 | - set_float_rounding_mode(i, &env->vfp.fp_status[FPST_A32]); | ||
213 | - set_float_rounding_mode(i, &env->vfp.fp_status[FPST_A64]); | ||
214 | - set_float_rounding_mode(i, &env->vfp.fp_status[FPST_A32_F16]); | ||
215 | - set_float_rounding_mode(i, &env->vfp.fp_status[FPST_A64_F16]); | ||
216 | - } | ||
217 | - if (changed & FPCR_FZ16) { | ||
218 | - bool ftz_enabled = val & FPCR_FZ16; | ||
219 | - set_flush_to_zero(ftz_enabled, &env->vfp.fp_status[FPST_A32_F16]); | ||
220 | - set_flush_to_zero(ftz_enabled, &env->vfp.fp_status[FPST_A64_F16]); | ||
221 | - set_flush_to_zero(ftz_enabled, &env->vfp.fp_status[FPST_STD_F16]); | ||
222 | - set_flush_to_zero(ftz_enabled, &env->vfp.fp_status[FPST_AH_F16]); | ||
223 | - set_flush_inputs_to_zero(ftz_enabled, &env->vfp.fp_status[FPST_A32_F16]); | ||
224 | - set_flush_inputs_to_zero(ftz_enabled, &env->vfp.fp_status[FPST_A64_F16]); | ||
225 | - set_flush_inputs_to_zero(ftz_enabled, &env->vfp.fp_status[FPST_STD_F16]); | ||
226 | - set_flush_inputs_to_zero(ftz_enabled, &env->vfp.fp_status[FPST_AH_F16]); | ||
227 | - } | ||
228 | - if (changed & FPCR_FZ) { | ||
229 | - bool ftz_enabled = val & FPCR_FZ; | ||
230 | - set_flush_to_zero(ftz_enabled, &env->vfp.fp_status[FPST_A32]); | ||
231 | - set_flush_to_zero(ftz_enabled, &env->vfp.fp_status[FPST_A64]); | ||
232 | - /* FIZ is A64 only so FZ always makes A32 code flush inputs to zero */ | ||
233 | - set_flush_inputs_to_zero(ftz_enabled, &env->vfp.fp_status[FPST_A32]); | ||
234 | - } | ||
235 | - if (changed & (FPCR_FZ | FPCR_AH | FPCR_FIZ)) { | ||
236 | - /* | ||
237 | - * A64: Flush denormalized inputs to zero if FPCR.FIZ = 1, or | ||
238 | - * both FPCR.AH = 0 and FPCR.FZ = 1. | ||
239 | - */ | ||
240 | - bool fitz_enabled = (val & FPCR_FIZ) || | ||
241 | - (val & (FPCR_FZ | FPCR_AH)) == FPCR_FZ; | ||
242 | - set_flush_inputs_to_zero(fitz_enabled, &env->vfp.fp_status[FPST_A64]); | ||
243 | - } | ||
244 | - if (changed & FPCR_DN) { | ||
245 | - bool dnan_enabled = val & FPCR_DN; | ||
246 | - set_default_nan_mode(dnan_enabled, &env->vfp.fp_status[FPST_A32]); | ||
247 | - set_default_nan_mode(dnan_enabled, &env->vfp.fp_status[FPST_A64]); | ||
248 | - set_default_nan_mode(dnan_enabled, &env->vfp.fp_status[FPST_A32_F16]); | ||
249 | - set_default_nan_mode(dnan_enabled, &env->vfp.fp_status[FPST_A64_F16]); | ||
250 | - set_default_nan_mode(dnan_enabled, &env->vfp.fp_status[FPST_AH]); | ||
251 | - set_default_nan_mode(dnan_enabled, &env->vfp.fp_status[FPST_AH_F16]); | ||
252 | - } | ||
253 | - if (changed & FPCR_AH) { | ||
254 | - bool ah_enabled = val & FPCR_AH; | ||
255 | - | ||
256 | - if (ah_enabled) { | ||
257 | - /* Change behaviours for A64 FP operations */ | ||
258 | - arm_set_ah_fp_behaviours(&env->vfp.fp_status[FPST_A64]); | ||
259 | - arm_set_ah_fp_behaviours(&env->vfp.fp_status[FPST_A64_F16]); | ||
260 | - } else { | ||
261 | - arm_set_default_fp_behaviours(&env->vfp.fp_status[FPST_A64]); | ||
262 | - arm_set_default_fp_behaviours(&env->vfp.fp_status[FPST_A64_F16]); | ||
263 | - } | ||
264 | - } | ||
265 | - /* | ||
266 | - * If any bits changed that we look at in vfp_get_fpsr_from_host(), | ||
267 | - * we must sync the float_status flags into vfp.fpsr now (under the | ||
268 | - * old regime) before we update vfp.fpcr. | ||
269 | - */ | ||
270 | - if (changed & (FPCR_FZ | FPCR_AH | FPCR_FIZ)) { | ||
271 | - vfp_sync_and_clear_float_status_exc_flags(env); | ||
272 | - } | ||
273 | -} | ||
274 | - | ||
275 | -#else | ||
276 | - | ||
277 | -static uint32_t vfp_get_fpsr_from_host(CPUARMState *env) | ||
278 | -{ | ||
279 | - return 0; | ||
280 | -} | ||
281 | - | ||
282 | -static void vfp_clear_float_status_exc_flags(CPUARMState *env) | ||
283 | -{ | ||
284 | -} | ||
285 | - | ||
286 | -static void vfp_set_fpcr_to_host(CPUARMState *env, uint32_t val, uint32_t mask) | ||
287 | -{ | ||
288 | -} | ||
289 | - | ||
290 | -#endif | ||
291 | - | ||
292 | -uint32_t vfp_get_fpcr(CPUARMState *env) | ||
293 | -{ | ||
294 | - uint32_t fpcr = env->vfp.fpcr | ||
295 | - | (env->vfp.vec_len << 16) | ||
296 | - | (env->vfp.vec_stride << 20); | ||
297 | - | ||
298 | - /* | ||
299 | - * M-profile LTPSIZE is the same bits [18:16] as A-profile Len; whichever | ||
300 | - * of the two is not applicable to this CPU will always be zero. | ||
301 | - */ | ||
302 | - fpcr |= env->v7m.ltpsize << 16; | ||
303 | - | ||
304 | - return fpcr; | ||
305 | -} | ||
306 | - | ||
307 | -uint32_t vfp_get_fpsr(CPUARMState *env) | ||
308 | -{ | ||
309 | - uint32_t fpsr = env->vfp.fpsr; | ||
310 | - uint32_t i; | ||
311 | - | ||
312 | - fpsr |= vfp_get_fpsr_from_host(env); | ||
313 | - | ||
314 | - i = env->vfp.qc[0] | env->vfp.qc[1] | env->vfp.qc[2] | env->vfp.qc[3]; | ||
315 | - fpsr |= i ? FPSR_QC : 0; | ||
316 | - return fpsr; | ||
317 | -} | ||
318 | - | ||
319 | -uint32_t HELPER(vfp_get_fpscr)(CPUARMState *env) | ||
320 | -{ | ||
321 | - return (vfp_get_fpcr(env) & FPSCR_FPCR_MASK) | | ||
322 | - (vfp_get_fpsr(env) & FPSCR_FPSR_MASK); | ||
323 | -} | ||
324 | - | ||
325 | -uint32_t vfp_get_fpscr(CPUARMState *env) | ||
326 | -{ | ||
327 | - return HELPER(vfp_get_fpscr)(env); | ||
328 | -} | ||
329 | - | ||
330 | -void vfp_set_fpsr(CPUARMState *env, uint32_t val) | ||
331 | -{ | ||
332 | - ARMCPU *cpu = env_archcpu(env); | ||
333 | - | ||
334 | - if (arm_feature(env, ARM_FEATURE_NEON) || | ||
335 | - cpu_isar_feature(aa32_mve, cpu)) { | ||
336 | - /* | ||
337 | - * The bit we set within vfp.qc[] is arbitrary; the array as a | ||
338 | - * whole being zero/non-zero is what counts. | ||
339 | - */ | ||
340 | - env->vfp.qc[0] = val & FPSR_QC; | ||
341 | - env->vfp.qc[1] = 0; | ||
342 | - env->vfp.qc[2] = 0; | ||
343 | - env->vfp.qc[3] = 0; | ||
344 | - } | ||
345 | - | ||
346 | - /* | ||
347 | - * NZCV lives only in env->vfp.fpsr. The cumulative exception flags | ||
348 | - * IOC|DZC|OFC|UFC|IXC|IDC also live in env->vfp.fpsr, with possible | ||
349 | - * extra pending exception information that hasn't yet been folded in | ||
350 | - * living in the float_status values (for TCG). | ||
351 | - * Since this FPSR write gives us the up to date values of the exception | ||
352 | - * flags, we want to store into vfp.fpsr the NZCV and CEXC bits, zeroing | ||
353 | - * anything else. We also need to clear out the float_status exception | ||
354 | - * information so that the next vfp_get_fpsr does not fold in stale data. | ||
355 | - */ | ||
356 | - val &= FPSR_NZCV_MASK | FPSR_CEXC_MASK; | ||
357 | - env->vfp.fpsr = val; | ||
358 | - vfp_clear_float_status_exc_flags(env); | ||
359 | -} | ||
360 | - | ||
361 | -static void vfp_set_fpcr_masked(CPUARMState *env, uint32_t val, uint32_t mask) | ||
362 | -{ | ||
363 | - /* | ||
364 | - * We only set FPCR bits defined by mask, and leave the others alone. | ||
365 | - * We assume the mask is sensible (e.g. doesn't try to set only | ||
366 | - * part of a field) | ||
367 | - */ | ||
368 | - ARMCPU *cpu = env_archcpu(env); | ||
369 | - | ||
370 | - /* When ARMv8.2-FP16 is not supported, FZ16 is RES0. */ | ||
371 | - if (!cpu_isar_feature(any_fp16, cpu)) { | ||
372 | - val &= ~FPCR_FZ16; | ||
373 | - } | ||
374 | - if (!cpu_isar_feature(aa64_afp, cpu)) { | ||
375 | - val &= ~(FPCR_FIZ | FPCR_AH | FPCR_NEP); | ||
376 | - } | ||
377 | - | ||
378 | - if (!cpu_isar_feature(aa64_ebf16, cpu)) { | ||
379 | - val &= ~FPCR_EBF; | ||
380 | - } | ||
381 | - | ||
382 | - vfp_set_fpcr_to_host(env, val, mask); | ||
383 | - | ||
384 | - if (mask & (FPCR_LEN_MASK | FPCR_STRIDE_MASK)) { | ||
385 | - if (!arm_feature(env, ARM_FEATURE_M)) { | ||
386 | - /* | ||
387 | - * Short-vector length and stride; on M-profile these bits | ||
388 | - * are used for different purposes. | ||
389 | - * We can't make this conditional be "if MVFR0.FPShVec != 0", | ||
390 | - * because in v7A no-short-vector-support cores still had to | ||
391 | - * allow Stride/Len to be written with the only effect that | ||
392 | - * some insns are required to UNDEF if the guest sets them. | ||
393 | - */ | ||
394 | - env->vfp.vec_len = extract32(val, 16, 3); | ||
395 | - env->vfp.vec_stride = extract32(val, 20, 2); | ||
396 | - } else if (cpu_isar_feature(aa32_mve, cpu)) { | ||
397 | - env->v7m.ltpsize = extract32(val, FPCR_LTPSIZE_SHIFT, | ||
398 | - FPCR_LTPSIZE_LENGTH); | ||
399 | - } | ||
400 | - } | ||
401 | - | ||
402 | - /* | ||
403 | - * We don't implement trapped exception handling, so the | ||
404 | - * trap enable bits, IDE|IXE|UFE|OFE|DZE|IOE are all RAZ/WI (not RES0!) | ||
405 | - * | ||
406 | - * The FPCR bits we keep in vfp.fpcr are AHP, DN, FZ, RMode, EBF, FZ16, | ||
407 | - * FIZ, AH, and NEP. | ||
408 | - * Len, Stride and LTPSIZE we just handled. Store those bits | ||
409 | - * there, and zero any of the other FPCR bits and the RES0 and RAZ/WI | ||
410 | - * bits. | ||
411 | - */ | ||
412 | - val &= FPCR_AHP | FPCR_DN | FPCR_FZ | FPCR_RMODE_MASK | FPCR_FZ16 | | ||
413 | - FPCR_EBF | FPCR_FIZ | FPCR_AH | FPCR_NEP; | ||
414 | - env->vfp.fpcr &= ~mask; | ||
415 | - env->vfp.fpcr |= val; | ||
416 | -} | ||
417 | - | ||
418 | -void vfp_set_fpcr(CPUARMState *env, uint32_t val) | ||
419 | -{ | ||
420 | - vfp_set_fpcr_masked(env, val, MAKE_64BIT_MASK(0, 32)); | ||
421 | -} | ||
422 | - | ||
423 | -void HELPER(vfp_set_fpscr)(CPUARMState *env, uint32_t val) | ||
424 | -{ | ||
425 | - vfp_set_fpcr_masked(env, val, FPSCR_FPCR_MASK); | ||
426 | - vfp_set_fpsr(env, val & FPSCR_FPSR_MASK); | ||
427 | -} | ||
428 | - | ||
429 | -void vfp_set_fpscr(CPUARMState *env, uint32_t val) | ||
430 | -{ | ||
431 | - HELPER(vfp_set_fpscr)(env, val); | ||
432 | -} | ||
433 | - | ||
434 | -#ifdef CONFIG_TCG | ||
435 | |||
436 | #define VFP_HELPER(name, p) HELPER(glue(glue(vfp_,name),p)) | ||
437 | |||
438 | @@ -XXX,XX +XXX,XX @@ void HELPER(check_hcr_el2_trap)(CPUARMState *env, uint32_t rt, uint32_t reg) | ||
439 | |||
440 | raise_exception(env, EXCP_HYP_TRAP, syndrome, 2); | ||
441 | } | ||
442 | - | ||
443 | -#endif | ||
444 | diff --git a/target/arm/vfp_helper.c b/target/arm/vfp_helper.c | ||
49 | index XXXXXXX..XXXXXXX 100644 | 445 | index XXXXXXX..XXXXXXX 100644 |
50 | --- a/hw/arm/aspeed_soc.c | 446 | --- a/target/arm/vfp_helper.c |
51 | +++ b/hw/arm/aspeed_soc.c | 447 | +++ b/target/arm/vfp_helper.c |
52 | @@ -XXX,XX +XXX,XX @@ static void aspeed_soc_init(Object *obj) | 448 | @@ -XXX,XX +XXX,XX @@ |
53 | &error_abort, NULL); | 449 | #include "internals.h" |
54 | } | 450 | #include "cpu-features.h" |
55 | 451 | #include "fpu/softfloat.h" | |
56 | + snprintf(typename, sizeof(typename), "aspeed.scu-%s", socname); | 452 | -#ifdef CONFIG_TCG |
57 | sysbus_init_child_obj(obj, "scu", OBJECT(&s->scu), sizeof(s->scu), | 453 | -#include "qemu/log.h" |
58 | - TYPE_ASPEED_SCU); | 454 | -#endif |
59 | + typename); | 455 | - |
60 | qdev_prop_set_uint32(DEVICE(&s->scu), "silicon-rev", | 456 | -/* VFP support. We follow the convention used for VFP instructions: |
61 | sc->info->silicon_rev); | 457 | - Single precision routines have a "s" suffix, double precision a |
62 | object_property_add_alias(obj, "hw-strap1", OBJECT(&s->scu), | 458 | - "d" suffix. */ |
63 | diff --git a/hw/misc/aspeed_scu.c b/hw/misc/aspeed_scu.c | 459 | |
64 | index XXXXXXX..XXXXXXX 100644 | 460 | /* |
65 | --- a/hw/misc/aspeed_scu.c | 461 | * Set the float_status behaviour to match the Arm defaults: |
66 | +++ b/hw/misc/aspeed_scu.c | 462 | @@ -XXX,XX +XXX,XX @@ void vfp_set_fpscr(CPUARMState *env, uint32_t val) |
67 | @@ -XXX,XX +XXX,XX @@ static uint32_t aspeed_scu_get_random(void) | ||
68 | |||
69 | static void aspeed_scu_set_apb_freq(AspeedSCUState *s) | ||
70 | { | 463 | { |
71 | - uint32_t apb_divider; | 464 | HELPER(vfp_set_fpscr)(env, val); |
72 | - | 465 | } |
73 | - switch (s->silicon_rev) { | 466 | - |
74 | - case AST2400_A0_SILICON_REV: | 467 | -#ifdef CONFIG_TCG |
75 | - case AST2400_A1_SILICON_REV: | 468 | - |
76 | - apb_divider = 2; | 469 | -#define VFP_HELPER(name, p) HELPER(glue(glue(vfp_,name),p)) |
470 | - | ||
471 | -#define VFP_BINOP(name) \ | ||
472 | -dh_ctype_f16 VFP_HELPER(name, h)(dh_ctype_f16 a, dh_ctype_f16 b, float_status *fpst) \ | ||
473 | -{ \ | ||
474 | - return float16_ ## name(a, b, fpst); \ | ||
475 | -} \ | ||
476 | -float32 VFP_HELPER(name, s)(float32 a, float32 b, float_status *fpst) \ | ||
477 | -{ \ | ||
478 | - return float32_ ## name(a, b, fpst); \ | ||
479 | -} \ | ||
480 | -float64 VFP_HELPER(name, d)(float64 a, float64 b, float_status *fpst) \ | ||
481 | -{ \ | ||
482 | - return float64_ ## name(a, b, fpst); \ | ||
483 | -} | ||
484 | -VFP_BINOP(add) | ||
485 | -VFP_BINOP(sub) | ||
486 | -VFP_BINOP(mul) | ||
487 | -VFP_BINOP(div) | ||
488 | -VFP_BINOP(min) | ||
489 | -VFP_BINOP(max) | ||
490 | -VFP_BINOP(minnum) | ||
491 | -VFP_BINOP(maxnum) | ||
492 | -#undef VFP_BINOP | ||
493 | - | ||
494 | -dh_ctype_f16 VFP_HELPER(sqrt, h)(dh_ctype_f16 a, float_status *fpst) | ||
495 | -{ | ||
496 | - return float16_sqrt(a, fpst); | ||
497 | -} | ||
498 | - | ||
499 | -float32 VFP_HELPER(sqrt, s)(float32 a, float_status *fpst) | ||
500 | -{ | ||
501 | - return float32_sqrt(a, fpst); | ||
502 | -} | ||
503 | - | ||
504 | -float64 VFP_HELPER(sqrt, d)(float64 a, float_status *fpst) | ||
505 | -{ | ||
506 | - return float64_sqrt(a, fpst); | ||
507 | -} | ||
508 | - | ||
509 | -static void softfloat_to_vfp_compare(CPUARMState *env, FloatRelation cmp) | ||
510 | -{ | ||
511 | - uint32_t flags; | ||
512 | - switch (cmp) { | ||
513 | - case float_relation_equal: | ||
514 | - flags = 0x6; | ||
77 | - break; | 515 | - break; |
78 | - case AST2500_A0_SILICON_REV: | 516 | - case float_relation_less: |
79 | - case AST2500_A1_SILICON_REV: | 517 | - flags = 0x8; |
80 | - apb_divider = 4; | 518 | - break; |
519 | - case float_relation_greater: | ||
520 | - flags = 0x2; | ||
521 | - break; | ||
522 | - case float_relation_unordered: | ||
523 | - flags = 0x3; | ||
81 | - break; | 524 | - break; |
82 | - default: | 525 | - default: |
83 | - g_assert_not_reached(); | 526 | - g_assert_not_reached(); |
84 | - } | 527 | - } |
85 | + AspeedSCUClass *asc = ASPEED_SCU_GET_CLASS(s); | 528 | - env->vfp.fpsr = deposit64(env->vfp.fpsr, 28, 4, flags); /* NZCV */ |
86 | 529 | -} | |
87 | s->apb_freq = s->hpll / (SCU_CLK_GET_PCLK_DIV(s->regs[CLK_SEL]) + 1) | 530 | - |
88 | - / apb_divider; | 531 | -/* XXX: check quiet/signaling case */ |
89 | + / asc->apb_divider; | 532 | -#define DO_VFP_cmp(P, FLOATTYPE, ARGTYPE, FPST) \ |
90 | } | 533 | -void VFP_HELPER(cmp, P)(ARGTYPE a, ARGTYPE b, CPUARMState *env) \ |
91 | 534 | -{ \ | |
92 | static uint64_t aspeed_scu_read(void *opaque, hwaddr offset, unsigned size) | 535 | - softfloat_to_vfp_compare(env, \ |
93 | @@ -XXX,XX +XXX,XX @@ static const uint32_t hpll_ast2400_freqs[][4] = { | 536 | - FLOATTYPE ## _compare_quiet(a, b, &env->vfp.fp_status[FPST])); \ |
94 | { 400, 375, 350, 425 }, /* 25MHz */ | 537 | -} \ |
95 | }; | 538 | -void VFP_HELPER(cmpe, P)(ARGTYPE a, ARGTYPE b, CPUARMState *env) \ |
96 | 539 | -{ \ | |
97 | -static uint32_t aspeed_scu_calc_hpll_ast2400(AspeedSCUState *s) | 540 | - softfloat_to_vfp_compare(env, \ |
98 | +static uint32_t aspeed_2400_scu_calc_hpll(AspeedSCUState *s) | 541 | - FLOATTYPE ## _compare(a, b, &env->vfp.fp_status[FPST])); \ |
99 | { | 542 | -} |
100 | uint32_t hpll_reg = s->regs[HPLL_PARAM]; | 543 | -DO_VFP_cmp(h, float16, dh_ctype_f16, FPST_A32_F16) |
101 | uint8_t freq_select; | 544 | -DO_VFP_cmp(s, float32, float32, FPST_A32) |
102 | @@ -XXX,XX +XXX,XX @@ static uint32_t aspeed_scu_calc_hpll_ast2400(AspeedSCUState *s) | 545 | -DO_VFP_cmp(d, float64, float64, FPST_A32) |
103 | return hpll_ast2400_freqs[clk_25m_in][freq_select] * 1000000; | 546 | -#undef DO_VFP_cmp |
104 | } | 547 | - |
105 | 548 | -/* Integer to float and float to integer conversions */ | |
106 | -static uint32_t aspeed_scu_calc_hpll_ast2500(AspeedSCUState *s) | 549 | - |
107 | +static uint32_t aspeed_2500_scu_calc_hpll(AspeedSCUState *s) | 550 | -#define CONV_ITOF(name, ftype, fsz, sign) \ |
108 | { | 551 | -ftype HELPER(name)(uint32_t x, float_status *fpst) \ |
109 | uint32_t hpll_reg = s->regs[HPLL_PARAM]; | 552 | -{ \ |
110 | uint32_t multiplier = 1; | 553 | - return sign##int32_to_##float##fsz((sign##int32_t)x, fpst); \ |
111 | @@ -XXX,XX +XXX,XX @@ static uint32_t aspeed_scu_calc_hpll_ast2500(AspeedSCUState *s) | 554 | -} |
112 | static void aspeed_scu_reset(DeviceState *dev) | 555 | - |
113 | { | 556 | -#define CONV_FTOI(name, ftype, fsz, sign, round) \ |
114 | AspeedSCUState *s = ASPEED_SCU(dev); | 557 | -sign##int32_t HELPER(name)(ftype x, float_status *fpst) \ |
115 | - const uint32_t *reset; | 558 | -{ \ |
116 | - uint32_t (*calc_hpll)(AspeedSCUState *s); | 559 | - if (float##fsz##_is_any_nan(x)) { \ |
117 | + AspeedSCUClass *asc = ASPEED_SCU_GET_CLASS(dev); | 560 | - float_raise(float_flag_invalid, fpst); \ |
118 | 561 | - return 0; \ | |
119 | - switch (s->silicon_rev) { | 562 | - } \ |
120 | - case AST2400_A0_SILICON_REV: | 563 | - return float##fsz##_to_##sign##int32##round(x, fpst); \ |
121 | - case AST2400_A1_SILICON_REV: | 564 | -} |
122 | - reset = ast2400_a0_resets; | 565 | - |
123 | - calc_hpll = aspeed_scu_calc_hpll_ast2400; | 566 | -#define FLOAT_CONVS(name, p, ftype, fsz, sign) \ |
567 | - CONV_ITOF(vfp_##name##to##p, ftype, fsz, sign) \ | ||
568 | - CONV_FTOI(vfp_to##name##p, ftype, fsz, sign, ) \ | ||
569 | - CONV_FTOI(vfp_to##name##z##p, ftype, fsz, sign, _round_to_zero) | ||
570 | - | ||
571 | -FLOAT_CONVS(si, h, uint32_t, 16, ) | ||
572 | -FLOAT_CONVS(si, s, float32, 32, ) | ||
573 | -FLOAT_CONVS(si, d, float64, 64, ) | ||
574 | -FLOAT_CONVS(ui, h, uint32_t, 16, u) | ||
575 | -FLOAT_CONVS(ui, s, float32, 32, u) | ||
576 | -FLOAT_CONVS(ui, d, float64, 64, u) | ||
577 | - | ||
578 | -#undef CONV_ITOF | ||
579 | -#undef CONV_FTOI | ||
580 | -#undef FLOAT_CONVS | ||
581 | - | ||
582 | -/* floating point conversion */ | ||
583 | -float64 VFP_HELPER(fcvtd, s)(float32 x, float_status *status) | ||
584 | -{ | ||
585 | - return float32_to_float64(x, status); | ||
586 | -} | ||
587 | - | ||
588 | -float32 VFP_HELPER(fcvts, d)(float64 x, float_status *status) | ||
589 | -{ | ||
590 | - return float64_to_float32(x, status); | ||
591 | -} | ||
592 | - | ||
593 | -uint32_t HELPER(bfcvt)(float32 x, float_status *status) | ||
594 | -{ | ||
595 | - return float32_to_bfloat16(x, status); | ||
596 | -} | ||
597 | - | ||
598 | -uint32_t HELPER(bfcvt_pair)(uint64_t pair, float_status *status) | ||
599 | -{ | ||
600 | - bfloat16 lo = float32_to_bfloat16(extract64(pair, 0, 32), status); | ||
601 | - bfloat16 hi = float32_to_bfloat16(extract64(pair, 32, 32), status); | ||
602 | - return deposit32(lo, 16, 16, hi); | ||
603 | -} | ||
604 | - | ||
605 | -/* | ||
606 | - * VFP3 fixed point conversion. The AArch32 versions of fix-to-float | ||
607 | - * must always round-to-nearest; the AArch64 ones honour the FPSCR | ||
608 | - * rounding mode. (For AArch32 Neon the standard-FPSCR is set to | ||
609 | - * round-to-nearest so either helper will work.) AArch32 float-to-fix | ||
610 | - * must round-to-zero. | ||
611 | - */ | ||
612 | -#define VFP_CONV_FIX_FLOAT(name, p, fsz, ftype, isz, itype) \ | ||
613 | -ftype HELPER(vfp_##name##to##p)(uint##isz##_t x, uint32_t shift, \ | ||
614 | - float_status *fpst) \ | ||
615 | -{ return itype##_to_##float##fsz##_scalbn(x, -shift, fpst); } | ||
616 | - | ||
617 | -#define VFP_CONV_FIX_FLOAT_ROUND(name, p, fsz, ftype, isz, itype) \ | ||
618 | - ftype HELPER(vfp_##name##to##p##_round_to_nearest)(uint##isz##_t x, \ | ||
619 | - uint32_t shift, \ | ||
620 | - float_status *fpst) \ | ||
621 | - { \ | ||
622 | - ftype ret; \ | ||
623 | - FloatRoundMode oldmode = fpst->float_rounding_mode; \ | ||
624 | - fpst->float_rounding_mode = float_round_nearest_even; \ | ||
625 | - ret = itype##_to_##float##fsz##_scalbn(x, -shift, fpst); \ | ||
626 | - fpst->float_rounding_mode = oldmode; \ | ||
627 | - return ret; \ | ||
628 | - } | ||
629 | - | ||
630 | -#define VFP_CONV_FLOAT_FIX_ROUND(name, p, fsz, ftype, isz, itype, ROUND, suff) \ | ||
631 | -uint##isz##_t HELPER(vfp_to##name##p##suff)(ftype x, uint32_t shift, \ | ||
632 | - float_status *fpst) \ | ||
633 | -{ \ | ||
634 | - if (unlikely(float##fsz##_is_any_nan(x))) { \ | ||
635 | - float_raise(float_flag_invalid, fpst); \ | ||
636 | - return 0; \ | ||
637 | - } \ | ||
638 | - return float##fsz##_to_##itype##_scalbn(x, ROUND, shift, fpst); \ | ||
639 | -} | ||
640 | - | ||
641 | -#define VFP_CONV_FIX(name, p, fsz, ftype, isz, itype) \ | ||
642 | -VFP_CONV_FIX_FLOAT(name, p, fsz, ftype, isz, itype) \ | ||
643 | -VFP_CONV_FIX_FLOAT_ROUND(name, p, fsz, ftype, isz, itype) \ | ||
644 | -VFP_CONV_FLOAT_FIX_ROUND(name, p, fsz, ftype, isz, itype, \ | ||
645 | - float_round_to_zero, _round_to_zero) \ | ||
646 | -VFP_CONV_FLOAT_FIX_ROUND(name, p, fsz, ftype, isz, itype, \ | ||
647 | - get_float_rounding_mode(fpst), ) | ||
648 | - | ||
649 | -#define VFP_CONV_FIX_A64(name, p, fsz, ftype, isz, itype) \ | ||
650 | -VFP_CONV_FIX_FLOAT(name, p, fsz, ftype, isz, itype) \ | ||
651 | -VFP_CONV_FLOAT_FIX_ROUND(name, p, fsz, ftype, isz, itype, \ | ||
652 | - get_float_rounding_mode(fpst), ) | ||
653 | - | ||
654 | -VFP_CONV_FIX(sh, d, 64, float64, 64, int16) | ||
655 | -VFP_CONV_FIX(sl, d, 64, float64, 64, int32) | ||
656 | -VFP_CONV_FIX_A64(sq, d, 64, float64, 64, int64) | ||
657 | -VFP_CONV_FIX(uh, d, 64, float64, 64, uint16) | ||
658 | -VFP_CONV_FIX(ul, d, 64, float64, 64, uint32) | ||
659 | -VFP_CONV_FIX_A64(uq, d, 64, float64, 64, uint64) | ||
660 | -VFP_CONV_FIX(sh, s, 32, float32, 32, int16) | ||
661 | -VFP_CONV_FIX(sl, s, 32, float32, 32, int32) | ||
662 | -VFP_CONV_FIX_A64(sq, s, 32, float32, 64, int64) | ||
663 | -VFP_CONV_FIX(uh, s, 32, float32, 32, uint16) | ||
664 | -VFP_CONV_FIX(ul, s, 32, float32, 32, uint32) | ||
665 | -VFP_CONV_FIX_A64(uq, s, 32, float32, 64, uint64) | ||
666 | -VFP_CONV_FIX(sh, h, 16, dh_ctype_f16, 32, int16) | ||
667 | -VFP_CONV_FIX(sl, h, 16, dh_ctype_f16, 32, int32) | ||
668 | -VFP_CONV_FIX_A64(sq, h, 16, dh_ctype_f16, 64, int64) | ||
669 | -VFP_CONV_FIX(uh, h, 16, dh_ctype_f16, 32, uint16) | ||
670 | -VFP_CONV_FIX(ul, h, 16, dh_ctype_f16, 32, uint32) | ||
671 | -VFP_CONV_FIX_A64(uq, h, 16, dh_ctype_f16, 64, uint64) | ||
672 | -VFP_CONV_FLOAT_FIX_ROUND(sq, d, 64, float64, 64, int64, | ||
673 | - float_round_to_zero, _round_to_zero) | ||
674 | -VFP_CONV_FLOAT_FIX_ROUND(uq, d, 64, float64, 64, uint64, | ||
675 | - float_round_to_zero, _round_to_zero) | ||
676 | - | ||
677 | -#undef VFP_CONV_FIX | ||
678 | -#undef VFP_CONV_FIX_FLOAT | ||
679 | -#undef VFP_CONV_FLOAT_FIX_ROUND | ||
680 | -#undef VFP_CONV_FIX_A64 | ||
681 | - | ||
682 | -/* Set the current fp rounding mode and return the old one. | ||
683 | - * The argument is a softfloat float_round_ value. | ||
684 | - */ | ||
685 | -uint32_t HELPER(set_rmode)(uint32_t rmode, float_status *fp_status) | ||
686 | -{ | ||
687 | - uint32_t prev_rmode = get_float_rounding_mode(fp_status); | ||
688 | - set_float_rounding_mode(rmode, fp_status); | ||
689 | - | ||
690 | - return prev_rmode; | ||
691 | -} | ||
692 | - | ||
693 | -/* Half precision conversions. */ | ||
694 | -float32 HELPER(vfp_fcvt_f16_to_f32)(uint32_t a, float_status *fpst, | ||
695 | - uint32_t ahp_mode) | ||
696 | -{ | ||
697 | - /* Squash FZ16 to 0 for the duration of conversion. In this case, | ||
698 | - * it would affect flushing input denormals. | ||
699 | - */ | ||
700 | - bool save = get_flush_inputs_to_zero(fpst); | ||
701 | - set_flush_inputs_to_zero(false, fpst); | ||
702 | - float32 r = float16_to_float32(a, !ahp_mode, fpst); | ||
703 | - set_flush_inputs_to_zero(save, fpst); | ||
704 | - return r; | ||
705 | -} | ||
706 | - | ||
707 | -uint32_t HELPER(vfp_fcvt_f32_to_f16)(float32 a, float_status *fpst, | ||
708 | - uint32_t ahp_mode) | ||
709 | -{ | ||
710 | - /* Squash FZ16 to 0 for the duration of conversion. In this case, | ||
711 | - * it would affect flushing output denormals. | ||
712 | - */ | ||
713 | - bool save = get_flush_to_zero(fpst); | ||
714 | - set_flush_to_zero(false, fpst); | ||
715 | - float16 r = float32_to_float16(a, !ahp_mode, fpst); | ||
716 | - set_flush_to_zero(save, fpst); | ||
717 | - return r; | ||
718 | -} | ||
719 | - | ||
720 | -float64 HELPER(vfp_fcvt_f16_to_f64)(uint32_t a, float_status *fpst, | ||
721 | - uint32_t ahp_mode) | ||
722 | -{ | ||
723 | - /* Squash FZ16 to 0 for the duration of conversion. In this case, | ||
724 | - * it would affect flushing input denormals. | ||
725 | - */ | ||
726 | - bool save = get_flush_inputs_to_zero(fpst); | ||
727 | - set_flush_inputs_to_zero(false, fpst); | ||
728 | - float64 r = float16_to_float64(a, !ahp_mode, fpst); | ||
729 | - set_flush_inputs_to_zero(save, fpst); | ||
730 | - return r; | ||
731 | -} | ||
732 | - | ||
733 | -uint32_t HELPER(vfp_fcvt_f64_to_f16)(float64 a, float_status *fpst, | ||
734 | - uint32_t ahp_mode) | ||
735 | -{ | ||
736 | - /* Squash FZ16 to 0 for the duration of conversion. In this case, | ||
737 | - * it would affect flushing output denormals. | ||
738 | - */ | ||
739 | - bool save = get_flush_to_zero(fpst); | ||
740 | - set_flush_to_zero(false, fpst); | ||
741 | - float16 r = float64_to_float16(a, !ahp_mode, fpst); | ||
742 | - set_flush_to_zero(save, fpst); | ||
743 | - return r; | ||
744 | -} | ||
745 | - | ||
746 | -/* NEON helpers. */ | ||
747 | - | ||
748 | -/* Constants 256 and 512 are used in some helpers; we avoid relying on | ||
749 | - * int->float conversions at run-time. */ | ||
750 | -#define float64_256 make_float64(0x4070000000000000LL) | ||
751 | -#define float64_512 make_float64(0x4080000000000000LL) | ||
752 | -#define float16_maxnorm make_float16(0x7bff) | ||
753 | -#define float32_maxnorm make_float32(0x7f7fffff) | ||
754 | -#define float64_maxnorm make_float64(0x7fefffffffffffffLL) | ||
755 | - | ||
756 | -/* Reciprocal functions | ||
757 | - * | ||
758 | - * The algorithm that must be used to calculate the estimate | ||
759 | - * is specified by the ARM ARM, see FPRecipEstimate()/RecipEstimate | ||
760 | - */ | ||
761 | - | ||
762 | -/* See RecipEstimate() | ||
763 | - * | ||
764 | - * input is a 9 bit fixed point number | ||
765 | - * input range 256 .. 511 for a number from 0.5 <= x < 1.0. | ||
766 | - * result range 256 .. 511 for a number from 1.0 to 511/256. | ||
767 | - */ | ||
768 | - | ||
769 | -static int recip_estimate(int input) | ||
770 | -{ | ||
771 | - int a, b, r; | ||
772 | - assert(256 <= input && input < 512); | ||
773 | - a = (input * 2) + 1; | ||
774 | - b = (1 << 19) / a; | ||
775 | - r = (b + 1) >> 1; | ||
776 | - assert(256 <= r && r < 512); | ||
777 | - return r; | ||
778 | -} | ||
779 | - | ||
780 | -/* | ||
781 | - * Increased precision version: | ||
782 | - * input is a 13 bit fixed point number | ||
783 | - * input range 2048 .. 4095 for a number from 0.5 <= x < 1.0. | ||
784 | - * result range 4096 .. 8191 for a number from 1.0 to 2.0 | ||
785 | - */ | ||
786 | -static int recip_estimate_incprec(int input) | ||
787 | -{ | ||
788 | - int a, b, r; | ||
789 | - assert(2048 <= input && input < 4096); | ||
790 | - a = (input * 2) + 1; | ||
791 | - /* | ||
792 | - * The pseudocode expresses this as an operation on infinite | ||
793 | - * precision reals where it calculates 2^25 / a and then looks | ||
794 | - * at the error between that and the rounded-down-to-integer | ||
795 | - * value to see if it should instead round up. We instead | ||
796 | - * follow the same approach as the pseudocode for the 8-bit | ||
797 | - * precision version, and calculate (2 * (2^25 / a)) as an | ||
798 | - * integer so we can do the "add one and halve" to round it. | ||
799 | - * So the 1 << 26 here is correct. | ||
800 | - */ | ||
801 | - b = (1 << 26) / a; | ||
802 | - r = (b + 1) >> 1; | ||
803 | - assert(4096 <= r && r < 8192); | ||
804 | - return r; | ||
805 | -} | ||
806 | - | ||
807 | -/* | ||
808 | - * Common wrapper to call recip_estimate | ||
809 | - * | ||
810 | - * The parameters are exponent and 64 bit fraction (without implicit | ||
811 | - * bit) where the binary point is nominally at bit 52. Returns a | ||
812 | - * float64 which can then be rounded to the appropriate size by the | ||
813 | - * callee. | ||
814 | - */ | ||
815 | - | ||
816 | -static uint64_t call_recip_estimate(int *exp, int exp_off, uint64_t frac, | ||
817 | - bool increasedprecision) | ||
818 | -{ | ||
819 | - uint32_t scaled, estimate; | ||
820 | - uint64_t result_frac; | ||
821 | - int result_exp; | ||
822 | - | ||
823 | - /* Handle sub-normals */ | ||
824 | - if (*exp == 0) { | ||
825 | - if (extract64(frac, 51, 1) == 0) { | ||
826 | - *exp = -1; | ||
827 | - frac <<= 2; | ||
828 | - } else { | ||
829 | - frac <<= 1; | ||
830 | - } | ||
831 | - } | ||
832 | - | ||
833 | - if (increasedprecision) { | ||
834 | - /* scaled = UInt('1':fraction<51:41>) */ | ||
835 | - scaled = deposit32(1 << 11, 0, 11, extract64(frac, 41, 11)); | ||
836 | - estimate = recip_estimate_incprec(scaled); | ||
837 | - } else { | ||
838 | - /* scaled = UInt('1':fraction<51:44>) */ | ||
839 | - scaled = deposit32(1 << 8, 0, 8, extract64(frac, 44, 8)); | ||
840 | - estimate = recip_estimate(scaled); | ||
841 | - } | ||
842 | - | ||
843 | - result_exp = exp_off - *exp; | ||
844 | - if (increasedprecision) { | ||
845 | - result_frac = deposit64(0, 40, 12, estimate); | ||
846 | - } else { | ||
847 | - result_frac = deposit64(0, 44, 8, estimate); | ||
848 | - } | ||
849 | - if (result_exp == 0) { | ||
850 | - result_frac = deposit64(result_frac >> 1, 51, 1, 1); | ||
851 | - } else if (result_exp == -1) { | ||
852 | - result_frac = deposit64(result_frac >> 2, 50, 2, 1); | ||
853 | - result_exp = 0; | ||
854 | - } | ||
855 | - | ||
856 | - *exp = result_exp; | ||
857 | - | ||
858 | - return result_frac; | ||
859 | -} | ||
860 | - | ||
861 | -static bool round_to_inf(float_status *fpst, bool sign_bit) | ||
862 | -{ | ||
863 | - switch (fpst->float_rounding_mode) { | ||
864 | - case float_round_nearest_even: /* Round to Nearest */ | ||
865 | - return true; | ||
866 | - case float_round_up: /* Round to +Inf */ | ||
867 | - return !sign_bit; | ||
868 | - case float_round_down: /* Round to -Inf */ | ||
869 | - return sign_bit; | ||
870 | - case float_round_to_zero: /* Round to Zero */ | ||
871 | - return false; | ||
872 | - default: | ||
873 | - g_assert_not_reached(); | ||
874 | - } | ||
875 | -} | ||
876 | - | ||
877 | -uint32_t HELPER(recpe_f16)(uint32_t input, float_status *fpst) | ||
878 | -{ | ||
879 | - float16 f16 = float16_squash_input_denormal(input, fpst); | ||
880 | - uint32_t f16_val = float16_val(f16); | ||
881 | - uint32_t f16_sign = float16_is_neg(f16); | ||
882 | - int f16_exp = extract32(f16_val, 10, 5); | ||
883 | - uint32_t f16_frac = extract32(f16_val, 0, 10); | ||
884 | - uint64_t f64_frac; | ||
885 | - | ||
886 | - if (float16_is_any_nan(f16)) { | ||
887 | - float16 nan = f16; | ||
888 | - if (float16_is_signaling_nan(f16, fpst)) { | ||
889 | - float_raise(float_flag_invalid, fpst); | ||
890 | - if (!fpst->default_nan_mode) { | ||
891 | - nan = float16_silence_nan(f16, fpst); | ||
892 | - } | ||
893 | - } | ||
894 | - if (fpst->default_nan_mode) { | ||
895 | - nan = float16_default_nan(fpst); | ||
896 | - } | ||
897 | - return nan; | ||
898 | - } else if (float16_is_infinity(f16)) { | ||
899 | - return float16_set_sign(float16_zero, float16_is_neg(f16)); | ||
900 | - } else if (float16_is_zero(f16)) { | ||
901 | - float_raise(float_flag_divbyzero, fpst); | ||
902 | - return float16_set_sign(float16_infinity, float16_is_neg(f16)); | ||
903 | - } else if (float16_abs(f16) < (1 << 8)) { | ||
904 | - /* Abs(value) < 2.0^-16 */ | ||
905 | - float_raise(float_flag_overflow | float_flag_inexact, fpst); | ||
906 | - if (round_to_inf(fpst, f16_sign)) { | ||
907 | - return float16_set_sign(float16_infinity, f16_sign); | ||
908 | - } else { | ||
909 | - return float16_set_sign(float16_maxnorm, f16_sign); | ||
910 | - } | ||
911 | - } else if (f16_exp >= 29 && fpst->flush_to_zero) { | ||
912 | - float_raise(float_flag_underflow, fpst); | ||
913 | - return float16_set_sign(float16_zero, float16_is_neg(f16)); | ||
914 | - } | ||
915 | - | ||
916 | - f64_frac = call_recip_estimate(&f16_exp, 29, | ||
917 | - ((uint64_t) f16_frac) << (52 - 10), false); | ||
918 | - | ||
919 | - /* result = sign : result_exp<4:0> : fraction<51:42> */ | ||
920 | - f16_val = deposit32(0, 15, 1, f16_sign); | ||
921 | - f16_val = deposit32(f16_val, 10, 5, f16_exp); | ||
922 | - f16_val = deposit32(f16_val, 0, 10, extract64(f64_frac, 52 - 10, 10)); | ||
923 | - return make_float16(f16_val); | ||
924 | -} | ||
925 | - | ||
926 | -/* | ||
927 | - * FEAT_RPRES means the f32 FRECPE has an "increased precision" variant | ||
928 | - * which is used when FPCR.AH == 1. | ||
929 | - */ | ||
930 | -static float32 do_recpe_f32(float32 input, float_status *fpst, bool rpres) | ||
931 | -{ | ||
932 | - float32 f32 = float32_squash_input_denormal(input, fpst); | ||
933 | - uint32_t f32_val = float32_val(f32); | ||
934 | - bool f32_sign = float32_is_neg(f32); | ||
935 | - int f32_exp = extract32(f32_val, 23, 8); | ||
936 | - uint32_t f32_frac = extract32(f32_val, 0, 23); | ||
937 | - uint64_t f64_frac; | ||
938 | - | ||
939 | - if (float32_is_any_nan(f32)) { | ||
940 | - float32 nan = f32; | ||
941 | - if (float32_is_signaling_nan(f32, fpst)) { | ||
942 | - float_raise(float_flag_invalid, fpst); | ||
943 | - if (!fpst->default_nan_mode) { | ||
944 | - nan = float32_silence_nan(f32, fpst); | ||
945 | - } | ||
946 | - } | ||
947 | - if (fpst->default_nan_mode) { | ||
948 | - nan = float32_default_nan(fpst); | ||
949 | - } | ||
950 | - return nan; | ||
951 | - } else if (float32_is_infinity(f32)) { | ||
952 | - return float32_set_sign(float32_zero, float32_is_neg(f32)); | ||
953 | - } else if (float32_is_zero(f32)) { | ||
954 | - float_raise(float_flag_divbyzero, fpst); | ||
955 | - return float32_set_sign(float32_infinity, float32_is_neg(f32)); | ||
956 | - } else if (float32_abs(f32) < (1ULL << 21)) { | ||
957 | - /* Abs(value) < 2.0^-128 */ | ||
958 | - float_raise(float_flag_overflow | float_flag_inexact, fpst); | ||
959 | - if (round_to_inf(fpst, f32_sign)) { | ||
960 | - return float32_set_sign(float32_infinity, f32_sign); | ||
961 | - } else { | ||
962 | - return float32_set_sign(float32_maxnorm, f32_sign); | ||
963 | - } | ||
964 | - } else if (f32_exp >= 253 && fpst->flush_to_zero) { | ||
965 | - float_raise(float_flag_underflow, fpst); | ||
966 | - return float32_set_sign(float32_zero, float32_is_neg(f32)); | ||
967 | - } | ||
968 | - | ||
969 | - f64_frac = call_recip_estimate(&f32_exp, 253, | ||
970 | - ((uint64_t) f32_frac) << (52 - 23), rpres); | ||
971 | - | ||
972 | - /* result = sign : result_exp<7:0> : fraction<51:29> */ | ||
973 | - f32_val = deposit32(0, 31, 1, f32_sign); | ||
974 | - f32_val = deposit32(f32_val, 23, 8, f32_exp); | ||
975 | - f32_val = deposit32(f32_val, 0, 23, extract64(f64_frac, 52 - 23, 23)); | ||
976 | - return make_float32(f32_val); | ||
977 | -} | ||
978 | - | ||
979 | -float32 HELPER(recpe_f32)(float32 input, float_status *fpst) | ||
980 | -{ | ||
981 | - return do_recpe_f32(input, fpst, false); | ||
982 | -} | ||
983 | - | ||
984 | -float32 HELPER(recpe_rpres_f32)(float32 input, float_status *fpst) | ||
985 | -{ | ||
986 | - return do_recpe_f32(input, fpst, true); | ||
987 | -} | ||
988 | - | ||
989 | -float64 HELPER(recpe_f64)(float64 input, float_status *fpst) | ||
990 | -{ | ||
991 | - float64 f64 = float64_squash_input_denormal(input, fpst); | ||
992 | - uint64_t f64_val = float64_val(f64); | ||
993 | - bool f64_sign = float64_is_neg(f64); | ||
994 | - int f64_exp = extract64(f64_val, 52, 11); | ||
995 | - uint64_t f64_frac = extract64(f64_val, 0, 52); | ||
996 | - | ||
997 | - /* Deal with any special cases */ | ||
998 | - if (float64_is_any_nan(f64)) { | ||
999 | - float64 nan = f64; | ||
1000 | - if (float64_is_signaling_nan(f64, fpst)) { | ||
1001 | - float_raise(float_flag_invalid, fpst); | ||
1002 | - if (!fpst->default_nan_mode) { | ||
1003 | - nan = float64_silence_nan(f64, fpst); | ||
1004 | - } | ||
1005 | - } | ||
1006 | - if (fpst->default_nan_mode) { | ||
1007 | - nan = float64_default_nan(fpst); | ||
1008 | - } | ||
1009 | - return nan; | ||
1010 | - } else if (float64_is_infinity(f64)) { | ||
1011 | - return float64_set_sign(float64_zero, float64_is_neg(f64)); | ||
1012 | - } else if (float64_is_zero(f64)) { | ||
1013 | - float_raise(float_flag_divbyzero, fpst); | ||
1014 | - return float64_set_sign(float64_infinity, float64_is_neg(f64)); | ||
1015 | - } else if ((f64_val & ~(1ULL << 63)) < (1ULL << 50)) { | ||
1016 | - /* Abs(value) < 2.0^-1024 */ | ||
1017 | - float_raise(float_flag_overflow | float_flag_inexact, fpst); | ||
1018 | - if (round_to_inf(fpst, f64_sign)) { | ||
1019 | - return float64_set_sign(float64_infinity, f64_sign); | ||
1020 | - } else { | ||
1021 | - return float64_set_sign(float64_maxnorm, f64_sign); | ||
1022 | - } | ||
1023 | - } else if (f64_exp >= 2045 && fpst->flush_to_zero) { | ||
1024 | - float_raise(float_flag_underflow, fpst); | ||
1025 | - return float64_set_sign(float64_zero, float64_is_neg(f64)); | ||
1026 | - } | ||
1027 | - | ||
1028 | - f64_frac = call_recip_estimate(&f64_exp, 2045, f64_frac, false); | ||
1029 | - | ||
1030 | - /* result = sign : result_exp<10:0> : fraction<51:0>; */ | ||
1031 | - f64_val = deposit64(0, 63, 1, f64_sign); | ||
1032 | - f64_val = deposit64(f64_val, 52, 11, f64_exp); | ||
1033 | - f64_val = deposit64(f64_val, 0, 52, f64_frac); | ||
1034 | - return make_float64(f64_val); | ||
1035 | -} | ||
1036 | - | ||
1037 | -/* The algorithm that must be used to calculate the estimate | ||
1038 | - * is specified by the ARM ARM. | ||
1039 | - */ | ||
1040 | - | ||
1041 | -static int do_recip_sqrt_estimate(int a) | ||
1042 | -{ | ||
1043 | - int b, estimate; | ||
1044 | - | ||
1045 | - assert(128 <= a && a < 512); | ||
1046 | - if (a < 256) { | ||
1047 | - a = a * 2 + 1; | ||
1048 | - } else { | ||
1049 | - a = (a >> 1) << 1; | ||
1050 | - a = (a + 1) * 2; | ||
1051 | - } | ||
1052 | - b = 512; | ||
1053 | - while (a * (b + 1) * (b + 1) < (1 << 28)) { | ||
1054 | - b += 1; | ||
1055 | - } | ||
1056 | - estimate = (b + 1) / 2; | ||
1057 | - assert(256 <= estimate && estimate < 512); | ||
1058 | - | ||
1059 | - return estimate; | ||
1060 | -} | ||
1061 | - | ||
1062 | -static int do_recip_sqrt_estimate_incprec(int a) | ||
1063 | -{ | ||
1064 | - /* | ||
1065 | - * The Arm ARM describes the 12-bit precision version of RecipSqrtEstimate | ||
1066 | - * in terms of an infinite-precision floating point calculation of a | ||
1067 | - * square root. We implement this using the same kind of pure integer | ||
1068 | - * algorithm as the 8-bit mantissa, to get the same bit-for-bit result. | ||
1069 | - */ | ||
1070 | - int64_t b, estimate; | ||
1071 | - | ||
1072 | - assert(1024 <= a && a < 4096); | ||
1073 | - if (a < 2048) { | ||
1074 | - a = a * 2 + 1; | ||
1075 | - } else { | ||
1076 | - a = (a >> 1) << 1; | ||
1077 | - a = (a + 1) * 2; | ||
1078 | - } | ||
1079 | - b = 8192; | ||
1080 | - while (a * (b + 1) * (b + 1) < (1ULL << 39)) { | ||
1081 | - b += 1; | ||
1082 | - } | ||
1083 | - estimate = (b + 1) / 2; | ||
1084 | - | ||
1085 | - assert(4096 <= estimate && estimate < 8192); | ||
1086 | - | ||
1087 | - return estimate; | ||
1088 | -} | ||
1089 | - | ||
1090 | -static uint64_t recip_sqrt_estimate(int *exp , int exp_off, uint64_t frac, | ||
1091 | - bool increasedprecision) | ||
1092 | -{ | ||
1093 | - int estimate; | ||
1094 | - uint32_t scaled; | ||
1095 | - | ||
1096 | - if (*exp == 0) { | ||
1097 | - while (extract64(frac, 51, 1) == 0) { | ||
1098 | - frac = frac << 1; | ||
1099 | - *exp -= 1; | ||
1100 | - } | ||
1101 | - frac = extract64(frac, 0, 51) << 1; | ||
1102 | - } | ||
1103 | - | ||
1104 | - if (increasedprecision) { | ||
1105 | - if (*exp & 1) { | ||
1106 | - /* scaled = UInt('01':fraction<51:42>) */ | ||
1107 | - scaled = deposit32(1 << 10, 0, 10, extract64(frac, 42, 10)); | ||
1108 | - } else { | ||
1109 | - /* scaled = UInt('1':fraction<51:41>) */ | ||
1110 | - scaled = deposit32(1 << 11, 0, 11, extract64(frac, 41, 11)); | ||
1111 | - } | ||
1112 | - estimate = do_recip_sqrt_estimate_incprec(scaled); | ||
1113 | - } else { | ||
1114 | - if (*exp & 1) { | ||
1115 | - /* scaled = UInt('01':fraction<51:45>) */ | ||
1116 | - scaled = deposit32(1 << 7, 0, 7, extract64(frac, 45, 7)); | ||
1117 | - } else { | ||
1118 | - /* scaled = UInt('1':fraction<51:44>) */ | ||
1119 | - scaled = deposit32(1 << 8, 0, 8, extract64(frac, 44, 8)); | ||
1120 | - } | ||
1121 | - estimate = do_recip_sqrt_estimate(scaled); | ||
1122 | - } | ||
1123 | - | ||
1124 | - *exp = (exp_off - *exp) / 2; | ||
1125 | - if (increasedprecision) { | ||
1126 | - return extract64(estimate, 0, 12) << 40; | ||
1127 | - } else { | ||
1128 | - return extract64(estimate, 0, 8) << 44; | ||
1129 | - } | ||
1130 | -} | ||
1131 | - | ||
1132 | -uint32_t HELPER(rsqrte_f16)(uint32_t input, float_status *s) | ||
1133 | -{ | ||
1134 | - float16 f16 = float16_squash_input_denormal(input, s); | ||
1135 | - uint16_t val = float16_val(f16); | ||
1136 | - bool f16_sign = float16_is_neg(f16); | ||
1137 | - int f16_exp = extract32(val, 10, 5); | ||
1138 | - uint16_t f16_frac = extract32(val, 0, 10); | ||
1139 | - uint64_t f64_frac; | ||
1140 | - | ||
1141 | - if (float16_is_any_nan(f16)) { | ||
1142 | - float16 nan = f16; | ||
1143 | - if (float16_is_signaling_nan(f16, s)) { | ||
1144 | - float_raise(float_flag_invalid, s); | ||
1145 | - if (!s->default_nan_mode) { | ||
1146 | - nan = float16_silence_nan(f16, s); | ||
1147 | - } | ||
1148 | - } | ||
1149 | - if (s->default_nan_mode) { | ||
1150 | - nan = float16_default_nan(s); | ||
1151 | - } | ||
1152 | - return nan; | ||
1153 | - } else if (float16_is_zero(f16)) { | ||
1154 | - float_raise(float_flag_divbyzero, s); | ||
1155 | - return float16_set_sign(float16_infinity, f16_sign); | ||
1156 | - } else if (f16_sign) { | ||
1157 | - float_raise(float_flag_invalid, s); | ||
1158 | - return float16_default_nan(s); | ||
1159 | - } else if (float16_is_infinity(f16)) { | ||
1160 | - return float16_zero; | ||
1161 | - } | ||
1162 | - | ||
1163 | - /* Scale and normalize to a double-precision value between 0.25 and 1.0, | ||
1164 | - * preserving the parity of the exponent. */ | ||
1165 | - | ||
1166 | - f64_frac = ((uint64_t) f16_frac) << (52 - 10); | ||
1167 | - | ||
1168 | - f64_frac = recip_sqrt_estimate(&f16_exp, 44, f64_frac, false); | ||
1169 | - | ||
1170 | - /* result = sign : result_exp<4:0> : estimate<7:0> : Zeros(2) */ | ||
1171 | - val = deposit32(0, 15, 1, f16_sign); | ||
1172 | - val = deposit32(val, 10, 5, f16_exp); | ||
1173 | - val = deposit32(val, 2, 8, extract64(f64_frac, 52 - 8, 8)); | ||
1174 | - return make_float16(val); | ||
1175 | -} | ||
1176 | - | ||
1177 | -/* | ||
1178 | - * FEAT_RPRES means the f32 FRSQRTE has an "increased precision" variant | ||
1179 | - * which is used when FPCR.AH == 1. | ||
1180 | - */ | ||
1181 | -static float32 do_rsqrte_f32(float32 input, float_status *s, bool rpres) | ||
1182 | -{ | ||
1183 | - float32 f32 = float32_squash_input_denormal(input, s); | ||
1184 | - uint32_t val = float32_val(f32); | ||
1185 | - uint32_t f32_sign = float32_is_neg(f32); | ||
1186 | - int f32_exp = extract32(val, 23, 8); | ||
1187 | - uint32_t f32_frac = extract32(val, 0, 23); | ||
1188 | - uint64_t f64_frac; | ||
1189 | - | ||
1190 | - if (float32_is_any_nan(f32)) { | ||
1191 | - float32 nan = f32; | ||
1192 | - if (float32_is_signaling_nan(f32, s)) { | ||
1193 | - float_raise(float_flag_invalid, s); | ||
1194 | - if (!s->default_nan_mode) { | ||
1195 | - nan = float32_silence_nan(f32, s); | ||
1196 | - } | ||
1197 | - } | ||
1198 | - if (s->default_nan_mode) { | ||
1199 | - nan = float32_default_nan(s); | ||
1200 | - } | ||
1201 | - return nan; | ||
1202 | - } else if (float32_is_zero(f32)) { | ||
1203 | - float_raise(float_flag_divbyzero, s); | ||
1204 | - return float32_set_sign(float32_infinity, float32_is_neg(f32)); | ||
1205 | - } else if (float32_is_neg(f32)) { | ||
1206 | - float_raise(float_flag_invalid, s); | ||
1207 | - return float32_default_nan(s); | ||
1208 | - } else if (float32_is_infinity(f32)) { | ||
1209 | - return float32_zero; | ||
1210 | - } | ||
1211 | - | ||
1212 | - /* Scale and normalize to a double-precision value between 0.25 and 1.0, | ||
1213 | - * preserving the parity of the exponent. */ | ||
1214 | - | ||
1215 | - f64_frac = ((uint64_t) f32_frac) << 29; | ||
1216 | - | ||
1217 | - f64_frac = recip_sqrt_estimate(&f32_exp, 380, f64_frac, rpres); | ||
1218 | - | ||
1219 | - /* | ||
1220 | - * result = sign : result_exp<7:0> : estimate<7:0> : Zeros(15) | ||
1221 | - * or for increased precision | ||
1222 | - * result = sign : result_exp<7:0> : estimate<11:0> : Zeros(11) | ||
1223 | - */ | ||
1224 | - val = deposit32(0, 31, 1, f32_sign); | ||
1225 | - val = deposit32(val, 23, 8, f32_exp); | ||
1226 | - if (rpres) { | ||
1227 | - val = deposit32(val, 11, 12, extract64(f64_frac, 52 - 12, 12)); | ||
1228 | - } else { | ||
1229 | - val = deposit32(val, 15, 8, extract64(f64_frac, 52 - 8, 8)); | ||
1230 | - } | ||
1231 | - return make_float32(val); | ||
1232 | -} | ||
1233 | - | ||
1234 | -float32 HELPER(rsqrte_f32)(float32 input, float_status *s) | ||
1235 | -{ | ||
1236 | - return do_rsqrte_f32(input, s, false); | ||
1237 | -} | ||
1238 | - | ||
1239 | -float32 HELPER(rsqrte_rpres_f32)(float32 input, float_status *s) | ||
1240 | -{ | ||
1241 | - return do_rsqrte_f32(input, s, true); | ||
1242 | -} | ||
1243 | - | ||
1244 | -float64 HELPER(rsqrte_f64)(float64 input, float_status *s) | ||
1245 | -{ | ||
1246 | - float64 f64 = float64_squash_input_denormal(input, s); | ||
1247 | - uint64_t val = float64_val(f64); | ||
1248 | - bool f64_sign = float64_is_neg(f64); | ||
1249 | - int f64_exp = extract64(val, 52, 11); | ||
1250 | - uint64_t f64_frac = extract64(val, 0, 52); | ||
1251 | - | ||
1252 | - if (float64_is_any_nan(f64)) { | ||
1253 | - float64 nan = f64; | ||
1254 | - if (float64_is_signaling_nan(f64, s)) { | ||
1255 | - float_raise(float_flag_invalid, s); | ||
1256 | - if (!s->default_nan_mode) { | ||
1257 | - nan = float64_silence_nan(f64, s); | ||
1258 | - } | ||
1259 | - } | ||
1260 | - if (s->default_nan_mode) { | ||
1261 | - nan = float64_default_nan(s); | ||
1262 | - } | ||
1263 | - return nan; | ||
1264 | - } else if (float64_is_zero(f64)) { | ||
1265 | - float_raise(float_flag_divbyzero, s); | ||
1266 | - return float64_set_sign(float64_infinity, float64_is_neg(f64)); | ||
1267 | - } else if (float64_is_neg(f64)) { | ||
1268 | - float_raise(float_flag_invalid, s); | ||
1269 | - return float64_default_nan(s); | ||
1270 | - } else if (float64_is_infinity(f64)) { | ||
1271 | - return float64_zero; | ||
1272 | - } | ||
1273 | - | ||
1274 | - f64_frac = recip_sqrt_estimate(&f64_exp, 3068, f64_frac, false); | ||
1275 | - | ||
1276 | - /* result = sign : result_exp<4:0> : estimate<7:0> : Zeros(44) */ | ||
1277 | - val = deposit64(0, 61, 1, f64_sign); | ||
1278 | - val = deposit64(val, 52, 11, f64_exp); | ||
1279 | - val = deposit64(val, 44, 8, extract64(f64_frac, 52 - 8, 8)); | ||
1280 | - return make_float64(val); | ||
1281 | -} | ||
1282 | - | ||
1283 | -uint32_t HELPER(recpe_u32)(uint32_t a) | ||
1284 | -{ | ||
1285 | - int input, estimate; | ||
1286 | - | ||
1287 | - if ((a & 0x80000000) == 0) { | ||
1288 | - return 0xffffffff; | ||
1289 | - } | ||
1290 | - | ||
1291 | - input = extract32(a, 23, 9); | ||
1292 | - estimate = recip_estimate(input); | ||
1293 | - | ||
1294 | - return deposit32(0, (32 - 9), 9, estimate); | ||
1295 | -} | ||
1296 | - | ||
1297 | -uint32_t HELPER(rsqrte_u32)(uint32_t a) | ||
1298 | -{ | ||
1299 | - int estimate; | ||
1300 | - | ||
1301 | - if ((a & 0xc0000000) == 0) { | ||
1302 | - return 0xffffffff; | ||
1303 | - } | ||
1304 | - | ||
1305 | - estimate = do_recip_sqrt_estimate(extract32(a, 23, 9)); | ||
1306 | - | ||
1307 | - return deposit32(0, 23, 9, estimate); | ||
1308 | -} | ||
1309 | - | ||
1310 | -/* VFPv4 fused multiply-accumulate */ | ||
1311 | -dh_ctype_f16 VFP_HELPER(muladd, h)(dh_ctype_f16 a, dh_ctype_f16 b, | ||
1312 | - dh_ctype_f16 c, float_status *fpst) | ||
1313 | -{ | ||
1314 | - return float16_muladd(a, b, c, 0, fpst); | ||
1315 | -} | ||
1316 | - | ||
1317 | -float32 VFP_HELPER(muladd, s)(float32 a, float32 b, float32 c, | ||
1318 | - float_status *fpst) | ||
1319 | -{ | ||
1320 | - return float32_muladd(a, b, c, 0, fpst); | ||
1321 | -} | ||
1322 | - | ||
1323 | -float64 VFP_HELPER(muladd, d)(float64 a, float64 b, float64 c, | ||
1324 | - float_status *fpst) | ||
1325 | -{ | ||
1326 | - return float64_muladd(a, b, c, 0, fpst); | ||
1327 | -} | ||
1328 | - | ||
1329 | -/* ARMv8 round to integral */ | ||
1330 | -dh_ctype_f16 HELPER(rinth_exact)(dh_ctype_f16 x, float_status *fp_status) | ||
1331 | -{ | ||
1332 | - return float16_round_to_int(x, fp_status); | ||
1333 | -} | ||
1334 | - | ||
1335 | -float32 HELPER(rints_exact)(float32 x, float_status *fp_status) | ||
1336 | -{ | ||
1337 | - return float32_round_to_int(x, fp_status); | ||
1338 | -} | ||
1339 | - | ||
1340 | -float64 HELPER(rintd_exact)(float64 x, float_status *fp_status) | ||
1341 | -{ | ||
1342 | - return float64_round_to_int(x, fp_status); | ||
1343 | -} | ||
1344 | - | ||
1345 | -dh_ctype_f16 HELPER(rinth)(dh_ctype_f16 x, float_status *fp_status) | ||
1346 | -{ | ||
1347 | - int old_flags = get_float_exception_flags(fp_status), new_flags; | ||
1348 | - float16 ret; | ||
1349 | - | ||
1350 | - ret = float16_round_to_int(x, fp_status); | ||
1351 | - | ||
1352 | - /* Suppress any inexact exceptions the conversion produced */ | ||
1353 | - if (!(old_flags & float_flag_inexact)) { | ||
1354 | - new_flags = get_float_exception_flags(fp_status); | ||
1355 | - set_float_exception_flags(new_flags & ~float_flag_inexact, fp_status); | ||
1356 | - } | ||
1357 | - | ||
1358 | - return ret; | ||
1359 | -} | ||
1360 | - | ||
1361 | -float32 HELPER(rints)(float32 x, float_status *fp_status) | ||
1362 | -{ | ||
1363 | - int old_flags = get_float_exception_flags(fp_status), new_flags; | ||
1364 | - float32 ret; | ||
1365 | - | ||
1366 | - ret = float32_round_to_int(x, fp_status); | ||
1367 | - | ||
1368 | - /* Suppress any inexact exceptions the conversion produced */ | ||
1369 | - if (!(old_flags & float_flag_inexact)) { | ||
1370 | - new_flags = get_float_exception_flags(fp_status); | ||
1371 | - set_float_exception_flags(new_flags & ~float_flag_inexact, fp_status); | ||
1372 | - } | ||
1373 | - | ||
1374 | - return ret; | ||
1375 | -} | ||
1376 | - | ||
1377 | -float64 HELPER(rintd)(float64 x, float_status *fp_status) | ||
1378 | -{ | ||
1379 | - int old_flags = get_float_exception_flags(fp_status), new_flags; | ||
1380 | - float64 ret; | ||
1381 | - | ||
1382 | - ret = float64_round_to_int(x, fp_status); | ||
1383 | - | ||
1384 | - /* Suppress any inexact exceptions the conversion produced */ | ||
1385 | - if (!(old_flags & float_flag_inexact)) { | ||
1386 | - new_flags = get_float_exception_flags(fp_status); | ||
1387 | - set_float_exception_flags(new_flags & ~float_flag_inexact, fp_status); | ||
1388 | - } | ||
1389 | - | ||
1390 | - return ret; | ||
1391 | -} | ||
1392 | - | ||
1393 | -/* Convert ARM rounding mode to softfloat */ | ||
1394 | -const FloatRoundMode arm_rmode_to_sf_map[] = { | ||
1395 | - [FPROUNDING_TIEEVEN] = float_round_nearest_even, | ||
1396 | - [FPROUNDING_POSINF] = float_round_up, | ||
1397 | - [FPROUNDING_NEGINF] = float_round_down, | ||
1398 | - [FPROUNDING_ZERO] = float_round_to_zero, | ||
1399 | - [FPROUNDING_TIEAWAY] = float_round_ties_away, | ||
1400 | - [FPROUNDING_ODD] = float_round_to_odd, | ||
1401 | -}; | ||
1402 | - | ||
1403 | -/* | ||
1404 | - * Implement float64 to int32_t conversion without saturation; | ||
1405 | - * the result is supplied modulo 2^32. | ||
1406 | - */ | ||
1407 | -uint64_t HELPER(fjcvtzs)(float64 value, float_status *status) | ||
1408 | -{ | ||
1409 | - uint32_t frac, e_old, e_new; | ||
1410 | - bool inexact; | ||
1411 | - | ||
1412 | - e_old = get_float_exception_flags(status); | ||
1413 | - set_float_exception_flags(0, status); | ||
1414 | - frac = float64_to_int32_modulo(value, float_round_to_zero, status); | ||
1415 | - e_new = get_float_exception_flags(status); | ||
1416 | - set_float_exception_flags(e_old | e_new, status); | ||
1417 | - | ||
1418 | - /* Normal inexact, denormal with flush-to-zero, or overflow or NaN */ | ||
1419 | - inexact = e_new & (float_flag_inexact | | ||
1420 | - float_flag_input_denormal_flushed | | ||
1421 | - float_flag_invalid); | ||
1422 | - | ||
1423 | - /* While not inexact for IEEE FP, -0.0 is inexact for JavaScript. */ | ||
1424 | - inexact |= value == float64_chs(float64_zero); | ||
1425 | - | ||
1426 | - /* Pack the result and the env->ZF representation of Z together. */ | ||
1427 | - return deposit64(frac, 32, 32, inexact); | ||
1428 | -} | ||
1429 | - | ||
1430 | -uint32_t HELPER(vjcvt)(float64 value, CPUARMState *env) | ||
1431 | -{ | ||
1432 | - uint64_t pair = HELPER(fjcvtzs)(value, &env->vfp.fp_status[FPST_A32]); | ||
1433 | - uint32_t result = pair; | ||
1434 | - uint32_t z = (pair >> 32) == 0; | ||
1435 | - | ||
1436 | - /* Store Z, clear NCV, in FPSCR.NZCV. */ | ||
1437 | - env->vfp.fpsr = (env->vfp.fpsr & ~FPSR_NZCV_MASK) | (z * FPSR_Z); | ||
1438 | - | ||
1439 | - return result; | ||
1440 | -} | ||
1441 | - | ||
1442 | -/* Round a float32 to an integer that fits in int32_t or int64_t. */ | ||
1443 | -static float32 frint_s(float32 f, float_status *fpst, int intsize) | ||
1444 | -{ | ||
1445 | - int old_flags = get_float_exception_flags(fpst); | ||
1446 | - uint32_t exp = extract32(f, 23, 8); | ||
1447 | - | ||
1448 | - if (unlikely(exp == 0xff)) { | ||
1449 | - /* NaN or Inf. */ | ||
1450 | - goto overflow; | ||
1451 | - } | ||
1452 | - | ||
1453 | - /* Round and re-extract the exponent. */ | ||
1454 | - f = float32_round_to_int(f, fpst); | ||
1455 | - exp = extract32(f, 23, 8); | ||
1456 | - | ||
1457 | - /* Validate the range of the result. */ | ||
1458 | - if (exp < 126 + intsize) { | ||
1459 | - /* abs(F) <= INT{N}_MAX */ | ||
1460 | - return f; | ||
1461 | - } | ||
1462 | - if (exp == 126 + intsize) { | ||
1463 | - uint32_t sign = extract32(f, 31, 1); | ||
1464 | - uint32_t frac = extract32(f, 0, 23); | ||
1465 | - if (sign && frac == 0) { | ||
1466 | - /* F == INT{N}_MIN */ | ||
1467 | - return f; | ||
1468 | - } | ||
1469 | - } | ||
1470 | - | ||
1471 | - overflow: | ||
1472 | - /* | ||
1473 | - * Raise Invalid and return INT{N}_MIN as a float. Revert any | ||
1474 | - * inexact exception float32_round_to_int may have raised. | ||
1475 | - */ | ||
1476 | - set_float_exception_flags(old_flags | float_flag_invalid, fpst); | ||
1477 | - return (0x100u + 126u + intsize) << 23; | ||
1478 | -} | ||
1479 | - | ||
1480 | -float32 HELPER(frint32_s)(float32 f, float_status *fpst) | ||
1481 | -{ | ||
1482 | - return frint_s(f, fpst, 32); | ||
1483 | -} | ||
1484 | - | ||
1485 | -float32 HELPER(frint64_s)(float32 f, float_status *fpst) | ||
1486 | -{ | ||
1487 | - return frint_s(f, fpst, 64); | ||
1488 | -} | ||
1489 | - | ||
1490 | -/* Round a float64 to an integer that fits in int32_t or int64_t. */ | ||
1491 | -static float64 frint_d(float64 f, float_status *fpst, int intsize) | ||
1492 | -{ | ||
1493 | - int old_flags = get_float_exception_flags(fpst); | ||
1494 | - uint32_t exp = extract64(f, 52, 11); | ||
1495 | - | ||
1496 | - if (unlikely(exp == 0x7ff)) { | ||
1497 | - /* NaN or Inf. */ | ||
1498 | - goto overflow; | ||
1499 | - } | ||
1500 | - | ||
1501 | - /* Round and re-extract the exponent. */ | ||
1502 | - f = float64_round_to_int(f, fpst); | ||
1503 | - exp = extract64(f, 52, 11); | ||
1504 | - | ||
1505 | - /* Validate the range of the result. */ | ||
1506 | - if (exp < 1022 + intsize) { | ||
1507 | - /* abs(F) <= INT{N}_MAX */ | ||
1508 | - return f; | ||
1509 | - } | ||
1510 | - if (exp == 1022 + intsize) { | ||
1511 | - uint64_t sign = extract64(f, 63, 1); | ||
1512 | - uint64_t frac = extract64(f, 0, 52); | ||
1513 | - if (sign && frac == 0) { | ||
1514 | - /* F == INT{N}_MIN */ | ||
1515 | - return f; | ||
1516 | - } | ||
1517 | - } | ||
1518 | - | ||
1519 | - overflow: | ||
1520 | - /* | ||
1521 | - * Raise Invalid and return INT{N}_MIN as a float. Revert any | ||
1522 | - * inexact exception float64_round_to_int may have raised. | ||
1523 | - */ | ||
1524 | - set_float_exception_flags(old_flags | float_flag_invalid, fpst); | ||
1525 | - return (uint64_t)(0x800 + 1022 + intsize) << 52; | ||
1526 | -} | ||
1527 | - | ||
1528 | -float64 HELPER(frint32_d)(float64 f, float_status *fpst) | ||
1529 | -{ | ||
1530 | - return frint_d(f, fpst, 32); | ||
1531 | -} | ||
1532 | - | ||
1533 | -float64 HELPER(frint64_d)(float64 f, float_status *fpst) | ||
1534 | -{ | ||
1535 | - return frint_d(f, fpst, 64); | ||
1536 | -} | ||
1537 | - | ||
1538 | -void HELPER(check_hcr_el2_trap)(CPUARMState *env, uint32_t rt, uint32_t reg) | ||
1539 | -{ | ||
1540 | - uint32_t syndrome; | ||
1541 | - | ||
1542 | - switch (reg) { | ||
1543 | - case ARM_VFP_MVFR0: | ||
1544 | - case ARM_VFP_MVFR1: | ||
1545 | - case ARM_VFP_MVFR2: | ||
1546 | - if (!(arm_hcr_el2_eff(env) & HCR_TID3)) { | ||
1547 | - return; | ||
1548 | - } | ||
124 | - break; | 1549 | - break; |
125 | - case AST2500_A0_SILICON_REV: | 1550 | - case ARM_VFP_FPSID: |
126 | - case AST2500_A1_SILICON_REV: | 1551 | - if (!(arm_hcr_el2_eff(env) & HCR_TID0)) { |
127 | - reset = ast2500_a1_resets; | 1552 | - return; |
128 | - calc_hpll = aspeed_scu_calc_hpll_ast2500; | 1553 | - } |
129 | - break; | 1554 | - break; |
130 | - default: | 1555 | - default: |
131 | - g_assert_not_reached(); | 1556 | - g_assert_not_reached(); |
132 | - } | 1557 | - } |
133 | - | 1558 | - |
134 | - memcpy(s->regs, reset, sizeof(s->regs)); | 1559 | - syndrome = ((EC_FPIDTRAP << ARM_EL_EC_SHIFT) |
135 | + memcpy(s->regs, asc->resets, sizeof(s->regs)); | 1560 | - | ARM_EL_IL |
136 | s->regs[SILICON_REV] = s->silicon_rev; | 1561 | - | (1 << 24) | (0xe << 20) | (7 << 14) |
137 | s->regs[HW_STRAP1] = s->hw_strap1; | 1562 | - | (reg << 10) | (rt << 5) | 1); |
138 | s->regs[HW_STRAP2] = s->hw_strap2; | 1563 | - |
139 | @@ -XXX,XX +XXX,XX @@ static void aspeed_scu_reset(DeviceState *dev) | 1564 | - raise_exception(env, EXCP_HYP_TRAP, syndrome, 2); |
140 | * All registers are set. Now compute the frequencies of the main clocks | 1565 | -} |
141 | */ | 1566 | - |
142 | s->clkin = aspeed_scu_get_clkin(s); | 1567 | -#endif |
143 | - s->hpll = calc_hpll(s); | 1568 | diff --git a/target/arm/tcg/meson.build b/target/arm/tcg/meson.build |
144 | + s->hpll = asc->calc_hpll(s); | 1569 | index XXXXXXX..XXXXXXX 100644 |
145 | aspeed_scu_set_apb_freq(s); | 1570 | --- a/target/arm/tcg/meson.build |
146 | } | 1571 | +++ b/target/arm/tcg/meson.build |
147 | 1572 | @@ -XXX,XX +XXX,XX @@ arm_ss.add(files( | |
148 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo aspeed_scu_info = { | 1573 | 'vec_helper.c', |
149 | .parent = TYPE_SYS_BUS_DEVICE, | 1574 | 'tlb-insns.c', |
150 | .instance_size = sizeof(AspeedSCUState), | 1575 | 'arith_helper.c', |
151 | .class_init = aspeed_scu_class_init, | 1576 | + 'vfp_helper.c', |
152 | + .class_size = sizeof(AspeedSCUClass), | 1577 | )) |
153 | + .abstract = true, | 1578 | |
154 | +}; | 1579 | arm_ss.add(when: 'TARGET_AARCH64', if_true: files( |
155 | + | ||
156 | +static void aspeed_2400_scu_class_init(ObjectClass *klass, void *data) | ||
157 | +{ | ||
158 | + DeviceClass *dc = DEVICE_CLASS(klass); | ||
159 | + AspeedSCUClass *asc = ASPEED_SCU_CLASS(klass); | ||
160 | + | ||
161 | + dc->desc = "ASPEED 2400 System Control Unit"; | ||
162 | + asc->resets = ast2400_a0_resets; | ||
163 | + asc->calc_hpll = aspeed_2400_scu_calc_hpll; | ||
164 | + asc->apb_divider = 2; | ||
165 | +} | ||
166 | + | ||
167 | +static const TypeInfo aspeed_2400_scu_info = { | ||
168 | + .name = TYPE_ASPEED_2400_SCU, | ||
169 | + .parent = TYPE_ASPEED_SCU, | ||
170 | + .instance_size = sizeof(AspeedSCUState), | ||
171 | + .class_init = aspeed_2400_scu_class_init, | ||
172 | +}; | ||
173 | + | ||
174 | +static void aspeed_2500_scu_class_init(ObjectClass *klass, void *data) | ||
175 | +{ | ||
176 | + DeviceClass *dc = DEVICE_CLASS(klass); | ||
177 | + AspeedSCUClass *asc = ASPEED_SCU_CLASS(klass); | ||
178 | + | ||
179 | + dc->desc = "ASPEED 2500 System Control Unit"; | ||
180 | + asc->resets = ast2500_a1_resets; | ||
181 | + asc->calc_hpll = aspeed_2500_scu_calc_hpll; | ||
182 | + asc->apb_divider = 4; | ||
183 | +} | ||
184 | + | ||
185 | +static const TypeInfo aspeed_2500_scu_info = { | ||
186 | + .name = TYPE_ASPEED_2500_SCU, | ||
187 | + .parent = TYPE_ASPEED_SCU, | ||
188 | + .instance_size = sizeof(AspeedSCUState), | ||
189 | + .class_init = aspeed_2500_scu_class_init, | ||
190 | }; | ||
191 | |||
192 | static void aspeed_scu_register_types(void) | ||
193 | { | ||
194 | type_register_static(&aspeed_scu_info); | ||
195 | + type_register_static(&aspeed_2400_scu_info); | ||
196 | + type_register_static(&aspeed_2500_scu_info); | ||
197 | } | ||
198 | |||
199 | type_init(aspeed_scu_register_types); | ||
200 | -- | 1580 | -- |
201 | 2.20.1 | 1581 | 2.43.0 |
202 | |||
203 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Currently the helper_vfp_get_fpscr() and helper_vfp_set_fpscr() | ||
2 | functions do the actual work of updating the FPSCR, and we have | ||
3 | wrappers vfp_get_fpscr() and vfp_set_fpscr() which we use for calls | ||
4 | from other QEMU C code. | ||
1 | 5 | ||
6 | Flip these around so that it is vfp_get_fpscr() and vfp_set_fpscr() | ||
7 | which do the actual work, and helper_vfp_get_fpscr() and | ||
8 | helper_vfp_set_fpscr() which are the wrappers; this allows us to move | ||
9 | them to tcg/vfp_helper.c. | ||
10 | |||
11 | Since this is the last HELPER() we had in arm/vfp_helper.c, we can | ||
12 | drop the include of helper-proto.h. | ||
13 | |||
14 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
15 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
16 | Message-id: 20250221190957.811948-3-peter.maydell@linaro.org | ||
17 | --- | ||
18 | target/arm/tcg/vfp_helper.c | 10 ++++++++++ | ||
19 | target/arm/vfp_helper.c | 15 ++------------- | ||
20 | 2 files changed, 12 insertions(+), 13 deletions(-) | ||
21 | |||
22 | diff --git a/target/arm/tcg/vfp_helper.c b/target/arm/tcg/vfp_helper.c | ||
23 | index XXXXXXX..XXXXXXX 100644 | ||
24 | --- a/target/arm/tcg/vfp_helper.c | ||
25 | +++ b/target/arm/tcg/vfp_helper.c | ||
26 | @@ -XXX,XX +XXX,XX @@ void HELPER(check_hcr_el2_trap)(CPUARMState *env, uint32_t rt, uint32_t reg) | ||
27 | |||
28 | raise_exception(env, EXCP_HYP_TRAP, syndrome, 2); | ||
29 | } | ||
30 | + | ||
31 | +uint32_t HELPER(vfp_get_fpscr)(CPUARMState *env) | ||
32 | +{ | ||
33 | + return vfp_get_fpscr(env); | ||
34 | +} | ||
35 | + | ||
36 | +void HELPER(vfp_set_fpscr)(CPUARMState *env, uint32_t val) | ||
37 | +{ | ||
38 | + vfp_set_fpscr(env, val); | ||
39 | +} | ||
40 | diff --git a/target/arm/vfp_helper.c b/target/arm/vfp_helper.c | ||
41 | index XXXXXXX..XXXXXXX 100644 | ||
42 | --- a/target/arm/vfp_helper.c | ||
43 | +++ b/target/arm/vfp_helper.c | ||
44 | @@ -XXX,XX +XXX,XX @@ | ||
45 | |||
46 | #include "qemu/osdep.h" | ||
47 | #include "cpu.h" | ||
48 | -#include "exec/helper-proto.h" | ||
49 | #include "internals.h" | ||
50 | #include "cpu-features.h" | ||
51 | #include "fpu/softfloat.h" | ||
52 | @@ -XXX,XX +XXX,XX @@ uint32_t vfp_get_fpsr(CPUARMState *env) | ||
53 | return fpsr; | ||
54 | } | ||
55 | |||
56 | -uint32_t HELPER(vfp_get_fpscr)(CPUARMState *env) | ||
57 | +uint32_t vfp_get_fpscr(CPUARMState *env) | ||
58 | { | ||
59 | return (vfp_get_fpcr(env) & FPSCR_FPCR_MASK) | | ||
60 | (vfp_get_fpsr(env) & FPSCR_FPSR_MASK); | ||
61 | } | ||
62 | |||
63 | -uint32_t vfp_get_fpscr(CPUARMState *env) | ||
64 | -{ | ||
65 | - return HELPER(vfp_get_fpscr)(env); | ||
66 | -} | ||
67 | - | ||
68 | void vfp_set_fpsr(CPUARMState *env, uint32_t val) | ||
69 | { | ||
70 | ARMCPU *cpu = env_archcpu(env); | ||
71 | @@ -XXX,XX +XXX,XX @@ void vfp_set_fpcr(CPUARMState *env, uint32_t val) | ||
72 | vfp_set_fpcr_masked(env, val, MAKE_64BIT_MASK(0, 32)); | ||
73 | } | ||
74 | |||
75 | -void HELPER(vfp_set_fpscr)(CPUARMState *env, uint32_t val) | ||
76 | +void vfp_set_fpscr(CPUARMState *env, uint32_t val) | ||
77 | { | ||
78 | vfp_set_fpcr_masked(env, val, FPSCR_FPCR_MASK); | ||
79 | vfp_set_fpsr(env, val & FPSCR_FPSR_MASK); | ||
80 | } | ||
81 | - | ||
82 | -void vfp_set_fpscr(CPUARMState *env, uint32_t val) | ||
83 | -{ | ||
84 | - HELPER(vfp_set_fpscr)(env, val); | ||
85 | -} | ||
86 | -- | ||
87 | 2.43.0 | diff view generated by jsdifflib |
1 | From: Cédric Le Goater <clg@kaod.org> | 1 | The softfloat (i.e. TCG) specific handling for the FPCR |
---|---|---|---|
2 | and FPSR is abstracted behind five functions: | ||
3 | arm_set_default_fp_behaviours | ||
4 | arm_set_ah_fp_behaviours | ||
5 | vfp_get_fpsr_from_host | ||
6 | vfp_clear_float_status_exc_flags | ||
7 | vfp_set_fpsr_to_host | ||
2 | 8 | ||
3 | Emulate read errors in the DMA Checksum Register for high frequencies | 9 | Currently we rely on the first two calling softfloat functions that |
4 | and optimistic settings of the Read Timing Compensation Register. This | 10 | work even in a KVM-only compile because they're defined as inline in |
5 | will help in tuning the SPI timing calibration algorithm. Errors are | 11 | the softfloat header file, and we provide stub versions of the last |
6 | only injected when the property "inject_failure" is set to true as | 12 | three in arm/vfp_helper.c if CONFIG_TCG isn't defined. |
7 | suggested by Philippe. | ||
8 | 13 | ||
9 | The values below are those to expect from the first flash device of | 14 | Move the softfloat-specific versions of these functions to |
10 | the FMC controller of a palmetto-bmc machine. | 15 | tcg/vfp_helper.c, and provide the non-TCG stub versions in |
16 | tcg-stubs.c. | ||
11 | 17 | ||
12 | Cc: Philippe Mathieu-Daudé <philmd@redhat.com> | 18 | This lets us drop the softfloat header include and the last |
13 | Signed-off-by: Cédric Le Goater <clg@kaod.org> | 19 | set of CONFIG_TCG ifdefs from arm/vfp_helper.c. |
14 | Reviewed-by: Joel Stanley <joel@jms.id.au> | 20 | |
15 | Message-id: 20190904070506.1052-8-clg@kaod.org | ||
16 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 21 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
22 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
23 | Message-id: 20250221190957.811948-4-peter.maydell@linaro.org | ||
17 | --- | 24 | --- |
18 | include/hw/ssi/aspeed_smc.h | 1 + | 25 | target/arm/internals.h | 9 ++ |
19 | hw/ssi/aspeed_smc.c | 36 ++++++++++++++++++++++++++++++++++++ | 26 | target/arm/tcg-stubs.c | 22 ++++ |
20 | 2 files changed, 37 insertions(+) | 27 | target/arm/tcg/vfp_helper.c | 228 +++++++++++++++++++++++++++++++++ |
28 | target/arm/vfp_helper.c | 248 ------------------------------------ | ||
29 | 4 files changed, 259 insertions(+), 248 deletions(-) | ||
21 | 30 | ||
22 | diff --git a/include/hw/ssi/aspeed_smc.h b/include/hw/ssi/aspeed_smc.h | 31 | diff --git a/target/arm/internals.h b/target/arm/internals.h |
23 | index XXXXXXX..XXXXXXX 100644 | 32 | index XXXXXXX..XXXXXXX 100644 |
24 | --- a/include/hw/ssi/aspeed_smc.h | 33 | --- a/target/arm/internals.h |
25 | +++ b/include/hw/ssi/aspeed_smc.h | 34 | +++ b/target/arm/internals.h |
26 | @@ -XXX,XX +XXX,XX @@ typedef struct AspeedSMCState { | 35 | @@ -XXX,XX +XXX,XX @@ int alle1_tlbmask(CPUARMState *env); |
27 | 36 | void arm_set_default_fp_behaviours(float_status *s); | |
28 | uint32_t num_cs; | 37 | /* Set the float_status behaviour to match Arm FPCR.AH=1 behaviour */ |
29 | qemu_irq *cs_lines; | 38 | void arm_set_ah_fp_behaviours(float_status *s); |
30 | + bool inject_failure; | 39 | +/* Read the float_status info and return the appropriate FPSR value */ |
31 | 40 | +uint32_t vfp_get_fpsr_from_host(CPUARMState *env); | |
32 | SSIBus *spi; | 41 | +/* Clear the exception status flags from all float_status fields */ |
33 | 42 | +void vfp_clear_float_status_exc_flags(CPUARMState *env); | |
34 | diff --git a/hw/ssi/aspeed_smc.c b/hw/ssi/aspeed_smc.c | 43 | +/* |
44 | + * Update float_status fields to handle the bits of the FPCR | ||
45 | + * specified by mask changing to the values in val. | ||
46 | + */ | ||
47 | +void vfp_set_fpcr_to_host(CPUARMState *env, uint32_t val, uint32_t mask); | ||
48 | |||
49 | #endif | ||
50 | diff --git a/target/arm/tcg-stubs.c b/target/arm/tcg-stubs.c | ||
35 | index XXXXXXX..XXXXXXX 100644 | 51 | index XXXXXXX..XXXXXXX 100644 |
36 | --- a/hw/ssi/aspeed_smc.c | 52 | --- a/target/arm/tcg-stubs.c |
37 | +++ b/hw/ssi/aspeed_smc.c | 53 | +++ b/target/arm/tcg-stubs.c |
38 | @@ -XXX,XX +XXX,XX @@ static void aspeed_smc_dma_calibration(AspeedSMCState *s) | 54 | @@ -XXX,XX +XXX,XX @@ void assert_hflags_rebuild_correctly(CPUARMState *env) |
39 | s->regs[s->r_ctrl0 + cs] |= CE_CTRL_CLOCK_FREQ(hclk_div); | 55 | void define_tlb_insn_regs(ARMCPU *cpu) |
56 | { | ||
40 | } | 57 | } |
58 | + | ||
59 | +/* With KVM, we never use float_status, so these can be no-ops */ | ||
60 | +void arm_set_default_fp_behaviours(float_status *s) | ||
61 | +{ | ||
62 | +} | ||
63 | + | ||
64 | +void arm_set_ah_fp_behaviours(float_status *s) | ||
65 | +{ | ||
66 | +} | ||
67 | + | ||
68 | +uint32_t vfp_get_fpsr_from_host(CPUARMState *env) | ||
69 | +{ | ||
70 | + return 0; | ||
71 | +} | ||
72 | + | ||
73 | +void vfp_clear_float_status_exc_flags(CPUARMState *env) | ||
74 | +{ | ||
75 | +} | ||
76 | + | ||
77 | +void vfp_set_fpcr_to_host(CPUARMState *env, uint32_t val, uint32_t mask) | ||
78 | +{ | ||
79 | +} | ||
80 | diff --git a/target/arm/tcg/vfp_helper.c b/target/arm/tcg/vfp_helper.c | ||
81 | index XXXXXXX..XXXXXXX 100644 | ||
82 | --- a/target/arm/tcg/vfp_helper.c | ||
83 | +++ b/target/arm/tcg/vfp_helper.c | ||
84 | @@ -XXX,XX +XXX,XX @@ | ||
85 | #include "fpu/softfloat.h" | ||
86 | #include "qemu/log.h" | ||
41 | 87 | ||
42 | +/* | 88 | +/* |
43 | + * Emulate read errors in the DMA Checksum Register for high | 89 | + * Set the float_status behaviour to match the Arm defaults: |
44 | + * frequencies and optimistic settings of the Read Timing Compensation | 90 | + * * tininess-before-rounding |
45 | + * Register. This will help in tuning the SPI timing calibration | 91 | + * * 2-input NaN propagation prefers SNaN over QNaN, and then |
46 | + * algorithm. | 92 | + * operand A over operand B (see FPProcessNaNs() pseudocode) |
93 | + * * 3-input NaN propagation prefers SNaN over QNaN, and then | ||
94 | + * operand C over A over B (see FPProcessNaNs3() pseudocode, | ||
95 | + * but note that for QEMU muladd is a * b + c, whereas for | ||
96 | + * the pseudocode function the arguments are in the order c, a, b. | ||
97 | + * * 0 * Inf + NaN returns the default NaN if the input NaN is quiet, | ||
98 | + * and the input NaN if it is signalling | ||
99 | + * * Default NaN has sign bit clear, msb frac bit set | ||
47 | + */ | 100 | + */ |
48 | +static bool aspeed_smc_inject_read_failure(AspeedSMCState *s) | 101 | +void arm_set_default_fp_behaviours(float_status *s) |
49 | +{ | 102 | +{ |
50 | + uint8_t delay = | 103 | + set_float_detect_tininess(float_tininess_before_rounding, s); |
51 | + (s->regs[R_DMA_CTRL] >> DMA_CTRL_DELAY_SHIFT) & DMA_CTRL_DELAY_MASK; | 104 | + set_float_ftz_detection(float_ftz_before_rounding, s); |
52 | + uint8_t hclk_mask = | 105 | + set_float_2nan_prop_rule(float_2nan_prop_s_ab, s); |
53 | + (s->regs[R_DMA_CTRL] >> DMA_CTRL_FREQ_SHIFT) & DMA_CTRL_FREQ_MASK; | 106 | + set_float_3nan_prop_rule(float_3nan_prop_s_cab, s); |
54 | + | 107 | + set_float_infzeronan_rule(float_infzeronan_dnan_if_qnan, s); |
108 | + set_float_default_nan_pattern(0b01000000, s); | ||
109 | +} | ||
110 | + | ||
111 | +/* | ||
112 | + * Set the float_status behaviour to match the FEAT_AFP | ||
113 | + * FPCR.AH=1 requirements: | ||
114 | + * * tininess-after-rounding | ||
115 | + * * 2-input NaN propagation prefers the first NaN | ||
116 | + * * 3-input NaN propagation prefers a over b over c | ||
117 | + * * 0 * Inf + NaN always returns the input NaN and doesn't | ||
118 | + * set Invalid for a QNaN | ||
119 | + * * default NaN has sign bit set, msb frac bit set | ||
120 | + */ | ||
121 | +void arm_set_ah_fp_behaviours(float_status *s) | ||
122 | +{ | ||
123 | + set_float_detect_tininess(float_tininess_after_rounding, s); | ||
124 | + set_float_ftz_detection(float_ftz_after_rounding, s); | ||
125 | + set_float_2nan_prop_rule(float_2nan_prop_ab, s); | ||
126 | + set_float_3nan_prop_rule(float_3nan_prop_abc, s); | ||
127 | + set_float_infzeronan_rule(float_infzeronan_dnan_never | | ||
128 | + float_infzeronan_suppress_invalid, s); | ||
129 | + set_float_default_nan_pattern(0b11000000, s); | ||
130 | +} | ||
131 | + | ||
132 | +/* Convert host exception flags to vfp form. */ | ||
133 | +static inline uint32_t vfp_exceptbits_from_host(int host_bits, bool ah) | ||
134 | +{ | ||
135 | + uint32_t target_bits = 0; | ||
136 | + | ||
137 | + if (host_bits & float_flag_invalid) { | ||
138 | + target_bits |= FPSR_IOC; | ||
139 | + } | ||
140 | + if (host_bits & float_flag_divbyzero) { | ||
141 | + target_bits |= FPSR_DZC; | ||
142 | + } | ||
143 | + if (host_bits & float_flag_overflow) { | ||
144 | + target_bits |= FPSR_OFC; | ||
145 | + } | ||
146 | + if (host_bits & (float_flag_underflow | float_flag_output_denormal_flushed)) { | ||
147 | + target_bits |= FPSR_UFC; | ||
148 | + } | ||
149 | + if (host_bits & float_flag_inexact) { | ||
150 | + target_bits |= FPSR_IXC; | ||
151 | + } | ||
152 | + if (host_bits & float_flag_input_denormal_flushed) { | ||
153 | + target_bits |= FPSR_IDC; | ||
154 | + } | ||
55 | + /* | 155 | + /* |
56 | + * Typical values of a palmetto-bmc machine. | 156 | + * With FPCR.AH, IDC is set when an input denormal is used, |
157 | + * and flushing an output denormal to zero sets both IXC and UFC. | ||
57 | + */ | 158 | + */ |
58 | + switch (aspeed_smc_hclk_divisor(hclk_mask)) { | 159 | + if (ah && (host_bits & float_flag_input_denormal_used)) { |
59 | + case 4 ... 16: | 160 | + target_bits |= FPSR_IDC; |
60 | + return false; | 161 | + } |
61 | + case 3: /* at least one HCLK cycle delay */ | 162 | + if (ah && (host_bits & float_flag_output_denormal_flushed)) { |
62 | + return (delay & 0x7) < 1; | 163 | + target_bits |= FPSR_IXC; |
63 | + case 2: /* at least two HCLK cycle delay */ | 164 | + } |
64 | + return (delay & 0x7) < 2; | 165 | + return target_bits; |
65 | + case 1: /* (> 100MHz) is above the max freq of the controller */ | 166 | +} |
66 | + return true; | 167 | + |
67 | + default: | 168 | +uint32_t vfp_get_fpsr_from_host(CPUARMState *env) |
68 | + g_assert_not_reached(); | 169 | +{ |
170 | + uint32_t a32_flags = 0, a64_flags = 0; | ||
171 | + | ||
172 | + a32_flags |= get_float_exception_flags(&env->vfp.fp_status[FPST_A32]); | ||
173 | + a32_flags |= get_float_exception_flags(&env->vfp.fp_status[FPST_STD]); | ||
174 | + /* FZ16 does not generate an input denormal exception. */ | ||
175 | + a32_flags |= (get_float_exception_flags(&env->vfp.fp_status[FPST_A32_F16]) | ||
176 | + & ~float_flag_input_denormal_flushed); | ||
177 | + a32_flags |= (get_float_exception_flags(&env->vfp.fp_status[FPST_STD_F16]) | ||
178 | + & ~float_flag_input_denormal_flushed); | ||
179 | + | ||
180 | + a64_flags |= get_float_exception_flags(&env->vfp.fp_status[FPST_A64]); | ||
181 | + a64_flags |= (get_float_exception_flags(&env->vfp.fp_status[FPST_A64_F16]) | ||
182 | + & ~(float_flag_input_denormal_flushed | float_flag_input_denormal_used)); | ||
183 | + /* | ||
184 | + * We do not merge in flags from FPST_AH or FPST_AH_F16, because | ||
185 | + * they are used for insns that must not set the cumulative exception bits. | ||
186 | + */ | ||
187 | + | ||
188 | + /* | ||
189 | + * Flushing an input denormal *only* because FPCR.FIZ == 1 does | ||
190 | + * not set FPSR.IDC; if FPCR.FZ is also set then this takes | ||
191 | + * precedence and IDC is set (see the FPUnpackBase pseudocode). | ||
192 | + * So squash it unless (FPCR.AH == 0 && FPCR.FZ == 1). | ||
193 | + * We only do this for the a64 flags because FIZ has no effect | ||
194 | + * on AArch32 even if it is set. | ||
195 | + */ | ||
196 | + if ((env->vfp.fpcr & (FPCR_FZ | FPCR_AH)) != FPCR_FZ) { | ||
197 | + a64_flags &= ~float_flag_input_denormal_flushed; | ||
198 | + } | ||
199 | + return vfp_exceptbits_from_host(a64_flags, env->vfp.fpcr & FPCR_AH) | | ||
200 | + vfp_exceptbits_from_host(a32_flags, false); | ||
201 | +} | ||
202 | + | ||
203 | +void vfp_clear_float_status_exc_flags(CPUARMState *env) | ||
204 | +{ | ||
205 | + /* | ||
206 | + * Clear out all the exception-flag information in the float_status | ||
207 | + * values. The caller should have arranged for env->vfp.fpsr to | ||
208 | + * be the architecturally up-to-date exception flag information first. | ||
209 | + */ | ||
210 | + set_float_exception_flags(0, &env->vfp.fp_status[FPST_A32]); | ||
211 | + set_float_exception_flags(0, &env->vfp.fp_status[FPST_A64]); | ||
212 | + set_float_exception_flags(0, &env->vfp.fp_status[FPST_A32_F16]); | ||
213 | + set_float_exception_flags(0, &env->vfp.fp_status[FPST_A64_F16]); | ||
214 | + set_float_exception_flags(0, &env->vfp.fp_status[FPST_STD]); | ||
215 | + set_float_exception_flags(0, &env->vfp.fp_status[FPST_STD_F16]); | ||
216 | + set_float_exception_flags(0, &env->vfp.fp_status[FPST_AH]); | ||
217 | + set_float_exception_flags(0, &env->vfp.fp_status[FPST_AH_F16]); | ||
218 | +} | ||
219 | + | ||
220 | +static void vfp_sync_and_clear_float_status_exc_flags(CPUARMState *env) | ||
221 | +{ | ||
222 | + /* | ||
223 | + * Synchronize any pending exception-flag information in the | ||
224 | + * float_status values into env->vfp.fpsr, and then clear out | ||
225 | + * the float_status data. | ||
226 | + */ | ||
227 | + env->vfp.fpsr |= vfp_get_fpsr_from_host(env); | ||
228 | + vfp_clear_float_status_exc_flags(env); | ||
229 | +} | ||
230 | + | ||
231 | +void vfp_set_fpcr_to_host(CPUARMState *env, uint32_t val, uint32_t mask) | ||
232 | +{ | ||
233 | + uint64_t changed = env->vfp.fpcr; | ||
234 | + | ||
235 | + changed ^= val; | ||
236 | + changed &= mask; | ||
237 | + if (changed & (3 << 22)) { | ||
238 | + int i = (val >> 22) & 3; | ||
239 | + switch (i) { | ||
240 | + case FPROUNDING_TIEEVEN: | ||
241 | + i = float_round_nearest_even; | ||
242 | + break; | ||
243 | + case FPROUNDING_POSINF: | ||
244 | + i = float_round_up; | ||
245 | + break; | ||
246 | + case FPROUNDING_NEGINF: | ||
247 | + i = float_round_down; | ||
248 | + break; | ||
249 | + case FPROUNDING_ZERO: | ||
250 | + i = float_round_to_zero; | ||
251 | + break; | ||
252 | + } | ||
253 | + set_float_rounding_mode(i, &env->vfp.fp_status[FPST_A32]); | ||
254 | + set_float_rounding_mode(i, &env->vfp.fp_status[FPST_A64]); | ||
255 | + set_float_rounding_mode(i, &env->vfp.fp_status[FPST_A32_F16]); | ||
256 | + set_float_rounding_mode(i, &env->vfp.fp_status[FPST_A64_F16]); | ||
257 | + } | ||
258 | + if (changed & FPCR_FZ16) { | ||
259 | + bool ftz_enabled = val & FPCR_FZ16; | ||
260 | + set_flush_to_zero(ftz_enabled, &env->vfp.fp_status[FPST_A32_F16]); | ||
261 | + set_flush_to_zero(ftz_enabled, &env->vfp.fp_status[FPST_A64_F16]); | ||
262 | + set_flush_to_zero(ftz_enabled, &env->vfp.fp_status[FPST_STD_F16]); | ||
263 | + set_flush_to_zero(ftz_enabled, &env->vfp.fp_status[FPST_AH_F16]); | ||
264 | + set_flush_inputs_to_zero(ftz_enabled, &env->vfp.fp_status[FPST_A32_F16]); | ||
265 | + set_flush_inputs_to_zero(ftz_enabled, &env->vfp.fp_status[FPST_A64_F16]); | ||
266 | + set_flush_inputs_to_zero(ftz_enabled, &env->vfp.fp_status[FPST_STD_F16]); | ||
267 | + set_flush_inputs_to_zero(ftz_enabled, &env->vfp.fp_status[FPST_AH_F16]); | ||
268 | + } | ||
269 | + if (changed & FPCR_FZ) { | ||
270 | + bool ftz_enabled = val & FPCR_FZ; | ||
271 | + set_flush_to_zero(ftz_enabled, &env->vfp.fp_status[FPST_A32]); | ||
272 | + set_flush_to_zero(ftz_enabled, &env->vfp.fp_status[FPST_A64]); | ||
273 | + /* FIZ is A64 only so FZ always makes A32 code flush inputs to zero */ | ||
274 | + set_flush_inputs_to_zero(ftz_enabled, &env->vfp.fp_status[FPST_A32]); | ||
275 | + } | ||
276 | + if (changed & (FPCR_FZ | FPCR_AH | FPCR_FIZ)) { | ||
277 | + /* | ||
278 | + * A64: Flush denormalized inputs to zero if FPCR.FIZ = 1, or | ||
279 | + * both FPCR.AH = 0 and FPCR.FZ = 1. | ||
280 | + */ | ||
281 | + bool fitz_enabled = (val & FPCR_FIZ) || | ||
282 | + (val & (FPCR_FZ | FPCR_AH)) == FPCR_FZ; | ||
283 | + set_flush_inputs_to_zero(fitz_enabled, &env->vfp.fp_status[FPST_A64]); | ||
284 | + } | ||
285 | + if (changed & FPCR_DN) { | ||
286 | + bool dnan_enabled = val & FPCR_DN; | ||
287 | + set_default_nan_mode(dnan_enabled, &env->vfp.fp_status[FPST_A32]); | ||
288 | + set_default_nan_mode(dnan_enabled, &env->vfp.fp_status[FPST_A64]); | ||
289 | + set_default_nan_mode(dnan_enabled, &env->vfp.fp_status[FPST_A32_F16]); | ||
290 | + set_default_nan_mode(dnan_enabled, &env->vfp.fp_status[FPST_A64_F16]); | ||
291 | + set_default_nan_mode(dnan_enabled, &env->vfp.fp_status[FPST_AH]); | ||
292 | + set_default_nan_mode(dnan_enabled, &env->vfp.fp_status[FPST_AH_F16]); | ||
293 | + } | ||
294 | + if (changed & FPCR_AH) { | ||
295 | + bool ah_enabled = val & FPCR_AH; | ||
296 | + | ||
297 | + if (ah_enabled) { | ||
298 | + /* Change behaviours for A64 FP operations */ | ||
299 | + arm_set_ah_fp_behaviours(&env->vfp.fp_status[FPST_A64]); | ||
300 | + arm_set_ah_fp_behaviours(&env->vfp.fp_status[FPST_A64_F16]); | ||
301 | + } else { | ||
302 | + arm_set_default_fp_behaviours(&env->vfp.fp_status[FPST_A64]); | ||
303 | + arm_set_default_fp_behaviours(&env->vfp.fp_status[FPST_A64_F16]); | ||
304 | + } | ||
305 | + } | ||
306 | + /* | ||
307 | + * If any bits changed that we look at in vfp_get_fpsr_from_host(), | ||
308 | + * we must sync the float_status flags into vfp.fpsr now (under the | ||
309 | + * old regime) before we update vfp.fpcr. | ||
310 | + */ | ||
311 | + if (changed & (FPCR_FZ | FPCR_AH | FPCR_FIZ)) { | ||
312 | + vfp_sync_and_clear_float_status_exc_flags(env); | ||
69 | + } | 313 | + } |
70 | +} | 314 | +} |
71 | + | 315 | + |
72 | /* | 316 | /* |
73 | * Accumulate the result of the reads to provide a checksum that will | 317 | * VFP support. We follow the convention used for VFP instructions: |
74 | * be used to validate the read timing settings. | 318 | * Single precision routines have a "s" suffix, double precision a |
75 | @@ -XXX,XX +XXX,XX @@ static void aspeed_smc_dma_checksum(AspeedSMCState *s) | 319 | diff --git a/target/arm/vfp_helper.c b/target/arm/vfp_helper.c |
76 | s->regs[R_DMA_FLASH_ADDR] += 4; | 320 | index XXXXXXX..XXXXXXX 100644 |
77 | s->regs[R_DMA_LEN] -= 4; | 321 | --- a/target/arm/vfp_helper.c |
78 | } | 322 | +++ b/target/arm/vfp_helper.c |
79 | + | 323 | @@ -XXX,XX +XXX,XX @@ |
80 | + if (s->inject_failure && aspeed_smc_inject_read_failure(s)) { | 324 | #include "cpu.h" |
81 | + s->regs[R_DMA_CHECKSUM] = 0xbadc0de; | 325 | #include "internals.h" |
82 | + } | 326 | #include "cpu-features.h" |
83 | + | 327 | -#include "fpu/softfloat.h" |
84 | } | 328 | - |
85 | 329 | -/* | |
86 | static void aspeed_smc_dma_rw(AspeedSMCState *s) | 330 | - * Set the float_status behaviour to match the Arm defaults: |
87 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_aspeed_smc = { | 331 | - * * tininess-before-rounding |
88 | 332 | - * * 2-input NaN propagation prefers SNaN over QNaN, and then | |
89 | static Property aspeed_smc_properties[] = { | 333 | - * operand A over operand B (see FPProcessNaNs() pseudocode) |
90 | DEFINE_PROP_UINT32("num-cs", AspeedSMCState, num_cs, 1), | 334 | - * * 3-input NaN propagation prefers SNaN over QNaN, and then |
91 | + DEFINE_PROP_BOOL("inject-failure", AspeedSMCState, inject_failure, false), | 335 | - * operand C over A over B (see FPProcessNaNs3() pseudocode, |
92 | DEFINE_PROP_UINT64("sdram-base", AspeedSMCState, sdram_base, 0), | 336 | - * but note that for QEMU muladd is a * b + c, whereas for |
93 | DEFINE_PROP_LINK("dram", AspeedSMCState, dram_mr, | 337 | - * the pseudocode function the arguments are in the order c, a, b. |
94 | TYPE_MEMORY_REGION, MemoryRegion *), | 338 | - * * 0 * Inf + NaN returns the default NaN if the input NaN is quiet, |
339 | - * and the input NaN if it is signalling | ||
340 | - * * Default NaN has sign bit clear, msb frac bit set | ||
341 | - */ | ||
342 | -void arm_set_default_fp_behaviours(float_status *s) | ||
343 | -{ | ||
344 | - set_float_detect_tininess(float_tininess_before_rounding, s); | ||
345 | - set_float_ftz_detection(float_ftz_before_rounding, s); | ||
346 | - set_float_2nan_prop_rule(float_2nan_prop_s_ab, s); | ||
347 | - set_float_3nan_prop_rule(float_3nan_prop_s_cab, s); | ||
348 | - set_float_infzeronan_rule(float_infzeronan_dnan_if_qnan, s); | ||
349 | - set_float_default_nan_pattern(0b01000000, s); | ||
350 | -} | ||
351 | - | ||
352 | -/* | ||
353 | - * Set the float_status behaviour to match the FEAT_AFP | ||
354 | - * FPCR.AH=1 requirements: | ||
355 | - * * tininess-after-rounding | ||
356 | - * * 2-input NaN propagation prefers the first NaN | ||
357 | - * * 3-input NaN propagation prefers a over b over c | ||
358 | - * * 0 * Inf + NaN always returns the input NaN and doesn't | ||
359 | - * set Invalid for a QNaN | ||
360 | - * * default NaN has sign bit set, msb frac bit set | ||
361 | - */ | ||
362 | -void arm_set_ah_fp_behaviours(float_status *s) | ||
363 | -{ | ||
364 | - set_float_detect_tininess(float_tininess_after_rounding, s); | ||
365 | - set_float_ftz_detection(float_ftz_after_rounding, s); | ||
366 | - set_float_2nan_prop_rule(float_2nan_prop_ab, s); | ||
367 | - set_float_3nan_prop_rule(float_3nan_prop_abc, s); | ||
368 | - set_float_infzeronan_rule(float_infzeronan_dnan_never | | ||
369 | - float_infzeronan_suppress_invalid, s); | ||
370 | - set_float_default_nan_pattern(0b11000000, s); | ||
371 | -} | ||
372 | - | ||
373 | -#ifdef CONFIG_TCG | ||
374 | - | ||
375 | -/* Convert host exception flags to vfp form. */ | ||
376 | -static inline uint32_t vfp_exceptbits_from_host(int host_bits, bool ah) | ||
377 | -{ | ||
378 | - uint32_t target_bits = 0; | ||
379 | - | ||
380 | - if (host_bits & float_flag_invalid) { | ||
381 | - target_bits |= FPSR_IOC; | ||
382 | - } | ||
383 | - if (host_bits & float_flag_divbyzero) { | ||
384 | - target_bits |= FPSR_DZC; | ||
385 | - } | ||
386 | - if (host_bits & float_flag_overflow) { | ||
387 | - target_bits |= FPSR_OFC; | ||
388 | - } | ||
389 | - if (host_bits & (float_flag_underflow | float_flag_output_denormal_flushed)) { | ||
390 | - target_bits |= FPSR_UFC; | ||
391 | - } | ||
392 | - if (host_bits & float_flag_inexact) { | ||
393 | - target_bits |= FPSR_IXC; | ||
394 | - } | ||
395 | - if (host_bits & float_flag_input_denormal_flushed) { | ||
396 | - target_bits |= FPSR_IDC; | ||
397 | - } | ||
398 | - /* | ||
399 | - * With FPCR.AH, IDC is set when an input denormal is used, | ||
400 | - * and flushing an output denormal to zero sets both IXC and UFC. | ||
401 | - */ | ||
402 | - if (ah && (host_bits & float_flag_input_denormal_used)) { | ||
403 | - target_bits |= FPSR_IDC; | ||
404 | - } | ||
405 | - if (ah && (host_bits & float_flag_output_denormal_flushed)) { | ||
406 | - target_bits |= FPSR_IXC; | ||
407 | - } | ||
408 | - return target_bits; | ||
409 | -} | ||
410 | - | ||
411 | -static uint32_t vfp_get_fpsr_from_host(CPUARMState *env) | ||
412 | -{ | ||
413 | - uint32_t a32_flags = 0, a64_flags = 0; | ||
414 | - | ||
415 | - a32_flags |= get_float_exception_flags(&env->vfp.fp_status[FPST_A32]); | ||
416 | - a32_flags |= get_float_exception_flags(&env->vfp.fp_status[FPST_STD]); | ||
417 | - /* FZ16 does not generate an input denormal exception. */ | ||
418 | - a32_flags |= (get_float_exception_flags(&env->vfp.fp_status[FPST_A32_F16]) | ||
419 | - & ~float_flag_input_denormal_flushed); | ||
420 | - a32_flags |= (get_float_exception_flags(&env->vfp.fp_status[FPST_STD_F16]) | ||
421 | - & ~float_flag_input_denormal_flushed); | ||
422 | - | ||
423 | - a64_flags |= get_float_exception_flags(&env->vfp.fp_status[FPST_A64]); | ||
424 | - a64_flags |= (get_float_exception_flags(&env->vfp.fp_status[FPST_A64_F16]) | ||
425 | - & ~(float_flag_input_denormal_flushed | float_flag_input_denormal_used)); | ||
426 | - /* | ||
427 | - * We do not merge in flags from FPST_AH or FPST_AH_F16, because | ||
428 | - * they are used for insns that must not set the cumulative exception bits. | ||
429 | - */ | ||
430 | - | ||
431 | - /* | ||
432 | - * Flushing an input denormal *only* because FPCR.FIZ == 1 does | ||
433 | - * not set FPSR.IDC; if FPCR.FZ is also set then this takes | ||
434 | - * precedence and IDC is set (see the FPUnpackBase pseudocode). | ||
435 | - * So squash it unless (FPCR.AH == 0 && FPCR.FZ == 1). | ||
436 | - * We only do this for the a64 flags because FIZ has no effect | ||
437 | - * on AArch32 even if it is set. | ||
438 | - */ | ||
439 | - if ((env->vfp.fpcr & (FPCR_FZ | FPCR_AH)) != FPCR_FZ) { | ||
440 | - a64_flags &= ~float_flag_input_denormal_flushed; | ||
441 | - } | ||
442 | - return vfp_exceptbits_from_host(a64_flags, env->vfp.fpcr & FPCR_AH) | | ||
443 | - vfp_exceptbits_from_host(a32_flags, false); | ||
444 | -} | ||
445 | - | ||
446 | -static void vfp_clear_float_status_exc_flags(CPUARMState *env) | ||
447 | -{ | ||
448 | - /* | ||
449 | - * Clear out all the exception-flag information in the float_status | ||
450 | - * values. The caller should have arranged for env->vfp.fpsr to | ||
451 | - * be the architecturally up-to-date exception flag information first. | ||
452 | - */ | ||
453 | - set_float_exception_flags(0, &env->vfp.fp_status[FPST_A32]); | ||
454 | - set_float_exception_flags(0, &env->vfp.fp_status[FPST_A64]); | ||
455 | - set_float_exception_flags(0, &env->vfp.fp_status[FPST_A32_F16]); | ||
456 | - set_float_exception_flags(0, &env->vfp.fp_status[FPST_A64_F16]); | ||
457 | - set_float_exception_flags(0, &env->vfp.fp_status[FPST_STD]); | ||
458 | - set_float_exception_flags(0, &env->vfp.fp_status[FPST_STD_F16]); | ||
459 | - set_float_exception_flags(0, &env->vfp.fp_status[FPST_AH]); | ||
460 | - set_float_exception_flags(0, &env->vfp.fp_status[FPST_AH_F16]); | ||
461 | -} | ||
462 | - | ||
463 | -static void vfp_sync_and_clear_float_status_exc_flags(CPUARMState *env) | ||
464 | -{ | ||
465 | - /* | ||
466 | - * Synchronize any pending exception-flag information in the | ||
467 | - * float_status values into env->vfp.fpsr, and then clear out | ||
468 | - * the float_status data. | ||
469 | - */ | ||
470 | - env->vfp.fpsr |= vfp_get_fpsr_from_host(env); | ||
471 | - vfp_clear_float_status_exc_flags(env); | ||
472 | -} | ||
473 | - | ||
474 | -static void vfp_set_fpcr_to_host(CPUARMState *env, uint32_t val, uint32_t mask) | ||
475 | -{ | ||
476 | - uint64_t changed = env->vfp.fpcr; | ||
477 | - | ||
478 | - changed ^= val; | ||
479 | - changed &= mask; | ||
480 | - if (changed & (3 << 22)) { | ||
481 | - int i = (val >> 22) & 3; | ||
482 | - switch (i) { | ||
483 | - case FPROUNDING_TIEEVEN: | ||
484 | - i = float_round_nearest_even; | ||
485 | - break; | ||
486 | - case FPROUNDING_POSINF: | ||
487 | - i = float_round_up; | ||
488 | - break; | ||
489 | - case FPROUNDING_NEGINF: | ||
490 | - i = float_round_down; | ||
491 | - break; | ||
492 | - case FPROUNDING_ZERO: | ||
493 | - i = float_round_to_zero; | ||
494 | - break; | ||
495 | - } | ||
496 | - set_float_rounding_mode(i, &env->vfp.fp_status[FPST_A32]); | ||
497 | - set_float_rounding_mode(i, &env->vfp.fp_status[FPST_A64]); | ||
498 | - set_float_rounding_mode(i, &env->vfp.fp_status[FPST_A32_F16]); | ||
499 | - set_float_rounding_mode(i, &env->vfp.fp_status[FPST_A64_F16]); | ||
500 | - } | ||
501 | - if (changed & FPCR_FZ16) { | ||
502 | - bool ftz_enabled = val & FPCR_FZ16; | ||
503 | - set_flush_to_zero(ftz_enabled, &env->vfp.fp_status[FPST_A32_F16]); | ||
504 | - set_flush_to_zero(ftz_enabled, &env->vfp.fp_status[FPST_A64_F16]); | ||
505 | - set_flush_to_zero(ftz_enabled, &env->vfp.fp_status[FPST_STD_F16]); | ||
506 | - set_flush_to_zero(ftz_enabled, &env->vfp.fp_status[FPST_AH_F16]); | ||
507 | - set_flush_inputs_to_zero(ftz_enabled, &env->vfp.fp_status[FPST_A32_F16]); | ||
508 | - set_flush_inputs_to_zero(ftz_enabled, &env->vfp.fp_status[FPST_A64_F16]); | ||
509 | - set_flush_inputs_to_zero(ftz_enabled, &env->vfp.fp_status[FPST_STD_F16]); | ||
510 | - set_flush_inputs_to_zero(ftz_enabled, &env->vfp.fp_status[FPST_AH_F16]); | ||
511 | - } | ||
512 | - if (changed & FPCR_FZ) { | ||
513 | - bool ftz_enabled = val & FPCR_FZ; | ||
514 | - set_flush_to_zero(ftz_enabled, &env->vfp.fp_status[FPST_A32]); | ||
515 | - set_flush_to_zero(ftz_enabled, &env->vfp.fp_status[FPST_A64]); | ||
516 | - /* FIZ is A64 only so FZ always makes A32 code flush inputs to zero */ | ||
517 | - set_flush_inputs_to_zero(ftz_enabled, &env->vfp.fp_status[FPST_A32]); | ||
518 | - } | ||
519 | - if (changed & (FPCR_FZ | FPCR_AH | FPCR_FIZ)) { | ||
520 | - /* | ||
521 | - * A64: Flush denormalized inputs to zero if FPCR.FIZ = 1, or | ||
522 | - * both FPCR.AH = 0 and FPCR.FZ = 1. | ||
523 | - */ | ||
524 | - bool fitz_enabled = (val & FPCR_FIZ) || | ||
525 | - (val & (FPCR_FZ | FPCR_AH)) == FPCR_FZ; | ||
526 | - set_flush_inputs_to_zero(fitz_enabled, &env->vfp.fp_status[FPST_A64]); | ||
527 | - } | ||
528 | - if (changed & FPCR_DN) { | ||
529 | - bool dnan_enabled = val & FPCR_DN; | ||
530 | - set_default_nan_mode(dnan_enabled, &env->vfp.fp_status[FPST_A32]); | ||
531 | - set_default_nan_mode(dnan_enabled, &env->vfp.fp_status[FPST_A64]); | ||
532 | - set_default_nan_mode(dnan_enabled, &env->vfp.fp_status[FPST_A32_F16]); | ||
533 | - set_default_nan_mode(dnan_enabled, &env->vfp.fp_status[FPST_A64_F16]); | ||
534 | - set_default_nan_mode(dnan_enabled, &env->vfp.fp_status[FPST_AH]); | ||
535 | - set_default_nan_mode(dnan_enabled, &env->vfp.fp_status[FPST_AH_F16]); | ||
536 | - } | ||
537 | - if (changed & FPCR_AH) { | ||
538 | - bool ah_enabled = val & FPCR_AH; | ||
539 | - | ||
540 | - if (ah_enabled) { | ||
541 | - /* Change behaviours for A64 FP operations */ | ||
542 | - arm_set_ah_fp_behaviours(&env->vfp.fp_status[FPST_A64]); | ||
543 | - arm_set_ah_fp_behaviours(&env->vfp.fp_status[FPST_A64_F16]); | ||
544 | - } else { | ||
545 | - arm_set_default_fp_behaviours(&env->vfp.fp_status[FPST_A64]); | ||
546 | - arm_set_default_fp_behaviours(&env->vfp.fp_status[FPST_A64_F16]); | ||
547 | - } | ||
548 | - } | ||
549 | - /* | ||
550 | - * If any bits changed that we look at in vfp_get_fpsr_from_host(), | ||
551 | - * we must sync the float_status flags into vfp.fpsr now (under the | ||
552 | - * old regime) before we update vfp.fpcr. | ||
553 | - */ | ||
554 | - if (changed & (FPCR_FZ | FPCR_AH | FPCR_FIZ)) { | ||
555 | - vfp_sync_and_clear_float_status_exc_flags(env); | ||
556 | - } | ||
557 | -} | ||
558 | - | ||
559 | -#else | ||
560 | - | ||
561 | -static uint32_t vfp_get_fpsr_from_host(CPUARMState *env) | ||
562 | -{ | ||
563 | - return 0; | ||
564 | -} | ||
565 | - | ||
566 | -static void vfp_clear_float_status_exc_flags(CPUARMState *env) | ||
567 | -{ | ||
568 | -} | ||
569 | - | ||
570 | -static void vfp_set_fpcr_to_host(CPUARMState *env, uint32_t val, uint32_t mask) | ||
571 | -{ | ||
572 | -} | ||
573 | - | ||
574 | -#endif | ||
575 | |||
576 | uint32_t vfp_get_fpcr(CPUARMState *env) | ||
577 | { | ||
95 | -- | 578 | -- |
96 | 2.20.1 | 579 | 2.43.0 |
97 | |||
98 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | The vfp_helper.c in the target/arm directory now only has | ||
2 | code for handling FPSCR/FPCR/FPSR in it, and no helper | ||
3 | functions. Rename it to vfp_fpscr.c; this helps keep it | ||
4 | distinct from tcg/vfp_helper.c. | ||
1 | 5 | ||
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
7 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Message-id: 20250221190957.811948-5-peter.maydell@linaro.org | ||
9 | --- | ||
10 | target/arm/{vfp_helper.c => vfp_fpscr.c} | 2 +- | ||
11 | target/arm/meson.build | 2 +- | ||
12 | 2 files changed, 2 insertions(+), 2 deletions(-) | ||
13 | rename target/arm/{vfp_helper.c => vfp_fpscr.c} (98%) | ||
14 | |||
15 | diff --git a/target/arm/vfp_helper.c b/target/arm/vfp_fpscr.c | ||
16 | similarity index 98% | ||
17 | rename from target/arm/vfp_helper.c | ||
18 | rename to target/arm/vfp_fpscr.c | ||
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/target/arm/vfp_helper.c | ||
21 | +++ b/target/arm/vfp_fpscr.c | ||
22 | @@ -XXX,XX +XXX,XX @@ | ||
23 | /* | ||
24 | - * ARM VFP floating-point operations | ||
25 | + * ARM VFP floating-point: handling of FPSCR/FPCR/FPSR | ||
26 | * | ||
27 | * Copyright (c) 2003 Fabrice Bellard | ||
28 | * | ||
29 | diff --git a/target/arm/meson.build b/target/arm/meson.build | ||
30 | index XXXXXXX..XXXXXXX 100644 | ||
31 | --- a/target/arm/meson.build | ||
32 | +++ b/target/arm/meson.build | ||
33 | @@ -XXX,XX +XXX,XX @@ arm_ss.add(files( | ||
34 | 'debug_helper.c', | ||
35 | 'gdbstub.c', | ||
36 | 'helper.c', | ||
37 | - 'vfp_helper.c', | ||
38 | + 'vfp_fpscr.c', | ||
39 | )) | ||
40 | arm_ss.add(zlib) | ||
41 | |||
42 | -- | ||
43 | 2.43.0 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Joelle van Dyne <j@getutm.app> | ||
1 | 2 | ||
3 | macOS 15.2's Hypervisor.framework exposes SME feature on M4 Macs. | ||
4 | However, QEMU's hvf accelerator code does not properly support it | ||
5 | yet, causing QEMU to fail to start when hvf accelerator is used on | ||
6 | these systems, with the error message: | ||
7 | |||
8 | qemu-aarch64-softmmu: cannot disable sme4224 | ||
9 | All SME vector lengths are disabled. | ||
10 | With SME enabled, at least one vector length must be enabled. | ||
11 | |||
12 | Ideally we would have SME support on these hosts; however, until that | ||
13 | point, we must suppress the SME feature in the ID registers, so that | ||
14 | users can at least run non-SME guests. | ||
15 | |||
16 | Cc: qemu-stable@nongnu.org | ||
17 | Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2665 | ||
18 | Signed-off-by: Joelle van Dyne <j@getutm.app> | ||
19 | Message-id: 20250224165735.36792-1-j@getutm.app | ||
20 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
21 | [PMM: expanded commit message, comment] | ||
22 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
23 | --- | ||
24 | target/arm/hvf/hvf.c | 12 ++++++++++++ | ||
25 | 1 file changed, 12 insertions(+) | ||
26 | |||
27 | diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c | ||
28 | index XXXXXXX..XXXXXXX 100644 | ||
29 | --- a/target/arm/hvf/hvf.c | ||
30 | +++ b/target/arm/hvf/hvf.c | ||
31 | @@ -XXX,XX +XXX,XX @@ static bool hvf_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf) | ||
32 | |||
33 | clamp_id_aa64mmfr0_parange_to_ipa_size(&host_isar.id_aa64mmfr0); | ||
34 | |||
35 | + /* | ||
36 | + * Disable SME, which is not properly handled by QEMU hvf yet. | ||
37 | + * To allow this through we would need to: | ||
38 | + * - make sure that the SME state is correctly handled in the | ||
39 | + * get_registers/put_registers functions | ||
40 | + * - get the SME-specific CPU properties to work with accelerators | ||
41 | + * other than TCG | ||
42 | + * - fix any assumptions we made that SME implies SVE (since | ||
43 | + * on the M4 there is SME but not SVE) | ||
44 | + */ | ||
45 | + host_isar.id_aa64pfr1 &= ~R_ID_AA64PFR1_SME_MASK; | ||
46 | + | ||
47 | ahcf->isar = host_isar; | ||
48 | |||
49 | /* | ||
50 | -- | ||
51 | 2.43.0 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Joelle van Dyne <j@getutm.app> | ||
1 | 2 | ||
3 | In the syndrome value for a data abort, bit 21 is SSE, which is | ||
4 | set to indicate that the abort was on a sign-extending load. When | ||
5 | we handle the data abort from the guest via address_space_read(), | ||
6 | we forgot to handle this and so would return the wrong value if | ||
7 | the guest did a sign-extending load to an MMIO region. Add the | ||
8 | sign-extension of the returned data. | ||
9 | |||
10 | Cc: qemu-stable@nongnu.org | ||
11 | Signed-off-by: Joelle van Dyne <j@getutm.app> | ||
12 | Message-id: 20250224184123.50780-1-j@getutm.app | ||
13 | [PMM: Drop an unnecessary check on 'len'; expand commit message] | ||
14 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
15 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
16 | --- | ||
17 | target/arm/hvf/hvf.c | 4 ++++ | ||
18 | 1 file changed, 4 insertions(+) | ||
19 | |||
20 | diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c | ||
21 | index XXXXXXX..XXXXXXX 100644 | ||
22 | --- a/target/arm/hvf/hvf.c | ||
23 | +++ b/target/arm/hvf/hvf.c | ||
24 | @@ -XXX,XX +XXX,XX @@ int hvf_vcpu_exec(CPUState *cpu) | ||
25 | bool isv = syndrome & ARM_EL_ISV; | ||
26 | bool iswrite = (syndrome >> 6) & 1; | ||
27 | bool s1ptw = (syndrome >> 7) & 1; | ||
28 | + bool sse = (syndrome >> 21) & 1; | ||
29 | uint32_t sas = (syndrome >> 22) & 3; | ||
30 | uint32_t len = 1 << sas; | ||
31 | uint32_t srt = (syndrome >> 16) & 0x1f; | ||
32 | @@ -XXX,XX +XXX,XX @@ int hvf_vcpu_exec(CPUState *cpu) | ||
33 | address_space_read(&address_space_memory, | ||
34 | hvf_exit->exception.physical_address, | ||
35 | MEMTXATTRS_UNSPECIFIED, &val, len); | ||
36 | + if (sse) { | ||
37 | + val = sextract64(val, 0, len * 8); | ||
38 | + } | ||
39 | hvf_set_reg(cpu, srt, val); | ||
40 | } | ||
41 | |||
42 | -- | ||
43 | 2.43.0 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Pierrick Bouvier <pierrick.bouvier@linaro.org> | ||
1 | 2 | ||
3 | Regression introduced by cf76c4 | ||
4 | (hw/misc: Add nr_regs and cold_reset_values to NPCM CLK) | ||
5 | |||
6 | cold_reset_values has a different size, depending on device used | ||
7 | (NPCM7xx vs NPCM8xx). However, s->regs has a fixed size, which matches | ||
8 | NPCM8xx. Thus, when initializing a NPCM7xx, we go past cold_reset_values | ||
9 | ending. | ||
10 | |||
11 | Report by asan: | ||
12 | ==2066==ERROR: AddressSanitizer: global-buffer-overflow on address 0x55d68a3e97f0 at pc 0x7fcaf2b2d14b bp 0x7ffff0cc3890 sp 0x7ffff0cc3040 | ||
13 | READ of size 196 at 0x55d68a3e97f0 thread T0 | ||
14 | #0 0x7fcaf2b2d14a in __interceptor_memcpy ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:827 | ||
15 | #1 0x55d688447e0d in memcpy /usr/include/x86_64-linux-gnu/bits/string_fortified.h:29 | ||
16 | #2 0x55d688447e0d in npcm_clk_enter_reset ../hw/misc/npcm_clk.c:968 | ||
17 | #3 0x55d6899b7213 in resettable_phase_enter ../hw/core/resettable.c:136 | ||
18 | #4 0x55d6899a1ef7 in bus_reset_child_foreach ../hw/core/bus.c:97 | ||
19 | #5 0x55d6899b717d in resettable_child_foreach ../hw/core/resettable.c:92 | ||
20 | #6 0x55d6899b717d in resettable_phase_enter ../hw/core/resettable.c:129 | ||
21 | #7 0x55d6899b4ead in resettable_container_child_foreach ../hw/core/resetcontainer.c:54 | ||
22 | #8 0x55d6899b717d in resettable_child_foreach ../hw/core/resettable.c:92 | ||
23 | #9 0x55d6899b717d in resettable_phase_enter ../hw/core/resettable.c:129 | ||
24 | #10 0x55d6899b7bfa in resettable_assert_reset ../hw/core/resettable.c:55 | ||
25 | #11 0x55d6899b8666 in resettable_reset ../hw/core/resettable.c:45 | ||
26 | #12 0x55d688d15cd2 in qemu_system_reset ../system/runstate.c:527 | ||
27 | #13 0x55d687fc5edd in qdev_machine_creation_done ../hw/core/machine.c:1738 | ||
28 | #14 0x55d688d209bd in qemu_machine_creation_done ../system/vl.c:2779 | ||
29 | #15 0x55d688d209bd in qmp_x_exit_preconfig ../system/vl.c:2807 | ||
30 | #16 0x55d688d281fb in qemu_init ../system/vl.c:3838 | ||
31 | #17 0x55d687ceab12 in main ../system/main.c:68 | ||
32 | #18 0x7fcaef006249 (/lib/x86_64-linux-gnu/libc.so.6+0x27249) | ||
33 | #19 0x7fcaef006304 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x27304) | ||
34 | #20 0x55d687cf0010 in _start (/home/runner/work/qemu-ci/qemu-ci/build/qemu-system-arm+0x371c010) | ||
35 | |||
36 | 0x55d68a3e97f0 is located 0 bytes to the right of global variable 'npcm7xx_cold_reset_values' defined in '../hw/misc/npcm_clk.c:134:23' (0x55d68a3e9780) of size 112 | ||
37 | |||
38 | Impacted tests: | ||
39 | Summary of Failures: | ||
40 | |||
41 | check: | ||
42 | 2/747 qemu:qtest+qtest-aarch64 / qtest-aarch64/qom-test ERROR 9.28s killed by signal 6 SIGABRT | ||
43 | 4/747 qemu:qtest+qtest-arm / qtest-arm/qom-test ERROR 7.82s killed by signal 6 SIGABRT | ||
44 | 32/747 qemu:qtest+qtest-aarch64 / qtest-aarch64/device-introspect-test ERROR 10.91s killed by signal 6 SIGABRT | ||
45 | 35/747 qemu:qtest+qtest-arm / qtest-arm/device-introspect-test ERROR 11.33s killed by signal 6 SIGABRT | ||
46 | 114/747 qemu:qtest+qtest-arm / qtest-arm/npcm7xx_pwm-test ERROR 0.98s killed by signal 6 SIGABRT | ||
47 | 115/747 qemu:qtest+qtest-aarch64 / qtest-aarch64/test-hmp ERROR 2.95s killed by signal 6 SIGABRT | ||
48 | 117/747 qemu:qtest+qtest-arm / qtest-arm/test-hmp ERROR 2.54s killed by signal 6 SIGABRT | ||
49 | 151/747 qemu:qtest+qtest-arm / qtest-arm/npcm7xx_watchdog_timer-test ERROR 0.96s killed by signal 6 SIGABRT | ||
50 | 247/747 qemu:qtest+qtest-arm / qtest-arm/npcm7xx_adc-test ERROR 0.96s killed by signal 6 SIGABRT | ||
51 | 248/747 qemu:qtest+qtest-arm / qtest-arm/npcm7xx_gpio-test ERROR 1.05s killed by signal 6 SIGABRT | ||
52 | 249/747 qemu:qtest+qtest-arm / qtest-arm/npcm7xx_rng-test ERROR 0.97s killed by signal 6 SIGABRT | ||
53 | 250/747 qemu:qtest+qtest-arm / qtest-arm/npcm7xx_sdhci-test ERROR 0.97s killed by signal 6 SIGABRT | ||
54 | 251/747 qemu:qtest+qtest-arm / qtest-arm/npcm7xx_smbus-test ERROR 0.89s killed by signal 6 SIGABRT | ||
55 | 252/747 qemu:qtest+qtest-arm / qtest-arm/npcm7xx_timer-test ERROR 1.09s killed by signal 6 SIGABRT | ||
56 | 253/747 qemu:qtest+qtest-arm / qtest-arm/npcm_gmac-test ERROR 1.12s killed by signal 6 SIGABRT | ||
57 | 255/747 qemu:qtest+qtest-arm / qtest-arm/npcm7xx_emc-test ERROR 1.05s killed by signal 6 SIGABRT | ||
58 | |||
59 | check-functional: | ||
60 | 22/203 qemu:func-thorough+func-arm-thorough+thorough / func-arm-arm_quanta_gsj ERROR 0.79s exit status 1 | ||
61 | 38/203 qemu:func-quick+func-aarch64 / func-aarch64-migration ERROR 1.97s exit status 1 | ||
62 | 45/203 qemu:func-quick+func-arm / func-arm-migration ERROR 1.90s exit status 1 | ||
63 | |||
64 | Fixes: cf76c4e174e1 ("hw/misc: Add nr_regs and cold_reset_values to NPCM CLK") | ||
65 | Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org> | ||
66 | Reviewed-by: Hao Wu <wuhaotsh@google.com> | ||
67 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
68 | --- | ||
69 | hw/misc/npcm_clk.c | 5 +++-- | ||
70 | 1 file changed, 3 insertions(+), 2 deletions(-) | ||
71 | |||
72 | diff --git a/hw/misc/npcm_clk.c b/hw/misc/npcm_clk.c | ||
73 | index XXXXXXX..XXXXXXX 100644 | ||
74 | --- a/hw/misc/npcm_clk.c | ||
75 | +++ b/hw/misc/npcm_clk.c | ||
76 | @@ -XXX,XX +XXX,XX @@ static void npcm_clk_enter_reset(Object *obj, ResetType type) | ||
77 | NPCMCLKState *s = NPCM_CLK(obj); | ||
78 | NPCMCLKClass *c = NPCM_CLK_GET_CLASS(s); | ||
79 | |||
80 | - g_assert(sizeof(s->regs) >= c->nr_regs * sizeof(uint32_t)); | ||
81 | - memcpy(s->regs, c->cold_reset_values, sizeof(s->regs)); | ||
82 | + size_t sizeof_regs = c->nr_regs * sizeof(uint32_t); | ||
83 | + g_assert(sizeof(s->regs) >= sizeof_regs); | ||
84 | + memcpy(s->regs, c->cold_reset_values, sizeof_regs); | ||
85 | s->ref_ns = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); | ||
86 | npcm7xx_clk_update_all_clocks(s); | ||
87 | /* | ||
88 | -- | ||
89 | 2.43.0 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Bernhard Beschow <shentey@gmail.com> | ||
1 | 2 | ||
3 | While at it add missing GUSB2RHBCTL register as found in i.MX 8M Plus reference | ||
4 | manual. | ||
5 | |||
6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
7 | Signed-off-by: Bernhard Beschow <shentey@gmail.com> | ||
8 | Message-id: 20250223114708.1780-2-shentey@gmail.com | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
10 | --- | ||
11 | include/hw/usb/hcd-dwc3.h | 2 +- | ||
12 | hw/usb/hcd-dwc3.c | 5 +++++ | ||
13 | 2 files changed, 6 insertions(+), 1 deletion(-) | ||
14 | |||
15 | diff --git a/include/hw/usb/hcd-dwc3.h b/include/hw/usb/hcd-dwc3.h | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/include/hw/usb/hcd-dwc3.h | ||
18 | +++ b/include/hw/usb/hcd-dwc3.h | ||
19 | @@ -XXX,XX +XXX,XX @@ | ||
20 | #define USB_DWC3(obj) \ | ||
21 | OBJECT_CHECK(USBDWC3, (obj), TYPE_USB_DWC3) | ||
22 | |||
23 | -#define USB_DWC3_R_MAX ((0x530 / 4) + 1) | ||
24 | +#define USB_DWC3_R_MAX (0x600 / 4) | ||
25 | #define DWC3_SIZE 0x10000 | ||
26 | |||
27 | typedef struct USBDWC3 { | ||
28 | diff --git a/hw/usb/hcd-dwc3.c b/hw/usb/hcd-dwc3.c | ||
29 | index XXXXXXX..XXXXXXX 100644 | ||
30 | --- a/hw/usb/hcd-dwc3.c | ||
31 | +++ b/hw/usb/hcd-dwc3.c | ||
32 | @@ -XXX,XX +XXX,XX @@ REG32(GFLADJ, 0x530) | ||
33 | FIELD(GFLADJ, GFLADJ_REFCLK_FLADJ, 8, 14) | ||
34 | FIELD(GFLADJ, GFLADJ_30MHZ_SDBND_SEL, 7, 1) | ||
35 | FIELD(GFLADJ, GFLADJ_30MHZ, 0, 6) | ||
36 | +REG32(GUSB2RHBCTL, 0x540) | ||
37 | + FIELD(GUSB2RHBCTL, OVRD_L1TIMEOUT, 0, 4) | ||
38 | |||
39 | #define DWC3_GLOBAL_OFFSET 0xC100 | ||
40 | static void reset_csr(USBDWC3 * s) | ||
41 | @@ -XXX,XX +XXX,XX @@ static const RegisterAccessInfo usb_dwc3_regs_info[] = { | ||
42 | .rsvd = 0x40, | ||
43 | .ro = 0x400040, | ||
44 | .unimp = 0xffffffff, | ||
45 | + },{ .name = "GUSB2RHBCTL", .addr = A_GUSB2RHBCTL, | ||
46 | + .rsvd = 0xfffffff0, | ||
47 | + .unimp = 0xffffffff, | ||
48 | } | ||
49 | }; | ||
50 | |||
51 | -- | ||
52 | 2.43.0 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Bernhard Beschow <shentey@gmail.com> | ||
1 | 2 | ||
3 | On the real device, the PCIe root bus is only connected to a PCIe bridge and | ||
4 | does not allow for direct attachment of devices. Doing so in QEMU results in no | ||
5 | PCI devices being detected by Linux. Instead, PCI devices should plug into the | ||
6 | secondary PCIe bus spawned by the internal PCIe bridge. | ||
7 | |||
8 | Unfortunately, QEMU defaults to plugging devices into the PCIe root bus. To work | ||
9 | around this, every PCI device created on the command line needs an extra | ||
10 | `bus=dw-pcie` option which is error prone. Fix that by marking the PCIe root bus | ||
11 | as full which makes QEMU decend into the child PCIe bus. | ||
12 | |||
13 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
14 | Signed-off-by: Bernhard Beschow <shentey@gmail.com> | ||
15 | Message-id: 20250223114708.1780-3-shentey@gmail.com | ||
16 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
17 | --- | ||
18 | include/hw/pci-host/designware.h | 7 +++++++ | ||
19 | hw/pci-host/designware.c | 18 +++++++++++++++++- | ||
20 | 2 files changed, 24 insertions(+), 1 deletion(-) | ||
21 | |||
22 | diff --git a/include/hw/pci-host/designware.h b/include/hw/pci-host/designware.h | ||
23 | index XXXXXXX..XXXXXXX 100644 | ||
24 | --- a/include/hw/pci-host/designware.h | ||
25 | +++ b/include/hw/pci-host/designware.h | ||
26 | @@ -XXX,XX +XXX,XX @@ | ||
27 | #include "hw/pci/pci_bridge.h" | ||
28 | #include "qom/object.h" | ||
29 | |||
30 | +#define TYPE_DESIGNWARE_PCIE_ROOT_BUS "designware-pcie-root-BUS" | ||
31 | +OBJECT_DECLARE_SIMPLE_TYPE(DesignwarePCIERootBus, DESIGNWARE_PCIE_ROOT_BUS) | ||
32 | + | ||
33 | #define TYPE_DESIGNWARE_PCIE_HOST "designware-pcie-host" | ||
34 | OBJECT_DECLARE_SIMPLE_TYPE(DesignwarePCIEHost, DESIGNWARE_PCIE_HOST) | ||
35 | |||
36 | #define TYPE_DESIGNWARE_PCIE_ROOT "designware-pcie-root" | ||
37 | OBJECT_DECLARE_SIMPLE_TYPE(DesignwarePCIERoot, DESIGNWARE_PCIE_ROOT) | ||
38 | |||
39 | +struct DesignwarePCIERootBus { | ||
40 | + PCIBus parent; | ||
41 | +}; | ||
42 | + | ||
43 | typedef struct DesignwarePCIEViewport { | ||
44 | DesignwarePCIERoot *root; | ||
45 | |||
46 | diff --git a/hw/pci-host/designware.c b/hw/pci-host/designware.c | ||
47 | index XXXXXXX..XXXXXXX 100644 | ||
48 | --- a/hw/pci-host/designware.c | ||
49 | +++ b/hw/pci-host/designware.c | ||
50 | @@ -XXX,XX +XXX,XX @@ | ||
51 | #define DESIGNWARE_PCIE_ATU_DEVFN(x) (((x) >> 16) & 0xff) | ||
52 | #define DESIGNWARE_PCIE_ATU_UPPER_TARGET 0x91C | ||
53 | |||
54 | +static void designware_pcie_root_bus_class_init(ObjectClass *klass, void *data) | ||
55 | +{ | ||
56 | + BusClass *k = BUS_CLASS(klass); | ||
57 | + | ||
58 | + /* | ||
59 | + * Designware has only a single root complex. Enforce the limit on the | ||
60 | + * parent bus | ||
61 | + */ | ||
62 | + k->max_dev = 1; | ||
63 | +} | ||
64 | + | ||
65 | static DesignwarePCIEHost * | ||
66 | designware_pcie_root_to_host(DesignwarePCIERoot *root) | ||
67 | { | ||
68 | @@ -XXX,XX +XXX,XX @@ static void designware_pcie_host_realize(DeviceState *dev, Error **errp) | ||
69 | &s->pci.memory, | ||
70 | &s->pci.io, | ||
71 | 0, 4, | ||
72 | - TYPE_PCIE_BUS); | ||
73 | + TYPE_DESIGNWARE_PCIE_ROOT_BUS); | ||
74 | pci->bus->flags |= PCI_BUS_EXTENDED_CONFIG_SPACE; | ||
75 | |||
76 | memory_region_init(&s->pci.address_space_root, | ||
77 | @@ -XXX,XX +XXX,XX @@ static void designware_pcie_host_init(Object *obj) | ||
78 | |||
79 | static const TypeInfo designware_pcie_types[] = { | ||
80 | { | ||
81 | + .name = TYPE_DESIGNWARE_PCIE_ROOT_BUS, | ||
82 | + .parent = TYPE_PCIE_BUS, | ||
83 | + .instance_size = sizeof(DesignwarePCIERootBus), | ||
84 | + .class_init = designware_pcie_root_bus_class_init, | ||
85 | + }, { | ||
86 | .name = TYPE_DESIGNWARE_PCIE_HOST, | ||
87 | .parent = TYPE_PCI_HOST_BRIDGE, | ||
88 | .instance_size = sizeof(DesignwarePCIEHost), | ||
89 | -- | ||
90 | 2.43.0 | diff view generated by jsdifflib |
1 | From: Cédric Le Goater <clg@kaod.org> | 1 | From: Bernhard Beschow <shentey@gmail.com> |
---|---|---|---|
2 | 2 | ||
3 | There are no QEMU Aspeed machines using the SoCs "ast2400-a0" or | 3 | The move of the Kconfig bits to hw/gpio is fixing a bug in 6328d8ffa6cb9d |
4 | "ast2400". | 4 | ("misc/pca955*: Move models under hw/gpio"), which moved the code but forgot to |
5 | move the Kconfig sections. | ||
5 | 6 | ||
6 | Signed-off-by: Cédric Le Goater <clg@kaod.org> | 7 | Fixes: 6328d8ffa6cb9d "misc/pca955*: Move models under hw/gpio" |
7 | Message-id: 20190904070506.1052-4-clg@kaod.org | 8 | Signed-off-by: Bernhard Beschow <shentey@gmail.com> |
9 | Message-id: 20250223114708.1780-4-shentey@gmail.com | ||
8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
10 | --- | 12 | --- |
11 | hw/arm/aspeed_soc.c | 26 -------------------------- | 13 | hw/gpio/Kconfig | 8 ++++++++ |
12 | 1 file changed, 26 deletions(-) | 14 | hw/misc/Kconfig | 8 -------- |
15 | 2 files changed, 8 insertions(+), 8 deletions(-) | ||
13 | 16 | ||
14 | diff --git a/hw/arm/aspeed_soc.c b/hw/arm/aspeed_soc.c | 17 | diff --git a/hw/gpio/Kconfig b/hw/gpio/Kconfig |
15 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/hw/arm/aspeed_soc.c | 19 | --- a/hw/gpio/Kconfig |
17 | +++ b/hw/arm/aspeed_soc.c | 20 | +++ b/hw/gpio/Kconfig |
18 | @@ -XXX,XX +XXX,XX @@ static const char *aspeed_soc_ast2500_typenames[] = { | 21 | @@ -XXX,XX +XXX,XX @@ config SIFIVE_GPIO |
19 | 22 | config STM32L4X5_GPIO | |
20 | static const AspeedSoCInfo aspeed_socs[] = { | 23 | bool |
21 | { | 24 | |
22 | - .name = "ast2400-a0", | 25 | +config PCA9552 |
23 | - .cpu_type = ARM_CPU_TYPE_NAME("arm926"), | 26 | + bool |
24 | - .silicon_rev = AST2400_A0_SILICON_REV, | 27 | + depends on I2C |
25 | - .sram_size = 0x8000, | 28 | + |
26 | - .spis_num = 1, | 29 | +config PCA9554 |
27 | - .fmc_typename = "aspeed.smc.fmc", | 30 | + bool |
28 | - .spi_typename = aspeed_soc_ast2400_typenames, | 31 | + depends on I2C |
29 | - .gpio_typename = "aspeed.gpio-ast2400", | 32 | + |
30 | - .wdts_num = 2, | 33 | config PCF8574 |
31 | - .irqmap = aspeed_soc_ast2400_irqmap, | 34 | bool |
32 | - .memmap = aspeed_soc_ast2400_memmap, | 35 | depends on I2C |
33 | - .num_cpus = 1, | 36 | diff --git a/hw/misc/Kconfig b/hw/misc/Kconfig |
34 | - }, { | 37 | index XXXXXXX..XXXXXXX 100644 |
35 | .name = "ast2400-a1", | 38 | --- a/hw/misc/Kconfig |
36 | .cpu_type = ARM_CPU_TYPE_NAME("arm926"), | 39 | +++ b/hw/misc/Kconfig |
37 | .silicon_rev = AST2400_A1_SILICON_REV, | 40 | @@ -XXX,XX +XXX,XX @@ config EDU |
38 | @@ -XXX,XX +XXX,XX @@ static const AspeedSoCInfo aspeed_socs[] = { | 41 | default y if TEST_DEVICES |
39 | .irqmap = aspeed_soc_ast2400_irqmap, | 42 | depends on PCI && MSI_NONBROKEN |
40 | .memmap = aspeed_soc_ast2400_memmap, | 43 | |
41 | .num_cpus = 1, | 44 | -config PCA9552 |
42 | - }, { | 45 | - bool |
43 | - .name = "ast2400", | 46 | - depends on I2C |
44 | - .cpu_type = ARM_CPU_TYPE_NAME("arm926"), | 47 | - |
45 | - .silicon_rev = AST2400_A0_SILICON_REV, | 48 | -config PCA9554 |
46 | - .sram_size = 0x8000, | 49 | - bool |
47 | - .spis_num = 1, | 50 | - depends on I2C |
48 | - .fmc_typename = "aspeed.smc.fmc", | 51 | - |
49 | - .spi_typename = aspeed_soc_ast2400_typenames, | 52 | config I2C_ECHO |
50 | - .gpio_typename = "aspeed.gpio-ast2400", | 53 | bool |
51 | - .wdts_num = 2, | 54 | default y if TEST_DEVICES |
52 | - .irqmap = aspeed_soc_ast2400_irqmap, | ||
53 | - .memmap = aspeed_soc_ast2400_memmap, | ||
54 | - .num_cpus = 1, | ||
55 | }, { | ||
56 | .name = "ast2500-a1", | ||
57 | .cpu_type = ARM_CPU_TYPE_NAME("arm1176"), | ||
58 | -- | 55 | -- |
59 | 2.20.1 | 56 | 2.43.0 |
60 | |||
61 | diff view generated by jsdifflib |
1 | From: Cédric Le Goater <clg@kaod.org> | 1 | From: Bernhard Beschow <shentey@gmail.com> |
---|---|---|---|
2 | 2 | ||
3 | The FMC controller on the Aspeed SoCs support DMA to access the flash | 3 | As a first step, implement the bare minimum: CPUs, RAM, interrupt controller, |
4 | modules. It can operate in a normal mode, to copy to or from the flash | 4 | serial. All other devices of the A53 memory map are represented as |
5 | module mapping window, or in a checksum calculation mode, to evaluate | 5 | TYPE_UNIMPLEMENTED_DEVICE, i.e. the whole memory map is provided. This allows |
6 | the best clock settings for reads. | 6 | for running Linux without it crashing due to invalid memory accesses. |
7 | 7 | ||
8 | The model introduces two custom address spaces for DMAs: one for the | 8 | Signed-off-by: Bernhard Beschow <shentey@gmail.com> |
9 | AHB window of the FMC flash devices and one for the DRAM. The latter | 9 | Message-id: 20250223114708.1780-5-shentey@gmail.com |
10 | is populated using a "dram" link set from the machine with the RAM | ||
11 | container region. | ||
12 | |||
13 | Signed-off-by: Cédric Le Goater <clg@kaod.org> | ||
14 | Acked-by: Joel Stanley <joel@jms.id.au> | ||
15 | Message-id: 20190904070506.1052-6-clg@kaod.org | ||
16 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
11 | [PMM: drop 'static const' from serial_table[] definition to avoid | ||
12 | compile failure on GCC 7.5] | ||
17 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 13 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
18 | --- | 14 | --- |
19 | include/hw/ssi/aspeed_smc.h | 6 + | 15 | MAINTAINERS | 9 + |
20 | hw/arm/aspeed.c | 2 + | 16 | docs/system/arm/imx8mp-evk.rst | 54 +++++ |
21 | hw/arm/aspeed_soc.c | 2 + | 17 | docs/system/target-arm.rst | 1 + |
22 | hw/ssi/aspeed_smc.c | 222 +++++++++++++++++++++++++++++++++++- | 18 | include/hw/arm/fsl-imx8mp.h | 189 +++++++++++++++++ |
23 | 4 files changed, 226 insertions(+), 6 deletions(-) | 19 | hw/arm/fsl-imx8mp.c | 367 +++++++++++++++++++++++++++++++++ |
20 | hw/arm/imx8mp-evk.c | 55 +++++ | ||
21 | hw/arm/Kconfig | 12 ++ | ||
22 | hw/arm/meson.build | 2 + | ||
23 | 8 files changed, 689 insertions(+) | ||
24 | create mode 100644 docs/system/arm/imx8mp-evk.rst | ||
25 | create mode 100644 include/hw/arm/fsl-imx8mp.h | ||
26 | create mode 100644 hw/arm/fsl-imx8mp.c | ||
27 | create mode 100644 hw/arm/imx8mp-evk.c | ||
24 | 28 | ||
25 | diff --git a/include/hw/ssi/aspeed_smc.h b/include/hw/ssi/aspeed_smc.h | 29 | diff --git a/MAINTAINERS b/MAINTAINERS |
26 | index XXXXXXX..XXXXXXX 100644 | 30 | index XXXXXXX..XXXXXXX 100644 |
27 | --- a/include/hw/ssi/aspeed_smc.h | 31 | --- a/MAINTAINERS |
28 | +++ b/include/hw/ssi/aspeed_smc.h | 32 | +++ b/MAINTAINERS |
29 | @@ -XXX,XX +XXX,XX @@ typedef struct AspeedSMCController { | 33 | @@ -XXX,XX +XXX,XX @@ F: hw/pci-host/designware.c |
30 | hwaddr flash_window_base; | 34 | F: include/hw/pci-host/designware.h |
31 | uint32_t flash_window_size; | 35 | F: docs/system/arm/mcimx7d-sabre.rst |
32 | bool has_dma; | 36 | |
33 | + hwaddr dma_flash_mask; | 37 | +MCIMX8MP-EVK / i.MX8MP |
34 | + hwaddr dma_dram_mask; | 38 | +M: Bernhard Beschow <shentey@gmail.com> |
35 | uint32_t nregs; | 39 | +L: qemu-arm@nongnu.org |
36 | } AspeedSMCController; | 40 | +S: Maintained |
37 | 41 | +F: hw/arm/imx8mp-evk.c | |
38 | @@ -XXX,XX +XXX,XX @@ typedef struct AspeedSMCState { | 42 | +F: hw/arm/fsl-imx8mp.c |
39 | /* for DMA support */ | 43 | +F: include/hw/arm/fsl-imx8mp.h |
40 | uint64_t sdram_base; | 44 | +F: docs/system/arm/imx8mp-evk.rst |
41 | 45 | + | |
42 | + AddressSpace flash_as; | 46 | MPS2 / MPS3 |
43 | + MemoryRegion *dram_mr; | 47 | M: Peter Maydell <peter.maydell@linaro.org> |
44 | + AddressSpace dram_as; | 48 | L: qemu-arm@nongnu.org |
45 | + | 49 | diff --git a/docs/system/arm/imx8mp-evk.rst b/docs/system/arm/imx8mp-evk.rst |
46 | AspeedSMCFlash *flashes; | 50 | new file mode 100644 |
47 | 51 | index XXXXXXX..XXXXXXX | |
48 | uint8_t snoop_index; | 52 | --- /dev/null |
49 | diff --git a/hw/arm/aspeed.c b/hw/arm/aspeed.c | 53 | +++ b/docs/system/arm/imx8mp-evk.rst |
54 | @@ -XXX,XX +XXX,XX @@ | ||
55 | +NXP i.MX 8M Plus Evaluation Kit (``imx8mp-evk``) | ||
56 | +================================================ | ||
57 | + | ||
58 | +The ``imx8mp-evk`` machine models the i.MX 8M Plus Evaluation Kit, based on an | ||
59 | +i.MX 8M Plus SoC. | ||
60 | + | ||
61 | +Supported devices | ||
62 | +----------------- | ||
63 | + | ||
64 | +The ``imx8mp-evk`` machine implements the following devices: | ||
65 | + | ||
66 | + * Up to 4 Cortex-A53 cores | ||
67 | + * Generic Interrupt Controller (GICv3) | ||
68 | + * 4 UARTs | ||
69 | + | ||
70 | +Boot options | ||
71 | +------------ | ||
72 | + | ||
73 | +The ``imx8mp-evk`` machine can start a Linux kernel directly using the standard | ||
74 | +``-kernel`` functionality. | ||
75 | + | ||
76 | +Direct Linux Kernel Boot | ||
77 | +'''''''''''''''''''''''' | ||
78 | + | ||
79 | +Probably the easiest way to get started with a whole Linux system on the machine | ||
80 | +is to generate an image with Buildroot. Version 2024.11.1 is tested at the time | ||
81 | +of writing and involves two steps. First run the following commands in the | ||
82 | +toplevel directory of the Buildroot source tree: | ||
83 | + | ||
84 | +.. code-block:: bash | ||
85 | + | ||
86 | + $ echo "BR2_TARGET_ROOTFS_CPIO=y" >> configs/freescale_imx8mpevk_defconfig | ||
87 | + $ make freescale_imx8mpevk_defconfig | ||
88 | + $ make | ||
89 | + | ||
90 | +Once finished successfully there is an ``output/image`` subfolder. Navigate into | ||
91 | +it and patch the device tree with the following commands which will remove the | ||
92 | +``cpu-idle-states`` properties from CPU nodes: | ||
93 | + | ||
94 | +.. code-block:: bash | ||
95 | + | ||
96 | + $ dtc imx8mp-evk.dtb | sed '/cpu-idle-states/d' > imx8mp-evk-patched.dts | ||
97 | + $ dtc imx8mp-evk-patched.dts -o imx8mp-evk-patched.dtb | ||
98 | + | ||
99 | +Now that everything is prepared the machine can be started as follows: | ||
100 | + | ||
101 | +.. code-block:: bash | ||
102 | + | ||
103 | + $ qemu-system-aarch64 -M imx8mp-evk -smp 4 -m 3G \ | ||
104 | + -display none -serial null -serial stdio \ | ||
105 | + -kernel Image \ | ||
106 | + -dtb imx8mp-evk-patched.dtb \ | ||
107 | + -initrd rootfs.cpio \ | ||
108 | + -append "root=/dev/ram" | ||
109 | diff --git a/docs/system/target-arm.rst b/docs/system/target-arm.rst | ||
50 | index XXXXXXX..XXXXXXX 100644 | 110 | index XXXXXXX..XXXXXXX 100644 |
51 | --- a/hw/arm/aspeed.c | 111 | --- a/docs/system/target-arm.rst |
52 | +++ b/hw/arm/aspeed.c | 112 | +++ b/docs/system/target-arm.rst |
53 | @@ -XXX,XX +XXX,XX @@ static void aspeed_board_init(MachineState *machine, | 113 | @@ -XXX,XX +XXX,XX @@ Board-specific documentation |
54 | &error_abort); | 114 | arm/imx25-pdk |
55 | object_property_set_int(OBJECT(&bmc->soc), machine->smp.cpus, "num-cpus", | 115 | arm/mcimx6ul-evk |
56 | &error_abort); | 116 | arm/mcimx7d-sabre |
57 | + object_property_set_link(OBJECT(&bmc->soc), OBJECT(&bmc->ram_container), | 117 | + arm/imx8mp-evk |
58 | + "dram", &error_abort); | 118 | arm/orangepi |
59 | if (machine->kernel_filename) { | 119 | arm/raspi |
60 | /* | 120 | arm/collie |
61 | * When booting with a -kernel command line there is no u-boot | 121 | diff --git a/include/hw/arm/fsl-imx8mp.h b/include/hw/arm/fsl-imx8mp.h |
62 | diff --git a/hw/arm/aspeed_soc.c b/hw/arm/aspeed_soc.c | 122 | new file mode 100644 |
63 | index XXXXXXX..XXXXXXX 100644 | 123 | index XXXXXXX..XXXXXXX |
64 | --- a/hw/arm/aspeed_soc.c | 124 | --- /dev/null |
65 | +++ b/hw/arm/aspeed_soc.c | 125 | +++ b/include/hw/arm/fsl-imx8mp.h |
66 | @@ -XXX,XX +XXX,XX @@ static void aspeed_soc_init(Object *obj) | ||
67 | typename); | ||
68 | object_property_add_alias(obj, "num-cs", OBJECT(&s->fmc), "num-cs", | ||
69 | &error_abort); | ||
70 | + object_property_add_alias(obj, "dram", OBJECT(&s->fmc), "dram", | ||
71 | + &error_abort); | ||
72 | |||
73 | for (i = 0; i < sc->info->spis_num; i++) { | ||
74 | snprintf(typename, sizeof(typename), "aspeed.spi%d-%s", i + 1, socname); | ||
75 | diff --git a/hw/ssi/aspeed_smc.c b/hw/ssi/aspeed_smc.c | ||
76 | index XXXXXXX..XXXXXXX 100644 | ||
77 | --- a/hw/ssi/aspeed_smc.c | ||
78 | +++ b/hw/ssi/aspeed_smc.c | ||
79 | @@ -XXX,XX +XXX,XX @@ | 126 | @@ -XXX,XX +XXX,XX @@ |
80 | #include "qemu/log.h" | 127 | +/* |
81 | #include "qemu/module.h" | 128 | + * i.MX 8M Plus SoC Definitions |
82 | #include "qemu/error-report.h" | 129 | + * |
130 | + * Copyright (c) 2024, Bernhard Beschow <shentey@gmail.com> | ||
131 | + * | ||
132 | + * SPDX-License-Identifier: GPL-2.0-or-later | ||
133 | + */ | ||
134 | + | ||
135 | +#ifndef FSL_IMX8MP_H | ||
136 | +#define FSL_IMX8MP_H | ||
137 | + | ||
138 | +#include "cpu.h" | ||
139 | +#include "hw/char/imx_serial.h" | ||
140 | +#include "hw/intc/arm_gicv3_common.h" | ||
141 | +#include "qom/object.h" | ||
142 | +#include "qemu/units.h" | ||
143 | + | ||
144 | +#define TYPE_FSL_IMX8MP "fsl-imx8mp" | ||
145 | +OBJECT_DECLARE_SIMPLE_TYPE(FslImx8mpState, FSL_IMX8MP) | ||
146 | + | ||
147 | +#define FSL_IMX8MP_RAM_START 0x40000000 | ||
148 | +#define FSL_IMX8MP_RAM_SIZE_MAX (8 * GiB) | ||
149 | + | ||
150 | +enum FslImx8mpConfiguration { | ||
151 | + FSL_IMX8MP_NUM_CPUS = 4, | ||
152 | + FSL_IMX8MP_NUM_IRQS = 160, | ||
153 | + FSL_IMX8MP_NUM_UARTS = 4, | ||
154 | +}; | ||
155 | + | ||
156 | +struct FslImx8mpState { | ||
157 | + DeviceState parent_obj; | ||
158 | + | ||
159 | + ARMCPU cpu[FSL_IMX8MP_NUM_CPUS]; | ||
160 | + GICv3State gic; | ||
161 | + IMXSerialState uart[FSL_IMX8MP_NUM_UARTS]; | ||
162 | +}; | ||
163 | + | ||
164 | +enum FslImx8mpMemoryRegions { | ||
165 | + FSL_IMX8MP_A53_DAP, | ||
166 | + FSL_IMX8MP_AIPS1_CONFIGURATION, | ||
167 | + FSL_IMX8MP_AIPS2_CONFIGURATION, | ||
168 | + FSL_IMX8MP_AIPS3_CONFIGURATION, | ||
169 | + FSL_IMX8MP_AIPS4_CONFIGURATION, | ||
170 | + FSL_IMX8MP_AIPS5_CONFIGURATION, | ||
171 | + FSL_IMX8MP_ANA_OSC, | ||
172 | + FSL_IMX8MP_ANA_PLL, | ||
173 | + FSL_IMX8MP_ANA_TSENSOR, | ||
174 | + FSL_IMX8MP_APBH_DMA, | ||
175 | + FSL_IMX8MP_ASRC, | ||
176 | + FSL_IMX8MP_AUDIO_BLK_CTRL, | ||
177 | + FSL_IMX8MP_AUDIO_DSP, | ||
178 | + FSL_IMX8MP_AUDIO_XCVR_RX, | ||
179 | + FSL_IMX8MP_AUD_IRQ_STEER, | ||
180 | + FSL_IMX8MP_BOOT_ROM, | ||
181 | + FSL_IMX8MP_BOOT_ROM_PROTECTED, | ||
182 | + FSL_IMX8MP_CAAM, | ||
183 | + FSL_IMX8MP_CAAM_MEM, | ||
184 | + FSL_IMX8MP_CCM, | ||
185 | + FSL_IMX8MP_CSU, | ||
186 | + FSL_IMX8MP_DDR_BLK_CTRL, | ||
187 | + FSL_IMX8MP_DDR_CTL, | ||
188 | + FSL_IMX8MP_DDR_PERF_MON, | ||
189 | + FSL_IMX8MP_DDR_PHY, | ||
190 | + FSL_IMX8MP_DDR_PHY_BROADCAST, | ||
191 | + FSL_IMX8MP_ECSPI1, | ||
192 | + FSL_IMX8MP_ECSPI2, | ||
193 | + FSL_IMX8MP_ECSPI3, | ||
194 | + FSL_IMX8MP_EDMA_CHANNELS, | ||
195 | + FSL_IMX8MP_EDMA_MANAGEMENT_PAGE, | ||
196 | + FSL_IMX8MP_ENET1, | ||
197 | + FSL_IMX8MP_ENET2_TSN, | ||
198 | + FSL_IMX8MP_FLEXCAN1, | ||
199 | + FSL_IMX8MP_FLEXCAN2, | ||
200 | + FSL_IMX8MP_GIC_DIST, | ||
201 | + FSL_IMX8MP_GIC_REDIST, | ||
202 | + FSL_IMX8MP_GPC, | ||
203 | + FSL_IMX8MP_GPIO1, | ||
204 | + FSL_IMX8MP_GPIO2, | ||
205 | + FSL_IMX8MP_GPIO3, | ||
206 | + FSL_IMX8MP_GPIO4, | ||
207 | + FSL_IMX8MP_GPIO5, | ||
208 | + FSL_IMX8MP_GPT1, | ||
209 | + FSL_IMX8MP_GPT2, | ||
210 | + FSL_IMX8MP_GPT3, | ||
211 | + FSL_IMX8MP_GPT4, | ||
212 | + FSL_IMX8MP_GPT5, | ||
213 | + FSL_IMX8MP_GPT6, | ||
214 | + FSL_IMX8MP_GPU2D, | ||
215 | + FSL_IMX8MP_GPU3D, | ||
216 | + FSL_IMX8MP_HDMI_TX, | ||
217 | + FSL_IMX8MP_HDMI_TX_AUDLNK_MSTR, | ||
218 | + FSL_IMX8MP_HSIO_BLK_CTL, | ||
219 | + FSL_IMX8MP_I2C1, | ||
220 | + FSL_IMX8MP_I2C2, | ||
221 | + FSL_IMX8MP_I2C3, | ||
222 | + FSL_IMX8MP_I2C4, | ||
223 | + FSL_IMX8MP_I2C5, | ||
224 | + FSL_IMX8MP_I2C6, | ||
225 | + FSL_IMX8MP_INTERCONNECT, | ||
226 | + FSL_IMX8MP_IOMUXC, | ||
227 | + FSL_IMX8MP_IOMUXC_GPR, | ||
228 | + FSL_IMX8MP_IPS_DEWARP, | ||
229 | + FSL_IMX8MP_ISI, | ||
230 | + FSL_IMX8MP_ISP1, | ||
231 | + FSL_IMX8MP_ISP2, | ||
232 | + FSL_IMX8MP_LCDIF1, | ||
233 | + FSL_IMX8MP_LCDIF2, | ||
234 | + FSL_IMX8MP_MEDIA_BLK_CTL, | ||
235 | + FSL_IMX8MP_MIPI_CSI1, | ||
236 | + FSL_IMX8MP_MIPI_CSI2, | ||
237 | + FSL_IMX8MP_MIPI_DSI1, | ||
238 | + FSL_IMX8MP_MU_1_A, | ||
239 | + FSL_IMX8MP_MU_1_B, | ||
240 | + FSL_IMX8MP_MU_2_A, | ||
241 | + FSL_IMX8MP_MU_2_B, | ||
242 | + FSL_IMX8MP_MU_3_A, | ||
243 | + FSL_IMX8MP_MU_3_B, | ||
244 | + FSL_IMX8MP_NPU, | ||
245 | + FSL_IMX8MP_OCOTP_CTRL, | ||
246 | + FSL_IMX8MP_OCRAM, | ||
247 | + FSL_IMX8MP_OCRAM_S, | ||
248 | + FSL_IMX8MP_PCIE1, | ||
249 | + FSL_IMX8MP_PCIE1_MEM, | ||
250 | + FSL_IMX8MP_PCIE_PHY1, | ||
251 | + FSL_IMX8MP_PDM, | ||
252 | + FSL_IMX8MP_PERFMON1, | ||
253 | + FSL_IMX8MP_PERFMON2, | ||
254 | + FSL_IMX8MP_PWM1, | ||
255 | + FSL_IMX8MP_PWM2, | ||
256 | + FSL_IMX8MP_PWM3, | ||
257 | + FSL_IMX8MP_PWM4, | ||
258 | + FSL_IMX8MP_QOSC, | ||
259 | + FSL_IMX8MP_QSPI, | ||
260 | + FSL_IMX8MP_QSPI1_RX_BUFFER, | ||
261 | + FSL_IMX8MP_QSPI1_TX_BUFFER, | ||
262 | + FSL_IMX8MP_QSPI_MEM, | ||
263 | + FSL_IMX8MP_RAM, | ||
264 | + FSL_IMX8MP_RDC, | ||
265 | + FSL_IMX8MP_SAI1, | ||
266 | + FSL_IMX8MP_SAI2, | ||
267 | + FSL_IMX8MP_SAI3, | ||
268 | + FSL_IMX8MP_SAI5, | ||
269 | + FSL_IMX8MP_SAI6, | ||
270 | + FSL_IMX8MP_SAI7, | ||
271 | + FSL_IMX8MP_SDMA1, | ||
272 | + FSL_IMX8MP_SDMA2, | ||
273 | + FSL_IMX8MP_SDMA3, | ||
274 | + FSL_IMX8MP_SEMAPHORE1, | ||
275 | + FSL_IMX8MP_SEMAPHORE2, | ||
276 | + FSL_IMX8MP_SEMAPHORE_HS, | ||
277 | + FSL_IMX8MP_SNVS_HP, | ||
278 | + FSL_IMX8MP_SPBA1, | ||
279 | + FSL_IMX8MP_SPBA2, | ||
280 | + FSL_IMX8MP_SRC, | ||
281 | + FSL_IMX8MP_SYSCNT_CMP, | ||
282 | + FSL_IMX8MP_SYSCNT_CTRL, | ||
283 | + FSL_IMX8MP_SYSCNT_RD, | ||
284 | + FSL_IMX8MP_TCM_DTCM, | ||
285 | + FSL_IMX8MP_TCM_ITCM, | ||
286 | + FSL_IMX8MP_TZASC, | ||
287 | + FSL_IMX8MP_UART1, | ||
288 | + FSL_IMX8MP_UART2, | ||
289 | + FSL_IMX8MP_UART3, | ||
290 | + FSL_IMX8MP_UART4, | ||
291 | + FSL_IMX8MP_USB1, | ||
292 | + FSL_IMX8MP_USB2, | ||
293 | + FSL_IMX8MP_USDHC1, | ||
294 | + FSL_IMX8MP_USDHC2, | ||
295 | + FSL_IMX8MP_USDHC3, | ||
296 | + FSL_IMX8MP_VPU, | ||
297 | + FSL_IMX8MP_VPU_BLK_CTRL, | ||
298 | + FSL_IMX8MP_VPU_G1_DECODER, | ||
299 | + FSL_IMX8MP_VPU_G2_DECODER, | ||
300 | + FSL_IMX8MP_VPU_VC8000E_ENCODER, | ||
301 | + FSL_IMX8MP_WDOG1, | ||
302 | + FSL_IMX8MP_WDOG2, | ||
303 | + FSL_IMX8MP_WDOG3, | ||
304 | +}; | ||
305 | + | ||
306 | +enum FslImx8mpIrqs { | ||
307 | + FSL_IMX8MP_UART1_IRQ = 26, | ||
308 | + FSL_IMX8MP_UART2_IRQ = 27, | ||
309 | + FSL_IMX8MP_UART3_IRQ = 28, | ||
310 | + FSL_IMX8MP_UART4_IRQ = 29, | ||
311 | + FSL_IMX8MP_UART5_IRQ = 30, | ||
312 | + FSL_IMX8MP_UART6_IRQ = 16, | ||
313 | +}; | ||
314 | + | ||
315 | +#endif /* FSL_IMX8MP_H */ | ||
316 | diff --git a/hw/arm/fsl-imx8mp.c b/hw/arm/fsl-imx8mp.c | ||
317 | new file mode 100644 | ||
318 | index XXXXXXX..XXXXXXX | ||
319 | --- /dev/null | ||
320 | +++ b/hw/arm/fsl-imx8mp.c | ||
321 | @@ -XXX,XX +XXX,XX @@ | ||
322 | +/* | ||
323 | + * i.MX 8M Plus SoC Implementation | ||
324 | + * | ||
325 | + * Based on hw/arm/fsl-imx6.c | ||
326 | + * | ||
327 | + * Copyright (c) 2024, Bernhard Beschow <shentey@gmail.com> | ||
328 | + * | ||
329 | + * SPDX-License-Identifier: GPL-2.0-or-later | ||
330 | + */ | ||
331 | + | ||
332 | +#include "qemu/osdep.h" | ||
333 | +#include "exec/address-spaces.h" | ||
334 | +#include "hw/arm/bsa.h" | ||
335 | +#include "hw/arm/fsl-imx8mp.h" | ||
336 | +#include "hw/intc/arm_gicv3.h" | ||
337 | +#include "hw/misc/unimp.h" | ||
338 | +#include "hw/boards.h" | ||
339 | +#include "system/system.h" | ||
340 | +#include "target/arm/cpu-qom.h" | ||
83 | +#include "qapi/error.h" | 341 | +#include "qapi/error.h" |
84 | +#include "exec/address-spaces.h" | 342 | +#include "qobject/qlist.h" |
85 | 343 | + | |
86 | #include "hw/irq.h" | 344 | +static const struct { |
87 | #include "hw/qdev-properties.h" | 345 | + hwaddr addr; |
88 | @@ -XXX,XX +XXX,XX @@ | 346 | + size_t size; |
89 | #define DMA_CTRL_FREQ_SHIFT 4 | 347 | + const char *name; |
90 | #define DMA_CTRL_MODE (1 << 3) | 348 | +} fsl_imx8mp_memmap[] = { |
91 | #define DMA_CTRL_CKSUM (1 << 2) | 349 | + [FSL_IMX8MP_RAM] = { FSL_IMX8MP_RAM_START, FSL_IMX8MP_RAM_SIZE_MAX, "ram" }, |
92 | -#define DMA_CTRL_DIR (1 << 1) | 350 | + [FSL_IMX8MP_DDR_PHY_BROADCAST] = { 0x3dc00000, 4 * MiB, "ddr_phy_broadcast" }, |
93 | -#define DMA_CTRL_EN (1 << 0) | 351 | + [FSL_IMX8MP_DDR_PERF_MON] = { 0x3d800000, 4 * MiB, "ddr_perf_mon" }, |
94 | +#define DMA_CTRL_WRITE (1 << 1) | 352 | + [FSL_IMX8MP_DDR_CTL] = { 0x3d400000, 4 * MiB, "ddr_ctl" }, |
95 | +#define DMA_CTRL_ENABLE (1 << 0) | 353 | + [FSL_IMX8MP_DDR_BLK_CTRL] = { 0x3d000000, 1 * MiB, "ddr_blk_ctrl" }, |
96 | 354 | + [FSL_IMX8MP_DDR_PHY] = { 0x3c000000, 16 * MiB, "ddr_phy" }, | |
97 | /* DMA Flash Side Address */ | 355 | + [FSL_IMX8MP_AUDIO_DSP] = { 0x3b000000, 16 * MiB, "audio_dsp" }, |
98 | #define R_DMA_FLASH_ADDR (0x84 / 4) | 356 | + [FSL_IMX8MP_GIC_DIST] = { 0x38800000, 512 * KiB, "gic_dist" }, |
99 | @@ -XXX,XX +XXX,XX @@ | 357 | + [FSL_IMX8MP_GIC_REDIST] = { 0x38880000, 512 * KiB, "gic_redist" }, |
100 | #define ASPEED_SOC_SPI_FLASH_BASE 0x30000000 | 358 | + [FSL_IMX8MP_NPU] = { 0x38500000, 2 * MiB, "npu" }, |
101 | #define ASPEED_SOC_SPI2_FLASH_BASE 0x38000000 | 359 | + [FSL_IMX8MP_VPU] = { 0x38340000, 2 * MiB, "vpu" }, |
102 | 360 | + [FSL_IMX8MP_VPU_BLK_CTRL] = { 0x38330000, 2 * MiB, "vpu_blk_ctrl" }, | |
103 | +/* | 361 | + [FSL_IMX8MP_VPU_VC8000E_ENCODER] = { 0x38320000, 2 * MiB, "vpu_vc8000e_encoder" }, |
104 | + * DMA DRAM addresses should be 4 bytes aligned and the valid address | 362 | + [FSL_IMX8MP_VPU_G2_DECODER] = { 0x38310000, 2 * MiB, "vpu_g2_decoder" }, |
105 | + * range is 0x40000000 - 0x5FFFFFFF (AST2400) | 363 | + [FSL_IMX8MP_VPU_G1_DECODER] = { 0x38300000, 2 * MiB, "vpu_g1_decoder" }, |
106 | + * 0x80000000 - 0xBFFFFFFF (AST2500) | 364 | + [FSL_IMX8MP_USB2] = { 0x38200000, 1 * MiB, "usb2" }, |
107 | + * | 365 | + [FSL_IMX8MP_USB1] = { 0x38100000, 1 * MiB, "usb1" }, |
108 | + * DMA flash addresses should be 4 bytes aligned and the valid address | 366 | + [FSL_IMX8MP_GPU2D] = { 0x38008000, 32 * KiB, "gpu2d" }, |
109 | + * range is 0x20000000 - 0x2FFFFFFF. | 367 | + [FSL_IMX8MP_GPU3D] = { 0x38000000, 32 * KiB, "gpu3d" }, |
110 | + * | 368 | + [FSL_IMX8MP_QSPI1_RX_BUFFER] = { 0x34000000, 32 * MiB, "qspi1_rx_buffer" }, |
111 | + * DMA length is from 4 bytes to 32MB | 369 | + [FSL_IMX8MP_PCIE1] = { 0x33800000, 4 * MiB, "pcie1" }, |
112 | + * 0: 4 bytes | 370 | + [FSL_IMX8MP_QSPI1_TX_BUFFER] = { 0x33008000, 32 * KiB, "qspi1_tx_buffer" }, |
113 | + * 0x7FFFFF: 32M bytes | 371 | + [FSL_IMX8MP_APBH_DMA] = { 0x33000000, 32 * KiB, "apbh_dma" }, |
114 | + */ | 372 | + |
115 | +#define DMA_DRAM_ADDR(s, val) ((s)->sdram_base | \ | 373 | + /* AIPS-5 Begin */ |
116 | + ((val) & (s)->ctrl->dma_dram_mask)) | 374 | + [FSL_IMX8MP_MU_3_B] = { 0x30e90000, 64 * KiB, "mu_3_b" }, |
117 | +#define DMA_FLASH_ADDR(s, val) ((s)->ctrl->flash_window_base | \ | 375 | + [FSL_IMX8MP_MU_3_A] = { 0x30e80000, 64 * KiB, "mu_3_a" }, |
118 | + ((val) & (s)->ctrl->dma_flash_mask)) | 376 | + [FSL_IMX8MP_MU_2_B] = { 0x30e70000, 64 * KiB, "mu_2_b" }, |
119 | +#define DMA_LENGTH(val) ((val) & 0x01FFFFFC) | 377 | + [FSL_IMX8MP_MU_2_A] = { 0x30e60000, 64 * KiB, "mu_2_a" }, |
120 | + | 378 | + [FSL_IMX8MP_EDMA_CHANNELS] = { 0x30e40000, 128 * KiB, "edma_channels" }, |
121 | /* Flash opcodes. */ | 379 | + [FSL_IMX8MP_EDMA_MANAGEMENT_PAGE] = { 0x30e30000, 64 * KiB, "edma_management_page" }, |
122 | #define SPI_OP_READ 0x03 /* Read data bytes (low frequency) */ | 380 | + [FSL_IMX8MP_AUDIO_BLK_CTRL] = { 0x30e20000, 64 * KiB, "audio_blk_ctrl" }, |
123 | 381 | + [FSL_IMX8MP_SDMA2] = { 0x30e10000, 64 * KiB, "sdma2" }, | |
124 | @@ -XXX,XX +XXX,XX @@ static const AspeedSMCController controllers[] = { | 382 | + [FSL_IMX8MP_SDMA3] = { 0x30e00000, 64 * KiB, "sdma3" }, |
125 | .flash_window_base = ASPEED_SOC_FMC_FLASH_BASE, | 383 | + [FSL_IMX8MP_AIPS5_CONFIGURATION] = { 0x30df0000, 64 * KiB, "aips5_configuration" }, |
126 | .flash_window_size = 0x10000000, | 384 | + [FSL_IMX8MP_SPBA2] = { 0x30cf0000, 64 * KiB, "spba2" }, |
127 | .has_dma = true, | 385 | + [FSL_IMX8MP_AUDIO_XCVR_RX] = { 0x30cc0000, 64 * KiB, "audio_xcvr_rx" }, |
128 | + .dma_flash_mask = 0x0FFFFFFC, | 386 | + [FSL_IMX8MP_HDMI_TX_AUDLNK_MSTR] = { 0x30cb0000, 64 * KiB, "hdmi_tx_audlnk_mstr" }, |
129 | + .dma_dram_mask = 0x1FFFFFFC, | 387 | + [FSL_IMX8MP_PDM] = { 0x30ca0000, 64 * KiB, "pdm" }, |
130 | .nregs = ASPEED_SMC_R_MAX, | 388 | + [FSL_IMX8MP_ASRC] = { 0x30c90000, 64 * KiB, "asrc" }, |
131 | }, { | 389 | + [FSL_IMX8MP_SAI7] = { 0x30c80000, 64 * KiB, "sai7" }, |
132 | .name = "aspeed.spi1-ast2400", | 390 | + [FSL_IMX8MP_SAI6] = { 0x30c60000, 64 * KiB, "sai6" }, |
133 | @@ -XXX,XX +XXX,XX @@ static const AspeedSMCController controllers[] = { | 391 | + [FSL_IMX8MP_SAI5] = { 0x30c50000, 64 * KiB, "sai5" }, |
134 | .flash_window_base = ASPEED_SOC_FMC_FLASH_BASE, | 392 | + [FSL_IMX8MP_SAI3] = { 0x30c30000, 64 * KiB, "sai3" }, |
135 | .flash_window_size = 0x10000000, | 393 | + [FSL_IMX8MP_SAI2] = { 0x30c20000, 64 * KiB, "sai2" }, |
136 | .has_dma = true, | 394 | + [FSL_IMX8MP_SAI1] = { 0x30c10000, 64 * KiB, "sai1" }, |
137 | + .dma_flash_mask = 0x0FFFFFFC, | 395 | + /* AIPS-5 End */ |
138 | + .dma_dram_mask = 0x3FFFFFFC, | 396 | + |
139 | .nregs = ASPEED_SMC_R_MAX, | 397 | + /* AIPS-4 Begin */ |
140 | }, { | 398 | + [FSL_IMX8MP_HDMI_TX] = { 0x32fc0000, 128 * KiB, "hdmi_tx" }, |
141 | .name = "aspeed.spi1-ast2500", | 399 | + [FSL_IMX8MP_TZASC] = { 0x32f80000, 64 * KiB, "tzasc" }, |
142 | @@ -XXX,XX +XXX,XX @@ static void aspeed_smc_reset(DeviceState *d) | 400 | + [FSL_IMX8MP_HSIO_BLK_CTL] = { 0x32f10000, 64 * KiB, "hsio_blk_ctl" }, |
143 | 401 | + [FSL_IMX8MP_PCIE_PHY1] = { 0x32f00000, 64 * KiB, "pcie_phy1" }, | |
144 | memset(s->regs, 0, sizeof s->regs); | 402 | + [FSL_IMX8MP_MEDIA_BLK_CTL] = { 0x32ec0000, 64 * KiB, "media_blk_ctl" }, |
145 | 403 | + [FSL_IMX8MP_LCDIF2] = { 0x32e90000, 64 * KiB, "lcdif2" }, | |
146 | - /* Pretend DMA is done (u-boot initialization) */ | 404 | + [FSL_IMX8MP_LCDIF1] = { 0x32e80000, 64 * KiB, "lcdif1" }, |
147 | - s->regs[R_INTR_CTRL] = INTR_CTRL_DMA_STATUS; | 405 | + [FSL_IMX8MP_MIPI_DSI1] = { 0x32e60000, 64 * KiB, "mipi_dsi1" }, |
148 | - | 406 | + [FSL_IMX8MP_MIPI_CSI2] = { 0x32e50000, 64 * KiB, "mipi_csi2" }, |
149 | /* Unselect all slaves */ | 407 | + [FSL_IMX8MP_MIPI_CSI1] = { 0x32e40000, 64 * KiB, "mipi_csi1" }, |
150 | for (i = 0; i < s->num_cs; ++i) { | 408 | + [FSL_IMX8MP_IPS_DEWARP] = { 0x32e30000, 64 * KiB, "ips_dewarp" }, |
151 | s->regs[s->r_ctrl0 + i] |= CTRL_CE_STOP_ACTIVE; | 409 | + [FSL_IMX8MP_ISP2] = { 0x32e20000, 64 * KiB, "isp2" }, |
152 | @@ -XXX,XX +XXX,XX @@ static uint64_t aspeed_smc_read(void *opaque, hwaddr addr, unsigned int size) | 410 | + [FSL_IMX8MP_ISP1] = { 0x32e10000, 64 * KiB, "isp1" }, |
153 | addr == s->r_ce_ctrl || | 411 | + [FSL_IMX8MP_ISI] = { 0x32e00000, 64 * KiB, "isi" }, |
154 | addr == R_INTR_CTRL || | 412 | + [FSL_IMX8MP_AIPS4_CONFIGURATION] = { 0x32df0000, 64 * KiB, "aips4_configuration" }, |
155 | addr == R_DUMMY_DATA || | 413 | + /* AIPS-4 End */ |
156 | + (s->ctrl->has_dma && addr == R_DMA_CTRL) || | 414 | + |
157 | + (s->ctrl->has_dma && addr == R_DMA_FLASH_ADDR) || | 415 | + [FSL_IMX8MP_INTERCONNECT] = { 0x32700000, 1 * MiB, "interconnect" }, |
158 | + (s->ctrl->has_dma && addr == R_DMA_DRAM_ADDR) || | 416 | + |
159 | + (s->ctrl->has_dma && addr == R_DMA_LEN) || | 417 | + /* AIPS-3 Begin */ |
160 | + (s->ctrl->has_dma && addr == R_DMA_CHECKSUM) || | 418 | + [FSL_IMX8MP_ENET2_TSN] = { 0x30bf0000, 64 * KiB, "enet2_tsn" }, |
161 | (addr >= R_SEG_ADDR0 && addr < R_SEG_ADDR0 + s->ctrl->max_slaves) || | 419 | + [FSL_IMX8MP_ENET1] = { 0x30be0000, 64 * KiB, "enet1" }, |
162 | (addr >= s->r_ctrl0 && addr < s->r_ctrl0 + s->ctrl->max_slaves)) { | 420 | + [FSL_IMX8MP_SDMA1] = { 0x30bd0000, 64 * KiB, "sdma1" }, |
163 | return s->regs[addr]; | 421 | + [FSL_IMX8MP_QSPI] = { 0x30bb0000, 64 * KiB, "qspi" }, |
164 | @@ -XXX,XX +XXX,XX @@ static uint64_t aspeed_smc_read(void *opaque, hwaddr addr, unsigned int size) | 422 | + [FSL_IMX8MP_USDHC3] = { 0x30b60000, 64 * KiB, "usdhc3" }, |
165 | } | 423 | + [FSL_IMX8MP_USDHC2] = { 0x30b50000, 64 * KiB, "usdhc2" }, |
166 | } | 424 | + [FSL_IMX8MP_USDHC1] = { 0x30b40000, 64 * KiB, "usdhc1" }, |
167 | 425 | + [FSL_IMX8MP_I2C6] = { 0x30ae0000, 64 * KiB, "i2c6" }, | |
168 | +/* | 426 | + [FSL_IMX8MP_I2C5] = { 0x30ad0000, 64 * KiB, "i2c5" }, |
169 | + * Accumulate the result of the reads to provide a checksum that will | 427 | + [FSL_IMX8MP_SEMAPHORE_HS] = { 0x30ac0000, 64 * KiB, "semaphore_hs" }, |
170 | + * be used to validate the read timing settings. | 428 | + [FSL_IMX8MP_MU_1_B] = { 0x30ab0000, 64 * KiB, "mu_1_b" }, |
171 | + */ | 429 | + [FSL_IMX8MP_MU_1_A] = { 0x30aa0000, 64 * KiB, "mu_1_a" }, |
172 | +static void aspeed_smc_dma_checksum(AspeedSMCState *s) | 430 | + [FSL_IMX8MP_AUD_IRQ_STEER] = { 0x30a80000, 64 * KiB, "aud_irq_steer" }, |
431 | + [FSL_IMX8MP_UART4] = { 0x30a60000, 64 * KiB, "uart4" }, | ||
432 | + [FSL_IMX8MP_I2C4] = { 0x30a50000, 64 * KiB, "i2c4" }, | ||
433 | + [FSL_IMX8MP_I2C3] = { 0x30a40000, 64 * KiB, "i2c3" }, | ||
434 | + [FSL_IMX8MP_I2C2] = { 0x30a30000, 64 * KiB, "i2c2" }, | ||
435 | + [FSL_IMX8MP_I2C1] = { 0x30a20000, 64 * KiB, "i2c1" }, | ||
436 | + [FSL_IMX8MP_AIPS3_CONFIGURATION] = { 0x309f0000, 64 * KiB, "aips3_configuration" }, | ||
437 | + [FSL_IMX8MP_CAAM] = { 0x30900000, 256 * KiB, "caam" }, | ||
438 | + [FSL_IMX8MP_SPBA1] = { 0x308f0000, 64 * KiB, "spba1" }, | ||
439 | + [FSL_IMX8MP_FLEXCAN2] = { 0x308d0000, 64 * KiB, "flexcan2" }, | ||
440 | + [FSL_IMX8MP_FLEXCAN1] = { 0x308c0000, 64 * KiB, "flexcan1" }, | ||
441 | + [FSL_IMX8MP_UART2] = { 0x30890000, 64 * KiB, "uart2" }, | ||
442 | + [FSL_IMX8MP_UART3] = { 0x30880000, 64 * KiB, "uart3" }, | ||
443 | + [FSL_IMX8MP_UART1] = { 0x30860000, 64 * KiB, "uart1" }, | ||
444 | + [FSL_IMX8MP_ECSPI3] = { 0x30840000, 64 * KiB, "ecspi3" }, | ||
445 | + [FSL_IMX8MP_ECSPI2] = { 0x30830000, 64 * KiB, "ecspi2" }, | ||
446 | + [FSL_IMX8MP_ECSPI1] = { 0x30820000, 64 * KiB, "ecspi1" }, | ||
447 | + /* AIPS-3 End */ | ||
448 | + | ||
449 | + /* AIPS-2 Begin */ | ||
450 | + [FSL_IMX8MP_QOSC] = { 0x307f0000, 64 * KiB, "qosc" }, | ||
451 | + [FSL_IMX8MP_PERFMON2] = { 0x307d0000, 64 * KiB, "perfmon2" }, | ||
452 | + [FSL_IMX8MP_PERFMON1] = { 0x307c0000, 64 * KiB, "perfmon1" }, | ||
453 | + [FSL_IMX8MP_GPT4] = { 0x30700000, 64 * KiB, "gpt4" }, | ||
454 | + [FSL_IMX8MP_GPT5] = { 0x306f0000, 64 * KiB, "gpt5" }, | ||
455 | + [FSL_IMX8MP_GPT6] = { 0x306e0000, 64 * KiB, "gpt6" }, | ||
456 | + [FSL_IMX8MP_SYSCNT_CTRL] = { 0x306c0000, 64 * KiB, "syscnt_ctrl" }, | ||
457 | + [FSL_IMX8MP_SYSCNT_CMP] = { 0x306b0000, 64 * KiB, "syscnt_cmp" }, | ||
458 | + [FSL_IMX8MP_SYSCNT_RD] = { 0x306a0000, 64 * KiB, "syscnt_rd" }, | ||
459 | + [FSL_IMX8MP_PWM4] = { 0x30690000, 64 * KiB, "pwm4" }, | ||
460 | + [FSL_IMX8MP_PWM3] = { 0x30680000, 64 * KiB, "pwm3" }, | ||
461 | + [FSL_IMX8MP_PWM2] = { 0x30670000, 64 * KiB, "pwm2" }, | ||
462 | + [FSL_IMX8MP_PWM1] = { 0x30660000, 64 * KiB, "pwm1" }, | ||
463 | + [FSL_IMX8MP_AIPS2_CONFIGURATION] = { 0x305f0000, 64 * KiB, "aips2_configuration" }, | ||
464 | + /* AIPS-2 End */ | ||
465 | + | ||
466 | + /* AIPS-1 Begin */ | ||
467 | + [FSL_IMX8MP_CSU] = { 0x303e0000, 64 * KiB, "csu" }, | ||
468 | + [FSL_IMX8MP_RDC] = { 0x303d0000, 64 * KiB, "rdc" }, | ||
469 | + [FSL_IMX8MP_SEMAPHORE2] = { 0x303c0000, 64 * KiB, "semaphore2" }, | ||
470 | + [FSL_IMX8MP_SEMAPHORE1] = { 0x303b0000, 64 * KiB, "semaphore1" }, | ||
471 | + [FSL_IMX8MP_GPC] = { 0x303a0000, 64 * KiB, "gpc" }, | ||
472 | + [FSL_IMX8MP_SRC] = { 0x30390000, 64 * KiB, "src" }, | ||
473 | + [FSL_IMX8MP_CCM] = { 0x30380000, 64 * KiB, "ccm" }, | ||
474 | + [FSL_IMX8MP_SNVS_HP] = { 0x30370000, 64 * KiB, "snvs_hp" }, | ||
475 | + [FSL_IMX8MP_ANA_PLL] = { 0x30360000, 64 * KiB, "ana_pll" }, | ||
476 | + [FSL_IMX8MP_OCOTP_CTRL] = { 0x30350000, 64 * KiB, "ocotp_ctrl" }, | ||
477 | + [FSL_IMX8MP_IOMUXC_GPR] = { 0x30340000, 64 * KiB, "iomuxc_gpr" }, | ||
478 | + [FSL_IMX8MP_IOMUXC] = { 0x30330000, 64 * KiB, "iomuxc" }, | ||
479 | + [FSL_IMX8MP_GPT3] = { 0x302f0000, 64 * KiB, "gpt3" }, | ||
480 | + [FSL_IMX8MP_GPT2] = { 0x302e0000, 64 * KiB, "gpt2" }, | ||
481 | + [FSL_IMX8MP_GPT1] = { 0x302d0000, 64 * KiB, "gpt1" }, | ||
482 | + [FSL_IMX8MP_WDOG3] = { 0x302a0000, 64 * KiB, "wdog3" }, | ||
483 | + [FSL_IMX8MP_WDOG2] = { 0x30290000, 64 * KiB, "wdog2" }, | ||
484 | + [FSL_IMX8MP_WDOG1] = { 0x30280000, 64 * KiB, "wdog1" }, | ||
485 | + [FSL_IMX8MP_ANA_OSC] = { 0x30270000, 64 * KiB, "ana_osc" }, | ||
486 | + [FSL_IMX8MP_ANA_TSENSOR] = { 0x30260000, 64 * KiB, "ana_tsensor" }, | ||
487 | + [FSL_IMX8MP_GPIO5] = { 0x30240000, 64 * KiB, "gpio5" }, | ||
488 | + [FSL_IMX8MP_GPIO4] = { 0x30230000, 64 * KiB, "gpio4" }, | ||
489 | + [FSL_IMX8MP_GPIO3] = { 0x30220000, 64 * KiB, "gpio3" }, | ||
490 | + [FSL_IMX8MP_GPIO2] = { 0x30210000, 64 * KiB, "gpio2" }, | ||
491 | + [FSL_IMX8MP_GPIO1] = { 0x30200000, 64 * KiB, "gpio1" }, | ||
492 | + [FSL_IMX8MP_AIPS1_CONFIGURATION] = { 0x301f0000, 64 * KiB, "aips1_configuration" }, | ||
493 | + /* AIPS-1 End */ | ||
494 | + | ||
495 | + [FSL_IMX8MP_A53_DAP] = { 0x28000000, 16 * MiB, "a53_dap" }, | ||
496 | + [FSL_IMX8MP_PCIE1_MEM] = { 0x18000000, 128 * MiB, "pcie1_mem" }, | ||
497 | + [FSL_IMX8MP_QSPI_MEM] = { 0x08000000, 256 * MiB, "qspi_mem" }, | ||
498 | + [FSL_IMX8MP_OCRAM] = { 0x00900000, 576 * KiB, "ocram" }, | ||
499 | + [FSL_IMX8MP_TCM_DTCM] = { 0x00800000, 128 * KiB, "tcm_dtcm" }, | ||
500 | + [FSL_IMX8MP_TCM_ITCM] = { 0x007e0000, 128 * KiB, "tcm_itcm" }, | ||
501 | + [FSL_IMX8MP_OCRAM_S] = { 0x00180000, 36 * KiB, "ocram_s" }, | ||
502 | + [FSL_IMX8MP_CAAM_MEM] = { 0x00100000, 32 * KiB, "caam_mem" }, | ||
503 | + [FSL_IMX8MP_BOOT_ROM_PROTECTED] = { 0x0003f000, 4 * KiB, "boot_rom_protected" }, | ||
504 | + [FSL_IMX8MP_BOOT_ROM] = { 0x00000000, 252 * KiB, "boot_rom" }, | ||
505 | +}; | ||
506 | + | ||
507 | +static void fsl_imx8mp_init(Object *obj) | ||
173 | +{ | 508 | +{ |
174 | + MemTxResult result; | 509 | + MachineState *ms = MACHINE(qdev_get_machine()); |
175 | + uint32_t data; | 510 | + FslImx8mpState *s = FSL_IMX8MP(obj); |
176 | + | 511 | + int i; |
177 | + if (s->regs[R_DMA_CTRL] & DMA_CTRL_WRITE) { | 512 | + |
178 | + qemu_log_mask(LOG_GUEST_ERROR, | 513 | + for (i = 0; i < MIN(ms->smp.cpus, FSL_IMX8MP_NUM_CPUS); i++) { |
179 | + "%s: invalid direction for DMA checksum\n", __func__); | 514 | + g_autofree char *name = g_strdup_printf("cpu%d", i); |
515 | + object_initialize_child(obj, name, &s->cpu[i], | ||
516 | + ARM_CPU_TYPE_NAME("cortex-a53")); | ||
517 | + } | ||
518 | + | ||
519 | + object_initialize_child(obj, "gic", &s->gic, TYPE_ARM_GICV3); | ||
520 | + | ||
521 | + for (i = 0; i < FSL_IMX8MP_NUM_UARTS; i++) { | ||
522 | + g_autofree char *name = g_strdup_printf("uart%d", i + 1); | ||
523 | + object_initialize_child(obj, name, &s->uart[i], TYPE_IMX_SERIAL); | ||
524 | + } | ||
525 | +} | ||
526 | + | ||
527 | +static void fsl_imx8mp_realize(DeviceState *dev, Error **errp) | ||
528 | +{ | ||
529 | + MachineState *ms = MACHINE(qdev_get_machine()); | ||
530 | + FslImx8mpState *s = FSL_IMX8MP(dev); | ||
531 | + DeviceState *gicdev = DEVICE(&s->gic); | ||
532 | + int i; | ||
533 | + | ||
534 | + if (ms->smp.cpus > FSL_IMX8MP_NUM_CPUS) { | ||
535 | + error_setg(errp, "%s: Only %d CPUs are supported (%d requested)", | ||
536 | + TYPE_FSL_IMX8MP, FSL_IMX8MP_NUM_CPUS, ms->smp.cpus); | ||
180 | + return; | 537 | + return; |
181 | + } | 538 | + } |
182 | + | 539 | + |
183 | + while (s->regs[R_DMA_LEN]) { | 540 | + /* CPUs */ |
184 | + data = address_space_ldl_le(&s->flash_as, s->regs[R_DMA_FLASH_ADDR], | 541 | + for (i = 0; i < ms->smp.cpus; i++) { |
185 | + MEMTXATTRS_UNSPECIFIED, &result); | 542 | + /* On uniprocessor, the CBAR is set to 0 */ |
186 | + if (result != MEMTX_OK) { | 543 | + if (ms->smp.cpus > 1) { |
187 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: Flash read failed @%08x\n", | 544 | + object_property_set_int(OBJECT(&s->cpu[i]), "reset-cbar", |
188 | + __func__, s->regs[R_DMA_FLASH_ADDR]); | 545 | + fsl_imx8mp_memmap[FSL_IMX8MP_GIC_DIST].addr, |
546 | + &error_abort); | ||
547 | + } | ||
548 | + | ||
549 | + /* | ||
550 | + * CNTFID0 base frequency in Hz of system counter | ||
551 | + */ | ||
552 | + object_property_set_int(OBJECT(&s->cpu[i]), "cntfrq", 8000000, | ||
553 | + &error_abort); | ||
554 | + | ||
555 | + if (i) { | ||
556 | + /* | ||
557 | + * Secondary CPUs start in powered-down state (and can be | ||
558 | + * powered up via the SRC system reset controller) | ||
559 | + */ | ||
560 | + object_property_set_bool(OBJECT(&s->cpu[i]), "start-powered-off", | ||
561 | + true, &error_abort); | ||
562 | + } | ||
563 | + | ||
564 | + if (!qdev_realize(DEVICE(&s->cpu[i]), NULL, errp)) { | ||
189 | + return; | 565 | + return; |
190 | + } | 566 | + } |
567 | + } | ||
568 | + | ||
569 | + /* GIC */ | ||
570 | + { | ||
571 | + SysBusDevice *gicsbd = SYS_BUS_DEVICE(&s->gic); | ||
572 | + QList *redist_region_count; | ||
573 | + | ||
574 | + qdev_prop_set_uint32(gicdev, "num-cpu", ms->smp.cpus); | ||
575 | + qdev_prop_set_uint32(gicdev, "num-irq", | ||
576 | + FSL_IMX8MP_NUM_IRQS + GIC_INTERNAL); | ||
577 | + redist_region_count = qlist_new(); | ||
578 | + qlist_append_int(redist_region_count, ms->smp.cpus); | ||
579 | + qdev_prop_set_array(gicdev, "redist-region-count", redist_region_count); | ||
580 | + object_property_set_link(OBJECT(&s->gic), "sysmem", | ||
581 | + OBJECT(get_system_memory()), &error_fatal); | ||
582 | + if (!sysbus_realize(gicsbd, errp)) { | ||
583 | + return; | ||
584 | + } | ||
585 | + sysbus_mmio_map(gicsbd, 0, fsl_imx8mp_memmap[FSL_IMX8MP_GIC_DIST].addr); | ||
586 | + sysbus_mmio_map(gicsbd, 1, fsl_imx8mp_memmap[FSL_IMX8MP_GIC_REDIST].addr); | ||
191 | + | 587 | + |
192 | + /* | 588 | + /* |
193 | + * When the DMA is on-going, the DMA registers are updated | 589 | + * Wire the outputs from each CPU's generic timer and the GICv3 |
194 | + * with the current working addresses and length. | 590 | + * maintenance interrupt signal to the appropriate GIC PPI inputs, and |
591 | + * the GIC's IRQ/FIQ interrupt outputs to the CPU's inputs. | ||
195 | + */ | 592 | + */ |
196 | + s->regs[R_DMA_CHECKSUM] += data; | 593 | + for (i = 0; i < ms->smp.cpus; i++) { |
197 | + s->regs[R_DMA_FLASH_ADDR] += 4; | 594 | + DeviceState *cpudev = DEVICE(&s->cpu[i]); |
198 | + s->regs[R_DMA_LEN] -= 4; | 595 | + int intidbase = FSL_IMX8MP_NUM_IRQS + i * GIC_INTERNAL; |
596 | + qemu_irq irq; | ||
597 | + | ||
598 | + /* | ||
599 | + * Mapping from the output timer irq lines from the CPU to the | ||
600 | + * GIC PPI inputs. | ||
601 | + */ | ||
602 | + static const int timer_irqs[] = { | ||
603 | + [GTIMER_PHYS] = ARCH_TIMER_NS_EL1_IRQ, | ||
604 | + [GTIMER_VIRT] = ARCH_TIMER_VIRT_IRQ, | ||
605 | + [GTIMER_HYP] = ARCH_TIMER_NS_EL2_IRQ, | ||
606 | + [GTIMER_SEC] = ARCH_TIMER_S_EL1_IRQ, | ||
607 | + }; | ||
608 | + | ||
609 | + for (int j = 0; j < ARRAY_SIZE(timer_irqs); j++) { | ||
610 | + irq = qdev_get_gpio_in(gicdev, intidbase + timer_irqs[j]); | ||
611 | + qdev_connect_gpio_out(cpudev, j, irq); | ||
612 | + } | ||
613 | + | ||
614 | + irq = qdev_get_gpio_in(gicdev, intidbase + ARCH_GIC_MAINT_IRQ); | ||
615 | + qdev_connect_gpio_out_named(cpudev, "gicv3-maintenance-interrupt", | ||
616 | + 0, irq); | ||
617 | + | ||
618 | + irq = qdev_get_gpio_in(gicdev, intidbase + VIRTUAL_PMU_IRQ); | ||
619 | + qdev_connect_gpio_out_named(cpudev, "pmu-interrupt", 0, irq); | ||
620 | + | ||
621 | + sysbus_connect_irq(gicsbd, i, | ||
622 | + qdev_get_gpio_in(cpudev, ARM_CPU_IRQ)); | ||
623 | + sysbus_connect_irq(gicsbd, i + ms->smp.cpus, | ||
624 | + qdev_get_gpio_in(cpudev, ARM_CPU_FIQ)); | ||
625 | + } | ||
626 | + } | ||
627 | + | ||
628 | + /* UARTs */ | ||
629 | + for (i = 0; i < FSL_IMX8MP_NUM_UARTS; i++) { | ||
630 | + struct { | ||
631 | + hwaddr addr; | ||
632 | + unsigned int irq; | ||
633 | + } serial_table[FSL_IMX8MP_NUM_UARTS] = { | ||
634 | + { fsl_imx8mp_memmap[FSL_IMX8MP_UART1].addr, FSL_IMX8MP_UART1_IRQ }, | ||
635 | + { fsl_imx8mp_memmap[FSL_IMX8MP_UART2].addr, FSL_IMX8MP_UART2_IRQ }, | ||
636 | + { fsl_imx8mp_memmap[FSL_IMX8MP_UART3].addr, FSL_IMX8MP_UART3_IRQ }, | ||
637 | + { fsl_imx8mp_memmap[FSL_IMX8MP_UART4].addr, FSL_IMX8MP_UART4_IRQ }, | ||
638 | + }; | ||
639 | + | ||
640 | + qdev_prop_set_chr(DEVICE(&s->uart[i]), "chardev", serial_hd(i)); | ||
641 | + if (!sysbus_realize(SYS_BUS_DEVICE(&s->uart[i]), errp)) { | ||
642 | + return; | ||
643 | + } | ||
644 | + | ||
645 | + sysbus_mmio_map(SYS_BUS_DEVICE(&s->uart[i]), 0, serial_table[i].addr); | ||
646 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->uart[i]), 0, | ||
647 | + qdev_get_gpio_in(gicdev, serial_table[i].irq)); | ||
648 | + } | ||
649 | + | ||
650 | + /* Unimplemented devices */ | ||
651 | + for (i = 0; i < ARRAY_SIZE(fsl_imx8mp_memmap); i++) { | ||
652 | + switch (i) { | ||
653 | + case FSL_IMX8MP_GIC_DIST: | ||
654 | + case FSL_IMX8MP_GIC_REDIST: | ||
655 | + case FSL_IMX8MP_RAM: | ||
656 | + case FSL_IMX8MP_UART1 ... FSL_IMX8MP_UART4: | ||
657 | + /* device implemented and treated above */ | ||
658 | + break; | ||
659 | + | ||
660 | + default: | ||
661 | + create_unimplemented_device(fsl_imx8mp_memmap[i].name, | ||
662 | + fsl_imx8mp_memmap[i].addr, | ||
663 | + fsl_imx8mp_memmap[i].size); | ||
664 | + break; | ||
665 | + } | ||
199 | + } | 666 | + } |
200 | +} | 667 | +} |
201 | + | 668 | + |
202 | +static void aspeed_smc_dma_rw(AspeedSMCState *s) | 669 | +static void fsl_imx8mp_class_init(ObjectClass *oc, void *data) |
203 | +{ | 670 | +{ |
204 | + MemTxResult result; | 671 | + DeviceClass *dc = DEVICE_CLASS(oc); |
205 | + uint32_t data; | 672 | + |
206 | + | 673 | + dc->realize = fsl_imx8mp_realize; |
207 | + while (s->regs[R_DMA_LEN]) { | 674 | + |
208 | + if (s->regs[R_DMA_CTRL] & DMA_CTRL_WRITE) { | 675 | + dc->desc = "i.MX 8M Plus SoC"; |
209 | + data = address_space_ldl_le(&s->dram_as, s->regs[R_DMA_DRAM_ADDR], | ||
210 | + MEMTXATTRS_UNSPECIFIED, &result); | ||
211 | + if (result != MEMTX_OK) { | ||
212 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: DRAM read failed @%08x\n", | ||
213 | + __func__, s->regs[R_DMA_DRAM_ADDR]); | ||
214 | + return; | ||
215 | + } | ||
216 | + | ||
217 | + address_space_stl_le(&s->flash_as, s->regs[R_DMA_FLASH_ADDR], | ||
218 | + data, MEMTXATTRS_UNSPECIFIED, &result); | ||
219 | + if (result != MEMTX_OK) { | ||
220 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: Flash write failed @%08x\n", | ||
221 | + __func__, s->regs[R_DMA_FLASH_ADDR]); | ||
222 | + return; | ||
223 | + } | ||
224 | + } else { | ||
225 | + data = address_space_ldl_le(&s->flash_as, s->regs[R_DMA_FLASH_ADDR], | ||
226 | + MEMTXATTRS_UNSPECIFIED, &result); | ||
227 | + if (result != MEMTX_OK) { | ||
228 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: Flash read failed @%08x\n", | ||
229 | + __func__, s->regs[R_DMA_FLASH_ADDR]); | ||
230 | + return; | ||
231 | + } | ||
232 | + | ||
233 | + address_space_stl_le(&s->dram_as, s->regs[R_DMA_DRAM_ADDR], | ||
234 | + data, MEMTXATTRS_UNSPECIFIED, &result); | ||
235 | + if (result != MEMTX_OK) { | ||
236 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: DRAM write failed @%08x\n", | ||
237 | + __func__, s->regs[R_DMA_DRAM_ADDR]); | ||
238 | + return; | ||
239 | + } | ||
240 | + } | ||
241 | + | ||
242 | + /* | ||
243 | + * When the DMA is on-going, the DMA registers are updated | ||
244 | + * with the current working addresses and length. | ||
245 | + */ | ||
246 | + s->regs[R_DMA_FLASH_ADDR] += 4; | ||
247 | + s->regs[R_DMA_DRAM_ADDR] += 4; | ||
248 | + s->regs[R_DMA_LEN] -= 4; | ||
249 | + } | ||
250 | +} | 676 | +} |
251 | + | 677 | + |
252 | +static void aspeed_smc_dma_stop(AspeedSMCState *s) | 678 | +static const TypeInfo fsl_imx8mp_types[] = { |
679 | + { | ||
680 | + .name = TYPE_FSL_IMX8MP, | ||
681 | + .parent = TYPE_DEVICE, | ||
682 | + .instance_size = sizeof(FslImx8mpState), | ||
683 | + .instance_init = fsl_imx8mp_init, | ||
684 | + .class_init = fsl_imx8mp_class_init, | ||
685 | + }, | ||
686 | +}; | ||
687 | + | ||
688 | +DEFINE_TYPES(fsl_imx8mp_types) | ||
689 | diff --git a/hw/arm/imx8mp-evk.c b/hw/arm/imx8mp-evk.c | ||
690 | new file mode 100644 | ||
691 | index XXXXXXX..XXXXXXX | ||
692 | --- /dev/null | ||
693 | +++ b/hw/arm/imx8mp-evk.c | ||
694 | @@ -XXX,XX +XXX,XX @@ | ||
695 | +/* | ||
696 | + * NXP i.MX 8M Plus Evaluation Kit System Emulation | ||
697 | + * | ||
698 | + * Copyright (c) 2024, Bernhard Beschow <shentey@gmail.com> | ||
699 | + * | ||
700 | + * SPDX-License-Identifier: GPL-2.0-or-later | ||
701 | + */ | ||
702 | + | ||
703 | +#include "qemu/osdep.h" | ||
704 | +#include "exec/address-spaces.h" | ||
705 | +#include "hw/arm/boot.h" | ||
706 | +#include "hw/arm/fsl-imx8mp.h" | ||
707 | +#include "hw/boards.h" | ||
708 | +#include "system/qtest.h" | ||
709 | +#include "qemu/error-report.h" | ||
710 | +#include "qapi/error.h" | ||
711 | + | ||
712 | +static void imx8mp_evk_init(MachineState *machine) | ||
253 | +{ | 713 | +{ |
254 | + /* | 714 | + static struct arm_boot_info boot_info; |
255 | + * When the DMA is disabled, INTR_CTRL_DMA_STATUS=0 means the | 715 | + FslImx8mpState *s; |
256 | + * engine is idle | 716 | + |
257 | + */ | 717 | + if (machine->ram_size > FSL_IMX8MP_RAM_SIZE_MAX) { |
258 | + s->regs[R_INTR_CTRL] &= ~INTR_CTRL_DMA_STATUS; | 718 | + error_report("RAM size " RAM_ADDR_FMT " above max supported (%08" PRIx64 ")", |
259 | + s->regs[R_DMA_CHECKSUM] = 0; | 719 | + machine->ram_size, FSL_IMX8MP_RAM_SIZE_MAX); |
260 | + | 720 | + exit(1); |
261 | + /* | 721 | + } |
262 | + * Lower the DMA irq in any case. The IRQ control register could | 722 | + |
263 | + * have been cleared before disabling the DMA. | 723 | + boot_info = (struct arm_boot_info) { |
264 | + */ | 724 | + .loader_start = FSL_IMX8MP_RAM_START, |
265 | + qemu_irq_lower(s->irq); | 725 | + .board_id = -1, |
726 | + .ram_size = machine->ram_size, | ||
727 | + .psci_conduit = QEMU_PSCI_CONDUIT_SMC, | ||
728 | + }; | ||
729 | + | ||
730 | + s = FSL_IMX8MP(object_new(TYPE_FSL_IMX8MP)); | ||
731 | + object_property_add_child(OBJECT(machine), "soc", OBJECT(s)); | ||
732 | + qdev_realize(DEVICE(s), NULL, &error_fatal); | ||
733 | + | ||
734 | + memory_region_add_subregion(get_system_memory(), FSL_IMX8MP_RAM_START, | ||
735 | + machine->ram); | ||
736 | + | ||
737 | + if (!qtest_enabled()) { | ||
738 | + arm_load_kernel(&s->cpu[0], machine, &boot_info); | ||
739 | + } | ||
266 | +} | 740 | +} |
267 | + | 741 | + |
268 | +/* | 742 | +static void imx8mp_evk_machine_init(MachineClass *mc) |
269 | + * When INTR_CTRL_DMA_STATUS=1, the DMA has completed and a new DMA | ||
270 | + * can start even if the result of the previous was not collected. | ||
271 | + */ | ||
272 | +static bool aspeed_smc_dma_in_progress(AspeedSMCState *s) | ||
273 | +{ | 743 | +{ |
274 | + return s->regs[R_DMA_CTRL] & DMA_CTRL_ENABLE && | 744 | + mc->desc = "NXP i.MX 8M Plus EVK Board"; |
275 | + !(s->regs[R_INTR_CTRL] & INTR_CTRL_DMA_STATUS); | 745 | + mc->init = imx8mp_evk_init; |
746 | + mc->max_cpus = FSL_IMX8MP_NUM_CPUS; | ||
747 | + mc->default_ram_id = "imx8mp-evk.ram"; | ||
276 | +} | 748 | +} |
277 | + | 749 | +DEFINE_MACHINE("imx8mp-evk", imx8mp_evk_machine_init) |
278 | +static void aspeed_smc_dma_done(AspeedSMCState *s) | 750 | diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig |
279 | +{ | 751 | index XXXXXXX..XXXXXXX 100644 |
280 | + s->regs[R_INTR_CTRL] |= INTR_CTRL_DMA_STATUS; | 752 | --- a/hw/arm/Kconfig |
281 | + if (s->regs[R_INTR_CTRL] & INTR_CTRL_DMA_EN) { | 753 | +++ b/hw/arm/Kconfig |
282 | + qemu_irq_raise(s->irq); | 754 | @@ -XXX,XX +XXX,XX @@ config FSL_IMX7 |
283 | + } | 755 | select UNIMP |
284 | +} | 756 | select USB_CHIPIDEA |
285 | + | 757 | |
286 | +static void aspeed_smc_dma_ctrl(AspeedSMCState *s, uint64_t dma_ctrl) | 758 | +config FSL_IMX8MP |
287 | +{ | 759 | + bool |
288 | + if (!(dma_ctrl & DMA_CTRL_ENABLE)) { | 760 | + select ARM_GIC |
289 | + s->regs[R_DMA_CTRL] = dma_ctrl; | 761 | + select IMX |
290 | + | 762 | + select UNIMP |
291 | + aspeed_smc_dma_stop(s); | 763 | + |
292 | + return; | 764 | +config FSL_IMX8MP_EVK |
293 | + } | 765 | + bool |
294 | + | 766 | + default y |
295 | + if (aspeed_smc_dma_in_progress(s)) { | 767 | + depends on TCG && AARCH64 |
296 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: DMA in progress\n", __func__); | 768 | + select FSL_IMX8MP |
297 | + return; | 769 | + |
298 | + } | 770 | config ARM_SMMUV3 |
299 | + | 771 | bool |
300 | + s->regs[R_DMA_CTRL] = dma_ctrl; | 772 | |
301 | + | 773 | diff --git a/hw/arm/meson.build b/hw/arm/meson.build |
302 | + if (s->regs[R_DMA_CTRL] & DMA_CTRL_CKSUM) { | 774 | index XXXXXXX..XXXXXXX 100644 |
303 | + aspeed_smc_dma_checksum(s); | 775 | --- a/hw/arm/meson.build |
304 | + } else { | 776 | +++ b/hw/arm/meson.build |
305 | + aspeed_smc_dma_rw(s); | 777 | @@ -XXX,XX +XXX,XX @@ arm_ss.add(when: 'CONFIG_MSF2', if_true: files('msf2-soc.c')) |
306 | + } | 778 | arm_ss.add(when: 'CONFIG_MUSCA', if_true: files('musca.c')) |
307 | + | 779 | arm_ss.add(when: 'CONFIG_ARMSSE', if_true: files('armsse.c')) |
308 | + aspeed_smc_dma_done(s); | 780 | arm_ss.add(when: 'CONFIG_FSL_IMX7', if_true: files('fsl-imx7.c', 'mcimx7d-sabre.c')) |
309 | +} | 781 | +arm_ss.add(when: 'CONFIG_FSL_IMX8MP', if_true: files('fsl-imx8mp.c')) |
310 | + | 782 | +arm_ss.add(when: 'CONFIG_FSL_IMX8MP_EVK', if_true: files('imx8mp-evk.c')) |
311 | static void aspeed_smc_write(void *opaque, hwaddr addr, uint64_t data, | 783 | arm_ss.add(when: 'CONFIG_ARM_SMMUV3', if_true: files('smmuv3.c')) |
312 | unsigned int size) | 784 | arm_ss.add(when: 'CONFIG_FSL_IMX6UL', if_true: files('fsl-imx6ul.c', 'mcimx6ul-evk.c')) |
313 | { | 785 | arm_ss.add(when: 'CONFIG_NRF51_SOC', if_true: files('nrf51_soc.c')) |
314 | @@ -XXX,XX +XXX,XX @@ static void aspeed_smc_write(void *opaque, hwaddr addr, uint64_t data, | ||
315 | } | ||
316 | } else if (addr == R_DUMMY_DATA) { | ||
317 | s->regs[addr] = value & 0xff; | ||
318 | + } else if (addr == R_INTR_CTRL) { | ||
319 | + s->regs[addr] = value; | ||
320 | + } else if (s->ctrl->has_dma && addr == R_DMA_CTRL) { | ||
321 | + aspeed_smc_dma_ctrl(s, value); | ||
322 | + } else if (s->ctrl->has_dma && addr == R_DMA_DRAM_ADDR) { | ||
323 | + s->regs[addr] = DMA_DRAM_ADDR(s, value); | ||
324 | + } else if (s->ctrl->has_dma && addr == R_DMA_FLASH_ADDR) { | ||
325 | + s->regs[addr] = DMA_FLASH_ADDR(s, value); | ||
326 | + } else if (s->ctrl->has_dma && addr == R_DMA_LEN) { | ||
327 | + s->regs[addr] = DMA_LENGTH(value); | ||
328 | } else { | ||
329 | qemu_log_mask(LOG_UNIMP, "%s: not implemented: 0x%" HWADDR_PRIx "\n", | ||
330 | __func__, addr); | ||
331 | @@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps aspeed_smc_ops = { | ||
332 | .valid.unaligned = true, | ||
333 | }; | ||
334 | |||
335 | + | ||
336 | +/* | ||
337 | + * Initialize the custom address spaces for DMAs | ||
338 | + */ | ||
339 | +static void aspeed_smc_dma_setup(AspeedSMCState *s, Error **errp) | ||
340 | +{ | ||
341 | + char *name; | ||
342 | + | ||
343 | + if (!s->dram_mr) { | ||
344 | + error_setg(errp, TYPE_ASPEED_SMC ": 'dram' link not set"); | ||
345 | + return; | ||
346 | + } | ||
347 | + | ||
348 | + name = g_strdup_printf("%s-dma-flash", s->ctrl->name); | ||
349 | + address_space_init(&s->flash_as, &s->mmio_flash, name); | ||
350 | + g_free(name); | ||
351 | + | ||
352 | + name = g_strdup_printf("%s-dma-dram", s->ctrl->name); | ||
353 | + address_space_init(&s->dram_as, s->dram_mr, name); | ||
354 | + g_free(name); | ||
355 | +} | ||
356 | + | ||
357 | static void aspeed_smc_realize(DeviceState *dev, Error **errp) | ||
358 | { | ||
359 | SysBusDevice *sbd = SYS_BUS_DEVICE(dev); | ||
360 | @@ -XXX,XX +XXX,XX @@ static void aspeed_smc_realize(DeviceState *dev, Error **errp) | ||
361 | s->num_cs = s->ctrl->max_slaves; | ||
362 | } | ||
363 | |||
364 | + /* DMA irq. Keep it first for the initialization in the SoC */ | ||
365 | + sysbus_init_irq(sbd, &s->irq); | ||
366 | + | ||
367 | s->spi = ssi_create_bus(dev, "spi"); | ||
368 | |||
369 | /* Setup cs_lines for slaves */ | ||
370 | - sysbus_init_irq(sbd, &s->irq); | ||
371 | s->cs_lines = g_new0(qemu_irq, s->num_cs); | ||
372 | ssi_auto_connect_slaves(dev, s->cs_lines, s->spi); | ||
373 | |||
374 | @@ -XXX,XX +XXX,XX @@ static void aspeed_smc_realize(DeviceState *dev, Error **errp) | ||
375 | memory_region_add_subregion(&s->mmio_flash, offset, &fl->mmio); | ||
376 | offset += fl->size; | ||
377 | } | ||
378 | + | ||
379 | + /* DMA support */ | ||
380 | + if (s->ctrl->has_dma) { | ||
381 | + aspeed_smc_dma_setup(s, errp); | ||
382 | + } | ||
383 | } | ||
384 | |||
385 | static const VMStateDescription vmstate_aspeed_smc = { | ||
386 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_aspeed_smc = { | ||
387 | static Property aspeed_smc_properties[] = { | ||
388 | DEFINE_PROP_UINT32("num-cs", AspeedSMCState, num_cs, 1), | ||
389 | DEFINE_PROP_UINT64("sdram-base", AspeedSMCState, sdram_base, 0), | ||
390 | + DEFINE_PROP_LINK("dram", AspeedSMCState, dram_mr, | ||
391 | + TYPE_MEMORY_REGION, MemoryRegion *), | ||
392 | DEFINE_PROP_END_OF_LIST(), | ||
393 | }; | ||
394 | |||
395 | -- | 786 | -- |
396 | 2.20.1 | 787 | 2.43.0 |
397 | |||
398 | diff view generated by jsdifflib |
1 | The qemu-ga documentation is currently in qemu-ga.texi in | 1 | From: Bernhard Beschow <shentey@gmail.com> |
---|---|---|---|
2 | Texinfo format, which we present to the user as: | ||
3 | * a qemu-ga manpage | ||
4 | * a section of the main qemu-doc HTML documentation | ||
5 | 2 | ||
6 | Convert the documentation to rST format, and present it to | 3 | Fixes quite a few stack traces during the Linux boot process. Also provides the |
7 | the user as: | 4 | clocks for devices added later, e.g. enet1. |
8 | * a qemu-ga manpage | ||
9 | * part of the interop/ Sphinx manual | ||
10 | 5 | ||
6 | Signed-off-by: Bernhard Beschow <shentey@gmail.com> | ||
7 | Message-id: 20250223114708.1780-6-shentey@gmail.com | ||
8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
12 | Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com> | ||
13 | Tested-by: Michael Roth <mdroth@linux.vnet.ibm.com> | ||
14 | Message-id: 20190905131040.8350-1-peter.maydell@linaro.org | ||
15 | --- | 10 | --- |
16 | Makefile | 24 ++++--- | 11 | MAINTAINERS | 2 + |
17 | MAINTAINERS | 2 +- | 12 | docs/system/arm/imx8mp-evk.rst | 1 + |
18 | docs/conf.py | 18 ++--- | 13 | include/hw/arm/fsl-imx8mp.h | 4 + |
19 | docs/interop/conf.py | 7 ++ | 14 | include/hw/misc/imx8mp_analog.h | 81 +++++++++++++++ |
20 | docs/interop/index.rst | 1 + | 15 | include/hw/misc/imx8mp_ccm.h | 30 ++++++ |
21 | docs/interop/qemu-ga.rst | 133 +++++++++++++++++++++++++++++++++++++ | 16 | hw/arm/fsl-imx8mp.c | 20 ++++ |
22 | qemu-doc.texi | 5 -- | 17 | hw/misc/imx8mp_analog.c | 160 +++++++++++++++++++++++++++++ |
23 | qemu-ga.texi | 137 --------------------------------------- | 18 | hw/misc/imx8mp_ccm.c | 175 ++++++++++++++++++++++++++++++++ |
24 | 8 files changed, 166 insertions(+), 161 deletions(-) | 19 | hw/arm/Kconfig | 2 + |
25 | create mode 100644 docs/interop/qemu-ga.rst | 20 | hw/misc/Kconfig | 6 ++ |
26 | delete mode 100644 qemu-ga.texi | 21 | hw/misc/meson.build | 2 + |
22 | 11 files changed, 483 insertions(+) | ||
23 | create mode 100644 include/hw/misc/imx8mp_analog.h | ||
24 | create mode 100644 include/hw/misc/imx8mp_ccm.h | ||
25 | create mode 100644 hw/misc/imx8mp_analog.c | ||
26 | create mode 100644 hw/misc/imx8mp_ccm.c | ||
27 | 27 | ||
28 | diff --git a/Makefile b/Makefile | ||
29 | index XXXXXXX..XXXXXXX 100644 | ||
30 | --- a/Makefile | ||
31 | +++ b/Makefile | ||
32 | @@ -XXX,XX +XXX,XX @@ endif | ||
33 | endif | ||
34 | |||
35 | ifdef BUILD_DOCS | ||
36 | -DOCS=qemu-doc.html qemu-doc.txt qemu.1 qemu-img.1 qemu-nbd.8 qemu-ga.8 | ||
37 | +DOCS=qemu-doc.html qemu-doc.txt qemu.1 qemu-img.1 qemu-nbd.8 docs/interop/qemu-ga.8 | ||
38 | DOCS+=docs/interop/qemu-qmp-ref.html docs/interop/qemu-qmp-ref.txt docs/interop/qemu-qmp-ref.7 | ||
39 | DOCS+=docs/interop/qemu-ga-ref.html docs/interop/qemu-ga-ref.txt docs/interop/qemu-ga-ref.7 | ||
40 | DOCS+=docs/qemu-block-drivers.7 | ||
41 | @@ -XXX,XX +XXX,XX @@ DESCS= | ||
42 | endif | ||
43 | |||
44 | # Note that we manually filter-out the non-Sphinx documentation which | ||
45 | -# is currently built into the docs/interop directory in the build tree. | ||
46 | +# is currently built into the docs/interop directory in the build tree, | ||
47 | +# and also any sphinx-built manpages. | ||
48 | define install-manual = | ||
49 | for d in $$(cd $(MANUAL_BUILDDIR) && find $1 -type d); do $(INSTALL_DIR) "$(DESTDIR)$(qemu_docdir)/$$d"; done | ||
50 | -for f in $$(cd $(MANUAL_BUILDDIR) && find $1 -type f -a '!' '(' -name 'qemu-*-qapi.*' -o -name 'qemu-*-ref.*' ')' ); do $(INSTALL_DATA) "$(MANUAL_BUILDDIR)/$$f" "$(DESTDIR)$(qemu_docdir)/$$f"; done | ||
51 | +for f in $$(cd $(MANUAL_BUILDDIR) && find $1 -type f -a '!' '(' -name '*.[0-9]' -o -name 'qemu-*-qapi.*' -o -name 'qemu-*-ref.*' ')' ); do $(INSTALL_DATA) "$(MANUAL_BUILDDIR)/$$f" "$(DESTDIR)$(qemu_docdir)/$$f"; done | ||
52 | endef | ||
53 | |||
54 | # Note that we deliberately do not install the "devel" manual: it is | ||
55 | @@ -XXX,XX +XXX,XX @@ ifdef CONFIG_TRACE_SYSTEMTAP | ||
56 | $(INSTALL_DATA) scripts/qemu-trace-stap.1 "$(DESTDIR)$(mandir)/man1" | ||
57 | endif | ||
58 | ifneq (,$(findstring qemu-ga,$(TOOLS))) | ||
59 | - $(INSTALL_DATA) qemu-ga.8 "$(DESTDIR)$(mandir)/man8" | ||
60 | + $(INSTALL_DATA) docs/interop/qemu-ga.8 "$(DESTDIR)$(mandir)/man8" | ||
61 | $(INSTALL_DATA) docs/interop/qemu-ga-ref.html "$(DESTDIR)$(qemu_docdir)" | ||
62 | $(INSTALL_DATA) docs/interop/qemu-ga-ref.txt "$(DESTDIR)$(qemu_docdir)" | ||
63 | $(INSTALL_DATA) docs/interop/qemu-ga-ref.7 "$(DESTDIR)$(mandir)/man7" | ||
64 | @@ -XXX,XX +XXX,XX @@ docs/version.texi: $(SRC_PATH)/VERSION config-host.mak | ||
65 | sphinxdocs: $(MANUAL_BUILDDIR)/devel/index.html $(MANUAL_BUILDDIR)/interop/index.html $(MANUAL_BUILDDIR)/specs/index.html | ||
66 | |||
67 | # Canned command to build a single manual | ||
68 | -build-manual = $(call quiet-command,sphinx-build $(if $(V),,-q) -W -n -b html -D version=$(VERSION) -D release="$(FULL_VERSION)" -d .doctrees/$1 $(SRC_PATH)/docs/$1 $(MANUAL_BUILDDIR)/$1 ,"SPHINX","$(MANUAL_BUILDDIR)/$1") | ||
69 | +# Arguments: $1 = manual name, $2 = Sphinx builder ('html' or 'man') | ||
70 | +build-manual = $(call quiet-command,CONFDIR="$(qemu_confdir)" sphinx-build $(if $(V),,-q) -W -n -b $2 -D version=$(VERSION) -D release="$(FULL_VERSION)" -d .doctrees/$1 $(SRC_PATH)/docs/$1 $(MANUAL_BUILDDIR)/$1 ,"SPHINX","$(MANUAL_BUILDDIR)/$1") | ||
71 | # We assume all RST files in the manual's directory are used in it | ||
72 | manual-deps = $(wildcard $(SRC_PATH)/docs/$1/*.rst) $(SRC_PATH)/docs/$1/conf.py $(SRC_PATH)/docs/conf.py | ||
73 | |||
74 | $(MANUAL_BUILDDIR)/devel/index.html: $(call manual-deps,devel) | ||
75 | - $(call build-manual,devel) | ||
76 | + $(call build-manual,devel,html) | ||
77 | |||
78 | $(MANUAL_BUILDDIR)/interop/index.html: $(call manual-deps,interop) | ||
79 | - $(call build-manual,interop) | ||
80 | + $(call build-manual,interop,html) | ||
81 | |||
82 | $(MANUAL_BUILDDIR)/specs/index.html: $(call manual-deps,specs) | ||
83 | - $(call build-manual,specs) | ||
84 | + $(call build-manual,specs,html) | ||
85 | + | ||
86 | +$(MANUAL_BUILDDIR)/interop/qemu-ga.8: $(call manual-deps,interop) | ||
87 | + $(call build-manual,interop,man) | ||
88 | |||
89 | qemu-options.texi: $(SRC_PATH)/qemu-options.hx $(SRC_PATH)/scripts/hxtool | ||
90 | $(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -t < $< > $@,"GEN","$@") | ||
91 | @@ -XXX,XX +XXX,XX @@ qemu.1: qemu-option-trace.texi | ||
92 | qemu-img.1: qemu-img.texi qemu-option-trace.texi qemu-img-cmds.texi | ||
93 | fsdev/virtfs-proxy-helper.1: fsdev/virtfs-proxy-helper.texi | ||
94 | qemu-nbd.8: qemu-nbd.texi qemu-option-trace.texi | ||
95 | -qemu-ga.8: qemu-ga.texi | ||
96 | docs/qemu-block-drivers.7: docs/qemu-block-drivers.texi | ||
97 | docs/qemu-cpu-models.7: docs/qemu-cpu-models.texi | ||
98 | scripts/qemu-trace-stap.1: scripts/qemu-trace-stap.texi | ||
99 | @@ -XXX,XX +XXX,XX @@ txt: qemu-doc.txt docs/interop/qemu-qmp-ref.txt docs/interop/qemu-ga-ref.txt | ||
100 | qemu-doc.html qemu-doc.info qemu-doc.pdf qemu-doc.txt: \ | ||
101 | qemu-img.texi qemu-nbd.texi qemu-options.texi \ | ||
102 | qemu-tech.texi qemu-option-trace.texi \ | ||
103 | - qemu-deprecated.texi qemu-monitor.texi qemu-img-cmds.texi qemu-ga.texi \ | ||
104 | + qemu-deprecated.texi qemu-monitor.texi qemu-img-cmds.texi \ | ||
105 | qemu-monitor-info.texi docs/qemu-block-drivers.texi \ | ||
106 | docs/qemu-cpu-models.texi docs/security.texi | ||
107 | |||
108 | diff --git a/MAINTAINERS b/MAINTAINERS | 28 | diff --git a/MAINTAINERS b/MAINTAINERS |
109 | index XXXXXXX..XXXXXXX 100644 | 29 | index XXXXXXX..XXXXXXX 100644 |
110 | --- a/MAINTAINERS | 30 | --- a/MAINTAINERS |
111 | +++ b/MAINTAINERS | 31 | +++ b/MAINTAINERS |
112 | @@ -XXX,XX +XXX,XX @@ QEMU Guest Agent | 32 | @@ -XXX,XX +XXX,XX @@ L: qemu-arm@nongnu.org |
113 | M: Michael Roth <mdroth@linux.vnet.ibm.com> | ||
114 | S: Maintained | 33 | S: Maintained |
115 | F: qga/ | 34 | F: hw/arm/imx8mp-evk.c |
116 | -F: qemu-ga.texi | 35 | F: hw/arm/fsl-imx8mp.c |
117 | +F: docs/interop/qemu-ga.rst | 36 | +F: hw/misc/imx8mp_*.c |
118 | F: scripts/qemu-guest-agent/ | 37 | F: include/hw/arm/fsl-imx8mp.h |
119 | F: tests/test-qga.c | 38 | +F: include/hw/misc/imx8mp_*.h |
120 | F: docs/interop/qemu-ga-ref.texi | 39 | F: docs/system/arm/imx8mp-evk.rst |
121 | diff --git a/docs/conf.py b/docs/conf.py | 40 | |
41 | MPS2 / MPS3 | ||
42 | diff --git a/docs/system/arm/imx8mp-evk.rst b/docs/system/arm/imx8mp-evk.rst | ||
122 | index XXXXXXX..XXXXXXX 100644 | 43 | index XXXXXXX..XXXXXXX 100644 |
123 | --- a/docs/conf.py | 44 | --- a/docs/system/arm/imx8mp-evk.rst |
124 | +++ b/docs/conf.py | 45 | +++ b/docs/system/arm/imx8mp-evk.rst |
125 | @@ -XXX,XX +XXX,XX @@ todo_include_todos = False | 46 | @@ -XXX,XX +XXX,XX @@ The ``imx8mp-evk`` machine implements the following devices: |
126 | # with "option::" in the document being processed. Turn that off. | 47 | * Up to 4 Cortex-A53 cores |
127 | suppress_warnings = ["ref.option"] | 48 | * Generic Interrupt Controller (GICv3) |
128 | 49 | * 4 UARTs | |
129 | +# The rst_epilog fragment is effectively included in every rST file. | 50 | + * Clock Tree |
130 | +# We use it to define substitutions based on build config that | 51 | |
131 | +# can then be used in the documentation. The fallback if the | 52 | Boot options |
132 | +# environment variable is not set is for the benefit of readthedocs | 53 | ------------ |
133 | +# style document building; our Makefile always sets the variable. | 54 | diff --git a/include/hw/arm/fsl-imx8mp.h b/include/hw/arm/fsl-imx8mp.h |
134 | +confdir = os.getenv('CONFDIR', "/etc/qemu") | ||
135 | +rst_epilog = ".. |CONFDIR| replace:: ``" + confdir + "``\n" | ||
136 | + | ||
137 | # -- Options for HTML output ---------------------------------------------- | ||
138 | |||
139 | # The theme to use for HTML and HTML Help pages. See the documentation for | ||
140 | @@ -XXX,XX +XXX,XX @@ latex_documents = [ | ||
141 | |||
142 | |||
143 | # -- Options for manual page output --------------------------------------- | ||
144 | - | ||
145 | -# One entry per manual page. List of tuples | ||
146 | -# (source start file, name, description, authors, manual section). | ||
147 | -man_pages = [ | ||
148 | - (master_doc, 'qemu', u'QEMU Documentation', | ||
149 | - [author], 1) | ||
150 | -] | ||
151 | - | ||
152 | +# Individual manual/conf.py can override this to create man pages | ||
153 | +man_pages = [] | ||
154 | |||
155 | # -- Options for Texinfo output ------------------------------------------- | ||
156 | |||
157 | diff --git a/docs/interop/conf.py b/docs/interop/conf.py | ||
158 | index XXXXXXX..XXXXXXX 100644 | 55 | index XXXXXXX..XXXXXXX 100644 |
159 | --- a/docs/interop/conf.py | 56 | --- a/include/hw/arm/fsl-imx8mp.h |
160 | +++ b/docs/interop/conf.py | 57 | +++ b/include/hw/arm/fsl-imx8mp.h |
161 | @@ -XXX,XX +XXX,XX @@ exec(compile(open(parent_config, "rb").read(), parent_config, 'exec')) | 58 | @@ -XXX,XX +XXX,XX @@ |
162 | # This slightly misuses the 'description', but is the best way to get | 59 | #include "cpu.h" |
163 | # the manual title to appear in the sidebar. | 60 | #include "hw/char/imx_serial.h" |
164 | html_theme_options['description'] = u'System Emulation Management and Interoperability Guide' | 61 | #include "hw/intc/arm_gicv3_common.h" |
165 | + | 62 | +#include "hw/misc/imx8mp_analog.h" |
166 | +# One entry per manual page. List of tuples | 63 | +#include "hw/misc/imx8mp_ccm.h" |
167 | +# (source start file, name, description, authors, manual section). | 64 | #include "qom/object.h" |
168 | +man_pages = [ | 65 | #include "qemu/units.h" |
169 | + ('qemu-ga', 'qemu-ga', u'QEMU Guest Agent', | 66 | |
170 | + ['Michael Roth <mdroth@linux.vnet.ibm.com>'], 8) | 67 | @@ -XXX,XX +XXX,XX @@ struct FslImx8mpState { |
171 | +] | 68 | |
172 | diff --git a/docs/interop/index.rst b/docs/interop/index.rst | 69 | ARMCPU cpu[FSL_IMX8MP_NUM_CPUS]; |
173 | index XXXXXXX..XXXXXXX 100644 | 70 | GICv3State gic; |
174 | --- a/docs/interop/index.rst | 71 | + IMX8MPCCMState ccm; |
175 | +++ b/docs/interop/index.rst | 72 | + IMX8MPAnalogState analog; |
176 | @@ -XXX,XX +XXX,XX @@ Contents: | 73 | IMXSerialState uart[FSL_IMX8MP_NUM_UARTS]; |
177 | bitmaps | 74 | }; |
178 | live-block-operations | 75 | |
179 | pr-helper | 76 | diff --git a/include/hw/misc/imx8mp_analog.h b/include/hw/misc/imx8mp_analog.h |
180 | + qemu-ga | ||
181 | vhost-user | ||
182 | vhost-user-gpu | ||
183 | diff --git a/docs/interop/qemu-ga.rst b/docs/interop/qemu-ga.rst | ||
184 | new file mode 100644 | 77 | new file mode 100644 |
185 | index XXXXXXX..XXXXXXX | 78 | index XXXXXXX..XXXXXXX |
186 | --- /dev/null | 79 | --- /dev/null |
187 | +++ b/docs/interop/qemu-ga.rst | 80 | +++ b/include/hw/misc/imx8mp_analog.h |
188 | @@ -XXX,XX +XXX,XX @@ | 81 | @@ -XXX,XX +XXX,XX @@ |
189 | +QEMU Guest Agent | 82 | +/* |
190 | +================ | 83 | + * Copyright (c) 2025 Bernhard Beschow <shentey@gmail.com> |
191 | + | 84 | + * |
192 | +Synopsis | 85 | + * i.MX8MP ANALOG IP block emulation code |
193 | +-------- | 86 | + * |
194 | + | 87 | + * SPDX-License-Identifier: GPL-2.0-or-later |
195 | +**qemu-ga** [*OPTIONS*] | 88 | + */ |
196 | + | 89 | + |
197 | +Description | 90 | +#ifndef IMX8MP_ANALOG_H |
198 | +----------- | 91 | +#define IMX8MP_ANALOG_H |
199 | + | 92 | + |
200 | +The QEMU Guest Agent is a daemon intended to be run within virtual | 93 | +#include "qom/object.h" |
201 | +machines. It allows the hypervisor host to perform various operations | 94 | +#include "hw/sysbus.h" |
202 | +in the guest, such as: | 95 | + |
203 | + | 96 | +enum IMX8MPAnalogRegisters { |
204 | +- get information from the guest | 97 | + ANALOG_AUDIO_PLL1_GEN_CTRL = 0x000 / 4, |
205 | +- set the guest's system time | 98 | + ANALOG_AUDIO_PLL1_FDIV_CTL0 = 0x004 / 4, |
206 | +- read/write a file | 99 | + ANALOG_AUDIO_PLL1_FDIV_CTL1 = 0x008 / 4, |
207 | +- sync and freeze the filesystems | 100 | + ANALOG_AUDIO_PLL1_SSCG_CTRL = 0x00c / 4, |
208 | +- suspend the guest | 101 | + ANALOG_AUDIO_PLL1_MNIT_CTRL = 0x010 / 4, |
209 | +- reconfigure guest local processors | 102 | + ANALOG_AUDIO_PLL2_GEN_CTRL = 0x014 / 4, |
210 | +- set user's password | 103 | + ANALOG_AUDIO_PLL2_FDIV_CTL0 = 0x018 / 4, |
211 | +- ... | 104 | + ANALOG_AUDIO_PLL2_FDIV_CTL1 = 0x01c / 4, |
212 | + | 105 | + ANALOG_AUDIO_PLL2_SSCG_CTRL = 0x020 / 4, |
213 | +qemu-ga will read a system configuration file on startup (located at | 106 | + ANALOG_AUDIO_PLL2_MNIT_CTRL = 0x024 / 4, |
214 | +|CONFDIR|\ ``/qemu-ga.conf`` by default), then parse remaining | 107 | + ANALOG_VIDEO_PLL1_GEN_CTRL = 0x028 / 4, |
215 | +configuration options on the command line. For the same key, the last | 108 | + ANALOG_VIDEO_PLL1_FDIV_CTL0 = 0x02c / 4, |
216 | +option wins, but the lists accumulate (see below for configuration | 109 | + ANALOG_VIDEO_PLL1_FDIV_CTL1 = 0x030 / 4, |
217 | +file format). | 110 | + ANALOG_VIDEO_PLL1_SSCG_CTRL = 0x034 / 4, |
218 | + | 111 | + ANALOG_VIDEO_PLL1_MNIT_CTRL = 0x038 / 4, |
219 | +Options | 112 | + ANALOG_DRAM_PLL_GEN_CTRL = 0x050 / 4, |
220 | +------- | 113 | + ANALOG_DRAM_PLL_FDIV_CTL0 = 0x054 / 4, |
221 | + | 114 | + ANALOG_DRAM_PLL_FDIV_CTL1 = 0x058 / 4, |
222 | +.. program:: qemu-ga | 115 | + ANALOG_DRAM_PLL_SSCG_CTRL = 0x05c / 4, |
223 | + | 116 | + ANALOG_DRAM_PLL_MNIT_CTRL = 0x060 / 4, |
224 | +.. option:: -m, --method=METHOD | 117 | + ANALOG_GPU_PLL_GEN_CTRL = 0x064 / 4, |
225 | + | 118 | + ANALOG_GPU_PLL_FDIV_CTL0 = 0x068 / 4, |
226 | + Transport method: one of ``unix-listen``, ``virtio-serial``, or | 119 | + ANALOG_GPU_PLL_LOCKD_CTRL = 0x06c / 4, |
227 | + ``isa-serial`` (``virtio-serial`` is the default). | 120 | + ANALOG_GPU_PLL_MNIT_CTRL = 0x070 / 4, |
228 | + | 121 | + ANALOG_VPU_PLL_GEN_CTRL = 0x074 / 4, |
229 | +.. option:: -p, --path=PATH | 122 | + ANALOG_VPU_PLL_FDIV_CTL0 = 0x078 / 4, |
230 | + | 123 | + ANALOG_VPU_PLL_LOCKD_CTRL = 0x07c / 4, |
231 | + Device/socket path (the default for virtio-serial is | 124 | + ANALOG_VPU_PLL_MNIT_CTRL = 0x080 / 4, |
232 | + ``/dev/virtio-ports/org.qemu.guest_agent.0``, | 125 | + ANALOG_ARM_PLL_GEN_CTRL = 0x084 / 4, |
233 | + the default for isa-serial is ``/dev/ttyS0``) | 126 | + ANALOG_ARM_PLL_FDIV_CTL0 = 0x088 / 4, |
234 | + | 127 | + ANALOG_ARM_PLL_LOCKD_CTRL = 0x08c / 4, |
235 | +.. option:: -l, --logfile=PATH | 128 | + ANALOG_ARM_PLL_MNIT_CTRL = 0x090 / 4, |
236 | + | 129 | + ANALOG_SYS_PLL1_GEN_CTRL = 0x094 / 4, |
237 | + Set log file path (default is stderr). | 130 | + ANALOG_SYS_PLL1_FDIV_CTL0 = 0x098 / 4, |
238 | + | 131 | + ANALOG_SYS_PLL1_LOCKD_CTRL = 0x09c / 4, |
239 | +.. option:: -f, --pidfile=PATH | 132 | + ANALOG_SYS_PLL1_MNIT_CTRL = 0x100 / 4, |
240 | + | 133 | + ANALOG_SYS_PLL2_GEN_CTRL = 0x104 / 4, |
241 | + Specify pid file (default is ``/var/run/qemu-ga.pid``). | 134 | + ANALOG_SYS_PLL2_FDIV_CTL0 = 0x108 / 4, |
242 | + | 135 | + ANALOG_SYS_PLL2_LOCKD_CTRL = 0x10c / 4, |
243 | +.. option:: -F, --fsfreeze-hook=PATH | 136 | + ANALOG_SYS_PLL2_MNIT_CTRL = 0x110 / 4, |
244 | + | 137 | + ANALOG_SYS_PLL3_GEN_CTRL = 0x114 / 4, |
245 | + Enable fsfreeze hook. Accepts an optional argument that specifies | 138 | + ANALOG_SYS_PLL3_FDIV_CTL0 = 0x118 / 4, |
246 | + script to run on freeze/thaw. Script will be called with | 139 | + ANALOG_SYS_PLL3_LOCKD_CTRL = 0x11c / 4, |
247 | + 'freeze'/'thaw' arguments accordingly (default is | 140 | + ANALOG_SYS_PLL3_MNIT_CTRL = 0x120 / 4, |
248 | + |CONFDIR|\ ``/fsfreeze-hook``). If using -F with an argument, do | 141 | + ANALOG_OSC_MISC_CFG = 0x124 / 4, |
249 | + not follow -F with a space (for example: | 142 | + ANALOG_ANAMIX_PLL_MNIT_CTL = 0x128 / 4, |
250 | + ``-F/var/run/fsfreezehook.sh``). | 143 | + |
251 | + | 144 | + ANALOG_DIGPROG = 0x800 / 4, |
252 | +.. option:: -t, --statedir=PATH | 145 | + ANALOG_MAX, |
253 | + | 146 | +}; |
254 | + Specify the directory to store state information (absolute paths only, | 147 | + |
255 | + default is ``/var/run``). | 148 | +#define TYPE_IMX8MP_ANALOG "imx8mp.analog" |
256 | + | 149 | +OBJECT_DECLARE_SIMPLE_TYPE(IMX8MPAnalogState, IMX8MP_ANALOG) |
257 | +.. option:: -v, --verbose | 150 | + |
258 | + | 151 | +struct IMX8MPAnalogState { |
259 | + Log extra debugging information. | 152 | + SysBusDevice parent_obj; |
260 | + | 153 | + |
261 | +.. option:: -V, --version | 154 | + struct { |
262 | + | 155 | + MemoryRegion container; |
263 | + Print version information and exit. | 156 | + MemoryRegion analog; |
264 | + | 157 | + } mmio; |
265 | +.. option:: -d, --daemon | 158 | + |
266 | + | 159 | + uint32_t analog[ANALOG_MAX]; |
267 | + Daemonize after startup (detach from terminal). | 160 | +}; |
268 | + | 161 | + |
269 | +.. option:: -b, --blacklist=LIST | 162 | +#endif /* IMX8MP_ANALOG_H */ |
270 | + | 163 | diff --git a/include/hw/misc/imx8mp_ccm.h b/include/hw/misc/imx8mp_ccm.h |
271 | + Comma-separated list of RPCs to disable (no spaces, ``?`` to list | 164 | new file mode 100644 |
272 | + available RPCs). | 165 | index XXXXXXX..XXXXXXX |
273 | + | 166 | --- /dev/null |
274 | +.. option:: -D, --dump-conf | 167 | +++ b/include/hw/misc/imx8mp_ccm.h |
275 | + | 168 | @@ -XXX,XX +XXX,XX @@ |
276 | + Dump the configuration in a format compatible with ``qemu-ga.conf`` | 169 | +/* |
277 | + and exit. | 170 | + * Copyright (c) 2025 Bernhard Beschow <shentey@gmail.com> |
278 | + | 171 | + * |
279 | +.. option:: -h, --help | 172 | + * i.MX 8M Plus CCM IP block emulation code |
280 | + | 173 | + * |
281 | + Display this help and exit. | 174 | + * SPDX-License-Identifier: GPL-2.0-or-later |
282 | + | 175 | + */ |
283 | +Files | 176 | + |
284 | +----- | 177 | +#ifndef IMX8MP_CCM_H |
285 | + | 178 | +#define IMX8MP_CCM_H |
286 | + | 179 | + |
287 | +The syntax of the ``qemu-ga.conf`` configuration file follows the | 180 | +#include "hw/misc/imx_ccm.h" |
288 | +Desktop Entry Specification, here is a quick summary: it consists of | 181 | +#include "qom/object.h" |
289 | +groups of key-value pairs, interspersed with comments. | 182 | + |
290 | + | 183 | +enum IMX8MPCCMRegisters { |
291 | +:: | 184 | + CCM_MAX = 0xc6fc / sizeof(uint32_t) + 1, |
292 | + | 185 | +}; |
293 | + # qemu-ga configuration sample | 186 | + |
294 | + [general] | 187 | +#define TYPE_IMX8MP_CCM "imx8mp.ccm" |
295 | + daemonize = 0 | 188 | +OBJECT_DECLARE_SIMPLE_TYPE(IMX8MPCCMState, IMX8MP_CCM) |
296 | + pidfile = /var/run/qemu-ga.pid | 189 | + |
297 | + verbose = 0 | 190 | +struct IMX8MPCCMState { |
298 | + method = virtio-serial | 191 | + IMXCCMState parent_obj; |
299 | + path = /dev/virtio-ports/org.qemu.guest_agent.0 | 192 | + |
300 | + statedir = /var/run | 193 | + MemoryRegion iomem; |
301 | + | 194 | + |
302 | +The list of keys follows the command line options: | 195 | + uint32_t ccm[CCM_MAX]; |
303 | + | 196 | +}; |
304 | +============= =========== | 197 | + |
305 | +Key Key type | 198 | +#endif /* IMX8MP_CCM_H */ |
306 | +============= =========== | 199 | diff --git a/hw/arm/fsl-imx8mp.c b/hw/arm/fsl-imx8mp.c |
307 | +daemon boolean | ||
308 | +method string | ||
309 | +path string | ||
310 | +logfile string | ||
311 | +pidfile string | ||
312 | +fsfreeze-hook string | ||
313 | +statedir string | ||
314 | +verbose boolean | ||
315 | +blacklist string list | ||
316 | +============= =========== | ||
317 | + | ||
318 | +See also | ||
319 | +-------- | ||
320 | + | ||
321 | +:manpage:`qemu(1)` | ||
322 | diff --git a/qemu-doc.texi b/qemu-doc.texi | ||
323 | index XXXXXXX..XXXXXXX 100644 | 200 | index XXXXXXX..XXXXXXX 100644 |
324 | --- a/qemu-doc.texi | 201 | --- a/hw/arm/fsl-imx8mp.c |
325 | +++ b/qemu-doc.texi | 202 | +++ b/hw/arm/fsl-imx8mp.c |
326 | @@ -XXX,XX +XXX,XX @@ so should only be used with trusted guest OS. | 203 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx8mp_init(Object *obj) |
327 | 204 | ||
328 | @c man end | 205 | object_initialize_child(obj, "gic", &s->gic, TYPE_ARM_GICV3); |
329 | 206 | ||
330 | -@node QEMU Guest Agent | 207 | + object_initialize_child(obj, "ccm", &s->ccm, TYPE_IMX8MP_CCM); |
331 | -@chapter QEMU Guest Agent invocation | 208 | + |
332 | - | 209 | + object_initialize_child(obj, "analog", &s->analog, TYPE_IMX8MP_ANALOG); |
333 | -@include qemu-ga.texi | 210 | + |
334 | - | 211 | for (i = 0; i < FSL_IMX8MP_NUM_UARTS; i++) { |
335 | @node QEMU User space emulator | 212 | g_autofree char *name = g_strdup_printf("uart%d", i + 1); |
336 | @chapter QEMU User space emulator | 213 | object_initialize_child(obj, name, &s->uart[i], TYPE_IMX_SERIAL); |
337 | 214 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp) | |
338 | diff --git a/qemu-ga.texi b/qemu-ga.texi | 215 | } |
339 | deleted file mode 100644 | 216 | } |
217 | |||
218 | + /* CCM */ | ||
219 | + if (!sysbus_realize(SYS_BUS_DEVICE(&s->ccm), errp)) { | ||
220 | + return; | ||
221 | + } | ||
222 | + sysbus_mmio_map(SYS_BUS_DEVICE(&s->ccm), 0, | ||
223 | + fsl_imx8mp_memmap[FSL_IMX8MP_CCM].addr); | ||
224 | + | ||
225 | + /* Analog */ | ||
226 | + if (!sysbus_realize(SYS_BUS_DEVICE(&s->analog), errp)) { | ||
227 | + return; | ||
228 | + } | ||
229 | + sysbus_mmio_map(SYS_BUS_DEVICE(&s->analog), 0, | ||
230 | + fsl_imx8mp_memmap[FSL_IMX8MP_ANA_PLL].addr); | ||
231 | + | ||
232 | /* UARTs */ | ||
233 | for (i = 0; i < FSL_IMX8MP_NUM_UARTS; i++) { | ||
234 | struct { | ||
235 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp) | ||
236 | /* Unimplemented devices */ | ||
237 | for (i = 0; i < ARRAY_SIZE(fsl_imx8mp_memmap); i++) { | ||
238 | switch (i) { | ||
239 | + case FSL_IMX8MP_ANA_PLL: | ||
240 | + case FSL_IMX8MP_CCM: | ||
241 | case FSL_IMX8MP_GIC_DIST: | ||
242 | case FSL_IMX8MP_GIC_REDIST: | ||
243 | case FSL_IMX8MP_RAM: | ||
244 | diff --git a/hw/misc/imx8mp_analog.c b/hw/misc/imx8mp_analog.c | ||
245 | new file mode 100644 | ||
340 | index XXXXXXX..XXXXXXX | 246 | index XXXXXXX..XXXXXXX |
341 | --- a/qemu-ga.texi | 247 | --- /dev/null |
342 | +++ /dev/null | 248 | +++ b/hw/misc/imx8mp_analog.c |
343 | @@ -XXX,XX +XXX,XX @@ | 249 | @@ -XXX,XX +XXX,XX @@ |
344 | -@example | 250 | +/* |
345 | -@c man begin SYNOPSIS | 251 | + * Copyright (c) 2025 Bernhard Beschow <shentey@gmail.com> |
346 | -@command{qemu-ga} [@var{OPTIONS}] | 252 | + * |
347 | -@c man end | 253 | + * i.MX 8M Plus ANALOG IP block emulation code |
348 | -@end example | 254 | + * |
349 | - | 255 | + * Based on hw/misc/imx7_ccm.c |
350 | -@c man begin DESCRIPTION | 256 | + * |
351 | - | 257 | + * SPDX-License-Identifier: GPL-2.0-or-later |
352 | -The QEMU Guest Agent is a daemon intended to be run within virtual | 258 | + */ |
353 | -machines. It allows the hypervisor host to perform various operations | 259 | + |
354 | -in the guest, such as: | 260 | +#include "qemu/osdep.h" |
355 | - | 261 | +#include "qemu/log.h" |
356 | -@itemize | 262 | + |
357 | -@item | 263 | +#include "hw/misc/imx8mp_analog.h" |
358 | -get information from the guest | 264 | +#include "migration/vmstate.h" |
359 | -@item | 265 | + |
360 | -set the guest's system time | 266 | +#define ANALOG_PLL_LOCK BIT(31) |
361 | -@item | 267 | + |
362 | -read/write a file | 268 | +static void imx8mp_analog_reset(DeviceState *dev) |
363 | -@item | 269 | +{ |
364 | -sync and freeze the filesystems | 270 | + IMX8MPAnalogState *s = IMX8MP_ANALOG(dev); |
365 | -@item | 271 | + |
366 | -suspend the guest | 272 | + memset(s->analog, 0, sizeof(s->analog)); |
367 | -@item | 273 | + |
368 | -reconfigure guest local processors | 274 | + s->analog[ANALOG_AUDIO_PLL1_GEN_CTRL] = 0x00002010; |
369 | -@item | 275 | + s->analog[ANALOG_AUDIO_PLL1_FDIV_CTL0] = 0x00145032; |
370 | -set user's password | 276 | + s->analog[ANALOG_AUDIO_PLL1_FDIV_CTL1] = 0x00000000; |
371 | -@item | 277 | + s->analog[ANALOG_AUDIO_PLL1_SSCG_CTRL] = 0x00000000; |
372 | -... | 278 | + s->analog[ANALOG_AUDIO_PLL1_MNIT_CTRL] = 0x00100103; |
373 | -@end itemize | 279 | + s->analog[ANALOG_AUDIO_PLL2_GEN_CTRL] = 0x00002010; |
374 | - | 280 | + s->analog[ANALOG_AUDIO_PLL2_FDIV_CTL0] = 0x00145032; |
375 | -qemu-ga will read a system configuration file on startup (located at | 281 | + s->analog[ANALOG_AUDIO_PLL2_FDIV_CTL1] = 0x00000000; |
376 | -@file{@value{CONFDIR}/qemu-ga.conf} by default), then parse remaining | 282 | + s->analog[ANALOG_AUDIO_PLL2_SSCG_CTRL] = 0x00000000; |
377 | -configuration options on the command line. For the same key, the last | 283 | + s->analog[ANALOG_AUDIO_PLL2_MNIT_CTRL] = 0x00100103; |
378 | -option wins, but the lists accumulate (see below for configuration | 284 | + s->analog[ANALOG_VIDEO_PLL1_GEN_CTRL] = 0x00002010; |
379 | -file format). | 285 | + s->analog[ANALOG_VIDEO_PLL1_FDIV_CTL0] = 0x00145032; |
380 | - | 286 | + s->analog[ANALOG_VIDEO_PLL1_FDIV_CTL1] = 0x00000000; |
381 | -@c man end | 287 | + s->analog[ANALOG_VIDEO_PLL1_SSCG_CTRL] = 0x00000000; |
382 | - | 288 | + s->analog[ANALOG_VIDEO_PLL1_MNIT_CTRL] = 0x00100103; |
383 | -@c man begin OPTIONS | 289 | + s->analog[ANALOG_DRAM_PLL_GEN_CTRL] = 0x00002010; |
384 | -@table @option | 290 | + s->analog[ANALOG_DRAM_PLL_FDIV_CTL0] = 0x0012c032; |
385 | -@item -m, --method=@var{method} | 291 | + s->analog[ANALOG_DRAM_PLL_FDIV_CTL1] = 0x00000000; |
386 | - Transport method: one of @samp{unix-listen}, @samp{virtio-serial}, or | 292 | + s->analog[ANALOG_DRAM_PLL_SSCG_CTRL] = 0x00000000; |
387 | - @samp{isa-serial} (@samp{virtio-serial} is the default). | 293 | + s->analog[ANALOG_DRAM_PLL_MNIT_CTRL] = 0x00100103; |
388 | - | 294 | + s->analog[ANALOG_GPU_PLL_GEN_CTRL] = 0x00000810; |
389 | -@item -p, --path=@var{path} | 295 | + s->analog[ANALOG_GPU_PLL_FDIV_CTL0] = 0x000c8031; |
390 | - Device/socket path (the default for virtio-serial is | 296 | + s->analog[ANALOG_GPU_PLL_LOCKD_CTRL] = 0x0010003f; |
391 | - @samp{/dev/virtio-ports/org.qemu.guest_agent.0}, | 297 | + s->analog[ANALOG_GPU_PLL_MNIT_CTRL] = 0x00280081; |
392 | - the default for isa-serial is @samp{/dev/ttyS0}) | 298 | + s->analog[ANALOG_VPU_PLL_GEN_CTRL] = 0x00000810; |
393 | - | 299 | + s->analog[ANALOG_VPU_PLL_FDIV_CTL0] = 0x0012c032; |
394 | -@item -l, --logfile=@var{path} | 300 | + s->analog[ANALOG_VPU_PLL_LOCKD_CTRL] = 0x0010003f; |
395 | - Set log file path (default is stderr). | 301 | + s->analog[ANALOG_VPU_PLL_MNIT_CTRL] = 0x00280081; |
396 | - | 302 | + s->analog[ANALOG_ARM_PLL_GEN_CTRL] = 0x00000810; |
397 | -@item -f, --pidfile=@var{path} | 303 | + s->analog[ANALOG_ARM_PLL_FDIV_CTL0] = 0x000fa031; |
398 | - Specify pid file (default is @samp{/var/run/qemu-ga.pid}). | 304 | + s->analog[ANALOG_ARM_PLL_LOCKD_CTRL] = 0x0010003f; |
399 | - | 305 | + s->analog[ANALOG_ARM_PLL_MNIT_CTRL] = 0x00280081; |
400 | -@item -F, --fsfreeze-hook=@var{path} | 306 | + s->analog[ANALOG_SYS_PLL1_GEN_CTRL] = 0x0aaaa810; |
401 | - Enable fsfreeze hook. Accepts an optional argument that specifies | 307 | + s->analog[ANALOG_SYS_PLL1_FDIV_CTL0] = 0x00190032; |
402 | - script to run on freeze/thaw. Script will be called with | 308 | + s->analog[ANALOG_SYS_PLL1_LOCKD_CTRL] = 0x0010003f; |
403 | - 'freeze'/'thaw' arguments accordingly (default is | 309 | + s->analog[ANALOG_SYS_PLL1_MNIT_CTRL] = 0x00280081; |
404 | - @samp{@value{CONFDIR}/fsfreeze-hook}). If using -F with an argument, do | 310 | + s->analog[ANALOG_SYS_PLL2_GEN_CTRL] = 0x0aaaa810; |
405 | - not follow -F with a space (for example: | 311 | + s->analog[ANALOG_SYS_PLL2_FDIV_CTL0] = 0x000fa031; |
406 | - @samp{-F/var/run/fsfreezehook.sh}). | 312 | + s->analog[ANALOG_SYS_PLL2_LOCKD_CTRL] = 0x0010003f; |
407 | - | 313 | + s->analog[ANALOG_SYS_PLL2_MNIT_CTRL] = 0x00280081; |
408 | -@item -t, --statedir=@var{path} | 314 | + s->analog[ANALOG_SYS_PLL3_GEN_CTRL] = 0x00000810; |
409 | - Specify the directory to store state information (absolute paths only, | 315 | + s->analog[ANALOG_SYS_PLL3_FDIV_CTL0] = 0x000fa031; |
410 | - default is @samp{/var/run}). | 316 | + s->analog[ANALOG_SYS_PLL3_LOCKD_CTRL] = 0x0010003f; |
411 | - | 317 | + s->analog[ANALOG_SYS_PLL3_MNIT_CTRL] = 0x00280081; |
412 | -@item -v, --verbose | 318 | + s->analog[ANALOG_OSC_MISC_CFG] = 0x00000000; |
413 | - Log extra debugging information. | 319 | + s->analog[ANALOG_ANAMIX_PLL_MNIT_CTL] = 0x00000000; |
414 | - | 320 | + s->analog[ANALOG_DIGPROG] = 0x00824010; |
415 | -@item -V, --version | 321 | + |
416 | - Print version information and exit. | 322 | + /* all PLLs need to be locked */ |
417 | - | 323 | + s->analog[ANALOG_AUDIO_PLL1_GEN_CTRL] |= ANALOG_PLL_LOCK; |
418 | -@item -d, --daemon | 324 | + s->analog[ANALOG_AUDIO_PLL2_GEN_CTRL] |= ANALOG_PLL_LOCK; |
419 | - Daemonize after startup (detach from terminal). | 325 | + s->analog[ANALOG_VIDEO_PLL1_GEN_CTRL] |= ANALOG_PLL_LOCK; |
420 | - | 326 | + s->analog[ANALOG_DRAM_PLL_GEN_CTRL] |= ANALOG_PLL_LOCK; |
421 | -@item -b, --blacklist=@var{list} | 327 | + s->analog[ANALOG_GPU_PLL_GEN_CTRL] |= ANALOG_PLL_LOCK; |
422 | - Comma-separated list of RPCs to disable (no spaces, @samp{?} to list | 328 | + s->analog[ANALOG_VPU_PLL_GEN_CTRL] |= ANALOG_PLL_LOCK; |
423 | - available RPCs). | 329 | + s->analog[ANALOG_ARM_PLL_GEN_CTRL] |= ANALOG_PLL_LOCK; |
424 | - | 330 | + s->analog[ANALOG_SYS_PLL1_GEN_CTRL] |= ANALOG_PLL_LOCK; |
425 | -@item -D, --dump-conf | 331 | + s->analog[ANALOG_SYS_PLL2_GEN_CTRL] |= ANALOG_PLL_LOCK; |
426 | - Dump the configuration in a format compatible with @file{qemu-ga.conf} | 332 | + s->analog[ANALOG_SYS_PLL3_GEN_CTRL] |= ANALOG_PLL_LOCK; |
427 | - and exit. | 333 | +} |
428 | - | 334 | + |
429 | -@item -h, --help | 335 | +static uint64_t imx8mp_analog_read(void *opaque, hwaddr offset, unsigned size) |
430 | - Display this help and exit. | 336 | +{ |
431 | -@end table | 337 | + IMX8MPAnalogState *s = opaque; |
432 | - | 338 | + |
433 | -@c man end | 339 | + return s->analog[offset >> 2]; |
434 | - | 340 | +} |
435 | -@c man begin FILES | 341 | + |
436 | - | 342 | +static void imx8mp_analog_write(void *opaque, hwaddr offset, |
437 | -The syntax of the @file{qemu-ga.conf} configuration file follows the | 343 | + uint64_t value, unsigned size) |
438 | -Desktop Entry Specification, here is a quick summary: it consists of | 344 | +{ |
439 | -groups of key-value pairs, interspersed with comments. | 345 | + IMX8MPAnalogState *s = opaque; |
440 | - | 346 | + |
441 | -@example | 347 | + if (offset >> 2 == ANALOG_DIGPROG) { |
442 | -# qemu-ga configuration sample | 348 | + qemu_log_mask(LOG_GUEST_ERROR, |
443 | -[general] | 349 | + "Guest write to read-only ANALOG_DIGPROG register\n"); |
444 | -daemonize = 0 | 350 | + } else { |
445 | -pidfile = /var/run/qemu-ga.pid | 351 | + s->analog[offset >> 2] = value; |
446 | -verbose = 0 | 352 | + } |
447 | -method = virtio-serial | 353 | +} |
448 | -path = /dev/virtio-ports/org.qemu.guest_agent.0 | 354 | + |
449 | -statedir = /var/run | 355 | +static const struct MemoryRegionOps imx8mp_analog_ops = { |
450 | -@end example | 356 | + .read = imx8mp_analog_read, |
451 | - | 357 | + .write = imx8mp_analog_write, |
452 | -The list of keys follows the command line options: | 358 | + .endianness = DEVICE_NATIVE_ENDIAN, |
453 | -@table @option | 359 | + .impl = { |
454 | -@item daemon= boolean | 360 | + .min_access_size = 4, |
455 | -@item method= string | 361 | + .max_access_size = 4, |
456 | -@item path= string | 362 | + .unaligned = false, |
457 | -@item logfile= string | 363 | + }, |
458 | -@item pidfile= string | 364 | +}; |
459 | -@item fsfreeze-hook= string | 365 | + |
460 | -@item statedir= string | 366 | +static void imx8mp_analog_init(Object *obj) |
461 | -@item verbose= boolean | 367 | +{ |
462 | -@item blacklist= string list | 368 | + IMX8MPAnalogState *s = IMX8MP_ANALOG(obj); |
463 | -@end table | 369 | + SysBusDevice *sd = SYS_BUS_DEVICE(obj); |
464 | - | 370 | + |
465 | -@c man end | 371 | + memory_region_init(&s->mmio.container, obj, TYPE_IMX8MP_ANALOG, 0x10000); |
466 | - | 372 | + |
467 | -@ignore | 373 | + memory_region_init_io(&s->mmio.analog, obj, &imx8mp_analog_ops, s, |
468 | - | 374 | + TYPE_IMX8MP_ANALOG, sizeof(s->analog)); |
469 | -@setfilename qemu-ga | 375 | + memory_region_add_subregion(&s->mmio.container, 0, &s->mmio.analog); |
470 | -@settitle QEMU Guest Agent | 376 | + |
471 | - | 377 | + sysbus_init_mmio(sd, &s->mmio.container); |
472 | -@c man begin AUTHOR | 378 | +} |
473 | -Michael Roth <mdroth@linux.vnet.ibm.com> | 379 | + |
474 | -@c man end | 380 | +static const VMStateDescription imx8mp_analog_vmstate = { |
475 | - | 381 | + .name = TYPE_IMX8MP_ANALOG, |
476 | -@c man begin SEEALSO | 382 | + .version_id = 1, |
477 | -qemu(1) | 383 | + .minimum_version_id = 1, |
478 | -@c man end | 384 | + .fields = (const VMStateField[]) { |
479 | - | 385 | + VMSTATE_UINT32_ARRAY(analog, IMX8MPAnalogState, ANALOG_MAX), |
480 | -@end ignore | 386 | + VMSTATE_END_OF_LIST() |
387 | + }, | ||
388 | +}; | ||
389 | + | ||
390 | +static void imx8mp_analog_class_init(ObjectClass *klass, void *data) | ||
391 | +{ | ||
392 | + DeviceClass *dc = DEVICE_CLASS(klass); | ||
393 | + | ||
394 | + device_class_set_legacy_reset(dc, imx8mp_analog_reset); | ||
395 | + dc->vmsd = &imx8mp_analog_vmstate; | ||
396 | + dc->desc = "i.MX 8M Plus Analog Module"; | ||
397 | +} | ||
398 | + | ||
399 | +static const TypeInfo imx8mp_analog_types[] = { | ||
400 | + { | ||
401 | + .name = TYPE_IMX8MP_ANALOG, | ||
402 | + .parent = TYPE_SYS_BUS_DEVICE, | ||
403 | + .instance_size = sizeof(IMX8MPAnalogState), | ||
404 | + .instance_init = imx8mp_analog_init, | ||
405 | + .class_init = imx8mp_analog_class_init, | ||
406 | + } | ||
407 | +}; | ||
408 | + | ||
409 | +DEFINE_TYPES(imx8mp_analog_types); | ||
410 | diff --git a/hw/misc/imx8mp_ccm.c b/hw/misc/imx8mp_ccm.c | ||
411 | new file mode 100644 | ||
412 | index XXXXXXX..XXXXXXX | ||
413 | --- /dev/null | ||
414 | +++ b/hw/misc/imx8mp_ccm.c | ||
415 | @@ -XXX,XX +XXX,XX @@ | ||
416 | +/* | ||
417 | + * Copyright (c) 2025 Bernhard Beschow <shentey@gmail.com> | ||
418 | + * | ||
419 | + * i.MX 8M Plus CCM IP block emulation code | ||
420 | + * | ||
421 | + * Based on hw/misc/imx7_ccm.c | ||
422 | + * | ||
423 | + * SPDX-License-Identifier: GPL-2.0-or-later | ||
424 | + */ | ||
425 | + | ||
426 | +#include "qemu/osdep.h" | ||
427 | +#include "qemu/log.h" | ||
428 | + | ||
429 | +#include "hw/misc/imx8mp_ccm.h" | ||
430 | +#include "migration/vmstate.h" | ||
431 | + | ||
432 | +#include "trace.h" | ||
433 | + | ||
434 | +#define CKIH_FREQ 16000000 /* 16MHz crystal input */ | ||
435 | + | ||
436 | +static void imx8mp_ccm_reset(DeviceState *dev) | ||
437 | +{ | ||
438 | + IMX8MPCCMState *s = IMX8MP_CCM(dev); | ||
439 | + | ||
440 | + memset(s->ccm, 0, sizeof(s->ccm)); | ||
441 | +} | ||
442 | + | ||
443 | +#define CCM_INDEX(offset) (((offset) & ~(hwaddr)0xF) / sizeof(uint32_t)) | ||
444 | +#define CCM_BITOP(offset) ((offset) & (hwaddr)0xF) | ||
445 | + | ||
446 | +enum { | ||
447 | + CCM_BITOP_NONE = 0x00, | ||
448 | + CCM_BITOP_SET = 0x04, | ||
449 | + CCM_BITOP_CLR = 0x08, | ||
450 | + CCM_BITOP_TOG = 0x0C, | ||
451 | +}; | ||
452 | + | ||
453 | +static uint64_t imx8mp_set_clr_tog_read(void *opaque, hwaddr offset, | ||
454 | + unsigned size) | ||
455 | +{ | ||
456 | + const uint32_t *mmio = opaque; | ||
457 | + | ||
458 | + return mmio[CCM_INDEX(offset)]; | ||
459 | +} | ||
460 | + | ||
461 | +static void imx8mp_set_clr_tog_write(void *opaque, hwaddr offset, | ||
462 | + uint64_t value, unsigned size) | ||
463 | +{ | ||
464 | + const uint8_t bitop = CCM_BITOP(offset); | ||
465 | + const uint32_t index = CCM_INDEX(offset); | ||
466 | + uint32_t *mmio = opaque; | ||
467 | + | ||
468 | + switch (bitop) { | ||
469 | + case CCM_BITOP_NONE: | ||
470 | + mmio[index] = value; | ||
471 | + break; | ||
472 | + case CCM_BITOP_SET: | ||
473 | + mmio[index] |= value; | ||
474 | + break; | ||
475 | + case CCM_BITOP_CLR: | ||
476 | + mmio[index] &= ~value; | ||
477 | + break; | ||
478 | + case CCM_BITOP_TOG: | ||
479 | + mmio[index] ^= value; | ||
480 | + break; | ||
481 | + }; | ||
482 | +} | ||
483 | + | ||
484 | +static const struct MemoryRegionOps imx8mp_set_clr_tog_ops = { | ||
485 | + .read = imx8mp_set_clr_tog_read, | ||
486 | + .write = imx8mp_set_clr_tog_write, | ||
487 | + .endianness = DEVICE_NATIVE_ENDIAN, | ||
488 | + .impl = { | ||
489 | + /* | ||
490 | + * Our device would not work correctly if the guest was doing | ||
491 | + * unaligned access. This might not be a limitation on the real | ||
492 | + * device but in practice there is no reason for a guest to access | ||
493 | + * this device unaligned. | ||
494 | + */ | ||
495 | + .min_access_size = 4, | ||
496 | + .max_access_size = 4, | ||
497 | + .unaligned = false, | ||
498 | + }, | ||
499 | +}; | ||
500 | + | ||
501 | +static void imx8mp_ccm_init(Object *obj) | ||
502 | +{ | ||
503 | + SysBusDevice *sd = SYS_BUS_DEVICE(obj); | ||
504 | + IMX8MPCCMState *s = IMX8MP_CCM(obj); | ||
505 | + | ||
506 | + memory_region_init_io(&s->iomem, | ||
507 | + obj, | ||
508 | + &imx8mp_set_clr_tog_ops, | ||
509 | + s->ccm, | ||
510 | + TYPE_IMX8MP_CCM ".ccm", | ||
511 | + sizeof(s->ccm)); | ||
512 | + | ||
513 | + sysbus_init_mmio(sd, &s->iomem); | ||
514 | +} | ||
515 | + | ||
516 | +static const VMStateDescription imx8mp_ccm_vmstate = { | ||
517 | + .name = TYPE_IMX8MP_CCM, | ||
518 | + .version_id = 1, | ||
519 | + .minimum_version_id = 1, | ||
520 | + .fields = (const VMStateField[]) { | ||
521 | + VMSTATE_UINT32_ARRAY(ccm, IMX8MPCCMState, CCM_MAX), | ||
522 | + VMSTATE_END_OF_LIST() | ||
523 | + }, | ||
524 | +}; | ||
525 | + | ||
526 | +static uint32_t imx8mp_ccm_get_clock_frequency(IMXCCMState *dev, IMXClk clock) | ||
527 | +{ | ||
528 | + /* | ||
529 | + * This function is "consumed" by GPT emulation code. Some clocks | ||
530 | + * have fixed frequencies and we can provide requested frequency | ||
531 | + * easily. However for CCM provided clocks (like IPG) each GPT | ||
532 | + * timer can have its own clock root. | ||
533 | + * This means we need additional information when calling this | ||
534 | + * function to know the requester's identity. | ||
535 | + */ | ||
536 | + uint32_t freq = 0; | ||
537 | + | ||
538 | + switch (clock) { | ||
539 | + case CLK_NONE: | ||
540 | + break; | ||
541 | + case CLK_32k: | ||
542 | + freq = CKIL_FREQ; | ||
543 | + break; | ||
544 | + case CLK_HIGH: | ||
545 | + freq = CKIH_FREQ; | ||
546 | + break; | ||
547 | + case CLK_IPG: | ||
548 | + case CLK_IPG_HIGH: | ||
549 | + /* | ||
550 | + * For now we don't have a way to figure out the device this | ||
551 | + * function is called for. Until then the IPG derived clocks | ||
552 | + * are left unimplemented. | ||
553 | + */ | ||
554 | + qemu_log_mask(LOG_GUEST_ERROR, "[%s]%s: Clock %d Not implemented\n", | ||
555 | + TYPE_IMX8MP_CCM, __func__, clock); | ||
556 | + break; | ||
557 | + default: | ||
558 | + qemu_log_mask(LOG_GUEST_ERROR, "[%s]%s: unsupported clock %d\n", | ||
559 | + TYPE_IMX8MP_CCM, __func__, clock); | ||
560 | + break; | ||
561 | + } | ||
562 | + | ||
563 | + trace_ccm_clock_freq(clock, freq); | ||
564 | + | ||
565 | + return freq; | ||
566 | +} | ||
567 | + | ||
568 | +static void imx8mp_ccm_class_init(ObjectClass *klass, void *data) | ||
569 | +{ | ||
570 | + DeviceClass *dc = DEVICE_CLASS(klass); | ||
571 | + IMXCCMClass *ccm = IMX_CCM_CLASS(klass); | ||
572 | + | ||
573 | + device_class_set_legacy_reset(dc, imx8mp_ccm_reset); | ||
574 | + dc->vmsd = &imx8mp_ccm_vmstate; | ||
575 | + dc->desc = "i.MX 8M Plus Clock Control Module"; | ||
576 | + | ||
577 | + ccm->get_clock_frequency = imx8mp_ccm_get_clock_frequency; | ||
578 | +} | ||
579 | + | ||
580 | +static const TypeInfo imx8mp_ccm_types[] = { | ||
581 | + { | ||
582 | + .name = TYPE_IMX8MP_CCM, | ||
583 | + .parent = TYPE_IMX_CCM, | ||
584 | + .instance_size = sizeof(IMX8MPCCMState), | ||
585 | + .instance_init = imx8mp_ccm_init, | ||
586 | + .class_init = imx8mp_ccm_class_init, | ||
587 | + }, | ||
588 | +}; | ||
589 | + | ||
590 | +DEFINE_TYPES(imx8mp_ccm_types); | ||
591 | diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig | ||
592 | index XXXXXXX..XXXXXXX 100644 | ||
593 | --- a/hw/arm/Kconfig | ||
594 | +++ b/hw/arm/Kconfig | ||
595 | @@ -XXX,XX +XXX,XX @@ config FSL_IMX7 | ||
596 | config FSL_IMX8MP | ||
597 | bool | ||
598 | select ARM_GIC | ||
599 | + select FSL_IMX8MP_ANALOG | ||
600 | + select FSL_IMX8MP_CCM | ||
601 | select IMX | ||
602 | select UNIMP | ||
603 | |||
604 | diff --git a/hw/misc/Kconfig b/hw/misc/Kconfig | ||
605 | index XXXXXXX..XXXXXXX 100644 | ||
606 | --- a/hw/misc/Kconfig | ||
607 | +++ b/hw/misc/Kconfig | ||
608 | @@ -XXX,XX +XXX,XX @@ config IMX | ||
609 | select SSI | ||
610 | select USB_EHCI_SYSBUS | ||
611 | |||
612 | +config FSL_IMX8MP_ANALOG | ||
613 | + bool | ||
614 | + | ||
615 | +config FSL_IMX8MP_CCM | ||
616 | + bool | ||
617 | + | ||
618 | config STM32_RCC | ||
619 | bool | ||
620 | |||
621 | diff --git a/hw/misc/meson.build b/hw/misc/meson.build | ||
622 | index XXXXXXX..XXXXXXX 100644 | ||
623 | --- a/hw/misc/meson.build | ||
624 | +++ b/hw/misc/meson.build | ||
625 | @@ -XXX,XX +XXX,XX @@ system_ss.add(when: 'CONFIG_AXP2XX_PMU', if_true: files('axp2xx.c')) | ||
626 | system_ss.add(when: 'CONFIG_REALVIEW', if_true: files('arm_sysctl.c')) | ||
627 | system_ss.add(when: 'CONFIG_ECCMEMCTL', if_true: files('eccmemctl.c')) | ||
628 | system_ss.add(when: 'CONFIG_EXYNOS4', if_true: files('exynos4210_pmu.c', 'exynos4210_clk.c', 'exynos4210_rng.c')) | ||
629 | +system_ss.add(when: 'CONFIG_FSL_IMX8MP_ANALOG', if_true: files('imx8mp_analog.c')) | ||
630 | +system_ss.add(when: 'CONFIG_FSL_IMX8MP_CCM', if_true: files('imx8mp_ccm.c')) | ||
631 | system_ss.add(when: 'CONFIG_IMX', if_true: files( | ||
632 | 'imx25_ccm.c', | ||
633 | 'imx31_ccm.c', | ||
481 | -- | 634 | -- |
482 | 2.20.1 | 635 | 2.43.0 |
483 | |||
484 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Bernhard Beschow <shentey@gmail.com> | ||
1 | 2 | ||
3 | SNVS contains an RTC which allows Linux to deal correctly with time. This is | ||
4 | particularly useful when handling persistent storage which will be done in the | ||
5 | next patch. | ||
6 | |||
7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
8 | Signed-off-by: Bernhard Beschow <shentey@gmail.com> | ||
9 | Message-id: 20250223114708.1780-7-shentey@gmail.com | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
11 | --- | ||
12 | docs/system/arm/imx8mp-evk.rst | 1 + | ||
13 | include/hw/arm/fsl-imx8mp.h | 2 ++ | ||
14 | hw/arm/fsl-imx8mp.c | 10 ++++++++++ | ||
15 | 3 files changed, 13 insertions(+) | ||
16 | |||
17 | diff --git a/docs/system/arm/imx8mp-evk.rst b/docs/system/arm/imx8mp-evk.rst | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/docs/system/arm/imx8mp-evk.rst | ||
20 | +++ b/docs/system/arm/imx8mp-evk.rst | ||
21 | @@ -XXX,XX +XXX,XX @@ The ``imx8mp-evk`` machine implements the following devices: | ||
22 | * Up to 4 Cortex-A53 cores | ||
23 | * Generic Interrupt Controller (GICv3) | ||
24 | * 4 UARTs | ||
25 | + * Secure Non-Volatile Storage (SNVS) including an RTC | ||
26 | * Clock Tree | ||
27 | |||
28 | Boot options | ||
29 | diff --git a/include/hw/arm/fsl-imx8mp.h b/include/hw/arm/fsl-imx8mp.h | ||
30 | index XXXXXXX..XXXXXXX 100644 | ||
31 | --- a/include/hw/arm/fsl-imx8mp.h | ||
32 | +++ b/include/hw/arm/fsl-imx8mp.h | ||
33 | @@ -XXX,XX +XXX,XX @@ | ||
34 | #include "cpu.h" | ||
35 | #include "hw/char/imx_serial.h" | ||
36 | #include "hw/intc/arm_gicv3_common.h" | ||
37 | +#include "hw/misc/imx7_snvs.h" | ||
38 | #include "hw/misc/imx8mp_analog.h" | ||
39 | #include "hw/misc/imx8mp_ccm.h" | ||
40 | #include "qom/object.h" | ||
41 | @@ -XXX,XX +XXX,XX @@ struct FslImx8mpState { | ||
42 | GICv3State gic; | ||
43 | IMX8MPCCMState ccm; | ||
44 | IMX8MPAnalogState analog; | ||
45 | + IMX7SNVSState snvs; | ||
46 | IMXSerialState uart[FSL_IMX8MP_NUM_UARTS]; | ||
47 | }; | ||
48 | |||
49 | diff --git a/hw/arm/fsl-imx8mp.c b/hw/arm/fsl-imx8mp.c | ||
50 | index XXXXXXX..XXXXXXX 100644 | ||
51 | --- a/hw/arm/fsl-imx8mp.c | ||
52 | +++ b/hw/arm/fsl-imx8mp.c | ||
53 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx8mp_init(Object *obj) | ||
54 | |||
55 | object_initialize_child(obj, "analog", &s->analog, TYPE_IMX8MP_ANALOG); | ||
56 | |||
57 | + object_initialize_child(obj, "snvs", &s->snvs, TYPE_IMX7_SNVS); | ||
58 | + | ||
59 | for (i = 0; i < FSL_IMX8MP_NUM_UARTS; i++) { | ||
60 | g_autofree char *name = g_strdup_printf("uart%d", i + 1); | ||
61 | object_initialize_child(obj, name, &s->uart[i], TYPE_IMX_SERIAL); | ||
62 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp) | ||
63 | qdev_get_gpio_in(gicdev, serial_table[i].irq)); | ||
64 | } | ||
65 | |||
66 | + /* SNVS */ | ||
67 | + if (!sysbus_realize(SYS_BUS_DEVICE(&s->snvs), errp)) { | ||
68 | + return; | ||
69 | + } | ||
70 | + sysbus_mmio_map(SYS_BUS_DEVICE(&s->snvs), 0, | ||
71 | + fsl_imx8mp_memmap[FSL_IMX8MP_SNVS_HP].addr); | ||
72 | + | ||
73 | /* Unimplemented devices */ | ||
74 | for (i = 0; i < ARRAY_SIZE(fsl_imx8mp_memmap); i++) { | ||
75 | switch (i) { | ||
76 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp) | ||
77 | case FSL_IMX8MP_GIC_DIST: | ||
78 | case FSL_IMX8MP_GIC_REDIST: | ||
79 | case FSL_IMX8MP_RAM: | ||
80 | + case FSL_IMX8MP_SNVS_HP: | ||
81 | case FSL_IMX8MP_UART1 ... FSL_IMX8MP_UART4: | ||
82 | /* device implemented and treated above */ | ||
83 | break; | ||
84 | -- | ||
85 | 2.43.0 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Bernhard Beschow <shentey@gmail.com> | ||
1 | 2 | ||
3 | The USDHC emulation allows for running real-world images such as those generated | ||
4 | by Buildroot. Convert the board documentation accordingly instead of running a | ||
5 | Linux kernel with ephemeral storage. | ||
6 | |||
7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
8 | Signed-off-by: Bernhard Beschow <shentey@gmail.com> | ||
9 | Message-id: 20250223114708.1780-8-shentey@gmail.com | ||
10 | [PMM: drop 'static const' from usdhc_table[] for GCC 7.5] | ||
11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
12 | --- | ||
13 | docs/system/arm/imx8mp-evk.rst | 18 ++++++++++++------ | ||
14 | include/hw/arm/fsl-imx8mp.h | 7 +++++++ | ||
15 | hw/arm/fsl-imx8mp.c | 28 ++++++++++++++++++++++++++++ | ||
16 | hw/arm/imx8mp-evk.c | 18 ++++++++++++++++++ | ||
17 | hw/arm/Kconfig | 1 + | ||
18 | 5 files changed, 66 insertions(+), 6 deletions(-) | ||
19 | |||
20 | diff --git a/docs/system/arm/imx8mp-evk.rst b/docs/system/arm/imx8mp-evk.rst | ||
21 | index XXXXXXX..XXXXXXX 100644 | ||
22 | --- a/docs/system/arm/imx8mp-evk.rst | ||
23 | +++ b/docs/system/arm/imx8mp-evk.rst | ||
24 | @@ -XXX,XX +XXX,XX @@ The ``imx8mp-evk`` machine implements the following devices: | ||
25 | * Up to 4 Cortex-A53 cores | ||
26 | * Generic Interrupt Controller (GICv3) | ||
27 | * 4 UARTs | ||
28 | + * 3 USDHC Storage Controllers | ||
29 | * Secure Non-Volatile Storage (SNVS) including an RTC | ||
30 | * Clock Tree | ||
31 | |||
32 | @@ -XXX,XX +XXX,XX @@ Direct Linux Kernel Boot | ||
33 | |||
34 | Probably the easiest way to get started with a whole Linux system on the machine | ||
35 | is to generate an image with Buildroot. Version 2024.11.1 is tested at the time | ||
36 | -of writing and involves two steps. First run the following commands in the | ||
37 | +of writing and involves three steps. First run the following commands in the | ||
38 | toplevel directory of the Buildroot source tree: | ||
39 | |||
40 | .. code-block:: bash | ||
41 | |||
42 | - $ echo "BR2_TARGET_ROOTFS_CPIO=y" >> configs/freescale_imx8mpevk_defconfig | ||
43 | $ make freescale_imx8mpevk_defconfig | ||
44 | $ make | ||
45 | |||
46 | Once finished successfully there is an ``output/image`` subfolder. Navigate into | ||
47 | -it and patch the device tree with the following commands which will remove the | ||
48 | -``cpu-idle-states`` properties from CPU nodes: | ||
49 | +it and resize the SD card image to a power of two: | ||
50 | + | ||
51 | +.. code-block:: bash | ||
52 | + | ||
53 | + $ qemu-img resize sdcard.img 256M | ||
54 | + | ||
55 | +Finally, the device tree needs to be patched with the following commands which | ||
56 | +will remove the ``cpu-idle-states`` properties from CPU nodes: | ||
57 | |||
58 | .. code-block:: bash | ||
59 | |||
60 | @@ -XXX,XX +XXX,XX @@ Now that everything is prepared the machine can be started as follows: | ||
61 | -display none -serial null -serial stdio \ | ||
62 | -kernel Image \ | ||
63 | -dtb imx8mp-evk-patched.dtb \ | ||
64 | - -initrd rootfs.cpio \ | ||
65 | - -append "root=/dev/ram" | ||
66 | + -append "root=/dev/mmcblk2p2" \ | ||
67 | + -drive file=sdcard.img,if=sd,bus=2,format=raw,id=mmcblk2 | ||
68 | diff --git a/include/hw/arm/fsl-imx8mp.h b/include/hw/arm/fsl-imx8mp.h | ||
69 | index XXXXXXX..XXXXXXX 100644 | ||
70 | --- a/include/hw/arm/fsl-imx8mp.h | ||
71 | +++ b/include/hw/arm/fsl-imx8mp.h | ||
72 | @@ -XXX,XX +XXX,XX @@ | ||
73 | #include "hw/misc/imx7_snvs.h" | ||
74 | #include "hw/misc/imx8mp_analog.h" | ||
75 | #include "hw/misc/imx8mp_ccm.h" | ||
76 | +#include "hw/sd/sdhci.h" | ||
77 | #include "qom/object.h" | ||
78 | #include "qemu/units.h" | ||
79 | |||
80 | @@ -XXX,XX +XXX,XX @@ enum FslImx8mpConfiguration { | ||
81 | FSL_IMX8MP_NUM_CPUS = 4, | ||
82 | FSL_IMX8MP_NUM_IRQS = 160, | ||
83 | FSL_IMX8MP_NUM_UARTS = 4, | ||
84 | + FSL_IMX8MP_NUM_USDHCS = 3, | ||
85 | }; | ||
86 | |||
87 | struct FslImx8mpState { | ||
88 | @@ -XXX,XX +XXX,XX @@ struct FslImx8mpState { | ||
89 | IMX8MPAnalogState analog; | ||
90 | IMX7SNVSState snvs; | ||
91 | IMXSerialState uart[FSL_IMX8MP_NUM_UARTS]; | ||
92 | + SDHCIState usdhc[FSL_IMX8MP_NUM_USDHCS]; | ||
93 | }; | ||
94 | |||
95 | enum FslImx8mpMemoryRegions { | ||
96 | @@ -XXX,XX +XXX,XX @@ enum FslImx8mpMemoryRegions { | ||
97 | }; | ||
98 | |||
99 | enum FslImx8mpIrqs { | ||
100 | + FSL_IMX8MP_USDHC1_IRQ = 22, | ||
101 | + FSL_IMX8MP_USDHC2_IRQ = 23, | ||
102 | + FSL_IMX8MP_USDHC3_IRQ = 24, | ||
103 | + | ||
104 | FSL_IMX8MP_UART1_IRQ = 26, | ||
105 | FSL_IMX8MP_UART2_IRQ = 27, | ||
106 | FSL_IMX8MP_UART3_IRQ = 28, | ||
107 | diff --git a/hw/arm/fsl-imx8mp.c b/hw/arm/fsl-imx8mp.c | ||
108 | index XXXXXXX..XXXXXXX 100644 | ||
109 | --- a/hw/arm/fsl-imx8mp.c | ||
110 | +++ b/hw/arm/fsl-imx8mp.c | ||
111 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx8mp_init(Object *obj) | ||
112 | g_autofree char *name = g_strdup_printf("uart%d", i + 1); | ||
113 | object_initialize_child(obj, name, &s->uart[i], TYPE_IMX_SERIAL); | ||
114 | } | ||
115 | + | ||
116 | + for (i = 0; i < FSL_IMX8MP_NUM_USDHCS; i++) { | ||
117 | + g_autofree char *name = g_strdup_printf("usdhc%d", i + 1); | ||
118 | + object_initialize_child(obj, name, &s->usdhc[i], TYPE_IMX_USDHC); | ||
119 | + } | ||
120 | } | ||
121 | |||
122 | static void fsl_imx8mp_realize(DeviceState *dev, Error **errp) | ||
123 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp) | ||
124 | qdev_get_gpio_in(gicdev, serial_table[i].irq)); | ||
125 | } | ||
126 | |||
127 | + /* USDHCs */ | ||
128 | + for (i = 0; i < FSL_IMX8MP_NUM_USDHCS; i++) { | ||
129 | + struct { | ||
130 | + hwaddr addr; | ||
131 | + unsigned int irq; | ||
132 | + } usdhc_table[FSL_IMX8MP_NUM_USDHCS] = { | ||
133 | + { fsl_imx8mp_memmap[FSL_IMX8MP_USDHC1].addr, FSL_IMX8MP_USDHC1_IRQ }, | ||
134 | + { fsl_imx8mp_memmap[FSL_IMX8MP_USDHC2].addr, FSL_IMX8MP_USDHC2_IRQ }, | ||
135 | + { fsl_imx8mp_memmap[FSL_IMX8MP_USDHC3].addr, FSL_IMX8MP_USDHC3_IRQ }, | ||
136 | + }; | ||
137 | + | ||
138 | + object_property_set_uint(OBJECT(&s->usdhc[i]), "vendor", | ||
139 | + SDHCI_VENDOR_IMX, &error_abort); | ||
140 | + if (!sysbus_realize(SYS_BUS_DEVICE(&s->usdhc[i]), errp)) { | ||
141 | + return; | ||
142 | + } | ||
143 | + | ||
144 | + sysbus_mmio_map(SYS_BUS_DEVICE(&s->usdhc[i]), 0, usdhc_table[i].addr); | ||
145 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->usdhc[i]), 0, | ||
146 | + qdev_get_gpio_in(gicdev, usdhc_table[i].irq)); | ||
147 | + } | ||
148 | + | ||
149 | /* SNVS */ | ||
150 | if (!sysbus_realize(SYS_BUS_DEVICE(&s->snvs), errp)) { | ||
151 | return; | ||
152 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp) | ||
153 | case FSL_IMX8MP_RAM: | ||
154 | case FSL_IMX8MP_SNVS_HP: | ||
155 | case FSL_IMX8MP_UART1 ... FSL_IMX8MP_UART4: | ||
156 | + case FSL_IMX8MP_USDHC1 ... FSL_IMX8MP_USDHC3: | ||
157 | /* device implemented and treated above */ | ||
158 | break; | ||
159 | |||
160 | diff --git a/hw/arm/imx8mp-evk.c b/hw/arm/imx8mp-evk.c | ||
161 | index XXXXXXX..XXXXXXX 100644 | ||
162 | --- a/hw/arm/imx8mp-evk.c | ||
163 | +++ b/hw/arm/imx8mp-evk.c | ||
164 | @@ -XXX,XX +XXX,XX @@ | ||
165 | #include "hw/arm/boot.h" | ||
166 | #include "hw/arm/fsl-imx8mp.h" | ||
167 | #include "hw/boards.h" | ||
168 | +#include "hw/qdev-properties.h" | ||
169 | #include "system/qtest.h" | ||
170 | #include "qemu/error-report.h" | ||
171 | #include "qapi/error.h" | ||
172 | @@ -XXX,XX +XXX,XX @@ static void imx8mp_evk_init(MachineState *machine) | ||
173 | memory_region_add_subregion(get_system_memory(), FSL_IMX8MP_RAM_START, | ||
174 | machine->ram); | ||
175 | |||
176 | + for (int i = 0; i < FSL_IMX8MP_NUM_USDHCS; i++) { | ||
177 | + BusState *bus; | ||
178 | + DeviceState *carddev; | ||
179 | + BlockBackend *blk; | ||
180 | + DriveInfo *di = drive_get(IF_SD, i, 0); | ||
181 | + | ||
182 | + if (!di) { | ||
183 | + continue; | ||
184 | + } | ||
185 | + | ||
186 | + blk = blk_by_legacy_dinfo(di); | ||
187 | + bus = qdev_get_child_bus(DEVICE(&s->usdhc[i]), "sd-bus"); | ||
188 | + carddev = qdev_new(TYPE_SD_CARD); | ||
189 | + qdev_prop_set_drive_err(carddev, "drive", blk, &error_fatal); | ||
190 | + qdev_realize_and_unref(carddev, bus, &error_fatal); | ||
191 | + } | ||
192 | + | ||
193 | if (!qtest_enabled()) { | ||
194 | arm_load_kernel(&s->cpu[0], machine, &boot_info); | ||
195 | } | ||
196 | diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig | ||
197 | index XXXXXXX..XXXXXXX 100644 | ||
198 | --- a/hw/arm/Kconfig | ||
199 | +++ b/hw/arm/Kconfig | ||
200 | @@ -XXX,XX +XXX,XX @@ config FSL_IMX8MP | ||
201 | select FSL_IMX8MP_ANALOG | ||
202 | select FSL_IMX8MP_CCM | ||
203 | select IMX | ||
204 | + select SDHCI | ||
205 | select UNIMP | ||
206 | |||
207 | config FSL_IMX8MP_EVK | ||
208 | -- | ||
209 | 2.43.0 | diff view generated by jsdifflib |
1 | From: Rashmica Gupta <rashmica.g@gmail.com> | 1 | From: Bernhard Beschow <shentey@gmail.com> |
---|---|---|---|
2 | 2 | ||
3 | GPIO pins are arranged in groups of 8 pins labeled A,B,..,Y,Z,AA,AB,AC. | 3 | Linux checks for the PLLs in the PHY to be locked, so implement a model |
4 | (Note that the ast2400 controller only goes up to group AB). | 4 | emulating that. |
5 | A set has four groups (except set AC which only has one) and is | ||
6 | referred to by the groups it is composed of (eg ABCD,EFGH,...,YZAAAB). | ||
7 | Each set is accessed and controlled by a bank of 14 registers. | ||
8 | 5 | ||
9 | These registers operate on a per pin level where each bit in the register | 6 | Signed-off-by: Bernhard Beschow <shentey@gmail.com> |
10 | corresponds to a pin, except for the command source registers. The command | 7 | Message-id: 20250223114708.1780-9-shentey@gmail.com |
11 | source registers operate on a per group level where bits 24, 16, 8 and 0 | 8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
12 | correspond to each group in the set. | ||
13 | |||
14 | eg. registers for set ABCD: | ||
15 | |D7...D0|C7...C0|B7...B0|A7...A0| <- GPIOs | ||
16 | |31...24|23...16|15....8|7.....0| <- bit position | ||
17 | |||
18 | Note that there are a couple of groups that only have 4 pins. | ||
19 | |||
20 | There are two ways that this model deviates from the behaviour of the | ||
21 | actual controller: | ||
22 | (1) The only control source driving the GPIO pins in the model is the ARM | ||
23 | model (as there currently aren't models for the LPC or Coprocessor). | ||
24 | |||
25 | (2) None of the registers in the model are reset tolerant (needs | ||
26 | integration with the watchdog). | ||
27 | |||
28 | Signed-off-by: Rashmica Gupta <rashmica.g@gmail.com> | ||
29 | Tested-by: Andrew Jeffery <andrew@aj.id.au> | ||
30 | Reviewed-by: Cédric Le Goater <clg@kaod.org> | ||
31 | Signed-off-by: Cédric Le Goater <clg@kaod.org> | ||
32 | Message-id: 20190904070506.1052-2-clg@kaod.org | ||
33 | [clg: fixed missing header files | ||
34 | made use of HWADDR_PRIx to fix compilation on windows ] | ||
35 | Signed-off-by: Cédric Le Goater <clg@kaod.org> | ||
36 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
37 | --- | 10 | --- |
38 | hw/gpio/Makefile.objs | 1 + | 11 | MAINTAINERS | 2 + |
39 | include/hw/gpio/aspeed_gpio.h | 100 ++++ | 12 | docs/system/arm/imx8mp-evk.rst | 1 + |
40 | hw/gpio/aspeed_gpio.c | 884 ++++++++++++++++++++++++++++++++++ | 13 | include/hw/arm/fsl-imx8mp.h | 10 +++ |
41 | 3 files changed, 985 insertions(+) | 14 | include/hw/pci-host/fsl_imx8m_phy.h | 28 +++++++++ |
42 | create mode 100644 include/hw/gpio/aspeed_gpio.h | 15 | hw/arm/fsl-imx8mp.c | 30 +++++++++ |
43 | create mode 100644 hw/gpio/aspeed_gpio.c | 16 | hw/pci-host/fsl_imx8m_phy.c | 98 +++++++++++++++++++++++++++++ |
17 | hw/arm/Kconfig | 3 + | ||
18 | hw/pci-host/Kconfig | 3 + | ||
19 | hw/pci-host/meson.build | 1 + | ||
20 | 9 files changed, 176 insertions(+) | ||
21 | create mode 100644 include/hw/pci-host/fsl_imx8m_phy.h | ||
22 | create mode 100644 hw/pci-host/fsl_imx8m_phy.c | ||
44 | 23 | ||
45 | diff --git a/hw/gpio/Makefile.objs b/hw/gpio/Makefile.objs | 24 | diff --git a/MAINTAINERS b/MAINTAINERS |
46 | index XXXXXXX..XXXXXXX 100644 | 25 | index XXXXXXX..XXXXXXX 100644 |
47 | --- a/hw/gpio/Makefile.objs | 26 | --- a/MAINTAINERS |
48 | +++ b/hw/gpio/Makefile.objs | 27 | +++ b/MAINTAINERS |
49 | @@ -XXX,XX +XXX,XX @@ obj-$(CONFIG_OMAP) += omap_gpio.o | 28 | @@ -XXX,XX +XXX,XX @@ S: Maintained |
50 | obj-$(CONFIG_IMX) += imx_gpio.o | 29 | F: hw/arm/imx8mp-evk.c |
51 | obj-$(CONFIG_RASPI) += bcm2835_gpio.o | 30 | F: hw/arm/fsl-imx8mp.c |
52 | obj-$(CONFIG_NRF51_SOC) += nrf51_gpio.o | 31 | F: hw/misc/imx8mp_*.c |
53 | +obj-$(CONFIG_ASPEED_SOC) += aspeed_gpio.o | 32 | +F: hw/pci-host/fsl_imx8m_phy.c |
54 | diff --git a/include/hw/gpio/aspeed_gpio.h b/include/hw/gpio/aspeed_gpio.h | 33 | F: include/hw/arm/fsl-imx8mp.h |
34 | F: include/hw/misc/imx8mp_*.h | ||
35 | +F: include/hw/pci-host/fsl_imx8m_phy.h | ||
36 | F: docs/system/arm/imx8mp-evk.rst | ||
37 | |||
38 | MPS2 / MPS3 | ||
39 | diff --git a/docs/system/arm/imx8mp-evk.rst b/docs/system/arm/imx8mp-evk.rst | ||
40 | index XXXXXXX..XXXXXXX 100644 | ||
41 | --- a/docs/system/arm/imx8mp-evk.rst | ||
42 | +++ b/docs/system/arm/imx8mp-evk.rst | ||
43 | @@ -XXX,XX +XXX,XX @@ The ``imx8mp-evk`` machine implements the following devices: | ||
44 | * Generic Interrupt Controller (GICv3) | ||
45 | * 4 UARTs | ||
46 | * 3 USDHC Storage Controllers | ||
47 | + * 1 Designware PCI Express Controller | ||
48 | * Secure Non-Volatile Storage (SNVS) including an RTC | ||
49 | * Clock Tree | ||
50 | |||
51 | diff --git a/include/hw/arm/fsl-imx8mp.h b/include/hw/arm/fsl-imx8mp.h | ||
52 | index XXXXXXX..XXXXXXX 100644 | ||
53 | --- a/include/hw/arm/fsl-imx8mp.h | ||
54 | +++ b/include/hw/arm/fsl-imx8mp.h | ||
55 | @@ -XXX,XX +XXX,XX @@ | ||
56 | #include "hw/misc/imx7_snvs.h" | ||
57 | #include "hw/misc/imx8mp_analog.h" | ||
58 | #include "hw/misc/imx8mp_ccm.h" | ||
59 | +#include "hw/pci-host/designware.h" | ||
60 | +#include "hw/pci-host/fsl_imx8m_phy.h" | ||
61 | #include "hw/sd/sdhci.h" | ||
62 | #include "qom/object.h" | ||
63 | #include "qemu/units.h" | ||
64 | @@ -XXX,XX +XXX,XX @@ struct FslImx8mpState { | ||
65 | IMX7SNVSState snvs; | ||
66 | IMXSerialState uart[FSL_IMX8MP_NUM_UARTS]; | ||
67 | SDHCIState usdhc[FSL_IMX8MP_NUM_USDHCS]; | ||
68 | + DesignwarePCIEHost pcie; | ||
69 | + FslImx8mPciePhyState pcie_phy; | ||
70 | }; | ||
71 | |||
72 | enum FslImx8mpMemoryRegions { | ||
73 | @@ -XXX,XX +XXX,XX @@ enum FslImx8mpIrqs { | ||
74 | FSL_IMX8MP_UART4_IRQ = 29, | ||
75 | FSL_IMX8MP_UART5_IRQ = 30, | ||
76 | FSL_IMX8MP_UART6_IRQ = 16, | ||
77 | + | ||
78 | + FSL_IMX8MP_PCI_INTA_IRQ = 126, | ||
79 | + FSL_IMX8MP_PCI_INTB_IRQ = 125, | ||
80 | + FSL_IMX8MP_PCI_INTC_IRQ = 124, | ||
81 | + FSL_IMX8MP_PCI_INTD_IRQ = 123, | ||
82 | + FSL_IMX8MP_PCI_MSI_IRQ = 140, | ||
83 | }; | ||
84 | |||
85 | #endif /* FSL_IMX8MP_H */ | ||
86 | diff --git a/include/hw/pci-host/fsl_imx8m_phy.h b/include/hw/pci-host/fsl_imx8m_phy.h | ||
55 | new file mode 100644 | 87 | new file mode 100644 |
56 | index XXXXXXX..XXXXXXX | 88 | index XXXXXXX..XXXXXXX |
57 | --- /dev/null | 89 | --- /dev/null |
58 | +++ b/include/hw/gpio/aspeed_gpio.h | 90 | +++ b/include/hw/pci-host/fsl_imx8m_phy.h |
59 | @@ -XXX,XX +XXX,XX @@ | 91 | @@ -XXX,XX +XXX,XX @@ |
60 | +/* | 92 | +/* |
61 | + * ASPEED GPIO Controller | 93 | + * i.MX8 PCIe PHY emulation |
62 | + * | 94 | + * |
63 | + * Copyright (C) 2017-2018 IBM Corp. | 95 | + * Copyright (c) 2025 Bernhard Beschow <shentey@gmail.com> |
64 | + * | 96 | + * |
65 | + * This code is licensed under the GPL version 2 or later. See | 97 | + * SPDX-License-Identifier: GPL-2.0-or-later |
66 | + * the COPYING file in the top-level directory. | ||
67 | + */ | 98 | + */ |
68 | + | 99 | + |
69 | +#ifndef ASPEED_GPIO_H | 100 | +#ifndef HW_PCIHOST_FSLIMX8MPCIEPHY_H |
70 | +#define ASPEED_GPIO_H | 101 | +#define HW_PCIHOST_FSLIMX8MPCIEPHY_H |
71 | + | 102 | + |
72 | +#include "hw/sysbus.h" | 103 | +#include "hw/sysbus.h" |
73 | + | 104 | +#include "qom/object.h" |
74 | +#define TYPE_ASPEED_GPIO "aspeed.gpio" | 105 | +#include "exec/memory.h" |
75 | +#define ASPEED_GPIO(obj) OBJECT_CHECK(AspeedGPIOState, (obj), TYPE_ASPEED_GPIO) | 106 | + |
76 | +#define ASPEED_GPIO_CLASS(klass) \ | 107 | +#define TYPE_FSL_IMX8M_PCIE_PHY "fsl-imx8m-pcie-phy" |
77 | + OBJECT_CLASS_CHECK(AspeedGPIOClass, (klass), TYPE_ASPEED_GPIO) | 108 | +OBJECT_DECLARE_SIMPLE_TYPE(FslImx8mPciePhyState, FSL_IMX8M_PCIE_PHY) |
78 | +#define ASPEED_GPIO_GET_CLASS(obj) \ | 109 | + |
79 | + OBJECT_GET_CLASS(AspeedGPIOClass, (obj), TYPE_ASPEED_GPIO) | 110 | +#define FSL_IMX8M_PCIE_PHY_DATA_SIZE 0x800 |
80 | + | 111 | + |
81 | +#define ASPEED_GPIO_MAX_NR_SETS 8 | 112 | +struct FslImx8mPciePhyState { |
82 | +#define ASPEED_REGS_PER_BANK 14 | 113 | + SysBusDevice parent_obj; |
83 | +#define ASPEED_GPIO_MAX_NR_REGS (ASPEED_REGS_PER_BANK * ASPEED_GPIO_MAX_NR_SETS) | 114 | + |
84 | +#define ASPEED_GPIO_NR_PINS 228 | 115 | + MemoryRegion iomem; |
85 | +#define ASPEED_GROUPS_PER_SET 4 | 116 | + uint8_t data[FSL_IMX8M_PCIE_PHY_DATA_SIZE]; |
86 | +#define ASPEED_GPIO_NR_DEBOUNCE_REGS 3 | ||
87 | +#define ASPEED_CHARS_PER_GROUP_LABEL 4 | ||
88 | + | ||
89 | +typedef struct GPIOSets GPIOSets; | ||
90 | + | ||
91 | +typedef struct GPIOSetProperties { | ||
92 | + uint32_t input; | ||
93 | + uint32_t output; | ||
94 | + char group_label[ASPEED_GROUPS_PER_SET][ASPEED_CHARS_PER_GROUP_LABEL]; | ||
95 | +} GPIOSetProperties; | ||
96 | + | ||
97 | +enum GPIORegType { | ||
98 | + gpio_not_a_reg, | ||
99 | + gpio_reg_data_value, | ||
100 | + gpio_reg_direction, | ||
101 | + gpio_reg_int_enable, | ||
102 | + gpio_reg_int_sens_0, | ||
103 | + gpio_reg_int_sens_1, | ||
104 | + gpio_reg_int_sens_2, | ||
105 | + gpio_reg_int_status, | ||
106 | + gpio_reg_reset_tolerant, | ||
107 | + gpio_reg_debounce_1, | ||
108 | + gpio_reg_debounce_2, | ||
109 | + gpio_reg_cmd_source_0, | ||
110 | + gpio_reg_cmd_source_1, | ||
111 | + gpio_reg_data_read, | ||
112 | + gpio_reg_input_mask, | ||
113 | +}; | 117 | +}; |
114 | + | 118 | + |
115 | +typedef struct AspeedGPIOReg { | 119 | +#endif |
116 | + uint16_t set_idx; | 120 | diff --git a/hw/arm/fsl-imx8mp.c b/hw/arm/fsl-imx8mp.c |
117 | + enum GPIORegType type; | 121 | index XXXXXXX..XXXXXXX 100644 |
118 | + } AspeedGPIOReg; | 122 | --- a/hw/arm/fsl-imx8mp.c |
119 | + | 123 | +++ b/hw/arm/fsl-imx8mp.c |
120 | +typedef struct AspeedGPIOClass { | 124 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx8mp_init(Object *obj) |
121 | + SysBusDevice parent_obj; | 125 | g_autofree char *name = g_strdup_printf("usdhc%d", i + 1); |
122 | + const GPIOSetProperties *props; | 126 | object_initialize_child(obj, name, &s->usdhc[i], TYPE_IMX_USDHC); |
123 | + uint32_t nr_gpio_pins; | 127 | } |
124 | + uint32_t nr_gpio_sets; | 128 | + |
125 | + uint32_t gap; | 129 | + object_initialize_child(obj, "pcie", &s->pcie, TYPE_DESIGNWARE_PCIE_HOST); |
126 | + const AspeedGPIOReg *reg_table; | 130 | + object_initialize_child(obj, "pcie_phy", &s->pcie_phy, |
127 | +} AspeedGPIOClass; | 131 | + TYPE_FSL_IMX8M_PCIE_PHY); |
128 | + | 132 | } |
129 | +typedef struct AspeedGPIOState { | 133 | |
130 | + /* <private> */ | 134 | static void fsl_imx8mp_realize(DeviceState *dev, Error **errp) |
131 | + SysBusDevice parent; | 135 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp) |
132 | + | 136 | sysbus_mmio_map(SYS_BUS_DEVICE(&s->snvs), 0, |
133 | + /*< public >*/ | 137 | fsl_imx8mp_memmap[FSL_IMX8MP_SNVS_HP].addr); |
134 | + MemoryRegion iomem; | 138 | |
135 | + int pending; | 139 | + /* PCIe */ |
136 | + qemu_irq irq; | 140 | + if (!sysbus_realize(SYS_BUS_DEVICE(&s->pcie), errp)) { |
137 | + qemu_irq gpios[ASPEED_GPIO_NR_PINS]; | 141 | + return; |
138 | + | 142 | + } |
139 | +/* Parallel GPIO Registers */ | 143 | + sysbus_mmio_map(SYS_BUS_DEVICE(&s->pcie), 0, |
140 | + uint32_t debounce_regs[ASPEED_GPIO_NR_DEBOUNCE_REGS]; | 144 | + fsl_imx8mp_memmap[FSL_IMX8MP_PCIE1].addr); |
141 | + struct GPIOSets { | 145 | + |
142 | + uint32_t data_value; /* Reflects pin values */ | 146 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->pcie), 0, |
143 | + uint32_t data_read; /* Contains last value written to data value */ | 147 | + qdev_get_gpio_in(gicdev, FSL_IMX8MP_PCI_INTA_IRQ)); |
144 | + uint32_t direction; | 148 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->pcie), 1, |
145 | + uint32_t int_enable; | 149 | + qdev_get_gpio_in(gicdev, FSL_IMX8MP_PCI_INTB_IRQ)); |
146 | + uint32_t int_sens_0; | 150 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->pcie), 2, |
147 | + uint32_t int_sens_1; | 151 | + qdev_get_gpio_in(gicdev, FSL_IMX8MP_PCI_INTC_IRQ)); |
148 | + uint32_t int_sens_2; | 152 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->pcie), 3, |
149 | + uint32_t int_status; | 153 | + qdev_get_gpio_in(gicdev, FSL_IMX8MP_PCI_INTD_IRQ)); |
150 | + uint32_t reset_tol; | 154 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->pcie), 4, |
151 | + uint32_t cmd_source_0; | 155 | + qdev_get_gpio_in(gicdev, FSL_IMX8MP_PCI_MSI_IRQ)); |
152 | + uint32_t cmd_source_1; | 156 | + |
153 | + uint32_t debounce_1; | 157 | + if (!sysbus_realize(SYS_BUS_DEVICE(&s->pcie_phy), errp)) { |
154 | + uint32_t debounce_2; | 158 | + return; |
155 | + uint32_t input_mask; | 159 | + } |
156 | + } sets[ASPEED_GPIO_MAX_NR_SETS]; | 160 | + sysbus_mmio_map(SYS_BUS_DEVICE(&s->pcie_phy), 0, |
157 | +} AspeedGPIOState; | 161 | + fsl_imx8mp_memmap[FSL_IMX8MP_PCIE_PHY1].addr); |
158 | + | 162 | + |
159 | +#endif /* _ASPEED_GPIO_H_ */ | 163 | /* Unimplemented devices */ |
160 | diff --git a/hw/gpio/aspeed_gpio.c b/hw/gpio/aspeed_gpio.c | 164 | for (i = 0; i < ARRAY_SIZE(fsl_imx8mp_memmap); i++) { |
165 | switch (i) { | ||
166 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp) | ||
167 | case FSL_IMX8MP_CCM: | ||
168 | case FSL_IMX8MP_GIC_DIST: | ||
169 | case FSL_IMX8MP_GIC_REDIST: | ||
170 | + case FSL_IMX8MP_PCIE1: | ||
171 | + case FSL_IMX8MP_PCIE_PHY1: | ||
172 | case FSL_IMX8MP_RAM: | ||
173 | case FSL_IMX8MP_SNVS_HP: | ||
174 | case FSL_IMX8MP_UART1 ... FSL_IMX8MP_UART4: | ||
175 | diff --git a/hw/pci-host/fsl_imx8m_phy.c b/hw/pci-host/fsl_imx8m_phy.c | ||
161 | new file mode 100644 | 176 | new file mode 100644 |
162 | index XXXXXXX..XXXXXXX | 177 | index XXXXXXX..XXXXXXX |
163 | --- /dev/null | 178 | --- /dev/null |
164 | +++ b/hw/gpio/aspeed_gpio.c | 179 | +++ b/hw/pci-host/fsl_imx8m_phy.c |
165 | @@ -XXX,XX +XXX,XX @@ | 180 | @@ -XXX,XX +XXX,XX @@ |
166 | +/* | 181 | +/* |
167 | + * ASPEED GPIO Controller | 182 | + * i.MX8 PCIe PHY emulation |
168 | + * | 183 | + * |
169 | + * Copyright (C) 2017-2019 IBM Corp. | 184 | + * Copyright (c) 2025 Bernhard Beschow <shentey@gmail.com> |
170 | + * | 185 | + * |
171 | + * SPDX-License-Identifier: GPL-2.0-or-later | 186 | + * SPDX-License-Identifier: GPL-2.0-or-later |
172 | + */ | 187 | + */ |
173 | + | 188 | + |
174 | +#include <assert.h> | ||
175 | + | ||
176 | +#include "qemu/osdep.h" | 189 | +#include "qemu/osdep.h" |
177 | +#include "qemu/host-utils.h" | 190 | +#include "hw/pci-host/fsl_imx8m_phy.h" |
178 | +#include "qemu/log.h" | 191 | +#include "hw/resettable.h" |
179 | +#include "hw/gpio/aspeed_gpio.h" | ||
180 | +#include "include/hw/misc/aspeed_scu.h" | ||
181 | +#include "qapi/error.h" | ||
182 | +#include "qapi/visitor.h" | ||
183 | +#include "hw/irq.h" | ||
184 | +#include "migration/vmstate.h" | 192 | +#include "migration/vmstate.h" |
185 | + | 193 | + |
186 | +#define GPIOS_PER_REG 32 | 194 | +#define CMN_REG075 0x1d4 |
187 | +#define GPIOS_PER_SET GPIOS_PER_REG | 195 | +#define ANA_PLL_LOCK_DONE BIT(1) |
188 | +#define GPIO_PIN_GAP_SIZE 4 | 196 | +#define ANA_PLL_AFC_DONE BIT(0) |
189 | +#define GPIOS_PER_GROUP 8 | 197 | + |
190 | +#define GPIO_GROUP_SHIFT 3 | 198 | +static uint64_t fsl_imx8m_pcie_phy_read(void *opaque, hwaddr offset, |
191 | + | 199 | + unsigned size) |
192 | +/* GPIO Source Types */ | 200 | +{ |
193 | +#define ASPEED_CMD_SRC_MASK 0x01010101 | 201 | + FslImx8mPciePhyState *s = opaque; |
194 | +#define ASPEED_SOURCE_ARM 0 | 202 | + |
195 | +#define ASPEED_SOURCE_LPC 1 | 203 | + if (offset == CMN_REG075) { |
196 | +#define ASPEED_SOURCE_COPROCESSOR 2 | 204 | + return s->data[offset] | ANA_PLL_LOCK_DONE | ANA_PLL_AFC_DONE; |
197 | +#define ASPEED_SOURCE_RESERVED 3 | 205 | + } |
198 | + | 206 | + |
199 | +/* GPIO Interrupt Triggers */ | 207 | + return s->data[offset]; |
200 | +/* | 208 | +} |
201 | + * For each set of gpios there are three sensitivity registers that control | 209 | + |
202 | + * the interrupt trigger mode. | 210 | +static void fsl_imx8m_pcie_phy_write(void *opaque, hwaddr offset, |
203 | + * | 211 | + uint64_t value, unsigned size) |
204 | + * | 2 | 1 | 0 | trigger mode | 212 | +{ |
205 | + * ----------------------------- | 213 | + FslImx8mPciePhyState *s = opaque; |
206 | + * | 0 | 0 | 0 | falling-edge | 214 | + |
207 | + * | 0 | 0 | 1 | rising-edge | 215 | + s->data[offset] = value; |
208 | + * | 0 | 1 | 0 | level-low | 216 | +} |
209 | + * | 0 | 1 | 1 | level-high | 217 | + |
210 | + * | 1 | X | X | dual-edge | 218 | +static const MemoryRegionOps fsl_imx8m_pcie_phy_ops = { |
211 | + */ | 219 | + .read = fsl_imx8m_pcie_phy_read, |
212 | +#define ASPEED_FALLING_EDGE 0 | 220 | + .write = fsl_imx8m_pcie_phy_write, |
213 | +#define ASPEED_RISING_EDGE 1 | 221 | + .impl = { |
214 | +#define ASPEED_LEVEL_LOW 2 | 222 | + .min_access_size = 1, |
215 | +#define ASPEED_LEVEL_HIGH 3 | 223 | + .max_access_size = 1, |
216 | +#define ASPEED_DUAL_EDGE 4 | 224 | + }, |
217 | + | 225 | + .valid = { |
218 | +/* GPIO Register Address Offsets */ | 226 | + .min_access_size = 1, |
219 | +#define GPIO_ABCD_DATA_VALUE (0x000 >> 2) | 227 | + .max_access_size = 8, |
220 | +#define GPIO_ABCD_DIRECTION (0x004 >> 2) | 228 | + }, |
221 | +#define GPIO_ABCD_INT_ENABLE (0x008 >> 2) | 229 | + .endianness = DEVICE_LITTLE_ENDIAN, |
222 | +#define GPIO_ABCD_INT_SENS_0 (0x00C >> 2) | ||
223 | +#define GPIO_ABCD_INT_SENS_1 (0x010 >> 2) | ||
224 | +#define GPIO_ABCD_INT_SENS_2 (0x014 >> 2) | ||
225 | +#define GPIO_ABCD_INT_STATUS (0x018 >> 2) | ||
226 | +#define GPIO_ABCD_RESET_TOLERANT (0x01C >> 2) | ||
227 | +#define GPIO_EFGH_DATA_VALUE (0x020 >> 2) | ||
228 | +#define GPIO_EFGH_DIRECTION (0x024 >> 2) | ||
229 | +#define GPIO_EFGH_INT_ENABLE (0x028 >> 2) | ||
230 | +#define GPIO_EFGH_INT_SENS_0 (0x02C >> 2) | ||
231 | +#define GPIO_EFGH_INT_SENS_1 (0x030 >> 2) | ||
232 | +#define GPIO_EFGH_INT_SENS_2 (0x034 >> 2) | ||
233 | +#define GPIO_EFGH_INT_STATUS (0x038 >> 2) | ||
234 | +#define GPIO_EFGH_RESET_TOLERANT (0x03C >> 2) | ||
235 | +#define GPIO_ABCD_DEBOUNCE_1 (0x040 >> 2) | ||
236 | +#define GPIO_ABCD_DEBOUNCE_2 (0x044 >> 2) | ||
237 | +#define GPIO_EFGH_DEBOUNCE_1 (0x048 >> 2) | ||
238 | +#define GPIO_EFGH_DEBOUNCE_2 (0x04C >> 2) | ||
239 | +#define GPIO_DEBOUNCE_TIME_1 (0x050 >> 2) | ||
240 | +#define GPIO_DEBOUNCE_TIME_2 (0x054 >> 2) | ||
241 | +#define GPIO_DEBOUNCE_TIME_3 (0x058 >> 2) | ||
242 | +#define GPIO_ABCD_COMMAND_SRC_0 (0x060 >> 2) | ||
243 | +#define GPIO_ABCD_COMMAND_SRC_1 (0x064 >> 2) | ||
244 | +#define GPIO_EFGH_COMMAND_SRC_0 (0x068 >> 2) | ||
245 | +#define GPIO_EFGH_COMMAND_SRC_1 (0x06C >> 2) | ||
246 | +#define GPIO_IJKL_DATA_VALUE (0x070 >> 2) | ||
247 | +#define GPIO_IJKL_DIRECTION (0x074 >> 2) | ||
248 | +#define GPIO_MNOP_DATA_VALUE (0x078 >> 2) | ||
249 | +#define GPIO_MNOP_DIRECTION (0x07C >> 2) | ||
250 | +#define GPIO_QRST_DATA_VALUE (0x080 >> 2) | ||
251 | +#define GPIO_QRST_DIRECTION (0x084 >> 2) | ||
252 | +#define GPIO_UVWX_DATA_VALUE (0x088 >> 2) | ||
253 | +#define GPIO_UVWX_DIRECTION (0x08C >> 2) | ||
254 | +#define GPIO_IJKL_COMMAND_SRC_0 (0x090 >> 2) | ||
255 | +#define GPIO_IJKL_COMMAND_SRC_1 (0x094 >> 2) | ||
256 | +#define GPIO_IJKL_INT_ENABLE (0x098 >> 2) | ||
257 | +#define GPIO_IJKL_INT_SENS_0 (0x09C >> 2) | ||
258 | +#define GPIO_IJKL_INT_SENS_1 (0x0A0 >> 2) | ||
259 | +#define GPIO_IJKL_INT_SENS_2 (0x0A4 >> 2) | ||
260 | +#define GPIO_IJKL_INT_STATUS (0x0A8 >> 2) | ||
261 | +#define GPIO_IJKL_RESET_TOLERANT (0x0AC >> 2) | ||
262 | +#define GPIO_IJKL_DEBOUNCE_1 (0x0B0 >> 2) | ||
263 | +#define GPIO_IJKL_DEBOUNCE_2 (0x0B4 >> 2) | ||
264 | +#define GPIO_IJKL_INPUT_MASK (0x0B8 >> 2) | ||
265 | +#define GPIO_ABCD_DATA_READ (0x0C0 >> 2) | ||
266 | +#define GPIO_EFGH_DATA_READ (0x0C4 >> 2) | ||
267 | +#define GPIO_IJKL_DATA_READ (0x0C8 >> 2) | ||
268 | +#define GPIO_MNOP_DATA_READ (0x0CC >> 2) | ||
269 | +#define GPIO_QRST_DATA_READ (0x0D0 >> 2) | ||
270 | +#define GPIO_UVWX_DATA_READ (0x0D4 >> 2) | ||
271 | +#define GPIO_YZAAAB_DATA_READ (0x0D8 >> 2) | ||
272 | +#define GPIO_AC_DATA_READ (0x0DC >> 2) | ||
273 | +#define GPIO_MNOP_COMMAND_SRC_0 (0x0E0 >> 2) | ||
274 | +#define GPIO_MNOP_COMMAND_SRC_1 (0x0E4 >> 2) | ||
275 | +#define GPIO_MNOP_INT_ENABLE (0x0E8 >> 2) | ||
276 | +#define GPIO_MNOP_INT_SENS_0 (0x0EC >> 2) | ||
277 | +#define GPIO_MNOP_INT_SENS_1 (0x0F0 >> 2) | ||
278 | +#define GPIO_MNOP_INT_SENS_2 (0x0F4 >> 2) | ||
279 | +#define GPIO_MNOP_INT_STATUS (0x0F8 >> 2) | ||
280 | +#define GPIO_MNOP_RESET_TOLERANT (0x0FC >> 2) | ||
281 | +#define GPIO_MNOP_DEBOUNCE_1 (0x100 >> 2) | ||
282 | +#define GPIO_MNOP_DEBOUNCE_2 (0x104 >> 2) | ||
283 | +#define GPIO_MNOP_INPUT_MASK (0x108 >> 2) | ||
284 | +#define GPIO_QRST_COMMAND_SRC_0 (0x110 >> 2) | ||
285 | +#define GPIO_QRST_COMMAND_SRC_1 (0x114 >> 2) | ||
286 | +#define GPIO_QRST_INT_ENABLE (0x118 >> 2) | ||
287 | +#define GPIO_QRST_INT_SENS_0 (0x11C >> 2) | ||
288 | +#define GPIO_QRST_INT_SENS_1 (0x120 >> 2) | ||
289 | +#define GPIO_QRST_INT_SENS_2 (0x124 >> 2) | ||
290 | +#define GPIO_QRST_INT_STATUS (0x128 >> 2) | ||
291 | +#define GPIO_QRST_RESET_TOLERANT (0x12C >> 2) | ||
292 | +#define GPIO_QRST_DEBOUNCE_1 (0x130 >> 2) | ||
293 | +#define GPIO_QRST_DEBOUNCE_2 (0x134 >> 2) | ||
294 | +#define GPIO_QRST_INPUT_MASK (0x138 >> 2) | ||
295 | +#define GPIO_UVWX_COMMAND_SRC_0 (0x140 >> 2) | ||
296 | +#define GPIO_UVWX_COMMAND_SRC_1 (0x144 >> 2) | ||
297 | +#define GPIO_UVWX_INT_ENABLE (0x148 >> 2) | ||
298 | +#define GPIO_UVWX_INT_SENS_0 (0x14C >> 2) | ||
299 | +#define GPIO_UVWX_INT_SENS_1 (0x150 >> 2) | ||
300 | +#define GPIO_UVWX_INT_SENS_2 (0x154 >> 2) | ||
301 | +#define GPIO_UVWX_INT_STATUS (0x158 >> 2) | ||
302 | +#define GPIO_UVWX_RESET_TOLERANT (0x15C >> 2) | ||
303 | +#define GPIO_UVWX_DEBOUNCE_1 (0x160 >> 2) | ||
304 | +#define GPIO_UVWX_DEBOUNCE_2 (0x164 >> 2) | ||
305 | +#define GPIO_UVWX_INPUT_MASK (0x168 >> 2) | ||
306 | +#define GPIO_YZAAAB_COMMAND_SRC_0 (0x170 >> 2) | ||
307 | +#define GPIO_YZAAAB_COMMAND_SRC_1 (0x174 >> 2) | ||
308 | +#define GPIO_YZAAAB_INT_ENABLE (0x178 >> 2) | ||
309 | +#define GPIO_YZAAAB_INT_SENS_0 (0x17C >> 2) | ||
310 | +#define GPIO_YZAAAB_INT_SENS_1 (0x180 >> 2) | ||
311 | +#define GPIO_YZAAAB_INT_SENS_2 (0x184 >> 2) | ||
312 | +#define GPIO_YZAAAB_INT_STATUS (0x188 >> 2) | ||
313 | +#define GPIO_YZAAAB_RESET_TOLERANT (0x18C >> 2) | ||
314 | +#define GPIO_YZAAAB_DEBOUNCE_1 (0x190 >> 2) | ||
315 | +#define GPIO_YZAAAB_DEBOUNCE_2 (0x194 >> 2) | ||
316 | +#define GPIO_YZAAAB_INPUT_MASK (0x198 >> 2) | ||
317 | +#define GPIO_AC_COMMAND_SRC_0 (0x1A0 >> 2) | ||
318 | +#define GPIO_AC_COMMAND_SRC_1 (0x1A4 >> 2) | ||
319 | +#define GPIO_AC_INT_ENABLE (0x1A8 >> 2) | ||
320 | +#define GPIO_AC_INT_SENS_0 (0x1AC >> 2) | ||
321 | +#define GPIO_AC_INT_SENS_1 (0x1B0 >> 2) | ||
322 | +#define GPIO_AC_INT_SENS_2 (0x1B4 >> 2) | ||
323 | +#define GPIO_AC_INT_STATUS (0x1B8 >> 2) | ||
324 | +#define GPIO_AC_RESET_TOLERANT (0x1BC >> 2) | ||
325 | +#define GPIO_AC_DEBOUNCE_1 (0x1C0 >> 2) | ||
326 | +#define GPIO_AC_DEBOUNCE_2 (0x1C4 >> 2) | ||
327 | +#define GPIO_AC_INPUT_MASK (0x1C8 >> 2) | ||
328 | +#define GPIO_ABCD_INPUT_MASK (0x1D0 >> 2) | ||
329 | +#define GPIO_EFGH_INPUT_MASK (0x1D4 >> 2) | ||
330 | +#define GPIO_YZAAAB_DATA_VALUE (0x1E0 >> 2) | ||
331 | +#define GPIO_YZAAAB_DIRECTION (0x1E4 >> 2) | ||
332 | +#define GPIO_AC_DATA_VALUE (0x1E8 >> 2) | ||
333 | +#define GPIO_AC_DIRECTION (0x1EC >> 2) | ||
334 | +#define GPIO_3_6V_MEM_SIZE 0x1F0 | ||
335 | +#define GPIO_3_6V_REG_ARRAY_SIZE (GPIO_3_6V_MEM_SIZE >> 2) | ||
336 | + | ||
337 | +static int aspeed_evaluate_irq(GPIOSets *regs, int gpio_prev_high, int gpio) | ||
338 | +{ | ||
339 | + uint32_t falling_edge = 0, rising_edge = 0; | ||
340 | + uint32_t int_trigger = extract32(regs->int_sens_0, gpio, 1) | ||
341 | + | extract32(regs->int_sens_1, gpio, 1) << 1 | ||
342 | + | extract32(regs->int_sens_2, gpio, 1) << 2; | ||
343 | + uint32_t gpio_curr_high = extract32(regs->data_value, gpio, 1); | ||
344 | + uint32_t gpio_int_enabled = extract32(regs->int_enable, gpio, 1); | ||
345 | + | ||
346 | + if (!gpio_int_enabled) { | ||
347 | + return 0; | ||
348 | + } | ||
349 | + | ||
350 | + /* Detect edges */ | ||
351 | + if (gpio_curr_high && !gpio_prev_high) { | ||
352 | + rising_edge = 1; | ||
353 | + } else if (!gpio_curr_high && gpio_prev_high) { | ||
354 | + falling_edge = 1; | ||
355 | + } | ||
356 | + | ||
357 | + if (((int_trigger == ASPEED_FALLING_EDGE) && falling_edge) || | ||
358 | + ((int_trigger == ASPEED_RISING_EDGE) && rising_edge) || | ||
359 | + ((int_trigger == ASPEED_LEVEL_LOW) && !gpio_curr_high) || | ||
360 | + ((int_trigger == ASPEED_LEVEL_HIGH) && gpio_curr_high) || | ||
361 | + ((int_trigger >= ASPEED_DUAL_EDGE) && (rising_edge || falling_edge))) | ||
362 | + { | ||
363 | + regs->int_status = deposit32(regs->int_status, gpio, 1, 1); | ||
364 | + return 1; | ||
365 | + } | ||
366 | + return 0; | ||
367 | +} | ||
368 | + | ||
369 | +#define nested_struct_index(ta, pa, m, tb, pb) \ | ||
370 | + (pb - ((tb *)(((char *)pa) + offsetof(ta, m)))) | ||
371 | + | ||
372 | +static ptrdiff_t aspeed_gpio_set_idx(AspeedGPIOState *s, GPIOSets *regs) | ||
373 | +{ | ||
374 | + return nested_struct_index(AspeedGPIOState, s, sets, GPIOSets, regs); | ||
375 | +} | ||
376 | + | ||
377 | +static void aspeed_gpio_update(AspeedGPIOState *s, GPIOSets *regs, | ||
378 | + uint32_t value) | ||
379 | +{ | ||
380 | + uint32_t input_mask = regs->input_mask; | ||
381 | + uint32_t direction = regs->direction; | ||
382 | + uint32_t old = regs->data_value; | ||
383 | + uint32_t new = value; | ||
384 | + uint32_t diff; | ||
385 | + int gpio; | ||
386 | + | ||
387 | + diff = old ^ new; | ||
388 | + if (diff) { | ||
389 | + for (gpio = 0; gpio < GPIOS_PER_REG; gpio++) { | ||
390 | + uint32_t mask = 1 << gpio; | ||
391 | + | ||
392 | + /* If the gpio needs to be updated... */ | ||
393 | + if (!(diff & mask)) { | ||
394 | + continue; | ||
395 | + } | ||
396 | + | ||
397 | + /* ...and we're output or not input-masked... */ | ||
398 | + if (!(direction & mask) && (input_mask & mask)) { | ||
399 | + continue; | ||
400 | + } | ||
401 | + | ||
402 | + /* ...then update the state. */ | ||
403 | + if (mask & new) { | ||
404 | + regs->data_value |= mask; | ||
405 | + } else { | ||
406 | + regs->data_value &= ~mask; | ||
407 | + } | ||
408 | + | ||
409 | + /* If the gpio is set to output... */ | ||
410 | + if (direction & mask) { | ||
411 | + /* ...trigger the line-state IRQ */ | ||
412 | + ptrdiff_t set = aspeed_gpio_set_idx(s, regs); | ||
413 | + size_t offset = set * GPIOS_PER_SET + gpio; | ||
414 | + qemu_set_irq(s->gpios[offset], !!(new & mask)); | ||
415 | + } else { | ||
416 | + /* ...otherwise if we meet the line's current IRQ policy... */ | ||
417 | + if (aspeed_evaluate_irq(regs, old & mask, gpio)) { | ||
418 | + /* ...trigger the VIC IRQ */ | ||
419 | + s->pending++; | ||
420 | + } | ||
421 | + } | ||
422 | + } | ||
423 | + } | ||
424 | + qemu_set_irq(s->irq, !!(s->pending)); | ||
425 | +} | ||
426 | + | ||
427 | +static uint32_t aspeed_adjust_pin(AspeedGPIOState *s, uint32_t pin) | ||
428 | +{ | ||
429 | + AspeedGPIOClass *agc = ASPEED_GPIO_GET_CLASS(s); | ||
430 | + /* | ||
431 | + * The 2500 has a 4 pin gap in group AB and the 2400 has a 4 pin | ||
432 | + * gap in group Y (and only four pins in AB but this is the last group so | ||
433 | + * it doesn't matter). | ||
434 | + */ | ||
435 | + if (agc->gap && pin >= agc->gap) { | ||
436 | + pin += GPIO_PIN_GAP_SIZE; | ||
437 | + } | ||
438 | + | ||
439 | + return pin; | ||
440 | +} | ||
441 | + | ||
442 | +static bool aspeed_gpio_get_pin_level(AspeedGPIOState *s, uint32_t set_idx, | ||
443 | + uint32_t pin) | ||
444 | +{ | ||
445 | + uint32_t reg_val; | ||
446 | + uint32_t pin_mask = 1 << pin; | ||
447 | + | ||
448 | + reg_val = s->sets[set_idx].data_value; | ||
449 | + | ||
450 | + return !!(reg_val & pin_mask); | ||
451 | +} | ||
452 | + | ||
453 | +static void aspeed_gpio_set_pin_level(AspeedGPIOState *s, uint32_t set_idx, | ||
454 | + uint32_t pin, bool level) | ||
455 | +{ | ||
456 | + uint32_t value = s->sets[set_idx].data_value; | ||
457 | + uint32_t pin_mask = 1 << pin; | ||
458 | + | ||
459 | + if (level) { | ||
460 | + value |= pin_mask; | ||
461 | + } else { | ||
462 | + value &= !pin_mask; | ||
463 | + } | ||
464 | + | ||
465 | + aspeed_gpio_update(s, &s->sets[set_idx], value); | ||
466 | +} | ||
467 | + | ||
468 | +/* | ||
469 | + * | src_1 | src_2 | source | | ||
470 | + * |-----------------------------| | ||
471 | + * | 0 | 0 | ARM | | ||
472 | + * | 0 | 1 | LPC | | ||
473 | + * | 1 | 0 | Coprocessor| | ||
474 | + * | 1 | 1 | Reserved | | ||
475 | + * | ||
476 | + * Once the source of a set is programmed, corresponding bits in the | ||
477 | + * data_value, direction, interrupt [enable, sens[0-2]], reset_tol and | ||
478 | + * debounce registers can only be written by the source. | ||
479 | + * | ||
480 | + * Source is ARM by default | ||
481 | + * only bits 24, 16, 8, and 0 can be set | ||
482 | + * | ||
483 | + * we don't currently have a model for the LPC or Coprocessor | ||
484 | + */ | ||
485 | +static uint32_t update_value_control_source(GPIOSets *regs, uint32_t old_value, | ||
486 | + uint32_t value) | ||
487 | +{ | ||
488 | + int i; | ||
489 | + int cmd_source; | ||
490 | + | ||
491 | + /* assume the source is always ARM for now */ | ||
492 | + int source = ASPEED_SOURCE_ARM; | ||
493 | + | ||
494 | + uint32_t new_value = 0; | ||
495 | + | ||
496 | + /* for each group in set */ | ||
497 | + for (i = 0; i < GPIOS_PER_REG; i += GPIOS_PER_GROUP) { | ||
498 | + cmd_source = extract32(regs->cmd_source_0, i, 1) | ||
499 | + | (extract32(regs->cmd_source_1, i, 1) << 1); | ||
500 | + | ||
501 | + if (source == cmd_source) { | ||
502 | + new_value |= (0xff << i) & value; | ||
503 | + } else { | ||
504 | + new_value |= (0xff << i) & old_value; | ||
505 | + } | ||
506 | + } | ||
507 | + return new_value; | ||
508 | +} | ||
509 | + | ||
510 | +static const AspeedGPIOReg aspeed_3_6v_gpios[GPIO_3_6V_REG_ARRAY_SIZE] = { | ||
511 | + /* Set ABCD */ | ||
512 | + [GPIO_ABCD_DATA_VALUE] = { 0, gpio_reg_data_value }, | ||
513 | + [GPIO_ABCD_DIRECTION] = { 0, gpio_reg_direction }, | ||
514 | + [GPIO_ABCD_INT_ENABLE] = { 0, gpio_reg_int_enable }, | ||
515 | + [GPIO_ABCD_INT_SENS_0] = { 0, gpio_reg_int_sens_0 }, | ||
516 | + [GPIO_ABCD_INT_SENS_1] = { 0, gpio_reg_int_sens_1 }, | ||
517 | + [GPIO_ABCD_INT_SENS_2] = { 0, gpio_reg_int_sens_2 }, | ||
518 | + [GPIO_ABCD_INT_STATUS] = { 0, gpio_reg_int_status }, | ||
519 | + [GPIO_ABCD_RESET_TOLERANT] = { 0, gpio_reg_reset_tolerant }, | ||
520 | + [GPIO_ABCD_DEBOUNCE_1] = { 0, gpio_reg_debounce_1 }, | ||
521 | + [GPIO_ABCD_DEBOUNCE_2] = { 0, gpio_reg_debounce_2 }, | ||
522 | + [GPIO_ABCD_COMMAND_SRC_0] = { 0, gpio_reg_cmd_source_0 }, | ||
523 | + [GPIO_ABCD_COMMAND_SRC_1] = { 0, gpio_reg_cmd_source_1 }, | ||
524 | + [GPIO_ABCD_DATA_READ] = { 0, gpio_reg_data_read }, | ||
525 | + [GPIO_ABCD_INPUT_MASK] = { 0, gpio_reg_input_mask }, | ||
526 | + /* Set EFGH */ | ||
527 | + [GPIO_EFGH_DATA_VALUE] = { 1, gpio_reg_data_value }, | ||
528 | + [GPIO_EFGH_DIRECTION] = { 1, gpio_reg_direction }, | ||
529 | + [GPIO_EFGH_INT_ENABLE] = { 1, gpio_reg_int_enable }, | ||
530 | + [GPIO_EFGH_INT_SENS_0] = { 1, gpio_reg_int_sens_0 }, | ||
531 | + [GPIO_EFGH_INT_SENS_1] = { 1, gpio_reg_int_sens_1 }, | ||
532 | + [GPIO_EFGH_INT_SENS_2] = { 1, gpio_reg_int_sens_2 }, | ||
533 | + [GPIO_EFGH_INT_STATUS] = { 1, gpio_reg_int_status }, | ||
534 | + [GPIO_EFGH_RESET_TOLERANT] = { 1, gpio_reg_reset_tolerant }, | ||
535 | + [GPIO_EFGH_DEBOUNCE_1] = { 1, gpio_reg_debounce_1 }, | ||
536 | + [GPIO_EFGH_DEBOUNCE_2] = { 1, gpio_reg_debounce_2 }, | ||
537 | + [GPIO_EFGH_COMMAND_SRC_0] = { 1, gpio_reg_cmd_source_0 }, | ||
538 | + [GPIO_EFGH_COMMAND_SRC_1] = { 1, gpio_reg_cmd_source_1 }, | ||
539 | + [GPIO_EFGH_DATA_READ] = { 1, gpio_reg_data_read }, | ||
540 | + [GPIO_EFGH_INPUT_MASK] = { 1, gpio_reg_input_mask }, | ||
541 | + /* Set IJKL */ | ||
542 | + [GPIO_IJKL_DATA_VALUE] = { 2, gpio_reg_data_value }, | ||
543 | + [GPIO_IJKL_DIRECTION] = { 2, gpio_reg_direction }, | ||
544 | + [GPIO_IJKL_INT_ENABLE] = { 2, gpio_reg_int_enable }, | ||
545 | + [GPIO_IJKL_INT_SENS_0] = { 2, gpio_reg_int_sens_0 }, | ||
546 | + [GPIO_IJKL_INT_SENS_1] = { 2, gpio_reg_int_sens_1 }, | ||
547 | + [GPIO_IJKL_INT_SENS_2] = { 2, gpio_reg_int_sens_2 }, | ||
548 | + [GPIO_IJKL_INT_STATUS] = { 2, gpio_reg_int_status }, | ||
549 | + [GPIO_IJKL_RESET_TOLERANT] = { 2, gpio_reg_reset_tolerant }, | ||
550 | + [GPIO_IJKL_DEBOUNCE_1] = { 2, gpio_reg_debounce_1 }, | ||
551 | + [GPIO_IJKL_DEBOUNCE_2] = { 2, gpio_reg_debounce_2 }, | ||
552 | + [GPIO_IJKL_COMMAND_SRC_0] = { 2, gpio_reg_cmd_source_0 }, | ||
553 | + [GPIO_IJKL_COMMAND_SRC_1] = { 2, gpio_reg_cmd_source_1 }, | ||
554 | + [GPIO_IJKL_DATA_READ] = { 2, gpio_reg_data_read }, | ||
555 | + [GPIO_IJKL_INPUT_MASK] = { 2, gpio_reg_input_mask }, | ||
556 | + /* Set MNOP */ | ||
557 | + [GPIO_MNOP_DATA_VALUE] = { 3, gpio_reg_data_value }, | ||
558 | + [GPIO_MNOP_DIRECTION] = { 3, gpio_reg_direction }, | ||
559 | + [GPIO_MNOP_INT_ENABLE] = { 3, gpio_reg_int_enable }, | ||
560 | + [GPIO_MNOP_INT_SENS_0] = { 3, gpio_reg_int_sens_0 }, | ||
561 | + [GPIO_MNOP_INT_SENS_1] = { 3, gpio_reg_int_sens_1 }, | ||
562 | + [GPIO_MNOP_INT_SENS_2] = { 3, gpio_reg_int_sens_2 }, | ||
563 | + [GPIO_MNOP_INT_STATUS] = { 3, gpio_reg_int_status }, | ||
564 | + [GPIO_MNOP_RESET_TOLERANT] = { 3, gpio_reg_reset_tolerant }, | ||
565 | + [GPIO_MNOP_DEBOUNCE_1] = { 3, gpio_reg_debounce_1 }, | ||
566 | + [GPIO_MNOP_DEBOUNCE_2] = { 3, gpio_reg_debounce_2 }, | ||
567 | + [GPIO_MNOP_COMMAND_SRC_0] = { 3, gpio_reg_cmd_source_0 }, | ||
568 | + [GPIO_MNOP_COMMAND_SRC_1] = { 3, gpio_reg_cmd_source_1 }, | ||
569 | + [GPIO_MNOP_DATA_READ] = { 3, gpio_reg_data_read }, | ||
570 | + [GPIO_MNOP_INPUT_MASK] = { 3, gpio_reg_input_mask }, | ||
571 | + /* Set QRST */ | ||
572 | + [GPIO_QRST_DATA_VALUE] = { 4, gpio_reg_data_value }, | ||
573 | + [GPIO_QRST_DIRECTION] = { 4, gpio_reg_direction }, | ||
574 | + [GPIO_QRST_INT_ENABLE] = { 4, gpio_reg_int_enable }, | ||
575 | + [GPIO_QRST_INT_SENS_0] = { 4, gpio_reg_int_sens_0 }, | ||
576 | + [GPIO_QRST_INT_SENS_1] = { 4, gpio_reg_int_sens_1 }, | ||
577 | + [GPIO_QRST_INT_SENS_2] = { 4, gpio_reg_int_sens_2 }, | ||
578 | + [GPIO_QRST_INT_STATUS] = { 4, gpio_reg_int_status }, | ||
579 | + [GPIO_QRST_RESET_TOLERANT] = { 4, gpio_reg_reset_tolerant }, | ||
580 | + [GPIO_QRST_DEBOUNCE_1] = { 4, gpio_reg_debounce_1 }, | ||
581 | + [GPIO_QRST_DEBOUNCE_2] = { 4, gpio_reg_debounce_2 }, | ||
582 | + [GPIO_QRST_COMMAND_SRC_0] = { 4, gpio_reg_cmd_source_0 }, | ||
583 | + [GPIO_QRST_COMMAND_SRC_1] = { 4, gpio_reg_cmd_source_1 }, | ||
584 | + [GPIO_QRST_DATA_READ] = { 4, gpio_reg_data_read }, | ||
585 | + [GPIO_QRST_INPUT_MASK] = { 4, gpio_reg_input_mask }, | ||
586 | + /* Set UVWX */ | ||
587 | + [GPIO_UVWX_DATA_VALUE] = { 5, gpio_reg_data_value }, | ||
588 | + [GPIO_UVWX_DIRECTION] = { 5, gpio_reg_direction }, | ||
589 | + [GPIO_UVWX_INT_ENABLE] = { 5, gpio_reg_int_enable }, | ||
590 | + [GPIO_UVWX_INT_SENS_0] = { 5, gpio_reg_int_sens_0 }, | ||
591 | + [GPIO_UVWX_INT_SENS_1] = { 5, gpio_reg_int_sens_1 }, | ||
592 | + [GPIO_UVWX_INT_SENS_2] = { 5, gpio_reg_int_sens_2 }, | ||
593 | + [GPIO_UVWX_INT_STATUS] = { 5, gpio_reg_int_status }, | ||
594 | + [GPIO_UVWX_RESET_TOLERANT] = { 5, gpio_reg_reset_tolerant }, | ||
595 | + [GPIO_UVWX_DEBOUNCE_1] = { 5, gpio_reg_debounce_1 }, | ||
596 | + [GPIO_UVWX_DEBOUNCE_2] = { 5, gpio_reg_debounce_2 }, | ||
597 | + [GPIO_UVWX_COMMAND_SRC_0] = { 5, gpio_reg_cmd_source_0 }, | ||
598 | + [GPIO_UVWX_COMMAND_SRC_1] = { 5, gpio_reg_cmd_source_1 }, | ||
599 | + [GPIO_UVWX_DATA_READ] = { 5, gpio_reg_data_read }, | ||
600 | + [GPIO_UVWX_INPUT_MASK] = { 5, gpio_reg_input_mask }, | ||
601 | + /* Set YZAAAB */ | ||
602 | + [GPIO_YZAAAB_DATA_VALUE] = { 6, gpio_reg_data_value }, | ||
603 | + [GPIO_YZAAAB_DIRECTION] = { 6, gpio_reg_direction }, | ||
604 | + [GPIO_YZAAAB_INT_ENABLE] = { 6, gpio_reg_int_enable }, | ||
605 | + [GPIO_YZAAAB_INT_SENS_0] = { 6, gpio_reg_int_sens_0 }, | ||
606 | + [GPIO_YZAAAB_INT_SENS_1] = { 6, gpio_reg_int_sens_1 }, | ||
607 | + [GPIO_YZAAAB_INT_SENS_2] = { 6, gpio_reg_int_sens_2 }, | ||
608 | + [GPIO_YZAAAB_INT_STATUS] = { 6, gpio_reg_int_status }, | ||
609 | + [GPIO_YZAAAB_RESET_TOLERANT] = { 6, gpio_reg_reset_tolerant }, | ||
610 | + [GPIO_YZAAAB_DEBOUNCE_1] = { 6, gpio_reg_debounce_1 }, | ||
611 | + [GPIO_YZAAAB_DEBOUNCE_2] = { 6, gpio_reg_debounce_2 }, | ||
612 | + [GPIO_YZAAAB_COMMAND_SRC_0] = { 6, gpio_reg_cmd_source_0 }, | ||
613 | + [GPIO_YZAAAB_COMMAND_SRC_1] = { 6, gpio_reg_cmd_source_1 }, | ||
614 | + [GPIO_YZAAAB_DATA_READ] = { 6, gpio_reg_data_read }, | ||
615 | + [GPIO_YZAAAB_INPUT_MASK] = { 6, gpio_reg_input_mask }, | ||
616 | + /* Set AC (ast2500 only) */ | ||
617 | + [GPIO_AC_DATA_VALUE] = { 7, gpio_reg_data_value }, | ||
618 | + [GPIO_AC_DIRECTION] = { 7, gpio_reg_direction }, | ||
619 | + [GPIO_AC_INT_ENABLE] = { 7, gpio_reg_int_enable }, | ||
620 | + [GPIO_AC_INT_SENS_0] = { 7, gpio_reg_int_sens_0 }, | ||
621 | + [GPIO_AC_INT_SENS_1] = { 7, gpio_reg_int_sens_1 }, | ||
622 | + [GPIO_AC_INT_SENS_2] = { 7, gpio_reg_int_sens_2 }, | ||
623 | + [GPIO_AC_INT_STATUS] = { 7, gpio_reg_int_status }, | ||
624 | + [GPIO_AC_RESET_TOLERANT] = { 7, gpio_reg_reset_tolerant }, | ||
625 | + [GPIO_AC_DEBOUNCE_1] = { 7, gpio_reg_debounce_1 }, | ||
626 | + [GPIO_AC_DEBOUNCE_2] = { 7, gpio_reg_debounce_2 }, | ||
627 | + [GPIO_AC_COMMAND_SRC_0] = { 7, gpio_reg_cmd_source_0 }, | ||
628 | + [GPIO_AC_COMMAND_SRC_1] = { 7, gpio_reg_cmd_source_1 }, | ||
629 | + [GPIO_AC_DATA_READ] = { 7, gpio_reg_data_read }, | ||
630 | + [GPIO_AC_INPUT_MASK] = { 7, gpio_reg_input_mask }, | ||
631 | +}; | 230 | +}; |
632 | + | 231 | + |
633 | +static uint64_t aspeed_gpio_read(void *opaque, hwaddr offset, uint32_t size) | 232 | +static void fsl_imx8m_pcie_phy_realize(DeviceState *dev, Error **errp) |
634 | +{ | 233 | +{ |
635 | + AspeedGPIOState *s = ASPEED_GPIO(opaque); | 234 | + FslImx8mPciePhyState *s = FSL_IMX8M_PCIE_PHY(dev); |
636 | + AspeedGPIOClass *agc = ASPEED_GPIO_GET_CLASS(s); | 235 | + |
637 | + uint64_t idx = -1; | 236 | + memory_region_init_io(&s->iomem, OBJECT(s), &fsl_imx8m_pcie_phy_ops, s, |
638 | + const AspeedGPIOReg *reg; | 237 | + TYPE_FSL_IMX8M_PCIE_PHY, ARRAY_SIZE(s->data)); |
639 | + GPIOSets *set; | 238 | + sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->iomem); |
640 | + | 239 | +} |
641 | + idx = offset >> 2; | 240 | + |
642 | + if (idx >= GPIO_DEBOUNCE_TIME_1 && idx <= GPIO_DEBOUNCE_TIME_3) { | 241 | +static void fsl_imx8m_pcie_phy_reset_hold(Object *obj, ResetType type) |
643 | + idx -= GPIO_DEBOUNCE_TIME_1; | 242 | +{ |
644 | + return (uint64_t) s->debounce_regs[idx]; | 243 | + FslImx8mPciePhyState *s = FSL_IMX8M_PCIE_PHY(obj); |
645 | + } | 244 | + |
646 | + | 245 | + memset(s->data, 0, sizeof(s->data)); |
647 | + reg = &agc->reg_table[idx]; | 246 | +} |
648 | + if (reg->set_idx >= agc->nr_gpio_sets) { | 247 | + |
649 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: no getter for offset 0x%" | 248 | +static const VMStateDescription fsl_imx8m_pcie_phy_vmstate = { |
650 | + HWADDR_PRIx"\n", __func__, offset); | 249 | + .name = "fsl-imx8m-pcie-phy", |
651 | + return 0; | ||
652 | + } | ||
653 | + | ||
654 | + set = &s->sets[reg->set_idx]; | ||
655 | + switch (reg->type) { | ||
656 | + case gpio_reg_data_value: | ||
657 | + return set->data_value; | ||
658 | + case gpio_reg_direction: | ||
659 | + return set->direction; | ||
660 | + case gpio_reg_int_enable: | ||
661 | + return set->int_enable; | ||
662 | + case gpio_reg_int_sens_0: | ||
663 | + return set->int_sens_0; | ||
664 | + case gpio_reg_int_sens_1: | ||
665 | + return set->int_sens_1; | ||
666 | + case gpio_reg_int_sens_2: | ||
667 | + return set->int_sens_2; | ||
668 | + case gpio_reg_int_status: | ||
669 | + return set->int_status; | ||
670 | + case gpio_reg_reset_tolerant: | ||
671 | + return set->reset_tol; | ||
672 | + case gpio_reg_debounce_1: | ||
673 | + return set->debounce_1; | ||
674 | + case gpio_reg_debounce_2: | ||
675 | + return set->debounce_2; | ||
676 | + case gpio_reg_cmd_source_0: | ||
677 | + return set->cmd_source_0; | ||
678 | + case gpio_reg_cmd_source_1: | ||
679 | + return set->cmd_source_1; | ||
680 | + case gpio_reg_data_read: | ||
681 | + return set->data_read; | ||
682 | + case gpio_reg_input_mask: | ||
683 | + return set->input_mask; | ||
684 | + default: | ||
685 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: no getter for offset 0x%" | ||
686 | + HWADDR_PRIx"\n", __func__, offset); | ||
687 | + return 0; | ||
688 | + }; | ||
689 | +} | ||
690 | + | ||
691 | +static void aspeed_gpio_write(void *opaque, hwaddr offset, uint64_t data, | ||
692 | + uint32_t size) | ||
693 | +{ | ||
694 | + AspeedGPIOState *s = ASPEED_GPIO(opaque); | ||
695 | + AspeedGPIOClass *agc = ASPEED_GPIO_GET_CLASS(s); | ||
696 | + const GPIOSetProperties *props; | ||
697 | + uint64_t idx = -1; | ||
698 | + const AspeedGPIOReg *reg; | ||
699 | + GPIOSets *set; | ||
700 | + uint32_t cleared; | ||
701 | + | ||
702 | + idx = offset >> 2; | ||
703 | + if (idx >= GPIO_DEBOUNCE_TIME_1 && idx <= GPIO_DEBOUNCE_TIME_3) { | ||
704 | + idx -= GPIO_DEBOUNCE_TIME_1; | ||
705 | + s->debounce_regs[idx] = (uint32_t) data; | ||
706 | + return; | ||
707 | + } | ||
708 | + | ||
709 | + reg = &agc->reg_table[idx]; | ||
710 | + if (reg->set_idx >= agc->nr_gpio_sets) { | ||
711 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: no setter for offset 0x%" | ||
712 | + HWADDR_PRIx"\n", __func__, offset); | ||
713 | + return; | ||
714 | + } | ||
715 | + | ||
716 | + set = &s->sets[reg->set_idx]; | ||
717 | + props = &agc->props[reg->set_idx]; | ||
718 | + | ||
719 | + switch (reg->type) { | ||
720 | + case gpio_reg_data_value: | ||
721 | + data &= props->output; | ||
722 | + data = update_value_control_source(set, set->data_value, data); | ||
723 | + set->data_read = data; | ||
724 | + aspeed_gpio_update(s, set, data); | ||
725 | + return; | ||
726 | + case gpio_reg_direction: | ||
727 | + /* | ||
728 | + * where data is the value attempted to be written to the pin: | ||
729 | + * pin type | input mask | output mask | expected value | ||
730 | + * ------------------------------------------------------------ | ||
731 | + * bidirectional | 1 | 1 | data | ||
732 | + * input only | 1 | 0 | 0 | ||
733 | + * output only | 0 | 1 | 1 | ||
734 | + * no pin / gap | 0 | 0 | 0 | ||
735 | + * | ||
736 | + * which is captured by: | ||
737 | + * data = ( data | ~input) & output; | ||
738 | + */ | ||
739 | + data = (data | ~props->input) & props->output; | ||
740 | + set->direction = update_value_control_source(set, set->direction, data); | ||
741 | + break; | ||
742 | + case gpio_reg_int_enable: | ||
743 | + set->int_enable = update_value_control_source(set, set->int_enable, | ||
744 | + data); | ||
745 | + break; | ||
746 | + case gpio_reg_int_sens_0: | ||
747 | + set->int_sens_0 = update_value_control_source(set, set->int_sens_0, | ||
748 | + data); | ||
749 | + break; | ||
750 | + case gpio_reg_int_sens_1: | ||
751 | + set->int_sens_1 = update_value_control_source(set, set->int_sens_1, | ||
752 | + data); | ||
753 | + break; | ||
754 | + case gpio_reg_int_sens_2: | ||
755 | + set->int_sens_2 = update_value_control_source(set, set->int_sens_2, | ||
756 | + data); | ||
757 | + break; | ||
758 | + case gpio_reg_int_status: | ||
759 | + cleared = ctpop32(data & set->int_status); | ||
760 | + if (s->pending && cleared) { | ||
761 | + assert(s->pending >= cleared); | ||
762 | + s->pending -= cleared; | ||
763 | + } | ||
764 | + set->int_status &= ~data; | ||
765 | + break; | ||
766 | + case gpio_reg_reset_tolerant: | ||
767 | + set->reset_tol = update_value_control_source(set, set->reset_tol, | ||
768 | + data); | ||
769 | + return; | ||
770 | + case gpio_reg_debounce_1: | ||
771 | + set->debounce_1 = update_value_control_source(set, set->debounce_1, | ||
772 | + data); | ||
773 | + return; | ||
774 | + case gpio_reg_debounce_2: | ||
775 | + set->debounce_2 = update_value_control_source(set, set->debounce_2, | ||
776 | + data); | ||
777 | + return; | ||
778 | + case gpio_reg_cmd_source_0: | ||
779 | + set->cmd_source_0 = data & ASPEED_CMD_SRC_MASK; | ||
780 | + return; | ||
781 | + case gpio_reg_cmd_source_1: | ||
782 | + set->cmd_source_1 = data & ASPEED_CMD_SRC_MASK; | ||
783 | + return; | ||
784 | + case gpio_reg_data_read: | ||
785 | + /* Read only register */ | ||
786 | + return; | ||
787 | + case gpio_reg_input_mask: | ||
788 | + /* | ||
789 | + * feeds into interrupt generation | ||
790 | + * 0: read from data value reg will be updated | ||
791 | + * 1: read from data value reg will not be updated | ||
792 | + */ | ||
793 | + set->input_mask = data & props->input; | ||
794 | + break; | ||
795 | + default: | ||
796 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: no setter for offset 0x%" | ||
797 | + HWADDR_PRIx"\n", __func__, offset); | ||
798 | + return; | ||
799 | + } | ||
800 | + aspeed_gpio_update(s, set, set->data_value); | ||
801 | + return; | ||
802 | +} | ||
803 | + | ||
804 | +static int get_set_idx(AspeedGPIOState *s, const char *group, int *group_idx) | ||
805 | +{ | ||
806 | + AspeedGPIOClass *agc = ASPEED_GPIO_GET_CLASS(s); | ||
807 | + int set_idx, g_idx = *group_idx; | ||
808 | + | ||
809 | + for (set_idx = 0; set_idx < agc->nr_gpio_sets; set_idx++) { | ||
810 | + const GPIOSetProperties *set_props = &agc->props[set_idx]; | ||
811 | + for (g_idx = 0; g_idx < ASPEED_GROUPS_PER_SET; g_idx++) { | ||
812 | + if (!strncmp(group, set_props->group_label[g_idx], strlen(group))) { | ||
813 | + *group_idx = g_idx; | ||
814 | + return set_idx; | ||
815 | + } | ||
816 | + } | ||
817 | + } | ||
818 | + return -1; | ||
819 | +} | ||
820 | + | ||
821 | +static void aspeed_gpio_get_pin(Object *obj, Visitor *v, const char *name, | ||
822 | + void *opaque, Error **errp) | ||
823 | +{ | ||
824 | + int pin = 0xfff; | ||
825 | + bool level = true; | ||
826 | + char group[3]; | ||
827 | + AspeedGPIOState *s = ASPEED_GPIO(obj); | ||
828 | + int set_idx, group_idx = 0; | ||
829 | + | ||
830 | + if (sscanf(name, "gpio%2[A-Z]%1d", group, &pin) != 2) { | ||
831 | + error_setg(errp, "%s: error reading %s", __func__, name); | ||
832 | + return; | ||
833 | + } | ||
834 | + set_idx = get_set_idx(s, group, &group_idx); | ||
835 | + if (set_idx == -1) { | ||
836 | + error_setg(errp, "%s: invalid group %s", __func__, group); | ||
837 | + return; | ||
838 | + } | ||
839 | + pin = pin + group_idx * GPIOS_PER_GROUP; | ||
840 | + level = aspeed_gpio_get_pin_level(s, set_idx, pin); | ||
841 | + visit_type_bool(v, name, &level, errp); | ||
842 | +} | ||
843 | + | ||
844 | +static void aspeed_gpio_set_pin(Object *obj, Visitor *v, const char *name, | ||
845 | + void *opaque, Error **errp) | ||
846 | +{ | ||
847 | + Error *local_err = NULL; | ||
848 | + bool level; | ||
849 | + int pin = 0xfff; | ||
850 | + char group[3]; | ||
851 | + AspeedGPIOState *s = ASPEED_GPIO(obj); | ||
852 | + int set_idx, group_idx = 0; | ||
853 | + | ||
854 | + visit_type_bool(v, name, &level, &local_err); | ||
855 | + if (local_err) { | ||
856 | + error_propagate(errp, local_err); | ||
857 | + return; | ||
858 | + } | ||
859 | + if (sscanf(name, "gpio%2[A-Z]%1d", group, &pin) != 2) { | ||
860 | + error_setg(errp, "%s: error reading %s", __func__, name); | ||
861 | + return; | ||
862 | + } | ||
863 | + set_idx = get_set_idx(s, group, &group_idx); | ||
864 | + if (set_idx == -1) { | ||
865 | + error_setg(errp, "%s: invalid group %s", __func__, group); | ||
866 | + return; | ||
867 | + } | ||
868 | + pin = pin + group_idx * GPIOS_PER_GROUP; | ||
869 | + aspeed_gpio_set_pin_level(s, set_idx, pin, level); | ||
870 | +} | ||
871 | + | ||
872 | +/****************** Setup functions ******************/ | ||
873 | +static const GPIOSetProperties ast2400_set_props[] = { | ||
874 | + [0] = {0xffffffff, 0xffffffff, {"A", "B", "C", "D"} }, | ||
875 | + [1] = {0xffffffff, 0xffffffff, {"E", "F", "G", "H"} }, | ||
876 | + [2] = {0xffffffff, 0xffffffff, {"I", "J", "K", "L"} }, | ||
877 | + [3] = {0xffffffff, 0xffffffff, {"M", "N", "O", "P"} }, | ||
878 | + [4] = {0xffffffff, 0xffffffff, {"Q", "R", "S", "T"} }, | ||
879 | + [5] = {0xffffffff, 0x0000ffff, {"U", "V", "W", "X"} }, | ||
880 | + [6] = {0x0000000f, 0x0fffff0f, {"Y", "Z", "AA", "AB"} }, | ||
881 | +}; | ||
882 | + | ||
883 | +static const GPIOSetProperties ast2500_set_props[] = { | ||
884 | + [0] = {0xffffffff, 0xffffffff, {"A", "B", "C", "D"} }, | ||
885 | + [1] = {0xffffffff, 0xffffffff, {"E", "F", "G", "H"} }, | ||
886 | + [2] = {0xffffffff, 0xffffffff, {"I", "J", "K", "L"} }, | ||
887 | + [3] = {0xffffffff, 0xffffffff, {"M", "N", "O", "P"} }, | ||
888 | + [4] = {0xffffffff, 0xffffffff, {"Q", "R", "S", "T"} }, | ||
889 | + [5] = {0xffffffff, 0x0000ffff, {"U", "V", "W", "X"} }, | ||
890 | + [6] = {0xffffff0f, 0x0fffff0f, {"Y", "Z", "AA", "AB"} }, | ||
891 | + [7] = {0x000000ff, 0x000000ff, {"AC"} }, | ||
892 | +}; | ||
893 | + | ||
894 | +static const MemoryRegionOps aspeed_gpio_ops = { | ||
895 | + .read = aspeed_gpio_read, | ||
896 | + .write = aspeed_gpio_write, | ||
897 | + .endianness = DEVICE_LITTLE_ENDIAN, | ||
898 | + .valid.min_access_size = 4, | ||
899 | + .valid.max_access_size = 4, | ||
900 | +}; | ||
901 | + | ||
902 | +static void aspeed_gpio_reset(DeviceState *dev) | ||
903 | +{ | ||
904 | + AspeedGPIOState *s = ASPEED_GPIO(dev); | ||
905 | + | ||
906 | + /* TODO: respect the reset tolerance registers */ | ||
907 | + memset(s->sets, 0, sizeof(s->sets)); | ||
908 | +} | ||
909 | + | ||
910 | +static void aspeed_gpio_realize(DeviceState *dev, Error **errp) | ||
911 | +{ | ||
912 | + AspeedGPIOState *s = ASPEED_GPIO(dev); | ||
913 | + SysBusDevice *sbd = SYS_BUS_DEVICE(dev); | ||
914 | + AspeedGPIOClass *agc = ASPEED_GPIO_GET_CLASS(s); | ||
915 | + int pin; | ||
916 | + | ||
917 | + /* Interrupt parent line */ | ||
918 | + sysbus_init_irq(sbd, &s->irq); | ||
919 | + | ||
920 | + /* Individual GPIOs */ | ||
921 | + for (pin = 0; pin < agc->nr_gpio_pins; pin++) { | ||
922 | + sysbus_init_irq(sbd, &s->gpios[pin]); | ||
923 | + } | ||
924 | + | ||
925 | + memory_region_init_io(&s->iomem, OBJECT(s), &aspeed_gpio_ops, s, | ||
926 | + TYPE_ASPEED_GPIO, GPIO_3_6V_MEM_SIZE); | ||
927 | + | ||
928 | + sysbus_init_mmio(sbd, &s->iomem); | ||
929 | +} | ||
930 | + | ||
931 | +static void aspeed_gpio_init(Object *obj) | ||
932 | +{ | ||
933 | + AspeedGPIOState *s = ASPEED_GPIO(obj); | ||
934 | + AspeedGPIOClass *agc = ASPEED_GPIO_GET_CLASS(s); | ||
935 | + int pin; | ||
936 | + | ||
937 | + for (pin = 0; pin < agc->nr_gpio_pins; pin++) { | ||
938 | + char *name; | ||
939 | + int set_idx = pin / GPIOS_PER_SET; | ||
940 | + int pin_idx = aspeed_adjust_pin(s, pin) - (set_idx * GPIOS_PER_SET); | ||
941 | + int group_idx = pin_idx >> GPIO_GROUP_SHIFT; | ||
942 | + const GPIOSetProperties *props = &agc->props[set_idx]; | ||
943 | + | ||
944 | + name = g_strdup_printf("gpio%s%d", props->group_label[group_idx], | ||
945 | + pin_idx % GPIOS_PER_GROUP); | ||
946 | + object_property_add(obj, name, "bool", aspeed_gpio_get_pin, | ||
947 | + aspeed_gpio_set_pin, NULL, NULL, NULL); | ||
948 | + } | ||
949 | +} | ||
950 | + | ||
951 | +static const VMStateDescription vmstate_gpio_regs = { | ||
952 | + .name = TYPE_ASPEED_GPIO"/regs", | ||
953 | + .version_id = 1, | 250 | + .version_id = 1, |
954 | + .minimum_version_id = 1, | 251 | + .minimum_version_id = 1, |
955 | + .fields = (VMStateField[]) { | 252 | + .fields = (const VMStateField[]) { |
956 | + VMSTATE_UINT32(data_value, GPIOSets), | 253 | + VMSTATE_UINT8_ARRAY(data, FslImx8mPciePhyState, |
957 | + VMSTATE_UINT32(data_read, GPIOSets), | 254 | + FSL_IMX8M_PCIE_PHY_DATA_SIZE), |
958 | + VMSTATE_UINT32(direction, GPIOSets), | 255 | + VMSTATE_END_OF_LIST() |
959 | + VMSTATE_UINT32(int_enable, GPIOSets), | ||
960 | + VMSTATE_UINT32(int_sens_0, GPIOSets), | ||
961 | + VMSTATE_UINT32(int_sens_1, GPIOSets), | ||
962 | + VMSTATE_UINT32(int_sens_2, GPIOSets), | ||
963 | + VMSTATE_UINT32(int_status, GPIOSets), | ||
964 | + VMSTATE_UINT32(reset_tol, GPIOSets), | ||
965 | + VMSTATE_UINT32(cmd_source_0, GPIOSets), | ||
966 | + VMSTATE_UINT32(cmd_source_1, GPIOSets), | ||
967 | + VMSTATE_UINT32(debounce_1, GPIOSets), | ||
968 | + VMSTATE_UINT32(debounce_2, GPIOSets), | ||
969 | + VMSTATE_UINT32(input_mask, GPIOSets), | ||
970 | + VMSTATE_END_OF_LIST(), | ||
971 | + } | 256 | + } |
972 | +}; | 257 | +}; |
973 | + | 258 | + |
974 | +static const VMStateDescription vmstate_aspeed_gpio = { | 259 | +static void fsl_imx8m_pcie_phy_class_init(ObjectClass *klass, void *data) |
975 | + .name = TYPE_ASPEED_GPIO, | 260 | +{ |
976 | + .version_id = 1, | 261 | + DeviceClass *dc = DEVICE_CLASS(klass); |
977 | + .minimum_version_id = 1, | 262 | + ResettableClass *rc = RESETTABLE_CLASS(klass); |
978 | + .fields = (VMStateField[]) { | 263 | + |
979 | + VMSTATE_STRUCT_ARRAY(sets, AspeedGPIOState, ASPEED_GPIO_MAX_NR_SETS, | 264 | + dc->realize = fsl_imx8m_pcie_phy_realize; |
980 | + 1, vmstate_gpio_regs, GPIOSets), | 265 | + dc->vmsd = &fsl_imx8m_pcie_phy_vmstate; |
981 | + VMSTATE_UINT32_ARRAY(debounce_regs, AspeedGPIOState, | 266 | + rc->phases.hold = fsl_imx8m_pcie_phy_reset_hold; |
982 | + ASPEED_GPIO_NR_DEBOUNCE_REGS), | 267 | +} |
983 | + VMSTATE_END_OF_LIST(), | 268 | + |
984 | + } | 269 | +static const TypeInfo fsl_imx8m_pcie_phy_types[] = { |
270 | + { | ||
271 | + .name = TYPE_FSL_IMX8M_PCIE_PHY, | ||
272 | + .parent = TYPE_SYS_BUS_DEVICE, | ||
273 | + .instance_size = sizeof(FslImx8mPciePhyState), | ||
274 | + .class_init = fsl_imx8m_pcie_phy_class_init, | ||
275 | + } | ||
985 | +}; | 276 | +}; |
986 | + | 277 | + |
987 | +static void aspeed_gpio_class_init(ObjectClass *klass, void *data) | 278 | +DEFINE_TYPES(fsl_imx8m_pcie_phy_types) |
988 | +{ | 279 | diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig |
989 | + DeviceClass *dc = DEVICE_CLASS(klass); | 280 | index XXXXXXX..XXXXXXX 100644 |
990 | + | 281 | --- a/hw/arm/Kconfig |
991 | + dc->realize = aspeed_gpio_realize; | 282 | +++ b/hw/arm/Kconfig |
992 | + dc->reset = aspeed_gpio_reset; | 283 | @@ -XXX,XX +XXX,XX @@ config FSL_IMX7 |
993 | + dc->desc = "Aspeed GPIO Controller"; | 284 | |
994 | + dc->vmsd = &vmstate_aspeed_gpio; | 285 | config FSL_IMX8MP |
995 | +} | 286 | bool |
996 | + | 287 | + imply PCI_DEVICES |
997 | +static void aspeed_gpio_ast2400_class_init(ObjectClass *klass, void *data) | 288 | select ARM_GIC |
998 | +{ | 289 | select FSL_IMX8MP_ANALOG |
999 | + AspeedGPIOClass *agc = ASPEED_GPIO_CLASS(klass); | 290 | select FSL_IMX8MP_CCM |
1000 | + | 291 | select IMX |
1001 | + agc->props = ast2400_set_props; | 292 | + select PCI_EXPRESS_DESIGNWARE |
1002 | + agc->nr_gpio_pins = 216; | 293 | + select PCI_EXPRESS_FSL_IMX8M_PHY |
1003 | + agc->nr_gpio_sets = 7; | 294 | select SDHCI |
1004 | + agc->gap = 196; | 295 | select UNIMP |
1005 | + agc->reg_table = aspeed_3_6v_gpios; | 296 | |
1006 | +} | 297 | diff --git a/hw/pci-host/Kconfig b/hw/pci-host/Kconfig |
1007 | + | 298 | index XXXXXXX..XXXXXXX 100644 |
1008 | +static void aspeed_gpio_2500_class_init(ObjectClass *klass, void *data) | 299 | --- a/hw/pci-host/Kconfig |
1009 | +{ | 300 | +++ b/hw/pci-host/Kconfig |
1010 | + AspeedGPIOClass *agc = ASPEED_GPIO_CLASS(klass); | 301 | @@ -XXX,XX +XXX,XX @@ config ASTRO |
1011 | + | 302 | bool |
1012 | + agc->props = ast2500_set_props; | 303 | select PCI |
1013 | + agc->nr_gpio_pins = 228; | 304 | |
1014 | + agc->nr_gpio_sets = 8; | 305 | +config PCI_EXPRESS_FSL_IMX8M_PHY |
1015 | + agc->gap = 220; | 306 | + bool |
1016 | + agc->reg_table = aspeed_3_6v_gpios; | 307 | + |
1017 | +} | 308 | config GT64120 |
1018 | + | 309 | bool |
1019 | +static const TypeInfo aspeed_gpio_info = { | 310 | select PCI |
1020 | + .name = TYPE_ASPEED_GPIO, | 311 | diff --git a/hw/pci-host/meson.build b/hw/pci-host/meson.build |
1021 | + .parent = TYPE_SYS_BUS_DEVICE, | 312 | index XXXXXXX..XXXXXXX 100644 |
1022 | + .instance_size = sizeof(AspeedGPIOState), | 313 | --- a/hw/pci-host/meson.build |
1023 | + .class_size = sizeof(AspeedGPIOClass), | 314 | +++ b/hw/pci-host/meson.build |
1024 | + .class_init = aspeed_gpio_class_init, | 315 | @@ -XXX,XX +XXX,XX @@ pci_ss.add(when: 'CONFIG_ARTICIA', if_true: files('articia.c')) |
1025 | + .abstract = true, | 316 | pci_ss.add(when: 'CONFIG_MV64361', if_true: files('mv64361.c')) |
1026 | +}; | 317 | |
1027 | + | 318 | # ARM devices |
1028 | +static const TypeInfo aspeed_gpio_ast2400_info = { | 319 | +pci_ss.add(when: 'CONFIG_PCI_EXPRESS_FSL_IMX8M_PHY', if_true: files('fsl_imx8m_phy.c')) |
1029 | + .name = TYPE_ASPEED_GPIO "-ast2400", | 320 | pci_ss.add(when: 'CONFIG_VERSATILE_PCI', if_true: files('versatile.c')) |
1030 | + .parent = TYPE_ASPEED_GPIO, | 321 | |
1031 | + .class_init = aspeed_gpio_ast2400_class_init, | 322 | # HPPA devices |
1032 | + .instance_init = aspeed_gpio_init, | ||
1033 | +}; | ||
1034 | + | ||
1035 | +static const TypeInfo aspeed_gpio_ast2500_info = { | ||
1036 | + .name = TYPE_ASPEED_GPIO "-ast2500", | ||
1037 | + .parent = TYPE_ASPEED_GPIO, | ||
1038 | + .class_init = aspeed_gpio_2500_class_init, | ||
1039 | + .instance_init = aspeed_gpio_init, | ||
1040 | +}; | ||
1041 | + | ||
1042 | +static void aspeed_gpio_register_types(void) | ||
1043 | +{ | ||
1044 | + type_register_static(&aspeed_gpio_info); | ||
1045 | + type_register_static(&aspeed_gpio_ast2400_info); | ||
1046 | + type_register_static(&aspeed_gpio_ast2500_info); | ||
1047 | +} | ||
1048 | + | ||
1049 | +type_init(aspeed_gpio_register_types); | ||
1050 | -- | 323 | -- |
1051 | 2.20.1 | 324 | 2.43.0 |
1052 | |||
1053 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Bernhard Beschow <shentey@gmail.com> | ||
1 | 2 | ||
3 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
4 | Signed-off-by: Bernhard Beschow <shentey@gmail.com> | ||
5 | Message-id: 20250223114708.1780-10-shentey@gmail.com | ||
6 | [PMM: drop static const from gpio_table for GCC 7.5] | ||
7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
8 | --- | ||
9 | docs/system/arm/imx8mp-evk.rst | 1 + | ||
10 | include/hw/arm/fsl-imx8mp.h | 14 +++++++++ | ||
11 | hw/arm/fsl-imx8mp.c | 55 ++++++++++++++++++++++++++++++++++ | ||
12 | 3 files changed, 70 insertions(+) | ||
13 | |||
14 | diff --git a/docs/system/arm/imx8mp-evk.rst b/docs/system/arm/imx8mp-evk.rst | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/docs/system/arm/imx8mp-evk.rst | ||
17 | +++ b/docs/system/arm/imx8mp-evk.rst | ||
18 | @@ -XXX,XX +XXX,XX @@ The ``imx8mp-evk`` machine implements the following devices: | ||
19 | * 4 UARTs | ||
20 | * 3 USDHC Storage Controllers | ||
21 | * 1 Designware PCI Express Controller | ||
22 | + * 5 GPIO Controllers | ||
23 | * Secure Non-Volatile Storage (SNVS) including an RTC | ||
24 | * Clock Tree | ||
25 | |||
26 | diff --git a/include/hw/arm/fsl-imx8mp.h b/include/hw/arm/fsl-imx8mp.h | ||
27 | index XXXXXXX..XXXXXXX 100644 | ||
28 | --- a/include/hw/arm/fsl-imx8mp.h | ||
29 | +++ b/include/hw/arm/fsl-imx8mp.h | ||
30 | @@ -XXX,XX +XXX,XX @@ | ||
31 | |||
32 | #include "cpu.h" | ||
33 | #include "hw/char/imx_serial.h" | ||
34 | +#include "hw/gpio/imx_gpio.h" | ||
35 | #include "hw/intc/arm_gicv3_common.h" | ||
36 | #include "hw/misc/imx7_snvs.h" | ||
37 | #include "hw/misc/imx8mp_analog.h" | ||
38 | @@ -XXX,XX +XXX,XX @@ OBJECT_DECLARE_SIMPLE_TYPE(FslImx8mpState, FSL_IMX8MP) | ||
39 | |||
40 | enum FslImx8mpConfiguration { | ||
41 | FSL_IMX8MP_NUM_CPUS = 4, | ||
42 | + FSL_IMX8MP_NUM_GPIOS = 5, | ||
43 | FSL_IMX8MP_NUM_IRQS = 160, | ||
44 | FSL_IMX8MP_NUM_UARTS = 4, | ||
45 | FSL_IMX8MP_NUM_USDHCS = 3, | ||
46 | @@ -XXX,XX +XXX,XX @@ struct FslImx8mpState { | ||
47 | |||
48 | ARMCPU cpu[FSL_IMX8MP_NUM_CPUS]; | ||
49 | GICv3State gic; | ||
50 | + IMXGPIOState gpio[FSL_IMX8MP_NUM_GPIOS]; | ||
51 | IMX8MPCCMState ccm; | ||
52 | IMX8MPAnalogState analog; | ||
53 | IMX7SNVSState snvs; | ||
54 | @@ -XXX,XX +XXX,XX @@ enum FslImx8mpIrqs { | ||
55 | FSL_IMX8MP_UART5_IRQ = 30, | ||
56 | FSL_IMX8MP_UART6_IRQ = 16, | ||
57 | |||
58 | + FSL_IMX8MP_GPIO1_LOW_IRQ = 64, | ||
59 | + FSL_IMX8MP_GPIO1_HIGH_IRQ = 65, | ||
60 | + FSL_IMX8MP_GPIO2_LOW_IRQ = 66, | ||
61 | + FSL_IMX8MP_GPIO2_HIGH_IRQ = 67, | ||
62 | + FSL_IMX8MP_GPIO3_LOW_IRQ = 68, | ||
63 | + FSL_IMX8MP_GPIO3_HIGH_IRQ = 69, | ||
64 | + FSL_IMX8MP_GPIO4_LOW_IRQ = 70, | ||
65 | + FSL_IMX8MP_GPIO4_HIGH_IRQ = 71, | ||
66 | + FSL_IMX8MP_GPIO5_LOW_IRQ = 72, | ||
67 | + FSL_IMX8MP_GPIO5_HIGH_IRQ = 73, | ||
68 | + | ||
69 | FSL_IMX8MP_PCI_INTA_IRQ = 126, | ||
70 | FSL_IMX8MP_PCI_INTB_IRQ = 125, | ||
71 | FSL_IMX8MP_PCI_INTC_IRQ = 124, | ||
72 | diff --git a/hw/arm/fsl-imx8mp.c b/hw/arm/fsl-imx8mp.c | ||
73 | index XXXXXXX..XXXXXXX 100644 | ||
74 | --- a/hw/arm/fsl-imx8mp.c | ||
75 | +++ b/hw/arm/fsl-imx8mp.c | ||
76 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx8mp_init(Object *obj) | ||
77 | object_initialize_child(obj, name, &s->uart[i], TYPE_IMX_SERIAL); | ||
78 | } | ||
79 | |||
80 | + for (i = 0; i < FSL_IMX8MP_NUM_GPIOS; i++) { | ||
81 | + g_autofree char *name = g_strdup_printf("gpio%d", i + 1); | ||
82 | + object_initialize_child(obj, name, &s->gpio[i], TYPE_IMX_GPIO); | ||
83 | + } | ||
84 | + | ||
85 | for (i = 0; i < FSL_IMX8MP_NUM_USDHCS; i++) { | ||
86 | g_autofree char *name = g_strdup_printf("usdhc%d", i + 1); | ||
87 | object_initialize_child(obj, name, &s->usdhc[i], TYPE_IMX_USDHC); | ||
88 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp) | ||
89 | qdev_get_gpio_in(gicdev, serial_table[i].irq)); | ||
90 | } | ||
91 | |||
92 | + /* GPIOs */ | ||
93 | + for (i = 0; i < FSL_IMX8MP_NUM_GPIOS; i++) { | ||
94 | + struct { | ||
95 | + hwaddr addr; | ||
96 | + unsigned int irq_low; | ||
97 | + unsigned int irq_high; | ||
98 | + } gpio_table[FSL_IMX8MP_NUM_GPIOS] = { | ||
99 | + { | ||
100 | + fsl_imx8mp_memmap[FSL_IMX8MP_GPIO1].addr, | ||
101 | + FSL_IMX8MP_GPIO1_LOW_IRQ, | ||
102 | + FSL_IMX8MP_GPIO1_HIGH_IRQ | ||
103 | + }, | ||
104 | + { | ||
105 | + fsl_imx8mp_memmap[FSL_IMX8MP_GPIO2].addr, | ||
106 | + FSL_IMX8MP_GPIO2_LOW_IRQ, | ||
107 | + FSL_IMX8MP_GPIO2_HIGH_IRQ | ||
108 | + }, | ||
109 | + { | ||
110 | + fsl_imx8mp_memmap[FSL_IMX8MP_GPIO3].addr, | ||
111 | + FSL_IMX8MP_GPIO3_LOW_IRQ, | ||
112 | + FSL_IMX8MP_GPIO3_HIGH_IRQ | ||
113 | + }, | ||
114 | + { | ||
115 | + fsl_imx8mp_memmap[FSL_IMX8MP_GPIO4].addr, | ||
116 | + FSL_IMX8MP_GPIO4_LOW_IRQ, | ||
117 | + FSL_IMX8MP_GPIO4_HIGH_IRQ | ||
118 | + }, | ||
119 | + { | ||
120 | + fsl_imx8mp_memmap[FSL_IMX8MP_GPIO5].addr, | ||
121 | + FSL_IMX8MP_GPIO5_LOW_IRQ, | ||
122 | + FSL_IMX8MP_GPIO5_HIGH_IRQ | ||
123 | + }, | ||
124 | + }; | ||
125 | + | ||
126 | + object_property_set_bool(OBJECT(&s->gpio[i]), "has-edge-sel", true, | ||
127 | + &error_abort); | ||
128 | + object_property_set_bool(OBJECT(&s->gpio[i]), "has-upper-pin-irq", | ||
129 | + true, &error_abort); | ||
130 | + if (!sysbus_realize(SYS_BUS_DEVICE(&s->gpio[i]), errp)) { | ||
131 | + return; | ||
132 | + } | ||
133 | + | ||
134 | + sysbus_mmio_map(SYS_BUS_DEVICE(&s->gpio[i]), 0, gpio_table[i].addr); | ||
135 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->gpio[i]), 0, | ||
136 | + qdev_get_gpio_in(gicdev, gpio_table[i].irq_low)); | ||
137 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->gpio[i]), 1, | ||
138 | + qdev_get_gpio_in(gicdev, gpio_table[i].irq_high)); | ||
139 | + } | ||
140 | + | ||
141 | /* USDHCs */ | ||
142 | for (i = 0; i < FSL_IMX8MP_NUM_USDHCS; i++) { | ||
143 | struct { | ||
144 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp) | ||
145 | case FSL_IMX8MP_CCM: | ||
146 | case FSL_IMX8MP_GIC_DIST: | ||
147 | case FSL_IMX8MP_GIC_REDIST: | ||
148 | + case FSL_IMX8MP_GPIO1 ... FSL_IMX8MP_GPIO5: | ||
149 | case FSL_IMX8MP_PCIE1: | ||
150 | case FSL_IMX8MP_PCIE_PHY1: | ||
151 | case FSL_IMX8MP_RAM: | ||
152 | -- | ||
153 | 2.43.0 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Bernhard Beschow <shentey@gmail.com> | ||
1 | 2 | ||
3 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
4 | Signed-off-by: Bernhard Beschow <shentey@gmail.com> | ||
5 | Message-id: 20250223114708.1780-11-shentey@gmail.com | ||
6 | [PMM: drop static const from i2c_table for GCC 7.5] | ||
7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
8 | --- | ||
9 | docs/system/arm/imx8mp-evk.rst | 1 + | ||
10 | include/hw/arm/fsl-imx8mp.h | 11 +++++++++++ | ||
11 | hw/arm/fsl-imx8mp.c | 29 +++++++++++++++++++++++++++++ | ||
12 | hw/arm/Kconfig | 2 ++ | ||
13 | 4 files changed, 43 insertions(+) | ||
14 | |||
15 | diff --git a/docs/system/arm/imx8mp-evk.rst b/docs/system/arm/imx8mp-evk.rst | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/docs/system/arm/imx8mp-evk.rst | ||
18 | +++ b/docs/system/arm/imx8mp-evk.rst | ||
19 | @@ -XXX,XX +XXX,XX @@ The ``imx8mp-evk`` machine implements the following devices: | ||
20 | * 3 USDHC Storage Controllers | ||
21 | * 1 Designware PCI Express Controller | ||
22 | * 5 GPIO Controllers | ||
23 | + * 6 I2C Controllers | ||
24 | * Secure Non-Volatile Storage (SNVS) including an RTC | ||
25 | * Clock Tree | ||
26 | |||
27 | diff --git a/include/hw/arm/fsl-imx8mp.h b/include/hw/arm/fsl-imx8mp.h | ||
28 | index XXXXXXX..XXXXXXX 100644 | ||
29 | --- a/include/hw/arm/fsl-imx8mp.h | ||
30 | +++ b/include/hw/arm/fsl-imx8mp.h | ||
31 | @@ -XXX,XX +XXX,XX @@ | ||
32 | #include "cpu.h" | ||
33 | #include "hw/char/imx_serial.h" | ||
34 | #include "hw/gpio/imx_gpio.h" | ||
35 | +#include "hw/i2c/imx_i2c.h" | ||
36 | #include "hw/intc/arm_gicv3_common.h" | ||
37 | #include "hw/misc/imx7_snvs.h" | ||
38 | #include "hw/misc/imx8mp_analog.h" | ||
39 | @@ -XXX,XX +XXX,XX @@ OBJECT_DECLARE_SIMPLE_TYPE(FslImx8mpState, FSL_IMX8MP) | ||
40 | enum FslImx8mpConfiguration { | ||
41 | FSL_IMX8MP_NUM_CPUS = 4, | ||
42 | FSL_IMX8MP_NUM_GPIOS = 5, | ||
43 | + FSL_IMX8MP_NUM_I2CS = 6, | ||
44 | FSL_IMX8MP_NUM_IRQS = 160, | ||
45 | FSL_IMX8MP_NUM_UARTS = 4, | ||
46 | FSL_IMX8MP_NUM_USDHCS = 3, | ||
47 | @@ -XXX,XX +XXX,XX @@ struct FslImx8mpState { | ||
48 | IMX8MPCCMState ccm; | ||
49 | IMX8MPAnalogState analog; | ||
50 | IMX7SNVSState snvs; | ||
51 | + IMXI2CState i2c[FSL_IMX8MP_NUM_I2CS]; | ||
52 | IMXSerialState uart[FSL_IMX8MP_NUM_UARTS]; | ||
53 | SDHCIState usdhc[FSL_IMX8MP_NUM_USDHCS]; | ||
54 | DesignwarePCIEHost pcie; | ||
55 | @@ -XXX,XX +XXX,XX @@ enum FslImx8mpIrqs { | ||
56 | FSL_IMX8MP_UART5_IRQ = 30, | ||
57 | FSL_IMX8MP_UART6_IRQ = 16, | ||
58 | |||
59 | + FSL_IMX8MP_I2C1_IRQ = 35, | ||
60 | + FSL_IMX8MP_I2C2_IRQ = 36, | ||
61 | + FSL_IMX8MP_I2C3_IRQ = 37, | ||
62 | + FSL_IMX8MP_I2C4_IRQ = 38, | ||
63 | + | ||
64 | FSL_IMX8MP_GPIO1_LOW_IRQ = 64, | ||
65 | FSL_IMX8MP_GPIO1_HIGH_IRQ = 65, | ||
66 | FSL_IMX8MP_GPIO2_LOW_IRQ = 66, | ||
67 | @@ -XXX,XX +XXX,XX @@ enum FslImx8mpIrqs { | ||
68 | FSL_IMX8MP_GPIO5_LOW_IRQ = 72, | ||
69 | FSL_IMX8MP_GPIO5_HIGH_IRQ = 73, | ||
70 | |||
71 | + FSL_IMX8MP_I2C5_IRQ = 76, | ||
72 | + FSL_IMX8MP_I2C6_IRQ = 77, | ||
73 | + | ||
74 | FSL_IMX8MP_PCI_INTA_IRQ = 126, | ||
75 | FSL_IMX8MP_PCI_INTB_IRQ = 125, | ||
76 | FSL_IMX8MP_PCI_INTC_IRQ = 124, | ||
77 | diff --git a/hw/arm/fsl-imx8mp.c b/hw/arm/fsl-imx8mp.c | ||
78 | index XXXXXXX..XXXXXXX 100644 | ||
79 | --- a/hw/arm/fsl-imx8mp.c | ||
80 | +++ b/hw/arm/fsl-imx8mp.c | ||
81 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx8mp_init(Object *obj) | ||
82 | object_initialize_child(obj, name, &s->uart[i], TYPE_IMX_SERIAL); | ||
83 | } | ||
84 | |||
85 | + for (i = 0; i < FSL_IMX8MP_NUM_I2CS; i++) { | ||
86 | + g_autofree char *name = g_strdup_printf("i2c%d", i + 1); | ||
87 | + object_initialize_child(obj, name, &s->i2c[i], TYPE_IMX_I2C); | ||
88 | + } | ||
89 | + | ||
90 | for (i = 0; i < FSL_IMX8MP_NUM_GPIOS; i++) { | ||
91 | g_autofree char *name = g_strdup_printf("gpio%d", i + 1); | ||
92 | object_initialize_child(obj, name, &s->gpio[i], TYPE_IMX_GPIO); | ||
93 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp) | ||
94 | qdev_get_gpio_in(gicdev, serial_table[i].irq)); | ||
95 | } | ||
96 | |||
97 | + /* I2Cs */ | ||
98 | + for (i = 0; i < FSL_IMX8MP_NUM_I2CS; i++) { | ||
99 | + struct { | ||
100 | + hwaddr addr; | ||
101 | + unsigned int irq; | ||
102 | + } i2c_table[FSL_IMX8MP_NUM_I2CS] = { | ||
103 | + { fsl_imx8mp_memmap[FSL_IMX8MP_I2C1].addr, FSL_IMX8MP_I2C1_IRQ }, | ||
104 | + { fsl_imx8mp_memmap[FSL_IMX8MP_I2C2].addr, FSL_IMX8MP_I2C2_IRQ }, | ||
105 | + { fsl_imx8mp_memmap[FSL_IMX8MP_I2C3].addr, FSL_IMX8MP_I2C3_IRQ }, | ||
106 | + { fsl_imx8mp_memmap[FSL_IMX8MP_I2C4].addr, FSL_IMX8MP_I2C4_IRQ }, | ||
107 | + { fsl_imx8mp_memmap[FSL_IMX8MP_I2C5].addr, FSL_IMX8MP_I2C5_IRQ }, | ||
108 | + { fsl_imx8mp_memmap[FSL_IMX8MP_I2C6].addr, FSL_IMX8MP_I2C6_IRQ }, | ||
109 | + }; | ||
110 | + | ||
111 | + if (!sysbus_realize(SYS_BUS_DEVICE(&s->i2c[i]), errp)) { | ||
112 | + return; | ||
113 | + } | ||
114 | + | ||
115 | + sysbus_mmio_map(SYS_BUS_DEVICE(&s->i2c[i]), 0, i2c_table[i].addr); | ||
116 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->i2c[i]), 0, | ||
117 | + qdev_get_gpio_in(gicdev, i2c_table[i].irq)); | ||
118 | + } | ||
119 | + | ||
120 | /* GPIOs */ | ||
121 | for (i = 0; i < FSL_IMX8MP_NUM_GPIOS; i++) { | ||
122 | struct { | ||
123 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp) | ||
124 | case FSL_IMX8MP_GIC_DIST: | ||
125 | case FSL_IMX8MP_GIC_REDIST: | ||
126 | case FSL_IMX8MP_GPIO1 ... FSL_IMX8MP_GPIO5: | ||
127 | + case FSL_IMX8MP_I2C1 ... FSL_IMX8MP_I2C6: | ||
128 | case FSL_IMX8MP_PCIE1: | ||
129 | case FSL_IMX8MP_PCIE_PHY1: | ||
130 | case FSL_IMX8MP_RAM: | ||
131 | diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig | ||
132 | index XXXXXXX..XXXXXXX 100644 | ||
133 | --- a/hw/arm/Kconfig | ||
134 | +++ b/hw/arm/Kconfig | ||
135 | @@ -XXX,XX +XXX,XX @@ config FSL_IMX7 | ||
136 | |||
137 | config FSL_IMX8MP | ||
138 | bool | ||
139 | + imply I2C_DEVICES | ||
140 | imply PCI_DEVICES | ||
141 | select ARM_GIC | ||
142 | select FSL_IMX8MP_ANALOG | ||
143 | select FSL_IMX8MP_CCM | ||
144 | select IMX | ||
145 | + select IMX_I2C | ||
146 | select PCI_EXPRESS_DESIGNWARE | ||
147 | select PCI_EXPRESS_FSL_IMX8M_PHY | ||
148 | select SDHCI | ||
149 | -- | ||
150 | 2.43.0 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Bernhard Beschow <shentey@gmail.com> | ||
1 | 2 | ||
3 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
4 | Signed-off-by: Bernhard Beschow <shentey@gmail.com> | ||
5 | Message-id: 20250223114708.1780-12-shentey@gmail.com | ||
6 | [PMM: drop static const from spi_table for GCC 7.5] | ||
7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
8 | --- | ||
9 | docs/system/arm/imx8mp-evk.rst | 1 + | ||
10 | include/hw/arm/fsl-imx8mp.h | 8 ++++++++ | ||
11 | hw/arm/fsl-imx8mp.c | 26 ++++++++++++++++++++++++++ | ||
12 | 3 files changed, 35 insertions(+) | ||
13 | |||
14 | diff --git a/docs/system/arm/imx8mp-evk.rst b/docs/system/arm/imx8mp-evk.rst | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/docs/system/arm/imx8mp-evk.rst | ||
17 | +++ b/docs/system/arm/imx8mp-evk.rst | ||
18 | @@ -XXX,XX +XXX,XX @@ The ``imx8mp-evk`` machine implements the following devices: | ||
19 | * 1 Designware PCI Express Controller | ||
20 | * 5 GPIO Controllers | ||
21 | * 6 I2C Controllers | ||
22 | + * 3 SPI Controllers | ||
23 | * Secure Non-Volatile Storage (SNVS) including an RTC | ||
24 | * Clock Tree | ||
25 | |||
26 | diff --git a/include/hw/arm/fsl-imx8mp.h b/include/hw/arm/fsl-imx8mp.h | ||
27 | index XXXXXXX..XXXXXXX 100644 | ||
28 | --- a/include/hw/arm/fsl-imx8mp.h | ||
29 | +++ b/include/hw/arm/fsl-imx8mp.h | ||
30 | @@ -XXX,XX +XXX,XX @@ | ||
31 | #include "hw/pci-host/designware.h" | ||
32 | #include "hw/pci-host/fsl_imx8m_phy.h" | ||
33 | #include "hw/sd/sdhci.h" | ||
34 | +#include "hw/ssi/imx_spi.h" | ||
35 | #include "qom/object.h" | ||
36 | #include "qemu/units.h" | ||
37 | |||
38 | @@ -XXX,XX +XXX,XX @@ OBJECT_DECLARE_SIMPLE_TYPE(FslImx8mpState, FSL_IMX8MP) | ||
39 | |||
40 | enum FslImx8mpConfiguration { | ||
41 | FSL_IMX8MP_NUM_CPUS = 4, | ||
42 | + FSL_IMX8MP_NUM_ECSPIS = 3, | ||
43 | FSL_IMX8MP_NUM_GPIOS = 5, | ||
44 | FSL_IMX8MP_NUM_I2CS = 6, | ||
45 | FSL_IMX8MP_NUM_IRQS = 160, | ||
46 | @@ -XXX,XX +XXX,XX @@ struct FslImx8mpState { | ||
47 | IMX8MPCCMState ccm; | ||
48 | IMX8MPAnalogState analog; | ||
49 | IMX7SNVSState snvs; | ||
50 | + IMXSPIState spi[FSL_IMX8MP_NUM_ECSPIS]; | ||
51 | IMXI2CState i2c[FSL_IMX8MP_NUM_I2CS]; | ||
52 | IMXSerialState uart[FSL_IMX8MP_NUM_UARTS]; | ||
53 | SDHCIState usdhc[FSL_IMX8MP_NUM_USDHCS]; | ||
54 | @@ -XXX,XX +XXX,XX @@ enum FslImx8mpIrqs { | ||
55 | FSL_IMX8MP_UART5_IRQ = 30, | ||
56 | FSL_IMX8MP_UART6_IRQ = 16, | ||
57 | |||
58 | + FSL_IMX8MP_ECSPI1_IRQ = 31, | ||
59 | + FSL_IMX8MP_ECSPI2_IRQ = 32, | ||
60 | + FSL_IMX8MP_ECSPI3_IRQ = 33, | ||
61 | + FSL_IMX8MP_ECSPI4_IRQ = 34, | ||
62 | + | ||
63 | FSL_IMX8MP_I2C1_IRQ = 35, | ||
64 | FSL_IMX8MP_I2C2_IRQ = 36, | ||
65 | FSL_IMX8MP_I2C3_IRQ = 37, | ||
66 | diff --git a/hw/arm/fsl-imx8mp.c b/hw/arm/fsl-imx8mp.c | ||
67 | index XXXXXXX..XXXXXXX 100644 | ||
68 | --- a/hw/arm/fsl-imx8mp.c | ||
69 | +++ b/hw/arm/fsl-imx8mp.c | ||
70 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx8mp_init(Object *obj) | ||
71 | object_initialize_child(obj, name, &s->usdhc[i], TYPE_IMX_USDHC); | ||
72 | } | ||
73 | |||
74 | + for (i = 0; i < FSL_IMX8MP_NUM_ECSPIS; i++) { | ||
75 | + g_autofree char *name = g_strdup_printf("spi%d", i + 1); | ||
76 | + object_initialize_child(obj, name, &s->spi[i], TYPE_IMX_SPI); | ||
77 | + } | ||
78 | + | ||
79 | object_initialize_child(obj, "pcie", &s->pcie, TYPE_DESIGNWARE_PCIE_HOST); | ||
80 | object_initialize_child(obj, "pcie_phy", &s->pcie_phy, | ||
81 | TYPE_FSL_IMX8M_PCIE_PHY); | ||
82 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp) | ||
83 | qdev_get_gpio_in(gicdev, usdhc_table[i].irq)); | ||
84 | } | ||
85 | |||
86 | + /* ECSPIs */ | ||
87 | + for (i = 0; i < FSL_IMX8MP_NUM_ECSPIS; i++) { | ||
88 | + struct { | ||
89 | + hwaddr addr; | ||
90 | + unsigned int irq; | ||
91 | + } spi_table[FSL_IMX8MP_NUM_ECSPIS] = { | ||
92 | + { fsl_imx8mp_memmap[FSL_IMX8MP_ECSPI1].addr, FSL_IMX8MP_ECSPI1_IRQ }, | ||
93 | + { fsl_imx8mp_memmap[FSL_IMX8MP_ECSPI2].addr, FSL_IMX8MP_ECSPI2_IRQ }, | ||
94 | + { fsl_imx8mp_memmap[FSL_IMX8MP_ECSPI3].addr, FSL_IMX8MP_ECSPI3_IRQ }, | ||
95 | + }; | ||
96 | + | ||
97 | + if (!sysbus_realize(SYS_BUS_DEVICE(&s->spi[i]), errp)) { | ||
98 | + return; | ||
99 | + } | ||
100 | + | ||
101 | + sysbus_mmio_map(SYS_BUS_DEVICE(&s->spi[i]), 0, spi_table[i].addr); | ||
102 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->spi[i]), 0, | ||
103 | + qdev_get_gpio_in(gicdev, spi_table[i].irq)); | ||
104 | + } | ||
105 | + | ||
106 | /* SNVS */ | ||
107 | if (!sysbus_realize(SYS_BUS_DEVICE(&s->snvs), errp)) { | ||
108 | return; | ||
109 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp) | ||
110 | case FSL_IMX8MP_GIC_DIST: | ||
111 | case FSL_IMX8MP_GIC_REDIST: | ||
112 | case FSL_IMX8MP_GPIO1 ... FSL_IMX8MP_GPIO5: | ||
113 | + case FSL_IMX8MP_ECSPI1 ... FSL_IMX8MP_ECSPI3: | ||
114 | case FSL_IMX8MP_I2C1 ... FSL_IMX8MP_I2C6: | ||
115 | case FSL_IMX8MP_PCIE1: | ||
116 | case FSL_IMX8MP_PCIE_PHY1: | ||
117 | -- | ||
118 | 2.43.0 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Bernhard Beschow <shentey@gmail.com> | ||
1 | 2 | ||
3 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
4 | Signed-off-by: Bernhard Beschow <shentey@gmail.com> | ||
5 | Message-id: 20250223114708.1780-13-shentey@gmail.com | ||
6 | [PMM: drop static const from wdog_table for GCC 7.5] | ||
7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
8 | --- | ||
9 | docs/system/arm/imx8mp-evk.rst | 1 + | ||
10 | include/hw/arm/fsl-imx8mp.h | 7 +++++++ | ||
11 | hw/arm/fsl-imx8mp.c | 28 ++++++++++++++++++++++++++++ | ||
12 | hw/arm/Kconfig | 1 + | ||
13 | 4 files changed, 37 insertions(+) | ||
14 | |||
15 | diff --git a/docs/system/arm/imx8mp-evk.rst b/docs/system/arm/imx8mp-evk.rst | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/docs/system/arm/imx8mp-evk.rst | ||
18 | +++ b/docs/system/arm/imx8mp-evk.rst | ||
19 | @@ -XXX,XX +XXX,XX @@ The ``imx8mp-evk`` machine implements the following devices: | ||
20 | * 5 GPIO Controllers | ||
21 | * 6 I2C Controllers | ||
22 | * 3 SPI Controllers | ||
23 | + * 3 Watchdogs | ||
24 | * Secure Non-Volatile Storage (SNVS) including an RTC | ||
25 | * Clock Tree | ||
26 | |||
27 | diff --git a/include/hw/arm/fsl-imx8mp.h b/include/hw/arm/fsl-imx8mp.h | ||
28 | index XXXXXXX..XXXXXXX 100644 | ||
29 | --- a/include/hw/arm/fsl-imx8mp.h | ||
30 | +++ b/include/hw/arm/fsl-imx8mp.h | ||
31 | @@ -XXX,XX +XXX,XX @@ | ||
32 | #include "hw/pci-host/fsl_imx8m_phy.h" | ||
33 | #include "hw/sd/sdhci.h" | ||
34 | #include "hw/ssi/imx_spi.h" | ||
35 | +#include "hw/watchdog/wdt_imx2.h" | ||
36 | #include "qom/object.h" | ||
37 | #include "qemu/units.h" | ||
38 | |||
39 | @@ -XXX,XX +XXX,XX @@ enum FslImx8mpConfiguration { | ||
40 | FSL_IMX8MP_NUM_IRQS = 160, | ||
41 | FSL_IMX8MP_NUM_UARTS = 4, | ||
42 | FSL_IMX8MP_NUM_USDHCS = 3, | ||
43 | + FSL_IMX8MP_NUM_WDTS = 3, | ||
44 | }; | ||
45 | |||
46 | struct FslImx8mpState { | ||
47 | @@ -XXX,XX +XXX,XX @@ struct FslImx8mpState { | ||
48 | IMXI2CState i2c[FSL_IMX8MP_NUM_I2CS]; | ||
49 | IMXSerialState uart[FSL_IMX8MP_NUM_UARTS]; | ||
50 | SDHCIState usdhc[FSL_IMX8MP_NUM_USDHCS]; | ||
51 | + IMX2WdtState wdt[FSL_IMX8MP_NUM_WDTS]; | ||
52 | DesignwarePCIEHost pcie; | ||
53 | FslImx8mPciePhyState pcie_phy; | ||
54 | }; | ||
55 | @@ -XXX,XX +XXX,XX @@ enum FslImx8mpIrqs { | ||
56 | FSL_IMX8MP_I2C5_IRQ = 76, | ||
57 | FSL_IMX8MP_I2C6_IRQ = 77, | ||
58 | |||
59 | + FSL_IMX8MP_WDOG1_IRQ = 78, | ||
60 | + FSL_IMX8MP_WDOG2_IRQ = 79, | ||
61 | + FSL_IMX8MP_WDOG3_IRQ = 10, | ||
62 | + | ||
63 | FSL_IMX8MP_PCI_INTA_IRQ = 126, | ||
64 | FSL_IMX8MP_PCI_INTB_IRQ = 125, | ||
65 | FSL_IMX8MP_PCI_INTC_IRQ = 124, | ||
66 | diff --git a/hw/arm/fsl-imx8mp.c b/hw/arm/fsl-imx8mp.c | ||
67 | index XXXXXXX..XXXXXXX 100644 | ||
68 | --- a/hw/arm/fsl-imx8mp.c | ||
69 | +++ b/hw/arm/fsl-imx8mp.c | ||
70 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx8mp_init(Object *obj) | ||
71 | object_initialize_child(obj, name, &s->spi[i], TYPE_IMX_SPI); | ||
72 | } | ||
73 | |||
74 | + for (i = 0; i < FSL_IMX8MP_NUM_WDTS; i++) { | ||
75 | + g_autofree char *name = g_strdup_printf("wdt%d", i); | ||
76 | + object_initialize_child(obj, name, &s->wdt[i], TYPE_IMX2_WDT); | ||
77 | + } | ||
78 | + | ||
79 | object_initialize_child(obj, "pcie", &s->pcie, TYPE_DESIGNWARE_PCIE_HOST); | ||
80 | object_initialize_child(obj, "pcie_phy", &s->pcie_phy, | ||
81 | TYPE_FSL_IMX8M_PCIE_PHY); | ||
82 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp) | ||
83 | sysbus_mmio_map(SYS_BUS_DEVICE(&s->snvs), 0, | ||
84 | fsl_imx8mp_memmap[FSL_IMX8MP_SNVS_HP].addr); | ||
85 | |||
86 | + /* Watchdogs */ | ||
87 | + for (i = 0; i < FSL_IMX8MP_NUM_WDTS; i++) { | ||
88 | + struct { | ||
89 | + hwaddr addr; | ||
90 | + unsigned int irq; | ||
91 | + } wdog_table[FSL_IMX8MP_NUM_WDTS] = { | ||
92 | + { fsl_imx8mp_memmap[FSL_IMX8MP_WDOG1].addr, FSL_IMX8MP_WDOG1_IRQ }, | ||
93 | + { fsl_imx8mp_memmap[FSL_IMX8MP_WDOG2].addr, FSL_IMX8MP_WDOG2_IRQ }, | ||
94 | + { fsl_imx8mp_memmap[FSL_IMX8MP_WDOG3].addr, FSL_IMX8MP_WDOG3_IRQ }, | ||
95 | + }; | ||
96 | + | ||
97 | + object_property_set_bool(OBJECT(&s->wdt[i]), "pretimeout-support", | ||
98 | + true, &error_abort); | ||
99 | + if (!sysbus_realize(SYS_BUS_DEVICE(&s->wdt[i]), errp)) { | ||
100 | + return; | ||
101 | + } | ||
102 | + | ||
103 | + sysbus_mmio_map(SYS_BUS_DEVICE(&s->wdt[i]), 0, wdog_table[i].addr); | ||
104 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->wdt[i]), 0, | ||
105 | + qdev_get_gpio_in(gicdev, wdog_table[i].irq)); | ||
106 | + } | ||
107 | + | ||
108 | /* PCIe */ | ||
109 | if (!sysbus_realize(SYS_BUS_DEVICE(&s->pcie), errp)) { | ||
110 | return; | ||
111 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp) | ||
112 | case FSL_IMX8MP_SNVS_HP: | ||
113 | case FSL_IMX8MP_UART1 ... FSL_IMX8MP_UART4: | ||
114 | case FSL_IMX8MP_USDHC1 ... FSL_IMX8MP_USDHC3: | ||
115 | + case FSL_IMX8MP_WDOG1 ... FSL_IMX8MP_WDOG3: | ||
116 | /* device implemented and treated above */ | ||
117 | break; | ||
118 | |||
119 | diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig | ||
120 | index XXXXXXX..XXXXXXX 100644 | ||
121 | --- a/hw/arm/Kconfig | ||
122 | +++ b/hw/arm/Kconfig | ||
123 | @@ -XXX,XX +XXX,XX @@ config FSL_IMX8MP | ||
124 | select PCI_EXPRESS_FSL_IMX8M_PHY | ||
125 | select SDHCI | ||
126 | select UNIMP | ||
127 | + select WDT_IMX2 | ||
128 | |||
129 | config FSL_IMX8MP_EVK | ||
130 | bool | ||
131 | -- | ||
132 | 2.43.0 | diff view generated by jsdifflib |
1 | From: Cédric Le Goater <clg@kaod.org> | 1 | From: Bernhard Beschow <shentey@gmail.com> |
---|---|---|---|
2 | 2 | ||
3 | Improve the naming of the different controller models to ease their | ||
4 | generation when initializing the SoC. The rename of the SMC types is | ||
5 | breaking migration compatibility. | ||
6 | |||
7 | Signed-off-by: Cédric Le Goater <clg@kaod.org> | ||
8 | Message-id: 20190904070506.1052-5-clg@kaod.org | ||
9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 3 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
4 | Signed-off-by: Bernhard Beschow <shentey@gmail.com> | ||
5 | Message-id: 20250223114708.1780-14-shentey@gmail.com | ||
6 | [PMM: drop static const from gpt_attrs for GCC 7.5] | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
11 | --- | 8 | --- |
12 | include/hw/arm/aspeed_soc.h | 3 --- | 9 | docs/system/arm/imx8mp-evk.rst | 1 + |
13 | hw/arm/aspeed_soc.c | 25 ++++++++++++------------- | 10 | include/hw/arm/fsl-imx8mp.h | 11 +++++++ |
14 | hw/ssi/aspeed_smc.c | 12 ++++++------ | 11 | include/hw/timer/imx_gpt.h | 1 + |
15 | 3 files changed, 18 insertions(+), 22 deletions(-) | 12 | hw/arm/fsl-imx8mp.c | 53 ++++++++++++++++++++++++++++++++++ |
13 | hw/timer/imx_gpt.c | 25 ++++++++++++++++ | ||
14 | hw/arm/Kconfig | 1 + | ||
15 | 6 files changed, 92 insertions(+) | ||
16 | 16 | ||
17 | diff --git a/include/hw/arm/aspeed_soc.h b/include/hw/arm/aspeed_soc.h | 17 | diff --git a/docs/system/arm/imx8mp-evk.rst b/docs/system/arm/imx8mp-evk.rst |
18 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/include/hw/arm/aspeed_soc.h | 19 | --- a/docs/system/arm/imx8mp-evk.rst |
20 | +++ b/include/hw/arm/aspeed_soc.h | 20 | +++ b/docs/system/arm/imx8mp-evk.rst |
21 | @@ -XXX,XX +XXX,XX @@ typedef struct AspeedSoCInfo { | 21 | @@ -XXX,XX +XXX,XX @@ The ``imx8mp-evk`` machine implements the following devices: |
22 | uint32_t silicon_rev; | 22 | * 6 I2C Controllers |
23 | uint64_t sram_size; | 23 | * 3 SPI Controllers |
24 | int spis_num; | 24 | * 3 Watchdogs |
25 | - const char *fmc_typename; | 25 | + * 6 General Purpose Timers |
26 | - const char **spi_typename; | 26 | * Secure Non-Volatile Storage (SNVS) including an RTC |
27 | - const char *gpio_typename; | 27 | * Clock Tree |
28 | int wdts_num; | 28 | |
29 | const int *irqmap; | 29 | diff --git a/include/hw/arm/fsl-imx8mp.h b/include/hw/arm/fsl-imx8mp.h |
30 | const hwaddr *memmap; | 30 | index XXXXXXX..XXXXXXX 100644 |
31 | diff --git a/hw/arm/aspeed_soc.c b/hw/arm/aspeed_soc.c | 31 | --- a/include/hw/arm/fsl-imx8mp.h |
32 | index XXXXXXX..XXXXXXX 100644 | 32 | +++ b/include/hw/arm/fsl-imx8mp.h |
33 | --- a/hw/arm/aspeed_soc.c | 33 | @@ -XXX,XX +XXX,XX @@ |
34 | +++ b/hw/arm/aspeed_soc.c | 34 | #include "hw/misc/imx7_snvs.h" |
35 | @@ -XXX,XX +XXX,XX @@ static const int aspeed_soc_ast2400_irqmap[] = { | 35 | #include "hw/misc/imx8mp_analog.h" |
36 | 36 | #include "hw/misc/imx8mp_ccm.h" | |
37 | #define aspeed_soc_ast2500_irqmap aspeed_soc_ast2400_irqmap | 37 | +#include "hw/or-irq.h" |
38 | 38 | #include "hw/pci-host/designware.h" | |
39 | -static const char *aspeed_soc_ast2400_typenames[] = { "aspeed.smc.spi" }; | 39 | #include "hw/pci-host/fsl_imx8m_phy.h" |
40 | -static const char *aspeed_soc_ast2500_typenames[] = { | 40 | #include "hw/sd/sdhci.h" |
41 | - "aspeed.smc.ast2500-spi1", "aspeed.smc.ast2500-spi2" }; | 41 | #include "hw/ssi/imx_spi.h" |
42 | - | 42 | +#include "hw/timer/imx_gpt.h" |
43 | static const AspeedSoCInfo aspeed_socs[] = { | 43 | #include "hw/watchdog/wdt_imx2.h" |
44 | { | 44 | #include "qom/object.h" |
45 | .name = "ast2400-a1", | 45 | #include "qemu/units.h" |
46 | @@ -XXX,XX +XXX,XX @@ static const AspeedSoCInfo aspeed_socs[] = { | 46 | @@ -XXX,XX +XXX,XX @@ enum FslImx8mpConfiguration { |
47 | .silicon_rev = AST2400_A1_SILICON_REV, | 47 | FSL_IMX8MP_NUM_CPUS = 4, |
48 | .sram_size = 0x8000, | 48 | FSL_IMX8MP_NUM_ECSPIS = 3, |
49 | .spis_num = 1, | 49 | FSL_IMX8MP_NUM_GPIOS = 5, |
50 | - .fmc_typename = "aspeed.smc.fmc", | 50 | + FSL_IMX8MP_NUM_GPTS = 6, |
51 | - .spi_typename = aspeed_soc_ast2400_typenames, | 51 | FSL_IMX8MP_NUM_I2CS = 6, |
52 | - .gpio_typename = "aspeed.gpio-ast2400", | 52 | FSL_IMX8MP_NUM_IRQS = 160, |
53 | .wdts_num = 2, | 53 | FSL_IMX8MP_NUM_UARTS = 4, |
54 | .irqmap = aspeed_soc_ast2400_irqmap, | 54 | @@ -XXX,XX +XXX,XX @@ struct FslImx8mpState { |
55 | .memmap = aspeed_soc_ast2400_memmap, | 55 | |
56 | @@ -XXX,XX +XXX,XX @@ static const AspeedSoCInfo aspeed_socs[] = { | 56 | ARMCPU cpu[FSL_IMX8MP_NUM_CPUS]; |
57 | .silicon_rev = AST2500_A1_SILICON_REV, | 57 | GICv3State gic; |
58 | .sram_size = 0x9000, | 58 | + IMXGPTState gpt[FSL_IMX8MP_NUM_GPTS]; |
59 | .spis_num = 2, | 59 | IMXGPIOState gpio[FSL_IMX8MP_NUM_GPIOS]; |
60 | - .fmc_typename = "aspeed.smc.ast2500-fmc", | 60 | IMX8MPCCMState ccm; |
61 | - .spi_typename = aspeed_soc_ast2500_typenames, | 61 | IMX8MPAnalogState analog; |
62 | - .gpio_typename = "aspeed.gpio-ast2500", | 62 | @@ -XXX,XX +XXX,XX @@ struct FslImx8mpState { |
63 | .wdts_num = 3, | 63 | IMX2WdtState wdt[FSL_IMX8MP_NUM_WDTS]; |
64 | .irqmap = aspeed_soc_ast2500_irqmap, | 64 | DesignwarePCIEHost pcie; |
65 | .memmap = aspeed_soc_ast2500_memmap, | 65 | FslImx8mPciePhyState pcie_phy; |
66 | @@ -XXX,XX +XXX,XX @@ static void aspeed_soc_init(Object *obj) | 66 | + OrIRQState gpt5_gpt6_irq; |
67 | AspeedSoCState *s = ASPEED_SOC(obj); | 67 | }; |
68 | AspeedSoCClass *sc = ASPEED_SOC_GET_CLASS(s); | 68 | |
69 | int i; | 69 | enum FslImx8mpMemoryRegions { |
70 | + char socname[8]; | 70 | @@ -XXX,XX +XXX,XX @@ enum FslImx8mpIrqs { |
71 | + char typename[64]; | 71 | FSL_IMX8MP_I2C3_IRQ = 37, |
72 | + | 72 | FSL_IMX8MP_I2C4_IRQ = 38, |
73 | + if (sscanf(sc->info->name, "%7s", socname) != 1) { | 73 | |
74 | + g_assert_not_reached(); | 74 | + FSL_IMX8MP_GPT1_IRQ = 55, |
75 | + FSL_IMX8MP_GPT2_IRQ = 54, | ||
76 | + FSL_IMX8MP_GPT3_IRQ = 53, | ||
77 | + FSL_IMX8MP_GPT4_IRQ = 52, | ||
78 | + FSL_IMX8MP_GPT5_GPT6_IRQ = 51, | ||
79 | + | ||
80 | FSL_IMX8MP_GPIO1_LOW_IRQ = 64, | ||
81 | FSL_IMX8MP_GPIO1_HIGH_IRQ = 65, | ||
82 | FSL_IMX8MP_GPIO2_LOW_IRQ = 66, | ||
83 | diff --git a/include/hw/timer/imx_gpt.h b/include/hw/timer/imx_gpt.h | ||
84 | index XXXXXXX..XXXXXXX 100644 | ||
85 | --- a/include/hw/timer/imx_gpt.h | ||
86 | +++ b/include/hw/timer/imx_gpt.h | ||
87 | @@ -XXX,XX +XXX,XX @@ | ||
88 | #define TYPE_IMX6_GPT "imx6.gpt" | ||
89 | #define TYPE_IMX6UL_GPT "imx6ul.gpt" | ||
90 | #define TYPE_IMX7_GPT "imx7.gpt" | ||
91 | +#define TYPE_IMX8MP_GPT "imx8mp.gpt" | ||
92 | |||
93 | #define TYPE_IMX_GPT TYPE_IMX25_GPT | ||
94 | |||
95 | diff --git a/hw/arm/fsl-imx8mp.c b/hw/arm/fsl-imx8mp.c | ||
96 | index XXXXXXX..XXXXXXX 100644 | ||
97 | --- a/hw/arm/fsl-imx8mp.c | ||
98 | +++ b/hw/arm/fsl-imx8mp.c | ||
99 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx8mp_init(Object *obj) | ||
100 | object_initialize_child(obj, name, &s->uart[i], TYPE_IMX_SERIAL); | ||
101 | } | ||
102 | |||
103 | + for (i = 0; i < FSL_IMX8MP_NUM_GPTS; i++) { | ||
104 | + g_autofree char *name = g_strdup_printf("gpt%d", i + 1); | ||
105 | + object_initialize_child(obj, name, &s->gpt[i], TYPE_IMX8MP_GPT); | ||
75 | + } | 106 | + } |
76 | 107 | + object_initialize_child(obj, "gpt5-gpt6-irq", &s->gpt5_gpt6_irq, | |
77 | for (i = 0; i < sc->info->num_cpus; i++) { | 108 | + TYPE_OR_IRQ); |
78 | object_initialize_child(obj, "cpu[*]", OBJECT(&s->cpu[i]), | 109 | + |
79 | @@ -XXX,XX +XXX,XX @@ static void aspeed_soc_init(Object *obj) | 110 | for (i = 0; i < FSL_IMX8MP_NUM_I2CS; i++) { |
80 | sysbus_init_child_obj(obj, "i2c", OBJECT(&s->i2c), sizeof(s->i2c), | 111 | g_autofree char *name = g_strdup_printf("i2c%d", i + 1); |
81 | TYPE_ASPEED_I2C); | 112 | object_initialize_child(obj, name, &s->i2c[i], TYPE_IMX_I2C); |
82 | 113 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp) | |
83 | + snprintf(typename, sizeof(typename), "aspeed.fmc-%s", socname); | 114 | qdev_get_gpio_in(gicdev, serial_table[i].irq)); |
84 | sysbus_init_child_obj(obj, "fmc", OBJECT(&s->fmc), sizeof(s->fmc), | ||
85 | - sc->info->fmc_typename); | ||
86 | + typename); | ||
87 | object_property_add_alias(obj, "num-cs", OBJECT(&s->fmc), "num-cs", | ||
88 | &error_abort); | ||
89 | |||
90 | for (i = 0; i < sc->info->spis_num; i++) { | ||
91 | + snprintf(typename, sizeof(typename), "aspeed.spi%d-%s", i + 1, socname); | ||
92 | sysbus_init_child_obj(obj, "spi[*]", OBJECT(&s->spi[i]), | ||
93 | - sizeof(s->spi[i]), sc->info->spi_typename[i]); | ||
94 | + sizeof(s->spi[i]), typename); | ||
95 | } | 115 | } |
96 | 116 | ||
97 | sysbus_init_child_obj(obj, "sdmc", OBJECT(&s->sdmc), sizeof(s->sdmc), | 117 | + /* GPTs */ |
98 | @@ -XXX,XX +XXX,XX @@ static void aspeed_soc_init(Object *obj) | 118 | + object_property_set_int(OBJECT(&s->gpt5_gpt6_irq), "num-lines", 2, |
99 | sysbus_init_child_obj(obj, "xdma", OBJECT(&s->xdma), sizeof(s->xdma), | 119 | + &error_abort); |
100 | TYPE_ASPEED_XDMA); | 120 | + if (!qdev_realize(DEVICE(&s->gpt5_gpt6_irq), NULL, errp)) { |
101 | 121 | + return; | |
102 | + snprintf(typename, sizeof(typename), "aspeed.gpio-%s", socname); | 122 | + } |
103 | sysbus_init_child_obj(obj, "gpio", OBJECT(&s->gpio), sizeof(s->gpio), | 123 | + |
104 | - sc->info->gpio_typename); | 124 | + qdev_connect_gpio_out(DEVICE(&s->gpt5_gpt6_irq), 0, |
105 | + typename); | 125 | + qdev_get_gpio_in(gicdev, FSL_IMX8MP_GPT5_GPT6_IRQ)); |
126 | + | ||
127 | + for (i = 0; i < FSL_IMX8MP_NUM_GPTS; i++) { | ||
128 | + hwaddr gpt_addrs[FSL_IMX8MP_NUM_GPTS] = { | ||
129 | + fsl_imx8mp_memmap[FSL_IMX8MP_GPT1].addr, | ||
130 | + fsl_imx8mp_memmap[FSL_IMX8MP_GPT2].addr, | ||
131 | + fsl_imx8mp_memmap[FSL_IMX8MP_GPT3].addr, | ||
132 | + fsl_imx8mp_memmap[FSL_IMX8MP_GPT4].addr, | ||
133 | + fsl_imx8mp_memmap[FSL_IMX8MP_GPT5].addr, | ||
134 | + fsl_imx8mp_memmap[FSL_IMX8MP_GPT6].addr, | ||
135 | + }; | ||
136 | + | ||
137 | + s->gpt[i].ccm = IMX_CCM(&s->ccm); | ||
138 | + | ||
139 | + if (!sysbus_realize(SYS_BUS_DEVICE(&s->gpt[i]), errp)) { | ||
140 | + return; | ||
141 | + } | ||
142 | + | ||
143 | + sysbus_mmio_map(SYS_BUS_DEVICE(&s->gpt[i]), 0, gpt_addrs[i]); | ||
144 | + | ||
145 | + if (i < FSL_IMX8MP_NUM_GPTS - 2) { | ||
146 | + static const unsigned int gpt_irqs[FSL_IMX8MP_NUM_GPTS - 2] = { | ||
147 | + FSL_IMX8MP_GPT1_IRQ, | ||
148 | + FSL_IMX8MP_GPT2_IRQ, | ||
149 | + FSL_IMX8MP_GPT3_IRQ, | ||
150 | + FSL_IMX8MP_GPT4_IRQ, | ||
151 | + }; | ||
152 | + | ||
153 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->gpt[i]), 0, | ||
154 | + qdev_get_gpio_in(gicdev, gpt_irqs[i])); | ||
155 | + } else { | ||
156 | + int irq = i - FSL_IMX8MP_NUM_GPTS + 2; | ||
157 | + | ||
158 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->gpt[i]), 0, | ||
159 | + qdev_get_gpio_in(DEVICE(&s->gpt5_gpt6_irq), irq)); | ||
160 | + } | ||
161 | + } | ||
162 | + | ||
163 | /* I2Cs */ | ||
164 | for (i = 0; i < FSL_IMX8MP_NUM_I2CS; i++) { | ||
165 | struct { | ||
166 | diff --git a/hw/timer/imx_gpt.c b/hw/timer/imx_gpt.c | ||
167 | index XXXXXXX..XXXXXXX 100644 | ||
168 | --- a/hw/timer/imx_gpt.c | ||
169 | +++ b/hw/timer/imx_gpt.c | ||
170 | @@ -XXX,XX +XXX,XX @@ static const IMXClk imx7_gpt_clocks[] = { | ||
171 | CLK_NONE, /* 111 not defined */ | ||
172 | }; | ||
173 | |||
174 | +static const IMXClk imx8mp_gpt_clocks[] = { | ||
175 | + CLK_NONE, /* 000 No clock source */ | ||
176 | + CLK_IPG, /* 001 ipg_clk, 532MHz */ | ||
177 | + CLK_IPG_HIGH, /* 010 ipg_clk_highfreq */ | ||
178 | + CLK_EXT, /* 011 External clock */ | ||
179 | + CLK_32k, /* 100 ipg_clk_32k */ | ||
180 | + CLK_HIGH, /* 101 ipg_clk_16M */ | ||
181 | + CLK_NONE, /* 110 not defined */ | ||
182 | + CLK_NONE, /* 111 not defined */ | ||
183 | +}; | ||
184 | + | ||
185 | /* Must be called from within ptimer_transaction_begin/commit block */ | ||
186 | static void imx_gpt_set_freq(IMXGPTState *s) | ||
187 | { | ||
188 | @@ -XXX,XX +XXX,XX @@ static void imx7_gpt_init(Object *obj) | ||
189 | s->clocks = imx7_gpt_clocks; | ||
106 | } | 190 | } |
107 | 191 | ||
108 | static void aspeed_soc_realize(DeviceState *dev, Error **errp) | 192 | +static void imx8mp_gpt_init(Object *obj) |
109 | diff --git a/hw/ssi/aspeed_smc.c b/hw/ssi/aspeed_smc.c | 193 | +{ |
110 | index XXXXXXX..XXXXXXX 100644 | 194 | + IMXGPTState *s = IMX_GPT(obj); |
111 | --- a/hw/ssi/aspeed_smc.c | 195 | + |
112 | +++ b/hw/ssi/aspeed_smc.c | 196 | + s->clocks = imx8mp_gpt_clocks; |
113 | @@ -XXX,XX +XXX,XX @@ static const AspeedSegments aspeed_segments_ast2500_spi2[] = { | 197 | +} |
114 | 198 | + | |
115 | static const AspeedSMCController controllers[] = { | 199 | static const TypeInfo imx25_gpt_info = { |
116 | { | 200 | .name = TYPE_IMX25_GPT, |
117 | - .name = "aspeed.smc.smc", | 201 | .parent = TYPE_SYS_BUS_DEVICE, |
118 | + .name = "aspeed.smc-ast2400", | 202 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo imx7_gpt_info = { |
119 | .r_conf = R_CONF, | 203 | .instance_init = imx7_gpt_init, |
120 | .r_ce_ctrl = R_CE_CTRL, | 204 | }; |
121 | .r_ctrl0 = R_CTRL0, | 205 | |
122 | @@ -XXX,XX +XXX,XX @@ static const AspeedSMCController controllers[] = { | 206 | +static const TypeInfo imx8mp_gpt_info = { |
123 | .has_dma = false, | 207 | + .name = TYPE_IMX8MP_GPT, |
124 | .nregs = ASPEED_SMC_R_SMC_MAX, | 208 | + .parent = TYPE_IMX25_GPT, |
125 | }, { | 209 | + .instance_init = imx8mp_gpt_init, |
126 | - .name = "aspeed.smc.fmc", | 210 | +}; |
127 | + .name = "aspeed.fmc-ast2400", | 211 | + |
128 | .r_conf = R_CONF, | 212 | static void imx_gpt_register_types(void) |
129 | .r_ce_ctrl = R_CE_CTRL, | 213 | { |
130 | .r_ctrl0 = R_CTRL0, | 214 | type_register_static(&imx25_gpt_info); |
131 | @@ -XXX,XX +XXX,XX @@ static const AspeedSMCController controllers[] = { | 215 | @@ -XXX,XX +XXX,XX @@ static void imx_gpt_register_types(void) |
132 | .has_dma = true, | 216 | type_register_static(&imx6_gpt_info); |
133 | .nregs = ASPEED_SMC_R_MAX, | 217 | type_register_static(&imx6ul_gpt_info); |
134 | }, { | 218 | type_register_static(&imx7_gpt_info); |
135 | - .name = "aspeed.smc.spi", | 219 | + type_register_static(&imx8mp_gpt_info); |
136 | + .name = "aspeed.spi1-ast2400", | 220 | } |
137 | .r_conf = R_SPI_CONF, | 221 | |
138 | .r_ce_ctrl = 0xff, | 222 | type_init(imx_gpt_register_types) |
139 | .r_ctrl0 = R_SPI_CTRL0, | 223 | diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig |
140 | @@ -XXX,XX +XXX,XX @@ static const AspeedSMCController controllers[] = { | 224 | index XXXXXXX..XXXXXXX 100644 |
141 | .has_dma = false, | 225 | --- a/hw/arm/Kconfig |
142 | .nregs = ASPEED_SMC_R_SPI_MAX, | 226 | +++ b/hw/arm/Kconfig |
143 | }, { | 227 | @@ -XXX,XX +XXX,XX @@ config FSL_IMX8MP |
144 | - .name = "aspeed.smc.ast2500-fmc", | 228 | select FSL_IMX8MP_CCM |
145 | + .name = "aspeed.fmc-ast2500", | 229 | select IMX |
146 | .r_conf = R_CONF, | 230 | select IMX_I2C |
147 | .r_ce_ctrl = R_CE_CTRL, | 231 | + select OR_IRQ |
148 | .r_ctrl0 = R_CTRL0, | 232 | select PCI_EXPRESS_DESIGNWARE |
149 | @@ -XXX,XX +XXX,XX @@ static const AspeedSMCController controllers[] = { | 233 | select PCI_EXPRESS_FSL_IMX8M_PHY |
150 | .has_dma = true, | 234 | select SDHCI |
151 | .nregs = ASPEED_SMC_R_MAX, | ||
152 | }, { | ||
153 | - .name = "aspeed.smc.ast2500-spi1", | ||
154 | + .name = "aspeed.spi1-ast2500", | ||
155 | .r_conf = R_CONF, | ||
156 | .r_ce_ctrl = R_CE_CTRL, | ||
157 | .r_ctrl0 = R_CTRL0, | ||
158 | @@ -XXX,XX +XXX,XX @@ static const AspeedSMCController controllers[] = { | ||
159 | .has_dma = false, | ||
160 | .nregs = ASPEED_SMC_R_MAX, | ||
161 | }, { | ||
162 | - .name = "aspeed.smc.ast2500-spi2", | ||
163 | + .name = "aspeed.spi2-ast2500", | ||
164 | .r_conf = R_CONF, | ||
165 | .r_ce_ctrl = R_CE_CTRL, | ||
166 | .r_ctrl0 = R_CTRL0, | ||
167 | -- | 235 | -- |
168 | 2.20.1 | 236 | 2.43.0 |
169 | |||
170 | diff view generated by jsdifflib |
1 | From: Christian Svensson <bluecmd@google.com> | 1 | From: Bernhard Beschow <shentey@gmail.com> |
---|---|---|---|
2 | 2 | ||
3 | This patch adds the missing checksum calculation on normal DMA transfer. | 3 | The i.MX 8M Plus SoC actually has two ethernet controllers, the usual ENET one |
4 | According to the datasheet this is how the SMC should behave. | 4 | and a Designware one. There is no device model for the latter, so only add the |
5 | ENET one. | ||
5 | 6 | ||
6 | Verified on AST1250 that the hardware matches the behaviour. | 7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
7 | 8 | Signed-off-by: Bernhard Beschow <shentey@gmail.com> | |
8 | Signed-off-by: Christian Svensson <bluecmd@google.com> | 9 | Message-id: 20250223114708.1780-15-shentey@gmail.com |
9 | Reviewed-by: Joel Stanley <joel@jms.id.au> | ||
10 | Signed-off-by: Cédric Le Goater <clg@kaod.org> | ||
11 | Message-id: 20190904070506.1052-9-clg@kaod.org | ||
12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
13 | --- | 11 | --- |
14 | hw/ssi/aspeed_smc.c | 1 + | 12 | docs/system/arm/imx8mp-evk.rst | 1 + |
15 | 1 file changed, 1 insertion(+) | 13 | include/hw/arm/fsl-imx8mp.h | 8 ++++++++ |
14 | hw/arm/fsl-imx8mp.c | 24 ++++++++++++++++++++++++ | ||
15 | hw/arm/imx8mp-evk.c | 1 + | ||
16 | hw/arm/Kconfig | 1 + | ||
17 | 5 files changed, 35 insertions(+) | ||
16 | 18 | ||
17 | diff --git a/hw/ssi/aspeed_smc.c b/hw/ssi/aspeed_smc.c | 19 | diff --git a/docs/system/arm/imx8mp-evk.rst b/docs/system/arm/imx8mp-evk.rst |
18 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/hw/ssi/aspeed_smc.c | 21 | --- a/docs/system/arm/imx8mp-evk.rst |
20 | +++ b/hw/ssi/aspeed_smc.c | 22 | +++ b/docs/system/arm/imx8mp-evk.rst |
21 | @@ -XXX,XX +XXX,XX @@ static void aspeed_smc_dma_rw(AspeedSMCState *s) | 23 | @@ -XXX,XX +XXX,XX @@ The ``imx8mp-evk`` machine implements the following devices: |
22 | s->regs[R_DMA_FLASH_ADDR] += 4; | 24 | * 4 UARTs |
23 | s->regs[R_DMA_DRAM_ADDR] += 4; | 25 | * 3 USDHC Storage Controllers |
24 | s->regs[R_DMA_LEN] -= 4; | 26 | * 1 Designware PCI Express Controller |
25 | + s->regs[R_DMA_CHECKSUM] += data; | 27 | + * 1 Ethernet Controller |
28 | * 5 GPIO Controllers | ||
29 | * 6 I2C Controllers | ||
30 | * 3 SPI Controllers | ||
31 | diff --git a/include/hw/arm/fsl-imx8mp.h b/include/hw/arm/fsl-imx8mp.h | ||
32 | index XXXXXXX..XXXXXXX 100644 | ||
33 | --- a/include/hw/arm/fsl-imx8mp.h | ||
34 | +++ b/include/hw/arm/fsl-imx8mp.h | ||
35 | @@ -XXX,XX +XXX,XX @@ | ||
36 | #include "hw/misc/imx7_snvs.h" | ||
37 | #include "hw/misc/imx8mp_analog.h" | ||
38 | #include "hw/misc/imx8mp_ccm.h" | ||
39 | +#include "hw/net/imx_fec.h" | ||
40 | #include "hw/or-irq.h" | ||
41 | #include "hw/pci-host/designware.h" | ||
42 | #include "hw/pci-host/fsl_imx8m_phy.h" | ||
43 | @@ -XXX,XX +XXX,XX @@ struct FslImx8mpState { | ||
44 | IMXSPIState spi[FSL_IMX8MP_NUM_ECSPIS]; | ||
45 | IMXI2CState i2c[FSL_IMX8MP_NUM_I2CS]; | ||
46 | IMXSerialState uart[FSL_IMX8MP_NUM_UARTS]; | ||
47 | + IMXFECState enet; | ||
48 | SDHCIState usdhc[FSL_IMX8MP_NUM_USDHCS]; | ||
49 | IMX2WdtState wdt[FSL_IMX8MP_NUM_WDTS]; | ||
50 | DesignwarePCIEHost pcie; | ||
51 | FslImx8mPciePhyState pcie_phy; | ||
52 | OrIRQState gpt5_gpt6_irq; | ||
53 | + | ||
54 | + uint32_t phy_num; | ||
55 | + bool phy_connected; | ||
56 | }; | ||
57 | |||
58 | enum FslImx8mpMemoryRegions { | ||
59 | @@ -XXX,XX +XXX,XX @@ enum FslImx8mpIrqs { | ||
60 | FSL_IMX8MP_WDOG2_IRQ = 79, | ||
61 | FSL_IMX8MP_WDOG3_IRQ = 10, | ||
62 | |||
63 | + FSL_IMX8MP_ENET1_MAC_IRQ = 118, | ||
64 | + FSL_IMX6_ENET1_MAC_1588_IRQ = 121, | ||
65 | + | ||
66 | FSL_IMX8MP_PCI_INTA_IRQ = 126, | ||
67 | FSL_IMX8MP_PCI_INTB_IRQ = 125, | ||
68 | FSL_IMX8MP_PCI_INTC_IRQ = 124, | ||
69 | diff --git a/hw/arm/fsl-imx8mp.c b/hw/arm/fsl-imx8mp.c | ||
70 | index XXXXXXX..XXXXXXX 100644 | ||
71 | --- a/hw/arm/fsl-imx8mp.c | ||
72 | +++ b/hw/arm/fsl-imx8mp.c | ||
73 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx8mp_init(Object *obj) | ||
74 | object_initialize_child(obj, name, &s->wdt[i], TYPE_IMX2_WDT); | ||
75 | } | ||
76 | |||
77 | + object_initialize_child(obj, "eth0", &s->enet, TYPE_IMX_ENET); | ||
78 | + | ||
79 | object_initialize_child(obj, "pcie", &s->pcie, TYPE_DESIGNWARE_PCIE_HOST); | ||
80 | object_initialize_child(obj, "pcie_phy", &s->pcie_phy, | ||
81 | TYPE_FSL_IMX8M_PCIE_PHY); | ||
82 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp) | ||
83 | qdev_get_gpio_in(gicdev, spi_table[i].irq)); | ||
84 | } | ||
85 | |||
86 | + /* ENET1 */ | ||
87 | + object_property_set_uint(OBJECT(&s->enet), "phy-num", s->phy_num, | ||
88 | + &error_abort); | ||
89 | + object_property_set_uint(OBJECT(&s->enet), "tx-ring-num", 3, &error_abort); | ||
90 | + qemu_configure_nic_device(DEVICE(&s->enet), true, NULL); | ||
91 | + if (!sysbus_realize(SYS_BUS_DEVICE(&s->enet), errp)) { | ||
92 | + return; | ||
93 | + } | ||
94 | + sysbus_mmio_map(SYS_BUS_DEVICE(&s->enet), 0, | ||
95 | + fsl_imx8mp_memmap[FSL_IMX8MP_ENET1].addr); | ||
96 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->enet), 0, | ||
97 | + qdev_get_gpio_in(gicdev, FSL_IMX8MP_ENET1_MAC_IRQ)); | ||
98 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->enet), 1, | ||
99 | + qdev_get_gpio_in(gicdev, FSL_IMX6_ENET1_MAC_1588_IRQ)); | ||
100 | + | ||
101 | /* SNVS */ | ||
102 | if (!sysbus_realize(SYS_BUS_DEVICE(&s->snvs), errp)) { | ||
103 | return; | ||
104 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp) | ||
105 | case FSL_IMX8MP_GIC_REDIST: | ||
106 | case FSL_IMX8MP_GPIO1 ... FSL_IMX8MP_GPIO5: | ||
107 | case FSL_IMX8MP_ECSPI1 ... FSL_IMX8MP_ECSPI3: | ||
108 | + case FSL_IMX8MP_ENET1: | ||
109 | case FSL_IMX8MP_I2C1 ... FSL_IMX8MP_I2C6: | ||
110 | case FSL_IMX8MP_PCIE1: | ||
111 | case FSL_IMX8MP_PCIE_PHY1: | ||
112 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp) | ||
26 | } | 113 | } |
27 | } | 114 | } |
28 | 115 | ||
116 | +static const Property fsl_imx8mp_properties[] = { | ||
117 | + DEFINE_PROP_UINT32("fec1-phy-num", FslImx8mpState, phy_num, 0), | ||
118 | + DEFINE_PROP_BOOL("fec1-phy-connected", FslImx8mpState, phy_connected, true), | ||
119 | +}; | ||
120 | + | ||
121 | static void fsl_imx8mp_class_init(ObjectClass *oc, void *data) | ||
122 | { | ||
123 | DeviceClass *dc = DEVICE_CLASS(oc); | ||
124 | |||
125 | + device_class_set_props(dc, fsl_imx8mp_properties); | ||
126 | dc->realize = fsl_imx8mp_realize; | ||
127 | |||
128 | dc->desc = "i.MX 8M Plus SoC"; | ||
129 | diff --git a/hw/arm/imx8mp-evk.c b/hw/arm/imx8mp-evk.c | ||
130 | index XXXXXXX..XXXXXXX 100644 | ||
131 | --- a/hw/arm/imx8mp-evk.c | ||
132 | +++ b/hw/arm/imx8mp-evk.c | ||
133 | @@ -XXX,XX +XXX,XX @@ static void imx8mp_evk_init(MachineState *machine) | ||
134 | |||
135 | s = FSL_IMX8MP(object_new(TYPE_FSL_IMX8MP)); | ||
136 | object_property_add_child(OBJECT(machine), "soc", OBJECT(s)); | ||
137 | + object_property_set_uint(OBJECT(s), "fec1-phy-num", 1, &error_fatal); | ||
138 | qdev_realize(DEVICE(s), NULL, &error_fatal); | ||
139 | |||
140 | memory_region_add_subregion(get_system_memory(), FSL_IMX8MP_RAM_START, | ||
141 | diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig | ||
142 | index XXXXXXX..XXXXXXX 100644 | ||
143 | --- a/hw/arm/Kconfig | ||
144 | +++ b/hw/arm/Kconfig | ||
145 | @@ -XXX,XX +XXX,XX @@ config FSL_IMX8MP | ||
146 | select FSL_IMX8MP_ANALOG | ||
147 | select FSL_IMX8MP_CCM | ||
148 | select IMX | ||
149 | + select IMX_FEC | ||
150 | select IMX_I2C | ||
151 | select OR_IRQ | ||
152 | select PCI_EXPRESS_DESIGNWARE | ||
29 | -- | 153 | -- |
30 | 2.20.1 | 154 | 2.43.0 |
31 | |||
32 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Bernhard Beschow <shentey@gmail.com> | ||
1 | 2 | ||
3 | Split the USB MMIO regions to better keep track of the implemented vs. | ||
4 | unimplemented regions. | ||
5 | |||
6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
7 | Signed-off-by: Bernhard Beschow <shentey@gmail.com> | ||
8 | Message-id: 20250223114708.1780-16-shentey@gmail.com | ||
9 | [PMM: drop "static const" from usb_table for GCC 7.5] | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
11 | --- | ||
12 | docs/system/arm/imx8mp-evk.rst | 1 + | ||
13 | include/hw/arm/fsl-imx8mp.h | 12 +++++++++++ | ||
14 | hw/arm/fsl-imx8mp.c | 37 ++++++++++++++++++++++++++++++++-- | ||
15 | hw/arm/Kconfig | 1 + | ||
16 | 4 files changed, 49 insertions(+), 2 deletions(-) | ||
17 | |||
18 | diff --git a/docs/system/arm/imx8mp-evk.rst b/docs/system/arm/imx8mp-evk.rst | ||
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/docs/system/arm/imx8mp-evk.rst | ||
21 | +++ b/docs/system/arm/imx8mp-evk.rst | ||
22 | @@ -XXX,XX +XXX,XX @@ The ``imx8mp-evk`` machine implements the following devices: | ||
23 | * 3 USDHC Storage Controllers | ||
24 | * 1 Designware PCI Express Controller | ||
25 | * 1 Ethernet Controller | ||
26 | + * 2 Designware USB 3 Controllers | ||
27 | * 5 GPIO Controllers | ||
28 | * 6 I2C Controllers | ||
29 | * 3 SPI Controllers | ||
30 | diff --git a/include/hw/arm/fsl-imx8mp.h b/include/hw/arm/fsl-imx8mp.h | ||
31 | index XXXXXXX..XXXXXXX 100644 | ||
32 | --- a/include/hw/arm/fsl-imx8mp.h | ||
33 | +++ b/include/hw/arm/fsl-imx8mp.h | ||
34 | @@ -XXX,XX +XXX,XX @@ | ||
35 | #include "hw/sd/sdhci.h" | ||
36 | #include "hw/ssi/imx_spi.h" | ||
37 | #include "hw/timer/imx_gpt.h" | ||
38 | +#include "hw/usb/hcd-dwc3.h" | ||
39 | #include "hw/watchdog/wdt_imx2.h" | ||
40 | #include "qom/object.h" | ||
41 | #include "qemu/units.h" | ||
42 | @@ -XXX,XX +XXX,XX @@ enum FslImx8mpConfiguration { | ||
43 | FSL_IMX8MP_NUM_I2CS = 6, | ||
44 | FSL_IMX8MP_NUM_IRQS = 160, | ||
45 | FSL_IMX8MP_NUM_UARTS = 4, | ||
46 | + FSL_IMX8MP_NUM_USBS = 2, | ||
47 | FSL_IMX8MP_NUM_USDHCS = 3, | ||
48 | FSL_IMX8MP_NUM_WDTS = 3, | ||
49 | }; | ||
50 | @@ -XXX,XX +XXX,XX @@ struct FslImx8mpState { | ||
51 | IMXFECState enet; | ||
52 | SDHCIState usdhc[FSL_IMX8MP_NUM_USDHCS]; | ||
53 | IMX2WdtState wdt[FSL_IMX8MP_NUM_WDTS]; | ||
54 | + USBDWC3 usb[FSL_IMX8MP_NUM_USBS]; | ||
55 | DesignwarePCIEHost pcie; | ||
56 | FslImx8mPciePhyState pcie_phy; | ||
57 | OrIRQState gpt5_gpt6_irq; | ||
58 | @@ -XXX,XX +XXX,XX @@ enum FslImx8mpMemoryRegions { | ||
59 | FSL_IMX8MP_UART4, | ||
60 | FSL_IMX8MP_USB1, | ||
61 | FSL_IMX8MP_USB2, | ||
62 | + FSL_IMX8MP_USB1_DEV, | ||
63 | + FSL_IMX8MP_USB2_DEV, | ||
64 | + FSL_IMX8MP_USB1_OTG, | ||
65 | + FSL_IMX8MP_USB2_OTG, | ||
66 | + FSL_IMX8MP_USB1_GLUE, | ||
67 | + FSL_IMX8MP_USB2_GLUE, | ||
68 | FSL_IMX8MP_USDHC1, | ||
69 | FSL_IMX8MP_USDHC2, | ||
70 | FSL_IMX8MP_USDHC3, | ||
71 | @@ -XXX,XX +XXX,XX @@ enum FslImx8mpIrqs { | ||
72 | FSL_IMX8MP_I2C3_IRQ = 37, | ||
73 | FSL_IMX8MP_I2C4_IRQ = 38, | ||
74 | |||
75 | + FSL_IMX8MP_USB1_IRQ = 40, | ||
76 | + FSL_IMX8MP_USB2_IRQ = 41, | ||
77 | + | ||
78 | FSL_IMX8MP_GPT1_IRQ = 55, | ||
79 | FSL_IMX8MP_GPT2_IRQ = 54, | ||
80 | FSL_IMX8MP_GPT3_IRQ = 53, | ||
81 | diff --git a/hw/arm/fsl-imx8mp.c b/hw/arm/fsl-imx8mp.c | ||
82 | index XXXXXXX..XXXXXXX 100644 | ||
83 | --- a/hw/arm/fsl-imx8mp.c | ||
84 | +++ b/hw/arm/fsl-imx8mp.c | ||
85 | @@ -XXX,XX +XXX,XX @@ static const struct { | ||
86 | [FSL_IMX8MP_VPU_VC8000E_ENCODER] = { 0x38320000, 2 * MiB, "vpu_vc8000e_encoder" }, | ||
87 | [FSL_IMX8MP_VPU_G2_DECODER] = { 0x38310000, 2 * MiB, "vpu_g2_decoder" }, | ||
88 | [FSL_IMX8MP_VPU_G1_DECODER] = { 0x38300000, 2 * MiB, "vpu_g1_decoder" }, | ||
89 | - [FSL_IMX8MP_USB2] = { 0x38200000, 1 * MiB, "usb2" }, | ||
90 | - [FSL_IMX8MP_USB1] = { 0x38100000, 1 * MiB, "usb1" }, | ||
91 | + [FSL_IMX8MP_USB2_GLUE] = { 0x382f0000, 0x100, "usb2_glue" }, | ||
92 | + [FSL_IMX8MP_USB2_OTG] = { 0x3820cc00, 0x100, "usb2_otg" }, | ||
93 | + [FSL_IMX8MP_USB2_DEV] = { 0x3820c700, 0x500, "usb2_dev" }, | ||
94 | + [FSL_IMX8MP_USB2] = { 0x38200000, 0xc700, "usb2" }, | ||
95 | + [FSL_IMX8MP_USB1_GLUE] = { 0x381f0000, 0x100, "usb1_glue" }, | ||
96 | + [FSL_IMX8MP_USB1_OTG] = { 0x3810cc00, 0x100, "usb1_otg" }, | ||
97 | + [FSL_IMX8MP_USB1_DEV] = { 0x3810c700, 0x500, "usb1_dev" }, | ||
98 | + [FSL_IMX8MP_USB1] = { 0x38100000, 0xc700, "usb1" }, | ||
99 | [FSL_IMX8MP_GPU2D] = { 0x38008000, 32 * KiB, "gpu2d" }, | ||
100 | [FSL_IMX8MP_GPU3D] = { 0x38000000, 32 * KiB, "gpu3d" }, | ||
101 | [FSL_IMX8MP_QSPI1_RX_BUFFER] = { 0x34000000, 32 * MiB, "qspi1_rx_buffer" }, | ||
102 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx8mp_init(Object *obj) | ||
103 | object_initialize_child(obj, name, &s->usdhc[i], TYPE_IMX_USDHC); | ||
104 | } | ||
105 | |||
106 | + for (i = 0; i < FSL_IMX8MP_NUM_USBS; i++) { | ||
107 | + g_autofree char *name = g_strdup_printf("usb%d", i); | ||
108 | + object_initialize_child(obj, name, &s->usb[i], TYPE_USB_DWC3); | ||
109 | + } | ||
110 | + | ||
111 | for (i = 0; i < FSL_IMX8MP_NUM_ECSPIS; i++) { | ||
112 | g_autofree char *name = g_strdup_printf("spi%d", i + 1); | ||
113 | object_initialize_child(obj, name, &s->spi[i], TYPE_IMX_SPI); | ||
114 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp) | ||
115 | qdev_get_gpio_in(gicdev, usdhc_table[i].irq)); | ||
116 | } | ||
117 | |||
118 | + /* USBs */ | ||
119 | + for (i = 0; i < FSL_IMX8MP_NUM_USBS; i++) { | ||
120 | + struct { | ||
121 | + hwaddr addr; | ||
122 | + unsigned int irq; | ||
123 | + } usb_table[FSL_IMX8MP_NUM_USBS] = { | ||
124 | + { fsl_imx8mp_memmap[FSL_IMX8MP_USB1].addr, FSL_IMX8MP_USB1_IRQ }, | ||
125 | + { fsl_imx8mp_memmap[FSL_IMX8MP_USB2].addr, FSL_IMX8MP_USB2_IRQ }, | ||
126 | + }; | ||
127 | + | ||
128 | + qdev_prop_set_uint32(DEVICE(&s->usb[i].sysbus_xhci), "p2", 1); | ||
129 | + qdev_prop_set_uint32(DEVICE(&s->usb[i].sysbus_xhci), "p3", 1); | ||
130 | + qdev_prop_set_uint32(DEVICE(&s->usb[i].sysbus_xhci), "slots", 2); | ||
131 | + if (!sysbus_realize(SYS_BUS_DEVICE(&s->usb[i]), errp)) { | ||
132 | + return; | ||
133 | + } | ||
134 | + sysbus_mmio_map(SYS_BUS_DEVICE(&s->usb[i]), 0, usb_table[i].addr); | ||
135 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->usb[i].sysbus_xhci), 0, | ||
136 | + qdev_get_gpio_in(gicdev, usb_table[i].irq)); | ||
137 | + } | ||
138 | + | ||
139 | /* ECSPIs */ | ||
140 | for (i = 0; i < FSL_IMX8MP_NUM_ECSPIS; i++) { | ||
141 | struct { | ||
142 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp) | ||
143 | case FSL_IMX8MP_RAM: | ||
144 | case FSL_IMX8MP_SNVS_HP: | ||
145 | case FSL_IMX8MP_UART1 ... FSL_IMX8MP_UART4: | ||
146 | + case FSL_IMX8MP_USB1 ... FSL_IMX8MP_USB2: | ||
147 | case FSL_IMX8MP_USDHC1 ... FSL_IMX8MP_USDHC3: | ||
148 | case FSL_IMX8MP_WDOG1 ... FSL_IMX8MP_WDOG3: | ||
149 | /* device implemented and treated above */ | ||
150 | diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig | ||
151 | index XXXXXXX..XXXXXXX 100644 | ||
152 | --- a/hw/arm/Kconfig | ||
153 | +++ b/hw/arm/Kconfig | ||
154 | @@ -XXX,XX +XXX,XX @@ config FSL_IMX8MP | ||
155 | select PCI_EXPRESS_FSL_IMX8M_PHY | ||
156 | select SDHCI | ||
157 | select UNIMP | ||
158 | + select USB_DWC3 | ||
159 | select WDT_IMX2 | ||
160 | |||
161 | config FSL_IMX8MP_EVK | ||
162 | -- | ||
163 | 2.43.0 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Bernhard Beschow <shentey@gmail.com> | ||
1 | 2 | ||
3 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
4 | Signed-off-by: Bernhard Beschow <shentey@gmail.com> | ||
5 | Message-id: 20250223114708.1780-18-shentey@gmail.com | ||
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
7 | --- | ||
8 | include/hw/arm/fsl-imx8mp.h | 1 + | ||
9 | hw/arm/fsl-imx8mp.c | 11 +++++++++++ | ||
10 | 2 files changed, 12 insertions(+) | ||
11 | |||
12 | diff --git a/include/hw/arm/fsl-imx8mp.h b/include/hw/arm/fsl-imx8mp.h | ||
13 | index XXXXXXX..XXXXXXX 100644 | ||
14 | --- a/include/hw/arm/fsl-imx8mp.h | ||
15 | +++ b/include/hw/arm/fsl-imx8mp.h | ||
16 | @@ -XXX,XX +XXX,XX @@ struct FslImx8mpState { | ||
17 | DesignwarePCIEHost pcie; | ||
18 | FslImx8mPciePhyState pcie_phy; | ||
19 | OrIRQState gpt5_gpt6_irq; | ||
20 | + MemoryRegion ocram; | ||
21 | |||
22 | uint32_t phy_num; | ||
23 | bool phy_connected; | ||
24 | diff --git a/hw/arm/fsl-imx8mp.c b/hw/arm/fsl-imx8mp.c | ||
25 | index XXXXXXX..XXXXXXX 100644 | ||
26 | --- a/hw/arm/fsl-imx8mp.c | ||
27 | +++ b/hw/arm/fsl-imx8mp.c | ||
28 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp) | ||
29 | sysbus_mmio_map(SYS_BUS_DEVICE(&s->pcie_phy), 0, | ||
30 | fsl_imx8mp_memmap[FSL_IMX8MP_PCIE_PHY1].addr); | ||
31 | |||
32 | + /* On-Chip RAM */ | ||
33 | + if (!memory_region_init_ram(&s->ocram, NULL, "imx8mp.ocram", | ||
34 | + fsl_imx8mp_memmap[FSL_IMX8MP_OCRAM].size, | ||
35 | + errp)) { | ||
36 | + return; | ||
37 | + } | ||
38 | + memory_region_add_subregion(get_system_memory(), | ||
39 | + fsl_imx8mp_memmap[FSL_IMX8MP_OCRAM].addr, | ||
40 | + &s->ocram); | ||
41 | + | ||
42 | /* Unimplemented devices */ | ||
43 | for (i = 0; i < ARRAY_SIZE(fsl_imx8mp_memmap); i++) { | ||
44 | switch (i) { | ||
45 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx8mp_realize(DeviceState *dev, Error **errp) | ||
46 | case FSL_IMX8MP_ECSPI1 ... FSL_IMX8MP_ECSPI3: | ||
47 | case FSL_IMX8MP_ENET1: | ||
48 | case FSL_IMX8MP_I2C1 ... FSL_IMX8MP_I2C6: | ||
49 | + case FSL_IMX8MP_OCRAM: | ||
50 | case FSL_IMX8MP_PCIE1: | ||
51 | case FSL_IMX8MP_PCIE_PHY1: | ||
52 | case FSL_IMX8MP_RAM: | ||
53 | -- | ||
54 | 2.43.0 | diff view generated by jsdifflib |