1 | The following changes since commit 8f6330a807f2642dc2a3cdf33347aa28a4c00a87: | 1 | Hi; here's the first arm pullreq for 9.1. |
---|---|---|---|
2 | 2 | ||
3 | Merge tag 'pull-maintainer-updates-060324-1' of https://gitlab.com/stsquad/qemu into staging (2024-03-06 16:56:20 +0000) | 3 | This includes the reset method function signature change, so it has |
4 | some chance of compile failures due to merge conflicts if some other | ||
5 | pullreq added a device reset method and that pullreq got applied | ||
6 | before this one. If so, the changes needed to fix those up can be | ||
7 | created by running the spatch rune described in the commit message of | ||
8 | the "hw, target: Add ResetType argument to hold and exit phase | ||
9 | methods" commit. | ||
10 | |||
11 | thanks | ||
12 | -- PMM | ||
13 | |||
14 | The following changes since commit 5da72194df36535d773c8bdc951529ecd5e31707: | ||
15 | |||
16 | Merge tag 'pull-tcg-20240424' of https://gitlab.com/rth7680/qemu into staging (2024-04-24 15:51:49 -0700) | ||
4 | 17 | ||
5 | are available in the Git repository at: | 18 | are available in the Git repository at: |
6 | 19 | ||
7 | https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20240308 | 20 | https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20240425 |
8 | 21 | ||
9 | for you to fetch changes up to bbf6c6dbead82292a20951eb1204442a6b838de9: | 22 | for you to fetch changes up to 214652da123e3821657a64691ee556281e9f6238: |
10 | 23 | ||
11 | target/arm: Move v7m-related code from cpu32.c into a separate file (2024-03-08 14:45:03 +0000) | 24 | tests/qtest: Add tests for the STM32L4x5 USART (2024-04-25 10:21:59 +0100) |
12 | 25 | ||
13 | ---------------------------------------------------------------- | 26 | ---------------------------------------------------------------- |
14 | target-arm queue: | 27 | target-arm queue: |
15 | * Implement FEAT_ECV | 28 | * Implement FEAT_NMI and NMI support in the GICv3 |
16 | * STM32L4x5: Implement GPIO device | 29 | * hw/dma: avoid apparent overflow in soc_dma_set_request |
17 | * Fix 32-bit SMOPA | 30 | * linux-user/flatload.c: Remove unused bFLT shared-library and ZFLAT code |
18 | * Refactor v7m related code from cpu32.c into its own file | 31 | * Add ResetType argument to Resettable hold and exit phase methods |
19 | * hw/rtc/sun4v-rtc: Relicense to GPLv2-or-later | 32 | * Add RESET_TYPE_SNAPSHOT_LOAD ResetType |
33 | * Implement STM32L4x5 USART | ||
20 | 34 | ||
21 | ---------------------------------------------------------------- | 35 | ---------------------------------------------------------------- |
22 | Inès Varhol (3): | 36 | Anastasia Belova (1): |
23 | hw/gpio: Implement STM32L4x5 GPIO | 37 | hw/dma: avoid apparent overflow in soc_dma_set_request |
24 | hw/arm: Connect STM32L4x5 GPIO to STM32L4x5 SoC | 38 | |
25 | tests/qtest: Add STM32L4x5 GPIO QTest testcase | 39 | Arnaud Minier (5): |
40 | hw/char: Implement STM32L4x5 USART skeleton | ||
41 | hw/char/stm32l4x5_usart: Enable serial read and write | ||
42 | hw/char/stm32l4x5_usart: Add options for serial parameters setting | ||
43 | hw/arm: Add the USART to the stm32l4x5 SoC | ||
44 | tests/qtest: Add tests for the STM32L4x5 USART | ||
45 | |||
46 | Jinjie Ruan (22): | ||
47 | target/arm: Handle HCR_EL2 accesses for bits introduced with FEAT_NMI | ||
48 | target/arm: Add PSTATE.ALLINT | ||
49 | target/arm: Add support for FEAT_NMI, Non-maskable Interrupt | ||
50 | target/arm: Implement ALLINT MSR (immediate) | ||
51 | target/arm: Support MSR access to ALLINT | ||
52 | target/arm: Add support for Non-maskable Interrupt | ||
53 | target/arm: Add support for NMI in arm_phys_excp_target_el() | ||
54 | target/arm: Handle IS/FS in ISR_EL1 for NMI, VINMI and VFNMI | ||
55 | target/arm: Handle PSTATE.ALLINT on taking an exception | ||
56 | hw/intc/arm_gicv3: Add external IRQ lines for NMI | ||
57 | hw/arm/virt: Wire NMI and VINMI irq lines from GIC to CPU | ||
58 | target/arm: Handle NMI in arm_cpu_do_interrupt_aarch64() | ||
59 | hw/intc/arm_gicv3: Add has-nmi property to GICv3 device | ||
60 | hw/intc/arm_gicv3_kvm: Not set has-nmi=true for the KVM GICv3 | ||
61 | hw/intc/arm_gicv3: Add irq non-maskable property | ||
62 | hw/intc/arm_gicv3_redist: Implement GICR_INMIR0 | ||
63 | hw/intc/arm_gicv3: Implement GICD_INMIR | ||
64 | hw/intc/arm_gicv3: Implement NMI interrupt priority | ||
65 | hw/intc/arm_gicv3: Report the NMI interrupt in gicv3_cpuif_update() | ||
66 | hw/intc/arm_gicv3: Report the VINMI interrupt | ||
67 | target/arm: Add FEAT_NMI to max | ||
68 | hw/arm/virt: Enable NMI support in the GIC if the CPU has FEAT_NMI | ||
26 | 69 | ||
27 | Peter Maydell (9): | 70 | Peter Maydell (9): |
28 | target/arm: Move some register related defines to internals.h | 71 | hw/intc/arm_gicv3: Add NMI handling CPU interface registers |
29 | target/arm: Timer _EL02 registers UNDEF for E2H == 0 | 72 | hw/intc/arm_gicv3: Handle icv_nmiar1_read() for icc_nmiar1_read() |
30 | target/arm: use FIELD macro for CNTHCTL bit definitions | 73 | linux-user/flatload.c: Remove unused bFLT shared-library and ZFLAT code |
31 | target/arm: Don't allow RES0 CNTHCTL_EL2 bits to be written | 74 | hw/misc: Don't special case RESET_TYPE_COLD in npcm7xx_clk, gcr |
32 | target/arm: Implement new FEAT_ECV trap bits | 75 | allwinner-i2c, adm1272: Use device_cold_reset() for software-triggered reset |
33 | target/arm: Define CNTPCTSS_EL0 and CNTVCTSS_EL0 | 76 | scripts/coccinelle: New script to add ResetType to hold and exit phases |
34 | target/arm: Implement FEAT_ECV CNTPOFF_EL2 handling | 77 | hw, target: Add ResetType argument to hold and exit phase methods |
35 | target/arm: Enable FEAT_ECV for 'max' CPU | 78 | docs/devel/reset: Update to new API for hold and exit phase methods |
36 | hw/rtc/sun4v-rtc: Relicense to GPLv2-or-later | 79 | reset: Add RESET_TYPE_SNAPSHOT_LOAD |
37 | 80 | ||
38 | Richard Henderson (1): | 81 | MAINTAINERS | 1 + |
39 | target/arm: Fix 32-bit SMOPA | 82 | docs/devel/reset.rst | 25 +- |
40 | 83 | docs/system/arm/b-l475e-iot01a.rst | 2 +- | |
41 | Thomas Huth (1): | 84 | docs/system/arm/emulation.rst | 1 + |
42 | target/arm: Move v7m-related code from cpu32.c into a separate file | 85 | scripts/coccinelle/reset-type.cocci | 133 ++++++++ |
43 | 86 | hw/intc/gicv3_internal.h | 13 + | |
44 | MAINTAINERS | 1 + | 87 | include/hw/arm/stm32l4x5_soc.h | 7 + |
45 | docs/system/arm/b-l475e-iot01a.rst | 2 +- | 88 | include/hw/char/stm32l4x5_usart.h | 67 ++++ |
46 | docs/system/arm/emulation.rst | 1 + | 89 | include/hw/intc/arm_gic_common.h | 2 + |
47 | include/hw/arm/stm32l4x5_soc.h | 2 + | 90 | include/hw/intc/arm_gicv3_common.h | 14 + |
48 | include/hw/gpio/stm32l4x5_gpio.h | 71 +++++ | 91 | include/hw/resettable.h | 5 +- |
49 | include/hw/misc/stm32l4x5_syscfg.h | 3 +- | 92 | linux-user/flat.h | 5 +- |
50 | include/hw/rtc/sun4v-rtc.h | 2 +- | 93 | target/arm/cpu-features.h | 5 + |
51 | target/arm/cpu-features.h | 10 + | 94 | target/arm/cpu-qom.h | 5 +- |
52 | target/arm/cpu.h | 129 +-------- | 95 | target/arm/cpu.h | 9 + |
53 | target/arm/internals.h | 151 ++++++++++ | 96 | target/arm/internals.h | 21 ++ |
54 | hw/arm/stm32l4x5_soc.c | 71 ++++- | 97 | target/arm/tcg/helper-a64.h | 1 + |
55 | hw/gpio/stm32l4x5_gpio.c | 477 ++++++++++++++++++++++++++++++++ | 98 | target/arm/tcg/a64.decode | 1 + |
56 | hw/misc/stm32l4x5_syscfg.c | 1 + | 99 | hw/adc/npcm7xx_adc.c | 2 +- |
57 | hw/rtc/sun4v-rtc.c | 2 +- | 100 | hw/arm/pxa2xx_pic.c | 2 +- |
58 | target/arm/helper.c | 189 ++++++++++++- | 101 | hw/arm/smmu-common.c | 2 +- |
59 | target/arm/tcg/cpu-v7m.c | 290 +++++++++++++++++++ | 102 | hw/arm/smmuv3.c | 4 +- |
60 | target/arm/tcg/cpu32.c | 261 ------------------ | 103 | hw/arm/stellaris.c | 10 +- |
61 | target/arm/tcg/cpu64.c | 1 + | 104 | hw/arm/stm32l4x5_soc.c | 83 ++++- |
62 | target/arm/tcg/sme_helper.c | 77 +++--- | 105 | hw/arm/virt.c | 29 +- |
63 | tests/qtest/stm32l4x5_gpio-test.c | 551 +++++++++++++++++++++++++++++++++++++ | 106 | hw/audio/asc.c | 2 +- |
64 | tests/tcg/aarch64/sme-smopa-1.c | 47 ++++ | 107 | hw/char/cadence_uart.c | 2 +- |
65 | tests/tcg/aarch64/sme-smopa-2.c | 54 ++++ | 108 | hw/char/sifive_uart.c | 2 +- |
66 | hw/arm/Kconfig | 3 +- | 109 | hw/char/stm32l4x5_usart.c | 637 ++++++++++++++++++++++++++++++++++++ |
67 | hw/gpio/Kconfig | 3 + | 110 | hw/core/cpu-common.c | 2 +- |
68 | hw/gpio/meson.build | 1 + | 111 | hw/core/qdev.c | 4 +- |
69 | hw/gpio/trace-events | 6 + | 112 | hw/core/reset.c | 17 +- |
70 | target/arm/meson.build | 3 + | 113 | hw/core/resettable.c | 8 +- |
71 | target/arm/tcg/meson.build | 3 + | 114 | hw/display/virtio-vga.c | 4 +- |
72 | target/arm/trace-events | 1 + | 115 | hw/dma/soc_dma.c | 4 +- |
73 | tests/qtest/meson.build | 3 +- | 116 | hw/gpio/npcm7xx_gpio.c | 2 +- |
74 | tests/tcg/aarch64/Makefile.target | 2 +- | 117 | hw/gpio/pl061.c | 2 +- |
75 | 31 files changed, 1962 insertions(+), 456 deletions(-) | 118 | hw/gpio/stm32l4x5_gpio.c | 2 +- |
76 | create mode 100644 include/hw/gpio/stm32l4x5_gpio.h | 119 | hw/hyperv/vmbus.c | 2 +- |
77 | create mode 100644 hw/gpio/stm32l4x5_gpio.c | 120 | hw/i2c/allwinner-i2c.c | 5 +- |
78 | create mode 100644 target/arm/tcg/cpu-v7m.c | 121 | hw/i2c/npcm7xx_smbus.c | 2 +- |
79 | create mode 100644 tests/qtest/stm32l4x5_gpio-test.c | 122 | hw/input/adb.c | 2 +- |
80 | create mode 100644 tests/tcg/aarch64/sme-smopa-1.c | 123 | hw/input/ps2.c | 12 +- |
81 | create mode 100644 tests/tcg/aarch64/sme-smopa-2.c | 124 | hw/intc/arm_gic_common.c | 2 +- |
82 | 125 | hw/intc/arm_gic_kvm.c | 4 +- | |
126 | hw/intc/arm_gicv3.c | 67 +++- | ||
127 | hw/intc/arm_gicv3_common.c | 50 ++- | ||
128 | hw/intc/arm_gicv3_cpuif.c | 268 ++++++++++++++- | ||
129 | hw/intc/arm_gicv3_dist.c | 36 ++ | ||
130 | hw/intc/arm_gicv3_its.c | 4 +- | ||
131 | hw/intc/arm_gicv3_its_common.c | 2 +- | ||
132 | hw/intc/arm_gicv3_its_kvm.c | 4 +- | ||
133 | hw/intc/arm_gicv3_kvm.c | 9 +- | ||
134 | hw/intc/arm_gicv3_redist.c | 22 ++ | ||
135 | hw/intc/xics.c | 2 +- | ||
136 | hw/m68k/q800-glue.c | 2 +- | ||
137 | hw/misc/djmemc.c | 2 +- | ||
138 | hw/misc/iosb.c | 2 +- | ||
139 | hw/misc/mac_via.c | 8 +- | ||
140 | hw/misc/macio/cuda.c | 4 +- | ||
141 | hw/misc/macio/pmu.c | 4 +- | ||
142 | hw/misc/mos6522.c | 2 +- | ||
143 | hw/misc/npcm7xx_clk.c | 13 +- | ||
144 | hw/misc/npcm7xx_gcr.c | 12 +- | ||
145 | hw/misc/npcm7xx_mft.c | 2 +- | ||
146 | hw/misc/npcm7xx_pwm.c | 2 +- | ||
147 | hw/misc/stm32l4x5_exti.c | 2 +- | ||
148 | hw/misc/stm32l4x5_rcc.c | 10 +- | ||
149 | hw/misc/stm32l4x5_syscfg.c | 2 +- | ||
150 | hw/misc/xlnx-versal-cframe-reg.c | 2 +- | ||
151 | hw/misc/xlnx-versal-crl.c | 2 +- | ||
152 | hw/misc/xlnx-versal-pmc-iou-slcr.c | 2 +- | ||
153 | hw/misc/xlnx-versal-trng.c | 2 +- | ||
154 | hw/misc/xlnx-versal-xramc.c | 2 +- | ||
155 | hw/misc/xlnx-zynqmp-apu-ctrl.c | 2 +- | ||
156 | hw/misc/xlnx-zynqmp-crf.c | 2 +- | ||
157 | hw/misc/zynq_slcr.c | 4 +- | ||
158 | hw/net/can/xlnx-zynqmp-can.c | 2 +- | ||
159 | hw/net/e1000.c | 2 +- | ||
160 | hw/net/e1000e.c | 2 +- | ||
161 | hw/net/igb.c | 2 +- | ||
162 | hw/net/igbvf.c | 2 +- | ||
163 | hw/nvram/xlnx-bbram.c | 2 +- | ||
164 | hw/nvram/xlnx-versal-efuse-ctrl.c | 2 +- | ||
165 | hw/nvram/xlnx-zynqmp-efuse.c | 2 +- | ||
166 | hw/pci-bridge/cxl_root_port.c | 4 +- | ||
167 | hw/pci-bridge/pcie_root_port.c | 2 +- | ||
168 | hw/pci-host/bonito.c | 2 +- | ||
169 | hw/pci-host/pnv_phb.c | 4 +- | ||
170 | hw/pci-host/pnv_phb3_msi.c | 4 +- | ||
171 | hw/pci/pci.c | 4 +- | ||
172 | hw/rtc/mc146818rtc.c | 2 +- | ||
173 | hw/s390x/css-bridge.c | 2 +- | ||
174 | hw/sensor/adm1266.c | 2 +- | ||
175 | hw/sensor/adm1272.c | 4 +- | ||
176 | hw/sensor/isl_pmbus_vr.c | 10 +- | ||
177 | hw/sensor/max31785.c | 2 +- | ||
178 | hw/sensor/max34451.c | 2 +- | ||
179 | hw/ssi/npcm7xx_fiu.c | 2 +- | ||
180 | hw/timer/etraxfs_timer.c | 2 +- | ||
181 | hw/timer/npcm7xx_timer.c | 2 +- | ||
182 | hw/usb/hcd-dwc2.c | 8 +- | ||
183 | hw/usb/xlnx-versal-usb2-ctrl-regs.c | 2 +- | ||
184 | hw/virtio/virtio-pci.c | 2 +- | ||
185 | linux-user/flatload.c | 293 +---------------- | ||
186 | target/arm/cpu.c | 151 ++++++++- | ||
187 | target/arm/helper.c | 101 +++++- | ||
188 | target/arm/tcg/cpu64.c | 1 + | ||
189 | target/arm/tcg/helper-a64.c | 16 +- | ||
190 | target/arm/tcg/translate-a64.c | 19 ++ | ||
191 | target/avr/cpu.c | 4 +- | ||
192 | target/cris/cpu.c | 4 +- | ||
193 | target/hexagon/cpu.c | 4 +- | ||
194 | target/i386/cpu.c | 4 +- | ||
195 | target/loongarch/cpu.c | 4 +- | ||
196 | target/m68k/cpu.c | 4 +- | ||
197 | target/microblaze/cpu.c | 4 +- | ||
198 | target/mips/cpu.c | 4 +- | ||
199 | target/openrisc/cpu.c | 4 +- | ||
200 | target/ppc/cpu_init.c | 4 +- | ||
201 | target/riscv/cpu.c | 4 +- | ||
202 | target/rx/cpu.c | 4 +- | ||
203 | target/sh4/cpu.c | 4 +- | ||
204 | target/sparc/cpu.c | 4 +- | ||
205 | target/tricore/cpu.c | 4 +- | ||
206 | target/xtensa/cpu.c | 4 +- | ||
207 | tests/qtest/stm32l4x5_usart-test.c | 315 ++++++++++++++++++ | ||
208 | hw/arm/Kconfig | 1 + | ||
209 | hw/char/Kconfig | 3 + | ||
210 | hw/char/meson.build | 1 + | ||
211 | hw/char/trace-events | 12 + | ||
212 | hw/intc/trace-events | 2 + | ||
213 | tests/qtest/meson.build | 4 +- | ||
214 | 133 files changed, 2239 insertions(+), 537 deletions(-) | ||
215 | create mode 100644 scripts/coccinelle/reset-type.cocci | ||
216 | create mode 100644 include/hw/char/stm32l4x5_usart.h | ||
217 | create mode 100644 hw/char/stm32l4x5_usart.c | ||
218 | create mode 100644 tests/qtest/stm32l4x5_usart-test.c | diff view generated by jsdifflib |
1 | The functionality defined by ID_AA64MMFR0_EL1.ECV == 1 is: | 1 | From: Jinjie Ruan <ruanjinjie@huawei.com> |
---|---|---|---|
2 | * four new trap bits for various counter and timer registers | ||
3 | * the CNTHCTL_EL2.EVNTIS and CNTKCTL_EL1.EVNTIS bits which control | ||
4 | scaling of the event stream. This is a no-op for us, because we don't | ||
5 | implement the event stream (our WFE is a NOP): all we need to do is | ||
6 | allow CNTHCTL_EL2.ENVTIS to be read and written. | ||
7 | * extensions to PMSCR_EL1.PCT, PMSCR_EL2.PCT, TRFCR_EL1.TS and | ||
8 | TRFCR_EL2.TS: these are all no-ops for us, because we don't implement | ||
9 | FEAT_SPE or FEAT_TRF. | ||
10 | * new registers CNTPCTSS_EL0 and NCTVCTSS_EL0 which are | ||
11 | "self-sychronizing" views of the CNTPCT_EL0 and CNTVCT_EL0, meaning | ||
12 | that no barriers are needed around their accesses. For us these | ||
13 | are just the same as the normal views, because all our sysregs are | ||
14 | inherently self-sychronizing. | ||
15 | 2 | ||
16 | In this commit we implement the trap handling and permit the new | 3 | FEAT_NMI defines another three new bits in HCRX_EL2: TALLINT, HCRX_VINMI and |
17 | CNTHCTL_EL2 bits to be written. | 4 | HCRX_VFNMI. When the feature is enabled, allow these bits to be written in |
5 | HCRX_EL2. | ||
18 | 6 | ||
7 | Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> | ||
8 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
10 | Message-id: 20240407081733.3231820-2-ruanjinjie@huawei.com | ||
19 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
20 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
21 | Message-id: 20240301183219.2424889-6-peter.maydell@linaro.org | ||
22 | --- | 12 | --- |
23 | target/arm/cpu-features.h | 5 ++++ | 13 | target/arm/cpu-features.h | 5 +++++ |
24 | target/arm/helper.c | 51 +++++++++++++++++++++++++++++++++++---- | 14 | target/arm/helper.c | 8 +++++++- |
25 | 2 files changed, 51 insertions(+), 5 deletions(-) | 15 | 2 files changed, 12 insertions(+), 1 deletion(-) |
26 | 16 | ||
27 | diff --git a/target/arm/cpu-features.h b/target/arm/cpu-features.h | 17 | diff --git a/target/arm/cpu-features.h b/target/arm/cpu-features.h |
28 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
29 | --- a/target/arm/cpu-features.h | 19 | --- a/target/arm/cpu-features.h |
30 | +++ b/target/arm/cpu-features.h | 20 | +++ b/target/arm/cpu-features.h |
31 | @@ -XXX,XX +XXX,XX @@ static inline bool isar_feature_aa64_fgt(const ARMISARegisters *id) | 21 | @@ -XXX,XX +XXX,XX @@ static inline bool isar_feature_aa64_sme(const ARMISARegisters *id) |
32 | return FIELD_EX64(id->id_aa64mmfr0, ID_AA64MMFR0, FGT) != 0; | 22 | return FIELD_EX64(id->id_aa64pfr1, ID_AA64PFR1, SME) != 0; |
33 | } | 23 | } |
34 | 24 | ||
35 | +static inline bool isar_feature_aa64_ecv_traps(const ARMISARegisters *id) | 25 | +static inline bool isar_feature_aa64_nmi(const ARMISARegisters *id) |
36 | +{ | 26 | +{ |
37 | + return FIELD_EX64(id->id_aa64mmfr0, ID_AA64MMFR0, ECV) > 0; | 27 | + return FIELD_EX64(id->id_aa64pfr1, ID_AA64PFR1, NMI) != 0; |
38 | +} | 28 | +} |
39 | + | 29 | + |
40 | static inline bool isar_feature_aa64_vh(const ARMISARegisters *id) | 30 | static inline bool isar_feature_aa64_tgran4_lpa2(const ARMISARegisters *id) |
41 | { | 31 | { |
42 | return FIELD_EX64(id->id_aa64mmfr1, ID_AA64MMFR1, VH) != 0; | 32 | return FIELD_SEX64(id->id_aa64mmfr0, ID_AA64MMFR0, TGRAN4) >= 1; |
43 | diff --git a/target/arm/helper.c b/target/arm/helper.c | 33 | diff --git a/target/arm/helper.c b/target/arm/helper.c |
44 | index XXXXXXX..XXXXXXX 100644 | 34 | index XXXXXXX..XXXXXXX 100644 |
45 | --- a/target/arm/helper.c | 35 | --- a/target/arm/helper.c |
46 | +++ b/target/arm/helper.c | 36 | +++ b/target/arm/helper.c |
47 | @@ -XXX,XX +XXX,XX @@ static CPAccessResult gt_counter_access(CPUARMState *env, int timeridx, | 37 | @@ -XXX,XX +XXX,XX @@ bool el_is_in_host(CPUARMState *env, int el) |
48 | : !extract32(env->cp15.cnthctl_el2, 0, 1))) { | 38 | static void hcrx_write(CPUARMState *env, const ARMCPRegInfo *ri, |
49 | return CP_ACCESS_TRAP_EL2; | 39 | uint64_t value) |
50 | } | 40 | { |
51 | + if (has_el2 && timeridx == GTIMER_VIRT) { | 41 | + ARMCPU *cpu = env_archcpu(env); |
52 | + if (FIELD_EX64(env->cp15.cnthctl_el2, CNTHCTL, EL1TVCT)) { | 42 | uint64_t valid_mask = 0; |
53 | + return CP_ACCESS_TRAP_EL2; | 43 | |
54 | + } | 44 | /* FEAT_MOPS adds MSCEn and MCE2 */ |
55 | + } | 45 | - if (cpu_isar_feature(aa64_mops, env_archcpu(env))) { |
56 | break; | 46 | + if (cpu_isar_feature(aa64_mops, cpu)) { |
47 | valid_mask |= HCRX_MSCEN | HCRX_MCE2; | ||
57 | } | 48 | } |
58 | return CP_ACCESS_OK; | 49 | |
59 | @@ -XXX,XX +XXX,XX @@ static CPAccessResult gt_timer_access(CPUARMState *env, int timeridx, | 50 | + /* FEAT_NMI adds TALLINT, VINMI and VFNMI */ |
60 | } | 51 | + if (cpu_isar_feature(aa64_nmi, cpu)) { |
61 | } | 52 | + valid_mask |= HCRX_TALLINT | HCRX_VINMI | HCRX_VFNMI; |
62 | } | ||
63 | + if (has_el2 && timeridx == GTIMER_VIRT) { | ||
64 | + if (FIELD_EX64(env->cp15.cnthctl_el2, CNTHCTL, EL1TVT)) { | ||
65 | + return CP_ACCESS_TRAP_EL2; | ||
66 | + } | ||
67 | + } | ||
68 | break; | ||
69 | } | ||
70 | return CP_ACCESS_OK; | ||
71 | @@ -XXX,XX +XXX,XX @@ static void gt_cnthctl_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
72 | if (cpu_isar_feature(aa64_rme, cpu)) { | ||
73 | valid_mask |= R_CNTHCTL_CNTVMASK_MASK | R_CNTHCTL_CNTPMASK_MASK; | ||
74 | } | ||
75 | + if (cpu_isar_feature(aa64_ecv_traps, cpu)) { | ||
76 | + valid_mask |= | ||
77 | + R_CNTHCTL_EL1TVT_MASK | | ||
78 | + R_CNTHCTL_EL1TVCT_MASK | | ||
79 | + R_CNTHCTL_EL1NVPCT_MASK | | ||
80 | + R_CNTHCTL_EL1NVVCT_MASK | | ||
81 | + R_CNTHCTL_EVNTIS_MASK; | ||
82 | + } | 53 | + } |
83 | 54 | + | |
84 | /* Clear RES0 bits */ | 55 | /* Clear RES0 bits. */ |
85 | value &= valid_mask; | 56 | env->cp15.hcrx_el2 = value & valid_mask; |
86 | @@ -XXX,XX +XXX,XX @@ static CPAccessResult e2h_access(CPUARMState *env, const ARMCPRegInfo *ri, | ||
87 | { | ||
88 | if (arm_current_el(env) == 1) { | ||
89 | /* This must be a FEAT_NV access */ | ||
90 | - /* TODO: FEAT_ECV will need to check CNTHCTL_EL2 here */ | ||
91 | return CP_ACCESS_OK; | ||
92 | } | ||
93 | if (!(arm_hcr_el2_eff(env) & HCR_E2H)) { | ||
94 | @@ -XXX,XX +XXX,XX @@ static CPAccessResult e2h_access(CPUARMState *env, const ARMCPRegInfo *ri, | ||
95 | return CP_ACCESS_OK; | ||
96 | } | 57 | } |
97 | |||
98 | +static CPAccessResult access_el1nvpct(CPUARMState *env, const ARMCPRegInfo *ri, | ||
99 | + bool isread) | ||
100 | +{ | ||
101 | + if (arm_current_el(env) == 1) { | ||
102 | + /* This must be a FEAT_NV access with NVx == 101 */ | ||
103 | + if (FIELD_EX64(env->cp15.cnthctl_el2, CNTHCTL, EL1NVPCT)) { | ||
104 | + return CP_ACCESS_TRAP_EL2; | ||
105 | + } | ||
106 | + } | ||
107 | + return e2h_access(env, ri, isread); | ||
108 | +} | ||
109 | + | ||
110 | +static CPAccessResult access_el1nvvct(CPUARMState *env, const ARMCPRegInfo *ri, | ||
111 | + bool isread) | ||
112 | +{ | ||
113 | + if (arm_current_el(env) == 1) { | ||
114 | + /* This must be a FEAT_NV access with NVx == 101 */ | ||
115 | + if (FIELD_EX64(env->cp15.cnthctl_el2, CNTHCTL, EL1NVVCT)) { | ||
116 | + return CP_ACCESS_TRAP_EL2; | ||
117 | + } | ||
118 | + } | ||
119 | + return e2h_access(env, ri, isread); | ||
120 | +} | ||
121 | + | ||
122 | /* Test if system register redirection is to occur in the current state. */ | ||
123 | static bool redirect_for_e2h(CPUARMState *env) | ||
124 | { | ||
125 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo vhe_reginfo[] = { | ||
126 | { .name = "CNTP_CTL_EL02", .state = ARM_CP_STATE_AA64, | ||
127 | .opc0 = 3, .opc1 = 5, .crn = 14, .crm = 2, .opc2 = 1, | ||
128 | .type = ARM_CP_IO | ARM_CP_ALIAS, | ||
129 | - .access = PL2_RW, .accessfn = e2h_access, | ||
130 | + .access = PL2_RW, .accessfn = access_el1nvpct, | ||
131 | .nv2_redirect_offset = 0x180 | NV2_REDIR_NO_NV1, | ||
132 | .fieldoffset = offsetof(CPUARMState, cp15.c14_timer[GTIMER_PHYS].ctl), | ||
133 | .writefn = gt_phys_ctl_write, .raw_writefn = raw_write }, | ||
134 | { .name = "CNTV_CTL_EL02", .state = ARM_CP_STATE_AA64, | ||
135 | .opc0 = 3, .opc1 = 5, .crn = 14, .crm = 3, .opc2 = 1, | ||
136 | .type = ARM_CP_IO | ARM_CP_ALIAS, | ||
137 | - .access = PL2_RW, .accessfn = e2h_access, | ||
138 | + .access = PL2_RW, .accessfn = access_el1nvvct, | ||
139 | .nv2_redirect_offset = 0x170 | NV2_REDIR_NO_NV1, | ||
140 | .fieldoffset = offsetof(CPUARMState, cp15.c14_timer[GTIMER_VIRT].ctl), | ||
141 | .writefn = gt_virt_ctl_write, .raw_writefn = raw_write }, | ||
142 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo vhe_reginfo[] = { | ||
143 | .type = ARM_CP_IO | ARM_CP_ALIAS, | ||
144 | .fieldoffset = offsetof(CPUARMState, cp15.c14_timer[GTIMER_PHYS].cval), | ||
145 | .nv2_redirect_offset = 0x178 | NV2_REDIR_NO_NV1, | ||
146 | - .access = PL2_RW, .accessfn = e2h_access, | ||
147 | + .access = PL2_RW, .accessfn = access_el1nvpct, | ||
148 | .writefn = gt_phys_cval_write, .raw_writefn = raw_write }, | ||
149 | { .name = "CNTV_CVAL_EL02", .state = ARM_CP_STATE_AA64, | ||
150 | .opc0 = 3, .opc1 = 5, .crn = 14, .crm = 3, .opc2 = 2, | ||
151 | .type = ARM_CP_IO | ARM_CP_ALIAS, | ||
152 | .nv2_redirect_offset = 0x168 | NV2_REDIR_NO_NV1, | ||
153 | .fieldoffset = offsetof(CPUARMState, cp15.c14_timer[GTIMER_VIRT].cval), | ||
154 | - .access = PL2_RW, .accessfn = e2h_access, | ||
155 | + .access = PL2_RW, .accessfn = access_el1nvvct, | ||
156 | .writefn = gt_virt_cval_write, .raw_writefn = raw_write }, | ||
157 | #endif | ||
158 | }; | ||
159 | -- | 58 | -- |
160 | 2.34.1 | 59 | 2.34.1 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Jinjie Ruan <ruanjinjie@huawei.com> | ||
1 | 2 | ||
3 | When PSTATE.ALLINT is set, an IRQ or FIQ interrupt that is targeted to | ||
4 | ELx, with or without superpriority is masked. As Richard suggested, place | ||
5 | ALLINT bit in PSTATE in env->pstate. | ||
6 | |||
7 | In the pseudocode, AArch64.ExceptionReturn() calls SetPSTATEFromPSR(), which | ||
8 | treats PSTATE.ALLINT as one of the bits which are reinstated from SPSR to | ||
9 | PSTATE regardless of whether this is an illegal exception return or not. So | ||
10 | handle PSTATE.ALLINT the same way as PSTATE.DAIF in the illegal_return exit | ||
11 | path of the exception_return helper. With the change, exception entry and | ||
12 | return are automatically handled. | ||
13 | |||
14 | Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> | ||
15 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
16 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
17 | Message-id: 20240407081733.3231820-3-ruanjinjie@huawei.com | ||
18 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
19 | --- | ||
20 | target/arm/cpu.h | 1 + | ||
21 | target/arm/tcg/helper-a64.c | 4 ++-- | ||
22 | 2 files changed, 3 insertions(+), 2 deletions(-) | ||
23 | |||
24 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | ||
25 | index XXXXXXX..XXXXXXX 100644 | ||
26 | --- a/target/arm/cpu.h | ||
27 | +++ b/target/arm/cpu.h | ||
28 | @@ -XXX,XX +XXX,XX @@ void pmu_init(ARMCPU *cpu); | ||
29 | #define PSTATE_D (1U << 9) | ||
30 | #define PSTATE_BTYPE (3U << 10) | ||
31 | #define PSTATE_SSBS (1U << 12) | ||
32 | +#define PSTATE_ALLINT (1U << 13) | ||
33 | #define PSTATE_IL (1U << 20) | ||
34 | #define PSTATE_SS (1U << 21) | ||
35 | #define PSTATE_PAN (1U << 22) | ||
36 | diff --git a/target/arm/tcg/helper-a64.c b/target/arm/tcg/helper-a64.c | ||
37 | index XXXXXXX..XXXXXXX 100644 | ||
38 | --- a/target/arm/tcg/helper-a64.c | ||
39 | +++ b/target/arm/tcg/helper-a64.c | ||
40 | @@ -XXX,XX +XXX,XX @@ illegal_return: | ||
41 | */ | ||
42 | env->pstate |= PSTATE_IL; | ||
43 | env->pc = new_pc; | ||
44 | - spsr &= PSTATE_NZCV | PSTATE_DAIF; | ||
45 | - spsr |= pstate_read(env) & ~(PSTATE_NZCV | PSTATE_DAIF); | ||
46 | + spsr &= PSTATE_NZCV | PSTATE_DAIF | PSTATE_ALLINT; | ||
47 | + spsr |= pstate_read(env) & ~(PSTATE_NZCV | PSTATE_DAIF | PSTATE_ALLINT); | ||
48 | pstate_write(env, spsr); | ||
49 | if (!arm_singlestep_active(env)) { | ||
50 | env->pstate &= ~PSTATE_SS; | ||
51 | -- | ||
52 | 2.34.1 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Jinjie Ruan <ruanjinjie@huawei.com> | ||
1 | 2 | ||
3 | Add support for FEAT_NMI. NMI (FEAT_NMI) is an mandatory feature in | ||
4 | ARMv8.8-A and ARM v9.3-A. | ||
5 | |||
6 | Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> | ||
7 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
9 | Message-id: 20240407081733.3231820-4-ruanjinjie@huawei.com | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
11 | --- | ||
12 | target/arm/internals.h | 3 +++ | ||
13 | 1 file changed, 3 insertions(+) | ||
14 | |||
15 | diff --git a/target/arm/internals.h b/target/arm/internals.h | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/target/arm/internals.h | ||
18 | +++ b/target/arm/internals.h | ||
19 | @@ -XXX,XX +XXX,XX @@ static inline uint32_t aarch64_pstate_valid_mask(const ARMISARegisters *id) | ||
20 | if (isar_feature_aa64_mte(id)) { | ||
21 | valid |= PSTATE_TCO; | ||
22 | } | ||
23 | + if (isar_feature_aa64_nmi(id)) { | ||
24 | + valid |= PSTATE_ALLINT; | ||
25 | + } | ||
26 | |||
27 | return valid; | ||
28 | } | ||
29 | -- | ||
30 | 2.34.1 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Jinjie Ruan <ruanjinjie@huawei.com> | ||
1 | 2 | ||
3 | Add ALLINT MSR (immediate) to decodetree, in which the CRm is 0b000x. The | ||
4 | EL0 check is necessary to ALLINT, and the EL1 check is necessary when | ||
5 | imm == 1. So implement it inline for EL2/3, or EL1 with imm==0. Avoid the | ||
6 | unconditional write to pc and use raise_exception_ra to unwind. | ||
7 | |||
8 | Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> | ||
9 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
10 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
11 | Message-id: 20240407081733.3231820-5-ruanjinjie@huawei.com | ||
12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
13 | --- | ||
14 | target/arm/tcg/helper-a64.h | 1 + | ||
15 | target/arm/tcg/a64.decode | 1 + | ||
16 | target/arm/tcg/helper-a64.c | 12 ++++++++++++ | ||
17 | target/arm/tcg/translate-a64.c | 19 +++++++++++++++++++ | ||
18 | 4 files changed, 33 insertions(+) | ||
19 | |||
20 | diff --git a/target/arm/tcg/helper-a64.h b/target/arm/tcg/helper-a64.h | ||
21 | index XXXXXXX..XXXXXXX 100644 | ||
22 | --- a/target/arm/tcg/helper-a64.h | ||
23 | +++ b/target/arm/tcg/helper-a64.h | ||
24 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_1(rbit64, TCG_CALL_NO_RWG_SE, i64, i64) | ||
25 | DEF_HELPER_2(msr_i_spsel, void, env, i32) | ||
26 | DEF_HELPER_2(msr_i_daifset, void, env, i32) | ||
27 | DEF_HELPER_2(msr_i_daifclear, void, env, i32) | ||
28 | +DEF_HELPER_1(msr_set_allint_el1, void, env) | ||
29 | DEF_HELPER_3(vfp_cmph_a64, i64, f16, f16, ptr) | ||
30 | DEF_HELPER_3(vfp_cmpeh_a64, i64, f16, f16, ptr) | ||
31 | DEF_HELPER_3(vfp_cmps_a64, i64, f32, f32, ptr) | ||
32 | diff --git a/target/arm/tcg/a64.decode b/target/arm/tcg/a64.decode | ||
33 | index XXXXXXX..XXXXXXX 100644 | ||
34 | --- a/target/arm/tcg/a64.decode | ||
35 | +++ b/target/arm/tcg/a64.decode | ||
36 | @@ -XXX,XX +XXX,XX @@ MSR_i_DIT 1101 0101 0000 0 011 0100 .... 010 11111 @msr_i | ||
37 | MSR_i_TCO 1101 0101 0000 0 011 0100 .... 100 11111 @msr_i | ||
38 | MSR_i_DAIFSET 1101 0101 0000 0 011 0100 .... 110 11111 @msr_i | ||
39 | MSR_i_DAIFCLEAR 1101 0101 0000 0 011 0100 .... 111 11111 @msr_i | ||
40 | +MSR_i_ALLINT 1101 0101 0000 0 001 0100 000 imm:1 000 11111 | ||
41 | MSR_i_SVCR 1101 0101 0000 0 011 0100 0 mask:2 imm:1 011 11111 | ||
42 | |||
43 | # MRS, MSR (register), SYS, SYSL. These are all essentially the | ||
44 | diff --git a/target/arm/tcg/helper-a64.c b/target/arm/tcg/helper-a64.c | ||
45 | index XXXXXXX..XXXXXXX 100644 | ||
46 | --- a/target/arm/tcg/helper-a64.c | ||
47 | +++ b/target/arm/tcg/helper-a64.c | ||
48 | @@ -XXX,XX +XXX,XX @@ void HELPER(msr_i_spsel)(CPUARMState *env, uint32_t imm) | ||
49 | update_spsel(env, imm); | ||
50 | } | ||
51 | |||
52 | +void HELPER(msr_set_allint_el1)(CPUARMState *env) | ||
53 | +{ | ||
54 | + /* ALLINT update to PSTATE. */ | ||
55 | + if (arm_hcrx_el2_eff(env) & HCRX_TALLINT) { | ||
56 | + raise_exception_ra(env, EXCP_UDEF, | ||
57 | + syn_aa64_sysregtrap(0, 1, 0, 4, 1, 0x1f, 0), 2, | ||
58 | + GETPC()); | ||
59 | + } | ||
60 | + | ||
61 | + env->pstate |= PSTATE_ALLINT; | ||
62 | +} | ||
63 | + | ||
64 | static void daif_check(CPUARMState *env, uint32_t op, | ||
65 | uint32_t imm, uintptr_t ra) | ||
66 | { | ||
67 | diff --git a/target/arm/tcg/translate-a64.c b/target/arm/tcg/translate-a64.c | ||
68 | index XXXXXXX..XXXXXXX 100644 | ||
69 | --- a/target/arm/tcg/translate-a64.c | ||
70 | +++ b/target/arm/tcg/translate-a64.c | ||
71 | @@ -XXX,XX +XXX,XX @@ static bool trans_MSR_i_DAIFCLEAR(DisasContext *s, arg_i *a) | ||
72 | return true; | ||
73 | } | ||
74 | |||
75 | +static bool trans_MSR_i_ALLINT(DisasContext *s, arg_i *a) | ||
76 | +{ | ||
77 | + if (!dc_isar_feature(aa64_nmi, s) || s->current_el == 0) { | ||
78 | + return false; | ||
79 | + } | ||
80 | + | ||
81 | + if (a->imm == 0) { | ||
82 | + clear_pstate_bits(PSTATE_ALLINT); | ||
83 | + } else if (s->current_el > 1) { | ||
84 | + set_pstate_bits(PSTATE_ALLINT); | ||
85 | + } else { | ||
86 | + gen_helper_msr_set_allint_el1(tcg_env); | ||
87 | + } | ||
88 | + | ||
89 | + /* Exit the cpu loop to re-evaluate pending IRQs. */ | ||
90 | + s->base.is_jmp = DISAS_UPDATE_EXIT; | ||
91 | + return true; | ||
92 | +} | ||
93 | + | ||
94 | static bool trans_MSR_i_SVCR(DisasContext *s, arg_MSR_i_SVCR *a) | ||
95 | { | ||
96 | if (!dc_isar_feature(aa64_sme, s) || a->mask == 0) { | ||
97 | -- | ||
98 | 2.34.1 | diff view generated by jsdifflib |
1 | For FEAT_ECV, new registers CNTPCTSS_EL0 and CNTVCTSS_EL0 are | 1 | From: Jinjie Ruan <ruanjinjie@huawei.com> |
---|---|---|---|
2 | defined, which are "self-synchronized" views of the physical and | ||
3 | virtual counts as seen in the CNTPCT_EL0 and CNTVCT_EL0 registers | ||
4 | (meaning that no barriers are needed around accesses to them to | ||
5 | ensure that reads of them do not occur speculatively and out-of-order | ||
6 | with other instructions). | ||
7 | 2 | ||
8 | For QEMU, all our system registers are self-synchronized, so we can | 3 | Support ALLINT msr access as follow: |
9 | simply copy the existing implementation of CNTPCT_EL0 and CNTVCT_EL0 | 4 | mrs <xt>, ALLINT // read allint |
10 | to the new register encodings. | 5 | msr ALLINT, <xt> // write allint with imm |
11 | 6 | ||
12 | This means we now implement all the functionality required for | 7 | Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> |
13 | ID_AA64MMFR0_EL1.ECV == 0b0001. | 8 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
14 | 9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | |
10 | Message-id: 20240407081733.3231820-6-ruanjinjie@huawei.com | ||
15 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
16 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
17 | Message-id: 20240301183219.2424889-7-peter.maydell@linaro.org | ||
18 | --- | 12 | --- |
19 | target/arm/helper.c | 43 +++++++++++++++++++++++++++++++++++++++++++ | 13 | target/arm/helper.c | 35 +++++++++++++++++++++++++++++++++++ |
20 | 1 file changed, 43 insertions(+) | 14 | 1 file changed, 35 insertions(+) |
21 | 15 | ||
22 | diff --git a/target/arm/helper.c b/target/arm/helper.c | 16 | diff --git a/target/arm/helper.c b/target/arm/helper.c |
23 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
24 | --- a/target/arm/helper.c | 18 | --- a/target/arm/helper.c |
25 | +++ b/target/arm/helper.c | 19 | +++ b/target/arm/helper.c |
26 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo generic_timer_cp_reginfo[] = { | 20 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo rme_mte_reginfo[] = { |
27 | }, | 21 | .opc0 = 1, .opc1 = 6, .crn = 7, .crm = 14, .opc2 = 5, |
22 | .access = PL3_W, .type = ARM_CP_NOP }, | ||
28 | }; | 23 | }; |
29 | 24 | + | |
30 | +/* | 25 | +static void aa64_allint_write(CPUARMState *env, const ARMCPRegInfo *ri, |
31 | + * FEAT_ECV adds extra views of CNTVCT_EL0 and CNTPCT_EL0 which | 26 | + uint64_t value) |
32 | + * are "self-synchronizing". For QEMU all sysregs are self-synchronizing, | 27 | +{ |
33 | + * so our implementations here are identical to the normal registers. | 28 | + env->pstate = (env->pstate & ~PSTATE_ALLINT) | (value & PSTATE_ALLINT); |
34 | + */ | 29 | +} |
35 | +static const ARMCPRegInfo gen_timer_ecv_cp_reginfo[] = { | 30 | + |
36 | + { .name = "CNTVCTSS", .cp = 15, .crm = 14, .opc1 = 9, | 31 | +static uint64_t aa64_allint_read(CPUARMState *env, const ARMCPRegInfo *ri) |
37 | + .access = PL0_R, .type = ARM_CP_64BIT | ARM_CP_NO_RAW | ARM_CP_IO, | 32 | +{ |
38 | + .accessfn = gt_vct_access, | 33 | + return env->pstate & PSTATE_ALLINT; |
39 | + .readfn = gt_virt_cnt_read, .resetfn = arm_cp_reset_ignore, | 34 | +} |
40 | + }, | 35 | + |
41 | + { .name = "CNTVCTSS_EL0", .state = ARM_CP_STATE_AA64, | 36 | +static CPAccessResult aa64_allint_access(CPUARMState *env, |
42 | + .opc0 = 3, .opc1 = 3, .crn = 14, .crm = 0, .opc2 = 6, | 37 | + const ARMCPRegInfo *ri, bool isread) |
43 | + .access = PL0_R, .type = ARM_CP_NO_RAW | ARM_CP_IO, | 38 | +{ |
44 | + .accessfn = gt_vct_access, .readfn = gt_virt_cnt_read, | 39 | + if (!isread && arm_current_el(env) == 1 && |
45 | + }, | 40 | + (arm_hcrx_el2_eff(env) & HCRX_TALLINT)) { |
46 | + { .name = "CNTPCTSS", .cp = 15, .crm = 14, .opc1 = 8, | 41 | + return CP_ACCESS_TRAP_EL2; |
47 | + .access = PL0_R, .type = ARM_CP_64BIT | ARM_CP_NO_RAW | ARM_CP_IO, | 42 | + } |
48 | + .accessfn = gt_pct_access, | 43 | + return CP_ACCESS_OK; |
49 | + .readfn = gt_cnt_read, .resetfn = arm_cp_reset_ignore, | 44 | +} |
50 | + }, | 45 | + |
51 | + { .name = "CNTPCTSS_EL0", .state = ARM_CP_STATE_AA64, | 46 | +static const ARMCPRegInfo nmi_reginfo[] = { |
52 | + .opc0 = 3, .opc1 = 3, .crn = 14, .crm = 0, .opc2 = 5, | 47 | + { .name = "ALLINT", .state = ARM_CP_STATE_AA64, |
53 | + .access = PL0_R, .type = ARM_CP_NO_RAW | ARM_CP_IO, | 48 | + .opc0 = 3, .opc1 = 0, .opc2 = 0, .crn = 4, .crm = 3, |
54 | + .accessfn = gt_pct_access, .readfn = gt_cnt_read, | 49 | + .type = ARM_CP_NO_RAW, |
55 | + }, | 50 | + .access = PL1_RW, .accessfn = aa64_allint_access, |
51 | + .fieldoffset = offsetof(CPUARMState, pstate), | ||
52 | + .writefn = aa64_allint_write, .readfn = aa64_allint_read, | ||
53 | + .resetfn = arm_cp_reset_ignore }, | ||
56 | +}; | 54 | +}; |
55 | #endif /* TARGET_AARCH64 */ | ||
56 | |||
57 | static void define_pmu_regs(ARMCPU *cpu) | ||
58 | @@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu) | ||
59 | if (cpu_isar_feature(aa64_nv2, cpu)) { | ||
60 | define_arm_cp_regs(cpu, nv2_reginfo); | ||
61 | } | ||
57 | + | 62 | + |
58 | #else | 63 | + if (cpu_isar_feature(aa64_nmi, cpu)) { |
59 | 64 | + define_arm_cp_regs(cpu, nmi_reginfo); | |
60 | /* | 65 | + } |
61 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo generic_timer_cp_reginfo[] = { | ||
62 | }, | ||
63 | }; | ||
64 | |||
65 | +/* | ||
66 | + * CNTVCTSS_EL0 has the same trap conditions as CNTVCT_EL0, so it also | ||
67 | + * is exposed to userspace by Linux. | ||
68 | + */ | ||
69 | +static const ARMCPRegInfo gen_timer_ecv_cp_reginfo[] = { | ||
70 | + { .name = "CNTVCTSS_EL0", .state = ARM_CP_STATE_AA64, | ||
71 | + .opc0 = 3, .opc1 = 3, .crn = 14, .crm = 0, .opc2 = 6, | ||
72 | + .access = PL0_R, .type = ARM_CP_NO_RAW | ARM_CP_IO, | ||
73 | + .readfn = gt_virt_cnt_read, | ||
74 | + }, | ||
75 | +}; | ||
76 | + | ||
77 | #endif | 66 | #endif |
78 | 67 | ||
79 | static void par_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value) | 68 | if (cpu_isar_feature(any_predinv, cpu)) { |
80 | @@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu) | ||
81 | if (arm_feature(env, ARM_FEATURE_GENERIC_TIMER)) { | ||
82 | define_arm_cp_regs(cpu, generic_timer_cp_reginfo); | ||
83 | } | ||
84 | + if (cpu_isar_feature(aa64_ecv_traps, cpu)) { | ||
85 | + define_arm_cp_regs(cpu, gen_timer_ecv_cp_reginfo); | ||
86 | + } | ||
87 | if (arm_feature(env, ARM_FEATURE_VAPA)) { | ||
88 | ARMCPRegInfo vapa_cp_reginfo[] = { | ||
89 | { .name = "PAR", .cp = 15, .crn = 7, .crm = 4, .opc1 = 0, .opc2 = 0, | ||
90 | -- | 69 | -- |
91 | 2.34.1 | 70 | 2.34.1 | diff view generated by jsdifflib |
1 | cpu.h has a lot of #defines relating to CPU register fields. | 1 | From: Jinjie Ruan <ruanjinjie@huawei.com> |
---|---|---|---|
2 | Most of these aren't actually used outside target/arm code, | ||
3 | so there's no point in cluttering up the cpu.h file with them. | ||
4 | Move some easy ones to internals.h. | ||
5 | 2 | ||
3 | This only implements the external delivery method via the GICv3. | ||
4 | |||
5 | Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> | ||
6 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
8 | Message-id: 20240407081733.3231820-7-ruanjinjie@huawei.com | ||
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
7 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
8 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
9 | Message-id: 20240301183219.2424889-2-peter.maydell@linaro.org | ||
10 | --- | 10 | --- |
11 | target/arm/cpu.h | 128 ----------------------------------------- | 11 | target/arm/cpu-qom.h | 5 +- |
12 | target/arm/internals.h | 128 +++++++++++++++++++++++++++++++++++++++++ | 12 | target/arm/cpu.h | 6 ++ |
13 | 2 files changed, 128 insertions(+), 128 deletions(-) | 13 | target/arm/internals.h | 18 +++++ |
14 | target/arm/cpu.c | 147 ++++++++++++++++++++++++++++++++++++++--- | ||
15 | target/arm/helper.c | 33 +++++++-- | ||
16 | 5 files changed, 193 insertions(+), 16 deletions(-) | ||
14 | 17 | ||
18 | diff --git a/target/arm/cpu-qom.h b/target/arm/cpu-qom.h | ||
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/target/arm/cpu-qom.h | ||
21 | +++ b/target/arm/cpu-qom.h | ||
22 | @@ -XXX,XX +XXX,XX @@ DECLARE_CLASS_CHECKERS(AArch64CPUClass, AARCH64_CPU, | ||
23 | #define ARM_CPU_TYPE_SUFFIX "-" TYPE_ARM_CPU | ||
24 | #define ARM_CPU_TYPE_NAME(name) (name ARM_CPU_TYPE_SUFFIX) | ||
25 | |||
26 | -/* Meanings of the ARMCPU object's four inbound GPIO lines */ | ||
27 | +/* Meanings of the ARMCPU object's seven inbound GPIO lines */ | ||
28 | #define ARM_CPU_IRQ 0 | ||
29 | #define ARM_CPU_FIQ 1 | ||
30 | #define ARM_CPU_VIRQ 2 | ||
31 | #define ARM_CPU_VFIQ 3 | ||
32 | +#define ARM_CPU_NMI 4 | ||
33 | +#define ARM_CPU_VINMI 5 | ||
34 | +#define ARM_CPU_VFNMI 6 | ||
35 | |||
36 | /* For M profile, some registers are banked secure vs non-secure; | ||
37 | * these are represented as a 2-element array where the first element | ||
15 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | 38 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h |
16 | index XXXXXXX..XXXXXXX 100644 | 39 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/target/arm/cpu.h | 40 | --- a/target/arm/cpu.h |
18 | +++ b/target/arm/cpu.h | 41 | +++ b/target/arm/cpu.h |
19 | @@ -XXX,XX +XXX,XX @@ typedef struct ARMGenericTimer { | 42 | @@ -XXX,XX +XXX,XX @@ |
20 | uint64_t ctl; /* Timer Control register */ | 43 | #define EXCP_DIVBYZERO 23 /* v7M DIVBYZERO UsageFault */ |
21 | } ARMGenericTimer; | 44 | #define EXCP_VSERR 24 |
22 | 45 | #define EXCP_GPC 25 /* v9 Granule Protection Check Fault */ | |
23 | -#define VTCR_NSW (1u << 29) | 46 | +#define EXCP_NMI 26 |
24 | -#define VTCR_NSA (1u << 30) | 47 | +#define EXCP_VINMI 27 |
25 | -#define VSTCR_SW VTCR_NSW | 48 | +#define EXCP_VFNMI 28 |
26 | -#define VSTCR_SA VTCR_NSA | 49 | /* NB: add new EXCP_ defines to the array in arm_log_exception() too */ |
27 | - | 50 | |
28 | /* Define a maximum sized vector register. | 51 | #define ARMV7M_EXCP_RESET 1 |
29 | * For 32-bit, this is a 128-bit NEON/AdvSIMD register. | 52 | @@ -XXX,XX +XXX,XX @@ |
30 | * For 64-bit, this is a 2048-bit SVE register. | 53 | #define CPU_INTERRUPT_VIRQ CPU_INTERRUPT_TGT_EXT_2 |
31 | @@ -XXX,XX +XXX,XX @@ void pmu_init(ARMCPU *cpu); | 54 | #define CPU_INTERRUPT_VFIQ CPU_INTERRUPT_TGT_EXT_3 |
32 | #define SCTLR_SPINTMASK (1ULL << 62) /* FEAT_NMI */ | 55 | #define CPU_INTERRUPT_VSERR CPU_INTERRUPT_TGT_INT_0 |
33 | #define SCTLR_TIDCP (1ULL << 63) /* FEAT_TIDCP1 */ | 56 | +#define CPU_INTERRUPT_NMI CPU_INTERRUPT_TGT_EXT_4 |
34 | 57 | +#define CPU_INTERRUPT_VINMI CPU_INTERRUPT_TGT_EXT_0 | |
35 | -/* Bit definitions for CPACR (AArch32 only) */ | 58 | +#define CPU_INTERRUPT_VFNMI CPU_INTERRUPT_TGT_INT_1 |
36 | -FIELD(CPACR, CP10, 20, 2) | 59 | |
37 | -FIELD(CPACR, CP11, 22, 2) | 60 | /* The usual mapping for an AArch64 system register to its AArch32 |
38 | -FIELD(CPACR, TRCDIS, 28, 1) /* matches CPACR_EL1.TTA */ | 61 | * counterpart is for the 32 bit world to have access to the lower |
39 | -FIELD(CPACR, D32DIS, 30, 1) /* up to v7; RAZ in v8 */ | ||
40 | -FIELD(CPACR, ASEDIS, 31, 1) | ||
41 | - | ||
42 | -/* Bit definitions for CPACR_EL1 (AArch64 only) */ | ||
43 | -FIELD(CPACR_EL1, ZEN, 16, 2) | ||
44 | -FIELD(CPACR_EL1, FPEN, 20, 2) | ||
45 | -FIELD(CPACR_EL1, SMEN, 24, 2) | ||
46 | -FIELD(CPACR_EL1, TTA, 28, 1) /* matches CPACR.TRCDIS */ | ||
47 | - | ||
48 | -/* Bit definitions for HCPTR (AArch32 only) */ | ||
49 | -FIELD(HCPTR, TCP10, 10, 1) | ||
50 | -FIELD(HCPTR, TCP11, 11, 1) | ||
51 | -FIELD(HCPTR, TASE, 15, 1) | ||
52 | -FIELD(HCPTR, TTA, 20, 1) | ||
53 | -FIELD(HCPTR, TAM, 30, 1) /* matches CPTR_EL2.TAM */ | ||
54 | -FIELD(HCPTR, TCPAC, 31, 1) /* matches CPTR_EL2.TCPAC */ | ||
55 | - | ||
56 | -/* Bit definitions for CPTR_EL2 (AArch64 only) */ | ||
57 | -FIELD(CPTR_EL2, TZ, 8, 1) /* !E2H */ | ||
58 | -FIELD(CPTR_EL2, TFP, 10, 1) /* !E2H, matches HCPTR.TCP10 */ | ||
59 | -FIELD(CPTR_EL2, TSM, 12, 1) /* !E2H */ | ||
60 | -FIELD(CPTR_EL2, ZEN, 16, 2) /* E2H */ | ||
61 | -FIELD(CPTR_EL2, FPEN, 20, 2) /* E2H */ | ||
62 | -FIELD(CPTR_EL2, SMEN, 24, 2) /* E2H */ | ||
63 | -FIELD(CPTR_EL2, TTA, 28, 1) | ||
64 | -FIELD(CPTR_EL2, TAM, 30, 1) /* matches HCPTR.TAM */ | ||
65 | -FIELD(CPTR_EL2, TCPAC, 31, 1) /* matches HCPTR.TCPAC */ | ||
66 | - | ||
67 | -/* Bit definitions for CPTR_EL3 (AArch64 only) */ | ||
68 | -FIELD(CPTR_EL3, EZ, 8, 1) | ||
69 | -FIELD(CPTR_EL3, TFP, 10, 1) | ||
70 | -FIELD(CPTR_EL3, ESM, 12, 1) | ||
71 | -FIELD(CPTR_EL3, TTA, 20, 1) | ||
72 | -FIELD(CPTR_EL3, TAM, 30, 1) | ||
73 | -FIELD(CPTR_EL3, TCPAC, 31, 1) | ||
74 | - | ||
75 | -#define MDCR_MTPME (1U << 28) | ||
76 | -#define MDCR_TDCC (1U << 27) | ||
77 | -#define MDCR_HLP (1U << 26) /* MDCR_EL2 */ | ||
78 | -#define MDCR_SCCD (1U << 23) /* MDCR_EL3 */ | ||
79 | -#define MDCR_HCCD (1U << 23) /* MDCR_EL2 */ | ||
80 | -#define MDCR_EPMAD (1U << 21) | ||
81 | -#define MDCR_EDAD (1U << 20) | ||
82 | -#define MDCR_TTRF (1U << 19) | ||
83 | -#define MDCR_STE (1U << 18) /* MDCR_EL3 */ | ||
84 | -#define MDCR_SPME (1U << 17) /* MDCR_EL3 */ | ||
85 | -#define MDCR_HPMD (1U << 17) /* MDCR_EL2 */ | ||
86 | -#define MDCR_SDD (1U << 16) | ||
87 | -#define MDCR_SPD (3U << 14) | ||
88 | -#define MDCR_TDRA (1U << 11) | ||
89 | -#define MDCR_TDOSA (1U << 10) | ||
90 | -#define MDCR_TDA (1U << 9) | ||
91 | -#define MDCR_TDE (1U << 8) | ||
92 | -#define MDCR_HPME (1U << 7) | ||
93 | -#define MDCR_TPM (1U << 6) | ||
94 | -#define MDCR_TPMCR (1U << 5) | ||
95 | -#define MDCR_HPMN (0x1fU) | ||
96 | - | ||
97 | -/* Not all of the MDCR_EL3 bits are present in the 32-bit SDCR */ | ||
98 | -#define SDCR_VALID_MASK (MDCR_MTPME | MDCR_TDCC | MDCR_SCCD | \ | ||
99 | - MDCR_EPMAD | MDCR_EDAD | MDCR_TTRF | \ | ||
100 | - MDCR_STE | MDCR_SPME | MDCR_SPD) | ||
101 | - | ||
102 | #define CPSR_M (0x1fU) | ||
103 | #define CPSR_T (1U << 5) | ||
104 | #define CPSR_F (1U << 6) | ||
105 | @@ -XXX,XX +XXX,XX @@ FIELD(CPTR_EL3, TCPAC, 31, 1) | ||
106 | #define XPSR_NZCV CPSR_NZCV | ||
107 | #define XPSR_IT CPSR_IT | ||
108 | |||
109 | -#define TTBCR_N (7U << 0) /* TTBCR.EAE==0 */ | ||
110 | -#define TTBCR_T0SZ (7U << 0) /* TTBCR.EAE==1 */ | ||
111 | -#define TTBCR_PD0 (1U << 4) | ||
112 | -#define TTBCR_PD1 (1U << 5) | ||
113 | -#define TTBCR_EPD0 (1U << 7) | ||
114 | -#define TTBCR_IRGN0 (3U << 8) | ||
115 | -#define TTBCR_ORGN0 (3U << 10) | ||
116 | -#define TTBCR_SH0 (3U << 12) | ||
117 | -#define TTBCR_T1SZ (3U << 16) | ||
118 | -#define TTBCR_A1 (1U << 22) | ||
119 | -#define TTBCR_EPD1 (1U << 23) | ||
120 | -#define TTBCR_IRGN1 (3U << 24) | ||
121 | -#define TTBCR_ORGN1 (3U << 26) | ||
122 | -#define TTBCR_SH1 (1U << 28) | ||
123 | -#define TTBCR_EAE (1U << 31) | ||
124 | - | ||
125 | -FIELD(VTCR, T0SZ, 0, 6) | ||
126 | -FIELD(VTCR, SL0, 6, 2) | ||
127 | -FIELD(VTCR, IRGN0, 8, 2) | ||
128 | -FIELD(VTCR, ORGN0, 10, 2) | ||
129 | -FIELD(VTCR, SH0, 12, 2) | ||
130 | -FIELD(VTCR, TG0, 14, 2) | ||
131 | -FIELD(VTCR, PS, 16, 3) | ||
132 | -FIELD(VTCR, VS, 19, 1) | ||
133 | -FIELD(VTCR, HA, 21, 1) | ||
134 | -FIELD(VTCR, HD, 22, 1) | ||
135 | -FIELD(VTCR, HWU59, 25, 1) | ||
136 | -FIELD(VTCR, HWU60, 26, 1) | ||
137 | -FIELD(VTCR, HWU61, 27, 1) | ||
138 | -FIELD(VTCR, HWU62, 28, 1) | ||
139 | -FIELD(VTCR, NSW, 29, 1) | ||
140 | -FIELD(VTCR, NSA, 30, 1) | ||
141 | -FIELD(VTCR, DS, 32, 1) | ||
142 | -FIELD(VTCR, SL2, 33, 1) | ||
143 | - | ||
144 | /* Bit definitions for ARMv8 SPSR (PSTATE) format. | ||
145 | * Only these are valid when in AArch64 mode; in | ||
146 | * AArch32 mode SPSRs are basically CPSR-format. | ||
147 | @@ -XXX,XX +XXX,XX @@ static inline void xpsr_write(CPUARMState *env, uint32_t val, uint32_t mask) | ||
148 | #define HCR_TWEDEN (1ULL << 59) | ||
149 | #define HCR_TWEDEL MAKE_64BIT_MASK(60, 4) | ||
150 | |||
151 | -#define HCRX_ENAS0 (1ULL << 0) | ||
152 | -#define HCRX_ENALS (1ULL << 1) | ||
153 | -#define HCRX_ENASR (1ULL << 2) | ||
154 | -#define HCRX_FNXS (1ULL << 3) | ||
155 | -#define HCRX_FGTNXS (1ULL << 4) | ||
156 | -#define HCRX_SMPME (1ULL << 5) | ||
157 | -#define HCRX_TALLINT (1ULL << 6) | ||
158 | -#define HCRX_VINMI (1ULL << 7) | ||
159 | -#define HCRX_VFNMI (1ULL << 8) | ||
160 | -#define HCRX_CMOW (1ULL << 9) | ||
161 | -#define HCRX_MCE2 (1ULL << 10) | ||
162 | -#define HCRX_MSCEN (1ULL << 11) | ||
163 | - | ||
164 | -#define HPFAR_NS (1ULL << 63) | ||
165 | - | ||
166 | #define SCR_NS (1ULL << 0) | ||
167 | #define SCR_IRQ (1ULL << 1) | ||
168 | #define SCR_FIQ (1ULL << 2) | ||
169 | @@ -XXX,XX +XXX,XX @@ static inline void xpsr_write(CPUARMState *env, uint32_t val, uint32_t mask) | ||
170 | #define SCR_GPF (1ULL << 48) | ||
171 | #define SCR_NSE (1ULL << 62) | ||
172 | |||
173 | -#define HSTR_TTEE (1 << 16) | ||
174 | -#define HSTR_TJDBX (1 << 17) | ||
175 | - | ||
176 | -#define CNTHCTL_CNTVMASK (1 << 18) | ||
177 | -#define CNTHCTL_CNTPMASK (1 << 19) | ||
178 | - | ||
179 | /* Return the current FPSCR value. */ | ||
180 | uint32_t vfp_get_fpscr(CPUARMState *env); | ||
181 | void vfp_set_fpscr(CPUARMState *env, uint32_t val); | ||
182 | diff --git a/target/arm/internals.h b/target/arm/internals.h | 62 | diff --git a/target/arm/internals.h b/target/arm/internals.h |
183 | index XXXXXXX..XXXXXXX 100644 | 63 | index XXXXXXX..XXXXXXX 100644 |
184 | --- a/target/arm/internals.h | 64 | --- a/target/arm/internals.h |
185 | +++ b/target/arm/internals.h | 65 | +++ b/target/arm/internals.h |
186 | @@ -XXX,XX +XXX,XX @@ FIELD(DBGWCR, WT, 20, 1) | 66 | @@ -XXX,XX +XXX,XX @@ void arm_cpu_update_virq(ARMCPU *cpu); |
187 | FIELD(DBGWCR, MASK, 24, 5) | 67 | */ |
188 | FIELD(DBGWCR, SSCE, 29, 1) | 68 | void arm_cpu_update_vfiq(ARMCPU *cpu); |
189 | 69 | ||
190 | +#define VTCR_NSW (1u << 29) | 70 | +/** |
191 | +#define VTCR_NSA (1u << 30) | 71 | + * arm_cpu_update_vinmi: Update CPU_INTERRUPT_VINMI bit in cs->interrupt_request |
192 | +#define VSTCR_SW VTCR_NSW | 72 | + * |
193 | +#define VSTCR_SA VTCR_NSA | 73 | + * Update the CPU_INTERRUPT_VINMI bit in cs->interrupt_request, following |
194 | + | 74 | + * a change to either the input VNMI line from the GIC or the HCRX_EL2.VINMI. |
195 | +/* Bit definitions for CPACR (AArch32 only) */ | 75 | + * Must be called with the BQL held. |
196 | +FIELD(CPACR, CP10, 20, 2) | 76 | + */ |
197 | +FIELD(CPACR, CP11, 22, 2) | 77 | +void arm_cpu_update_vinmi(ARMCPU *cpu); |
198 | +FIELD(CPACR, TRCDIS, 28, 1) /* matches CPACR_EL1.TTA */ | 78 | + |
199 | +FIELD(CPACR, D32DIS, 30, 1) /* up to v7; RAZ in v8 */ | 79 | +/** |
200 | +FIELD(CPACR, ASEDIS, 31, 1) | 80 | + * arm_cpu_update_vfnmi: Update CPU_INTERRUPT_VFNMI bit in cs->interrupt_request |
201 | + | 81 | + * |
202 | +/* Bit definitions for CPACR_EL1 (AArch64 only) */ | 82 | + * Update the CPU_INTERRUPT_VFNMI bit in cs->interrupt_request, following |
203 | +FIELD(CPACR_EL1, ZEN, 16, 2) | 83 | + * a change to the HCRX_EL2.VFNMI. |
204 | +FIELD(CPACR_EL1, FPEN, 20, 2) | 84 | + * Must be called with the BQL held. |
205 | +FIELD(CPACR_EL1, SMEN, 24, 2) | 85 | + */ |
206 | +FIELD(CPACR_EL1, TTA, 28, 1) /* matches CPACR.TRCDIS */ | 86 | +void arm_cpu_update_vfnmi(ARMCPU *cpu); |
207 | + | 87 | + |
208 | +/* Bit definitions for HCPTR (AArch32 only) */ | 88 | /** |
209 | +FIELD(HCPTR, TCP10, 10, 1) | 89 | * arm_cpu_update_vserr: Update CPU_INTERRUPT_VSERR bit |
210 | +FIELD(HCPTR, TCP11, 11, 1) | 90 | * |
211 | +FIELD(HCPTR, TASE, 15, 1) | 91 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c |
212 | +FIELD(HCPTR, TTA, 20, 1) | 92 | index XXXXXXX..XXXXXXX 100644 |
213 | +FIELD(HCPTR, TAM, 30, 1) /* matches CPTR_EL2.TAM */ | 93 | --- a/target/arm/cpu.c |
214 | +FIELD(HCPTR, TCPAC, 31, 1) /* matches CPTR_EL2.TCPAC */ | 94 | +++ b/target/arm/cpu.c |
215 | + | 95 | @@ -XXX,XX +XXX,XX @@ void arm_restore_state_to_opc(CPUState *cs, |
216 | +/* Bit definitions for CPTR_EL2 (AArch64 only) */ | 96 | } |
217 | +FIELD(CPTR_EL2, TZ, 8, 1) /* !E2H */ | 97 | #endif /* CONFIG_TCG */ |
218 | +FIELD(CPTR_EL2, TFP, 10, 1) /* !E2H, matches HCPTR.TCP10 */ | 98 | |
219 | +FIELD(CPTR_EL2, TSM, 12, 1) /* !E2H */ | 99 | +/* |
220 | +FIELD(CPTR_EL2, ZEN, 16, 2) /* E2H */ | 100 | + * With SCTLR_ELx.NMI == 0, IRQ with Superpriority is masked identically with |
221 | +FIELD(CPTR_EL2, FPEN, 20, 2) /* E2H */ | 101 | + * IRQ without Superpriority. Moreover, if the GIC is configured so that |
222 | +FIELD(CPTR_EL2, SMEN, 24, 2) /* E2H */ | 102 | + * FEAT_GICv3_NMI is only set if FEAT_NMI is set, then we won't ever see |
223 | +FIELD(CPTR_EL2, TTA, 28, 1) | 103 | + * CPU_INTERRUPT_*NMI anyway. So we might as well accept NMI here |
224 | +FIELD(CPTR_EL2, TAM, 30, 1) /* matches HCPTR.TAM */ | 104 | + * unconditionally. |
225 | +FIELD(CPTR_EL2, TCPAC, 31, 1) /* matches HCPTR.TCPAC */ | 105 | + */ |
226 | + | 106 | static bool arm_cpu_has_work(CPUState *cs) |
227 | +/* Bit definitions for CPTR_EL3 (AArch64 only) */ | 107 | { |
228 | +FIELD(CPTR_EL3, EZ, 8, 1) | 108 | ARMCPU *cpu = ARM_CPU(cs); |
229 | +FIELD(CPTR_EL3, TFP, 10, 1) | 109 | @@ -XXX,XX +XXX,XX @@ static bool arm_cpu_has_work(CPUState *cs) |
230 | +FIELD(CPTR_EL3, ESM, 12, 1) | 110 | return (cpu->power_state != PSCI_OFF) |
231 | +FIELD(CPTR_EL3, TTA, 20, 1) | 111 | && cs->interrupt_request & |
232 | +FIELD(CPTR_EL3, TAM, 30, 1) | 112 | (CPU_INTERRUPT_FIQ | CPU_INTERRUPT_HARD |
233 | +FIELD(CPTR_EL3, TCPAC, 31, 1) | 113 | + | CPU_INTERRUPT_NMI | CPU_INTERRUPT_VINMI | CPU_INTERRUPT_VFNMI |
234 | + | 114 | | CPU_INTERRUPT_VFIQ | CPU_INTERRUPT_VIRQ | CPU_INTERRUPT_VSERR |
235 | +#define MDCR_MTPME (1U << 28) | 115 | | CPU_INTERRUPT_EXITTB); |
236 | +#define MDCR_TDCC (1U << 27) | 116 | } |
237 | +#define MDCR_HLP (1U << 26) /* MDCR_EL2 */ | 117 | @@ -XXX,XX +XXX,XX @@ static inline bool arm_excp_unmasked(CPUState *cs, unsigned int excp_idx, |
238 | +#define MDCR_SCCD (1U << 23) /* MDCR_EL3 */ | 118 | CPUARMState *env = cpu_env(cs); |
239 | +#define MDCR_HCCD (1U << 23) /* MDCR_EL2 */ | 119 | bool pstate_unmasked; |
240 | +#define MDCR_EPMAD (1U << 21) | 120 | bool unmasked = false; |
241 | +#define MDCR_EDAD (1U << 20) | 121 | + bool allIntMask = false; |
242 | +#define MDCR_TTRF (1U << 19) | 122 | |
243 | +#define MDCR_STE (1U << 18) /* MDCR_EL3 */ | 123 | /* |
244 | +#define MDCR_SPME (1U << 17) /* MDCR_EL3 */ | 124 | * Don't take exceptions if they target a lower EL. |
245 | +#define MDCR_HPMD (1U << 17) /* MDCR_EL2 */ | 125 | @@ -XXX,XX +XXX,XX @@ static inline bool arm_excp_unmasked(CPUState *cs, unsigned int excp_idx, |
246 | +#define MDCR_SDD (1U << 16) | 126 | return false; |
247 | +#define MDCR_SPD (3U << 14) | 127 | } |
248 | +#define MDCR_TDRA (1U << 11) | 128 | |
249 | +#define MDCR_TDOSA (1U << 10) | 129 | + if (cpu_isar_feature(aa64_nmi, env_archcpu(env)) && |
250 | +#define MDCR_TDA (1U << 9) | 130 | + env->cp15.sctlr_el[target_el] & SCTLR_NMI && cur_el == target_el) { |
251 | +#define MDCR_TDE (1U << 8) | 131 | + allIntMask = env->pstate & PSTATE_ALLINT || |
252 | +#define MDCR_HPME (1U << 7) | 132 | + ((env->cp15.sctlr_el[target_el] & SCTLR_SPINTMASK) && |
253 | +#define MDCR_TPM (1U << 6) | 133 | + (env->pstate & PSTATE_SP)); |
254 | +#define MDCR_TPMCR (1U << 5) | 134 | + } |
255 | +#define MDCR_HPMN (0x1fU) | 135 | + |
256 | + | 136 | switch (excp_idx) { |
257 | +/* Not all of the MDCR_EL3 bits are present in the 32-bit SDCR */ | 137 | + case EXCP_NMI: |
258 | +#define SDCR_VALID_MASK (MDCR_MTPME | MDCR_TDCC | MDCR_SCCD | \ | 138 | + pstate_unmasked = !allIntMask; |
259 | + MDCR_EPMAD | MDCR_EDAD | MDCR_TTRF | \ | 139 | + break; |
260 | + MDCR_STE | MDCR_SPME | MDCR_SPD) | 140 | + |
261 | + | 141 | + case EXCP_VINMI: |
262 | +#define TTBCR_N (7U << 0) /* TTBCR.EAE==0 */ | 142 | + if (!(hcr_el2 & HCR_IMO) || (hcr_el2 & HCR_TGE)) { |
263 | +#define TTBCR_T0SZ (7U << 0) /* TTBCR.EAE==1 */ | 143 | + /* VINMIs are only taken when hypervized. */ |
264 | +#define TTBCR_PD0 (1U << 4) | 144 | + return false; |
265 | +#define TTBCR_PD1 (1U << 5) | 145 | + } |
266 | +#define TTBCR_EPD0 (1U << 7) | 146 | + return !allIntMask; |
267 | +#define TTBCR_IRGN0 (3U << 8) | 147 | + case EXCP_VFNMI: |
268 | +#define TTBCR_ORGN0 (3U << 10) | 148 | + if (!(hcr_el2 & HCR_FMO) || (hcr_el2 & HCR_TGE)) { |
269 | +#define TTBCR_SH0 (3U << 12) | 149 | + /* VFNMIs are only taken when hypervized. */ |
270 | +#define TTBCR_T1SZ (3U << 16) | 150 | + return false; |
271 | +#define TTBCR_A1 (1U << 22) | 151 | + } |
272 | +#define TTBCR_EPD1 (1U << 23) | 152 | + return !allIntMask; |
273 | +#define TTBCR_IRGN1 (3U << 24) | 153 | case EXCP_FIQ: |
274 | +#define TTBCR_ORGN1 (3U << 26) | 154 | - pstate_unmasked = !(env->daif & PSTATE_F); |
275 | +#define TTBCR_SH1 (1U << 28) | 155 | + pstate_unmasked = (!(env->daif & PSTATE_F)) && (!allIntMask); |
276 | +#define TTBCR_EAE (1U << 31) | 156 | break; |
277 | + | 157 | |
278 | +FIELD(VTCR, T0SZ, 0, 6) | 158 | case EXCP_IRQ: |
279 | +FIELD(VTCR, SL0, 6, 2) | 159 | - pstate_unmasked = !(env->daif & PSTATE_I); |
280 | +FIELD(VTCR, IRGN0, 8, 2) | 160 | + pstate_unmasked = (!(env->daif & PSTATE_I)) && (!allIntMask); |
281 | +FIELD(VTCR, ORGN0, 10, 2) | 161 | break; |
282 | +FIELD(VTCR, SH0, 12, 2) | 162 | |
283 | +FIELD(VTCR, TG0, 14, 2) | 163 | case EXCP_VFIQ: |
284 | +FIELD(VTCR, PS, 16, 3) | 164 | @@ -XXX,XX +XXX,XX @@ static inline bool arm_excp_unmasked(CPUState *cs, unsigned int excp_idx, |
285 | +FIELD(VTCR, VS, 19, 1) | 165 | /* VFIQs are only taken when hypervized. */ |
286 | +FIELD(VTCR, HA, 21, 1) | 166 | return false; |
287 | +FIELD(VTCR, HD, 22, 1) | 167 | } |
288 | +FIELD(VTCR, HWU59, 25, 1) | 168 | - return !(env->daif & PSTATE_F); |
289 | +FIELD(VTCR, HWU60, 26, 1) | 169 | + return !(env->daif & PSTATE_F) && (!allIntMask); |
290 | +FIELD(VTCR, HWU61, 27, 1) | 170 | case EXCP_VIRQ: |
291 | +FIELD(VTCR, HWU62, 28, 1) | 171 | if (!(hcr_el2 & HCR_IMO) || (hcr_el2 & HCR_TGE)) { |
292 | +FIELD(VTCR, NSW, 29, 1) | 172 | /* VIRQs are only taken when hypervized. */ |
293 | +FIELD(VTCR, NSA, 30, 1) | 173 | return false; |
294 | +FIELD(VTCR, DS, 32, 1) | 174 | } |
295 | +FIELD(VTCR, SL2, 33, 1) | 175 | - return !(env->daif & PSTATE_I); |
296 | + | 176 | + return !(env->daif & PSTATE_I) && (!allIntMask); |
297 | +#define HCRX_ENAS0 (1ULL << 0) | 177 | case EXCP_VSERR: |
298 | +#define HCRX_ENALS (1ULL << 1) | 178 | if (!(hcr_el2 & HCR_AMO) || (hcr_el2 & HCR_TGE)) { |
299 | +#define HCRX_ENASR (1ULL << 2) | 179 | /* VIRQs are only taken when hypervized. */ |
300 | +#define HCRX_FNXS (1ULL << 3) | 180 | @@ -XXX,XX +XXX,XX @@ static bool arm_cpu_exec_interrupt(CPUState *cs, int interrupt_request) |
301 | +#define HCRX_FGTNXS (1ULL << 4) | 181 | |
302 | +#define HCRX_SMPME (1ULL << 5) | 182 | /* The prioritization of interrupts is IMPLEMENTATION DEFINED. */ |
303 | +#define HCRX_TALLINT (1ULL << 6) | 183 | |
304 | +#define HCRX_VINMI (1ULL << 7) | 184 | + if (cpu_isar_feature(aa64_nmi, env_archcpu(env)) && |
305 | +#define HCRX_VFNMI (1ULL << 8) | 185 | + (arm_sctlr(env, cur_el) & SCTLR_NMI)) { |
306 | +#define HCRX_CMOW (1ULL << 9) | 186 | + if (interrupt_request & CPU_INTERRUPT_NMI) { |
307 | +#define HCRX_MCE2 (1ULL << 10) | 187 | + excp_idx = EXCP_NMI; |
308 | +#define HCRX_MSCEN (1ULL << 11) | 188 | + target_el = arm_phys_excp_target_el(cs, excp_idx, cur_el, secure); |
309 | + | 189 | + if (arm_excp_unmasked(cs, excp_idx, target_el, |
310 | +#define HPFAR_NS (1ULL << 63) | 190 | + cur_el, secure, hcr_el2)) { |
311 | + | 191 | + goto found; |
312 | +#define HSTR_TTEE (1 << 16) | 192 | + } |
313 | +#define HSTR_TJDBX (1 << 17) | 193 | + } |
314 | + | 194 | + if (interrupt_request & CPU_INTERRUPT_VINMI) { |
315 | +#define CNTHCTL_CNTVMASK (1 << 18) | 195 | + excp_idx = EXCP_VINMI; |
316 | +#define CNTHCTL_CNTPMASK (1 << 19) | 196 | + target_el = 1; |
317 | + | 197 | + if (arm_excp_unmasked(cs, excp_idx, target_el, |
318 | /* We use a few fake FSR values for internal purposes in M profile. | 198 | + cur_el, secure, hcr_el2)) { |
319 | * M profile cores don't have A/R format FSRs, but currently our | 199 | + goto found; |
320 | * get_phys_addr() code assumes A/R profile and reports failures via | 200 | + } |
201 | + } | ||
202 | + if (interrupt_request & CPU_INTERRUPT_VFNMI) { | ||
203 | + excp_idx = EXCP_VFNMI; | ||
204 | + target_el = 1; | ||
205 | + if (arm_excp_unmasked(cs, excp_idx, target_el, | ||
206 | + cur_el, secure, hcr_el2)) { | ||
207 | + goto found; | ||
208 | + } | ||
209 | + } | ||
210 | + } else { | ||
211 | + /* | ||
212 | + * NMI disabled: interrupts with superpriority are handled | ||
213 | + * as if they didn't have it | ||
214 | + */ | ||
215 | + if (interrupt_request & CPU_INTERRUPT_NMI) { | ||
216 | + interrupt_request |= CPU_INTERRUPT_HARD; | ||
217 | + } | ||
218 | + if (interrupt_request & CPU_INTERRUPT_VINMI) { | ||
219 | + interrupt_request |= CPU_INTERRUPT_VIRQ; | ||
220 | + } | ||
221 | + if (interrupt_request & CPU_INTERRUPT_VFNMI) { | ||
222 | + interrupt_request |= CPU_INTERRUPT_VFIQ; | ||
223 | + } | ||
224 | + } | ||
225 | + | ||
226 | if (interrupt_request & CPU_INTERRUPT_FIQ) { | ||
227 | excp_idx = EXCP_FIQ; | ||
228 | target_el = arm_phys_excp_target_el(cs, excp_idx, cur_el, secure); | ||
229 | @@ -XXX,XX +XXX,XX @@ void arm_cpu_update_virq(ARMCPU *cpu) | ||
230 | CPUARMState *env = &cpu->env; | ||
231 | CPUState *cs = CPU(cpu); | ||
232 | |||
233 | - bool new_state = (env->cp15.hcr_el2 & HCR_VI) || | ||
234 | + bool new_state = ((arm_hcr_el2_eff(env) & HCR_VI) && | ||
235 | + !(arm_hcrx_el2_eff(env) & HCRX_VINMI)) || | ||
236 | (env->irq_line_state & CPU_INTERRUPT_VIRQ); | ||
237 | |||
238 | if (new_state != ((cs->interrupt_request & CPU_INTERRUPT_VIRQ) != 0)) { | ||
239 | @@ -XXX,XX +XXX,XX @@ void arm_cpu_update_vfiq(ARMCPU *cpu) | ||
240 | CPUARMState *env = &cpu->env; | ||
241 | CPUState *cs = CPU(cpu); | ||
242 | |||
243 | - bool new_state = (env->cp15.hcr_el2 & HCR_VF) || | ||
244 | + bool new_state = ((arm_hcr_el2_eff(env) & HCR_VF) && | ||
245 | + !(arm_hcrx_el2_eff(env) & HCRX_VFNMI)) || | ||
246 | (env->irq_line_state & CPU_INTERRUPT_VFIQ); | ||
247 | |||
248 | if (new_state != ((cs->interrupt_request & CPU_INTERRUPT_VFIQ) != 0)) { | ||
249 | @@ -XXX,XX +XXX,XX @@ void arm_cpu_update_vfiq(ARMCPU *cpu) | ||
250 | } | ||
251 | } | ||
252 | |||
253 | +void arm_cpu_update_vinmi(ARMCPU *cpu) | ||
254 | +{ | ||
255 | + /* | ||
256 | + * Update the interrupt level for VINMI, which is the logical OR of | ||
257 | + * the HCRX_EL2.VINMI bit and the input line level from the GIC. | ||
258 | + */ | ||
259 | + CPUARMState *env = &cpu->env; | ||
260 | + CPUState *cs = CPU(cpu); | ||
261 | + | ||
262 | + bool new_state = ((arm_hcr_el2_eff(env) & HCR_VI) && | ||
263 | + (arm_hcrx_el2_eff(env) & HCRX_VINMI)) || | ||
264 | + (env->irq_line_state & CPU_INTERRUPT_VINMI); | ||
265 | + | ||
266 | + if (new_state != ((cs->interrupt_request & CPU_INTERRUPT_VINMI) != 0)) { | ||
267 | + if (new_state) { | ||
268 | + cpu_interrupt(cs, CPU_INTERRUPT_VINMI); | ||
269 | + } else { | ||
270 | + cpu_reset_interrupt(cs, CPU_INTERRUPT_VINMI); | ||
271 | + } | ||
272 | + } | ||
273 | +} | ||
274 | + | ||
275 | +void arm_cpu_update_vfnmi(ARMCPU *cpu) | ||
276 | +{ | ||
277 | + /* | ||
278 | + * Update the interrupt level for VFNMI, which is the HCRX_EL2.VFNMI bit. | ||
279 | + */ | ||
280 | + CPUARMState *env = &cpu->env; | ||
281 | + CPUState *cs = CPU(cpu); | ||
282 | + | ||
283 | + bool new_state = (arm_hcr_el2_eff(env) & HCR_VF) && | ||
284 | + (arm_hcrx_el2_eff(env) & HCRX_VFNMI); | ||
285 | + | ||
286 | + if (new_state != ((cs->interrupt_request & CPU_INTERRUPT_VFNMI) != 0)) { | ||
287 | + if (new_state) { | ||
288 | + cpu_interrupt(cs, CPU_INTERRUPT_VFNMI); | ||
289 | + } else { | ||
290 | + cpu_reset_interrupt(cs, CPU_INTERRUPT_VFNMI); | ||
291 | + } | ||
292 | + } | ||
293 | +} | ||
294 | + | ||
295 | void arm_cpu_update_vserr(ARMCPU *cpu) | ||
296 | { | ||
297 | /* | ||
298 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_set_irq(void *opaque, int irq, int level) | ||
299 | [ARM_CPU_IRQ] = CPU_INTERRUPT_HARD, | ||
300 | [ARM_CPU_FIQ] = CPU_INTERRUPT_FIQ, | ||
301 | [ARM_CPU_VIRQ] = CPU_INTERRUPT_VIRQ, | ||
302 | - [ARM_CPU_VFIQ] = CPU_INTERRUPT_VFIQ | ||
303 | + [ARM_CPU_VFIQ] = CPU_INTERRUPT_VFIQ, | ||
304 | + [ARM_CPU_NMI] = CPU_INTERRUPT_NMI, | ||
305 | + [ARM_CPU_VINMI] = CPU_INTERRUPT_VINMI, | ||
306 | }; | ||
307 | |||
308 | if (!arm_feature(env, ARM_FEATURE_EL2) && | ||
309 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_set_irq(void *opaque, int irq, int level) | ||
310 | case ARM_CPU_VFIQ: | ||
311 | arm_cpu_update_vfiq(cpu); | ||
312 | break; | ||
313 | + case ARM_CPU_VINMI: | ||
314 | + arm_cpu_update_vinmi(cpu); | ||
315 | + break; | ||
316 | case ARM_CPU_IRQ: | ||
317 | case ARM_CPU_FIQ: | ||
318 | + case ARM_CPU_NMI: | ||
319 | if (level) { | ||
320 | cpu_interrupt(cs, mask[irq]); | ||
321 | } else { | ||
322 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_initfn(Object *obj) | ||
323 | #else | ||
324 | /* Our inbound IRQ and FIQ lines */ | ||
325 | if (kvm_enabled()) { | ||
326 | - /* VIRQ and VFIQ are unused with KVM but we add them to maintain | ||
327 | - * the same interface as non-KVM CPUs. | ||
328 | + /* | ||
329 | + * VIRQ, VFIQ, NMI, VINMI are unused with KVM but we add | ||
330 | + * them to maintain the same interface as non-KVM CPUs. | ||
331 | */ | ||
332 | - qdev_init_gpio_in(DEVICE(cpu), arm_cpu_kvm_set_irq, 4); | ||
333 | + qdev_init_gpio_in(DEVICE(cpu), arm_cpu_kvm_set_irq, 6); | ||
334 | } else { | ||
335 | - qdev_init_gpio_in(DEVICE(cpu), arm_cpu_set_irq, 4); | ||
336 | + qdev_init_gpio_in(DEVICE(cpu), arm_cpu_set_irq, 6); | ||
337 | } | ||
338 | |||
339 | qdev_init_gpio_out(DEVICE(cpu), cpu->gt_timer_outputs, | ||
340 | diff --git a/target/arm/helper.c b/target/arm/helper.c | ||
341 | index XXXXXXX..XXXXXXX 100644 | ||
342 | --- a/target/arm/helper.c | ||
343 | +++ b/target/arm/helper.c | ||
344 | @@ -XXX,XX +XXX,XX @@ static void do_hcr_write(CPUARMState *env, uint64_t value, uint64_t valid_mask) | ||
345 | * and the state of the input lines from the GIC. (This requires | ||
346 | * that we have the BQL, which is done by marking the | ||
347 | * reginfo structs as ARM_CP_IO.) | ||
348 | - * Note that if a write to HCR pends a VIRQ or VFIQ it is never | ||
349 | - * possible for it to be taken immediately, because VIRQ and | ||
350 | - * VFIQ are masked unless running at EL0 or EL1, and HCR | ||
351 | - * can only be written at EL2. | ||
352 | + * Note that if a write to HCR pends a VIRQ or VFIQ or VINMI or | ||
353 | + * VFNMI, it is never possible for it to be taken immediately | ||
354 | + * because VIRQ, VFIQ, VINMI and VFNMI are masked unless running | ||
355 | + * at EL0 or EL1, and HCR can only be written at EL2. | ||
356 | */ | ||
357 | g_assert(bql_locked()); | ||
358 | arm_cpu_update_virq(cpu); | ||
359 | arm_cpu_update_vfiq(cpu); | ||
360 | arm_cpu_update_vserr(cpu); | ||
361 | + if (cpu_isar_feature(aa64_nmi, cpu)) { | ||
362 | + arm_cpu_update_vinmi(cpu); | ||
363 | + arm_cpu_update_vfnmi(cpu); | ||
364 | + } | ||
365 | } | ||
366 | |||
367 | static void hcr_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value) | ||
368 | @@ -XXX,XX +XXX,XX @@ static void hcrx_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
369 | |||
370 | /* Clear RES0 bits. */ | ||
371 | env->cp15.hcrx_el2 = value & valid_mask; | ||
372 | + | ||
373 | + /* | ||
374 | + * Updates to VINMI and VFNMI require us to update the status of | ||
375 | + * virtual NMI, which are the logical OR of these bits | ||
376 | + * and the state of the input lines from the GIC. (This requires | ||
377 | + * that we have the BQL, which is done by marking the | ||
378 | + * reginfo structs as ARM_CP_IO.) | ||
379 | + * Note that if a write to HCRX pends a VINMI or VFNMI it is never | ||
380 | + * possible for it to be taken immediately, because VINMI and | ||
381 | + * VFNMI are masked unless running at EL0 or EL1, and HCRX | ||
382 | + * can only be written at EL2. | ||
383 | + */ | ||
384 | + if (cpu_isar_feature(aa64_nmi, cpu)) { | ||
385 | + g_assert(bql_locked()); | ||
386 | + arm_cpu_update_vinmi(cpu); | ||
387 | + arm_cpu_update_vfnmi(cpu); | ||
388 | + } | ||
389 | } | ||
390 | |||
391 | static CPAccessResult access_hxen(CPUARMState *env, const ARMCPRegInfo *ri, | ||
392 | @@ -XXX,XX +XXX,XX @@ static CPAccessResult access_hxen(CPUARMState *env, const ARMCPRegInfo *ri, | ||
393 | |||
394 | static const ARMCPRegInfo hcrx_el2_reginfo = { | ||
395 | .name = "HCRX_EL2", .state = ARM_CP_STATE_AA64, | ||
396 | + .type = ARM_CP_IO, | ||
397 | .opc0 = 3, .opc1 = 4, .crn = 1, .crm = 2, .opc2 = 2, | ||
398 | .access = PL2_RW, .writefn = hcrx_write, .accessfn = access_hxen, | ||
399 | .nv2_redirect_offset = 0xa0, | ||
400 | @@ -XXX,XX +XXX,XX @@ void arm_log_exception(CPUState *cs) | ||
401 | [EXCP_DIVBYZERO] = "v7M DIVBYZERO UsageFault", | ||
402 | [EXCP_VSERR] = "Virtual SERR", | ||
403 | [EXCP_GPC] = "Granule Protection Check", | ||
404 | + [EXCP_NMI] = "NMI", | ||
405 | + [EXCP_VINMI] = "Virtual IRQ NMI", | ||
406 | + [EXCP_VFNMI] = "Virtual FIQ NMI", | ||
407 | }; | ||
408 | |||
409 | if (idx >= 0 && idx < ARRAY_SIZE(excnames)) { | ||
321 | -- | 410 | -- |
322 | 2.34.1 | 411 | 2.34.1 |
323 | |||
324 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Jinjie Ruan <ruanjinjie@huawei.com> | ||
1 | 2 | ||
3 | According to Arm GIC section 4.6.3 Interrupt superpriority, the interrupt | ||
4 | with superpriority is always IRQ, never FIQ, so handle NMI same as IRQ in | ||
5 | arm_phys_excp_target_el(). | ||
6 | |||
7 | Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> | ||
8 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
10 | Message-id: 20240407081733.3231820-8-ruanjinjie@huawei.com | ||
11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
12 | --- | ||
13 | target/arm/helper.c | 1 + | ||
14 | 1 file changed, 1 insertion(+) | ||
15 | |||
16 | diff --git a/target/arm/helper.c b/target/arm/helper.c | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/target/arm/helper.c | ||
19 | +++ b/target/arm/helper.c | ||
20 | @@ -XXX,XX +XXX,XX @@ uint32_t arm_phys_excp_target_el(CPUState *cs, uint32_t excp_idx, | ||
21 | hcr_el2 = arm_hcr_el2_eff(env); | ||
22 | switch (excp_idx) { | ||
23 | case EXCP_IRQ: | ||
24 | + case EXCP_NMI: | ||
25 | scr = ((env->cp15.scr_el3 & SCR_IRQ) == SCR_IRQ); | ||
26 | hcr = hcr_el2 & HCR_IMO; | ||
27 | break; | ||
28 | -- | ||
29 | 2.34.1 | diff view generated by jsdifflib |
1 | When ID_AA64MMFR0_EL1.ECV is 0b0010, a new register CNTPOFF_EL2 is | 1 | From: Jinjie Ruan <ruanjinjie@huawei.com> |
---|---|---|---|
2 | implemented. This is similar to the existing CNTVOFF_EL2, except | ||
3 | that it controls a hypervisor-adjustable offset made to the physical | ||
4 | counter and timer. | ||
5 | 2 | ||
6 | Implement the handling for this register, which includes control/trap | 3 | Add IS and FS bit in ISR_EL1 and handle the read. With CPU_INTERRUPT_NMI or |
7 | bits in SCR_EL3 and CNTHCTL_EL2. | 4 | CPU_INTERRUPT_VINMI, both CPSR_I and ISR_IS must be set. With |
5 | CPU_INTERRUPT_VFNMI, both CPSR_F and ISR_FS must be set. | ||
8 | 6 | ||
7 | Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> | ||
8 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
10 | Message-id: 20240407081733.3231820-9-ruanjinjie@huawei.com | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
10 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
11 | Message-id: 20240301183219.2424889-8-peter.maydell@linaro.org | ||
12 | --- | 12 | --- |
13 | target/arm/cpu-features.h | 5 +++ | 13 | target/arm/cpu.h | 2 ++ |
14 | target/arm/cpu.h | 1 + | 14 | target/arm/helper.c | 13 +++++++++++++ |
15 | target/arm/helper.c | 68 +++++++++++++++++++++++++++++++++++++-- | 15 | 2 files changed, 15 insertions(+) |
16 | target/arm/trace-events | 1 + | ||
17 | 4 files changed, 73 insertions(+), 2 deletions(-) | ||
18 | 16 | ||
19 | diff --git a/target/arm/cpu-features.h b/target/arm/cpu-features.h | ||
20 | index XXXXXXX..XXXXXXX 100644 | ||
21 | --- a/target/arm/cpu-features.h | ||
22 | +++ b/target/arm/cpu-features.h | ||
23 | @@ -XXX,XX +XXX,XX @@ static inline bool isar_feature_aa64_ecv_traps(const ARMISARegisters *id) | ||
24 | return FIELD_EX64(id->id_aa64mmfr0, ID_AA64MMFR0, ECV) > 0; | ||
25 | } | ||
26 | |||
27 | +static inline bool isar_feature_aa64_ecv(const ARMISARegisters *id) | ||
28 | +{ | ||
29 | + return FIELD_EX64(id->id_aa64mmfr0, ID_AA64MMFR0, ECV) > 1; | ||
30 | +} | ||
31 | + | ||
32 | static inline bool isar_feature_aa64_vh(const ARMISARegisters *id) | ||
33 | { | ||
34 | return FIELD_EX64(id->id_aa64mmfr1, ID_AA64MMFR1, VH) != 0; | ||
35 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | 17 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h |
36 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
37 | --- a/target/arm/cpu.h | 19 | --- a/target/arm/cpu.h |
38 | +++ b/target/arm/cpu.h | 20 | +++ b/target/arm/cpu.h |
39 | @@ -XXX,XX +XXX,XX @@ typedef struct CPUArchState { | 21 | @@ -XXX,XX +XXX,XX @@ void pmu_init(ARMCPU *cpu); |
40 | uint64_t c14_cntkctl; /* Timer Control register */ | 22 | #define CPSR_N (1U << 31) |
41 | uint64_t cnthctl_el2; /* Counter/Timer Hyp Control register */ | 23 | #define CPSR_NZCV (CPSR_N | CPSR_Z | CPSR_C | CPSR_V) |
42 | uint64_t cntvoff_el2; /* Counter Virtual Offset register */ | 24 | #define CPSR_AIF (CPSR_A | CPSR_I | CPSR_F) |
43 | + uint64_t cntpoff_el2; /* Counter Physical Offset register */ | 25 | +#define ISR_FS (1U << 9) |
44 | ARMGenericTimer c14_timer[NUM_GTIMERS]; | 26 | +#define ISR_IS (1U << 10) |
45 | uint32_t c15_cpar; /* XScale Coprocessor Access Register */ | 27 | |
46 | uint32_t c15_ticonfig; /* TI925T configuration byte. */ | 28 | #define CPSR_IT (CPSR_IT_0_1 | CPSR_IT_2_7) |
29 | #define CACHED_CPSR_BITS (CPSR_T | CPSR_AIF | CPSR_GE | CPSR_IT | CPSR_Q \ | ||
47 | diff --git a/target/arm/helper.c b/target/arm/helper.c | 30 | diff --git a/target/arm/helper.c b/target/arm/helper.c |
48 | index XXXXXXX..XXXXXXX 100644 | 31 | index XXXXXXX..XXXXXXX 100644 |
49 | --- a/target/arm/helper.c | 32 | --- a/target/arm/helper.c |
50 | +++ b/target/arm/helper.c | 33 | +++ b/target/arm/helper.c |
51 | @@ -XXX,XX +XXX,XX @@ static void scr_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value) | 34 | @@ -XXX,XX +XXX,XX @@ static uint64_t isr_read(CPUARMState *env, const ARMCPRegInfo *ri) |
52 | if (cpu_isar_feature(aa64_rme, cpu)) { | 35 | if (cs->interrupt_request & CPU_INTERRUPT_VIRQ) { |
53 | valid_mask |= SCR_NSE | SCR_GPF; | 36 | ret |= CPSR_I; |
54 | } | 37 | } |
55 | + if (cpu_isar_feature(aa64_ecv, cpu)) { | 38 | + if (cs->interrupt_request & CPU_INTERRUPT_VINMI) { |
56 | + valid_mask |= SCR_ECVEN; | 39 | + ret |= ISR_IS; |
40 | + ret |= CPSR_I; | ||
57 | + } | 41 | + } |
58 | } else { | 42 | } else { |
59 | valid_mask &= ~(SCR_RW | SCR_ST); | 43 | if (cs->interrupt_request & CPU_INTERRUPT_HARD) { |
60 | if (cpu_isar_feature(aa32_ras, cpu)) { | 44 | ret |= CPSR_I; |
61 | @@ -XXX,XX +XXX,XX @@ void gt_rme_post_el_change(ARMCPU *cpu, void *ignored) | 45 | } |
62 | gt_update_irq(cpu, GTIMER_PHYS); | ||
63 | } | ||
64 | |||
65 | +static uint64_t gt_phys_raw_cnt_offset(CPUARMState *env) | ||
66 | +{ | ||
67 | + if ((env->cp15.scr_el3 & SCR_ECVEN) && | ||
68 | + FIELD_EX64(env->cp15.cnthctl_el2, CNTHCTL, ECV) && | ||
69 | + arm_is_el2_enabled(env) && | ||
70 | + (arm_hcr_el2_eff(env) & (HCR_E2H | HCR_TGE)) != (HCR_E2H | HCR_TGE)) { | ||
71 | + return env->cp15.cntpoff_el2; | ||
72 | + } | ||
73 | + return 0; | ||
74 | +} | ||
75 | + | 46 | + |
76 | +static uint64_t gt_phys_cnt_offset(CPUARMState *env) | 47 | + if (cs->interrupt_request & CPU_INTERRUPT_NMI) { |
77 | +{ | 48 | + ret |= ISR_IS; |
78 | + if (arm_current_el(env) >= 2) { | 49 | + ret |= CPSR_I; |
79 | + return 0; | 50 | + } |
80 | + } | ||
81 | + return gt_phys_raw_cnt_offset(env); | ||
82 | +} | ||
83 | + | ||
84 | static void gt_recalc_timer(ARMCPU *cpu, int timeridx) | ||
85 | { | ||
86 | ARMGenericTimer *gt = &cpu->env.cp15.c14_timer[timeridx]; | ||
87 | @@ -XXX,XX +XXX,XX @@ static void gt_recalc_timer(ARMCPU *cpu, int timeridx) | ||
88 | * reset timer to when ISTATUS next has to change | ||
89 | */ | ||
90 | uint64_t offset = timeridx == GTIMER_VIRT ? | ||
91 | - cpu->env.cp15.cntvoff_el2 : 0; | ||
92 | + cpu->env.cp15.cntvoff_el2 : gt_phys_raw_cnt_offset(&cpu->env); | ||
93 | uint64_t count = gt_get_countervalue(&cpu->env); | ||
94 | /* Note that this must be unsigned 64 bit arithmetic: */ | ||
95 | int istatus = count - offset >= gt->cval; | ||
96 | @@ -XXX,XX +XXX,XX @@ static void gt_timer_reset(CPUARMState *env, const ARMCPRegInfo *ri, | ||
97 | |||
98 | static uint64_t gt_cnt_read(CPUARMState *env, const ARMCPRegInfo *ri) | ||
99 | { | ||
100 | - return gt_get_countervalue(env); | ||
101 | + return gt_get_countervalue(env) - gt_phys_cnt_offset(env); | ||
102 | } | ||
103 | |||
104 | static uint64_t gt_virt_cnt_offset(CPUARMState *env) | ||
105 | @@ -XXX,XX +XXX,XX @@ static uint64_t gt_tval_read(CPUARMState *env, const ARMCPRegInfo *ri, | ||
106 | case GTIMER_HYPVIRT: | ||
107 | offset = gt_virt_cnt_offset(env); | ||
108 | break; | ||
109 | + case GTIMER_PHYS: | ||
110 | + offset = gt_phys_cnt_offset(env); | ||
111 | + break; | ||
112 | } | 51 | } |
113 | 52 | ||
114 | return (uint32_t)(env->cp15.c14_timer[timeridx].cval - | 53 | if (hcr_el2 & HCR_FMO) { |
115 | @@ -XXX,XX +XXX,XX @@ static void gt_tval_write(CPUARMState *env, const ARMCPRegInfo *ri, | 54 | if (cs->interrupt_request & CPU_INTERRUPT_VFIQ) { |
116 | case GTIMER_HYPVIRT: | 55 | ret |= CPSR_F; |
117 | offset = gt_virt_cnt_offset(env); | 56 | } |
118 | break; | 57 | + if (cs->interrupt_request & CPU_INTERRUPT_VFNMI) { |
119 | + case GTIMER_PHYS: | 58 | + ret |= ISR_FS; |
120 | + offset = gt_phys_cnt_offset(env); | 59 | + ret |= CPSR_F; |
121 | + break; | 60 | + } |
122 | } | 61 | } else { |
123 | 62 | if (cs->interrupt_request & CPU_INTERRUPT_FIQ) { | |
124 | trace_arm_gt_tval_write(timeridx, value); | 63 | ret |= CPSR_F; |
125 | @@ -XXX,XX +XXX,XX @@ static void gt_cnthctl_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
126 | R_CNTHCTL_EL1NVVCT_MASK | | ||
127 | R_CNTHCTL_EVNTIS_MASK; | ||
128 | } | ||
129 | + if (cpu_isar_feature(aa64_ecv, cpu)) { | ||
130 | + valid_mask |= R_CNTHCTL_ECV_MASK; | ||
131 | + } | ||
132 | |||
133 | /* Clear RES0 bits */ | ||
134 | value &= valid_mask; | ||
135 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo gen_timer_ecv_cp_reginfo[] = { | ||
136 | }, | ||
137 | }; | ||
138 | |||
139 | +static CPAccessResult gt_cntpoff_access(CPUARMState *env, | ||
140 | + const ARMCPRegInfo *ri, | ||
141 | + bool isread) | ||
142 | +{ | ||
143 | + if (arm_current_el(env) == 2 && !(env->cp15.scr_el3 & SCR_ECVEN)) { | ||
144 | + return CP_ACCESS_TRAP_EL3; | ||
145 | + } | ||
146 | + return CP_ACCESS_OK; | ||
147 | +} | ||
148 | + | ||
149 | +static void gt_cntpoff_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
150 | + uint64_t value) | ||
151 | +{ | ||
152 | + ARMCPU *cpu = env_archcpu(env); | ||
153 | + | ||
154 | + trace_arm_gt_cntpoff_write(value); | ||
155 | + raw_write(env, ri, value); | ||
156 | + gt_recalc_timer(cpu, GTIMER_PHYS); | ||
157 | +} | ||
158 | + | ||
159 | +static const ARMCPRegInfo gen_timer_cntpoff_reginfo = { | ||
160 | + .name = "CNTPOFF_EL2", .state = ARM_CP_STATE_AA64, | ||
161 | + .opc0 = 3, .opc1 = 4, .crn = 14, .crm = 0, .opc2 = 6, | ||
162 | + .access = PL2_RW, .type = ARM_CP_IO, .resetvalue = 0, | ||
163 | + .accessfn = gt_cntpoff_access, .writefn = gt_cntpoff_write, | ||
164 | + .nv2_redirect_offset = 0x1a8, | ||
165 | + .fieldoffset = offsetof(CPUARMState, cp15.cntpoff_el2), | ||
166 | +}; | ||
167 | #else | ||
168 | |||
169 | /* | ||
170 | @@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu) | ||
171 | if (cpu_isar_feature(aa64_ecv_traps, cpu)) { | ||
172 | define_arm_cp_regs(cpu, gen_timer_ecv_cp_reginfo); | ||
173 | } | ||
174 | +#ifndef CONFIG_USER_ONLY | ||
175 | + if (cpu_isar_feature(aa64_ecv, cpu)) { | ||
176 | + define_one_arm_cp_reg(cpu, &gen_timer_cntpoff_reginfo); | ||
177 | + } | ||
178 | +#endif | ||
179 | if (arm_feature(env, ARM_FEATURE_VAPA)) { | ||
180 | ARMCPRegInfo vapa_cp_reginfo[] = { | ||
181 | { .name = "PAR", .cp = 15, .crn = 7, .crm = 4, .opc1 = 0, .opc2 = 0, | ||
182 | diff --git a/target/arm/trace-events b/target/arm/trace-events | ||
183 | index XXXXXXX..XXXXXXX 100644 | ||
184 | --- a/target/arm/trace-events | ||
185 | +++ b/target/arm/trace-events | ||
186 | @@ -XXX,XX +XXX,XX @@ arm_gt_tval_write(int timer, uint64_t value) "gt_tval_write: timer %d value 0x%" | ||
187 | arm_gt_ctl_write(int timer, uint64_t value) "gt_ctl_write: timer %d value 0x%" PRIx64 | ||
188 | arm_gt_imask_toggle(int timer) "gt_ctl_write: timer %d IMASK toggle" | ||
189 | arm_gt_cntvoff_write(uint64_t value) "gt_cntvoff_write: value 0x%" PRIx64 | ||
190 | +arm_gt_cntpoff_write(uint64_t value) "gt_cntpoff_write: value 0x%" PRIx64 | ||
191 | arm_gt_update_irq(int timer, int irqstate) "gt_update_irq: timer %d irqstate %d" | ||
192 | |||
193 | # kvm.c | ||
194 | -- | 64 | -- |
195 | 2.34.1 | 65 | 2.34.1 | diff view generated by jsdifflib |
1 | Don't allow the guest to write CNTHCTL_EL2 bits which don't exist. | 1 | From: Jinjie Ruan <ruanjinjie@huawei.com> |
---|---|---|---|
2 | This is not strictly architecturally required, but it is how we've | ||
3 | tended to implement registers more recently. | ||
4 | 2 | ||
5 | In particular, bits [19:18] are only present with FEAT_RME, | 3 | Set or clear PSTATE.ALLINT on taking an exception to ELx according to the |
6 | and bits [17:12] will only be present with FEAT_ECV. | 4 | SCTLR_ELx.SPINTMASK bit. |
7 | 5 | ||
6 | Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> | ||
7 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
9 | Message-id: 20240407081733.3231820-10-ruanjinjie@huawei.com | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
9 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
10 | Message-id: 20240301183219.2424889-5-peter.maydell@linaro.org | ||
11 | --- | 11 | --- |
12 | target/arm/helper.c | 18 ++++++++++++++++++ | 12 | target/arm/helper.c | 8 ++++++++ |
13 | 1 file changed, 18 insertions(+) | 13 | 1 file changed, 8 insertions(+) |
14 | 14 | ||
15 | diff --git a/target/arm/helper.c b/target/arm/helper.c | 15 | diff --git a/target/arm/helper.c b/target/arm/helper.c |
16 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/target/arm/helper.c | 17 | --- a/target/arm/helper.c |
18 | +++ b/target/arm/helper.c | 18 | +++ b/target/arm/helper.c |
19 | @@ -XXX,XX +XXX,XX @@ static void gt_cnthctl_write(CPUARMState *env, const ARMCPRegInfo *ri, | 19 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_do_interrupt_aarch64(CPUState *cs) |
20 | { | 20 | } |
21 | ARMCPU *cpu = env_archcpu(env); | 21 | } |
22 | uint32_t oldval = env->cp15.cnthctl_el2; | 22 | |
23 | + uint32_t valid_mask = | 23 | + if (cpu_isar_feature(aa64_nmi, cpu)) { |
24 | + R_CNTHCTL_EL0PCTEN_E2H1_MASK | | 24 | + if (!(env->cp15.sctlr_el[new_el] & SCTLR_SPINTMASK)) { |
25 | + R_CNTHCTL_EL0VCTEN_E2H1_MASK | | 25 | + new_mode |= PSTATE_ALLINT; |
26 | + R_CNTHCTL_EVNTEN_MASK | | 26 | + } else { |
27 | + R_CNTHCTL_EVNTDIR_MASK | | 27 | + new_mode &= ~PSTATE_ALLINT; |
28 | + R_CNTHCTL_EVNTI_MASK | | 28 | + } |
29 | + R_CNTHCTL_EL0VTEN_MASK | | ||
30 | + R_CNTHCTL_EL0PTEN_MASK | | ||
31 | + R_CNTHCTL_EL1PCTEN_E2H1_MASK | | ||
32 | + R_CNTHCTL_EL1PTEN_MASK; | ||
33 | + | ||
34 | + if (cpu_isar_feature(aa64_rme, cpu)) { | ||
35 | + valid_mask |= R_CNTHCTL_CNTVMASK_MASK | R_CNTHCTL_CNTPMASK_MASK; | ||
36 | + } | 29 | + } |
37 | + | 30 | + |
38 | + /* Clear RES0 bits */ | 31 | pstate_write(env, PSTATE_DAIF | new_mode); |
39 | + value &= valid_mask; | 32 | env->aarch64 = true; |
40 | + | 33 | aarch64_restore_sp(env, new_el); |
41 | raw_write(env, ri, value); | ||
42 | |||
43 | if ((oldval ^ value) & R_CNTHCTL_CNTVMASK_MASK) { | ||
44 | -- | 34 | -- |
45 | 2.34.1 | 35 | 2.34.1 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Jinjie Ruan <ruanjinjie@huawei.com> | ||
1 | 2 | ||
3 | Augment the GICv3's QOM device interface by adding one | ||
4 | new set of sysbus IRQ line, to signal NMI to each CPU. | ||
5 | |||
6 | Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> | ||
7 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
9 | Message-id: 20240407081733.3231820-11-ruanjinjie@huawei.com | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
11 | --- | ||
12 | include/hw/intc/arm_gic_common.h | 2 ++ | ||
13 | include/hw/intc/arm_gicv3_common.h | 2 ++ | ||
14 | hw/intc/arm_gicv3_common.c | 6 ++++++ | ||
15 | 3 files changed, 10 insertions(+) | ||
16 | |||
17 | diff --git a/include/hw/intc/arm_gic_common.h b/include/hw/intc/arm_gic_common.h | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/include/hw/intc/arm_gic_common.h | ||
20 | +++ b/include/hw/intc/arm_gic_common.h | ||
21 | @@ -XXX,XX +XXX,XX @@ struct GICState { | ||
22 | qemu_irq parent_fiq[GIC_NCPU]; | ||
23 | qemu_irq parent_virq[GIC_NCPU]; | ||
24 | qemu_irq parent_vfiq[GIC_NCPU]; | ||
25 | + qemu_irq parent_nmi[GIC_NCPU]; | ||
26 | + qemu_irq parent_vnmi[GIC_NCPU]; | ||
27 | qemu_irq maintenance_irq[GIC_NCPU]; | ||
28 | |||
29 | /* GICD_CTLR; for a GIC with the security extensions the NS banked version | ||
30 | diff --git a/include/hw/intc/arm_gicv3_common.h b/include/hw/intc/arm_gicv3_common.h | ||
31 | index XXXXXXX..XXXXXXX 100644 | ||
32 | --- a/include/hw/intc/arm_gicv3_common.h | ||
33 | +++ b/include/hw/intc/arm_gicv3_common.h | ||
34 | @@ -XXX,XX +XXX,XX @@ struct GICv3CPUState { | ||
35 | qemu_irq parent_fiq; | ||
36 | qemu_irq parent_virq; | ||
37 | qemu_irq parent_vfiq; | ||
38 | + qemu_irq parent_nmi; | ||
39 | + qemu_irq parent_vnmi; | ||
40 | |||
41 | /* Redistributor */ | ||
42 | uint32_t level; /* Current IRQ level */ | ||
43 | diff --git a/hw/intc/arm_gicv3_common.c b/hw/intc/arm_gicv3_common.c | ||
44 | index XXXXXXX..XXXXXXX 100644 | ||
45 | --- a/hw/intc/arm_gicv3_common.c | ||
46 | +++ b/hw/intc/arm_gicv3_common.c | ||
47 | @@ -XXX,XX +XXX,XX @@ void gicv3_init_irqs_and_mmio(GICv3State *s, qemu_irq_handler handler, | ||
48 | for (i = 0; i < s->num_cpu; i++) { | ||
49 | sysbus_init_irq(sbd, &s->cpu[i].parent_vfiq); | ||
50 | } | ||
51 | + for (i = 0; i < s->num_cpu; i++) { | ||
52 | + sysbus_init_irq(sbd, &s->cpu[i].parent_nmi); | ||
53 | + } | ||
54 | + for (i = 0; i < s->num_cpu; i++) { | ||
55 | + sysbus_init_irq(sbd, &s->cpu[i].parent_vnmi); | ||
56 | + } | ||
57 | |||
58 | memory_region_init_io(&s->iomem_dist, OBJECT(s), ops, s, | ||
59 | "gicv3_dist", 0x10000); | ||
60 | -- | ||
61 | 2.34.1 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Jinjie Ruan <ruanjinjie@huawei.com> | ||
1 | 2 | ||
3 | Wire the new NMI and VINMI interrupt line from the GIC to each CPU if it | ||
4 | is not GICv2. | ||
5 | |||
6 | Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> | ||
7 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Message-id: 20240407081733.3231820-12-ruanjinjie@huawei.com | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
10 | --- | ||
11 | hw/arm/virt.c | 10 +++++++++- | ||
12 | 1 file changed, 9 insertions(+), 1 deletion(-) | ||
13 | |||
14 | diff --git a/hw/arm/virt.c b/hw/arm/virt.c | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/hw/arm/virt.c | ||
17 | +++ b/hw/arm/virt.c | ||
18 | @@ -XXX,XX +XXX,XX @@ static void create_gic(VirtMachineState *vms, MemoryRegion *mem) | ||
19 | |||
20 | /* Wire the outputs from each CPU's generic timer and the GICv3 | ||
21 | * maintenance interrupt signal to the appropriate GIC PPI inputs, | ||
22 | - * and the GIC's IRQ/FIQ/VIRQ/VFIQ interrupt outputs to the CPU's inputs. | ||
23 | + * and the GIC's IRQ/FIQ/VIRQ/VFIQ/NMI/VINMI interrupt outputs to the | ||
24 | + * CPU's inputs. | ||
25 | */ | ||
26 | for (i = 0; i < smp_cpus; i++) { | ||
27 | DeviceState *cpudev = DEVICE(qemu_get_cpu(i)); | ||
28 | @@ -XXX,XX +XXX,XX @@ static void create_gic(VirtMachineState *vms, MemoryRegion *mem) | ||
29 | qdev_get_gpio_in(cpudev, ARM_CPU_VIRQ)); | ||
30 | sysbus_connect_irq(gicbusdev, i + 3 * smp_cpus, | ||
31 | qdev_get_gpio_in(cpudev, ARM_CPU_VFIQ)); | ||
32 | + | ||
33 | + if (vms->gic_version != VIRT_GIC_VERSION_2) { | ||
34 | + sysbus_connect_irq(gicbusdev, i + 4 * smp_cpus, | ||
35 | + qdev_get_gpio_in(cpudev, ARM_CPU_NMI)); | ||
36 | + sysbus_connect_irq(gicbusdev, i + 5 * smp_cpus, | ||
37 | + qdev_get_gpio_in(cpudev, ARM_CPU_VINMI)); | ||
38 | + } | ||
39 | } | ||
40 | |||
41 | fdt_add_gic_node(vms); | ||
42 | -- | ||
43 | 2.34.1 | diff view generated by jsdifflib |
1 | The timer _EL02 registers should UNDEF for invalid accesses from EL2 | 1 | From: Jinjie Ruan <ruanjinjie@huawei.com> |
---|---|---|---|
2 | or EL3 when HCR_EL2.E2H == 0, not take a cp access trap. We were | ||
3 | delivering the exception to EL2 with the wrong syndrome. | ||
4 | 2 | ||
3 | According to Arm GIC section 4.6.3 Interrupt superpriority, the interrupt | ||
4 | with superpriority is always IRQ, never FIQ, so the NMI exception trap entry | ||
5 | behave like IRQ. And VINMI(vIRQ with Superpriority) can be raised from the | ||
6 | GIC or come from the hcrx_el2.HCRX_VINMI bit, VFNMI(vFIQ with Superpriority) | ||
7 | come from the hcrx_el2.HCRX_VFNMI bit. | ||
8 | |||
9 | Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> | ||
10 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
11 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
12 | Message-id: 20240407081733.3231820-13-ruanjinjie@huawei.com | ||
5 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 13 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
6 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | Message-id: 20240301183219.2424889-3-peter.maydell@linaro.org | ||
8 | --- | 14 | --- |
9 | target/arm/helper.c | 2 +- | 15 | target/arm/helper.c | 3 +++ |
10 | 1 file changed, 1 insertion(+), 1 deletion(-) | 16 | 1 file changed, 3 insertions(+) |
11 | 17 | ||
12 | diff --git a/target/arm/helper.c b/target/arm/helper.c | 18 | diff --git a/target/arm/helper.c b/target/arm/helper.c |
13 | index XXXXXXX..XXXXXXX 100644 | 19 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/target/arm/helper.c | 20 | --- a/target/arm/helper.c |
15 | +++ b/target/arm/helper.c | 21 | +++ b/target/arm/helper.c |
16 | @@ -XXX,XX +XXX,XX @@ static CPAccessResult e2h_access(CPUARMState *env, const ARMCPRegInfo *ri, | 22 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_do_interrupt_aarch64(CPUState *cs) |
17 | return CP_ACCESS_OK; | 23 | break; |
18 | } | 24 | case EXCP_IRQ: |
19 | if (!(arm_hcr_el2_eff(env) & HCR_E2H)) { | 25 | case EXCP_VIRQ: |
20 | - return CP_ACCESS_TRAP; | 26 | + case EXCP_NMI: |
21 | + return CP_ACCESS_TRAP_UNCATEGORIZED; | 27 | + case EXCP_VINMI: |
22 | } | 28 | addr += 0x80; |
23 | return CP_ACCESS_OK; | 29 | break; |
24 | } | 30 | case EXCP_FIQ: |
31 | case EXCP_VFIQ: | ||
32 | + case EXCP_VFNMI: | ||
33 | addr += 0x100; | ||
34 | break; | ||
35 | case EXCP_VSERR: | ||
25 | -- | 36 | -- |
26 | 2.34.1 | 37 | 2.34.1 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Jinjie Ruan <ruanjinjie@huawei.com> | ||
1 | 2 | ||
3 | Add a property has-nmi to the GICv3 device, and use this to set | ||
4 | the NMI bit in the GICD_TYPER register. This isn't visible to | ||
5 | guests yet because the property defaults to false and we won't | ||
6 | set it in the board code until we've landed all of the changes | ||
7 | needed to implement FEAT_GICV3_NMI. | ||
8 | |||
9 | Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> | ||
10 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
11 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
12 | Message-id: 20240407081733.3231820-14-ruanjinjie@huawei.com | ||
13 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
14 | --- | ||
15 | hw/intc/gicv3_internal.h | 1 + | ||
16 | include/hw/intc/arm_gicv3_common.h | 1 + | ||
17 | hw/intc/arm_gicv3_common.c | 1 + | ||
18 | hw/intc/arm_gicv3_dist.c | 2 ++ | ||
19 | 4 files changed, 5 insertions(+) | ||
20 | |||
21 | diff --git a/hw/intc/gicv3_internal.h b/hw/intc/gicv3_internal.h | ||
22 | index XXXXXXX..XXXXXXX 100644 | ||
23 | --- a/hw/intc/gicv3_internal.h | ||
24 | +++ b/hw/intc/gicv3_internal.h | ||
25 | @@ -XXX,XX +XXX,XX @@ | ||
26 | #define GICD_CTLR_E1NWF (1U << 7) | ||
27 | #define GICD_CTLR_RWP (1U << 31) | ||
28 | |||
29 | +#define GICD_TYPER_NMI_SHIFT 9 | ||
30 | #define GICD_TYPER_LPIS_SHIFT 17 | ||
31 | |||
32 | /* 16 bits EventId */ | ||
33 | diff --git a/include/hw/intc/arm_gicv3_common.h b/include/hw/intc/arm_gicv3_common.h | ||
34 | index XXXXXXX..XXXXXXX 100644 | ||
35 | --- a/include/hw/intc/arm_gicv3_common.h | ||
36 | +++ b/include/hw/intc/arm_gicv3_common.h | ||
37 | @@ -XXX,XX +XXX,XX @@ struct GICv3State { | ||
38 | uint32_t num_irq; | ||
39 | uint32_t revision; | ||
40 | bool lpi_enable; | ||
41 | + bool nmi_support; | ||
42 | bool security_extn; | ||
43 | bool force_8bit_prio; | ||
44 | bool irq_reset_nonsecure; | ||
45 | diff --git a/hw/intc/arm_gicv3_common.c b/hw/intc/arm_gicv3_common.c | ||
46 | index XXXXXXX..XXXXXXX 100644 | ||
47 | --- a/hw/intc/arm_gicv3_common.c | ||
48 | +++ b/hw/intc/arm_gicv3_common.c | ||
49 | @@ -XXX,XX +XXX,XX @@ static Property arm_gicv3_common_properties[] = { | ||
50 | DEFINE_PROP_UINT32("num-irq", GICv3State, num_irq, 32), | ||
51 | DEFINE_PROP_UINT32("revision", GICv3State, revision, 3), | ||
52 | DEFINE_PROP_BOOL("has-lpi", GICv3State, lpi_enable, 0), | ||
53 | + DEFINE_PROP_BOOL("has-nmi", GICv3State, nmi_support, 0), | ||
54 | DEFINE_PROP_BOOL("has-security-extensions", GICv3State, security_extn, 0), | ||
55 | /* | ||
56 | * Compatibility property: force 8 bits of physical priority, even | ||
57 | diff --git a/hw/intc/arm_gicv3_dist.c b/hw/intc/arm_gicv3_dist.c | ||
58 | index XXXXXXX..XXXXXXX 100644 | ||
59 | --- a/hw/intc/arm_gicv3_dist.c | ||
60 | +++ b/hw/intc/arm_gicv3_dist.c | ||
61 | @@ -XXX,XX +XXX,XX @@ static bool gicd_readl(GICv3State *s, hwaddr offset, | ||
62 | * by GICD_TYPER.IDbits) | ||
63 | * MBIS == 0 (message-based SPIs not supported) | ||
64 | * SecurityExtn == 1 if security extns supported | ||
65 | + * NMI = 1 if Non-maskable interrupt property is supported | ||
66 | * CPUNumber == 0 since for us ARE is always 1 | ||
67 | * ITLinesNumber == (((max SPI IntID + 1) / 32) - 1) | ||
68 | */ | ||
69 | @@ -XXX,XX +XXX,XX @@ static bool gicd_readl(GICv3State *s, hwaddr offset, | ||
70 | bool dvis = s->revision >= 4; | ||
71 | |||
72 | *data = (1 << 25) | (1 << 24) | (dvis << 18) | (sec_extn << 10) | | ||
73 | + (s->nmi_support << GICD_TYPER_NMI_SHIFT) | | ||
74 | (s->lpi_enable << GICD_TYPER_LPIS_SHIFT) | | ||
75 | (0xf << 19) | itlinesnumber; | ||
76 | return true; | ||
77 | -- | ||
78 | 2.34.1 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Jinjie Ruan <ruanjinjie@huawei.com> | ||
1 | 2 | ||
3 | So far, there is no FEAT_GICv3_NMI support in the in-kernel GIC, so make it | ||
4 | an error to try to set has-nmi=true for the KVM GICv3. | ||
5 | |||
6 | Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> | ||
7 | Message-id: 20240407081733.3231820-15-ruanjinjie@huawei.com | ||
8 | Suggested-by: Peter Maydell <peter.maydell@linaro.org> | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
10 | --- | ||
11 | hw/intc/arm_gicv3_kvm.c | 5 +++++ | ||
12 | 1 file changed, 5 insertions(+) | ||
13 | |||
14 | diff --git a/hw/intc/arm_gicv3_kvm.c b/hw/intc/arm_gicv3_kvm.c | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/hw/intc/arm_gicv3_kvm.c | ||
17 | +++ b/hw/intc/arm_gicv3_kvm.c | ||
18 | @@ -XXX,XX +XXX,XX @@ static void kvm_arm_gicv3_realize(DeviceState *dev, Error **errp) | ||
19 | return; | ||
20 | } | ||
21 | |||
22 | + if (s->nmi_support) { | ||
23 | + error_setg(errp, "NMI is not supported with the in-kernel GIC"); | ||
24 | + return; | ||
25 | + } | ||
26 | + | ||
27 | gicv3_init_irqs_and_mmio(s, kvm_arm_gicv3_set_irq, NULL); | ||
28 | |||
29 | for (i = 0; i < s->num_cpu; i++) { | ||
30 | -- | ||
31 | 2.34.1 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Jinjie Ruan <ruanjinjie@huawei.com> | ||
1 | 2 | ||
3 | A SPI, PPI or SGI interrupt can have non-maskable property. So maintain | ||
4 | non-maskable property in PendingIrq and GICR/GICD. Since add new device | ||
5 | state, it also needs to be migrated, so also save NMI info in | ||
6 | vmstate_gicv3_cpu and vmstate_gicv3. | ||
7 | |||
8 | Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> | ||
9 | Acked-by: Richard Henderson <richard.henderson@linaro.org> | ||
10 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
11 | Message-id: 20240407081733.3231820-16-ruanjinjie@huawei.com | ||
12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
13 | --- | ||
14 | include/hw/intc/arm_gicv3_common.h | 4 ++++ | ||
15 | hw/intc/arm_gicv3_common.c | 38 ++++++++++++++++++++++++++++++ | ||
16 | 2 files changed, 42 insertions(+) | ||
17 | |||
18 | diff --git a/include/hw/intc/arm_gicv3_common.h b/include/hw/intc/arm_gicv3_common.h | ||
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/include/hw/intc/arm_gicv3_common.h | ||
21 | +++ b/include/hw/intc/arm_gicv3_common.h | ||
22 | @@ -XXX,XX +XXX,XX @@ typedef struct { | ||
23 | int irq; | ||
24 | uint8_t prio; | ||
25 | int grp; | ||
26 | + bool nmi; | ||
27 | } PendingIrq; | ||
28 | |||
29 | struct GICv3CPUState { | ||
30 | @@ -XXX,XX +XXX,XX @@ struct GICv3CPUState { | ||
31 | uint32_t gicr_ienabler0; | ||
32 | uint32_t gicr_ipendr0; | ||
33 | uint32_t gicr_iactiver0; | ||
34 | + uint32_t gicr_inmir0; | ||
35 | uint32_t edge_trigger; /* ICFGR0 and ICFGR1 even bits */ | ||
36 | uint32_t gicr_igrpmodr0; | ||
37 | uint32_t gicr_nsacr; | ||
38 | @@ -XXX,XX +XXX,XX @@ struct GICv3State { | ||
39 | GIC_DECLARE_BITMAP(active); /* GICD_ISACTIVER */ | ||
40 | GIC_DECLARE_BITMAP(level); /* Current level */ | ||
41 | GIC_DECLARE_BITMAP(edge_trigger); /* GICD_ICFGR even bits */ | ||
42 | + GIC_DECLARE_BITMAP(nmi); /* GICD_INMIR */ | ||
43 | uint8_t gicd_ipriority[GICV3_MAXIRQ]; | ||
44 | uint64_t gicd_irouter[GICV3_MAXIRQ]; | ||
45 | /* Cached information: pointer to the cpu i/f for the CPUs specified | ||
46 | @@ -XXX,XX +XXX,XX @@ GICV3_BITMAP_ACCESSORS(pending) | ||
47 | GICV3_BITMAP_ACCESSORS(active) | ||
48 | GICV3_BITMAP_ACCESSORS(level) | ||
49 | GICV3_BITMAP_ACCESSORS(edge_trigger) | ||
50 | +GICV3_BITMAP_ACCESSORS(nmi) | ||
51 | |||
52 | #define TYPE_ARM_GICV3_COMMON "arm-gicv3-common" | ||
53 | typedef struct ARMGICv3CommonClass ARMGICv3CommonClass; | ||
54 | diff --git a/hw/intc/arm_gicv3_common.c b/hw/intc/arm_gicv3_common.c | ||
55 | index XXXXXXX..XXXXXXX 100644 | ||
56 | --- a/hw/intc/arm_gicv3_common.c | ||
57 | +++ b/hw/intc/arm_gicv3_common.c | ||
58 | @@ -XXX,XX +XXX,XX @@ const VMStateDescription vmstate_gicv3_gicv4 = { | ||
59 | } | ||
60 | }; | ||
61 | |||
62 | +static bool gicv3_cpu_nmi_needed(void *opaque) | ||
63 | +{ | ||
64 | + GICv3CPUState *cs = opaque; | ||
65 | + | ||
66 | + return cs->gic->nmi_support; | ||
67 | +} | ||
68 | + | ||
69 | +static const VMStateDescription vmstate_gicv3_cpu_nmi = { | ||
70 | + .name = "arm_gicv3_cpu/nmi", | ||
71 | + .version_id = 1, | ||
72 | + .minimum_version_id = 1, | ||
73 | + .needed = gicv3_cpu_nmi_needed, | ||
74 | + .fields = (const VMStateField[]) { | ||
75 | + VMSTATE_UINT32(gicr_inmir0, GICv3CPUState), | ||
76 | + VMSTATE_END_OF_LIST() | ||
77 | + } | ||
78 | +}; | ||
79 | + | ||
80 | static const VMStateDescription vmstate_gicv3_cpu = { | ||
81 | .name = "arm_gicv3_cpu", | ||
82 | .version_id = 1, | ||
83 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_gicv3_cpu = { | ||
84 | &vmstate_gicv3_cpu_virt, | ||
85 | &vmstate_gicv3_cpu_sre_el1, | ||
86 | &vmstate_gicv3_gicv4, | ||
87 | + &vmstate_gicv3_cpu_nmi, | ||
88 | NULL | ||
89 | } | ||
90 | }; | ||
91 | @@ -XXX,XX +XXX,XX @@ const VMStateDescription vmstate_gicv3_gicd_no_migration_shift_bug = { | ||
92 | } | ||
93 | }; | ||
94 | |||
95 | +static bool gicv3_nmi_needed(void *opaque) | ||
96 | +{ | ||
97 | + GICv3State *cs = opaque; | ||
98 | + | ||
99 | + return cs->nmi_support; | ||
100 | +} | ||
101 | + | ||
102 | +const VMStateDescription vmstate_gicv3_gicd_nmi = { | ||
103 | + .name = "arm_gicv3/gicd_nmi", | ||
104 | + .version_id = 1, | ||
105 | + .minimum_version_id = 1, | ||
106 | + .needed = gicv3_nmi_needed, | ||
107 | + .fields = (const VMStateField[]) { | ||
108 | + VMSTATE_UINT32_ARRAY(nmi, GICv3State, GICV3_BMP_SIZE), | ||
109 | + VMSTATE_END_OF_LIST() | ||
110 | + } | ||
111 | +}; | ||
112 | + | ||
113 | static const VMStateDescription vmstate_gicv3 = { | ||
114 | .name = "arm_gicv3", | ||
115 | .version_id = 1, | ||
116 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_gicv3 = { | ||
117 | }, | ||
118 | .subsections = (const VMStateDescription * const []) { | ||
119 | &vmstate_gicv3_gicd_no_migration_shift_bug, | ||
120 | + &vmstate_gicv3_gicd_nmi, | ||
121 | NULL | ||
122 | } | ||
123 | }; | ||
124 | -- | ||
125 | 2.34.1 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Jinjie Ruan <ruanjinjie@huawei.com> | ||
1 | 2 | ||
3 | Add GICR_INMIR0 register and support access GICR_INMIR0. | ||
4 | |||
5 | Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> | ||
6 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
8 | Message-id: 20240407081733.3231820-17-ruanjinjie@huawei.com | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
10 | --- | ||
11 | hw/intc/gicv3_internal.h | 1 + | ||
12 | hw/intc/arm_gicv3_redist.c | 19 +++++++++++++++++++ | ||
13 | 2 files changed, 20 insertions(+) | ||
14 | |||
15 | diff --git a/hw/intc/gicv3_internal.h b/hw/intc/gicv3_internal.h | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/hw/intc/gicv3_internal.h | ||
18 | +++ b/hw/intc/gicv3_internal.h | ||
19 | @@ -XXX,XX +XXX,XX @@ | ||
20 | #define GICR_ICFGR1 (GICR_SGI_OFFSET + 0x0C04) | ||
21 | #define GICR_IGRPMODR0 (GICR_SGI_OFFSET + 0x0D00) | ||
22 | #define GICR_NSACR (GICR_SGI_OFFSET + 0x0E00) | ||
23 | +#define GICR_INMIR0 (GICR_SGI_OFFSET + 0x0F80) | ||
24 | |||
25 | /* VLPI redistributor registers, offsets from VLPI_base */ | ||
26 | #define GICR_VPROPBASER (GICR_VLPI_OFFSET + 0x70) | ||
27 | diff --git a/hw/intc/arm_gicv3_redist.c b/hw/intc/arm_gicv3_redist.c | ||
28 | index XXXXXXX..XXXXXXX 100644 | ||
29 | --- a/hw/intc/arm_gicv3_redist.c | ||
30 | +++ b/hw/intc/arm_gicv3_redist.c | ||
31 | @@ -XXX,XX +XXX,XX @@ static int gicr_ns_access(GICv3CPUState *cs, int irq) | ||
32 | return extract32(cs->gicr_nsacr, irq * 2, 2); | ||
33 | } | ||
34 | |||
35 | +static void gicr_write_bitmap_reg(GICv3CPUState *cs, MemTxAttrs attrs, | ||
36 | + uint32_t *reg, uint32_t val) | ||
37 | +{ | ||
38 | + /* Helper routine to implement writing to a "set" register */ | ||
39 | + val &= mask_group(cs, attrs); | ||
40 | + *reg = val; | ||
41 | + gicv3_redist_update(cs); | ||
42 | +} | ||
43 | + | ||
44 | static void gicr_write_set_bitmap_reg(GICv3CPUState *cs, MemTxAttrs attrs, | ||
45 | uint32_t *reg, uint32_t val) | ||
46 | { | ||
47 | @@ -XXX,XX +XXX,XX @@ static MemTxResult gicr_readl(GICv3CPUState *cs, hwaddr offset, | ||
48 | *data = value; | ||
49 | return MEMTX_OK; | ||
50 | } | ||
51 | + case GICR_INMIR0: | ||
52 | + *data = cs->gic->nmi_support ? | ||
53 | + gicr_read_bitmap_reg(cs, attrs, cs->gicr_inmir0) : 0; | ||
54 | + return MEMTX_OK; | ||
55 | case GICR_ICFGR0: | ||
56 | case GICR_ICFGR1: | ||
57 | { | ||
58 | @@ -XXX,XX +XXX,XX @@ static MemTxResult gicr_writel(GICv3CPUState *cs, hwaddr offset, | ||
59 | gicv3_redist_update(cs); | ||
60 | return MEMTX_OK; | ||
61 | } | ||
62 | + case GICR_INMIR0: | ||
63 | + if (cs->gic->nmi_support) { | ||
64 | + gicr_write_bitmap_reg(cs, attrs, &cs->gicr_inmir0, value); | ||
65 | + } | ||
66 | + return MEMTX_OK; | ||
67 | + | ||
68 | case GICR_ICFGR0: | ||
69 | /* Register is all RAZ/WI or RAO/WI bits */ | ||
70 | return MEMTX_OK; | ||
71 | -- | ||
72 | 2.34.1 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Jinjie Ruan <ruanjinjie@huawei.com> | ||
1 | 2 | ||
3 | Add GICD_INMIR, GICD_INMIRnE register and support access GICD_INMIR0. | ||
4 | |||
5 | Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> | ||
6 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
8 | Message-id: 20240407081733.3231820-18-ruanjinjie@huawei.com | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
10 | --- | ||
11 | hw/intc/gicv3_internal.h | 2 ++ | ||
12 | hw/intc/arm_gicv3_dist.c | 34 ++++++++++++++++++++++++++++++++++ | ||
13 | 2 files changed, 36 insertions(+) | ||
14 | |||
15 | diff --git a/hw/intc/gicv3_internal.h b/hw/intc/gicv3_internal.h | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/hw/intc/gicv3_internal.h | ||
18 | +++ b/hw/intc/gicv3_internal.h | ||
19 | @@ -XXX,XX +XXX,XX @@ | ||
20 | #define GICD_SGIR 0x0F00 | ||
21 | #define GICD_CPENDSGIR 0x0F10 | ||
22 | #define GICD_SPENDSGIR 0x0F20 | ||
23 | +#define GICD_INMIR 0x0F80 | ||
24 | +#define GICD_INMIRnE 0x3B00 | ||
25 | #define GICD_IROUTER 0x6000 | ||
26 | #define GICD_IDREGS 0xFFD0 | ||
27 | |||
28 | diff --git a/hw/intc/arm_gicv3_dist.c b/hw/intc/arm_gicv3_dist.c | ||
29 | index XXXXXXX..XXXXXXX 100644 | ||
30 | --- a/hw/intc/arm_gicv3_dist.c | ||
31 | +++ b/hw/intc/arm_gicv3_dist.c | ||
32 | @@ -XXX,XX +XXX,XX @@ static int gicd_ns_access(GICv3State *s, int irq) | ||
33 | return extract32(s->gicd_nsacr[irq / 16], (irq % 16) * 2, 2); | ||
34 | } | ||
35 | |||
36 | +static void gicd_write_bitmap_reg(GICv3State *s, MemTxAttrs attrs, | ||
37 | + uint32_t *bmp, maskfn *maskfn, | ||
38 | + int offset, uint32_t val) | ||
39 | +{ | ||
40 | + /* | ||
41 | + * Helper routine to implement writing to a "set" register | ||
42 | + * (GICD_INMIR, etc). | ||
43 | + * Semantics implemented here: | ||
44 | + * RAZ/WI for SGIs, PPIs, unimplemented IRQs | ||
45 | + * Bits corresponding to Group 0 or Secure Group 1 interrupts RAZ/WI. | ||
46 | + * offset should be the offset in bytes of the register from the start | ||
47 | + * of its group. | ||
48 | + */ | ||
49 | + int irq = offset * 8; | ||
50 | + | ||
51 | + if (irq < GIC_INTERNAL || irq >= s->num_irq) { | ||
52 | + return; | ||
53 | + } | ||
54 | + val &= mask_group_and_nsacr(s, attrs, maskfn, irq); | ||
55 | + *gic_bmp_ptr32(bmp, irq) = val; | ||
56 | + gicv3_update(s, irq, 32); | ||
57 | +} | ||
58 | + | ||
59 | static void gicd_write_set_bitmap_reg(GICv3State *s, MemTxAttrs attrs, | ||
60 | uint32_t *bmp, | ||
61 | maskfn *maskfn, | ||
62 | @@ -XXX,XX +XXX,XX @@ static bool gicd_readl(GICv3State *s, hwaddr offset, | ||
63 | /* RAZ/WI since affinity routing is always enabled */ | ||
64 | *data = 0; | ||
65 | return true; | ||
66 | + case GICD_INMIR ... GICD_INMIR + 0x7f: | ||
67 | + *data = (!s->nmi_support) ? 0 : | ||
68 | + gicd_read_bitmap_reg(s, attrs, s->nmi, NULL, | ||
69 | + offset - GICD_INMIR); | ||
70 | + return true; | ||
71 | case GICD_IROUTER ... GICD_IROUTER + 0x1fdf: | ||
72 | { | ||
73 | uint64_t r; | ||
74 | @@ -XXX,XX +XXX,XX @@ static bool gicd_writel(GICv3State *s, hwaddr offset, | ||
75 | case GICD_SPENDSGIR ... GICD_SPENDSGIR + 0xf: | ||
76 | /* RAZ/WI since affinity routing is always enabled */ | ||
77 | return true; | ||
78 | + case GICD_INMIR ... GICD_INMIR + 0x7f: | ||
79 | + if (s->nmi_support) { | ||
80 | + gicd_write_bitmap_reg(s, attrs, s->nmi, NULL, | ||
81 | + offset - GICD_INMIR, value); | ||
82 | + } | ||
83 | + return true; | ||
84 | case GICD_IROUTER ... GICD_IROUTER + 0x1fdf: | ||
85 | { | ||
86 | uint64_t r; | ||
87 | -- | ||
88 | 2.34.1 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Add the NMIAR CPU interface registers which deal with acknowledging NMI. | ||
1 | 2 | ||
3 | When introduce NMI interrupt, there are some updates to the semantics for the | ||
4 | register ICC_IAR1_EL1 and ICC_HPPIR1_EL1. For ICC_IAR1_EL1 register, it | ||
5 | should return 1022 if the intid has non-maskable property. And for | ||
6 | ICC_NMIAR1_EL1 register, it should return 1023 if the intid do not have | ||
7 | non-maskable property. Howerever, these are not necessary for ICC_HPPIR1_EL1 | ||
8 | register. | ||
9 | |||
10 | And the APR and RPR has NMI bits which should be handled correctly. | ||
11 | |||
12 | Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> | ||
13 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
14 | [PMM: Separate out whether cpuif supports NMI from whether the | ||
15 | GIC proper (IRI) supports NMI] | ||
16 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
17 | Message-id: 20240407081733.3231820-19-ruanjinjie@huawei.com | ||
18 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
19 | --- | ||
20 | hw/intc/gicv3_internal.h | 5 + | ||
21 | include/hw/intc/arm_gicv3_common.h | 7 ++ | ||
22 | hw/intc/arm_gicv3_cpuif.c | 147 ++++++++++++++++++++++++++++- | ||
23 | hw/intc/trace-events | 1 + | ||
24 | 4 files changed, 155 insertions(+), 5 deletions(-) | ||
25 | |||
26 | diff --git a/hw/intc/gicv3_internal.h b/hw/intc/gicv3_internal.h | ||
27 | index XXXXXXX..XXXXXXX 100644 | ||
28 | --- a/hw/intc/gicv3_internal.h | ||
29 | +++ b/hw/intc/gicv3_internal.h | ||
30 | @@ -XXX,XX +XXX,XX @@ FIELD(GICR_VPENDBASER, VALID, 63, 1) | ||
31 | #define ICC_CTLR_EL3_A3V (1U << 15) | ||
32 | #define ICC_CTLR_EL3_NDS (1U << 17) | ||
33 | |||
34 | +#define ICC_AP1R_EL1_NMI (1ULL << 63) | ||
35 | +#define ICC_RPR_EL1_NSNMI (1ULL << 62) | ||
36 | +#define ICC_RPR_EL1_NMI (1ULL << 63) | ||
37 | + | ||
38 | #define ICH_VMCR_EL2_VENG0_SHIFT 0 | ||
39 | #define ICH_VMCR_EL2_VENG0 (1U << ICH_VMCR_EL2_VENG0_SHIFT) | ||
40 | #define ICH_VMCR_EL2_VENG1_SHIFT 1 | ||
41 | @@ -XXX,XX +XXX,XX @@ FIELD(VTE, RDBASE, 42, RDBASE_PROCNUM_LENGTH) | ||
42 | /* Special interrupt IDs */ | ||
43 | #define INTID_SECURE 1020 | ||
44 | #define INTID_NONSECURE 1021 | ||
45 | +#define INTID_NMI 1022 | ||
46 | #define INTID_SPURIOUS 1023 | ||
47 | |||
48 | /* Functions internal to the emulated GICv3 */ | ||
49 | diff --git a/include/hw/intc/arm_gicv3_common.h b/include/hw/intc/arm_gicv3_common.h | ||
50 | index XXXXXXX..XXXXXXX 100644 | ||
51 | --- a/include/hw/intc/arm_gicv3_common.h | ||
52 | +++ b/include/hw/intc/arm_gicv3_common.h | ||
53 | @@ -XXX,XX +XXX,XX @@ struct GICv3CPUState { | ||
54 | |||
55 | /* This is temporary working state, to avoid a malloc in gicv3_update() */ | ||
56 | bool seenbetter; | ||
57 | + | ||
58 | + /* | ||
59 | + * Whether the CPU interface has NMI support (FEAT_GICv3_NMI). The | ||
60 | + * CPU interface may support NMIs even when the GIC proper (what the | ||
61 | + * spec calls the IRI; the redistributors and distributor) does not. | ||
62 | + */ | ||
63 | + bool nmi_support; | ||
64 | }; | ||
65 | |||
66 | /* | ||
67 | diff --git a/hw/intc/arm_gicv3_cpuif.c b/hw/intc/arm_gicv3_cpuif.c | ||
68 | index XXXXXXX..XXXXXXX 100644 | ||
69 | --- a/hw/intc/arm_gicv3_cpuif.c | ||
70 | +++ b/hw/intc/arm_gicv3_cpuif.c | ||
71 | @@ -XXX,XX +XXX,XX @@ | ||
72 | #include "hw/irq.h" | ||
73 | #include "cpu.h" | ||
74 | #include "target/arm/cpregs.h" | ||
75 | +#include "target/arm/cpu-features.h" | ||
76 | #include "sysemu/tcg.h" | ||
77 | #include "sysemu/qtest.h" | ||
78 | |||
79 | @@ -XXX,XX +XXX,XX @@ static uint64_t icv_iar_read(CPUARMState *env, const ARMCPRegInfo *ri) | ||
80 | return intid; | ||
81 | } | ||
82 | |||
83 | +static uint64_t icv_nmiar1_read(CPUARMState *env, const ARMCPRegInfo *ri) | ||
84 | +{ | ||
85 | + /* todo */ | ||
86 | + uint64_t intid = INTID_SPURIOUS; | ||
87 | + return intid; | ||
88 | +} | ||
89 | + | ||
90 | static uint32_t icc_fullprio_mask(GICv3CPUState *cs) | ||
91 | { | ||
92 | /* | ||
93 | @@ -XXX,XX +XXX,XX @@ static int icc_highest_active_prio(GICv3CPUState *cs) | ||
94 | */ | ||
95 | int i; | ||
96 | |||
97 | + if (cs->nmi_support) { | ||
98 | + /* | ||
99 | + * If an NMI is active this takes precedence over anything else | ||
100 | + * for priority purposes; the NMI bit is only in the AP1R0 bit. | ||
101 | + * We return here the effective priority of the NMI, which is | ||
102 | + * either 0x0 or 0x80. Callers will need to check NMI again for | ||
103 | + * purposes of either setting the RPR register bits or for | ||
104 | + * prioritization of NMI vs non-NMI. | ||
105 | + */ | ||
106 | + if (cs->icc_apr[GICV3_G1][0] & ICC_AP1R_EL1_NMI) { | ||
107 | + return 0; | ||
108 | + } | ||
109 | + if (cs->icc_apr[GICV3_G1NS][0] & ICC_AP1R_EL1_NMI) { | ||
110 | + return (cs->gic->gicd_ctlr & GICD_CTLR_DS) ? 0 : 0x80; | ||
111 | + } | ||
112 | + } | ||
113 | + | ||
114 | for (i = 0; i < icc_num_aprs(cs); i++) { | ||
115 | uint32_t apr = cs->icc_apr[GICV3_G0][i] | | ||
116 | cs->icc_apr[GICV3_G1][i] | cs->icc_apr[GICV3_G1NS][i]; | ||
117 | @@ -XXX,XX +XXX,XX @@ static bool icc_hppi_can_preempt(GICv3CPUState *cs) | ||
118 | */ | ||
119 | int rprio; | ||
120 | uint32_t mask; | ||
121 | + ARMCPU *cpu = ARM_CPU(cs->cpu); | ||
122 | + CPUARMState *env = &cpu->env; | ||
123 | |||
124 | if (icc_no_enabled_hppi(cs)) { | ||
125 | return false; | ||
126 | } | ||
127 | |||
128 | - if (cs->hppi.prio >= cs->icc_pmr_el1) { | ||
129 | + if (cs->hppi.nmi) { | ||
130 | + if (!(cs->gic->gicd_ctlr & GICD_CTLR_DS) && | ||
131 | + cs->hppi.grp == GICV3_G1NS) { | ||
132 | + if (cs->icc_pmr_el1 < 0x80) { | ||
133 | + return false; | ||
134 | + } | ||
135 | + if (arm_is_secure(env) && cs->icc_pmr_el1 == 0x80) { | ||
136 | + return false; | ||
137 | + } | ||
138 | + } | ||
139 | + } else if (cs->hppi.prio >= cs->icc_pmr_el1) { | ||
140 | /* Priority mask masks this interrupt */ | ||
141 | return false; | ||
142 | } | ||
143 | @@ -XXX,XX +XXX,XX @@ static bool icc_hppi_can_preempt(GICv3CPUState *cs) | ||
144 | return true; | ||
145 | } | ||
146 | |||
147 | + if (cs->hppi.nmi && (cs->hppi.prio & mask) == (rprio & mask)) { | ||
148 | + if (!(cs->icc_apr[cs->hppi.grp][0] & ICC_AP1R_EL1_NMI)) { | ||
149 | + return true; | ||
150 | + } | ||
151 | + } | ||
152 | + | ||
153 | return false; | ||
154 | } | ||
155 | |||
156 | @@ -XXX,XX +XXX,XX @@ static void icc_activate_irq(GICv3CPUState *cs, int irq) | ||
157 | int aprbit = prio >> (8 - cs->prebits); | ||
158 | int regno = aprbit / 32; | ||
159 | int regbit = aprbit % 32; | ||
160 | + bool nmi = cs->hppi.nmi; | ||
161 | |||
162 | - cs->icc_apr[cs->hppi.grp][regno] |= (1 << regbit); | ||
163 | + if (nmi) { | ||
164 | + cs->icc_apr[cs->hppi.grp][regno] |= ICC_AP1R_EL1_NMI; | ||
165 | + } else { | ||
166 | + cs->icc_apr[cs->hppi.grp][regno] |= (1 << regbit); | ||
167 | + } | ||
168 | |||
169 | if (irq < GIC_INTERNAL) { | ||
170 | cs->gicr_iactiver0 = deposit32(cs->gicr_iactiver0, irq, 1, 1); | ||
171 | @@ -XXX,XX +XXX,XX @@ static uint64_t icc_iar0_read(CPUARMState *env, const ARMCPRegInfo *ri) | ||
172 | static uint64_t icc_iar1_read(CPUARMState *env, const ARMCPRegInfo *ri) | ||
173 | { | ||
174 | GICv3CPUState *cs = icc_cs_from_env(env); | ||
175 | + int el = arm_current_el(env); | ||
176 | uint64_t intid; | ||
177 | |||
178 | if (icv_access(env, HCR_IMO)) { | ||
179 | @@ -XXX,XX +XXX,XX @@ static uint64_t icc_iar1_read(CPUARMState *env, const ARMCPRegInfo *ri) | ||
180 | } | ||
181 | |||
182 | if (!gicv3_intid_is_special(intid)) { | ||
183 | - icc_activate_irq(cs, intid); | ||
184 | + if (cs->hppi.nmi && env->cp15.sctlr_el[el] & SCTLR_NMI) { | ||
185 | + intid = INTID_NMI; | ||
186 | + } else { | ||
187 | + icc_activate_irq(cs, intid); | ||
188 | + } | ||
189 | } | ||
190 | |||
191 | trace_gicv3_icc_iar1_read(gicv3_redist_affid(cs), intid); | ||
192 | return intid; | ||
193 | } | ||
194 | |||
195 | +static uint64_t icc_nmiar1_read(CPUARMState *env, const ARMCPRegInfo *ri) | ||
196 | +{ | ||
197 | + GICv3CPUState *cs = icc_cs_from_env(env); | ||
198 | + uint64_t intid; | ||
199 | + | ||
200 | + if (icv_access(env, HCR_IMO)) { | ||
201 | + return icv_nmiar1_read(env, ri); | ||
202 | + } | ||
203 | + | ||
204 | + if (!icc_hppi_can_preempt(cs)) { | ||
205 | + intid = INTID_SPURIOUS; | ||
206 | + } else { | ||
207 | + intid = icc_hppir1_value(cs, env); | ||
208 | + } | ||
209 | + | ||
210 | + if (!gicv3_intid_is_special(intid)) { | ||
211 | + if (!cs->hppi.nmi) { | ||
212 | + intid = INTID_SPURIOUS; | ||
213 | + } else { | ||
214 | + icc_activate_irq(cs, intid); | ||
215 | + } | ||
216 | + } | ||
217 | + | ||
218 | + trace_gicv3_icc_nmiar1_read(gicv3_redist_affid(cs), intid); | ||
219 | + return intid; | ||
220 | +} | ||
221 | + | ||
222 | static void icc_drop_prio(GICv3CPUState *cs, int grp) | ||
223 | { | ||
224 | /* Drop the priority of the currently active interrupt in | ||
225 | @@ -XXX,XX +XXX,XX @@ static void icc_drop_prio(GICv3CPUState *cs, int grp) | ||
226 | if (!*papr) { | ||
227 | continue; | ||
228 | } | ||
229 | + | ||
230 | + if (i == 0 && cs->nmi_support && (*papr & ICC_AP1R_EL1_NMI)) { | ||
231 | + *papr &= (~ICC_AP1R_EL1_NMI); | ||
232 | + break; | ||
233 | + } | ||
234 | + | ||
235 | /* Clear the lowest set bit */ | ||
236 | *papr &= *papr - 1; | ||
237 | break; | ||
238 | @@ -XXX,XX +XXX,XX @@ static int icc_highest_active_group(GICv3CPUState *cs) | ||
239 | */ | ||
240 | int i; | ||
241 | |||
242 | + if (cs->nmi_support) { | ||
243 | + if (cs->icc_apr[GICV3_G1][0] & ICC_AP1R_EL1_NMI) { | ||
244 | + return GICV3_G1; | ||
245 | + } | ||
246 | + if (cs->icc_apr[GICV3_G1NS][0] & ICC_AP1R_EL1_NMI) { | ||
247 | + return GICV3_G1NS; | ||
248 | + } | ||
249 | + } | ||
250 | + | ||
251 | for (i = 0; i < ARRAY_SIZE(cs->icc_apr[0]); i++) { | ||
252 | int g0ctz = ctz32(cs->icc_apr[GICV3_G0][i]); | ||
253 | int g1ctz = ctz32(cs->icc_apr[GICV3_G1][i]); | ||
254 | @@ -XXX,XX +XXX,XX @@ static void icc_ap_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
255 | return; | ||
256 | } | ||
257 | |||
258 | - cs->icc_apr[grp][regno] = value & 0xFFFFFFFFU; | ||
259 | + if (cs->nmi_support) { | ||
260 | + cs->icc_apr[grp][regno] = value & (0xFFFFFFFFU | ICC_AP1R_EL1_NMI); | ||
261 | + } else { | ||
262 | + cs->icc_apr[grp][regno] = value & 0xFFFFFFFFU; | ||
263 | + } | ||
264 | gicv3_cpuif_update(cs); | ||
265 | } | ||
266 | |||
267 | @@ -XXX,XX +XXX,XX @@ static void icc_dir_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
268 | static uint64_t icc_rpr_read(CPUARMState *env, const ARMCPRegInfo *ri) | ||
269 | { | ||
270 | GICv3CPUState *cs = icc_cs_from_env(env); | ||
271 | - int prio; | ||
272 | + uint64_t prio; | ||
273 | |||
274 | if (icv_access(env, HCR_FMO | HCR_IMO)) { | ||
275 | return icv_rpr_read(env, ri); | ||
276 | @@ -XXX,XX +XXX,XX @@ static uint64_t icc_rpr_read(CPUARMState *env, const ARMCPRegInfo *ri) | ||
277 | } | ||
278 | } | ||
279 | |||
280 | + if (cs->nmi_support) { | ||
281 | + /* NMI info is reported in the high bits of RPR */ | ||
282 | + if (arm_feature(env, ARM_FEATURE_EL3) && !arm_is_secure(env)) { | ||
283 | + if (cs->icc_apr[GICV3_G1NS][0] & ICC_AP1R_EL1_NMI) { | ||
284 | + prio |= ICC_RPR_EL1_NMI; | ||
285 | + } | ||
286 | + } else { | ||
287 | + if (cs->icc_apr[GICV3_G1NS][0] & ICC_AP1R_EL1_NMI) { | ||
288 | + prio |= ICC_RPR_EL1_NSNMI; | ||
289 | + } | ||
290 | + if (cs->icc_apr[GICV3_G1][0] & ICC_AP1R_EL1_NMI) { | ||
291 | + prio |= ICC_RPR_EL1_NMI; | ||
292 | + } | ||
293 | + } | ||
294 | + } | ||
295 | + | ||
296 | trace_gicv3_icc_rpr_read(gicv3_redist_affid(cs), prio); | ||
297 | return prio; | ||
298 | } | ||
299 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo gicv3_cpuif_icc_apxr23_reginfo[] = { | ||
300 | }, | ||
301 | }; | ||
302 | |||
303 | +static const ARMCPRegInfo gicv3_cpuif_gicv3_nmi_reginfo[] = { | ||
304 | + { .name = "ICC_NMIAR1_EL1", .state = ARM_CP_STATE_BOTH, | ||
305 | + .opc0 = 3, .opc1 = 0, .crn = 12, .crm = 9, .opc2 = 5, | ||
306 | + .type = ARM_CP_IO | ARM_CP_NO_RAW, | ||
307 | + .access = PL1_R, .accessfn = gicv3_irq_access, | ||
308 | + .readfn = icc_nmiar1_read, | ||
309 | + }, | ||
310 | +}; | ||
311 | + | ||
312 | static uint64_t ich_ap_read(CPUARMState *env, const ARMCPRegInfo *ri) | ||
313 | { | ||
314 | GICv3CPUState *cs = icc_cs_from_env(env); | ||
315 | @@ -XXX,XX +XXX,XX @@ void gicv3_init_cpuif(GICv3State *s) | ||
316 | */ | ||
317 | define_arm_cp_regs(cpu, gicv3_cpuif_reginfo); | ||
318 | |||
319 | + /* | ||
320 | + * If the CPU implements FEAT_NMI and FEAT_GICv3 it must also | ||
321 | + * implement FEAT_GICv3_NMI, which is the CPU interface part | ||
322 | + * of NMI support. This is distinct from whether the GIC proper | ||
323 | + * (redistributors and distributor) have NMI support. In QEMU | ||
324 | + * that is a property of the GIC device in s->nmi_support; | ||
325 | + * cs->nmi_support indicates the CPU interface's support. | ||
326 | + */ | ||
327 | + if (cpu_isar_feature(aa64_nmi, cpu)) { | ||
328 | + cs->nmi_support = true; | ||
329 | + define_arm_cp_regs(cpu, gicv3_cpuif_gicv3_nmi_reginfo); | ||
330 | + } | ||
331 | + | ||
332 | /* | ||
333 | * The CPU implementation specifies the number of supported | ||
334 | * bits of physical priority. For backwards compatibility | ||
335 | diff --git a/hw/intc/trace-events b/hw/intc/trace-events | ||
336 | index XXXXXXX..XXXXXXX 100644 | ||
337 | --- a/hw/intc/trace-events | ||
338 | +++ b/hw/intc/trace-events | ||
339 | @@ -XXX,XX +XXX,XX @@ gicv3_cpuif_set_irqs(uint32_t cpuid, int fiqlevel, int irqlevel) "GICv3 CPU i/f | ||
340 | gicv3_icc_generate_sgi(uint32_t cpuid, int irq, int irm, uint32_t aff, uint32_t targetlist) "GICv3 CPU i/f 0x%x generating SGI %d IRM %d target affinity 0x%xxx targetlist 0x%x" | ||
341 | gicv3_icc_iar0_read(uint32_t cpu, uint64_t val) "GICv3 ICC_IAR0 read cpu 0x%x value 0x%" PRIx64 | ||
342 | gicv3_icc_iar1_read(uint32_t cpu, uint64_t val) "GICv3 ICC_IAR1 read cpu 0x%x value 0x%" PRIx64 | ||
343 | +gicv3_icc_nmiar1_read(uint32_t cpu, uint64_t val) "GICv3 ICC_NMIAR1 read cpu 0x%x value 0x%" PRIx64 | ||
344 | gicv3_icc_eoir_write(int grp, uint32_t cpu, uint64_t val) "GICv3 ICC_EOIR%d write cpu 0x%x value 0x%" PRIx64 | ||
345 | gicv3_icc_hppir0_read(uint32_t cpu, uint64_t val) "GICv3 ICC_HPPIR0 read cpu 0x%x value 0x%" PRIx64 | ||
346 | gicv3_icc_hppir1_read(uint32_t cpu, uint64_t val) "GICv3 ICC_HPPIR1 read cpu 0x%x value 0x%" PRIx64 | ||
347 | -- | ||
348 | 2.34.1 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | Implement icv_nmiar1_read() for icc_nmiar1_read(), so add definition for | |
2 | ICH_LR_EL2.NMI and ICH_AP1R_EL2.NMI bit. | ||
3 | |||
4 | If FEAT_GICv3_NMI is supported, ich_ap_write() should consider ICV_AP1R_EL1.NMI | ||
5 | bit. In icv_activate_irq() and icv_eoir_write(), the ICV_AP1R_EL1.NMI bit | ||
6 | should be set or clear according to the Non-maskable property. And the RPR | ||
7 | priority should also update the NMI bit according to the APR priority NMI bit. | ||
8 | |||
9 | By the way, add gicv3_icv_nmiar1_read trace event. | ||
10 | |||
11 | If the hpp irq is a NMI, the icv iar read should return 1022 and trap for | ||
12 | NMI again | ||
13 | |||
14 | Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> | ||
15 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
16 | [PMM: use cs->nmi_support instead of cs->gic->nmi_support] | ||
17 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
18 | Message-id: 20240407081733.3231820-20-ruanjinjie@huawei.com | ||
19 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
20 | --- | ||
21 | hw/intc/gicv3_internal.h | 4 ++ | ||
22 | hw/intc/arm_gicv3_cpuif.c | 105 +++++++++++++++++++++++++++++++++----- | ||
23 | hw/intc/trace-events | 1 + | ||
24 | 3 files changed, 98 insertions(+), 12 deletions(-) | ||
25 | |||
26 | diff --git a/hw/intc/gicv3_internal.h b/hw/intc/gicv3_internal.h | ||
27 | index XXXXXXX..XXXXXXX 100644 | ||
28 | --- a/hw/intc/gicv3_internal.h | ||
29 | +++ b/hw/intc/gicv3_internal.h | ||
30 | @@ -XXX,XX +XXX,XX @@ FIELD(GICR_VPENDBASER, VALID, 63, 1) | ||
31 | #define ICH_LR_EL2_PRIORITY_SHIFT 48 | ||
32 | #define ICH_LR_EL2_PRIORITY_LENGTH 8 | ||
33 | #define ICH_LR_EL2_PRIORITY_MASK (0xffULL << ICH_LR_EL2_PRIORITY_SHIFT) | ||
34 | +#define ICH_LR_EL2_NMI (1ULL << 59) | ||
35 | #define ICH_LR_EL2_GROUP (1ULL << 60) | ||
36 | #define ICH_LR_EL2_HW (1ULL << 61) | ||
37 | #define ICH_LR_EL2_STATE_SHIFT 62 | ||
38 | @@ -XXX,XX +XXX,XX @@ FIELD(GICR_VPENDBASER, VALID, 63, 1) | ||
39 | #define ICH_VTR_EL2_PREBITS_SHIFT 26 | ||
40 | #define ICH_VTR_EL2_PRIBITS_SHIFT 29 | ||
41 | |||
42 | +#define ICV_AP1R_EL1_NMI (1ULL << 63) | ||
43 | +#define ICV_RPR_EL1_NMI (1ULL << 63) | ||
44 | + | ||
45 | /* ITS Registers */ | ||
46 | |||
47 | FIELD(GITS_BASER, SIZE, 0, 8) | ||
48 | diff --git a/hw/intc/arm_gicv3_cpuif.c b/hw/intc/arm_gicv3_cpuif.c | ||
49 | index XXXXXXX..XXXXXXX 100644 | ||
50 | --- a/hw/intc/arm_gicv3_cpuif.c | ||
51 | +++ b/hw/intc/arm_gicv3_cpuif.c | ||
52 | @@ -XXX,XX +XXX,XX @@ static int ich_highest_active_virt_prio(GICv3CPUState *cs) | ||
53 | int i; | ||
54 | int aprmax = ich_num_aprs(cs); | ||
55 | |||
56 | + if (cs->ich_apr[GICV3_G1NS][0] & ICV_AP1R_EL1_NMI) { | ||
57 | + return 0x0; | ||
58 | + } | ||
59 | + | ||
60 | for (i = 0; i < aprmax; i++) { | ||
61 | uint32_t apr = cs->ich_apr[GICV3_G0][i] | | ||
62 | cs->ich_apr[GICV3_G1NS][i]; | ||
63 | @@ -XXX,XX +XXX,XX @@ static int hppvi_index(GICv3CPUState *cs) | ||
64 | * correct behaviour. | ||
65 | */ | ||
66 | int prio = 0xff; | ||
67 | + bool nmi = false; | ||
68 | |||
69 | if (!(cs->ich_vmcr_el2 & (ICH_VMCR_EL2_VENG0 | ICH_VMCR_EL2_VENG1))) { | ||
70 | /* Both groups disabled, definitely nothing to do */ | ||
71 | @@ -XXX,XX +XXX,XX @@ static int hppvi_index(GICv3CPUState *cs) | ||
72 | |||
73 | for (i = 0; i < cs->num_list_regs; i++) { | ||
74 | uint64_t lr = cs->ich_lr_el2[i]; | ||
75 | + bool thisnmi; | ||
76 | int thisprio; | ||
77 | |||
78 | if (ich_lr_state(lr) != ICH_LR_EL2_STATE_PENDING) { | ||
79 | @@ -XXX,XX +XXX,XX @@ static int hppvi_index(GICv3CPUState *cs) | ||
80 | } | ||
81 | } | ||
82 | |||
83 | + thisnmi = lr & ICH_LR_EL2_NMI; | ||
84 | thisprio = ich_lr_prio(lr); | ||
85 | |||
86 | - if (thisprio < prio) { | ||
87 | + if ((thisprio < prio) || ((thisprio == prio) && (thisnmi & (!nmi)))) { | ||
88 | prio = thisprio; | ||
89 | + nmi = thisnmi; | ||
90 | idx = i; | ||
91 | } | ||
92 | } | ||
93 | @@ -XXX,XX +XXX,XX @@ static bool icv_hppi_can_preempt(GICv3CPUState *cs, uint64_t lr) | ||
94 | * equivalent of these checks. | ||
95 | */ | ||
96 | int grp; | ||
97 | + bool is_nmi; | ||
98 | uint32_t mask, prio, rprio, vpmr; | ||
99 | |||
100 | if (!(cs->ich_hcr_el2 & ICH_HCR_EL2_EN)) { | ||
101 | @@ -XXX,XX +XXX,XX @@ static bool icv_hppi_can_preempt(GICv3CPUState *cs, uint64_t lr) | ||
102 | */ | ||
103 | |||
104 | prio = ich_lr_prio(lr); | ||
105 | + is_nmi = lr & ICH_LR_EL2_NMI; | ||
106 | vpmr = extract64(cs->ich_vmcr_el2, ICH_VMCR_EL2_VPMR_SHIFT, | ||
107 | ICH_VMCR_EL2_VPMR_LENGTH); | ||
108 | |||
109 | - if (prio >= vpmr) { | ||
110 | + if (!is_nmi && prio >= vpmr) { | ||
111 | /* Priority mask masks this interrupt */ | ||
112 | return false; | ||
113 | } | ||
114 | @@ -XXX,XX +XXX,XX @@ static bool icv_hppi_can_preempt(GICv3CPUState *cs, uint64_t lr) | ||
115 | return true; | ||
116 | } | ||
117 | |||
118 | + if ((prio & mask) == (rprio & mask) && is_nmi && | ||
119 | + !(cs->ich_apr[GICV3_G1NS][0] & ICV_AP1R_EL1_NMI)) { | ||
120 | + return true; | ||
121 | + } | ||
122 | + | ||
123 | return false; | ||
124 | } | ||
125 | |||
126 | @@ -XXX,XX +XXX,XX @@ static void icv_ap_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
127 | |||
128 | trace_gicv3_icv_ap_write(ri->crm & 1, regno, gicv3_redist_affid(cs), value); | ||
129 | |||
130 | - cs->ich_apr[grp][regno] = value & 0xFFFFFFFFU; | ||
131 | + if (cs->nmi_support) { | ||
132 | + cs->ich_apr[grp][regno] = value & (0xFFFFFFFFU | ICV_AP1R_EL1_NMI); | ||
133 | + } else { | ||
134 | + cs->ich_apr[grp][regno] = value & 0xFFFFFFFFU; | ||
135 | + } | ||
136 | |||
137 | gicv3_cpuif_virt_irq_fiq_update(cs); | ||
138 | return; | ||
139 | @@ -XXX,XX +XXX,XX @@ static void icv_ctlr_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
140 | static uint64_t icv_rpr_read(CPUARMState *env, const ARMCPRegInfo *ri) | ||
141 | { | ||
142 | GICv3CPUState *cs = icc_cs_from_env(env); | ||
143 | - int prio = ich_highest_active_virt_prio(cs); | ||
144 | + uint64_t prio = ich_highest_active_virt_prio(cs); | ||
145 | + | ||
146 | + if (cs->ich_apr[GICV3_G1NS][0] & ICV_AP1R_EL1_NMI) { | ||
147 | + prio |= ICV_RPR_EL1_NMI; | ||
148 | + } | ||
149 | |||
150 | trace_gicv3_icv_rpr_read(gicv3_redist_affid(cs), prio); | ||
151 | return prio; | ||
152 | @@ -XXX,XX +XXX,XX @@ static void icv_activate_irq(GICv3CPUState *cs, int idx, int grp) | ||
153 | */ | ||
154 | uint32_t mask = icv_gprio_mask(cs, grp); | ||
155 | int prio = ich_lr_prio(cs->ich_lr_el2[idx]) & mask; | ||
156 | + bool nmi = cs->ich_lr_el2[idx] & ICH_LR_EL2_NMI; | ||
157 | int aprbit = prio >> (8 - cs->vprebits); | ||
158 | int regno = aprbit / 32; | ||
159 | int regbit = aprbit % 32; | ||
160 | |||
161 | cs->ich_lr_el2[idx] &= ~ICH_LR_EL2_STATE_PENDING_BIT; | ||
162 | cs->ich_lr_el2[idx] |= ICH_LR_EL2_STATE_ACTIVE_BIT; | ||
163 | - cs->ich_apr[grp][regno] |= (1 << regbit); | ||
164 | + | ||
165 | + if (nmi) { | ||
166 | + cs->ich_apr[grp][regno] |= ICV_AP1R_EL1_NMI; | ||
167 | + } else { | ||
168 | + cs->ich_apr[grp][regno] |= (1 << regbit); | ||
169 | + } | ||
170 | } | ||
171 | |||
172 | static void icv_activate_vlpi(GICv3CPUState *cs) | ||
173 | @@ -XXX,XX +XXX,XX @@ static uint64_t icv_iar_read(CPUARMState *env, const ARMCPRegInfo *ri) | ||
174 | int grp = ri->crm == 8 ? GICV3_G0 : GICV3_G1NS; | ||
175 | int idx = hppvi_index(cs); | ||
176 | uint64_t intid = INTID_SPURIOUS; | ||
177 | + int el = arm_current_el(env); | ||
178 | |||
179 | if (idx == HPPVI_INDEX_VLPI) { | ||
180 | if (cs->hppvlpi.grp == grp && icv_hppvlpi_can_preempt(cs)) { | ||
181 | @@ -XXX,XX +XXX,XX @@ static uint64_t icv_iar_read(CPUARMState *env, const ARMCPRegInfo *ri) | ||
182 | } else if (idx >= 0) { | ||
183 | uint64_t lr = cs->ich_lr_el2[idx]; | ||
184 | int thisgrp = (lr & ICH_LR_EL2_GROUP) ? GICV3_G1NS : GICV3_G0; | ||
185 | + bool nmi = env->cp15.sctlr_el[el] & SCTLR_NMI && lr & ICH_LR_EL2_NMI; | ||
186 | |||
187 | if (thisgrp == grp && icv_hppi_can_preempt(cs, lr)) { | ||
188 | intid = ich_lr_vintid(lr); | ||
189 | if (!gicv3_intid_is_special(intid)) { | ||
190 | - icv_activate_irq(cs, idx, grp); | ||
191 | + if (!nmi) { | ||
192 | + icv_activate_irq(cs, idx, grp); | ||
193 | + } else { | ||
194 | + intid = INTID_NMI; | ||
195 | + } | ||
196 | } else { | ||
197 | /* Interrupt goes from Pending to Invalid */ | ||
198 | cs->ich_lr_el2[idx] &= ~ICH_LR_EL2_STATE_PENDING_BIT; | ||
199 | @@ -XXX,XX +XXX,XX @@ static uint64_t icv_iar_read(CPUARMState *env, const ARMCPRegInfo *ri) | ||
200 | |||
201 | static uint64_t icv_nmiar1_read(CPUARMState *env, const ARMCPRegInfo *ri) | ||
202 | { | ||
203 | - /* todo */ | ||
204 | + GICv3CPUState *cs = icc_cs_from_env(env); | ||
205 | + int idx = hppvi_index(cs); | ||
206 | uint64_t intid = INTID_SPURIOUS; | ||
207 | + | ||
208 | + if (idx >= 0 && idx != HPPVI_INDEX_VLPI) { | ||
209 | + uint64_t lr = cs->ich_lr_el2[idx]; | ||
210 | + int thisgrp = (lr & ICH_LR_EL2_GROUP) ? GICV3_G1NS : GICV3_G0; | ||
211 | + | ||
212 | + if ((thisgrp == GICV3_G1NS) && icv_hppi_can_preempt(cs, lr)) { | ||
213 | + intid = ich_lr_vintid(lr); | ||
214 | + if (!gicv3_intid_is_special(intid)) { | ||
215 | + if (lr & ICH_LR_EL2_NMI) { | ||
216 | + icv_activate_irq(cs, idx, GICV3_G1NS); | ||
217 | + } else { | ||
218 | + intid = INTID_SPURIOUS; | ||
219 | + } | ||
220 | + } else { | ||
221 | + /* Interrupt goes from Pending to Invalid */ | ||
222 | + cs->ich_lr_el2[idx] &= ~ICH_LR_EL2_STATE_PENDING_BIT; | ||
223 | + /* | ||
224 | + * We will now return the (bogus) ID from the list register, | ||
225 | + * as per the pseudocode. | ||
226 | + */ | ||
227 | + } | ||
228 | + } | ||
229 | + } | ||
230 | + | ||
231 | + trace_gicv3_icv_nmiar1_read(gicv3_redist_affid(cs), intid); | ||
232 | + | ||
233 | + gicv3_cpuif_virt_update(cs); | ||
234 | + | ||
235 | return intid; | ||
236 | } | ||
237 | |||
238 | @@ -XXX,XX +XXX,XX @@ static void icv_increment_eoicount(GICv3CPUState *cs) | ||
239 | ICH_HCR_EL2_EOICOUNT_LENGTH, eoicount + 1); | ||
240 | } | ||
241 | |||
242 | -static int icv_drop_prio(GICv3CPUState *cs) | ||
243 | +static int icv_drop_prio(GICv3CPUState *cs, bool *nmi) | ||
244 | { | ||
245 | /* Drop the priority of the currently active virtual interrupt | ||
246 | * (favouring group 0 if there is a set active bit at | ||
247 | @@ -XXX,XX +XXX,XX @@ static int icv_drop_prio(GICv3CPUState *cs) | ||
248 | continue; | ||
249 | } | ||
250 | |||
251 | + if (i == 0 && cs->nmi_support && (*papr1 & ICV_AP1R_EL1_NMI)) { | ||
252 | + *papr1 &= (~ICV_AP1R_EL1_NMI); | ||
253 | + *nmi = true; | ||
254 | + return 0xff; | ||
255 | + } | ||
256 | + | ||
257 | /* We can't just use the bit-twiddling hack icc_drop_prio() does | ||
258 | * because we need to return the bit number we cleared so | ||
259 | * it can be compared against the list register's priority field. | ||
260 | @@ -XXX,XX +XXX,XX @@ static void icv_eoir_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
261 | int irq = value & 0xffffff; | ||
262 | int grp = ri->crm == 8 ? GICV3_G0 : GICV3_G1NS; | ||
263 | int idx, dropprio; | ||
264 | + bool nmi = false; | ||
265 | |||
266 | trace_gicv3_icv_eoir_write(ri->crm == 8 ? 0 : 1, | ||
267 | gicv3_redist_affid(cs), value); | ||
268 | @@ -XXX,XX +XXX,XX @@ static void icv_eoir_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
269 | * error checks" (because that lets us avoid scanning the AP | ||
270 | * registers twice). | ||
271 | */ | ||
272 | - dropprio = icv_drop_prio(cs); | ||
273 | - if (dropprio == 0xff) { | ||
274 | + dropprio = icv_drop_prio(cs, &nmi); | ||
275 | + if (dropprio == 0xff && !nmi) { | ||
276 | /* No active interrupt. It is CONSTRAINED UNPREDICTABLE | ||
277 | * whether the list registers are checked in this | ||
278 | * situation; we choose not to. | ||
279 | @@ -XXX,XX +XXX,XX @@ static void icv_eoir_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
280 | uint64_t lr = cs->ich_lr_el2[idx]; | ||
281 | int thisgrp = (lr & ICH_LR_EL2_GROUP) ? GICV3_G1NS : GICV3_G0; | ||
282 | int lr_gprio = ich_lr_prio(lr) & icv_gprio_mask(cs, grp); | ||
283 | + bool thisnmi = lr & ICH_LR_EL2_NMI; | ||
284 | |||
285 | - if (thisgrp == grp && lr_gprio == dropprio) { | ||
286 | + if (thisgrp == grp && (lr_gprio == dropprio || (thisnmi & nmi))) { | ||
287 | if (!icv_eoi_split(env, cs) || irq >= GICV3_LPI_INTID_START) { | ||
288 | /* | ||
289 | * Priority drop and deactivate not split: deactivate irq now. | ||
290 | @@ -XXX,XX +XXX,XX @@ static void ich_ap_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
291 | |||
292 | trace_gicv3_ich_ap_write(ri->crm & 1, regno, gicv3_redist_affid(cs), value); | ||
293 | |||
294 | - cs->ich_apr[grp][regno] = value & 0xFFFFFFFFU; | ||
295 | + if (cs->nmi_support) { | ||
296 | + cs->ich_apr[grp][regno] = value & (0xFFFFFFFFU | ICV_AP1R_EL1_NMI); | ||
297 | + } else { | ||
298 | + cs->ich_apr[grp][regno] = value & 0xFFFFFFFFU; | ||
299 | + } | ||
300 | gicv3_cpuif_virt_irq_fiq_update(cs); | ||
301 | } | ||
302 | |||
303 | @@ -XXX,XX +XXX,XX @@ static void ich_lr_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
304 | 8 - cs->vpribits, 0); | ||
305 | } | ||
306 | |||
307 | + /* Enforce RES0 bit in NMI field when FEAT_GICv3_NMI is not implemented */ | ||
308 | + if (!cs->nmi_support) { | ||
309 | + value &= ~ICH_LR_EL2_NMI; | ||
310 | + } | ||
311 | + | ||
312 | cs->ich_lr_el2[regno] = value; | ||
313 | gicv3_cpuif_virt_update(cs); | ||
314 | } | ||
315 | diff --git a/hw/intc/trace-events b/hw/intc/trace-events | ||
316 | index XXXXXXX..XXXXXXX 100644 | ||
317 | --- a/hw/intc/trace-events | ||
318 | +++ b/hw/intc/trace-events | ||
319 | @@ -XXX,XX +XXX,XX @@ gicv3_icv_rpr_read(uint32_t cpu, uint64_t val) "GICv3 ICV_RPR read cpu 0x%x valu | ||
320 | gicv3_icv_hppir_read(int grp, uint32_t cpu, uint64_t val) "GICv3 ICV_HPPIR%d read cpu 0x%x value 0x%" PRIx64 | ||
321 | gicv3_icv_dir_write(uint32_t cpu, uint64_t val) "GICv3 ICV_DIR write cpu 0x%x value 0x%" PRIx64 | ||
322 | gicv3_icv_iar_read(int grp, uint32_t cpu, uint64_t val) "GICv3 ICV_IAR%d read cpu 0x%x value 0x%" PRIx64 | ||
323 | +gicv3_icv_nmiar1_read(uint32_t cpu, uint64_t val) "GICv3 ICV_NMIAR1 read cpu 0x%x value 0x%" PRIx64 | ||
324 | gicv3_icv_eoir_write(int grp, uint32_t cpu, uint64_t val) "GICv3 ICV_EOIR%d write cpu 0x%x value 0x%" PRIx64 | ||
325 | gicv3_cpuif_virt_update(uint32_t cpuid, int idx, int hppvlpi, int grp, int prio) "GICv3 CPU i/f 0x%x virt HPPI update LR index %d HPPVLPI %d grp %d prio %d" | ||
326 | gicv3_cpuif_virt_set_irqs(uint32_t cpuid, int fiqlevel, int irqlevel) "GICv3 CPU i/f 0x%x virt HPPI update: setting FIQ %d IRQ %d" | ||
327 | -- | ||
328 | 2.34.1 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Jinjie Ruan <ruanjinjie@huawei.com> | ||
1 | 2 | ||
3 | If GICD_CTLR_DS bit is zero and the NMI is non-secure, the NMI priority is | ||
4 | higher than 0x80, otherwise it is higher than 0x0. And save the interrupt | ||
5 | non-maskable property in hppi.nmi to deliver NMI exception. Since both GICR | ||
6 | and GICD can deliver NMI, it is both necessary to check whether the pending | ||
7 | irq is NMI in gicv3_redist_update_noirqset and gicv3_update_noirqset. | ||
8 | |||
9 | Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> | ||
10 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
11 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
12 | Message-id: 20240407081733.3231820-21-ruanjinjie@huawei.com | ||
13 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
14 | --- | ||
15 | hw/intc/arm_gicv3.c | 67 +++++++++++++++++++++++++++++++++----- | ||
16 | hw/intc/arm_gicv3_common.c | 3 ++ | ||
17 | hw/intc/arm_gicv3_redist.c | 3 ++ | ||
18 | 3 files changed, 64 insertions(+), 9 deletions(-) | ||
19 | |||
20 | diff --git a/hw/intc/arm_gicv3.c b/hw/intc/arm_gicv3.c | ||
21 | index XXXXXXX..XXXXXXX 100644 | ||
22 | --- a/hw/intc/arm_gicv3.c | ||
23 | +++ b/hw/intc/arm_gicv3.c | ||
24 | @@ -XXX,XX +XXX,XX @@ | ||
25 | #include "hw/intc/arm_gicv3.h" | ||
26 | #include "gicv3_internal.h" | ||
27 | |||
28 | -static bool irqbetter(GICv3CPUState *cs, int irq, uint8_t prio) | ||
29 | +static bool irqbetter(GICv3CPUState *cs, int irq, uint8_t prio, bool nmi) | ||
30 | { | ||
31 | /* Return true if this IRQ at this priority should take | ||
32 | * precedence over the current recorded highest priority | ||
33 | @@ -XXX,XX +XXX,XX @@ static bool irqbetter(GICv3CPUState *cs, int irq, uint8_t prio) | ||
34 | * is the same as this one (a property which the calling code | ||
35 | * relies on). | ||
36 | */ | ||
37 | - if (prio < cs->hppi.prio) { | ||
38 | - return true; | ||
39 | + if (prio != cs->hppi.prio) { | ||
40 | + return prio < cs->hppi.prio; | ||
41 | } | ||
42 | + | ||
43 | + /* | ||
44 | + * The same priority IRQ with non-maskable property should signal to | ||
45 | + * the CPU as it have the priority higher than the labelled 0x80 or 0x00. | ||
46 | + */ | ||
47 | + if (nmi != cs->hppi.nmi) { | ||
48 | + return nmi; | ||
49 | + } | ||
50 | + | ||
51 | /* If multiple pending interrupts have the same priority then it is an | ||
52 | * IMPDEF choice which of them to signal to the CPU. We choose to | ||
53 | * signal the one with the lowest interrupt number. | ||
54 | */ | ||
55 | - if (prio == cs->hppi.prio && irq <= cs->hppi.irq) { | ||
56 | + if (irq <= cs->hppi.irq) { | ||
57 | return true; | ||
58 | } | ||
59 | return false; | ||
60 | @@ -XXX,XX +XXX,XX @@ static uint32_t gicr_int_pending(GICv3CPUState *cs) | ||
61 | return pend; | ||
62 | } | ||
63 | |||
64 | +static bool gicv3_get_priority(GICv3CPUState *cs, bool is_redist, int irq, | ||
65 | + uint8_t *prio) | ||
66 | +{ | ||
67 | + uint32_t nmi = 0x0; | ||
68 | + | ||
69 | + if (is_redist) { | ||
70 | + nmi = extract32(cs->gicr_inmir0, irq, 1); | ||
71 | + } else { | ||
72 | + nmi = *gic_bmp_ptr32(cs->gic->nmi, irq); | ||
73 | + nmi = nmi & (1 << (irq & 0x1f)); | ||
74 | + } | ||
75 | + | ||
76 | + if (nmi) { | ||
77 | + /* DS = 0 & Non-secure NMI */ | ||
78 | + if (!(cs->gic->gicd_ctlr & GICD_CTLR_DS) && | ||
79 | + ((is_redist && extract32(cs->gicr_igroupr0, irq, 1)) || | ||
80 | + (!is_redist && gicv3_gicd_group_test(cs->gic, irq)))) { | ||
81 | + *prio = 0x80; | ||
82 | + } else { | ||
83 | + *prio = 0x0; | ||
84 | + } | ||
85 | + | ||
86 | + return true; | ||
87 | + } | ||
88 | + | ||
89 | + if (is_redist) { | ||
90 | + *prio = cs->gicr_ipriorityr[irq]; | ||
91 | + } else { | ||
92 | + *prio = cs->gic->gicd_ipriority[irq]; | ||
93 | + } | ||
94 | + | ||
95 | + return false; | ||
96 | +} | ||
97 | + | ||
98 | /* Update the interrupt status after state in a redistributor | ||
99 | * or CPU interface has changed, but don't tell the CPU i/f. | ||
100 | */ | ||
101 | @@ -XXX,XX +XXX,XX @@ static void gicv3_redist_update_noirqset(GICv3CPUState *cs) | ||
102 | uint8_t prio; | ||
103 | int i; | ||
104 | uint32_t pend; | ||
105 | + bool nmi = false; | ||
106 | |||
107 | /* Find out which redistributor interrupts are eligible to be | ||
108 | * signaled to the CPU interface. | ||
109 | @@ -XXX,XX +XXX,XX @@ static void gicv3_redist_update_noirqset(GICv3CPUState *cs) | ||
110 | if (!(pend & (1 << i))) { | ||
111 | continue; | ||
112 | } | ||
113 | - prio = cs->gicr_ipriorityr[i]; | ||
114 | - if (irqbetter(cs, i, prio)) { | ||
115 | + nmi = gicv3_get_priority(cs, true, i, &prio); | ||
116 | + if (irqbetter(cs, i, prio, nmi)) { | ||
117 | cs->hppi.irq = i; | ||
118 | cs->hppi.prio = prio; | ||
119 | + cs->hppi.nmi = nmi; | ||
120 | seenbetter = true; | ||
121 | } | ||
122 | } | ||
123 | @@ -XXX,XX +XXX,XX @@ static void gicv3_redist_update_noirqset(GICv3CPUState *cs) | ||
124 | if ((cs->gicr_ctlr & GICR_CTLR_ENABLE_LPIS) && cs->gic->lpi_enable && | ||
125 | (cs->gic->gicd_ctlr & GICD_CTLR_EN_GRP1NS) && | ||
126 | (cs->hpplpi.prio != 0xff)) { | ||
127 | - if (irqbetter(cs, cs->hpplpi.irq, cs->hpplpi.prio)) { | ||
128 | + if (irqbetter(cs, cs->hpplpi.irq, cs->hpplpi.prio, cs->hpplpi.nmi)) { | ||
129 | cs->hppi.irq = cs->hpplpi.irq; | ||
130 | cs->hppi.prio = cs->hpplpi.prio; | ||
131 | + cs->hppi.nmi = cs->hpplpi.nmi; | ||
132 | cs->hppi.grp = cs->hpplpi.grp; | ||
133 | seenbetter = true; | ||
134 | } | ||
135 | @@ -XXX,XX +XXX,XX @@ static void gicv3_update_noirqset(GICv3State *s, int start, int len) | ||
136 | int i; | ||
137 | uint8_t prio; | ||
138 | uint32_t pend = 0; | ||
139 | + bool nmi = false; | ||
140 | |||
141 | assert(start >= GIC_INTERNAL); | ||
142 | assert(len > 0); | ||
143 | @@ -XXX,XX +XXX,XX @@ static void gicv3_update_noirqset(GICv3State *s, int start, int len) | ||
144 | */ | ||
145 | continue; | ||
146 | } | ||
147 | - prio = s->gicd_ipriority[i]; | ||
148 | - if (irqbetter(cs, i, prio)) { | ||
149 | + nmi = gicv3_get_priority(cs, false, i, &prio); | ||
150 | + if (irqbetter(cs, i, prio, nmi)) { | ||
151 | cs->hppi.irq = i; | ||
152 | cs->hppi.prio = prio; | ||
153 | + cs->hppi.nmi = nmi; | ||
154 | cs->seenbetter = true; | ||
155 | } | ||
156 | } | ||
157 | @@ -XXX,XX +XXX,XX @@ void gicv3_full_update_noirqset(GICv3State *s) | ||
158 | |||
159 | for (i = 0; i < s->num_cpu; i++) { | ||
160 | s->cpu[i].hppi.prio = 0xff; | ||
161 | + s->cpu[i].hppi.nmi = false; | ||
162 | } | ||
163 | |||
164 | /* Note that we can guarantee that these functions will not | ||
165 | diff --git a/hw/intc/arm_gicv3_common.c b/hw/intc/arm_gicv3_common.c | ||
166 | index XXXXXXX..XXXXXXX 100644 | ||
167 | --- a/hw/intc/arm_gicv3_common.c | ||
168 | +++ b/hw/intc/arm_gicv3_common.c | ||
169 | @@ -XXX,XX +XXX,XX @@ static void arm_gicv3_common_reset_hold(Object *obj) | ||
170 | memset(cs->gicr_ipriorityr, 0, sizeof(cs->gicr_ipriorityr)); | ||
171 | |||
172 | cs->hppi.prio = 0xff; | ||
173 | + cs->hppi.nmi = false; | ||
174 | cs->hpplpi.prio = 0xff; | ||
175 | + cs->hpplpi.nmi = false; | ||
176 | cs->hppvlpi.prio = 0xff; | ||
177 | + cs->hppvlpi.nmi = false; | ||
178 | |||
179 | /* State in the CPU interface must *not* be reset here, because it | ||
180 | * is part of the CPU's reset domain, not the GIC device's. | ||
181 | diff --git a/hw/intc/arm_gicv3_redist.c b/hw/intc/arm_gicv3_redist.c | ||
182 | index XXXXXXX..XXXXXXX 100644 | ||
183 | --- a/hw/intc/arm_gicv3_redist.c | ||
184 | +++ b/hw/intc/arm_gicv3_redist.c | ||
185 | @@ -XXX,XX +XXX,XX @@ static void update_for_one_lpi(GICv3CPUState *cs, int irq, | ||
186 | ((prio == hpp->prio) && (irq <= hpp->irq))) { | ||
187 | hpp->irq = irq; | ||
188 | hpp->prio = prio; | ||
189 | + hpp->nmi = false; | ||
190 | /* LPIs and vLPIs are always non-secure Grp1 interrupts */ | ||
191 | hpp->grp = GICV3_G1NS; | ||
192 | } | ||
193 | @@ -XXX,XX +XXX,XX @@ static void update_for_all_lpis(GICv3CPUState *cs, uint64_t ptbase, | ||
194 | int i, bit; | ||
195 | |||
196 | hpp->prio = 0xff; | ||
197 | + hpp->nmi = false; | ||
198 | |||
199 | for (i = GICV3_LPI_INTID_START / 8; i < pendt_size / 8; i++) { | ||
200 | address_space_read(as, ptbase + i, MEMTXATTRS_UNSPECIFIED, &pend, 1); | ||
201 | @@ -XXX,XX +XXX,XX @@ static void gicv3_redist_update_vlpi_only(GICv3CPUState *cs) | ||
202 | |||
203 | if (!FIELD_EX64(cs->gicr_vpendbaser, GICR_VPENDBASER, VALID)) { | ||
204 | cs->hppvlpi.prio = 0xff; | ||
205 | + cs->hppvlpi.nmi = false; | ||
206 | return; | ||
207 | } | ||
208 | |||
209 | -- | ||
210 | 2.34.1 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Jinjie Ruan <ruanjinjie@huawei.com> | ||
1 | 2 | ||
3 | In CPU Interface, if the IRQ has the non-maskable property, report NMI to | ||
4 | the corresponding PE. | ||
5 | |||
6 | Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> | ||
7 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
9 | Message-id: 20240407081733.3231820-22-ruanjinjie@huawei.com | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
11 | --- | ||
12 | hw/intc/arm_gicv3_cpuif.c | 4 ++++ | ||
13 | 1 file changed, 4 insertions(+) | ||
14 | |||
15 | diff --git a/hw/intc/arm_gicv3_cpuif.c b/hw/intc/arm_gicv3_cpuif.c | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/hw/intc/arm_gicv3_cpuif.c | ||
18 | +++ b/hw/intc/arm_gicv3_cpuif.c | ||
19 | @@ -XXX,XX +XXX,XX @@ void gicv3_cpuif_update(GICv3CPUState *cs) | ||
20 | /* Tell the CPU about its highest priority pending interrupt */ | ||
21 | int irqlevel = 0; | ||
22 | int fiqlevel = 0; | ||
23 | + int nmilevel = 0; | ||
24 | ARMCPU *cpu = ARM_CPU(cs->cpu); | ||
25 | CPUARMState *env = &cpu->env; | ||
26 | |||
27 | @@ -XXX,XX +XXX,XX @@ void gicv3_cpuif_update(GICv3CPUState *cs) | ||
28 | |||
29 | if (isfiq) { | ||
30 | fiqlevel = 1; | ||
31 | + } else if (cs->hppi.nmi) { | ||
32 | + nmilevel = 1; | ||
33 | } else { | ||
34 | irqlevel = 1; | ||
35 | } | ||
36 | @@ -XXX,XX +XXX,XX @@ void gicv3_cpuif_update(GICv3CPUState *cs) | ||
37 | |||
38 | qemu_set_irq(cs->parent_fiq, fiqlevel); | ||
39 | qemu_set_irq(cs->parent_irq, irqlevel); | ||
40 | + qemu_set_irq(cs->parent_nmi, nmilevel); | ||
41 | } | ||
42 | |||
43 | static uint64_t icc_pmr_read(CPUARMState *env, const ARMCPRegInfo *ri) | ||
44 | -- | ||
45 | 2.34.1 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Jinjie Ruan <ruanjinjie@huawei.com> | ||
1 | 2 | ||
3 | In vCPU Interface, if the vIRQ has the non-maskable property, report | ||
4 | vINMI to the corresponding vPE. | ||
5 | |||
6 | Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> | ||
7 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
9 | Message-id: 20240407081733.3231820-23-ruanjinjie@huawei.com | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
11 | --- | ||
12 | hw/intc/arm_gicv3_cpuif.c | 14 ++++++++++++-- | ||
13 | 1 file changed, 12 insertions(+), 2 deletions(-) | ||
14 | |||
15 | diff --git a/hw/intc/arm_gicv3_cpuif.c b/hw/intc/arm_gicv3_cpuif.c | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/hw/intc/arm_gicv3_cpuif.c | ||
18 | +++ b/hw/intc/arm_gicv3_cpuif.c | ||
19 | @@ -XXX,XX +XXX,XX @@ void gicv3_cpuif_virt_irq_fiq_update(GICv3CPUState *cs) | ||
20 | int idx; | ||
21 | int irqlevel = 0; | ||
22 | int fiqlevel = 0; | ||
23 | + int nmilevel = 0; | ||
24 | |||
25 | idx = hppvi_index(cs); | ||
26 | trace_gicv3_cpuif_virt_update(gicv3_redist_affid(cs), idx, | ||
27 | @@ -XXX,XX +XXX,XX @@ void gicv3_cpuif_virt_irq_fiq_update(GICv3CPUState *cs) | ||
28 | uint64_t lr = cs->ich_lr_el2[idx]; | ||
29 | |||
30 | if (icv_hppi_can_preempt(cs, lr)) { | ||
31 | - /* Virtual interrupts are simple: G0 are always FIQ, and G1 IRQ */ | ||
32 | + /* | ||
33 | + * Virtual interrupts are simple: G0 are always FIQ, and G1 are | ||
34 | + * IRQ or NMI which depends on the ICH_LR<n>_EL2.NMI to have | ||
35 | + * non-maskable property. | ||
36 | + */ | ||
37 | if (lr & ICH_LR_EL2_GROUP) { | ||
38 | - irqlevel = 1; | ||
39 | + if (lr & ICH_LR_EL2_NMI) { | ||
40 | + nmilevel = 1; | ||
41 | + } else { | ||
42 | + irqlevel = 1; | ||
43 | + } | ||
44 | } else { | ||
45 | fiqlevel = 1; | ||
46 | } | ||
47 | @@ -XXX,XX +XXX,XX @@ void gicv3_cpuif_virt_irq_fiq_update(GICv3CPUState *cs) | ||
48 | trace_gicv3_cpuif_virt_set_irqs(gicv3_redist_affid(cs), fiqlevel, irqlevel); | ||
49 | qemu_set_irq(cs->parent_vfiq, fiqlevel); | ||
50 | qemu_set_irq(cs->parent_virq, irqlevel); | ||
51 | + qemu_set_irq(cs->parent_vnmi, nmilevel); | ||
52 | } | ||
53 | |||
54 | static void gicv3_cpuif_virt_update(GICv3CPUState *cs) | ||
55 | -- | ||
56 | 2.34.1 | diff view generated by jsdifflib |
1 | Enable all FEAT_ECV features on the 'max' CPU. | 1 | From: Jinjie Ruan <ruanjinjie@huawei.com> |
---|---|---|---|
2 | 2 | ||
3 | Enable FEAT_NMI on the 'max' CPU. | ||
4 | |||
5 | Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> | ||
6 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
8 | Message-id: 20240407081733.3231820-24-ruanjinjie@huawei.com | ||
3 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
4 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
5 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | Message-id: 20240301183219.2424889-9-peter.maydell@linaro.org | ||
7 | --- | 10 | --- |
8 | docs/system/arm/emulation.rst | 1 + | 11 | docs/system/arm/emulation.rst | 1 + |
9 | target/arm/tcg/cpu64.c | 1 + | 12 | target/arm/tcg/cpu64.c | 1 + |
10 | 2 files changed, 2 insertions(+) | 13 | 2 files changed, 2 insertions(+) |
11 | 14 | ||
12 | diff --git a/docs/system/arm/emulation.rst b/docs/system/arm/emulation.rst | 15 | diff --git a/docs/system/arm/emulation.rst b/docs/system/arm/emulation.rst |
13 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/docs/system/arm/emulation.rst | 17 | --- a/docs/system/arm/emulation.rst |
15 | +++ b/docs/system/arm/emulation.rst | 18 | +++ b/docs/system/arm/emulation.rst |
16 | @@ -XXX,XX +XXX,XX @@ the following architecture extensions: | 19 | @@ -XXX,XX +XXX,XX @@ the following architecture extensions: |
17 | - FEAT_DotProd (Advanced SIMD dot product instructions) | 20 | - FEAT_MTE (Memory Tagging Extension) |
18 | - FEAT_DoubleFault (Double Fault Extension) | 21 | - FEAT_MTE2 (Memory Tagging Extension) |
19 | - FEAT_E0PD (Preventing EL0 access to halves of address maps) | 22 | - FEAT_MTE3 (MTE Asymmetric Fault Handling) |
20 | +- FEAT_ECV (Enhanced Counter Virtualization) | 23 | +- FEAT_NMI (Non-maskable Interrupt) |
21 | - FEAT_EPAC (Enhanced pointer authentication) | 24 | - FEAT_NV (Nested Virtualization) |
22 | - FEAT_ETS (Enhanced Translation Synchronization) | 25 | - FEAT_NV2 (Enhanced nested virtualization support) |
23 | - FEAT_EVT (Enhanced Virtualization Traps) | 26 | - FEAT_PACIMP (Pointer authentication - IMPLEMENTATION DEFINED algorithm) |
24 | diff --git a/target/arm/tcg/cpu64.c b/target/arm/tcg/cpu64.c | 27 | diff --git a/target/arm/tcg/cpu64.c b/target/arm/tcg/cpu64.c |
25 | index XXXXXXX..XXXXXXX 100644 | 28 | index XXXXXXX..XXXXXXX 100644 |
26 | --- a/target/arm/tcg/cpu64.c | 29 | --- a/target/arm/tcg/cpu64.c |
27 | +++ b/target/arm/tcg/cpu64.c | 30 | +++ b/target/arm/tcg/cpu64.c |
28 | @@ -XXX,XX +XXX,XX @@ void aarch64_max_tcg_initfn(Object *obj) | 31 | @@ -XXX,XX +XXX,XX @@ void aarch64_max_tcg_initfn(Object *obj) |
29 | t = FIELD_DP64(t, ID_AA64MMFR0, TGRAN64_2, 2); /* 64k stage2 supported */ | 32 | t = FIELD_DP64(t, ID_AA64PFR1, RAS_FRAC, 0); /* FEAT_RASv1p1 + FEAT_DoubleFault */ |
30 | t = FIELD_DP64(t, ID_AA64MMFR0, TGRAN4_2, 2); /* 4k stage2 supported */ | 33 | t = FIELD_DP64(t, ID_AA64PFR1, SME, 1); /* FEAT_SME */ |
31 | t = FIELD_DP64(t, ID_AA64MMFR0, FGT, 1); /* FEAT_FGT */ | 34 | t = FIELD_DP64(t, ID_AA64PFR1, CSV2_FRAC, 0); /* FEAT_CSV2_2 */ |
32 | + t = FIELD_DP64(t, ID_AA64MMFR0, ECV, 2); /* FEAT_ECV */ | 35 | + t = FIELD_DP64(t, ID_AA64PFR1, NMI, 1); /* FEAT_NMI */ |
33 | cpu->isar.id_aa64mmfr0 = t; | 36 | cpu->isar.id_aa64pfr1 = t; |
34 | 37 | ||
35 | t = cpu->isar.id_aa64mmfr1; | 38 | t = cpu->isar.id_aa64mmfr0; |
36 | -- | 39 | -- |
37 | 2.34.1 | 40 | 2.34.1 |
38 | |||
39 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Jinjie Ruan <ruanjinjie@huawei.com> | ||
1 | 2 | ||
3 | If the CPU implements FEAT_NMI, then turn on the NMI support in the | ||
4 | GICv3 too. It's permitted to have a configuration with FEAT_NMI in | ||
5 | the CPU (and thus NMI support in the CPU interfaces too) but no NMI | ||
6 | support in the distributor and redistributor, but this isn't a very | ||
7 | useful setup as it's close to having no NMI support at all. | ||
8 | |||
9 | We don't need to gate the enabling of NMI in the GIC behind a | ||
10 | machine version property, because none of our current CPUs | ||
11 | implement FEAT_NMI, and '-cpu max' is not something we maintain | ||
12 | migration compatibility across versions for. So we can always | ||
13 | enable the GIC NMI support when the CPU has it. | ||
14 | |||
15 | Neither hvf nor KVM support NMI in the GIC yet, so we don't enable | ||
16 | it unless we're using TCG. | ||
17 | |||
18 | Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> | ||
19 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
20 | Message-id: 20240407081733.3231820-25-ruanjinjie@huawei.com | ||
21 | [PMM: Update comment and commit message] | ||
22 | Suggested-by: Peter Maydell <peter.maydell@linaro.org> | ||
23 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
24 | --- | ||
25 | hw/arm/virt.c | 19 +++++++++++++++++++ | ||
26 | 1 file changed, 19 insertions(+) | ||
27 | |||
28 | diff --git a/hw/arm/virt.c b/hw/arm/virt.c | ||
29 | index XXXXXXX..XXXXXXX 100644 | ||
30 | --- a/hw/arm/virt.c | ||
31 | +++ b/hw/arm/virt.c | ||
32 | @@ -XXX,XX +XXX,XX @@ static void create_v2m(VirtMachineState *vms) | ||
33 | vms->msi_controller = VIRT_MSI_CTRL_GICV2M; | ||
34 | } | ||
35 | |||
36 | +/* | ||
37 | + * If the CPU has FEAT_NMI, then turn on the NMI support in the GICv3 too. | ||
38 | + * It's permitted to have a configuration with NMI in the CPU (and thus the | ||
39 | + * GICv3 CPU interface) but not in the distributor/redistributors, but it's | ||
40 | + * not very useful. | ||
41 | + */ | ||
42 | +static bool gicv3_nmi_present(VirtMachineState *vms) | ||
43 | +{ | ||
44 | + ARMCPU *cpu = ARM_CPU(qemu_get_cpu(0)); | ||
45 | + | ||
46 | + return tcg_enabled() && cpu_isar_feature(aa64_nmi, cpu) && | ||
47 | + (vms->gic_version != VIRT_GIC_VERSION_2); | ||
48 | +} | ||
49 | + | ||
50 | static void create_gic(VirtMachineState *vms, MemoryRegion *mem) | ||
51 | { | ||
52 | MachineState *ms = MACHINE(vms); | ||
53 | @@ -XXX,XX +XXX,XX @@ static void create_gic(VirtMachineState *vms, MemoryRegion *mem) | ||
54 | vms->virt); | ||
55 | } | ||
56 | } | ||
57 | + | ||
58 | + if (gicv3_nmi_present(vms)) { | ||
59 | + qdev_prop_set_bit(vms->gic, "has-nmi", true); | ||
60 | + } | ||
61 | + | ||
62 | gicbusdev = SYS_BUS_DEVICE(vms->gic); | ||
63 | sysbus_realize_and_unref(gicbusdev, &error_fatal); | ||
64 | sysbus_mmio_map(gicbusdev, 0, vms->memmap[VIRT_GIC_DIST].base); | ||
65 | -- | ||
66 | 2.34.1 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Anastasia Belova <abelova@astralinux.ru> | ||
1 | 2 | ||
3 | In soc_dma_set_request() we try to set a bit in a uint64_t, but we | ||
4 | do it with "1 << ch->num", which can't set any bits past 31; | ||
5 | any use for a channel number of 32 or more would fail due to | ||
6 | integer overflow. | ||
7 | |||
8 | This doesn't happen in practice for our current use of this code, | ||
9 | because the worst case is when we call soc_dma_init() with an | ||
10 | argument of 32 for the number of channels, and QEMU builds with | ||
11 | -fwrapv so the shift into the sign bit is well-defined. However, | ||
12 | it's obviously not the intended behaviour of the code. | ||
13 | |||
14 | Add casts to force the shift to be done as 64-bit arithmetic, | ||
15 | allowing up to 64 channels. | ||
16 | |||
17 | Found by Linux Verification Center (linuxtesting.org) with SVACE. | ||
18 | |||
19 | Fixes: afbb5194d4 ("Handle on-chip DMA controllers in one place, convert OMAP DMA to use it.") | ||
20 | Signed-off-by: Anastasia Belova <abelova@astralinux.ru> | ||
21 | Message-id: 20240409115301.21829-1-abelova@astralinux.ru | ||
22 | [PMM: Edit commit message to clarify that this doesn't actually | ||
23 | bite us in our current usage of this code.] | ||
24 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
25 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
26 | --- | ||
27 | hw/dma/soc_dma.c | 4 ++-- | ||
28 | 1 file changed, 2 insertions(+), 2 deletions(-) | ||
29 | |||
30 | diff --git a/hw/dma/soc_dma.c b/hw/dma/soc_dma.c | ||
31 | index XXXXXXX..XXXXXXX 100644 | ||
32 | --- a/hw/dma/soc_dma.c | ||
33 | +++ b/hw/dma/soc_dma.c | ||
34 | @@ -XXX,XX +XXX,XX @@ void soc_dma_set_request(struct soc_dma_ch_s *ch, int level) | ||
35 | dma->enabled_count += level - ch->enable; | ||
36 | |||
37 | if (level) | ||
38 | - dma->ch_enable_mask |= 1 << ch->num; | ||
39 | + dma->ch_enable_mask |= (uint64_t)1 << ch->num; | ||
40 | else | ||
41 | - dma->ch_enable_mask &= ~(1 << ch->num); | ||
42 | + dma->ch_enable_mask &= ~((uint64_t)1 << ch->num); | ||
43 | |||
44 | if (level != ch->enable) { | ||
45 | soc_dma_ch_freq_update(dma); | ||
46 | -- | ||
47 | 2.34.1 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | Ever since the bFLT format support was added in 2006, there has been | |
2 | a chunk of code in the file guarded by CONFIG_BINFMT_SHARED_FLAT | ||
3 | which is supposedly for shared library support. This is not enabled | ||
4 | and it's not possible to enable it, because if you do you'll run into | ||
5 | the "#error needs checking" in the calc_reloc() function. | ||
6 | |||
7 | Similarly, CONFIG_BINFMT_ZFLAT exists but can't be enabled because of | ||
8 | an "#error code needs checking" in load_flat_file(). | ||
9 | |||
10 | This code is obviously unfinished and has never been used; nobody in | ||
11 | the intervening 18 years has complained about this or fixed it, so | ||
12 | just delete the dead code. If anybody ever wants the feature they | ||
13 | can always pull it out of git, or (perhaps better) write it from | ||
14 | scratch based on the current Linux bFLT loader rather than the one of | ||
15 | 18 years ago. | ||
16 | |||
17 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
18 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
19 | Message-id: 20240411115313.680433-1-peter.maydell@linaro.org | ||
20 | --- | ||
21 | linux-user/flat.h | 5 +- | ||
22 | linux-user/flatload.c | 293 ++---------------------------------------- | ||
23 | 2 files changed, 11 insertions(+), 287 deletions(-) | ||
24 | |||
25 | diff --git a/linux-user/flat.h b/linux-user/flat.h | ||
26 | index XXXXXXX..XXXXXXX 100644 | ||
27 | --- a/linux-user/flat.h | ||
28 | +++ b/linux-user/flat.h | ||
29 | @@ -XXX,XX +XXX,XX @@ | ||
30 | |||
31 | #define FLAT_VERSION 0x00000004L | ||
32 | |||
33 | -#ifdef CONFIG_BINFMT_SHARED_FLAT | ||
34 | -#define MAX_SHARED_LIBS (4) | ||
35 | -#else | ||
36 | +/* QEMU doesn't support bflt shared libraries */ | ||
37 | #define MAX_SHARED_LIBS (1) | ||
38 | -#endif | ||
39 | |||
40 | /* | ||
41 | * To make everything easier to port and manage cross platform | ||
42 | diff --git a/linux-user/flatload.c b/linux-user/flatload.c | ||
43 | index XXXXXXX..XXXXXXX 100644 | ||
44 | --- a/linux-user/flatload.c | ||
45 | +++ b/linux-user/flatload.c | ||
46 | @@ -XXX,XX +XXX,XX @@ | ||
47 | * JAN/99 -- coded full program relocation (gerg@snapgear.com) | ||
48 | */ | ||
49 | |||
50 | -/* ??? ZFLAT and shared library support is currently disabled. */ | ||
51 | - | ||
52 | /****************************************************************************/ | ||
53 | |||
54 | #include "qemu/osdep.h" | ||
55 | @@ -XXX,XX +XXX,XX @@ struct lib_info { | ||
56 | short loaded; /* Has this library been loaded? */ | ||
57 | }; | ||
58 | |||
59 | -#ifdef CONFIG_BINFMT_SHARED_FLAT | ||
60 | -static int load_flat_shared_library(int id, struct lib_info *p); | ||
61 | -#endif | ||
62 | - | ||
63 | struct linux_binprm; | ||
64 | |||
65 | /****************************************************************************/ | ||
66 | @@ -XXX,XX +XXX,XX @@ static int target_pread(int fd, abi_ulong ptr, abi_ulong len, | ||
67 | unlock_user(buf, ptr, len); | ||
68 | return ret; | ||
69 | } | ||
70 | -/****************************************************************************/ | ||
71 | - | ||
72 | -#ifdef CONFIG_BINFMT_ZFLAT | ||
73 | - | ||
74 | -#include <linux/zlib.h> | ||
75 | - | ||
76 | -#define LBUFSIZE 4000 | ||
77 | - | ||
78 | -/* gzip flag byte */ | ||
79 | -#define ASCII_FLAG 0x01 /* bit 0 set: file probably ASCII text */ | ||
80 | -#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */ | ||
81 | -#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */ | ||
82 | -#define ORIG_NAME 0x08 /* bit 3 set: original file name present */ | ||
83 | -#define COMMENT 0x10 /* bit 4 set: file comment present */ | ||
84 | -#define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */ | ||
85 | -#define RESERVED 0xC0 /* bit 6,7: reserved */ | ||
86 | - | ||
87 | -static int decompress_exec( | ||
88 | - struct linux_binprm *bprm, | ||
89 | - unsigned long offset, | ||
90 | - char *dst, | ||
91 | - long len, | ||
92 | - int fd) | ||
93 | -{ | ||
94 | - unsigned char *buf; | ||
95 | - z_stream strm; | ||
96 | - loff_t fpos; | ||
97 | - int ret, retval; | ||
98 | - | ||
99 | - DBG_FLT("decompress_exec(offset=%x,buf=%x,len=%x)\n",(int)offset, (int)dst, (int)len); | ||
100 | - | ||
101 | - memset(&strm, 0, sizeof(strm)); | ||
102 | - strm.workspace = kmalloc(zlib_inflate_workspacesize(), GFP_KERNEL); | ||
103 | - if (strm.workspace == NULL) { | ||
104 | - DBG_FLT("binfmt_flat: no memory for decompress workspace\n"); | ||
105 | - return -ENOMEM; | ||
106 | - } | ||
107 | - buf = kmalloc(LBUFSIZE, GFP_KERNEL); | ||
108 | - if (buf == NULL) { | ||
109 | - DBG_FLT("binfmt_flat: no memory for read buffer\n"); | ||
110 | - retval = -ENOMEM; | ||
111 | - goto out_free; | ||
112 | - } | ||
113 | - | ||
114 | - /* Read in first chunk of data and parse gzip header. */ | ||
115 | - fpos = offset; | ||
116 | - ret = bprm->file->f_op->read(bprm->file, buf, LBUFSIZE, &fpos); | ||
117 | - | ||
118 | - strm.next_in = buf; | ||
119 | - strm.avail_in = ret; | ||
120 | - strm.total_in = 0; | ||
121 | - | ||
122 | - retval = -ENOEXEC; | ||
123 | - | ||
124 | - /* Check minimum size -- gzip header */ | ||
125 | - if (ret < 10) { | ||
126 | - DBG_FLT("binfmt_flat: file too small?\n"); | ||
127 | - goto out_free_buf; | ||
128 | - } | ||
129 | - | ||
130 | - /* Check gzip magic number */ | ||
131 | - if ((buf[0] != 037) || ((buf[1] != 0213) && (buf[1] != 0236))) { | ||
132 | - DBG_FLT("binfmt_flat: unknown compression magic?\n"); | ||
133 | - goto out_free_buf; | ||
134 | - } | ||
135 | - | ||
136 | - /* Check gzip method */ | ||
137 | - if (buf[2] != 8) { | ||
138 | - DBG_FLT("binfmt_flat: unknown compression method?\n"); | ||
139 | - goto out_free_buf; | ||
140 | - } | ||
141 | - /* Check gzip flags */ | ||
142 | - if ((buf[3] & ENCRYPTED) || (buf[3] & CONTINUATION) || | ||
143 | - (buf[3] & RESERVED)) { | ||
144 | - DBG_FLT("binfmt_flat: unknown flags?\n"); | ||
145 | - goto out_free_buf; | ||
146 | - } | ||
147 | - | ||
148 | - ret = 10; | ||
149 | - if (buf[3] & EXTRA_FIELD) { | ||
150 | - ret += 2 + buf[10] + (buf[11] << 8); | ||
151 | - if (unlikely(LBUFSIZE == ret)) { | ||
152 | - DBG_FLT("binfmt_flat: buffer overflow (EXTRA)?\n"); | ||
153 | - goto out_free_buf; | ||
154 | - } | ||
155 | - } | ||
156 | - if (buf[3] & ORIG_NAME) { | ||
157 | - for (; ret < LBUFSIZE && (buf[ret] != 0); ret++) | ||
158 | - ; | ||
159 | - if (unlikely(LBUFSIZE == ret)) { | ||
160 | - DBG_FLT("binfmt_flat: buffer overflow (ORIG_NAME)?\n"); | ||
161 | - goto out_free_buf; | ||
162 | - } | ||
163 | - } | ||
164 | - if (buf[3] & COMMENT) { | ||
165 | - for (; ret < LBUFSIZE && (buf[ret] != 0); ret++) | ||
166 | - ; | ||
167 | - if (unlikely(LBUFSIZE == ret)) { | ||
168 | - DBG_FLT("binfmt_flat: buffer overflow (COMMENT)?\n"); | ||
169 | - goto out_free_buf; | ||
170 | - } | ||
171 | - } | ||
172 | - | ||
173 | - strm.next_in += ret; | ||
174 | - strm.avail_in -= ret; | ||
175 | - | ||
176 | - strm.next_out = dst; | ||
177 | - strm.avail_out = len; | ||
178 | - strm.total_out = 0; | ||
179 | - | ||
180 | - if (zlib_inflateInit2(&strm, -MAX_WBITS) != Z_OK) { | ||
181 | - DBG_FLT("binfmt_flat: zlib init failed?\n"); | ||
182 | - goto out_free_buf; | ||
183 | - } | ||
184 | - | ||
185 | - while ((ret = zlib_inflate(&strm, Z_NO_FLUSH)) == Z_OK) { | ||
186 | - ret = bprm->file->f_op->read(bprm->file, buf, LBUFSIZE, &fpos); | ||
187 | - if (ret <= 0) | ||
188 | - break; | ||
189 | - if (is_error(ret)) { | ||
190 | - break; | ||
191 | - } | ||
192 | - len -= ret; | ||
193 | - | ||
194 | - strm.next_in = buf; | ||
195 | - strm.avail_in = ret; | ||
196 | - strm.total_in = 0; | ||
197 | - } | ||
198 | - | ||
199 | - if (ret < 0) { | ||
200 | - DBG_FLT("binfmt_flat: decompression failed (%d), %s\n", | ||
201 | - ret, strm.msg); | ||
202 | - goto out_zlib; | ||
203 | - } | ||
204 | - | ||
205 | - retval = 0; | ||
206 | -out_zlib: | ||
207 | - zlib_inflateEnd(&strm); | ||
208 | -out_free_buf: | ||
209 | - kfree(buf); | ||
210 | -out_free: | ||
211 | - kfree(strm.workspace); | ||
212 | -out: | ||
213 | - return retval; | ||
214 | -} | ||
215 | - | ||
216 | -#endif /* CONFIG_BINFMT_ZFLAT */ | ||
217 | |||
218 | /****************************************************************************/ | ||
219 | |||
220 | @@ -XXX,XX +XXX,XX @@ calc_reloc(abi_ulong r, struct lib_info *p, int curid, int internalp) | ||
221 | abi_ulong text_len; | ||
222 | abi_ulong start_code; | ||
223 | |||
224 | -#ifdef CONFIG_BINFMT_SHARED_FLAT | ||
225 | -#error needs checking | ||
226 | - if (r == 0) | ||
227 | - id = curid; /* Relocs of 0 are always self referring */ | ||
228 | - else { | ||
229 | - id = (r >> 24) & 0xff; /* Find ID for this reloc */ | ||
230 | - r &= 0x00ffffff; /* Trim ID off here */ | ||
231 | - } | ||
232 | - if (id >= MAX_SHARED_LIBS) { | ||
233 | - fprintf(stderr, "BINFMT_FLAT: reference 0x%x to shared library %d\n", | ||
234 | - (unsigned) r, id); | ||
235 | - goto failed; | ||
236 | - } | ||
237 | - if (curid != id) { | ||
238 | - if (internalp) { | ||
239 | - fprintf(stderr, "BINFMT_FLAT: reloc address 0x%x not " | ||
240 | - "in same module (%d != %d)\n", | ||
241 | - (unsigned) r, curid, id); | ||
242 | - goto failed; | ||
243 | - } else if (!p[id].loaded && is_error(load_flat_shared_library(id, p))) { | ||
244 | - fprintf(stderr, "BINFMT_FLAT: failed to load library %d\n", id); | ||
245 | - goto failed; | ||
246 | - } | ||
247 | - /* Check versioning information (i.e. time stamps) */ | ||
248 | - if (p[id].build_date && p[curid].build_date | ||
249 | - && p[curid].build_date < p[id].build_date) { | ||
250 | - fprintf(stderr, "BINFMT_FLAT: library %d is younger than %d\n", | ||
251 | - id, curid); | ||
252 | - goto failed; | ||
253 | - } | ||
254 | - } | ||
255 | -#else | ||
256 | id = 0; | ||
257 | -#endif | ||
258 | |||
259 | start_brk = p[id].start_brk; | ||
260 | start_data = p[id].start_data; | ||
261 | @@ -XXX,XX +XXX,XX @@ static int load_flat_file(struct linux_binprm * bprm, | ||
262 | if (rev == OLD_FLAT_VERSION && flat_old_ram_flag(flags)) | ||
263 | flags = FLAT_FLAG_RAM; | ||
264 | |||
265 | -#ifndef CONFIG_BINFMT_ZFLAT | ||
266 | if (flags & (FLAT_FLAG_GZIP|FLAT_FLAG_GZDATA)) { | ||
267 | - fprintf(stderr, "Support for ZFLAT executables is not enabled\n"); | ||
268 | + fprintf(stderr, "ZFLAT executables are not supported\n"); | ||
269 | return -ENOEXEC; | ||
270 | } | ||
271 | -#endif | ||
272 | |||
273 | /* | ||
274 | * calculate the extra space we need to map in | ||
275 | @@ -XXX,XX +XXX,XX @@ static int load_flat_file(struct linux_binprm * bprm, | ||
276 | (int)(data_len + bss_len + stack_len), (int)datapos); | ||
277 | |||
278 | fpos = ntohl(hdr->data_start); | ||
279 | -#ifdef CONFIG_BINFMT_ZFLAT | ||
280 | - if (flags & FLAT_FLAG_GZDATA) { | ||
281 | - result = decompress_exec(bprm, fpos, (char *) datapos, | ||
282 | - data_len + (relocs * sizeof(abi_ulong))) | ||
283 | - } else | ||
284 | -#endif | ||
285 | - { | ||
286 | - result = target_pread(bprm->src.fd, datapos, | ||
287 | - data_len + (relocs * sizeof(abi_ulong)), | ||
288 | - fpos); | ||
289 | - } | ||
290 | + result = target_pread(bprm->src.fd, datapos, | ||
291 | + data_len + (relocs * sizeof(abi_ulong)), | ||
292 | + fpos); | ||
293 | if (result < 0) { | ||
294 | fprintf(stderr, "Unable to read data+bss\n"); | ||
295 | return result; | ||
296 | @@ -XXX,XX +XXX,XX @@ static int load_flat_file(struct linux_binprm * bprm, | ||
297 | datapos = realdatastart + indx_len; | ||
298 | reloc = (textpos + ntohl(hdr->reloc_start) + indx_len); | ||
299 | |||
300 | -#ifdef CONFIG_BINFMT_ZFLAT | ||
301 | -#error code needs checking | ||
302 | - /* | ||
303 | - * load it all in and treat it like a RAM load from now on | ||
304 | - */ | ||
305 | - if (flags & FLAT_FLAG_GZIP) { | ||
306 | - result = decompress_exec(bprm, sizeof (struct flat_hdr), | ||
307 | - (((char *) textpos) + sizeof (struct flat_hdr)), | ||
308 | - (text_len + data_len + (relocs * sizeof(unsigned long)) | ||
309 | - - sizeof (struct flat_hdr)), | ||
310 | - 0); | ||
311 | - memmove((void *) datapos, (void *) realdatastart, | ||
312 | - data_len + (relocs * sizeof(unsigned long))); | ||
313 | - } else if (flags & FLAT_FLAG_GZDATA) { | ||
314 | - fpos = 0; | ||
315 | - result = bprm->file->f_op->read(bprm->file, | ||
316 | - (char *) textpos, text_len, &fpos); | ||
317 | - if (!is_error(result)) { | ||
318 | - result = decompress_exec(bprm, text_len, (char *) datapos, | ||
319 | - data_len + (relocs * sizeof(unsigned long)), 0); | ||
320 | - } | ||
321 | - } | ||
322 | - else | ||
323 | -#endif | ||
324 | - { | ||
325 | - result = target_pread(bprm->src.fd, textpos, | ||
326 | - text_len, 0); | ||
327 | - if (result >= 0) { | ||
328 | - result = target_pread(bprm->src.fd, datapos, | ||
329 | - data_len + (relocs * sizeof(abi_ulong)), | ||
330 | - ntohl(hdr->data_start)); | ||
331 | - } | ||
332 | + result = target_pread(bprm->src.fd, textpos, | ||
333 | + text_len, 0); | ||
334 | + if (result >= 0) { | ||
335 | + result = target_pread(bprm->src.fd, datapos, | ||
336 | + data_len + (relocs * sizeof(abi_ulong)), | ||
337 | + ntohl(hdr->data_start)); | ||
338 | } | ||
339 | if (result < 0) { | ||
340 | fprintf(stderr, "Unable to read code+data+bss\n"); | ||
341 | @@ -XXX,XX +XXX,XX @@ static int load_flat_file(struct linux_binprm * bprm, | ||
342 | |||
343 | |||
344 | /****************************************************************************/ | ||
345 | -#ifdef CONFIG_BINFMT_SHARED_FLAT | ||
346 | - | ||
347 | -/* | ||
348 | - * Load a shared library into memory. The library gets its own data | ||
349 | - * segment (including bss) but not argv/argc/environ. | ||
350 | - */ | ||
351 | - | ||
352 | -static int load_flat_shared_library(int id, struct lib_info *libs) | ||
353 | -{ | ||
354 | - struct linux_binprm bprm; | ||
355 | - int res; | ||
356 | - char buf[16]; | ||
357 | - | ||
358 | - /* Create the file name */ | ||
359 | - sprintf(buf, "/lib/lib%d.so", id); | ||
360 | - | ||
361 | - /* Open the file up */ | ||
362 | - bprm.filename = buf; | ||
363 | - bprm.file = open_exec(bprm.filename); | ||
364 | - res = PTR_ERR(bprm.file); | ||
365 | - if (IS_ERR(bprm.file)) | ||
366 | - return res; | ||
367 | - | ||
368 | - res = prepare_binprm(&bprm); | ||
369 | - | ||
370 | - if (!is_error(res)) { | ||
371 | - res = load_flat_file(&bprm, libs, id, NULL); | ||
372 | - } | ||
373 | - if (bprm.file) { | ||
374 | - allow_write_access(bprm.file); | ||
375 | - fput(bprm.file); | ||
376 | - bprm.file = NULL; | ||
377 | - } | ||
378 | - return(res); | ||
379 | -} | ||
380 | - | ||
381 | -#endif /* CONFIG_BINFMT_SHARED_FLAT */ | ||
382 | - | ||
383 | int load_flt_binary(struct linux_binprm *bprm, struct image_info *info) | ||
384 | { | ||
385 | struct lib_info libinfo[MAX_SHARED_LIBS]; | ||
386 | @@ -XXX,XX +XXX,XX @@ int load_flt_binary(struct linux_binprm *bprm, struct image_info *info) | ||
387 | */ | ||
388 | start_addr = libinfo[0].entry; | ||
389 | |||
390 | -#ifdef CONFIG_BINFMT_SHARED_FLAT | ||
391 | -#error here | ||
392 | - for (i = MAX_SHARED_LIBS-1; i>0; i--) { | ||
393 | - if (libinfo[i].loaded) { | ||
394 | - /* Push previous first to call address */ | ||
395 | - --sp; | ||
396 | - if (put_user_ual(start_addr, sp)) | ||
397 | - return -EFAULT; | ||
398 | - start_addr = libinfo[i].entry; | ||
399 | - } | ||
400 | - } | ||
401 | -#endif | ||
402 | - | ||
403 | /* Stash our initial stack pointer into the mm structure */ | ||
404 | info->start_code = libinfo[0].start_code; | ||
405 | info->end_code = libinfo[0].start_code + libinfo[0].text_len; | ||
406 | -- | ||
407 | 2.34.1 | ||
408 | |||
409 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | The npcm7xx_clk and npcm7xx_gcr device reset methods look at | ||
2 | the ResetType argument and only handle RESET_TYPE_COLD, | ||
3 | producing a warning if another reset type is passed. This | ||
4 | is different from how every other three-phase-reset method | ||
5 | we have works, and makes it difficult to add new reset types. | ||
1 | 6 | ||
7 | A better pattern is "assume that any reset type you don't know | ||
8 | about should be handled like RESET_TYPE_COLD"; switch these | ||
9 | devices to do that. Then adding a new reset type will only | ||
10 | need to touch those devices where its behaviour really needs | ||
11 | to be different from the standard cold reset. | ||
12 | |||
13 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
14 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
15 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
16 | Reviewed-by: Luc Michel <luc.michel@amd.com> | ||
17 | Message-id: 20240412160809.1260625-2-peter.maydell@linaro.org | ||
18 | --- | ||
19 | hw/misc/npcm7xx_clk.c | 13 +++---------- | ||
20 | hw/misc/npcm7xx_gcr.c | 12 ++++-------- | ||
21 | 2 files changed, 7 insertions(+), 18 deletions(-) | ||
22 | |||
23 | diff --git a/hw/misc/npcm7xx_clk.c b/hw/misc/npcm7xx_clk.c | ||
24 | index XXXXXXX..XXXXXXX 100644 | ||
25 | --- a/hw/misc/npcm7xx_clk.c | ||
26 | +++ b/hw/misc/npcm7xx_clk.c | ||
27 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_clk_enter_reset(Object *obj, ResetType type) | ||
28 | |||
29 | QEMU_BUILD_BUG_ON(sizeof(s->regs) != sizeof(cold_reset_values)); | ||
30 | |||
31 | - switch (type) { | ||
32 | - case RESET_TYPE_COLD: | ||
33 | - memcpy(s->regs, cold_reset_values, sizeof(cold_reset_values)); | ||
34 | - s->ref_ns = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); | ||
35 | - npcm7xx_clk_update_all_clocks(s); | ||
36 | - return; | ||
37 | - } | ||
38 | - | ||
39 | + memcpy(s->regs, cold_reset_values, sizeof(cold_reset_values)); | ||
40 | + s->ref_ns = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); | ||
41 | + npcm7xx_clk_update_all_clocks(s); | ||
42 | /* | ||
43 | * A small number of registers need to be reset on a core domain reset, | ||
44 | * but no such reset type exists yet. | ||
45 | */ | ||
46 | - qemu_log_mask(LOG_UNIMP, "%s: reset type %d not implemented.", | ||
47 | - __func__, type); | ||
48 | } | ||
49 | |||
50 | static void npcm7xx_clk_init_clock_hierarchy(NPCM7xxCLKState *s) | ||
51 | diff --git a/hw/misc/npcm7xx_gcr.c b/hw/misc/npcm7xx_gcr.c | ||
52 | index XXXXXXX..XXXXXXX 100644 | ||
53 | --- a/hw/misc/npcm7xx_gcr.c | ||
54 | +++ b/hw/misc/npcm7xx_gcr.c | ||
55 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_gcr_enter_reset(Object *obj, ResetType type) | ||
56 | |||
57 | QEMU_BUILD_BUG_ON(sizeof(s->regs) != sizeof(cold_reset_values)); | ||
58 | |||
59 | - switch (type) { | ||
60 | - case RESET_TYPE_COLD: | ||
61 | - memcpy(s->regs, cold_reset_values, sizeof(s->regs)); | ||
62 | - s->regs[NPCM7XX_GCR_PWRON] = s->reset_pwron; | ||
63 | - s->regs[NPCM7XX_GCR_MDLR] = s->reset_mdlr; | ||
64 | - s->regs[NPCM7XX_GCR_INTCR3] = s->reset_intcr3; | ||
65 | - break; | ||
66 | - } | ||
67 | + memcpy(s->regs, cold_reset_values, sizeof(s->regs)); | ||
68 | + s->regs[NPCM7XX_GCR_PWRON] = s->reset_pwron; | ||
69 | + s->regs[NPCM7XX_GCR_MDLR] = s->reset_mdlr; | ||
70 | + s->regs[NPCM7XX_GCR_INTCR3] = s->reset_intcr3; | ||
71 | } | ||
72 | |||
73 | static void npcm7xx_gcr_realize(DeviceState *dev, Error **errp) | ||
74 | -- | ||
75 | 2.34.1 | ||
76 | |||
77 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Rather than directly calling the device's implementation of its 'hold' | ||
2 | reset phase, call device_cold_reset(). This means we don't have to | ||
3 | adjust this callsite when we add another argument to the function | ||
4 | signature for the hold and exit reset methods. | ||
1 | 5 | ||
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
7 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Reviewed-by: Luc Michel <luc.michel@amd.com> | ||
9 | Message-id: 20240412160809.1260625-3-peter.maydell@linaro.org | ||
10 | --- | ||
11 | hw/i2c/allwinner-i2c.c | 3 +-- | ||
12 | hw/sensor/adm1272.c | 2 +- | ||
13 | 2 files changed, 2 insertions(+), 3 deletions(-) | ||
14 | |||
15 | diff --git a/hw/i2c/allwinner-i2c.c b/hw/i2c/allwinner-i2c.c | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/hw/i2c/allwinner-i2c.c | ||
18 | +++ b/hw/i2c/allwinner-i2c.c | ||
19 | @@ -XXX,XX +XXX,XX @@ static void allwinner_i2c_write(void *opaque, hwaddr offset, | ||
20 | break; | ||
21 | case TWI_SRST_REG: | ||
22 | if (((value & TWI_SRST_MASK) == 0) && (s->srst & TWI_SRST_MASK)) { | ||
23 | - /* Perform reset */ | ||
24 | - allwinner_i2c_reset_hold(OBJECT(s)); | ||
25 | + device_cold_reset(DEVICE(s)); | ||
26 | } | ||
27 | s->srst = value & TWI_SRST_MASK; | ||
28 | break; | ||
29 | diff --git a/hw/sensor/adm1272.c b/hw/sensor/adm1272.c | ||
30 | index XXXXXXX..XXXXXXX 100644 | ||
31 | --- a/hw/sensor/adm1272.c | ||
32 | +++ b/hw/sensor/adm1272.c | ||
33 | @@ -XXX,XX +XXX,XX @@ static int adm1272_write_data(PMBusDevice *pmdev, const uint8_t *buf, | ||
34 | break; | ||
35 | |||
36 | case ADM1272_MFR_POWER_CYCLE: | ||
37 | - adm1272_exit_reset((Object *)s); | ||
38 | + device_cold_reset(DEVICE(s)); | ||
39 | break; | ||
40 | |||
41 | case ADM1272_HYSTERESIS_LOW: | ||
42 | -- | ||
43 | 2.34.1 | diff view generated by jsdifflib |
1 | From: Thomas Huth <thuth@redhat.com> | 1 | We pass a ResetType argument to the Resettable class enter phase |
---|---|---|---|
2 | method, but we don't pass it to hold and exit, even though the | ||
3 | callsites have it readily available. This means that if a device | ||
4 | cared about the ResetType it would need to record it in the enter | ||
5 | phase method to use later on. We should pass the type to all three | ||
6 | of the phase methods to avoid having to do that. | ||
2 | 7 | ||
3 | Move the code to a separate file so that we do not have to compile | 8 | This coccinelle script adds the ResetType argument to the hold and |
4 | it anymore if CONFIG_ARM_V7M is not set. | 9 | exit phases of the Resettable interface. |
5 | 10 | ||
6 | Signed-off-by: Thomas Huth <thuth@redhat.com> | 11 | The first part of the script (rules holdfn_assigned, holdfn_defined, |
7 | Message-id: 20240308141051.536599-2-thuth@redhat.com | 12 | exitfn_assigned, exitfn_defined) update implementations of the |
8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 13 | interface within device models, both to change the signature of their |
14 | method implementations and to pass on the reset type when they invoke | ||
15 | reset on some other device. | ||
16 | |||
17 | The second part of the script is various special cases: | ||
18 | * method callsites in resettable_phase_hold(), resettable_phase_exit() | ||
19 | and device_phases_reset() | ||
20 | * updating the typedefs for the methods | ||
21 | * isl_pmbus_vr.c has some code where one device's reset method directly | ||
22 | calls the implementation of a different device's method | ||
23 | |||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 24 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
25 | Reviewed-by: Luc Michel <luc.michel@amd.com> | ||
26 | Message-id: 20240412160809.1260625-4-peter.maydell@linaro.org | ||
10 | --- | 27 | --- |
11 | target/arm/tcg/cpu-v7m.c | 290 +++++++++++++++++++++++++++++++++++++ | 28 | scripts/coccinelle/reset-type.cocci | 133 ++++++++++++++++++++++++++++ |
12 | target/arm/tcg/cpu32.c | 261 --------------------------------- | 29 | 1 file changed, 133 insertions(+) |
13 | target/arm/meson.build | 3 + | 30 | create mode 100644 scripts/coccinelle/reset-type.cocci |
14 | target/arm/tcg/meson.build | 3 + | ||
15 | 4 files changed, 296 insertions(+), 261 deletions(-) | ||
16 | create mode 100644 target/arm/tcg/cpu-v7m.c | ||
17 | 31 | ||
18 | diff --git a/target/arm/tcg/cpu-v7m.c b/target/arm/tcg/cpu-v7m.c | 32 | diff --git a/scripts/coccinelle/reset-type.cocci b/scripts/coccinelle/reset-type.cocci |
19 | new file mode 100644 | 33 | new file mode 100644 |
20 | index XXXXXXX..XXXXXXX | 34 | index XXXXXXX..XXXXXXX |
21 | --- /dev/null | 35 | --- /dev/null |
22 | +++ b/target/arm/tcg/cpu-v7m.c | 36 | +++ b/scripts/coccinelle/reset-type.cocci |
23 | @@ -XXX,XX +XXX,XX @@ | 37 | @@ -XXX,XX +XXX,XX @@ |
24 | +/* | 38 | +// Convert device code using three-phase reset to add a ResetType |
25 | + * QEMU ARMv7-M TCG-only CPUs. | 39 | +// argument to implementations of ResettableHoldPhase and |
26 | + * | 40 | +// ResettableEnterPhase methods. |
27 | + * Copyright (c) 2012 SUSE LINUX Products GmbH | 41 | +// |
28 | + * | 42 | +// Copyright Linaro Ltd 2024 |
29 | + * This code is licensed under the GNU GPL v2 or later. | 43 | +// SPDX-License-Identifier: GPL-2.0-or-later |
30 | + * | 44 | +// |
31 | + * SPDX-License-Identifier: GPL-2.0-or-later | 45 | +// for dir in include hw target; do \ |
32 | + */ | 46 | +// spatch --macro-file scripts/cocci-macro-file.h \ |
47 | +// --sp-file scripts/coccinelle/reset-type.cocci \ | ||
48 | +// --keep-comments --smpl-spacing --in-place --include-headers \ | ||
49 | +// --dir $dir; done | ||
50 | +// | ||
51 | +// This coccinelle script aims to produce a complete change that needs | ||
52 | +// no human interaction, so as well as the generic "update device | ||
53 | +// implementations of the hold and exit phase methods" it includes | ||
54 | +// the special-case transformations needed for the core code and for | ||
55 | +// one device model that does something a bit nonstandard. Those | ||
56 | +// special cases are at the end of the file. | ||
33 | + | 57 | + |
34 | +#include "qemu/osdep.h" | 58 | +// Look for where we use a function as a ResettableHoldPhase method, |
35 | +#include "cpu.h" | 59 | +// either by directly assigning it to phases.hold or by calling |
36 | +#include "hw/core/tcg-cpu-ops.h" | 60 | +// resettable_class_set_parent_phases, and remember the function name. |
37 | +#include "internals.h" | 61 | +@ holdfn_assigned @ |
62 | +identifier enterfn, holdfn, exitfn; | ||
63 | +identifier rc; | ||
64 | +expression e; | ||
65 | +@@ | ||
66 | +ResettableClass *rc; | ||
67 | +... | ||
68 | +( | ||
69 | + rc->phases.hold = holdfn; | ||
70 | +| | ||
71 | + resettable_class_set_parent_phases(rc, enterfn, holdfn, exitfn, e); | ||
72 | +) | ||
38 | + | 73 | + |
39 | +#if !defined(CONFIG_USER_ONLY) | 74 | +// Look for the definition of the function we found in holdfn_assigned, |
40 | + | 75 | +// and add the new argument. If the function calls a hold function |
41 | +#include "hw/intc/armv7m_nvic.h" | 76 | +// itself (probably chaining to the parent class reset) then add the |
42 | + | 77 | +// new argument there too. |
43 | +static bool arm_v7m_cpu_exec_interrupt(CPUState *cs, int interrupt_request) | 78 | +@ holdfn_defined @ |
79 | +identifier holdfn_assigned.holdfn; | ||
80 | +typedef Object; | ||
81 | +identifier obj; | ||
82 | +expression parent; | ||
83 | +@@ | ||
84 | +-holdfn(Object *obj) | ||
85 | ++holdfn(Object *obj, ResetType type) | ||
44 | +{ | 86 | +{ |
45 | + CPUClass *cc = CPU_GET_CLASS(cs); | 87 | + <... |
46 | + ARMCPU *cpu = ARM_CPU(cs); | 88 | +- parent.hold(obj) |
47 | + CPUARMState *env = &cpu->env; | 89 | ++ parent.hold(obj, type) |
48 | + bool ret = false; | 90 | + ...> |
49 | + | ||
50 | + /* | ||
51 | + * ARMv7-M interrupt masking works differently than -A or -R. | ||
52 | + * There is no FIQ/IRQ distinction. Instead of I and F bits | ||
53 | + * masking FIQ and IRQ interrupts, an exception is taken only | ||
54 | + * if it is higher priority than the current execution priority | ||
55 | + * (which depends on state like BASEPRI, FAULTMASK and the | ||
56 | + * currently active exception). | ||
57 | + */ | ||
58 | + if (interrupt_request & CPU_INTERRUPT_HARD | ||
59 | + && (armv7m_nvic_can_take_pending_exception(env->nvic))) { | ||
60 | + cs->exception_index = EXCP_IRQ; | ||
61 | + cc->tcg_ops->do_interrupt(cs); | ||
62 | + ret = true; | ||
63 | + } | ||
64 | + return ret; | ||
65 | +} | 91 | +} |
66 | + | 92 | + |
67 | +#endif /* !CONFIG_USER_ONLY */ | 93 | +// Similarly for ResettableExitPhase. |
68 | + | 94 | +@ exitfn_assigned @ |
69 | +static void cortex_m0_initfn(Object *obj) | 95 | +identifier enterfn, holdfn, exitfn; |
96 | +identifier rc; | ||
97 | +expression e; | ||
98 | +@@ | ||
99 | +ResettableClass *rc; | ||
100 | +... | ||
101 | +( | ||
102 | + rc->phases.exit = exitfn; | ||
103 | +| | ||
104 | + resettable_class_set_parent_phases(rc, enterfn, holdfn, exitfn, e); | ||
105 | +) | ||
106 | +@ exitfn_defined @ | ||
107 | +identifier exitfn_assigned.exitfn; | ||
108 | +typedef Object; | ||
109 | +identifier obj; | ||
110 | +expression parent; | ||
111 | +@@ | ||
112 | +-exitfn(Object *obj) | ||
113 | ++exitfn(Object *obj, ResetType type) | ||
70 | +{ | 114 | +{ |
71 | + ARMCPU *cpu = ARM_CPU(obj); | 115 | + <... |
72 | + set_feature(&cpu->env, ARM_FEATURE_V6); | 116 | +- parent.exit(obj) |
73 | + set_feature(&cpu->env, ARM_FEATURE_M); | 117 | ++ parent.exit(obj, type) |
74 | + | 118 | + ...> |
75 | + cpu->midr = 0x410cc200; | ||
76 | + | ||
77 | + /* | ||
78 | + * These ID register values are not guest visible, because | ||
79 | + * we do not implement the Main Extension. They must be set | ||
80 | + * to values corresponding to the Cortex-M0's implemented | ||
81 | + * features, because QEMU generally controls its emulation | ||
82 | + * by looking at ID register fields. We use the same values as | ||
83 | + * for the M3. | ||
84 | + */ | ||
85 | + cpu->isar.id_pfr0 = 0x00000030; | ||
86 | + cpu->isar.id_pfr1 = 0x00000200; | ||
87 | + cpu->isar.id_dfr0 = 0x00100000; | ||
88 | + cpu->id_afr0 = 0x00000000; | ||
89 | + cpu->isar.id_mmfr0 = 0x00000030; | ||
90 | + cpu->isar.id_mmfr1 = 0x00000000; | ||
91 | + cpu->isar.id_mmfr2 = 0x00000000; | ||
92 | + cpu->isar.id_mmfr3 = 0x00000000; | ||
93 | + cpu->isar.id_isar0 = 0x01141110; | ||
94 | + cpu->isar.id_isar1 = 0x02111000; | ||
95 | + cpu->isar.id_isar2 = 0x21112231; | ||
96 | + cpu->isar.id_isar3 = 0x01111110; | ||
97 | + cpu->isar.id_isar4 = 0x01310102; | ||
98 | + cpu->isar.id_isar5 = 0x00000000; | ||
99 | + cpu->isar.id_isar6 = 0x00000000; | ||
100 | +} | 119 | +} |
101 | + | 120 | + |
102 | +static void cortex_m3_initfn(Object *obj) | 121 | +// SPECIAL CASES ONLY BELOW HERE |
103 | +{ | 122 | +// We use a python scripted constraint on the position of the match |
104 | + ARMCPU *cpu = ARM_CPU(obj); | 123 | +// to ensure that they only match in a particular function. See |
105 | + set_feature(&cpu->env, ARM_FEATURE_V7); | 124 | +// https://public-inbox.org/git/alpine.DEB.2.21.1808240652370.2344@hadrien/ |
106 | + set_feature(&cpu->env, ARM_FEATURE_M); | 125 | +// which recommends this as the way to do "match only in this function". |
107 | + set_feature(&cpu->env, ARM_FEATURE_M_MAIN); | ||
108 | + cpu->midr = 0x410fc231; | ||
109 | + cpu->pmsav7_dregion = 8; | ||
110 | + cpu->isar.id_pfr0 = 0x00000030; | ||
111 | + cpu->isar.id_pfr1 = 0x00000200; | ||
112 | + cpu->isar.id_dfr0 = 0x00100000; | ||
113 | + cpu->id_afr0 = 0x00000000; | ||
114 | + cpu->isar.id_mmfr0 = 0x00000030; | ||
115 | + cpu->isar.id_mmfr1 = 0x00000000; | ||
116 | + cpu->isar.id_mmfr2 = 0x00000000; | ||
117 | + cpu->isar.id_mmfr3 = 0x00000000; | ||
118 | + cpu->isar.id_isar0 = 0x01141110; | ||
119 | + cpu->isar.id_isar1 = 0x02111000; | ||
120 | + cpu->isar.id_isar2 = 0x21112231; | ||
121 | + cpu->isar.id_isar3 = 0x01111110; | ||
122 | + cpu->isar.id_isar4 = 0x01310102; | ||
123 | + cpu->isar.id_isar5 = 0x00000000; | ||
124 | + cpu->isar.id_isar6 = 0x00000000; | ||
125 | +} | ||
126 | + | 126 | + |
127 | +static void cortex_m4_initfn(Object *obj) | 127 | +// Special case: isl_pmbus_vr.c has some reset methods calling others directly |
128 | +{ | 128 | +@ isl_pmbus_vr @ |
129 | + ARMCPU *cpu = ARM_CPU(obj); | 129 | +identifier obj; |
130 | +@@ | ||
131 | +- isl_pmbus_vr_exit_reset(obj); | ||
132 | ++ isl_pmbus_vr_exit_reset(obj, type); | ||
130 | + | 133 | + |
131 | + set_feature(&cpu->env, ARM_FEATURE_V7); | 134 | +// Special case: device_phases_reset() needs to pass RESET_TYPE_COLD |
132 | + set_feature(&cpu->env, ARM_FEATURE_M); | 135 | +@ device_phases_reset_hold @ |
133 | + set_feature(&cpu->env, ARM_FEATURE_M_MAIN); | 136 | +expression obj; |
134 | + set_feature(&cpu->env, ARM_FEATURE_THUMB_DSP); | 137 | +identifier rc; |
135 | + cpu->midr = 0x410fc240; /* r0p0 */ | 138 | +identifier phase; |
136 | + cpu->pmsav7_dregion = 8; | 139 | +position p : script:python() { p[0].current_element == "device_phases_reset" }; |
137 | + cpu->isar.mvfr0 = 0x10110021; | 140 | +@@ |
138 | + cpu->isar.mvfr1 = 0x11000011; | 141 | +- rc->phases.phase(obj)@p |
139 | + cpu->isar.mvfr2 = 0x00000000; | 142 | ++ rc->phases.phase(obj, RESET_TYPE_COLD) |
140 | + cpu->isar.id_pfr0 = 0x00000030; | ||
141 | + cpu->isar.id_pfr1 = 0x00000200; | ||
142 | + cpu->isar.id_dfr0 = 0x00100000; | ||
143 | + cpu->id_afr0 = 0x00000000; | ||
144 | + cpu->isar.id_mmfr0 = 0x00000030; | ||
145 | + cpu->isar.id_mmfr1 = 0x00000000; | ||
146 | + cpu->isar.id_mmfr2 = 0x00000000; | ||
147 | + cpu->isar.id_mmfr3 = 0x00000000; | ||
148 | + cpu->isar.id_isar0 = 0x01141110; | ||
149 | + cpu->isar.id_isar1 = 0x02111000; | ||
150 | + cpu->isar.id_isar2 = 0x21112231; | ||
151 | + cpu->isar.id_isar3 = 0x01111110; | ||
152 | + cpu->isar.id_isar4 = 0x01310102; | ||
153 | + cpu->isar.id_isar5 = 0x00000000; | ||
154 | + cpu->isar.id_isar6 = 0x00000000; | ||
155 | +} | ||
156 | + | 143 | + |
157 | +static void cortex_m7_initfn(Object *obj) | 144 | +// Special case: in resettable_phase_hold() and resettable_phase_exit() |
158 | +{ | 145 | +// we need to pass through the ResetType argument to the method being called |
159 | + ARMCPU *cpu = ARM_CPU(obj); | 146 | +@ resettable_phase_hold @ |
160 | + | 147 | +expression obj; |
161 | + set_feature(&cpu->env, ARM_FEATURE_V7); | 148 | +identifier rc; |
162 | + set_feature(&cpu->env, ARM_FEATURE_M); | 149 | +position p : script:python() { p[0].current_element == "resettable_phase_hold" }; |
163 | + set_feature(&cpu->env, ARM_FEATURE_M_MAIN); | 150 | +@@ |
164 | + set_feature(&cpu->env, ARM_FEATURE_THUMB_DSP); | 151 | +- rc->phases.hold(obj)@p |
165 | + cpu->midr = 0x411fc272; /* r1p2 */ | 152 | ++ rc->phases.hold(obj, type) |
166 | + cpu->pmsav7_dregion = 8; | 153 | +@ resettable_phase_exit @ |
167 | + cpu->isar.mvfr0 = 0x10110221; | 154 | +expression obj; |
168 | + cpu->isar.mvfr1 = 0x12000011; | 155 | +identifier rc; |
169 | + cpu->isar.mvfr2 = 0x00000040; | 156 | +position p : script:python() { p[0].current_element == "resettable_phase_exit" }; |
170 | + cpu->isar.id_pfr0 = 0x00000030; | 157 | +@@ |
171 | + cpu->isar.id_pfr1 = 0x00000200; | 158 | +- rc->phases.exit(obj)@p |
172 | + cpu->isar.id_dfr0 = 0x00100000; | 159 | ++ rc->phases.exit(obj, type) |
173 | + cpu->id_afr0 = 0x00000000; | 160 | +// Special case: the typedefs for the methods need to declare the new argument |
174 | + cpu->isar.id_mmfr0 = 0x00100030; | 161 | +@ phase_typedef_hold @ |
175 | + cpu->isar.id_mmfr1 = 0x00000000; | 162 | +identifier obj; |
176 | + cpu->isar.id_mmfr2 = 0x01000000; | 163 | +@@ |
177 | + cpu->isar.id_mmfr3 = 0x00000000; | 164 | +- typedef void (*ResettableHoldPhase)(Object *obj); |
178 | + cpu->isar.id_isar0 = 0x01101110; | 165 | ++ typedef void (*ResettableHoldPhase)(Object *obj, ResetType type); |
179 | + cpu->isar.id_isar1 = 0x02112000; | 166 | +@ phase_typedef_exit @ |
180 | + cpu->isar.id_isar2 = 0x20232231; | 167 | +identifier obj; |
181 | + cpu->isar.id_isar3 = 0x01111131; | 168 | +@@ |
182 | + cpu->isar.id_isar4 = 0x01310132; | 169 | +- typedef void (*ResettableExitPhase)(Object *obj); |
183 | + cpu->isar.id_isar5 = 0x00000000; | 170 | ++ typedef void (*ResettableExitPhase)(Object *obj, ResetType type); |
184 | + cpu->isar.id_isar6 = 0x00000000; | ||
185 | +} | ||
186 | + | ||
187 | +static void cortex_m33_initfn(Object *obj) | ||
188 | +{ | ||
189 | + ARMCPU *cpu = ARM_CPU(obj); | ||
190 | + | ||
191 | + set_feature(&cpu->env, ARM_FEATURE_V8); | ||
192 | + set_feature(&cpu->env, ARM_FEATURE_M); | ||
193 | + set_feature(&cpu->env, ARM_FEATURE_M_MAIN); | ||
194 | + set_feature(&cpu->env, ARM_FEATURE_M_SECURITY); | ||
195 | + set_feature(&cpu->env, ARM_FEATURE_THUMB_DSP); | ||
196 | + cpu->midr = 0x410fd213; /* r0p3 */ | ||
197 | + cpu->pmsav7_dregion = 16; | ||
198 | + cpu->sau_sregion = 8; | ||
199 | + cpu->isar.mvfr0 = 0x10110021; | ||
200 | + cpu->isar.mvfr1 = 0x11000011; | ||
201 | + cpu->isar.mvfr2 = 0x00000040; | ||
202 | + cpu->isar.id_pfr0 = 0x00000030; | ||
203 | + cpu->isar.id_pfr1 = 0x00000210; | ||
204 | + cpu->isar.id_dfr0 = 0x00200000; | ||
205 | + cpu->id_afr0 = 0x00000000; | ||
206 | + cpu->isar.id_mmfr0 = 0x00101F40; | ||
207 | + cpu->isar.id_mmfr1 = 0x00000000; | ||
208 | + cpu->isar.id_mmfr2 = 0x01000000; | ||
209 | + cpu->isar.id_mmfr3 = 0x00000000; | ||
210 | + cpu->isar.id_isar0 = 0x01101110; | ||
211 | + cpu->isar.id_isar1 = 0x02212000; | ||
212 | + cpu->isar.id_isar2 = 0x20232232; | ||
213 | + cpu->isar.id_isar3 = 0x01111131; | ||
214 | + cpu->isar.id_isar4 = 0x01310132; | ||
215 | + cpu->isar.id_isar5 = 0x00000000; | ||
216 | + cpu->isar.id_isar6 = 0x00000000; | ||
217 | + cpu->clidr = 0x00000000; | ||
218 | + cpu->ctr = 0x8000c000; | ||
219 | +} | ||
220 | + | ||
221 | +static void cortex_m55_initfn(Object *obj) | ||
222 | +{ | ||
223 | + ARMCPU *cpu = ARM_CPU(obj); | ||
224 | + | ||
225 | + set_feature(&cpu->env, ARM_FEATURE_V8); | ||
226 | + set_feature(&cpu->env, ARM_FEATURE_V8_1M); | ||
227 | + set_feature(&cpu->env, ARM_FEATURE_M); | ||
228 | + set_feature(&cpu->env, ARM_FEATURE_M_MAIN); | ||
229 | + set_feature(&cpu->env, ARM_FEATURE_M_SECURITY); | ||
230 | + set_feature(&cpu->env, ARM_FEATURE_THUMB_DSP); | ||
231 | + cpu->midr = 0x410fd221; /* r0p1 */ | ||
232 | + cpu->revidr = 0; | ||
233 | + cpu->pmsav7_dregion = 16; | ||
234 | + cpu->sau_sregion = 8; | ||
235 | + /* These are the MVFR* values for the FPU + full MVE configuration */ | ||
236 | + cpu->isar.mvfr0 = 0x10110221; | ||
237 | + cpu->isar.mvfr1 = 0x12100211; | ||
238 | + cpu->isar.mvfr2 = 0x00000040; | ||
239 | + cpu->isar.id_pfr0 = 0x20000030; | ||
240 | + cpu->isar.id_pfr1 = 0x00000230; | ||
241 | + cpu->isar.id_dfr0 = 0x10200000; | ||
242 | + cpu->id_afr0 = 0x00000000; | ||
243 | + cpu->isar.id_mmfr0 = 0x00111040; | ||
244 | + cpu->isar.id_mmfr1 = 0x00000000; | ||
245 | + cpu->isar.id_mmfr2 = 0x01000000; | ||
246 | + cpu->isar.id_mmfr3 = 0x00000011; | ||
247 | + cpu->isar.id_isar0 = 0x01103110; | ||
248 | + cpu->isar.id_isar1 = 0x02212000; | ||
249 | + cpu->isar.id_isar2 = 0x20232232; | ||
250 | + cpu->isar.id_isar3 = 0x01111131; | ||
251 | + cpu->isar.id_isar4 = 0x01310132; | ||
252 | + cpu->isar.id_isar5 = 0x00000000; | ||
253 | + cpu->isar.id_isar6 = 0x00000000; | ||
254 | + cpu->clidr = 0x00000000; /* caches not implemented */ | ||
255 | + cpu->ctr = 0x8303c003; | ||
256 | +} | ||
257 | + | ||
258 | +static const TCGCPUOps arm_v7m_tcg_ops = { | ||
259 | + .initialize = arm_translate_init, | ||
260 | + .synchronize_from_tb = arm_cpu_synchronize_from_tb, | ||
261 | + .debug_excp_handler = arm_debug_excp_handler, | ||
262 | + .restore_state_to_opc = arm_restore_state_to_opc, | ||
263 | + | ||
264 | +#ifdef CONFIG_USER_ONLY | ||
265 | + .record_sigsegv = arm_cpu_record_sigsegv, | ||
266 | + .record_sigbus = arm_cpu_record_sigbus, | ||
267 | +#else | ||
268 | + .tlb_fill = arm_cpu_tlb_fill, | ||
269 | + .cpu_exec_interrupt = arm_v7m_cpu_exec_interrupt, | ||
270 | + .do_interrupt = arm_v7m_cpu_do_interrupt, | ||
271 | + .do_transaction_failed = arm_cpu_do_transaction_failed, | ||
272 | + .do_unaligned_access = arm_cpu_do_unaligned_access, | ||
273 | + .adjust_watchpoint_address = arm_adjust_watchpoint_address, | ||
274 | + .debug_check_watchpoint = arm_debug_check_watchpoint, | ||
275 | + .debug_check_breakpoint = arm_debug_check_breakpoint, | ||
276 | +#endif /* !CONFIG_USER_ONLY */ | ||
277 | +}; | ||
278 | + | ||
279 | +static void arm_v7m_class_init(ObjectClass *oc, void *data) | ||
280 | +{ | ||
281 | + ARMCPUClass *acc = ARM_CPU_CLASS(oc); | ||
282 | + CPUClass *cc = CPU_CLASS(oc); | ||
283 | + | ||
284 | + acc->info = data; | ||
285 | + cc->tcg_ops = &arm_v7m_tcg_ops; | ||
286 | + cc->gdb_core_xml_file = "arm-m-profile.xml"; | ||
287 | +} | ||
288 | + | ||
289 | +static const ARMCPUInfo arm_v7m_cpus[] = { | ||
290 | + { .name = "cortex-m0", .initfn = cortex_m0_initfn, | ||
291 | + .class_init = arm_v7m_class_init }, | ||
292 | + { .name = "cortex-m3", .initfn = cortex_m3_initfn, | ||
293 | + .class_init = arm_v7m_class_init }, | ||
294 | + { .name = "cortex-m4", .initfn = cortex_m4_initfn, | ||
295 | + .class_init = arm_v7m_class_init }, | ||
296 | + { .name = "cortex-m7", .initfn = cortex_m7_initfn, | ||
297 | + .class_init = arm_v7m_class_init }, | ||
298 | + { .name = "cortex-m33", .initfn = cortex_m33_initfn, | ||
299 | + .class_init = arm_v7m_class_init }, | ||
300 | + { .name = "cortex-m55", .initfn = cortex_m55_initfn, | ||
301 | + .class_init = arm_v7m_class_init }, | ||
302 | +}; | ||
303 | + | ||
304 | +static void arm_v7m_cpu_register_types(void) | ||
305 | +{ | ||
306 | + size_t i; | ||
307 | + | ||
308 | + for (i = 0; i < ARRAY_SIZE(arm_v7m_cpus); ++i) { | ||
309 | + arm_cpu_register(&arm_v7m_cpus[i]); | ||
310 | + } | ||
311 | +} | ||
312 | + | ||
313 | +type_init(arm_v7m_cpu_register_types) | ||
314 | diff --git a/target/arm/tcg/cpu32.c b/target/arm/tcg/cpu32.c | ||
315 | index XXXXXXX..XXXXXXX 100644 | ||
316 | --- a/target/arm/tcg/cpu32.c | ||
317 | +++ b/target/arm/tcg/cpu32.c | ||
318 | @@ -XXX,XX +XXX,XX @@ | ||
319 | #include "hw/boards.h" | ||
320 | #endif | ||
321 | #include "cpregs.h" | ||
322 | -#if !defined(CONFIG_USER_ONLY) && defined(CONFIG_TCG) | ||
323 | -#include "hw/intc/armv7m_nvic.h" | ||
324 | -#endif | ||
325 | |||
326 | |||
327 | /* Share AArch32 -cpu max features with AArch64. */ | ||
328 | @@ -XXX,XX +XXX,XX @@ void aa32_max_features(ARMCPU *cpu) | ||
329 | /* CPU models. These are not needed for the AArch64 linux-user build. */ | ||
330 | #if !defined(CONFIG_USER_ONLY) || !defined(TARGET_AARCH64) | ||
331 | |||
332 | -#if !defined(CONFIG_USER_ONLY) | ||
333 | -static bool arm_v7m_cpu_exec_interrupt(CPUState *cs, int interrupt_request) | ||
334 | -{ | ||
335 | - CPUClass *cc = CPU_GET_CLASS(cs); | ||
336 | - ARMCPU *cpu = ARM_CPU(cs); | ||
337 | - CPUARMState *env = &cpu->env; | ||
338 | - bool ret = false; | ||
339 | - | ||
340 | - /* | ||
341 | - * ARMv7-M interrupt masking works differently than -A or -R. | ||
342 | - * There is no FIQ/IRQ distinction. Instead of I and F bits | ||
343 | - * masking FIQ and IRQ interrupts, an exception is taken only | ||
344 | - * if it is higher priority than the current execution priority | ||
345 | - * (which depends on state like BASEPRI, FAULTMASK and the | ||
346 | - * currently active exception). | ||
347 | - */ | ||
348 | - if (interrupt_request & CPU_INTERRUPT_HARD | ||
349 | - && (armv7m_nvic_can_take_pending_exception(env->nvic))) { | ||
350 | - cs->exception_index = EXCP_IRQ; | ||
351 | - cc->tcg_ops->do_interrupt(cs); | ||
352 | - ret = true; | ||
353 | - } | ||
354 | - return ret; | ||
355 | -} | ||
356 | -#endif /* !CONFIG_USER_ONLY */ | ||
357 | - | ||
358 | static void arm926_initfn(Object *obj) | ||
359 | { | ||
360 | ARMCPU *cpu = ARM_CPU(obj); | ||
361 | @@ -XXX,XX +XXX,XX @@ static void cortex_a15_initfn(Object *obj) | ||
362 | define_arm_cp_regs(cpu, cortexa15_cp_reginfo); | ||
363 | } | ||
364 | |||
365 | -static void cortex_m0_initfn(Object *obj) | ||
366 | -{ | ||
367 | - ARMCPU *cpu = ARM_CPU(obj); | ||
368 | - set_feature(&cpu->env, ARM_FEATURE_V6); | ||
369 | - set_feature(&cpu->env, ARM_FEATURE_M); | ||
370 | - | ||
371 | - cpu->midr = 0x410cc200; | ||
372 | - | ||
373 | - /* | ||
374 | - * These ID register values are not guest visible, because | ||
375 | - * we do not implement the Main Extension. They must be set | ||
376 | - * to values corresponding to the Cortex-M0's implemented | ||
377 | - * features, because QEMU generally controls its emulation | ||
378 | - * by looking at ID register fields. We use the same values as | ||
379 | - * for the M3. | ||
380 | - */ | ||
381 | - cpu->isar.id_pfr0 = 0x00000030; | ||
382 | - cpu->isar.id_pfr1 = 0x00000200; | ||
383 | - cpu->isar.id_dfr0 = 0x00100000; | ||
384 | - cpu->id_afr0 = 0x00000000; | ||
385 | - cpu->isar.id_mmfr0 = 0x00000030; | ||
386 | - cpu->isar.id_mmfr1 = 0x00000000; | ||
387 | - cpu->isar.id_mmfr2 = 0x00000000; | ||
388 | - cpu->isar.id_mmfr3 = 0x00000000; | ||
389 | - cpu->isar.id_isar0 = 0x01141110; | ||
390 | - cpu->isar.id_isar1 = 0x02111000; | ||
391 | - cpu->isar.id_isar2 = 0x21112231; | ||
392 | - cpu->isar.id_isar3 = 0x01111110; | ||
393 | - cpu->isar.id_isar4 = 0x01310102; | ||
394 | - cpu->isar.id_isar5 = 0x00000000; | ||
395 | - cpu->isar.id_isar6 = 0x00000000; | ||
396 | -} | ||
397 | - | ||
398 | -static void cortex_m3_initfn(Object *obj) | ||
399 | -{ | ||
400 | - ARMCPU *cpu = ARM_CPU(obj); | ||
401 | - set_feature(&cpu->env, ARM_FEATURE_V7); | ||
402 | - set_feature(&cpu->env, ARM_FEATURE_M); | ||
403 | - set_feature(&cpu->env, ARM_FEATURE_M_MAIN); | ||
404 | - cpu->midr = 0x410fc231; | ||
405 | - cpu->pmsav7_dregion = 8; | ||
406 | - cpu->isar.id_pfr0 = 0x00000030; | ||
407 | - cpu->isar.id_pfr1 = 0x00000200; | ||
408 | - cpu->isar.id_dfr0 = 0x00100000; | ||
409 | - cpu->id_afr0 = 0x00000000; | ||
410 | - cpu->isar.id_mmfr0 = 0x00000030; | ||
411 | - cpu->isar.id_mmfr1 = 0x00000000; | ||
412 | - cpu->isar.id_mmfr2 = 0x00000000; | ||
413 | - cpu->isar.id_mmfr3 = 0x00000000; | ||
414 | - cpu->isar.id_isar0 = 0x01141110; | ||
415 | - cpu->isar.id_isar1 = 0x02111000; | ||
416 | - cpu->isar.id_isar2 = 0x21112231; | ||
417 | - cpu->isar.id_isar3 = 0x01111110; | ||
418 | - cpu->isar.id_isar4 = 0x01310102; | ||
419 | - cpu->isar.id_isar5 = 0x00000000; | ||
420 | - cpu->isar.id_isar6 = 0x00000000; | ||
421 | -} | ||
422 | - | ||
423 | -static void cortex_m4_initfn(Object *obj) | ||
424 | -{ | ||
425 | - ARMCPU *cpu = ARM_CPU(obj); | ||
426 | - | ||
427 | - set_feature(&cpu->env, ARM_FEATURE_V7); | ||
428 | - set_feature(&cpu->env, ARM_FEATURE_M); | ||
429 | - set_feature(&cpu->env, ARM_FEATURE_M_MAIN); | ||
430 | - set_feature(&cpu->env, ARM_FEATURE_THUMB_DSP); | ||
431 | - cpu->midr = 0x410fc240; /* r0p0 */ | ||
432 | - cpu->pmsav7_dregion = 8; | ||
433 | - cpu->isar.mvfr0 = 0x10110021; | ||
434 | - cpu->isar.mvfr1 = 0x11000011; | ||
435 | - cpu->isar.mvfr2 = 0x00000000; | ||
436 | - cpu->isar.id_pfr0 = 0x00000030; | ||
437 | - cpu->isar.id_pfr1 = 0x00000200; | ||
438 | - cpu->isar.id_dfr0 = 0x00100000; | ||
439 | - cpu->id_afr0 = 0x00000000; | ||
440 | - cpu->isar.id_mmfr0 = 0x00000030; | ||
441 | - cpu->isar.id_mmfr1 = 0x00000000; | ||
442 | - cpu->isar.id_mmfr2 = 0x00000000; | ||
443 | - cpu->isar.id_mmfr3 = 0x00000000; | ||
444 | - cpu->isar.id_isar0 = 0x01141110; | ||
445 | - cpu->isar.id_isar1 = 0x02111000; | ||
446 | - cpu->isar.id_isar2 = 0x21112231; | ||
447 | - cpu->isar.id_isar3 = 0x01111110; | ||
448 | - cpu->isar.id_isar4 = 0x01310102; | ||
449 | - cpu->isar.id_isar5 = 0x00000000; | ||
450 | - cpu->isar.id_isar6 = 0x00000000; | ||
451 | -} | ||
452 | - | ||
453 | -static void cortex_m7_initfn(Object *obj) | ||
454 | -{ | ||
455 | - ARMCPU *cpu = ARM_CPU(obj); | ||
456 | - | ||
457 | - set_feature(&cpu->env, ARM_FEATURE_V7); | ||
458 | - set_feature(&cpu->env, ARM_FEATURE_M); | ||
459 | - set_feature(&cpu->env, ARM_FEATURE_M_MAIN); | ||
460 | - set_feature(&cpu->env, ARM_FEATURE_THUMB_DSP); | ||
461 | - cpu->midr = 0x411fc272; /* r1p2 */ | ||
462 | - cpu->pmsav7_dregion = 8; | ||
463 | - cpu->isar.mvfr0 = 0x10110221; | ||
464 | - cpu->isar.mvfr1 = 0x12000011; | ||
465 | - cpu->isar.mvfr2 = 0x00000040; | ||
466 | - cpu->isar.id_pfr0 = 0x00000030; | ||
467 | - cpu->isar.id_pfr1 = 0x00000200; | ||
468 | - cpu->isar.id_dfr0 = 0x00100000; | ||
469 | - cpu->id_afr0 = 0x00000000; | ||
470 | - cpu->isar.id_mmfr0 = 0x00100030; | ||
471 | - cpu->isar.id_mmfr1 = 0x00000000; | ||
472 | - cpu->isar.id_mmfr2 = 0x01000000; | ||
473 | - cpu->isar.id_mmfr3 = 0x00000000; | ||
474 | - cpu->isar.id_isar0 = 0x01101110; | ||
475 | - cpu->isar.id_isar1 = 0x02112000; | ||
476 | - cpu->isar.id_isar2 = 0x20232231; | ||
477 | - cpu->isar.id_isar3 = 0x01111131; | ||
478 | - cpu->isar.id_isar4 = 0x01310132; | ||
479 | - cpu->isar.id_isar5 = 0x00000000; | ||
480 | - cpu->isar.id_isar6 = 0x00000000; | ||
481 | -} | ||
482 | - | ||
483 | -static void cortex_m33_initfn(Object *obj) | ||
484 | -{ | ||
485 | - ARMCPU *cpu = ARM_CPU(obj); | ||
486 | - | ||
487 | - set_feature(&cpu->env, ARM_FEATURE_V8); | ||
488 | - set_feature(&cpu->env, ARM_FEATURE_M); | ||
489 | - set_feature(&cpu->env, ARM_FEATURE_M_MAIN); | ||
490 | - set_feature(&cpu->env, ARM_FEATURE_M_SECURITY); | ||
491 | - set_feature(&cpu->env, ARM_FEATURE_THUMB_DSP); | ||
492 | - cpu->midr = 0x410fd213; /* r0p3 */ | ||
493 | - cpu->pmsav7_dregion = 16; | ||
494 | - cpu->sau_sregion = 8; | ||
495 | - cpu->isar.mvfr0 = 0x10110021; | ||
496 | - cpu->isar.mvfr1 = 0x11000011; | ||
497 | - cpu->isar.mvfr2 = 0x00000040; | ||
498 | - cpu->isar.id_pfr0 = 0x00000030; | ||
499 | - cpu->isar.id_pfr1 = 0x00000210; | ||
500 | - cpu->isar.id_dfr0 = 0x00200000; | ||
501 | - cpu->id_afr0 = 0x00000000; | ||
502 | - cpu->isar.id_mmfr0 = 0x00101F40; | ||
503 | - cpu->isar.id_mmfr1 = 0x00000000; | ||
504 | - cpu->isar.id_mmfr2 = 0x01000000; | ||
505 | - cpu->isar.id_mmfr3 = 0x00000000; | ||
506 | - cpu->isar.id_isar0 = 0x01101110; | ||
507 | - cpu->isar.id_isar1 = 0x02212000; | ||
508 | - cpu->isar.id_isar2 = 0x20232232; | ||
509 | - cpu->isar.id_isar3 = 0x01111131; | ||
510 | - cpu->isar.id_isar4 = 0x01310132; | ||
511 | - cpu->isar.id_isar5 = 0x00000000; | ||
512 | - cpu->isar.id_isar6 = 0x00000000; | ||
513 | - cpu->clidr = 0x00000000; | ||
514 | - cpu->ctr = 0x8000c000; | ||
515 | -} | ||
516 | - | ||
517 | -static void cortex_m55_initfn(Object *obj) | ||
518 | -{ | ||
519 | - ARMCPU *cpu = ARM_CPU(obj); | ||
520 | - | ||
521 | - set_feature(&cpu->env, ARM_FEATURE_V8); | ||
522 | - set_feature(&cpu->env, ARM_FEATURE_V8_1M); | ||
523 | - set_feature(&cpu->env, ARM_FEATURE_M); | ||
524 | - set_feature(&cpu->env, ARM_FEATURE_M_MAIN); | ||
525 | - set_feature(&cpu->env, ARM_FEATURE_M_SECURITY); | ||
526 | - set_feature(&cpu->env, ARM_FEATURE_THUMB_DSP); | ||
527 | - cpu->midr = 0x410fd221; /* r0p1 */ | ||
528 | - cpu->revidr = 0; | ||
529 | - cpu->pmsav7_dregion = 16; | ||
530 | - cpu->sau_sregion = 8; | ||
531 | - /* These are the MVFR* values for the FPU + full MVE configuration */ | ||
532 | - cpu->isar.mvfr0 = 0x10110221; | ||
533 | - cpu->isar.mvfr1 = 0x12100211; | ||
534 | - cpu->isar.mvfr2 = 0x00000040; | ||
535 | - cpu->isar.id_pfr0 = 0x20000030; | ||
536 | - cpu->isar.id_pfr1 = 0x00000230; | ||
537 | - cpu->isar.id_dfr0 = 0x10200000; | ||
538 | - cpu->id_afr0 = 0x00000000; | ||
539 | - cpu->isar.id_mmfr0 = 0x00111040; | ||
540 | - cpu->isar.id_mmfr1 = 0x00000000; | ||
541 | - cpu->isar.id_mmfr2 = 0x01000000; | ||
542 | - cpu->isar.id_mmfr3 = 0x00000011; | ||
543 | - cpu->isar.id_isar0 = 0x01103110; | ||
544 | - cpu->isar.id_isar1 = 0x02212000; | ||
545 | - cpu->isar.id_isar2 = 0x20232232; | ||
546 | - cpu->isar.id_isar3 = 0x01111131; | ||
547 | - cpu->isar.id_isar4 = 0x01310132; | ||
548 | - cpu->isar.id_isar5 = 0x00000000; | ||
549 | - cpu->isar.id_isar6 = 0x00000000; | ||
550 | - cpu->clidr = 0x00000000; /* caches not implemented */ | ||
551 | - cpu->ctr = 0x8303c003; | ||
552 | -} | ||
553 | - | ||
554 | static const ARMCPRegInfo cortexr5_cp_reginfo[] = { | ||
555 | /* Dummy the TCM region regs for the moment */ | ||
556 | { .name = "ATCM", .cp = 15, .opc1 = 0, .crn = 9, .crm = 1, .opc2 = 0, | ||
557 | @@ -XXX,XX +XXX,XX @@ static void pxa270c5_initfn(Object *obj) | ||
558 | cpu->reset_sctlr = 0x00000078; | ||
559 | } | ||
560 | |||
561 | -static const TCGCPUOps arm_v7m_tcg_ops = { | ||
562 | - .initialize = arm_translate_init, | ||
563 | - .synchronize_from_tb = arm_cpu_synchronize_from_tb, | ||
564 | - .debug_excp_handler = arm_debug_excp_handler, | ||
565 | - .restore_state_to_opc = arm_restore_state_to_opc, | ||
566 | - | ||
567 | -#ifdef CONFIG_USER_ONLY | ||
568 | - .record_sigsegv = arm_cpu_record_sigsegv, | ||
569 | - .record_sigbus = arm_cpu_record_sigbus, | ||
570 | -#else | ||
571 | - .tlb_fill = arm_cpu_tlb_fill, | ||
572 | - .cpu_exec_interrupt = arm_v7m_cpu_exec_interrupt, | ||
573 | - .do_interrupt = arm_v7m_cpu_do_interrupt, | ||
574 | - .do_transaction_failed = arm_cpu_do_transaction_failed, | ||
575 | - .do_unaligned_access = arm_cpu_do_unaligned_access, | ||
576 | - .adjust_watchpoint_address = arm_adjust_watchpoint_address, | ||
577 | - .debug_check_watchpoint = arm_debug_check_watchpoint, | ||
578 | - .debug_check_breakpoint = arm_debug_check_breakpoint, | ||
579 | -#endif /* !CONFIG_USER_ONLY */ | ||
580 | -}; | ||
581 | - | ||
582 | -static void arm_v7m_class_init(ObjectClass *oc, void *data) | ||
583 | -{ | ||
584 | - ARMCPUClass *acc = ARM_CPU_CLASS(oc); | ||
585 | - CPUClass *cc = CPU_CLASS(oc); | ||
586 | - | ||
587 | - acc->info = data; | ||
588 | - cc->tcg_ops = &arm_v7m_tcg_ops; | ||
589 | - cc->gdb_core_xml_file = "arm-m-profile.xml"; | ||
590 | -} | ||
591 | - | ||
592 | #ifndef TARGET_AARCH64 | ||
593 | /* | ||
594 | * -cpu max: a CPU with as many features enabled as our emulation supports. | ||
595 | @@ -XXX,XX +XXX,XX @@ static const ARMCPUInfo arm_tcg_cpus[] = { | ||
596 | { .name = "cortex-a8", .initfn = cortex_a8_initfn }, | ||
597 | { .name = "cortex-a9", .initfn = cortex_a9_initfn }, | ||
598 | { .name = "cortex-a15", .initfn = cortex_a15_initfn }, | ||
599 | - { .name = "cortex-m0", .initfn = cortex_m0_initfn, | ||
600 | - .class_init = arm_v7m_class_init }, | ||
601 | - { .name = "cortex-m3", .initfn = cortex_m3_initfn, | ||
602 | - .class_init = arm_v7m_class_init }, | ||
603 | - { .name = "cortex-m4", .initfn = cortex_m4_initfn, | ||
604 | - .class_init = arm_v7m_class_init }, | ||
605 | - { .name = "cortex-m7", .initfn = cortex_m7_initfn, | ||
606 | - .class_init = arm_v7m_class_init }, | ||
607 | - { .name = "cortex-m33", .initfn = cortex_m33_initfn, | ||
608 | - .class_init = arm_v7m_class_init }, | ||
609 | - { .name = "cortex-m55", .initfn = cortex_m55_initfn, | ||
610 | - .class_init = arm_v7m_class_init }, | ||
611 | { .name = "cortex-r5", .initfn = cortex_r5_initfn }, | ||
612 | { .name = "cortex-r5f", .initfn = cortex_r5f_initfn }, | ||
613 | { .name = "cortex-r52", .initfn = cortex_r52_initfn }, | ||
614 | diff --git a/target/arm/meson.build b/target/arm/meson.build | ||
615 | index XXXXXXX..XXXXXXX 100644 | ||
616 | --- a/target/arm/meson.build | ||
617 | +++ b/target/arm/meson.build | ||
618 | @@ -XXX,XX +XXX,XX @@ arm_system_ss.add(files( | ||
619 | 'ptw.c', | ||
620 | )) | ||
621 | |||
622 | +arm_user_ss = ss.source_set() | ||
623 | + | ||
624 | subdir('hvf') | ||
625 | |||
626 | if 'CONFIG_TCG' in config_all_accel | ||
627 | @@ -XXX,XX +XXX,XX @@ endif | ||
628 | |||
629 | target_arch += {'arm': arm_ss} | ||
630 | target_system_arch += {'arm': arm_system_ss} | ||
631 | +target_user_arch += {'arm': arm_user_ss} | ||
632 | diff --git a/target/arm/tcg/meson.build b/target/arm/tcg/meson.build | ||
633 | index XXXXXXX..XXXXXXX 100644 | ||
634 | --- a/target/arm/tcg/meson.build | ||
635 | +++ b/target/arm/tcg/meson.build | ||
636 | @@ -XXX,XX +XXX,XX @@ arm_ss.add(when: 'TARGET_AARCH64', if_true: files( | ||
637 | arm_system_ss.add(files( | ||
638 | 'psci.c', | ||
639 | )) | ||
640 | + | ||
641 | +arm_system_ss.add(when: 'CONFIG_ARM_V7M', if_true: files('cpu-v7m.c')) | ||
642 | +arm_user_ss.add(when: 'TARGET_AARCH64', if_false: files('cpu-v7m.c')) | ||
643 | -- | 171 | -- |
644 | 2.34.1 | 172 | 2.34.1 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | We pass a ResetType argument to the Resettable class enter | ||
2 | phase method, but we don't pass it to hold and exit, even though | ||
3 | the callsites have it readily available. This means that if | ||
4 | a device cared about the ResetType it would need to record it | ||
5 | in the enter phase method to use later on. Pass the type to | ||
6 | all three of the phase methods to avoid having to do that. | ||
1 | 7 | ||
8 | Commit created with | ||
9 | |||
10 | for dir in hw target include; do \ | ||
11 | spatch --macro-file scripts/cocci-macro-file.h \ | ||
12 | --sp-file scripts/coccinelle/reset-type.cocci \ | ||
13 | --keep-comments --smpl-spacing --in-place \ | ||
14 | --include-headers --dir $dir; done | ||
15 | |||
16 | and no manual edits. | ||
17 | |||
18 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
19 | Reviewed-by: Edgar E. Iglesias <edgar.iglesias@amd.com> | ||
20 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
21 | Reviewed-by: Luc Michel <luc.michel@amd.com> | ||
22 | Message-id: 20240412160809.1260625-5-peter.maydell@linaro.org | ||
23 | --- | ||
24 | include/hw/resettable.h | 4 ++-- | ||
25 | hw/adc/npcm7xx_adc.c | 2 +- | ||
26 | hw/arm/pxa2xx_pic.c | 2 +- | ||
27 | hw/arm/smmu-common.c | 2 +- | ||
28 | hw/arm/smmuv3.c | 4 ++-- | ||
29 | hw/arm/stellaris.c | 10 +++++----- | ||
30 | hw/audio/asc.c | 2 +- | ||
31 | hw/char/cadence_uart.c | 2 +- | ||
32 | hw/char/sifive_uart.c | 2 +- | ||
33 | hw/core/cpu-common.c | 2 +- | ||
34 | hw/core/qdev.c | 4 ++-- | ||
35 | hw/core/reset.c | 2 +- | ||
36 | hw/core/resettable.c | 4 ++-- | ||
37 | hw/display/virtio-vga.c | 4 ++-- | ||
38 | hw/gpio/npcm7xx_gpio.c | 2 +- | ||
39 | hw/gpio/pl061.c | 2 +- | ||
40 | hw/gpio/stm32l4x5_gpio.c | 2 +- | ||
41 | hw/hyperv/vmbus.c | 2 +- | ||
42 | hw/i2c/allwinner-i2c.c | 2 +- | ||
43 | hw/i2c/npcm7xx_smbus.c | 2 +- | ||
44 | hw/input/adb.c | 2 +- | ||
45 | hw/input/ps2.c | 12 ++++++------ | ||
46 | hw/intc/arm_gic_common.c | 2 +- | ||
47 | hw/intc/arm_gic_kvm.c | 4 ++-- | ||
48 | hw/intc/arm_gicv3_common.c | 2 +- | ||
49 | hw/intc/arm_gicv3_its.c | 4 ++-- | ||
50 | hw/intc/arm_gicv3_its_common.c | 2 +- | ||
51 | hw/intc/arm_gicv3_its_kvm.c | 4 ++-- | ||
52 | hw/intc/arm_gicv3_kvm.c | 4 ++-- | ||
53 | hw/intc/xics.c | 2 +- | ||
54 | hw/m68k/q800-glue.c | 2 +- | ||
55 | hw/misc/djmemc.c | 2 +- | ||
56 | hw/misc/iosb.c | 2 +- | ||
57 | hw/misc/mac_via.c | 8 ++++---- | ||
58 | hw/misc/macio/cuda.c | 4 ++-- | ||
59 | hw/misc/macio/pmu.c | 4 ++-- | ||
60 | hw/misc/mos6522.c | 2 +- | ||
61 | hw/misc/npcm7xx_mft.c | 2 +- | ||
62 | hw/misc/npcm7xx_pwm.c | 2 +- | ||
63 | hw/misc/stm32l4x5_exti.c | 2 +- | ||
64 | hw/misc/stm32l4x5_rcc.c | 10 +++++----- | ||
65 | hw/misc/stm32l4x5_syscfg.c | 2 +- | ||
66 | hw/misc/xlnx-versal-cframe-reg.c | 2 +- | ||
67 | hw/misc/xlnx-versal-crl.c | 2 +- | ||
68 | hw/misc/xlnx-versal-pmc-iou-slcr.c | 2 +- | ||
69 | hw/misc/xlnx-versal-trng.c | 2 +- | ||
70 | hw/misc/xlnx-versal-xramc.c | 2 +- | ||
71 | hw/misc/xlnx-zynqmp-apu-ctrl.c | 2 +- | ||
72 | hw/misc/xlnx-zynqmp-crf.c | 2 +- | ||
73 | hw/misc/zynq_slcr.c | 4 ++-- | ||
74 | hw/net/can/xlnx-zynqmp-can.c | 2 +- | ||
75 | hw/net/e1000.c | 2 +- | ||
76 | hw/net/e1000e.c | 2 +- | ||
77 | hw/net/igb.c | 2 +- | ||
78 | hw/net/igbvf.c | 2 +- | ||
79 | hw/nvram/xlnx-bbram.c | 2 +- | ||
80 | hw/nvram/xlnx-versal-efuse-ctrl.c | 2 +- | ||
81 | hw/nvram/xlnx-zynqmp-efuse.c | 2 +- | ||
82 | hw/pci-bridge/cxl_root_port.c | 4 ++-- | ||
83 | hw/pci-bridge/pcie_root_port.c | 2 +- | ||
84 | hw/pci-host/bonito.c | 2 +- | ||
85 | hw/pci-host/pnv_phb.c | 4 ++-- | ||
86 | hw/pci-host/pnv_phb3_msi.c | 4 ++-- | ||
87 | hw/pci/pci.c | 4 ++-- | ||
88 | hw/rtc/mc146818rtc.c | 2 +- | ||
89 | hw/s390x/css-bridge.c | 2 +- | ||
90 | hw/sensor/adm1266.c | 2 +- | ||
91 | hw/sensor/adm1272.c | 2 +- | ||
92 | hw/sensor/isl_pmbus_vr.c | 10 +++++----- | ||
93 | hw/sensor/max31785.c | 2 +- | ||
94 | hw/sensor/max34451.c | 2 +- | ||
95 | hw/ssi/npcm7xx_fiu.c | 2 +- | ||
96 | hw/timer/etraxfs_timer.c | 2 +- | ||
97 | hw/timer/npcm7xx_timer.c | 2 +- | ||
98 | hw/usb/hcd-dwc2.c | 8 ++++---- | ||
99 | hw/usb/xlnx-versal-usb2-ctrl-regs.c | 2 +- | ||
100 | hw/virtio/virtio-pci.c | 2 +- | ||
101 | target/arm/cpu.c | 4 ++-- | ||
102 | target/avr/cpu.c | 4 ++-- | ||
103 | target/cris/cpu.c | 4 ++-- | ||
104 | target/hexagon/cpu.c | 4 ++-- | ||
105 | target/i386/cpu.c | 4 ++-- | ||
106 | target/loongarch/cpu.c | 4 ++-- | ||
107 | target/m68k/cpu.c | 4 ++-- | ||
108 | target/microblaze/cpu.c | 4 ++-- | ||
109 | target/mips/cpu.c | 4 ++-- | ||
110 | target/openrisc/cpu.c | 4 ++-- | ||
111 | target/ppc/cpu_init.c | 4 ++-- | ||
112 | target/riscv/cpu.c | 4 ++-- | ||
113 | target/rx/cpu.c | 4 ++-- | ||
114 | target/sh4/cpu.c | 4 ++-- | ||
115 | target/sparc/cpu.c | 4 ++-- | ||
116 | target/tricore/cpu.c | 4 ++-- | ||
117 | target/xtensa/cpu.c | 4 ++-- | ||
118 | 94 files changed, 150 insertions(+), 150 deletions(-) | ||
119 | |||
120 | diff --git a/include/hw/resettable.h b/include/hw/resettable.h | ||
121 | index XXXXXXX..XXXXXXX 100644 | ||
122 | --- a/include/hw/resettable.h | ||
123 | +++ b/include/hw/resettable.h | ||
124 | @@ -XXX,XX +XXX,XX @@ typedef enum ResetType { | ||
125 | * the callback. | ||
126 | */ | ||
127 | typedef void (*ResettableEnterPhase)(Object *obj, ResetType type); | ||
128 | -typedef void (*ResettableHoldPhase)(Object *obj); | ||
129 | -typedef void (*ResettableExitPhase)(Object *obj); | ||
130 | +typedef void (*ResettableHoldPhase)(Object *obj, ResetType type); | ||
131 | +typedef void (*ResettableExitPhase)(Object *obj, ResetType type); | ||
132 | typedef ResettableState * (*ResettableGetState)(Object *obj); | ||
133 | typedef void (*ResettableTrFunction)(Object *obj); | ||
134 | typedef ResettableTrFunction (*ResettableGetTrFunction)(Object *obj); | ||
135 | diff --git a/hw/adc/npcm7xx_adc.c b/hw/adc/npcm7xx_adc.c | ||
136 | index XXXXXXX..XXXXXXX 100644 | ||
137 | --- a/hw/adc/npcm7xx_adc.c | ||
138 | +++ b/hw/adc/npcm7xx_adc.c | ||
139 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_adc_enter_reset(Object *obj, ResetType type) | ||
140 | npcm7xx_adc_reset(s); | ||
141 | } | ||
142 | |||
143 | -static void npcm7xx_adc_hold_reset(Object *obj) | ||
144 | +static void npcm7xx_adc_hold_reset(Object *obj, ResetType type) | ||
145 | { | ||
146 | NPCM7xxADCState *s = NPCM7XX_ADC(obj); | ||
147 | |||
148 | diff --git a/hw/arm/pxa2xx_pic.c b/hw/arm/pxa2xx_pic.c | ||
149 | index XXXXXXX..XXXXXXX 100644 | ||
150 | --- a/hw/arm/pxa2xx_pic.c | ||
151 | +++ b/hw/arm/pxa2xx_pic.c | ||
152 | @@ -XXX,XX +XXX,XX @@ static int pxa2xx_pic_post_load(void *opaque, int version_id) | ||
153 | return 0; | ||
154 | } | ||
155 | |||
156 | -static void pxa2xx_pic_reset_hold(Object *obj) | ||
157 | +static void pxa2xx_pic_reset_hold(Object *obj, ResetType type) | ||
158 | { | ||
159 | PXA2xxPICState *s = PXA2XX_PIC(obj); | ||
160 | |||
161 | diff --git a/hw/arm/smmu-common.c b/hw/arm/smmu-common.c | ||
162 | index XXXXXXX..XXXXXXX 100644 | ||
163 | --- a/hw/arm/smmu-common.c | ||
164 | +++ b/hw/arm/smmu-common.c | ||
165 | @@ -XXX,XX +XXX,XX @@ static void smmu_base_realize(DeviceState *dev, Error **errp) | ||
166 | } | ||
167 | } | ||
168 | |||
169 | -static void smmu_base_reset_hold(Object *obj) | ||
170 | +static void smmu_base_reset_hold(Object *obj, ResetType type) | ||
171 | { | ||
172 | SMMUState *s = ARM_SMMU(obj); | ||
173 | |||
174 | diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c | ||
175 | index XXXXXXX..XXXXXXX 100644 | ||
176 | --- a/hw/arm/smmuv3.c | ||
177 | +++ b/hw/arm/smmuv3.c | ||
178 | @@ -XXX,XX +XXX,XX @@ static void smmu_init_irq(SMMUv3State *s, SysBusDevice *dev) | ||
179 | } | ||
180 | } | ||
181 | |||
182 | -static void smmu_reset_hold(Object *obj) | ||
183 | +static void smmu_reset_hold(Object *obj, ResetType type) | ||
184 | { | ||
185 | SMMUv3State *s = ARM_SMMUV3(obj); | ||
186 | SMMUv3Class *c = ARM_SMMUV3_GET_CLASS(s); | ||
187 | |||
188 | if (c->parent_phases.hold) { | ||
189 | - c->parent_phases.hold(obj); | ||
190 | + c->parent_phases.hold(obj, type); | ||
191 | } | ||
192 | |||
193 | smmuv3_init_regs(s); | ||
194 | diff --git a/hw/arm/stellaris.c b/hw/arm/stellaris.c | ||
195 | index XXXXXXX..XXXXXXX 100644 | ||
196 | --- a/hw/arm/stellaris.c | ||
197 | +++ b/hw/arm/stellaris.c | ||
198 | @@ -XXX,XX +XXX,XX @@ static void stellaris_sys_reset_enter(Object *obj, ResetType type) | ||
199 | s->dcgc[0] = 1; | ||
200 | } | ||
201 | |||
202 | -static void stellaris_sys_reset_hold(Object *obj) | ||
203 | +static void stellaris_sys_reset_hold(Object *obj, ResetType type) | ||
204 | { | ||
205 | ssys_state *s = STELLARIS_SYS(obj); | ||
206 | |||
207 | @@ -XXX,XX +XXX,XX @@ static void stellaris_sys_reset_hold(Object *obj) | ||
208 | ssys_calculate_system_clock(s, true); | ||
209 | } | ||
210 | |||
211 | -static void stellaris_sys_reset_exit(Object *obj) | ||
212 | +static void stellaris_sys_reset_exit(Object *obj, ResetType type) | ||
213 | { | ||
214 | } | ||
215 | |||
216 | @@ -XXX,XX +XXX,XX @@ static void stellaris_i2c_reset_enter(Object *obj, ResetType type) | ||
217 | i2c_end_transfer(s->bus); | ||
218 | } | ||
219 | |||
220 | -static void stellaris_i2c_reset_hold(Object *obj) | ||
221 | +static void stellaris_i2c_reset_hold(Object *obj, ResetType type) | ||
222 | { | ||
223 | stellaris_i2c_state *s = STELLARIS_I2C(obj); | ||
224 | |||
225 | @@ -XXX,XX +XXX,XX @@ static void stellaris_i2c_reset_hold(Object *obj) | ||
226 | s->mcr = 0; | ||
227 | } | ||
228 | |||
229 | -static void stellaris_i2c_reset_exit(Object *obj) | ||
230 | +static void stellaris_i2c_reset_exit(Object *obj, ResetType type) | ||
231 | { | ||
232 | stellaris_i2c_state *s = STELLARIS_I2C(obj); | ||
233 | |||
234 | @@ -XXX,XX +XXX,XX @@ static void stellaris_adc_trigger(void *opaque, int irq, int level) | ||
235 | } | ||
236 | } | ||
237 | |||
238 | -static void stellaris_adc_reset_hold(Object *obj) | ||
239 | +static void stellaris_adc_reset_hold(Object *obj, ResetType type) | ||
240 | { | ||
241 | StellarisADCState *s = STELLARIS_ADC(obj); | ||
242 | int n; | ||
243 | diff --git a/hw/audio/asc.c b/hw/audio/asc.c | ||
244 | index XXXXXXX..XXXXXXX 100644 | ||
245 | --- a/hw/audio/asc.c | ||
246 | +++ b/hw/audio/asc.c | ||
247 | @@ -XXX,XX +XXX,XX @@ static void asc_fifo_init(ASCFIFOState *fs, int index) | ||
248 | g_free(name); | ||
249 | } | ||
250 | |||
251 | -static void asc_reset_hold(Object *obj) | ||
252 | +static void asc_reset_hold(Object *obj, ResetType type) | ||
253 | { | ||
254 | ASCState *s = ASC(obj); | ||
255 | |||
256 | diff --git a/hw/char/cadence_uart.c b/hw/char/cadence_uart.c | ||
257 | index XXXXXXX..XXXXXXX 100644 | ||
258 | --- a/hw/char/cadence_uart.c | ||
259 | +++ b/hw/char/cadence_uart.c | ||
260 | @@ -XXX,XX +XXX,XX @@ static void cadence_uart_reset_init(Object *obj, ResetType type) | ||
261 | s->r[R_TTRIG] = 0x00000020; | ||
262 | } | ||
263 | |||
264 | -static void cadence_uart_reset_hold(Object *obj) | ||
265 | +static void cadence_uart_reset_hold(Object *obj, ResetType type) | ||
266 | { | ||
267 | CadenceUARTState *s = CADENCE_UART(obj); | ||
268 | |||
269 | diff --git a/hw/char/sifive_uart.c b/hw/char/sifive_uart.c | ||
270 | index XXXXXXX..XXXXXXX 100644 | ||
271 | --- a/hw/char/sifive_uart.c | ||
272 | +++ b/hw/char/sifive_uart.c | ||
273 | @@ -XXX,XX +XXX,XX @@ static void sifive_uart_reset_enter(Object *obj, ResetType type) | ||
274 | s->rx_fifo_len = 0; | ||
275 | } | ||
276 | |||
277 | -static void sifive_uart_reset_hold(Object *obj) | ||
278 | +static void sifive_uart_reset_hold(Object *obj, ResetType type) | ||
279 | { | ||
280 | SiFiveUARTState *s = SIFIVE_UART(obj); | ||
281 | qemu_irq_lower(s->irq); | ||
282 | diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c | ||
283 | index XXXXXXX..XXXXXXX 100644 | ||
284 | --- a/hw/core/cpu-common.c | ||
285 | +++ b/hw/core/cpu-common.c | ||
286 | @@ -XXX,XX +XXX,XX @@ void cpu_reset(CPUState *cpu) | ||
287 | trace_cpu_reset(cpu->cpu_index); | ||
288 | } | ||
289 | |||
290 | -static void cpu_common_reset_hold(Object *obj) | ||
291 | +static void cpu_common_reset_hold(Object *obj, ResetType type) | ||
292 | { | ||
293 | CPUState *cpu = CPU(obj); | ||
294 | CPUClass *cc = CPU_GET_CLASS(cpu); | ||
295 | diff --git a/hw/core/qdev.c b/hw/core/qdev.c | ||
296 | index XXXXXXX..XXXXXXX 100644 | ||
297 | --- a/hw/core/qdev.c | ||
298 | +++ b/hw/core/qdev.c | ||
299 | @@ -XXX,XX +XXX,XX @@ static void device_phases_reset(DeviceState *dev) | ||
300 | rc->phases.enter(OBJECT(dev), RESET_TYPE_COLD); | ||
301 | } | ||
302 | if (rc->phases.hold) { | ||
303 | - rc->phases.hold(OBJECT(dev)); | ||
304 | + rc->phases.hold(OBJECT(dev), RESET_TYPE_COLD); | ||
305 | } | ||
306 | if (rc->phases.exit) { | ||
307 | - rc->phases.exit(OBJECT(dev)); | ||
308 | + rc->phases.exit(OBJECT(dev), RESET_TYPE_COLD); | ||
309 | } | ||
310 | } | ||
311 | |||
312 | diff --git a/hw/core/reset.c b/hw/core/reset.c | ||
313 | index XXXXXXX..XXXXXXX 100644 | ||
314 | --- a/hw/core/reset.c | ||
315 | +++ b/hw/core/reset.c | ||
316 | @@ -XXX,XX +XXX,XX @@ static ResettableState *legacy_reset_get_state(Object *obj) | ||
317 | return &lr->reset_state; | ||
318 | } | ||
319 | |||
320 | -static void legacy_reset_hold(Object *obj) | ||
321 | +static void legacy_reset_hold(Object *obj, ResetType type) | ||
322 | { | ||
323 | LegacyReset *lr = LEGACY_RESET(obj); | ||
324 | |||
325 | diff --git a/hw/core/resettable.c b/hw/core/resettable.c | ||
326 | index XXXXXXX..XXXXXXX 100644 | ||
327 | --- a/hw/core/resettable.c | ||
328 | +++ b/hw/core/resettable.c | ||
329 | @@ -XXX,XX +XXX,XX @@ static void resettable_phase_hold(Object *obj, void *opaque, ResetType type) | ||
330 | trace_resettable_transitional_function(obj, obj_typename); | ||
331 | tr_func(obj); | ||
332 | } else if (rc->phases.hold) { | ||
333 | - rc->phases.hold(obj); | ||
334 | + rc->phases.hold(obj, type); | ||
335 | } | ||
336 | } | ||
337 | trace_resettable_phase_hold_end(obj, obj_typename, s->count); | ||
338 | @@ -XXX,XX +XXX,XX @@ static void resettable_phase_exit(Object *obj, void *opaque, ResetType type) | ||
339 | if (--s->count == 0) { | ||
340 | trace_resettable_phase_exit_exec(obj, obj_typename, !!rc->phases.exit); | ||
341 | if (rc->phases.exit && !resettable_get_tr_func(rc, obj)) { | ||
342 | - rc->phases.exit(obj); | ||
343 | + rc->phases.exit(obj, type); | ||
344 | } | ||
345 | } | ||
346 | s->exit_phase_in_progress = false; | ||
347 | diff --git a/hw/display/virtio-vga.c b/hw/display/virtio-vga.c | ||
348 | index XXXXXXX..XXXXXXX 100644 | ||
349 | --- a/hw/display/virtio-vga.c | ||
350 | +++ b/hw/display/virtio-vga.c | ||
351 | @@ -XXX,XX +XXX,XX @@ static void virtio_vga_base_realize(VirtIOPCIProxy *vpci_dev, Error **errp) | ||
352 | } | ||
353 | } | ||
354 | |||
355 | -static void virtio_vga_base_reset_hold(Object *obj) | ||
356 | +static void virtio_vga_base_reset_hold(Object *obj, ResetType type) | ||
357 | { | ||
358 | VirtIOVGABaseClass *klass = VIRTIO_VGA_BASE_GET_CLASS(obj); | ||
359 | VirtIOVGABase *vvga = VIRTIO_VGA_BASE(obj); | ||
360 | |||
361 | /* reset virtio-gpu */ | ||
362 | if (klass->parent_phases.hold) { | ||
363 | - klass->parent_phases.hold(obj); | ||
364 | + klass->parent_phases.hold(obj, type); | ||
365 | } | ||
366 | |||
367 | /* reset vga */ | ||
368 | diff --git a/hw/gpio/npcm7xx_gpio.c b/hw/gpio/npcm7xx_gpio.c | ||
369 | index XXXXXXX..XXXXXXX 100644 | ||
370 | --- a/hw/gpio/npcm7xx_gpio.c | ||
371 | +++ b/hw/gpio/npcm7xx_gpio.c | ||
372 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_gpio_enter_reset(Object *obj, ResetType type) | ||
373 | s->regs[NPCM7XX_GPIO_ODSC] = s->reset_odsc; | ||
374 | } | ||
375 | |||
376 | -static void npcm7xx_gpio_hold_reset(Object *obj) | ||
377 | +static void npcm7xx_gpio_hold_reset(Object *obj, ResetType type) | ||
378 | { | ||
379 | NPCM7xxGPIOState *s = NPCM7XX_GPIO(obj); | ||
380 | |||
381 | diff --git a/hw/gpio/pl061.c b/hw/gpio/pl061.c | ||
382 | index XXXXXXX..XXXXXXX 100644 | ||
383 | --- a/hw/gpio/pl061.c | ||
384 | +++ b/hw/gpio/pl061.c | ||
385 | @@ -XXX,XX +XXX,XX @@ static void pl061_enter_reset(Object *obj, ResetType type) | ||
386 | s->amsel = 0; | ||
387 | } | ||
388 | |||
389 | -static void pl061_hold_reset(Object *obj) | ||
390 | +static void pl061_hold_reset(Object *obj, ResetType type) | ||
391 | { | ||
392 | PL061State *s = PL061(obj); | ||
393 | int i, level; | ||
394 | diff --git a/hw/gpio/stm32l4x5_gpio.c b/hw/gpio/stm32l4x5_gpio.c | ||
395 | index XXXXXXX..XXXXXXX 100644 | ||
396 | --- a/hw/gpio/stm32l4x5_gpio.c | ||
397 | +++ b/hw/gpio/stm32l4x5_gpio.c | ||
398 | @@ -XXX,XX +XXX,XX @@ static bool is_push_pull(Stm32l4x5GpioState *s, unsigned pin) | ||
399 | return extract32(s->otyper, pin, 1) == 0; | ||
400 | } | ||
401 | |||
402 | -static void stm32l4x5_gpio_reset_hold(Object *obj) | ||
403 | +static void stm32l4x5_gpio_reset_hold(Object *obj, ResetType type) | ||
404 | { | ||
405 | Stm32l4x5GpioState *s = STM32L4X5_GPIO(obj); | ||
406 | |||
407 | diff --git a/hw/hyperv/vmbus.c b/hw/hyperv/vmbus.c | ||
408 | index XXXXXXX..XXXXXXX 100644 | ||
409 | --- a/hw/hyperv/vmbus.c | ||
410 | +++ b/hw/hyperv/vmbus.c | ||
411 | @@ -XXX,XX +XXX,XX @@ static void vmbus_unrealize(BusState *bus) | ||
412 | qemu_mutex_destroy(&vmbus->rx_queue_lock); | ||
413 | } | ||
414 | |||
415 | -static void vmbus_reset_hold(Object *obj) | ||
416 | +static void vmbus_reset_hold(Object *obj, ResetType type) | ||
417 | { | ||
418 | vmbus_deinit(VMBUS(obj)); | ||
419 | } | ||
420 | diff --git a/hw/i2c/allwinner-i2c.c b/hw/i2c/allwinner-i2c.c | ||
421 | index XXXXXXX..XXXXXXX 100644 | ||
422 | --- a/hw/i2c/allwinner-i2c.c | ||
423 | +++ b/hw/i2c/allwinner-i2c.c | ||
424 | @@ -XXX,XX +XXX,XX @@ static inline bool allwinner_i2c_interrupt_is_enabled(AWI2CState *s) | ||
425 | return s->cntr & TWI_CNTR_INT_EN; | ||
426 | } | ||
427 | |||
428 | -static void allwinner_i2c_reset_hold(Object *obj) | ||
429 | +static void allwinner_i2c_reset_hold(Object *obj, ResetType type) | ||
430 | { | ||
431 | AWI2CState *s = AW_I2C(obj); | ||
432 | |||
433 | diff --git a/hw/i2c/npcm7xx_smbus.c b/hw/i2c/npcm7xx_smbus.c | ||
434 | index XXXXXXX..XXXXXXX 100644 | ||
435 | --- a/hw/i2c/npcm7xx_smbus.c | ||
436 | +++ b/hw/i2c/npcm7xx_smbus.c | ||
437 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_smbus_enter_reset(Object *obj, ResetType type) | ||
438 | s->rx_cur = 0; | ||
439 | } | ||
440 | |||
441 | -static void npcm7xx_smbus_hold_reset(Object *obj) | ||
442 | +static void npcm7xx_smbus_hold_reset(Object *obj, ResetType type) | ||
443 | { | ||
444 | NPCM7xxSMBusState *s = NPCM7XX_SMBUS(obj); | ||
445 | |||
446 | diff --git a/hw/input/adb.c b/hw/input/adb.c | ||
447 | index XXXXXXX..XXXXXXX 100644 | ||
448 | --- a/hw/input/adb.c | ||
449 | +++ b/hw/input/adb.c | ||
450 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_adb_bus = { | ||
451 | } | ||
452 | }; | ||
453 | |||
454 | -static void adb_bus_reset_hold(Object *obj) | ||
455 | +static void adb_bus_reset_hold(Object *obj, ResetType type) | ||
456 | { | ||
457 | ADBBusState *adb_bus = ADB_BUS(obj); | ||
458 | |||
459 | diff --git a/hw/input/ps2.c b/hw/input/ps2.c | ||
460 | index XXXXXXX..XXXXXXX 100644 | ||
461 | --- a/hw/input/ps2.c | ||
462 | +++ b/hw/input/ps2.c | ||
463 | @@ -XXX,XX +XXX,XX @@ void ps2_write_mouse(PS2MouseState *s, int val) | ||
464 | } | ||
465 | } | ||
466 | |||
467 | -static void ps2_reset_hold(Object *obj) | ||
468 | +static void ps2_reset_hold(Object *obj, ResetType type) | ||
469 | { | ||
470 | PS2State *s = PS2_DEVICE(obj); | ||
471 | |||
472 | @@ -XXX,XX +XXX,XX @@ static void ps2_reset_hold(Object *obj) | ||
473 | ps2_reset_queue(s); | ||
474 | } | ||
475 | |||
476 | -static void ps2_reset_exit(Object *obj) | ||
477 | +static void ps2_reset_exit(Object *obj, ResetType type) | ||
478 | { | ||
479 | PS2State *s = PS2_DEVICE(obj); | ||
480 | |||
481 | @@ -XXX,XX +XXX,XX @@ static void ps2_common_post_load(PS2State *s) | ||
482 | q->cwptr = ccount ? (q->rptr + ccount) & (PS2_BUFFER_SIZE - 1) : -1; | ||
483 | } | ||
484 | |||
485 | -static void ps2_kbd_reset_hold(Object *obj) | ||
486 | +static void ps2_kbd_reset_hold(Object *obj, ResetType type) | ||
487 | { | ||
488 | PS2DeviceClass *ps2dc = PS2_DEVICE_GET_CLASS(obj); | ||
489 | PS2KbdState *s = PS2_KBD_DEVICE(obj); | ||
490 | @@ -XXX,XX +XXX,XX @@ static void ps2_kbd_reset_hold(Object *obj) | ||
491 | trace_ps2_kbd_reset(s); | ||
492 | |||
493 | if (ps2dc->parent_phases.hold) { | ||
494 | - ps2dc->parent_phases.hold(obj); | ||
495 | + ps2dc->parent_phases.hold(obj, type); | ||
496 | } | ||
497 | |||
498 | s->scan_enabled = 1; | ||
499 | @@ -XXX,XX +XXX,XX @@ static void ps2_kbd_reset_hold(Object *obj) | ||
500 | s->modifiers = 0; | ||
501 | } | ||
502 | |||
503 | -static void ps2_mouse_reset_hold(Object *obj) | ||
504 | +static void ps2_mouse_reset_hold(Object *obj, ResetType type) | ||
505 | { | ||
506 | PS2DeviceClass *ps2dc = PS2_DEVICE_GET_CLASS(obj); | ||
507 | PS2MouseState *s = PS2_MOUSE_DEVICE(obj); | ||
508 | @@ -XXX,XX +XXX,XX @@ static void ps2_mouse_reset_hold(Object *obj) | ||
509 | trace_ps2_mouse_reset(s); | ||
510 | |||
511 | if (ps2dc->parent_phases.hold) { | ||
512 | - ps2dc->parent_phases.hold(obj); | ||
513 | + ps2dc->parent_phases.hold(obj, type); | ||
514 | } | ||
515 | |||
516 | s->mouse_status = 0; | ||
517 | diff --git a/hw/intc/arm_gic_common.c b/hw/intc/arm_gic_common.c | ||
518 | index XXXXXXX..XXXXXXX 100644 | ||
519 | --- a/hw/intc/arm_gic_common.c | ||
520 | +++ b/hw/intc/arm_gic_common.c | ||
521 | @@ -XXX,XX +XXX,XX @@ static inline void arm_gic_common_reset_irq_state(GICState *s, int cidx, | ||
522 | } | ||
523 | } | ||
524 | |||
525 | -static void arm_gic_common_reset_hold(Object *obj) | ||
526 | +static void arm_gic_common_reset_hold(Object *obj, ResetType type) | ||
527 | { | ||
528 | GICState *s = ARM_GIC_COMMON(obj); | ||
529 | int i, j; | ||
530 | diff --git a/hw/intc/arm_gic_kvm.c b/hw/intc/arm_gic_kvm.c | ||
531 | index XXXXXXX..XXXXXXX 100644 | ||
532 | --- a/hw/intc/arm_gic_kvm.c | ||
533 | +++ b/hw/intc/arm_gic_kvm.c | ||
534 | @@ -XXX,XX +XXX,XX @@ static void kvm_arm_gic_get(GICState *s) | ||
535 | } | ||
536 | } | ||
537 | |||
538 | -static void kvm_arm_gic_reset_hold(Object *obj) | ||
539 | +static void kvm_arm_gic_reset_hold(Object *obj, ResetType type) | ||
540 | { | ||
541 | GICState *s = ARM_GIC_COMMON(obj); | ||
542 | KVMARMGICClass *kgc = KVM_ARM_GIC_GET_CLASS(s); | ||
543 | |||
544 | if (kgc->parent_phases.hold) { | ||
545 | - kgc->parent_phases.hold(obj); | ||
546 | + kgc->parent_phases.hold(obj, type); | ||
547 | } | ||
548 | |||
549 | if (kvm_arm_gic_can_save_restore(s)) { | ||
550 | diff --git a/hw/intc/arm_gicv3_common.c b/hw/intc/arm_gicv3_common.c | ||
551 | index XXXXXXX..XXXXXXX 100644 | ||
552 | --- a/hw/intc/arm_gicv3_common.c | ||
553 | +++ b/hw/intc/arm_gicv3_common.c | ||
554 | @@ -XXX,XX +XXX,XX @@ static void arm_gicv3_finalize(Object *obj) | ||
555 | g_free(s->redist_region_count); | ||
556 | } | ||
557 | |||
558 | -static void arm_gicv3_common_reset_hold(Object *obj) | ||
559 | +static void arm_gicv3_common_reset_hold(Object *obj, ResetType type) | ||
560 | { | ||
561 | GICv3State *s = ARM_GICV3_COMMON(obj); | ||
562 | int i; | ||
563 | diff --git a/hw/intc/arm_gicv3_its.c b/hw/intc/arm_gicv3_its.c | ||
564 | index XXXXXXX..XXXXXXX 100644 | ||
565 | --- a/hw/intc/arm_gicv3_its.c | ||
566 | +++ b/hw/intc/arm_gicv3_its.c | ||
567 | @@ -XXX,XX +XXX,XX @@ static void gicv3_arm_its_realize(DeviceState *dev, Error **errp) | ||
568 | } | ||
569 | } | ||
570 | |||
571 | -static void gicv3_its_reset_hold(Object *obj) | ||
572 | +static void gicv3_its_reset_hold(Object *obj, ResetType type) | ||
573 | { | ||
574 | GICv3ITSState *s = ARM_GICV3_ITS_COMMON(obj); | ||
575 | GICv3ITSClass *c = ARM_GICV3_ITS_GET_CLASS(s); | ||
576 | |||
577 | if (c->parent_phases.hold) { | ||
578 | - c->parent_phases.hold(obj); | ||
579 | + c->parent_phases.hold(obj, type); | ||
580 | } | ||
581 | |||
582 | /* Quiescent bit reset to 1 */ | ||
583 | diff --git a/hw/intc/arm_gicv3_its_common.c b/hw/intc/arm_gicv3_its_common.c | ||
584 | index XXXXXXX..XXXXXXX 100644 | ||
585 | --- a/hw/intc/arm_gicv3_its_common.c | ||
586 | +++ b/hw/intc/arm_gicv3_its_common.c | ||
587 | @@ -XXX,XX +XXX,XX @@ void gicv3_its_init_mmio(GICv3ITSState *s, const MemoryRegionOps *ops, | ||
588 | msi_nonbroken = true; | ||
589 | } | ||
590 | |||
591 | -static void gicv3_its_common_reset_hold(Object *obj) | ||
592 | +static void gicv3_its_common_reset_hold(Object *obj, ResetType type) | ||
593 | { | ||
594 | GICv3ITSState *s = ARM_GICV3_ITS_COMMON(obj); | ||
595 | |||
596 | diff --git a/hw/intc/arm_gicv3_its_kvm.c b/hw/intc/arm_gicv3_its_kvm.c | ||
597 | index XXXXXXX..XXXXXXX 100644 | ||
598 | --- a/hw/intc/arm_gicv3_its_kvm.c | ||
599 | +++ b/hw/intc/arm_gicv3_its_kvm.c | ||
600 | @@ -XXX,XX +XXX,XX @@ static void kvm_arm_its_post_load(GICv3ITSState *s) | ||
601 | GITS_CTLR, &s->ctlr, true, &error_abort); | ||
602 | } | ||
603 | |||
604 | -static void kvm_arm_its_reset_hold(Object *obj) | ||
605 | +static void kvm_arm_its_reset_hold(Object *obj, ResetType type) | ||
606 | { | ||
607 | GICv3ITSState *s = ARM_GICV3_ITS_COMMON(obj); | ||
608 | KVMARMITSClass *c = KVM_ARM_ITS_GET_CLASS(s); | ||
609 | int i; | ||
610 | |||
611 | if (c->parent_phases.hold) { | ||
612 | - c->parent_phases.hold(obj); | ||
613 | + c->parent_phases.hold(obj, type); | ||
614 | } | ||
615 | |||
616 | if (kvm_device_check_attr(s->dev_fd, KVM_DEV_ARM_VGIC_GRP_CTRL, | ||
617 | diff --git a/hw/intc/arm_gicv3_kvm.c b/hw/intc/arm_gicv3_kvm.c | ||
618 | index XXXXXXX..XXXXXXX 100644 | ||
619 | --- a/hw/intc/arm_gicv3_kvm.c | ||
620 | +++ b/hw/intc/arm_gicv3_kvm.c | ||
621 | @@ -XXX,XX +XXX,XX @@ static void arm_gicv3_icc_reset(CPUARMState *env, const ARMCPRegInfo *ri) | ||
622 | c->icc_ctlr_el1[GICV3_S] = c->icc_ctlr_el1[GICV3_NS]; | ||
623 | } | ||
624 | |||
625 | -static void kvm_arm_gicv3_reset_hold(Object *obj) | ||
626 | +static void kvm_arm_gicv3_reset_hold(Object *obj, ResetType type) | ||
627 | { | ||
628 | GICv3State *s = ARM_GICV3_COMMON(obj); | ||
629 | KVMARMGICv3Class *kgc = KVM_ARM_GICV3_GET_CLASS(s); | ||
630 | @@ -XXX,XX +XXX,XX @@ static void kvm_arm_gicv3_reset_hold(Object *obj) | ||
631 | DPRINTF("Reset\n"); | ||
632 | |||
633 | if (kgc->parent_phases.hold) { | ||
634 | - kgc->parent_phases.hold(obj); | ||
635 | + kgc->parent_phases.hold(obj, type); | ||
636 | } | ||
637 | |||
638 | if (s->migration_blocker) { | ||
639 | diff --git a/hw/intc/xics.c b/hw/intc/xics.c | ||
640 | index XXXXXXX..XXXXXXX 100644 | ||
641 | --- a/hw/intc/xics.c | ||
642 | +++ b/hw/intc/xics.c | ||
643 | @@ -XXX,XX +XXX,XX @@ static void ics_reset_irq(ICSIRQState *irq) | ||
644 | irq->saved_priority = 0xff; | ||
645 | } | ||
646 | |||
647 | -static void ics_reset_hold(Object *obj) | ||
648 | +static void ics_reset_hold(Object *obj, ResetType type) | ||
649 | { | ||
650 | ICSState *ics = ICS(obj); | ||
651 | g_autofree uint8_t *flags = g_malloc(ics->nr_irqs); | ||
652 | diff --git a/hw/m68k/q800-glue.c b/hw/m68k/q800-glue.c | ||
653 | index XXXXXXX..XXXXXXX 100644 | ||
654 | --- a/hw/m68k/q800-glue.c | ||
655 | +++ b/hw/m68k/q800-glue.c | ||
656 | @@ -XXX,XX +XXX,XX @@ static void glue_nmi_release(void *opaque) | ||
657 | GLUE_set_irq(s, GLUE_IRQ_IN_NMI, 0); | ||
658 | } | ||
659 | |||
660 | -static void glue_reset_hold(Object *obj) | ||
661 | +static void glue_reset_hold(Object *obj, ResetType type) | ||
662 | { | ||
663 | GLUEState *s = GLUE(obj); | ||
664 | |||
665 | diff --git a/hw/misc/djmemc.c b/hw/misc/djmemc.c | ||
666 | index XXXXXXX..XXXXXXX 100644 | ||
667 | --- a/hw/misc/djmemc.c | ||
668 | +++ b/hw/misc/djmemc.c | ||
669 | @@ -XXX,XX +XXX,XX @@ static void djmemc_init(Object *obj) | ||
670 | sysbus_init_mmio(sbd, &s->mem_regs); | ||
671 | } | ||
672 | |||
673 | -static void djmemc_reset_hold(Object *obj) | ||
674 | +static void djmemc_reset_hold(Object *obj, ResetType type) | ||
675 | { | ||
676 | DJMEMCState *s = DJMEMC(obj); | ||
677 | |||
678 | diff --git a/hw/misc/iosb.c b/hw/misc/iosb.c | ||
679 | index XXXXXXX..XXXXXXX 100644 | ||
680 | --- a/hw/misc/iosb.c | ||
681 | +++ b/hw/misc/iosb.c | ||
682 | @@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps iosb_mmio_ops = { | ||
683 | .endianness = DEVICE_BIG_ENDIAN, | ||
684 | }; | ||
685 | |||
686 | -static void iosb_reset_hold(Object *obj) | ||
687 | +static void iosb_reset_hold(Object *obj, ResetType type) | ||
688 | { | ||
689 | IOSBState *s = IOSB(obj); | ||
690 | |||
691 | diff --git a/hw/misc/mac_via.c b/hw/misc/mac_via.c | ||
692 | index XXXXXXX..XXXXXXX 100644 | ||
693 | --- a/hw/misc/mac_via.c | ||
694 | +++ b/hw/misc/mac_via.c | ||
695 | @@ -XXX,XX +XXX,XX @@ static int via1_post_load(void *opaque, int version_id) | ||
696 | } | ||
697 | |||
698 | /* VIA 1 */ | ||
699 | -static void mos6522_q800_via1_reset_hold(Object *obj) | ||
700 | +static void mos6522_q800_via1_reset_hold(Object *obj, ResetType type) | ||
701 | { | ||
702 | MOS6522Q800VIA1State *v1s = MOS6522_Q800_VIA1(obj); | ||
703 | MOS6522State *ms = MOS6522(v1s); | ||
704 | @@ -XXX,XX +XXX,XX @@ static void mos6522_q800_via1_reset_hold(Object *obj) | ||
705 | ADBBusState *adb_bus = &v1s->adb_bus; | ||
706 | |||
707 | if (mdc->parent_phases.hold) { | ||
708 | - mdc->parent_phases.hold(obj); | ||
709 | + mdc->parent_phases.hold(obj, type); | ||
710 | } | ||
711 | |||
712 | ms->timers[0].frequency = VIA_TIMER_FREQ; | ||
713 | @@ -XXX,XX +XXX,XX @@ static void mos6522_q800_via2_portB_write(MOS6522State *s) | ||
714 | } | ||
715 | } | ||
716 | |||
717 | -static void mos6522_q800_via2_reset_hold(Object *obj) | ||
718 | +static void mos6522_q800_via2_reset_hold(Object *obj, ResetType type) | ||
719 | { | ||
720 | MOS6522State *ms = MOS6522(obj); | ||
721 | MOS6522DeviceClass *mdc = MOS6522_GET_CLASS(ms); | ||
722 | |||
723 | if (mdc->parent_phases.hold) { | ||
724 | - mdc->parent_phases.hold(obj); | ||
725 | + mdc->parent_phases.hold(obj, type); | ||
726 | } | ||
727 | |||
728 | ms->timers[0].frequency = VIA_TIMER_FREQ; | ||
729 | diff --git a/hw/misc/macio/cuda.c b/hw/misc/macio/cuda.c | ||
730 | index XXXXXXX..XXXXXXX 100644 | ||
731 | --- a/hw/misc/macio/cuda.c | ||
732 | +++ b/hw/misc/macio/cuda.c | ||
733 | @@ -XXX,XX +XXX,XX @@ static void mos6522_cuda_portB_write(MOS6522State *s) | ||
734 | cuda_update(cs); | ||
735 | } | ||
736 | |||
737 | -static void mos6522_cuda_reset_hold(Object *obj) | ||
738 | +static void mos6522_cuda_reset_hold(Object *obj, ResetType type) | ||
739 | { | ||
740 | MOS6522State *ms = MOS6522(obj); | ||
741 | MOS6522DeviceClass *mdc = MOS6522_GET_CLASS(ms); | ||
742 | |||
743 | if (mdc->parent_phases.hold) { | ||
744 | - mdc->parent_phases.hold(obj); | ||
745 | + mdc->parent_phases.hold(obj, type); | ||
746 | } | ||
747 | |||
748 | ms->timers[0].frequency = CUDA_TIMER_FREQ; | ||
749 | diff --git a/hw/misc/macio/pmu.c b/hw/misc/macio/pmu.c | ||
750 | index XXXXXXX..XXXXXXX 100644 | ||
751 | --- a/hw/misc/macio/pmu.c | ||
752 | +++ b/hw/misc/macio/pmu.c | ||
753 | @@ -XXX,XX +XXX,XX @@ static void mos6522_pmu_portB_write(MOS6522State *s) | ||
754 | pmu_update(ps); | ||
755 | } | ||
756 | |||
757 | -static void mos6522_pmu_reset_hold(Object *obj) | ||
758 | +static void mos6522_pmu_reset_hold(Object *obj, ResetType type) | ||
759 | { | ||
760 | MOS6522State *ms = MOS6522(obj); | ||
761 | MOS6522PMUState *mps = container_of(ms, MOS6522PMUState, parent_obj); | ||
762 | @@ -XXX,XX +XXX,XX @@ static void mos6522_pmu_reset_hold(Object *obj) | ||
763 | MOS6522DeviceClass *mdc = MOS6522_GET_CLASS(ms); | ||
764 | |||
765 | if (mdc->parent_phases.hold) { | ||
766 | - mdc->parent_phases.hold(obj); | ||
767 | + mdc->parent_phases.hold(obj, type); | ||
768 | } | ||
769 | |||
770 | ms->timers[0].frequency = VIA_TIMER_FREQ; | ||
771 | diff --git a/hw/misc/mos6522.c b/hw/misc/mos6522.c | ||
772 | index XXXXXXX..XXXXXXX 100644 | ||
773 | --- a/hw/misc/mos6522.c | ||
774 | +++ b/hw/misc/mos6522.c | ||
775 | @@ -XXX,XX +XXX,XX @@ const VMStateDescription vmstate_mos6522 = { | ||
776 | } | ||
777 | }; | ||
778 | |||
779 | -static void mos6522_reset_hold(Object *obj) | ||
780 | +static void mos6522_reset_hold(Object *obj, ResetType type) | ||
781 | { | ||
782 | MOS6522State *s = MOS6522(obj); | ||
783 | |||
784 | diff --git a/hw/misc/npcm7xx_mft.c b/hw/misc/npcm7xx_mft.c | ||
785 | index XXXXXXX..XXXXXXX 100644 | ||
786 | --- a/hw/misc/npcm7xx_mft.c | ||
787 | +++ b/hw/misc/npcm7xx_mft.c | ||
788 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_mft_enter_reset(Object *obj, ResetType type) | ||
789 | npcm7xx_mft_reset(s); | ||
790 | } | ||
791 | |||
792 | -static void npcm7xx_mft_hold_reset(Object *obj) | ||
793 | +static void npcm7xx_mft_hold_reset(Object *obj, ResetType type) | ||
794 | { | ||
795 | NPCM7xxMFTState *s = NPCM7XX_MFT(obj); | ||
796 | |||
797 | diff --git a/hw/misc/npcm7xx_pwm.c b/hw/misc/npcm7xx_pwm.c | ||
798 | index XXXXXXX..XXXXXXX 100644 | ||
799 | --- a/hw/misc/npcm7xx_pwm.c | ||
800 | +++ b/hw/misc/npcm7xx_pwm.c | ||
801 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_pwm_enter_reset(Object *obj, ResetType type) | ||
802 | s->piir = 0x00000000; | ||
803 | } | ||
804 | |||
805 | -static void npcm7xx_pwm_hold_reset(Object *obj) | ||
806 | +static void npcm7xx_pwm_hold_reset(Object *obj, ResetType type) | ||
807 | { | ||
808 | NPCM7xxPWMState *s = NPCM7XX_PWM(obj); | ||
809 | int i; | ||
810 | diff --git a/hw/misc/stm32l4x5_exti.c b/hw/misc/stm32l4x5_exti.c | ||
811 | index XXXXXXX..XXXXXXX 100644 | ||
812 | --- a/hw/misc/stm32l4x5_exti.c | ||
813 | +++ b/hw/misc/stm32l4x5_exti.c | ||
814 | @@ -XXX,XX +XXX,XX @@ static unsigned configurable_mask(unsigned bank) | ||
815 | return valid_mask(bank) & ~exti_romask[bank]; | ||
816 | } | ||
817 | |||
818 | -static void stm32l4x5_exti_reset_hold(Object *obj) | ||
819 | +static void stm32l4x5_exti_reset_hold(Object *obj, ResetType type) | ||
820 | { | ||
821 | Stm32l4x5ExtiState *s = STM32L4X5_EXTI(obj); | ||
822 | |||
823 | diff --git a/hw/misc/stm32l4x5_rcc.c b/hw/misc/stm32l4x5_rcc.c | ||
824 | index XXXXXXX..XXXXXXX 100644 | ||
825 | --- a/hw/misc/stm32l4x5_rcc.c | ||
826 | +++ b/hw/misc/stm32l4x5_rcc.c | ||
827 | @@ -XXX,XX +XXX,XX @@ static void clock_mux_reset_enter(Object *obj, ResetType type) | ||
828 | set_clock_mux_init_info(s, s->id); | ||
829 | } | ||
830 | |||
831 | -static void clock_mux_reset_hold(Object *obj) | ||
832 | +static void clock_mux_reset_hold(Object *obj, ResetType type) | ||
833 | { | ||
834 | RccClockMuxState *s = RCC_CLOCK_MUX(obj); | ||
835 | clock_mux_update(s, true); | ||
836 | } | ||
837 | |||
838 | -static void clock_mux_reset_exit(Object *obj) | ||
839 | +static void clock_mux_reset_exit(Object *obj, ResetType type) | ||
840 | { | ||
841 | RccClockMuxState *s = RCC_CLOCK_MUX(obj); | ||
842 | clock_mux_update(s, false); | ||
843 | @@ -XXX,XX +XXX,XX @@ static void pll_reset_enter(Object *obj, ResetType type) | ||
844 | set_pll_init_info(s, s->id); | ||
845 | } | ||
846 | |||
847 | -static void pll_reset_hold(Object *obj) | ||
848 | +static void pll_reset_hold(Object *obj, ResetType type) | ||
849 | { | ||
850 | RccPllState *s = RCC_PLL(obj); | ||
851 | pll_update(s, true); | ||
852 | } | ||
853 | |||
854 | -static void pll_reset_exit(Object *obj) | ||
855 | +static void pll_reset_exit(Object *obj, ResetType type) | ||
856 | { | ||
857 | RccPllState *s = RCC_PLL(obj); | ||
858 | pll_update(s, false); | ||
859 | @@ -XXX,XX +XXX,XX @@ static void rcc_update_csr(Stm32l4x5RccState *s) | ||
860 | rcc_update_irq(s); | ||
861 | } | ||
862 | |||
863 | -static void stm32l4x5_rcc_reset_hold(Object *obj) | ||
864 | +static void stm32l4x5_rcc_reset_hold(Object *obj, ResetType type) | ||
865 | { | ||
866 | Stm32l4x5RccState *s = STM32L4X5_RCC(obj); | ||
867 | s->cr = 0x00000063; | ||
868 | diff --git a/hw/misc/stm32l4x5_syscfg.c b/hw/misc/stm32l4x5_syscfg.c | ||
869 | index XXXXXXX..XXXXXXX 100644 | ||
870 | --- a/hw/misc/stm32l4x5_syscfg.c | ||
871 | +++ b/hw/misc/stm32l4x5_syscfg.c | ||
872 | @@ -XXX,XX +XXX,XX @@ | ||
873 | |||
874 | #define NUM_LINES_PER_EXTICR_REG 4 | ||
875 | |||
876 | -static void stm32l4x5_syscfg_hold_reset(Object *obj) | ||
877 | +static void stm32l4x5_syscfg_hold_reset(Object *obj, ResetType type) | ||
878 | { | ||
879 | Stm32l4x5SyscfgState *s = STM32L4X5_SYSCFG(obj); | ||
880 | |||
881 | diff --git a/hw/misc/xlnx-versal-cframe-reg.c b/hw/misc/xlnx-versal-cframe-reg.c | ||
882 | index XXXXXXX..XXXXXXX 100644 | ||
883 | --- a/hw/misc/xlnx-versal-cframe-reg.c | ||
884 | +++ b/hw/misc/xlnx-versal-cframe-reg.c | ||
885 | @@ -XXX,XX +XXX,XX @@ static void cframe_reg_reset_enter(Object *obj, ResetType type) | ||
886 | } | ||
887 | } | ||
888 | |||
889 | -static void cframe_reg_reset_hold(Object *obj) | ||
890 | +static void cframe_reg_reset_hold(Object *obj, ResetType type) | ||
891 | { | ||
892 | XlnxVersalCFrameReg *s = XLNX_VERSAL_CFRAME_REG(obj); | ||
893 | |||
894 | diff --git a/hw/misc/xlnx-versal-crl.c b/hw/misc/xlnx-versal-crl.c | ||
895 | index XXXXXXX..XXXXXXX 100644 | ||
896 | --- a/hw/misc/xlnx-versal-crl.c | ||
897 | +++ b/hw/misc/xlnx-versal-crl.c | ||
898 | @@ -XXX,XX +XXX,XX @@ static void crl_reset_enter(Object *obj, ResetType type) | ||
899 | } | ||
900 | } | ||
901 | |||
902 | -static void crl_reset_hold(Object *obj) | ||
903 | +static void crl_reset_hold(Object *obj, ResetType type) | ||
904 | { | ||
905 | XlnxVersalCRL *s = XLNX_VERSAL_CRL(obj); | ||
906 | |||
907 | diff --git a/hw/misc/xlnx-versal-pmc-iou-slcr.c b/hw/misc/xlnx-versal-pmc-iou-slcr.c | ||
908 | index XXXXXXX..XXXXXXX 100644 | ||
909 | --- a/hw/misc/xlnx-versal-pmc-iou-slcr.c | ||
910 | +++ b/hw/misc/xlnx-versal-pmc-iou-slcr.c | ||
911 | @@ -XXX,XX +XXX,XX @@ static void xlnx_versal_pmc_iou_slcr_reset_init(Object *obj, ResetType type) | ||
912 | } | ||
913 | } | ||
914 | |||
915 | -static void xlnx_versal_pmc_iou_slcr_reset_hold(Object *obj) | ||
916 | +static void xlnx_versal_pmc_iou_slcr_reset_hold(Object *obj, ResetType type) | ||
917 | { | ||
918 | XlnxVersalPmcIouSlcr *s = XILINX_VERSAL_PMC_IOU_SLCR(obj); | ||
919 | |||
920 | diff --git a/hw/misc/xlnx-versal-trng.c b/hw/misc/xlnx-versal-trng.c | ||
921 | index XXXXXXX..XXXXXXX 100644 | ||
922 | --- a/hw/misc/xlnx-versal-trng.c | ||
923 | +++ b/hw/misc/xlnx-versal-trng.c | ||
924 | @@ -XXX,XX +XXX,XX @@ static void trng_unrealize(DeviceState *dev) | ||
925 | s->prng = NULL; | ||
926 | } | ||
927 | |||
928 | -static void trng_reset_hold(Object *obj) | ||
929 | +static void trng_reset_hold(Object *obj, ResetType type) | ||
930 | { | ||
931 | trng_reset(XLNX_VERSAL_TRNG(obj)); | ||
932 | } | ||
933 | diff --git a/hw/misc/xlnx-versal-xramc.c b/hw/misc/xlnx-versal-xramc.c | ||
934 | index XXXXXXX..XXXXXXX 100644 | ||
935 | --- a/hw/misc/xlnx-versal-xramc.c | ||
936 | +++ b/hw/misc/xlnx-versal-xramc.c | ||
937 | @@ -XXX,XX +XXX,XX @@ static void xram_ctrl_reset_enter(Object *obj, ResetType type) | ||
938 | ARRAY_FIELD_DP32(s->regs, XRAM_IMP, SIZE, s->cfg.encoded_size); | ||
939 | } | ||
940 | |||
941 | -static void xram_ctrl_reset_hold(Object *obj) | ||
942 | +static void xram_ctrl_reset_hold(Object *obj, ResetType type) | ||
943 | { | ||
944 | XlnxXramCtrl *s = XLNX_XRAM_CTRL(obj); | ||
945 | |||
946 | diff --git a/hw/misc/xlnx-zynqmp-apu-ctrl.c b/hw/misc/xlnx-zynqmp-apu-ctrl.c | ||
947 | index XXXXXXX..XXXXXXX 100644 | ||
948 | --- a/hw/misc/xlnx-zynqmp-apu-ctrl.c | ||
949 | +++ b/hw/misc/xlnx-zynqmp-apu-ctrl.c | ||
950 | @@ -XXX,XX +XXX,XX @@ static void zynqmp_apu_reset_enter(Object *obj, ResetType type) | ||
951 | s->cpu_in_wfi = 0; | ||
952 | } | ||
953 | |||
954 | -static void zynqmp_apu_reset_hold(Object *obj) | ||
955 | +static void zynqmp_apu_reset_hold(Object *obj, ResetType type) | ||
956 | { | ||
957 | XlnxZynqMPAPUCtrl *s = XLNX_ZYNQMP_APU_CTRL(obj); | ||
958 | |||
959 | diff --git a/hw/misc/xlnx-zynqmp-crf.c b/hw/misc/xlnx-zynqmp-crf.c | ||
960 | index XXXXXXX..XXXXXXX 100644 | ||
961 | --- a/hw/misc/xlnx-zynqmp-crf.c | ||
962 | +++ b/hw/misc/xlnx-zynqmp-crf.c | ||
963 | @@ -XXX,XX +XXX,XX @@ static void crf_reset_enter(Object *obj, ResetType type) | ||
964 | } | ||
965 | } | ||
966 | |||
967 | -static void crf_reset_hold(Object *obj) | ||
968 | +static void crf_reset_hold(Object *obj, ResetType type) | ||
969 | { | ||
970 | XlnxZynqMPCRF *s = XLNX_ZYNQMP_CRF(obj); | ||
971 | ir_update_irq(s); | ||
972 | diff --git a/hw/misc/zynq_slcr.c b/hw/misc/zynq_slcr.c | ||
973 | index XXXXXXX..XXXXXXX 100644 | ||
974 | --- a/hw/misc/zynq_slcr.c | ||
975 | +++ b/hw/misc/zynq_slcr.c | ||
976 | @@ -XXX,XX +XXX,XX @@ static void zynq_slcr_reset_init(Object *obj, ResetType type) | ||
977 | s->regs[R_DDRIOB + 12] = 0x00000021; | ||
978 | } | ||
979 | |||
980 | -static void zynq_slcr_reset_hold(Object *obj) | ||
981 | +static void zynq_slcr_reset_hold(Object *obj, ResetType type) | ||
982 | { | ||
983 | ZynqSLCRState *s = ZYNQ_SLCR(obj); | ||
984 | |||
985 | @@ -XXX,XX +XXX,XX @@ static void zynq_slcr_reset_hold(Object *obj) | ||
986 | zynq_slcr_propagate_clocks(s); | ||
987 | } | ||
988 | |||
989 | -static void zynq_slcr_reset_exit(Object *obj) | ||
990 | +static void zynq_slcr_reset_exit(Object *obj, ResetType type) | ||
991 | { | ||
992 | ZynqSLCRState *s = ZYNQ_SLCR(obj); | ||
993 | |||
994 | diff --git a/hw/net/can/xlnx-zynqmp-can.c b/hw/net/can/xlnx-zynqmp-can.c | ||
995 | index XXXXXXX..XXXXXXX 100644 | ||
996 | --- a/hw/net/can/xlnx-zynqmp-can.c | ||
997 | +++ b/hw/net/can/xlnx-zynqmp-can.c | ||
998 | @@ -XXX,XX +XXX,XX @@ static void xlnx_zynqmp_can_reset_init(Object *obj, ResetType type) | ||
999 | ptimer_transaction_commit(s->can_timer); | ||
1000 | } | ||
1001 | |||
1002 | -static void xlnx_zynqmp_can_reset_hold(Object *obj) | ||
1003 | +static void xlnx_zynqmp_can_reset_hold(Object *obj, ResetType type) | ||
1004 | { | ||
1005 | XlnxZynqMPCANState *s = XLNX_ZYNQMP_CAN(obj); | ||
1006 | unsigned int i; | ||
1007 | diff --git a/hw/net/e1000.c b/hw/net/e1000.c | ||
1008 | index XXXXXXX..XXXXXXX 100644 | ||
1009 | --- a/hw/net/e1000.c | ||
1010 | +++ b/hw/net/e1000.c | ||
1011 | @@ -XXX,XX +XXX,XX @@ static bool e1000_vet_init_need(void *opaque) | ||
1012 | return chkflag(VET); | ||
1013 | } | ||
1014 | |||
1015 | -static void e1000_reset_hold(Object *obj) | ||
1016 | +static void e1000_reset_hold(Object *obj, ResetType type) | ||
1017 | { | ||
1018 | E1000State *d = E1000(obj); | ||
1019 | E1000BaseClass *edc = E1000_GET_CLASS(d); | ||
1020 | diff --git a/hw/net/e1000e.c b/hw/net/e1000e.c | ||
1021 | index XXXXXXX..XXXXXXX 100644 | ||
1022 | --- a/hw/net/e1000e.c | ||
1023 | +++ b/hw/net/e1000e.c | ||
1024 | @@ -XXX,XX +XXX,XX @@ static void e1000e_pci_uninit(PCIDevice *pci_dev) | ||
1025 | msi_uninit(pci_dev); | ||
1026 | } | ||
1027 | |||
1028 | -static void e1000e_qdev_reset_hold(Object *obj) | ||
1029 | +static void e1000e_qdev_reset_hold(Object *obj, ResetType type) | ||
1030 | { | ||
1031 | E1000EState *s = E1000E(obj); | ||
1032 | |||
1033 | diff --git a/hw/net/igb.c b/hw/net/igb.c | ||
1034 | index XXXXXXX..XXXXXXX 100644 | ||
1035 | --- a/hw/net/igb.c | ||
1036 | +++ b/hw/net/igb.c | ||
1037 | @@ -XXX,XX +XXX,XX @@ static void igb_pci_uninit(PCIDevice *pci_dev) | ||
1038 | msi_uninit(pci_dev); | ||
1039 | } | ||
1040 | |||
1041 | -static void igb_qdev_reset_hold(Object *obj) | ||
1042 | +static void igb_qdev_reset_hold(Object *obj, ResetType type) | ||
1043 | { | ||
1044 | IGBState *s = IGB(obj); | ||
1045 | |||
1046 | diff --git a/hw/net/igbvf.c b/hw/net/igbvf.c | ||
1047 | index XXXXXXX..XXXXXXX 100644 | ||
1048 | --- a/hw/net/igbvf.c | ||
1049 | +++ b/hw/net/igbvf.c | ||
1050 | @@ -XXX,XX +XXX,XX @@ static void igbvf_pci_realize(PCIDevice *dev, Error **errp) | ||
1051 | pcie_ari_init(dev, 0x150); | ||
1052 | } | ||
1053 | |||
1054 | -static void igbvf_qdev_reset_hold(Object *obj) | ||
1055 | +static void igbvf_qdev_reset_hold(Object *obj, ResetType type) | ||
1056 | { | ||
1057 | PCIDevice *vf = PCI_DEVICE(obj); | ||
1058 | |||
1059 | diff --git a/hw/nvram/xlnx-bbram.c b/hw/nvram/xlnx-bbram.c | ||
1060 | index XXXXXXX..XXXXXXX 100644 | ||
1061 | --- a/hw/nvram/xlnx-bbram.c | ||
1062 | +++ b/hw/nvram/xlnx-bbram.c | ||
1063 | @@ -XXX,XX +XXX,XX @@ static RegisterAccessInfo bbram_ctrl_regs_info[] = { | ||
1064 | } | ||
1065 | }; | ||
1066 | |||
1067 | -static void bbram_ctrl_reset_hold(Object *obj) | ||
1068 | +static void bbram_ctrl_reset_hold(Object *obj, ResetType type) | ||
1069 | { | ||
1070 | XlnxBBRam *s = XLNX_BBRAM(obj); | ||
1071 | unsigned int i; | ||
1072 | diff --git a/hw/nvram/xlnx-versal-efuse-ctrl.c b/hw/nvram/xlnx-versal-efuse-ctrl.c | ||
1073 | index XXXXXXX..XXXXXXX 100644 | ||
1074 | --- a/hw/nvram/xlnx-versal-efuse-ctrl.c | ||
1075 | +++ b/hw/nvram/xlnx-versal-efuse-ctrl.c | ||
1076 | @@ -XXX,XX +XXX,XX @@ static void efuse_ctrl_register_reset(RegisterInfo *reg) | ||
1077 | register_reset(reg); | ||
1078 | } | ||
1079 | |||
1080 | -static void efuse_ctrl_reset_hold(Object *obj) | ||
1081 | +static void efuse_ctrl_reset_hold(Object *obj, ResetType type) | ||
1082 | { | ||
1083 | XlnxVersalEFuseCtrl *s = XLNX_VERSAL_EFUSE_CTRL(obj); | ||
1084 | unsigned int i; | ||
1085 | diff --git a/hw/nvram/xlnx-zynqmp-efuse.c b/hw/nvram/xlnx-zynqmp-efuse.c | ||
1086 | index XXXXXXX..XXXXXXX 100644 | ||
1087 | --- a/hw/nvram/xlnx-zynqmp-efuse.c | ||
1088 | +++ b/hw/nvram/xlnx-zynqmp-efuse.c | ||
1089 | @@ -XXX,XX +XXX,XX @@ static void zynqmp_efuse_register_reset(RegisterInfo *reg) | ||
1090 | register_reset(reg); | ||
1091 | } | ||
1092 | |||
1093 | -static void zynqmp_efuse_reset_hold(Object *obj) | ||
1094 | +static void zynqmp_efuse_reset_hold(Object *obj, ResetType type) | ||
1095 | { | ||
1096 | XlnxZynqMPEFuse *s = XLNX_ZYNQMP_EFUSE(obj); | ||
1097 | unsigned int i; | ||
1098 | diff --git a/hw/pci-bridge/cxl_root_port.c b/hw/pci-bridge/cxl_root_port.c | ||
1099 | index XXXXXXX..XXXXXXX 100644 | ||
1100 | --- a/hw/pci-bridge/cxl_root_port.c | ||
1101 | +++ b/hw/pci-bridge/cxl_root_port.c | ||
1102 | @@ -XXX,XX +XXX,XX @@ static void cxl_rp_realize(DeviceState *dev, Error **errp) | ||
1103 | component_bar); | ||
1104 | } | ||
1105 | |||
1106 | -static void cxl_rp_reset_hold(Object *obj) | ||
1107 | +static void cxl_rp_reset_hold(Object *obj, ResetType type) | ||
1108 | { | ||
1109 | PCIERootPortClass *rpc = PCIE_ROOT_PORT_GET_CLASS(obj); | ||
1110 | CXLRootPort *crp = CXL_ROOT_PORT(obj); | ||
1111 | |||
1112 | if (rpc->parent_phases.hold) { | ||
1113 | - rpc->parent_phases.hold(obj); | ||
1114 | + rpc->parent_phases.hold(obj, type); | ||
1115 | } | ||
1116 | |||
1117 | latch_registers(crp); | ||
1118 | diff --git a/hw/pci-bridge/pcie_root_port.c b/hw/pci-bridge/pcie_root_port.c | ||
1119 | index XXXXXXX..XXXXXXX 100644 | ||
1120 | --- a/hw/pci-bridge/pcie_root_port.c | ||
1121 | +++ b/hw/pci-bridge/pcie_root_port.c | ||
1122 | @@ -XXX,XX +XXX,XX @@ static void rp_write_config(PCIDevice *d, uint32_t address, | ||
1123 | pcie_aer_root_write_config(d, address, val, len, root_cmd); | ||
1124 | } | ||
1125 | |||
1126 | -static void rp_reset_hold(Object *obj) | ||
1127 | +static void rp_reset_hold(Object *obj, ResetType type) | ||
1128 | { | ||
1129 | PCIDevice *d = PCI_DEVICE(obj); | ||
1130 | DeviceState *qdev = DEVICE(obj); | ||
1131 | diff --git a/hw/pci-host/bonito.c b/hw/pci-host/bonito.c | ||
1132 | index XXXXXXX..XXXXXXX 100644 | ||
1133 | --- a/hw/pci-host/bonito.c | ||
1134 | +++ b/hw/pci-host/bonito.c | ||
1135 | @@ -XXX,XX +XXX,XX @@ static int pci_bonito_map_irq(PCIDevice *pci_dev, int irq_num) | ||
1136 | } | ||
1137 | } | ||
1138 | |||
1139 | -static void bonito_reset_hold(Object *obj) | ||
1140 | +static void bonito_reset_hold(Object *obj, ResetType type) | ||
1141 | { | ||
1142 | PCIBonitoState *s = PCI_BONITO(obj); | ||
1143 | uint32_t val = 0; | ||
1144 | diff --git a/hw/pci-host/pnv_phb.c b/hw/pci-host/pnv_phb.c | ||
1145 | index XXXXXXX..XXXXXXX 100644 | ||
1146 | --- a/hw/pci-host/pnv_phb.c | ||
1147 | +++ b/hw/pci-host/pnv_phb.c | ||
1148 | @@ -XXX,XX +XXX,XX @@ static void pnv_phb_class_init(ObjectClass *klass, void *data) | ||
1149 | dc->user_creatable = true; | ||
1150 | } | ||
1151 | |||
1152 | -static void pnv_phb_root_port_reset_hold(Object *obj) | ||
1153 | +static void pnv_phb_root_port_reset_hold(Object *obj, ResetType type) | ||
1154 | { | ||
1155 | PCIERootPortClass *rpc = PCIE_ROOT_PORT_GET_CLASS(obj); | ||
1156 | PnvPHBRootPort *phb_rp = PNV_PHB_ROOT_PORT(obj); | ||
1157 | @@ -XXX,XX +XXX,XX @@ static void pnv_phb_root_port_reset_hold(Object *obj) | ||
1158 | uint8_t *conf = d->config; | ||
1159 | |||
1160 | if (rpc->parent_phases.hold) { | ||
1161 | - rpc->parent_phases.hold(obj); | ||
1162 | + rpc->parent_phases.hold(obj, type); | ||
1163 | } | ||
1164 | |||
1165 | if (phb_rp->version == 3) { | ||
1166 | diff --git a/hw/pci-host/pnv_phb3_msi.c b/hw/pci-host/pnv_phb3_msi.c | ||
1167 | index XXXXXXX..XXXXXXX 100644 | ||
1168 | --- a/hw/pci-host/pnv_phb3_msi.c | ||
1169 | +++ b/hw/pci-host/pnv_phb3_msi.c | ||
1170 | @@ -XXX,XX +XXX,XX @@ static void phb3_msi_resend(ICSState *ics) | ||
1171 | } | ||
1172 | } | ||
1173 | |||
1174 | -static void phb3_msi_reset_hold(Object *obj) | ||
1175 | +static void phb3_msi_reset_hold(Object *obj, ResetType type) | ||
1176 | { | ||
1177 | Phb3MsiState *msi = PHB3_MSI(obj); | ||
1178 | ICSStateClass *icsc = ICS_GET_CLASS(obj); | ||
1179 | |||
1180 | if (icsc->parent_phases.hold) { | ||
1181 | - icsc->parent_phases.hold(obj); | ||
1182 | + icsc->parent_phases.hold(obj, type); | ||
1183 | } | ||
1184 | |||
1185 | memset(msi->rba, 0, sizeof(msi->rba)); | ||
1186 | diff --git a/hw/pci/pci.c b/hw/pci/pci.c | ||
1187 | index XXXXXXX..XXXXXXX 100644 | ||
1188 | --- a/hw/pci/pci.c | ||
1189 | +++ b/hw/pci/pci.c | ||
1190 | @@ -XXX,XX +XXX,XX @@ bool pci_available = true; | ||
1191 | |||
1192 | static char *pcibus_get_dev_path(DeviceState *dev); | ||
1193 | static char *pcibus_get_fw_dev_path(DeviceState *dev); | ||
1194 | -static void pcibus_reset_hold(Object *obj); | ||
1195 | +static void pcibus_reset_hold(Object *obj, ResetType type); | ||
1196 | static bool pcie_has_upstream_port(PCIDevice *dev); | ||
1197 | |||
1198 | static Property pci_props[] = { | ||
1199 | @@ -XXX,XX +XXX,XX @@ void pci_device_reset(PCIDevice *dev) | ||
1200 | * Called via bus_cold_reset on RST# assert, after the devices | ||
1201 | * have been reset device_cold_reset-ed already. | ||
1202 | */ | ||
1203 | -static void pcibus_reset_hold(Object *obj) | ||
1204 | +static void pcibus_reset_hold(Object *obj, ResetType type) | ||
1205 | { | ||
1206 | PCIBus *bus = PCI_BUS(obj); | ||
1207 | int i; | ||
1208 | diff --git a/hw/rtc/mc146818rtc.c b/hw/rtc/mc146818rtc.c | ||
1209 | index XXXXXXX..XXXXXXX 100644 | ||
1210 | --- a/hw/rtc/mc146818rtc.c | ||
1211 | +++ b/hw/rtc/mc146818rtc.c | ||
1212 | @@ -XXX,XX +XXX,XX @@ static void rtc_reset_enter(Object *obj, ResetType type) | ||
1213 | } | ||
1214 | } | ||
1215 | |||
1216 | -static void rtc_reset_hold(Object *obj) | ||
1217 | +static void rtc_reset_hold(Object *obj, ResetType type) | ||
1218 | { | ||
1219 | MC146818RtcState *s = MC146818_RTC(obj); | ||
1220 | |||
1221 | diff --git a/hw/s390x/css-bridge.c b/hw/s390x/css-bridge.c | ||
1222 | index XXXXXXX..XXXXXXX 100644 | ||
1223 | --- a/hw/s390x/css-bridge.c | ||
1224 | +++ b/hw/s390x/css-bridge.c | ||
1225 | @@ -XXX,XX +XXX,XX @@ static void ccw_device_unplug(HotplugHandler *hotplug_dev, | ||
1226 | qdev_unrealize(dev); | ||
1227 | } | ||
1228 | |||
1229 | -static void virtual_css_bus_reset_hold(Object *obj) | ||
1230 | +static void virtual_css_bus_reset_hold(Object *obj, ResetType type) | ||
1231 | { | ||
1232 | /* This should actually be modelled via the generic css */ | ||
1233 | css_reset(); | ||
1234 | diff --git a/hw/sensor/adm1266.c b/hw/sensor/adm1266.c | ||
1235 | index XXXXXXX..XXXXXXX 100644 | ||
1236 | --- a/hw/sensor/adm1266.c | ||
1237 | +++ b/hw/sensor/adm1266.c | ||
1238 | @@ -XXX,XX +XXX,XX @@ static const uint8_t adm1266_ic_device_id[] = {0x03, 0x41, 0x12, 0x66}; | ||
1239 | static const uint8_t adm1266_ic_device_rev[] = {0x08, 0x01, 0x08, 0x07, 0x0, | ||
1240 | 0x0, 0x07, 0x41, 0x30}; | ||
1241 | |||
1242 | -static void adm1266_exit_reset(Object *obj) | ||
1243 | +static void adm1266_exit_reset(Object *obj, ResetType type) | ||
1244 | { | ||
1245 | ADM1266State *s = ADM1266(obj); | ||
1246 | PMBusDevice *pmdev = PMBUS_DEVICE(obj); | ||
1247 | diff --git a/hw/sensor/adm1272.c b/hw/sensor/adm1272.c | ||
1248 | index XXXXXXX..XXXXXXX 100644 | ||
1249 | --- a/hw/sensor/adm1272.c | ||
1250 | +++ b/hw/sensor/adm1272.c | ||
1251 | @@ -XXX,XX +XXX,XX @@ static uint32_t adm1272_direct_to_watts(uint16_t value) | ||
1252 | return pmbus_direct_mode2data(c, value); | ||
1253 | } | ||
1254 | |||
1255 | -static void adm1272_exit_reset(Object *obj) | ||
1256 | +static void adm1272_exit_reset(Object *obj, ResetType type) | ||
1257 | { | ||
1258 | ADM1272State *s = ADM1272(obj); | ||
1259 | PMBusDevice *pmdev = PMBUS_DEVICE(obj); | ||
1260 | diff --git a/hw/sensor/isl_pmbus_vr.c b/hw/sensor/isl_pmbus_vr.c | ||
1261 | index XXXXXXX..XXXXXXX 100644 | ||
1262 | --- a/hw/sensor/isl_pmbus_vr.c | ||
1263 | +++ b/hw/sensor/isl_pmbus_vr.c | ||
1264 | @@ -XXX,XX +XXX,XX @@ static void isl_pmbus_vr_set(Object *obj, Visitor *v, const char *name, | ||
1265 | pmbus_check_limits(pmdev); | ||
1266 | } | ||
1267 | |||
1268 | -static void isl_pmbus_vr_exit_reset(Object *obj) | ||
1269 | +static void isl_pmbus_vr_exit_reset(Object *obj, ResetType type) | ||
1270 | { | ||
1271 | PMBusDevice *pmdev = PMBUS_DEVICE(obj); | ||
1272 | |||
1273 | @@ -XXX,XX +XXX,XX @@ static void isl_pmbus_vr_exit_reset(Object *obj) | ||
1274 | } | ||
1275 | |||
1276 | /* The raa228000 uses different direct mode coefficients from most isl devices */ | ||
1277 | -static void raa228000_exit_reset(Object *obj) | ||
1278 | +static void raa228000_exit_reset(Object *obj, ResetType type) | ||
1279 | { | ||
1280 | PMBusDevice *pmdev = PMBUS_DEVICE(obj); | ||
1281 | |||
1282 | - isl_pmbus_vr_exit_reset(obj); | ||
1283 | + isl_pmbus_vr_exit_reset(obj, type); | ||
1284 | |||
1285 | pmdev->pages[0].read_iout = 0; | ||
1286 | pmdev->pages[0].read_pout = 0; | ||
1287 | @@ -XXX,XX +XXX,XX @@ static void raa228000_exit_reset(Object *obj) | ||
1288 | pmdev->pages[0].read_temperature_3 = 0; | ||
1289 | } | ||
1290 | |||
1291 | -static void isl69259_exit_reset(Object *obj) | ||
1292 | +static void isl69259_exit_reset(Object *obj, ResetType type) | ||
1293 | { | ||
1294 | ISLState *s = ISL69260(obj); | ||
1295 | static const uint8_t ic_device_id[] = {0x04, 0x00, 0x81, 0xD2, 0x49, 0x3c}; | ||
1296 | g_assert(sizeof(ic_device_id) <= sizeof(s->ic_device_id)); | ||
1297 | |||
1298 | - isl_pmbus_vr_exit_reset(obj); | ||
1299 | + isl_pmbus_vr_exit_reset(obj, type); | ||
1300 | |||
1301 | s->ic_device_id_len = sizeof(ic_device_id); | ||
1302 | memcpy(s->ic_device_id, ic_device_id, sizeof(ic_device_id)); | ||
1303 | diff --git a/hw/sensor/max31785.c b/hw/sensor/max31785.c | ||
1304 | index XXXXXXX..XXXXXXX 100644 | ||
1305 | --- a/hw/sensor/max31785.c | ||
1306 | +++ b/hw/sensor/max31785.c | ||
1307 | @@ -XXX,XX +XXX,XX @@ static int max31785_write_data(PMBusDevice *pmdev, const uint8_t *buf, | ||
1308 | return 0; | ||
1309 | } | ||
1310 | |||
1311 | -static void max31785_exit_reset(Object *obj) | ||
1312 | +static void max31785_exit_reset(Object *obj, ResetType type) | ||
1313 | { | ||
1314 | PMBusDevice *pmdev = PMBUS_DEVICE(obj); | ||
1315 | MAX31785State *s = MAX31785(obj); | ||
1316 | diff --git a/hw/sensor/max34451.c b/hw/sensor/max34451.c | ||
1317 | index XXXXXXX..XXXXXXX 100644 | ||
1318 | --- a/hw/sensor/max34451.c | ||
1319 | +++ b/hw/sensor/max34451.c | ||
1320 | @@ -XXX,XX +XXX,XX @@ static inline void *memset_word(void *s, uint16_t c, size_t n) | ||
1321 | return s; | ||
1322 | } | ||
1323 | |||
1324 | -static void max34451_exit_reset(Object *obj) | ||
1325 | +static void max34451_exit_reset(Object *obj, ResetType type) | ||
1326 | { | ||
1327 | PMBusDevice *pmdev = PMBUS_DEVICE(obj); | ||
1328 | MAX34451State *s = MAX34451(obj); | ||
1329 | diff --git a/hw/ssi/npcm7xx_fiu.c b/hw/ssi/npcm7xx_fiu.c | ||
1330 | index XXXXXXX..XXXXXXX 100644 | ||
1331 | --- a/hw/ssi/npcm7xx_fiu.c | ||
1332 | +++ b/hw/ssi/npcm7xx_fiu.c | ||
1333 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_fiu_enter_reset(Object *obj, ResetType type) | ||
1334 | s->regs[NPCM7XX_FIU_CFG] = 0x0000000b; | ||
1335 | } | ||
1336 | |||
1337 | -static void npcm7xx_fiu_hold_reset(Object *obj) | ||
1338 | +static void npcm7xx_fiu_hold_reset(Object *obj, ResetType type) | ||
1339 | { | ||
1340 | NPCM7xxFIUState *s = NPCM7XX_FIU(obj); | ||
1341 | int i; | ||
1342 | diff --git a/hw/timer/etraxfs_timer.c b/hw/timer/etraxfs_timer.c | ||
1343 | index XXXXXXX..XXXXXXX 100644 | ||
1344 | --- a/hw/timer/etraxfs_timer.c | ||
1345 | +++ b/hw/timer/etraxfs_timer.c | ||
1346 | @@ -XXX,XX +XXX,XX @@ static void etraxfs_timer_reset_enter(Object *obj, ResetType type) | ||
1347 | t->rw_intr_mask = 0; | ||
1348 | } | ||
1349 | |||
1350 | -static void etraxfs_timer_reset_hold(Object *obj) | ||
1351 | +static void etraxfs_timer_reset_hold(Object *obj, ResetType type) | ||
1352 | { | ||
1353 | ETRAXTimerState *t = ETRAX_TIMER(obj); | ||
1354 | |||
1355 | diff --git a/hw/timer/npcm7xx_timer.c b/hw/timer/npcm7xx_timer.c | ||
1356 | index XXXXXXX..XXXXXXX 100644 | ||
1357 | --- a/hw/timer/npcm7xx_timer.c | ||
1358 | +++ b/hw/timer/npcm7xx_timer.c | ||
1359 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_watchdog_timer_expired(void *opaque) | ||
1360 | } | ||
1361 | } | ||
1362 | |||
1363 | -static void npcm7xx_timer_hold_reset(Object *obj) | ||
1364 | +static void npcm7xx_timer_hold_reset(Object *obj, ResetType type) | ||
1365 | { | ||
1366 | NPCM7xxTimerCtrlState *s = NPCM7XX_TIMER(obj); | ||
1367 | int i; | ||
1368 | diff --git a/hw/usb/hcd-dwc2.c b/hw/usb/hcd-dwc2.c | ||
1369 | index XXXXXXX..XXXXXXX 100644 | ||
1370 | --- a/hw/usb/hcd-dwc2.c | ||
1371 | +++ b/hw/usb/hcd-dwc2.c | ||
1372 | @@ -XXX,XX +XXX,XX @@ static void dwc2_reset_enter(Object *obj, ResetType type) | ||
1373 | } | ||
1374 | } | ||
1375 | |||
1376 | -static void dwc2_reset_hold(Object *obj) | ||
1377 | +static void dwc2_reset_hold(Object *obj, ResetType type) | ||
1378 | { | ||
1379 | DWC2Class *c = DWC2_USB_GET_CLASS(obj); | ||
1380 | DWC2State *s = DWC2_USB(obj); | ||
1381 | @@ -XXX,XX +XXX,XX @@ static void dwc2_reset_hold(Object *obj) | ||
1382 | trace_usb_dwc2_reset_hold(); | ||
1383 | |||
1384 | if (c->parent_phases.hold) { | ||
1385 | - c->parent_phases.hold(obj); | ||
1386 | + c->parent_phases.hold(obj, type); | ||
1387 | } | ||
1388 | |||
1389 | dwc2_update_irq(s); | ||
1390 | } | ||
1391 | |||
1392 | -static void dwc2_reset_exit(Object *obj) | ||
1393 | +static void dwc2_reset_exit(Object *obj, ResetType type) | ||
1394 | { | ||
1395 | DWC2Class *c = DWC2_USB_GET_CLASS(obj); | ||
1396 | DWC2State *s = DWC2_USB(obj); | ||
1397 | @@ -XXX,XX +XXX,XX @@ static void dwc2_reset_exit(Object *obj) | ||
1398 | trace_usb_dwc2_reset_exit(); | ||
1399 | |||
1400 | if (c->parent_phases.exit) { | ||
1401 | - c->parent_phases.exit(obj); | ||
1402 | + c->parent_phases.exit(obj, type); | ||
1403 | } | ||
1404 | |||
1405 | s->hprt0 = HPRT0_PWR; | ||
1406 | diff --git a/hw/usb/xlnx-versal-usb2-ctrl-regs.c b/hw/usb/xlnx-versal-usb2-ctrl-regs.c | ||
1407 | index XXXXXXX..XXXXXXX 100644 | ||
1408 | --- a/hw/usb/xlnx-versal-usb2-ctrl-regs.c | ||
1409 | +++ b/hw/usb/xlnx-versal-usb2-ctrl-regs.c | ||
1410 | @@ -XXX,XX +XXX,XX @@ static void usb2_ctrl_regs_reset_init(Object *obj, ResetType type) | ||
1411 | } | ||
1412 | } | ||
1413 | |||
1414 | -static void usb2_ctrl_regs_reset_hold(Object *obj) | ||
1415 | +static void usb2_ctrl_regs_reset_hold(Object *obj, ResetType type) | ||
1416 | { | ||
1417 | VersalUsb2CtrlRegs *s = XILINX_VERSAL_USB2_CTRL_REGS(obj); | ||
1418 | |||
1419 | diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c | ||
1420 | index XXXXXXX..XXXXXXX 100644 | ||
1421 | --- a/hw/virtio/virtio-pci.c | ||
1422 | +++ b/hw/virtio/virtio-pci.c | ||
1423 | @@ -XXX,XX +XXX,XX @@ static void virtio_pci_reset(DeviceState *qdev) | ||
1424 | } | ||
1425 | } | ||
1426 | |||
1427 | -static void virtio_pci_bus_reset_hold(Object *obj) | ||
1428 | +static void virtio_pci_bus_reset_hold(Object *obj, ResetType type) | ||
1429 | { | ||
1430 | PCIDevice *dev = PCI_DEVICE(obj); | ||
1431 | DeviceState *qdev = DEVICE(obj); | ||
1432 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c | ||
1433 | index XXXXXXX..XXXXXXX 100644 | ||
1434 | --- a/target/arm/cpu.c | ||
1435 | +++ b/target/arm/cpu.c | ||
1436 | @@ -XXX,XX +XXX,XX @@ static void cp_reg_check_reset(gpointer key, gpointer value, gpointer opaque) | ||
1437 | assert(oldvalue == newvalue); | ||
1438 | } | ||
1439 | |||
1440 | -static void arm_cpu_reset_hold(Object *obj) | ||
1441 | +static void arm_cpu_reset_hold(Object *obj, ResetType type) | ||
1442 | { | ||
1443 | CPUState *cs = CPU(obj); | ||
1444 | ARMCPU *cpu = ARM_CPU(cs); | ||
1445 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_reset_hold(Object *obj) | ||
1446 | CPUARMState *env = &cpu->env; | ||
1447 | |||
1448 | if (acc->parent_phases.hold) { | ||
1449 | - acc->parent_phases.hold(obj); | ||
1450 | + acc->parent_phases.hold(obj, type); | ||
1451 | } | ||
1452 | |||
1453 | memset(env, 0, offsetof(CPUARMState, end_reset_fields)); | ||
1454 | diff --git a/target/avr/cpu.c b/target/avr/cpu.c | ||
1455 | index XXXXXXX..XXXXXXX 100644 | ||
1456 | --- a/target/avr/cpu.c | ||
1457 | +++ b/target/avr/cpu.c | ||
1458 | @@ -XXX,XX +XXX,XX @@ static void avr_restore_state_to_opc(CPUState *cs, | ||
1459 | cpu_env(cs)->pc_w = data[0]; | ||
1460 | } | ||
1461 | |||
1462 | -static void avr_cpu_reset_hold(Object *obj) | ||
1463 | +static void avr_cpu_reset_hold(Object *obj, ResetType type) | ||
1464 | { | ||
1465 | CPUState *cs = CPU(obj); | ||
1466 | AVRCPU *cpu = AVR_CPU(cs); | ||
1467 | @@ -XXX,XX +XXX,XX @@ static void avr_cpu_reset_hold(Object *obj) | ||
1468 | CPUAVRState *env = &cpu->env; | ||
1469 | |||
1470 | if (mcc->parent_phases.hold) { | ||
1471 | - mcc->parent_phases.hold(obj); | ||
1472 | + mcc->parent_phases.hold(obj, type); | ||
1473 | } | ||
1474 | |||
1475 | env->pc_w = 0; | ||
1476 | diff --git a/target/cris/cpu.c b/target/cris/cpu.c | ||
1477 | index XXXXXXX..XXXXXXX 100644 | ||
1478 | --- a/target/cris/cpu.c | ||
1479 | +++ b/target/cris/cpu.c | ||
1480 | @@ -XXX,XX +XXX,XX @@ static int cris_cpu_mmu_index(CPUState *cs, bool ifetch) | ||
1481 | return !!(cpu_env(cs)->pregs[PR_CCS] & U_FLAG); | ||
1482 | } | ||
1483 | |||
1484 | -static void cris_cpu_reset_hold(Object *obj) | ||
1485 | +static void cris_cpu_reset_hold(Object *obj, ResetType type) | ||
1486 | { | ||
1487 | CPUState *cs = CPU(obj); | ||
1488 | CRISCPUClass *ccc = CRIS_CPU_GET_CLASS(obj); | ||
1489 | @@ -XXX,XX +XXX,XX @@ static void cris_cpu_reset_hold(Object *obj) | ||
1490 | uint32_t vr; | ||
1491 | |||
1492 | if (ccc->parent_phases.hold) { | ||
1493 | - ccc->parent_phases.hold(obj); | ||
1494 | + ccc->parent_phases.hold(obj, type); | ||
1495 | } | ||
1496 | |||
1497 | vr = env->pregs[PR_VR]; | ||
1498 | diff --git a/target/hexagon/cpu.c b/target/hexagon/cpu.c | ||
1499 | index XXXXXXX..XXXXXXX 100644 | ||
1500 | --- a/target/hexagon/cpu.c | ||
1501 | +++ b/target/hexagon/cpu.c | ||
1502 | @@ -XXX,XX +XXX,XX @@ static void hexagon_restore_state_to_opc(CPUState *cs, | ||
1503 | cpu_env(cs)->gpr[HEX_REG_PC] = data[0]; | ||
1504 | } | ||
1505 | |||
1506 | -static void hexagon_cpu_reset_hold(Object *obj) | ||
1507 | +static void hexagon_cpu_reset_hold(Object *obj, ResetType type) | ||
1508 | { | ||
1509 | CPUState *cs = CPU(obj); | ||
1510 | HexagonCPUClass *mcc = HEXAGON_CPU_GET_CLASS(obj); | ||
1511 | CPUHexagonState *env = cpu_env(cs); | ||
1512 | |||
1513 | if (mcc->parent_phases.hold) { | ||
1514 | - mcc->parent_phases.hold(obj); | ||
1515 | + mcc->parent_phases.hold(obj, type); | ||
1516 | } | ||
1517 | |||
1518 | set_default_nan_mode(1, &env->fp_status); | ||
1519 | diff --git a/target/i386/cpu.c b/target/i386/cpu.c | ||
1520 | index XXXXXXX..XXXXXXX 100644 | ||
1521 | --- a/target/i386/cpu.c | ||
1522 | +++ b/target/i386/cpu.c | ||
1523 | @@ -XXX,XX +XXX,XX @@ static void x86_cpu_set_sgxlepubkeyhash(CPUX86State *env) | ||
1524 | #endif | ||
1525 | } | ||
1526 | |||
1527 | -static void x86_cpu_reset_hold(Object *obj) | ||
1528 | +static void x86_cpu_reset_hold(Object *obj, ResetType type) | ||
1529 | { | ||
1530 | CPUState *cs = CPU(obj); | ||
1531 | X86CPU *cpu = X86_CPU(cs); | ||
1532 | @@ -XXX,XX +XXX,XX @@ static void x86_cpu_reset_hold(Object *obj) | ||
1533 | int i; | ||
1534 | |||
1535 | if (xcc->parent_phases.hold) { | ||
1536 | - xcc->parent_phases.hold(obj); | ||
1537 | + xcc->parent_phases.hold(obj, type); | ||
1538 | } | ||
1539 | |||
1540 | memset(env, 0, offsetof(CPUX86State, end_reset_fields)); | ||
1541 | diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c | ||
1542 | index XXXXXXX..XXXXXXX 100644 | ||
1543 | --- a/target/loongarch/cpu.c | ||
1544 | +++ b/target/loongarch/cpu.c | ||
1545 | @@ -XXX,XX +XXX,XX @@ static void loongarch_max_initfn(Object *obj) | ||
1546 | loongarch_la464_initfn(obj); | ||
1547 | } | ||
1548 | |||
1549 | -static void loongarch_cpu_reset_hold(Object *obj) | ||
1550 | +static void loongarch_cpu_reset_hold(Object *obj, ResetType type) | ||
1551 | { | ||
1552 | CPUState *cs = CPU(obj); | ||
1553 | LoongArchCPUClass *lacc = LOONGARCH_CPU_GET_CLASS(obj); | ||
1554 | CPULoongArchState *env = cpu_env(cs); | ||
1555 | |||
1556 | if (lacc->parent_phases.hold) { | ||
1557 | - lacc->parent_phases.hold(obj); | ||
1558 | + lacc->parent_phases.hold(obj, type); | ||
1559 | } | ||
1560 | |||
1561 | env->fcsr0_mask = FCSR0_M1 | FCSR0_M2 | FCSR0_M3; | ||
1562 | diff --git a/target/m68k/cpu.c b/target/m68k/cpu.c | ||
1563 | index XXXXXXX..XXXXXXX 100644 | ||
1564 | --- a/target/m68k/cpu.c | ||
1565 | +++ b/target/m68k/cpu.c | ||
1566 | @@ -XXX,XX +XXX,XX @@ static void m68k_unset_feature(CPUM68KState *env, int feature) | ||
1567 | env->features &= ~BIT_ULL(feature); | ||
1568 | } | ||
1569 | |||
1570 | -static void m68k_cpu_reset_hold(Object *obj) | ||
1571 | +static void m68k_cpu_reset_hold(Object *obj, ResetType type) | ||
1572 | { | ||
1573 | CPUState *cs = CPU(obj); | ||
1574 | M68kCPUClass *mcc = M68K_CPU_GET_CLASS(obj); | ||
1575 | @@ -XXX,XX +XXX,XX @@ static void m68k_cpu_reset_hold(Object *obj) | ||
1576 | int i; | ||
1577 | |||
1578 | if (mcc->parent_phases.hold) { | ||
1579 | - mcc->parent_phases.hold(obj); | ||
1580 | + mcc->parent_phases.hold(obj, type); | ||
1581 | } | ||
1582 | |||
1583 | memset(env, 0, offsetof(CPUM68KState, end_reset_fields)); | ||
1584 | diff --git a/target/microblaze/cpu.c b/target/microblaze/cpu.c | ||
1585 | index XXXXXXX..XXXXXXX 100644 | ||
1586 | --- a/target/microblaze/cpu.c | ||
1587 | +++ b/target/microblaze/cpu.c | ||
1588 | @@ -XXX,XX +XXX,XX @@ static void microblaze_cpu_set_irq(void *opaque, int irq, int level) | ||
1589 | } | ||
1590 | #endif | ||
1591 | |||
1592 | -static void mb_cpu_reset_hold(Object *obj) | ||
1593 | +static void mb_cpu_reset_hold(Object *obj, ResetType type) | ||
1594 | { | ||
1595 | CPUState *cs = CPU(obj); | ||
1596 | MicroBlazeCPU *cpu = MICROBLAZE_CPU(cs); | ||
1597 | @@ -XXX,XX +XXX,XX @@ static void mb_cpu_reset_hold(Object *obj) | ||
1598 | CPUMBState *env = &cpu->env; | ||
1599 | |||
1600 | if (mcc->parent_phases.hold) { | ||
1601 | - mcc->parent_phases.hold(obj); | ||
1602 | + mcc->parent_phases.hold(obj, type); | ||
1603 | } | ||
1604 | |||
1605 | memset(env, 0, offsetof(CPUMBState, end_reset_fields)); | ||
1606 | diff --git a/target/mips/cpu.c b/target/mips/cpu.c | ||
1607 | index XXXXXXX..XXXXXXX 100644 | ||
1608 | --- a/target/mips/cpu.c | ||
1609 | +++ b/target/mips/cpu.c | ||
1610 | @@ -XXX,XX +XXX,XX @@ static int mips_cpu_mmu_index(CPUState *cs, bool ifunc) | ||
1611 | |||
1612 | #include "cpu-defs.c.inc" | ||
1613 | |||
1614 | -static void mips_cpu_reset_hold(Object *obj) | ||
1615 | +static void mips_cpu_reset_hold(Object *obj, ResetType type) | ||
1616 | { | ||
1617 | CPUState *cs = CPU(obj); | ||
1618 | MIPSCPU *cpu = MIPS_CPU(cs); | ||
1619 | @@ -XXX,XX +XXX,XX @@ static void mips_cpu_reset_hold(Object *obj) | ||
1620 | CPUMIPSState *env = &cpu->env; | ||
1621 | |||
1622 | if (mcc->parent_phases.hold) { | ||
1623 | - mcc->parent_phases.hold(obj); | ||
1624 | + mcc->parent_phases.hold(obj, type); | ||
1625 | } | ||
1626 | |||
1627 | memset(env, 0, offsetof(CPUMIPSState, end_reset_fields)); | ||
1628 | diff --git a/target/openrisc/cpu.c b/target/openrisc/cpu.c | ||
1629 | index XXXXXXX..XXXXXXX 100644 | ||
1630 | --- a/target/openrisc/cpu.c | ||
1631 | +++ b/target/openrisc/cpu.c | ||
1632 | @@ -XXX,XX +XXX,XX @@ static void openrisc_disas_set_info(CPUState *cpu, disassemble_info *info) | ||
1633 | info->print_insn = print_insn_or1k; | ||
1634 | } | ||
1635 | |||
1636 | -static void openrisc_cpu_reset_hold(Object *obj) | ||
1637 | +static void openrisc_cpu_reset_hold(Object *obj, ResetType type) | ||
1638 | { | ||
1639 | CPUState *cs = CPU(obj); | ||
1640 | OpenRISCCPU *cpu = OPENRISC_CPU(cs); | ||
1641 | OpenRISCCPUClass *occ = OPENRISC_CPU_GET_CLASS(obj); | ||
1642 | |||
1643 | if (occ->parent_phases.hold) { | ||
1644 | - occ->parent_phases.hold(obj); | ||
1645 | + occ->parent_phases.hold(obj, type); | ||
1646 | } | ||
1647 | |||
1648 | memset(&cpu->env, 0, offsetof(CPUOpenRISCState, end_reset_fields)); | ||
1649 | diff --git a/target/ppc/cpu_init.c b/target/ppc/cpu_init.c | ||
1650 | index XXXXXXX..XXXXXXX 100644 | ||
1651 | --- a/target/ppc/cpu_init.c | ||
1652 | +++ b/target/ppc/cpu_init.c | ||
1653 | @@ -XXX,XX +XXX,XX @@ static int ppc_cpu_mmu_index(CPUState *cs, bool ifetch) | ||
1654 | return ppc_env_mmu_index(cpu_env(cs), ifetch); | ||
1655 | } | ||
1656 | |||
1657 | -static void ppc_cpu_reset_hold(Object *obj) | ||
1658 | +static void ppc_cpu_reset_hold(Object *obj, ResetType type) | ||
1659 | { | ||
1660 | CPUState *cs = CPU(obj); | ||
1661 | PowerPCCPU *cpu = POWERPC_CPU(cs); | ||
1662 | @@ -XXX,XX +XXX,XX @@ static void ppc_cpu_reset_hold(Object *obj) | ||
1663 | int i; | ||
1664 | |||
1665 | if (pcc->parent_phases.hold) { | ||
1666 | - pcc->parent_phases.hold(obj); | ||
1667 | + pcc->parent_phases.hold(obj, type); | ||
1668 | } | ||
1669 | |||
1670 | msr = (target_ulong)0; | ||
1671 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
1672 | index XXXXXXX..XXXXXXX 100644 | ||
1673 | --- a/target/riscv/cpu.c | ||
1674 | +++ b/target/riscv/cpu.c | ||
1675 | @@ -XXX,XX +XXX,XX @@ static int riscv_cpu_mmu_index(CPUState *cs, bool ifetch) | ||
1676 | return riscv_env_mmu_index(cpu_env(cs), ifetch); | ||
1677 | } | ||
1678 | |||
1679 | -static void riscv_cpu_reset_hold(Object *obj) | ||
1680 | +static void riscv_cpu_reset_hold(Object *obj, ResetType type) | ||
1681 | { | ||
1682 | #ifndef CONFIG_USER_ONLY | ||
1683 | uint8_t iprio; | ||
1684 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_reset_hold(Object *obj) | ||
1685 | CPURISCVState *env = &cpu->env; | ||
1686 | |||
1687 | if (mcc->parent_phases.hold) { | ||
1688 | - mcc->parent_phases.hold(obj); | ||
1689 | + mcc->parent_phases.hold(obj, type); | ||
1690 | } | ||
1691 | #ifndef CONFIG_USER_ONLY | ||
1692 | env->misa_mxl = mcc->misa_mxl_max; | ||
1693 | diff --git a/target/rx/cpu.c b/target/rx/cpu.c | ||
1694 | index XXXXXXX..XXXXXXX 100644 | ||
1695 | --- a/target/rx/cpu.c | ||
1696 | +++ b/target/rx/cpu.c | ||
1697 | @@ -XXX,XX +XXX,XX @@ static int riscv_cpu_mmu_index(CPUState *cs, bool ifunc) | ||
1698 | return 0; | ||
1699 | } | ||
1700 | |||
1701 | -static void rx_cpu_reset_hold(Object *obj) | ||
1702 | +static void rx_cpu_reset_hold(Object *obj, ResetType type) | ||
1703 | { | ||
1704 | CPUState *cs = CPU(obj); | ||
1705 | RXCPUClass *rcc = RX_CPU_GET_CLASS(obj); | ||
1706 | @@ -XXX,XX +XXX,XX @@ static void rx_cpu_reset_hold(Object *obj) | ||
1707 | uint32_t *resetvec; | ||
1708 | |||
1709 | if (rcc->parent_phases.hold) { | ||
1710 | - rcc->parent_phases.hold(obj); | ||
1711 | + rcc->parent_phases.hold(obj, type); | ||
1712 | } | ||
1713 | |||
1714 | memset(env, 0, offsetof(CPURXState, end_reset_fields)); | ||
1715 | diff --git a/target/sh4/cpu.c b/target/sh4/cpu.c | ||
1716 | index XXXXXXX..XXXXXXX 100644 | ||
1717 | --- a/target/sh4/cpu.c | ||
1718 | +++ b/target/sh4/cpu.c | ||
1719 | @@ -XXX,XX +XXX,XX @@ static int sh4_cpu_mmu_index(CPUState *cs, bool ifetch) | ||
1720 | } | ||
1721 | } | ||
1722 | |||
1723 | -static void superh_cpu_reset_hold(Object *obj) | ||
1724 | +static void superh_cpu_reset_hold(Object *obj, ResetType type) | ||
1725 | { | ||
1726 | CPUState *cs = CPU(obj); | ||
1727 | SuperHCPUClass *scc = SUPERH_CPU_GET_CLASS(obj); | ||
1728 | CPUSH4State *env = cpu_env(cs); | ||
1729 | |||
1730 | if (scc->parent_phases.hold) { | ||
1731 | - scc->parent_phases.hold(obj); | ||
1732 | + scc->parent_phases.hold(obj, type); | ||
1733 | } | ||
1734 | |||
1735 | memset(env, 0, offsetof(CPUSH4State, end_reset_fields)); | ||
1736 | diff --git a/target/sparc/cpu.c b/target/sparc/cpu.c | ||
1737 | index XXXXXXX..XXXXXXX 100644 | ||
1738 | --- a/target/sparc/cpu.c | ||
1739 | +++ b/target/sparc/cpu.c | ||
1740 | @@ -XXX,XX +XXX,XX @@ | ||
1741 | |||
1742 | //#define DEBUG_FEATURES | ||
1743 | |||
1744 | -static void sparc_cpu_reset_hold(Object *obj) | ||
1745 | +static void sparc_cpu_reset_hold(Object *obj, ResetType type) | ||
1746 | { | ||
1747 | CPUState *cs = CPU(obj); | ||
1748 | SPARCCPUClass *scc = SPARC_CPU_GET_CLASS(obj); | ||
1749 | CPUSPARCState *env = cpu_env(cs); | ||
1750 | |||
1751 | if (scc->parent_phases.hold) { | ||
1752 | - scc->parent_phases.hold(obj); | ||
1753 | + scc->parent_phases.hold(obj, type); | ||
1754 | } | ||
1755 | |||
1756 | memset(env, 0, offsetof(CPUSPARCState, end_reset_fields)); | ||
1757 | diff --git a/target/tricore/cpu.c b/target/tricore/cpu.c | ||
1758 | index XXXXXXX..XXXXXXX 100644 | ||
1759 | --- a/target/tricore/cpu.c | ||
1760 | +++ b/target/tricore/cpu.c | ||
1761 | @@ -XXX,XX +XXX,XX @@ static void tricore_restore_state_to_opc(CPUState *cs, | ||
1762 | cpu_env(cs)->PC = data[0]; | ||
1763 | } | ||
1764 | |||
1765 | -static void tricore_cpu_reset_hold(Object *obj) | ||
1766 | +static void tricore_cpu_reset_hold(Object *obj, ResetType type) | ||
1767 | { | ||
1768 | CPUState *cs = CPU(obj); | ||
1769 | TriCoreCPUClass *tcc = TRICORE_CPU_GET_CLASS(obj); | ||
1770 | |||
1771 | if (tcc->parent_phases.hold) { | ||
1772 | - tcc->parent_phases.hold(obj); | ||
1773 | + tcc->parent_phases.hold(obj, type); | ||
1774 | } | ||
1775 | |||
1776 | cpu_state_reset(cpu_env(cs)); | ||
1777 | diff --git a/target/xtensa/cpu.c b/target/xtensa/cpu.c | ||
1778 | index XXXXXXX..XXXXXXX 100644 | ||
1779 | --- a/target/xtensa/cpu.c | ||
1780 | +++ b/target/xtensa/cpu.c | ||
1781 | @@ -XXX,XX +XXX,XX @@ bool xtensa_abi_call0(void) | ||
1782 | } | ||
1783 | #endif | ||
1784 | |||
1785 | -static void xtensa_cpu_reset_hold(Object *obj) | ||
1786 | +static void xtensa_cpu_reset_hold(Object *obj, ResetType type) | ||
1787 | { | ||
1788 | CPUState *cs = CPU(obj); | ||
1789 | XtensaCPUClass *xcc = XTENSA_CPU_GET_CLASS(obj); | ||
1790 | @@ -XXX,XX +XXX,XX @@ static void xtensa_cpu_reset_hold(Object *obj) | ||
1791 | XTENSA_OPTION_DFP_COPROCESSOR); | ||
1792 | |||
1793 | if (xcc->parent_phases.hold) { | ||
1794 | - xcc->parent_phases.hold(obj); | ||
1795 | + xcc->parent_phases.hold(obj, type); | ||
1796 | } | ||
1797 | |||
1798 | env->pc = env->config->exception_vector[EXC_RESET0 + env->static_vectors]; | ||
1799 | -- | ||
1800 | 2.34.1 | diff view generated by jsdifflib |
1 | We prefer the FIELD macro over ad-hoc #defines for register bits; | 1 | Update the reset documentation's example code to match the new API |
---|---|---|---|
2 | switch CNTHCTL to that style before we add any more bits. | 2 | for the hold and exit phase method APIs where they take a ResetType |
3 | argument. | ||
3 | 4 | ||
4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 5 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
6 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
5 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | 7 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
6 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 8 | Reviewed-by: Luc Michel <luc.michel@amd.com> |
7 | Message-id: 20240301183219.2424889-4-peter.maydell@linaro.org | 9 | Message-id: 20240412160809.1260625-6-peter.maydell@linaro.org |
8 | --- | 10 | --- |
9 | target/arm/internals.h | 27 +++++++++++++++++++++++++-- | 11 | docs/devel/reset.rst | 8 ++++---- |
10 | target/arm/helper.c | 9 ++++----- | 12 | 1 file changed, 4 insertions(+), 4 deletions(-) |
11 | 2 files changed, 29 insertions(+), 7 deletions(-) | ||
12 | 13 | ||
13 | diff --git a/target/arm/internals.h b/target/arm/internals.h | 14 | diff --git a/docs/devel/reset.rst b/docs/devel/reset.rst |
14 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/target/arm/internals.h | 16 | --- a/docs/devel/reset.rst |
16 | +++ b/target/arm/internals.h | 17 | +++ b/docs/devel/reset.rst |
17 | @@ -XXX,XX +XXX,XX @@ FIELD(VTCR, SL2, 33, 1) | 18 | @@ -XXX,XX +XXX,XX @@ in reset. |
18 | #define HSTR_TTEE (1 << 16) | 19 | mydev->var = 0; |
19 | #define HSTR_TJDBX (1 << 17) | ||
20 | |||
21 | -#define CNTHCTL_CNTVMASK (1 << 18) | ||
22 | -#define CNTHCTL_CNTPMASK (1 << 19) | ||
23 | +/* | ||
24 | + * Depending on the value of HCR_EL2.E2H, bits 0 and 1 | ||
25 | + * have different bit definitions, and EL1PCTEN might be | ||
26 | + * bit 0 or bit 10. We use _E2H1 and _E2H0 suffixes to | ||
27 | + * disambiguate if necessary. | ||
28 | + */ | ||
29 | +FIELD(CNTHCTL, EL0PCTEN_E2H1, 0, 1) | ||
30 | +FIELD(CNTHCTL, EL0VCTEN_E2H1, 1, 1) | ||
31 | +FIELD(CNTHCTL, EL1PCTEN_E2H0, 0, 1) | ||
32 | +FIELD(CNTHCTL, EL1PCEN_E2H0, 1, 1) | ||
33 | +FIELD(CNTHCTL, EVNTEN, 2, 1) | ||
34 | +FIELD(CNTHCTL, EVNTDIR, 3, 1) | ||
35 | +FIELD(CNTHCTL, EVNTI, 4, 4) | ||
36 | +FIELD(CNTHCTL, EL0VTEN, 8, 1) | ||
37 | +FIELD(CNTHCTL, EL0PTEN, 9, 1) | ||
38 | +FIELD(CNTHCTL, EL1PCTEN_E2H1, 10, 1) | ||
39 | +FIELD(CNTHCTL, EL1PTEN, 11, 1) | ||
40 | +FIELD(CNTHCTL, ECV, 12, 1) | ||
41 | +FIELD(CNTHCTL, EL1TVT, 13, 1) | ||
42 | +FIELD(CNTHCTL, EL1TVCT, 14, 1) | ||
43 | +FIELD(CNTHCTL, EL1NVPCT, 15, 1) | ||
44 | +FIELD(CNTHCTL, EL1NVVCT, 16, 1) | ||
45 | +FIELD(CNTHCTL, EVNTIS, 17, 1) | ||
46 | +FIELD(CNTHCTL, CNTVMASK, 18, 1) | ||
47 | +FIELD(CNTHCTL, CNTPMASK, 19, 1) | ||
48 | |||
49 | /* We use a few fake FSR values for internal purposes in M profile. | ||
50 | * M profile cores don't have A/R format FSRs, but currently our | ||
51 | diff --git a/target/arm/helper.c b/target/arm/helper.c | ||
52 | index XXXXXXX..XXXXXXX 100644 | ||
53 | --- a/target/arm/helper.c | ||
54 | +++ b/target/arm/helper.c | ||
55 | @@ -XXX,XX +XXX,XX @@ static void gt_update_irq(ARMCPU *cpu, int timeridx) | ||
56 | * It is RES0 in Secure and NonSecure state. | ||
57 | */ | ||
58 | if ((ss == ARMSS_Root || ss == ARMSS_Realm) && | ||
59 | - ((timeridx == GTIMER_VIRT && (cnthctl & CNTHCTL_CNTVMASK)) || | ||
60 | - (timeridx == GTIMER_PHYS && (cnthctl & CNTHCTL_CNTPMASK)))) { | ||
61 | + ((timeridx == GTIMER_VIRT && (cnthctl & R_CNTHCTL_CNTVMASK_MASK)) || | ||
62 | + (timeridx == GTIMER_PHYS && (cnthctl & R_CNTHCTL_CNTPMASK_MASK)))) { | ||
63 | irqstate = 0; | ||
64 | } | 20 | } |
65 | 21 | ||
66 | @@ -XXX,XX +XXX,XX @@ static void gt_cnthctl_write(CPUARMState *env, const ARMCPRegInfo *ri, | 22 | - static void mydev_reset_hold(Object *obj) |
67 | { | 23 | + static void mydev_reset_hold(Object *obj, ResetType type) |
68 | ARMCPU *cpu = env_archcpu(env); | 24 | { |
69 | uint32_t oldval = env->cp15.cnthctl_el2; | 25 | MyDevClass *myclass = MYDEV_GET_CLASS(obj); |
70 | - | 26 | MyDevState *mydev = MYDEV(obj); |
71 | raw_write(env, ri, value); | 27 | /* call parent class hold phase */ |
72 | 28 | if (myclass->parent_phases.hold) { | |
73 | - if ((oldval ^ value) & CNTHCTL_CNTVMASK) { | 29 | - myclass->parent_phases.hold(obj); |
74 | + if ((oldval ^ value) & R_CNTHCTL_CNTVMASK_MASK) { | 30 | + myclass->parent_phases.hold(obj, type); |
75 | gt_update_irq(cpu, GTIMER_VIRT); | 31 | } |
76 | - } else if ((oldval ^ value) & CNTHCTL_CNTPMASK) { | 32 | /* set an IO */ |
77 | + } else if ((oldval ^ value) & R_CNTHCTL_CNTPMASK_MASK) { | 33 | qemu_set_irq(mydev->irq, 1); |
78 | gt_update_irq(cpu, GTIMER_PHYS); | ||
79 | } | 34 | } |
80 | } | 35 | |
36 | - static void mydev_reset_exit(Object *obj) | ||
37 | + static void mydev_reset_exit(Object *obj, ResetType type) | ||
38 | { | ||
39 | MyDevClass *myclass = MYDEV_GET_CLASS(obj); | ||
40 | MyDevState *mydev = MYDEV(obj); | ||
41 | /* call parent class exit phase */ | ||
42 | if (myclass->parent_phases.exit) { | ||
43 | - myclass->parent_phases.exit(obj); | ||
44 | + myclass->parent_phases.exit(obj, type); | ||
45 | } | ||
46 | /* clear an IO */ | ||
47 | qemu_set_irq(mydev->irq, 0); | ||
81 | -- | 48 | -- |
82 | 2.34.1 | 49 | 2.34.1 |
83 | 50 | ||
84 | 51 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Some devices and machines need to handle the reset before a vmsave | ||
2 | snapshot is loaded differently -- the main user is the handling of | ||
3 | RNG seed information, which does not want to put a new RNG seed into | ||
4 | a ROM blob when we are doing a snapshot load. | ||
1 | 5 | ||
6 | Currently this kind of reset handling is supported only for: | ||
7 | * TYPE_MACHINE reset methods, which take a ShutdownCause argument | ||
8 | * reset functions registered with qemu_register_reset_nosnapshotload | ||
9 | |||
10 | To allow a three-phase-reset device to also distinguish "snapshot | ||
11 | load" reset from the normal kind, add a new ResetType | ||
12 | RESET_TYPE_SNAPSHOT_LOAD. All our existing reset methods ignore | ||
13 | the reset type, so we don't need to update any device code. | ||
14 | |||
15 | Add the enum type, and make qemu_devices_reset() use the | ||
16 | right reset type for the ShutdownCause it is passed. This | ||
17 | allows us to get rid of the device_reset_reason global we | ||
18 | were using to implement qemu_register_reset_nosnapshotload(). | ||
19 | |||
20 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
21 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
22 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
23 | Reviewed-by: Luc Michel <luc.michel@amd.com> | ||
24 | Message-id: 20240412160809.1260625-7-peter.maydell@linaro.org | ||
25 | --- | ||
26 | docs/devel/reset.rst | 17 ++++++++++++++--- | ||
27 | include/hw/resettable.h | 1 + | ||
28 | hw/core/reset.c | 15 ++++----------- | ||
29 | hw/core/resettable.c | 4 ---- | ||
30 | 4 files changed, 19 insertions(+), 18 deletions(-) | ||
31 | |||
32 | diff --git a/docs/devel/reset.rst b/docs/devel/reset.rst | ||
33 | index XXXXXXX..XXXXXXX 100644 | ||
34 | --- a/docs/devel/reset.rst | ||
35 | +++ b/docs/devel/reset.rst | ||
36 | @@ -XXX,XX +XXX,XX @@ instantly reset an object, without keeping it in reset state, just call | ||
37 | ``resettable_reset()``. These functions take two parameters: a pointer to the | ||
38 | object to reset and a reset type. | ||
39 | |||
40 | -Several types of reset will be supported. For now only cold reset is defined; | ||
41 | -others may be added later. The Resettable interface handles reset types with an | ||
42 | -enum: | ||
43 | +The Resettable interface handles reset types with an enum ``ResetType``: | ||
44 | |||
45 | ``RESET_TYPE_COLD`` | ||
46 | Cold reset is supported by every resettable object. In QEMU, it means we reset | ||
47 | @@ -XXX,XX +XXX,XX @@ enum: | ||
48 | from what is a real hardware cold reset. It differs from other resets (like | ||
49 | warm or bus resets) which may keep certain parts untouched. | ||
50 | |||
51 | +``RESET_TYPE_SNAPSHOT_LOAD`` | ||
52 | + This is called for a reset which is being done to put the system into a | ||
53 | + clean state prior to loading a snapshot. (This corresponds to a reset | ||
54 | + with ``SHUTDOWN_CAUSE_SNAPSHOT_LOAD``.) Almost all devices should treat | ||
55 | + this the same as ``RESET_TYPE_COLD``. The main exception is devices which | ||
56 | + have some non-deterministic state they want to reinitialize to a different | ||
57 | + value on each cold reset, such as RNG seed information, and which they | ||
58 | + must not reinitialize on a snapshot-load reset. | ||
59 | + | ||
60 | +Devices which implement reset methods must treat any unknown ``ResetType`` | ||
61 | +as equivalent to ``RESET_TYPE_COLD``; this will reduce the amount of | ||
62 | +existing code we need to change if we add more types in future. | ||
63 | + | ||
64 | Calling ``resettable_reset()`` is equivalent to calling | ||
65 | ``resettable_assert_reset()`` then ``resettable_release_reset()``. It is | ||
66 | possible to interleave multiple calls to these three functions. There may | ||
67 | diff --git a/include/hw/resettable.h b/include/hw/resettable.h | ||
68 | index XXXXXXX..XXXXXXX 100644 | ||
69 | --- a/include/hw/resettable.h | ||
70 | +++ b/include/hw/resettable.h | ||
71 | @@ -XXX,XX +XXX,XX @@ typedef struct ResettableState ResettableState; | ||
72 | */ | ||
73 | typedef enum ResetType { | ||
74 | RESET_TYPE_COLD, | ||
75 | + RESET_TYPE_SNAPSHOT_LOAD, | ||
76 | } ResetType; | ||
77 | |||
78 | /* | ||
79 | diff --git a/hw/core/reset.c b/hw/core/reset.c | ||
80 | index XXXXXXX..XXXXXXX 100644 | ||
81 | --- a/hw/core/reset.c | ||
82 | +++ b/hw/core/reset.c | ||
83 | @@ -XXX,XX +XXX,XX @@ static ResettableContainer *get_root_reset_container(void) | ||
84 | return root_reset_container; | ||
85 | } | ||
86 | |||
87 | -/* | ||
88 | - * Reason why the currently in-progress qemu_devices_reset() was called. | ||
89 | - * If we made at least SHUTDOWN_CAUSE_SNAPSHOT_LOAD have a corresponding | ||
90 | - * ResetType we could perhaps avoid the need for this global. | ||
91 | - */ | ||
92 | -static ShutdownCause device_reset_reason; | ||
93 | - | ||
94 | /* | ||
95 | * This is an Object which implements Resettable simply to call the | ||
96 | * callback function in the hold phase. | ||
97 | @@ -XXX,XX +XXX,XX @@ static void legacy_reset_hold(Object *obj, ResetType type) | ||
98 | { | ||
99 | LegacyReset *lr = LEGACY_RESET(obj); | ||
100 | |||
101 | - if (device_reset_reason == SHUTDOWN_CAUSE_SNAPSHOT_LOAD && | ||
102 | - lr->skip_on_snapshot_load) { | ||
103 | + if (type == RESET_TYPE_SNAPSHOT_LOAD && lr->skip_on_snapshot_load) { | ||
104 | return; | ||
105 | } | ||
106 | lr->func(lr->opaque); | ||
107 | @@ -XXX,XX +XXX,XX @@ void qemu_unregister_resettable(Object *obj) | ||
108 | |||
109 | void qemu_devices_reset(ShutdownCause reason) | ||
110 | { | ||
111 | - device_reset_reason = reason; | ||
112 | + ResetType type = (reason == SHUTDOWN_CAUSE_SNAPSHOT_LOAD) ? | ||
113 | + RESET_TYPE_SNAPSHOT_LOAD : RESET_TYPE_COLD; | ||
114 | |||
115 | /* Reset the simulation */ | ||
116 | - resettable_reset(OBJECT(get_root_reset_container()), RESET_TYPE_COLD); | ||
117 | + resettable_reset(OBJECT(get_root_reset_container()), type); | ||
118 | } | ||
119 | diff --git a/hw/core/resettable.c b/hw/core/resettable.c | ||
120 | index XXXXXXX..XXXXXXX 100644 | ||
121 | --- a/hw/core/resettable.c | ||
122 | +++ b/hw/core/resettable.c | ||
123 | @@ -XXX,XX +XXX,XX @@ void resettable_reset(Object *obj, ResetType type) | ||
124 | |||
125 | void resettable_assert_reset(Object *obj, ResetType type) | ||
126 | { | ||
127 | - /* TODO: change this assert when adding support for other reset types */ | ||
128 | - assert(type == RESET_TYPE_COLD); | ||
129 | trace_resettable_reset_assert_begin(obj, type); | ||
130 | assert(!enter_phase_in_progress); | ||
131 | |||
132 | @@ -XXX,XX +XXX,XX @@ void resettable_assert_reset(Object *obj, ResetType type) | ||
133 | |||
134 | void resettable_release_reset(Object *obj, ResetType type) | ||
135 | { | ||
136 | - /* TODO: change this assert when adding support for other reset types */ | ||
137 | - assert(type == RESET_TYPE_COLD); | ||
138 | trace_resettable_reset_release_begin(obj, type); | ||
139 | assert(!enter_phase_in_progress); | ||
140 | |||
141 | -- | ||
142 | 2.34.1 | ||
143 | |||
144 | diff view generated by jsdifflib |
1 | From: Inès Varhol <ines.varhol@telecom-paris.fr> | 1 | From: Arnaud Minier <arnaud.minier@telecom-paris.fr> |
---|---|---|---|
2 | 2 | ||
3 | Features supported : | 3 | Add the basic infrastructure (register read/write, type...) |
4 | - the 8 STM32L4x5 GPIOs are initialized with their reset values | 4 | to implement the STM32L4x5 USART. |
5 | (except IDR, see below) | ||
6 | - input mode : setting a pin in input mode "externally" (using input | ||
7 | irqs) results in an out irq (transmitted to SYSCFG) | ||
8 | - output mode : setting a bit in ODR sets the corresponding out irq | ||
9 | (if this line is configured in output mode) | ||
10 | - pull-up, pull-down | ||
11 | - push-pull, open-drain | ||
12 | 5 | ||
13 | Difference with the real GPIOs : | 6 | Also create different types for the USART, UART and LPUART |
14 | - Alternate Function and Analog mode aren't implemented : | 7 | of the STM32L4x5 to deduplicate code and enable the |
15 | pins in AF/Analog behave like pins in input mode | 8 | implementation of different behaviors depending on the type. |
16 | - floating pins stay at their last value | ||
17 | - register IDR reset values differ from the real one : | ||
18 | values are coherent with the other registers reset values | ||
19 | and the fact that AF/Analog modes aren't implemented | ||
20 | - setting I/O output speed isn't supported | ||
21 | - locking port bits isn't supported | ||
22 | - ADC function isn't supported | ||
23 | - GPIOH has 16 pins instead of 2 pins | ||
24 | - writing to registers LCKR, AFRL, AFRH and ASCR is ineffective | ||
25 | 9 | ||
26 | Signed-off-by: Arnaud Minier <arnaud.minier@telecom-paris.fr> | 10 | Signed-off-by: Arnaud Minier <arnaud.minier@telecom-paris.fr> |
27 | Signed-off-by: Inès Varhol <ines.varhol@telecom-paris.fr> | 11 | Signed-off-by: Inès Varhol <ines.varhol@telecom-paris.fr> |
28 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | 12 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
29 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | 13 | Message-id: 20240329174402.60382-2-arnaud.minier@telecom-paris.fr |
30 | Message-id: 20240305210444.310665-2-ines.varhol@telecom-paris.fr | 14 | [PMM: update to new reset hold method signature; |
15 | fixed a few checkpatch nits] | ||
31 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 16 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
32 | --- | 17 | --- |
33 | MAINTAINERS | 1 + | 18 | MAINTAINERS | 1 + |
34 | docs/system/arm/b-l475e-iot01a.rst | 2 +- | 19 | include/hw/char/stm32l4x5_usart.h | 66 +++++ |
35 | include/hw/gpio/stm32l4x5_gpio.h | 70 +++++ | 20 | hw/char/stm32l4x5_usart.c | 396 ++++++++++++++++++++++++++++++ |
36 | hw/gpio/stm32l4x5_gpio.c | 477 +++++++++++++++++++++++++++++ | 21 | hw/char/Kconfig | 3 + |
37 | hw/gpio/Kconfig | 3 + | 22 | hw/char/meson.build | 1 + |
38 | hw/gpio/meson.build | 1 + | 23 | hw/char/trace-events | 4 + |
39 | hw/gpio/trace-events | 6 + | 24 | 6 files changed, 471 insertions(+) |
40 | 7 files changed, 559 insertions(+), 1 deletion(-) | 25 | create mode 100644 include/hw/char/stm32l4x5_usart.h |
41 | create mode 100644 include/hw/gpio/stm32l4x5_gpio.h | 26 | create mode 100644 hw/char/stm32l4x5_usart.c |
42 | create mode 100644 hw/gpio/stm32l4x5_gpio.c | ||
43 | 27 | ||
44 | diff --git a/MAINTAINERS b/MAINTAINERS | 28 | diff --git a/MAINTAINERS b/MAINTAINERS |
45 | index XXXXXXX..XXXXXXX 100644 | 29 | index XXXXXXX..XXXXXXX 100644 |
46 | --- a/MAINTAINERS | 30 | --- a/MAINTAINERS |
47 | +++ b/MAINTAINERS | 31 | +++ b/MAINTAINERS |
48 | @@ -XXX,XX +XXX,XX @@ F: hw/arm/stm32l4x5_soc.c | 32 | @@ -XXX,XX +XXX,XX @@ M: Inès Varhol <ines.varhol@telecom-paris.fr> |
33 | L: qemu-arm@nongnu.org | ||
34 | S: Maintained | ||
35 | F: hw/arm/stm32l4x5_soc.c | ||
36 | +F: hw/char/stm32l4x5_usart.c | ||
49 | F: hw/misc/stm32l4x5_exti.c | 37 | F: hw/misc/stm32l4x5_exti.c |
50 | F: hw/misc/stm32l4x5_syscfg.c | 38 | F: hw/misc/stm32l4x5_syscfg.c |
51 | F: hw/misc/stm32l4x5_rcc.c | 39 | F: hw/misc/stm32l4x5_rcc.c |
52 | +F: hw/gpio/stm32l4x5_gpio.c | 40 | diff --git a/include/hw/char/stm32l4x5_usart.h b/include/hw/char/stm32l4x5_usart.h |
53 | F: include/hw/*/stm32l4x5_*.h | ||
54 | |||
55 | B-L475E-IOT01A IoT Node | ||
56 | diff --git a/docs/system/arm/b-l475e-iot01a.rst b/docs/system/arm/b-l475e-iot01a.rst | ||
57 | index XXXXXXX..XXXXXXX 100644 | ||
58 | --- a/docs/system/arm/b-l475e-iot01a.rst | ||
59 | +++ b/docs/system/arm/b-l475e-iot01a.rst | ||
60 | @@ -XXX,XX +XXX,XX @@ Currently B-L475E-IOT01A machine's only supports the following devices: | ||
61 | - STM32L4x5 EXTI (Extended interrupts and events controller) | ||
62 | - STM32L4x5 SYSCFG (System configuration controller) | ||
63 | - STM32L4x5 RCC (Reset and clock control) | ||
64 | +- STM32L4x5 GPIOs (General-purpose I/Os) | ||
65 | |||
66 | Missing devices | ||
67 | """"""""""""""" | ||
68 | @@ -XXX,XX +XXX,XX @@ Missing devices | ||
69 | The B-L475E-IOT01A does *not* support the following devices: | ||
70 | |||
71 | - Serial ports (UART) | ||
72 | -- General-purpose I/Os (GPIO) | ||
73 | - Analog to Digital Converter (ADC) | ||
74 | - SPI controller | ||
75 | - Timer controller (TIMER) | ||
76 | diff --git a/include/hw/gpio/stm32l4x5_gpio.h b/include/hw/gpio/stm32l4x5_gpio.h | ||
77 | new file mode 100644 | 41 | new file mode 100644 |
78 | index XXXXXXX..XXXXXXX | 42 | index XXXXXXX..XXXXXXX |
79 | --- /dev/null | 43 | --- /dev/null |
80 | +++ b/include/hw/gpio/stm32l4x5_gpio.h | 44 | +++ b/include/hw/char/stm32l4x5_usart.h |
81 | @@ -XXX,XX +XXX,XX @@ | 45 | @@ -XXX,XX +XXX,XX @@ |
82 | +/* | 46 | +/* |
83 | + * STM32L4x5 GPIO (General Purpose Input/Ouput) | 47 | + * STM32L4X5 USART (Universal Synchronous Asynchronous Receiver Transmitter) |
84 | + * | 48 | + * |
85 | + * Copyright (c) 2024 Arnaud Minier <arnaud.minier@telecom-paris.fr> | 49 | + * Copyright (c) 2023 Arnaud Minier <arnaud.minier@telecom-paris.fr> |
86 | + * Copyright (c) 2024 Inès Varhol <ines.varhol@telecom-paris.fr> | 50 | + * Copyright (c) 2023 Inès Varhol <ines.varhol@telecom-paris.fr> |
87 | + * | 51 | + * |
88 | + * SPDX-License-Identifier: GPL-2.0-or-later | 52 | + * SPDX-License-Identifier: GPL-2.0-or-later |
89 | + * | 53 | + * |
90 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | 54 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. |
91 | + * See the COPYING file in the top-level directory. | 55 | + * See the COPYING file in the top-level directory. |
92 | + */ | 56 | + * |
93 | + | 57 | + * The STM32L4X5 USART is heavily inspired by the stm32f2xx_usart |
94 | +/* | 58 | + * by Alistair Francis. |
95 | + * The reference used is the STMicroElectronics RM0351 Reference manual | 59 | + * The reference used is the STMicroElectronics RM0351 Reference manual |
96 | + * for STM32L4x5 and STM32L4x6 advanced Arm ® -based 32-bit MCUs. | 60 | + * for STM32L4x5 and STM32L4x6 advanced Arm ® -based 32-bit MCUs. |
97 | + * https://www.st.com/en/microcontrollers-microprocessors/stm32l4x5/documentation.html | ||
98 | + */ | 61 | + */ |
99 | + | 62 | + |
100 | +#ifndef HW_STM32L4X5_GPIO_H | 63 | +#ifndef HW_STM32L4X5_USART_H |
101 | +#define HW_STM32L4X5_GPIO_H | 64 | +#define HW_STM32L4X5_USART_H |
102 | + | 65 | + |
103 | +#include "hw/sysbus.h" | 66 | +#include "hw/sysbus.h" |
67 | +#include "chardev/char-fe.h" | ||
104 | +#include "qom/object.h" | 68 | +#include "qom/object.h" |
105 | + | 69 | + |
106 | +#define TYPE_STM32L4X5_GPIO "stm32l4x5-gpio" | 70 | +#define TYPE_STM32L4X5_USART_BASE "stm32l4x5-usart-base" |
107 | +OBJECT_DECLARE_SIMPLE_TYPE(Stm32l4x5GpioState, STM32L4X5_GPIO) | 71 | +#define TYPE_STM32L4X5_USART "stm32l4x5-usart" |
108 | + | 72 | +#define TYPE_STM32L4X5_UART "stm32l4x5-uart" |
109 | +#define GPIO_NUM_PINS 16 | 73 | +#define TYPE_STM32L4X5_LPUART "stm32l4x5-lpuart" |
110 | + | 74 | +OBJECT_DECLARE_TYPE(Stm32l4x5UsartBaseState, Stm32l4x5UsartBaseClass, |
111 | +struct Stm32l4x5GpioState { | 75 | + STM32L4X5_USART_BASE) |
76 | + | ||
77 | +typedef enum { | ||
78 | + STM32L4x5_USART, | ||
79 | + STM32L4x5_UART, | ||
80 | + STM32L4x5_LPUART, | ||
81 | +} Stm32l4x5UsartType; | ||
82 | + | ||
83 | +struct Stm32l4x5UsartBaseState { | ||
112 | + SysBusDevice parent_obj; | 84 | + SysBusDevice parent_obj; |
113 | + | 85 | + |
114 | + MemoryRegion mmio; | 86 | + MemoryRegion mmio; |
115 | + | 87 | + |
116 | + /* GPIO registers */ | 88 | + uint32_t cr1; |
117 | + uint32_t moder; | 89 | + uint32_t cr2; |
118 | + uint32_t otyper; | 90 | + uint32_t cr3; |
119 | + uint32_t ospeedr; | 91 | + uint32_t brr; |
120 | + uint32_t pupdr; | 92 | + uint32_t gtpr; |
121 | + uint32_t idr; | 93 | + uint32_t rtor; |
122 | + uint32_t odr; | 94 | + /* rqr is write-only */ |
123 | + uint32_t lckr; | 95 | + uint32_t isr; |
124 | + uint32_t afrl; | 96 | + /* icr is a clear register */ |
125 | + uint32_t afrh; | 97 | + uint32_t rdr; |
126 | + uint32_t ascr; | 98 | + uint32_t tdr; |
127 | + | 99 | + |
128 | + /* GPIO registers reset values */ | ||
129 | + uint32_t moder_reset; | ||
130 | + uint32_t ospeedr_reset; | ||
131 | + uint32_t pupdr_reset; | ||
132 | + | ||
133 | + /* | ||
134 | + * External driving of pins. | ||
135 | + * The pins can be set externally through the device | ||
136 | + * anonymous input GPIOs lines under certain conditions. | ||
137 | + * The pin must not be in push-pull output mode, | ||
138 | + * and can't be set high in open-drain mode. | ||
139 | + * Pins driven externally and configured to | ||
140 | + * output mode will in general be "disconnected" | ||
141 | + * (see `get_gpio_pinmask_to_disconnect()`) | ||
142 | + */ | ||
143 | + uint16_t disconnected_pins; | ||
144 | + uint16_t pins_connected_high; | ||
145 | + | ||
146 | + char *name; | ||
147 | + Clock *clk; | 100 | + Clock *clk; |
148 | + qemu_irq pin[GPIO_NUM_PINS]; | 101 | + CharBackend chr; |
102 | + qemu_irq irq; | ||
149 | +}; | 103 | +}; |
150 | + | 104 | + |
151 | +#endif | 105 | +struct Stm32l4x5UsartBaseClass { |
152 | diff --git a/hw/gpio/stm32l4x5_gpio.c b/hw/gpio/stm32l4x5_gpio.c | 106 | + SysBusDeviceClass parent_class; |
107 | + | ||
108 | + Stm32l4x5UsartType type; | ||
109 | +}; | ||
110 | + | ||
111 | +#endif /* HW_STM32L4X5_USART_H */ | ||
112 | diff --git a/hw/char/stm32l4x5_usart.c b/hw/char/stm32l4x5_usart.c | ||
153 | new file mode 100644 | 113 | new file mode 100644 |
154 | index XXXXXXX..XXXXXXX | 114 | index XXXXXXX..XXXXXXX |
155 | --- /dev/null | 115 | --- /dev/null |
156 | +++ b/hw/gpio/stm32l4x5_gpio.c | 116 | +++ b/hw/char/stm32l4x5_usart.c |
157 | @@ -XXX,XX +XXX,XX @@ | 117 | @@ -XXX,XX +XXX,XX @@ |
158 | +/* | 118 | +/* |
159 | + * STM32L4x5 GPIO (General Purpose Input/Ouput) | 119 | + * STM32L4X5 USART (Universal Synchronous Asynchronous Receiver Transmitter) |
160 | + * | 120 | + * |
161 | + * Copyright (c) 2024 Arnaud Minier <arnaud.minier@telecom-paris.fr> | 121 | + * Copyright (c) 2023 Arnaud Minier <arnaud.minier@telecom-paris.fr> |
162 | + * Copyright (c) 2024 Inès Varhol <ines.varhol@telecom-paris.fr> | 122 | + * Copyright (c) 2023 Inès Varhol <ines.varhol@telecom-paris.fr> |
163 | + * | 123 | + * |
164 | + * SPDX-License-Identifier: GPL-2.0-or-later | 124 | + * SPDX-License-Identifier: GPL-2.0-or-later |
165 | + * | 125 | + * |
166 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | 126 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. |
167 | + * See the COPYING file in the top-level directory. | 127 | + * See the COPYING file in the top-level directory. |
168 | + */ | 128 | + * |
169 | + | 129 | + * The STM32L4X5 USART is heavily inspired by the stm32f2xx_usart |
170 | +/* | 130 | + * by Alistair Francis. |
171 | + * The reference used is the STMicroElectronics RM0351 Reference manual | 131 | + * The reference used is the STMicroElectronics RM0351 Reference manual |
172 | + * for STM32L4x5 and STM32L4x6 advanced Arm ® -based 32-bit MCUs. | 132 | + * for STM32L4x5 and STM32L4x6 advanced Arm ® -based 32-bit MCUs. |
173 | + * https://www.st.com/en/microcontrollers-microprocessors/stm32l4x5/documentation.html | ||
174 | + */ | 133 | + */ |
175 | + | 134 | + |
176 | +#include "qemu/osdep.h" | 135 | +#include "qemu/osdep.h" |
177 | +#include "qemu/log.h" | 136 | +#include "qemu/log.h" |
178 | +#include "hw/gpio/stm32l4x5_gpio.h" | 137 | +#include "qemu/module.h" |
138 | +#include "qapi/error.h" | ||
139 | +#include "chardev/char-fe.h" | ||
140 | +#include "chardev/char-serial.h" | ||
141 | +#include "migration/vmstate.h" | ||
142 | +#include "hw/char/stm32l4x5_usart.h" | ||
143 | +#include "hw/clock.h" | ||
179 | +#include "hw/irq.h" | 144 | +#include "hw/irq.h" |
180 | +#include "hw/qdev-clock.h" | 145 | +#include "hw/qdev-clock.h" |
181 | +#include "hw/qdev-properties.h" | 146 | +#include "hw/qdev-properties.h" |
182 | +#include "qapi/visitor.h" | 147 | +#include "hw/qdev-properties-system.h" |
183 | +#include "qapi/error.h" | 148 | +#include "hw/registerfields.h" |
184 | +#include "migration/vmstate.h" | ||
185 | +#include "trace.h" | 149 | +#include "trace.h" |
186 | + | 150 | + |
187 | +#define GPIO_MODER 0x00 | 151 | + |
188 | +#define GPIO_OTYPER 0x04 | 152 | +REG32(CR1, 0x00) |
189 | +#define GPIO_OSPEEDR 0x08 | 153 | + FIELD(CR1, M1, 28, 1) /* Word length (part 2, see M0) */ |
190 | +#define GPIO_PUPDR 0x0C | 154 | + FIELD(CR1, EOBIE, 27, 1) /* End of Block interrupt enable */ |
191 | +#define GPIO_IDR 0x10 | 155 | + FIELD(CR1, RTOIE, 26, 1) /* Receiver timeout interrupt enable */ |
192 | +#define GPIO_ODR 0x14 | 156 | + FIELD(CR1, DEAT, 21, 5) /* Driver Enable assertion time */ |
193 | +#define GPIO_BSRR 0x18 | 157 | + FIELD(CR1, DEDT, 16, 5) /* Driver Enable de-assertion time */ |
194 | +#define GPIO_LCKR 0x1C | 158 | + FIELD(CR1, OVER8, 15, 1) /* Oversampling mode */ |
195 | +#define GPIO_AFRL 0x20 | 159 | + FIELD(CR1, CMIE, 14, 1) /* Character match interrupt enable */ |
196 | +#define GPIO_AFRH 0x24 | 160 | + FIELD(CR1, MME, 13, 1) /* Mute mode enable */ |
197 | +#define GPIO_BRR 0x28 | 161 | + FIELD(CR1, M0, 12, 1) /* Word length (part 1, see M1) */ |
198 | +#define GPIO_ASCR 0x2C | 162 | + FIELD(CR1, WAKE, 11, 1) /* Receiver wakeup method */ |
199 | + | 163 | + FIELD(CR1, PCE, 10, 1) /* Parity control enable */ |
200 | +/* 0b11111111_11111111_00000000_00000000 */ | 164 | + FIELD(CR1, PS, 9, 1) /* Parity selection */ |
201 | +#define RESERVED_BITS_MASK 0xFFFF0000 | 165 | + FIELD(CR1, PEIE, 8, 1) /* PE interrupt enable */ |
202 | + | 166 | + FIELD(CR1, TXEIE, 7, 1) /* TXE interrupt enable */ |
203 | +static void update_gpio_idr(Stm32l4x5GpioState *s); | 167 | + FIELD(CR1, TCIE, 6, 1) /* Transmission complete interrupt enable */ |
204 | + | 168 | + FIELD(CR1, RXNEIE, 5, 1) /* RXNE interrupt enable */ |
205 | +static bool is_pull_up(Stm32l4x5GpioState *s, unsigned pin) | 169 | + FIELD(CR1, IDLEIE, 4, 1) /* IDLE interrupt enable */ |
206 | +{ | 170 | + FIELD(CR1, TE, 3, 1) /* Transmitter enable */ |
207 | + return extract32(s->pupdr, 2 * pin, 2) == 1; | 171 | + FIELD(CR1, RE, 2, 1) /* Receiver enable */ |
208 | +} | 172 | + FIELD(CR1, UESM, 1, 1) /* USART enable in Stop mode */ |
209 | + | 173 | + FIELD(CR1, UE, 0, 1) /* USART enable */ |
210 | +static bool is_pull_down(Stm32l4x5GpioState *s, unsigned pin) | 174 | +REG32(CR2, 0x04) |
211 | +{ | 175 | + FIELD(CR2, ADD_1, 28, 4) /* ADD[7:4] */ |
212 | + return extract32(s->pupdr, 2 * pin, 2) == 2; | 176 | + FIELD(CR2, ADD_0, 24, 1) /* ADD[3:0] */ |
213 | +} | 177 | + FIELD(CR2, RTOEN, 23, 1) /* Receiver timeout enable */ |
214 | + | 178 | + FIELD(CR2, ABRMOD, 21, 2) /* Auto baud rate mode */ |
215 | +static bool is_output(Stm32l4x5GpioState *s, unsigned pin) | 179 | + FIELD(CR2, ABREN, 20, 1) /* Auto baud rate enable */ |
216 | +{ | 180 | + FIELD(CR2, MSBFIRST, 19, 1) /* Most significant bit first */ |
217 | + return extract32(s->moder, 2 * pin, 2) == 1; | 181 | + FIELD(CR2, DATAINV, 18, 1) /* Binary data inversion */ |
218 | +} | 182 | + FIELD(CR2, TXINV, 17, 1) /* TX pin active level inversion */ |
219 | + | 183 | + FIELD(CR2, RXINV, 16, 1) /* RX pin active level inversion */ |
220 | +static bool is_open_drain(Stm32l4x5GpioState *s, unsigned pin) | 184 | + FIELD(CR2, SWAP, 15, 1) /* Swap RX/TX pins */ |
221 | +{ | 185 | + FIELD(CR2, LINEN, 14, 1) /* LIN mode enable */ |
222 | + return extract32(s->otyper, pin, 1) == 1; | 186 | + FIELD(CR2, STOP, 12, 2) /* STOP bits */ |
223 | +} | 187 | + FIELD(CR2, CLKEN, 11, 1) /* Clock enable */ |
224 | + | 188 | + FIELD(CR2, CPOL, 10, 1) /* Clock polarity */ |
225 | +static bool is_push_pull(Stm32l4x5GpioState *s, unsigned pin) | 189 | + FIELD(CR2, CPHA, 9, 1) /* Clock phase */ |
226 | +{ | 190 | + FIELD(CR2, LBCL, 8, 1) /* Last bit clock pulse */ |
227 | + return extract32(s->otyper, pin, 1) == 0; | 191 | + FIELD(CR2, LBDIE, 6, 1) /* LIN break detection interrupt enable */ |
228 | +} | 192 | + FIELD(CR2, LBDL, 5, 1) /* LIN break detection length */ |
229 | + | 193 | + FIELD(CR2, ADDM7, 4, 1) /* 7-bit / 4-bit Address Detection */ |
230 | +static void stm32l4x5_gpio_reset_hold(Object *obj) | 194 | + |
231 | +{ | 195 | +REG32(CR3, 0x08) |
232 | + Stm32l4x5GpioState *s = STM32L4X5_GPIO(obj); | 196 | + /* TCBGTIE only on STM32L496xx/4A6xx devices */ |
233 | + | 197 | + FIELD(CR3, UCESM, 23, 1) /* USART Clock Enable in Stop Mode */ |
234 | + s->moder = s->moder_reset; | 198 | + FIELD(CR3, WUFIE, 22, 1) /* Wakeup from Stop mode interrupt enable */ |
235 | + s->otyper = 0x00000000; | 199 | + FIELD(CR3, WUS, 20, 2) /* Wakeup from Stop mode interrupt flag selection */ |
236 | + s->ospeedr = s->ospeedr_reset; | 200 | + FIELD(CR3, SCARCNT, 17, 3) /* Smartcard auto-retry count */ |
237 | + s->pupdr = s->pupdr_reset; | 201 | + FIELD(CR3, DEP, 15, 1) /* Driver enable polarity selection */ |
238 | + s->idr = 0x00000000; | 202 | + FIELD(CR3, DEM, 14, 1) /* Driver enable mode */ |
239 | + s->odr = 0x00000000; | 203 | + FIELD(CR3, DDRE, 13, 1) /* DMA Disable on Reception Error */ |
240 | + s->lckr = 0x00000000; | 204 | + FIELD(CR3, OVRDIS, 12, 1) /* Overrun Disable */ |
241 | + s->afrl = 0x00000000; | 205 | + FIELD(CR3, ONEBIT, 11, 1) /* One sample bit method enable */ |
242 | + s->afrh = 0x00000000; | 206 | + FIELD(CR3, CTSIE, 10, 1) /* CTS interrupt enable */ |
243 | + s->ascr = 0x00000000; | 207 | + FIELD(CR3, CTSE, 9, 1) /* CTS enable */ |
244 | + | 208 | + FIELD(CR3, RTSE, 8, 1) /* RTS enable */ |
245 | + s->disconnected_pins = 0xFFFF; | 209 | + FIELD(CR3, DMAT, 7, 1) /* DMA enable transmitter */ |
246 | + s->pins_connected_high = 0x0000; | 210 | + FIELD(CR3, DMAR, 6, 1) /* DMA enable receiver */ |
247 | + update_gpio_idr(s); | 211 | + FIELD(CR3, SCEN, 5, 1) /* Smartcard mode enable */ |
248 | +} | 212 | + FIELD(CR3, NACK, 4, 1) /* Smartcard NACK enable */ |
249 | + | 213 | + FIELD(CR3, HDSEL, 3, 1) /* Half-duplex selection */ |
250 | +static void stm32l4x5_gpio_set(void *opaque, int line, int level) | 214 | + FIELD(CR3, IRLP, 2, 1) /* IrDA low-power */ |
251 | +{ | 215 | + FIELD(CR3, IREN, 1, 1) /* IrDA mode enable */ |
252 | + Stm32l4x5GpioState *s = opaque; | 216 | + FIELD(CR3, EIE, 0, 1) /* Error interrupt enable */ |
253 | + /* | 217 | +REG32(BRR, 0x0C) |
254 | + * The pin isn't set if line is configured in output mode | 218 | + FIELD(BRR, BRR, 0, 16) |
255 | + * except if level is 0 and the output is open-drain. | 219 | +REG32(GTPR, 0x10) |
256 | + * This way there will be no short-circuit prone situations. | 220 | + FIELD(GTPR, GT, 8, 8) /* Guard time value */ |
257 | + */ | 221 | + FIELD(GTPR, PSC, 0, 8) /* Prescaler value */ |
258 | + if (is_output(s, line) && !(is_open_drain(s, line) && (level == 0))) { | 222 | +REG32(RTOR, 0x14) |
259 | + qemu_log_mask(LOG_GUEST_ERROR, "Line %d can't be driven externally\n", | 223 | + FIELD(RTOR, BLEN, 24, 8) /* Block Length */ |
260 | + line); | 224 | + FIELD(RTOR, RTO, 0, 24) /* Receiver timeout value */ |
261 | + return; | 225 | +REG32(RQR, 0x18) |
262 | + } | 226 | + FIELD(RQR, TXFRQ, 4, 1) /* Transmit data flush request */ |
263 | + | 227 | + FIELD(RQR, RXFRQ, 3, 1) /* Receive data flush request */ |
264 | + s->disconnected_pins &= ~(1 << line); | 228 | + FIELD(RQR, MMRQ, 2, 1) /* Mute mode request */ |
265 | + if (level) { | 229 | + FIELD(RQR, SBKRQ, 1, 1) /* Send break request */ |
266 | + s->pins_connected_high |= (1 << line); | 230 | + FIELD(RQR, ABBRRQ, 0, 1) /* Auto baud rate request */ |
267 | + } else { | 231 | +REG32(ISR, 0x1C) |
268 | + s->pins_connected_high &= ~(1 << line); | 232 | + /* TCBGT only for STM32L475xx/476xx/486xx devices */ |
269 | + } | 233 | + FIELD(ISR, REACK, 22, 1) /* Receive enable acknowledge flag */ |
270 | + trace_stm32l4x5_gpio_pins(s->name, s->disconnected_pins, | 234 | + FIELD(ISR, TEACK, 21, 1) /* Transmit enable acknowledge flag */ |
271 | + s->pins_connected_high); | 235 | + FIELD(ISR, WUF, 20, 1) /* Wakeup from Stop mode flag */ |
272 | + update_gpio_idr(s); | 236 | + FIELD(ISR, RWU, 19, 1) /* Receiver wakeup from Mute mode */ |
273 | +} | 237 | + FIELD(ISR, SBKF, 18, 1) /* Send break flag */ |
274 | + | 238 | + FIELD(ISR, CMF, 17, 1) /* Character match flag */ |
275 | + | 239 | + FIELD(ISR, BUSY, 16, 1) /* Busy flag */ |
276 | +static void update_gpio_idr(Stm32l4x5GpioState *s) | 240 | + FIELD(ISR, ABRF, 15, 1) /* Auto Baud rate flag */ |
277 | +{ | 241 | + FIELD(ISR, ABRE, 14, 1) /* Auto Baud rate error */ |
278 | + uint32_t new_idr_mask = 0; | 242 | + FIELD(ISR, EOBF, 12, 1) /* End of block flag */ |
279 | + uint32_t new_idr = s->odr; | 243 | + FIELD(ISR, RTOF, 11, 1) /* Receiver timeout */ |
280 | + uint32_t old_idr = s->idr; | 244 | + FIELD(ISR, CTS, 10, 1) /* CTS flag */ |
281 | + int new_pin_state, old_pin_state; | 245 | + FIELD(ISR, CTSIF, 9, 1) /* CTS interrupt flag */ |
282 | + | 246 | + FIELD(ISR, LBDF, 8, 1) /* LIN break detection flag */ |
283 | + for (int i = 0; i < GPIO_NUM_PINS; i++) { | 247 | + FIELD(ISR, TXE, 7, 1) /* Transmit data register empty */ |
284 | + if (is_output(s, i)) { | 248 | + FIELD(ISR, TC, 6, 1) /* Transmission complete */ |
285 | + if (is_push_pull(s, i)) { | 249 | + FIELD(ISR, RXNE, 5, 1) /* Read data register not empty */ |
286 | + new_idr_mask |= (1 << i); | 250 | + FIELD(ISR, IDLE, 4, 1) /* Idle line detected */ |
287 | + } else if (!(s->odr & (1 << i))) { | 251 | + FIELD(ISR, ORE, 3, 1) /* Overrun error */ |
288 | + /* open-drain ODR 0 */ | 252 | + FIELD(ISR, NF, 2, 1) /* START bit Noise detection flag */ |
289 | + new_idr_mask |= (1 << i); | 253 | + FIELD(ISR, FE, 1, 1) /* Framing Error */ |
290 | + /* open-drain ODR 1 */ | 254 | + FIELD(ISR, PE, 0, 1) /* Parity Error */ |
291 | + } else if (!(s->disconnected_pins & (1 << i)) && | 255 | +REG32(ICR, 0x20) |
292 | + !(s->pins_connected_high & (1 << i))) { | 256 | + FIELD(ICR, WUCF, 20, 1) /* Wakeup from Stop mode clear flag */ |
293 | + /* open-drain ODR 1 with pin connected low */ | 257 | + FIELD(ICR, CMCF, 17, 1) /* Character match clear flag */ |
294 | + new_idr_mask |= (1 << i); | 258 | + FIELD(ICR, EOBCF, 12, 1) /* End of block clear flag */ |
295 | + new_idr &= ~(1 << i); | 259 | + FIELD(ICR, RTOCF, 11, 1) /* Receiver timeout clear flag */ |
296 | + /* open-drain ODR 1 with unactive pin */ | 260 | + FIELD(ICR, CTSCF, 9, 1) /* CTS clear flag */ |
297 | + } else if (is_pull_up(s, i)) { | 261 | + FIELD(ICR, LBDCF, 8, 1) /* LIN break detection clear flag */ |
298 | + new_idr_mask |= (1 << i); | 262 | + /* TCBGTCF only on STM32L496xx/4A6xx devices */ |
299 | + } else if (is_pull_down(s, i)) { | 263 | + FIELD(ICR, TCCF, 6, 1) /* Transmission complete clear flag */ |
300 | + new_idr_mask |= (1 << i); | 264 | + FIELD(ICR, IDLECF, 4, 1) /* Idle line detected clear flag */ |
301 | + new_idr &= ~(1 << i); | 265 | + FIELD(ICR, ORECF, 3, 1) /* Overrun error clear flag */ |
302 | + } | 266 | + FIELD(ICR, NCF, 2, 1) /* Noise detected clear flag */ |
303 | + /* | 267 | + FIELD(ICR, FECF, 1, 1) /* Framing error clear flag */ |
304 | + * The only case left is for open-drain ODR 1 | 268 | + FIELD(ICR, PECF, 0, 1) /* Parity error clear flag */ |
305 | + * with unactive pin without pull-up or pull-down : | 269 | +REG32(RDR, 0x24) |
306 | + * the value is floating. | 270 | + FIELD(RDR, RDR, 0, 9) |
307 | + */ | 271 | +REG32(TDR, 0x28) |
308 | + /* input or analog mode with connected pin */ | 272 | + FIELD(TDR, TDR, 0, 9) |
309 | + } else if (!(s->disconnected_pins & (1 << i))) { | 273 | + |
310 | + if (s->pins_connected_high & (1 << i)) { | 274 | +static void stm32l4x5_usart_base_reset_hold(Object *obj, ResetType type) |
311 | + /* pin high */ | 275 | +{ |
312 | + new_idr_mask |= (1 << i); | 276 | + Stm32l4x5UsartBaseState *s = STM32L4X5_USART_BASE(obj); |
313 | + new_idr |= (1 << i); | 277 | + |
314 | + } else { | 278 | + s->cr1 = 0x00000000; |
315 | + /* pin low */ | 279 | + s->cr2 = 0x00000000; |
316 | + new_idr_mask |= (1 << i); | 280 | + s->cr3 = 0x00000000; |
317 | + new_idr &= ~(1 << i); | 281 | + s->brr = 0x00000000; |
318 | + } | 282 | + s->gtpr = 0x00000000; |
319 | + /* input or analog mode with disconnected pin */ | 283 | + s->rtor = 0x00000000; |
320 | + } else { | 284 | + s->isr = 0x020000C0; |
321 | + if (is_pull_up(s, i)) { | 285 | + s->rdr = 0x00000000; |
322 | + /* pull-up */ | 286 | + s->tdr = 0x00000000; |
323 | + new_idr_mask |= (1 << i); | 287 | +} |
324 | + new_idr |= (1 << i); | 288 | + |
325 | + } else if (is_pull_down(s, i)) { | 289 | +static uint64_t stm32l4x5_usart_base_read(void *opaque, hwaddr addr, |
326 | + /* pull-down */ | 290 | + unsigned int size) |
327 | + new_idr_mask |= (1 << i); | 291 | +{ |
328 | + new_idr &= ~(1 << i); | 292 | + Stm32l4x5UsartBaseState *s = opaque; |
329 | + } | 293 | + uint64_t retvalue = 0; |
330 | + /* | ||
331 | + * The only case left is for a disconnected pin | ||
332 | + * without pull-up or pull-down : | ||
333 | + * the value is floating. | ||
334 | + */ | ||
335 | + } | ||
336 | + } | ||
337 | + | ||
338 | + s->idr = (old_idr & ~new_idr_mask) | (new_idr & new_idr_mask); | ||
339 | + trace_stm32l4x5_gpio_update_idr(s->name, old_idr, s->idr); | ||
340 | + | ||
341 | + for (int i = 0; i < GPIO_NUM_PINS; i++) { | ||
342 | + if (new_idr_mask & (1 << i)) { | ||
343 | + new_pin_state = (new_idr & (1 << i)) > 0; | ||
344 | + old_pin_state = (old_idr & (1 << i)) > 0; | ||
345 | + if (new_pin_state > old_pin_state) { | ||
346 | + qemu_irq_raise(s->pin[i]); | ||
347 | + } else if (new_pin_state < old_pin_state) { | ||
348 | + qemu_irq_lower(s->pin[i]); | ||
349 | + } | ||
350 | + } | ||
351 | + } | ||
352 | +} | ||
353 | + | ||
354 | +/* | ||
355 | + * Return mask of pins that are both configured in output | ||
356 | + * mode and externally driven (except pins in open-drain | ||
357 | + * mode externally set to 0). | ||
358 | + */ | ||
359 | +static uint32_t get_gpio_pinmask_to_disconnect(Stm32l4x5GpioState *s) | ||
360 | +{ | ||
361 | + uint32_t pins_to_disconnect = 0; | ||
362 | + for (int i = 0; i < GPIO_NUM_PINS; i++) { | ||
363 | + /* for each connected pin in output mode */ | ||
364 | + if (!(s->disconnected_pins & (1 << i)) && is_output(s, i)) { | ||
365 | + /* if either push-pull or high level */ | ||
366 | + if (is_push_pull(s, i) || s->pins_connected_high & (1 << i)) { | ||
367 | + pins_to_disconnect |= (1 << i); | ||
368 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
369 | + "Line %d can't be driven externally\n", | ||
370 | + i); | ||
371 | + } | ||
372 | + } | ||
373 | + } | ||
374 | + return pins_to_disconnect; | ||
375 | +} | ||
376 | + | ||
377 | +/* | ||
378 | + * Set field `disconnected_pins` and call `update_gpio_idr()` | ||
379 | + */ | ||
380 | +static void disconnect_gpio_pins(Stm32l4x5GpioState *s, uint16_t lines) | ||
381 | +{ | ||
382 | + s->disconnected_pins |= lines; | ||
383 | + trace_stm32l4x5_gpio_pins(s->name, s->disconnected_pins, | ||
384 | + s->pins_connected_high); | ||
385 | + update_gpio_idr(s); | ||
386 | +} | ||
387 | + | ||
388 | +static void disconnected_pins_set(Object *obj, Visitor *v, | ||
389 | + const char *name, void *opaque, Error **errp) | ||
390 | +{ | ||
391 | + Stm32l4x5GpioState *s = STM32L4X5_GPIO(obj); | ||
392 | + uint16_t value; | ||
393 | + if (!visit_type_uint16(v, name, &value, errp)) { | ||
394 | + return; | ||
395 | + } | ||
396 | + disconnect_gpio_pins(s, value); | ||
397 | +} | ||
398 | + | ||
399 | +static void disconnected_pins_get(Object *obj, Visitor *v, | ||
400 | + const char *name, void *opaque, Error **errp) | ||
401 | +{ | ||
402 | + visit_type_uint16(v, name, (uint16_t *)opaque, errp); | ||
403 | +} | ||
404 | + | ||
405 | +static void clock_freq_get(Object *obj, Visitor *v, | ||
406 | + const char *name, void *opaque, Error **errp) | ||
407 | +{ | ||
408 | + Stm32l4x5GpioState *s = STM32L4X5_GPIO(obj); | ||
409 | + uint32_t clock_freq_hz = clock_get_hz(s->clk); | ||
410 | + visit_type_uint32(v, name, &clock_freq_hz, errp); | ||
411 | +} | ||
412 | + | ||
413 | +static void stm32l4x5_gpio_write(void *opaque, hwaddr addr, | ||
414 | + uint64_t val64, unsigned int size) | ||
415 | +{ | ||
416 | + Stm32l4x5GpioState *s = opaque; | ||
417 | + | ||
418 | + uint32_t value = val64; | ||
419 | + trace_stm32l4x5_gpio_write(s->name, addr, val64); | ||
420 | + | 294 | + |
421 | + switch (addr) { | 295 | + switch (addr) { |
422 | + case GPIO_MODER: | 296 | + case A_CR1: |
423 | + s->moder = value; | 297 | + retvalue = s->cr1; |
424 | + disconnect_gpio_pins(s, get_gpio_pinmask_to_disconnect(s)); | 298 | + break; |
425 | + qemu_log_mask(LOG_UNIMP, | 299 | + case A_CR2: |
426 | + "%s: Analog and AF modes aren't supported\n\ | 300 | + retvalue = s->cr2; |
427 | + Analog and AF mode behave like input mode\n", | 301 | + break; |
428 | + __func__); | 302 | + case A_CR3: |
429 | + return; | 303 | + retvalue = s->cr3; |
430 | + case GPIO_OTYPER: | 304 | + break; |
431 | + s->otyper = value & ~RESERVED_BITS_MASK; | 305 | + case A_BRR: |
432 | + disconnect_gpio_pins(s, get_gpio_pinmask_to_disconnect(s)); | 306 | + retvalue = FIELD_EX32(s->brr, BRR, BRR); |
433 | + return; | 307 | + break; |
434 | + case GPIO_OSPEEDR: | 308 | + case A_GTPR: |
435 | + qemu_log_mask(LOG_UNIMP, | 309 | + retvalue = s->gtpr; |
436 | + "%s: Changing I/O output speed isn't supported\n\ | 310 | + break; |
437 | + I/O speed is already maximal\n", | 311 | + case A_RTOR: |
438 | + __func__); | 312 | + retvalue = s->rtor; |
439 | + s->ospeedr = value; | 313 | + break; |
440 | + return; | 314 | + case A_RQR: |
441 | + case GPIO_PUPDR: | 315 | + /* RQR is a write only register */ |
442 | + s->pupdr = value; | 316 | + retvalue = 0x00000000; |
443 | + update_gpio_idr(s); | 317 | + break; |
444 | + return; | 318 | + case A_ISR: |
445 | + case GPIO_IDR: | 319 | + retvalue = s->isr; |
446 | + qemu_log_mask(LOG_UNIMP, | 320 | + break; |
447 | + "%s: GPIO->IDR is read-only\n", | 321 | + case A_ICR: |
448 | + __func__); | 322 | + /* ICR is a clear register */ |
449 | + return; | 323 | + retvalue = 0x00000000; |
450 | + case GPIO_ODR: | 324 | + break; |
451 | + s->odr = value & ~RESERVED_BITS_MASK; | 325 | + case A_RDR: |
452 | + update_gpio_idr(s); | 326 | + retvalue = FIELD_EX32(s->rdr, RDR, RDR); |
453 | + return; | 327 | + /* Reset RXNE flag */ |
454 | + case GPIO_BSRR: { | 328 | + s->isr &= ~R_ISR_RXNE_MASK; |
455 | + uint32_t bits_to_reset = (value & RESERVED_BITS_MASK) >> GPIO_NUM_PINS; | 329 | + break; |
456 | + uint32_t bits_to_set = value & ~RESERVED_BITS_MASK; | 330 | + case A_TDR: |
457 | + /* If both BSx and BRx are set, BSx has priority.*/ | 331 | + retvalue = FIELD_EX32(s->tdr, TDR, TDR); |
458 | + s->odr &= ~bits_to_reset; | 332 | + break; |
459 | + s->odr |= bits_to_set; | ||
460 | + update_gpio_idr(s); | ||
461 | + return; | ||
462 | + } | ||
463 | + case GPIO_LCKR: | ||
464 | + qemu_log_mask(LOG_UNIMP, | ||
465 | + "%s: Locking port bits configuration isn't supported\n", | ||
466 | + __func__); | ||
467 | + s->lckr = value & ~RESERVED_BITS_MASK; | ||
468 | + return; | ||
469 | + case GPIO_AFRL: | ||
470 | + qemu_log_mask(LOG_UNIMP, | ||
471 | + "%s: Alternate functions aren't supported\n", | ||
472 | + __func__); | ||
473 | + s->afrl = value; | ||
474 | + return; | ||
475 | + case GPIO_AFRH: | ||
476 | + qemu_log_mask(LOG_UNIMP, | ||
477 | + "%s: Alternate functions aren't supported\n", | ||
478 | + __func__); | ||
479 | + s->afrh = value; | ||
480 | + return; | ||
481 | + case GPIO_BRR: { | ||
482 | + uint32_t bits_to_reset = value & ~RESERVED_BITS_MASK; | ||
483 | + s->odr &= ~bits_to_reset; | ||
484 | + update_gpio_idr(s); | ||
485 | + return; | ||
486 | + } | ||
487 | + case GPIO_ASCR: | ||
488 | + qemu_log_mask(LOG_UNIMP, | ||
489 | + "%s: ADC function isn't supported\n", | ||
490 | + __func__); | ||
491 | + s->ascr = value & ~RESERVED_BITS_MASK; | ||
492 | + return; | ||
493 | + default: | 333 | + default: |
494 | + qemu_log_mask(LOG_GUEST_ERROR, | 334 | + qemu_log_mask(LOG_GUEST_ERROR, |
495 | + "%s: Bad offset 0x%" HWADDR_PRIx "\n", __func__, addr); | 335 | + "%s: Bad offset 0x%"HWADDR_PRIx"\n", __func__, addr); |
336 | + break; | ||
496 | + } | 337 | + } |
497 | +} | 338 | + |
498 | + | 339 | + trace_stm32l4x5_usart_read(addr, retvalue); |
499 | +static uint64_t stm32l4x5_gpio_read(void *opaque, hwaddr addr, | 340 | + |
500 | + unsigned int size) | 341 | + return retvalue; |
501 | +{ | 342 | +} |
502 | + Stm32l4x5GpioState *s = opaque; | 343 | + |
503 | + | 344 | +static void stm32l4x5_usart_base_write(void *opaque, hwaddr addr, |
504 | + trace_stm32l4x5_gpio_read(s->name, addr); | 345 | + uint64_t val64, unsigned int size) |
346 | +{ | ||
347 | + Stm32l4x5UsartBaseState *s = opaque; | ||
348 | + const uint32_t value = val64; | ||
349 | + | ||
350 | + trace_stm32l4x5_usart_write(addr, value); | ||
505 | + | 351 | + |
506 | + switch (addr) { | 352 | + switch (addr) { |
507 | + case GPIO_MODER: | 353 | + case A_CR1: |
508 | + return s->moder; | 354 | + s->cr1 = value; |
509 | + case GPIO_OTYPER: | 355 | + return; |
510 | + return s->otyper; | 356 | + case A_CR2: |
511 | + case GPIO_OSPEEDR: | 357 | + s->cr2 = value; |
512 | + return s->ospeedr; | 358 | + return; |
513 | + case GPIO_PUPDR: | 359 | + case A_CR3: |
514 | + return s->pupdr; | 360 | + s->cr3 = value; |
515 | + case GPIO_IDR: | 361 | + return; |
516 | + return s->idr; | 362 | + case A_BRR: |
517 | + case GPIO_ODR: | 363 | + s->brr = value; |
518 | + return s->odr; | 364 | + return; |
519 | + case GPIO_BSRR: | 365 | + case A_GTPR: |
520 | + return 0; | 366 | + s->gtpr = value; |
521 | + case GPIO_LCKR: | 367 | + return; |
522 | + return s->lckr; | 368 | + case A_RTOR: |
523 | + case GPIO_AFRL: | 369 | + s->rtor = value; |
524 | + return s->afrl; | 370 | + return; |
525 | + case GPIO_AFRH: | 371 | + case A_RQR: |
526 | + return s->afrh; | 372 | + return; |
527 | + case GPIO_BRR: | 373 | + case A_ISR: |
528 | + return 0; | 374 | + qemu_log_mask(LOG_GUEST_ERROR, |
529 | + case GPIO_ASCR: | 375 | + "%s: ISR is read only !\n", __func__); |
530 | + return s->ascr; | 376 | + return; |
377 | + case A_ICR: | ||
378 | + /* Clear the status flags */ | ||
379 | + s->isr &= ~value; | ||
380 | + return; | ||
381 | + case A_RDR: | ||
382 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
383 | + "%s: RDR is read only !\n", __func__); | ||
384 | + return; | ||
385 | + case A_TDR: | ||
386 | + s->tdr = value; | ||
387 | + return; | ||
531 | + default: | 388 | + default: |
532 | + qemu_log_mask(LOG_GUEST_ERROR, | 389 | + qemu_log_mask(LOG_GUEST_ERROR, |
533 | + "%s: Bad offset 0x%" HWADDR_PRIx "\n", __func__, addr); | 390 | + "%s: Bad offset 0x%"HWADDR_PRIx"\n", __func__, addr); |
534 | + return 0; | ||
535 | + } | 391 | + } |
536 | +} | 392 | +} |
537 | + | 393 | + |
538 | +static const MemoryRegionOps stm32l4x5_gpio_ops = { | 394 | +static const MemoryRegionOps stm32l4x5_usart_base_ops = { |
539 | + .read = stm32l4x5_gpio_read, | 395 | + .read = stm32l4x5_usart_base_read, |
540 | + .write = stm32l4x5_gpio_write, | 396 | + .write = stm32l4x5_usart_base_write, |
541 | + .endianness = DEVICE_NATIVE_ENDIAN, | 397 | + .endianness = DEVICE_NATIVE_ENDIAN, |
398 | + .valid = { | ||
399 | + .max_access_size = 4, | ||
400 | + .min_access_size = 4, | ||
401 | + .unaligned = false | ||
402 | + }, | ||
542 | + .impl = { | 403 | + .impl = { |
404 | + .max_access_size = 4, | ||
543 | + .min_access_size = 4, | 405 | + .min_access_size = 4, |
544 | + .max_access_size = 4, | 406 | + .unaligned = false |
545 | + .unaligned = false, | ||
546 | + }, | ||
547 | + .valid = { | ||
548 | + .min_access_size = 4, | ||
549 | + .max_access_size = 4, | ||
550 | + .unaligned = false, | ||
551 | + }, | 407 | + }, |
552 | +}; | 408 | +}; |
553 | + | 409 | + |
554 | +static void stm32l4x5_gpio_init(Object *obj) | 410 | +static Property stm32l4x5_usart_base_properties[] = { |
555 | +{ | 411 | + DEFINE_PROP_CHR("chardev", Stm32l4x5UsartBaseState, chr), |
556 | + Stm32l4x5GpioState *s = STM32L4X5_GPIO(obj); | 412 | + DEFINE_PROP_END_OF_LIST(), |
557 | + | 413 | +}; |
558 | + memory_region_init_io(&s->mmio, obj, &stm32l4x5_gpio_ops, s, | 414 | + |
559 | + TYPE_STM32L4X5_GPIO, 0x400); | 415 | +static void stm32l4x5_usart_base_init(Object *obj) |
560 | + | 416 | +{ |
417 | + Stm32l4x5UsartBaseState *s = STM32L4X5_USART_BASE(obj); | ||
418 | + | ||
419 | + sysbus_init_irq(SYS_BUS_DEVICE(obj), &s->irq); | ||
420 | + | ||
421 | + memory_region_init_io(&s->mmio, obj, &stm32l4x5_usart_base_ops, s, | ||
422 | + TYPE_STM32L4X5_USART_BASE, 0x400); | ||
561 | + sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->mmio); | 423 | + sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->mmio); |
562 | + | 424 | + |
563 | + qdev_init_gpio_out(DEVICE(obj), s->pin, GPIO_NUM_PINS); | ||
564 | + qdev_init_gpio_in(DEVICE(obj), stm32l4x5_gpio_set, GPIO_NUM_PINS); | ||
565 | + | ||
566 | + s->clk = qdev_init_clock_in(DEVICE(s), "clk", NULL, s, 0); | 425 | + s->clk = qdev_init_clock_in(DEVICE(s), "clk", NULL, s, 0); |
567 | + | 426 | +} |
568 | + object_property_add(obj, "disconnected-pins", "uint16", | 427 | + |
569 | + disconnected_pins_get, disconnected_pins_set, | 428 | +static const VMStateDescription vmstate_stm32l4x5_usart_base = { |
570 | + NULL, &s->disconnected_pins); | 429 | + .name = TYPE_STM32L4X5_USART_BASE, |
571 | + object_property_add(obj, "clock-freq-hz", "uint32", | ||
572 | + clock_freq_get, NULL, NULL, NULL); | ||
573 | +} | ||
574 | + | ||
575 | +static void stm32l4x5_gpio_realize(DeviceState *dev, Error **errp) | ||
576 | +{ | ||
577 | + Stm32l4x5GpioState *s = STM32L4X5_GPIO(dev); | ||
578 | + if (!clock_has_source(s->clk)) { | ||
579 | + error_setg(errp, "GPIO: clk input must be connected"); | ||
580 | + return; | ||
581 | + } | ||
582 | +} | ||
583 | + | ||
584 | +static const VMStateDescription vmstate_stm32l4x5_gpio = { | ||
585 | + .name = TYPE_STM32L4X5_GPIO, | ||
586 | + .version_id = 1, | 430 | + .version_id = 1, |
587 | + .minimum_version_id = 1, | 431 | + .minimum_version_id = 1, |
588 | + .fields = (VMStateField[]){ | 432 | + .fields = (VMStateField[]) { |
589 | + VMSTATE_UINT32(moder, Stm32l4x5GpioState), | 433 | + VMSTATE_UINT32(cr1, Stm32l4x5UsartBaseState), |
590 | + VMSTATE_UINT32(otyper, Stm32l4x5GpioState), | 434 | + VMSTATE_UINT32(cr2, Stm32l4x5UsartBaseState), |
591 | + VMSTATE_UINT32(ospeedr, Stm32l4x5GpioState), | 435 | + VMSTATE_UINT32(cr3, Stm32l4x5UsartBaseState), |
592 | + VMSTATE_UINT32(pupdr, Stm32l4x5GpioState), | 436 | + VMSTATE_UINT32(brr, Stm32l4x5UsartBaseState), |
593 | + VMSTATE_UINT32(idr, Stm32l4x5GpioState), | 437 | + VMSTATE_UINT32(gtpr, Stm32l4x5UsartBaseState), |
594 | + VMSTATE_UINT32(odr, Stm32l4x5GpioState), | 438 | + VMSTATE_UINT32(rtor, Stm32l4x5UsartBaseState), |
595 | + VMSTATE_UINT32(lckr, Stm32l4x5GpioState), | 439 | + VMSTATE_UINT32(isr, Stm32l4x5UsartBaseState), |
596 | + VMSTATE_UINT32(afrl, Stm32l4x5GpioState), | 440 | + VMSTATE_UINT32(rdr, Stm32l4x5UsartBaseState), |
597 | + VMSTATE_UINT32(afrh, Stm32l4x5GpioState), | 441 | + VMSTATE_UINT32(tdr, Stm32l4x5UsartBaseState), |
598 | + VMSTATE_UINT32(ascr, Stm32l4x5GpioState), | 442 | + VMSTATE_CLOCK(clk, Stm32l4x5UsartBaseState), |
599 | + VMSTATE_UINT16(disconnected_pins, Stm32l4x5GpioState), | ||
600 | + VMSTATE_UINT16(pins_connected_high, Stm32l4x5GpioState), | ||
601 | + VMSTATE_END_OF_LIST() | 443 | + VMSTATE_END_OF_LIST() |
602 | + } | 444 | + } |
603 | +}; | 445 | +}; |
604 | + | 446 | + |
605 | +static Property stm32l4x5_gpio_properties[] = { | 447 | + |
606 | + DEFINE_PROP_STRING("name", Stm32l4x5GpioState, name), | 448 | +static void stm32l4x5_usart_base_realize(DeviceState *dev, Error **errp) |
607 | + DEFINE_PROP_UINT32("mode-reset", Stm32l4x5GpioState, moder_reset, 0), | 449 | +{ |
608 | + DEFINE_PROP_UINT32("ospeed-reset", Stm32l4x5GpioState, ospeedr_reset, 0), | 450 | + ERRP_GUARD(); |
609 | + DEFINE_PROP_UINT32("pupd-reset", Stm32l4x5GpioState, pupdr_reset, 0), | 451 | + Stm32l4x5UsartBaseState *s = STM32L4X5_USART_BASE(dev); |
610 | + DEFINE_PROP_END_OF_LIST(), | 452 | + if (!clock_has_source(s->clk)) { |
611 | +}; | 453 | + error_setg(errp, "USART clock must be wired up by SoC code"); |
612 | + | 454 | + return; |
613 | +static void stm32l4x5_gpio_class_init(ObjectClass *klass, void *data) | 455 | + } |
456 | +} | ||
457 | + | ||
458 | +static void stm32l4x5_usart_base_class_init(ObjectClass *klass, void *data) | ||
614 | +{ | 459 | +{ |
615 | + DeviceClass *dc = DEVICE_CLASS(klass); | 460 | + DeviceClass *dc = DEVICE_CLASS(klass); |
616 | + ResettableClass *rc = RESETTABLE_CLASS(klass); | 461 | + ResettableClass *rc = RESETTABLE_CLASS(klass); |
617 | + | 462 | + |
618 | + device_class_set_props(dc, stm32l4x5_gpio_properties); | 463 | + rc->phases.hold = stm32l4x5_usart_base_reset_hold; |
619 | + dc->vmsd = &vmstate_stm32l4x5_gpio; | 464 | + device_class_set_props(dc, stm32l4x5_usart_base_properties); |
620 | + dc->realize = stm32l4x5_gpio_realize; | 465 | + dc->realize = stm32l4x5_usart_base_realize; |
621 | + rc->phases.hold = stm32l4x5_gpio_reset_hold; | 466 | + dc->vmsd = &vmstate_stm32l4x5_usart_base; |
622 | +} | 467 | +} |
623 | + | 468 | + |
624 | +static const TypeInfo stm32l4x5_gpio_types[] = { | 469 | +static void stm32l4x5_usart_class_init(ObjectClass *oc, void *data) |
470 | +{ | ||
471 | + Stm32l4x5UsartBaseClass *subc = STM32L4X5_USART_BASE_CLASS(oc); | ||
472 | + | ||
473 | + subc->type = STM32L4x5_USART; | ||
474 | +} | ||
475 | + | ||
476 | +static void stm32l4x5_uart_class_init(ObjectClass *oc, void *data) | ||
477 | +{ | ||
478 | + Stm32l4x5UsartBaseClass *subc = STM32L4X5_USART_BASE_CLASS(oc); | ||
479 | + | ||
480 | + subc->type = STM32L4x5_UART; | ||
481 | +} | ||
482 | + | ||
483 | +static void stm32l4x5_lpuart_class_init(ObjectClass *oc, void *data) | ||
484 | +{ | ||
485 | + Stm32l4x5UsartBaseClass *subc = STM32L4X5_USART_BASE_CLASS(oc); | ||
486 | + | ||
487 | + subc->type = STM32L4x5_LPUART; | ||
488 | +} | ||
489 | + | ||
490 | +static const TypeInfo stm32l4x5_usart_types[] = { | ||
625 | + { | 491 | + { |
626 | + .name = TYPE_STM32L4X5_GPIO, | 492 | + .name = TYPE_STM32L4X5_USART_BASE, |
627 | + .parent = TYPE_SYS_BUS_DEVICE, | 493 | + .parent = TYPE_SYS_BUS_DEVICE, |
628 | + .instance_size = sizeof(Stm32l4x5GpioState), | 494 | + .instance_size = sizeof(Stm32l4x5UsartBaseState), |
629 | + .instance_init = stm32l4x5_gpio_init, | 495 | + .instance_init = stm32l4x5_usart_base_init, |
630 | + .class_init = stm32l4x5_gpio_class_init, | 496 | + .class_init = stm32l4x5_usart_base_class_init, |
631 | + }, | 497 | + .abstract = true, |
498 | + }, { | ||
499 | + .name = TYPE_STM32L4X5_USART, | ||
500 | + .parent = TYPE_STM32L4X5_USART_BASE, | ||
501 | + .class_init = stm32l4x5_usart_class_init, | ||
502 | + }, { | ||
503 | + .name = TYPE_STM32L4X5_UART, | ||
504 | + .parent = TYPE_STM32L4X5_USART_BASE, | ||
505 | + .class_init = stm32l4x5_uart_class_init, | ||
506 | + }, { | ||
507 | + .name = TYPE_STM32L4X5_LPUART, | ||
508 | + .parent = TYPE_STM32L4X5_USART_BASE, | ||
509 | + .class_init = stm32l4x5_lpuart_class_init, | ||
510 | + } | ||
632 | +}; | 511 | +}; |
633 | + | 512 | + |
634 | +DEFINE_TYPES(stm32l4x5_gpio_types) | 513 | +DEFINE_TYPES(stm32l4x5_usart_types) |
635 | diff --git a/hw/gpio/Kconfig b/hw/gpio/Kconfig | 514 | diff --git a/hw/char/Kconfig b/hw/char/Kconfig |
636 | index XXXXXXX..XXXXXXX 100644 | 515 | index XXXXXXX..XXXXXXX 100644 |
637 | --- a/hw/gpio/Kconfig | 516 | --- a/hw/char/Kconfig |
638 | +++ b/hw/gpio/Kconfig | 517 | +++ b/hw/char/Kconfig |
639 | @@ -XXX,XX +XXX,XX @@ config GPIO_PWR | 518 | @@ -XXX,XX +XXX,XX @@ config VIRTIO_SERIAL |
640 | 519 | config STM32F2XX_USART | |
641 | config SIFIVE_GPIO | ||
642 | bool | 520 | bool |
643 | + | 521 | |
644 | +config STM32L4X5_GPIO | 522 | +config STM32L4X5_USART |
645 | + bool | 523 | + bool |
646 | diff --git a/hw/gpio/meson.build b/hw/gpio/meson.build | 524 | + |
525 | config CMSDK_APB_UART | ||
526 | bool | ||
527 | |||
528 | diff --git a/hw/char/meson.build b/hw/char/meson.build | ||
647 | index XXXXXXX..XXXXXXX 100644 | 529 | index XXXXXXX..XXXXXXX 100644 |
648 | --- a/hw/gpio/meson.build | 530 | --- a/hw/char/meson.build |
649 | +++ b/hw/gpio/meson.build | 531 | +++ b/hw/char/meson.build |
650 | @@ -XXX,XX +XXX,XX @@ system_ss.add(when: 'CONFIG_RASPI', if_true: files( | 532 | @@ -XXX,XX +XXX,XX @@ system_ss.add(when: 'CONFIG_RENESAS_SCI', if_true: files('renesas_sci.c')) |
651 | 'bcm2835_gpio.c', | 533 | system_ss.add(when: 'CONFIG_SIFIVE_UART', if_true: files('sifive_uart.c')) |
652 | 'bcm2838_gpio.c' | 534 | system_ss.add(when: 'CONFIG_SH_SCI', if_true: files('sh_serial.c')) |
653 | )) | 535 | system_ss.add(when: 'CONFIG_STM32F2XX_USART', if_true: files('stm32f2xx_usart.c')) |
654 | +system_ss.add(when: 'CONFIG_STM32L4X5_SOC', if_true: files('stm32l4x5_gpio.c')) | 536 | +system_ss.add(when: 'CONFIG_STM32L4X5_USART', if_true: files('stm32l4x5_usart.c')) |
655 | system_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('aspeed_gpio.c')) | 537 | system_ss.add(when: 'CONFIG_MCHP_PFSOC_MMUART', if_true: files('mchp_pfsoc_mmuart.c')) |
656 | system_ss.add(when: 'CONFIG_SIFIVE_GPIO', if_true: files('sifive_gpio.c')) | 538 | system_ss.add(when: 'CONFIG_HTIF', if_true: files('riscv_htif.c')) |
657 | diff --git a/hw/gpio/trace-events b/hw/gpio/trace-events | 539 | system_ss.add(when: 'CONFIG_GOLDFISH_TTY', if_true: files('goldfish_tty.c')) |
540 | diff --git a/hw/char/trace-events b/hw/char/trace-events | ||
658 | index XXXXXXX..XXXXXXX 100644 | 541 | index XXXXXXX..XXXXXXX 100644 |
659 | --- a/hw/gpio/trace-events | 542 | --- a/hw/char/trace-events |
660 | +++ b/hw/gpio/trace-events | 543 | +++ b/hw/char/trace-events |
661 | @@ -XXX,XX +XXX,XX @@ sifive_gpio_update_output_irq(int64_t line, int64_t value) "line %" PRIi64 " val | 544 | @@ -XXX,XX +XXX,XX @@ cadence_uart_baudrate(unsigned baudrate) "baudrate %u" |
662 | # aspeed_gpio.c | 545 | sh_serial_read(char *id, unsigned size, uint64_t offs, uint64_t val) " %s size %d offs 0x%02" PRIx64 " -> 0x%02" PRIx64 |
663 | aspeed_gpio_read(uint64_t offset, uint64_t value) "offset: 0x%" PRIx64 " value 0x%" PRIx64 | 546 | sh_serial_write(char *id, unsigned size, uint64_t offs, uint64_t val) "%s size %d offs 0x%02" PRIx64 " <- 0x%02" PRIx64 |
664 | aspeed_gpio_write(uint64_t offset, uint64_t value) "offset: 0x%" PRIx64 " value 0x%" PRIx64 | 547 | |
665 | + | 548 | +# stm32l4x5_usart.c |
666 | +# stm32l4x5_gpio.c | 549 | +stm32l4x5_usart_read(uint64_t addr, uint32_t data) "USART: Read <0x%" PRIx64 "> -> 0x%" PRIx32 "" |
667 | +stm32l4x5_gpio_read(char *gpio, uint64_t addr) "GPIO%s addr: 0x%" PRIx64 " " | 550 | +stm32l4x5_usart_write(uint64_t addr, uint32_t data) "USART: Write <0x%" PRIx64 "> <- 0x%" PRIx32 "" |
668 | +stm32l4x5_gpio_write(char *gpio, uint64_t addr, uint64_t data) "GPIO%s addr: 0x%" PRIx64 " val: 0x%" PRIx64 "" | 551 | + |
669 | +stm32l4x5_gpio_update_idr(char *gpio, uint32_t old_idr, uint32_t new_idr) "GPIO%s from: 0x%x to: 0x%x" | 552 | # xen_console.c |
670 | +stm32l4x5_gpio_pins(char *gpio, uint16_t disconnected, uint16_t high) "GPIO%s disconnected pins: 0x%x levels: 0x%x" | 553 | xen_console_connect(unsigned int idx, unsigned int ring_ref, unsigned int port, unsigned int limit) "idx %u ring_ref %u port %u limit %u" |
554 | xen_console_disconnect(unsigned int idx) "idx %u" | ||
671 | -- | 555 | -- |
672 | 2.34.1 | 556 | 2.34.1 |
673 | 557 | ||
674 | 558 | diff view generated by jsdifflib |
1 | The sun4v RTC device model added under commit a0e893039cf2ce0 in 2016 | 1 | From: Arnaud Minier <arnaud.minier@telecom-paris.fr> |
---|---|---|---|
2 | was unfortunately added with a license of GPL-v3-or-later, which is | 2 | |
3 | not compatible with other QEMU code which has a GPL-v2-only license. | 3 | Implement the ability to read and write characters to the |
4 | 4 | usart using the serial port. | |
5 | Relicense the code in the .c and the .h file to GPL-v2-or-later, | 5 | |
6 | to make it compatible with the rest of QEMU. | 6 | The character transmission is based on the |
7 | 7 | cmsdk-apb-uart implementation. | |
8 | Cc: qemu-stable@nongnu.org | 8 | |
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Arnaud Minier <arnaud.minier@telecom-paris.fr> |
10 | Signed-off-by: Paolo Bonzini (for Red Hat) <pbonzini@redhat.com> | 10 | Signed-off-by: Inès Varhol <ines.varhol@telecom-paris.fr> |
11 | Signed-off-by: Artyom Tarasenko <atar4qemu@gmail.com> | 11 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
12 | Signed-off-by: Markus Armbruster <armbru@redhat.com> | 12 | Message-id: 20240329174402.60382-3-arnaud.minier@telecom-paris.fr |
13 | Signed-off-by: Alex Bennée <alex.bennee@linaro.org> | 13 | [PMM: fixed a few checkpatch nits] |
14 | Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
15 | Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> | ||
16 | Acked-by: Alex Bennée <alex.bennee@linaro.org> | ||
17 | Message-id: 20240223161300.938542-1-peter.maydell@linaro.org | ||
18 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 14 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
19 | --- | 15 | --- |
20 | include/hw/rtc/sun4v-rtc.h | 2 +- | 16 | include/hw/char/stm32l4x5_usart.h | 1 + |
21 | hw/rtc/sun4v-rtc.c | 2 +- | 17 | hw/char/stm32l4x5_usart.c | 143 ++++++++++++++++++++++++++++++ |
22 | 2 files changed, 2 insertions(+), 2 deletions(-) | 18 | hw/char/trace-events | 7 ++ |
23 | 19 | 3 files changed, 151 insertions(+) | |
24 | diff --git a/include/hw/rtc/sun4v-rtc.h b/include/hw/rtc/sun4v-rtc.h | 20 | |
21 | diff --git a/include/hw/char/stm32l4x5_usart.h b/include/hw/char/stm32l4x5_usart.h | ||
25 | index XXXXXXX..XXXXXXX 100644 | 22 | index XXXXXXX..XXXXXXX 100644 |
26 | --- a/include/hw/rtc/sun4v-rtc.h | 23 | --- a/include/hw/char/stm32l4x5_usart.h |
27 | +++ b/include/hw/rtc/sun4v-rtc.h | 24 | +++ b/include/hw/char/stm32l4x5_usart.h |
28 | @@ -XXX,XX +XXX,XX @@ | 25 | @@ -XXX,XX +XXX,XX @@ struct Stm32l4x5UsartBaseState { |
29 | * | 26 | Clock *clk; |
30 | * Copyright (c) 2016 Artyom Tarasenko | 27 | CharBackend chr; |
31 | * | 28 | qemu_irq irq; |
32 | - * This code is licensed under the GNU GPL v3 or (at your option) any later | 29 | + guint watch_tag; |
33 | + * This code is licensed under the GNU GPL v2 or (at your option) any later | 30 | }; |
34 | * version. | 31 | |
35 | */ | 32 | struct Stm32l4x5UsartBaseClass { |
36 | 33 | diff --git a/hw/char/stm32l4x5_usart.c b/hw/char/stm32l4x5_usart.c | |
37 | diff --git a/hw/rtc/sun4v-rtc.c b/hw/rtc/sun4v-rtc.c | ||
38 | index XXXXXXX..XXXXXXX 100644 | 34 | index XXXXXXX..XXXXXXX 100644 |
39 | --- a/hw/rtc/sun4v-rtc.c | 35 | --- a/hw/char/stm32l4x5_usart.c |
40 | +++ b/hw/rtc/sun4v-rtc.c | 36 | +++ b/hw/char/stm32l4x5_usart.c |
41 | @@ -XXX,XX +XXX,XX @@ | 37 | @@ -XXX,XX +XXX,XX @@ REG32(RDR, 0x24) |
42 | * | 38 | REG32(TDR, 0x28) |
43 | * Copyright (c) 2016 Artyom Tarasenko | 39 | FIELD(TDR, TDR, 0, 9) |
44 | * | 40 | |
45 | - * This code is licensed under the GNU GPL v3 or (at your option) any later | 41 | +static void stm32l4x5_update_irq(Stm32l4x5UsartBaseState *s) |
46 | + * This code is licensed under the GNU GPL v2 or (at your option) any later | 42 | +{ |
47 | * version. | 43 | + if (((s->isr & R_ISR_WUF_MASK) && (s->cr3 & R_CR3_WUFIE_MASK)) || |
48 | */ | 44 | + ((s->isr & R_ISR_CMF_MASK) && (s->cr1 & R_CR1_CMIE_MASK)) || |
49 | 45 | + ((s->isr & R_ISR_ABRF_MASK) && (s->cr1 & R_CR1_RXNEIE_MASK)) || | |
46 | + ((s->isr & R_ISR_EOBF_MASK) && (s->cr1 & R_CR1_EOBIE_MASK)) || | ||
47 | + ((s->isr & R_ISR_RTOF_MASK) && (s->cr1 & R_CR1_RTOIE_MASK)) || | ||
48 | + ((s->isr & R_ISR_CTSIF_MASK) && (s->cr3 & R_CR3_CTSIE_MASK)) || | ||
49 | + ((s->isr & R_ISR_LBDF_MASK) && (s->cr2 & R_CR2_LBDIE_MASK)) || | ||
50 | + ((s->isr & R_ISR_TXE_MASK) && (s->cr1 & R_CR1_TXEIE_MASK)) || | ||
51 | + ((s->isr & R_ISR_TC_MASK) && (s->cr1 & R_CR1_TCIE_MASK)) || | ||
52 | + ((s->isr & R_ISR_RXNE_MASK) && (s->cr1 & R_CR1_RXNEIE_MASK)) || | ||
53 | + ((s->isr & R_ISR_IDLE_MASK) && (s->cr1 & R_CR1_IDLEIE_MASK)) || | ||
54 | + ((s->isr & R_ISR_ORE_MASK) && | ||
55 | + ((s->cr1 & R_CR1_RXNEIE_MASK) || (s->cr3 & R_CR3_EIE_MASK))) || | ||
56 | + /* TODO: Handle NF ? */ | ||
57 | + ((s->isr & R_ISR_FE_MASK) && (s->cr3 & R_CR3_EIE_MASK)) || | ||
58 | + ((s->isr & R_ISR_PE_MASK) && (s->cr1 & R_CR1_PEIE_MASK))) { | ||
59 | + qemu_irq_raise(s->irq); | ||
60 | + trace_stm32l4x5_usart_irq_raised(s->isr); | ||
61 | + } else { | ||
62 | + qemu_irq_lower(s->irq); | ||
63 | + trace_stm32l4x5_usart_irq_lowered(); | ||
64 | + } | ||
65 | +} | ||
66 | + | ||
67 | +static int stm32l4x5_usart_base_can_receive(void *opaque) | ||
68 | +{ | ||
69 | + Stm32l4x5UsartBaseState *s = opaque; | ||
70 | + | ||
71 | + if (!(s->isr & R_ISR_RXNE_MASK)) { | ||
72 | + return 1; | ||
73 | + } | ||
74 | + | ||
75 | + return 0; | ||
76 | +} | ||
77 | + | ||
78 | +static void stm32l4x5_usart_base_receive(void *opaque, const uint8_t *buf, | ||
79 | + int size) | ||
80 | +{ | ||
81 | + Stm32l4x5UsartBaseState *s = opaque; | ||
82 | + | ||
83 | + if (!((s->cr1 & R_CR1_UE_MASK) && (s->cr1 & R_CR1_RE_MASK))) { | ||
84 | + trace_stm32l4x5_usart_receiver_not_enabled( | ||
85 | + FIELD_EX32(s->cr1, CR1, UE), FIELD_EX32(s->cr1, CR1, RE)); | ||
86 | + return; | ||
87 | + } | ||
88 | + | ||
89 | + /* Check if overrun detection is enabled and if there is an overrun */ | ||
90 | + if (!(s->cr3 & R_CR3_OVRDIS_MASK) && (s->isr & R_ISR_RXNE_MASK)) { | ||
91 | + /* | ||
92 | + * A character has been received while | ||
93 | + * the previous has not been read = Overrun. | ||
94 | + */ | ||
95 | + s->isr |= R_ISR_ORE_MASK; | ||
96 | + trace_stm32l4x5_usart_overrun_detected(s->rdr, *buf); | ||
97 | + } else { | ||
98 | + /* No overrun */ | ||
99 | + s->rdr = *buf; | ||
100 | + s->isr |= R_ISR_RXNE_MASK; | ||
101 | + trace_stm32l4x5_usart_rx(s->rdr); | ||
102 | + } | ||
103 | + | ||
104 | + stm32l4x5_update_irq(s); | ||
105 | +} | ||
106 | + | ||
107 | +/* | ||
108 | + * Try to send tx data, and arrange to be called back later if | ||
109 | + * we can't (ie the char backend is busy/blocking). | ||
110 | + */ | ||
111 | +static gboolean usart_transmit(void *do_not_use, GIOCondition cond, | ||
112 | + void *opaque) | ||
113 | +{ | ||
114 | + Stm32l4x5UsartBaseState *s = STM32L4X5_USART_BASE(opaque); | ||
115 | + int ret; | ||
116 | + /* TODO: Handle 9 bits transmission */ | ||
117 | + uint8_t ch = s->tdr; | ||
118 | + | ||
119 | + s->watch_tag = 0; | ||
120 | + | ||
121 | + if (!(s->cr1 & R_CR1_TE_MASK) || (s->isr & R_ISR_TXE_MASK)) { | ||
122 | + return G_SOURCE_REMOVE; | ||
123 | + } | ||
124 | + | ||
125 | + ret = qemu_chr_fe_write(&s->chr, &ch, 1); | ||
126 | + if (ret <= 0) { | ||
127 | + s->watch_tag = qemu_chr_fe_add_watch(&s->chr, G_IO_OUT | G_IO_HUP, | ||
128 | + usart_transmit, s); | ||
129 | + if (!s->watch_tag) { | ||
130 | + /* | ||
131 | + * Most common reason to be here is "no chardev backend": | ||
132 | + * just insta-drain the buffer, so the serial output | ||
133 | + * goes into a void, rather than blocking the guest. | ||
134 | + */ | ||
135 | + goto buffer_drained; | ||
136 | + } | ||
137 | + /* Transmit pending */ | ||
138 | + trace_stm32l4x5_usart_tx_pending(); | ||
139 | + return G_SOURCE_REMOVE; | ||
140 | + } | ||
141 | + | ||
142 | +buffer_drained: | ||
143 | + /* Character successfully sent */ | ||
144 | + trace_stm32l4x5_usart_tx(ch); | ||
145 | + s->isr |= R_ISR_TC_MASK | R_ISR_TXE_MASK; | ||
146 | + stm32l4x5_update_irq(s); | ||
147 | + return G_SOURCE_REMOVE; | ||
148 | +} | ||
149 | + | ||
150 | +static void usart_cancel_transmit(Stm32l4x5UsartBaseState *s) | ||
151 | +{ | ||
152 | + if (s->watch_tag) { | ||
153 | + g_source_remove(s->watch_tag); | ||
154 | + s->watch_tag = 0; | ||
155 | + } | ||
156 | +} | ||
157 | + | ||
158 | static void stm32l4x5_usart_base_reset_hold(Object *obj, ResetType type) | ||
159 | { | ||
160 | Stm32l4x5UsartBaseState *s = STM32L4X5_USART_BASE(obj); | ||
161 | @@ -XXX,XX +XXX,XX @@ static void stm32l4x5_usart_base_reset_hold(Object *obj, ResetType type) | ||
162 | s->isr = 0x020000C0; | ||
163 | s->rdr = 0x00000000; | ||
164 | s->tdr = 0x00000000; | ||
165 | + | ||
166 | + usart_cancel_transmit(s); | ||
167 | + stm32l4x5_update_irq(s); | ||
168 | +} | ||
169 | + | ||
170 | +static void usart_update_rqr(Stm32l4x5UsartBaseState *s, uint32_t value) | ||
171 | +{ | ||
172 | + /* TXFRQ */ | ||
173 | + /* Reset RXNE flag */ | ||
174 | + if (value & R_RQR_RXFRQ_MASK) { | ||
175 | + s->isr &= ~R_ISR_RXNE_MASK; | ||
176 | + } | ||
177 | + /* MMRQ */ | ||
178 | + /* SBKRQ */ | ||
179 | + /* ABRRQ */ | ||
180 | + stm32l4x5_update_irq(s); | ||
181 | } | ||
182 | |||
183 | static uint64_t stm32l4x5_usart_base_read(void *opaque, hwaddr addr, | ||
184 | @@ -XXX,XX +XXX,XX @@ static uint64_t stm32l4x5_usart_base_read(void *opaque, hwaddr addr, | ||
185 | retvalue = FIELD_EX32(s->rdr, RDR, RDR); | ||
186 | /* Reset RXNE flag */ | ||
187 | s->isr &= ~R_ISR_RXNE_MASK; | ||
188 | + stm32l4x5_update_irq(s); | ||
189 | break; | ||
190 | case A_TDR: | ||
191 | retvalue = FIELD_EX32(s->tdr, TDR, TDR); | ||
192 | @@ -XXX,XX +XXX,XX @@ static void stm32l4x5_usart_base_write(void *opaque, hwaddr addr, | ||
193 | switch (addr) { | ||
194 | case A_CR1: | ||
195 | s->cr1 = value; | ||
196 | + stm32l4x5_update_irq(s); | ||
197 | return; | ||
198 | case A_CR2: | ||
199 | s->cr2 = value; | ||
200 | @@ -XXX,XX +XXX,XX @@ static void stm32l4x5_usart_base_write(void *opaque, hwaddr addr, | ||
201 | s->rtor = value; | ||
202 | return; | ||
203 | case A_RQR: | ||
204 | + usart_update_rqr(s, value); | ||
205 | return; | ||
206 | case A_ISR: | ||
207 | qemu_log_mask(LOG_GUEST_ERROR, | ||
208 | @@ -XXX,XX +XXX,XX @@ static void stm32l4x5_usart_base_write(void *opaque, hwaddr addr, | ||
209 | case A_ICR: | ||
210 | /* Clear the status flags */ | ||
211 | s->isr &= ~value; | ||
212 | + stm32l4x5_update_irq(s); | ||
213 | return; | ||
214 | case A_RDR: | ||
215 | qemu_log_mask(LOG_GUEST_ERROR, | ||
216 | @@ -XXX,XX +XXX,XX @@ static void stm32l4x5_usart_base_write(void *opaque, hwaddr addr, | ||
217 | return; | ||
218 | case A_TDR: | ||
219 | s->tdr = value; | ||
220 | + s->isr &= ~R_ISR_TXE_MASK; | ||
221 | + usart_transmit(NULL, G_IO_OUT, s); | ||
222 | return; | ||
223 | default: | ||
224 | qemu_log_mask(LOG_GUEST_ERROR, | ||
225 | @@ -XXX,XX +XXX,XX @@ static void stm32l4x5_usart_base_realize(DeviceState *dev, Error **errp) | ||
226 | error_setg(errp, "USART clock must be wired up by SoC code"); | ||
227 | return; | ||
228 | } | ||
229 | + | ||
230 | + qemu_chr_fe_set_handlers(&s->chr, stm32l4x5_usart_base_can_receive, | ||
231 | + stm32l4x5_usart_base_receive, NULL, NULL, | ||
232 | + s, NULL, true); | ||
233 | } | ||
234 | |||
235 | static void stm32l4x5_usart_base_class_init(ObjectClass *klass, void *data) | ||
236 | diff --git a/hw/char/trace-events b/hw/char/trace-events | ||
237 | index XXXXXXX..XXXXXXX 100644 | ||
238 | --- a/hw/char/trace-events | ||
239 | +++ b/hw/char/trace-events | ||
240 | @@ -XXX,XX +XXX,XX @@ sh_serial_write(char *id, unsigned size, uint64_t offs, uint64_t val) "%s size % | ||
241 | # stm32l4x5_usart.c | ||
242 | stm32l4x5_usart_read(uint64_t addr, uint32_t data) "USART: Read <0x%" PRIx64 "> -> 0x%" PRIx32 "" | ||
243 | stm32l4x5_usart_write(uint64_t addr, uint32_t data) "USART: Write <0x%" PRIx64 "> <- 0x%" PRIx32 "" | ||
244 | +stm32l4x5_usart_rx(uint8_t c) "USART: got character 0x%x from backend" | ||
245 | +stm32l4x5_usart_tx(uint8_t c) "USART: character 0x%x sent to backend" | ||
246 | +stm32l4x5_usart_tx_pending(void) "USART: character send to backend pending" | ||
247 | +stm32l4x5_usart_irq_raised(uint32_t reg) "USART: IRQ raised: 0x%08"PRIx32 | ||
248 | +stm32l4x5_usart_irq_lowered(void) "USART: IRQ lowered" | ||
249 | +stm32l4x5_usart_overrun_detected(uint8_t current, uint8_t received) "USART: Overrun detected, RDR='0x%x', received 0x%x" | ||
250 | +stm32l4x5_usart_receiver_not_enabled(uint8_t ue_bit, uint8_t re_bit) "USART: Receiver not enabled, UE=0x%x, RE=0x%x" | ||
251 | |||
252 | # xen_console.c | ||
253 | xen_console_connect(unsigned int idx, unsigned int ring_ref, unsigned int port, unsigned int limit) "idx %u ring_ref %u port %u limit %u" | ||
50 | -- | 254 | -- |
51 | 2.34.1 | 255 | 2.34.1 |
52 | 256 | ||
53 | 257 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Arnaud Minier <arnaud.minier@telecom-paris.fr> |
---|---|---|---|
2 | 2 | ||
3 | While the 8-bit input elements are sequential in the input vector, | 3 | Add a function to change the settings of the |
4 | the 32-bit output elements are not sequential in the output matrix. | 4 | serial connection. |
5 | Do not attempt to compute 2 32-bit outputs at the same time. | ||
6 | 5 | ||
7 | Cc: qemu-stable@nongnu.org | 6 | Signed-off-by: Arnaud Minier <arnaud.minier@telecom-paris.fr> |
8 | Fixes: 23a5e3859f5 ("target/arm: Implement SME integer outer product") | 7 | Signed-off-by: Inès Varhol <ines.varhol@telecom-paris.fr> |
9 | Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2083 | 8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
10 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 9 | Message-id: 20240329174402.60382-4-arnaud.minier@telecom-paris.fr |
11 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
12 | Message-id: 20240305163931.242795-1-richard.henderson@linaro.org | ||
13 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
14 | --- | 11 | --- |
15 | target/arm/tcg/sme_helper.c | 77 ++++++++++++++++++------------- | 12 | hw/char/stm32l4x5_usart.c | 98 +++++++++++++++++++++++++++++++++++++++ |
16 | tests/tcg/aarch64/sme-smopa-1.c | 47 +++++++++++++++++++ | 13 | hw/char/trace-events | 1 + |
17 | tests/tcg/aarch64/sme-smopa-2.c | 54 ++++++++++++++++++++++ | 14 | 2 files changed, 99 insertions(+) |
18 | tests/tcg/aarch64/Makefile.target | 2 +- | ||
19 | 4 files changed, 147 insertions(+), 33 deletions(-) | ||
20 | create mode 100644 tests/tcg/aarch64/sme-smopa-1.c | ||
21 | create mode 100644 tests/tcg/aarch64/sme-smopa-2.c | ||
22 | 15 | ||
23 | diff --git a/target/arm/tcg/sme_helper.c b/target/arm/tcg/sme_helper.c | 16 | diff --git a/hw/char/stm32l4x5_usart.c b/hw/char/stm32l4x5_usart.c |
24 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
25 | --- a/target/arm/tcg/sme_helper.c | 18 | --- a/hw/char/stm32l4x5_usart.c |
26 | +++ b/target/arm/tcg/sme_helper.c | 19 | +++ b/hw/char/stm32l4x5_usart.c |
27 | @@ -XXX,XX +XXX,XX @@ void HELPER(sme_bfmopa)(void *vza, void *vzn, void *vzm, void *vpn, | 20 | @@ -XXX,XX +XXX,XX @@ static void usart_cancel_transmit(Stm32l4x5UsartBaseState *s) |
28 | } | 21 | } |
29 | } | 22 | } |
30 | 23 | ||
31 | -typedef uint64_t IMOPFn(uint64_t, uint64_t, uint64_t, uint8_t, bool); | 24 | +static void stm32l4x5_update_params(Stm32l4x5UsartBaseState *s) |
32 | +typedef uint32_t IMOPFn32(uint32_t, uint32_t, uint32_t, uint8_t, bool); | ||
33 | +static inline void do_imopa_s(uint32_t *za, uint32_t *zn, uint32_t *zm, | ||
34 | + uint8_t *pn, uint8_t *pm, | ||
35 | + uint32_t desc, IMOPFn32 *fn) | ||
36 | +{ | 25 | +{ |
37 | + intptr_t row, col, oprsz = simd_oprsz(desc) / 4; | 26 | + int speed, parity, data_bits, stop_bits; |
38 | + bool neg = simd_data(desc); | 27 | + uint32_t value, usart_div; |
39 | 28 | + QEMUSerialSetParams ssp; | |
40 | -static inline void do_imopa(uint64_t *za, uint64_t *zn, uint64_t *zm, | ||
41 | - uint8_t *pn, uint8_t *pm, | ||
42 | - uint32_t desc, IMOPFn *fn) | ||
43 | + for (row = 0; row < oprsz; ++row) { | ||
44 | + uint8_t pa = (pn[H1(row >> 1)] >> ((row & 1) * 4)) & 0xf; | ||
45 | + uint32_t *za_row = &za[tile_vslice_index(row)]; | ||
46 | + uint32_t n = zn[H4(row)]; | ||
47 | + | 29 | + |
48 | + for (col = 0; col < oprsz; ++col) { | 30 | + /* Select the parity type */ |
49 | + uint8_t pb = pm[H1(col >> 1)] >> ((col & 1) * 4); | 31 | + if (s->cr1 & R_CR1_PCE_MASK) { |
50 | + uint32_t *a = &za_row[H4(col)]; | 32 | + if (s->cr1 & R_CR1_PS_MASK) { |
33 | + parity = 'O'; | ||
34 | + } else { | ||
35 | + parity = 'E'; | ||
36 | + } | ||
37 | + } else { | ||
38 | + parity = 'N'; | ||
39 | + } | ||
51 | + | 40 | + |
52 | + *a = fn(n, zm[H4(col)], *a, pa & pb, neg); | 41 | + /* Select the number of stop bits */ |
53 | + } | 42 | + switch (FIELD_EX32(s->cr2, CR2, STOP)) { |
43 | + case 0: | ||
44 | + stop_bits = 1; | ||
45 | + break; | ||
46 | + case 2: | ||
47 | + stop_bits = 2; | ||
48 | + break; | ||
49 | + default: | ||
50 | + qemu_log_mask(LOG_UNIMP, | ||
51 | + "UNIMPLEMENTED: fractionnal stop bits; CR2[13:12] = %u", | ||
52 | + FIELD_EX32(s->cr2, CR2, STOP)); | ||
53 | + return; | ||
54 | + } | 54 | + } |
55 | + | ||
56 | + /* Select the length of the word */ | ||
57 | + switch ((FIELD_EX32(s->cr1, CR1, M1) << 1) | FIELD_EX32(s->cr1, CR1, M0)) { | ||
58 | + case 0: | ||
59 | + data_bits = 8; | ||
60 | + break; | ||
61 | + case 1: | ||
62 | + data_bits = 9; | ||
63 | + break; | ||
64 | + case 2: | ||
65 | + data_bits = 7; | ||
66 | + break; | ||
67 | + default: | ||
68 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
69 | + "UNDEFINED: invalid word length, CR1.M = 0b11"); | ||
70 | + return; | ||
71 | + } | ||
72 | + | ||
73 | + /* Select the baud rate */ | ||
74 | + value = FIELD_EX32(s->brr, BRR, BRR); | ||
75 | + if (value < 16) { | ||
76 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
77 | + "UNDEFINED: BRR less than 16: %u", value); | ||
78 | + return; | ||
79 | + } | ||
80 | + | ||
81 | + if (FIELD_EX32(s->cr1, CR1, OVER8) == 0) { | ||
82 | + /* | ||
83 | + * Oversampling by 16 | ||
84 | + * BRR = USARTDIV | ||
85 | + */ | ||
86 | + usart_div = value; | ||
87 | + } else { | ||
88 | + /* | ||
89 | + * Oversampling by 8 | ||
90 | + * - BRR[2:0] = USARTDIV[3:0] shifted 1 bit to the right. | ||
91 | + * - BRR[3] must be kept cleared. | ||
92 | + * - BRR[15:4] = USARTDIV[15:4] | ||
93 | + * - The frequency is multiplied by 2 | ||
94 | + */ | ||
95 | + usart_div = ((value & 0xFFF0) | ((value & 0x0007) << 1)) / 2; | ||
96 | + } | ||
97 | + | ||
98 | + speed = clock_get_hz(s->clk) / usart_div; | ||
99 | + | ||
100 | + ssp.speed = speed; | ||
101 | + ssp.parity = parity; | ||
102 | + ssp.data_bits = data_bits; | ||
103 | + ssp.stop_bits = stop_bits; | ||
104 | + | ||
105 | + qemu_chr_fe_ioctl(&s->chr, CHR_IOCTL_SERIAL_SET_PARAMS, &ssp); | ||
106 | + | ||
107 | + trace_stm32l4x5_usart_update_params(speed, parity, data_bits, stop_bits); | ||
55 | +} | 108 | +} |
56 | + | 109 | + |
57 | +typedef uint64_t IMOPFn64(uint64_t, uint64_t, uint64_t, uint8_t, bool); | 110 | static void stm32l4x5_usart_base_reset_hold(Object *obj, ResetType type) |
58 | +static inline void do_imopa_d(uint64_t *za, uint64_t *zn, uint64_t *zm, | ||
59 | + uint8_t *pn, uint8_t *pm, | ||
60 | + uint32_t desc, IMOPFn64 *fn) | ||
61 | { | 111 | { |
62 | intptr_t row, col, oprsz = simd_oprsz(desc) / 8; | 112 | Stm32l4x5UsartBaseState *s = STM32L4X5_USART_BASE(obj); |
63 | bool neg = simd_data(desc); | 113 | @@ -XXX,XX +XXX,XX @@ static void stm32l4x5_usart_base_write(void *opaque, hwaddr addr, |
64 | @@ -XXX,XX +XXX,XX @@ static inline void do_imopa(uint64_t *za, uint64_t *zn, uint64_t *zm, | 114 | switch (addr) { |
115 | case A_CR1: | ||
116 | s->cr1 = value; | ||
117 | + stm32l4x5_update_params(s); | ||
118 | stm32l4x5_update_irq(s); | ||
119 | return; | ||
120 | case A_CR2: | ||
121 | s->cr2 = value; | ||
122 | + stm32l4x5_update_params(s); | ||
123 | return; | ||
124 | case A_CR3: | ||
125 | s->cr3 = value; | ||
126 | return; | ||
127 | case A_BRR: | ||
128 | s->brr = value; | ||
129 | + stm32l4x5_update_params(s); | ||
130 | return; | ||
131 | case A_GTPR: | ||
132 | s->gtpr = value; | ||
133 | @@ -XXX,XX +XXX,XX @@ static void stm32l4x5_usart_base_init(Object *obj) | ||
134 | s->clk = qdev_init_clock_in(DEVICE(s), "clk", NULL, s, 0); | ||
65 | } | 135 | } |
66 | 136 | ||
67 | #define DEF_IMOP_32(NAME, NTYPE, MTYPE) \ | 137 | +static int stm32l4x5_usart_base_post_load(void *opaque, int version_id) |
68 | -static uint64_t NAME(uint64_t n, uint64_t m, uint64_t a, uint8_t p, bool neg) \ | 138 | +{ |
69 | +static uint32_t NAME(uint32_t n, uint32_t m, uint32_t a, uint8_t p, bool neg) \ | 139 | + Stm32l4x5UsartBaseState *s = (Stm32l4x5UsartBaseState *)opaque; |
70 | { \ | ||
71 | - uint32_t sum0 = 0, sum1 = 0; \ | ||
72 | + uint32_t sum = 0; \ | ||
73 | /* Apply P to N as a mask, making the inactive elements 0. */ \ | ||
74 | n &= expand_pred_b(p); \ | ||
75 | - sum0 += (NTYPE)(n >> 0) * (MTYPE)(m >> 0); \ | ||
76 | - sum0 += (NTYPE)(n >> 8) * (MTYPE)(m >> 8); \ | ||
77 | - sum0 += (NTYPE)(n >> 16) * (MTYPE)(m >> 16); \ | ||
78 | - sum0 += (NTYPE)(n >> 24) * (MTYPE)(m >> 24); \ | ||
79 | - sum1 += (NTYPE)(n >> 32) * (MTYPE)(m >> 32); \ | ||
80 | - sum1 += (NTYPE)(n >> 40) * (MTYPE)(m >> 40); \ | ||
81 | - sum1 += (NTYPE)(n >> 48) * (MTYPE)(m >> 48); \ | ||
82 | - sum1 += (NTYPE)(n >> 56) * (MTYPE)(m >> 56); \ | ||
83 | - if (neg) { \ | ||
84 | - sum0 = (uint32_t)a - sum0, sum1 = (uint32_t)(a >> 32) - sum1; \ | ||
85 | - } else { \ | ||
86 | - sum0 = (uint32_t)a + sum0, sum1 = (uint32_t)(a >> 32) + sum1; \ | ||
87 | - } \ | ||
88 | - return ((uint64_t)sum1 << 32) | sum0; \ | ||
89 | + sum += (NTYPE)(n >> 0) * (MTYPE)(m >> 0); \ | ||
90 | + sum += (NTYPE)(n >> 8) * (MTYPE)(m >> 8); \ | ||
91 | + sum += (NTYPE)(n >> 16) * (MTYPE)(m >> 16); \ | ||
92 | + sum += (NTYPE)(n >> 24) * (MTYPE)(m >> 24); \ | ||
93 | + return neg ? a - sum : a + sum; \ | ||
94 | } | ||
95 | |||
96 | #define DEF_IMOP_64(NAME, NTYPE, MTYPE) \ | ||
97 | @@ -XXX,XX +XXX,XX @@ DEF_IMOP_64(umopa_d, uint16_t, uint16_t) | ||
98 | DEF_IMOP_64(sumopa_d, int16_t, uint16_t) | ||
99 | DEF_IMOP_64(usmopa_d, uint16_t, int16_t) | ||
100 | |||
101 | -#define DEF_IMOPH(NAME) \ | ||
102 | - void HELPER(sme_##NAME)(void *vza, void *vzn, void *vzm, void *vpn, \ | ||
103 | - void *vpm, uint32_t desc) \ | ||
104 | - { do_imopa(vza, vzn, vzm, vpn, vpm, desc, NAME); } | ||
105 | +#define DEF_IMOPH(NAME, S) \ | ||
106 | + void HELPER(sme_##NAME##_##S)(void *vza, void *vzn, void *vzm, \ | ||
107 | + void *vpn, void *vpm, uint32_t desc) \ | ||
108 | + { do_imopa_##S(vza, vzn, vzm, vpn, vpm, desc, NAME##_##S); } | ||
109 | |||
110 | -DEF_IMOPH(smopa_s) | ||
111 | -DEF_IMOPH(umopa_s) | ||
112 | -DEF_IMOPH(sumopa_s) | ||
113 | -DEF_IMOPH(usmopa_s) | ||
114 | -DEF_IMOPH(smopa_d) | ||
115 | -DEF_IMOPH(umopa_d) | ||
116 | -DEF_IMOPH(sumopa_d) | ||
117 | -DEF_IMOPH(usmopa_d) | ||
118 | +DEF_IMOPH(smopa, s) | ||
119 | +DEF_IMOPH(umopa, s) | ||
120 | +DEF_IMOPH(sumopa, s) | ||
121 | +DEF_IMOPH(usmopa, s) | ||
122 | + | 140 | + |
123 | +DEF_IMOPH(smopa, d) | 141 | + stm32l4x5_update_params(s); |
124 | +DEF_IMOPH(umopa, d) | 142 | + return 0; |
125 | +DEF_IMOPH(sumopa, d) | 143 | +} |
126 | +DEF_IMOPH(usmopa, d) | ||
127 | diff --git a/tests/tcg/aarch64/sme-smopa-1.c b/tests/tcg/aarch64/sme-smopa-1.c | ||
128 | new file mode 100644 | ||
129 | index XXXXXXX..XXXXXXX | ||
130 | --- /dev/null | ||
131 | +++ b/tests/tcg/aarch64/sme-smopa-1.c | ||
132 | @@ -XXX,XX +XXX,XX @@ | ||
133 | +#include <stdio.h> | ||
134 | +#include <string.h> | ||
135 | + | 144 | + |
136 | +int main() | 145 | static const VMStateDescription vmstate_stm32l4x5_usart_base = { |
137 | +{ | 146 | .name = TYPE_STM32L4X5_USART_BASE, |
138 | + static const int cmp[4][4] = { | 147 | .version_id = 1, |
139 | + { 110, 134, 158, 182 }, | 148 | .minimum_version_id = 1, |
140 | + { 390, 478, 566, 654 }, | 149 | + .post_load = stm32l4x5_usart_base_post_load, |
141 | + { 670, 822, 974, 1126 }, | 150 | .fields = (VMStateField[]) { |
142 | + { 950, 1166, 1382, 1598 } | 151 | VMSTATE_UINT32(cr1, Stm32l4x5UsartBaseState), |
143 | + }; | 152 | VMSTATE_UINT32(cr2, Stm32l4x5UsartBaseState), |
144 | + int dst[4][4]; | 153 | diff --git a/hw/char/trace-events b/hw/char/trace-events |
145 | + int *tmp = &dst[0][0]; | ||
146 | + | ||
147 | + asm volatile( | ||
148 | + ".arch armv8-r+sme\n\t" | ||
149 | + "smstart\n\t" | ||
150 | + "index z0.b, #0, #1\n\t" | ||
151 | + "movprfx z1, z0\n\t" | ||
152 | + "add z1.b, z1.b, #16\n\t" | ||
153 | + "ptrue p0.b\n\t" | ||
154 | + "smopa za0.s, p0/m, p0/m, z0.b, z1.b\n\t" | ||
155 | + "ptrue p0.s, vl4\n\t" | ||
156 | + "mov w12, #0\n\t" | ||
157 | + "st1w { za0h.s[w12, #0] }, p0, [%0]\n\t" | ||
158 | + "add %0, %0, #16\n\t" | ||
159 | + "st1w { za0h.s[w12, #1] }, p0, [%0]\n\t" | ||
160 | + "add %0, %0, #16\n\t" | ||
161 | + "st1w { za0h.s[w12, #2] }, p0, [%0]\n\t" | ||
162 | + "add %0, %0, #16\n\t" | ||
163 | + "st1w { za0h.s[w12, #3] }, p0, [%0]\n\t" | ||
164 | + "smstop" | ||
165 | + : "+r"(tmp) : : "memory"); | ||
166 | + | ||
167 | + if (memcmp(cmp, dst, sizeof(dst)) == 0) { | ||
168 | + return 0; | ||
169 | + } | ||
170 | + | ||
171 | + /* See above for correct results. */ | ||
172 | + for (int i = 0; i < 4; ++i) { | ||
173 | + for (int j = 0; j < 4; ++j) { | ||
174 | + printf("%6d", dst[i][j]); | ||
175 | + } | ||
176 | + printf("\n"); | ||
177 | + } | ||
178 | + return 1; | ||
179 | +} | ||
180 | diff --git a/tests/tcg/aarch64/sme-smopa-2.c b/tests/tcg/aarch64/sme-smopa-2.c | ||
181 | new file mode 100644 | ||
182 | index XXXXXXX..XXXXXXX | ||
183 | --- /dev/null | ||
184 | +++ b/tests/tcg/aarch64/sme-smopa-2.c | ||
185 | @@ -XXX,XX +XXX,XX @@ | ||
186 | +#include <stdio.h> | ||
187 | +#include <string.h> | ||
188 | + | ||
189 | +int main() | ||
190 | +{ | ||
191 | + static const long cmp[4][4] = { | ||
192 | + { 110, 134, 158, 182 }, | ||
193 | + { 390, 478, 566, 654 }, | ||
194 | + { 670, 822, 974, 1126 }, | ||
195 | + { 950, 1166, 1382, 1598 } | ||
196 | + }; | ||
197 | + long dst[4][4]; | ||
198 | + long *tmp = &dst[0][0]; | ||
199 | + long svl; | ||
200 | + | ||
201 | + /* Validate that we have a wide enough vector for 4 elements. */ | ||
202 | + asm(".arch armv8-r+sme-i64\n\trdsvl %0, #1" : "=r"(svl)); | ||
203 | + if (svl < 32) { | ||
204 | + return 0; | ||
205 | + } | ||
206 | + | ||
207 | + asm volatile( | ||
208 | + "smstart\n\t" | ||
209 | + "index z0.h, #0, #1\n\t" | ||
210 | + "movprfx z1, z0\n\t" | ||
211 | + "add z1.h, z1.h, #16\n\t" | ||
212 | + "ptrue p0.b\n\t" | ||
213 | + "smopa za0.d, p0/m, p0/m, z0.h, z1.h\n\t" | ||
214 | + "ptrue p0.d, vl4\n\t" | ||
215 | + "mov w12, #0\n\t" | ||
216 | + "st1d { za0h.d[w12, #0] }, p0, [%0]\n\t" | ||
217 | + "add %0, %0, #32\n\t" | ||
218 | + "st1d { za0h.d[w12, #1] }, p0, [%0]\n\t" | ||
219 | + "mov w12, #2\n\t" | ||
220 | + "add %0, %0, #32\n\t" | ||
221 | + "st1d { za0h.d[w12, #0] }, p0, [%0]\n\t" | ||
222 | + "add %0, %0, #32\n\t" | ||
223 | + "st1d { za0h.d[w12, #1] }, p0, [%0]\n\t" | ||
224 | + "smstop" | ||
225 | + : "+r"(tmp) : : "memory"); | ||
226 | + | ||
227 | + if (memcmp(cmp, dst, sizeof(dst)) == 0) { | ||
228 | + return 0; | ||
229 | + } | ||
230 | + | ||
231 | + /* See above for correct results. */ | ||
232 | + for (int i = 0; i < 4; ++i) { | ||
233 | + for (int j = 0; j < 4; ++j) { | ||
234 | + printf("%6ld", dst[i][j]); | ||
235 | + } | ||
236 | + printf("\n"); | ||
237 | + } | ||
238 | + return 1; | ||
239 | +} | ||
240 | diff --git a/tests/tcg/aarch64/Makefile.target b/tests/tcg/aarch64/Makefile.target | ||
241 | index XXXXXXX..XXXXXXX 100644 | 154 | index XXXXXXX..XXXXXXX 100644 |
242 | --- a/tests/tcg/aarch64/Makefile.target | 155 | --- a/hw/char/trace-events |
243 | +++ b/tests/tcg/aarch64/Makefile.target | 156 | +++ b/hw/char/trace-events |
244 | @@ -XXX,XX +XXX,XX @@ endif | 157 | @@ -XXX,XX +XXX,XX @@ stm32l4x5_usart_irq_raised(uint32_t reg) "USART: IRQ raised: 0x%08"PRIx32 |
245 | 158 | stm32l4x5_usart_irq_lowered(void) "USART: IRQ lowered" | |
246 | # SME Tests | 159 | stm32l4x5_usart_overrun_detected(uint8_t current, uint8_t received) "USART: Overrun detected, RDR='0x%x', received 0x%x" |
247 | ifneq ($(CROSS_AS_HAS_ARMV9_SME),) | 160 | stm32l4x5_usart_receiver_not_enabled(uint8_t ue_bit, uint8_t re_bit) "USART: Receiver not enabled, UE=0x%x, RE=0x%x" |
248 | -AARCH64_TESTS += sme-outprod1 | 161 | +stm32l4x5_usart_update_params(int speed, uint8_t parity, int data, int stop) "USART: speed: %d, parity: %c, data bits: %d, stop bits: %d" |
249 | +AARCH64_TESTS += sme-outprod1 sme-smopa-1 sme-smopa-2 | 162 | |
250 | endif | 163 | # xen_console.c |
251 | 164 | xen_console_connect(unsigned int idx, unsigned int ring_ref, unsigned int port, unsigned int limit) "idx %u ring_ref %u port %u limit %u" | |
252 | # System Registers Tests | ||
253 | -- | 165 | -- |
254 | 2.34.1 | 166 | 2.34.1 |
255 | 167 | ||
256 | 168 | diff view generated by jsdifflib |
1 | From: Inès Varhol <ines.varhol@telecom-paris.fr> | 1 | From: Arnaud Minier <arnaud.minier@telecom-paris.fr> |
---|---|---|---|
2 | |||
3 | Add the USART to the SoC and connect it to the other implemented devices. | ||
2 | 4 | ||
3 | Signed-off-by: Arnaud Minier <arnaud.minier@telecom-paris.fr> | 5 | Signed-off-by: Arnaud Minier <arnaud.minier@telecom-paris.fr> |
4 | Signed-off-by: Inès Varhol <ines.varhol@telecom-paris.fr> | 6 | Signed-off-by: Inès Varhol <ines.varhol@telecom-paris.fr> |
5 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | 7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
6 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | 8 | Message-id: 20240329174402.60382-5-arnaud.minier@telecom-paris.fr |
7 | Message-id: 20240305210444.310665-3-ines.varhol@telecom-paris.fr | 9 | [PMM: fixed a few checkpatch nits] |
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
9 | --- | 11 | --- |
10 | include/hw/arm/stm32l4x5_soc.h | 2 + | 12 | docs/system/arm/b-l475e-iot01a.rst | 2 +- |
11 | include/hw/gpio/stm32l4x5_gpio.h | 1 + | 13 | include/hw/arm/stm32l4x5_soc.h | 7 +++ |
12 | include/hw/misc/stm32l4x5_syscfg.h | 3 +- | 14 | hw/arm/stm32l4x5_soc.c | 83 +++++++++++++++++++++++++++--- |
13 | hw/arm/stm32l4x5_soc.c | 71 +++++++++++++++++++++++------- | 15 | hw/arm/Kconfig | 1 + |
14 | hw/misc/stm32l4x5_syscfg.c | 1 + | 16 | 4 files changed, 86 insertions(+), 7 deletions(-) |
15 | hw/arm/Kconfig | 3 +- | 17 | |
16 | 6 files changed, 63 insertions(+), 18 deletions(-) | 18 | diff --git a/docs/system/arm/b-l475e-iot01a.rst b/docs/system/arm/b-l475e-iot01a.rst |
17 | 19 | index XXXXXXX..XXXXXXX 100644 | |
20 | --- a/docs/system/arm/b-l475e-iot01a.rst | ||
21 | +++ b/docs/system/arm/b-l475e-iot01a.rst | ||
22 | @@ -XXX,XX +XXX,XX @@ Currently B-L475E-IOT01A machine's only supports the following devices: | ||
23 | - STM32L4x5 SYSCFG (System configuration controller) | ||
24 | - STM32L4x5 RCC (Reset and clock control) | ||
25 | - STM32L4x5 GPIOs (General-purpose I/Os) | ||
26 | +- STM32L4x5 USARTs, UARTs and LPUART (Serial ports) | ||
27 | |||
28 | Missing devices | ||
29 | """"""""""""""" | ||
30 | |||
31 | The B-L475E-IOT01A does *not* support the following devices: | ||
32 | |||
33 | -- Serial ports (UART) | ||
34 | - Analog to Digital Converter (ADC) | ||
35 | - SPI controller | ||
36 | - Timer controller (TIMER) | ||
18 | diff --git a/include/hw/arm/stm32l4x5_soc.h b/include/hw/arm/stm32l4x5_soc.h | 37 | diff --git a/include/hw/arm/stm32l4x5_soc.h b/include/hw/arm/stm32l4x5_soc.h |
19 | index XXXXXXX..XXXXXXX 100644 | 38 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/include/hw/arm/stm32l4x5_soc.h | 39 | --- a/include/hw/arm/stm32l4x5_soc.h |
21 | +++ b/include/hw/arm/stm32l4x5_soc.h | 40 | +++ b/include/hw/arm/stm32l4x5_soc.h |
22 | @@ -XXX,XX +XXX,XX @@ | 41 | @@ -XXX,XX +XXX,XX @@ |
23 | #include "hw/misc/stm32l4x5_syscfg.h" | ||
24 | #include "hw/misc/stm32l4x5_exti.h" | 42 | #include "hw/misc/stm32l4x5_exti.h" |
25 | #include "hw/misc/stm32l4x5_rcc.h" | 43 | #include "hw/misc/stm32l4x5_rcc.h" |
26 | +#include "hw/gpio/stm32l4x5_gpio.h" | 44 | #include "hw/gpio/stm32l4x5_gpio.h" |
45 | +#include "hw/char/stm32l4x5_usart.h" | ||
27 | #include "qom/object.h" | 46 | #include "qom/object.h" |
28 | 47 | ||
29 | #define TYPE_STM32L4X5_SOC "stm32l4x5-soc" | 48 | #define TYPE_STM32L4X5_SOC "stm32l4x5-soc" |
49 | @@ -XXX,XX +XXX,XX @@ OBJECT_DECLARE_TYPE(Stm32l4x5SocState, Stm32l4x5SocClass, STM32L4X5_SOC) | ||
50 | |||
51 | #define NUM_EXTI_OR_GATES 4 | ||
52 | |||
53 | +#define STM_NUM_USARTS 3 | ||
54 | +#define STM_NUM_UARTS 2 | ||
55 | + | ||
56 | struct Stm32l4x5SocState { | ||
57 | SysBusDevice parent_obj; | ||
58 | |||
30 | @@ -XXX,XX +XXX,XX @@ struct Stm32l4x5SocState { | 59 | @@ -XXX,XX +XXX,XX @@ struct Stm32l4x5SocState { |
31 | OrIRQState exti_or_gates[NUM_EXTI_OR_GATES]; | ||
32 | Stm32l4x5SyscfgState syscfg; | 60 | Stm32l4x5SyscfgState syscfg; |
33 | Stm32l4x5RccState rcc; | 61 | Stm32l4x5RccState rcc; |
34 | + Stm32l4x5GpioState gpio[NUM_GPIOS]; | 62 | Stm32l4x5GpioState gpio[NUM_GPIOS]; |
63 | + Stm32l4x5UsartBaseState usart[STM_NUM_USARTS]; | ||
64 | + Stm32l4x5UsartBaseState uart[STM_NUM_UARTS]; | ||
65 | + Stm32l4x5UsartBaseState lpuart; | ||
35 | 66 | ||
36 | MemoryRegion sram1; | 67 | MemoryRegion sram1; |
37 | MemoryRegion sram2; | 68 | MemoryRegion sram2; |
38 | diff --git a/include/hw/gpio/stm32l4x5_gpio.h b/include/hw/gpio/stm32l4x5_gpio.h | ||
39 | index XXXXXXX..XXXXXXX 100644 | ||
40 | --- a/include/hw/gpio/stm32l4x5_gpio.h | ||
41 | +++ b/include/hw/gpio/stm32l4x5_gpio.h | ||
42 | @@ -XXX,XX +XXX,XX @@ | ||
43 | #define TYPE_STM32L4X5_GPIO "stm32l4x5-gpio" | ||
44 | OBJECT_DECLARE_SIMPLE_TYPE(Stm32l4x5GpioState, STM32L4X5_GPIO) | ||
45 | |||
46 | +#define NUM_GPIOS 8 | ||
47 | #define GPIO_NUM_PINS 16 | ||
48 | |||
49 | struct Stm32l4x5GpioState { | ||
50 | diff --git a/include/hw/misc/stm32l4x5_syscfg.h b/include/hw/misc/stm32l4x5_syscfg.h | ||
51 | index XXXXXXX..XXXXXXX 100644 | ||
52 | --- a/include/hw/misc/stm32l4x5_syscfg.h | ||
53 | +++ b/include/hw/misc/stm32l4x5_syscfg.h | ||
54 | @@ -XXX,XX +XXX,XX @@ | ||
55 | |||
56 | #include "hw/sysbus.h" | ||
57 | #include "qom/object.h" | ||
58 | +#include "hw/gpio/stm32l4x5_gpio.h" | ||
59 | |||
60 | #define TYPE_STM32L4X5_SYSCFG "stm32l4x5-syscfg" | ||
61 | OBJECT_DECLARE_SIMPLE_TYPE(Stm32l4x5SyscfgState, STM32L4X5_SYSCFG) | ||
62 | |||
63 | -#define NUM_GPIOS 8 | ||
64 | -#define GPIO_NUM_PINS 16 | ||
65 | #define SYSCFG_NUM_EXTICR 4 | ||
66 | |||
67 | struct Stm32l4x5SyscfgState { | ||
68 | diff --git a/hw/arm/stm32l4x5_soc.c b/hw/arm/stm32l4x5_soc.c | 69 | diff --git a/hw/arm/stm32l4x5_soc.c b/hw/arm/stm32l4x5_soc.c |
69 | index XXXXXXX..XXXXXXX 100644 | 70 | index XXXXXXX..XXXXXXX 100644 |
70 | --- a/hw/arm/stm32l4x5_soc.c | 71 | --- a/hw/arm/stm32l4x5_soc.c |
71 | +++ b/hw/arm/stm32l4x5_soc.c | 72 | +++ b/hw/arm/stm32l4x5_soc.c |
72 | @@ -XXX,XX +XXX,XX @@ | 73 | @@ -XXX,XX +XXX,XX @@ |
73 | #include "sysemu/sysemu.h" | 74 | #include "sysemu/sysemu.h" |
74 | #include "hw/or-irq.h" | 75 | #include "hw/or-irq.h" |
75 | #include "hw/arm/stm32l4x5_soc.h" | 76 | #include "hw/arm/stm32l4x5_soc.h" |
76 | +#include "hw/gpio/stm32l4x5_gpio.h" | 77 | +#include "hw/char/stm32l4x5_usart.h" |
78 | #include "hw/gpio/stm32l4x5_gpio.h" | ||
77 | #include "hw/qdev-clock.h" | 79 | #include "hw/qdev-clock.h" |
78 | #include "hw/misc/unimp.h" | 80 | #include "hw/misc/unimp.h" |
79 | 81 | @@ -XXX,XX +XXX,XX @@ static const struct { | |
80 | @@ -XXX,XX +XXX,XX @@ static const int exti_or_gate1_lines_in[EXTI_OR_GATE1_NUM_LINES_IN] = { | 82 | { 0x48001C00, 0x0000000F, 0x00000000, 0x00000000 }, |
81 | 16, 35, 36, 37, 38, | ||
82 | }; | 83 | }; |
83 | 84 | ||
84 | +static const struct { | 85 | +static const hwaddr usart_addr[] = { |
85 | + uint32_t addr; | 86 | + 0x40013800, /* "USART1", 0x400 */ |
86 | + uint32_t moder_reset; | 87 | + 0x40004400, /* "USART2", 0x400 */ |
87 | + uint32_t ospeedr_reset; | 88 | + 0x40004800, /* "USART3", 0x400 */ |
88 | + uint32_t pupdr_reset; | ||
89 | +} stm32l4x5_gpio_cfg[NUM_GPIOS] = { | ||
90 | + { 0x48000000, 0xABFFFFFF, 0x0C000000, 0x64000000 }, | ||
91 | + { 0x48000400, 0xFFFFFEBF, 0x00000000, 0x00000100 }, | ||
92 | + { 0x48000800, 0xFFFFFFFF, 0x00000000, 0x00000000 }, | ||
93 | + { 0x48000C00, 0xFFFFFFFF, 0x00000000, 0x00000000 }, | ||
94 | + { 0x48001000, 0xFFFFFFFF, 0x00000000, 0x00000000 }, | ||
95 | + { 0x48001400, 0xFFFFFFFF, 0x00000000, 0x00000000 }, | ||
96 | + { 0x48001800, 0xFFFFFFFF, 0x00000000, 0x00000000 }, | ||
97 | + { 0x48001C00, 0x0000000F, 0x00000000, 0x00000000 }, | ||
98 | +}; | 89 | +}; |
90 | +static const hwaddr uart_addr[] = { | ||
91 | + 0x40004C00, /* "UART4" , 0x400 */ | ||
92 | + 0x40005000 /* "UART5" , 0x400 */ | ||
93 | +}; | ||
94 | + | ||
95 | +#define LPUART_BASE_ADDRESS 0x40008000 | ||
96 | + | ||
97 | +static const int usart_irq[] = { 37, 38, 39 }; | ||
98 | +static const int uart_irq[] = { 52, 53 }; | ||
99 | +#define LPUART_IRQ 70 | ||
99 | + | 100 | + |
100 | static void stm32l4x5_soc_initfn(Object *obj) | 101 | static void stm32l4x5_soc_initfn(Object *obj) |
101 | { | 102 | { |
102 | Stm32l4x5SocState *s = STM32L4X5_SOC(obj); | 103 | Stm32l4x5SocState *s = STM32L4X5_SOC(obj); |
103 | @@ -XXX,XX +XXX,XX @@ static void stm32l4x5_soc_initfn(Object *obj) | 104 | @@ -XXX,XX +XXX,XX @@ static void stm32l4x5_soc_initfn(Object *obj) |
105 | g_autofree char *name = g_strdup_printf("gpio%c", 'a' + i); | ||
106 | object_initialize_child(obj, name, &s->gpio[i], TYPE_STM32L4X5_GPIO); | ||
104 | } | 107 | } |
105 | object_initialize_child(obj, "syscfg", &s->syscfg, TYPE_STM32L4X5_SYSCFG); | 108 | + |
106 | object_initialize_child(obj, "rcc", &s->rcc, TYPE_STM32L4X5_RCC); | 109 | + for (int i = 0; i < STM_NUM_USARTS; i++) { |
107 | + | 110 | + object_initialize_child(obj, "usart[*]", &s->usart[i], |
108 | + for (unsigned i = 0; i < NUM_GPIOS; i++) { | 111 | + TYPE_STM32L4X5_USART); |
109 | + g_autofree char *name = g_strdup_printf("gpio%c", 'a' + i); | 112 | + } |
110 | + object_initialize_child(obj, name, &s->gpio[i], TYPE_STM32L4X5_GPIO); | 113 | + |
111 | + } | 114 | + for (int i = 0; i < STM_NUM_UARTS; i++) { |
115 | + object_initialize_child(obj, "uart[*]", &s->uart[i], | ||
116 | + TYPE_STM32L4X5_UART); | ||
117 | + } | ||
118 | + object_initialize_child(obj, "lpuart1", &s->lpuart, | ||
119 | + TYPE_STM32L4X5_LPUART); | ||
112 | } | 120 | } |
113 | 121 | ||
114 | static void stm32l4x5_soc_realize(DeviceState *dev_soc, Error **errp) | 122 | static void stm32l4x5_soc_realize(DeviceState *dev_soc, Error **errp) |
115 | @@ -XXX,XX +XXX,XX @@ static void stm32l4x5_soc_realize(DeviceState *dev_soc, Error **errp) | 123 | @@ -XXX,XX +XXX,XX @@ static void stm32l4x5_soc_realize(DeviceState *dev_soc, Error **errp) |
116 | Stm32l4x5SocState *s = STM32L4X5_SOC(dev_soc); | 124 | sysbus_mmio_map(busdev, 0, RCC_BASE_ADDRESS); |
117 | const Stm32l4x5SocClass *sc = STM32L4X5_SOC_GET_CLASS(dev_soc); | 125 | sysbus_connect_irq(busdev, 0, qdev_get_gpio_in(armv7m, RCC_IRQ)); |
118 | MemoryRegion *system_memory = get_system_memory(); | 126 | |
119 | - DeviceState *armv7m; | 127 | + /* USART devices */ |
120 | + DeviceState *armv7m, *dev; | 128 | + for (int i = 0; i < STM_NUM_USARTS; i++) { |
121 | SysBusDevice *busdev; | 129 | + g_autofree char *name = g_strdup_printf("usart%d-out", i + 1); |
122 | + uint32_t pin_index; | 130 | + dev = DEVICE(&(s->usart[i])); |
123 | 131 | + qdev_prop_set_chr(dev, "chardev", serial_hd(i)); | |
124 | if (!memory_region_init_rom(&s->flash, OBJECT(dev_soc), "flash", | 132 | + qdev_connect_clock_in(dev, "clk", |
125 | sc->flash_size, errp)) { | ||
126 | @@ -XXX,XX +XXX,XX @@ static void stm32l4x5_soc_realize(DeviceState *dev_soc, Error **errp) | ||
127 | return; | ||
128 | } | ||
129 | |||
130 | + /* GPIOs */ | ||
131 | + for (unsigned i = 0; i < NUM_GPIOS; i++) { | ||
132 | + g_autofree char *name = g_strdup_printf("%c", 'A' + i); | ||
133 | + dev = DEVICE(&s->gpio[i]); | ||
134 | + qdev_prop_set_string(dev, "name", name); | ||
135 | + qdev_prop_set_uint32(dev, "mode-reset", | ||
136 | + stm32l4x5_gpio_cfg[i].moder_reset); | ||
137 | + qdev_prop_set_uint32(dev, "ospeed-reset", | ||
138 | + stm32l4x5_gpio_cfg[i].ospeedr_reset); | ||
139 | + qdev_prop_set_uint32(dev, "pupd-reset", | ||
140 | + stm32l4x5_gpio_cfg[i].pupdr_reset); | ||
141 | + busdev = SYS_BUS_DEVICE(&s->gpio[i]); | ||
142 | + g_free(name); | ||
143 | + name = g_strdup_printf("gpio%c-out", 'a' + i); | ||
144 | + qdev_connect_clock_in(DEVICE(&s->gpio[i]), "clk", | ||
145 | + qdev_get_clock_out(DEVICE(&(s->rcc)), name)); | 133 | + qdev_get_clock_out(DEVICE(&(s->rcc)), name)); |
134 | + busdev = SYS_BUS_DEVICE(dev); | ||
146 | + if (!sysbus_realize(busdev, errp)) { | 135 | + if (!sysbus_realize(busdev, errp)) { |
147 | + return; | 136 | + return; |
148 | + } | 137 | + } |
149 | + sysbus_mmio_map(busdev, 0, stm32l4x5_gpio_cfg[i].addr); | 138 | + sysbus_mmio_map(busdev, 0, usart_addr[i]); |
150 | + } | 139 | + sysbus_connect_irq(busdev, 0, qdev_get_gpio_in(armv7m, usart_irq[i])); |
151 | + | 140 | + } |
152 | /* System configuration controller */ | 141 | + |
153 | busdev = SYS_BUS_DEVICE(&s->syscfg); | 142 | + /* |
154 | if (!sysbus_realize(busdev, errp)) { | 143 | + * TODO: Connect the USARTs, UARTs and LPUART to the EXTI once the EXTI |
155 | return; | 144 | + * can handle other gpio-in than the gpios. (e.g. Direct Lines for the |
156 | } | 145 | + * usarts) |
157 | sysbus_mmio_map(busdev, 0, SYSCFG_ADDR); | 146 | + */ |
158 | - /* | 147 | + |
159 | - * TODO: when the GPIO device is implemented, connect it | 148 | + /* UART devices */ |
160 | - * to SYCFG using `qdev_connect_gpio_out`, NUM_GPIOS and | 149 | + for (int i = 0; i < STM_NUM_UARTS; i++) { |
161 | - * GPIO_NUM_PINS. | 150 | + g_autofree char *name = g_strdup_printf("uart%d-out", STM_NUM_USARTS + i + 1); |
162 | - */ | 151 | + dev = DEVICE(&(s->uart[i])); |
163 | + | 152 | + qdev_prop_set_chr(dev, "chardev", serial_hd(STM_NUM_USARTS + i)); |
164 | + for (unsigned i = 0; i < NUM_GPIOS; i++) { | 153 | + qdev_connect_clock_in(dev, "clk", |
165 | + for (unsigned j = 0; j < GPIO_NUM_PINS; j++) { | 154 | + qdev_get_clock_out(DEVICE(&(s->rcc)), name)); |
166 | + pin_index = GPIO_NUM_PINS * i + j; | 155 | + busdev = SYS_BUS_DEVICE(dev); |
167 | + qdev_connect_gpio_out(DEVICE(&s->gpio[i]), j, | 156 | + if (!sysbus_realize(busdev, errp)) { |
168 | + qdev_get_gpio_in(DEVICE(&s->syscfg), | 157 | + return; |
169 | + pin_index)); | ||
170 | + } | 158 | + } |
171 | + } | 159 | + sysbus_mmio_map(busdev, 0, uart_addr[i]); |
172 | 160 | + sysbus_connect_irq(busdev, 0, qdev_get_gpio_in(armv7m, uart_irq[i])); | |
173 | /* EXTI device */ | 161 | + } |
174 | busdev = SYS_BUS_DEVICE(&s->exti); | 162 | + |
175 | @@ -XXX,XX +XXX,XX @@ static void stm32l4x5_soc_realize(DeviceState *dev_soc, Error **errp) | 163 | + /* LPUART device*/ |
176 | } | 164 | + dev = DEVICE(&(s->lpuart)); |
177 | } | 165 | + qdev_prop_set_chr(dev, "chardev", serial_hd(STM_NUM_USARTS + STM_NUM_UARTS)); |
178 | 166 | + qdev_connect_clock_in(dev, "clk", | |
179 | - for (unsigned i = 0; i < 16; i++) { | 167 | + qdev_get_clock_out(DEVICE(&(s->rcc)), "lpuart1-out")); |
180 | + for (unsigned i = 0; i < GPIO_NUM_PINS; i++) { | 168 | + busdev = SYS_BUS_DEVICE(dev); |
181 | qdev_connect_gpio_out(DEVICE(&s->syscfg), i, | 169 | + if (!sysbus_realize(busdev, errp)) { |
182 | qdev_get_gpio_in(DEVICE(&s->exti), i)); | 170 | + return; |
183 | } | 171 | + } |
184 | @@ -XXX,XX +XXX,XX @@ static void stm32l4x5_soc_realize(DeviceState *dev_soc, Error **errp) | 172 | + sysbus_mmio_map(busdev, 0, LPUART_BASE_ADDRESS); |
185 | /* RESERVED: 0x40024400, 0x7FDBC00 */ | 173 | + sysbus_connect_irq(busdev, 0, qdev_get_gpio_in(armv7m, LPUART_IRQ)); |
186 | 174 | + | |
187 | /* AHB2 BUS */ | 175 | /* APB1 BUS */ |
188 | - create_unimplemented_device("GPIOA", 0x48000000, 0x400); | 176 | create_unimplemented_device("TIM2", 0x40000000, 0x400); |
189 | - create_unimplemented_device("GPIOB", 0x48000400, 0x400); | 177 | create_unimplemented_device("TIM3", 0x40000400, 0x400); |
190 | - create_unimplemented_device("GPIOC", 0x48000800, 0x400); | 178 | @@ -XXX,XX +XXX,XX @@ static void stm32l4x5_soc_realize(DeviceState *dev_soc, Error **errp) |
191 | - create_unimplemented_device("GPIOD", 0x48000C00, 0x400); | 179 | create_unimplemented_device("SPI2", 0x40003800, 0x400); |
192 | - create_unimplemented_device("GPIOE", 0x48001000, 0x400); | 180 | create_unimplemented_device("SPI3", 0x40003C00, 0x400); |
193 | - create_unimplemented_device("GPIOF", 0x48001400, 0x400); | 181 | /* RESERVED: 0x40004000, 0x400 */ |
194 | - create_unimplemented_device("GPIOG", 0x48001800, 0x400); | 182 | - create_unimplemented_device("USART2", 0x40004400, 0x400); |
195 | - create_unimplemented_device("GPIOH", 0x48001C00, 0x400); | 183 | - create_unimplemented_device("USART3", 0x40004800, 0x400); |
196 | /* RESERVED: 0x48002000, 0x7FDBC00 */ | 184 | - create_unimplemented_device("UART4", 0x40004C00, 0x400); |
197 | create_unimplemented_device("OTG_FS", 0x50000000, 0x40000); | 185 | - create_unimplemented_device("UART5", 0x40005000, 0x400); |
198 | create_unimplemented_device("ADC", 0x50040000, 0x400); | 186 | create_unimplemented_device("I2C1", 0x40005400, 0x400); |
199 | diff --git a/hw/misc/stm32l4x5_syscfg.c b/hw/misc/stm32l4x5_syscfg.c | 187 | create_unimplemented_device("I2C2", 0x40005800, 0x400); |
200 | index XXXXXXX..XXXXXXX 100644 | 188 | create_unimplemented_device("I2C3", 0x40005C00, 0x400); |
201 | --- a/hw/misc/stm32l4x5_syscfg.c | 189 | @@ -XXX,XX +XXX,XX @@ static void stm32l4x5_soc_realize(DeviceState *dev_soc, Error **errp) |
202 | +++ b/hw/misc/stm32l4x5_syscfg.c | 190 | create_unimplemented_device("DAC1", 0x40007400, 0x400); |
203 | @@ -XXX,XX +XXX,XX @@ | 191 | create_unimplemented_device("OPAMP", 0x40007800, 0x400); |
204 | #include "hw/irq.h" | 192 | create_unimplemented_device("LPTIM1", 0x40007C00, 0x400); |
205 | #include "migration/vmstate.h" | 193 | - create_unimplemented_device("LPUART1", 0x40008000, 0x400); |
206 | #include "hw/misc/stm32l4x5_syscfg.h" | 194 | /* RESERVED: 0x40008400, 0x400 */ |
207 | +#include "hw/gpio/stm32l4x5_gpio.h" | 195 | create_unimplemented_device("SWPMI1", 0x40008800, 0x400); |
208 | 196 | /* RESERVED: 0x40008C00, 0x800 */ | |
209 | #define SYSCFG_MEMRMP 0x00 | 197 | @@ -XXX,XX +XXX,XX @@ static void stm32l4x5_soc_realize(DeviceState *dev_soc, Error **errp) |
210 | #define SYSCFG_CFGR1 0x04 | 198 | create_unimplemented_device("TIM1", 0x40012C00, 0x400); |
199 | create_unimplemented_device("SPI1", 0x40013000, 0x400); | ||
200 | create_unimplemented_device("TIM8", 0x40013400, 0x400); | ||
201 | - create_unimplemented_device("USART1", 0x40013800, 0x400); | ||
202 | /* RESERVED: 0x40013C00, 0x400 */ | ||
203 | create_unimplemented_device("TIM15", 0x40014000, 0x400); | ||
204 | create_unimplemented_device("TIM16", 0x40014400, 0x400); | ||
211 | diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig | 205 | diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig |
212 | index XXXXXXX..XXXXXXX 100644 | 206 | index XXXXXXX..XXXXXXX 100644 |
213 | --- a/hw/arm/Kconfig | 207 | --- a/hw/arm/Kconfig |
214 | +++ b/hw/arm/Kconfig | 208 | +++ b/hw/arm/Kconfig |
215 | @@ -XXX,XX +XXX,XX @@ config STM32L4X5_SOC | 209 | @@ -XXX,XX +XXX,XX @@ config STM32L4X5_SOC |
216 | bool | 210 | select STM32L4X5_SYSCFG |
217 | select ARM_V7M | ||
218 | select OR_IRQ | ||
219 | - select STM32L4X5_SYSCFG | ||
220 | select STM32L4X5_EXTI | ||
221 | + select STM32L4X5_SYSCFG | ||
222 | select STM32L4X5_RCC | 211 | select STM32L4X5_RCC |
223 | + select STM32L4X5_GPIO | 212 | select STM32L4X5_GPIO |
213 | + select STM32L4X5_USART | ||
224 | 214 | ||
225 | config XLNX_ZYNQMP_ARM | 215 | config XLNX_ZYNQMP_ARM |
226 | bool | 216 | bool |
227 | -- | 217 | -- |
228 | 2.34.1 | 218 | 2.34.1 |
229 | 219 | ||
230 | 220 | diff view generated by jsdifflib |
1 | From: Inès Varhol <ines.varhol@telecom-paris.fr> | 1 | From: Arnaud Minier <arnaud.minier@telecom-paris.fr> |
---|---|---|---|
2 | 2 | ||
3 | The testcase contains : | 3 | Test: |
4 | - `test_idr_reset_value()` : | 4 | - read/write from/to the usart registers |
5 | Checks the reset values of MODER, OTYPER, PUPDR, ODR and IDR. | 5 | - send/receive a character/string over the serial port |
6 | - `test_gpio_output_mode()` : | 6 | |
7 | Checks that writing a bit in register ODR results in the corresponding | ||
8 | pin rising or lowering, if this pin is configured in output mode. | ||
9 | - `test_gpio_input_mode()` : | ||
10 | Checks that a input pin set high or low externally results | ||
11 | in the pin rising and lowering. | ||
12 | - `test_pull_up_pull_down()` : | ||
13 | Checks that a floating pin in pull-up/down mode is actually high/down. | ||
14 | - `test_push_pull()` : | ||
15 | Checks that a pin set externally is disconnected when configured in | ||
16 | push-pull output mode, and can't be set externally while in this mode. | ||
17 | - `test_open_drain()` : | ||
18 | Checks that a pin set externally high is disconnected when configured | ||
19 | in open-drain output mode, and can't be set high while in this mode. | ||
20 | - `test_bsrr_brr()` : | ||
21 | Checks that writing to BSRR and BRR has the desired result in ODR. | ||
22 | - `test_clock_enable()` : | ||
23 | Checks that GPIO clock is at the right frequency after enabling it. | ||
24 | |||
25 | Acked-by: Thomas Huth <thuth@redhat.com> | ||
26 | Signed-off-by: Arnaud Minier <arnaud.minier@telecom-paris.fr> | 7 | Signed-off-by: Arnaud Minier <arnaud.minier@telecom-paris.fr> |
27 | Signed-off-by: Inès Varhol <ines.varhol@telecom-paris.fr> | 8 | Signed-off-by: Inès Varhol <ines.varhol@telecom-paris.fr> |
28 | Message-id: 20240305210444.310665-4-ines.varhol@telecom-paris.fr | 9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
10 | Message-id: 20240329174402.60382-6-arnaud.minier@telecom-paris.fr | ||
11 | [PMM: fix checkpatch nits, remove commented out code] | ||
29 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
30 | --- | 13 | --- |
31 | tests/qtest/stm32l4x5_gpio-test.c | 551 ++++++++++++++++++++++++++++++ | 14 | tests/qtest/stm32l4x5_usart-test.c | 315 +++++++++++++++++++++++++++++ |
32 | tests/qtest/meson.build | 3 +- | 15 | tests/qtest/meson.build | 4 +- |
33 | 2 files changed, 553 insertions(+), 1 deletion(-) | 16 | 2 files changed, 318 insertions(+), 1 deletion(-) |
34 | create mode 100644 tests/qtest/stm32l4x5_gpio-test.c | 17 | create mode 100644 tests/qtest/stm32l4x5_usart-test.c |
35 | 18 | ||
36 | diff --git a/tests/qtest/stm32l4x5_gpio-test.c b/tests/qtest/stm32l4x5_gpio-test.c | 19 | diff --git a/tests/qtest/stm32l4x5_usart-test.c b/tests/qtest/stm32l4x5_usart-test.c |
37 | new file mode 100644 | 20 | new file mode 100644 |
38 | index XXXXXXX..XXXXXXX | 21 | index XXXXXXX..XXXXXXX |
39 | --- /dev/null | 22 | --- /dev/null |
40 | +++ b/tests/qtest/stm32l4x5_gpio-test.c | 23 | +++ b/tests/qtest/stm32l4x5_usart-test.c |
41 | @@ -XXX,XX +XXX,XX @@ | 24 | @@ -XXX,XX +XXX,XX @@ |
42 | +/* | 25 | +/* |
43 | + * QTest testcase for STM32L4x5_GPIO | 26 | + * QTest testcase for STML4X5_USART |
44 | + * | 27 | + * |
45 | + * Copyright (c) 2024 Arnaud Minier <arnaud.minier@telecom-paris.fr> | 28 | + * Copyright (c) 2023 Arnaud Minier <arnaud.minier@telecom-paris.fr> |
46 | + * Copyright (c) 2024 Inès Varhol <ines.varhol@telecom-paris.fr> | 29 | + * Copyright (c) 2023 Inès Varhol <ines.varhol@telecom-paris.fr> |
47 | + * | 30 | + * |
48 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | 31 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. |
49 | + * See the COPYING file in the top-level directory. | 32 | + * See the COPYING file in the top-level directory. |
50 | + */ | 33 | + */ |
51 | + | 34 | + |
52 | +#include "qemu/osdep.h" | 35 | +#include "qemu/osdep.h" |
53 | +#include "libqtest-single.h" | 36 | +#include "libqtest.h" |
54 | + | 37 | +#include "hw/misc/stm32l4x5_rcc_internals.h" |
55 | +#define GPIO_BASE_ADDR 0x48000000 | 38 | +#include "hw/registerfields.h" |
56 | +#define GPIO_SIZE 0x400 | 39 | + |
57 | +#define NUM_GPIOS 8 | 40 | +#define RCC_BASE_ADDR 0x40021000 |
58 | +#define NUM_GPIO_PINS 16 | 41 | +/* Use USART 1 ADDR, assume the others work the same */ |
59 | + | 42 | +#define USART1_BASE_ADDR 0x40013800 |
60 | +#define GPIO_A 0x48000000 | 43 | + |
61 | +#define GPIO_B 0x48000400 | 44 | +/* See stm32l4x5_usart for definitions */ |
62 | +#define GPIO_C 0x48000800 | 45 | +REG32(CR1, 0x00) |
63 | +#define GPIO_D 0x48000C00 | 46 | + FIELD(CR1, M1, 28, 1) |
64 | +#define GPIO_E 0x48001000 | 47 | + FIELD(CR1, OVER8, 15, 1) |
65 | +#define GPIO_F 0x48001400 | 48 | + FIELD(CR1, M0, 12, 1) |
66 | +#define GPIO_G 0x48001800 | 49 | + FIELD(CR1, PCE, 10, 1) |
67 | +#define GPIO_H 0x48001C00 | 50 | + FIELD(CR1, TXEIE, 7, 1) |
68 | + | 51 | + FIELD(CR1, RXNEIE, 5, 1) |
69 | +#define MODER 0x00 | 52 | + FIELD(CR1, TE, 3, 1) |
70 | +#define OTYPER 0x04 | 53 | + FIELD(CR1, RE, 2, 1) |
71 | +#define PUPDR 0x0C | 54 | + FIELD(CR1, UE, 0, 1) |
72 | +#define IDR 0x10 | 55 | +REG32(CR2, 0x04) |
73 | +#define ODR 0x14 | 56 | +REG32(CR3, 0x08) |
74 | +#define BSRR 0x18 | 57 | + FIELD(CR3, OVRDIS, 12, 1) |
75 | +#define BRR 0x28 | 58 | +REG32(BRR, 0x0C) |
76 | + | 59 | +REG32(GTPR, 0x10) |
77 | +#define MODER_INPUT 0 | 60 | +REG32(RTOR, 0x14) |
78 | +#define MODER_OUTPUT 1 | 61 | +REG32(RQR, 0x18) |
79 | + | 62 | +REG32(ISR, 0x1C) |
80 | +#define PUPDR_NONE 0 | 63 | + FIELD(ISR, TXE, 7, 1) |
81 | +#define PUPDR_PULLUP 1 | 64 | + FIELD(ISR, RXNE, 5, 1) |
82 | +#define PUPDR_PULLDOWN 2 | 65 | + FIELD(ISR, ORE, 3, 1) |
83 | + | 66 | +REG32(ICR, 0x20) |
84 | +#define OTYPER_PUSH_PULL 0 | 67 | +REG32(RDR, 0x24) |
85 | +#define OTYPER_OPEN_DRAIN 1 | 68 | +REG32(TDR, 0x28) |
86 | + | 69 | + |
87 | +const uint32_t moder_reset[NUM_GPIOS] = { | 70 | +#define NVIC_ISPR1 0XE000E204 |
88 | + 0xABFFFFFF, | 71 | +#define NVIC_ICPR1 0xE000E284 |
89 | + 0xFFFFFEBF, | 72 | +#define USART1_IRQ 37 |
90 | + 0xFFFFFFFF, | 73 | + |
91 | + 0xFFFFFFFF, | 74 | +static bool check_nvic_pending(QTestState *qts, unsigned int n) |
92 | + 0xFFFFFFFF, | 75 | +{ |
93 | + 0xFFFFFFFF, | 76 | + /* No USART interrupts are less than 32 */ |
94 | + 0xFFFFFFFF, | 77 | + assert(n > 32); |
95 | + 0x0000000F | 78 | + n -= 32; |
96 | +}; | 79 | + return qtest_readl(qts, NVIC_ISPR1) & (1 << n); |
97 | + | 80 | +} |
98 | +const uint32_t pupdr_reset[NUM_GPIOS] = { | 81 | + |
99 | + 0x64000000, | 82 | +static bool clear_nvic_pending(QTestState *qts, unsigned int n) |
100 | + 0x00000100, | 83 | +{ |
101 | + 0x00000000, | 84 | + /* No USART interrupts are less than 32 */ |
102 | + 0x00000000, | 85 | + assert(n > 32); |
103 | + 0x00000000, | 86 | + n -= 32; |
104 | + 0x00000000, | 87 | + qtest_writel(qts, NVIC_ICPR1, (1 << n)); |
105 | + 0x00000000, | 88 | + return true; |
106 | + 0x00000000 | 89 | +} |
107 | +}; | 90 | + |
108 | + | 91 | +/* |
109 | +const uint32_t idr_reset[NUM_GPIOS] = { | 92 | + * Wait indefinitely for the flag to be updated. |
110 | + 0x0000A000, | 93 | + * If this is run on a slow CI runner, |
111 | + 0x00000010, | 94 | + * the meson harness will timeout after 10 minutes for us. |
112 | + 0x00000000, | 95 | + */ |
113 | + 0x00000000, | 96 | +static bool usart_wait_for_flag(QTestState *qts, uint32_t event_addr, |
114 | + 0x00000000, | 97 | + uint32_t flag) |
115 | + 0x00000000, | 98 | +{ |
116 | + 0x00000000, | 99 | + while (true) { |
117 | + 0x00000000 | 100 | + if ((qtest_readl(qts, event_addr) & flag)) { |
118 | +}; | 101 | + return true; |
119 | + | 102 | + } |
120 | +static uint32_t gpio_readl(unsigned int gpio, unsigned int offset) | 103 | + g_usleep(1000); |
121 | +{ | ||
122 | + return readl(gpio + offset); | ||
123 | +} | ||
124 | + | ||
125 | +static void gpio_writel(unsigned int gpio, unsigned int offset, uint32_t value) | ||
126 | +{ | ||
127 | + writel(gpio + offset, value); | ||
128 | +} | ||
129 | + | ||
130 | +static void gpio_set_bit(unsigned int gpio, unsigned int reg, | ||
131 | + unsigned int pin, uint32_t value) | ||
132 | +{ | ||
133 | + uint32_t mask = 0xFFFFFFFF & ~(0x1 << pin); | ||
134 | + gpio_writel(gpio, reg, (gpio_readl(gpio, reg) & mask) | value << pin); | ||
135 | +} | ||
136 | + | ||
137 | +static void gpio_set_2bits(unsigned int gpio, unsigned int reg, | ||
138 | + unsigned int pin, uint32_t value) | ||
139 | +{ | ||
140 | + uint32_t offset = 2 * pin; | ||
141 | + uint32_t mask = 0xFFFFFFFF & ~(0x3 << offset); | ||
142 | + gpio_writel(gpio, reg, (gpio_readl(gpio, reg) & mask) | value << offset); | ||
143 | +} | ||
144 | + | ||
145 | +static unsigned int get_gpio_id(uint32_t gpio_addr) | ||
146 | +{ | ||
147 | + return (gpio_addr - GPIO_BASE_ADDR) / GPIO_SIZE; | ||
148 | +} | ||
149 | + | ||
150 | +static void gpio_set_irq(unsigned int gpio, int num, int level) | ||
151 | +{ | ||
152 | + g_autofree char *name = g_strdup_printf("/machine/soc/gpio%c", | ||
153 | + get_gpio_id(gpio) + 'a'); | ||
154 | + qtest_set_irq_in(global_qtest, name, NULL, num, level); | ||
155 | +} | ||
156 | + | ||
157 | +static void disconnect_all_pins(unsigned int gpio) | ||
158 | +{ | ||
159 | + g_autofree char *path = g_strdup_printf("/machine/soc/gpio%c", | ||
160 | + get_gpio_id(gpio) + 'a'); | ||
161 | + QDict *r; | ||
162 | + | ||
163 | + r = qtest_qmp(global_qtest, "{ 'execute': 'qom-set', 'arguments': " | ||
164 | + "{ 'path': %s, 'property': 'disconnected-pins', 'value': %d } }", | ||
165 | + path, 0xFFFF); | ||
166 | + g_assert_false(qdict_haskey(r, "error")); | ||
167 | + qobject_unref(r); | ||
168 | +} | ||
169 | + | ||
170 | +static uint32_t get_disconnected_pins(unsigned int gpio) | ||
171 | +{ | ||
172 | + g_autofree char *path = g_strdup_printf("/machine/soc/gpio%c", | ||
173 | + get_gpio_id(gpio) + 'a'); | ||
174 | + uint32_t disconnected_pins = 0; | ||
175 | + QDict *r; | ||
176 | + | ||
177 | + r = qtest_qmp(global_qtest, "{ 'execute': 'qom-get', 'arguments':" | ||
178 | + " { 'path': %s, 'property': 'disconnected-pins'} }", path); | ||
179 | + g_assert_false(qdict_haskey(r, "error")); | ||
180 | + disconnected_pins = qdict_get_int(r, "return"); | ||
181 | + qobject_unref(r); | ||
182 | + return disconnected_pins; | ||
183 | +} | ||
184 | + | ||
185 | +static uint32_t reset(uint32_t gpio, unsigned int offset) | ||
186 | +{ | ||
187 | + switch (offset) { | ||
188 | + case MODER: | ||
189 | + return moder_reset[get_gpio_id(gpio)]; | ||
190 | + case PUPDR: | ||
191 | + return pupdr_reset[get_gpio_id(gpio)]; | ||
192 | + case IDR: | ||
193 | + return idr_reset[get_gpio_id(gpio)]; | ||
194 | + } | 104 | + } |
195 | + return 0x0; | 105 | + |
196 | +} | 106 | + return false; |
197 | + | 107 | +} |
198 | +static void system_reset(void) | 108 | + |
199 | +{ | 109 | +static void usart_receive_string(QTestState *qts, int sock_fd, const char *in, |
200 | + QDict *r; | 110 | + char *out) |
201 | + r = qtest_qmp(global_qtest, "{'execute': 'system_reset'}"); | 111 | +{ |
202 | + g_assert_false(qdict_haskey(r, "error")); | 112 | + int i, in_len = strlen(in); |
203 | + qobject_unref(r); | 113 | + |
204 | +} | 114 | + g_assert_true(send(sock_fd, in, in_len, 0) == in_len); |
205 | + | 115 | + for (i = 0; i < in_len; i++) { |
206 | +static void test_idr_reset_value(void) | 116 | + g_assert_true(usart_wait_for_flag(qts, |
207 | +{ | 117 | + USART1_BASE_ADDR + A_ISR, R_ISR_RXNE_MASK)); |
118 | + out[i] = qtest_readl(qts, USART1_BASE_ADDR + A_RDR); | ||
119 | + } | ||
120 | + out[i] = '\0'; | ||
121 | +} | ||
122 | + | ||
123 | +static void usart_send_string(QTestState *qts, const char *in) | ||
124 | +{ | ||
125 | + int i, in_len = strlen(in); | ||
126 | + | ||
127 | + for (i = 0; i < in_len; i++) { | ||
128 | + qtest_writel(qts, USART1_BASE_ADDR + A_TDR, in[i]); | ||
129 | + g_assert_true(usart_wait_for_flag(qts, | ||
130 | + USART1_BASE_ADDR + A_ISR, R_ISR_TXE_MASK)); | ||
131 | + } | ||
132 | +} | ||
133 | + | ||
134 | +/* Init the RCC clocks to run at 80 MHz */ | ||
135 | +static void init_clocks(QTestState *qts) | ||
136 | +{ | ||
137 | + uint32_t value; | ||
138 | + | ||
139 | + /* MSIRANGE can be set only when MSI is OFF or READY */ | ||
140 | + qtest_writel(qts, (RCC_BASE_ADDR + A_CR), R_CR_MSION_MASK); | ||
141 | + | ||
142 | + /* Clocking from MSI, in case MSI was not the default source */ | ||
143 | + qtest_writel(qts, (RCC_BASE_ADDR + A_CFGR), 0); | ||
144 | + | ||
208 | + /* | 145 | + /* |
209 | + * Checks that the values in MODER, OTYPER, PUPDR and ODR | 146 | + * Update PLL and set MSI as the source clock. |
210 | + * after reset are correct, and that the value in IDR is | 147 | + * PLLM = 1 --> 000 |
211 | + * coherent. | 148 | + * PLLN = 40 --> 40 |
212 | + * Since AF and analog modes aren't implemented, IDR reset | 149 | + * PPLLR = 2 --> 00 |
213 | + * values aren't the same as with a real board. | 150 | + * PLLDIV = unused, PLLP = unused (SAI3), PLLQ = unused (48M1) |
214 | + * | 151 | + * SRC = MSI --> 01 |
215 | + * Register IDR contains the actual values of all GPIO pins. | ||
216 | + * Its value depends on the pins' configuration | ||
217 | + * (intput/output/analog : register MODER, push-pull/open-drain : | ||
218 | + * register OTYPER, pull-up/pull-down/none : register PUPDR) | ||
219 | + * and on the values stored in register ODR | ||
220 | + * (in case the pin is in output mode). | ||
221 | + */ | 152 | + */ |
222 | + | 153 | + qtest_writel(qts, (RCC_BASE_ADDR + A_PLLCFGR), R_PLLCFGR_PLLREN_MASK | |
223 | + gpio_writel(GPIO_A, MODER, 0xDEADBEEF); | 154 | + (40 << R_PLLCFGR_PLLN_SHIFT) | |
224 | + gpio_writel(GPIO_A, ODR, 0xDEADBEEF); | 155 | + (0b01 << R_PLLCFGR_PLLSRC_SHIFT)); |
225 | + gpio_writel(GPIO_A, OTYPER, 0xDEADBEEF); | 156 | + |
226 | + gpio_writel(GPIO_A, PUPDR, 0xDEADBEEF); | 157 | + /* PLL activation */ |
227 | + | 158 | + |
228 | + gpio_writel(GPIO_B, MODER, 0xDEADBEEF); | 159 | + value = qtest_readl(qts, (RCC_BASE_ADDR + A_CR)); |
229 | + gpio_writel(GPIO_B, ODR, 0xDEADBEEF); | 160 | + qtest_writel(qts, (RCC_BASE_ADDR + A_CR), value | R_CR_PLLON_MASK); |
230 | + gpio_writel(GPIO_B, OTYPER, 0xDEADBEEF); | 161 | + |
231 | + gpio_writel(GPIO_B, PUPDR, 0xDEADBEEF); | 162 | + /* RCC_CFGR is OK by defaut */ |
232 | + | 163 | + qtest_writel(qts, (RCC_BASE_ADDR + A_CFGR), 0); |
233 | + gpio_writel(GPIO_C, MODER, 0xDEADBEEF); | 164 | + |
234 | + gpio_writel(GPIO_C, ODR, 0xDEADBEEF); | 165 | + /* CCIPR : no periph clock by default */ |
235 | + gpio_writel(GPIO_C, OTYPER, 0xDEADBEEF); | 166 | + qtest_writel(qts, (RCC_BASE_ADDR + A_CCIPR), 0); |
236 | + gpio_writel(GPIO_C, PUPDR, 0xDEADBEEF); | 167 | + |
237 | + | 168 | + /* Switches on the PLL clock source */ |
238 | + gpio_writel(GPIO_H, MODER, 0xDEADBEEF); | 169 | + value = qtest_readl(qts, (RCC_BASE_ADDR + A_CFGR)); |
239 | + gpio_writel(GPIO_H, ODR, 0xDEADBEEF); | 170 | + qtest_writel(qts, (RCC_BASE_ADDR + A_CFGR), (value & ~R_CFGR_SW_MASK) | |
240 | + gpio_writel(GPIO_H, OTYPER, 0xDEADBEEF); | 171 | + (0b11 << R_CFGR_SW_SHIFT)); |
241 | + gpio_writel(GPIO_H, PUPDR, 0xDEADBEEF); | 172 | + |
242 | + | 173 | + /* Enable SYSCFG clock enabled */ |
243 | + system_reset(); | 174 | + qtest_writel(qts, (RCC_BASE_ADDR + A_APB2ENR), R_APB2ENR_SYSCFGEN_MASK); |
244 | + | 175 | + |
245 | + uint32_t moder = gpio_readl(GPIO_A, MODER); | 176 | + /* Enable the IO port B clock (See p.252) */ |
246 | + uint32_t odr = gpio_readl(GPIO_A, ODR); | 177 | + qtest_writel(qts, (RCC_BASE_ADDR + A_AHB2ENR), R_AHB2ENR_GPIOBEN_MASK); |
247 | + uint32_t otyper = gpio_readl(GPIO_A, OTYPER); | 178 | + |
248 | + uint32_t pupdr = gpio_readl(GPIO_A, PUPDR); | 179 | + /* Enable the clock for USART1 (cf p.259) */ |
249 | + uint32_t idr = gpio_readl(GPIO_A, IDR); | 180 | + /* We rewrite SYSCFGEN to not disable it */ |
250 | + /* 15: AF, 14: AF, 13: AF, 12: Analog ... */ | 181 | + qtest_writel(qts, (RCC_BASE_ADDR + A_APB2ENR), |
251 | + /* here AF is the same as Analog and Input mode */ | 182 | + R_APB2ENR_SYSCFGEN_MASK | R_APB2ENR_USART1EN_MASK); |
252 | + g_assert_cmphex(moder, ==, reset(GPIO_A, MODER)); | 183 | + |
253 | + g_assert_cmphex(odr, ==, reset(GPIO_A, ODR)); | 184 | + /* TODO: Enable usart via gpio */ |
254 | + g_assert_cmphex(otyper, ==, reset(GPIO_A, OTYPER)); | 185 | + |
255 | + /* 15: pull-up, 14: pull-down, 13: pull-up, 12: neither ... */ | 186 | + /* Set PCLK as the clock for USART1(cf p.272) i.e. reset both bits */ |
256 | + g_assert_cmphex(pupdr, ==, reset(GPIO_A, PUPDR)); | 187 | + qtest_writel(qts, (RCC_BASE_ADDR + A_CCIPR), 0); |
257 | + /* 15 : 1, 14: 0, 13: 1, 12 : reset value ... */ | 188 | + |
258 | + g_assert_cmphex(idr, ==, reset(GPIO_A, IDR)); | 189 | + /* Reset USART1 (see p.249) */ |
259 | + | 190 | + qtest_writel(qts, (RCC_BASE_ADDR + A_APB2RSTR), 1 << 14); |
260 | + moder = gpio_readl(GPIO_B, MODER); | 191 | + qtest_writel(qts, (RCC_BASE_ADDR + A_APB2RSTR), 0); |
261 | + odr = gpio_readl(GPIO_B, ODR); | 192 | +} |
262 | + otyper = gpio_readl(GPIO_B, OTYPER); | 193 | + |
263 | + pupdr = gpio_readl(GPIO_B, PUPDR); | 194 | +static void init_uart(QTestState *qts) |
264 | + idr = gpio_readl(GPIO_B, IDR); | 195 | +{ |
265 | + /* ... 5: Analog, 4: AF, 3: AF, 2: Analog ... */ | 196 | + uint32_t cr1; |
266 | + /* here AF is the same as Analog and Input mode */ | 197 | + |
267 | + g_assert_cmphex(moder, ==, reset(GPIO_B, MODER)); | 198 | + init_clocks(qts); |
268 | + g_assert_cmphex(odr, ==, reset(GPIO_B, ODR)); | 199 | + |
269 | + g_assert_cmphex(otyper, ==, reset(GPIO_B, OTYPER)); | ||
270 | + /* ... 5: neither, 4: pull-up, 3: neither ... */ | ||
271 | + g_assert_cmphex(pupdr, ==, reset(GPIO_B, PUPDR)); | ||
272 | + /* ... 5 : reset value, 4 : 1, 3 : reset value ... */ | ||
273 | + g_assert_cmphex(idr, ==, reset(GPIO_B, IDR)); | ||
274 | + | ||
275 | + moder = gpio_readl(GPIO_C, MODER); | ||
276 | + odr = gpio_readl(GPIO_C, ODR); | ||
277 | + otyper = gpio_readl(GPIO_C, OTYPER); | ||
278 | + pupdr = gpio_readl(GPIO_C, PUPDR); | ||
279 | + idr = gpio_readl(GPIO_C, IDR); | ||
280 | + /* Analog, same as Input mode*/ | ||
281 | + g_assert_cmphex(moder, ==, reset(GPIO_C, MODER)); | ||
282 | + g_assert_cmphex(odr, ==, reset(GPIO_C, ODR)); | ||
283 | + g_assert_cmphex(otyper, ==, reset(GPIO_C, OTYPER)); | ||
284 | + /* no pull-up or pull-down */ | ||
285 | + g_assert_cmphex(pupdr, ==, reset(GPIO_C, PUPDR)); | ||
286 | + /* reset value */ | ||
287 | + g_assert_cmphex(idr, ==, reset(GPIO_C, IDR)); | ||
288 | + | ||
289 | + moder = gpio_readl(GPIO_H, MODER); | ||
290 | + odr = gpio_readl(GPIO_H, ODR); | ||
291 | + otyper = gpio_readl(GPIO_H, OTYPER); | ||
292 | + pupdr = gpio_readl(GPIO_H, PUPDR); | ||
293 | + idr = gpio_readl(GPIO_H, IDR); | ||
294 | + /* Analog, same as Input mode */ | ||
295 | + g_assert_cmphex(moder, ==, reset(GPIO_H, MODER)); | ||
296 | + g_assert_cmphex(odr, ==, reset(GPIO_H, ODR)); | ||
297 | + g_assert_cmphex(otyper, ==, reset(GPIO_H, OTYPER)); | ||
298 | + /* no pull-up or pull-down */ | ||
299 | + g_assert_cmphex(pupdr, ==, reset(GPIO_H, PUPDR)); | ||
300 | + /* reset value */ | ||
301 | + g_assert_cmphex(idr, ==, reset(GPIO_H, IDR)); | ||
302 | +} | ||
303 | + | ||
304 | +static void test_gpio_output_mode(const void *data) | ||
305 | +{ | ||
306 | + /* | 200 | + /* |
307 | + * Checks that setting a bit in ODR sets the corresponding | 201 | + * For 115200 bauds, see p.1349. |
308 | + * GPIO line high : it should set the right bit in IDR | 202 | + * The clock has a frequency of 80Mhz, |
309 | + * and send an irq to syscfg. | 203 | + * for 115200, we have to put a divider of 695 = 0x2B7. |
310 | + * Additionally, it checks that values written to ODR | ||
311 | + * when not in output mode are stored and not discarded. | ||
312 | + */ | 204 | + */ |
313 | + unsigned int pin = ((uint64_t)data) & 0xF; | 205 | + qtest_writel(qts, (USART1_BASE_ADDR + A_BRR), 0x2B7); |
314 | + uint32_t gpio = ((uint64_t)data) >> 32; | 206 | + |
315 | + unsigned int gpio_id = get_gpio_id(gpio); | ||
316 | + | ||
317 | + qtest_irq_intercept_in(global_qtest, "/machine/soc/syscfg"); | ||
318 | + | ||
319 | + /* Set a bit in ODR and check nothing happens */ | ||
320 | + gpio_set_bit(gpio, ODR, pin, 1); | ||
321 | + g_assert_cmphex(gpio_readl(gpio, IDR), ==, reset(gpio, IDR)); | ||
322 | + g_assert_false(get_irq(gpio_id * NUM_GPIO_PINS + pin)); | ||
323 | + | ||
324 | + /* Configure the relevant line as output and check the pin is high */ | ||
325 | + gpio_set_2bits(gpio, MODER, pin, MODER_OUTPUT); | ||
326 | + g_assert_cmphex(gpio_readl(gpio, IDR), ==, reset(gpio, IDR) | (1 << pin)); | ||
327 | + g_assert_true(get_irq(gpio_id * NUM_GPIO_PINS + pin)); | ||
328 | + | ||
329 | + /* Reset the bit in ODR and check the pin is low */ | ||
330 | + gpio_set_bit(gpio, ODR, pin, 0); | ||
331 | + g_assert_cmphex(gpio_readl(gpio, IDR), ==, reset(gpio, IDR) & ~(1 << pin)); | ||
332 | + g_assert_false(get_irq(gpio_id * NUM_GPIO_PINS + pin)); | ||
333 | + | ||
334 | + /* Clean the test */ | ||
335 | + gpio_writel(gpio, ODR, reset(gpio, ODR)); | ||
336 | + gpio_writel(gpio, MODER, reset(gpio, MODER)); | ||
337 | + g_assert_cmphex(gpio_readl(gpio, IDR), ==, reset(gpio, IDR)); | ||
338 | + g_assert_false(get_irq(gpio_id * NUM_GPIO_PINS + pin)); | ||
339 | +} | ||
340 | + | ||
341 | +static void test_gpio_input_mode(const void *data) | ||
342 | +{ | ||
343 | + /* | 207 | + /* |
344 | + * Test that setting a line high/low externally sets the | 208 | + * Set the oversampling by 16, |
345 | + * corresponding GPIO line high/low : it should set the | 209 | + * disable the parity control and |
346 | + * right bit in IDR and send an irq to syscfg. | 210 | + * set the word length to 8. (cf p.1377) |
347 | + */ | 211 | + */ |
348 | + unsigned int pin = ((uint64_t)data) & 0xF; | 212 | + cr1 = qtest_readl(qts, (USART1_BASE_ADDR + A_CR1)); |
349 | + uint32_t gpio = ((uint64_t)data) >> 32; | 213 | + cr1 &= ~(R_CR1_M1_MASK | R_CR1_M0_MASK | R_CR1_OVER8_MASK | R_CR1_PCE_MASK); |
350 | + unsigned int gpio_id = get_gpio_id(gpio); | 214 | + qtest_writel(qts, (USART1_BASE_ADDR + A_CR1), cr1); |
351 | + | 215 | + |
352 | + qtest_irq_intercept_in(global_qtest, "/machine/soc/syscfg"); | 216 | + /* Enable the transmitter, the receiver and the USART. */ |
353 | + | 217 | + qtest_writel(qts, (USART1_BASE_ADDR + A_CR1), |
354 | + /* Configure a line as input, raise it, and check that the pin is high */ | 218 | + R_CR1_UE_MASK | R_CR1_RE_MASK | R_CR1_TE_MASK); |
355 | + gpio_set_2bits(gpio, MODER, pin, MODER_INPUT); | 219 | +} |
356 | + gpio_set_irq(gpio, pin, 1); | 220 | + |
357 | + g_assert_cmphex(gpio_readl(gpio, IDR), ==, reset(gpio, IDR) | (1 << pin)); | 221 | +static void test_write_read(void) |
358 | + g_assert_true(get_irq(gpio_id * NUM_GPIO_PINS + pin)); | 222 | +{ |
359 | + | 223 | + QTestState *qts = qtest_init("-M b-l475e-iot01a"); |
360 | + /* Lower the line and check that the pin is low */ | 224 | + |
361 | + gpio_set_irq(gpio, pin, 0); | 225 | + /* Test that we can write and retrieve a value from the device */ |
362 | + g_assert_cmphex(gpio_readl(gpio, IDR), ==, reset(gpio, IDR) & ~(1 << pin)); | 226 | + qtest_writel(qts, USART1_BASE_ADDR + A_TDR, 0xFFFFFFFF); |
363 | + g_assert_false(get_irq(gpio_id * NUM_GPIO_PINS + pin)); | 227 | + const uint32_t tdr = qtest_readl(qts, USART1_BASE_ADDR + A_TDR); |
364 | + | 228 | + g_assert_cmpuint(tdr, ==, 0x000001FF); |
365 | + /* Clean the test */ | 229 | +} |
366 | + gpio_writel(gpio, MODER, reset(gpio, MODER)); | 230 | + |
367 | + disconnect_all_pins(gpio); | 231 | +static void test_receive_char(void) |
368 | + g_assert_cmphex(gpio_readl(gpio, IDR), ==, reset(gpio, IDR)); | 232 | +{ |
369 | +} | 233 | + int sock_fd; |
370 | + | 234 | + uint32_t cr1; |
371 | +static void test_pull_up_pull_down(const void *data) | 235 | + QTestState *qts = qtest_init_with_serial("-M b-l475e-iot01a", &sock_fd); |
372 | +{ | 236 | + |
373 | + /* | 237 | + init_uart(qts); |
374 | + * Test that a floating pin with pull-up sets the pin | 238 | + |
375 | + * high and vice-versa. | 239 | + /* Try without initializing IRQ */ |
376 | + */ | 240 | + g_assert_true(send(sock_fd, "a", 1, 0) == 1); |
377 | + unsigned int pin = ((uint64_t)data) & 0xF; | 241 | + usart_wait_for_flag(qts, USART1_BASE_ADDR + A_ISR, R_ISR_RXNE_MASK); |
378 | + uint32_t gpio = ((uint64_t)data) >> 32; | 242 | + g_assert_cmphex(qtest_readl(qts, USART1_BASE_ADDR + A_RDR), ==, 'a'); |
379 | + unsigned int gpio_id = get_gpio_id(gpio); | 243 | + g_assert_false(check_nvic_pending(qts, USART1_IRQ)); |
380 | + | 244 | + |
381 | + qtest_irq_intercept_in(global_qtest, "/machine/soc/syscfg"); | 245 | + /* Now with the IRQ */ |
382 | + | 246 | + cr1 = qtest_readl(qts, (USART1_BASE_ADDR + A_CR1)); |
383 | + /* Configure a line as input with pull-up, check the line is set high */ | 247 | + cr1 |= R_CR1_RXNEIE_MASK; |
384 | + gpio_set_2bits(gpio, MODER, pin, MODER_INPUT); | 248 | + qtest_writel(qts, USART1_BASE_ADDR + A_CR1, cr1); |
385 | + gpio_set_2bits(gpio, PUPDR, pin, PUPDR_PULLUP); | 249 | + g_assert_true(send(sock_fd, "b", 1, 0) == 1); |
386 | + g_assert_cmphex(gpio_readl(gpio, IDR), ==, reset(gpio, IDR) | (1 << pin)); | 250 | + usart_wait_for_flag(qts, USART1_BASE_ADDR + A_ISR, R_ISR_RXNE_MASK); |
387 | + g_assert_true(get_irq(gpio_id * NUM_GPIO_PINS + pin)); | 251 | + g_assert_cmphex(qtest_readl(qts, USART1_BASE_ADDR + A_RDR), ==, 'b'); |
388 | + | 252 | + g_assert_true(check_nvic_pending(qts, USART1_IRQ)); |
389 | + /* Configure the line with pull-down, check the line is low */ | 253 | + clear_nvic_pending(qts, USART1_IRQ); |
390 | + gpio_set_2bits(gpio, PUPDR, pin, PUPDR_PULLDOWN); | 254 | + |
391 | + g_assert_cmphex(gpio_readl(gpio, IDR), ==, reset(gpio, IDR) & ~(1 << pin)); | 255 | + close(sock_fd); |
392 | + g_assert_false(get_irq(gpio_id * NUM_GPIO_PINS + pin)); | 256 | + |
393 | + | 257 | + qtest_quit(qts); |
394 | + /* Clean the test */ | 258 | +} |
395 | + gpio_writel(gpio, MODER, reset(gpio, MODER)); | 259 | + |
396 | + gpio_writel(gpio, PUPDR, reset(gpio, PUPDR)); | 260 | +static void test_send_char(void) |
397 | + g_assert_cmphex(gpio_readl(gpio, IDR), ==, reset(gpio, IDR)); | 261 | +{ |
398 | +} | 262 | + int sock_fd; |
399 | + | 263 | + char s[1]; |
400 | +static void test_push_pull(const void *data) | 264 | + uint32_t cr1; |
401 | +{ | 265 | + QTestState *qts = qtest_init_with_serial("-M b-l475e-iot01a", &sock_fd); |
402 | + /* | 266 | + |
403 | + * Test that configuring a line in push-pull output mode | 267 | + init_uart(qts); |
404 | + * disconnects the pin, that the pin can't be set or reset | 268 | + |
405 | + * externally afterwards. | 269 | + /* Try without initializing IRQ */ |
406 | + */ | 270 | + qtest_writel(qts, USART1_BASE_ADDR + A_TDR, 'c'); |
407 | + unsigned int pin = ((uint64_t)data) & 0xF; | 271 | + g_assert_true(recv(sock_fd, s, 1, 0) == 1); |
408 | + uint32_t gpio = ((uint64_t)data) >> 32; | 272 | + g_assert_cmphex(s[0], ==, 'c'); |
409 | + uint32_t gpio2 = GPIO_BASE_ADDR + (GPIO_H - gpio); | 273 | + g_assert_false(check_nvic_pending(qts, USART1_IRQ)); |
410 | + | 274 | + |
411 | + qtest_irq_intercept_in(global_qtest, "/machine/soc/syscfg"); | 275 | + /* Now with the IRQ */ |
412 | + | 276 | + cr1 = qtest_readl(qts, (USART1_BASE_ADDR + A_CR1)); |
413 | + /* Setting a line high externally, configuring it in push-pull output */ | 277 | + cr1 |= R_CR1_TXEIE_MASK; |
414 | + /* And checking the pin was disconnected */ | 278 | + qtest_writel(qts, USART1_BASE_ADDR + A_CR1, cr1); |
415 | + gpio_set_irq(gpio, pin, 1); | 279 | + qtest_writel(qts, USART1_BASE_ADDR + A_TDR, 'd'); |
416 | + gpio_set_2bits(gpio, MODER, pin, MODER_OUTPUT); | 280 | + g_assert_true(recv(sock_fd, s, 1, 0) == 1); |
417 | + g_assert_cmphex(get_disconnected_pins(gpio), ==, 0xFFFF); | 281 | + g_assert_cmphex(s[0], ==, 'd'); |
418 | + g_assert_cmphex(gpio_readl(gpio, IDR), ==, reset(gpio, IDR) & ~(1 << pin)); | 282 | + g_assert_true(check_nvic_pending(qts, USART1_IRQ)); |
419 | + | 283 | + clear_nvic_pending(qts, USART1_IRQ); |
420 | + /* Setting a line low externally, configuring it in push-pull output */ | 284 | + |
421 | + /* And checking the pin was disconnected */ | 285 | + close(sock_fd); |
422 | + gpio_set_irq(gpio2, pin, 0); | 286 | + |
423 | + gpio_set_bit(gpio2, ODR, pin, 1); | 287 | + qtest_quit(qts); |
424 | + gpio_set_2bits(gpio2, MODER, pin, MODER_OUTPUT); | 288 | +} |
425 | + g_assert_cmphex(get_disconnected_pins(gpio2), ==, 0xFFFF); | 289 | + |
426 | + g_assert_cmphex(gpio_readl(gpio2, IDR), ==, reset(gpio2, IDR) | (1 << pin)); | 290 | +static void test_receive_str(void) |
427 | + | 291 | +{ |
428 | + /* Trying to set a push-pull output pin, checking it doesn't work */ | 292 | + int sock_fd; |
429 | + gpio_set_irq(gpio, pin, 1); | 293 | + char s[10]; |
430 | + g_assert_cmphex(get_disconnected_pins(gpio), ==, 0xFFFF); | 294 | + QTestState *qts = qtest_init_with_serial("-M b-l475e-iot01a", &sock_fd); |
431 | + g_assert_cmphex(gpio_readl(gpio, IDR), ==, reset(gpio, IDR) & ~(1 << pin)); | 295 | + |
432 | + | 296 | + init_uart(qts); |
433 | + /* Trying to reset a push-pull output pin, checking it doesn't work */ | 297 | + |
434 | + gpio_set_irq(gpio2, pin, 0); | 298 | + usart_receive_string(qts, sock_fd, "hello", s); |
435 | + g_assert_cmphex(get_disconnected_pins(gpio2), ==, 0xFFFF); | 299 | + g_assert_true(memcmp(s, "hello", 5) == 0); |
436 | + g_assert_cmphex(gpio_readl(gpio2, IDR), ==, reset(gpio2, IDR) | (1 << pin)); | 300 | + |
437 | + | 301 | + close(sock_fd); |
438 | + /* Clean the test */ | 302 | + |
439 | + gpio_writel(gpio, MODER, reset(gpio, MODER)); | 303 | + qtest_quit(qts); |
440 | + gpio_writel(gpio2, ODR, reset(gpio2, ODR)); | 304 | +} |
441 | + gpio_writel(gpio2, MODER, reset(gpio2, MODER)); | 305 | + |
442 | +} | 306 | +static void test_send_str(void) |
443 | + | 307 | +{ |
444 | +static void test_open_drain(const void *data) | 308 | + int sock_fd; |
445 | +{ | 309 | + char s[10]; |
446 | + /* | 310 | + QTestState *qts = qtest_init_with_serial("-M b-l475e-iot01a", &sock_fd); |
447 | + * Test that configuring a line in open-drain output mode | 311 | + |
448 | + * disconnects a pin set high externally and that the pin | 312 | + init_uart(qts); |
449 | + * can't be set high externally while configured in open-drain. | 313 | + |
450 | + * | 314 | + usart_send_string(qts, "world"); |
451 | + * However a pin set low externally shouldn't be disconnected, | 315 | + g_assert_true(recv(sock_fd, s, 10, 0) == 5); |
452 | + * and it can be set low externally when in open-drain mode. | 316 | + g_assert_true(memcmp(s, "world", 5) == 0); |
453 | + */ | 317 | + |
454 | + unsigned int pin = ((uint64_t)data) & 0xF; | 318 | + close(sock_fd); |
455 | + uint32_t gpio = ((uint64_t)data) >> 32; | 319 | + |
456 | + uint32_t gpio2 = GPIO_BASE_ADDR + (GPIO_H - gpio); | 320 | + qtest_quit(qts); |
457 | + | ||
458 | + qtest_irq_intercept_in(global_qtest, "/machine/soc/syscfg"); | ||
459 | + | ||
460 | + /* Setting a line high externally, configuring it in open-drain output */ | ||
461 | + /* And checking the pin was disconnected */ | ||
462 | + gpio_set_irq(gpio, pin, 1); | ||
463 | + gpio_set_bit(gpio, OTYPER, pin, OTYPER_OPEN_DRAIN); | ||
464 | + gpio_set_2bits(gpio, MODER, pin, MODER_OUTPUT); | ||
465 | + g_assert_cmphex(get_disconnected_pins(gpio), ==, 0xFFFF); | ||
466 | + g_assert_cmphex(gpio_readl(gpio, IDR), ==, reset(gpio, IDR) & ~(1 << pin)); | ||
467 | + | ||
468 | + /* Setting a line low externally, configuring it in open-drain output */ | ||
469 | + /* And checking the pin wasn't disconnected */ | ||
470 | + gpio_set_irq(gpio2, pin, 0); | ||
471 | + gpio_set_bit(gpio2, ODR, pin, 1); | ||
472 | + gpio_set_bit(gpio2, OTYPER, pin, OTYPER_OPEN_DRAIN); | ||
473 | + gpio_set_2bits(gpio2, MODER, pin, MODER_OUTPUT); | ||
474 | + g_assert_cmphex(get_disconnected_pins(gpio2), ==, 0xFFFF & ~(1 << pin)); | ||
475 | + g_assert_cmphex(gpio_readl(gpio2, IDR), ==, | ||
476 | + reset(gpio2, IDR) & ~(1 << pin)); | ||
477 | + | ||
478 | + /* Trying to set a open-drain output pin, checking it doesn't work */ | ||
479 | + gpio_set_irq(gpio, pin, 1); | ||
480 | + g_assert_cmphex(get_disconnected_pins(gpio), ==, 0xFFFF); | ||
481 | + g_assert_cmphex(gpio_readl(gpio, IDR), ==, reset(gpio, IDR) & ~(1 << pin)); | ||
482 | + | ||
483 | + /* Trying to reset a open-drain output pin, checking it works */ | ||
484 | + gpio_set_bit(gpio, ODR, pin, 1); | ||
485 | + gpio_set_irq(gpio, pin, 0); | ||
486 | + g_assert_cmphex(get_disconnected_pins(gpio2), ==, 0xFFFF & ~(1 << pin)); | ||
487 | + g_assert_cmphex(gpio_readl(gpio2, IDR), ==, | ||
488 | + reset(gpio2, IDR) & ~(1 << pin)); | ||
489 | + | ||
490 | + /* Clean the test */ | ||
491 | + disconnect_all_pins(gpio2); | ||
492 | + gpio_writel(gpio2, OTYPER, reset(gpio2, OTYPER)); | ||
493 | + gpio_writel(gpio2, ODR, reset(gpio2, ODR)); | ||
494 | + gpio_writel(gpio2, MODER, reset(gpio2, MODER)); | ||
495 | + g_assert_cmphex(gpio_readl(gpio2, IDR), ==, reset(gpio2, IDR)); | ||
496 | + disconnect_all_pins(gpio); | ||
497 | + gpio_writel(gpio, OTYPER, reset(gpio, OTYPER)); | ||
498 | + gpio_writel(gpio, ODR, reset(gpio, ODR)); | ||
499 | + gpio_writel(gpio, MODER, reset(gpio, MODER)); | ||
500 | + g_assert_cmphex(gpio_readl(gpio, IDR), ==, reset(gpio, IDR)); | ||
501 | +} | ||
502 | + | ||
503 | +static void test_bsrr_brr(const void *data) | ||
504 | +{ | ||
505 | + /* | ||
506 | + * Test that writing a '1' in BSS and BSRR | ||
507 | + * has the desired effect on ODR. | ||
508 | + * In BSRR, BSx has priority over BRx. | ||
509 | + */ | ||
510 | + unsigned int pin = ((uint64_t)data) & 0xF; | ||
511 | + uint32_t gpio = ((uint64_t)data) >> 32; | ||
512 | + | ||
513 | + gpio_writel(gpio, BSRR, (1 << pin)); | ||
514 | + g_assert_cmphex(gpio_readl(gpio, ODR), ==, reset(gpio, ODR) | (1 << pin)); | ||
515 | + | ||
516 | + gpio_writel(gpio, BSRR, (1 << (pin + NUM_GPIO_PINS))); | ||
517 | + g_assert_cmphex(gpio_readl(gpio, ODR), ==, reset(gpio, ODR)); | ||
518 | + | ||
519 | + gpio_writel(gpio, BSRR, (1 << pin)); | ||
520 | + g_assert_cmphex(gpio_readl(gpio, ODR), ==, reset(gpio, ODR) | (1 << pin)); | ||
521 | + | ||
522 | + gpio_writel(gpio, BRR, (1 << pin)); | ||
523 | + g_assert_cmphex(gpio_readl(gpio, ODR), ==, reset(gpio, ODR)); | ||
524 | + | ||
525 | + /* BSx should have priority over BRx */ | ||
526 | + gpio_writel(gpio, BSRR, (1 << pin) | (1 << (pin + NUM_GPIO_PINS))); | ||
527 | + g_assert_cmphex(gpio_readl(gpio, ODR), ==, reset(gpio, ODR) | (1 << pin)); | ||
528 | + | ||
529 | + gpio_writel(gpio, BRR, (1 << pin)); | ||
530 | + g_assert_cmphex(gpio_readl(gpio, ODR), ==, reset(gpio, ODR)); | ||
531 | + | ||
532 | + gpio_writel(gpio, ODR, reset(gpio, ODR)); | ||
533 | +} | 321 | +} |
534 | + | 322 | + |
535 | +int main(int argc, char **argv) | 323 | +int main(int argc, char **argv) |
536 | +{ | 324 | +{ |
537 | + int ret; | 325 | + int ret; |
538 | + | 326 | + |
539 | + g_test_init(&argc, &argv, NULL); | 327 | + g_test_init(&argc, &argv, NULL); |
540 | + g_test_set_nonfatal_assertions(); | 328 | + g_test_set_nonfatal_assertions(); |
541 | + qtest_add_func("stm32l4x5/gpio/test_idr_reset_value", | 329 | + |
542 | + test_idr_reset_value); | 330 | + qtest_add_func("stm32l4x5/usart/write_read", test_write_read); |
543 | + /* | 331 | + qtest_add_func("stm32l4x5/usart/receive_char", test_receive_char); |
544 | + * The inputs for the tests (gpio and pin) can be changed, | 332 | + qtest_add_func("stm32l4x5/usart/send_char", test_send_char); |
545 | + * but the tests don't work for pins that are high at reset | 333 | + qtest_add_func("stm32l4x5/usart/receive_str", test_receive_str); |
546 | + * (GPIOA15, GPIO13 and GPIOB5). | 334 | + qtest_add_func("stm32l4x5/usart/send_str", test_send_str); |
547 | + * Specifically, rising the pin then checking `get_irq()` | ||
548 | + * is problematic since the pin was already high. | ||
549 | + */ | ||
550 | + qtest_add_data_func("stm32l4x5/gpio/test_gpioc5_output_mode", | ||
551 | + (void *)((uint64_t)GPIO_C << 32 | 5), | ||
552 | + test_gpio_output_mode); | ||
553 | + qtest_add_data_func("stm32l4x5/gpio/test_gpioh3_output_mode", | ||
554 | + (void *)((uint64_t)GPIO_H << 32 | 3), | ||
555 | + test_gpio_output_mode); | ||
556 | + qtest_add_data_func("stm32l4x5/gpio/test_gpio_input_mode1", | ||
557 | + (void *)((uint64_t)GPIO_D << 32 | 6), | ||
558 | + test_gpio_input_mode); | ||
559 | + qtest_add_data_func("stm32l4x5/gpio/test_gpio_input_mode2", | ||
560 | + (void *)((uint64_t)GPIO_C << 32 | 10), | ||
561 | + test_gpio_input_mode); | ||
562 | + qtest_add_data_func("stm32l4x5/gpio/test_gpio_pull_up_pull_down1", | ||
563 | + (void *)((uint64_t)GPIO_B << 32 | 5), | ||
564 | + test_pull_up_pull_down); | ||
565 | + qtest_add_data_func("stm32l4x5/gpio/test_gpio_pull_up_pull_down2", | ||
566 | + (void *)((uint64_t)GPIO_F << 32 | 1), | ||
567 | + test_pull_up_pull_down); | ||
568 | + qtest_add_data_func("stm32l4x5/gpio/test_gpio_push_pull1", | ||
569 | + (void *)((uint64_t)GPIO_G << 32 | 6), | ||
570 | + test_push_pull); | ||
571 | + qtest_add_data_func("stm32l4x5/gpio/test_gpio_push_pull2", | ||
572 | + (void *)((uint64_t)GPIO_H << 32 | 3), | ||
573 | + test_push_pull); | ||
574 | + qtest_add_data_func("stm32l4x5/gpio/test_gpio_open_drain1", | ||
575 | + (void *)((uint64_t)GPIO_C << 32 | 4), | ||
576 | + test_open_drain); | ||
577 | + qtest_add_data_func("stm32l4x5/gpio/test_gpio_open_drain2", | ||
578 | + (void *)((uint64_t)GPIO_E << 32 | 11), | ||
579 | + test_open_drain); | ||
580 | + qtest_add_data_func("stm32l4x5/gpio/test_bsrr_brr1", | ||
581 | + (void *)((uint64_t)GPIO_A << 32 | 12), | ||
582 | + test_bsrr_brr); | ||
583 | + qtest_add_data_func("stm32l4x5/gpio/test_bsrr_brr2", | ||
584 | + (void *)((uint64_t)GPIO_D << 32 | 0), | ||
585 | + test_bsrr_brr); | ||
586 | + | ||
587 | + qtest_start("-machine b-l475e-iot01a"); | ||
588 | + ret = g_test_run(); | 335 | + ret = g_test_run(); |
589 | + qtest_end(); | ||
590 | + | 336 | + |
591 | + return ret; | 337 | + return ret; |
592 | +} | 338 | +} |
339 | + | ||
593 | diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build | 340 | diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build |
594 | index XXXXXXX..XXXXXXX 100644 | 341 | index XXXXXXX..XXXXXXX 100644 |
595 | --- a/tests/qtest/meson.build | 342 | --- a/tests/qtest/meson.build |
596 | +++ b/tests/qtest/meson.build | 343 | +++ b/tests/qtest/meson.build |
597 | @@ -XXX,XX +XXX,XX @@ qtests_aspeed = \ | 344 | @@ -XXX,XX +XXX,XX @@ slow_qtests = { |
598 | qtests_stm32l4x5 = \ | 345 | 'npcm7xx_pwm-test': 300, |
346 | 'npcm7xx_watchdog_timer-test': 120, | ||
347 | 'qom-test' : 900, | ||
348 | + 'stm32l4x5_usart-test' : 600, | ||
349 | 'test-hmp' : 240, | ||
350 | 'pxe-test': 610, | ||
351 | 'prom-env-test': 360, | ||
352 | @@ -XXX,XX +XXX,XX @@ qtests_stm32l4x5 = \ | ||
599 | ['stm32l4x5_exti-test', | 353 | ['stm32l4x5_exti-test', |
600 | 'stm32l4x5_syscfg-test', | 354 | 'stm32l4x5_syscfg-test', |
601 | - 'stm32l4x5_rcc-test'] | 355 | 'stm32l4x5_rcc-test', |
602 | + 'stm32l4x5_rcc-test', | 356 | - 'stm32l4x5_gpio-test'] |
603 | + 'stm32l4x5_gpio-test'] | 357 | + 'stm32l4x5_gpio-test', |
358 | + 'stm32l4x5_usart-test'] | ||
604 | 359 | ||
605 | qtests_arm = \ | 360 | qtests_arm = \ |
606 | (config_all_devices.has_key('CONFIG_MPS2') ? ['sse-timer-test'] : []) + \ | 361 | (config_all_devices.has_key('CONFIG_MPS2') ? ['sse-timer-test'] : []) + \ |
607 | -- | 362 | -- |
608 | 2.34.1 | 363 | 2.34.1 |
609 | 364 | ||
610 | 365 | diff view generated by jsdifflib |