1
arm queue; dunno if this will be the last before softfreeze
1
Hi; here's the first arm pullreq for 9.1.
2
or not, but anyway probably the last large one. New orangepi-pc
2
3
board model is the big item here.
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.
4
10
5
thanks
11
thanks
6
-- PMM
12
-- PMM
7
13
8
The following changes since commit 67d9ef7d541c3d21a25796c51c26da096a433565:
14
The following changes since commit 5da72194df36535d773c8bdc951529ecd5e31707:
9
15
10
Merge remote-tracking branch 'remotes/pmaydell/tags/pull-docs-20200312' into staging (2020-03-12 15:20:52 +0000)
16
Merge tag 'pull-tcg-20240424' of https://gitlab.com/rth7680/qemu into staging (2024-04-24 15:51:49 -0700)
11
17
12
are available in the Git repository at:
18
are available in the Git repository at:
13
19
14
https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20200312
20
https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20240425
15
21
16
for you to fetch changes up to aca53be34ac3e7cac5f39396a51a338860a5a837:
22
for you to fetch changes up to 214652da123e3821657a64691ee556281e9f6238:
17
23
18
target/arm: kvm: Inject events at the last stage of sync (2020-03-12 16:31:10 +0000)
24
tests/qtest: Add tests for the STM32L4x5 USART (2024-04-25 10:21:59 +0100)
19
25
20
----------------------------------------------------------------
26
----------------------------------------------------------------
21
target-arm queue:
27
target-arm queue:
22
* Fix various bugs that might result in an assert() due to
28
* Implement FEAT_NMI and NMI support in the GICv3
23
incorrect hflags for M-profile CPUs
29
* hw/dma: avoid apparent overflow in soc_dma_set_request
24
* Fix Aspeed SMC Controller user-mode select handling
30
* linux-user/flatload.c: Remove unused bFLT shared-library and ZFLAT code
25
* Report correct (with-tag) address in fault address register
31
* Add ResetType argument to Resettable hold and exit phase methods
26
when TBI is enabled
32
* Add RESET_TYPE_SNAPSHOT_LOAD ResetType
27
* cubieboard: make sure SOC object isn't leaked
33
* Implement STM32L4x5 USART
28
* fsl-imx25: Wire up eSDHC controllers
29
* fsl-imx25: Wire up USB controllers
30
* New board model: orangepi-pc (OrangePi PC)
31
* ARM/KVM: if user doesn't select GIC version and the
32
host kernel can only provide GICv3, use that, rather
33
than defaulting to "fail because GICv2 isn't possible"
34
* kvm: Only do KVM_SET_VCPU_EVENTS at the last stage of sync
35
34
36
----------------------------------------------------------------
35
----------------------------------------------------------------
37
Beata Michalska (1):
36
Anastasia Belova (1):
38
target/arm: kvm: Inject events at the last stage of sync
37
hw/dma: avoid apparent overflow in soc_dma_set_request
39
38
40
Cédric Le Goater (2):
39
Arnaud Minier (5):
41
aspeed/smc: Add some tracing
40
hw/char: Implement STM32L4x5 USART skeleton
42
aspeed/smc: Fix User mode select/unselect scheme
41
hw/char/stm32l4x5_usart: Enable serial read and write
43
42
hw/char/stm32l4x5_usart: Add options for serial parameters setting
44
Eric Auger (6):
43
hw/arm: Add the USART to the stm32l4x5 SoC
45
hw/arm/virt: Document 'max' value in gic-version property description
44
tests/qtest: Add tests for the STM32L4x5 USART
46
hw/arm/virt: Introduce VirtGICType enum type
45
47
hw/arm/virt: Introduce finalize_gic_version()
46
Jinjie Ruan (22):
48
target/arm/kvm: Let kvm_arm_vgic_probe() return a bitmap
47
target/arm: Handle HCR_EL2 accesses for bits introduced with FEAT_NMI
49
hw/arm/virt: kvm: Restructure finalize_gic_version()
48
target/arm: Add PSTATE.ALLINT
50
hw/arm/virt: kvm: allow gicv3 by default if v2 cannot work
49
target/arm: Add support for FEAT_NMI, Non-maskable Interrupt
51
50
target/arm: Implement ALLINT MSR (immediate)
52
Guenter Roeck (2):
51
target/arm: Support MSR access to ALLINT
53
hw/arm/fsl-imx25: Wire up eSDHC controllers
52
target/arm: Add support for Non-maskable Interrupt
54
hw/arm/fsl-imx25: Wire up USB controllers
53
target/arm: Add support for NMI in arm_phys_excp_target_el()
55
54
target/arm: Handle IS/FS in ISR_EL1 for NMI, VINMI and VFNMI
56
Igor Mammedov (1):
55
target/arm: Handle PSTATE.ALLINT on taking an exception
57
hw/arm/cubieboard: make sure SOC object isn't leaked
56
hw/intc/arm_gicv3: Add external IRQ lines for NMI
58
57
hw/arm/virt: Wire NMI and VINMI irq lines from GIC to CPU
59
Niek Linnenbank (13):
58
target/arm: Handle NMI in arm_cpu_do_interrupt_aarch64()
60
hw/arm: add Allwinner H3 System-on-Chip
59
hw/intc/arm_gicv3: Add has-nmi property to GICv3 device
61
hw/arm: add Xunlong Orange Pi PC machine
60
hw/intc/arm_gicv3_kvm: Not set has-nmi=true for the KVM GICv3
62
hw/arm/allwinner-h3: add Clock Control Unit
61
hw/intc/arm_gicv3: Add irq non-maskable property
63
hw/arm/allwinner-h3: add USB host controller
62
hw/intc/arm_gicv3_redist: Implement GICR_INMIR0
64
hw/arm/allwinner-h3: add System Control module
63
hw/intc/arm_gicv3: Implement GICD_INMIR
65
hw/arm/allwinner: add CPU Configuration module
64
hw/intc/arm_gicv3: Implement NMI interrupt priority
66
hw/arm/allwinner: add Security Identifier device
65
hw/intc/arm_gicv3: Report the NMI interrupt in gicv3_cpuif_update()
67
hw/arm/allwinner: add SD/MMC host controller
66
hw/intc/arm_gicv3: Report the VINMI interrupt
68
hw/arm/allwinner-h3: add EMAC ethernet device
67
target/arm: Add FEAT_NMI to max
69
hw/arm/allwinner-h3: add Boot ROM support
68
hw/arm/virt: Enable NMI support in the GIC if the CPU has FEAT_NMI
70
hw/arm/allwinner-h3: add SDRAM controller device
69
71
hw/arm/allwinner: add RTC device support
70
Peter Maydell (9):
72
docs: add Orange Pi PC document
71
hw/intc/arm_gicv3: Add NMI handling CPU interface registers
73
72
hw/intc/arm_gicv3: Handle icv_nmiar1_read() for icc_nmiar1_read()
74
Peter Maydell (4):
73
linux-user/flatload.c: Remove unused bFLT shared-library and ZFLAT code
75
hw/intc/armv7m_nvic: Rebuild hflags on reset
74
hw/misc: Don't special case RESET_TYPE_COLD in npcm7xx_clk, gcr
76
target/arm: Update hflags in trans_CPS_v7m()
75
allwinner-i2c, adm1272: Use device_cold_reset() for software-triggered reset
77
target/arm: Recalculate hflags correctly after writes to CONTROL
76
scripts/coccinelle: New script to add ResetType to hold and exit phases
78
target/arm: Fix some comment typos
77
hw, target: Add ResetType argument to hold and exit phase methods
79
78
docs/devel/reset: Update to new API for hold and exit phase methods
80
Philippe Mathieu-Daudé (5):
79
reset: Add RESET_TYPE_SNAPSHOT_LOAD
81
tests/boot_linux_console: Add a quick test for the OrangePi PC board
80
82
tests/boot_linux_console: Add initrd test for the Orange Pi PC board
81
MAINTAINERS | 1 +
83
tests/boot_linux_console: Add a SD card test for the OrangePi PC board
82
docs/devel/reset.rst | 25 +-
84
tests/boot_linux_console: Add a SLOW test booting Ubuntu on OrangePi PC
83
docs/system/arm/b-l475e-iot01a.rst | 2 +-
85
tests/boot_linux_console: Test booting NetBSD via U-Boot on OrangePi PC
84
docs/system/arm/emulation.rst | 1 +
86
85
scripts/coccinelle/reset-type.cocci | 133 ++++++++
87
Richard Henderson (2):
86
hw/intc/gicv3_internal.h | 13 +
88
target/arm: Check addresses for disabled regimes
87
include/hw/arm/stm32l4x5_soc.h | 7 +
89
target/arm: Disable clean_data_tbi for system mode
88
include/hw/char/stm32l4x5_usart.h | 67 ++++
90
89
include/hw/intc/arm_gic_common.h | 2 +
91
Makefile.objs | 1 +
90
include/hw/intc/arm_gicv3_common.h | 14 +
92
hw/arm/Makefile.objs | 1 +
91
include/hw/resettable.h | 5 +-
93
hw/misc/Makefile.objs | 5 +
92
linux-user/flat.h | 5 +-
94
hw/net/Makefile.objs | 1 +
93
target/arm/cpu-features.h | 5 +
95
hw/rtc/Makefile.objs | 1 +
94
target/arm/cpu-qom.h | 5 +-
96
hw/sd/Makefile.objs | 1 +
95
target/arm/cpu.h | 9 +
97
hw/usb/hcd-ehci.h | 1 +
96
target/arm/internals.h | 21 ++
98
include/hw/arm/allwinner-a10.h | 4 +
97
target/arm/tcg/helper-a64.h | 1 +
99
include/hw/arm/allwinner-h3.h | 161 ++++++
98
target/arm/tcg/a64.decode | 1 +
100
include/hw/arm/fsl-imx25.h | 18 +
99
hw/adc/npcm7xx_adc.c | 2 +-
101
include/hw/arm/virt.h | 12 +-
100
hw/arm/pxa2xx_pic.c | 2 +-
102
include/hw/misc/allwinner-cpucfg.h | 52 ++
101
hw/arm/smmu-common.c | 2 +-
103
include/hw/misc/allwinner-h3-ccu.h | 66 +++
102
hw/arm/smmuv3.c | 4 +-
104
include/hw/misc/allwinner-h3-dramc.h | 106 ++++
103
hw/arm/stellaris.c | 10 +-
105
include/hw/misc/allwinner-h3-sysctrl.h | 67 +++
104
hw/arm/stm32l4x5_soc.c | 83 ++++-
106
include/hw/misc/allwinner-sid.h | 60 +++
105
hw/arm/virt.c | 29 +-
107
include/hw/net/allwinner-sun8i-emac.h | 99 ++++
106
hw/audio/asc.c | 2 +-
108
include/hw/rtc/allwinner-rtc.h | 134 +++++
107
hw/char/cadence_uart.c | 2 +-
109
include/hw/sd/allwinner-sdhost.h | 135 +++++
108
hw/char/sifive_uart.c | 2 +-
110
target/arm/helper.h | 1 +
109
hw/char/stm32l4x5_usart.c | 637 ++++++++++++++++++++++++++++++++++++
111
target/arm/kvm_arm.h | 3 +
110
hw/core/cpu-common.c | 2 +-
112
hw/arm/allwinner-a10.c | 19 +
111
hw/core/qdev.c | 4 +-
113
hw/arm/allwinner-h3.c | 465 ++++++++++++++++++
112
hw/core/reset.c | 17 +-
114
hw/arm/cubieboard.c | 18 +
113
hw/core/resettable.c | 8 +-
115
hw/arm/fsl-imx25.c | 56 +++
114
hw/display/virtio-vga.c | 4 +-
116
hw/arm/imx25_pdk.c | 16 +
115
hw/dma/soc_dma.c | 4 +-
117
hw/arm/orangepi.c | 130 +++++
116
hw/gpio/npcm7xx_gpio.c | 2 +-
118
hw/arm/virt.c | 145 ++++--
117
hw/gpio/pl061.c | 2 +-
119
hw/intc/armv7m_nvic.c | 6 +
118
hw/gpio/stm32l4x5_gpio.c | 2 +-
120
hw/misc/allwinner-cpucfg.c | 282 +++++++++++
119
hw/hyperv/vmbus.c | 2 +-
121
hw/misc/allwinner-h3-ccu.c | 242 +++++++++
120
hw/i2c/allwinner-i2c.c | 5 +-
122
hw/misc/allwinner-h3-dramc.c | 358 ++++++++++++++
121
hw/i2c/npcm7xx_smbus.c | 2 +-
123
hw/misc/allwinner-h3-sysctrl.c | 140 ++++++
122
hw/input/adb.c | 2 +-
124
hw/misc/allwinner-sid.c | 168 +++++++
123
hw/input/ps2.c | 12 +-
125
hw/net/allwinner-sun8i-emac.c | 871 +++++++++++++++++++++++++++++++++
124
hw/intc/arm_gic_common.c | 2 +-
126
hw/rtc/allwinner-rtc.c | 411 ++++++++++++++++
125
hw/intc/arm_gic_kvm.c | 4 +-
127
hw/sd/allwinner-sdhost.c | 854 ++++++++++++++++++++++++++++++++
126
hw/intc/arm_gicv3.c | 67 +++-
128
hw/ssi/aspeed_smc.c | 56 ++-
127
hw/intc/arm_gicv3_common.c | 50 ++-
129
hw/usb/hcd-ehci-sysbus.c | 17 +
128
hw/intc/arm_gicv3_cpuif.c | 268 ++++++++++++++-
130
target/arm/helper.c | 49 +-
129
hw/intc/arm_gicv3_dist.c | 36 ++
131
target/arm/kvm.c | 14 +-
130
hw/intc/arm_gicv3_its.c | 4 +-
132
target/arm/kvm32.c | 15 +-
131
hw/intc/arm_gicv3_its_common.c | 2 +-
133
target/arm/kvm64.c | 15 +-
132
hw/intc/arm_gicv3_its_kvm.c | 4 +-
134
target/arm/translate-a64.c | 11 +
133
hw/intc/arm_gicv3_kvm.c | 9 +-
135
target/arm/translate.c | 14 +-
134
hw/intc/arm_gicv3_redist.c | 22 ++
136
MAINTAINERS | 9 +
135
hw/intc/xics.c | 2 +-
137
default-configs/arm-softmmu.mak | 1 +
136
hw/m68k/q800-glue.c | 2 +-
138
docs/system/arm/orangepi.rst | 253 ++++++++++
137
hw/misc/djmemc.c | 2 +-
139
docs/system/target-arm.rst | 2 +
138
hw/misc/iosb.c | 2 +-
140
hw/arm/Kconfig | 12 +
139
hw/misc/mac_via.c | 8 +-
141
hw/misc/trace-events | 19 +
140
hw/misc/macio/cuda.c | 4 +-
142
hw/net/Kconfig | 3 +
141
hw/misc/macio/pmu.c | 4 +-
143
hw/net/trace-events | 10 +
142
hw/misc/mos6522.c | 2 +-
144
hw/rtc/trace-events | 4 +
143
hw/misc/npcm7xx_clk.c | 13 +-
145
hw/sd/trace-events | 7 +
144
hw/misc/npcm7xx_gcr.c | 12 +-
146
hw/ssi/trace-events | 10 +
145
hw/misc/npcm7xx_mft.c | 2 +-
147
tests/acceptance/boot_linux_console.py | 230 +++++++++
146
hw/misc/npcm7xx_pwm.c | 2 +-
148
57 files changed, 5787 insertions(+), 74 deletions(-)
147
hw/misc/stm32l4x5_exti.c | 2 +-
149
create mode 100644 include/hw/arm/allwinner-h3.h
148
hw/misc/stm32l4x5_rcc.c | 10 +-
150
create mode 100644 include/hw/misc/allwinner-cpucfg.h
149
hw/misc/stm32l4x5_syscfg.c | 2 +-
151
create mode 100644 include/hw/misc/allwinner-h3-ccu.h
150
hw/misc/xlnx-versal-cframe-reg.c | 2 +-
152
create mode 100644 include/hw/misc/allwinner-h3-dramc.h
151
hw/misc/xlnx-versal-crl.c | 2 +-
153
create mode 100644 include/hw/misc/allwinner-h3-sysctrl.h
152
hw/misc/xlnx-versal-pmc-iou-slcr.c | 2 +-
154
create mode 100644 include/hw/misc/allwinner-sid.h
153
hw/misc/xlnx-versal-trng.c | 2 +-
155
create mode 100644 include/hw/net/allwinner-sun8i-emac.h
154
hw/misc/xlnx-versal-xramc.c | 2 +-
156
create mode 100644 include/hw/rtc/allwinner-rtc.h
155
hw/misc/xlnx-zynqmp-apu-ctrl.c | 2 +-
157
create mode 100644 include/hw/sd/allwinner-sdhost.h
156
hw/misc/xlnx-zynqmp-crf.c | 2 +-
158
create mode 100644 hw/arm/allwinner-h3.c
157
hw/misc/zynq_slcr.c | 4 +-
159
create mode 100644 hw/arm/orangepi.c
158
hw/net/can/xlnx-zynqmp-can.c | 2 +-
160
create mode 100644 hw/misc/allwinner-cpucfg.c
159
hw/net/e1000.c | 2 +-
161
create mode 100644 hw/misc/allwinner-h3-ccu.c
160
hw/net/e1000e.c | 2 +-
162
create mode 100644 hw/misc/allwinner-h3-dramc.c
161
hw/net/igb.c | 2 +-
163
create mode 100644 hw/misc/allwinner-h3-sysctrl.c
162
hw/net/igbvf.c | 2 +-
164
create mode 100644 hw/misc/allwinner-sid.c
163
hw/nvram/xlnx-bbram.c | 2 +-
165
create mode 100644 hw/net/allwinner-sun8i-emac.c
164
hw/nvram/xlnx-versal-efuse-ctrl.c | 2 +-
166
create mode 100644 hw/rtc/allwinner-rtc.c
165
hw/nvram/xlnx-zynqmp-efuse.c | 2 +-
167
create mode 100644 hw/sd/allwinner-sdhost.c
166
hw/pci-bridge/cxl_root_port.c | 4 +-
168
create mode 100644 docs/system/arm/orangepi.rst
167
hw/pci-bridge/pcie_root_port.c | 2 +-
169
create mode 100644 hw/ssi/trace-events
168
hw/pci-host/bonito.c | 2 +-
170
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
From: Beata Michalska <beata.michalska@linaro.org>
1
From: Jinjie Ruan <ruanjinjie@huawei.com>
2
2
3
KVM_SET_VCPU_EVENTS might actually lead to vcpu registers being modified.
3
FEAT_NMI defines another three new bits in HCRX_EL2: TALLINT, HCRX_VINMI and
4
As such this should be the last step of sync to avoid potential overwriting
4
HCRX_VFNMI. When the feature is enabled, allow these bits to be written in
5
of whatever changes KVM might have done.
5
HCRX_EL2.
6
6
7
Signed-off-by: Beata Michalska <beata.michalska@linaro.org>
7
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
8
Reviewed-by: Andrew Jones <drjones@redhat.com>
8
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
9
Message-id: 20200312003401.29017-2-beata.michalska@linaro.org
9
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
10
Message-id: 20240407081733.3231820-2-ruanjinjie@huawei.com
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
---
12
---
12
target/arm/kvm32.c | 15 ++++++++++-----
13
target/arm/cpu-features.h | 5 +++++
13
target/arm/kvm64.c | 15 ++++++++++-----
14
target/arm/helper.c | 8 +++++++-
14
2 files changed, 20 insertions(+), 10 deletions(-)
15
2 files changed, 12 insertions(+), 1 deletion(-)
15
16
16
diff --git a/target/arm/kvm32.c b/target/arm/kvm32.c
17
diff --git a/target/arm/cpu-features.h b/target/arm/cpu-features.h
17
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
18
--- a/target/arm/kvm32.c
19
--- a/target/arm/cpu-features.h
19
+++ b/target/arm/kvm32.c
20
+++ b/target/arm/cpu-features.h
20
@@ -XXX,XX +XXX,XX @@ int kvm_arch_put_registers(CPUState *cs, int level)
21
@@ -XXX,XX +XXX,XX @@ static inline bool isar_feature_aa64_sme(const ARMISARegisters *id)
21
return ret;
22
return FIELD_EX64(id->id_aa64pfr1, ID_AA64PFR1, SME) != 0;
23
}
24
25
+static inline bool isar_feature_aa64_nmi(const ARMISARegisters *id)
26
+{
27
+ return FIELD_EX64(id->id_aa64pfr1, ID_AA64PFR1, NMI) != 0;
28
+}
29
+
30
static inline bool isar_feature_aa64_tgran4_lpa2(const ARMISARegisters *id)
31
{
32
return FIELD_SEX64(id->id_aa64mmfr0, ID_AA64MMFR0, TGRAN4) >= 1;
33
diff --git a/target/arm/helper.c b/target/arm/helper.c
34
index XXXXXXX..XXXXXXX 100644
35
--- a/target/arm/helper.c
36
+++ b/target/arm/helper.c
37
@@ -XXX,XX +XXX,XX @@ bool el_is_in_host(CPUARMState *env, int el)
38
static void hcrx_write(CPUARMState *env, const ARMCPRegInfo *ri,
39
uint64_t value)
40
{
41
+ ARMCPU *cpu = env_archcpu(env);
42
uint64_t valid_mask = 0;
43
44
/* FEAT_MOPS adds MSCEn and MCE2 */
45
- if (cpu_isar_feature(aa64_mops, env_archcpu(env))) {
46
+ if (cpu_isar_feature(aa64_mops, cpu)) {
47
valid_mask |= HCRX_MSCEN | HCRX_MCE2;
22
}
48
}
23
49
24
- ret = kvm_put_vcpu_events(cpu);
50
+ /* FEAT_NMI adds TALLINT, VINMI and VFNMI */
25
- if (ret) {
51
+ if (cpu_isar_feature(aa64_nmi, cpu)) {
26
- return ret;
52
+ valid_mask |= HCRX_TALLINT | HCRX_VINMI | HCRX_VFNMI;
27
- }
28
-
29
write_cpustate_to_list(cpu, true);
30
31
if (!write_list_to_kvmstate(cpu, level)) {
32
return EINVAL;
33
}
34
35
+ /*
36
+ * Setting VCPU events should be triggered after syncing the registers
37
+ * to avoid overwriting potential changes made by KVM upon calling
38
+ * KVM_SET_VCPU_EVENTS ioctl
39
+ */
40
+ ret = kvm_put_vcpu_events(cpu);
41
+ if (ret) {
42
+ return ret;
43
+ }
53
+ }
44
+
54
+
45
kvm_arm_sync_mpstate_to_kvm(cpu);
55
/* Clear RES0 bits. */
46
56
env->cp15.hcrx_el2 = value & valid_mask;
47
return ret;
57
}
48
diff --git a/target/arm/kvm64.c b/target/arm/kvm64.c
49
index XXXXXXX..XXXXXXX 100644
50
--- a/target/arm/kvm64.c
51
+++ b/target/arm/kvm64.c
52
@@ -XXX,XX +XXX,XX @@ int kvm_arch_put_registers(CPUState *cs, int level)
53
return ret;
54
}
55
56
- ret = kvm_put_vcpu_events(cpu);
57
- if (ret) {
58
- return ret;
59
- }
60
-
61
write_cpustate_to_list(cpu, true);
62
63
if (!write_list_to_kvmstate(cpu, level)) {
64
return -EINVAL;
65
}
66
67
+ /*
68
+ * Setting VCPU events should be triggered after syncing the registers
69
+ * to avoid overwriting potential changes made by KVM upon calling
70
+ * KVM_SET_VCPU_EVENTS ioctl
71
+ */
72
+ ret = kvm_put_vcpu_events(cpu);
73
+ if (ret) {
74
+ return ret;
75
+ }
76
+
77
kvm_arm_sync_mpstate_to_kvm(cpu);
78
79
return ret;
80
--
58
--
81
2.20.1
59
2.34.1
82
83
diff view generated by jsdifflib
1
From: Niek Linnenbank <nieklinnenbank@gmail.com>
1
From: Jinjie Ruan <ruanjinjie@huawei.com>
2
2
3
The Xunlong Orange Pi PC machine is a functional ARM machine
3
When PSTATE.ALLINT is set, an IRQ or FIQ interrupt that is targeted to
4
based on the Allwinner H3 System-on-Chip. It supports mainline
4
ELx, with or without superpriority is masked. As Richard suggested, place
5
Linux, U-Boot, NetBSD and is covered by acceptance tests.
5
ALLINT bit in PSTATE in env->pstate.
6
6
7
This commit adds a documentation text file with a description
7
In the pseudocode, AArch64.ExceptionReturn() calls SetPSTATEFromPSR(), which
8
of the machine and instructions for the user.
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.
9
13
10
Signed-off-by: Niek Linnenbank <nieklinnenbank@gmail.com>
14
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
11
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
15
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
12
Message-id: 20200311221854.30370-19-nieklinnenbank@gmail.com
16
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
13
[PMM: moved file into docs/system/arm to match the reorg
17
Message-id: 20240407081733.3231820-3-ruanjinjie@huawei.com
14
of the arm target part of the docs; tweaked heading to
15
match other boards]
16
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
18
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
17
---
19
---
18
MAINTAINERS | 1 +
20
target/arm/cpu.h | 1 +
19
docs/system/arm/orangepi.rst | 253 +++++++++++++++++++++++++++++++++++
21
target/arm/tcg/helper-a64.c | 4 ++--
20
docs/system/target-arm.rst | 2 +
22
2 files changed, 3 insertions(+), 2 deletions(-)
21
3 files changed, 256 insertions(+)
22
create mode 100644 docs/system/arm/orangepi.rst
23
23
24
diff --git a/MAINTAINERS b/MAINTAINERS
24
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
25
index XXXXXXX..XXXXXXX 100644
25
index XXXXXXX..XXXXXXX 100644
26
--- a/MAINTAINERS
26
--- a/target/arm/cpu.h
27
+++ b/MAINTAINERS
27
+++ b/target/arm/cpu.h
28
@@ -XXX,XX +XXX,XX @@ S: Maintained
28
@@ -XXX,XX +XXX,XX @@ void pmu_init(ARMCPU *cpu);
29
F: hw/*/allwinner-h3*
29
#define PSTATE_D (1U << 9)
30
F: include/hw/*/allwinner-h3*
30
#define PSTATE_BTYPE (3U << 10)
31
F: hw/arm/orangepi.c
31
#define PSTATE_SSBS (1U << 12)
32
+F: docs/system/orangepi.rst
32
+#define PSTATE_ALLINT (1U << 13)
33
33
#define PSTATE_IL (1U << 20)
34
ARM PrimeCell and CMSDK devices
34
#define PSTATE_SS (1U << 21)
35
M: Peter Maydell <peter.maydell@linaro.org>
35
#define PSTATE_PAN (1U << 22)
36
diff --git a/docs/system/arm/orangepi.rst b/docs/system/arm/orangepi.rst
36
diff --git a/target/arm/tcg/helper-a64.c b/target/arm/tcg/helper-a64.c
37
new file mode 100644
38
index XXXXXXX..XXXXXXX
39
--- /dev/null
40
+++ b/docs/system/arm/orangepi.rst
41
@@ -XXX,XX +XXX,XX @@
42
+Orange Pi PC (``orangepi-pc``)
43
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
44
+
45
+The Xunlong Orange Pi PC is an Allwinner H3 System on Chip
46
+based embedded computer with mainline support in both U-Boot
47
+and Linux. The board comes with a Quad Core Cortex-A7 @ 1.3GHz,
48
+1GiB RAM, 100Mbit ethernet, USB, SD/MMC, USB, HDMI and
49
+various other I/O.
50
+
51
+Supported devices
52
+"""""""""""""""""
53
+
54
+The Orange Pi PC machine supports the following devices:
55
+
56
+ * SMP (Quad Core Cortex-A7)
57
+ * Generic Interrupt Controller configuration
58
+ * SRAM mappings
59
+ * SDRAM controller
60
+ * Real Time Clock
61
+ * Timer device (re-used from Allwinner A10)
62
+ * UART
63
+ * SD/MMC storage controller
64
+ * EMAC ethernet
65
+ * USB 2.0 interfaces
66
+ * Clock Control Unit
67
+ * System Control module
68
+ * Security Identifier device
69
+
70
+Limitations
71
+"""""""""""
72
+
73
+Currently, Orange Pi PC does *not* support the following features:
74
+
75
+- Graphical output via HDMI, GPU and/or the Display Engine
76
+- Audio output
77
+- Hardware Watchdog
78
+
79
+Also see the 'unimplemented' array in the Allwinner H3 SoC module
80
+for a complete list of unimplemented I/O devices: ``./hw/arm/allwinner-h3.c``
81
+
82
+Boot options
83
+""""""""""""
84
+
85
+The Orange Pi PC machine can start using the standard -kernel functionality
86
+for loading a Linux kernel or ELF executable. Additionally, the Orange Pi PC
87
+machine can also emulate the BootROM which is present on an actual Allwinner H3
88
+based SoC, which loads the bootloader from a SD card, specified via the -sd argument
89
+to qemu-system-arm.
90
+
91
+Machine-specific options
92
+""""""""""""""""""""""""
93
+
94
+The following machine-specific options are supported:
95
+
96
+- allwinner-rtc.base-year=YYYY
97
+
98
+ The Allwinner RTC device is automatically created by the Orange Pi PC machine
99
+ and uses a default base year value which can be overridden using the 'base-year' property.
100
+ The base year is the actual represented year when the RTC year value is zero.
101
+ This option can be used in case the target operating system driver uses a different
102
+ base year value. The minimum value for the base year is 1900.
103
+
104
+- allwinner-sid.identifier=abcd1122-a000-b000-c000-12345678ffff
105
+
106
+ The Security Identifier value can be read by the guest.
107
+ For example, U-Boot uses it to determine a unique MAC address.
108
+
109
+The above machine-specific options can be specified in qemu-system-arm
110
+via the '-global' argument, for example:
111
+
112
+.. code-block:: bash
113
+
114
+ $ qemu-system-arm -M orangepi-pc -sd mycard.img \
115
+ -global allwinner-rtc.base-year=2000
116
+
117
+Running mainline Linux
118
+""""""""""""""""""""""
119
+
120
+Mainline Linux kernels from 4.19 up to latest master are known to work.
121
+To build a Linux mainline kernel that can be booted by the Orange Pi PC machine,
122
+simply configure the kernel using the sunxi_defconfig configuration:
123
+
124
+.. code-block:: bash
125
+
126
+ $ ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- make mrproper
127
+ $ ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- make sunxi_defconfig
128
+
129
+To be able to use USB storage, you need to manually enable the corresponding
130
+configuration item. Start the kconfig configuration tool:
131
+
132
+.. code-block:: bash
133
+
134
+ $ ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- make menuconfig
135
+
136
+Navigate to the following item, enable it and save your configuration:
137
+
138
+ Device Drivers > USB support > USB Mass Storage support
139
+
140
+Build the Linux kernel with:
141
+
142
+.. code-block:: bash
143
+
144
+ $ ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- make
145
+
146
+To boot the newly build linux kernel in QEMU with the Orange Pi PC machine, use:
147
+
148
+.. code-block:: bash
149
+
150
+ $ qemu-system-arm -M orangepi-pc -nic user -nographic \
151
+ -kernel /path/to/linux/arch/arm/boot/zImage \
152
+ -append 'console=ttyS0,115200' \
153
+ -dtb /path/to/linux/arch/arm/boot/dts/sun8i-h3-orangepi-pc.dtb
154
+
155
+Orange Pi PC images
156
+"""""""""""""""""""
157
+
158
+Note that the mainline kernel does not have a root filesystem. You may provide it
159
+with an official Orange Pi PC image from the official website:
160
+
161
+ http://www.orangepi.org/downloadresources/
162
+
163
+Another possibility is to run an Armbian image for Orange Pi PC which
164
+can be downloaded from:
165
+
166
+ https://www.armbian.com/orange-pi-pc/
167
+
168
+Alternatively, you can also choose to build you own image with buildroot
169
+using the orangepi_pc_defconfig. Also see https://buildroot.org for more information.
170
+
171
+You can choose to attach the selected image either as an SD card or as USB mass storage.
172
+For example, to boot using the Orange Pi PC Debian image on SD card, simply add the -sd
173
+argument and provide the proper root= kernel parameter:
174
+
175
+.. code-block:: bash
176
+
177
+ $ qemu-system-arm -M orangepi-pc -nic user -nographic \
178
+ -kernel /path/to/linux/arch/arm/boot/zImage \
179
+ -append 'console=ttyS0,115200 root=/dev/mmcblk0p2' \
180
+ -dtb /path/to/linux/arch/arm/boot/dts/sun8i-h3-orangepi-pc.dtb \
181
+ -sd OrangePi_pc_debian_stretch_server_linux5.3.5_v1.0.img
182
+
183
+To attach the image as an USB mass storage device to the machine,
184
+simply append to the command:
185
+
186
+.. code-block:: bash
187
+
188
+ -drive if=none,id=stick,file=myimage.img \
189
+ -device usb-storage,bus=usb-bus.0,drive=stick
190
+
191
+Instead of providing a custom Linux kernel via the -kernel command you may also
192
+choose to let the Orange Pi PC machine load the bootloader from SD card, just like
193
+a real board would do using the BootROM. Simply pass the selected image via the -sd
194
+argument and remove the -kernel, -append, -dbt and -initrd arguments:
195
+
196
+.. code-block:: bash
197
+
198
+ $ qemu-system-arm -M orangepi-pc -nic user -nographic \
199
+ -sd Armbian_19.11.3_Orangepipc_buster_current_5.3.9.img
200
+
201
+Note that both the official Orange Pi PC images and Armbian images start
202
+a lot of userland programs via systemd. Depending on the host hardware and OS,
203
+they may be slow to emulate, especially due to emulating the 4 cores.
204
+To help reduce the performance slow down due to emulating the 4 cores, you can
205
+give the following kernel parameters via U-Boot (or via -append):
206
+
207
+.. code-block:: bash
208
+
209
+ => setenv extraargs 'systemd.default_timeout_start_sec=9000 loglevel=7 nosmp console=ttyS0,115200'
210
+
211
+Running U-Boot
212
+""""""""""""""
213
+
214
+U-Boot mainline can be build and configured using the orangepi_pc_defconfig
215
+using similar commands as describe above for Linux. Note that it is recommended
216
+for development/testing to select the following configuration setting in U-Boot:
217
+
218
+ Device Tree Control > Provider for DTB for DT Control > Embedded DTB
219
+
220
+To start U-Boot using the Orange Pi PC machine, provide the
221
+u-boot binary to the -kernel argument:
222
+
223
+.. code-block:: bash
224
+
225
+ $ qemu-system-arm -M orangepi-pc -nic user -nographic \
226
+ -kernel /path/to/uboot/u-boot -sd disk.img
227
+
228
+Use the following U-boot commands to load and boot a Linux kernel from SD card:
229
+
230
+.. code-block:: bash
231
+
232
+ => setenv bootargs console=ttyS0,115200
233
+ => ext2load mmc 0 0x42000000 zImage
234
+ => ext2load mmc 0 0x43000000 sun8i-h3-orangepi-pc.dtb
235
+ => bootz 0x42000000 - 0x43000000
236
+
237
+Running NetBSD
238
+""""""""""""""
239
+
240
+The NetBSD operating system also includes support for Allwinner H3 based boards,
241
+including the Orange Pi PC. NetBSD 9.0 is known to work best for the Orange Pi PC
242
+board and provides a fully working system with serial console, networking and storage.
243
+For the Orange Pi PC machine, get the 'evbarm-earmv7hf' based image from:
244
+
245
+ https://cdn.netbsd.org/pub/NetBSD/NetBSD-9.0/evbarm-earmv7hf/binary/gzimg/armv7.img.gz
246
+
247
+The image requires manually installing U-Boot in the image. Build U-Boot with
248
+the orangepi_pc_defconfig configuration as described in the previous section.
249
+Next, unzip the NetBSD image and write the U-Boot binary including SPL using:
250
+
251
+.. code-block:: bash
252
+
253
+ $ gunzip armv7.img.gz
254
+ $ dd if=/path/to/u-boot-sunxi-with-spl.bin of=armv7.img bs=1024 seek=8 conv=notrunc
255
+
256
+Finally, before starting the machine the SD image must be extended such
257
+that the NetBSD kernel will not conclude the NetBSD partition is larger than
258
+the emulated SD card:
259
+
260
+.. code-block:: bash
261
+
262
+ $ dd if=/dev/zero bs=1M count=64 >> armv7.img
263
+
264
+Start the machine using the following command:
265
+
266
+.. code-block:: bash
267
+
268
+ $ qemu-system-arm -M orangepi-pc -nic user -nographic \
269
+ -sd armv7.img -global allwinner-rtc.base-year=2000
270
+
271
+At the U-Boot stage, interrupt the automatic boot process by pressing a key
272
+and set the following environment variables before booting:
273
+
274
+.. code-block:: bash
275
+
276
+ => setenv bootargs root=ld0a
277
+ => setenv kernel netbsd-GENERIC.ub
278
+ => setenv fdtfile dtb/sun8i-h3-orangepi-pc.dtb
279
+ => setenv bootcmd 'fatload mmc 0:1 ${kernel_addr_r} ${kernel}; fatload mmc 0:1 ${fdt_addr_r} ${fdtfile}; fdt addr ${fdt_addr_r}; bootm ${kernel_addr_r} - ${fdt_addr_r}'
280
+
281
+Optionally you may save the environment variables to SD card with 'saveenv'.
282
+To continue booting simply give the 'boot' command and NetBSD boots.
283
+
284
+Orange Pi PC acceptance tests
285
+"""""""""""""""""""""""""""""
286
+
287
+The Orange Pi PC machine has several acceptance tests included.
288
+To run the whole set of tests, build QEMU from source and simply
289
+provide the following command:
290
+
291
+.. code-block:: bash
292
+
293
+ $ AVOCADO_ALLOW_LARGE_STORAGE=yes avocado --show=app,console run \
294
+ -t machine:orangepi-pc tests/acceptance/boot_linux_console.py
295
diff --git a/docs/system/target-arm.rst b/docs/system/target-arm.rst
296
index XXXXXXX..XXXXXXX 100644
37
index XXXXXXX..XXXXXXX 100644
297
--- a/docs/system/target-arm.rst
38
--- a/target/arm/tcg/helper-a64.c
298
+++ b/docs/system/target-arm.rst
39
+++ b/target/arm/tcg/helper-a64.c
299
@@ -XXX,XX +XXX,XX @@ undocumented; you can get a complete list by running
40
@@ -XXX,XX +XXX,XX @@ illegal_return:
300
``qemu-system-aarch64 --machine help``.
41
*/
301
42
env->pstate |= PSTATE_IL;
302
.. toctree::
43
env->pc = new_pc;
303
+ :maxdepth: 1
44
- spsr &= PSTATE_NZCV | PSTATE_DAIF;
304
45
- spsr |= pstate_read(env) & ~(PSTATE_NZCV | PSTATE_DAIF);
305
arm/integratorcp
46
+ spsr &= PSTATE_NZCV | PSTATE_DAIF | PSTATE_ALLINT;
306
arm/versatile
47
+ spsr |= pstate_read(env) & ~(PSTATE_NZCV | PSTATE_DAIF | PSTATE_ALLINT);
307
@@ -XXX,XX +XXX,XX @@ undocumented; you can get a complete list by running
48
pstate_write(env, spsr);
308
arm/stellaris
49
if (!arm_singlestep_active(env)) {
309
arm/musicpal
50
env->pstate &= ~PSTATE_SS;
310
arm/sx1
311
+ arm/orangepi
312
313
Arm CPU features
314
================
315
--
51
--
316
2.20.1
52
2.34.1
317
318
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
1
From: Jinjie Ruan <ruanjinjie@huawei.com>
2
2
3
This test boots U-Boot then NetBSD (stored on a SD card) on
3
Add support for FEAT_NMI. NMI (FEAT_NMI) is an mandatory feature in
4
a OrangePi PC board.
4
ARMv8.8-A and ARM v9.3-A.
5
5
6
As it requires ~1.3GB of storage, it is disabled by default.
6
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
7
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
U-Boot is built by the Debian project [1], and the SD card image
8
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
9
is provided by the NetBSD organization [2].
9
Message-id: 20240407081733.3231820-4-ruanjinjie@huawei.com
10
11
Once the compressed SD card image is downloaded (304MB) and
12
extracted, this test is fast:
13
14
$ AVOCADO_ALLOW_LARGE_STORAGE=yes \
15
avocado --show=app,console run -t machine:orangepi-pc \
16
tests/acceptance/boot_linux_console.py
17
console: U-Boot SPL 2020.01+dfsg-1 (Jan 08 2020 - 08:19:44 +0000)
18
console: DRAM: 1024 MiB
19
console: U-Boot 2020.01+dfsg-1 (Jan 08 2020 - 08:19:44 +0000) Allwinner Technology
20
console: CPU: Allwinner H3 (SUN8I 0000)
21
console: scanning bus usb@1c1b000 for devices... 1 USB Device(s) found
22
console: scanning bus usb@1c1d000 for devices... 1 USB Device(s) found
23
console: scanning usb for storage devices... 0 Storage Device(s) found
24
console: Hit any key to stop autoboot: 0
25
console: => setenv bootargs root=ld0a
26
console: => setenv kernel netbsd-GENERIC.ub
27
console: => setenv fdtfile dtb/sun8i-h3-orangepi-pc.dtb
28
console: => boot
29
console: ## Booting kernel from Legacy Image at 42000000 ...
30
console: Image Name: NetBSD/earmv7hf 9.0_RC1
31
console: Image Type: ARM Linux Kernel Image (no loading done) (uncompressed)
32
console: XIP Kernel Image (no loading done)
33
console: Loading Device Tree to 49ff6000, end 49fffe01 ... OK
34
console: Starting kernel ...
35
console: [ 1.0000000] NetBSD/evbarm (fdt) booting ...
36
console: [ 1.0000000] NetBSD 9.0 (GENERIC) #0: Fri Feb 14 00:06:28 UTC 2020
37
console: [ 1.0000000] mkrepro@mkrepro.NetBSD.org:/usr/src/sys/arch/evbarm/compile/GENERIC
38
console: [ 1.0000000] total memory = 1024 MB
39
console: [ 1.0000000] avail memory = 1003 MB
40
console: [ 1.0000000] armfdt0 (root)
41
console: [ 1.0000000] simplebus0 at armfdt0: Xunlong Orange Pi PC
42
console: [ 1.0000000] cpu0 at cpus0: Cortex-A7 r0p5 (Cortex V7A core)
43
console: [ 1.0000000] cpu0: DC enabled IC enabled WB enabled LABT branch prediction enabled
44
console: [ 1.0000000] cpu0: 32KB/64B 2-way L1 VIPT Instruction cache
45
console: [ 1.0000000] cpu0: 32KB/64B 2-way write-back-locking-C L1 PIPT Data cache
46
console: [ 1.0000000] cpu0: 2304KB/64B 16-way write-through L2 PIPT Unified cache
47
console: [ 1.0000000] vfp0 at cpu0: NEON MPE (VFP 3.0+), rounding, NaN propagation, denormals
48
...
49
console: [ 2.3812082] sdmmc0: SD card status: 4-bit, C0
50
console: [ 2.3812082] ld0 at sdmmc0: <0xaa:0x5859:QEMU!:0x01:0xdeadbeef:0x062>
51
console: [ 2.4012856] ld0: 1226 MB, 622 cyl, 64 head, 63 sec, 512 bytes/sect x 2511872 sectors
52
console: [ 2.5321222] ld0: 4-bit width, High-Speed/SDR25, 50.000 MHz
53
console: [ 3.1068718] WARNING: 4 errors while detecting hardware; check system log.
54
console: [ 3.1179868] boot device: ld0
55
console: [ 3.1470623] root on ld0a dumps on ld0b
56
console: [ 3.2464436] root file system type: ffs
57
console: [ 3.2897123] kern.module.path=/stand/evbarm/9.0/modules
58
console: Mon Feb 17 20:33:35 UTC 2020
59
console: Starting root file system check:
60
PASS (35.96 s)
61
RESULTS : PASS 1 | ERROR 0 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 0
62
JOB TIME : 36.09 s
63
64
Note, this test only took ~65 seconds to run on Travis-CI, see: [3].
65
66
This test is based on a description from Niek Linnenbank from [4].
67
68
[1] https://wiki.debian.org/InstallingDebianOn/Allwinner#Creating_a_bootable_SD_Card_with_u-boot
69
[2] https://wiki.netbsd.org/ports/evbarm/allwinner/
70
[3] https://travis-ci.org/philmd/qemu/jobs/638823612#L3778
71
[4] https://www.mail-archive.com/qemu-devel@nongnu.org/msg669347.html
72
73
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
74
Signed-off-by: Niek Linnenbank <nieklinnenbank@gmail.com>
75
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
76
Tested-by: Alex Bennée <alex.bennee@linaro.org>
77
Message-id: 20200311221854.30370-18-nieklinnenbank@gmail.com
78
[NL: changed test to use NetBSD 9.0 final release and -global allwinner-rtc.base-year]
79
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
80
---
11
---
81
tests/acceptance/boot_linux_console.py | 70 ++++++++++++++++++++++++++
12
target/arm/internals.h | 3 +++
82
1 file changed, 70 insertions(+)
13
1 file changed, 3 insertions(+)
83
14
84
diff --git a/tests/acceptance/boot_linux_console.py b/tests/acceptance/boot_linux_console.py
15
diff --git a/target/arm/internals.h b/target/arm/internals.h
85
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
86
--- a/tests/acceptance/boot_linux_console.py
17
--- a/target/arm/internals.h
87
+++ b/tests/acceptance/boot_linux_console.py
18
+++ b/target/arm/internals.h
88
@@ -XXX,XX +XXX,XX @@ import shutil
19
@@ -XXX,XX +XXX,XX @@ static inline uint32_t aarch64_pstate_valid_mask(const ARMISARegisters *id)
89
from avocado import skipUnless
20
if (isar_feature_aa64_mte(id)) {
90
from avocado_qemu import Test
21
valid |= PSTATE_TCO;
91
from avocado_qemu import exec_command_and_wait_for_pattern
22
}
92
+from avocado_qemu import interrupt_interactive_console_until_pattern
23
+ if (isar_feature_aa64_nmi(id)) {
93
from avocado_qemu import wait_for_console_pattern
24
+ valid |= PSTATE_ALLINT;
94
from avocado.utils import process
25
+ }
95
from avocado.utils import archive
26
96
@@ -XXX,XX +XXX,XX @@ class BootLinuxConsole(Test):
27
return valid;
97
'to <orangepipc>')
28
}
98
self.wait_for_console_pattern('Starting Load Kernel Modules...')
99
100
+ @skipUnless(os.getenv('AVOCADO_ALLOW_LARGE_STORAGE'), 'storage limited')
101
+ def test_arm_orangepi_uboot_netbsd9(self):
102
+ """
103
+ :avocado: tags=arch:arm
104
+ :avocado: tags=machine:orangepi-pc
105
+ """
106
+ # This test download a 304MB compressed image and expand it to 1.3GB...
107
+ deb_url = ('http://snapshot.debian.org/archive/debian/'
108
+ '20200108T145233Z/pool/main/u/u-boot/'
109
+ 'u-boot-sunxi_2020.01%2Bdfsg-1_armhf.deb')
110
+ deb_hash = 'f67f404a80753ca3d1258f13e38f2b060e13db99'
111
+ deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
112
+ # We use the common OrangePi PC 'plus' build of U-Boot for our secondary
113
+ # program loader (SPL). We will then set the path to the more specific
114
+ # OrangePi "PC" device tree blob with 'setenv fdtfile' in U-Boot prompt,
115
+ # before to boot NetBSD.
116
+ uboot_path = '/usr/lib/u-boot/orangepi_plus/u-boot-sunxi-with-spl.bin'
117
+ uboot_path = self.extract_from_deb(deb_path, uboot_path)
118
+ image_url = ('https://cdn.netbsd.org/pub/NetBSD/NetBSD-9.0/'
119
+ 'evbarm-earmv7hf/binary/gzimg/armv7.img.gz')
120
+ image_hash = '2babb29d36d8360adcb39c09e31060945259917a'
121
+ image_path_gz = self.fetch_asset(image_url, asset_hash=image_hash)
122
+ image_path = os.path.join(self.workdir, 'armv7.img')
123
+ image_drive_args = 'if=sd,format=raw,snapshot=on,file=' + image_path
124
+ archive.gzip_uncompress(image_path_gz, image_path)
125
+
126
+ # dd if=u-boot-sunxi-with-spl.bin of=armv7.img bs=1K seek=8 conv=notrunc
127
+ with open(uboot_path, 'rb') as f_in:
128
+ with open(image_path, 'r+b') as f_out:
129
+ f_out.seek(8 * 1024)
130
+ shutil.copyfileobj(f_in, f_out)
131
+
132
+ # Extend image, to avoid that NetBSD thinks the partition
133
+ # inside the image is larger than device size itself
134
+ f_out.seek(0, 2)
135
+ f_out.seek(64 * 1024 * 1024, 1)
136
+ f_out.write(bytearray([0x00]))
137
+
138
+ self.vm.set_console()
139
+ self.vm.add_args('-nic', 'user',
140
+ '-drive', image_drive_args,
141
+ '-global', 'allwinner-rtc.base-year=2000',
142
+ '-no-reboot')
143
+ self.vm.launch()
144
+ wait_for_console_pattern(self, 'U-Boot 2020.01+dfsg-1')
145
+ interrupt_interactive_console_until_pattern(self,
146
+ 'Hit any key to stop autoboot:',
147
+ 'switch to partitions #0, OK')
148
+
149
+ exec_command_and_wait_for_pattern(self, '', '=>')
150
+ cmd = 'setenv bootargs root=ld0a'
151
+ exec_command_and_wait_for_pattern(self, cmd, '=>')
152
+ cmd = 'setenv kernel netbsd-GENERIC.ub'
153
+ exec_command_and_wait_for_pattern(self, cmd, '=>')
154
+ cmd = 'setenv fdtfile dtb/sun8i-h3-orangepi-pc.dtb'
155
+ exec_command_and_wait_for_pattern(self, cmd, '=>')
156
+ cmd = ("setenv bootcmd 'fatload mmc 0:1 ${kernel_addr_r} ${kernel}; "
157
+ "fatload mmc 0:1 ${fdt_addr_r} ${fdtfile}; "
158
+ "fdt addr ${fdt_addr_r}; "
159
+ "bootm ${kernel_addr_r} - ${fdt_addr_r}'")
160
+ exec_command_and_wait_for_pattern(self, cmd, '=>')
161
+
162
+ exec_command_and_wait_for_pattern(self, 'boot',
163
+ 'Booting kernel from Legacy Image')
164
+ wait_for_console_pattern(self, 'Starting kernel ...')
165
+ wait_for_console_pattern(self, 'NetBSD 9.0 (GENERIC)')
166
+ # Wait for user-space
167
+ wait_for_console_pattern(self, 'Starting root file system check')
168
+
169
def test_s390x_s390_ccw_virtio(self):
170
"""
171
:avocado: tags=arch:s390x
172
--
29
--
173
2.20.1
30
2.34.1
174
175
diff view generated by jsdifflib
1
From: Niek Linnenbank <nieklinnenbank@gmail.com>
1
From: Jinjie Ruan <ruanjinjie@huawei.com>
2
2
3
The Allwinner H3 System on Chip has an System Control
3
Add ALLINT MSR (immediate) to decodetree, in which the CRm is 0b000x. The
4
module that provides system wide generic controls and
4
EL0 check is necessary to ALLINT, and the EL1 check is necessary when
5
device information. This commit adds support for the
5
imm == 1. So implement it inline for EL2/3, or EL1 with imm==0. Avoid the
6
Allwinner H3 System Control module.
6
unconditional write to pc and use raise_exception_ra to unwind.
7
7
8
Signed-off-by: Niek Linnenbank <nieklinnenbank@gmail.com>
8
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
9
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
9
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
10
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
10
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
11
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
11
Message-id: 20240407081733.3231820-5-ruanjinjie@huawei.com
12
Message-id: 20200311221854.30370-6-nieklinnenbank@gmail.com
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
14
---
13
---
15
hw/misc/Makefile.objs | 1 +
14
target/arm/tcg/helper-a64.h | 1 +
16
include/hw/arm/allwinner-h3.h | 3 +
15
target/arm/tcg/a64.decode | 1 +
17
include/hw/misc/allwinner-h3-sysctrl.h | 67 ++++++++++++
16
target/arm/tcg/helper-a64.c | 12 ++++++++++++
18
hw/arm/allwinner-h3.c | 9 +-
17
target/arm/tcg/translate-a64.c | 19 +++++++++++++++++++
19
hw/misc/allwinner-h3-sysctrl.c | 140 +++++++++++++++++++++++++
18
4 files changed, 33 insertions(+)
20
5 files changed, 219 insertions(+), 1 deletion(-)
21
create mode 100644 include/hw/misc/allwinner-h3-sysctrl.h
22
create mode 100644 hw/misc/allwinner-h3-sysctrl.c
23
19
24
diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs
20
diff --git a/target/arm/tcg/helper-a64.h b/target/arm/tcg/helper-a64.h
25
index XXXXXXX..XXXXXXX 100644
21
index XXXXXXX..XXXXXXX 100644
26
--- a/hw/misc/Makefile.objs
22
--- a/target/arm/tcg/helper-a64.h
27
+++ b/hw/misc/Makefile.objs
23
+++ b/target/arm/tcg/helper-a64.h
28
@@ -XXX,XX +XXX,XX @@ common-obj-$(CONFIG_MACIO) += macio/
24
@@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_1(rbit64, TCG_CALL_NO_RWG_SE, i64, i64)
29
common-obj-$(CONFIG_IVSHMEM_DEVICE) += ivshmem.o
25
DEF_HELPER_2(msr_i_spsel, void, env, i32)
30
26
DEF_HELPER_2(msr_i_daifset, void, env, i32)
31
common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-ccu.o
27
DEF_HELPER_2(msr_i_daifclear, void, env, i32)
32
+common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-sysctrl.o
28
+DEF_HELPER_1(msr_set_allint_el1, void, env)
33
common-obj-$(CONFIG_REALVIEW) += arm_sysctl.o
29
DEF_HELPER_3(vfp_cmph_a64, i64, f16, f16, ptr)
34
common-obj-$(CONFIG_NSERIES) += cbus.o
30
DEF_HELPER_3(vfp_cmpeh_a64, i64, f16, f16, ptr)
35
common-obj-$(CONFIG_ECCMEMCTL) += eccmemctl.o
31
DEF_HELPER_3(vfp_cmps_a64, i64, f32, f32, ptr)
36
diff --git a/include/hw/arm/allwinner-h3.h b/include/hw/arm/allwinner-h3.h
32
diff --git a/target/arm/tcg/a64.decode b/target/arm/tcg/a64.decode
37
index XXXXXXX..XXXXXXX 100644
33
index XXXXXXX..XXXXXXX 100644
38
--- a/include/hw/arm/allwinner-h3.h
34
--- a/target/arm/tcg/a64.decode
39
+++ b/include/hw/arm/allwinner-h3.h
35
+++ b/target/arm/tcg/a64.decode
40
@@ -XXX,XX +XXX,XX @@
36
@@ -XXX,XX +XXX,XX @@ MSR_i_DIT 1101 0101 0000 0 011 0100 .... 010 11111 @msr_i
41
#include "hw/timer/allwinner-a10-pit.h"
37
MSR_i_TCO 1101 0101 0000 0 011 0100 .... 100 11111 @msr_i
42
#include "hw/intc/arm_gic.h"
38
MSR_i_DAIFSET 1101 0101 0000 0 011 0100 .... 110 11111 @msr_i
43
#include "hw/misc/allwinner-h3-ccu.h"
39
MSR_i_DAIFCLEAR 1101 0101 0000 0 011 0100 .... 111 11111 @msr_i
44
+#include "hw/misc/allwinner-h3-sysctrl.h"
40
+MSR_i_ALLINT 1101 0101 0000 0 001 0100 000 imm:1 000 11111
45
#include "target/arm/cpu.h"
41
MSR_i_SVCR 1101 0101 0000 0 011 0100 0 mask:2 imm:1 011 11111
46
42
47
/**
43
# MRS, MSR (register), SYS, SYSL. These are all essentially the
48
@@ -XXX,XX +XXX,XX @@ enum {
44
diff --git a/target/arm/tcg/helper-a64.c b/target/arm/tcg/helper-a64.c
49
AW_H3_SRAM_A1,
50
AW_H3_SRAM_A2,
51
AW_H3_SRAM_C,
52
+ AW_H3_SYSCTRL,
53
AW_H3_EHCI0,
54
AW_H3_OHCI0,
55
AW_H3_EHCI1,
56
@@ -XXX,XX +XXX,XX @@ typedef struct AwH3State {
57
const hwaddr *memmap;
58
AwA10PITState timer;
59
AwH3ClockCtlState ccu;
60
+ AwH3SysCtrlState sysctrl;
61
GICState gic;
62
MemoryRegion sram_a1;
63
MemoryRegion sram_a2;
64
diff --git a/include/hw/misc/allwinner-h3-sysctrl.h b/include/hw/misc/allwinner-h3-sysctrl.h
65
new file mode 100644
66
index XXXXXXX..XXXXXXX
67
--- /dev/null
68
+++ b/include/hw/misc/allwinner-h3-sysctrl.h
69
@@ -XXX,XX +XXX,XX @@
70
+/*
71
+ * Allwinner H3 System Control emulation
72
+ *
73
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
74
+ *
75
+ * This program is free software: you can redistribute it and/or modify
76
+ * it under the terms of the GNU General Public License as published by
77
+ * the Free Software Foundation, either version 2 of the License, or
78
+ * (at your option) any later version.
79
+ *
80
+ * This program is distributed in the hope that it will be useful,
81
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
82
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
83
+ * GNU General Public License for more details.
84
+ *
85
+ * You should have received a copy of the GNU General Public License
86
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
87
+ */
88
+
89
+#ifndef HW_MISC_ALLWINNER_H3_SYSCTRL_H
90
+#define HW_MISC_ALLWINNER_H3_SYSCTRL_H
91
+
92
+#include "qom/object.h"
93
+#include "hw/sysbus.h"
94
+
95
+/**
96
+ * @name Constants
97
+ * @{
98
+ */
99
+
100
+/** Highest register address used by System Control device */
101
+#define AW_H3_SYSCTRL_REGS_MAXADDR (0x30)
102
+
103
+/** Total number of known registers */
104
+#define AW_H3_SYSCTRL_REGS_NUM ((AW_H3_SYSCTRL_REGS_MAXADDR / \
105
+ sizeof(uint32_t)) + 1)
106
+
107
+/** @} */
108
+
109
+/**
110
+ * @name Object model
111
+ * @{
112
+ */
113
+
114
+#define TYPE_AW_H3_SYSCTRL "allwinner-h3-sysctrl"
115
+#define AW_H3_SYSCTRL(obj) \
116
+ OBJECT_CHECK(AwH3SysCtrlState, (obj), TYPE_AW_H3_SYSCTRL)
117
+
118
+/** @} */
119
+
120
+/**
121
+ * Allwinner H3 System Control object instance state
122
+ */
123
+typedef struct AwH3SysCtrlState {
124
+ /*< private >*/
125
+ SysBusDevice parent_obj;
126
+ /*< public >*/
127
+
128
+ /** Maps I/O registers in physical memory */
129
+ MemoryRegion iomem;
130
+
131
+ /** Array of hardware registers */
132
+ uint32_t regs[AW_H3_SYSCTRL_REGS_NUM];
133
+
134
+} AwH3SysCtrlState;
135
+
136
+#endif /* HW_MISC_ALLWINNER_H3_SYSCTRL_H */
137
diff --git a/hw/arm/allwinner-h3.c b/hw/arm/allwinner-h3.c
138
index XXXXXXX..XXXXXXX 100644
45
index XXXXXXX..XXXXXXX 100644
139
--- a/hw/arm/allwinner-h3.c
46
--- a/target/arm/tcg/helper-a64.c
140
+++ b/hw/arm/allwinner-h3.c
47
+++ b/target/arm/tcg/helper-a64.c
141
@@ -XXX,XX +XXX,XX @@ const hwaddr allwinner_h3_memmap[] = {
48
@@ -XXX,XX +XXX,XX @@ void HELPER(msr_i_spsel)(CPUARMState *env, uint32_t imm)
142
[AW_H3_SRAM_A1] = 0x00000000,
49
update_spsel(env, imm);
143
[AW_H3_SRAM_A2] = 0x00044000,
144
[AW_H3_SRAM_C] = 0x00010000,
145
+ [AW_H3_SYSCTRL] = 0x01c00000,
146
[AW_H3_EHCI0] = 0x01c1a000,
147
[AW_H3_OHCI0] = 0x01c1a400,
148
[AW_H3_EHCI1] = 0x01c1b000,
149
@@ -XXX,XX +XXX,XX @@ struct AwH3Unimplemented {
150
} unimplemented[] = {
151
{ "d-engine", 0x01000000, 4 * MiB },
152
{ "d-inter", 0x01400000, 128 * KiB },
153
- { "syscon", 0x01c00000, 4 * KiB },
154
{ "dma", 0x01c02000, 4 * KiB },
155
{ "nfdc", 0x01c03000, 4 * KiB },
156
{ "ts", 0x01c06000, 4 * KiB },
157
@@ -XXX,XX +XXX,XX @@ static void allwinner_h3_init(Object *obj)
158
159
sysbus_init_child_obj(obj, "ccu", &s->ccu, sizeof(s->ccu),
160
TYPE_AW_H3_CCU);
161
+
162
+ sysbus_init_child_obj(obj, "sysctrl", &s->sysctrl, sizeof(s->sysctrl),
163
+ TYPE_AW_H3_SYSCTRL);
164
}
50
}
165
51
166
static void allwinner_h3_realize(DeviceState *dev, Error **errp)
52
+void HELPER(msr_set_allint_el1)(CPUARMState *env)
167
@@ -XXX,XX +XXX,XX @@ static void allwinner_h3_realize(DeviceState *dev, Error **errp)
168
qdev_init_nofail(DEVICE(&s->ccu));
169
sysbus_mmio_map(SYS_BUS_DEVICE(&s->ccu), 0, s->memmap[AW_H3_CCU]);
170
171
+ /* System Control */
172
+ qdev_init_nofail(DEVICE(&s->sysctrl));
173
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->sysctrl), 0, s->memmap[AW_H3_SYSCTRL]);
174
+
175
/* Universal Serial Bus */
176
sysbus_create_simple(TYPE_AW_H3_EHCI, s->memmap[AW_H3_EHCI0],
177
qdev_get_gpio_in(DEVICE(&s->gic),
178
diff --git a/hw/misc/allwinner-h3-sysctrl.c b/hw/misc/allwinner-h3-sysctrl.c
179
new file mode 100644
180
index XXXXXXX..XXXXXXX
181
--- /dev/null
182
+++ b/hw/misc/allwinner-h3-sysctrl.c
183
@@ -XXX,XX +XXX,XX @@
184
+/*
185
+ * Allwinner H3 System Control emulation
186
+ *
187
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
188
+ *
189
+ * This program is free software: you can redistribute it and/or modify
190
+ * it under the terms of the GNU General Public License as published by
191
+ * the Free Software Foundation, either version 2 of the License, or
192
+ * (at your option) any later version.
193
+ *
194
+ * This program is distributed in the hope that it will be useful,
195
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
196
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
197
+ * GNU General Public License for more details.
198
+ *
199
+ * You should have received a copy of the GNU General Public License
200
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
201
+ */
202
+
203
+#include "qemu/osdep.h"
204
+#include "qemu/units.h"
205
+#include "hw/sysbus.h"
206
+#include "migration/vmstate.h"
207
+#include "qemu/log.h"
208
+#include "qemu/module.h"
209
+#include "hw/misc/allwinner-h3-sysctrl.h"
210
+
211
+/* System Control register offsets */
212
+enum {
213
+ REG_VER = 0x24, /* Version */
214
+ REG_EMAC_PHY_CLK = 0x30, /* EMAC PHY Clock */
215
+};
216
+
217
+#define REG_INDEX(offset) (offset / sizeof(uint32_t))
218
+
219
+/* System Control register reset values */
220
+enum {
221
+ REG_VER_RST = 0x0,
222
+ REG_EMAC_PHY_CLK_RST = 0x58000,
223
+};
224
+
225
+static uint64_t allwinner_h3_sysctrl_read(void *opaque, hwaddr offset,
226
+ unsigned size)
227
+{
53
+{
228
+ const AwH3SysCtrlState *s = AW_H3_SYSCTRL(opaque);
54
+ /* ALLINT update to PSTATE. */
229
+ const uint32_t idx = REG_INDEX(offset);
55
+ if (arm_hcrx_el2_eff(env) & HCRX_TALLINT) {
230
+
56
+ raise_exception_ra(env, EXCP_UDEF,
231
+ if (idx >= AW_H3_SYSCTRL_REGS_NUM) {
57
+ syn_aa64_sysregtrap(0, 1, 0, 4, 1, 0x1f, 0), 2,
232
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset 0x%04x\n",
58
+ GETPC());
233
+ __func__, (uint32_t)offset);
234
+ return 0;
235
+ }
59
+ }
236
+
60
+
237
+ return s->regs[idx];
61
+ env->pstate |= PSTATE_ALLINT;
238
+}
62
+}
239
+
63
+
240
+static void allwinner_h3_sysctrl_write(void *opaque, hwaddr offset,
64
static void daif_check(CPUARMState *env, uint32_t op,
241
+ uint64_t val, unsigned size)
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)
242
+{
76
+{
243
+ AwH3SysCtrlState *s = AW_H3_SYSCTRL(opaque);
77
+ if (!dc_isar_feature(aa64_nmi, s) || s->current_el == 0) {
244
+ const uint32_t idx = REG_INDEX(offset);
78
+ return false;
245
+
246
+ if (idx >= AW_H3_SYSCTRL_REGS_NUM) {
247
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset 0x%04x\n",
248
+ __func__, (uint32_t)offset);
249
+ return;
250
+ }
79
+ }
251
+
80
+
252
+ switch (offset) {
81
+ if (a->imm == 0) {
253
+ case REG_VER: /* Version */
82
+ clear_pstate_bits(PSTATE_ALLINT);
254
+ break;
83
+ } else if (s->current_el > 1) {
255
+ default:
84
+ set_pstate_bits(PSTATE_ALLINT);
256
+ s->regs[idx] = (uint32_t) val;
85
+ } else {
257
+ break;
86
+ gen_helper_msr_set_allint_el1(tcg_env);
258
+ }
87
+ }
88
+
89
+ /* Exit the cpu loop to re-evaluate pending IRQs. */
90
+ s->base.is_jmp = DISAS_UPDATE_EXIT;
91
+ return true;
259
+}
92
+}
260
+
93
+
261
+static const MemoryRegionOps allwinner_h3_sysctrl_ops = {
94
static bool trans_MSR_i_SVCR(DisasContext *s, arg_MSR_i_SVCR *a)
262
+ .read = allwinner_h3_sysctrl_read,
95
{
263
+ .write = allwinner_h3_sysctrl_write,
96
if (!dc_isar_feature(aa64_sme, s) || a->mask == 0) {
264
+ .endianness = DEVICE_NATIVE_ENDIAN,
265
+ .valid = {
266
+ .min_access_size = 4,
267
+ .max_access_size = 4,
268
+ },
269
+ .impl.min_access_size = 4,
270
+};
271
+
272
+static void allwinner_h3_sysctrl_reset(DeviceState *dev)
273
+{
274
+ AwH3SysCtrlState *s = AW_H3_SYSCTRL(dev);
275
+
276
+ /* Set default values for registers */
277
+ s->regs[REG_INDEX(REG_VER)] = REG_VER_RST;
278
+ s->regs[REG_INDEX(REG_EMAC_PHY_CLK)] = REG_EMAC_PHY_CLK_RST;
279
+}
280
+
281
+static void allwinner_h3_sysctrl_init(Object *obj)
282
+{
283
+ SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
284
+ AwH3SysCtrlState *s = AW_H3_SYSCTRL(obj);
285
+
286
+ /* Memory mapping */
287
+ memory_region_init_io(&s->iomem, OBJECT(s), &allwinner_h3_sysctrl_ops, s,
288
+ TYPE_AW_H3_SYSCTRL, 4 * KiB);
289
+ sysbus_init_mmio(sbd, &s->iomem);
290
+}
291
+
292
+static const VMStateDescription allwinner_h3_sysctrl_vmstate = {
293
+ .name = "allwinner-h3-sysctrl",
294
+ .version_id = 1,
295
+ .minimum_version_id = 1,
296
+ .fields = (VMStateField[]) {
297
+ VMSTATE_UINT32_ARRAY(regs, AwH3SysCtrlState, AW_H3_SYSCTRL_REGS_NUM),
298
+ VMSTATE_END_OF_LIST()
299
+ }
300
+};
301
+
302
+static void allwinner_h3_sysctrl_class_init(ObjectClass *klass, void *data)
303
+{
304
+ DeviceClass *dc = DEVICE_CLASS(klass);
305
+
306
+ dc->reset = allwinner_h3_sysctrl_reset;
307
+ dc->vmsd = &allwinner_h3_sysctrl_vmstate;
308
+}
309
+
310
+static const TypeInfo allwinner_h3_sysctrl_info = {
311
+ .name = TYPE_AW_H3_SYSCTRL,
312
+ .parent = TYPE_SYS_BUS_DEVICE,
313
+ .instance_init = allwinner_h3_sysctrl_init,
314
+ .instance_size = sizeof(AwH3SysCtrlState),
315
+ .class_init = allwinner_h3_sysctrl_class_init,
316
+};
317
+
318
+static void allwinner_h3_sysctrl_register(void)
319
+{
320
+ type_register_static(&allwinner_h3_sysctrl_info);
321
+}
322
+
323
+type_init(allwinner_h3_sysctrl_register)
324
--
97
--
325
2.20.1
98
2.34.1
326
327
diff view generated by jsdifflib
1
From: Niek Linnenbank <nieklinnenbank@gmail.com>
1
From: Jinjie Ruan <ruanjinjie@huawei.com>
2
2
3
Allwinner System-on-Chips usually contain a Real Time Clock (RTC)
3
Support ALLINT msr access as follow:
4
for non-volatile system date and time keeping. This commit adds a generic
4
    mrs <xt>, ALLINT    // read allint
5
Allwinner RTC device that supports the RTC devices found in Allwinner SoC
5
    msr ALLINT, <xt>    // write allint with imm
6
family sun4i (A10), sun7i (A20) and sun6i and newer (A31, H2+, H3, etc).
7
The following RTC functionality and features are implemented:
8
6
9
* Year-Month-Day read/write
7
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
10
* Hour-Minute-Second read/write
8
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
11
* General Purpose storage
9
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
12
10
Message-id: 20240407081733.3231820-6-ruanjinjie@huawei.com
13
The following boards are extended with the RTC device:
14
15
* Cubieboard (hw/arm/cubieboard.c)
16
* Orange Pi PC (hw/arm/orangepi.c)
17
18
Signed-off-by: Niek Linnenbank <nieklinnenbank@gmail.com>
19
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
20
Message-id: 20200311221854.30370-13-nieklinnenbank@gmail.com
21
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
22
---
12
---
23
hw/rtc/Makefile.objs | 1 +
13
target/arm/helper.c | 35 +++++++++++++++++++++++++++++++++++
24
include/hw/arm/allwinner-a10.h | 2 +
14
1 file changed, 35 insertions(+)
25
include/hw/arm/allwinner-h3.h | 3 +
26
include/hw/rtc/allwinner-rtc.h | 134 +++++++++++
27
hw/arm/allwinner-a10.c | 8 +
28
hw/arm/allwinner-h3.c | 9 +-
29
hw/rtc/allwinner-rtc.c | 411 +++++++++++++++++++++++++++++++++
30
hw/rtc/trace-events | 4 +
31
8 files changed, 571 insertions(+), 1 deletion(-)
32
create mode 100644 include/hw/rtc/allwinner-rtc.h
33
create mode 100644 hw/rtc/allwinner-rtc.c
34
15
35
diff --git a/hw/rtc/Makefile.objs b/hw/rtc/Makefile.objs
16
diff --git a/target/arm/helper.c b/target/arm/helper.c
36
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
37
--- a/hw/rtc/Makefile.objs
18
--- a/target/arm/helper.c
38
+++ b/hw/rtc/Makefile.objs
19
+++ b/target/arm/helper.c
39
@@ -XXX,XX +XXX,XX @@ obj-$(CONFIG_MC146818RTC) += mc146818rtc.o
20
@@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo rme_mte_reginfo[] = {
40
common-obj-$(CONFIG_SUN4V_RTC) += sun4v-rtc.o
21
.opc0 = 1, .opc1 = 6, .crn = 7, .crm = 14, .opc2 = 5,
41
common-obj-$(CONFIG_ASPEED_SOC) += aspeed_rtc.o
22
.access = PL3_W, .type = ARM_CP_NOP },
42
common-obj-$(CONFIG_GOLDFISH_RTC) += goldfish_rtc.o
43
+common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-rtc.o
44
diff --git a/include/hw/arm/allwinner-a10.h b/include/hw/arm/allwinner-a10.h
45
index XXXXXXX..XXXXXXX 100644
46
--- a/include/hw/arm/allwinner-a10.h
47
+++ b/include/hw/arm/allwinner-a10.h
48
@@ -XXX,XX +XXX,XX @@
49
#include "hw/ide/ahci.h"
50
#include "hw/usb/hcd-ohci.h"
51
#include "hw/usb/hcd-ehci.h"
52
+#include "hw/rtc/allwinner-rtc.h"
53
54
#include "target/arm/cpu.h"
55
56
@@ -XXX,XX +XXX,XX @@ typedef struct AwA10State {
57
AwEmacState emac;
58
AllwinnerAHCIState sata;
59
AwSdHostState mmc0;
60
+ AwRtcState rtc;
61
MemoryRegion sram_a;
62
EHCISysBusState ehci[AW_A10_NUM_USB];
63
OHCISysBusState ohci[AW_A10_NUM_USB];
64
diff --git a/include/hw/arm/allwinner-h3.h b/include/hw/arm/allwinner-h3.h
65
index XXXXXXX..XXXXXXX 100644
66
--- a/include/hw/arm/allwinner-h3.h
67
+++ b/include/hw/arm/allwinner-h3.h
68
@@ -XXX,XX +XXX,XX @@
69
#include "hw/misc/allwinner-sid.h"
70
#include "hw/sd/allwinner-sdhost.h"
71
#include "hw/net/allwinner-sun8i-emac.h"
72
+#include "hw/rtc/allwinner-rtc.h"
73
#include "target/arm/cpu.h"
74
#include "sysemu/block-backend.h"
75
76
@@ -XXX,XX +XXX,XX @@ enum {
77
AW_H3_GIC_CPU,
78
AW_H3_GIC_HYP,
79
AW_H3_GIC_VCPU,
80
+ AW_H3_RTC,
81
AW_H3_CPUCFG,
82
AW_H3_SDRAM
83
};
23
};
84
@@ -XXX,XX +XXX,XX @@ typedef struct AwH3State {
85
AwSidState sid;
86
AwSdHostState mmc0;
87
AwSun8iEmacState emac;
88
+ AwRtcState rtc;
89
GICState gic;
90
MemoryRegion sram_a1;
91
MemoryRegion sram_a2;
92
diff --git a/include/hw/rtc/allwinner-rtc.h b/include/hw/rtc/allwinner-rtc.h
93
new file mode 100644
94
index XXXXXXX..XXXXXXX
95
--- /dev/null
96
+++ b/include/hw/rtc/allwinner-rtc.h
97
@@ -XXX,XX +XXX,XX @@
98
+/*
99
+ * Allwinner Real Time Clock emulation
100
+ *
101
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
102
+ *
103
+ * This program is free software: you can redistribute it and/or modify
104
+ * it under the terms of the GNU General Public License as published by
105
+ * the Free Software Foundation, either version 2 of the License, or
106
+ * (at your option) any later version.
107
+ *
108
+ * This program is distributed in the hope that it will be useful,
109
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
110
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
111
+ * GNU General Public License for more details.
112
+ *
113
+ * You should have received a copy of the GNU General Public License
114
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
115
+ */
116
+
24
+
117
+#ifndef HW_MISC_ALLWINNER_RTC_H
25
+static void aa64_allint_write(CPUARMState *env, const ARMCPRegInfo *ri,
118
+#define HW_MISC_ALLWINNER_RTC_H
26
+ uint64_t value)
119
+
120
+#include "qom/object.h"
121
+#include "hw/sysbus.h"
122
+
123
+/**
124
+ * Constants
125
+ * @{
126
+ */
127
+
128
+/** Highest register address used by RTC device */
129
+#define AW_RTC_REGS_MAXADDR (0x200)
130
+
131
+/** Total number of known registers */
132
+#define AW_RTC_REGS_NUM (AW_RTC_REGS_MAXADDR / sizeof(uint32_t))
133
+
134
+/** @} */
135
+
136
+/**
137
+ * Object model types
138
+ * @{
139
+ */
140
+
141
+/** Generic Allwinner RTC device (abstract) */
142
+#define TYPE_AW_RTC "allwinner-rtc"
143
+
144
+/** Allwinner RTC sun4i family (A10, A12) */
145
+#define TYPE_AW_RTC_SUN4I TYPE_AW_RTC "-sun4i"
146
+
147
+/** Allwinner RTC sun6i family and newer (A31, H2+, H3, etc) */
148
+#define TYPE_AW_RTC_SUN6I TYPE_AW_RTC "-sun6i"
149
+
150
+/** Allwinner RTC sun7i family (A20) */
151
+#define TYPE_AW_RTC_SUN7I TYPE_AW_RTC "-sun7i"
152
+
153
+/** @} */
154
+
155
+/**
156
+ * Object model macros
157
+ * @{
158
+ */
159
+
160
+#define AW_RTC(obj) \
161
+ OBJECT_CHECK(AwRtcState, (obj), TYPE_AW_RTC)
162
+#define AW_RTC_CLASS(klass) \
163
+ OBJECT_CLASS_CHECK(AwRtcClass, (klass), TYPE_AW_RTC)
164
+#define AW_RTC_GET_CLASS(obj) \
165
+ OBJECT_GET_CLASS(AwRtcClass, (obj), TYPE_AW_RTC)
166
+
167
+/** @} */
168
+
169
+/**
170
+ * Allwinner RTC per-object instance state.
171
+ */
172
+typedef struct AwRtcState {
173
+ /*< private >*/
174
+ SysBusDevice parent_obj;
175
+ /*< public >*/
176
+
177
+ /**
178
+ * Actual year represented by the device when year counter is zero
179
+ *
180
+ * Can be overridden by the user using the corresponding 'base-year'
181
+ * property. The base year used by the target OS driver can vary, for
182
+ * example the Linux driver for sun6i uses 1970 while NetBSD uses 2000.
183
+ */
184
+ int base_year;
185
+
186
+ /** Maps I/O registers in physical memory */
187
+ MemoryRegion iomem;
188
+
189
+ /** Array of hardware registers */
190
+ uint32_t regs[AW_RTC_REGS_NUM];
191
+
192
+} AwRtcState;
193
+
194
+/**
195
+ * Allwinner RTC class-level struct.
196
+ *
197
+ * This struct is filled by each sunxi device specific code
198
+ * such that the generic code can use this struct to support
199
+ * all devices.
200
+ */
201
+typedef struct AwRtcClass {
202
+ /*< private >*/
203
+ SysBusDeviceClass parent_class;
204
+ /*< public >*/
205
+
206
+ /** Defines device specific register map */
207
+ const uint8_t *regmap;
208
+
209
+ /** Size of the regmap in bytes */
210
+ size_t regmap_size;
211
+
212
+ /**
213
+ * Read device specific register
214
+ *
215
+ * @offset: register offset to read
216
+ * @return true if register read successful, false otherwise
217
+ */
218
+ bool (*read)(AwRtcState *s, uint32_t offset);
219
+
220
+ /**
221
+ * Write device specific register
222
+ *
223
+ * @offset: register offset to write
224
+ * @data: value to set in register
225
+ * @return true if register write successful, false otherwise
226
+ */
227
+ bool (*write)(AwRtcState *s, uint32_t offset, uint32_t data);
228
+
229
+} AwRtcClass;
230
+
231
+#endif /* HW_MISC_ALLWINNER_RTC_H */
232
diff --git a/hw/arm/allwinner-a10.c b/hw/arm/allwinner-a10.c
233
index XXXXXXX..XXXXXXX 100644
234
--- a/hw/arm/allwinner-a10.c
235
+++ b/hw/arm/allwinner-a10.c
236
@@ -XXX,XX +XXX,XX @@
237
#define AW_A10_EHCI_BASE 0x01c14000
238
#define AW_A10_OHCI_BASE 0x01c14400
239
#define AW_A10_SATA_BASE 0x01c18000
240
+#define AW_A10_RTC_BASE 0x01c20d00
241
242
static void aw_a10_init(Object *obj)
243
{
244
@@ -XXX,XX +XXX,XX @@ static void aw_a10_init(Object *obj)
245
246
sysbus_init_child_obj(obj, "mmc0", &s->mmc0, sizeof(s->mmc0),
247
TYPE_AW_SDHOST_SUN4I);
248
+
249
+ sysbus_init_child_obj(obj, "rtc", &s->rtc, sizeof(s->rtc),
250
+ TYPE_AW_RTC_SUN4I);
251
}
252
253
static void aw_a10_realize(DeviceState *dev, Error **errp)
254
@@ -XXX,XX +XXX,XX @@ static void aw_a10_realize(DeviceState *dev, Error **errp)
255
sysbus_connect_irq(SYS_BUS_DEVICE(&s->mmc0), 0, qdev_get_gpio_in(dev, 32));
256
object_property_add_alias(OBJECT(s), "sd-bus", OBJECT(&s->mmc0),
257
"sd-bus", &error_abort);
258
+
259
+ /* RTC */
260
+ qdev_init_nofail(DEVICE(&s->rtc));
261
+ sysbus_mmio_map_overlap(SYS_BUS_DEVICE(&s->rtc), 0, AW_A10_RTC_BASE, 10);
262
}
263
264
static void aw_a10_class_init(ObjectClass *oc, void *data)
265
diff --git a/hw/arm/allwinner-h3.c b/hw/arm/allwinner-h3.c
266
index XXXXXXX..XXXXXXX 100644
267
--- a/hw/arm/allwinner-h3.c
268
+++ b/hw/arm/allwinner-h3.c
269
@@ -XXX,XX +XXX,XX @@ const hwaddr allwinner_h3_memmap[] = {
270
[AW_H3_GIC_CPU] = 0x01c82000,
271
[AW_H3_GIC_HYP] = 0x01c84000,
272
[AW_H3_GIC_VCPU] = 0x01c86000,
273
+ [AW_H3_RTC] = 0x01f00000,
274
[AW_H3_CPUCFG] = 0x01f01c00,
275
[AW_H3_SDRAM] = 0x40000000
276
};
277
@@ -XXX,XX +XXX,XX @@ struct AwH3Unimplemented {
278
{ "csi", 0x01cb0000, 320 * KiB },
279
{ "tve", 0x01e00000, 64 * KiB },
280
{ "hdmi", 0x01ee0000, 128 * KiB },
281
- { "rtc", 0x01f00000, 1 * KiB },
282
{ "r_timer", 0x01f00800, 1 * KiB },
283
{ "r_intc", 0x01f00c00, 1 * KiB },
284
{ "r_wdog", 0x01f01000, 1 * KiB },
285
@@ -XXX,XX +XXX,XX @@ static void allwinner_h3_init(Object *obj)
286
"ram-addr", &error_abort);
287
object_property_add_alias(obj, "ram-size", OBJECT(&s->dramc),
288
"ram-size", &error_abort);
289
+
290
+ sysbus_init_child_obj(obj, "rtc", &s->rtc, sizeof(s->rtc),
291
+ TYPE_AW_RTC_SUN6I);
292
}
293
294
static void allwinner_h3_realize(DeviceState *dev, Error **errp)
295
@@ -XXX,XX +XXX,XX @@ static void allwinner_h3_realize(DeviceState *dev, Error **errp)
296
sysbus_mmio_map(SYS_BUS_DEVICE(&s->dramc), 1, s->memmap[AW_H3_DRAMCTL]);
297
sysbus_mmio_map(SYS_BUS_DEVICE(&s->dramc), 2, s->memmap[AW_H3_DRAMPHY]);
298
299
+ /* RTC */
300
+ qdev_init_nofail(DEVICE(&s->rtc));
301
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->rtc), 0, s->memmap[AW_H3_RTC]);
302
+
303
/* Unimplemented devices */
304
for (i = 0; i < ARRAY_SIZE(unimplemented); i++) {
305
create_unimplemented_device(unimplemented[i].device_name,
306
diff --git a/hw/rtc/allwinner-rtc.c b/hw/rtc/allwinner-rtc.c
307
new file mode 100644
308
index XXXXXXX..XXXXXXX
309
--- /dev/null
310
+++ b/hw/rtc/allwinner-rtc.c
311
@@ -XXX,XX +XXX,XX @@
312
+/*
313
+ * Allwinner Real Time Clock emulation
314
+ *
315
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
316
+ *
317
+ * This program is free software: you can redistribute it and/or modify
318
+ * it under the terms of the GNU General Public License as published by
319
+ * the Free Software Foundation, either version 2 of the License, or
320
+ * (at your option) any later version.
321
+ *
322
+ * This program is distributed in the hope that it will be useful,
323
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
324
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
325
+ * GNU General Public License for more details.
326
+ *
327
+ * You should have received a copy of the GNU General Public License
328
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
329
+ */
330
+
331
+#include "qemu/osdep.h"
332
+#include "qemu/units.h"
333
+#include "hw/sysbus.h"
334
+#include "migration/vmstate.h"
335
+#include "qemu/log.h"
336
+#include "qemu/module.h"
337
+#include "qemu-common.h"
338
+#include "hw/qdev-properties.h"
339
+#include "hw/rtc/allwinner-rtc.h"
340
+#include "trace.h"
341
+
342
+/* RTC registers */
343
+enum {
344
+ REG_LOSC = 1, /* Low Oscillator Control */
345
+ REG_YYMMDD, /* RTC Year-Month-Day */
346
+ REG_HHMMSS, /* RTC Hour-Minute-Second */
347
+ REG_ALARM1_WKHHMMSS, /* Alarm1 Week Hour-Minute-Second */
348
+ REG_ALARM1_EN, /* Alarm1 Enable */
349
+ REG_ALARM1_IRQ_EN, /* Alarm1 IRQ Enable */
350
+ REG_ALARM1_IRQ_STA, /* Alarm1 IRQ Status */
351
+ REG_GP0, /* General Purpose Register 0 */
352
+ REG_GP1, /* General Purpose Register 1 */
353
+ REG_GP2, /* General Purpose Register 2 */
354
+ REG_GP3, /* General Purpose Register 3 */
355
+
356
+ /* sun4i registers */
357
+ REG_ALARM1_DDHHMMSS, /* Alarm1 Day Hour-Minute-Second */
358
+ REG_CPUCFG, /* CPU Configuration Register */
359
+
360
+ /* sun6i registers */
361
+ REG_LOSC_AUTOSTA, /* LOSC Auto Switch Status */
362
+ REG_INT_OSC_PRE, /* Internal OSC Clock Prescaler */
363
+ REG_ALARM0_COUNTER, /* Alarm0 Counter */
364
+ REG_ALARM0_CUR_VLU, /* Alarm0 Counter Current Value */
365
+ REG_ALARM0_ENABLE, /* Alarm0 Enable */
366
+ REG_ALARM0_IRQ_EN, /* Alarm0 IRQ Enable */
367
+ REG_ALARM0_IRQ_STA, /* Alarm0 IRQ Status */
368
+ REG_ALARM_CONFIG, /* Alarm Config */
369
+ REG_LOSC_OUT_GATING, /* LOSC Output Gating Register */
370
+ REG_GP4, /* General Purpose Register 4 */
371
+ REG_GP5, /* General Purpose Register 5 */
372
+ REG_GP6, /* General Purpose Register 6 */
373
+ REG_GP7, /* General Purpose Register 7 */
374
+ REG_RTC_DBG, /* RTC Debug Register */
375
+ REG_GPL_HOLD_OUT, /* GPL Hold Output Register */
376
+ REG_VDD_RTC, /* VDD RTC Regulate Register */
377
+ REG_IC_CHARA, /* IC Characteristics Register */
378
+};
379
+
380
+/* RTC register flags */
381
+enum {
382
+ REG_LOSC_YMD = (1 << 7),
383
+ REG_LOSC_HMS = (1 << 8),
384
+};
385
+
386
+/* RTC sun4i register map (offset to name) */
387
+const uint8_t allwinner_rtc_sun4i_regmap[] = {
388
+ [0x0000] = REG_LOSC,
389
+ [0x0004] = REG_YYMMDD,
390
+ [0x0008] = REG_HHMMSS,
391
+ [0x000C] = REG_ALARM1_DDHHMMSS,
392
+ [0x0010] = REG_ALARM1_WKHHMMSS,
393
+ [0x0014] = REG_ALARM1_EN,
394
+ [0x0018] = REG_ALARM1_IRQ_EN,
395
+ [0x001C] = REG_ALARM1_IRQ_STA,
396
+ [0x0020] = REG_GP0,
397
+ [0x0024] = REG_GP1,
398
+ [0x0028] = REG_GP2,
399
+ [0x002C] = REG_GP3,
400
+ [0x003C] = REG_CPUCFG,
401
+};
402
+
403
+/* RTC sun6i register map (offset to name) */
404
+const uint8_t allwinner_rtc_sun6i_regmap[] = {
405
+ [0x0000] = REG_LOSC,
406
+ [0x0004] = REG_LOSC_AUTOSTA,
407
+ [0x0008] = REG_INT_OSC_PRE,
408
+ [0x0010] = REG_YYMMDD,
409
+ [0x0014] = REG_HHMMSS,
410
+ [0x0020] = REG_ALARM0_COUNTER,
411
+ [0x0024] = REG_ALARM0_CUR_VLU,
412
+ [0x0028] = REG_ALARM0_ENABLE,
413
+ [0x002C] = REG_ALARM0_IRQ_EN,
414
+ [0x0030] = REG_ALARM0_IRQ_STA,
415
+ [0x0040] = REG_ALARM1_WKHHMMSS,
416
+ [0x0044] = REG_ALARM1_EN,
417
+ [0x0048] = REG_ALARM1_IRQ_EN,
418
+ [0x004C] = REG_ALARM1_IRQ_STA,
419
+ [0x0050] = REG_ALARM_CONFIG,
420
+ [0x0060] = REG_LOSC_OUT_GATING,
421
+ [0x0100] = REG_GP0,
422
+ [0x0104] = REG_GP1,
423
+ [0x0108] = REG_GP2,
424
+ [0x010C] = REG_GP3,
425
+ [0x0110] = REG_GP4,
426
+ [0x0114] = REG_GP5,
427
+ [0x0118] = REG_GP6,
428
+ [0x011C] = REG_GP7,
429
+ [0x0170] = REG_RTC_DBG,
430
+ [0x0180] = REG_GPL_HOLD_OUT,
431
+ [0x0190] = REG_VDD_RTC,
432
+ [0x01F0] = REG_IC_CHARA,
433
+};
434
+
435
+static bool allwinner_rtc_sun4i_read(AwRtcState *s, uint32_t offset)
436
+{
27
+{
437
+ /* no sun4i specific registers currently implemented */
28
+ env->pstate = (env->pstate & ~PSTATE_ALLINT) | (value & PSTATE_ALLINT);
438
+ return false;
439
+}
29
+}
440
+
30
+
441
+static bool allwinner_rtc_sun4i_write(AwRtcState *s, uint32_t offset,
31
+static uint64_t aa64_allint_read(CPUARMState *env, const ARMCPRegInfo *ri)
442
+ uint32_t data)
443
+{
32
+{
444
+ /* no sun4i specific registers currently implemented */
33
+ return env->pstate & PSTATE_ALLINT;
445
+ return false;
446
+}
34
+}
447
+
35
+
448
+static bool allwinner_rtc_sun6i_read(AwRtcState *s, uint32_t offset)
36
+static CPAccessResult aa64_allint_access(CPUARMState *env,
37
+ const ARMCPRegInfo *ri, bool isread)
449
+{
38
+{
450
+ const AwRtcClass *c = AW_RTC_GET_CLASS(s);
39
+ if (!isread && arm_current_el(env) == 1 &&
451
+
40
+ (arm_hcrx_el2_eff(env) & HCRX_TALLINT)) {
452
+ switch (c->regmap[offset]) {
41
+ return CP_ACCESS_TRAP_EL2;
453
+ case REG_GP4: /* General Purpose Register 4 */
454
+ case REG_GP5: /* General Purpose Register 5 */
455
+ case REG_GP6: /* General Purpose Register 6 */
456
+ case REG_GP7: /* General Purpose Register 7 */
457
+ return true;
458
+ default:
459
+ break;
460
+ }
42
+ }
461
+ return false;
43
+ return CP_ACCESS_OK;
462
+}
44
+}
463
+
45
+
464
+static bool allwinner_rtc_sun6i_write(AwRtcState *s, uint32_t offset,
46
+static const ARMCPRegInfo nmi_reginfo[] = {
465
+ uint32_t data)
47
+ { .name = "ALLINT", .state = ARM_CP_STATE_AA64,
466
+{
48
+ .opc0 = 3, .opc1 = 0, .opc2 = 0, .crn = 4, .crm = 3,
467
+ const AwRtcClass *c = AW_RTC_GET_CLASS(s);
49
+ .type = ARM_CP_NO_RAW,
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 },
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
}
468
+
62
+
469
+ switch (c->regmap[offset]) {
63
+ if (cpu_isar_feature(aa64_nmi, cpu)) {
470
+ case REG_GP4: /* General Purpose Register 4 */
64
+ define_arm_cp_regs(cpu, nmi_reginfo);
471
+ case REG_GP5: /* General Purpose Register 5 */
472
+ case REG_GP6: /* General Purpose Register 6 */
473
+ case REG_GP7: /* General Purpose Register 7 */
474
+ return true;
475
+ default:
476
+ break;
477
+ }
65
+ }
478
+ return false;
66
#endif
479
+}
67
480
+
68
if (cpu_isar_feature(any_predinv, cpu)) {
481
+static uint64_t allwinner_rtc_read(void *opaque, hwaddr offset,
482
+ unsigned size)
483
+{
484
+ AwRtcState *s = AW_RTC(opaque);
485
+ const AwRtcClass *c = AW_RTC_GET_CLASS(s);
486
+ uint64_t val = 0;
487
+
488
+ if (offset >= c->regmap_size) {
489
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset 0x%04x\n",
490
+ __func__, (uint32_t)offset);
491
+ return 0;
492
+ }
493
+
494
+ if (!c->regmap[offset]) {
495
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid register 0x%04x\n",
496
+ __func__, (uint32_t)offset);
497
+ return 0;
498
+ }
499
+
500
+ switch (c->regmap[offset]) {
501
+ case REG_LOSC: /* Low Oscillator Control */
502
+ val = s->regs[REG_LOSC];
503
+ s->regs[REG_LOSC] &= ~(REG_LOSC_YMD | REG_LOSC_HMS);
504
+ break;
505
+ case REG_YYMMDD: /* RTC Year-Month-Day */
506
+ case REG_HHMMSS: /* RTC Hour-Minute-Second */
507
+ case REG_GP0: /* General Purpose Register 0 */
508
+ case REG_GP1: /* General Purpose Register 1 */
509
+ case REG_GP2: /* General Purpose Register 2 */
510
+ case REG_GP3: /* General Purpose Register 3 */
511
+ val = s->regs[c->regmap[offset]];
512
+ break;
513
+ default:
514
+ if (!c->read(s, offset)) {
515
+ qemu_log_mask(LOG_UNIMP, "%s: unimplemented register 0x%04x\n",
516
+ __func__, (uint32_t)offset);
517
+ }
518
+ val = s->regs[c->regmap[offset]];
519
+ break;
520
+ }
521
+
522
+ trace_allwinner_rtc_read(offset, val);
523
+ return val;
524
+}
525
+
526
+static void allwinner_rtc_write(void *opaque, hwaddr offset,
527
+ uint64_t val, unsigned size)
528
+{
529
+ AwRtcState *s = AW_RTC(opaque);
530
+ const AwRtcClass *c = AW_RTC_GET_CLASS(s);
531
+
532
+ if (offset >= c->regmap_size) {
533
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset 0x%04x\n",
534
+ __func__, (uint32_t)offset);
535
+ return;
536
+ }
537
+
538
+ if (!c->regmap[offset]) {
539
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid register 0x%04x\n",
540
+ __func__, (uint32_t)offset);
541
+ return;
542
+ }
543
+
544
+ trace_allwinner_rtc_write(offset, val);
545
+
546
+ switch (c->regmap[offset]) {
547
+ case REG_YYMMDD: /* RTC Year-Month-Day */
548
+ s->regs[REG_YYMMDD] = val;
549
+ s->regs[REG_LOSC] |= REG_LOSC_YMD;
550
+ break;
551
+ case REG_HHMMSS: /* RTC Hour-Minute-Second */
552
+ s->regs[REG_HHMMSS] = val;
553
+ s->regs[REG_LOSC] |= REG_LOSC_HMS;
554
+ break;
555
+ case REG_GP0: /* General Purpose Register 0 */
556
+ case REG_GP1: /* General Purpose Register 1 */
557
+ case REG_GP2: /* General Purpose Register 2 */
558
+ case REG_GP3: /* General Purpose Register 3 */
559
+ s->regs[c->regmap[offset]] = val;
560
+ break;
561
+ default:
562
+ if (!c->write(s, offset, val)) {
563
+ qemu_log_mask(LOG_UNIMP, "%s: unimplemented register 0x%04x\n",
564
+ __func__, (uint32_t)offset);
565
+ }
566
+ break;
567
+ }
568
+}
569
+
570
+static const MemoryRegionOps allwinner_rtc_ops = {
571
+ .read = allwinner_rtc_read,
572
+ .write = allwinner_rtc_write,
573
+ .endianness = DEVICE_NATIVE_ENDIAN,
574
+ .valid = {
575
+ .min_access_size = 4,
576
+ .max_access_size = 4,
577
+ },
578
+ .impl.min_access_size = 4,
579
+};
580
+
581
+static void allwinner_rtc_reset(DeviceState *dev)
582
+{
583
+ AwRtcState *s = AW_RTC(dev);
584
+ struct tm now;
585
+
586
+ /* Clear registers */
587
+ memset(s->regs, 0, sizeof(s->regs));
588
+
589
+ /* Get current datetime */
590
+ qemu_get_timedate(&now, 0);
591
+
592
+ /* Set RTC with current datetime */
593
+ if (s->base_year > 1900) {
594
+ s->regs[REG_YYMMDD] = ((now.tm_year + 1900 - s->base_year) << 16) |
595
+ ((now.tm_mon + 1) << 8) |
596
+ now.tm_mday;
597
+ s->regs[REG_HHMMSS] = (((now.tm_wday + 6) % 7) << 29) |
598
+ (now.tm_hour << 16) |
599
+ (now.tm_min << 8) |
600
+ now.tm_sec;
601
+ }
602
+}
603
+
604
+static void allwinner_rtc_init(Object *obj)
605
+{
606
+ SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
607
+ AwRtcState *s = AW_RTC(obj);
608
+
609
+ /* Memory mapping */
610
+ memory_region_init_io(&s->iomem, OBJECT(s), &allwinner_rtc_ops, s,
611
+ TYPE_AW_RTC, 1 * KiB);
612
+ sysbus_init_mmio(sbd, &s->iomem);
613
+}
614
+
615
+static const VMStateDescription allwinner_rtc_vmstate = {
616
+ .name = "allwinner-rtc",
617
+ .version_id = 1,
618
+ .minimum_version_id = 1,
619
+ .fields = (VMStateField[]) {
620
+ VMSTATE_UINT32_ARRAY(regs, AwRtcState, AW_RTC_REGS_NUM),
621
+ VMSTATE_END_OF_LIST()
622
+ }
623
+};
624
+
625
+static Property allwinner_rtc_properties[] = {
626
+ DEFINE_PROP_INT32("base-year", AwRtcState, base_year, 0),
627
+ DEFINE_PROP_END_OF_LIST(),
628
+};
629
+
630
+static void allwinner_rtc_class_init(ObjectClass *klass, void *data)
631
+{
632
+ DeviceClass *dc = DEVICE_CLASS(klass);
633
+
634
+ dc->reset = allwinner_rtc_reset;
635
+ dc->vmsd = &allwinner_rtc_vmstate;
636
+ device_class_set_props(dc, allwinner_rtc_properties);
637
+}
638
+
639
+static void allwinner_rtc_sun4i_init(Object *obj)
640
+{
641
+ AwRtcState *s = AW_RTC(obj);
642
+ s->base_year = 2010;
643
+}
644
+
645
+static void allwinner_rtc_sun4i_class_init(ObjectClass *klass, void *data)
646
+{
647
+ AwRtcClass *arc = AW_RTC_CLASS(klass);
648
+
649
+ arc->regmap = allwinner_rtc_sun4i_regmap;
650
+ arc->regmap_size = sizeof(allwinner_rtc_sun4i_regmap);
651
+ arc->read = allwinner_rtc_sun4i_read;
652
+ arc->write = allwinner_rtc_sun4i_write;
653
+}
654
+
655
+static void allwinner_rtc_sun6i_init(Object *obj)
656
+{
657
+ AwRtcState *s = AW_RTC(obj);
658
+ s->base_year = 1970;
659
+}
660
+
661
+static void allwinner_rtc_sun6i_class_init(ObjectClass *klass, void *data)
662
+{
663
+ AwRtcClass *arc = AW_RTC_CLASS(klass);
664
+
665
+ arc->regmap = allwinner_rtc_sun6i_regmap;
666
+ arc->regmap_size = sizeof(allwinner_rtc_sun6i_regmap);
667
+ arc->read = allwinner_rtc_sun6i_read;
668
+ arc->write = allwinner_rtc_sun6i_write;
669
+}
670
+
671
+static void allwinner_rtc_sun7i_init(Object *obj)
672
+{
673
+ AwRtcState *s = AW_RTC(obj);
674
+ s->base_year = 1970;
675
+}
676
+
677
+static void allwinner_rtc_sun7i_class_init(ObjectClass *klass, void *data)
678
+{
679
+ AwRtcClass *arc = AW_RTC_CLASS(klass);
680
+ allwinner_rtc_sun4i_class_init(klass, arc);
681
+}
682
+
683
+static const TypeInfo allwinner_rtc_info = {
684
+ .name = TYPE_AW_RTC,
685
+ .parent = TYPE_SYS_BUS_DEVICE,
686
+ .instance_init = allwinner_rtc_init,
687
+ .instance_size = sizeof(AwRtcState),
688
+ .class_init = allwinner_rtc_class_init,
689
+ .class_size = sizeof(AwRtcClass),
690
+ .abstract = true,
691
+};
692
+
693
+static const TypeInfo allwinner_rtc_sun4i_info = {
694
+ .name = TYPE_AW_RTC_SUN4I,
695
+ .parent = TYPE_AW_RTC,
696
+ .class_init = allwinner_rtc_sun4i_class_init,
697
+ .instance_init = allwinner_rtc_sun4i_init,
698
+};
699
+
700
+static const TypeInfo allwinner_rtc_sun6i_info = {
701
+ .name = TYPE_AW_RTC_SUN6I,
702
+ .parent = TYPE_AW_RTC,
703
+ .class_init = allwinner_rtc_sun6i_class_init,
704
+ .instance_init = allwinner_rtc_sun6i_init,
705
+};
706
+
707
+static const TypeInfo allwinner_rtc_sun7i_info = {
708
+ .name = TYPE_AW_RTC_SUN7I,
709
+ .parent = TYPE_AW_RTC,
710
+ .class_init = allwinner_rtc_sun7i_class_init,
711
+ .instance_init = allwinner_rtc_sun7i_init,
712
+};
713
+
714
+static void allwinner_rtc_register(void)
715
+{
716
+ type_register_static(&allwinner_rtc_info);
717
+ type_register_static(&allwinner_rtc_sun4i_info);
718
+ type_register_static(&allwinner_rtc_sun6i_info);
719
+ type_register_static(&allwinner_rtc_sun7i_info);
720
+}
721
+
722
+type_init(allwinner_rtc_register)
723
diff --git a/hw/rtc/trace-events b/hw/rtc/trace-events
724
index XXXXXXX..XXXXXXX 100644
725
--- a/hw/rtc/trace-events
726
+++ b/hw/rtc/trace-events
727
@@ -XXX,XX +XXX,XX @@
728
# See docs/devel/tracing.txt for syntax documentation.
729
730
+# allwinner-rtc.c
731
+allwinner_rtc_read(uint64_t addr, uint64_t value) "addr 0x%" PRIx64 " value 0x%" PRIx64
732
+allwinner_rtc_write(uint64_t addr, uint64_t value) "addr 0x%" PRIx64 " value 0x%" PRIx64
733
+
734
# sun4v-rtc.c
735
sun4v_rtc_read(uint64_t addr, uint64_t value) "read: addr 0x%" PRIx64 " value 0x%" PRIx64
736
sun4v_rtc_write(uint64_t addr, uint64_t value) "write: addr 0x%" PRIx64 " value 0x%" PRIx64
737
--
69
--
738
2.20.1
70
2.34.1
739
740
diff view generated by jsdifflib
1
From: Cédric Le Goater <clg@kaod.org>
1
From: Jinjie Ruan <ruanjinjie@huawei.com>
2
2
3
The Aspeed SMC Controller can operate in different modes : Read, Fast
3
This only implements the external delivery method via the GICv3.
4
Read, Write and User modes. When the User mode is configured, it
5
selects automatically the SPI slave device until the CE_STOP_ACTIVE
6
bit is set to 1. When any other modes are configured the device is
7
unselected. The HW logic handles the chip select automatically when
8
the flash is accessed through its AHB window.
9
4
10
When configuring the CEx Control Register, the User mode logic to
5
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
11
select and unselect the slave is incorrect and data corruption can be
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
12
seen on machines using two chips, witherspoon and romulus.
7
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
13
8
Message-id: 20240407081733.3231820-7-ruanjinjie@huawei.com
14
Rework the handler setting the CEx Control Register to fix this issue.
15
16
Fixes: 7c1c69bca43c ("ast2400: add SMC controllers (FMC and SPI)")
17
Signed-off-by: Cédric Le Goater <clg@kaod.org>
18
Reviewed-by: Andrew Jeffery <andrew@aj.id.au>
19
Message-id: 20200206112645.21275-3-clg@kaod.org
20
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
21
---
10
---
22
hw/ssi/aspeed_smc.c | 39 +++++++++++++++++++++++----------------
11
target/arm/cpu-qom.h | 5 +-
23
hw/ssi/trace-events | 1 +
12
target/arm/cpu.h | 6 ++
24
2 files changed, 24 insertions(+), 16 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(-)
25
17
26
diff --git a/hw/ssi/aspeed_smc.c b/hw/ssi/aspeed_smc.c
18
diff --git a/target/arm/cpu-qom.h b/target/arm/cpu-qom.h
27
index XXXXXXX..XXXXXXX 100644
19
index XXXXXXX..XXXXXXX 100644
28
--- a/hw/ssi/aspeed_smc.c
20
--- a/target/arm/cpu-qom.h
29
+++ b/hw/ssi/aspeed_smc.c
21
+++ b/target/arm/cpu-qom.h
30
@@ -XXX,XX +XXX,XX @@ static inline int aspeed_smc_flash_is_4byte(const AspeedSMCFlash *fl)
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
38
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
39
index XXXXXXX..XXXXXXX 100644
40
--- a/target/arm/cpu.h
41
+++ b/target/arm/cpu.h
42
@@ -XXX,XX +XXX,XX @@
43
#define EXCP_DIVBYZERO 23 /* v7M DIVBYZERO UsageFault */
44
#define EXCP_VSERR 24
45
#define EXCP_GPC 25 /* v9 Granule Protection Check Fault */
46
+#define EXCP_NMI 26
47
+#define EXCP_VINMI 27
48
+#define EXCP_VFNMI 28
49
/* NB: add new EXCP_ defines to the array in arm_log_exception() too */
50
51
#define ARMV7M_EXCP_RESET 1
52
@@ -XXX,XX +XXX,XX @@
53
#define CPU_INTERRUPT_VIRQ CPU_INTERRUPT_TGT_EXT_2
54
#define CPU_INTERRUPT_VFIQ CPU_INTERRUPT_TGT_EXT_3
55
#define CPU_INTERRUPT_VSERR CPU_INTERRUPT_TGT_INT_0
56
+#define CPU_INTERRUPT_NMI CPU_INTERRUPT_TGT_EXT_4
57
+#define CPU_INTERRUPT_VINMI CPU_INTERRUPT_TGT_EXT_0
58
+#define CPU_INTERRUPT_VFNMI CPU_INTERRUPT_TGT_INT_1
59
60
/* The usual mapping for an AArch64 system register to its AArch32
61
* counterpart is for the 32 bit world to have access to the lower
62
diff --git a/target/arm/internals.h b/target/arm/internals.h
63
index XXXXXXX..XXXXXXX 100644
64
--- a/target/arm/internals.h
65
+++ b/target/arm/internals.h
66
@@ -XXX,XX +XXX,XX @@ void arm_cpu_update_virq(ARMCPU *cpu);
67
*/
68
void arm_cpu_update_vfiq(ARMCPU *cpu);
69
70
+/**
71
+ * arm_cpu_update_vinmi: Update CPU_INTERRUPT_VINMI bit in cs->interrupt_request
72
+ *
73
+ * Update the CPU_INTERRUPT_VINMI bit in cs->interrupt_request, following
74
+ * a change to either the input VNMI line from the GIC or the HCRX_EL2.VINMI.
75
+ * Must be called with the BQL held.
76
+ */
77
+void arm_cpu_update_vinmi(ARMCPU *cpu);
78
+
79
+/**
80
+ * arm_cpu_update_vfnmi: Update CPU_INTERRUPT_VFNMI bit in cs->interrupt_request
81
+ *
82
+ * Update the CPU_INTERRUPT_VFNMI bit in cs->interrupt_request, following
83
+ * a change to the HCRX_EL2.VFNMI.
84
+ * Must be called with the BQL held.
85
+ */
86
+void arm_cpu_update_vfnmi(ARMCPU *cpu);
87
+
88
/**
89
* arm_cpu_update_vserr: Update CPU_INTERRUPT_VSERR bit
90
*
91
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
92
index XXXXXXX..XXXXXXX 100644
93
--- a/target/arm/cpu.c
94
+++ b/target/arm/cpu.c
95
@@ -XXX,XX +XXX,XX @@ void arm_restore_state_to_opc(CPUState *cs,
96
}
97
#endif /* CONFIG_TCG */
98
99
+/*
100
+ * With SCTLR_ELx.NMI == 0, IRQ with Superpriority is masked identically with
101
+ * IRQ without Superpriority. Moreover, if the GIC is configured so that
102
+ * FEAT_GICv3_NMI is only set if FEAT_NMI is set, then we won't ever see
103
+ * CPU_INTERRUPT_*NMI anyway. So we might as well accept NMI here
104
+ * unconditionally.
105
+ */
106
static bool arm_cpu_has_work(CPUState *cs)
107
{
108
ARMCPU *cpu = ARM_CPU(cs);
109
@@ -XXX,XX +XXX,XX @@ static bool arm_cpu_has_work(CPUState *cs)
110
return (cpu->power_state != PSCI_OFF)
111
&& cs->interrupt_request &
112
(CPU_INTERRUPT_FIQ | CPU_INTERRUPT_HARD
113
+ | CPU_INTERRUPT_NMI | CPU_INTERRUPT_VINMI | CPU_INTERRUPT_VFNMI
114
| CPU_INTERRUPT_VFIQ | CPU_INTERRUPT_VIRQ | CPU_INTERRUPT_VSERR
115
| CPU_INTERRUPT_EXITTB);
116
}
117
@@ -XXX,XX +XXX,XX @@ static inline bool arm_excp_unmasked(CPUState *cs, unsigned int excp_idx,
118
CPUARMState *env = cpu_env(cs);
119
bool pstate_unmasked;
120
bool unmasked = false;
121
+ bool allIntMask = false;
122
123
/*
124
* Don't take exceptions if they target a lower EL.
125
@@ -XXX,XX +XXX,XX @@ static inline bool arm_excp_unmasked(CPUState *cs, unsigned int excp_idx,
126
return false;
127
}
128
129
+ if (cpu_isar_feature(aa64_nmi, env_archcpu(env)) &&
130
+ env->cp15.sctlr_el[target_el] & SCTLR_NMI && cur_el == target_el) {
131
+ allIntMask = env->pstate & PSTATE_ALLINT ||
132
+ ((env->cp15.sctlr_el[target_el] & SCTLR_SPINTMASK) &&
133
+ (env->pstate & PSTATE_SP));
134
+ }
135
+
136
switch (excp_idx) {
137
+ case EXCP_NMI:
138
+ pstate_unmasked = !allIntMask;
139
+ break;
140
+
141
+ case EXCP_VINMI:
142
+ if (!(hcr_el2 & HCR_IMO) || (hcr_el2 & HCR_TGE)) {
143
+ /* VINMIs are only taken when hypervized. */
144
+ return false;
145
+ }
146
+ return !allIntMask;
147
+ case EXCP_VFNMI:
148
+ if (!(hcr_el2 & HCR_FMO) || (hcr_el2 & HCR_TGE)) {
149
+ /* VFNMIs are only taken when hypervized. */
150
+ return false;
151
+ }
152
+ return !allIntMask;
153
case EXCP_FIQ:
154
- pstate_unmasked = !(env->daif & PSTATE_F);
155
+ pstate_unmasked = (!(env->daif & PSTATE_F)) && (!allIntMask);
156
break;
157
158
case EXCP_IRQ:
159
- pstate_unmasked = !(env->daif & PSTATE_I);
160
+ pstate_unmasked = (!(env->daif & PSTATE_I)) && (!allIntMask);
161
break;
162
163
case EXCP_VFIQ:
164
@@ -XXX,XX +XXX,XX @@ static inline bool arm_excp_unmasked(CPUState *cs, unsigned int excp_idx,
165
/* VFIQs are only taken when hypervized. */
166
return false;
167
}
168
- return !(env->daif & PSTATE_F);
169
+ return !(env->daif & PSTATE_F) && (!allIntMask);
170
case EXCP_VIRQ:
171
if (!(hcr_el2 & HCR_IMO) || (hcr_el2 & HCR_TGE)) {
172
/* VIRQs are only taken when hypervized. */
173
return false;
174
}
175
- return !(env->daif & PSTATE_I);
176
+ return !(env->daif & PSTATE_I) && (!allIntMask);
177
case EXCP_VSERR:
178
if (!(hcr_el2 & HCR_AMO) || (hcr_el2 & HCR_TGE)) {
179
/* VIRQs are only taken when hypervized. */
180
@@ -XXX,XX +XXX,XX @@ static bool arm_cpu_exec_interrupt(CPUState *cs, int interrupt_request)
181
182
/* The prioritization of interrupts is IMPLEMENTATION DEFINED. */
183
184
+ if (cpu_isar_feature(aa64_nmi, env_archcpu(env)) &&
185
+ (arm_sctlr(env, cur_el) & SCTLR_NMI)) {
186
+ if (interrupt_request & CPU_INTERRUPT_NMI) {
187
+ excp_idx = EXCP_NMI;
188
+ target_el = arm_phys_excp_target_el(cs, excp_idx, cur_el, secure);
189
+ if (arm_excp_unmasked(cs, excp_idx, target_el,
190
+ cur_el, secure, hcr_el2)) {
191
+ goto found;
192
+ }
193
+ }
194
+ if (interrupt_request & CPU_INTERRUPT_VINMI) {
195
+ excp_idx = EXCP_VINMI;
196
+ target_el = 1;
197
+ if (arm_excp_unmasked(cs, excp_idx, target_el,
198
+ cur_el, secure, hcr_el2)) {
199
+ goto found;
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)
31
}
250
}
32
}
251
}
33
252
34
-static inline bool aspeed_smc_is_ce_stop_active(const AspeedSMCFlash *fl)
253
+void arm_cpu_update_vinmi(ARMCPU *cpu)
35
+static void aspeed_smc_flash_do_select(AspeedSMCFlash *fl, bool unselect)
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)
36
{
296
{
37
- const AspeedSMCState *s = fl->controller;
297
/*
38
+ AspeedSMCState *s = fl->controller;
298
@@ -XXX,XX +XXX,XX @@ static void arm_cpu_set_irq(void *opaque, int irq, int level)
39
299
[ARM_CPU_IRQ] = CPU_INTERRUPT_HARD,
40
- return s->regs[s->r_ctrl0 + fl->id] & CTRL_CE_STOP_ACTIVE;
300
[ARM_CPU_FIQ] = CPU_INTERRUPT_FIQ,
41
+ trace_aspeed_smc_flash_select(fl->id, unselect ? "un" : "");
301
[ARM_CPU_VIRQ] = CPU_INTERRUPT_VIRQ,
42
+
302
- [ARM_CPU_VFIQ] = CPU_INTERRUPT_VFIQ
43
+ qemu_set_irq(s->cs_lines[fl->id], unselect);
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
+ }
44
}
365
}
45
366
46
static void aspeed_smc_flash_select(AspeedSMCFlash *fl)
367
static void hcr_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value)
47
{
368
@@ -XXX,XX +XXX,XX @@ static void hcrx_write(CPUARMState *env, const ARMCPRegInfo *ri,
48
- AspeedSMCState *s = fl->controller;
369
49
-
370
/* Clear RES0 bits. */
50
- s->regs[s->r_ctrl0 + fl->id] &= ~CTRL_CE_STOP_ACTIVE;
371
env->cp15.hcrx_el2 = value & valid_mask;
51
- qemu_set_irq(s->cs_lines[fl->id], aspeed_smc_is_ce_stop_active(fl));
372
+
52
+ aspeed_smc_flash_do_select(fl, false);
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
+ }
53
}
389
}
54
390
55
static void aspeed_smc_flash_unselect(AspeedSMCFlash *fl)
391
static CPAccessResult access_hxen(CPUARMState *env, const ARMCPRegInfo *ri,
56
{
392
@@ -XXX,XX +XXX,XX @@ static CPAccessResult access_hxen(CPUARMState *env, const ARMCPRegInfo *ri,
57
- AspeedSMCState *s = fl->controller;
393
58
-
394
static const ARMCPRegInfo hcrx_el2_reginfo = {
59
- s->regs[s->r_ctrl0 + fl->id] |= CTRL_CE_STOP_ACTIVE;
395
.name = "HCRX_EL2", .state = ARM_CP_STATE_AA64,
60
- qemu_set_irq(s->cs_lines[fl->id], aspeed_smc_is_ce_stop_active(fl));
396
+ .type = ARM_CP_IO,
61
+ aspeed_smc_flash_do_select(fl, true);
397
.opc0 = 3, .opc1 = 4, .crn = 1, .crm = 2, .opc2 = 2,
62
}
398
.access = PL2_RW, .writefn = hcrx_write, .accessfn = access_hxen,
63
399
.nv2_redirect_offset = 0xa0,
64
static uint32_t aspeed_smc_check_segment_addr(const AspeedSMCFlash *fl,
400
@@ -XXX,XX +XXX,XX @@ void arm_log_exception(CPUState *cs)
65
@@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps aspeed_smc_flash_ops = {
401
[EXCP_DIVBYZERO] = "v7M DIVBYZERO UsageFault",
66
},
402
[EXCP_VSERR] = "Virtual SERR",
67
};
403
[EXCP_GPC] = "Granule Protection Check",
68
404
+ [EXCP_NMI] = "NMI",
69
-static void aspeed_smc_flash_update_cs(AspeedSMCFlash *fl)
405
+ [EXCP_VINMI] = "Virtual IRQ NMI",
70
+static void aspeed_smc_flash_update_ctrl(AspeedSMCFlash *fl, uint32_t value)
406
+ [EXCP_VFNMI] = "Virtual FIQ NMI",
71
{
407
};
72
AspeedSMCState *s = fl->controller;
408
73
+ bool unselect;
409
if (idx >= 0 && idx < ARRAY_SIZE(excnames)) {
74
75
- s->snoop_index = aspeed_smc_is_ce_stop_active(fl) ? SNOOP_OFF : SNOOP_START;
76
+ /* User mode selects the CS, other modes unselect */
77
+ unselect = (value & CTRL_CMD_MODE_MASK) != CTRL_USERMODE;
78
79
- qemu_set_irq(s->cs_lines[fl->id], aspeed_smc_is_ce_stop_active(fl));
80
+ /* A change of CTRL_CE_STOP_ACTIVE from 0 to 1, unselects the CS */
81
+ if (!(s->regs[s->r_ctrl0 + fl->id] & CTRL_CE_STOP_ACTIVE) &&
82
+ value & CTRL_CE_STOP_ACTIVE) {
83
+ unselect = true;
84
+ }
85
+
86
+ s->regs[s->r_ctrl0 + fl->id] = value;
87
+
88
+ s->snoop_index = unselect ? SNOOP_OFF : SNOOP_START;
89
+
90
+ aspeed_smc_flash_do_select(fl, unselect);
91
}
92
93
static void aspeed_smc_reset(DeviceState *d)
94
@@ -XXX,XX +XXX,XX @@ static void aspeed_smc_write(void *opaque, hwaddr addr, uint64_t data,
95
s->regs[addr] = value;
96
} else if (addr >= s->r_ctrl0 && addr < s->r_ctrl0 + s->num_cs) {
97
int cs = addr - s->r_ctrl0;
98
- s->regs[addr] = value;
99
- aspeed_smc_flash_update_cs(&s->flashes[cs]);
100
+ aspeed_smc_flash_update_ctrl(&s->flashes[cs], value);
101
} else if (addr >= R_SEG_ADDR0 &&
102
addr < R_SEG_ADDR0 + s->ctrl->max_slaves) {
103
int cs = addr - R_SEG_ADDR0;
104
diff --git a/hw/ssi/trace-events b/hw/ssi/trace-events
105
index XXXXXXX..XXXXXXX 100644
106
--- a/hw/ssi/trace-events
107
+++ b/hw/ssi/trace-events
108
@@ -XXX,XX +XXX,XX @@ aspeed_smc_flash_write(int cs, uint64_t addr, uint32_t size, uint64_t data, int
109
aspeed_smc_read(uint64_t addr, uint32_t size, uint64_t data) "@0x%" PRIx64 " size %u: 0x%" PRIx64
110
aspeed_smc_dma_checksum(uint32_t addr, uint32_t data) "0x%08x: 0x%08x"
111
aspeed_smc_write(uint64_t addr, uint32_t size, uint64_t data) "@0x%" PRIx64 " size %u: 0x%" PRIx64
112
+aspeed_smc_flash_select(int cs, const char *prefix) "CS%d %sselect"
113
--
410
--
114
2.20.1
411
2.34.1
115
116
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Jinjie Ruan <ruanjinjie@huawei.com>
2
2
3
We fail to validate the upper bits of a virtual address on a
3
According to Arm GIC section 4.6.3 Interrupt superpriority, the interrupt
4
translation disabled regime, as per AArch64.TranslateAddressS1Off.
4
with superpriority is always IRQ, never FIQ, so handle NMI same as IRQ in
5
arm_phys_excp_target_el().
5
6
6
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
7
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
7
Message-id: 20200308012946.16303-2-richard.henderson@linaro.org
8
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
9
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
10
Message-id: 20240407081733.3231820-8-ruanjinjie@huawei.com
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
---
12
---
11
target/arm/helper.c | 35 ++++++++++++++++++++++++++++++++++-
13
target/arm/helper.c | 1 +
12
1 file changed, 34 insertions(+), 1 deletion(-)
14
1 file changed, 1 insertion(+)
13
15
14
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
15
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
16
--- a/target/arm/helper.c
18
--- a/target/arm/helper.c
17
+++ b/target/arm/helper.c
19
+++ b/target/arm/helper.c
18
@@ -XXX,XX +XXX,XX @@ bool get_phys_addr(CPUARMState *env, target_ulong address,
20
@@ -XXX,XX +XXX,XX @@ uint32_t arm_phys_excp_target_el(CPUState *cs, uint32_t excp_idx,
19
/* Definitely a real MMU, not an MPU */
21
hcr_el2 = arm_hcr_el2_eff(env);
20
22
switch (excp_idx) {
21
if (regime_translation_disabled(env, mmu_idx)) {
23
case EXCP_IRQ:
22
- /* MMU disabled. */
24
+ case EXCP_NMI:
23
+ /*
25
scr = ((env->cp15.scr_el3 & SCR_IRQ) == SCR_IRQ);
24
+ * MMU disabled. S1 addresses within aa64 translation regimes are
26
hcr = hcr_el2 & HCR_IMO;
25
+ * still checked for bounds -- see AArch64.TranslateAddressS1Off.
27
break;
26
+ */
27
+ if (mmu_idx != ARMMMUIdx_Stage2) {
28
+ int r_el = regime_el(env, mmu_idx);
29
+ if (arm_el_is_aa64(env, r_el)) {
30
+ int pamax = arm_pamax(env_archcpu(env));
31
+ uint64_t tcr = env->cp15.tcr_el[r_el].raw_tcr;
32
+ int addrtop, tbi;
33
+
34
+ tbi = aa64_va_parameter_tbi(tcr, mmu_idx);
35
+ if (access_type == MMU_INST_FETCH) {
36
+ tbi &= ~aa64_va_parameter_tbid(tcr, mmu_idx);
37
+ }
38
+ tbi = (tbi >> extract64(address, 55, 1)) & 1;
39
+ addrtop = (tbi ? 55 : 63);
40
+
41
+ if (extract64(address, pamax, addrtop - pamax + 1) != 0) {
42
+ fi->type = ARMFault_AddressSize;
43
+ fi->level = 0;
44
+ fi->stage2 = false;
45
+ return 1;
46
+ }
47
+
48
+ /*
49
+ * When TBI is disabled, we've just validated that all of the
50
+ * bits above PAMax are zero, so logically we only need to
51
+ * clear the top byte for TBI. But it's clearer to follow
52
+ * the pseudocode set of addrdesc.paddress.
53
+ */
54
+ address = extract64(address, 0, 52);
55
+ }
56
+ }
57
*phys_ptr = address;
58
*prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;
59
*page_size = TARGET_PAGE_SIZE;
60
--
28
--
61
2.20.1
29
2.34.1
62
63
diff view generated by jsdifflib
1
From: Igor Mammedov <imammedo@redhat.com>
1
From: Jinjie Ruan <ruanjinjie@huawei.com>
2
2
3
SOC object returned by object_new() is leaked in current code.
3
Add IS and FS bit in ISR_EL1 and handle the read. With CPU_INTERRUPT_NMI or
4
Set SOC parent explicitly to board and then unref to SOC object
4
CPU_INTERRUPT_VINMI, both CPSR_I and ISR_IS must be set. With
5
to make sure that refererence returned by object_new() is taken
5
CPU_INTERRUPT_VFNMI, both CPSR_F and ISR_FS must be set.
6
care of.
7
6
8
The SOC object will be kept alive by its parent (machine) and
7
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
9
will be automatically freed when MachineState is destroyed.
8
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
10
11
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
12
Reported-by: Andrew Jones <drjones@redhat.com>
13
Tested-by: Niek Linnenbank <nieklinnenbank@gmail.com>
14
Message-id: 20200303091254.22373-1-imammedo@redhat.com
15
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
9
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
10
Message-id: 20240407081733.3231820-9-ruanjinjie@huawei.com
16
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
17
---
12
---
18
hw/arm/cubieboard.c | 3 +++
13
target/arm/cpu.h | 2 ++
19
1 file changed, 3 insertions(+)
14
target/arm/helper.c | 13 +++++++++++++
15
2 files changed, 15 insertions(+)
20
16
21
diff --git a/hw/arm/cubieboard.c b/hw/arm/cubieboard.c
17
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
22
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
23
--- a/hw/arm/cubieboard.c
19
--- a/target/arm/cpu.h
24
+++ b/hw/arm/cubieboard.c
20
+++ b/target/arm/cpu.h
25
@@ -XXX,XX +XXX,XX @@ static void cubieboard_init(MachineState *machine)
21
@@ -XXX,XX +XXX,XX @@ void pmu_init(ARMCPU *cpu);
22
#define CPSR_N (1U << 31)
23
#define CPSR_NZCV (CPSR_N | CPSR_Z | CPSR_C | CPSR_V)
24
#define CPSR_AIF (CPSR_A | CPSR_I | CPSR_F)
25
+#define ISR_FS (1U << 9)
26
+#define ISR_IS (1U << 10)
27
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 \
30
diff --git a/target/arm/helper.c b/target/arm/helper.c
31
index XXXXXXX..XXXXXXX 100644
32
--- a/target/arm/helper.c
33
+++ b/target/arm/helper.c
34
@@ -XXX,XX +XXX,XX @@ static uint64_t isr_read(CPUARMState *env, const ARMCPRegInfo *ri)
35
if (cs->interrupt_request & CPU_INTERRUPT_VIRQ) {
36
ret |= CPSR_I;
37
}
38
+ if (cs->interrupt_request & CPU_INTERRUPT_VINMI) {
39
+ ret |= ISR_IS;
40
+ ret |= CPSR_I;
41
+ }
42
} else {
43
if (cs->interrupt_request & CPU_INTERRUPT_HARD) {
44
ret |= CPSR_I;
45
}
46
+
47
+ if (cs->interrupt_request & CPU_INTERRUPT_NMI) {
48
+ ret |= ISR_IS;
49
+ ret |= CPSR_I;
50
+ }
26
}
51
}
27
52
28
a10 = AW_A10(object_new(TYPE_AW_A10));
53
if (hcr_el2 & HCR_FMO) {
29
+ object_property_add_child(OBJECT(machine), "soc", OBJECT(a10),
54
if (cs->interrupt_request & CPU_INTERRUPT_VFIQ) {
30
+ &error_abort);
55
ret |= CPSR_F;
31
+ object_unref(OBJECT(a10));
56
}
32
57
+ if (cs->interrupt_request & CPU_INTERRUPT_VFNMI) {
33
object_property_set_int(OBJECT(&a10->emac), 1, "phy-addr", &err);
58
+ ret |= ISR_FS;
34
if (err != NULL) {
59
+ ret |= CPSR_F;
60
+ }
61
} else {
62
if (cs->interrupt_request & CPU_INTERRUPT_FIQ) {
63
ret |= CPSR_F;
35
--
64
--
36
2.20.1
65
2.34.1
37
38
diff view generated by jsdifflib
1
From: Niek Linnenbank <nieklinnenbank@gmail.com>
1
From: Jinjie Ruan <ruanjinjie@huawei.com>
2
2
3
The Allwinner Sun8i System on Chip family includes an Ethernet MAC (EMAC)
3
Set or clear PSTATE.ALLINT on taking an exception to ELx according to the
4
which provides 10M/100M/1000M Ethernet connectivity. This commit
4
SCTLR_ELx.SPINTMASK bit.
5
adds support for the Allwinner EMAC from the Sun8i family (H2+, H3, A33, etc),
6
including emulation for the following functionality:
7
5
8
* DMA transfers
6
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
9
* MII interface
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
10
* Transmit CRC calculation
8
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
11
9
Message-id: 20240407081733.3231820-10-ruanjinjie@huawei.com
12
Signed-off-by: Niek Linnenbank <nieklinnenbank@gmail.com>
13
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
14
Message-id: 20200311221854.30370-10-nieklinnenbank@gmail.com
15
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
16
---
11
---
17
hw/net/Makefile.objs | 1 +
12
target/arm/helper.c | 8 ++++++++
18
include/hw/arm/allwinner-h3.h | 3 +
13
1 file changed, 8 insertions(+)
19
include/hw/net/allwinner-sun8i-emac.h | 99 +++
20
hw/arm/allwinner-h3.c | 16 +-
21
hw/arm/orangepi.c | 3 +
22
hw/net/allwinner-sun8i-emac.c | 871 ++++++++++++++++++++++++++
23
hw/arm/Kconfig | 1 +
24
hw/net/Kconfig | 3 +
25
hw/net/trace-events | 10 +
26
9 files changed, 1006 insertions(+), 1 deletion(-)
27
create mode 100644 include/hw/net/allwinner-sun8i-emac.h
28
create mode 100644 hw/net/allwinner-sun8i-emac.c
29
14
30
diff --git a/hw/net/Makefile.objs b/hw/net/Makefile.objs
15
diff --git a/target/arm/helper.c b/target/arm/helper.c
31
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
32
--- a/hw/net/Makefile.objs
17
--- a/target/arm/helper.c
33
+++ b/hw/net/Makefile.objs
18
+++ b/target/arm/helper.c
34
@@ -XXX,XX +XXX,XX @@ common-obj-$(CONFIG_XGMAC) += xgmac.o
19
@@ -XXX,XX +XXX,XX @@ static void arm_cpu_do_interrupt_aarch64(CPUState *cs)
35
common-obj-$(CONFIG_MIPSNET) += mipsnet.o
20
}
36
common-obj-$(CONFIG_XILINX_AXI) += xilinx_axienet.o
37
common-obj-$(CONFIG_ALLWINNER_EMAC) += allwinner_emac.o
38
+common-obj-$(CONFIG_ALLWINNER_SUN8I_EMAC) += allwinner-sun8i-emac.o
39
common-obj-$(CONFIG_IMX_FEC) += imx_fec.o
40
41
common-obj-$(CONFIG_CADENCE) += cadence_gem.o
42
diff --git a/include/hw/arm/allwinner-h3.h b/include/hw/arm/allwinner-h3.h
43
index XXXXXXX..XXXXXXX 100644
44
--- a/include/hw/arm/allwinner-h3.h
45
+++ b/include/hw/arm/allwinner-h3.h
46
@@ -XXX,XX +XXX,XX @@
47
#include "hw/misc/allwinner-h3-sysctrl.h"
48
#include "hw/misc/allwinner-sid.h"
49
#include "hw/sd/allwinner-sdhost.h"
50
+#include "hw/net/allwinner-sun8i-emac.h"
51
#include "target/arm/cpu.h"
52
53
/**
54
@@ -XXX,XX +XXX,XX @@ enum {
55
AW_H3_UART1,
56
AW_H3_UART2,
57
AW_H3_UART3,
58
+ AW_H3_EMAC,
59
AW_H3_GIC_DIST,
60
AW_H3_GIC_CPU,
61
AW_H3_GIC_HYP,
62
@@ -XXX,XX +XXX,XX @@ typedef struct AwH3State {
63
AwH3SysCtrlState sysctrl;
64
AwSidState sid;
65
AwSdHostState mmc0;
66
+ AwSun8iEmacState emac;
67
GICState gic;
68
MemoryRegion sram_a1;
69
MemoryRegion sram_a2;
70
diff --git a/include/hw/net/allwinner-sun8i-emac.h b/include/hw/net/allwinner-sun8i-emac.h
71
new file mode 100644
72
index XXXXXXX..XXXXXXX
73
--- /dev/null
74
+++ b/include/hw/net/allwinner-sun8i-emac.h
75
@@ -XXX,XX +XXX,XX @@
76
+/*
77
+ * Allwinner Sun8i Ethernet MAC emulation
78
+ *
79
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
80
+ *
81
+ * This program is free software: you can redistribute it and/or modify
82
+ * it under the terms of the GNU General Public License as published by
83
+ * the Free Software Foundation, either version 2 of the License, or
84
+ * (at your option) any later version.
85
+ *
86
+ * This program is distributed in the hope that it will be useful,
87
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
88
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
89
+ * GNU General Public License for more details.
90
+ *
91
+ * You should have received a copy of the GNU General Public License
92
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
93
+ */
94
+
95
+#ifndef HW_NET_ALLWINNER_SUN8I_EMAC_H
96
+#define HW_NET_ALLWINNER_SUN8I_EMAC_H
97
+
98
+#include "qom/object.h"
99
+#include "net/net.h"
100
+#include "hw/sysbus.h"
101
+
102
+/**
103
+ * Object model
104
+ * @{
105
+ */
106
+
107
+#define TYPE_AW_SUN8I_EMAC "allwinner-sun8i-emac"
108
+#define AW_SUN8I_EMAC(obj) \
109
+ OBJECT_CHECK(AwSun8iEmacState, (obj), TYPE_AW_SUN8I_EMAC)
110
+
111
+/** @} */
112
+
113
+/**
114
+ * Allwinner Sun8i EMAC object instance state
115
+ */
116
+typedef struct AwSun8iEmacState {
117
+ /*< private >*/
118
+ SysBusDevice parent_obj;
119
+ /*< public >*/
120
+
121
+ /** Maps I/O registers in physical memory */
122
+ MemoryRegion iomem;
123
+
124
+ /** Interrupt output signal to notify CPU */
125
+ qemu_irq irq;
126
+
127
+ /** Generic Network Interface Controller (NIC) for networking API */
128
+ NICState *nic;
129
+
130
+ /** Generic Network Interface Controller (NIC) configuration */
131
+ NICConf conf;
132
+
133
+ /**
134
+ * @name Media Independent Interface (MII)
135
+ * @{
136
+ */
137
+
138
+ uint8_t mii_phy_addr; /**< PHY address */
139
+ uint32_t mii_cr; /**< Control */
140
+ uint32_t mii_st; /**< Status */
141
+ uint32_t mii_adv; /**< Advertised Abilities */
142
+
143
+ /** @} */
144
+
145
+ /**
146
+ * @name Hardware Registers
147
+ * @{
148
+ */
149
+
150
+ uint32_t basic_ctl0; /**< Basic Control 0 */
151
+ uint32_t basic_ctl1; /**< Basic Control 1 */
152
+ uint32_t int_en; /**< Interrupt Enable */
153
+ uint32_t int_sta; /**< Interrupt Status */
154
+ uint32_t frm_flt; /**< Receive Frame Filter */
155
+
156
+ uint32_t rx_ctl0; /**< Receive Control 0 */
157
+ uint32_t rx_ctl1; /**< Receive Control 1 */
158
+ uint32_t rx_desc_head; /**< Receive Descriptor List Address */
159
+ uint32_t rx_desc_curr; /**< Current Receive Descriptor Address */
160
+
161
+ uint32_t tx_ctl0; /**< Transmit Control 0 */
162
+ uint32_t tx_ctl1; /**< Transmit Control 1 */
163
+ uint32_t tx_desc_head; /**< Transmit Descriptor List Address */
164
+ uint32_t tx_desc_curr; /**< Current Transmit Descriptor Address */
165
+ uint32_t tx_flowctl; /**< Transmit Flow Control */
166
+
167
+ uint32_t mii_cmd; /**< Management Interface Command */
168
+ uint32_t mii_data; /**< Management Interface Data */
169
+
170
+ /** @} */
171
+
172
+} AwSun8iEmacState;
173
+
174
+#endif /* HW_NET_ALLWINNER_SUN8I_H */
175
diff --git a/hw/arm/allwinner-h3.c b/hw/arm/allwinner-h3.c
176
index XXXXXXX..XXXXXXX 100644
177
--- a/hw/arm/allwinner-h3.c
178
+++ b/hw/arm/allwinner-h3.c
179
@@ -XXX,XX +XXX,XX @@ const hwaddr allwinner_h3_memmap[] = {
180
[AW_H3_UART1] = 0x01c28400,
181
[AW_H3_UART2] = 0x01c28800,
182
[AW_H3_UART3] = 0x01c28c00,
183
+ [AW_H3_EMAC] = 0x01c30000,
184
[AW_H3_GIC_DIST] = 0x01c81000,
185
[AW_H3_GIC_CPU] = 0x01c82000,
186
[AW_H3_GIC_HYP] = 0x01c84000,
187
@@ -XXX,XX +XXX,XX @@ struct AwH3Unimplemented {
188
{ "twi1", 0x01c2b000, 1 * KiB },
189
{ "twi2", 0x01c2b400, 1 * KiB },
190
{ "scr", 0x01c2c400, 1 * KiB },
191
- { "emac", 0x01c30000, 64 * KiB },
192
{ "gpu", 0x01c40000, 64 * KiB },
193
{ "hstmr", 0x01c60000, 4 * KiB },
194
{ "dramcom", 0x01c62000, 4 * KiB },
195
@@ -XXX,XX +XXX,XX @@ enum {
196
AW_H3_GIC_SPI_OHCI2 = 77,
197
AW_H3_GIC_SPI_EHCI3 = 78,
198
AW_H3_GIC_SPI_OHCI3 = 79,
199
+ AW_H3_GIC_SPI_EMAC = 82
200
};
201
202
/* Allwinner H3 general constants */
203
@@ -XXX,XX +XXX,XX @@ static void allwinner_h3_init(Object *obj)
204
205
sysbus_init_child_obj(obj, "mmc0", &s->mmc0, sizeof(s->mmc0),
206
TYPE_AW_SDHOST_SUN5I);
207
+
208
+ sysbus_init_child_obj(obj, "emac", &s->emac, sizeof(s->emac),
209
+ TYPE_AW_SUN8I_EMAC);
210
}
211
212
static void allwinner_h3_realize(DeviceState *dev, Error **errp)
213
@@ -XXX,XX +XXX,XX @@ static void allwinner_h3_realize(DeviceState *dev, Error **errp)
214
object_property_add_alias(OBJECT(s), "sd-bus", OBJECT(&s->mmc0),
215
"sd-bus", &error_abort);
216
217
+ /* EMAC */
218
+ if (nd_table[0].used) {
219
+ qemu_check_nic_model(&nd_table[0], TYPE_AW_SUN8I_EMAC);
220
+ qdev_set_nic_properties(DEVICE(&s->emac), &nd_table[0]);
221
+ }
222
+ qdev_init_nofail(DEVICE(&s->emac));
223
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->emac), 0, s->memmap[AW_H3_EMAC]);
224
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->emac), 0,
225
+ qdev_get_gpio_in(DEVICE(&s->gic), AW_H3_GIC_SPI_EMAC));
226
+
227
/* Universal Serial Bus */
228
sysbus_create_simple(TYPE_AW_H3_EHCI, s->memmap[AW_H3_EHCI0],
229
qdev_get_gpio_in(DEVICE(&s->gic),
230
diff --git a/hw/arm/orangepi.c b/hw/arm/orangepi.c
231
index XXXXXXX..XXXXXXX 100644
232
--- a/hw/arm/orangepi.c
233
+++ b/hw/arm/orangepi.c
234
@@ -XXX,XX +XXX,XX @@ static void orangepi_init(MachineState *machine)
235
warn_report("Security Identifier value does not include H3 prefix");
236
}
21
}
237
22
238
+ /* Setup EMAC properties */
23
+ if (cpu_isar_feature(aa64_nmi, cpu)) {
239
+ object_property_set_int(OBJECT(&h3->emac), 1, "phy-addr", &error_abort);
24
+ if (!(env->cp15.sctlr_el[new_el] & SCTLR_SPINTMASK)) {
240
+
25
+ new_mode |= PSTATE_ALLINT;
241
/* Mark H3 object realized */
242
object_property_set_bool(OBJECT(h3), true, "realized", &error_abort);
243
244
diff --git a/hw/net/allwinner-sun8i-emac.c b/hw/net/allwinner-sun8i-emac.c
245
new file mode 100644
246
index XXXXXXX..XXXXXXX
247
--- /dev/null
248
+++ b/hw/net/allwinner-sun8i-emac.c
249
@@ -XXX,XX +XXX,XX @@
250
+/*
251
+ * Allwinner Sun8i Ethernet MAC emulation
252
+ *
253
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
254
+ *
255
+ * This program is free software: you can redistribute it and/or modify
256
+ * it under the terms of the GNU General Public License as published by
257
+ * the Free Software Foundation, either version 2 of the License, or
258
+ * (at your option) any later version.
259
+ *
260
+ * This program is distributed in the hope that it will be useful,
261
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
262
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
263
+ * GNU General Public License for more details.
264
+ *
265
+ * You should have received a copy of the GNU General Public License
266
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
267
+ */
268
+
269
+#include "qemu/osdep.h"
270
+#include "qemu/units.h"
271
+#include "hw/sysbus.h"
272
+#include "migration/vmstate.h"
273
+#include "net/net.h"
274
+#include "hw/irq.h"
275
+#include "hw/qdev-properties.h"
276
+#include "qemu/log.h"
277
+#include "trace.h"
278
+#include "net/checksum.h"
279
+#include "qemu/module.h"
280
+#include "exec/cpu-common.h"
281
+#include "hw/net/allwinner-sun8i-emac.h"
282
+
283
+/* EMAC register offsets */
284
+enum {
285
+ REG_BASIC_CTL_0 = 0x0000, /* Basic Control 0 */
286
+ REG_BASIC_CTL_1 = 0x0004, /* Basic Control 1 */
287
+ REG_INT_STA = 0x0008, /* Interrupt Status */
288
+ REG_INT_EN = 0x000C, /* Interrupt Enable */
289
+ REG_TX_CTL_0 = 0x0010, /* Transmit Control 0 */
290
+ REG_TX_CTL_1 = 0x0014, /* Transmit Control 1 */
291
+ REG_TX_FLOW_CTL = 0x001C, /* Transmit Flow Control */
292
+ REG_TX_DMA_DESC_LIST = 0x0020, /* Transmit Descriptor List Address */
293
+ REG_RX_CTL_0 = 0x0024, /* Receive Control 0 */
294
+ REG_RX_CTL_1 = 0x0028, /* Receive Control 1 */
295
+ REG_RX_DMA_DESC_LIST = 0x0034, /* Receive Descriptor List Address */
296
+ REG_FRM_FLT = 0x0038, /* Receive Frame Filter */
297
+ REG_RX_HASH_0 = 0x0040, /* Receive Hash Table 0 */
298
+ REG_RX_HASH_1 = 0x0044, /* Receive Hash Table 1 */
299
+ REG_MII_CMD = 0x0048, /* Management Interface Command */
300
+ REG_MII_DATA = 0x004C, /* Management Interface Data */
301
+ REG_ADDR_HIGH = 0x0050, /* MAC Address High */
302
+ REG_ADDR_LOW = 0x0054, /* MAC Address Low */
303
+ REG_TX_DMA_STA = 0x00B0, /* Transmit DMA Status */
304
+ REG_TX_CUR_DESC = 0x00B4, /* Transmit Current Descriptor */
305
+ REG_TX_CUR_BUF = 0x00B8, /* Transmit Current Buffer */
306
+ REG_RX_DMA_STA = 0x00C0, /* Receive DMA Status */
307
+ REG_RX_CUR_DESC = 0x00C4, /* Receive Current Descriptor */
308
+ REG_RX_CUR_BUF = 0x00C8, /* Receive Current Buffer */
309
+ REG_RGMII_STA = 0x00D0, /* RGMII Status */
310
+};
311
+
312
+/* EMAC register flags */
313
+enum {
314
+ BASIC_CTL0_100Mbps = (0b11 << 2),
315
+ BASIC_CTL0_FD = (1 << 0),
316
+ BASIC_CTL1_SOFTRST = (1 << 0),
317
+};
318
+
319
+enum {
320
+ INT_STA_RGMII_LINK = (1 << 16),
321
+ INT_STA_RX_EARLY = (1 << 13),
322
+ INT_STA_RX_OVERFLOW = (1 << 12),
323
+ INT_STA_RX_TIMEOUT = (1 << 11),
324
+ INT_STA_RX_DMA_STOP = (1 << 10),
325
+ INT_STA_RX_BUF_UA = (1 << 9),
326
+ INT_STA_RX = (1 << 8),
327
+ INT_STA_TX_EARLY = (1 << 5),
328
+ INT_STA_TX_UNDERFLOW = (1 << 4),
329
+ INT_STA_TX_TIMEOUT = (1 << 3),
330
+ INT_STA_TX_BUF_UA = (1 << 2),
331
+ INT_STA_TX_DMA_STOP = (1 << 1),
332
+ INT_STA_TX = (1 << 0),
333
+};
334
+
335
+enum {
336
+ INT_EN_RX_EARLY = (1 << 13),
337
+ INT_EN_RX_OVERFLOW = (1 << 12),
338
+ INT_EN_RX_TIMEOUT = (1 << 11),
339
+ INT_EN_RX_DMA_STOP = (1 << 10),
340
+ INT_EN_RX_BUF_UA = (1 << 9),
341
+ INT_EN_RX = (1 << 8),
342
+ INT_EN_TX_EARLY = (1 << 5),
343
+ INT_EN_TX_UNDERFLOW = (1 << 4),
344
+ INT_EN_TX_TIMEOUT = (1 << 3),
345
+ INT_EN_TX_BUF_UA = (1 << 2),
346
+ INT_EN_TX_DMA_STOP = (1 << 1),
347
+ INT_EN_TX = (1 << 0),
348
+};
349
+
350
+enum {
351
+ TX_CTL0_TX_EN = (1 << 31),
352
+ TX_CTL1_TX_DMA_START = (1 << 31),
353
+ TX_CTL1_TX_DMA_EN = (1 << 30),
354
+ TX_CTL1_TX_FLUSH = (1 << 0),
355
+};
356
+
357
+enum {
358
+ RX_CTL0_RX_EN = (1 << 31),
359
+ RX_CTL0_STRIP_FCS = (1 << 28),
360
+ RX_CTL0_CRC_IPV4 = (1 << 27),
361
+};
362
+
363
+enum {
364
+ RX_CTL1_RX_DMA_START = (1 << 31),
365
+ RX_CTL1_RX_DMA_EN = (1 << 30),
366
+ RX_CTL1_RX_MD = (1 << 1),
367
+};
368
+
369
+enum {
370
+ RX_FRM_FLT_DIS_ADDR = (1 << 31),
371
+};
372
+
373
+enum {
374
+ MII_CMD_PHY_ADDR_SHIFT = (12),
375
+ MII_CMD_PHY_ADDR_MASK = (0xf000),
376
+ MII_CMD_PHY_REG_SHIFT = (4),
377
+ MII_CMD_PHY_REG_MASK = (0xf0),
378
+ MII_CMD_PHY_RW = (1 << 1),
379
+ MII_CMD_PHY_BUSY = (1 << 0),
380
+};
381
+
382
+enum {
383
+ TX_DMA_STA_STOP = (0b000),
384
+ TX_DMA_STA_RUN_FETCH = (0b001),
385
+ TX_DMA_STA_WAIT_STA = (0b010),
386
+};
387
+
388
+enum {
389
+ RX_DMA_STA_STOP = (0b000),
390
+ RX_DMA_STA_RUN_FETCH = (0b001),
391
+ RX_DMA_STA_WAIT_FRM = (0b011),
392
+};
393
+
394
+/* EMAC register reset values */
395
+enum {
396
+ REG_BASIC_CTL_1_RST = 0x08000000,
397
+};
398
+
399
+/* EMAC constants */
400
+enum {
401
+ AW_SUN8I_EMAC_MIN_PKT_SZ = 64
402
+};
403
+
404
+/* Transmit/receive frame descriptor */
405
+typedef struct FrameDescriptor {
406
+ uint32_t status;
407
+ uint32_t status2;
408
+ uint32_t addr;
409
+ uint32_t next;
410
+} FrameDescriptor;
411
+
412
+/* Frame descriptor flags */
413
+enum {
414
+ DESC_STATUS_CTL = (1 << 31),
415
+ DESC_STATUS2_BUF_SIZE_MASK = (0x7ff),
416
+};
417
+
418
+/* Transmit frame descriptor flags */
419
+enum {
420
+ TX_DESC_STATUS_LENGTH_ERR = (1 << 14),
421
+ TX_DESC_STATUS2_FIRST_DESC = (1 << 29),
422
+ TX_DESC_STATUS2_LAST_DESC = (1 << 30),
423
+ TX_DESC_STATUS2_CHECKSUM_MASK = (0x3 << 27),
424
+};
425
+
426
+/* Receive frame descriptor flags */
427
+enum {
428
+ RX_DESC_STATUS_FIRST_DESC = (1 << 9),
429
+ RX_DESC_STATUS_LAST_DESC = (1 << 8),
430
+ RX_DESC_STATUS_FRM_LEN_MASK = (0x3fff0000),
431
+ RX_DESC_STATUS_FRM_LEN_SHIFT = (16),
432
+ RX_DESC_STATUS_NO_BUF = (1 << 14),
433
+ RX_DESC_STATUS_HEADER_ERR = (1 << 7),
434
+ RX_DESC_STATUS_LENGTH_ERR = (1 << 4),
435
+ RX_DESC_STATUS_CRC_ERR = (1 << 1),
436
+ RX_DESC_STATUS_PAYLOAD_ERR = (1 << 0),
437
+ RX_DESC_STATUS2_RX_INT_CTL = (1 << 31),
438
+};
439
+
440
+/* MII register offsets */
441
+enum {
442
+ MII_REG_CR = (0x0), /* Control */
443
+ MII_REG_ST = (0x1), /* Status */
444
+ MII_REG_ID_HIGH = (0x2), /* Identifier High */
445
+ MII_REG_ID_LOW = (0x3), /* Identifier Low */
446
+ MII_REG_ADV = (0x4), /* Advertised abilities */
447
+ MII_REG_LPA = (0x5), /* Link partner abilities */
448
+};
449
+
450
+/* MII register flags */
451
+enum {
452
+ MII_REG_CR_RESET = (1 << 15),
453
+ MII_REG_CR_POWERDOWN = (1 << 11),
454
+ MII_REG_CR_10Mbit = (0),
455
+ MII_REG_CR_100Mbit = (1 << 13),
456
+ MII_REG_CR_1000Mbit = (1 << 6),
457
+ MII_REG_CR_AUTO_NEG = (1 << 12),
458
+ MII_REG_CR_AUTO_NEG_RESTART = (1 << 9),
459
+ MII_REG_CR_FULLDUPLEX = (1 << 8),
460
+};
461
+
462
+enum {
463
+ MII_REG_ST_100BASE_T4 = (1 << 15),
464
+ MII_REG_ST_100BASE_X_FD = (1 << 14),
465
+ MII_REG_ST_100BASE_X_HD = (1 << 13),
466
+ MII_REG_ST_10_FD = (1 << 12),
467
+ MII_REG_ST_10_HD = (1 << 11),
468
+ MII_REG_ST_100BASE_T2_FD = (1 << 10),
469
+ MII_REG_ST_100BASE_T2_HD = (1 << 9),
470
+ MII_REG_ST_AUTONEG_COMPLETE = (1 << 5),
471
+ MII_REG_ST_AUTONEG_AVAIL = (1 << 3),
472
+ MII_REG_ST_LINK_UP = (1 << 2),
473
+};
474
+
475
+enum {
476
+ MII_REG_LPA_10_HD = (1 << 5),
477
+ MII_REG_LPA_10_FD = (1 << 6),
478
+ MII_REG_LPA_100_HD = (1 << 7),
479
+ MII_REG_LPA_100_FD = (1 << 8),
480
+ MII_REG_LPA_PAUSE = (1 << 10),
481
+ MII_REG_LPA_ASYMPAUSE = (1 << 11),
482
+};
483
+
484
+/* MII constants */
485
+enum {
486
+ MII_PHY_ID_HIGH = 0x0044,
487
+ MII_PHY_ID_LOW = 0x1400,
488
+};
489
+
490
+static void allwinner_sun8i_emac_mii_set_link(AwSun8iEmacState *s,
491
+ bool link_active)
492
+{
493
+ if (link_active) {
494
+ s->mii_st |= MII_REG_ST_LINK_UP;
495
+ } else {
496
+ s->mii_st &= ~MII_REG_ST_LINK_UP;
497
+ }
498
+}
499
+
500
+static void allwinner_sun8i_emac_mii_reset(AwSun8iEmacState *s,
501
+ bool link_active)
502
+{
503
+ s->mii_cr = MII_REG_CR_100Mbit | MII_REG_CR_AUTO_NEG |
504
+ MII_REG_CR_FULLDUPLEX;
505
+ s->mii_st = MII_REG_ST_100BASE_T4 | MII_REG_ST_100BASE_X_FD |
506
+ MII_REG_ST_100BASE_X_HD | MII_REG_ST_10_FD | MII_REG_ST_10_HD |
507
+ MII_REG_ST_100BASE_T2_FD | MII_REG_ST_100BASE_T2_HD |
508
+ MII_REG_ST_AUTONEG_COMPLETE | MII_REG_ST_AUTONEG_AVAIL;
509
+ s->mii_adv = 0;
510
+
511
+ allwinner_sun8i_emac_mii_set_link(s, link_active);
512
+}
513
+
514
+static void allwinner_sun8i_emac_mii_cmd(AwSun8iEmacState *s)
515
+{
516
+ uint8_t addr, reg;
517
+
518
+ addr = (s->mii_cmd & MII_CMD_PHY_ADDR_MASK) >> MII_CMD_PHY_ADDR_SHIFT;
519
+ reg = (s->mii_cmd & MII_CMD_PHY_REG_MASK) >> MII_CMD_PHY_REG_SHIFT;
520
+
521
+ if (addr != s->mii_phy_addr) {
522
+ return;
523
+ }
524
+
525
+ /* Read or write a PHY register? */
526
+ if (s->mii_cmd & MII_CMD_PHY_RW) {
527
+ trace_allwinner_sun8i_emac_mii_write_reg(reg, s->mii_data);
528
+
529
+ switch (reg) {
530
+ case MII_REG_CR:
531
+ if (s->mii_data & MII_REG_CR_RESET) {
532
+ allwinner_sun8i_emac_mii_reset(s, s->mii_st &
533
+ MII_REG_ST_LINK_UP);
534
+ } else {
535
+ s->mii_cr = s->mii_data & ~(MII_REG_CR_RESET |
536
+ MII_REG_CR_AUTO_NEG_RESTART);
537
+ }
538
+ break;
539
+ case MII_REG_ADV:
540
+ s->mii_adv = s->mii_data;
541
+ break;
542
+ case MII_REG_ID_HIGH:
543
+ case MII_REG_ID_LOW:
544
+ case MII_REG_LPA:
545
+ break;
546
+ default:
547
+ qemu_log_mask(LOG_UNIMP, "allwinner-h3-emac: write access to "
548
+ "unknown MII register 0x%x\n", reg);
549
+ break;
550
+ }
551
+ } else {
552
+ switch (reg) {
553
+ case MII_REG_CR:
554
+ s->mii_data = s->mii_cr;
555
+ break;
556
+ case MII_REG_ST:
557
+ s->mii_data = s->mii_st;
558
+ break;
559
+ case MII_REG_ID_HIGH:
560
+ s->mii_data = MII_PHY_ID_HIGH;
561
+ break;
562
+ case MII_REG_ID_LOW:
563
+ s->mii_data = MII_PHY_ID_LOW;
564
+ break;
565
+ case MII_REG_ADV:
566
+ s->mii_data = s->mii_adv;
567
+ break;
568
+ case MII_REG_LPA:
569
+ s->mii_data = MII_REG_LPA_10_HD | MII_REG_LPA_10_FD |
570
+ MII_REG_LPA_100_HD | MII_REG_LPA_100_FD |
571
+ MII_REG_LPA_PAUSE | MII_REG_LPA_ASYMPAUSE;
572
+ break;
573
+ default:
574
+ qemu_log_mask(LOG_UNIMP, "allwinner-h3-emac: read access to "
575
+ "unknown MII register 0x%x\n", reg);
576
+ s->mii_data = 0;
577
+ break;
578
+ }
579
+
580
+ trace_allwinner_sun8i_emac_mii_read_reg(reg, s->mii_data);
581
+ }
582
+}
583
+
584
+static void allwinner_sun8i_emac_update_irq(AwSun8iEmacState *s)
585
+{
586
+ qemu_set_irq(s->irq, (s->int_sta & s->int_en) != 0);
587
+}
588
+
589
+static uint32_t allwinner_sun8i_emac_next_desc(FrameDescriptor *desc,
590
+ size_t min_size)
591
+{
592
+ uint32_t paddr = desc->next;
593
+
594
+ cpu_physical_memory_read(paddr, desc, sizeof(*desc));
595
+
596
+ if ((desc->status & DESC_STATUS_CTL) &&
597
+ (desc->status2 & DESC_STATUS2_BUF_SIZE_MASK) >= min_size) {
598
+ return paddr;
599
+ } else {
600
+ return 0;
601
+ }
602
+}
603
+
604
+static uint32_t allwinner_sun8i_emac_get_desc(FrameDescriptor *desc,
605
+ uint32_t start_addr,
606
+ size_t min_size)
607
+{
608
+ uint32_t desc_addr = start_addr;
609
+
610
+ /* Note that the list is a cycle. Last entry points back to the head. */
611
+ while (desc_addr != 0) {
612
+ cpu_physical_memory_read(desc_addr, desc, sizeof(*desc));
613
+
614
+ if ((desc->status & DESC_STATUS_CTL) &&
615
+ (desc->status2 & DESC_STATUS2_BUF_SIZE_MASK) >= min_size) {
616
+ return desc_addr;
617
+ } else if (desc->next == start_addr) {
618
+ break;
619
+ } else {
26
+ } else {
620
+ desc_addr = desc->next;
27
+ new_mode &= ~PSTATE_ALLINT;
621
+ }
28
+ }
622
+ }
29
+ }
623
+
30
+
624
+ return 0;
31
pstate_write(env, PSTATE_DAIF | new_mode);
625
+}
32
env->aarch64 = true;
626
+
33
aarch64_restore_sp(env, new_el);
627
+static uint32_t allwinner_sun8i_emac_rx_desc(AwSun8iEmacState *s,
628
+ FrameDescriptor *desc,
629
+ size_t min_size)
630
+{
631
+ return allwinner_sun8i_emac_get_desc(desc, s->rx_desc_curr, min_size);
632
+}
633
+
634
+static uint32_t allwinner_sun8i_emac_tx_desc(AwSun8iEmacState *s,
635
+ FrameDescriptor *desc,
636
+ size_t min_size)
637
+{
638
+ return allwinner_sun8i_emac_get_desc(desc, s->tx_desc_head, min_size);
639
+}
640
+
641
+static void allwinner_sun8i_emac_flush_desc(FrameDescriptor *desc,
642
+ uint32_t phys_addr)
643
+{
644
+ cpu_physical_memory_write(phys_addr, desc, sizeof(*desc));
645
+}
646
+
647
+static int allwinner_sun8i_emac_can_receive(NetClientState *nc)
648
+{
649
+ AwSun8iEmacState *s = qemu_get_nic_opaque(nc);
650
+ FrameDescriptor desc;
651
+
652
+ return (s->rx_ctl0 & RX_CTL0_RX_EN) &&
653
+ (allwinner_sun8i_emac_rx_desc(s, &desc, 0) != 0);
654
+}
655
+
656
+static ssize_t allwinner_sun8i_emac_receive(NetClientState *nc,
657
+ const uint8_t *buf,
658
+ size_t size)
659
+{
660
+ AwSun8iEmacState *s = qemu_get_nic_opaque(nc);
661
+ FrameDescriptor desc;
662
+ size_t bytes_left = size;
663
+ size_t desc_bytes = 0;
664
+ size_t pad_fcs_size = 4;
665
+ size_t padding = 0;
666
+
667
+ if (!(s->rx_ctl0 & RX_CTL0_RX_EN)) {
668
+ return -1;
669
+ }
670
+
671
+ s->rx_desc_curr = allwinner_sun8i_emac_rx_desc(s, &desc,
672
+ AW_SUN8I_EMAC_MIN_PKT_SZ);
673
+ if (!s->rx_desc_curr) {
674
+ s->int_sta |= INT_STA_RX_BUF_UA;
675
+ }
676
+
677
+ /* Keep filling RX descriptors until the whole frame is written */
678
+ while (s->rx_desc_curr && bytes_left > 0) {
679
+ desc.status &= ~DESC_STATUS_CTL;
680
+ desc.status &= ~RX_DESC_STATUS_FRM_LEN_MASK;
681
+
682
+ if (bytes_left == size) {
683
+ desc.status |= RX_DESC_STATUS_FIRST_DESC;
684
+ }
685
+
686
+ if ((desc.status2 & DESC_STATUS2_BUF_SIZE_MASK) <
687
+ (bytes_left + pad_fcs_size)) {
688
+ desc_bytes = desc.status2 & DESC_STATUS2_BUF_SIZE_MASK;
689
+ desc.status |= desc_bytes << RX_DESC_STATUS_FRM_LEN_SHIFT;
690
+ } else {
691
+ padding = pad_fcs_size;
692
+ if (bytes_left < AW_SUN8I_EMAC_MIN_PKT_SZ) {
693
+ padding += (AW_SUN8I_EMAC_MIN_PKT_SZ - bytes_left);
694
+ }
695
+
696
+ desc_bytes = (bytes_left);
697
+ desc.status |= RX_DESC_STATUS_LAST_DESC;
698
+ desc.status |= (bytes_left + padding)
699
+ << RX_DESC_STATUS_FRM_LEN_SHIFT;
700
+ }
701
+
702
+ cpu_physical_memory_write(desc.addr, buf, desc_bytes);
703
+ allwinner_sun8i_emac_flush_desc(&desc, s->rx_desc_curr);
704
+ trace_allwinner_sun8i_emac_receive(s->rx_desc_curr, desc.addr,
705
+ desc_bytes);
706
+
707
+ /* Check if frame needs to raise the receive interrupt */
708
+ if (!(desc.status2 & RX_DESC_STATUS2_RX_INT_CTL)) {
709
+ s->int_sta |= INT_STA_RX;
710
+ }
711
+
712
+ /* Increment variables */
713
+ buf += desc_bytes;
714
+ bytes_left -= desc_bytes;
715
+
716
+ /* Move to the next descriptor */
717
+ s->rx_desc_curr = allwinner_sun8i_emac_next_desc(&desc, 64);
718
+ if (!s->rx_desc_curr) {
719
+ /* Not enough buffer space available */
720
+ s->int_sta |= INT_STA_RX_BUF_UA;
721
+ s->rx_desc_curr = s->rx_desc_head;
722
+ break;
723
+ }
724
+ }
725
+
726
+ /* Report receive DMA is finished */
727
+ s->rx_ctl1 &= ~RX_CTL1_RX_DMA_START;
728
+ allwinner_sun8i_emac_update_irq(s);
729
+
730
+ return size;
731
+}
732
+
733
+static void allwinner_sun8i_emac_transmit(AwSun8iEmacState *s)
734
+{
735
+ NetClientState *nc = qemu_get_queue(s->nic);
736
+ FrameDescriptor desc;
737
+ size_t bytes = 0;
738
+ size_t packet_bytes = 0;
739
+ size_t transmitted = 0;
740
+ static uint8_t packet_buf[2048];
741
+
742
+ s->tx_desc_curr = allwinner_sun8i_emac_tx_desc(s, &desc, 0);
743
+
744
+ /* Read all transmit descriptors */
745
+ while (s->tx_desc_curr != 0) {
746
+
747
+ /* Read from physical memory into packet buffer */
748
+ bytes = desc.status2 & DESC_STATUS2_BUF_SIZE_MASK;
749
+ if (bytes + packet_bytes > sizeof(packet_buf)) {
750
+ desc.status |= TX_DESC_STATUS_LENGTH_ERR;
751
+ break;
752
+ }
753
+ cpu_physical_memory_read(desc.addr, packet_buf + packet_bytes, bytes);
754
+ packet_bytes += bytes;
755
+ desc.status &= ~DESC_STATUS_CTL;
756
+ allwinner_sun8i_emac_flush_desc(&desc, s->tx_desc_curr);
757
+
758
+ /* After the last descriptor, send the packet */
759
+ if (desc.status2 & TX_DESC_STATUS2_LAST_DESC) {
760
+ if (desc.status2 & TX_DESC_STATUS2_CHECKSUM_MASK) {
761
+ net_checksum_calculate(packet_buf, packet_bytes);
762
+ }
763
+
764
+ qemu_send_packet(nc, packet_buf, packet_bytes);
765
+ trace_allwinner_sun8i_emac_transmit(s->tx_desc_curr, desc.addr,
766
+ bytes);
767
+
768
+ packet_bytes = 0;
769
+ transmitted++;
770
+ }
771
+ s->tx_desc_curr = allwinner_sun8i_emac_next_desc(&desc, 0);
772
+ }
773
+
774
+ /* Raise transmit completed interrupt */
775
+ if (transmitted > 0) {
776
+ s->int_sta |= INT_STA_TX;
777
+ s->tx_ctl1 &= ~TX_CTL1_TX_DMA_START;
778
+ allwinner_sun8i_emac_update_irq(s);
779
+ }
780
+}
781
+
782
+static void allwinner_sun8i_emac_reset(DeviceState *dev)
783
+{
784
+ AwSun8iEmacState *s = AW_SUN8I_EMAC(dev);
785
+ NetClientState *nc = qemu_get_queue(s->nic);
786
+
787
+ trace_allwinner_sun8i_emac_reset();
788
+
789
+ s->mii_cmd = 0;
790
+ s->mii_data = 0;
791
+ s->basic_ctl0 = 0;
792
+ s->basic_ctl1 = REG_BASIC_CTL_1_RST;
793
+ s->int_en = 0;
794
+ s->int_sta = 0;
795
+ s->frm_flt = 0;
796
+ s->rx_ctl0 = 0;
797
+ s->rx_ctl1 = RX_CTL1_RX_MD;
798
+ s->rx_desc_head = 0;
799
+ s->rx_desc_curr = 0;
800
+ s->tx_ctl0 = 0;
801
+ s->tx_ctl1 = 0;
802
+ s->tx_desc_head = 0;
803
+ s->tx_desc_curr = 0;
804
+ s->tx_flowctl = 0;
805
+
806
+ allwinner_sun8i_emac_mii_reset(s, !nc->link_down);
807
+}
808
+
809
+static uint64_t allwinner_sun8i_emac_read(void *opaque, hwaddr offset,
810
+ unsigned size)
811
+{
812
+ AwSun8iEmacState *s = AW_SUN8I_EMAC(opaque);
813
+ uint64_t value = 0;
814
+ FrameDescriptor desc;
815
+
816
+ switch (offset) {
817
+ case REG_BASIC_CTL_0: /* Basic Control 0 */
818
+ value = s->basic_ctl0;
819
+ break;
820
+ case REG_BASIC_CTL_1: /* Basic Control 1 */
821
+ value = s->basic_ctl1;
822
+ break;
823
+ case REG_INT_STA: /* Interrupt Status */
824
+ value = s->int_sta;
825
+ break;
826
+ case REG_INT_EN: /* Interupt Enable */
827
+ value = s->int_en;
828
+ break;
829
+ case REG_TX_CTL_0: /* Transmit Control 0 */
830
+ value = s->tx_ctl0;
831
+ break;
832
+ case REG_TX_CTL_1: /* Transmit Control 1 */
833
+ value = s->tx_ctl1;
834
+ break;
835
+ case REG_TX_FLOW_CTL: /* Transmit Flow Control */
836
+ value = s->tx_flowctl;
837
+ break;
838
+ case REG_TX_DMA_DESC_LIST: /* Transmit Descriptor List Address */
839
+ value = s->tx_desc_head;
840
+ break;
841
+ case REG_RX_CTL_0: /* Receive Control 0 */
842
+ value = s->rx_ctl0;
843
+ break;
844
+ case REG_RX_CTL_1: /* Receive Control 1 */
845
+ value = s->rx_ctl1;
846
+ break;
847
+ case REG_RX_DMA_DESC_LIST: /* Receive Descriptor List Address */
848
+ value = s->rx_desc_head;
849
+ break;
850
+ case REG_FRM_FLT: /* Receive Frame Filter */
851
+ value = s->frm_flt;
852
+ break;
853
+ case REG_RX_HASH_0: /* Receive Hash Table 0 */
854
+ case REG_RX_HASH_1: /* Receive Hash Table 1 */
855
+ break;
856
+ case REG_MII_CMD: /* Management Interface Command */
857
+ value = s->mii_cmd;
858
+ break;
859
+ case REG_MII_DATA: /* Management Interface Data */
860
+ value = s->mii_data;
861
+ break;
862
+ case REG_ADDR_HIGH: /* MAC Address High */
863
+ value = *(((uint32_t *) (s->conf.macaddr.a)) + 1);
864
+ break;
865
+ case REG_ADDR_LOW: /* MAC Address Low */
866
+ value = *(uint32_t *) (s->conf.macaddr.a);
867
+ break;
868
+ case REG_TX_DMA_STA: /* Transmit DMA Status */
869
+ break;
870
+ case REG_TX_CUR_DESC: /* Transmit Current Descriptor */
871
+ value = s->tx_desc_curr;
872
+ break;
873
+ case REG_TX_CUR_BUF: /* Transmit Current Buffer */
874
+ if (s->tx_desc_curr != 0) {
875
+ cpu_physical_memory_read(s->tx_desc_curr, &desc, sizeof(desc));
876
+ value = desc.addr;
877
+ } else {
878
+ value = 0;
879
+ }
880
+ break;
881
+ case REG_RX_DMA_STA: /* Receive DMA Status */
882
+ break;
883
+ case REG_RX_CUR_DESC: /* Receive Current Descriptor */
884
+ value = s->rx_desc_curr;
885
+ break;
886
+ case REG_RX_CUR_BUF: /* Receive Current Buffer */
887
+ if (s->rx_desc_curr != 0) {
888
+ cpu_physical_memory_read(s->rx_desc_curr, &desc, sizeof(desc));
889
+ value = desc.addr;
890
+ } else {
891
+ value = 0;
892
+ }
893
+ break;
894
+ case REG_RGMII_STA: /* RGMII Status */
895
+ break;
896
+ default:
897
+ qemu_log_mask(LOG_UNIMP, "allwinner-h3-emac: read access to unknown "
898
+ "EMAC register 0x" TARGET_FMT_plx "\n",
899
+ offset);
900
+ }
901
+
902
+ trace_allwinner_sun8i_emac_read(offset, value);
903
+ return value;
904
+}
905
+
906
+static void allwinner_sun8i_emac_write(void *opaque, hwaddr offset,
907
+ uint64_t value, unsigned size)
908
+{
909
+ AwSun8iEmacState *s = AW_SUN8I_EMAC(opaque);
910
+ NetClientState *nc = qemu_get_queue(s->nic);
911
+
912
+ trace_allwinner_sun8i_emac_write(offset, value);
913
+
914
+ switch (offset) {
915
+ case REG_BASIC_CTL_0: /* Basic Control 0 */
916
+ s->basic_ctl0 = value;
917
+ break;
918
+ case REG_BASIC_CTL_1: /* Basic Control 1 */
919
+ if (value & BASIC_CTL1_SOFTRST) {
920
+ allwinner_sun8i_emac_reset(DEVICE(s));
921
+ value &= ~BASIC_CTL1_SOFTRST;
922
+ }
923
+ s->basic_ctl1 = value;
924
+ if (allwinner_sun8i_emac_can_receive(nc)) {
925
+ qemu_flush_queued_packets(nc);
926
+ }
927
+ break;
928
+ case REG_INT_STA: /* Interrupt Status */
929
+ s->int_sta &= ~value;
930
+ allwinner_sun8i_emac_update_irq(s);
931
+ break;
932
+ case REG_INT_EN: /* Interrupt Enable */
933
+ s->int_en = value;
934
+ allwinner_sun8i_emac_update_irq(s);
935
+ break;
936
+ case REG_TX_CTL_0: /* Transmit Control 0 */
937
+ s->tx_ctl0 = value;
938
+ break;
939
+ case REG_TX_CTL_1: /* Transmit Control 1 */
940
+ s->tx_ctl1 = value;
941
+ if (value & TX_CTL1_TX_DMA_EN) {
942
+ allwinner_sun8i_emac_transmit(s);
943
+ }
944
+ break;
945
+ case REG_TX_FLOW_CTL: /* Transmit Flow Control */
946
+ s->tx_flowctl = value;
947
+ break;
948
+ case REG_TX_DMA_DESC_LIST: /* Transmit Descriptor List Address */
949
+ s->tx_desc_head = value;
950
+ s->tx_desc_curr = value;
951
+ break;
952
+ case REG_RX_CTL_0: /* Receive Control 0 */
953
+ s->rx_ctl0 = value;
954
+ break;
955
+ case REG_RX_CTL_1: /* Receive Control 1 */
956
+ s->rx_ctl1 = value | RX_CTL1_RX_MD;
957
+ if ((value & RX_CTL1_RX_DMA_EN) &&
958
+ allwinner_sun8i_emac_can_receive(nc)) {
959
+ qemu_flush_queued_packets(nc);
960
+ }
961
+ break;
962
+ case REG_RX_DMA_DESC_LIST: /* Receive Descriptor List Address */
963
+ s->rx_desc_head = value;
964
+ s->rx_desc_curr = value;
965
+ break;
966
+ case REG_FRM_FLT: /* Receive Frame Filter */
967
+ s->frm_flt = value;
968
+ break;
969
+ case REG_RX_HASH_0: /* Receive Hash Table 0 */
970
+ case REG_RX_HASH_1: /* Receive Hash Table 1 */
971
+ break;
972
+ case REG_MII_CMD: /* Management Interface Command */
973
+ s->mii_cmd = value & ~MII_CMD_PHY_BUSY;
974
+ allwinner_sun8i_emac_mii_cmd(s);
975
+ break;
976
+ case REG_MII_DATA: /* Management Interface Data */
977
+ s->mii_data = value;
978
+ break;
979
+ case REG_ADDR_HIGH: /* MAC Address High */
980
+ s->conf.macaddr.a[4] = (value & 0xff);
981
+ s->conf.macaddr.a[5] = (value & 0xff00) >> 8;
982
+ break;
983
+ case REG_ADDR_LOW: /* MAC Address Low */
984
+ s->conf.macaddr.a[0] = (value & 0xff);
985
+ s->conf.macaddr.a[1] = (value & 0xff00) >> 8;
986
+ s->conf.macaddr.a[2] = (value & 0xff0000) >> 16;
987
+ s->conf.macaddr.a[3] = (value & 0xff000000) >> 24;
988
+ break;
989
+ case REG_TX_DMA_STA: /* Transmit DMA Status */
990
+ case REG_TX_CUR_DESC: /* Transmit Current Descriptor */
991
+ case REG_TX_CUR_BUF: /* Transmit Current Buffer */
992
+ case REG_RX_DMA_STA: /* Receive DMA Status */
993
+ case REG_RX_CUR_DESC: /* Receive Current Descriptor */
994
+ case REG_RX_CUR_BUF: /* Receive Current Buffer */
995
+ case REG_RGMII_STA: /* RGMII Status */
996
+ break;
997
+ default:
998
+ qemu_log_mask(LOG_UNIMP, "allwinner-h3-emac: write access to unknown "
999
+ "EMAC register 0x" TARGET_FMT_plx "\n",
1000
+ offset);
1001
+ }
1002
+}
1003
+
1004
+static void allwinner_sun8i_emac_set_link(NetClientState *nc)
1005
+{
1006
+ AwSun8iEmacState *s = qemu_get_nic_opaque(nc);
1007
+
1008
+ trace_allwinner_sun8i_emac_set_link(!nc->link_down);
1009
+ allwinner_sun8i_emac_mii_set_link(s, !nc->link_down);
1010
+}
1011
+
1012
+static const MemoryRegionOps allwinner_sun8i_emac_mem_ops = {
1013
+ .read = allwinner_sun8i_emac_read,
1014
+ .write = allwinner_sun8i_emac_write,
1015
+ .endianness = DEVICE_NATIVE_ENDIAN,
1016
+ .valid = {
1017
+ .min_access_size = 4,
1018
+ .max_access_size = 4,
1019
+ },
1020
+ .impl.min_access_size = 4,
1021
+};
1022
+
1023
+static NetClientInfo net_allwinner_sun8i_emac_info = {
1024
+ .type = NET_CLIENT_DRIVER_NIC,
1025
+ .size = sizeof(NICState),
1026
+ .can_receive = allwinner_sun8i_emac_can_receive,
1027
+ .receive = allwinner_sun8i_emac_receive,
1028
+ .link_status_changed = allwinner_sun8i_emac_set_link,
1029
+};
1030
+
1031
+static void allwinner_sun8i_emac_init(Object *obj)
1032
+{
1033
+ SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
1034
+ AwSun8iEmacState *s = AW_SUN8I_EMAC(obj);
1035
+
1036
+ memory_region_init_io(&s->iomem, OBJECT(s), &allwinner_sun8i_emac_mem_ops,
1037
+ s, TYPE_AW_SUN8I_EMAC, 64 * KiB);
1038
+ sysbus_init_mmio(sbd, &s->iomem);
1039
+ sysbus_init_irq(sbd, &s->irq);
1040
+}
1041
+
1042
+static void allwinner_sun8i_emac_realize(DeviceState *dev, Error **errp)
1043
+{
1044
+ AwSun8iEmacState *s = AW_SUN8I_EMAC(dev);
1045
+
1046
+ qemu_macaddr_default_if_unset(&s->conf.macaddr);
1047
+ s->nic = qemu_new_nic(&net_allwinner_sun8i_emac_info, &s->conf,
1048
+ object_get_typename(OBJECT(dev)), dev->id, s);
1049
+ qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a);
1050
+}
1051
+
1052
+static Property allwinner_sun8i_emac_properties[] = {
1053
+ DEFINE_NIC_PROPERTIES(AwSun8iEmacState, conf),
1054
+ DEFINE_PROP_UINT8("phy-addr", AwSun8iEmacState, mii_phy_addr, 0),
1055
+ DEFINE_PROP_END_OF_LIST(),
1056
+};
1057
+
1058
+static int allwinner_sun8i_emac_post_load(void *opaque, int version_id)
1059
+{
1060
+ AwSun8iEmacState *s = opaque;
1061
+
1062
+ allwinner_sun8i_emac_set_link(qemu_get_queue(s->nic));
1063
+
1064
+ return 0;
1065
+}
1066
+
1067
+static const VMStateDescription vmstate_aw_emac = {
1068
+ .name = "allwinner-sun8i-emac",
1069
+ .version_id = 1,
1070
+ .minimum_version_id = 1,
1071
+ .post_load = allwinner_sun8i_emac_post_load,
1072
+ .fields = (VMStateField[]) {
1073
+ VMSTATE_UINT8(mii_phy_addr, AwSun8iEmacState),
1074
+ VMSTATE_UINT32(mii_cmd, AwSun8iEmacState),
1075
+ VMSTATE_UINT32(mii_data, AwSun8iEmacState),
1076
+ VMSTATE_UINT32(mii_cr, AwSun8iEmacState),
1077
+ VMSTATE_UINT32(mii_st, AwSun8iEmacState),
1078
+ VMSTATE_UINT32(mii_adv, AwSun8iEmacState),
1079
+ VMSTATE_UINT32(basic_ctl0, AwSun8iEmacState),
1080
+ VMSTATE_UINT32(basic_ctl1, AwSun8iEmacState),
1081
+ VMSTATE_UINT32(int_en, AwSun8iEmacState),
1082
+ VMSTATE_UINT32(int_sta, AwSun8iEmacState),
1083
+ VMSTATE_UINT32(frm_flt, AwSun8iEmacState),
1084
+ VMSTATE_UINT32(rx_ctl0, AwSun8iEmacState),
1085
+ VMSTATE_UINT32(rx_ctl1, AwSun8iEmacState),
1086
+ VMSTATE_UINT32(rx_desc_head, AwSun8iEmacState),
1087
+ VMSTATE_UINT32(rx_desc_curr, AwSun8iEmacState),
1088
+ VMSTATE_UINT32(tx_ctl0, AwSun8iEmacState),
1089
+ VMSTATE_UINT32(tx_ctl1, AwSun8iEmacState),
1090
+ VMSTATE_UINT32(tx_desc_head, AwSun8iEmacState),
1091
+ VMSTATE_UINT32(tx_desc_curr, AwSun8iEmacState),
1092
+ VMSTATE_UINT32(tx_flowctl, AwSun8iEmacState),
1093
+ VMSTATE_END_OF_LIST()
1094
+ }
1095
+};
1096
+
1097
+static void allwinner_sun8i_emac_class_init(ObjectClass *klass, void *data)
1098
+{
1099
+ DeviceClass *dc = DEVICE_CLASS(klass);
1100
+
1101
+ dc->realize = allwinner_sun8i_emac_realize;
1102
+ dc->reset = allwinner_sun8i_emac_reset;
1103
+ dc->vmsd = &vmstate_aw_emac;
1104
+ device_class_set_props(dc, allwinner_sun8i_emac_properties);
1105
+}
1106
+
1107
+static const TypeInfo allwinner_sun8i_emac_info = {
1108
+ .name = TYPE_AW_SUN8I_EMAC,
1109
+ .parent = TYPE_SYS_BUS_DEVICE,
1110
+ .instance_size = sizeof(AwSun8iEmacState),
1111
+ .instance_init = allwinner_sun8i_emac_init,
1112
+ .class_init = allwinner_sun8i_emac_class_init,
1113
+};
1114
+
1115
+static void allwinner_sun8i_emac_register_types(void)
1116
+{
1117
+ type_register_static(&allwinner_sun8i_emac_info);
1118
+}
1119
+
1120
+type_init(allwinner_sun8i_emac_register_types)
1121
diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
1122
index XXXXXXX..XXXXXXX 100644
1123
--- a/hw/arm/Kconfig
1124
+++ b/hw/arm/Kconfig
1125
@@ -XXX,XX +XXX,XX @@ config ALLWINNER_A10
1126
config ALLWINNER_H3
1127
bool
1128
select ALLWINNER_A10_PIT
1129
+ select ALLWINNER_SUN8I_EMAC
1130
select SERIAL
1131
select ARM_TIMER
1132
select ARM_GIC
1133
diff --git a/hw/net/Kconfig b/hw/net/Kconfig
1134
index XXXXXXX..XXXXXXX 100644
1135
--- a/hw/net/Kconfig
1136
+++ b/hw/net/Kconfig
1137
@@ -XXX,XX +XXX,XX @@ config MIPSNET
1138
config ALLWINNER_EMAC
1139
bool
1140
1141
+config ALLWINNER_SUN8I_EMAC
1142
+ bool
1143
+
1144
config IMX_FEC
1145
bool
1146
1147
diff --git a/hw/net/trace-events b/hw/net/trace-events
1148
index XXXXXXX..XXXXXXX 100644
1149
--- a/hw/net/trace-events
1150
+++ b/hw/net/trace-events
1151
@@ -XXX,XX +XXX,XX @@
1152
# See docs/devel/tracing.txt for syntax documentation.
1153
1154
+# allwinner-sun8i-emac.c
1155
+allwinner_sun8i_emac_mii_write_reg(uint32_t reg, uint32_t value) "MII write: reg=0x%" PRIx32 " value=0x%" PRIx32
1156
+allwinner_sun8i_emac_mii_read_reg(uint32_t reg, uint32_t value) "MII read: reg=0x%" PRIx32 " value=0x%" PRIx32
1157
+allwinner_sun8i_emac_receive(uint32_t desc, uint32_t paddr, uint32_t bytes) "RX packet: desc=0x%" PRIx32 " paddr=0x%" PRIx32 " bytes=%" PRIu32
1158
+allwinner_sun8i_emac_transmit(uint32_t desc, uint32_t paddr, uint32_t bytes) "TX packet: desc=0x%" PRIx32 " paddr=0x%" PRIx32 " bytes=%" PRIu32
1159
+allwinner_sun8i_emac_reset(void) "HW reset"
1160
+allwinner_sun8i_emac_set_link(bool active) "Set link: active=%u"
1161
+allwinner_sun8i_emac_read(uint64_t offset, uint64_t val) "MMIO read: offset=0x%" PRIx64 " value=0x%" PRIx64
1162
+allwinner_sun8i_emac_write(uint64_t offset, uint64_t val) "MMIO write: offset=0x%" PRIx64 " value=0x%" PRIx64
1163
+
1164
# etraxfs_eth.c
1165
mdio_phy_read(int regnum, uint16_t value) "read phy_reg:%d value:0x%04x"
1166
mdio_phy_write(int regnum, uint16_t value) "write phy_reg:%d value:0x%04x"
1167
--
34
--
1168
2.20.1
35
2.34.1
1169
1170
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
1
From: Jinjie Ruan <ruanjinjie@huawei.com>
2
2
3
This test boots Ubuntu Bionic on a OrangePi PC board.
3
Augment the GICv3's QOM device interface by adding one
4
new set of sysbus IRQ line, to signal NMI to each CPU.
4
5
5
As it requires 1GB of storage, and is slow, this test is disabled
6
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
6
on automatic CI testing.
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
8
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
8
It is useful for workstation testing. Currently Avocado timeouts too
9
Message-id: 20240407081733.3231820-11-ruanjinjie@huawei.com
9
quickly, so we can't run userland commands.
10
11
The kernel image and DeviceTree blob are built by the Armbian
12
project (based on Debian):
13
https://www.armbian.com/orange-pi-pc/
14
15
The Ubuntu image is downloaded from:
16
https://dl.armbian.com/orangepipc/Bionic_current
17
18
This test can be run using:
19
20
$ AVOCADO_ALLOW_LARGE_STORAGE=yes \
21
avocado --show=app,console run -t machine:orangepi-pc \
22
tests/acceptance/boot_linux_console.py
23
console: U-Boot SPL 2019.04-armbian (Nov 18 2019 - 23:08:35 +0100)
24
console: DRAM: 1024 MiB
25
console: Failed to set core voltage! Can't set CPU frequency
26
console: Trying to boot from MMC1
27
console: U-Boot 2019.04-armbian (Nov 18 2019 - 23:08:35 +0100) Allwinner Technology
28
console: CPU: Allwinner H3 (SUN8I 0000)
29
console: Model: Xunlong Orange Pi PC
30
console: DRAM: 1 GiB
31
console: MMC: mmc@1c0f000: 0
32
[...]
33
console: Uncompressing Linux... done, booting the kernel.
34
console: Booting Linux on physical CPU 0x0
35
console: Linux version 5.3.9-sunxi (root@builder) (gcc version 8.3.0 (GNU Toolchain for the A-profile Architecture 8.3-2019.03 (arm-rel-8.36))) #19.11.3 SMP Mon Nov 18 18:49:43 CET 2019
36
console: CPU: ARMv7 Processor [410fc075] revision 5 (ARMv7), cr=50c5387d
37
console: CPU: div instructions available: patching division code
38
console: CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
39
console: OF: fdt: Machine model: Xunlong Orange Pi PC
40
[...]
41
console: EXT4-fs (mmcblk0p1): mounted filesystem with writeback data mode. Opts: (null)
42
console: done.
43
console: Begin: Running /scripts/local-bottom ... done.
44
console: Begin: Running /scripts/init-bottom ... done.
45
console: systemd[1]: systemd 237 running in system mode. (...)
46
console: systemd[1]: Detected architecture arm.
47
console: Welcome to Ubuntu 18.04.3 LTS!
48
console: systemd[1]: Set hostname to <orangepipc>.
49
50
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
51
Signed-off-by: Niek Linnenbank <nieklinnenbank@gmail.com>
52
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
53
Tested-by: Alex Bennée <alex.bennee@linaro.org>
54
Message-id: 20200311221854.30370-17-nieklinnenbank@gmail.com
55
[NL: rename in commit message Raspbian to Armbian, remove vm.set_machine()]
56
[NL: changed test to boot from SD card via BootROM, added check for 7z]
57
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
58
---
11
---
59
tests/acceptance/boot_linux_console.py | 48 ++++++++++++++++++++++++++
12
include/hw/intc/arm_gic_common.h | 2 ++
60
1 file changed, 48 insertions(+)
13
include/hw/intc/arm_gicv3_common.h | 2 ++
14
hw/intc/arm_gicv3_common.c | 6 ++++++
15
3 files changed, 10 insertions(+)
61
16
62
diff --git a/tests/acceptance/boot_linux_console.py b/tests/acceptance/boot_linux_console.py
17
diff --git a/include/hw/intc/arm_gic_common.h b/include/hw/intc/arm_gic_common.h
63
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
64
--- a/tests/acceptance/boot_linux_console.py
19
--- a/include/hw/intc/arm_gic_common.h
65
+++ b/tests/acceptance/boot_linux_console.py
20
+++ b/include/hw/intc/arm_gic_common.h
66
@@ -XXX,XX +XXX,XX @@ from avocado_qemu import exec_command_and_wait_for_pattern
21
@@ -XXX,XX +XXX,XX @@ struct GICState {
67
from avocado_qemu import wait_for_console_pattern
22
qemu_irq parent_fiq[GIC_NCPU];
68
from avocado.utils import process
23
qemu_irq parent_virq[GIC_NCPU];
69
from avocado.utils import archive
24
qemu_irq parent_vfiq[GIC_NCPU];
70
+from avocado.utils.path import find_command, CmdNotFoundError
25
+ qemu_irq parent_nmi[GIC_NCPU];
71
26
+ qemu_irq parent_vnmi[GIC_NCPU];
72
+P7ZIP_AVAILABLE = True
27
qemu_irq maintenance_irq[GIC_NCPU];
73
+try:
28
74
+ find_command('7z')
29
/* GICD_CTLR; for a GIC with the security extensions the NS banked version
75
+except CmdNotFoundError:
30
diff --git a/include/hw/intc/arm_gicv3_common.h b/include/hw/intc/arm_gicv3_common.h
76
+ P7ZIP_AVAILABLE = False
31
index XXXXXXX..XXXXXXX 100644
77
32
--- a/include/hw/intc/arm_gicv3_common.h
78
class BootLinuxConsole(Test):
33
+++ b/include/hw/intc/arm_gicv3_common.h
79
"""
34
@@ -XXX,XX +XXX,XX @@ struct GICv3CPUState {
80
@@ -XXX,XX +XXX,XX @@ class BootLinuxConsole(Test):
35
qemu_irq parent_fiq;
81
exec_command_and_wait_for_pattern(self, 'reboot',
36
qemu_irq parent_virq;
82
'reboot: Restarting system')
37
qemu_irq parent_vfiq;
83
38
+ qemu_irq parent_nmi;
84
+ @skipUnless(os.getenv('AVOCADO_ALLOW_LARGE_STORAGE'), 'storage limited')
39
+ qemu_irq parent_vnmi;
85
+ @skipUnless(P7ZIP_AVAILABLE, '7z not installed')
40
86
+ def test_arm_orangepi_bionic(self):
41
/* Redistributor */
87
+ """
42
uint32_t level; /* Current IRQ level */
88
+ :avocado: tags=arch:arm
43
diff --git a/hw/intc/arm_gicv3_common.c b/hw/intc/arm_gicv3_common.c
89
+ :avocado: tags=machine:orangepi-pc
44
index XXXXXXX..XXXXXXX 100644
90
+ """
45
--- a/hw/intc/arm_gicv3_common.c
91
+
46
+++ b/hw/intc/arm_gicv3_common.c
92
+ # This test download a 196MB compressed image and expand it to 932MB...
47
@@ -XXX,XX +XXX,XX @@ void gicv3_init_irqs_and_mmio(GICv3State *s, qemu_irq_handler handler,
93
+ image_url = ('https://dl.armbian.com/orangepipc/archive/'
48
for (i = 0; i < s->num_cpu; i++) {
94
+ 'Armbian_19.11.3_Orangepipc_bionic_current_5.3.9.7z')
49
sysbus_init_irq(sbd, &s->cpu[i].parent_vfiq);
95
+ image_hash = '196a8ffb72b0123d92cea4a070894813d305c71e'
50
}
96
+ image_path_7z = self.fetch_asset(image_url, asset_hash=image_hash)
51
+ for (i = 0; i < s->num_cpu; i++) {
97
+ image_name = 'Armbian_19.11.3_Orangepipc_bionic_current_5.3.9.img'
52
+ sysbus_init_irq(sbd, &s->cpu[i].parent_nmi);
98
+ image_path = os.path.join(self.workdir, image_name)
53
+ }
99
+ process.run("7z e -o%s %s" % (self.workdir, image_path_7z))
54
+ for (i = 0; i < s->num_cpu; i++) {
100
+
55
+ sysbus_init_irq(sbd, &s->cpu[i].parent_vnmi);
101
+ self.vm.set_console()
56
+ }
102
+ self.vm.add_args('-drive', 'file=' + image_path + ',if=sd,format=raw',
57
103
+ '-nic', 'user',
58
memory_region_init_io(&s->iomem_dist, OBJECT(s), ops, s,
104
+ '-no-reboot')
59
"gicv3_dist", 0x10000);
105
+ self.vm.launch()
106
+
107
+ kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
108
+ 'console=ttyS0,115200 '
109
+ 'loglevel=7 '
110
+ 'nosmp '
111
+ 'systemd.default_timeout_start_sec=9000 '
112
+ 'systemd.mask=armbian-zram-config.service '
113
+ 'systemd.mask=armbian-ramlog.service')
114
+
115
+ self.wait_for_console_pattern('U-Boot SPL')
116
+ self.wait_for_console_pattern('Autoboot in ')
117
+ exec_command_and_wait_for_pattern(self, ' ', '=>')
118
+ exec_command_and_wait_for_pattern(self, "setenv extraargs '" +
119
+ kernel_command_line + "'", '=>')
120
+ exec_command_and_wait_for_pattern(self, 'boot', 'Starting kernel ...');
121
+
122
+ self.wait_for_console_pattern('systemd[1]: Set hostname ' +
123
+ 'to <orangepipc>')
124
+ self.wait_for_console_pattern('Starting Load Kernel Modules...')
125
+
126
def test_s390x_s390_ccw_virtio(self):
127
"""
128
:avocado: tags=arch:s390x
129
--
60
--
130
2.20.1
61
2.34.1
131
132
diff view generated by jsdifflib
1
From: Eric Auger <eric.auger@redhat.com>
1
From: Jinjie Ruan <ruanjinjie@huawei.com>
2
2
3
At the moment if the end-user does not specify the gic-version along
3
Wire the new NMI and VINMI interrupt line from the GIC to each CPU if it
4
with KVM acceleration, v2 is set by default. However most of the
4
is not GICv2.
5
systems now have GICv3 and sometimes they do not support GICv2
6
compatibility.
7
5
8
This patch keeps the default v2 selection in all cases except
6
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
9
in the KVM accelerated mode when either
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
10
- the host does not support GICv2 in-kernel emulation or
8
Message-id: 20240407081733.3231820-12-ruanjinjie@huawei.com
11
- number of VCPUS exceeds 8.
12
13
Those cases did not work anyway so we do not break any compatibility.
14
Now we get v3 selected in such a case.
15
16
Signed-off-by: Eric Auger <eric.auger@redhat.com>
17
Reported-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
18
Reviewed-by: Andrew Jones <drjones@redhat.com>
19
Message-id: 20200311131618.7187-7-eric.auger@redhat.com
20
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
21
---
10
---
22
hw/arm/virt.c | 17 ++++++++++++++++-
11
hw/arm/virt.c | 10 +++++++++-
23
1 file changed, 16 insertions(+), 1 deletion(-)
12
1 file changed, 9 insertions(+), 1 deletion(-)
24
13
25
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
14
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
26
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
27
--- a/hw/arm/virt.c
16
--- a/hw/arm/virt.c
28
+++ b/hw/arm/virt.c
17
+++ b/hw/arm/virt.c
29
@@ -XXX,XX +XXX,XX @@ static void virt_set_memmap(VirtMachineState *vms)
18
@@ -XXX,XX +XXX,XX @@ static void create_gic(VirtMachineState *vms, MemoryRegion *mem)
30
*/
19
31
static void finalize_gic_version(VirtMachineState *vms)
20
/* Wire the outputs from each CPU's generic timer and the GICv3
32
{
21
* maintenance interrupt signal to the appropriate GIC PPI inputs,
33
+ unsigned int max_cpus = MACHINE(vms)->smp.max_cpus;
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));
34
+
32
+
35
if (kvm_enabled()) {
33
+ if (vms->gic_version != VIRT_GIC_VERSION_2) {
36
int probe_bitmap;
34
+ sysbus_connect_irq(gicbusdev, i + 4 * smp_cpus,
37
35
+ qdev_get_gpio_in(cpudev, ARM_CPU_NMI));
38
@@ -XXX,XX +XXX,XX @@ static void finalize_gic_version(VirtMachineState *vms)
36
+ sysbus_connect_irq(gicbusdev, i + 5 * smp_cpus,
39
}
37
+ qdev_get_gpio_in(cpudev, ARM_CPU_VINMI));
40
return;
38
+ }
41
case VIRT_GIC_VERSION_NOSEL:
39
}
42
- vms->gic_version = VIRT_GIC_VERSION_2;
40
43
+ if ((probe_bitmap & KVM_ARM_VGIC_V2) && max_cpus <= GIC_NCPU) {
41
fdt_add_gic_node(vms);
44
+ vms->gic_version = VIRT_GIC_VERSION_2;
45
+ } else if (probe_bitmap & KVM_ARM_VGIC_V3) {
46
+ /*
47
+ * in case the host does not support v2 in-kernel emulation or
48
+ * the end-user requested more than 8 VCPUs we now default
49
+ * to v3. In any case defaulting to v2 would be broken.
50
+ */
51
+ vms->gic_version = VIRT_GIC_VERSION_3;
52
+ } else if (max_cpus > GIC_NCPU) {
53
+ error_report("host only supports in-kernel GICv2 emulation "
54
+ "but more than 8 vcpus are requested");
55
+ exit(1);
56
+ }
57
break;
58
case VIRT_GIC_VERSION_2:
59
case VIRT_GIC_VERSION_3:
60
--
42
--
61
2.20.1
43
2.34.1
62
63
diff view generated by jsdifflib
1
Fix a couple of comment typos.
1
From: Jinjie Ruan <ruanjinjie@huawei.com>
2
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
3
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
4
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
5
Message-id: 20200303174950.3298-5-peter.maydell@linaro.org
6
---
14
---
7
target/arm/helper.c | 2 +-
15
target/arm/helper.c | 3 +++
8
target/arm/translate.c | 2 +-
16
1 file changed, 3 insertions(+)
9
2 files changed, 2 insertions(+), 2 deletions(-)
10
17
11
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
12
index XXXXXXX..XXXXXXX 100644
19
index XXXXXXX..XXXXXXX 100644
13
--- a/target/arm/helper.c
20
--- a/target/arm/helper.c
14
+++ b/target/arm/helper.c
21
+++ b/target/arm/helper.c
15
@@ -XXX,XX +XXX,XX @@ void HELPER(rebuild_hflags_m32)(CPUARMState *env, int el)
22
@@ -XXX,XX +XXX,XX @@ static void arm_cpu_do_interrupt_aarch64(CPUState *cs)
16
23
break;
17
/*
24
case EXCP_IRQ:
18
* If we have triggered a EL state change we can't rely on the
25
case EXCP_VIRQ:
19
- * translator having passed it too us, we need to recompute.
26
+ case EXCP_NMI:
20
+ * translator having passed it to us, we need to recompute.
27
+ case EXCP_VINMI:
21
*/
28
addr += 0x80;
22
void HELPER(rebuild_hflags_a32_newel)(CPUARMState *env)
29
break;
23
{
30
case EXCP_FIQ:
24
diff --git a/target/arm/translate.c b/target/arm/translate.c
31
case EXCP_VFIQ:
25
index XXXXXXX..XXXXXXX 100644
32
+ case EXCP_VFNMI:
26
--- a/target/arm/translate.c
33
addr += 0x100;
27
+++ b/target/arm/translate.c
34
break;
28
@@ -XXX,XX +XXX,XX @@ static int disas_coproc_insn(DisasContext *s, uint32_t insn)
35
case EXCP_VSERR:
29
30
if (!isread && !(ri->type & ARM_CP_SUPPRESS_TB_END)) {
31
/*
32
- * A write to any coprocessor regiser that ends a TB
33
+ * A write to any coprocessor register that ends a TB
34
* must rebuild the hflags for the next TB.
35
*/
36
TCGv_i32 tcg_el = tcg_const_i32(s->current_el);
37
--
36
--
38
2.20.1
37
2.34.1
39
40
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
1
From: Jinjie Ruan <ruanjinjie@huawei.com>
2
2
3
The kernel image and DeviceTree blob are built by the Armbian
3
Add a property has-nmi to the GICv3 device, and use this to set
4
project (based on Debian):
4
the NMI bit in the GICD_TYPER register. This isn't visible to
5
https://www.armbian.com/orange-pi-pc/
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.
6
8
7
The SD image is from the kernelci.org project:
9
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
8
https://kernelci.org/faq/#the-code
10
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
9
11
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
10
If ARM is a target being built, "make check-acceptance" will
12
Message-id: 20240407081733.3231820-14-ruanjinjie@huawei.com
11
automatically include this test by the use of the "arch:arm" tags.
12
13
Alternatively, this test can be run using:
14
15
$ avocado --show=console run -t machine:orangepi-pc tests/acceptance/boot_linux_console.py
16
console: Uncompressing Linux... done, booting the kernel.
17
console: Booting Linux on physical CPU 0x0
18
console: Linux version 4.20.7-sunxi (root@armbian.com) (gcc version 7.2.1 20171011 (Linaro GCC 7.2-2017.11)) #5.75 SMP Fri Feb 8 09:02:10 CET 2019
19
console: CPU: ARMv7 Processor [410fc075] revision 5 (ARMv7), cr=50c5387d
20
[...]
21
console: sunxi-wdt 1c20ca0.watchdog: Watchdog enabled (timeout=16 sec, nowayout=0)
22
console: sunxi-mmc 1c0f000.mmc: Linked as a consumer to regulator.2
23
console: sunxi-mmc 1c0f000.mmc: Got CD GPIO
24
console: ledtrig-cpu: registered to indicate activity on CPUs
25
console: hidraw: raw HID events driver (C) Jiri Kosina
26
console: usbcore: registered new interface driver usbhid
27
console: usbhid: USB HID core driver
28
console: Initializing XFRM netlink socket
29
console: sunxi-mmc 1c0f000.mmc: initialized, max. request size: 16384 KB
30
console: NET: Registered protocol family 10
31
console: mmc0: host does not support reading read-only switch, assuming write-enable
32
console: mmc0: Problem switching card into high-speed mode!
33
console: mmc0: new SD card at address 4567
34
console: mmcblk0: mmc0:4567 QEMU! 60.0 MiB
35
[...]
36
console: EXT4-fs (mmcblk0): mounting ext2 file system using the ext4 subsystem
37
console: EXT4-fs (mmcblk0): mounted filesystem without journal. Opts: (null)
38
console: VFS: Mounted root (ext2 filesystem) on device 179:0.
39
console: Run /sbin/init as init process
40
console: EXT4-fs (mmcblk0): re-mounted. Opts: block_validity,barrier,user_xattr,acl
41
console: Starting syslogd: OK
42
console: Starting klogd: OK
43
console: Populating /dev using udev: udevd[203]: starting version 3.2.7
44
console: /bin/sh: can't access tty; job control turned off
45
console: cat /proc/partitions
46
console: / # cat /proc/partitions
47
console: major minor #blocks name
48
console: 1 0 4096 ram0
49
console: 1 1 4096 ram1
50
console: 1 2 4096 ram2
51
console: 1 3 4096 ram3
52
console: 179 0 61440 mmcblk0
53
console: reboot
54
console: / # reboot
55
console: umount: devtmpfs busy - remounted read-only
56
console: EXT4-fs (mmcblk0): re-mounted. Opts: (null)
57
console: The system is going down NOW!
58
console: Sent SIGTERM to all processes
59
console: Sent SIGKILL to all processes
60
console: Requesting system reboot
61
console: reboot: Restarting system
62
JOB TIME : 68.64 s
63
64
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
65
Signed-off-by: Niek Linnenbank <nieklinnenbank@gmail.com>
66
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
67
Tested-by: Alex Bennée <alex.bennee@linaro.org>
68
Message-id: 20200311221854.30370-16-nieklinnenbank@gmail.com
69
[NL: rename in commit message Raspbian to Armbian, remove vm.set_machine()]
70
[NL: extend test with ethernet device checks]
71
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
72
---
14
---
73
tests/acceptance/boot_linux_console.py | 47 ++++++++++++++++++++++++++
15
hw/intc/gicv3_internal.h | 1 +
74
1 file changed, 47 insertions(+)
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(+)
75
20
76
diff --git a/tests/acceptance/boot_linux_console.py b/tests/acceptance/boot_linux_console.py
21
diff --git a/hw/intc/gicv3_internal.h b/hw/intc/gicv3_internal.h
77
index XXXXXXX..XXXXXXX 100644
22
index XXXXXXX..XXXXXXX 100644
78
--- a/tests/acceptance/boot_linux_console.py
23
--- a/hw/intc/gicv3_internal.h
79
+++ b/tests/acceptance/boot_linux_console.py
24
+++ b/hw/intc/gicv3_internal.h
80
@@ -XXX,XX +XXX,XX @@ class BootLinuxConsole(Test):
25
@@ -XXX,XX +XXX,XX @@
81
exec_command_and_wait_for_pattern(self, 'reboot',
26
#define GICD_CTLR_E1NWF (1U << 7)
82
'reboot: Restarting system')
27
#define GICD_CTLR_RWP (1U << 31)
83
28
84
+ def test_arm_orangepi_sd(self):
29
+#define GICD_TYPER_NMI_SHIFT 9
85
+ """
30
#define GICD_TYPER_LPIS_SHIFT 17
86
+ :avocado: tags=arch:arm
31
87
+ :avocado: tags=machine:orangepi-pc
32
/* 16 bits EventId */
88
+ """
33
diff --git a/include/hw/intc/arm_gicv3_common.h b/include/hw/intc/arm_gicv3_common.h
89
+ deb_url = ('https://apt.armbian.com/pool/main/l/'
34
index XXXXXXX..XXXXXXX 100644
90
+ 'linux-4.20.7-sunxi/linux-image-dev-sunxi_5.75_armhf.deb')
35
--- a/include/hw/intc/arm_gicv3_common.h
91
+ deb_hash = '1334c29c44d984ffa05ed10de8c3361f33d78315'
36
+++ b/include/hw/intc/arm_gicv3_common.h
92
+ deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
37
@@ -XXX,XX +XXX,XX @@ struct GICv3State {
93
+ kernel_path = self.extract_from_deb(deb_path,
38
uint32_t num_irq;
94
+ '/boot/vmlinuz-4.20.7-sunxi')
39
uint32_t revision;
95
+ dtb_path = '/usr/lib/linux-image-dev-sunxi/sun8i-h3-orangepi-pc.dtb'
40
bool lpi_enable;
96
+ dtb_path = self.extract_from_deb(deb_path, dtb_path)
41
+ bool nmi_support;
97
+ rootfs_url = ('http://storage.kernelci.org/images/rootfs/buildroot/'
42
bool security_extn;
98
+ 'kci-2019.02/armel/base/rootfs.ext2.xz')
43
bool force_8bit_prio;
99
+ rootfs_hash = '692510cb625efda31640d1de0a8d60e26040f061'
44
bool irq_reset_nonsecure;
100
+ rootfs_path_xz = self.fetch_asset(rootfs_url, asset_hash=rootfs_hash)
45
diff --git a/hw/intc/arm_gicv3_common.c b/hw/intc/arm_gicv3_common.c
101
+ rootfs_path = os.path.join(self.workdir, 'rootfs.cpio')
46
index XXXXXXX..XXXXXXX 100644
102
+ archive.lzma_uncompress(rootfs_path_xz, rootfs_path)
47
--- a/hw/intc/arm_gicv3_common.c
103
+
48
+++ b/hw/intc/arm_gicv3_common.c
104
+ self.vm.set_console()
49
@@ -XXX,XX +XXX,XX @@ static Property arm_gicv3_common_properties[] = {
105
+ kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
50
DEFINE_PROP_UINT32("num-irq", GICv3State, num_irq, 32),
106
+ 'console=ttyS0,115200 '
51
DEFINE_PROP_UINT32("revision", GICv3State, revision, 3),
107
+ 'root=/dev/mmcblk0 rootwait rw '
52
DEFINE_PROP_BOOL("has-lpi", GICv3State, lpi_enable, 0),
108
+ 'panic=-1 noreboot')
53
+ DEFINE_PROP_BOOL("has-nmi", GICv3State, nmi_support, 0),
109
+ self.vm.add_args('-kernel', kernel_path,
54
DEFINE_PROP_BOOL("has-security-extensions", GICv3State, security_extn, 0),
110
+ '-dtb', dtb_path,
55
/*
111
+ '-drive', 'file=' + rootfs_path + ',if=sd,format=raw',
56
* Compatibility property: force 8 bits of physical priority, even
112
+ '-append', kernel_command_line,
57
diff --git a/hw/intc/arm_gicv3_dist.c b/hw/intc/arm_gicv3_dist.c
113
+ '-no-reboot')
58
index XXXXXXX..XXXXXXX 100644
114
+ self.vm.launch()
59
--- a/hw/intc/arm_gicv3_dist.c
115
+ shell_ready = "/bin/sh: can't access tty; job control turned off"
60
+++ b/hw/intc/arm_gicv3_dist.c
116
+ self.wait_for_console_pattern(shell_ready)
61
@@ -XXX,XX +XXX,XX @@ static bool gicd_readl(GICv3State *s, hwaddr offset,
117
+
62
* by GICD_TYPER.IDbits)
118
+ exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
63
* MBIS == 0 (message-based SPIs not supported)
119
+ 'Allwinner sun8i Family')
64
* SecurityExtn == 1 if security extns supported
120
+ exec_command_and_wait_for_pattern(self, 'cat /proc/partitions',
65
+ * NMI = 1 if Non-maskable interrupt property is supported
121
+ 'mmcblk0')
66
* CPUNumber == 0 since for us ARE is always 1
122
+ exec_command_and_wait_for_pattern(self, 'ifconfig eth0 up',
67
* ITLinesNumber == (((max SPI IntID + 1) / 32) - 1)
123
+ 'eth0: Link is Up')
68
*/
124
+ exec_command_and_wait_for_pattern(self, 'udhcpc eth0',
69
@@ -XXX,XX +XXX,XX @@ static bool gicd_readl(GICv3State *s, hwaddr offset,
125
+ 'udhcpc: lease of 10.0.2.15 obtained')
70
bool dvis = s->revision >= 4;
126
+ exec_command_and_wait_for_pattern(self, 'ping -c 3 10.0.2.2',
71
127
+ '3 packets transmitted, 3 packets received, 0% packet loss')
72
*data = (1 << 25) | (1 << 24) | (dvis << 18) | (sec_extn << 10) |
128
+ exec_command_and_wait_for_pattern(self, 'reboot',
73
+ (s->nmi_support << GICD_TYPER_NMI_SHIFT) |
129
+ 'reboot: Restarting system')
74
(s->lpi_enable << GICD_TYPER_LPIS_SHIFT) |
130
+
75
(0xf << 19) | itlinesnumber;
131
def test_s390x_s390_ccw_virtio(self):
76
return true;
132
"""
133
:avocado: tags=arch:s390x
134
--
77
--
135
2.20.1
78
2.34.1
136
137
diff view generated by jsdifflib
1
From: Eric Auger <eric.auger@redhat.com>
1
From: Jinjie Ruan <ruanjinjie@huawei.com>
2
2
3
Restructure the finalize_gic_version with switch cases and
3
So far, there is no FEAT_GICv3_NMI support in the in-kernel GIC, so make it
4
clearly separate the following cases:
4
an error to try to set has-nmi=true for the KVM GICv3.
5
5
6
- KVM mode / in-kernel irqchip
6
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
7
- KVM mode / userspace irqchip
7
Message-id: 20240407081733.3231820-15-ruanjinjie@huawei.com
8
- TCG mode
8
Suggested-by: Peter Maydell <peter.maydell@linaro.org>
9
10
In KVM mode / in-kernel irqchip , we explictly check whether
11
the chosen version is supported by the host. If the end-user
12
explicitly sets v2/v3 and this is not supported by the host,
13
then the user gets an explicit error message. Note that for
14
old kernels where the CREATE_DEVICE ioctl doesn't exist then
15
we will now fail if the user specifically asked for gicv2,
16
where previously we (probably) would have succeeded.
17
18
In KVM mode / userspace irqchip we immediatly output an error
19
in case the end-user explicitly selected v3. Also we warn the
20
end-user about the unexpected usage of gic-version=host in
21
that case as only userspace GICv2 is supported.
22
23
Signed-off-by: Eric Auger <eric.auger@redhat.com>
24
Reviewed-by: Andrew Jones <drjones@redhat.com>
25
Message-id: 20200311131618.7187-6-eric.auger@redhat.com
26
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
27
---
10
---
28
hw/arm/virt.c | 88 +++++++++++++++++++++++++++++++++++++++------------
11
hw/intc/arm_gicv3_kvm.c | 5 +++++
29
1 file changed, 67 insertions(+), 21 deletions(-)
12
1 file changed, 5 insertions(+)
30
13
31
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
14
diff --git a/hw/intc/arm_gicv3_kvm.c b/hw/intc/arm_gicv3_kvm.c
32
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
33
--- a/hw/arm/virt.c
16
--- a/hw/intc/arm_gicv3_kvm.c
34
+++ b/hw/arm/virt.c
17
+++ b/hw/intc/arm_gicv3_kvm.c
35
@@ -XXX,XX +XXX,XX @@ static void virt_set_memmap(VirtMachineState *vms)
18
@@ -XXX,XX +XXX,XX @@ static void kvm_arm_gicv3_realize(DeviceState *dev, Error **errp)
36
*/
19
return;
37
static void finalize_gic_version(VirtMachineState *vms)
20
}
38
{
21
39
- if (vms->gic_version == VIRT_GIC_VERSION_HOST ||
22
+ if (s->nmi_support) {
40
- vms->gic_version == VIRT_GIC_VERSION_MAX) {
23
+ error_setg(errp, "NMI is not supported with the in-kernel GIC");
41
- if (!kvm_enabled()) {
42
- if (vms->gic_version == VIRT_GIC_VERSION_HOST) {
43
- error_report("gic-version=host requires KVM");
44
- exit(1);
45
- } else {
46
- /* "max": currently means 3 for TCG */
47
- vms->gic_version = VIRT_GIC_VERSION_3;
48
- }
49
- } else {
50
- int probe_bitmap = kvm_arm_vgic_probe();
51
+ if (kvm_enabled()) {
52
+ int probe_bitmap;
53
54
- if (!probe_bitmap) {
55
+ if (!kvm_irqchip_in_kernel()) {
56
+ switch (vms->gic_version) {
57
+ case VIRT_GIC_VERSION_HOST:
58
+ warn_report(
59
+ "gic-version=host not relevant with kernel-irqchip=off "
60
+ "as only userspace GICv2 is supported. Using v2 ...");
61
+ return;
62
+ case VIRT_GIC_VERSION_MAX:
63
+ case VIRT_GIC_VERSION_NOSEL:
64
+ vms->gic_version = VIRT_GIC_VERSION_2;
65
+ return;
66
+ case VIRT_GIC_VERSION_2:
67
+ return;
68
+ case VIRT_GIC_VERSION_3:
69
error_report(
70
- "Unable to determine GIC version supported by host");
71
+ "gic-version=3 is not supported with kernel-irqchip=off");
72
exit(1);
73
- } else {
74
- if (probe_bitmap & KVM_ARM_VGIC_V3) {
75
- vms->gic_version = VIRT_GIC_VERSION_3;
76
- } else {
77
- vms->gic_version = VIRT_GIC_VERSION_2;
78
- }
79
}
80
}
81
- } else if (vms->gic_version == VIRT_GIC_VERSION_NOSEL) {
82
+
83
+ probe_bitmap = kvm_arm_vgic_probe();
84
+ if (!probe_bitmap) {
85
+ error_report("Unable to determine GIC version supported by host");
86
+ exit(1);
87
+ }
88
+
89
+ switch (vms->gic_version) {
90
+ case VIRT_GIC_VERSION_HOST:
91
+ case VIRT_GIC_VERSION_MAX:
92
+ if (probe_bitmap & KVM_ARM_VGIC_V3) {
93
+ vms->gic_version = VIRT_GIC_VERSION_3;
94
+ } else {
95
+ vms->gic_version = VIRT_GIC_VERSION_2;
96
+ }
97
+ return;
98
+ case VIRT_GIC_VERSION_NOSEL:
99
+ vms->gic_version = VIRT_GIC_VERSION_2;
100
+ break;
101
+ case VIRT_GIC_VERSION_2:
102
+ case VIRT_GIC_VERSION_3:
103
+ break;
104
+ }
105
+
106
+ /* Check chosen version is effectively supported by the host */
107
+ if (vms->gic_version == VIRT_GIC_VERSION_2 &&
108
+ !(probe_bitmap & KVM_ARM_VGIC_V2)) {
109
+ error_report("host does not support in-kernel GICv2 emulation");
110
+ exit(1);
111
+ } else if (vms->gic_version == VIRT_GIC_VERSION_3 &&
112
+ !(probe_bitmap & KVM_ARM_VGIC_V3)) {
113
+ error_report("host does not support in-kernel GICv3 emulation");
114
+ exit(1);
115
+ }
116
+ return;
24
+ return;
117
+ }
25
+ }
118
+
26
+
119
+ /* TCG mode */
27
gicv3_init_irqs_and_mmio(s, kvm_arm_gicv3_set_irq, NULL);
120
+ switch (vms->gic_version) {
28
121
+ case VIRT_GIC_VERSION_NOSEL:
29
for (i = 0; i < s->num_cpu; i++) {
122
vms->gic_version = VIRT_GIC_VERSION_2;
123
+ break;
124
+ case VIRT_GIC_VERSION_MAX:
125
+ vms->gic_version = VIRT_GIC_VERSION_3;
126
+ break;
127
+ case VIRT_GIC_VERSION_HOST:
128
+ error_report("gic-version=host requires KVM");
129
+ exit(1);
130
+ case VIRT_GIC_VERSION_2:
131
+ case VIRT_GIC_VERSION_3:
132
+ break;
133
}
134
}
135
136
--
30
--
137
2.20.1
31
2.34.1
138
139
diff view generated by jsdifflib
1
From: Niek Linnenbank <nieklinnenbank@gmail.com>
1
From: Jinjie Ruan <ruanjinjie@huawei.com>
2
2
3
Various Allwinner System on Chip designs contain multiple processors
3
A SPI, PPI or SGI interrupt can have non-maskable property. So maintain
4
that can be configured and reset using the generic CPU Configuration
4
non-maskable property in PendingIrq and GICR/GICD. Since add new device
5
module interface. This commit adds support for the Allwinner CPU
5
state, it also needs to be migrated, so also save NMI info in
6
configuration interface which emulates the following features:
6
vmstate_gicv3_cpu and vmstate_gicv3.
7
7
8
* CPU reset
8
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
9
* CPU status
9
Acked-by: Richard Henderson <richard.henderson@linaro.org>
10
10
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
11
Signed-off-by: Niek Linnenbank <nieklinnenbank@gmail.com>
11
Message-id: 20240407081733.3231820-16-ruanjinjie@huawei.com
12
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
13
Message-id: 20200311221854.30370-7-nieklinnenbank@gmail.com
14
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
15
---
13
---
16
hw/misc/Makefile.objs | 1 +
14
include/hw/intc/arm_gicv3_common.h | 4 ++++
17
include/hw/arm/allwinner-h3.h | 3 +
15
hw/intc/arm_gicv3_common.c | 38 ++++++++++++++++++++++++++++++
18
include/hw/misc/allwinner-cpucfg.h | 52 ++++++
16
2 files changed, 42 insertions(+)
19
hw/arm/allwinner-h3.c | 9 +-
20
hw/misc/allwinner-cpucfg.c | 282 +++++++++++++++++++++++++++++
21
hw/misc/trace-events | 5 +
22
6 files changed, 351 insertions(+), 1 deletion(-)
23
create mode 100644 include/hw/misc/allwinner-cpucfg.h
24
create mode 100644 hw/misc/allwinner-cpucfg.c
25
17
26
diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs
18
diff --git a/include/hw/intc/arm_gicv3_common.h b/include/hw/intc/arm_gicv3_common.h
27
index XXXXXXX..XXXXXXX 100644
19
index XXXXXXX..XXXXXXX 100644
28
--- a/hw/misc/Makefile.objs
20
--- a/include/hw/intc/arm_gicv3_common.h
29
+++ b/hw/misc/Makefile.objs
21
+++ b/include/hw/intc/arm_gicv3_common.h
30
@@ -XXX,XX +XXX,XX @@ common-obj-$(CONFIG_MACIO) += macio/
22
@@ -XXX,XX +XXX,XX @@ typedef struct {
31
common-obj-$(CONFIG_IVSHMEM_DEVICE) += ivshmem.o
23
int irq;
32
24
uint8_t prio;
33
common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-ccu.o
25
int grp;
34
+obj-$(CONFIG_ALLWINNER_H3) += allwinner-cpucfg.o
26
+ bool nmi;
35
common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-sysctrl.o
27
} PendingIrq;
36
common-obj-$(CONFIG_REALVIEW) += arm_sysctl.o
28
37
common-obj-$(CONFIG_NSERIES) += cbus.o
29
struct GICv3CPUState {
38
diff --git a/include/hw/arm/allwinner-h3.h b/include/hw/arm/allwinner-h3.h
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
39
index XXXXXXX..XXXXXXX 100644
55
index XXXXXXX..XXXXXXX 100644
40
--- a/include/hw/arm/allwinner-h3.h
56
--- a/hw/intc/arm_gicv3_common.c
41
+++ b/include/hw/arm/allwinner-h3.h
57
+++ b/hw/intc/arm_gicv3_common.c
42
@@ -XXX,XX +XXX,XX @@
58
@@ -XXX,XX +XXX,XX @@ const VMStateDescription vmstate_gicv3_gicv4 = {
43
#include "hw/timer/allwinner-a10-pit.h"
59
}
44
#include "hw/intc/arm_gic.h"
45
#include "hw/misc/allwinner-h3-ccu.h"
46
+#include "hw/misc/allwinner-cpucfg.h"
47
#include "hw/misc/allwinner-h3-sysctrl.h"
48
#include "target/arm/cpu.h"
49
50
@@ -XXX,XX +XXX,XX @@ enum {
51
AW_H3_GIC_CPU,
52
AW_H3_GIC_HYP,
53
AW_H3_GIC_VCPU,
54
+ AW_H3_CPUCFG,
55
AW_H3_SDRAM
56
};
60
};
57
61
58
@@ -XXX,XX +XXX,XX @@ typedef struct AwH3State {
62
+static bool gicv3_cpu_nmi_needed(void *opaque)
59
const hwaddr *memmap;
63
+{
60
AwA10PITState timer;
64
+ GICv3CPUState *cs = opaque;
61
AwH3ClockCtlState ccu;
62
+ AwCpuCfgState cpucfg;
63
AwH3SysCtrlState sysctrl;
64
GICState gic;
65
MemoryRegion sram_a1;
66
diff --git a/include/hw/misc/allwinner-cpucfg.h b/include/hw/misc/allwinner-cpucfg.h
67
new file mode 100644
68
index XXXXXXX..XXXXXXX
69
--- /dev/null
70
+++ b/include/hw/misc/allwinner-cpucfg.h
71
@@ -XXX,XX +XXX,XX @@
72
+/*
73
+ * Allwinner CPU Configuration Module emulation
74
+ *
75
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
76
+ *
77
+ * This program is free software: you can redistribute it and/or modify
78
+ * it under the terms of the GNU General Public License as published by
79
+ * the Free Software Foundation, either version 2 of the License, or
80
+ * (at your option) any later version.
81
+ *
82
+ * This program is distributed in the hope that it will be useful,
83
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
84
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
85
+ * GNU General Public License for more details.
86
+ *
87
+ * You should have received a copy of the GNU General Public License
88
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
89
+ */
90
+
65
+
91
+#ifndef HW_MISC_ALLWINNER_CPUCFG_H
66
+ return cs->gic->nmi_support;
92
+#define HW_MISC_ALLWINNER_CPUCFG_H
93
+
94
+#include "qom/object.h"
95
+#include "hw/sysbus.h"
96
+
97
+/**
98
+ * Object model
99
+ * @{
100
+ */
101
+
102
+#define TYPE_AW_CPUCFG "allwinner-cpucfg"
103
+#define AW_CPUCFG(obj) \
104
+ OBJECT_CHECK(AwCpuCfgState, (obj), TYPE_AW_CPUCFG)
105
+
106
+/** @} */
107
+
108
+/**
109
+ * Allwinner CPU Configuration Module instance state
110
+ */
111
+typedef struct AwCpuCfgState {
112
+ /*< private >*/
113
+ SysBusDevice parent_obj;
114
+ /*< public >*/
115
+
116
+ MemoryRegion iomem;
117
+ uint32_t gen_ctrl;
118
+ uint32_t super_standby;
119
+ uint32_t entry_addr;
120
+
121
+} AwCpuCfgState;
122
+
123
+#endif /* HW_MISC_ALLWINNER_CPUCFG_H */
124
diff --git a/hw/arm/allwinner-h3.c b/hw/arm/allwinner-h3.c
125
index XXXXXXX..XXXXXXX 100644
126
--- a/hw/arm/allwinner-h3.c
127
+++ b/hw/arm/allwinner-h3.c
128
@@ -XXX,XX +XXX,XX @@ const hwaddr allwinner_h3_memmap[] = {
129
[AW_H3_GIC_CPU] = 0x01c82000,
130
[AW_H3_GIC_HYP] = 0x01c84000,
131
[AW_H3_GIC_VCPU] = 0x01c86000,
132
+ [AW_H3_CPUCFG] = 0x01f01c00,
133
[AW_H3_SDRAM] = 0x40000000
134
};
135
136
@@ -XXX,XX +XXX,XX @@ struct AwH3Unimplemented {
137
{ "r_wdog", 0x01f01000, 1 * KiB },
138
{ "r_prcm", 0x01f01400, 1 * KiB },
139
{ "r_twd", 0x01f01800, 1 * KiB },
140
- { "r_cpucfg", 0x01f01c00, 1 * KiB },
141
{ "r_cir-rx", 0x01f02000, 1 * KiB },
142
{ "r_twi", 0x01f02400, 1 * KiB },
143
{ "r_uart", 0x01f02800, 1 * KiB },
144
@@ -XXX,XX +XXX,XX @@ static void allwinner_h3_init(Object *obj)
145
146
sysbus_init_child_obj(obj, "sysctrl", &s->sysctrl, sizeof(s->sysctrl),
147
TYPE_AW_H3_SYSCTRL);
148
+
149
+ sysbus_init_child_obj(obj, "cpucfg", &s->cpucfg, sizeof(s->cpucfg),
150
+ TYPE_AW_CPUCFG);
151
}
152
153
static void allwinner_h3_realize(DeviceState *dev, Error **errp)
154
@@ -XXX,XX +XXX,XX @@ static void allwinner_h3_realize(DeviceState *dev, Error **errp)
155
qdev_init_nofail(DEVICE(&s->sysctrl));
156
sysbus_mmio_map(SYS_BUS_DEVICE(&s->sysctrl), 0, s->memmap[AW_H3_SYSCTRL]);
157
158
+ /* CPU Configuration */
159
+ qdev_init_nofail(DEVICE(&s->cpucfg));
160
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->cpucfg), 0, s->memmap[AW_H3_CPUCFG]);
161
+
162
/* Universal Serial Bus */
163
sysbus_create_simple(TYPE_AW_H3_EHCI, s->memmap[AW_H3_EHCI0],
164
qdev_get_gpio_in(DEVICE(&s->gic),
165
diff --git a/hw/misc/allwinner-cpucfg.c b/hw/misc/allwinner-cpucfg.c
166
new file mode 100644
167
index XXXXXXX..XXXXXXX
168
--- /dev/null
169
+++ b/hw/misc/allwinner-cpucfg.c
170
@@ -XXX,XX +XXX,XX @@
171
+/*
172
+ * Allwinner CPU Configuration Module emulation
173
+ *
174
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
175
+ *
176
+ * This program is free software: you can redistribute it and/or modify
177
+ * it under the terms of the GNU General Public License as published by
178
+ * the Free Software Foundation, either version 2 of the License, or
179
+ * (at your option) any later version.
180
+ *
181
+ * This program is distributed in the hope that it will be useful,
182
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
183
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
184
+ * GNU General Public License for more details.
185
+ *
186
+ * You should have received a copy of the GNU General Public License
187
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
188
+ */
189
+
190
+#include "qemu/osdep.h"
191
+#include "qemu/units.h"
192
+#include "hw/sysbus.h"
193
+#include "migration/vmstate.h"
194
+#include "qemu/log.h"
195
+#include "qemu/module.h"
196
+#include "qemu/error-report.h"
197
+#include "qemu/timer.h"
198
+#include "hw/core/cpu.h"
199
+#include "target/arm/arm-powerctl.h"
200
+#include "target/arm/cpu.h"
201
+#include "hw/misc/allwinner-cpucfg.h"
202
+#include "trace.h"
203
+
204
+/* CPUCFG register offsets */
205
+enum {
206
+ REG_CPUS_RST_CTRL = 0x0000, /* CPUs Reset Control */
207
+ REG_CPU0_RST_CTRL = 0x0040, /* CPU#0 Reset Control */
208
+ REG_CPU0_CTRL = 0x0044, /* CPU#0 Control */
209
+ REG_CPU0_STATUS = 0x0048, /* CPU#0 Status */
210
+ REG_CPU1_RST_CTRL = 0x0080, /* CPU#1 Reset Control */
211
+ REG_CPU1_CTRL = 0x0084, /* CPU#1 Control */
212
+ REG_CPU1_STATUS = 0x0088, /* CPU#1 Status */
213
+ REG_CPU2_RST_CTRL = 0x00C0, /* CPU#2 Reset Control */
214
+ REG_CPU2_CTRL = 0x00C4, /* CPU#2 Control */
215
+ REG_CPU2_STATUS = 0x00C8, /* CPU#2 Status */
216
+ REG_CPU3_RST_CTRL = 0x0100, /* CPU#3 Reset Control */
217
+ REG_CPU3_CTRL = 0x0104, /* CPU#3 Control */
218
+ REG_CPU3_STATUS = 0x0108, /* CPU#3 Status */
219
+ REG_CPU_SYS_RST = 0x0140, /* CPU System Reset */
220
+ REG_CLK_GATING = 0x0144, /* CPU Clock Gating */
221
+ REG_GEN_CTRL = 0x0184, /* General Control */
222
+ REG_SUPER_STANDBY = 0x01A0, /* Super Standby Flag */
223
+ REG_ENTRY_ADDR = 0x01A4, /* Reset Entry Address */
224
+ REG_DBG_EXTERN = 0x01E4, /* Debug External */
225
+ REG_CNT64_CTRL = 0x0280, /* 64-bit Counter Control */
226
+ REG_CNT64_LOW = 0x0284, /* 64-bit Counter Low */
227
+ REG_CNT64_HIGH = 0x0288, /* 64-bit Counter High */
228
+};
229
+
230
+/* CPUCFG register flags */
231
+enum {
232
+ CPUX_RESET_RELEASED = ((1 << 1) | (1 << 0)),
233
+ CPUX_STATUS_SMP = (1 << 0),
234
+ CPU_SYS_RESET_RELEASED = (1 << 0),
235
+ CLK_GATING_ENABLE = ((1 << 8) | 0xF),
236
+};
237
+
238
+/* CPUCFG register reset values */
239
+enum {
240
+ REG_CLK_GATING_RST = 0x0000010F,
241
+ REG_GEN_CTRL_RST = 0x00000020,
242
+ REG_SUPER_STANDBY_RST = 0x0,
243
+ REG_CNT64_CTRL_RST = 0x0,
244
+};
245
+
246
+/* CPUCFG constants */
247
+enum {
248
+ CPU_EXCEPTION_LEVEL_ON_RESET = 3, /* EL3 */
249
+};
250
+
251
+static void allwinner_cpucfg_cpu_reset(AwCpuCfgState *s, uint8_t cpu_id)
252
+{
253
+ int ret;
254
+
255
+ trace_allwinner_cpucfg_cpu_reset(cpu_id, s->entry_addr);
256
+
257
+ ARMCPU *target_cpu = ARM_CPU(arm_get_cpu_by_id(cpu_id));
258
+ if (!target_cpu) {
259
+ /*
260
+ * Called with a bogus value for cpu_id. Guest error will
261
+ * already have been logged, we can simply return here.
262
+ */
263
+ return;
264
+ }
265
+ bool target_aa64 = arm_feature(&target_cpu->env, ARM_FEATURE_AARCH64);
266
+
267
+ ret = arm_set_cpu_on(cpu_id, s->entry_addr, 0,
268
+ CPU_EXCEPTION_LEVEL_ON_RESET, target_aa64);
269
+ if (ret != QEMU_ARM_POWERCTL_RET_SUCCESS) {
270
+ error_report("%s: failed to bring up CPU %d: err %d",
271
+ __func__, cpu_id, ret);
272
+ return;
273
+ }
274
+}
67
+}
275
+
68
+
276
+static uint64_t allwinner_cpucfg_read(void *opaque, hwaddr offset,
69
+static const VMStateDescription vmstate_gicv3_cpu_nmi = {
277
+ unsigned size)
70
+ .name = "arm_gicv3_cpu/nmi",
278
+{
279
+ const AwCpuCfgState *s = AW_CPUCFG(opaque);
280
+ uint64_t val = 0;
281
+
282
+ switch (offset) {
283
+ case REG_CPUS_RST_CTRL: /* CPUs Reset Control */
284
+ case REG_CPU_SYS_RST: /* CPU System Reset */
285
+ val = CPU_SYS_RESET_RELEASED;
286
+ break;
287
+ case REG_CPU0_RST_CTRL: /* CPU#0 Reset Control */
288
+ case REG_CPU1_RST_CTRL: /* CPU#1 Reset Control */
289
+ case REG_CPU2_RST_CTRL: /* CPU#2 Reset Control */
290
+ case REG_CPU3_RST_CTRL: /* CPU#3 Reset Control */
291
+ val = CPUX_RESET_RELEASED;
292
+ break;
293
+ case REG_CPU0_CTRL: /* CPU#0 Control */
294
+ case REG_CPU1_CTRL: /* CPU#1 Control */
295
+ case REG_CPU2_CTRL: /* CPU#2 Control */
296
+ case REG_CPU3_CTRL: /* CPU#3 Control */
297
+ val = 0;
298
+ break;
299
+ case REG_CPU0_STATUS: /* CPU#0 Status */
300
+ case REG_CPU1_STATUS: /* CPU#1 Status */
301
+ case REG_CPU2_STATUS: /* CPU#2 Status */
302
+ case REG_CPU3_STATUS: /* CPU#3 Status */
303
+ val = CPUX_STATUS_SMP;
304
+ break;
305
+ case REG_CLK_GATING: /* CPU Clock Gating */
306
+ val = CLK_GATING_ENABLE;
307
+ break;
308
+ case REG_GEN_CTRL: /* General Control */
309
+ val = s->gen_ctrl;
310
+ break;
311
+ case REG_SUPER_STANDBY: /* Super Standby Flag */
312
+ val = s->super_standby;
313
+ break;
314
+ case REG_ENTRY_ADDR: /* Reset Entry Address */
315
+ val = s->entry_addr;
316
+ break;
317
+ case REG_DBG_EXTERN: /* Debug External */
318
+ case REG_CNT64_CTRL: /* 64-bit Counter Control */
319
+ case REG_CNT64_LOW: /* 64-bit Counter Low */
320
+ case REG_CNT64_HIGH: /* 64-bit Counter High */
321
+ qemu_log_mask(LOG_UNIMP, "%s: unimplemented register at 0x%04x\n",
322
+ __func__, (uint32_t)offset);
323
+ break;
324
+ default:
325
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset 0x%04x\n",
326
+ __func__, (uint32_t)offset);
327
+ break;
328
+ }
329
+
330
+ trace_allwinner_cpucfg_read(offset, val, size);
331
+
332
+ return val;
333
+}
334
+
335
+static void allwinner_cpucfg_write(void *opaque, hwaddr offset,
336
+ uint64_t val, unsigned size)
337
+{
338
+ AwCpuCfgState *s = AW_CPUCFG(opaque);
339
+
340
+ trace_allwinner_cpucfg_write(offset, val, size);
341
+
342
+ switch (offset) {
343
+ case REG_CPUS_RST_CTRL: /* CPUs Reset Control */
344
+ case REG_CPU_SYS_RST: /* CPU System Reset */
345
+ break;
346
+ case REG_CPU0_RST_CTRL: /* CPU#0 Reset Control */
347
+ case REG_CPU1_RST_CTRL: /* CPU#1 Reset Control */
348
+ case REG_CPU2_RST_CTRL: /* CPU#2 Reset Control */
349
+ case REG_CPU3_RST_CTRL: /* CPU#3 Reset Control */
350
+ if (val) {
351
+ allwinner_cpucfg_cpu_reset(s, (offset - REG_CPU0_RST_CTRL) >> 6);
352
+ }
353
+ break;
354
+ case REG_CPU0_CTRL: /* CPU#0 Control */
355
+ case REG_CPU1_CTRL: /* CPU#1 Control */
356
+ case REG_CPU2_CTRL: /* CPU#2 Control */
357
+ case REG_CPU3_CTRL: /* CPU#3 Control */
358
+ case REG_CPU0_STATUS: /* CPU#0 Status */
359
+ case REG_CPU1_STATUS: /* CPU#1 Status */
360
+ case REG_CPU2_STATUS: /* CPU#2 Status */
361
+ case REG_CPU3_STATUS: /* CPU#3 Status */
362
+ case REG_CLK_GATING: /* CPU Clock Gating */
363
+ break;
364
+ case REG_GEN_CTRL: /* General Control */
365
+ s->gen_ctrl = val;
366
+ break;
367
+ case REG_SUPER_STANDBY: /* Super Standby Flag */
368
+ s->super_standby = val;
369
+ break;
370
+ case REG_ENTRY_ADDR: /* Reset Entry Address */
371
+ s->entry_addr = val;
372
+ break;
373
+ case REG_DBG_EXTERN: /* Debug External */
374
+ case REG_CNT64_CTRL: /* 64-bit Counter Control */
375
+ case REG_CNT64_LOW: /* 64-bit Counter Low */
376
+ case REG_CNT64_HIGH: /* 64-bit Counter High */
377
+ qemu_log_mask(LOG_UNIMP, "%s: unimplemented register at 0x%04x\n",
378
+ __func__, (uint32_t)offset);
379
+ break;
380
+ default:
381
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset 0x%04x\n",
382
+ __func__, (uint32_t)offset);
383
+ break;
384
+ }
385
+}
386
+
387
+static const MemoryRegionOps allwinner_cpucfg_ops = {
388
+ .read = allwinner_cpucfg_read,
389
+ .write = allwinner_cpucfg_write,
390
+ .endianness = DEVICE_NATIVE_ENDIAN,
391
+ .valid = {
392
+ .min_access_size = 4,
393
+ .max_access_size = 4,
394
+ },
395
+ .impl.min_access_size = 4,
396
+};
397
+
398
+static void allwinner_cpucfg_reset(DeviceState *dev)
399
+{
400
+ AwCpuCfgState *s = AW_CPUCFG(dev);
401
+
402
+ /* Set default values for registers */
403
+ s->gen_ctrl = REG_GEN_CTRL_RST;
404
+ s->super_standby = REG_SUPER_STANDBY_RST;
405
+ s->entry_addr = 0;
406
+}
407
+
408
+static void allwinner_cpucfg_init(Object *obj)
409
+{
410
+ SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
411
+ AwCpuCfgState *s = AW_CPUCFG(obj);
412
+
413
+ /* Memory mapping */
414
+ memory_region_init_io(&s->iomem, OBJECT(s), &allwinner_cpucfg_ops, s,
415
+ TYPE_AW_CPUCFG, 1 * KiB);
416
+ sysbus_init_mmio(sbd, &s->iomem);
417
+}
418
+
419
+static const VMStateDescription allwinner_cpucfg_vmstate = {
420
+ .name = "allwinner-cpucfg",
421
+ .version_id = 1,
71
+ .version_id = 1,
422
+ .minimum_version_id = 1,
72
+ .minimum_version_id = 1,
423
+ .fields = (VMStateField[]) {
73
+ .needed = gicv3_cpu_nmi_needed,
424
+ VMSTATE_UINT32(gen_ctrl, AwCpuCfgState),
74
+ .fields = (const VMStateField[]) {
425
+ VMSTATE_UINT32(super_standby, AwCpuCfgState),
75
+ VMSTATE_UINT32(gicr_inmir0, GICv3CPUState),
426
+ VMSTATE_UINT32(entry_addr, AwCpuCfgState),
427
+ VMSTATE_END_OF_LIST()
76
+ VMSTATE_END_OF_LIST()
428
+ }
77
+ }
429
+};
78
+};
430
+
79
+
431
+static void allwinner_cpucfg_class_init(ObjectClass *klass, void *data)
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)
432
+{
96
+{
433
+ DeviceClass *dc = DEVICE_CLASS(klass);
97
+ GICv3State *cs = opaque;
434
+
98
+
435
+ dc->reset = allwinner_cpucfg_reset;
99
+ return cs->nmi_support;
436
+ dc->vmsd = &allwinner_cpucfg_vmstate;
437
+}
100
+}
438
+
101
+
439
+static const TypeInfo allwinner_cpucfg_info = {
102
+const VMStateDescription vmstate_gicv3_gicd_nmi = {
440
+ .name = TYPE_AW_CPUCFG,
103
+ .name = "arm_gicv3/gicd_nmi",
441
+ .parent = TYPE_SYS_BUS_DEVICE,
104
+ .version_id = 1,
442
+ .instance_init = allwinner_cpucfg_init,
105
+ .minimum_version_id = 1,
443
+ .instance_size = sizeof(AwCpuCfgState),
106
+ .needed = gicv3_nmi_needed,
444
+ .class_init = allwinner_cpucfg_class_init,
107
+ .fields = (const VMStateField[]) {
108
+ VMSTATE_UINT32_ARRAY(nmi, GICv3State, GICV3_BMP_SIZE),
109
+ VMSTATE_END_OF_LIST()
110
+ }
445
+};
111
+};
446
+
112
+
447
+static void allwinner_cpucfg_register(void)
113
static const VMStateDescription vmstate_gicv3 = {
448
+{
114
.name = "arm_gicv3",
449
+ type_register_static(&allwinner_cpucfg_info);
115
.version_id = 1,
450
+}
116
@@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_gicv3 = {
451
+
117
},
452
+type_init(allwinner_cpucfg_register)
118
.subsections = (const VMStateDescription * const []) {
453
diff --git a/hw/misc/trace-events b/hw/misc/trace-events
119
&vmstate_gicv3_gicd_no_migration_shift_bug,
454
index XXXXXXX..XXXXXXX 100644
120
+ &vmstate_gicv3_gicd_nmi,
455
--- a/hw/misc/trace-events
121
NULL
456
+++ b/hw/misc/trace-events
122
}
457
@@ -XXX,XX +XXX,XX @@
123
};
458
# See docs/devel/tracing.txt for syntax documentation.
459
460
+# allwinner-cpucfg.c
461
+allwinner_cpucfg_cpu_reset(uint8_t cpu_id, uint32_t reset_addr) "id %u, reset_addr 0x%" PRIu32
462
+allwinner_cpucfg_read(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
463
+allwinner_cpucfg_write(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
464
+
465
# eccmemctl.c
466
ecc_mem_writel_mer(uint32_t val) "Write memory enable 0x%08x"
467
ecc_mem_writel_mdr(uint32_t val) "Write memory delay 0x%08x"
468
--
124
--
469
2.20.1
125
2.34.1
470
471
diff view generated by jsdifflib
1
From: Niek Linnenbank <nieklinnenbank@gmail.com>
1
From: Jinjie Ruan <ruanjinjie@huawei.com>
2
2
3
The Clock Control Unit is responsible for clock signal generation,
3
Add GICR_INMIR0 register and support access GICR_INMIR0.
4
configuration and distribution in the Allwinner H3 System on Chip.
5
This commit adds support for the Clock Control Unit which emulates
6
a simple read/write register interface.
7
4
8
Signed-off-by: Niek Linnenbank <nieklinnenbank@gmail.com>
5
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
9
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
10
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
7
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
11
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
8
Message-id: 20240407081733.3231820-17-ruanjinjie@huawei.com
12
Message-id: 20200311221854.30370-4-nieklinnenbank@gmail.com
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
14
---
10
---
15
hw/misc/Makefile.objs | 1 +
11
hw/intc/gicv3_internal.h | 1 +
16
include/hw/arm/allwinner-h3.h | 3 +
12
hw/intc/arm_gicv3_redist.c | 19 +++++++++++++++++++
17
include/hw/misc/allwinner-h3-ccu.h | 66 ++++++++
13
2 files changed, 20 insertions(+)
18
hw/arm/allwinner-h3.c | 9 +-
19
hw/misc/allwinner-h3-ccu.c | 242 +++++++++++++++++++++++++++++
20
5 files changed, 320 insertions(+), 1 deletion(-)
21
create mode 100644 include/hw/misc/allwinner-h3-ccu.h
22
create mode 100644 hw/misc/allwinner-h3-ccu.c
23
14
24
diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs
15
diff --git a/hw/intc/gicv3_internal.h b/hw/intc/gicv3_internal.h
25
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
26
--- a/hw/misc/Makefile.objs
17
--- a/hw/intc/gicv3_internal.h
27
+++ b/hw/misc/Makefile.objs
18
+++ b/hw/intc/gicv3_internal.h
28
@@ -XXX,XX +XXX,XX @@ common-obj-$(CONFIG_MACIO) += macio/
19
@@ -XXX,XX +XXX,XX @@
29
20
#define GICR_ICFGR1 (GICR_SGI_OFFSET + 0x0C04)
30
common-obj-$(CONFIG_IVSHMEM_DEVICE) += ivshmem.o
21
#define GICR_IGRPMODR0 (GICR_SGI_OFFSET + 0x0D00)
31
22
#define GICR_NSACR (GICR_SGI_OFFSET + 0x0E00)
32
+common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-ccu.o
23
+#define GICR_INMIR0 (GICR_SGI_OFFSET + 0x0F80)
33
common-obj-$(CONFIG_REALVIEW) += arm_sysctl.o
24
34
common-obj-$(CONFIG_NSERIES) += cbus.o
25
/* VLPI redistributor registers, offsets from VLPI_base */
35
common-obj-$(CONFIG_ECCMEMCTL) += eccmemctl.o
26
#define GICR_VPROPBASER (GICR_VLPI_OFFSET + 0x70)
36
diff --git a/include/hw/arm/allwinner-h3.h b/include/hw/arm/allwinner-h3.h
27
diff --git a/hw/intc/arm_gicv3_redist.c b/hw/intc/arm_gicv3_redist.c
37
index XXXXXXX..XXXXXXX 100644
28
index XXXXXXX..XXXXXXX 100644
38
--- a/include/hw/arm/allwinner-h3.h
29
--- a/hw/intc/arm_gicv3_redist.c
39
+++ b/include/hw/arm/allwinner-h3.h
30
+++ b/hw/intc/arm_gicv3_redist.c
40
@@ -XXX,XX +XXX,XX @@
31
@@ -XXX,XX +XXX,XX @@ static int gicr_ns_access(GICv3CPUState *cs, int irq)
41
#include "hw/arm/boot.h"
32
return extract32(cs->gicr_nsacr, irq * 2, 2);
42
#include "hw/timer/allwinner-a10-pit.h"
43
#include "hw/intc/arm_gic.h"
44
+#include "hw/misc/allwinner-h3-ccu.h"
45
#include "target/arm/cpu.h"
46
47
/**
48
@@ -XXX,XX +XXX,XX @@ enum {
49
AW_H3_SRAM_A1,
50
AW_H3_SRAM_A2,
51
AW_H3_SRAM_C,
52
+ AW_H3_CCU,
53
AW_H3_PIT,
54
AW_H3_UART0,
55
AW_H3_UART1,
56
@@ -XXX,XX +XXX,XX @@ typedef struct AwH3State {
57
ARMCPU cpus[AW_H3_NUM_CPUS];
58
const hwaddr *memmap;
59
AwA10PITState timer;
60
+ AwH3ClockCtlState ccu;
61
GICState gic;
62
MemoryRegion sram_a1;
63
MemoryRegion sram_a2;
64
diff --git a/include/hw/misc/allwinner-h3-ccu.h b/include/hw/misc/allwinner-h3-ccu.h
65
new file mode 100644
66
index XXXXXXX..XXXXXXX
67
--- /dev/null
68
+++ b/include/hw/misc/allwinner-h3-ccu.h
69
@@ -XXX,XX +XXX,XX @@
70
+/*
71
+ * Allwinner H3 Clock Control Unit emulation
72
+ *
73
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
74
+ *
75
+ * This program is free software: you can redistribute it and/or modify
76
+ * it under the terms of the GNU General Public License as published by
77
+ * the Free Software Foundation, either version 2 of the License, or
78
+ * (at your option) any later version.
79
+ *
80
+ * This program is distributed in the hope that it will be useful,
81
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
82
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
83
+ * GNU General Public License for more details.
84
+ *
85
+ * You should have received a copy of the GNU General Public License
86
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
87
+ */
88
+
89
+#ifndef HW_MISC_ALLWINNER_H3_CCU_H
90
+#define HW_MISC_ALLWINNER_H3_CCU_H
91
+
92
+#include "qom/object.h"
93
+#include "hw/sysbus.h"
94
+
95
+/**
96
+ * @name Constants
97
+ * @{
98
+ */
99
+
100
+/** Size of register I/O address space used by CCU device */
101
+#define AW_H3_CCU_IOSIZE (0x400)
102
+
103
+/** Total number of known registers */
104
+#define AW_H3_CCU_REGS_NUM (AW_H3_CCU_IOSIZE / sizeof(uint32_t))
105
+
106
+/** @} */
107
+
108
+/**
109
+ * @name Object model
110
+ * @{
111
+ */
112
+
113
+#define TYPE_AW_H3_CCU "allwinner-h3-ccu"
114
+#define AW_H3_CCU(obj) \
115
+ OBJECT_CHECK(AwH3ClockCtlState, (obj), TYPE_AW_H3_CCU)
116
+
117
+/** @} */
118
+
119
+/**
120
+ * Allwinner H3 CCU object instance state.
121
+ */
122
+typedef struct AwH3ClockCtlState {
123
+ /*< private >*/
124
+ SysBusDevice parent_obj;
125
+ /*< public >*/
126
+
127
+ /** Maps I/O registers in physical memory */
128
+ MemoryRegion iomem;
129
+
130
+ /** Array of hardware registers */
131
+ uint32_t regs[AW_H3_CCU_REGS_NUM];
132
+
133
+} AwH3ClockCtlState;
134
+
135
+#endif /* HW_MISC_ALLWINNER_H3_CCU_H */
136
diff --git a/hw/arm/allwinner-h3.c b/hw/arm/allwinner-h3.c
137
index XXXXXXX..XXXXXXX 100644
138
--- a/hw/arm/allwinner-h3.c
139
+++ b/hw/arm/allwinner-h3.c
140
@@ -XXX,XX +XXX,XX @@ const hwaddr allwinner_h3_memmap[] = {
141
[AW_H3_SRAM_A1] = 0x00000000,
142
[AW_H3_SRAM_A2] = 0x00044000,
143
[AW_H3_SRAM_C] = 0x00010000,
144
+ [AW_H3_CCU] = 0x01c20000,
145
[AW_H3_PIT] = 0x01c20c00,
146
[AW_H3_UART0] = 0x01c28000,
147
[AW_H3_UART1] = 0x01c28400,
148
@@ -XXX,XX +XXX,XX @@ struct AwH3Unimplemented {
149
{ "usb2-phy", 0x01c1c000, 4 * KiB },
150
{ "usb3-phy", 0x01c1d000, 4 * KiB },
151
{ "smc", 0x01c1e000, 4 * KiB },
152
- { "ccu", 0x01c20000, 1 * KiB },
153
{ "pio", 0x01c20800, 1 * KiB },
154
{ "owa", 0x01c21000, 1 * KiB },
155
{ "pwm", 0x01c21400, 1 * KiB },
156
@@ -XXX,XX +XXX,XX @@ static void allwinner_h3_init(Object *obj)
157
"clk0-freq", &error_abort);
158
object_property_add_alias(obj, "clk1-freq", OBJECT(&s->timer),
159
"clk1-freq", &error_abort);
160
+
161
+ sysbus_init_child_obj(obj, "ccu", &s->ccu, sizeof(s->ccu),
162
+ TYPE_AW_H3_CCU);
163
}
33
}
164
34
165
static void allwinner_h3_realize(DeviceState *dev, Error **errp)
35
+static void gicr_write_bitmap_reg(GICv3CPUState *cs, MemTxAttrs attrs,
166
@@ -XXX,XX +XXX,XX @@ static void allwinner_h3_realize(DeviceState *dev, Error **errp)
36
+ uint32_t *reg, uint32_t val)
167
memory_region_add_subregion(get_system_memory(), s->memmap[AW_H3_SRAM_C],
168
&s->sram_c);
169
170
+ /* Clock Control Unit */
171
+ qdev_init_nofail(DEVICE(&s->ccu));
172
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->ccu), 0, s->memmap[AW_H3_CCU]);
173
+
174
/* UART0. For future clocktree API: All UARTS are connected to APB2_CLK. */
175
serial_mm_init(get_system_memory(), s->memmap[AW_H3_UART0], 2,
176
qdev_get_gpio_in(DEVICE(&s->gic), AW_H3_GIC_SPI_UART0),
177
diff --git a/hw/misc/allwinner-h3-ccu.c b/hw/misc/allwinner-h3-ccu.c
178
new file mode 100644
179
index XXXXXXX..XXXXXXX
180
--- /dev/null
181
+++ b/hw/misc/allwinner-h3-ccu.c
182
@@ -XXX,XX +XXX,XX @@
183
+/*
184
+ * Allwinner H3 Clock Control Unit emulation
185
+ *
186
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
187
+ *
188
+ * This program is free software: you can redistribute it and/or modify
189
+ * it under the terms of the GNU General Public License as published by
190
+ * the Free Software Foundation, either version 2 of the License, or
191
+ * (at your option) any later version.
192
+ *
193
+ * This program is distributed in the hope that it will be useful,
194
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
195
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
196
+ * GNU General Public License for more details.
197
+ *
198
+ * You should have received a copy of the GNU General Public License
199
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
200
+ */
201
+
202
+#include "qemu/osdep.h"
203
+#include "qemu/units.h"
204
+#include "hw/sysbus.h"
205
+#include "migration/vmstate.h"
206
+#include "qemu/log.h"
207
+#include "qemu/module.h"
208
+#include "hw/misc/allwinner-h3-ccu.h"
209
+
210
+/* CCU register offsets */
211
+enum {
212
+ REG_PLL_CPUX = 0x0000, /* PLL CPUX Control */
213
+ REG_PLL_AUDIO = 0x0008, /* PLL Audio Control */
214
+ REG_PLL_VIDEO = 0x0010, /* PLL Video Control */
215
+ REG_PLL_VE = 0x0018, /* PLL VE Control */
216
+ REG_PLL_DDR = 0x0020, /* PLL DDR Control */
217
+ REG_PLL_PERIPH0 = 0x0028, /* PLL Peripherals 0 Control */
218
+ REG_PLL_GPU = 0x0038, /* PLL GPU Control */
219
+ REG_PLL_PERIPH1 = 0x0044, /* PLL Peripherals 1 Control */
220
+ REG_PLL_DE = 0x0048, /* PLL Display Engine Control */
221
+ REG_CPUX_AXI = 0x0050, /* CPUX/AXI Configuration */
222
+ REG_APB1 = 0x0054, /* ARM Peripheral Bus 1 Config */
223
+ REG_APB2 = 0x0058, /* ARM Peripheral Bus 2 Config */
224
+ REG_DRAM_CFG = 0x00F4, /* DRAM Configuration */
225
+ REG_MBUS = 0x00FC, /* MBUS Reset */
226
+ REG_PLL_TIME0 = 0x0200, /* PLL Stable Time 0 */
227
+ REG_PLL_TIME1 = 0x0204, /* PLL Stable Time 1 */
228
+ REG_PLL_CPUX_BIAS = 0x0220, /* PLL CPUX Bias */
229
+ REG_PLL_AUDIO_BIAS = 0x0224, /* PLL Audio Bias */
230
+ REG_PLL_VIDEO_BIAS = 0x0228, /* PLL Video Bias */
231
+ REG_PLL_VE_BIAS = 0x022C, /* PLL VE Bias */
232
+ REG_PLL_DDR_BIAS = 0x0230, /* PLL DDR Bias */
233
+ REG_PLL_PERIPH0_BIAS = 0x0234, /* PLL Peripherals 0 Bias */
234
+ REG_PLL_GPU_BIAS = 0x023C, /* PLL GPU Bias */
235
+ REG_PLL_PERIPH1_BIAS = 0x0244, /* PLL Peripherals 1 Bias */
236
+ REG_PLL_DE_BIAS = 0x0248, /* PLL Display Engine Bias */
237
+ REG_PLL_CPUX_TUNING = 0x0250, /* PLL CPUX Tuning */
238
+ REG_PLL_DDR_TUNING = 0x0260, /* PLL DDR Tuning */
239
+};
240
+
241
+#define REG_INDEX(offset) (offset / sizeof(uint32_t))
242
+
243
+/* CCU register flags */
244
+enum {
245
+ REG_DRAM_CFG_UPDATE = (1 << 16),
246
+};
247
+
248
+enum {
249
+ REG_PLL_ENABLE = (1 << 31),
250
+ REG_PLL_LOCK = (1 << 28),
251
+};
252
+
253
+
254
+/* CCU register reset values */
255
+enum {
256
+ REG_PLL_CPUX_RST = 0x00001000,
257
+ REG_PLL_AUDIO_RST = 0x00035514,
258
+ REG_PLL_VIDEO_RST = 0x03006207,
259
+ REG_PLL_VE_RST = 0x03006207,
260
+ REG_PLL_DDR_RST = 0x00001000,
261
+ REG_PLL_PERIPH0_RST = 0x00041811,
262
+ REG_PLL_GPU_RST = 0x03006207,
263
+ REG_PLL_PERIPH1_RST = 0x00041811,
264
+ REG_PLL_DE_RST = 0x03006207,
265
+ REG_CPUX_AXI_RST = 0x00010000,
266
+ REG_APB1_RST = 0x00001010,
267
+ REG_APB2_RST = 0x01000000,
268
+ REG_DRAM_CFG_RST = 0x00000000,
269
+ REG_MBUS_RST = 0x80000000,
270
+ REG_PLL_TIME0_RST = 0x000000FF,
271
+ REG_PLL_TIME1_RST = 0x000000FF,
272
+ REG_PLL_CPUX_BIAS_RST = 0x08100200,
273
+ REG_PLL_AUDIO_BIAS_RST = 0x10100000,
274
+ REG_PLL_VIDEO_BIAS_RST = 0x10100000,
275
+ REG_PLL_VE_BIAS_RST = 0x10100000,
276
+ REG_PLL_DDR_BIAS_RST = 0x81104000,
277
+ REG_PLL_PERIPH0_BIAS_RST = 0x10100010,
278
+ REG_PLL_GPU_BIAS_RST = 0x10100000,
279
+ REG_PLL_PERIPH1_BIAS_RST = 0x10100010,
280
+ REG_PLL_DE_BIAS_RST = 0x10100000,
281
+ REG_PLL_CPUX_TUNING_RST = 0x0A101000,
282
+ REG_PLL_DDR_TUNING_RST = 0x14880000,
283
+};
284
+
285
+static uint64_t allwinner_h3_ccu_read(void *opaque, hwaddr offset,
286
+ unsigned size)
287
+{
37
+{
288
+ const AwH3ClockCtlState *s = AW_H3_CCU(opaque);
38
+ /* Helper routine to implement writing to a "set" register */
289
+ const uint32_t idx = REG_INDEX(offset);
39
+ val &= mask_group(cs, attrs);
290
+
40
+ *reg = val;
291
+ switch (offset) {
41
+ gicv3_redist_update(cs);
292
+ case 0x308 ... AW_H3_CCU_IOSIZE:
293
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset 0x%04x\n",
294
+ __func__, (uint32_t)offset);
295
+ return 0;
296
+ }
297
+
298
+ return s->regs[idx];
299
+}
42
+}
300
+
43
+
301
+static void allwinner_h3_ccu_write(void *opaque, hwaddr offset,
44
static void gicr_write_set_bitmap_reg(GICv3CPUState *cs, MemTxAttrs attrs,
302
+ uint64_t val, unsigned size)
45
uint32_t *reg, uint32_t val)
303
+{
46
{
304
+ AwH3ClockCtlState *s = AW_H3_CCU(opaque);
47
@@ -XXX,XX +XXX,XX @@ static MemTxResult gicr_readl(GICv3CPUState *cs, hwaddr offset,
305
+ const uint32_t idx = REG_INDEX(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;
306
+
67
+
307
+ switch (offset) {
68
case GICR_ICFGR0:
308
+ case REG_DRAM_CFG: /* DRAM Configuration */
69
/* Register is all RAZ/WI or RAO/WI bits */
309
+ val &= ~REG_DRAM_CFG_UPDATE;
70
return MEMTX_OK;
310
+ break;
311
+ case REG_PLL_CPUX: /* PLL CPUX Control */
312
+ case REG_PLL_AUDIO: /* PLL Audio Control */
313
+ case REG_PLL_VIDEO: /* PLL Video Control */
314
+ case REG_PLL_VE: /* PLL VE Control */
315
+ case REG_PLL_DDR: /* PLL DDR Control */
316
+ case REG_PLL_PERIPH0: /* PLL Peripherals 0 Control */
317
+ case REG_PLL_GPU: /* PLL GPU Control */
318
+ case REG_PLL_PERIPH1: /* PLL Peripherals 1 Control */
319
+ case REG_PLL_DE: /* PLL Display Engine Control */
320
+ if (val & REG_PLL_ENABLE) {
321
+ val |= REG_PLL_LOCK;
322
+ }
323
+ break;
324
+ case 0x308 ... AW_H3_CCU_IOSIZE:
325
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset 0x%04x\n",
326
+ __func__, (uint32_t)offset);
327
+ break;
328
+ default:
329
+ qemu_log_mask(LOG_UNIMP, "%s: unimplemented write offset 0x%04x\n",
330
+ __func__, (uint32_t)offset);
331
+ break;
332
+ }
333
+
334
+ s->regs[idx] = (uint32_t) val;
335
+}
336
+
337
+static const MemoryRegionOps allwinner_h3_ccu_ops = {
338
+ .read = allwinner_h3_ccu_read,
339
+ .write = allwinner_h3_ccu_write,
340
+ .endianness = DEVICE_NATIVE_ENDIAN,
341
+ .valid = {
342
+ .min_access_size = 4,
343
+ .max_access_size = 4,
344
+ },
345
+ .impl.min_access_size = 4,
346
+};
347
+
348
+static void allwinner_h3_ccu_reset(DeviceState *dev)
349
+{
350
+ AwH3ClockCtlState *s = AW_H3_CCU(dev);
351
+
352
+ /* Set default values for registers */
353
+ s->regs[REG_INDEX(REG_PLL_CPUX)] = REG_PLL_CPUX_RST;
354
+ s->regs[REG_INDEX(REG_PLL_AUDIO)] = REG_PLL_AUDIO_RST;
355
+ s->regs[REG_INDEX(REG_PLL_VIDEO)] = REG_PLL_VIDEO_RST;
356
+ s->regs[REG_INDEX(REG_PLL_VE)] = REG_PLL_VE_RST;
357
+ s->regs[REG_INDEX(REG_PLL_DDR)] = REG_PLL_DDR_RST;
358
+ s->regs[REG_INDEX(REG_PLL_PERIPH0)] = REG_PLL_PERIPH0_RST;
359
+ s->regs[REG_INDEX(REG_PLL_GPU)] = REG_PLL_GPU_RST;
360
+ s->regs[REG_INDEX(REG_PLL_PERIPH1)] = REG_PLL_PERIPH1_RST;
361
+ s->regs[REG_INDEX(REG_PLL_DE)] = REG_PLL_DE_RST;
362
+ s->regs[REG_INDEX(REG_CPUX_AXI)] = REG_CPUX_AXI_RST;
363
+ s->regs[REG_INDEX(REG_APB1)] = REG_APB1_RST;
364
+ s->regs[REG_INDEX(REG_APB2)] = REG_APB2_RST;
365
+ s->regs[REG_INDEX(REG_DRAM_CFG)] = REG_DRAM_CFG_RST;
366
+ s->regs[REG_INDEX(REG_MBUS)] = REG_MBUS_RST;
367
+ s->regs[REG_INDEX(REG_PLL_TIME0)] = REG_PLL_TIME0_RST;
368
+ s->regs[REG_INDEX(REG_PLL_TIME1)] = REG_PLL_TIME1_RST;
369
+ s->regs[REG_INDEX(REG_PLL_CPUX_BIAS)] = REG_PLL_CPUX_BIAS_RST;
370
+ s->regs[REG_INDEX(REG_PLL_AUDIO_BIAS)] = REG_PLL_AUDIO_BIAS_RST;
371
+ s->regs[REG_INDEX(REG_PLL_VIDEO_BIAS)] = REG_PLL_VIDEO_BIAS_RST;
372
+ s->regs[REG_INDEX(REG_PLL_VE_BIAS)] = REG_PLL_VE_BIAS_RST;
373
+ s->regs[REG_INDEX(REG_PLL_DDR_BIAS)] = REG_PLL_DDR_BIAS_RST;
374
+ s->regs[REG_INDEX(REG_PLL_PERIPH0_BIAS)] = REG_PLL_PERIPH0_BIAS_RST;
375
+ s->regs[REG_INDEX(REG_PLL_GPU_BIAS)] = REG_PLL_GPU_BIAS_RST;
376
+ s->regs[REG_INDEX(REG_PLL_PERIPH1_BIAS)] = REG_PLL_PERIPH1_BIAS_RST;
377
+ s->regs[REG_INDEX(REG_PLL_DE_BIAS)] = REG_PLL_DE_BIAS_RST;
378
+ s->regs[REG_INDEX(REG_PLL_CPUX_TUNING)] = REG_PLL_CPUX_TUNING_RST;
379
+ s->regs[REG_INDEX(REG_PLL_DDR_TUNING)] = REG_PLL_DDR_TUNING_RST;
380
+}
381
+
382
+static void allwinner_h3_ccu_init(Object *obj)
383
+{
384
+ SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
385
+ AwH3ClockCtlState *s = AW_H3_CCU(obj);
386
+
387
+ /* Memory mapping */
388
+ memory_region_init_io(&s->iomem, OBJECT(s), &allwinner_h3_ccu_ops, s,
389
+ TYPE_AW_H3_CCU, AW_H3_CCU_IOSIZE);
390
+ sysbus_init_mmio(sbd, &s->iomem);
391
+}
392
+
393
+static const VMStateDescription allwinner_h3_ccu_vmstate = {
394
+ .name = "allwinner-h3-ccu",
395
+ .version_id = 1,
396
+ .minimum_version_id = 1,
397
+ .fields = (VMStateField[]) {
398
+ VMSTATE_UINT32_ARRAY(regs, AwH3ClockCtlState, AW_H3_CCU_REGS_NUM),
399
+ VMSTATE_END_OF_LIST()
400
+ }
401
+};
402
+
403
+static void allwinner_h3_ccu_class_init(ObjectClass *klass, void *data)
404
+{
405
+ DeviceClass *dc = DEVICE_CLASS(klass);
406
+
407
+ dc->reset = allwinner_h3_ccu_reset;
408
+ dc->vmsd = &allwinner_h3_ccu_vmstate;
409
+}
410
+
411
+static const TypeInfo allwinner_h3_ccu_info = {
412
+ .name = TYPE_AW_H3_CCU,
413
+ .parent = TYPE_SYS_BUS_DEVICE,
414
+ .instance_init = allwinner_h3_ccu_init,
415
+ .instance_size = sizeof(AwH3ClockCtlState),
416
+ .class_init = allwinner_h3_ccu_class_init,
417
+};
418
+
419
+static void allwinner_h3_ccu_register(void)
420
+{
421
+ type_register_static(&allwinner_h3_ccu_info);
422
+}
423
+
424
+type_init(allwinner_h3_ccu_register)
425
--
71
--
426
2.20.1
72
2.34.1
427
428
diff view generated by jsdifflib
1
From: Niek Linnenbank <nieklinnenbank@gmail.com>
1
From: Jinjie Ruan <ruanjinjie@huawei.com>
2
2
3
A real Allwinner H3 SoC contains a Boot ROM which is the
3
Add GICD_INMIR, GICD_INMIRnE register and support access GICD_INMIR0.
4
first code that runs right after the SoC is powered on.
5
The Boot ROM is responsible for loading user code (e.g. a bootloader)
6
from any of the supported external devices and writing the downloaded
7
code to internal SRAM. After loading the SoC begins executing the code
8
written to SRAM.
9
4
10
This commits adds emulation of the Boot ROM firmware setup functionality
5
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
11
by loading user code from SD card in the A1 SRAM. While the A1 SRAM is
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
12
64KiB, we limit the size to 32KiB because the real H3 Boot ROM also rejects
7
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
13
sizes larger than 32KiB. For reference, this behaviour is documented
8
Message-id: 20240407081733.3231820-18-ruanjinjie@huawei.com
14
by the Linux Sunxi project wiki at:
15
16
https://linux-sunxi.org/BROM#U-Boot_SPL_limitations
17
18
Signed-off-by: Niek Linnenbank <nieklinnenbank@gmail.com>
19
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
20
Message-id: 20200311221854.30370-11-nieklinnenbank@gmail.com
21
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
22
---
10
---
23
include/hw/arm/allwinner-h3.h | 21 +++++++++++++++++++++
11
hw/intc/gicv3_internal.h | 2 ++
24
hw/arm/allwinner-h3.c | 17 +++++++++++++++++
12
hw/intc/arm_gicv3_dist.c | 34 ++++++++++++++++++++++++++++++++++
25
hw/arm/orangepi.c | 5 +++++
13
2 files changed, 36 insertions(+)
26
3 files changed, 43 insertions(+)
27
14
28
diff --git a/include/hw/arm/allwinner-h3.h b/include/hw/arm/allwinner-h3.h
15
diff --git a/hw/intc/gicv3_internal.h b/hw/intc/gicv3_internal.h
29
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
30
--- a/include/hw/arm/allwinner-h3.h
17
--- a/hw/intc/gicv3_internal.h
31
+++ b/include/hw/arm/allwinner-h3.h
18
+++ b/hw/intc/gicv3_internal.h
32
@@ -XXX,XX +XXX,XX @@
19
@@ -XXX,XX +XXX,XX @@
33
#include "hw/sd/allwinner-sdhost.h"
20
#define GICD_SGIR 0x0F00
34
#include "hw/net/allwinner-sun8i-emac.h"
21
#define GICD_CPENDSGIR 0x0F10
35
#include "target/arm/cpu.h"
22
#define GICD_SPENDSGIR 0x0F20
36
+#include "sysemu/block-backend.h"
23
+#define GICD_INMIR 0x0F80
37
24
+#define GICD_INMIRnE 0x3B00
38
/**
25
#define GICD_IROUTER 0x6000
39
* Allwinner H3 device list
26
#define GICD_IDREGS 0xFFD0
40
@@ -XXX,XX +XXX,XX @@ typedef struct AwH3State {
27
41
MemoryRegion sram_c;
28
diff --git a/hw/intc/arm_gicv3_dist.c b/hw/intc/arm_gicv3_dist.c
42
} AwH3State;
29
index XXXXXXX..XXXXXXX 100644
43
30
--- a/hw/intc/arm_gicv3_dist.c
44
+/**
31
+++ b/hw/intc/arm_gicv3_dist.c
45
+ * Emulate Boot ROM firmware setup functionality.
32
@@ -XXX,XX +XXX,XX @@ static int gicd_ns_access(GICv3State *s, int irq)
46
+ *
33
return extract32(s->gicd_nsacr[irq / 16], (irq % 16) * 2, 2);
47
+ * A real Allwinner H3 SoC contains a Boot ROM
34
}
48
+ * which is the first code that runs right after
35
49
+ * the SoC is powered on. The Boot ROM is responsible
36
+static void gicd_write_bitmap_reg(GICv3State *s, MemTxAttrs attrs,
50
+ * for loading user code (e.g. a bootloader) from any
37
+ uint32_t *bmp, maskfn *maskfn,
51
+ * of the supported external devices and writing the
38
+ int offset, uint32_t val)
52
+ * downloaded code to internal SRAM. After loading the SoC
39
+{
53
+ * begins executing the code written to SRAM.
40
+ /*
54
+ *
41
+ * Helper routine to implement writing to a "set" register
55
+ * This function emulates the Boot ROM by copying 32 KiB
42
+ * (GICD_INMIR, etc).
56
+ * of data from the given block device and writes it to
43
+ * Semantics implemented here:
57
+ * the start of the first internal SRAM memory.
44
+ * RAZ/WI for SGIs, PPIs, unimplemented IRQs
58
+ *
45
+ * Bits corresponding to Group 0 or Secure Group 1 interrupts RAZ/WI.
59
+ * @s: Allwinner H3 state object pointer
46
+ * offset should be the offset in bytes of the register from the start
60
+ * @blk: Block backend device object pointer
47
+ * of its group.
61
+ */
48
+ */
62
+void allwinner_h3_bootrom_setup(AwH3State *s, BlockBackend *blk);
49
+ int irq = offset * 8;
63
+
50
+
64
#endif /* HW_ARM_ALLWINNER_H3_H */
51
+ if (irq < GIC_INTERNAL || irq >= s->num_irq) {
65
diff --git a/hw/arm/allwinner-h3.c b/hw/arm/allwinner-h3.c
66
index XXXXXXX..XXXXXXX 100644
67
--- a/hw/arm/allwinner-h3.c
68
+++ b/hw/arm/allwinner-h3.c
69
@@ -XXX,XX +XXX,XX @@
70
#include "hw/char/serial.h"
71
#include "hw/misc/unimp.h"
72
#include "hw/usb/hcd-ehci.h"
73
+#include "hw/loader.h"
74
#include "sysemu/sysemu.h"
75
#include "hw/arm/allwinner-h3.h"
76
77
@@ -XXX,XX +XXX,XX @@ enum {
78
AW_H3_GIC_NUM_SPI = 128
79
};
80
81
+void allwinner_h3_bootrom_setup(AwH3State *s, BlockBackend *blk)
82
+{
83
+ const int64_t rom_size = 32 * KiB;
84
+ g_autofree uint8_t *buffer = g_new0(uint8_t, rom_size);
85
+
86
+ if (blk_pread(blk, 8 * KiB, buffer, rom_size) < 0) {
87
+ error_setg(&error_fatal, "%s: failed to read BlockBackend data",
88
+ __func__);
89
+ return;
52
+ return;
90
+ }
53
+ }
91
+
54
+ val &= mask_group_and_nsacr(s, attrs, maskfn, irq);
92
+ rom_add_blob("allwinner-h3.bootrom", buffer, rom_size,
55
+ *gic_bmp_ptr32(bmp, irq) = val;
93
+ rom_size, s->memmap[AW_H3_SRAM_A1],
56
+ gicv3_update(s, irq, 32);
94
+ NULL, NULL, NULL, NULL, false);
95
+}
57
+}
96
+
58
+
97
static void allwinner_h3_init(Object *obj)
59
static void gicd_write_set_bitmap_reg(GICv3State *s, MemTxAttrs attrs,
98
{
60
uint32_t *bmp,
99
AwH3State *s = AW_H3(obj);
61
maskfn *maskfn,
100
diff --git a/hw/arm/orangepi.c b/hw/arm/orangepi.c
62
@@ -XXX,XX +XXX,XX @@ static bool gicd_readl(GICv3State *s, hwaddr offset,
101
index XXXXXXX..XXXXXXX 100644
63
/* RAZ/WI since affinity routing is always enabled */
102
--- a/hw/arm/orangepi.c
64
*data = 0;
103
+++ b/hw/arm/orangepi.c
65
return true;
104
@@ -XXX,XX +XXX,XX @@ static void orangepi_init(MachineState *machine)
66
+ case GICD_INMIR ... GICD_INMIR + 0x7f:
105
memory_region_add_subregion(get_system_memory(), h3->memmap[AW_H3_SDRAM],
67
+ *data = (!s->nmi_support) ? 0 :
106
machine->ram);
68
+ gicd_read_bitmap_reg(s, attrs, s->nmi, NULL,
107
69
+ offset - GICD_INMIR);
108
+ /* Load target kernel or start using BootROM */
70
+ return true;
109
+ if (!machine->kernel_filename && blk_is_available(blk)) {
71
case GICD_IROUTER ... GICD_IROUTER + 0x1fdf:
110
+ /* Use Boot ROM to copy data from SD card to SRAM */
72
{
111
+ allwinner_h3_bootrom_setup(h3, blk);
73
uint64_t r;
112
+ }
74
@@ -XXX,XX +XXX,XX @@ static bool gicd_writel(GICv3State *s, hwaddr offset,
113
orangepi_binfo.loader_start = h3->memmap[AW_H3_SDRAM];
75
case GICD_SPENDSGIR ... GICD_SPENDSGIR + 0xf:
114
orangepi_binfo.ram_size = machine->ram_size;
76
/* RAZ/WI since affinity routing is always enabled */
115
arm_load_kernel(ARM_CPU(first_cpu), machine, &orangepi_binfo);
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;
116
--
87
--
117
2.20.1
88
2.34.1
118
119
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
1
Add the NMIAR CPU interface registers which deal with acknowledging NMI.
2
2
3
This test boots a Linux kernel on a OrangePi PC board and verify
3
When introduce NMI interrupt, there are some updates to the semantics for the
4
the serial output is working.
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.
5
9
6
The kernel image and DeviceTree blob are built by the Armbian
10
And the APR and RPR has NMI bits which should be handled correctly.
7
project (based on Debian):
8
https://www.armbian.com/orange-pi-pc/
9
11
10
The cpio image used comes from the linux-build-test project:
12
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
11
https://github.com/groeck/linux-build-test
13
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
12
14
[PMM: Separate out whether cpuif supports NMI from whether the
13
If ARM is a target being built, "make check-acceptance" will
15
GIC proper (IRI) supports NMI]
14
automatically include this test by the use of the "arch:arm" tags.
16
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
15
17
Message-id: 20240407081733.3231820-19-ruanjinjie@huawei.com
16
Alternatively, this test can be run using:
17
18
$ avocado --show=console run -t machine:orangepi-pc tests/acceptance/boot_linux_console.py
19
console: Uncompressing Linux... done, booting the kernel.
20
console: Booting Linux on physical CPU 0x0
21
console: Linux version 4.20.7-sunxi (root@armbian.com) (gcc version 7.2.1 20171011 (Linaro GCC 7.2-2017.11)) #5.75 SMP Fri Feb 8 09:02:10 CET 2019
22
console: CPU: ARMv7 Processor [410fc075] revision 5 (ARMv7), cr=50c5387d
23
console: CPU: div instructions available: patching division code
24
console: CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
25
console: OF: fdt: Machine model: Xunlong Orange Pi PC
26
[...]
27
console: Trying to unpack rootfs image as initramfs...
28
console: Freeing initrd memory: 3256K
29
console: Freeing unused kernel memory: 1024K
30
console: Run /init as init process
31
console: mount: mounting devtmpfs on /dev failed: Device or resource busy
32
console: Starting logging: OK
33
console: Initializing random number generator... random: dd: uninitialized urandom read (512 bytes read)
34
console: done.
35
console: Starting network: OK
36
console: Found console ttyS0
37
console: Linux version 4.20.7-sunxi (root@armbian.com) (gcc version 7.2.1 20171011 (Linaro GCC 7.2-2017.11)) #5.75 SMP Fri Feb 8 09:02:10 CET 2019
38
console: Boot successful.
39
console: cat /proc/cpuinfo
40
console: / # cat /proc/cpuinfo
41
console: processor : 0
42
console: model name : ARMv7 Processor rev 5 (v7l)
43
console: BogoMIPS : 125.00
44
console: Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm
45
console: CPU implementer : 0x41
46
console: CPU architecture: 7
47
console: CPU variant : 0x0
48
console: CPU part : 0xc07
49
console: CPU revision : 5
50
[...]
51
console: processor : 3
52
console: model name : ARMv7 Processor rev 5 (v7l)
53
console: BogoMIPS : 125.00
54
console: Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm
55
console: CPU implementer : 0x41
56
console: CPU architecture: 7
57
console: CPU variant : 0x0
58
console: CPU part : 0xc07
59
console: CPU revision : 5
60
console: Hardware : Allwinner sun8i Family
61
console: Revision : 0000
62
console: Serial : 0000000000000000
63
console: cat /proc/iomem
64
console: / # cat /proc/iomem
65
console: 01000000-010fffff : clock@1000000
66
console: 01c00000-01c00fff : system-control@1c00000
67
console: 01c02000-01c02fff : dma-controller@1c02000
68
[...]
69
console: reboot
70
console: / # reboot
71
console: / # Found console ttyS0
72
console: Stopping network: OK
73
console: hrtimer: interrupt took 21852064 ns
74
console: Saving random seed... random: dd: uninitialized urandom read (512 bytes read)
75
console: done.
76
console: Stopping logging: OK
77
console: umount: devtmpfs busy - remounted read-only
78
console: umount: can't unmount /: Invalid argument
79
console: The system is going down NOW!
80
console: Sent SIGTERM to all processes
81
console: Sent SIGKILL to all processes
82
console: Requesting system reboot
83
console: reboot: Restarting system
84
PASS (48.32 s)
85
JOB TIME : 49.16 s
86
87
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
88
Signed-off-by: Niek Linnenbank <nieklinnenbank@gmail.com>
89
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
90
Tested-by: Alex Bennée <alex.bennee@linaro.org>
91
Message-id: 20200311221854.30370-15-nieklinnenbank@gmail.com
92
[NL: rename in commit message Raspbian to Armbian, remove vm.set_machine()]
93
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
18
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
94
---
19
---
95
tests/acceptance/boot_linux_console.py | 40 ++++++++++++++++++++++++++
20
hw/intc/gicv3_internal.h | 5 +
96
1 file changed, 40 insertions(+)
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(-)
97
25
98
diff --git a/tests/acceptance/boot_linux_console.py b/tests/acceptance/boot_linux_console.py
26
diff --git a/hw/intc/gicv3_internal.h b/hw/intc/gicv3_internal.h
99
index XXXXXXX..XXXXXXX 100644
27
index XXXXXXX..XXXXXXX 100644
100
--- a/tests/acceptance/boot_linux_console.py
28
--- a/hw/intc/gicv3_internal.h
101
+++ b/tests/acceptance/boot_linux_console.py
29
+++ b/hw/intc/gicv3_internal.h
102
@@ -XXX,XX +XXX,XX @@ class BootLinuxConsole(Test):
30
@@ -XXX,XX +XXX,XX @@ FIELD(GICR_VPENDBASER, VALID, 63, 1)
103
console_pattern = 'Kernel command line: %s' % kernel_command_line
31
#define ICC_CTLR_EL3_A3V (1U << 15)
104
self.wait_for_console_pattern(console_pattern)
32
#define ICC_CTLR_EL3_NDS (1U << 17)
105
33
106
+ def test_arm_orangepi_initrd(self):
34
+#define ICC_AP1R_EL1_NMI (1ULL << 63)
107
+ """
35
+#define ICC_RPR_EL1_NSNMI (1ULL << 62)
108
+ :avocado: tags=arch:arm
36
+#define ICC_RPR_EL1_NMI (1ULL << 63)
109
+ :avocado: tags=machine:orangepi-pc
37
+
110
+ """
38
#define ICH_VMCR_EL2_VENG0_SHIFT 0
111
+ deb_url = ('https://apt.armbian.com/pool/main/l/'
39
#define ICH_VMCR_EL2_VENG0 (1U << ICH_VMCR_EL2_VENG0_SHIFT)
112
+ 'linux-4.20.7-sunxi/linux-image-dev-sunxi_5.75_armhf.deb')
40
#define ICH_VMCR_EL2_VENG1_SHIFT 1
113
+ deb_hash = '1334c29c44d984ffa05ed10de8c3361f33d78315'
41
@@ -XXX,XX +XXX,XX @@ FIELD(VTE, RDBASE, 42, RDBASE_PROCNUM_LENGTH)
114
+ deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
42
/* Special interrupt IDs */
115
+ kernel_path = self.extract_from_deb(deb_path,
43
#define INTID_SECURE 1020
116
+ '/boot/vmlinuz-4.20.7-sunxi')
44
#define INTID_NONSECURE 1021
117
+ dtb_path = '/usr/lib/linux-image-dev-sunxi/sun8i-h3-orangepi-pc.dtb'
45
+#define INTID_NMI 1022
118
+ dtb_path = self.extract_from_deb(deb_path, dtb_path)
46
#define INTID_SPURIOUS 1023
119
+ initrd_url = ('https://github.com/groeck/linux-build-test/raw/'
47
120
+ '2eb0a73b5d5a28df3170c546ddaaa9757e1e0848/rootfs/'
48
/* Functions internal to the emulated GICv3 */
121
+ 'arm/rootfs-armv7a.cpio.gz')
49
diff --git a/include/hw/intc/arm_gicv3_common.h b/include/hw/intc/arm_gicv3_common.h
122
+ initrd_hash = '604b2e45cdf35045846b8bbfbf2129b1891bdc9c'
50
index XXXXXXX..XXXXXXX 100644
123
+ initrd_path_gz = self.fetch_asset(initrd_url, asset_hash=initrd_hash)
51
--- a/include/hw/intc/arm_gicv3_common.h
124
+ initrd_path = os.path.join(self.workdir, 'rootfs.cpio')
52
+++ b/include/hw/intc/arm_gicv3_common.h
125
+ archive.gzip_uncompress(initrd_path_gz, initrd_path)
53
@@ -XXX,XX +XXX,XX @@ struct GICv3CPUState {
126
+
54
127
+ self.vm.set_console()
55
/* This is temporary working state, to avoid a malloc in gicv3_update() */
128
+ kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
56
bool seenbetter;
129
+ 'console=ttyS0,115200 '
57
+
130
+ 'panic=-1 noreboot')
58
+ /*
131
+ self.vm.add_args('-kernel', kernel_path,
59
+ * Whether the CPU interface has NMI support (FEAT_GICv3_NMI). The
132
+ '-dtb', dtb_path,
60
+ * CPU interface may support NMIs even when the GIC proper (what the
133
+ '-initrd', initrd_path,
61
+ * spec calls the IRI; the redistributors and distributor) does not.
134
+ '-append', kernel_command_line,
62
+ */
135
+ '-no-reboot')
63
+ bool nmi_support;
136
+ self.vm.launch()
64
};
137
+ self.wait_for_console_pattern('Boot successful.')
65
138
+
66
/*
139
+ exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
67
diff --git a/hw/intc/arm_gicv3_cpuif.c b/hw/intc/arm_gicv3_cpuif.c
140
+ 'Allwinner sun8i Family')
68
index XXXXXXX..XXXXXXX 100644
141
+ exec_command_and_wait_for_pattern(self, 'cat /proc/iomem',
69
--- a/hw/intc/arm_gicv3_cpuif.c
142
+ 'system-control@1c00000')
70
+++ b/hw/intc/arm_gicv3_cpuif.c
143
+ exec_command_and_wait_for_pattern(self, 'reboot',
71
@@ -XXX,XX +XXX,XX @@
144
+ 'reboot: Restarting system')
72
#include "hw/irq.h"
145
+
73
#include "cpu.h"
146
def test_s390x_s390_ccw_virtio(self):
74
#include "target/arm/cpregs.h"
147
"""
75
+#include "target/arm/cpu-features.h"
148
:avocado: tags=arch:s390x
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
149
--
347
--
150
2.20.1
348
2.34.1
151
152
diff view generated by jsdifflib
1
From: Niek Linnenbank <nieklinnenbank@gmail.com>
1
Implement icv_nmiar1_read() for icc_nmiar1_read(), so add definition for
2
2
ICH_LR_EL2.NMI and ICH_AP1R_EL2.NMI bit.
3
The Allwinner System on Chip families sun4i and above contain
3
4
an integrated storage controller for Secure Digital (SD) and
4
If FEAT_GICv3_NMI is supported, ich_ap_write() should consider ICV_AP1R_EL1.NMI
5
Multi Media Card (MMC) interfaces. This commit adds support
5
bit. In icv_activate_irq() and icv_eoir_write(), the ICV_AP1R_EL1.NMI bit
6
for the Allwinner SD/MMC storage controller with the following
6
should be set or clear according to the Non-maskable property. And the RPR
7
emulated features:
7
priority should also update the NMI bit according to the APR priority NMI bit.
8
8
9
* DMA transfers
9
By the way, add gicv3_icv_nmiar1_read trace event.
10
* Direct FIFO I/O
10
11
* Short/Long format command responses
11
If the hpp irq is a NMI, the icv iar read should return 1022 and trap for
12
* Auto-Stop command (CMD12)
12
NMI again
13
* Insert & remove card detection
13
14
14
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
15
The following boards are extended with the SD host controller:
15
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
16
16
[PMM: use cs->nmi_support instead of cs->gic->nmi_support]
17
* Cubieboard (hw/arm/cubieboard.c)
17
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
18
* Orange Pi PC (hw/arm/orangepi.c)
18
Message-id: 20240407081733.3231820-20-ruanjinjie@huawei.com
19
20
Signed-off-by: Niek Linnenbank <nieklinnenbank@gmail.com>
21
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
22
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
23
Message-id: 20200311221854.30370-9-nieklinnenbank@gmail.com
24
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
19
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
25
---
20
---
26
hw/sd/Makefile.objs | 1 +
21
hw/intc/gicv3_internal.h | 4 ++
27
include/hw/arm/allwinner-a10.h | 2 +
22
hw/intc/arm_gicv3_cpuif.c | 105 +++++++++++++++++++++++++++++++++-----
28
include/hw/arm/allwinner-h3.h | 3 +
23
hw/intc/trace-events | 1 +
29
include/hw/sd/allwinner-sdhost.h | 135 +++++
24
3 files changed, 98 insertions(+), 12 deletions(-)
30
hw/arm/allwinner-a10.c | 11 +
25
31
hw/arm/allwinner-h3.c | 15 +-
26
diff --git a/hw/intc/gicv3_internal.h b/hw/intc/gicv3_internal.h
32
hw/arm/cubieboard.c | 15 +
33
hw/arm/orangepi.c | 16 +
34
hw/sd/allwinner-sdhost.c | 854 +++++++++++++++++++++++++++++++
35
hw/arm/Kconfig | 1 +
36
hw/sd/trace-events | 7 +
37
11 files changed, 1059 insertions(+), 1 deletion(-)
38
create mode 100644 include/hw/sd/allwinner-sdhost.h
39
create mode 100644 hw/sd/allwinner-sdhost.c
40
41
diff --git a/hw/sd/Makefile.objs b/hw/sd/Makefile.objs
42
index XXXXXXX..XXXXXXX 100644
27
index XXXXXXX..XXXXXXX 100644
43
--- a/hw/sd/Makefile.objs
28
--- a/hw/intc/gicv3_internal.h
44
+++ b/hw/sd/Makefile.objs
29
+++ b/hw/intc/gicv3_internal.h
45
@@ -XXX,XX +XXX,XX @@ common-obj-$(CONFIG_SD) += sd.o core.o sdmmc-internal.o
30
@@ -XXX,XX +XXX,XX @@ FIELD(GICR_VPENDBASER, VALID, 63, 1)
46
common-obj-$(CONFIG_SDHCI) += sdhci.o
31
#define ICH_LR_EL2_PRIORITY_SHIFT 48
47
common-obj-$(CONFIG_SDHCI_PCI) += sdhci-pci.o
32
#define ICH_LR_EL2_PRIORITY_LENGTH 8
48
33
#define ICH_LR_EL2_PRIORITY_MASK (0xffULL << ICH_LR_EL2_PRIORITY_SHIFT)
49
+common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-sdhost.o
34
+#define ICH_LR_EL2_NMI (1ULL << 59)
50
common-obj-$(CONFIG_MILKYMIST) += milkymist-memcard.o
35
#define ICH_LR_EL2_GROUP (1ULL << 60)
51
common-obj-$(CONFIG_OMAP) += omap_mmc.o
36
#define ICH_LR_EL2_HW (1ULL << 61)
52
common-obj-$(CONFIG_PXA2XX) += pxa2xx_mmci.o
37
#define ICH_LR_EL2_STATE_SHIFT 62
53
diff --git a/include/hw/arm/allwinner-a10.h b/include/hw/arm/allwinner-a10.h
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
54
index XXXXXXX..XXXXXXX 100644
49
index XXXXXXX..XXXXXXX 100644
55
--- a/include/hw/arm/allwinner-a10.h
50
--- a/hw/intc/arm_gicv3_cpuif.c
56
+++ b/include/hw/arm/allwinner-a10.h
51
+++ b/hw/intc/arm_gicv3_cpuif.c
57
@@ -XXX,XX +XXX,XX @@
52
@@ -XXX,XX +XXX,XX @@ static int ich_highest_active_virt_prio(GICv3CPUState *cs)
58
#include "hw/timer/allwinner-a10-pit.h"
53
int i;
59
#include "hw/intc/allwinner-a10-pic.h"
54
int aprmax = ich_num_aprs(cs);
60
#include "hw/net/allwinner_emac.h"
55
61
+#include "hw/sd/allwinner-sdhost.h"
56
+ if (cs->ich_apr[GICV3_G1NS][0] & ICV_AP1R_EL1_NMI) {
62
#include "hw/ide/ahci.h"
57
+ return 0x0;
63
#include "hw/usb/hcd-ohci.h"
58
+ }
64
#include "hw/usb/hcd-ehci.h"
59
+
65
@@ -XXX,XX +XXX,XX @@ typedef struct AwA10State {
60
for (i = 0; i < aprmax; i++) {
66
AwA10PICState intc;
61
uint32_t apr = cs->ich_apr[GICV3_G0][i] |
67
AwEmacState emac;
62
cs->ich_apr[GICV3_G1NS][i];
68
AllwinnerAHCIState sata;
63
@@ -XXX,XX +XXX,XX @@ static int hppvi_index(GICv3CPUState *cs)
69
+ AwSdHostState mmc0;
64
* correct behaviour.
70
MemoryRegion sram_a;
65
*/
71
EHCISysBusState ehci[AW_A10_NUM_USB];
66
int prio = 0xff;
72
OHCISysBusState ohci[AW_A10_NUM_USB];
67
+ bool nmi = false;
73
diff --git a/include/hw/arm/allwinner-h3.h b/include/hw/arm/allwinner-h3.h
68
74
index XXXXXXX..XXXXXXX 100644
69
if (!(cs->ich_vmcr_el2 & (ICH_VMCR_EL2_VENG0 | ICH_VMCR_EL2_VENG1))) {
75
--- a/include/hw/arm/allwinner-h3.h
70
/* Both groups disabled, definitely nothing to do */
76
+++ b/include/hw/arm/allwinner-h3.h
71
@@ -XXX,XX +XXX,XX @@ static int hppvi_index(GICv3CPUState *cs)
77
@@ -XXX,XX +XXX,XX @@
72
78
#include "hw/misc/allwinner-cpucfg.h"
73
for (i = 0; i < cs->num_list_regs; i++) {
79
#include "hw/misc/allwinner-h3-sysctrl.h"
74
uint64_t lr = cs->ich_lr_el2[i];
80
#include "hw/misc/allwinner-sid.h"
75
+ bool thisnmi;
81
+#include "hw/sd/allwinner-sdhost.h"
76
int thisprio;
82
#include "target/arm/cpu.h"
77
83
78
if (ich_lr_state(lr) != ICH_LR_EL2_STATE_PENDING) {
84
/**
79
@@ -XXX,XX +XXX,XX @@ static int hppvi_index(GICv3CPUState *cs)
85
@@ -XXX,XX +XXX,XX @@ enum {
80
}
86
AW_H3_SRAM_A2,
81
}
87
AW_H3_SRAM_C,
82
88
AW_H3_SYSCTRL,
83
+ thisnmi = lr & ICH_LR_EL2_NMI;
89
+ AW_H3_MMC0,
84
thisprio = ich_lr_prio(lr);
90
AW_H3_SID,
85
91
AW_H3_EHCI0,
86
- if (thisprio < prio) {
92
AW_H3_OHCI0,
87
+ if ((thisprio < prio) || ((thisprio == prio) && (thisnmi & (!nmi)))) {
93
@@ -XXX,XX +XXX,XX @@ typedef struct AwH3State {
88
prio = thisprio;
94
AwCpuCfgState cpucfg;
89
+ nmi = thisnmi;
95
AwH3SysCtrlState sysctrl;
90
idx = i;
96
AwSidState sid;
97
+ AwSdHostState mmc0;
98
GICState gic;
99
MemoryRegion sram_a1;
100
MemoryRegion sram_a2;
101
diff --git a/include/hw/sd/allwinner-sdhost.h b/include/hw/sd/allwinner-sdhost.h
102
new file mode 100644
103
index XXXXXXX..XXXXXXX
104
--- /dev/null
105
+++ b/include/hw/sd/allwinner-sdhost.h
106
@@ -XXX,XX +XXX,XX @@
107
+/*
108
+ * Allwinner (sun4i and above) SD Host Controller emulation
109
+ *
110
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
111
+ *
112
+ * This program is free software: you can redistribute it and/or modify
113
+ * it under the terms of the GNU General Public License as published by
114
+ * the Free Software Foundation, either version 2 of the License, or
115
+ * (at your option) any later version.
116
+ *
117
+ * This program is distributed in the hope that it will be useful,
118
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
119
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
120
+ * GNU General Public License for more details.
121
+ *
122
+ * You should have received a copy of the GNU General Public License
123
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
124
+ */
125
+
126
+#ifndef HW_SD_ALLWINNER_SDHOST_H
127
+#define HW_SD_ALLWINNER_SDHOST_H
128
+
129
+#include "qom/object.h"
130
+#include "hw/sysbus.h"
131
+#include "hw/sd/sd.h"
132
+
133
+/**
134
+ * Object model types
135
+ * @{
136
+ */
137
+
138
+/** Generic Allwinner SD Host Controller (abstract) */
139
+#define TYPE_AW_SDHOST "allwinner-sdhost"
140
+
141
+/** Allwinner sun4i family (A10, A12) */
142
+#define TYPE_AW_SDHOST_SUN4I TYPE_AW_SDHOST "-sun4i"
143
+
144
+/** Allwinner sun5i family and newer (A13, H2+, H3, etc) */
145
+#define TYPE_AW_SDHOST_SUN5I TYPE_AW_SDHOST "-sun5i"
146
+
147
+/** @} */
148
+
149
+/**
150
+ * Object model macros
151
+ * @{
152
+ */
153
+
154
+#define AW_SDHOST(obj) \
155
+ OBJECT_CHECK(AwSdHostState, (obj), TYPE_AW_SDHOST)
156
+#define AW_SDHOST_CLASS(klass) \
157
+ OBJECT_CLASS_CHECK(AwSdHostClass, (klass), TYPE_AW_SDHOST)
158
+#define AW_SDHOST_GET_CLASS(obj) \
159
+ OBJECT_GET_CLASS(AwSdHostClass, (obj), TYPE_AW_SDHOST)
160
+
161
+/** @} */
162
+
163
+/**
164
+ * Allwinner SD Host Controller object instance state.
165
+ */
166
+typedef struct AwSdHostState {
167
+ /*< private >*/
168
+ SysBusDevice busdev;
169
+ /*< public >*/
170
+
171
+ /** Secure Digital (SD) bus, which connects to SD card (if present) */
172
+ SDBus sdbus;
173
+
174
+ /** Maps I/O registers in physical memory */
175
+ MemoryRegion iomem;
176
+
177
+ /** Interrupt output signal to notify CPU */
178
+ qemu_irq irq;
179
+
180
+ /** Number of bytes left in current DMA transfer */
181
+ uint32_t transfer_cnt;
182
+
183
+ /**
184
+ * @name Hardware Registers
185
+ * @{
186
+ */
187
+
188
+ uint32_t global_ctl; /**< Global Control */
189
+ uint32_t clock_ctl; /**< Clock Control */
190
+ uint32_t timeout; /**< Timeout */
191
+ uint32_t bus_width; /**< Bus Width */
192
+ uint32_t block_size; /**< Block Size */
193
+ uint32_t byte_count; /**< Byte Count */
194
+
195
+ uint32_t command; /**< Command */
196
+ uint32_t command_arg; /**< Command Argument */
197
+ uint32_t response[4]; /**< Command Response */
198
+
199
+ uint32_t irq_mask; /**< Interrupt Mask */
200
+ uint32_t irq_status; /**< Raw Interrupt Status */
201
+ uint32_t status; /**< Status */
202
+
203
+ uint32_t fifo_wlevel; /**< FIFO Water Level */
204
+ uint32_t fifo_func_sel; /**< FIFO Function Select */
205
+ uint32_t debug_enable; /**< Debug Enable */
206
+ uint32_t auto12_arg; /**< Auto Command 12 Argument */
207
+ uint32_t newtiming_set; /**< SD New Timing Set */
208
+ uint32_t newtiming_debug; /**< SD New Timing Debug */
209
+ uint32_t hardware_rst; /**< Hardware Reset */
210
+ uint32_t dmac; /**< Internal DMA Controller Control */
211
+ uint32_t desc_base; /**< Descriptor List Base Address */
212
+ uint32_t dmac_status; /**< Internal DMA Controller Status */
213
+ uint32_t dmac_irq; /**< Internal DMA Controller IRQ Enable */
214
+ uint32_t card_threshold; /**< Card Threshold Control */
215
+ uint32_t startbit_detect; /**< eMMC DDR Start Bit Detection Control */
216
+ uint32_t response_crc; /**< Response CRC */
217
+ uint32_t data_crc[8]; /**< Data CRC */
218
+ uint32_t status_crc; /**< Status CRC */
219
+
220
+ /** @} */
221
+
222
+} AwSdHostState;
223
+
224
+/**
225
+ * Allwinner SD Host Controller class-level struct.
226
+ *
227
+ * This struct is filled by each sunxi device specific code
228
+ * such that the generic code can use this struct to support
229
+ * all devices.
230
+ */
231
+typedef struct AwSdHostClass {
232
+ /*< private >*/
233
+ SysBusDeviceClass parent_class;
234
+ /*< public >*/
235
+
236
+ /** Maximum buffer size in bytes per DMA descriptor */
237
+ size_t max_desc_size;
238
+
239
+} AwSdHostClass;
240
+
241
+#endif /* HW_SD_ALLWINNER_SDHOST_H */
242
diff --git a/hw/arm/allwinner-a10.c b/hw/arm/allwinner-a10.c
243
index XXXXXXX..XXXXXXX 100644
244
--- a/hw/arm/allwinner-a10.c
245
+++ b/hw/arm/allwinner-a10.c
246
@@ -XXX,XX +XXX,XX @@
247
#include "hw/boards.h"
248
#include "hw/usb/hcd-ohci.h"
249
250
+#define AW_A10_MMC0_BASE 0x01c0f000
251
#define AW_A10_PIC_REG_BASE 0x01c20400
252
#define AW_A10_PIT_REG_BASE 0x01c20c00
253
#define AW_A10_UART0_REG_BASE 0x01c28000
254
@@ -XXX,XX +XXX,XX @@ static void aw_a10_init(Object *obj)
255
sizeof(s->ohci[i]), TYPE_SYSBUS_OHCI);
256
}
91
}
257
}
92
}
258
+
93
@@ -XXX,XX +XXX,XX @@ static bool icv_hppi_can_preempt(GICv3CPUState *cs, uint64_t lr)
259
+ sysbus_init_child_obj(obj, "mmc0", &s->mmc0, sizeof(s->mmc0),
94
* equivalent of these checks.
260
+ TYPE_AW_SDHOST_SUN4I);
95
*/
261
}
96
int grp;
262
97
+ bool is_nmi;
263
static void aw_a10_realize(DeviceState *dev, Error **errp)
98
uint32_t mask, prio, rprio, vpmr;
264
@@ -XXX,XX +XXX,XX @@ static void aw_a10_realize(DeviceState *dev, Error **errp)
99
265
qdev_get_gpio_in(dev, 64 + i));
100
if (!(cs->ich_hcr_el2 & ICH_HCR_EL2_EN)) {
266
}
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;
267
}
113
}
268
+
114
@@ -XXX,XX +XXX,XX @@ static bool icv_hppi_can_preempt(GICv3CPUState *cs, uint64_t lr)
269
+ /* SD/MMC */
115
return true;
270
+ qdev_init_nofail(DEVICE(&s->mmc0));
116
}
271
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->mmc0), 0, AW_A10_MMC0_BASE);
117
272
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->mmc0), 0, qdev_get_gpio_in(dev, 32));
118
+ if ((prio & mask) == (rprio & mask) && is_nmi &&
273
+ object_property_add_alias(OBJECT(s), "sd-bus", OBJECT(&s->mmc0),
119
+ !(cs->ich_apr[GICV3_G1NS][0] & ICV_AP1R_EL1_NMI)) {
274
+ "sd-bus", &error_abort);
120
+ return true;
275
}
121
+ }
276
122
+
277
static void aw_a10_class_init(ObjectClass *oc, void *data)
123
return false;
278
diff --git a/hw/arm/allwinner-h3.c b/hw/arm/allwinner-h3.c
124
}
279
index XXXXXXX..XXXXXXX 100644
125
280
--- a/hw/arm/allwinner-h3.c
126
@@ -XXX,XX +XXX,XX @@ static void icv_ap_write(CPUARMState *env, const ARMCPRegInfo *ri,
281
+++ b/hw/arm/allwinner-h3.c
127
282
@@ -XXX,XX +XXX,XX @@ const hwaddr allwinner_h3_memmap[] = {
128
trace_gicv3_icv_ap_write(ri->crm & 1, regno, gicv3_redist_affid(cs), value);
283
[AW_H3_SRAM_A2] = 0x00044000,
129
284
[AW_H3_SRAM_C] = 0x00010000,
130
- cs->ich_apr[grp][regno] = value & 0xFFFFFFFFU;
285
[AW_H3_SYSCTRL] = 0x01c00000,
131
+ if (cs->nmi_support) {
286
+ [AW_H3_MMC0] = 0x01c0f000,
132
+ cs->ich_apr[grp][regno] = value & (0xFFFFFFFFU | ICV_AP1R_EL1_NMI);
287
[AW_H3_SID] = 0x01c14000,
133
+ } else {
288
[AW_H3_EHCI0] = 0x01c1a000,
134
+ cs->ich_apr[grp][regno] = value & 0xFFFFFFFFU;
289
[AW_H3_OHCI0] = 0x01c1a400,
135
+ }
290
@@ -XXX,XX +XXX,XX @@ struct AwH3Unimplemented {
136
291
{ "lcd0", 0x01c0c000, 4 * KiB },
137
gicv3_cpuif_virt_irq_fiq_update(cs);
292
{ "lcd1", 0x01c0d000, 4 * KiB },
138
return;
293
{ "ve", 0x01c0e000, 4 * KiB },
139
@@ -XXX,XX +XXX,XX @@ static void icv_ctlr_write(CPUARMState *env, const ARMCPRegInfo *ri,
294
- { "mmc0", 0x01c0f000, 4 * KiB },
140
static uint64_t icv_rpr_read(CPUARMState *env, const ARMCPRegInfo *ri)
295
{ "mmc1", 0x01c10000, 4 * KiB },
296
{ "mmc2", 0x01c11000, 4 * KiB },
297
{ "crypto", 0x01c15000, 4 * KiB },
298
@@ -XXX,XX +XXX,XX @@ enum {
299
AW_H3_GIC_SPI_UART3 = 3,
300
AW_H3_GIC_SPI_TIMER0 = 18,
301
AW_H3_GIC_SPI_TIMER1 = 19,
302
+ AW_H3_GIC_SPI_MMC0 = 60,
303
AW_H3_GIC_SPI_EHCI0 = 72,
304
AW_H3_GIC_SPI_OHCI0 = 73,
305
AW_H3_GIC_SPI_EHCI1 = 74,
306
@@ -XXX,XX +XXX,XX @@ static void allwinner_h3_init(Object *obj)
307
TYPE_AW_SID);
308
object_property_add_alias(obj, "identifier", OBJECT(&s->sid),
309
"identifier", &error_abort);
310
+
311
+ sysbus_init_child_obj(obj, "mmc0", &s->mmc0, sizeof(s->mmc0),
312
+ TYPE_AW_SDHOST_SUN5I);
313
}
314
315
static void allwinner_h3_realize(DeviceState *dev, Error **errp)
316
@@ -XXX,XX +XXX,XX @@ static void allwinner_h3_realize(DeviceState *dev, Error **errp)
317
qdev_init_nofail(DEVICE(&s->sid));
318
sysbus_mmio_map(SYS_BUS_DEVICE(&s->sid), 0, s->memmap[AW_H3_SID]);
319
320
+ /* SD/MMC */
321
+ qdev_init_nofail(DEVICE(&s->mmc0));
322
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->mmc0), 0, s->memmap[AW_H3_MMC0]);
323
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->mmc0), 0,
324
+ qdev_get_gpio_in(DEVICE(&s->gic), AW_H3_GIC_SPI_MMC0));
325
+
326
+ object_property_add_alias(OBJECT(s), "sd-bus", OBJECT(&s->mmc0),
327
+ "sd-bus", &error_abort);
328
+
329
/* Universal Serial Bus */
330
sysbus_create_simple(TYPE_AW_H3_EHCI, s->memmap[AW_H3_EHCI0],
331
qdev_get_gpio_in(DEVICE(&s->gic),
332
diff --git a/hw/arm/cubieboard.c b/hw/arm/cubieboard.c
333
index XXXXXXX..XXXXXXX 100644
334
--- a/hw/arm/cubieboard.c
335
+++ b/hw/arm/cubieboard.c
336
@@ -XXX,XX +XXX,XX @@
337
#include "sysemu/sysemu.h"
338
#include "hw/sysbus.h"
339
#include "hw/boards.h"
340
+#include "hw/qdev-properties.h"
341
#include "hw/arm/allwinner-a10.h"
342
343
static struct arm_boot_info cubieboard_binfo = {
344
@@ -XXX,XX +XXX,XX @@ static void cubieboard_init(MachineState *machine)
345
{
141
{
346
AwA10State *a10;
142
GICv3CPUState *cs = icc_cs_from_env(env);
347
Error *err = NULL;
143
- int prio = ich_highest_active_virt_prio(cs);
348
+ DriveInfo *di;
144
+ uint64_t prio = ich_highest_active_virt_prio(cs);
349
+ BlockBackend *blk;
145
+
350
+ BusState *bus;
146
+ if (cs->ich_apr[GICV3_G1NS][0] & ICV_AP1R_EL1_NMI) {
351
+ DeviceState *carddev;
147
+ prio |= ICV_RPR_EL1_NMI;
352
148
+ }
353
/* BIOS is not supported by this board */
149
354
if (bios_name) {
150
trace_gicv3_icv_rpr_read(gicv3_redist_affid(cs), prio);
355
@@ -XXX,XX +XXX,XX @@ static void cubieboard_init(MachineState *machine)
151
return prio;
356
exit(1);
152
@@ -XXX,XX +XXX,XX @@ static void icv_activate_irq(GICv3CPUState *cs, int idx, int grp)
357
}
153
*/
358
154
uint32_t mask = icv_gprio_mask(cs, grp);
359
+ /* Retrieve SD bus */
155
int prio = ich_lr_prio(cs->ich_lr_el2[idx]) & mask;
360
+ di = drive_get_next(IF_SD);
156
+ bool nmi = cs->ich_lr_el2[idx] & ICH_LR_EL2_NMI;
361
+ blk = di ? blk_by_legacy_dinfo(di) : NULL;
157
int aprbit = prio >> (8 - cs->vprebits);
362
+ bus = qdev_get_child_bus(DEVICE(a10), "sd-bus");
158
int regno = aprbit / 32;
363
+
159
int regbit = aprbit % 32;
364
+ /* Plug in SD card */
160
365
+ carddev = qdev_create(bus, TYPE_SD_CARD);
161
cs->ich_lr_el2[idx] &= ~ICH_LR_EL2_STATE_PENDING_BIT;
366
+ qdev_prop_set_drive(carddev, "drive", blk, &error_fatal);
162
cs->ich_lr_el2[idx] |= ICH_LR_EL2_STATE_ACTIVE_BIT;
367
+ object_property_set_bool(OBJECT(carddev), true, "realized", &error_fatal);
163
- cs->ich_apr[grp][regno] |= (1 << regbit);
368
+
164
+
369
memory_region_add_subregion(get_system_memory(), AW_A10_SDRAM_BASE,
165
+ if (nmi) {
370
machine->ram);
166
+ cs->ich_apr[grp][regno] |= ICV_AP1R_EL1_NMI;
371
167
+ } else {
372
diff --git a/hw/arm/orangepi.c b/hw/arm/orangepi.c
168
+ cs->ich_apr[grp][regno] |= (1 << regbit);
373
index XXXXXXX..XXXXXXX 100644
169
+ }
374
--- a/hw/arm/orangepi.c
170
}
375
+++ b/hw/arm/orangepi.c
171
376
@@ -XXX,XX +XXX,XX @@ static struct arm_boot_info orangepi_binfo = {
172
static void icv_activate_vlpi(GICv3CPUState *cs)
377
static void orangepi_init(MachineState *machine)
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)
378
{
202
{
379
AwH3State *h3;
203
- /* todo */
380
+ DriveInfo *di;
204
+ GICv3CPUState *cs = icc_cs_from_env(env);
381
+ BlockBackend *blk;
205
+ int idx = hppvi_index(cs);
382
+ BusState *bus;
206
uint64_t intid = INTID_SPURIOUS;
383
+ DeviceState *carddev;
207
+
384
208
+ if (idx >= 0 && idx != HPPVI_INDEX_VLPI) {
385
/* BIOS is not supported by this board */
209
+ uint64_t lr = cs->ich_lr_el2[idx];
386
if (bios_name) {
210
+ int thisgrp = (lr & ICH_LR_EL2_GROUP) ? GICV3_G1NS : GICV3_G0;
387
@@ -XXX,XX +XXX,XX @@ static void orangepi_init(MachineState *machine)
211
+
388
/* Mark H3 object realized */
212
+ if ((thisgrp == GICV3_G1NS) && icv_hppi_can_preempt(cs, lr)) {
389
object_property_set_bool(OBJECT(h3), true, "realized", &error_abort);
213
+ intid = ich_lr_vintid(lr);
390
214
+ if (!gicv3_intid_is_special(intid)) {
391
+ /* Retrieve SD bus */
215
+ if (lr & ICH_LR_EL2_NMI) {
392
+ di = drive_get_next(IF_SD);
216
+ icv_activate_irq(cs, idx, GICV3_G1NS);
393
+ blk = di ? blk_by_legacy_dinfo(di) : NULL;
217
+ } else {
394
+ bus = qdev_get_child_bus(DEVICE(h3), "sd-bus");
218
+ intid = INTID_SPURIOUS;
395
+
219
+ }
396
+ /* Plug in SD card */
397
+ carddev = qdev_create(bus, TYPE_SD_CARD);
398
+ qdev_prop_set_drive(carddev, "drive", blk, &error_fatal);
399
+ object_property_set_bool(OBJECT(carddev), true, "realized", &error_fatal);
400
+
401
/* SDRAM */
402
memory_region_add_subregion(get_system_memory(), h3->memmap[AW_H3_SDRAM],
403
machine->ram);
404
@@ -XXX,XX +XXX,XX @@ static void orangepi_machine_init(MachineClass *mc)
405
{
406
mc->desc = "Orange Pi PC";
407
mc->init = orangepi_init;
408
+ mc->block_default_type = IF_SD;
409
+ mc->units_per_default_bus = 1;
410
mc->min_cpus = AW_H3_NUM_CPUS;
411
mc->max_cpus = AW_H3_NUM_CPUS;
412
mc->default_cpus = AW_H3_NUM_CPUS;
413
diff --git a/hw/sd/allwinner-sdhost.c b/hw/sd/allwinner-sdhost.c
414
new file mode 100644
415
index XXXXXXX..XXXXXXX
416
--- /dev/null
417
+++ b/hw/sd/allwinner-sdhost.c
418
@@ -XXX,XX +XXX,XX @@
419
+/*
420
+ * Allwinner (sun4i and above) SD Host Controller emulation
421
+ *
422
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
423
+ *
424
+ * This program is free software: you can redistribute it and/or modify
425
+ * it under the terms of the GNU General Public License as published by
426
+ * the Free Software Foundation, either version 2 of the License, or
427
+ * (at your option) any later version.
428
+ *
429
+ * This program is distributed in the hope that it will be useful,
430
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
431
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
432
+ * GNU General Public License for more details.
433
+ *
434
+ * You should have received a copy of the GNU General Public License
435
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
436
+ */
437
+
438
+#include "qemu/osdep.h"
439
+#include "qemu/log.h"
440
+#include "qemu/module.h"
441
+#include "qemu/units.h"
442
+#include "sysemu/blockdev.h"
443
+#include "hw/irq.h"
444
+#include "hw/sd/allwinner-sdhost.h"
445
+#include "migration/vmstate.h"
446
+#include "trace.h"
447
+
448
+#define TYPE_AW_SDHOST_BUS "allwinner-sdhost-bus"
449
+#define AW_SDHOST_BUS(obj) \
450
+ OBJECT_CHECK(SDBus, (obj), TYPE_AW_SDHOST_BUS)
451
+
452
+/* SD Host register offsets */
453
+enum {
454
+ REG_SD_GCTL = 0x00, /* Global Control */
455
+ REG_SD_CKCR = 0x04, /* Clock Control */
456
+ REG_SD_TMOR = 0x08, /* Timeout */
457
+ REG_SD_BWDR = 0x0C, /* Bus Width */
458
+ REG_SD_BKSR = 0x10, /* Block Size */
459
+ REG_SD_BYCR = 0x14, /* Byte Count */
460
+ REG_SD_CMDR = 0x18, /* Command */
461
+ REG_SD_CAGR = 0x1C, /* Command Argument */
462
+ REG_SD_RESP0 = 0x20, /* Response Zero */
463
+ REG_SD_RESP1 = 0x24, /* Response One */
464
+ REG_SD_RESP2 = 0x28, /* Response Two */
465
+ REG_SD_RESP3 = 0x2C, /* Response Three */
466
+ REG_SD_IMKR = 0x30, /* Interrupt Mask */
467
+ REG_SD_MISR = 0x34, /* Masked Interrupt Status */
468
+ REG_SD_RISR = 0x38, /* Raw Interrupt Status */
469
+ REG_SD_STAR = 0x3C, /* Status */
470
+ REG_SD_FWLR = 0x40, /* FIFO Water Level */
471
+ REG_SD_FUNS = 0x44, /* FIFO Function Select */
472
+ REG_SD_DBGC = 0x50, /* Debug Enable */
473
+ REG_SD_A12A = 0x58, /* Auto command 12 argument */
474
+ REG_SD_NTSR = 0x5C, /* SD NewTiming Set */
475
+ REG_SD_SDBG = 0x60, /* SD newTiming Set Debug */
476
+ REG_SD_HWRST = 0x78, /* Hardware Reset Register */
477
+ REG_SD_DMAC = 0x80, /* Internal DMA Controller Control */
478
+ REG_SD_DLBA = 0x84, /* Descriptor List Base Address */
479
+ REG_SD_IDST = 0x88, /* Internal DMA Controller Status */
480
+ REG_SD_IDIE = 0x8C, /* Internal DMA Controller IRQ Enable */
481
+ REG_SD_THLDC = 0x100, /* Card Threshold Control */
482
+ REG_SD_DSBD = 0x10C, /* eMMC DDR Start Bit Detection Control */
483
+ REG_SD_RES_CRC = 0x110, /* Response CRC from card/eMMC */
484
+ REG_SD_DATA7_CRC = 0x114, /* CRC Data 7 from card/eMMC */
485
+ REG_SD_DATA6_CRC = 0x118, /* CRC Data 6 from card/eMMC */
486
+ REG_SD_DATA5_CRC = 0x11C, /* CRC Data 5 from card/eMMC */
487
+ REG_SD_DATA4_CRC = 0x120, /* CRC Data 4 from card/eMMC */
488
+ REG_SD_DATA3_CRC = 0x124, /* CRC Data 3 from card/eMMC */
489
+ REG_SD_DATA2_CRC = 0x128, /* CRC Data 2 from card/eMMC */
490
+ REG_SD_DATA1_CRC = 0x12C, /* CRC Data 1 from card/eMMC */
491
+ REG_SD_DATA0_CRC = 0x130, /* CRC Data 0 from card/eMMC */
492
+ REG_SD_CRC_STA = 0x134, /* CRC status from card/eMMC during write */
493
+ REG_SD_FIFO = 0x200, /* Read/Write FIFO */
494
+};
495
+
496
+/* SD Host register flags */
497
+enum {
498
+ SD_GCTL_FIFO_AC_MOD = (1 << 31),
499
+ SD_GCTL_DDR_MOD_SEL = (1 << 10),
500
+ SD_GCTL_CD_DBC_ENB = (1 << 8),
501
+ SD_GCTL_DMA_ENB = (1 << 5),
502
+ SD_GCTL_INT_ENB = (1 << 4),
503
+ SD_GCTL_DMA_RST = (1 << 2),
504
+ SD_GCTL_FIFO_RST = (1 << 1),
505
+ SD_GCTL_SOFT_RST = (1 << 0),
506
+};
507
+
508
+enum {
509
+ SD_CMDR_LOAD = (1 << 31),
510
+ SD_CMDR_CLKCHANGE = (1 << 21),
511
+ SD_CMDR_WRITE = (1 << 10),
512
+ SD_CMDR_AUTOSTOP = (1 << 12),
513
+ SD_CMDR_DATA = (1 << 9),
514
+ SD_CMDR_RESPONSE_LONG = (1 << 7),
515
+ SD_CMDR_RESPONSE = (1 << 6),
516
+ SD_CMDR_CMDID_MASK = (0x3f),
517
+};
518
+
519
+enum {
520
+ SD_RISR_CARD_REMOVE = (1 << 31),
521
+ SD_RISR_CARD_INSERT = (1 << 30),
522
+ SD_RISR_SDIO_INTR = (1 << 16),
523
+ SD_RISR_AUTOCMD_DONE = (1 << 14),
524
+ SD_RISR_DATA_COMPLETE = (1 << 3),
525
+ SD_RISR_CMD_COMPLETE = (1 << 2),
526
+ SD_RISR_NO_RESPONSE = (1 << 1),
527
+};
528
+
529
+enum {
530
+ SD_STAR_CARD_PRESENT = (1 << 8),
531
+};
532
+
533
+enum {
534
+ SD_IDST_INT_SUMMARY = (1 << 8),
535
+ SD_IDST_RECEIVE_IRQ = (1 << 1),
536
+ SD_IDST_TRANSMIT_IRQ = (1 << 0),
537
+ SD_IDST_IRQ_MASK = (1 << 1) | (1 << 0) | (1 << 8),
538
+ SD_IDST_WR_MASK = (0x3ff),
539
+};
540
+
541
+/* SD Host register reset values */
542
+enum {
543
+ REG_SD_GCTL_RST = 0x00000300,
544
+ REG_SD_CKCR_RST = 0x0,
545
+ REG_SD_TMOR_RST = 0xFFFFFF40,
546
+ REG_SD_BWDR_RST = 0x0,
547
+ REG_SD_BKSR_RST = 0x00000200,
548
+ REG_SD_BYCR_RST = 0x00000200,
549
+ REG_SD_CMDR_RST = 0x0,
550
+ REG_SD_CAGR_RST = 0x0,
551
+ REG_SD_RESP_RST = 0x0,
552
+ REG_SD_IMKR_RST = 0x0,
553
+ REG_SD_MISR_RST = 0x0,
554
+ REG_SD_RISR_RST = 0x0,
555
+ REG_SD_STAR_RST = 0x00000100,
556
+ REG_SD_FWLR_RST = 0x000F0000,
557
+ REG_SD_FUNS_RST = 0x0,
558
+ REG_SD_DBGC_RST = 0x0,
559
+ REG_SD_A12A_RST = 0x0000FFFF,
560
+ REG_SD_NTSR_RST = 0x00000001,
561
+ REG_SD_SDBG_RST = 0x0,
562
+ REG_SD_HWRST_RST = 0x00000001,
563
+ REG_SD_DMAC_RST = 0x0,
564
+ REG_SD_DLBA_RST = 0x0,
565
+ REG_SD_IDST_RST = 0x0,
566
+ REG_SD_IDIE_RST = 0x0,
567
+ REG_SD_THLDC_RST = 0x0,
568
+ REG_SD_DSBD_RST = 0x0,
569
+ REG_SD_RES_CRC_RST = 0x0,
570
+ REG_SD_DATA_CRC_RST = 0x0,
571
+ REG_SD_CRC_STA_RST = 0x0,
572
+ REG_SD_FIFO_RST = 0x0,
573
+};
574
+
575
+/* Data transfer descriptor for DMA */
576
+typedef struct TransferDescriptor {
577
+ uint32_t status; /* Status flags */
578
+ uint32_t size; /* Data buffer size */
579
+ uint32_t addr; /* Data buffer address */
580
+ uint32_t next; /* Physical address of next descriptor */
581
+} TransferDescriptor;
582
+
583
+/* Data transfer descriptor flags */
584
+enum {
585
+ DESC_STATUS_HOLD = (1 << 31), /* Set when descriptor is in use by DMA */
586
+ DESC_STATUS_ERROR = (1 << 30), /* Set when DMA transfer error occurred */
587
+ DESC_STATUS_CHAIN = (1 << 4), /* Indicates chained descriptor. */
588
+ DESC_STATUS_FIRST = (1 << 3), /* Set on the first descriptor */
589
+ DESC_STATUS_LAST = (1 << 2), /* Set on the last descriptor */
590
+ DESC_STATUS_NOIRQ = (1 << 1), /* Skip raising interrupt after transfer */
591
+ DESC_SIZE_MASK = (0xfffffffc)
592
+};
593
+
594
+static void allwinner_sdhost_update_irq(AwSdHostState *s)
595
+{
596
+ uint32_t irq;
597
+
598
+ if (s->global_ctl & SD_GCTL_INT_ENB) {
599
+ irq = s->irq_status & s->irq_mask;
600
+ } else {
601
+ irq = 0;
602
+ }
603
+
604
+ trace_allwinner_sdhost_update_irq(irq);
605
+ qemu_set_irq(s->irq, irq);
606
+}
607
+
608
+static void allwinner_sdhost_update_transfer_cnt(AwSdHostState *s,
609
+ uint32_t bytes)
610
+{
611
+ if (s->transfer_cnt > bytes) {
612
+ s->transfer_cnt -= bytes;
613
+ } else {
614
+ s->transfer_cnt = 0;
615
+ }
616
+
617
+ if (!s->transfer_cnt) {
618
+ s->irq_status |= SD_RISR_DATA_COMPLETE;
619
+ }
620
+}
621
+
622
+static void allwinner_sdhost_set_inserted(DeviceState *dev, bool inserted)
623
+{
624
+ AwSdHostState *s = AW_SDHOST(dev);
625
+
626
+ trace_allwinner_sdhost_set_inserted(inserted);
627
+
628
+ if (inserted) {
629
+ s->irq_status |= SD_RISR_CARD_INSERT;
630
+ s->irq_status &= ~SD_RISR_CARD_REMOVE;
631
+ s->status |= SD_STAR_CARD_PRESENT;
632
+ } else {
633
+ s->irq_status &= ~SD_RISR_CARD_INSERT;
634
+ s->irq_status |= SD_RISR_CARD_REMOVE;
635
+ s->status &= ~SD_STAR_CARD_PRESENT;
636
+ }
637
+
638
+ allwinner_sdhost_update_irq(s);
639
+}
640
+
641
+static void allwinner_sdhost_send_command(AwSdHostState *s)
642
+{
643
+ SDRequest request;
644
+ uint8_t resp[16];
645
+ int rlen;
646
+
647
+ /* Auto clear load flag */
648
+ s->command &= ~SD_CMDR_LOAD;
649
+
650
+ /* Clock change does not actually interact with the SD bus */
651
+ if (!(s->command & SD_CMDR_CLKCHANGE)) {
652
+
653
+ /* Prepare request */
654
+ request.cmd = s->command & SD_CMDR_CMDID_MASK;
655
+ request.arg = s->command_arg;
656
+
657
+ /* Send request to SD bus */
658
+ rlen = sdbus_do_command(&s->sdbus, &request, resp);
659
+ if (rlen < 0) {
660
+ goto error;
661
+ }
662
+
663
+ /* If the command has a response, store it in the response registers */
664
+ if ((s->command & SD_CMDR_RESPONSE)) {
665
+ if (rlen == 4 && !(s->command & SD_CMDR_RESPONSE_LONG)) {
666
+ s->response[0] = ldl_be_p(&resp[0]);
667
+ s->response[1] = s->response[2] = s->response[3] = 0;
668
+
669
+ } else if (rlen == 16 && (s->command & SD_CMDR_RESPONSE_LONG)) {
670
+ s->response[0] = ldl_be_p(&resp[12]);
671
+ s->response[1] = ldl_be_p(&resp[8]);
672
+ s->response[2] = ldl_be_p(&resp[4]);
673
+ s->response[3] = ldl_be_p(&resp[0]);
674
+ } else {
220
+ } else {
675
+ goto error;
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
+ */
676
+ }
227
+ }
677
+ }
228
+ }
678
+ }
229
+ }
679
+
230
+
680
+ /* Set interrupt status bits */
231
+ trace_gicv3_icv_nmiar1_read(gicv3_redist_affid(cs), intid);
681
+ s->irq_status |= SD_RISR_CMD_COMPLETE;
232
+
682
+ return;
233
+ gicv3_cpuif_virt_update(cs);
683
+
234
+
684
+error:
235
return intid;
685
+ s->irq_status |= SD_RISR_NO_RESPONSE;
236
}
686
+}
237
687
+
238
@@ -XXX,XX +XXX,XX @@ static void icv_increment_eoicount(GICv3CPUState *cs)
688
+static void allwinner_sdhost_auto_stop(AwSdHostState *s)
239
ICH_HCR_EL2_EOICOUNT_LENGTH, eoicount + 1);
689
+{
240
}
690
+ /*
241
691
+ * The stop command (CMD12) ensures the SD bus
242
-static int icv_drop_prio(GICv3CPUState *cs)
692
+ * returns to the transfer state.
243
+static int icv_drop_prio(GICv3CPUState *cs, bool *nmi)
693
+ */
244
{
694
+ if ((s->command & SD_CMDR_AUTOSTOP) && (s->transfer_cnt == 0)) {
245
/* Drop the priority of the currently active virtual interrupt
695
+ /* First save current command registers */
246
* (favouring group 0 if there is a set active bit at
696
+ uint32_t saved_cmd = s->command;
247
@@ -XXX,XX +XXX,XX @@ static int icv_drop_prio(GICv3CPUState *cs)
697
+ uint32_t saved_arg = s->command_arg;
248
continue;
698
+
249
}
699
+ /* Prepare stop command (CMD12) */
250
700
+ s->command &= ~SD_CMDR_CMDID_MASK;
251
+ if (i == 0 && cs->nmi_support && (*papr1 & ICV_AP1R_EL1_NMI)) {
701
+ s->command |= 12; /* CMD12 */
252
+ *papr1 &= (~ICV_AP1R_EL1_NMI);
702
+ s->command_arg = 0;
253
+ *nmi = true;
703
+
254
+ return 0xff;
704
+ /* Put the command on SD bus */
705
+ allwinner_sdhost_send_command(s);
706
+
707
+ /* Restore command values */
708
+ s->command = saved_cmd;
709
+ s->command_arg = saved_arg;
710
+
711
+ /* Set IRQ status bit for automatic stop done */
712
+ s->irq_status |= SD_RISR_AUTOCMD_DONE;
713
+ }
714
+}
715
+
716
+static uint32_t allwinner_sdhost_process_desc(AwSdHostState *s,
717
+ hwaddr desc_addr,
718
+ TransferDescriptor *desc,
719
+ bool is_write, uint32_t max_bytes)
720
+{
721
+ AwSdHostClass *klass = AW_SDHOST_GET_CLASS(s);
722
+ uint32_t num_done = 0;
723
+ uint32_t num_bytes = max_bytes;
724
+ uint8_t buf[1024];
725
+
726
+ /* Read descriptor */
727
+ cpu_physical_memory_read(desc_addr, desc, sizeof(*desc));
728
+ if (desc->size == 0) {
729
+ desc->size = klass->max_desc_size;
730
+ } else if (desc->size > klass->max_desc_size) {
731
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: DMA descriptor buffer size "
732
+ " is out-of-bounds: %" PRIu32 " > %zu",
733
+ __func__, desc->size, klass->max_desc_size);
734
+ desc->size = klass->max_desc_size;
735
+ }
736
+ if (desc->size < num_bytes) {
737
+ num_bytes = desc->size;
738
+ }
739
+
740
+ trace_allwinner_sdhost_process_desc(desc_addr, desc->size,
741
+ is_write, max_bytes);
742
+
743
+ while (num_done < num_bytes) {
744
+ /* Try to completely fill the local buffer */
745
+ uint32_t buf_bytes = num_bytes - num_done;
746
+ if (buf_bytes > sizeof(buf)) {
747
+ buf_bytes = sizeof(buf);
748
+ }
255
+ }
749
+
256
+
750
+ /* Write to SD bus */
257
/* We can't just use the bit-twiddling hack icc_drop_prio() does
751
+ if (is_write) {
258
* because we need to return the bit number we cleared so
752
+ cpu_physical_memory_read((desc->addr & DESC_SIZE_MASK) + num_done,
259
* it can be compared against the list register's priority field.
753
+ buf, buf_bytes);
260
@@ -XXX,XX +XXX,XX @@ static void icv_eoir_write(CPUARMState *env, const ARMCPRegInfo *ri,
754
+
261
int irq = value & 0xffffff;
755
+ for (uint32_t i = 0; i < buf_bytes; i++) {
262
int grp = ri->crm == 8 ? GICV3_G0 : GICV3_G1NS;
756
+ sdbus_write_data(&s->sdbus, buf[i]);
263
int idx, dropprio;
757
+ }
264
+ bool nmi = false;
758
+
265
759
+ /* Read from SD bus */
266
trace_gicv3_icv_eoir_write(ri->crm == 8 ? 0 : 1,
760
+ } else {
267
gicv3_redist_affid(cs), value);
761
+ for (uint32_t i = 0; i < buf_bytes; i++) {
268
@@ -XXX,XX +XXX,XX @@ static void icv_eoir_write(CPUARMState *env, const ARMCPRegInfo *ri,
762
+ buf[i] = sdbus_read_data(&s->sdbus);
269
* error checks" (because that lets us avoid scanning the AP
763
+ }
270
* registers twice).
764
+ cpu_physical_memory_write((desc->addr & DESC_SIZE_MASK) + num_done,
271
*/
765
+ buf, buf_bytes);
272
- dropprio = icv_drop_prio(cs);
766
+ }
273
- if (dropprio == 0xff) {
767
+ num_done += buf_bytes;
274
+ dropprio = icv_drop_prio(cs, &nmi);
768
+ }
275
+ if (dropprio == 0xff && !nmi) {
769
+
276
/* No active interrupt. It is CONSTRAINED UNPREDICTABLE
770
+ /* Clear hold flag and flush descriptor */
277
* whether the list registers are checked in this
771
+ desc->status &= ~DESC_STATUS_HOLD;
278
* situation; we choose not to.
772
+ cpu_physical_memory_write(desc_addr, desc, sizeof(*desc));
279
@@ -XXX,XX +XXX,XX @@ static void icv_eoir_write(CPUARMState *env, const ARMCPRegInfo *ri,
773
+
280
uint64_t lr = cs->ich_lr_el2[idx];
774
+ return num_done;
281
int thisgrp = (lr & ICH_LR_EL2_GROUP) ? GICV3_G1NS : GICV3_G0;
775
+}
282
int lr_gprio = ich_lr_prio(lr) & icv_gprio_mask(cs, grp);
776
+
283
+ bool thisnmi = lr & ICH_LR_EL2_NMI;
777
+static void allwinner_sdhost_dma(AwSdHostState *s)
284
778
+{
285
- if (thisgrp == grp && lr_gprio == dropprio) {
779
+ TransferDescriptor desc;
286
+ if (thisgrp == grp && (lr_gprio == dropprio || (thisnmi & nmi))) {
780
+ hwaddr desc_addr = s->desc_base;
287
if (!icv_eoi_split(env, cs) || irq >= GICV3_LPI_INTID_START) {
781
+ bool is_write = (s->command & SD_CMDR_WRITE);
288
/*
782
+ uint32_t bytes_done = 0;
289
* Priority drop and deactivate not split: deactivate irq now.
783
+
290
@@ -XXX,XX +XXX,XX @@ static void ich_ap_write(CPUARMState *env, const ARMCPRegInfo *ri,
784
+ /* Check if DMA can be performed */
291
785
+ if (s->byte_count == 0 || s->block_size == 0 ||
292
trace_gicv3_ich_ap_write(ri->crm & 1, regno, gicv3_redist_affid(cs), value);
786
+ !(s->global_ctl & SD_GCTL_DMA_ENB)) {
293
787
+ return;
294
- cs->ich_apr[grp][regno] = value & 0xFFFFFFFFU;
788
+ }
295
+ if (cs->nmi_support) {
789
+
296
+ cs->ich_apr[grp][regno] = value & (0xFFFFFFFFU | ICV_AP1R_EL1_NMI);
790
+ /*
791
+ * For read operations, data must be available on the SD bus
792
+ * If not, it is an error and we should not act at all
793
+ */
794
+ if (!is_write && !sdbus_data_ready(&s->sdbus)) {
795
+ return;
796
+ }
797
+
798
+ /* Process the DMA descriptors until all data is copied */
799
+ while (s->byte_count > 0) {
800
+ bytes_done = allwinner_sdhost_process_desc(s, desc_addr, &desc,
801
+ is_write, s->byte_count);
802
+ allwinner_sdhost_update_transfer_cnt(s, bytes_done);
803
+
804
+ if (bytes_done <= s->byte_count) {
805
+ s->byte_count -= bytes_done;
806
+ } else {
807
+ s->byte_count = 0;
808
+ }
809
+
810
+ if (desc.status & DESC_STATUS_LAST) {
811
+ break;
812
+ } else {
813
+ desc_addr = desc.next;
814
+ }
815
+ }
816
+
817
+ /* Raise IRQ to signal DMA is completed */
818
+ s->irq_status |= SD_RISR_DATA_COMPLETE | SD_RISR_SDIO_INTR;
819
+
820
+ /* Update DMAC bits */
821
+ s->dmac_status |= SD_IDST_INT_SUMMARY;
822
+
823
+ if (is_write) {
824
+ s->dmac_status |= SD_IDST_TRANSMIT_IRQ;
825
+ } else {
297
+ } else {
826
+ s->dmac_status |= SD_IDST_RECEIVE_IRQ;
298
+ cs->ich_apr[grp][regno] = value & 0xFFFFFFFFU;
827
+ }
299
+ }
828
+}
300
gicv3_cpuif_virt_irq_fiq_update(cs);
829
+
301
}
830
+static uint64_t allwinner_sdhost_read(void *opaque, hwaddr offset,
302
831
+ unsigned size)
303
@@ -XXX,XX +XXX,XX @@ static void ich_lr_write(CPUARMState *env, const ARMCPRegInfo *ri,
832
+{
304
8 - cs->vpribits, 0);
833
+ AwSdHostState *s = AW_SDHOST(opaque);
305
}
834
+ uint32_t res = 0;
306
835
+
307
+ /* Enforce RES0 bit in NMI field when FEAT_GICv3_NMI is not implemented */
836
+ switch (offset) {
308
+ if (!cs->nmi_support) {
837
+ case REG_SD_GCTL: /* Global Control */
309
+ value &= ~ICH_LR_EL2_NMI;
838
+ res = s->global_ctl;
310
+ }
839
+ break;
311
+
840
+ case REG_SD_CKCR: /* Clock Control */
312
cs->ich_lr_el2[regno] = value;
841
+ res = s->clock_ctl;
313
gicv3_cpuif_virt_update(cs);
842
+ break;
314
}
843
+ case REG_SD_TMOR: /* Timeout */
315
diff --git a/hw/intc/trace-events b/hw/intc/trace-events
844
+ res = s->timeout;
845
+ break;
846
+ case REG_SD_BWDR: /* Bus Width */
847
+ res = s->bus_width;
848
+ break;
849
+ case REG_SD_BKSR: /* Block Size */
850
+ res = s->block_size;
851
+ break;
852
+ case REG_SD_BYCR: /* Byte Count */
853
+ res = s->byte_count;
854
+ break;
855
+ case REG_SD_CMDR: /* Command */
856
+ res = s->command;
857
+ break;
858
+ case REG_SD_CAGR: /* Command Argument */
859
+ res = s->command_arg;
860
+ break;
861
+ case REG_SD_RESP0: /* Response Zero */
862
+ res = s->response[0];
863
+ break;
864
+ case REG_SD_RESP1: /* Response One */
865
+ res = s->response[1];
866
+ break;
867
+ case REG_SD_RESP2: /* Response Two */
868
+ res = s->response[2];
869
+ break;
870
+ case REG_SD_RESP3: /* Response Three */
871
+ res = s->response[3];
872
+ break;
873
+ case REG_SD_IMKR: /* Interrupt Mask */
874
+ res = s->irq_mask;
875
+ break;
876
+ case REG_SD_MISR: /* Masked Interrupt Status */
877
+ res = s->irq_status & s->irq_mask;
878
+ break;
879
+ case REG_SD_RISR: /* Raw Interrupt Status */
880
+ res = s->irq_status;
881
+ break;
882
+ case REG_SD_STAR: /* Status */
883
+ res = s->status;
884
+ break;
885
+ case REG_SD_FWLR: /* FIFO Water Level */
886
+ res = s->fifo_wlevel;
887
+ break;
888
+ case REG_SD_FUNS: /* FIFO Function Select */
889
+ res = s->fifo_func_sel;
890
+ break;
891
+ case REG_SD_DBGC: /* Debug Enable */
892
+ res = s->debug_enable;
893
+ break;
894
+ case REG_SD_A12A: /* Auto command 12 argument */
895
+ res = s->auto12_arg;
896
+ break;
897
+ case REG_SD_NTSR: /* SD NewTiming Set */
898
+ res = s->newtiming_set;
899
+ break;
900
+ case REG_SD_SDBG: /* SD newTiming Set Debug */
901
+ res = s->newtiming_debug;
902
+ break;
903
+ case REG_SD_HWRST: /* Hardware Reset Register */
904
+ res = s->hardware_rst;
905
+ break;
906
+ case REG_SD_DMAC: /* Internal DMA Controller Control */
907
+ res = s->dmac;
908
+ break;
909
+ case REG_SD_DLBA: /* Descriptor List Base Address */
910
+ res = s->desc_base;
911
+ break;
912
+ case REG_SD_IDST: /* Internal DMA Controller Status */
913
+ res = s->dmac_status;
914
+ break;
915
+ case REG_SD_IDIE: /* Internal DMA Controller Interrupt Enable */
916
+ res = s->dmac_irq;
917
+ break;
918
+ case REG_SD_THLDC: /* Card Threshold Control */
919
+ res = s->card_threshold;
920
+ break;
921
+ case REG_SD_DSBD: /* eMMC DDR Start Bit Detection Control */
922
+ res = s->startbit_detect;
923
+ break;
924
+ case REG_SD_RES_CRC: /* Response CRC from card/eMMC */
925
+ res = s->response_crc;
926
+ break;
927
+ case REG_SD_DATA7_CRC: /* CRC Data 7 from card/eMMC */
928
+ case REG_SD_DATA6_CRC: /* CRC Data 6 from card/eMMC */
929
+ case REG_SD_DATA5_CRC: /* CRC Data 5 from card/eMMC */
930
+ case REG_SD_DATA4_CRC: /* CRC Data 4 from card/eMMC */
931
+ case REG_SD_DATA3_CRC: /* CRC Data 3 from card/eMMC */
932
+ case REG_SD_DATA2_CRC: /* CRC Data 2 from card/eMMC */
933
+ case REG_SD_DATA1_CRC: /* CRC Data 1 from card/eMMC */
934
+ case REG_SD_DATA0_CRC: /* CRC Data 0 from card/eMMC */
935
+ res = s->data_crc[((offset - REG_SD_DATA7_CRC) / sizeof(uint32_t))];
936
+ break;
937
+ case REG_SD_CRC_STA: /* CRC status from card/eMMC in write operation */
938
+ res = s->status_crc;
939
+ break;
940
+ case REG_SD_FIFO: /* Read/Write FIFO */
941
+ if (sdbus_data_ready(&s->sdbus)) {
942
+ res = sdbus_read_data(&s->sdbus);
943
+ res |= sdbus_read_data(&s->sdbus) << 8;
944
+ res |= sdbus_read_data(&s->sdbus) << 16;
945
+ res |= sdbus_read_data(&s->sdbus) << 24;
946
+ allwinner_sdhost_update_transfer_cnt(s, sizeof(uint32_t));
947
+ allwinner_sdhost_auto_stop(s);
948
+ allwinner_sdhost_update_irq(s);
949
+ } else {
950
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: no data ready on SD bus\n",
951
+ __func__);
952
+ }
953
+ break;
954
+ default:
955
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset %"
956
+ HWADDR_PRIx"\n", __func__, offset);
957
+ res = 0;
958
+ break;
959
+ }
960
+
961
+ trace_allwinner_sdhost_read(offset, res, size);
962
+ return res;
963
+}
964
+
965
+static void allwinner_sdhost_write(void *opaque, hwaddr offset,
966
+ uint64_t value, unsigned size)
967
+{
968
+ AwSdHostState *s = AW_SDHOST(opaque);
969
+
970
+ trace_allwinner_sdhost_write(offset, value, size);
971
+
972
+ switch (offset) {
973
+ case REG_SD_GCTL: /* Global Control */
974
+ s->global_ctl = value;
975
+ s->global_ctl &= ~(SD_GCTL_DMA_RST | SD_GCTL_FIFO_RST |
976
+ SD_GCTL_SOFT_RST);
977
+ allwinner_sdhost_update_irq(s);
978
+ break;
979
+ case REG_SD_CKCR: /* Clock Control */
980
+ s->clock_ctl = value;
981
+ break;
982
+ case REG_SD_TMOR: /* Timeout */
983
+ s->timeout = value;
984
+ break;
985
+ case REG_SD_BWDR: /* Bus Width */
986
+ s->bus_width = value;
987
+ break;
988
+ case REG_SD_BKSR: /* Block Size */
989
+ s->block_size = value;
990
+ break;
991
+ case REG_SD_BYCR: /* Byte Count */
992
+ s->byte_count = value;
993
+ s->transfer_cnt = value;
994
+ break;
995
+ case REG_SD_CMDR: /* Command */
996
+ s->command = value;
997
+ if (value & SD_CMDR_LOAD) {
998
+ allwinner_sdhost_send_command(s);
999
+ allwinner_sdhost_dma(s);
1000
+ allwinner_sdhost_auto_stop(s);
1001
+ }
1002
+ allwinner_sdhost_update_irq(s);
1003
+ break;
1004
+ case REG_SD_CAGR: /* Command Argument */
1005
+ s->command_arg = value;
1006
+ break;
1007
+ case REG_SD_RESP0: /* Response Zero */
1008
+ s->response[0] = value;
1009
+ break;
1010
+ case REG_SD_RESP1: /* Response One */
1011
+ s->response[1] = value;
1012
+ break;
1013
+ case REG_SD_RESP2: /* Response Two */
1014
+ s->response[2] = value;
1015
+ break;
1016
+ case REG_SD_RESP3: /* Response Three */
1017
+ s->response[3] = value;
1018
+ break;
1019
+ case REG_SD_IMKR: /* Interrupt Mask */
1020
+ s->irq_mask = value;
1021
+ allwinner_sdhost_update_irq(s);
1022
+ break;
1023
+ case REG_SD_MISR: /* Masked Interrupt Status */
1024
+ case REG_SD_RISR: /* Raw Interrupt Status */
1025
+ s->irq_status &= ~value;
1026
+ allwinner_sdhost_update_irq(s);
1027
+ break;
1028
+ case REG_SD_STAR: /* Status */
1029
+ s->status &= ~value;
1030
+ allwinner_sdhost_update_irq(s);
1031
+ break;
1032
+ case REG_SD_FWLR: /* FIFO Water Level */
1033
+ s->fifo_wlevel = value;
1034
+ break;
1035
+ case REG_SD_FUNS: /* FIFO Function Select */
1036
+ s->fifo_func_sel = value;
1037
+ break;
1038
+ case REG_SD_DBGC: /* Debug Enable */
1039
+ s->debug_enable = value;
1040
+ break;
1041
+ case REG_SD_A12A: /* Auto command 12 argument */
1042
+ s->auto12_arg = value;
1043
+ break;
1044
+ case REG_SD_NTSR: /* SD NewTiming Set */
1045
+ s->newtiming_set = value;
1046
+ break;
1047
+ case REG_SD_SDBG: /* SD newTiming Set Debug */
1048
+ s->newtiming_debug = value;
1049
+ break;
1050
+ case REG_SD_HWRST: /* Hardware Reset Register */
1051
+ s->hardware_rst = value;
1052
+ break;
1053
+ case REG_SD_DMAC: /* Internal DMA Controller Control */
1054
+ s->dmac = value;
1055
+ allwinner_sdhost_update_irq(s);
1056
+ break;
1057
+ case REG_SD_DLBA: /* Descriptor List Base Address */
1058
+ s->desc_base = value;
1059
+ break;
1060
+ case REG_SD_IDST: /* Internal DMA Controller Status */
1061
+ s->dmac_status &= (~SD_IDST_WR_MASK) | (~value & SD_IDST_WR_MASK);
1062
+ allwinner_sdhost_update_irq(s);
1063
+ break;
1064
+ case REG_SD_IDIE: /* Internal DMA Controller Interrupt Enable */
1065
+ s->dmac_irq = value;
1066
+ allwinner_sdhost_update_irq(s);
1067
+ break;
1068
+ case REG_SD_THLDC: /* Card Threshold Control */
1069
+ s->card_threshold = value;
1070
+ break;
1071
+ case REG_SD_DSBD: /* eMMC DDR Start Bit Detection Control */
1072
+ s->startbit_detect = value;
1073
+ break;
1074
+ case REG_SD_FIFO: /* Read/Write FIFO */
1075
+ sdbus_write_data(&s->sdbus, value & 0xff);
1076
+ sdbus_write_data(&s->sdbus, (value >> 8) & 0xff);
1077
+ sdbus_write_data(&s->sdbus, (value >> 16) & 0xff);
1078
+ sdbus_write_data(&s->sdbus, (value >> 24) & 0xff);
1079
+ allwinner_sdhost_update_transfer_cnt(s, sizeof(uint32_t));
1080
+ allwinner_sdhost_auto_stop(s);
1081
+ allwinner_sdhost_update_irq(s);
1082
+ break;
1083
+ case REG_SD_RES_CRC: /* Response CRC from card/eMMC */
1084
+ case REG_SD_DATA7_CRC: /* CRC Data 7 from card/eMMC */
1085
+ case REG_SD_DATA6_CRC: /* CRC Data 6 from card/eMMC */
1086
+ case REG_SD_DATA5_CRC: /* CRC Data 5 from card/eMMC */
1087
+ case REG_SD_DATA4_CRC: /* CRC Data 4 from card/eMMC */
1088
+ case REG_SD_DATA3_CRC: /* CRC Data 3 from card/eMMC */
1089
+ case REG_SD_DATA2_CRC: /* CRC Data 2 from card/eMMC */
1090
+ case REG_SD_DATA1_CRC: /* CRC Data 1 from card/eMMC */
1091
+ case REG_SD_DATA0_CRC: /* CRC Data 0 from card/eMMC */
1092
+ case REG_SD_CRC_STA: /* CRC status from card/eMMC in write operation */
1093
+ break;
1094
+ default:
1095
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset %"
1096
+ HWADDR_PRIx"\n", __func__, offset);
1097
+ break;
1098
+ }
1099
+}
1100
+
1101
+static const MemoryRegionOps allwinner_sdhost_ops = {
1102
+ .read = allwinner_sdhost_read,
1103
+ .write = allwinner_sdhost_write,
1104
+ .endianness = DEVICE_NATIVE_ENDIAN,
1105
+ .valid = {
1106
+ .min_access_size = 4,
1107
+ .max_access_size = 4,
1108
+ },
1109
+ .impl.min_access_size = 4,
1110
+};
1111
+
1112
+static const VMStateDescription vmstate_allwinner_sdhost = {
1113
+ .name = "allwinner-sdhost",
1114
+ .version_id = 1,
1115
+ .minimum_version_id = 1,
1116
+ .fields = (VMStateField[]) {
1117
+ VMSTATE_UINT32(global_ctl, AwSdHostState),
1118
+ VMSTATE_UINT32(clock_ctl, AwSdHostState),
1119
+ VMSTATE_UINT32(timeout, AwSdHostState),
1120
+ VMSTATE_UINT32(bus_width, AwSdHostState),
1121
+ VMSTATE_UINT32(block_size, AwSdHostState),
1122
+ VMSTATE_UINT32(byte_count, AwSdHostState),
1123
+ VMSTATE_UINT32(transfer_cnt, AwSdHostState),
1124
+ VMSTATE_UINT32(command, AwSdHostState),
1125
+ VMSTATE_UINT32(command_arg, AwSdHostState),
1126
+ VMSTATE_UINT32_ARRAY(response, AwSdHostState, 4),
1127
+ VMSTATE_UINT32(irq_mask, AwSdHostState),
1128
+ VMSTATE_UINT32(irq_status, AwSdHostState),
1129
+ VMSTATE_UINT32(status, AwSdHostState),
1130
+ VMSTATE_UINT32(fifo_wlevel, AwSdHostState),
1131
+ VMSTATE_UINT32(fifo_func_sel, AwSdHostState),
1132
+ VMSTATE_UINT32(debug_enable, AwSdHostState),
1133
+ VMSTATE_UINT32(auto12_arg, AwSdHostState),
1134
+ VMSTATE_UINT32(newtiming_set, AwSdHostState),
1135
+ VMSTATE_UINT32(newtiming_debug, AwSdHostState),
1136
+ VMSTATE_UINT32(hardware_rst, AwSdHostState),
1137
+ VMSTATE_UINT32(dmac, AwSdHostState),
1138
+ VMSTATE_UINT32(desc_base, AwSdHostState),
1139
+ VMSTATE_UINT32(dmac_status, AwSdHostState),
1140
+ VMSTATE_UINT32(dmac_irq, AwSdHostState),
1141
+ VMSTATE_UINT32(card_threshold, AwSdHostState),
1142
+ VMSTATE_UINT32(startbit_detect, AwSdHostState),
1143
+ VMSTATE_UINT32(response_crc, AwSdHostState),
1144
+ VMSTATE_UINT32_ARRAY(data_crc, AwSdHostState, 8),
1145
+ VMSTATE_UINT32(status_crc, AwSdHostState),
1146
+ VMSTATE_END_OF_LIST()
1147
+ }
1148
+};
1149
+
1150
+static void allwinner_sdhost_init(Object *obj)
1151
+{
1152
+ AwSdHostState *s = AW_SDHOST(obj);
1153
+
1154
+ qbus_create_inplace(&s->sdbus, sizeof(s->sdbus),
1155
+ TYPE_AW_SDHOST_BUS, DEVICE(s), "sd-bus");
1156
+
1157
+ memory_region_init_io(&s->iomem, obj, &allwinner_sdhost_ops, s,
1158
+ TYPE_AW_SDHOST, 4 * KiB);
1159
+ sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->iomem);
1160
+ sysbus_init_irq(SYS_BUS_DEVICE(s), &s->irq);
1161
+}
1162
+
1163
+static void allwinner_sdhost_reset(DeviceState *dev)
1164
+{
1165
+ AwSdHostState *s = AW_SDHOST(dev);
1166
+
1167
+ s->global_ctl = REG_SD_GCTL_RST;
1168
+ s->clock_ctl = REG_SD_CKCR_RST;
1169
+ s->timeout = REG_SD_TMOR_RST;
1170
+ s->bus_width = REG_SD_BWDR_RST;
1171
+ s->block_size = REG_SD_BKSR_RST;
1172
+ s->byte_count = REG_SD_BYCR_RST;
1173
+ s->transfer_cnt = 0;
1174
+
1175
+ s->command = REG_SD_CMDR_RST;
1176
+ s->command_arg = REG_SD_CAGR_RST;
1177
+
1178
+ for (int i = 0; i < ARRAY_SIZE(s->response); i++) {
1179
+ s->response[i] = REG_SD_RESP_RST;
1180
+ }
1181
+
1182
+ s->irq_mask = REG_SD_IMKR_RST;
1183
+ s->irq_status = REG_SD_RISR_RST;
1184
+ s->status = REG_SD_STAR_RST;
1185
+
1186
+ s->fifo_wlevel = REG_SD_FWLR_RST;
1187
+ s->fifo_func_sel = REG_SD_FUNS_RST;
1188
+ s->debug_enable = REG_SD_DBGC_RST;
1189
+ s->auto12_arg = REG_SD_A12A_RST;
1190
+ s->newtiming_set = REG_SD_NTSR_RST;
1191
+ s->newtiming_debug = REG_SD_SDBG_RST;
1192
+ s->hardware_rst = REG_SD_HWRST_RST;
1193
+ s->dmac = REG_SD_DMAC_RST;
1194
+ s->desc_base = REG_SD_DLBA_RST;
1195
+ s->dmac_status = REG_SD_IDST_RST;
1196
+ s->dmac_irq = REG_SD_IDIE_RST;
1197
+ s->card_threshold = REG_SD_THLDC_RST;
1198
+ s->startbit_detect = REG_SD_DSBD_RST;
1199
+ s->response_crc = REG_SD_RES_CRC_RST;
1200
+
1201
+ for (int i = 0; i < ARRAY_SIZE(s->data_crc); i++) {
1202
+ s->data_crc[i] = REG_SD_DATA_CRC_RST;
1203
+ }
1204
+
1205
+ s->status_crc = REG_SD_CRC_STA_RST;
1206
+}
1207
+
1208
+static void allwinner_sdhost_bus_class_init(ObjectClass *klass, void *data)
1209
+{
1210
+ SDBusClass *sbc = SD_BUS_CLASS(klass);
1211
+
1212
+ sbc->set_inserted = allwinner_sdhost_set_inserted;
1213
+}
1214
+
1215
+static void allwinner_sdhost_class_init(ObjectClass *klass, void *data)
1216
+{
1217
+ DeviceClass *dc = DEVICE_CLASS(klass);
1218
+
1219
+ dc->reset = allwinner_sdhost_reset;
1220
+ dc->vmsd = &vmstate_allwinner_sdhost;
1221
+}
1222
+
1223
+static void allwinner_sdhost_sun4i_class_init(ObjectClass *klass, void *data)
1224
+{
1225
+ AwSdHostClass *sc = AW_SDHOST_CLASS(klass);
1226
+ sc->max_desc_size = 8 * KiB;
1227
+}
1228
+
1229
+static void allwinner_sdhost_sun5i_class_init(ObjectClass *klass, void *data)
1230
+{
1231
+ AwSdHostClass *sc = AW_SDHOST_CLASS(klass);
1232
+ sc->max_desc_size = 64 * KiB;
1233
+}
1234
+
1235
+static TypeInfo allwinner_sdhost_info = {
1236
+ .name = TYPE_AW_SDHOST,
1237
+ .parent = TYPE_SYS_BUS_DEVICE,
1238
+ .instance_init = allwinner_sdhost_init,
1239
+ .instance_size = sizeof(AwSdHostState),
1240
+ .class_init = allwinner_sdhost_class_init,
1241
+ .class_size = sizeof(AwSdHostClass),
1242
+ .abstract = true,
1243
+};
1244
+
1245
+static const TypeInfo allwinner_sdhost_sun4i_info = {
1246
+ .name = TYPE_AW_SDHOST_SUN4I,
1247
+ .parent = TYPE_AW_SDHOST,
1248
+ .class_init = allwinner_sdhost_sun4i_class_init,
1249
+};
1250
+
1251
+static const TypeInfo allwinner_sdhost_sun5i_info = {
1252
+ .name = TYPE_AW_SDHOST_SUN5I,
1253
+ .parent = TYPE_AW_SDHOST,
1254
+ .class_init = allwinner_sdhost_sun5i_class_init,
1255
+};
1256
+
1257
+static const TypeInfo allwinner_sdhost_bus_info = {
1258
+ .name = TYPE_AW_SDHOST_BUS,
1259
+ .parent = TYPE_SD_BUS,
1260
+ .instance_size = sizeof(SDBus),
1261
+ .class_init = allwinner_sdhost_bus_class_init,
1262
+};
1263
+
1264
+static void allwinner_sdhost_register_types(void)
1265
+{
1266
+ type_register_static(&allwinner_sdhost_info);
1267
+ type_register_static(&allwinner_sdhost_sun4i_info);
1268
+ type_register_static(&allwinner_sdhost_sun5i_info);
1269
+ type_register_static(&allwinner_sdhost_bus_info);
1270
+}
1271
+
1272
+type_init(allwinner_sdhost_register_types)
1273
diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
1274
index XXXXXXX..XXXXXXX 100644
316
index XXXXXXX..XXXXXXX 100644
1275
--- a/hw/arm/Kconfig
317
--- a/hw/intc/trace-events
1276
+++ b/hw/arm/Kconfig
318
+++ b/hw/intc/trace-events
1277
@@ -XXX,XX +XXX,XX @@ config ALLWINNER_H3
319
@@ -XXX,XX +XXX,XX @@ gicv3_icv_rpr_read(uint32_t cpu, uint64_t val) "GICv3 ICV_RPR read cpu 0x%x valu
1278
select UNIMP
320
gicv3_icv_hppir_read(int grp, uint32_t cpu, uint64_t val) "GICv3 ICV_HPPIR%d read cpu 0x%x value 0x%" PRIx64
1279
select USB_OHCI
321
gicv3_icv_dir_write(uint32_t cpu, uint64_t val) "GICv3 ICV_DIR write cpu 0x%x value 0x%" PRIx64
1280
select USB_EHCI_SYSBUS
322
gicv3_icv_iar_read(int grp, uint32_t cpu, uint64_t val) "GICv3 ICV_IAR%d read cpu 0x%x value 0x%" PRIx64
1281
+ select SD
323
+gicv3_icv_nmiar1_read(uint32_t cpu, uint64_t val) "GICv3 ICV_NMIAR1 read cpu 0x%x value 0x%" PRIx64
1282
324
gicv3_icv_eoir_write(int grp, uint32_t cpu, uint64_t val) "GICv3 ICV_EOIR%d write cpu 0x%x value 0x%" PRIx64
1283
config RASPI
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"
1284
bool
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"
1285
diff --git a/hw/sd/trace-events b/hw/sd/trace-events
1286
index XXXXXXX..XXXXXXX 100644
1287
--- a/hw/sd/trace-events
1288
+++ b/hw/sd/trace-events
1289
@@ -XXX,XX +XXX,XX @@
1290
# See docs/devel/tracing.txt for syntax documentation.
1291
1292
+# allwinner-sdhost.c
1293
+allwinner_sdhost_set_inserted(bool inserted) "inserted %u"
1294
+allwinner_sdhost_process_desc(uint64_t desc_addr, uint32_t desc_size, bool is_write, uint32_t max_bytes) "desc_addr 0x%" PRIx64 " desc_size %" PRIu32 " is_write %u max_bytes %" PRIu32
1295
+allwinner_sdhost_read(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
1296
+allwinner_sdhost_write(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
1297
+allwinner_sdhost_update_irq(uint32_t irq) "IRQ bits 0x%" PRIx32
1298
+
1299
# bcm2835_sdhost.c
1300
bcm2835_sdhost_read(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u"
1301
bcm2835_sdhost_write(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u"
1302
--
327
--
1303
2.20.1
328
2.34.1
1304
1305
diff view generated by jsdifflib
1
From: Eric Auger <eric.auger@redhat.com>
1
From: Jinjie Ruan <ruanjinjie@huawei.com>
2
2
3
Mention 'max' value in the gic-version property description.
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.
4
8
5
Signed-off-by: Eric Auger <eric.auger@redhat.com>
9
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
10
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Reviewed-by: Andrew Jones <drjones@redhat.com>
11
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
8
Message-id: 20200311131618.7187-2-eric.auger@redhat.com
12
Message-id: 20240407081733.3231820-21-ruanjinjie@huawei.com
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
---
14
---
11
hw/arm/virt.c | 3 ++-
15
hw/intc/arm_gicv3.c | 67 +++++++++++++++++++++++++++++++++-----
12
1 file changed, 2 insertions(+), 1 deletion(-)
16
hw/intc/arm_gicv3_common.c | 3 ++
17
hw/intc/arm_gicv3_redist.c | 3 ++
18
3 files changed, 64 insertions(+), 9 deletions(-)
13
19
14
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
20
diff --git a/hw/intc/arm_gicv3.c b/hw/intc/arm_gicv3.c
15
index XXXXXXX..XXXXXXX 100644
21
index XXXXXXX..XXXXXXX 100644
16
--- a/hw/arm/virt.c
22
--- a/hw/intc/arm_gicv3.c
17
+++ b/hw/arm/virt.c
23
+++ b/hw/intc/arm_gicv3.c
18
@@ -XXX,XX +XXX,XX @@ static void virt_instance_init(Object *obj)
24
@@ -XXX,XX +XXX,XX @@
19
virt_set_gic_version, NULL);
25
#include "hw/intc/arm_gicv3.h"
20
object_property_set_description(obj, "gic-version",
26
#include "gicv3_internal.h"
21
"Set GIC version. "
27
22
- "Valid values are 2, 3 and host", NULL);
28
-static bool irqbetter(GICv3CPUState *cs, int irq, uint8_t prio)
23
+ "Valid values are 2, 3, host and max",
29
+static bool irqbetter(GICv3CPUState *cs, int irq, uint8_t prio, bool nmi)
24
+ NULL);
30
{
25
31
/* Return true if this IRQ at this priority should take
26
vms->highmem_ecam = !vmc->no_highmem_ecam;
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
}
27
208
28
--
209
--
29
2.20.1
210
2.34.1
30
31
diff view generated by jsdifflib
1
From: Eric Auger <eric.auger@redhat.com>
1
From: Jinjie Ruan <ruanjinjie@huawei.com>
2
2
3
Convert kvm_arm_vgic_probe() so that it returns a
3
In CPU Interface, if the IRQ has the non-maskable property, report NMI to
4
bitmap of supported in-kernel emulation VGIC versions instead
4
the corresponding PE.
5
of the max version: at the moment values can be v2 and v3.
6
This allows to expose the case where the host GICv3 also
7
supports GICv2 emulation. This will be useful to choose the
8
default version in KVM accelerated mode.
9
5
10
Signed-off-by: Eric Auger <eric.auger@redhat.com>
6
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
11
Reviewed-by: Andrew Jones <drjones@redhat.com>
12
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
13
Message-id: 20200311131618.7187-5-eric.auger@redhat.com
8
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
9
Message-id: 20240407081733.3231820-22-ruanjinjie@huawei.com
14
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
15
---
11
---
16
target/arm/kvm_arm.h | 3 +++
12
hw/intc/arm_gicv3_cpuif.c | 4 ++++
17
hw/arm/virt.c | 11 +++++++++--
13
1 file changed, 4 insertions(+)
18
target/arm/kvm.c | 14 ++++++++------
19
3 files changed, 20 insertions(+), 8 deletions(-)
20
14
21
diff --git a/target/arm/kvm_arm.h b/target/arm/kvm_arm.h
15
diff --git a/hw/intc/arm_gicv3_cpuif.c b/hw/intc/arm_gicv3_cpuif.c
22
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
23
--- a/target/arm/kvm_arm.h
17
--- a/hw/intc/arm_gicv3_cpuif.c
24
+++ b/target/arm/kvm_arm.h
18
+++ b/hw/intc/arm_gicv3_cpuif.c
25
@@ -XXX,XX +XXX,XX @@
19
@@ -XXX,XX +XXX,XX @@ void gicv3_cpuif_update(GICv3CPUState *cs)
26
#include "exec/memory.h"
20
/* Tell the CPU about its highest priority pending interrupt */
27
#include "qemu/error-report.h"
21
int irqlevel = 0;
28
22
int fiqlevel = 0;
29
+#define KVM_ARM_VGIC_V2 (1 << 0)
23
+ int nmilevel = 0;
30
+#define KVM_ARM_VGIC_V3 (1 << 1)
24
ARMCPU *cpu = ARM_CPU(cs->cpu);
31
+
25
CPUARMState *env = &cpu->env;
32
/**
26
33
* kvm_arm_vcpu_init:
27
@@ -XXX,XX +XXX,XX @@ void gicv3_cpuif_update(GICv3CPUState *cs)
34
* @cs: CPUState
28
35
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
29
if (isfiq) {
36
index XXXXXXX..XXXXXXX 100644
30
fiqlevel = 1;
37
--- a/hw/arm/virt.c
31
+ } else if (cs->hppi.nmi) {
38
+++ b/hw/arm/virt.c
32
+ nmilevel = 1;
39
@@ -XXX,XX +XXX,XX @@ static void finalize_gic_version(VirtMachineState *vms)
40
vms->gic_version = VIRT_GIC_VERSION_3;
41
}
42
} else {
33
} else {
43
- vms->gic_version = kvm_arm_vgic_probe();
34
irqlevel = 1;
44
- if (!vms->gic_version) {
45
+ int probe_bitmap = kvm_arm_vgic_probe();
46
+
47
+ if (!probe_bitmap) {
48
error_report(
49
"Unable to determine GIC version supported by host");
50
exit(1);
51
+ } else {
52
+ if (probe_bitmap & KVM_ARM_VGIC_V3) {
53
+ vms->gic_version = VIRT_GIC_VERSION_3;
54
+ } else {
55
+ vms->gic_version = VIRT_GIC_VERSION_2;
56
+ }
57
}
58
}
35
}
59
} else if (vms->gic_version == VIRT_GIC_VERSION_NOSEL) {
36
@@ -XXX,XX +XXX,XX @@ void gicv3_cpuif_update(GICv3CPUState *cs)
60
diff --git a/target/arm/kvm.c b/target/arm/kvm.c
37
61
index XXXXXXX..XXXXXXX 100644
38
qemu_set_irq(cs->parent_fiq, fiqlevel);
62
--- a/target/arm/kvm.c
39
qemu_set_irq(cs->parent_irq, irqlevel);
63
+++ b/target/arm/kvm.c
40
+ qemu_set_irq(cs->parent_nmi, nmilevel);
64
@@ -XXX,XX +XXX,XX @@ int kvm_arch_irqchip_create(KVMState *s)
65
66
int kvm_arm_vgic_probe(void)
67
{
68
+ int val = 0;
69
+
70
if (kvm_create_device(kvm_state,
71
KVM_DEV_TYPE_ARM_VGIC_V3, true) == 0) {
72
- return 3;
73
- } else if (kvm_create_device(kvm_state,
74
- KVM_DEV_TYPE_ARM_VGIC_V2, true) == 0) {
75
- return 2;
76
- } else {
77
- return 0;
78
+ val |= KVM_ARM_VGIC_V3;
79
}
80
+ if (kvm_create_device(kvm_state,
81
+ KVM_DEV_TYPE_ARM_VGIC_V2, true) == 0) {
82
+ val |= KVM_ARM_VGIC_V2;
83
+ }
84
+ return val;
85
}
41
}
86
42
87
int kvm_arm_set_irq(int cpu, int irqtype, int irq, int level)
43
static uint64_t icc_pmr_read(CPUARMState *env, const ARMCPRegInfo *ri)
88
--
44
--
89
2.20.1
45
2.34.1
90
91
diff view generated by jsdifflib
1
From: Guenter Roeck <linux@roeck-us.net>
1
From: Jinjie Ruan <ruanjinjie@huawei.com>
2
2
3
i.MX25 supports two USB controllers. Let's wire them up.
3
In vCPU Interface, if the vIRQ has the non-maskable property, report
4
vINMI to the corresponding vPE.
4
5
5
With this patch, imx25-pdk can boot from both USB ports.
6
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
6
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
8
Message-id: 20200310215146.19688-3-linux@roeck-us.net
9
Reviewed-by: Peter Maydell <peter.maydell@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>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
---
11
---
12
include/hw/arm/fsl-imx25.h | 9 +++++++++
12
hw/intc/arm_gicv3_cpuif.c | 14 ++++++++++++--
13
hw/arm/fsl-imx25.c | 24 ++++++++++++++++++++++++
13
1 file changed, 12 insertions(+), 2 deletions(-)
14
2 files changed, 33 insertions(+)
15
14
16
diff --git a/include/hw/arm/fsl-imx25.h b/include/hw/arm/fsl-imx25.h
15
diff --git a/hw/intc/arm_gicv3_cpuif.c b/hw/intc/arm_gicv3_cpuif.c
17
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
18
--- a/include/hw/arm/fsl-imx25.h
17
--- a/hw/intc/arm_gicv3_cpuif.c
19
+++ b/include/hw/arm/fsl-imx25.h
18
+++ b/hw/intc/arm_gicv3_cpuif.c
20
@@ -XXX,XX +XXX,XX @@
19
@@ -XXX,XX +XXX,XX @@ void gicv3_cpuif_virt_irq_fiq_update(GICv3CPUState *cs)
21
#include "hw/i2c/imx_i2c.h"
20
int idx;
22
#include "hw/gpio/imx_gpio.h"
21
int irqlevel = 0;
23
#include "hw/sd/sdhci.h"
22
int fiqlevel = 0;
24
+#include "hw/usb/chipidea.h"
23
+ int nmilevel = 0;
25
#include "exec/memory.h"
24
26
#include "target/arm/cpu.h"
25
idx = hppvi_index(cs);
27
26
trace_gicv3_cpuif_virt_update(gicv3_redist_affid(cs), idx,
28
@@ -XXX,XX +XXX,XX @@
27
@@ -XXX,XX +XXX,XX @@ void gicv3_cpuif_virt_irq_fiq_update(GICv3CPUState *cs)
29
#define FSL_IMX25_NUM_I2CS 3
28
uint64_t lr = cs->ich_lr_el2[idx];
30
#define FSL_IMX25_NUM_GPIOS 4
29
31
#define FSL_IMX25_NUM_ESDHCS 2
30
if (icv_hppi_can_preempt(cs, lr)) {
32
+#define FSL_IMX25_NUM_USBS 2
31
- /* Virtual interrupts are simple: G0 are always FIQ, and G1 IRQ */
33
32
+ /*
34
typedef struct FslIMX25State {
33
+ * Virtual interrupts are simple: G0 are always FIQ, and G1 are
35
/*< private >*/
34
+ * IRQ or NMI which depends on the ICH_LR<n>_EL2.NMI to have
36
@@ -XXX,XX +XXX,XX @@ typedef struct FslIMX25State {
35
+ * non-maskable property.
37
IMXI2CState i2c[FSL_IMX25_NUM_I2CS];
36
+ */
38
IMXGPIOState gpio[FSL_IMX25_NUM_GPIOS];
37
if (lr & ICH_LR_EL2_GROUP) {
39
SDHCIState esdhc[FSL_IMX25_NUM_ESDHCS];
38
- irqlevel = 1;
40
+ ChipideaState usb[FSL_IMX25_NUM_USBS];
39
+ if (lr & ICH_LR_EL2_NMI) {
41
MemoryRegion rom[2];
40
+ nmilevel = 1;
42
MemoryRegion iram;
41
+ } else {
43
MemoryRegion iram_alias;
42
+ irqlevel = 1;
44
@@ -XXX,XX +XXX,XX @@ typedef struct FslIMX25State {
43
+ }
45
#define FSL_IMX25_GPIO1_SIZE 0x4000
44
} else {
46
#define FSL_IMX25_GPIO2_ADDR 0x53FD0000
45
fiqlevel = 1;
47
#define FSL_IMX25_GPIO2_SIZE 0x4000
46
}
48
+#define FSL_IMX25_USB1_ADDR 0x53FF4000
47
@@ -XXX,XX +XXX,XX @@ void gicv3_cpuif_virt_irq_fiq_update(GICv3CPUState *cs)
49
+#define FSL_IMX25_USB1_SIZE 0x0200
48
trace_gicv3_cpuif_virt_set_irqs(gicv3_redist_affid(cs), fiqlevel, irqlevel);
50
+#define FSL_IMX25_USB2_ADDR 0x53FF4400
49
qemu_set_irq(cs->parent_vfiq, fiqlevel);
51
+#define FSL_IMX25_USB2_SIZE 0x0200
50
qemu_set_irq(cs->parent_virq, irqlevel);
52
#define FSL_IMX25_AVIC_ADDR 0x68000000
51
+ qemu_set_irq(cs->parent_vnmi, nmilevel);
53
#define FSL_IMX25_AVIC_SIZE 0x4000
54
#define FSL_IMX25_IRAM_ADDR 0x78000000
55
@@ -XXX,XX +XXX,XX @@ typedef struct FslIMX25State {
56
#define FSL_IMX25_GPIO4_IRQ 23
57
#define FSL_IMX25_ESDHC1_IRQ 9
58
#define FSL_IMX25_ESDHC2_IRQ 8
59
+#define FSL_IMX25_USB1_IRQ 37
60
+#define FSL_IMX25_USB2_IRQ 35
61
62
#endif /* FSL_IMX25_H */
63
diff --git a/hw/arm/fsl-imx25.c b/hw/arm/fsl-imx25.c
64
index XXXXXXX..XXXXXXX 100644
65
--- a/hw/arm/fsl-imx25.c
66
+++ b/hw/arm/fsl-imx25.c
67
@@ -XXX,XX +XXX,XX @@ static void fsl_imx25_init(Object *obj)
68
sysbus_init_child_obj(obj, "sdhc[*]", &s->esdhc[i], sizeof(s->esdhc[i]),
69
TYPE_IMX_USDHC);
70
}
71
+
72
+ for (i = 0; i < FSL_IMX25_NUM_USBS; i++) {
73
+ sysbus_init_child_obj(obj, "usb[*]", &s->usb[i], sizeof(s->usb[i]),
74
+ TYPE_CHIPIDEA);
75
+ }
76
+
77
}
52
}
78
53
79
static void fsl_imx25_realize(DeviceState *dev, Error **errp)
54
static void gicv3_cpuif_virt_update(GICv3CPUState *cs)
80
@@ -XXX,XX +XXX,XX @@ static void fsl_imx25_realize(DeviceState *dev, Error **errp)
81
esdhc_table[i].irq));
82
}
83
84
+ /* USB */
85
+ for (i = 0; i < FSL_IMX25_NUM_USBS; i++) {
86
+ static const struct {
87
+ hwaddr addr;
88
+ unsigned int irq;
89
+ } usb_table[FSL_IMX25_NUM_USBS] = {
90
+ { FSL_IMX25_USB1_ADDR, FSL_IMX25_USB1_IRQ },
91
+ { FSL_IMX25_USB2_ADDR, FSL_IMX25_USB2_IRQ },
92
+ };
93
+
94
+ object_property_set_bool(OBJECT(&s->usb[i]), true, "realized",
95
+ &error_abort);
96
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->usb[i]), 0, usb_table[i].addr);
97
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->usb[i]), 0,
98
+ qdev_get_gpio_in(DEVICE(&s->avic),
99
+ usb_table[i].irq));
100
+ }
101
+
102
/* initialize 2 x 16 KB ROM */
103
memory_region_init_rom(&s->rom[0], NULL,
104
"imx25.rom0", FSL_IMX25_ROM0_SIZE, &err);
105
--
55
--
106
2.20.1
56
2.34.1
107
108
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
1
From: Jinjie Ruan <ruanjinjie@huawei.com>
2
2
3
This test boots a Linux kernel on a OrangePi PC board and verify
3
Enable FEAT_NMI on the 'max' CPU.
4
the serial output is working.
5
4
6
The kernel image and DeviceTree blob are built by the Armbian
5
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
7
project (based on Debian):
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
https://www.armbian.com/orange-pi-pc/
7
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
9
8
Message-id: 20240407081733.3231820-24-ruanjinjie@huawei.com
10
If ARM is a target being built, "make check-acceptance" will
11
automatically include this test by the use of the "arch:arm" tags.
12
13
Alternatively, this test can be run using:
14
15
$ make check-venv
16
$ ./tests/venv/bin/avocado --show=console,app run -t machine:orangepi-pc tests/acceptance/boot_linux_console.py
17
JOB ID : 2e4d15eceb13c33672af406f08171e6e9de1414a
18
JOB LOG : ~/job-results/job-2019-12-17T05.46-2e4d15e/job.log
19
(1/1) tests/acceptance/boot_linux_console.py:BootLinuxConsole.test_arm_orangepi:
20
console: Uncompressing Linux... done, booting the kernel.
21
console: Booting Linux on physical CPU 0x0
22
console: Linux version 4.20.7-sunxi (root@armbian.com) (gcc version 7.2.1 20171011 (Linaro GCC 7.2-2017.11)) #5.75 SMP Fri Feb 8 09:02:10 CET 2019
23
console: CPU: ARMv7 Processor [410fc075] revision 5 (ARMv7), cr=50c5387d
24
console: CPU: div instructions available: patching division code
25
console: CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
26
console: OF: fdt: Machine model: Xunlong Orange Pi PC
27
console: Memory policy: Data cache writealloc
28
console: OF: reserved mem: failed to allocate memory for node 'cma@4a000000'
29
console: cma: Failed to reserve 128 MiB
30
console: psci: probing for conduit method from DT.
31
console: psci: PSCIv0.2 detected in firmware.
32
console: psci: Using standard PSCI v0.2 function IDs
33
console: psci: Trusted OS migration not required
34
console: random: get_random_bytes called from start_kernel+0x8d/0x3c2 with crng_init=0
35
console: percpu: Embedded 18 pages/cpu @(ptrval) s41228 r8192 d24308 u73728
36
console: Built 1 zonelists, mobility grouping on. Total pages: 32480
37
console: Kernel command line: printk.time=0 console=ttyS0,115200
38
PASS (8.59 s)
39
JOB TIME : 8.81 s
40
41
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
42
Signed-off-by: Niek Linnenbank <nieklinnenbank@gmail.com>
43
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
44
Tested-by: Alex Bennée <alex.bennee@linaro.org>
45
Message-id: 20200311221854.30370-14-nieklinnenbank@gmail.com
46
[NL: rename in commit message Raspbian to Armbian, remove vm.set_machine()]
47
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
48
---
10
---
49
tests/acceptance/boot_linux_console.py | 25 +++++++++++++++++++++++++
11
docs/system/arm/emulation.rst | 1 +
50
1 file changed, 25 insertions(+)
12
target/arm/tcg/cpu64.c | 1 +
13
2 files changed, 2 insertions(+)
51
14
52
diff --git a/tests/acceptance/boot_linux_console.py b/tests/acceptance/boot_linux_console.py
15
diff --git a/docs/system/arm/emulation.rst b/docs/system/arm/emulation.rst
53
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
54
--- a/tests/acceptance/boot_linux_console.py
17
--- a/docs/system/arm/emulation.rst
55
+++ b/tests/acceptance/boot_linux_console.py
18
+++ b/docs/system/arm/emulation.rst
56
@@ -XXX,XX +XXX,XX @@ class BootLinuxConsole(Test):
19
@@ -XXX,XX +XXX,XX @@ the following architecture extensions:
57
exec_command_and_wait_for_pattern(self, 'reboot',
20
- FEAT_MTE (Memory Tagging Extension)
58
'reboot: Restarting system')
21
- FEAT_MTE2 (Memory Tagging Extension)
59
22
- FEAT_MTE3 (MTE Asymmetric Fault Handling)
60
+ def test_arm_orangepi(self):
23
+- FEAT_NMI (Non-maskable Interrupt)
61
+ """
24
- FEAT_NV (Nested Virtualization)
62
+ :avocado: tags=arch:arm
25
- FEAT_NV2 (Enhanced nested virtualization support)
63
+ :avocado: tags=machine:orangepi-pc
26
- FEAT_PACIMP (Pointer authentication - IMPLEMENTATION DEFINED algorithm)
64
+ """
27
diff --git a/target/arm/tcg/cpu64.c b/target/arm/tcg/cpu64.c
65
+ deb_url = ('https://apt.armbian.com/pool/main/l/'
28
index XXXXXXX..XXXXXXX 100644
66
+ 'linux-4.20.7-sunxi/linux-image-dev-sunxi_5.75_armhf.deb')
29
--- a/target/arm/tcg/cpu64.c
67
+ deb_hash = '1334c29c44d984ffa05ed10de8c3361f33d78315'
30
+++ b/target/arm/tcg/cpu64.c
68
+ deb_path = self.fetch_asset(deb_url, asset_hash=deb_hash)
31
@@ -XXX,XX +XXX,XX @@ void aarch64_max_tcg_initfn(Object *obj)
69
+ kernel_path = self.extract_from_deb(deb_path,
32
t = FIELD_DP64(t, ID_AA64PFR1, RAS_FRAC, 0); /* FEAT_RASv1p1 + FEAT_DoubleFault */
70
+ '/boot/vmlinuz-4.20.7-sunxi')
33
t = FIELD_DP64(t, ID_AA64PFR1, SME, 1); /* FEAT_SME */
71
+ dtb_path = '/usr/lib/linux-image-dev-sunxi/sun8i-h3-orangepi-pc.dtb'
34
t = FIELD_DP64(t, ID_AA64PFR1, CSV2_FRAC, 0); /* FEAT_CSV2_2 */
72
+ dtb_path = self.extract_from_deb(deb_path, dtb_path)
35
+ t = FIELD_DP64(t, ID_AA64PFR1, NMI, 1); /* FEAT_NMI */
73
+
36
cpu->isar.id_aa64pfr1 = t;
74
+ self.vm.set_console()
37
75
+ kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
38
t = cpu->isar.id_aa64mmfr0;
76
+ 'console=ttyS0,115200n8 '
77
+ 'earlycon=uart,mmio32,0x1c28000')
78
+ self.vm.add_args('-kernel', kernel_path,
79
+ '-dtb', dtb_path,
80
+ '-append', kernel_command_line)
81
+ self.vm.launch()
82
+ console_pattern = 'Kernel command line: %s' % kernel_command_line
83
+ self.wait_for_console_pattern(console_pattern)
84
+
85
def test_s390x_s390_ccw_virtio(self):
86
"""
87
:avocado: tags=arch:s390x
88
--
39
--
89
2.20.1
40
2.34.1
90
91
diff view generated by jsdifflib
1
From: Eric Auger <eric.auger@redhat.com>
1
From: Jinjie Ruan <ruanjinjie@huawei.com>
2
2
3
Let's move the code which freezes which gic-version to
3
If the CPU implements FEAT_NMI, then turn on the NMI support in the
4
be applied in a dedicated function. We also now set by
4
GICv3 too. It's permitted to have a configuration with FEAT_NMI in
5
default the VIRT_GIC_VERSION_NO_SET. This eventually
5
the CPU (and thus NMI support in the CPU interfaces too) but no NMI
6
turns into the legacy v2 choice in the finalize() function.
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.
7
8
8
Signed-off-by: Eric Auger <eric.auger@redhat.com>
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>
9
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
19
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
10
Reviewed-by: Andrew Jones <drjones@redhat.com>
20
Message-id: 20240407081733.3231820-25-ruanjinjie@huawei.com
11
Message-id: 20200311131618.7187-4-eric.auger@redhat.com
21
[PMM: Update comment and commit message]
22
Suggested-by: Peter Maydell <peter.maydell@linaro.org>
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
23
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
---
24
---
14
include/hw/arm/virt.h | 1 +
25
hw/arm/virt.c | 19 +++++++++++++++++++
15
hw/arm/virt.c | 54 ++++++++++++++++++++++++++-----------------
26
1 file changed, 19 insertions(+)
16
2 files changed, 34 insertions(+), 21 deletions(-)
17
27
18
diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h
19
index XXXXXXX..XXXXXXX 100644
20
--- a/include/hw/arm/virt.h
21
+++ b/include/hw/arm/virt.h
22
@@ -XXX,XX +XXX,XX @@ typedef enum VirtGICType {
23
VIRT_GIC_VERSION_HOST,
24
VIRT_GIC_VERSION_2,
25
VIRT_GIC_VERSION_3,
26
+ VIRT_GIC_VERSION_NOSEL,
27
} VirtGICType;
28
29
typedef struct MemMapEntry {
30
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
28
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
31
index XXXXXXX..XXXXXXX 100644
29
index XXXXXXX..XXXXXXX 100644
32
--- a/hw/arm/virt.c
30
--- a/hw/arm/virt.c
33
+++ b/hw/arm/virt.c
31
+++ b/hw/arm/virt.c
34
@@ -XXX,XX +XXX,XX @@ static void virt_set_memmap(VirtMachineState *vms)
32
@@ -XXX,XX +XXX,XX @@ static void create_v2m(VirtMachineState *vms)
35
}
33
vms->msi_controller = VIRT_MSI_CTRL_GICV2M;
36
}
34
}
37
35
38
+/*
36
+/*
39
+ * finalize_gic_version - Determines the final gic_version
37
+ * If the CPU has FEAT_NMI, then turn on the NMI support in the GICv3 too.
40
+ * according to the gic-version property
38
+ * It's permitted to have a configuration with NMI in the CPU (and thus the
41
+ *
39
+ * GICv3 CPU interface) but not in the distributor/redistributors, but it's
42
+ * Default GIC type is v2
40
+ * not very useful.
43
+ */
41
+ */
44
+static void finalize_gic_version(VirtMachineState *vms)
42
+static bool gicv3_nmi_present(VirtMachineState *vms)
45
+{
43
+{
46
+ if (vms->gic_version == VIRT_GIC_VERSION_HOST ||
44
+ ARMCPU *cpu = ARM_CPU(qemu_get_cpu(0));
47
+ vms->gic_version == VIRT_GIC_VERSION_MAX) {
45
+
48
+ if (!kvm_enabled()) {
46
+ return tcg_enabled() && cpu_isar_feature(aa64_nmi, cpu) &&
49
+ if (vms->gic_version == VIRT_GIC_VERSION_HOST) {
47
+ (vms->gic_version != VIRT_GIC_VERSION_2);
50
+ error_report("gic-version=host requires KVM");
51
+ exit(1);
52
+ } else {
53
+ /* "max": currently means 3 for TCG */
54
+ vms->gic_version = VIRT_GIC_VERSION_3;
55
+ }
56
+ } else {
57
+ vms->gic_version = kvm_arm_vgic_probe();
58
+ if (!vms->gic_version) {
59
+ error_report(
60
+ "Unable to determine GIC version supported by host");
61
+ exit(1);
62
+ }
63
+ }
64
+ } else if (vms->gic_version == VIRT_GIC_VERSION_NOSEL) {
65
+ vms->gic_version = VIRT_GIC_VERSION_2;
66
+ }
67
+}
48
+}
68
+
49
+
69
static void machvirt_init(MachineState *machine)
50
static void create_gic(VirtMachineState *vms, MemoryRegion *mem)
70
{
51
{
71
VirtMachineState *vms = VIRT_MACHINE(machine);
52
MachineState *ms = MACHINE(vms);
72
@@ -XXX,XX +XXX,XX @@ static void machvirt_init(MachineState *machine)
53
@@ -XXX,XX +XXX,XX @@ static void create_gic(VirtMachineState *vms, MemoryRegion *mem)
73
/* We can probe only here because during property set
54
vms->virt);
74
* KVM is not available yet
55
}
75
*/
56
}
76
- if (vms->gic_version == VIRT_GIC_VERSION_HOST ||
57
+
77
- vms->gic_version == VIRT_GIC_VERSION_MAX) {
58
+ if (gicv3_nmi_present(vms)) {
78
- if (!kvm_enabled()) {
59
+ qdev_prop_set_bit(vms->gic, "has-nmi", true);
79
- if (vms->gic_version == VIRT_GIC_VERSION_HOST) {
60
+ }
80
- error_report("gic-version=host requires KVM");
61
+
81
- exit(1);
62
gicbusdev = SYS_BUS_DEVICE(vms->gic);
82
- } else {
63
sysbus_realize_and_unref(gicbusdev, &error_fatal);
83
- /* "max": currently means 3 for TCG */
64
sysbus_mmio_map(gicbusdev, 0, vms->memmap[VIRT_GIC_DIST].base);
84
- vms->gic_version = VIRT_GIC_VERSION_3;
85
- }
86
- } else {
87
- vms->gic_version = kvm_arm_vgic_probe();
88
- if (!vms->gic_version) {
89
- error_report(
90
- "Unable to determine GIC version supported by host");
91
- exit(1);
92
- }
93
- }
94
- }
95
+ finalize_gic_version(vms);
96
97
if (!cpu_type_valid(machine->cpu_type)) {
98
error_report("mach-virt: CPU type %s not supported", machine->cpu_type);
99
@@ -XXX,XX +XXX,XX @@ static void virt_instance_init(Object *obj)
100
"Set on/off to enable/disable using "
101
"physical address space above 32 bits",
102
NULL);
103
- /* Default GIC type is v2 */
104
- vms->gic_version = VIRT_GIC_VERSION_2;
105
+ vms->gic_version = VIRT_GIC_VERSION_NOSEL;
106
object_property_add_str(obj, "gic-version", virt_get_gic_version,
107
virt_set_gic_version, NULL);
108
object_property_set_description(obj, "gic-version",
109
--
65
--
110
2.20.1
66
2.34.1
111
112
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Anastasia Belova <abelova@astralinux.ru>
2
2
3
We must include the tag in the FAR_ELx register when raising
3
In soc_dma_set_request() we try to set a bit in a uint64_t, but we
4
an addressing exception. Which means that we should not clear
4
do it with "1 << ch->num", which can't set any bits past 31;
5
out the tag during translation.
5
any use for a channel number of 32 or more would fail due to
6
integer overflow.
6
7
7
We cannot at present comply with this for user mode, so we
8
This doesn't happen in practice for our current use of this code,
8
retain the clean_data_tbi function for the moment, though it
9
because the worst case is when we call soc_dma_init() with an
9
no longer does what it says on the tin for system mode. This
10
argument of 32 for the number of channels, and QEMU builds with
10
function is to be replaced with MTE, so don't worry about the
11
-fwrapv so the shift into the sign bit is well-defined. However,
11
slight misnaming.
12
it's obviously not the intended behaviour of the code.
12
13
13
Buglink: https://bugs.launchpad.net/qemu/+bug/1867072
14
Add casts to force the shift to be done as 64-bit arithmetic,
14
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
15
allowing up to 64 channels.
15
Message-id: 20200308012946.16303-3-richard.henderson@linaro.org
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.]
16
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
24
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
17
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
25
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
18
---
26
---
19
target/arm/translate-a64.c | 11 +++++++++++
27
hw/dma/soc_dma.c | 4 ++--
20
1 file changed, 11 insertions(+)
28
1 file changed, 2 insertions(+), 2 deletions(-)
21
29
22
diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c
30
diff --git a/hw/dma/soc_dma.c b/hw/dma/soc_dma.c
23
index XXXXXXX..XXXXXXX 100644
31
index XXXXXXX..XXXXXXX 100644
24
--- a/target/arm/translate-a64.c
32
--- a/hw/dma/soc_dma.c
25
+++ b/target/arm/translate-a64.c
33
+++ b/hw/dma/soc_dma.c
26
@@ -XXX,XX +XXX,XX @@ static void gen_a64_set_pc(DisasContext *s, TCGv_i64 src)
34
@@ -XXX,XX +XXX,XX @@ void soc_dma_set_request(struct soc_dma_ch_s *ch, int level)
27
static TCGv_i64 clean_data_tbi(DisasContext *s, TCGv_i64 addr)
35
dma->enabled_count += level - ch->enable;
28
{
36
29
TCGv_i64 clean = new_tmp_a64(s);
37
if (level)
30
+ /*
38
- dma->ch_enable_mask |= 1 << ch->num;
31
+ * In order to get the correct value in the FAR_ELx register,
39
+ dma->ch_enable_mask |= (uint64_t)1 << ch->num;
32
+ * we must present the memory subsystem with the "dirty" address
40
else
33
+ * including the TBI. In system mode we can make this work via
41
- dma->ch_enable_mask &= ~(1 << ch->num);
34
+ * the TLB, dropping the TBI during translation. But for user-only
42
+ dma->ch_enable_mask &= ~((uint64_t)1 << ch->num);
35
+ * mode we don't have that option, and must remove the top byte now.
43
36
+ */
44
if (level != ch->enable) {
37
+#ifdef CONFIG_USER_ONLY
45
soc_dma_ch_freq_update(dma);
38
gen_top_byte_ignore(s, clean, addr, s->tbid);
39
+#else
40
+ tcg_gen_mov_i64(clean, addr);
41
+#endif
42
return clean;
43
}
44
45
--
46
--
46
2.20.1
47
2.34.1
47
48
diff view generated by jsdifflib
1
From: Cédric Le Goater <clg@kaod.org>
1
Ever since the bFLT format support was added in 2006, there has been
2
2
a chunk of code in the file guarded by CONFIG_BINFMT_SHARED_FLAT
3
Signed-off-by: Cédric Le Goater <clg@kaod.org>
3
which is supposedly for shared library support. This is not enabled
4
Reviewed-by: Andrew Jeffery <andrew@aj.id.au>
4
and it's not possible to enable it, because if you do you'll run into
5
Reviewed-by: Joel Stanley <joel@jms.id.au>
5
the "#error needs checking" in the calc_reloc() function.
6
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
6
7
Message-id: 20200206112645.21275-2-clg@kaod.org
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
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
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
9
---
20
---
10
Makefile.objs | 1 +
21
linux-user/flat.h | 5 +-
11
hw/ssi/aspeed_smc.c | 17 +++++++++++++++++
22
linux-user/flatload.c | 293 ++----------------------------------------
12
hw/ssi/trace-events | 9 +++++++++
23
2 files changed, 11 insertions(+), 287 deletions(-)
13
3 files changed, 27 insertions(+)
24
14
create mode 100644 hw/ssi/trace-events
25
diff --git a/linux-user/flat.h b/linux-user/flat.h
15
16
diff --git a/Makefile.objs b/Makefile.objs
17
index XXXXXXX..XXXXXXX 100644
26
index XXXXXXX..XXXXXXX 100644
18
--- a/Makefile.objs
27
--- a/linux-user/flat.h
19
+++ b/Makefile.objs
28
+++ b/linux-user/flat.h
20
@@ -XXX,XX +XXX,XX @@ trace-events-subdirs += hw/scsi
29
@@ -XXX,XX +XXX,XX @@
21
trace-events-subdirs += hw/sd
30
22
trace-events-subdirs += hw/sparc
31
#define    FLAT_VERSION            0x00000004L
23
trace-events-subdirs += hw/sparc64
32
24
+trace-events-subdirs += hw/ssi
33
-#ifdef CONFIG_BINFMT_SHARED_FLAT
25
trace-events-subdirs += hw/timer
34
-#define    MAX_SHARED_LIBS            (4)
26
trace-events-subdirs += hw/tpm
35
-#else
27
trace-events-subdirs += hw/usb
36
+/* QEMU doesn't support bflt shared libraries */
28
diff --git a/hw/ssi/aspeed_smc.c b/hw/ssi/aspeed_smc.c
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
29
index XXXXXXX..XXXXXXX 100644
43
index XXXXXXX..XXXXXXX 100644
30
--- a/hw/ssi/aspeed_smc.c
44
--- a/linux-user/flatload.c
31
+++ b/hw/ssi/aspeed_smc.c
45
+++ b/linux-user/flatload.c
32
@@ -XXX,XX +XXX,XX @@
46
@@ -XXX,XX +XXX,XX @@
33
#include "qapi/error.h"
47
*    JAN/99 -- coded full program relocation (gerg@snapgear.com)
34
#include "exec/address-spaces.h"
48
*/
35
#include "qemu/units.h"
49
36
+#include "trace.h"
50
-/* ??? ZFLAT and shared library support is currently disabled. */
37
51
-
38
#include "hw/irq.h"
52
/****************************************************************************/
39
#include "hw/qdev-properties.h"
53
40
@@ -XXX,XX +XXX,XX @@ static void aspeed_smc_flash_set_segment(AspeedSMCState *s, int cs,
54
#include "qemu/osdep.h"
41
55
@@ -XXX,XX +XXX,XX @@ struct lib_info {
42
s->ctrl->reg_to_segment(s, new, &seg);
56
short loaded;        /* Has this library been loaded? */
43
57
};
44
+ trace_aspeed_smc_flash_set_segment(cs, new, seg.addr, seg.addr + seg.size);
58
45
+
59
-#ifdef CONFIG_BINFMT_SHARED_FLAT
46
/* The start address of CS0 is read-only */
60
-static int load_flat_shared_library(int id, struct lib_info *p);
47
if (cs == 0 && seg.addr != s->ctrl->flash_window_base) {
61
-#endif
48
qemu_log_mask(LOG_GUEST_ERROR,
62
-
49
@@ -XXX,XX +XXX,XX @@ static uint64_t aspeed_smc_flash_read(void *opaque, hwaddr addr, unsigned size)
63
struct linux_binprm;
50
__func__, aspeed_smc_flash_mode(fl));
64
51
}
65
/****************************************************************************/
52
66
@@ -XXX,XX +XXX,XX @@ static int target_pread(int fd, abi_ulong ptr, abi_ulong len,
53
+ trace_aspeed_smc_flash_read(fl->id, addr, size, ret,
67
unlock_user(buf, ptr, len);
54
+ aspeed_smc_flash_mode(fl));
55
return ret;
68
return ret;
56
}
69
}
57
70
-/****************************************************************************/
58
@@ -XXX,XX +XXX,XX @@ static bool aspeed_smc_do_snoop(AspeedSMCFlash *fl, uint64_t data,
71
-
59
AspeedSMCState *s = fl->controller;
72
-#ifdef CONFIG_BINFMT_ZFLAT
60
uint8_t addr_width = aspeed_smc_flash_is_4byte(fl) ? 4 : 3;
73
-
61
74
-#include <linux/zlib.h>
62
+ trace_aspeed_smc_do_snoop(fl->id, s->snoop_index, s->snoop_dummies,
75
-
63
+ (uint8_t) data & 0xff);
76
-#define LBUFSIZE    4000
64
+
77
-
65
if (s->snoop_index == SNOOP_OFF) {
78
-/* gzip flag byte */
66
return false; /* Do nothing */
79
-#define ASCII_FLAG 0x01 /* bit 0 set: file probably ASCII text */
67
80
-#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
68
@@ -XXX,XX +XXX,XX @@ static void aspeed_smc_flash_write(void *opaque, hwaddr addr, uint64_t data,
81
-#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
69
AspeedSMCState *s = fl->controller;
82
-#define ORIG_NAME 0x08 /* bit 3 set: original file name present */
70
int i;
83
-#define COMMENT 0x10 /* bit 4 set: file comment present */
71
84
-#define ENCRYPTED 0x20 /* bit 5 set: file is encrypted */
72
+ trace_aspeed_smc_flash_write(fl->id, addr, size, data,
85
-#define RESERVED 0xC0 /* bit 6,7: reserved */
73
+ aspeed_smc_flash_mode(fl));
86
-
74
+
87
-static int decompress_exec(
75
if (!aspeed_smc_is_writable(fl)) {
88
-    struct linux_binprm *bprm,
76
qemu_log_mask(LOG_GUEST_ERROR, "%s: flash is not writable at 0x%"
89
-    unsigned long offset,
77
HWADDR_PRIx "\n", __func__, addr);
90
-    char *dst,
78
@@ -XXX,XX +XXX,XX @@ static uint64_t aspeed_smc_read(void *opaque, hwaddr addr, unsigned int size)
91
-    long len,
79
(s->ctrl->has_dma && addr == R_DMA_CHECKSUM) ||
92
-    int fd)
80
(addr >= R_SEG_ADDR0 && addr < R_SEG_ADDR0 + s->ctrl->max_slaves) ||
93
-{
81
(addr >= s->r_ctrl0 && addr < s->r_ctrl0 + s->ctrl->max_slaves)) {
94
-    unsigned char *buf;
82
+
95
-    z_stream strm;
83
+ trace_aspeed_smc_read(addr, size, s->regs[addr]);
96
-    loff_t fpos;
84
+
97
-    int ret, retval;
85
return s->regs[addr];
98
-
86
} else {
99
-    DBG_FLT("decompress_exec(offset=%x,buf=%x,len=%x)\n",(int)offset, (int)dst, (int)len);
87
qemu_log_mask(LOG_UNIMP, "%s: not implemented: 0x%" HWADDR_PRIx "\n",
100
-
88
@@ -XXX,XX +XXX,XX @@ static void aspeed_smc_dma_checksum(AspeedSMCState *s)
101
-    memset(&strm, 0, sizeof(strm));
89
__func__, s->regs[R_DMA_FLASH_ADDR]);
102
-    strm.workspace = kmalloc(zlib_inflate_workspacesize(), GFP_KERNEL);
90
return;
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));
91
}
338
}
92
+ trace_aspeed_smc_dma_checksum(s->regs[R_DMA_FLASH_ADDR], data);
339
if (result < 0) {
93
340
fprintf(stderr, "Unable to read code+data+bss\n");
94
/*
341
@@ -XXX,XX +XXX,XX @@ static int load_flat_file(struct linux_binprm * bprm,
95
* When the DMA is on-going, the DMA registers are updated
342
96
@@ -XXX,XX +XXX,XX @@ static void aspeed_smc_write(void *opaque, hwaddr addr, uint64_t data,
343
97
344
/****************************************************************************/
98
addr >>= 2;
345
-#ifdef CONFIG_BINFMT_SHARED_FLAT
99
346
-
100
+ trace_aspeed_smc_write(addr, size, data);
347
-/*
101
+
348
- * Load a shared library into memory. The library gets its own data
102
if (addr == s->r_conf ||
349
- * segment (including bss) but not argv/argc/environ.
103
(addr >= s->r_timings &&
350
- */
104
addr < s->r_timings + s->ctrl->nregs_timings) ||
351
-
105
diff --git a/hw/ssi/trace-events b/hw/ssi/trace-events
352
-static int load_flat_shared_library(int id, struct lib_info *libs)
106
new file mode 100644
353
-{
107
index XXXXXXX..XXXXXXX
354
-    struct linux_binprm bprm;
108
--- /dev/null
355
-    int res;
109
+++ b/hw/ssi/trace-events
356
-    char buf[16];
110
@@ -XXX,XX +XXX,XX @@
357
-
111
+# aspeed_smc.c
358
-    /* Create the file name */
112
+
359
-    sprintf(buf, "/lib/lib%d.so", id);
113
+aspeed_smc_flash_set_segment(int cs, uint64_t reg, uint64_t start, uint64_t end) "CS%d segreg=0x%"PRIx64" [ 0x%"PRIx64" - 0x%"PRIx64" ]"
360
-
114
+aspeed_smc_flash_read(int cs, uint64_t addr, uint32_t size, uint64_t data, int mode) "CS%d @0x%" PRIx64 " size %u: 0x%" PRIx64" mode:%d"
361
-    /* Open the file up */
115
+aspeed_smc_do_snoop(int cs, int index, int dummies, int data) "CS%d index:0x%x dummies:%d data:0x%x"
362
-    bprm.filename = buf;
116
+aspeed_smc_flash_write(int cs, uint64_t addr, uint32_t size, uint64_t data, int mode) "CS%d @0x%" PRIx64 " size %u: 0x%" PRIx64" mode:%d"
363
-    bprm.file = open_exec(bprm.filename);
117
+aspeed_smc_read(uint64_t addr, uint32_t size, uint64_t data) "@0x%" PRIx64 " size %u: 0x%" PRIx64
364
-    res = PTR_ERR(bprm.file);
118
+aspeed_smc_dma_checksum(uint32_t addr, uint32_t data) "0x%08x: 0x%08x"
365
-    if (IS_ERR(bprm.file))
119
+aspeed_smc_write(uint64_t addr, uint32_t size, uint64_t data) "@0x%" PRIx64 " size %u: 0x%" PRIx64
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;
120
--
406
--
121
2.20.1
407
2.34.1
122
408
123
409
diff view generated by jsdifflib
1
Some of an M-profile CPU's cached hflags state depends on state that's
1
The npcm7xx_clk and npcm7xx_gcr device reset methods look at
2
in our NVIC object. We already do an hflags rebuild when the NVIC
2
the ResetType argument and only handle RESET_TYPE_COLD,
3
registers are written, but we also need to do this on NVIC reset,
3
producing a warning if another reset type is passed. This
4
because there's no guarantee that this will happen before the
4
is different from how every other three-phase-reset method
5
CPU reset.
5
we have works, and makes it difficult to add new reset types.
6
6
7
This fixes an assertion due to mismatched hflags which happens if
7
A better pattern is "assume that any reset type you don't know
8
the CPU is reset from inside a HardFault handler.
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.
9
12
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
14
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
12
Message-id: 20200303174950.3298-2-peter.maydell@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
13
---
18
---
14
hw/intc/armv7m_nvic.c | 6 ++++++
19
hw/misc/npcm7xx_clk.c | 13 +++----------
15
1 file changed, 6 insertions(+)
20
hw/misc/npcm7xx_gcr.c | 12 ++++--------
21
2 files changed, 7 insertions(+), 18 deletions(-)
16
22
17
diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c
23
diff --git a/hw/misc/npcm7xx_clk.c b/hw/misc/npcm7xx_clk.c
18
index XXXXXXX..XXXXXXX 100644
24
index XXXXXXX..XXXXXXX 100644
19
--- a/hw/intc/armv7m_nvic.c
25
--- a/hw/misc/npcm7xx_clk.c
20
+++ b/hw/intc/armv7m_nvic.c
26
+++ b/hw/misc/npcm7xx_clk.c
21
@@ -XXX,XX +XXX,XX @@ static void armv7m_nvic_reset(DeviceState *dev)
27
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_clk_enter_reset(Object *obj, ResetType type)
22
s->itns[i] = true;
28
23
}
29
QEMU_BUILD_BUG_ON(sizeof(s->regs) != sizeof(cold_reset_values));
24
}
30
25
+
31
- switch (type) {
26
+ /*
32
- case RESET_TYPE_COLD:
27
+ * We updated state that affects the CPU's MMUidx and thus its hflags;
33
- memcpy(s->regs, cold_reset_values, sizeof(cold_reset_values));
28
+ * and we can't guarantee that we run before the CPU reset function.
34
- s->ref_ns = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
29
+ */
35
- npcm7xx_clk_update_all_clocks(s);
30
+ arm_rebuild_hflags(&s->cpu->env);
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);
31
}
48
}
32
49
33
static void nvic_systick_trigger(void *opaque, int n, int level)
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)
34
--
74
--
35
2.20.1
75
2.34.1
36
76
37
77
diff view generated by jsdifflib
1
For M-profile CPUs, the FAULTMASK value affects the CPU's MMU index
1
Rather than directly calling the device's implementation of its 'hold'
2
(it changes the NegPri bit). We update the hflags after calls
2
reset phase, call device_cold_reset(). This means we don't have to
3
to the v7m_msr helper in trans_MSR_v7m() but forgot to do so
3
adjust this callsite when we add another argument to the function
4
in trans_CPS_v7m().
4
signature for the hold and exit reset methods.
5
5
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Message-id: 20200303174950.3298-3-peter.maydell@linaro.org
8
Reviewed-by: Luc Michel <luc.michel@amd.com>
9
Message-id: 20240412160809.1260625-3-peter.maydell@linaro.org
9
---
10
---
10
target/arm/translate.c | 5 ++++-
11
hw/i2c/allwinner-i2c.c | 3 +--
11
1 file changed, 4 insertions(+), 1 deletion(-)
12
hw/sensor/adm1272.c | 2 +-
13
2 files changed, 2 insertions(+), 3 deletions(-)
12
14
13
diff --git a/target/arm/translate.c b/target/arm/translate.c
15
diff --git a/hw/i2c/allwinner-i2c.c b/hw/i2c/allwinner-i2c.c
14
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
15
--- a/target/arm/translate.c
17
--- a/hw/i2c/allwinner-i2c.c
16
+++ b/target/arm/translate.c
18
+++ b/hw/i2c/allwinner-i2c.c
17
@@ -XXX,XX +XXX,XX @@ static bool trans_CPS(DisasContext *s, arg_CPS *a)
19
@@ -XXX,XX +XXX,XX @@ static void allwinner_i2c_write(void *opaque, hwaddr offset,
18
20
break;
19
static bool trans_CPS_v7m(DisasContext *s, arg_CPS_v7m *a)
21
case TWI_SRST_REG:
20
{
22
if (((value & TWI_SRST_MASK) == 0) && (s->srst & TWI_SRST_MASK)) {
21
- TCGv_i32 tmp, addr;
23
- /* Perform reset */
22
+ TCGv_i32 tmp, addr, el;
24
- allwinner_i2c_reset_hold(OBJECT(s));
23
25
+ device_cold_reset(DEVICE(s));
24
if (!arm_dc_feature(s, ARM_FEATURE_M)) {
26
}
25
return false;
27
s->srst = value & TWI_SRST_MASK;
26
@@ -XXX,XX +XXX,XX @@ static bool trans_CPS_v7m(DisasContext *s, arg_CPS_v7m *a)
28
break;
27
gen_helper_v7m_msr(cpu_env, addr, tmp);
29
diff --git a/hw/sensor/adm1272.c b/hw/sensor/adm1272.c
28
tcg_temp_free_i32(addr);
30
index XXXXXXX..XXXXXXX 100644
29
}
31
--- a/hw/sensor/adm1272.c
30
+ el = tcg_const_i32(s->current_el);
32
+++ b/hw/sensor/adm1272.c
31
+ gen_helper_rebuild_hflags_m32(cpu_env, el);
33
@@ -XXX,XX +XXX,XX @@ static int adm1272_write_data(PMBusDevice *pmdev, const uint8_t *buf,
32
+ tcg_temp_free_i32(el);
34
break;
33
tcg_temp_free_i32(tmp);
35
34
gen_lookup_tb(s);
36
case ADM1272_MFR_POWER_CYCLE:
35
return true;
37
- adm1272_exit_reset((Object *)s);
38
+ device_cold_reset(DEVICE(s));
39
break;
40
41
case ADM1272_HYSTERESIS_LOW:
36
--
42
--
37
2.20.1
43
2.34.1
38
39
diff view generated by jsdifflib
1
From: Niek Linnenbank <nieklinnenbank@gmail.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
The Allwinner H3 is a System on Chip containing four ARM Cortex A7
8
This coccinelle script adds the ResetType argument to the hold and
4
processor cores. Features and specifications include DDR2/DDR3 memory,
9
exit phases of the Resettable interface.
5
SD/MMC storage cards, 10/100/1000Mbit Ethernet, USB 2.0, HDMI and
6
various I/O modules. This commit adds support for the Allwinner H3
7
System on Chip.
8
10
9
Signed-off-by: Niek Linnenbank <nieklinnenbank@gmail.com>
11
The first part of the script (rules holdfn_assigned, holdfn_defined,
10
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
12
exitfn_assigned, exitfn_defined) update implementations of the
11
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
13
interface within device models, both to change the signature of their
12
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
14
method implementations and to pass on the reset type when they invoke
13
Message-id: 20200311221854.30370-2-nieklinnenbank@gmail.com
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
14
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
15
---
27
---
16
hw/arm/Makefile.objs | 1 +
28
scripts/coccinelle/reset-type.cocci | 133 ++++++++++++++++++++++++++++
17
include/hw/arm/allwinner-h3.h | 106 +++++++++++
29
1 file changed, 133 insertions(+)
18
hw/arm/allwinner-h3.c | 327 ++++++++++++++++++++++++++++++++
30
create mode 100644 scripts/coccinelle/reset-type.cocci
19
MAINTAINERS | 7 +
20
default-configs/arm-softmmu.mak | 1 +
21
hw/arm/Kconfig | 8 +
22
6 files changed, 450 insertions(+)
23
create mode 100644 include/hw/arm/allwinner-h3.h
24
create mode 100644 hw/arm/allwinner-h3.c
25
31
26
diff --git a/hw/arm/Makefile.objs b/hw/arm/Makefile.objs
32
diff --git a/scripts/coccinelle/reset-type.cocci b/scripts/coccinelle/reset-type.cocci
27
index XXXXXXX..XXXXXXX 100644
28
--- a/hw/arm/Makefile.objs
29
+++ b/hw/arm/Makefile.objs
30
@@ -XXX,XX +XXX,XX @@ obj-$(CONFIG_DIGIC) += digic.o
31
obj-$(CONFIG_OMAP) += omap1.o omap2.o
32
obj-$(CONFIG_STRONGARM) += strongarm.o
33
obj-$(CONFIG_ALLWINNER_A10) += allwinner-a10.o cubieboard.o
34
+obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3.o
35
obj-$(CONFIG_RASPI) += bcm2835_peripherals.o bcm2836.o raspi.o
36
obj-$(CONFIG_STM32F205_SOC) += stm32f205_soc.o
37
obj-$(CONFIG_STM32F405_SOC) += stm32f405_soc.o
38
diff --git a/include/hw/arm/allwinner-h3.h b/include/hw/arm/allwinner-h3.h
39
new file mode 100644
33
new file mode 100644
40
index XXXXXXX..XXXXXXX
34
index XXXXXXX..XXXXXXX
41
--- /dev/null
35
--- /dev/null
42
+++ b/include/hw/arm/allwinner-h3.h
36
+++ b/scripts/coccinelle/reset-type.cocci
43
@@ -XXX,XX +XXX,XX @@
37
@@ -XXX,XX +XXX,XX @@
44
+/*
38
+// Convert device code using three-phase reset to add a ResetType
45
+ * Allwinner H3 System on Chip emulation
39
+// argument to implementations of ResettableHoldPhase and
46
+ *
40
+// ResettableEnterPhase methods.
47
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
41
+//
48
+ *
42
+// Copyright Linaro Ltd 2024
49
+ * This program is free software: you can redistribute it and/or modify
43
+// SPDX-License-Identifier: GPL-2.0-or-later
50
+ * it under the terms of the GNU General Public License as published by
44
+//
51
+ * the Free Software Foundation, either version 2 of the License, or
45
+// for dir in include hw target; do \
52
+ * (at your option) any later version.
46
+// spatch --macro-file scripts/cocci-macro-file.h \
53
+ *
47
+// --sp-file scripts/coccinelle/reset-type.cocci \
54
+ * This program is distributed in the hope that it will be useful,
48
+// --keep-comments --smpl-spacing --in-place --include-headers \
55
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
49
+// --dir $dir; done
56
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
50
+//
57
+ * GNU General Public License for more details.
51
+// This coccinelle script aims to produce a complete change that needs
58
+ *
52
+// no human interaction, so as well as the generic "update device
59
+ * You should have received a copy of the GNU General Public License
53
+// implementations of the hold and exit phase methods" it includes
60
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
54
+// the special-case transformations needed for the core code and for
61
+ */
55
+// one device model that does something a bit nonstandard. Those
56
+// special cases are at the end of the file.
62
+
57
+
63
+/*
58
+// Look for where we use a function as a ResettableHoldPhase method,
64
+ * The Allwinner H3 is a System on Chip containing four ARM Cortex A7
59
+// either by directly assigning it to phases.hold or by calling
65
+ * processor cores. Features and specifications include DDR2/DDR3 memory,
60
+// resettable_class_set_parent_phases, and remember the function name.
66
+ * SD/MMC storage cards, 10/100/1000Mbit Ethernet, USB 2.0, HDMI and
61
+@ holdfn_assigned @
67
+ * various I/O modules.
62
+identifier enterfn, holdfn, exitfn;
68
+ *
63
+identifier rc;
69
+ * This implementation is based on the following datasheet:
64
+expression e;
70
+ *
65
+@@
71
+ * https://linux-sunxi.org/File:Allwinner_H3_Datasheet_V1.2.pdf
66
+ResettableClass *rc;
72
+ *
67
+...
73
+ * The latest datasheet and more info can be found on the Linux Sunxi wiki:
68
+(
74
+ *
69
+ rc->phases.hold = holdfn;
75
+ * https://linux-sunxi.org/H3
70
+|
76
+ */
71
+ resettable_class_set_parent_phases(rc, enterfn, holdfn, exitfn, e);
72
+)
77
+
73
+
78
+#ifndef HW_ARM_ALLWINNER_H3_H
74
+// Look for the definition of the function we found in holdfn_assigned,
79
+#define HW_ARM_ALLWINNER_H3_H
75
+// and add the new argument. If the function calls a hold function
80
+
76
+// itself (probably chaining to the parent class reset) then add the
81
+#include "qom/object.h"
77
+// new argument there too.
82
+#include "hw/arm/boot.h"
78
+@ holdfn_defined @
83
+#include "hw/timer/allwinner-a10-pit.h"
79
+identifier holdfn_assigned.holdfn;
84
+#include "hw/intc/arm_gic.h"
80
+typedef Object;
85
+#include "target/arm/cpu.h"
81
+identifier obj;
86
+
82
+expression parent;
87
+/**
83
+@@
88
+ * Allwinner H3 device list
84
+-holdfn(Object *obj)
89
+ *
85
++holdfn(Object *obj, ResetType type)
90
+ * This enumeration is can be used refer to a particular device in the
91
+ * Allwinner H3 SoC. For example, the physical memory base address for
92
+ * each device can be found in the AwH3State object in the memmap member
93
+ * using the device enum value as index.
94
+ *
95
+ * @see AwH3State
96
+ */
97
+enum {
98
+ AW_H3_SRAM_A1,
99
+ AW_H3_SRAM_A2,
100
+ AW_H3_SRAM_C,
101
+ AW_H3_PIT,
102
+ AW_H3_UART0,
103
+ AW_H3_UART1,
104
+ AW_H3_UART2,
105
+ AW_H3_UART3,
106
+ AW_H3_GIC_DIST,
107
+ AW_H3_GIC_CPU,
108
+ AW_H3_GIC_HYP,
109
+ AW_H3_GIC_VCPU,
110
+ AW_H3_SDRAM
111
+};
112
+
113
+/** Total number of CPU cores in the H3 SoC */
114
+#define AW_H3_NUM_CPUS (4)
115
+
116
+/**
117
+ * Allwinner H3 object model
118
+ * @{
119
+ */
120
+
121
+/** Object type for the Allwinner H3 SoC */
122
+#define TYPE_AW_H3 "allwinner-h3"
123
+
124
+/** Convert input object to Allwinner H3 state object */
125
+#define AW_H3(obj) OBJECT_CHECK(AwH3State, (obj), TYPE_AW_H3)
126
+
127
+/** @} */
128
+
129
+/**
130
+ * Allwinner H3 object
131
+ *
132
+ * This struct contains the state of all the devices
133
+ * which are currently emulated by the H3 SoC code.
134
+ */
135
+typedef struct AwH3State {
136
+ /*< private >*/
137
+ DeviceState parent_obj;
138
+ /*< public >*/
139
+
140
+ ARMCPU cpus[AW_H3_NUM_CPUS];
141
+ const hwaddr *memmap;
142
+ AwA10PITState timer;
143
+ GICState gic;
144
+ MemoryRegion sram_a1;
145
+ MemoryRegion sram_a2;
146
+ MemoryRegion sram_c;
147
+} AwH3State;
148
+
149
+#endif /* HW_ARM_ALLWINNER_H3_H */
150
diff --git a/hw/arm/allwinner-h3.c b/hw/arm/allwinner-h3.c
151
new file mode 100644
152
index XXXXXXX..XXXXXXX
153
--- /dev/null
154
+++ b/hw/arm/allwinner-h3.c
155
@@ -XXX,XX +XXX,XX @@
156
+/*
157
+ * Allwinner H3 System on Chip emulation
158
+ *
159
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
160
+ *
161
+ * This program is free software: you can redistribute it and/or modify
162
+ * it under the terms of the GNU General Public License as published by
163
+ * the Free Software Foundation, either version 2 of the License, or
164
+ * (at your option) any later version.
165
+ *
166
+ * This program is distributed in the hope that it will be useful,
167
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
168
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
169
+ * GNU General Public License for more details.
170
+ *
171
+ * You should have received a copy of the GNU General Public License
172
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
173
+ */
174
+
175
+#include "qemu/osdep.h"
176
+#include "exec/address-spaces.h"
177
+#include "qapi/error.h"
178
+#include "qemu/error-report.h"
179
+#include "qemu/module.h"
180
+#include "qemu/units.h"
181
+#include "hw/qdev-core.h"
182
+#include "cpu.h"
183
+#include "hw/sysbus.h"
184
+#include "hw/char/serial.h"
185
+#include "hw/misc/unimp.h"
186
+#include "sysemu/sysemu.h"
187
+#include "hw/arm/allwinner-h3.h"
188
+
189
+/* Memory map */
190
+const hwaddr allwinner_h3_memmap[] = {
191
+ [AW_H3_SRAM_A1] = 0x00000000,
192
+ [AW_H3_SRAM_A2] = 0x00044000,
193
+ [AW_H3_SRAM_C] = 0x00010000,
194
+ [AW_H3_PIT] = 0x01c20c00,
195
+ [AW_H3_UART0] = 0x01c28000,
196
+ [AW_H3_UART1] = 0x01c28400,
197
+ [AW_H3_UART2] = 0x01c28800,
198
+ [AW_H3_UART3] = 0x01c28c00,
199
+ [AW_H3_GIC_DIST] = 0x01c81000,
200
+ [AW_H3_GIC_CPU] = 0x01c82000,
201
+ [AW_H3_GIC_HYP] = 0x01c84000,
202
+ [AW_H3_GIC_VCPU] = 0x01c86000,
203
+ [AW_H3_SDRAM] = 0x40000000
204
+};
205
+
206
+/* List of unimplemented devices */
207
+struct AwH3Unimplemented {
208
+ const char *device_name;
209
+ hwaddr base;
210
+ hwaddr size;
211
+} unimplemented[] = {
212
+ { "d-engine", 0x01000000, 4 * MiB },
213
+ { "d-inter", 0x01400000, 128 * KiB },
214
+ { "syscon", 0x01c00000, 4 * KiB },
215
+ { "dma", 0x01c02000, 4 * KiB },
216
+ { "nfdc", 0x01c03000, 4 * KiB },
217
+ { "ts", 0x01c06000, 4 * KiB },
218
+ { "keymem", 0x01c0b000, 4 * KiB },
219
+ { "lcd0", 0x01c0c000, 4 * KiB },
220
+ { "lcd1", 0x01c0d000, 4 * KiB },
221
+ { "ve", 0x01c0e000, 4 * KiB },
222
+ { "mmc0", 0x01c0f000, 4 * KiB },
223
+ { "mmc1", 0x01c10000, 4 * KiB },
224
+ { "mmc2", 0x01c11000, 4 * KiB },
225
+ { "sid", 0x01c14000, 1 * KiB },
226
+ { "crypto", 0x01c15000, 4 * KiB },
227
+ { "msgbox", 0x01c17000, 4 * KiB },
228
+ { "spinlock", 0x01c18000, 4 * KiB },
229
+ { "usb0-otg", 0x01c19000, 4 * KiB },
230
+ { "usb0-phy", 0x01c1a000, 4 * KiB },
231
+ { "usb1-phy", 0x01c1b000, 4 * KiB },
232
+ { "usb2-phy", 0x01c1c000, 4 * KiB },
233
+ { "usb3-phy", 0x01c1d000, 4 * KiB },
234
+ { "smc", 0x01c1e000, 4 * KiB },
235
+ { "ccu", 0x01c20000, 1 * KiB },
236
+ { "pio", 0x01c20800, 1 * KiB },
237
+ { "owa", 0x01c21000, 1 * KiB },
238
+ { "pwm", 0x01c21400, 1 * KiB },
239
+ { "keyadc", 0x01c21800, 1 * KiB },
240
+ { "pcm0", 0x01c22000, 1 * KiB },
241
+ { "pcm1", 0x01c22400, 1 * KiB },
242
+ { "pcm2", 0x01c22800, 1 * KiB },
243
+ { "audio", 0x01c22c00, 2 * KiB },
244
+ { "smta", 0x01c23400, 1 * KiB },
245
+ { "ths", 0x01c25000, 1 * KiB },
246
+ { "uart0", 0x01c28000, 1 * KiB },
247
+ { "uart1", 0x01c28400, 1 * KiB },
248
+ { "uart2", 0x01c28800, 1 * KiB },
249
+ { "uart3", 0x01c28c00, 1 * KiB },
250
+ { "twi0", 0x01c2ac00, 1 * KiB },
251
+ { "twi1", 0x01c2b000, 1 * KiB },
252
+ { "twi2", 0x01c2b400, 1 * KiB },
253
+ { "scr", 0x01c2c400, 1 * KiB },
254
+ { "emac", 0x01c30000, 64 * KiB },
255
+ { "gpu", 0x01c40000, 64 * KiB },
256
+ { "hstmr", 0x01c60000, 4 * KiB },
257
+ { "dramcom", 0x01c62000, 4 * KiB },
258
+ { "dramctl0", 0x01c63000, 4 * KiB },
259
+ { "dramphy0", 0x01c65000, 4 * KiB },
260
+ { "spi0", 0x01c68000, 4 * KiB },
261
+ { "spi1", 0x01c69000, 4 * KiB },
262
+ { "csi", 0x01cb0000, 320 * KiB },
263
+ { "tve", 0x01e00000, 64 * KiB },
264
+ { "hdmi", 0x01ee0000, 128 * KiB },
265
+ { "rtc", 0x01f00000, 1 * KiB },
266
+ { "r_timer", 0x01f00800, 1 * KiB },
267
+ { "r_intc", 0x01f00c00, 1 * KiB },
268
+ { "r_wdog", 0x01f01000, 1 * KiB },
269
+ { "r_prcm", 0x01f01400, 1 * KiB },
270
+ { "r_twd", 0x01f01800, 1 * KiB },
271
+ { "r_cpucfg", 0x01f01c00, 1 * KiB },
272
+ { "r_cir-rx", 0x01f02000, 1 * KiB },
273
+ { "r_twi", 0x01f02400, 1 * KiB },
274
+ { "r_uart", 0x01f02800, 1 * KiB },
275
+ { "r_pio", 0x01f02c00, 1 * KiB },
276
+ { "r_pwm", 0x01f03800, 1 * KiB },
277
+ { "core-dbg", 0x3f500000, 128 * KiB },
278
+ { "tsgen-ro", 0x3f506000, 4 * KiB },
279
+ { "tsgen-ctl", 0x3f507000, 4 * KiB },
280
+ { "ddr-mem", 0x40000000, 2 * GiB },
281
+ { "n-brom", 0xffff0000, 32 * KiB },
282
+ { "s-brom", 0xffff0000, 64 * KiB }
283
+};
284
+
285
+/* Per Processor Interrupts */
286
+enum {
287
+ AW_H3_GIC_PPI_MAINT = 9,
288
+ AW_H3_GIC_PPI_HYPTIMER = 10,
289
+ AW_H3_GIC_PPI_VIRTTIMER = 11,
290
+ AW_H3_GIC_PPI_SECTIMER = 13,
291
+ AW_H3_GIC_PPI_PHYSTIMER = 14
292
+};
293
+
294
+/* Shared Processor Interrupts */
295
+enum {
296
+ AW_H3_GIC_SPI_UART0 = 0,
297
+ AW_H3_GIC_SPI_UART1 = 1,
298
+ AW_H3_GIC_SPI_UART2 = 2,
299
+ AW_H3_GIC_SPI_UART3 = 3,
300
+ AW_H3_GIC_SPI_TIMER0 = 18,
301
+ AW_H3_GIC_SPI_TIMER1 = 19,
302
+};
303
+
304
+/* Allwinner H3 general constants */
305
+enum {
306
+ AW_H3_GIC_NUM_SPI = 128
307
+};
308
+
309
+static void allwinner_h3_init(Object *obj)
310
+{
86
+{
311
+ AwH3State *s = AW_H3(obj);
87
+ <...
312
+
88
+- parent.hold(obj)
313
+ s->memmap = allwinner_h3_memmap;
89
++ parent.hold(obj, type)
314
+
90
+ ...>
315
+ for (int i = 0; i < AW_H3_NUM_CPUS; i++) {
316
+ object_initialize_child(obj, "cpu[*]", &s->cpus[i], sizeof(s->cpus[i]),
317
+ ARM_CPU_TYPE_NAME("cortex-a7"),
318
+ &error_abort, NULL);
319
+ }
320
+
321
+ sysbus_init_child_obj(obj, "gic", &s->gic, sizeof(s->gic),
322
+ TYPE_ARM_GIC);
323
+
324
+ sysbus_init_child_obj(obj, "timer", &s->timer, sizeof(s->timer),
325
+ TYPE_AW_A10_PIT);
326
+ object_property_add_alias(obj, "clk0-freq", OBJECT(&s->timer),
327
+ "clk0-freq", &error_abort);
328
+ object_property_add_alias(obj, "clk1-freq", OBJECT(&s->timer),
329
+ "clk1-freq", &error_abort);
330
+}
91
+}
331
+
92
+
332
+static void allwinner_h3_realize(DeviceState *dev, Error **errp)
93
+// Similarly for ResettableExitPhase.
94
+@ exitfn_assigned @
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)
333
+{
114
+{
334
+ AwH3State *s = AW_H3(dev);
115
+ <...
335
+ unsigned i;
116
+- parent.exit(obj)
336
+
117
++ parent.exit(obj, type)
337
+ /* CPUs */
118
+ ...>
338
+ for (i = 0; i < AW_H3_NUM_CPUS; i++) {
339
+
340
+ /* Provide Power State Coordination Interface */
341
+ qdev_prop_set_int32(DEVICE(&s->cpus[i]), "psci-conduit",
342
+ QEMU_PSCI_CONDUIT_HVC);
343
+
344
+ /* Disable secondary CPUs */
345
+ qdev_prop_set_bit(DEVICE(&s->cpus[i]), "start-powered-off",
346
+ i > 0);
347
+
348
+ /* All exception levels required */
349
+ qdev_prop_set_bit(DEVICE(&s->cpus[i]), "has_el3", true);
350
+ qdev_prop_set_bit(DEVICE(&s->cpus[i]), "has_el2", true);
351
+
352
+ /* Mark realized */
353
+ qdev_init_nofail(DEVICE(&s->cpus[i]));
354
+ }
355
+
356
+ /* Generic Interrupt Controller */
357
+ qdev_prop_set_uint32(DEVICE(&s->gic), "num-irq", AW_H3_GIC_NUM_SPI +
358
+ GIC_INTERNAL);
359
+ qdev_prop_set_uint32(DEVICE(&s->gic), "revision", 2);
360
+ qdev_prop_set_uint32(DEVICE(&s->gic), "num-cpu", AW_H3_NUM_CPUS);
361
+ qdev_prop_set_bit(DEVICE(&s->gic), "has-security-extensions", false);
362
+ qdev_prop_set_bit(DEVICE(&s->gic), "has-virtualization-extensions", true);
363
+ qdev_init_nofail(DEVICE(&s->gic));
364
+
365
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->gic), 0, s->memmap[AW_H3_GIC_DIST]);
366
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->gic), 1, s->memmap[AW_H3_GIC_CPU]);
367
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->gic), 2, s->memmap[AW_H3_GIC_HYP]);
368
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->gic), 3, s->memmap[AW_H3_GIC_VCPU]);
369
+
370
+ /*
371
+ * Wire the outputs from each CPU's generic timer and the GICv3
372
+ * maintenance interrupt signal to the appropriate GIC PPI inputs,
373
+ * and the GIC's IRQ/FIQ/VIRQ/VFIQ interrupt outputs to the CPU's inputs.
374
+ */
375
+ for (i = 0; i < AW_H3_NUM_CPUS; i++) {
376
+ DeviceState *cpudev = DEVICE(&s->cpus[i]);
377
+ int ppibase = AW_H3_GIC_NUM_SPI + i * GIC_INTERNAL + GIC_NR_SGIS;
378
+ int irq;
379
+ /*
380
+ * Mapping from the output timer irq lines from the CPU to the
381
+ * GIC PPI inputs used for this board.
382
+ */
383
+ const int timer_irq[] = {
384
+ [GTIMER_PHYS] = AW_H3_GIC_PPI_PHYSTIMER,
385
+ [GTIMER_VIRT] = AW_H3_GIC_PPI_VIRTTIMER,
386
+ [GTIMER_HYP] = AW_H3_GIC_PPI_HYPTIMER,
387
+ [GTIMER_SEC] = AW_H3_GIC_PPI_SECTIMER,
388
+ };
389
+
390
+ /* Connect CPU timer outputs to GIC PPI inputs */
391
+ for (irq = 0; irq < ARRAY_SIZE(timer_irq); irq++) {
392
+ qdev_connect_gpio_out(cpudev, irq,
393
+ qdev_get_gpio_in(DEVICE(&s->gic),
394
+ ppibase + timer_irq[irq]));
395
+ }
396
+
397
+ /* Connect GIC outputs to CPU interrupt inputs */
398
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->gic), i,
399
+ qdev_get_gpio_in(cpudev, ARM_CPU_IRQ));
400
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->gic), i + AW_H3_NUM_CPUS,
401
+ qdev_get_gpio_in(cpudev, ARM_CPU_FIQ));
402
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->gic), i + (2 * AW_H3_NUM_CPUS),
403
+ qdev_get_gpio_in(cpudev, ARM_CPU_VIRQ));
404
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->gic), i + (3 * AW_H3_NUM_CPUS),
405
+ qdev_get_gpio_in(cpudev, ARM_CPU_VFIQ));
406
+
407
+ /* GIC maintenance signal */
408
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->gic), i + (4 * AW_H3_NUM_CPUS),
409
+ qdev_get_gpio_in(DEVICE(&s->gic),
410
+ ppibase + AW_H3_GIC_PPI_MAINT));
411
+ }
412
+
413
+ /* Timer */
414
+ qdev_init_nofail(DEVICE(&s->timer));
415
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->timer), 0, s->memmap[AW_H3_PIT]);
416
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->timer), 0,
417
+ qdev_get_gpio_in(DEVICE(&s->gic), AW_H3_GIC_SPI_TIMER0));
418
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->timer), 1,
419
+ qdev_get_gpio_in(DEVICE(&s->gic), AW_H3_GIC_SPI_TIMER1));
420
+
421
+ /* SRAM */
422
+ memory_region_init_ram(&s->sram_a1, OBJECT(dev), "sram A1",
423
+ 64 * KiB, &error_abort);
424
+ memory_region_init_ram(&s->sram_a2, OBJECT(dev), "sram A2",
425
+ 32 * KiB, &error_abort);
426
+ memory_region_init_ram(&s->sram_c, OBJECT(dev), "sram C",
427
+ 44 * KiB, &error_abort);
428
+ memory_region_add_subregion(get_system_memory(), s->memmap[AW_H3_SRAM_A1],
429
+ &s->sram_a1);
430
+ memory_region_add_subregion(get_system_memory(), s->memmap[AW_H3_SRAM_A2],
431
+ &s->sram_a2);
432
+ memory_region_add_subregion(get_system_memory(), s->memmap[AW_H3_SRAM_C],
433
+ &s->sram_c);
434
+
435
+ /* UART0. For future clocktree API: All UARTS are connected to APB2_CLK. */
436
+ serial_mm_init(get_system_memory(), s->memmap[AW_H3_UART0], 2,
437
+ qdev_get_gpio_in(DEVICE(&s->gic), AW_H3_GIC_SPI_UART0),
438
+ 115200, serial_hd(0), DEVICE_NATIVE_ENDIAN);
439
+ /* UART1 */
440
+ serial_mm_init(get_system_memory(), s->memmap[AW_H3_UART1], 2,
441
+ qdev_get_gpio_in(DEVICE(&s->gic), AW_H3_GIC_SPI_UART1),
442
+ 115200, serial_hd(1), DEVICE_NATIVE_ENDIAN);
443
+ /* UART2 */
444
+ serial_mm_init(get_system_memory(), s->memmap[AW_H3_UART2], 2,
445
+ qdev_get_gpio_in(DEVICE(&s->gic), AW_H3_GIC_SPI_UART2),
446
+ 115200, serial_hd(2), DEVICE_NATIVE_ENDIAN);
447
+ /* UART3 */
448
+ serial_mm_init(get_system_memory(), s->memmap[AW_H3_UART3], 2,
449
+ qdev_get_gpio_in(DEVICE(&s->gic), AW_H3_GIC_SPI_UART3),
450
+ 115200, serial_hd(3), DEVICE_NATIVE_ENDIAN);
451
+
452
+ /* Unimplemented devices */
453
+ for (i = 0; i < ARRAY_SIZE(unimplemented); i++) {
454
+ create_unimplemented_device(unimplemented[i].device_name,
455
+ unimplemented[i].base,
456
+ unimplemented[i].size);
457
+ }
458
+}
119
+}
459
+
120
+
460
+static void allwinner_h3_class_init(ObjectClass *oc, void *data)
121
+// SPECIAL CASES ONLY BELOW HERE
461
+{
122
+// We use a python scripted constraint on the position of the match
462
+ DeviceClass *dc = DEVICE_CLASS(oc);
123
+// to ensure that they only match in a particular function. See
124
+// https://public-inbox.org/git/alpine.DEB.2.21.1808240652370.2344@hadrien/
125
+// which recommends this as the way to do "match only in this function".
463
+
126
+
464
+ dc->realize = allwinner_h3_realize;
127
+// Special case: isl_pmbus_vr.c has some reset methods calling others directly
465
+ /* Reason: uses serial_hd() in realize function */
128
+@ isl_pmbus_vr @
466
+ dc->user_creatable = false;
129
+identifier obj;
467
+}
130
+@@
131
+- isl_pmbus_vr_exit_reset(obj);
132
++ isl_pmbus_vr_exit_reset(obj, type);
468
+
133
+
469
+static const TypeInfo allwinner_h3_type_info = {
134
+// Special case: device_phases_reset() needs to pass RESET_TYPE_COLD
470
+ .name = TYPE_AW_H3,
135
+@ device_phases_reset_hold @
471
+ .parent = TYPE_DEVICE,
136
+expression obj;
472
+ .instance_size = sizeof(AwH3State),
137
+identifier rc;
473
+ .instance_init = allwinner_h3_init,
138
+identifier phase;
474
+ .class_init = allwinner_h3_class_init,
139
+position p : script:python() { p[0].current_element == "device_phases_reset" };
475
+};
140
+@@
141
+- rc->phases.phase(obj)@p
142
++ rc->phases.phase(obj, RESET_TYPE_COLD)
476
+
143
+
477
+static void allwinner_h3_register_types(void)
144
+// Special case: in resettable_phase_hold() and resettable_phase_exit()
478
+{
145
+// we need to pass through the ResetType argument to the method being called
479
+ type_register_static(&allwinner_h3_type_info);
146
+@ resettable_phase_hold @
480
+}
147
+expression obj;
481
+
148
+identifier rc;
482
+type_init(allwinner_h3_register_types)
149
+position p : script:python() { p[0].current_element == "resettable_phase_hold" };
483
diff --git a/MAINTAINERS b/MAINTAINERS
150
+@@
484
index XXXXXXX..XXXXXXX 100644
151
+- rc->phases.hold(obj)@p
485
--- a/MAINTAINERS
152
++ rc->phases.hold(obj, type)
486
+++ b/MAINTAINERS
153
+@ resettable_phase_exit @
487
@@ -XXX,XX +XXX,XX @@ F: hw/*/allwinner*
154
+expression obj;
488
F: include/hw/*/allwinner*
155
+identifier rc;
489
F: hw/arm/cubieboard.c
156
+position p : script:python() { p[0].current_element == "resettable_phase_exit" };
490
157
+@@
491
+Allwinner-h3
158
+- rc->phases.exit(obj)@p
492
+M: Niek Linnenbank <nieklinnenbank@gmail.com>
159
++ rc->phases.exit(obj, type)
493
+L: qemu-arm@nongnu.org
160
+// Special case: the typedefs for the methods need to declare the new argument
494
+S: Maintained
161
+@ phase_typedef_hold @
495
+F: hw/*/allwinner-h3*
162
+identifier obj;
496
+F: include/hw/*/allwinner-h3*
163
+@@
497
+
164
+- typedef void (*ResettableHoldPhase)(Object *obj);
498
ARM PrimeCell and CMSDK devices
165
++ typedef void (*ResettableHoldPhase)(Object *obj, ResetType type);
499
M: Peter Maydell <peter.maydell@linaro.org>
166
+@ phase_typedef_exit @
500
L: qemu-arm@nongnu.org
167
+identifier obj;
501
diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
168
+@@
502
index XXXXXXX..XXXXXXX 100644
169
+- typedef void (*ResettableExitPhase)(Object *obj);
503
--- a/default-configs/arm-softmmu.mak
170
++ typedef void (*ResettableExitPhase)(Object *obj, ResetType type);
504
+++ b/default-configs/arm-softmmu.mak
505
@@ -XXX,XX +XXX,XX @@ CONFIG_FSL_IMX25=y
506
CONFIG_FSL_IMX7=y
507
CONFIG_FSL_IMX6UL=y
508
CONFIG_SEMIHOSTING=y
509
+CONFIG_ALLWINNER_H3=y
510
diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
511
index XXXXXXX..XXXXXXX 100644
512
--- a/hw/arm/Kconfig
513
+++ b/hw/arm/Kconfig
514
@@ -XXX,XX +XXX,XX @@ config ALLWINNER_A10
515
select SERIAL
516
select UNIMP
517
518
+config ALLWINNER_H3
519
+ bool
520
+ select ALLWINNER_A10_PIT
521
+ select SERIAL
522
+ select ARM_TIMER
523
+ select ARM_GIC
524
+ select UNIMP
525
+
526
config RASPI
527
bool
528
select FRAMEBUFFER
529
--
171
--
530
2.20.1
172
2.34.1
531
532
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
From: Eric Auger <eric.auger@redhat.com>
1
Update the reset documentation's example code to match the new API
2
for the hold and exit phase method APIs where they take a ResetType
3
argument.
2
4
3
We plan to introduce yet another value for the gic version (nosel).
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
4
As we already use exotic values such as 0 and -1, let's introduce
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
5
a dedicated enum type and let vms->gic_version take this
7
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
6
type.
8
Reviewed-by: Luc Michel <luc.michel@amd.com>
9
Message-id: 20240412160809.1260625-6-peter.maydell@linaro.org
10
---
11
docs/devel/reset.rst | 8 ++++----
12
1 file changed, 4 insertions(+), 4 deletions(-)
7
13
8
Signed-off-by: Eric Auger <eric.auger@redhat.com>
14
diff --git a/docs/devel/reset.rst b/docs/devel/reset.rst
9
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
10
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
11
Reviewed-by: Andrew Jones <drjones@redhat.com>
12
Message-id: 20200311131618.7187-3-eric.auger@redhat.com
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
14
---
15
include/hw/arm/virt.h | 11 +++++++++--
16
hw/arm/virt.c | 30 +++++++++++++++---------------
17
2 files changed, 24 insertions(+), 17 deletions(-)
18
19
diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h
20
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
21
--- a/include/hw/arm/virt.h
16
--- a/docs/devel/reset.rst
22
+++ b/include/hw/arm/virt.h
17
+++ b/docs/devel/reset.rst
23
@@ -XXX,XX +XXX,XX @@ typedef enum VirtIOMMUType {
18
@@ -XXX,XX +XXX,XX @@ in reset.
24
VIRT_IOMMU_VIRTIO,
19
mydev->var = 0;
25
} VirtIOMMUType;
26
27
+typedef enum VirtGICType {
28
+ VIRT_GIC_VERSION_MAX,
29
+ VIRT_GIC_VERSION_HOST,
30
+ VIRT_GIC_VERSION_2,
31
+ VIRT_GIC_VERSION_3,
32
+} VirtGICType;
33
+
34
typedef struct MemMapEntry {
35
hwaddr base;
36
hwaddr size;
37
@@ -XXX,XX +XXX,XX @@ typedef struct {
38
bool highmem_ecam;
39
bool its;
40
bool virt;
41
- int32_t gic_version;
42
+ VirtGICType gic_version;
43
VirtIOMMUType iommu;
44
uint16_t virtio_iommu_bdf;
45
struct arm_boot_info bootinfo;
46
@@ -XXX,XX +XXX,XX @@ static inline int virt_gicv3_redist_region_count(VirtMachineState *vms)
47
uint32_t redist0_capacity =
48
vms->memmap[VIRT_GIC_REDIST].size / GICV3_REDIST_SIZE;
49
50
- assert(vms->gic_version == 3);
51
+ assert(vms->gic_version == VIRT_GIC_VERSION_3);
52
53
return vms->smp_cpus > redist0_capacity ? 2 : 1;
54
}
55
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
56
index XXXXXXX..XXXXXXX 100644
57
--- a/hw/arm/virt.c
58
+++ b/hw/arm/virt.c
59
@@ -XXX,XX +XXX,XX @@ static void fdt_add_timer_nodes(const VirtMachineState *vms)
60
irqflags = GIC_FDT_IRQ_FLAGS_EDGE_LO_HI;
61
}
20
}
62
21
63
- if (vms->gic_version == 2) {
22
- static void mydev_reset_hold(Object *obj)
64
+ if (vms->gic_version == VIRT_GIC_VERSION_2) {
23
+ static void mydev_reset_hold(Object *obj, ResetType type)
65
irqflags = deposit32(irqflags, GIC_FDT_IRQ_PPI_CPU_START,
24
{
66
GIC_FDT_IRQ_PPI_CPU_WIDTH,
25
MyDevClass *myclass = MYDEV_GET_CLASS(obj);
67
(1 << vms->smp_cpus) - 1);
26
MyDevState *mydev = MYDEV(obj);
68
@@ -XXX,XX +XXX,XX @@ static void fdt_add_gic_node(VirtMachineState *vms)
27
/* call parent class hold phase */
69
qemu_fdt_setprop_cell(vms->fdt, nodename, "#address-cells", 0x2);
28
if (myclass->parent_phases.hold) {
70
qemu_fdt_setprop_cell(vms->fdt, nodename, "#size-cells", 0x2);
29
- myclass->parent_phases.hold(obj);
71
qemu_fdt_setprop(vms->fdt, nodename, "ranges", NULL, 0);
30
+ myclass->parent_phases.hold(obj, type);
72
- if (vms->gic_version == 3) {
73
+ if (vms->gic_version == VIRT_GIC_VERSION_3) {
74
int nb_redist_regions = virt_gicv3_redist_region_count(vms);
75
76
qemu_fdt_setprop_string(vms->fdt, nodename, "compatible",
77
@@ -XXX,XX +XXX,XX @@ static void fdt_add_pmu_nodes(const VirtMachineState *vms)
78
}
31
}
32
/* set an IO */
33
qemu_set_irq(mydev->irq, 1);
79
}
34
}
80
35
81
- if (vms->gic_version == 2) {
36
- static void mydev_reset_exit(Object *obj)
82
+ if (vms->gic_version == VIRT_GIC_VERSION_2) {
37
+ static void mydev_reset_exit(Object *obj, ResetType type)
83
irqflags = deposit32(irqflags, GIC_FDT_IRQ_PPI_CPU_START,
38
{
84
GIC_FDT_IRQ_PPI_CPU_WIDTH,
39
MyDevClass *myclass = MYDEV_GET_CLASS(obj);
85
(1 << vms->smp_cpus) - 1);
40
MyDevState *mydev = MYDEV(obj);
86
@@ -XXX,XX +XXX,XX @@ static uint64_t virt_cpu_mp_affinity(VirtMachineState *vms, int idx)
41
/* call parent class exit phase */
87
* purposes are to make TCG consistent (with 64-bit KVM hosts)
42
if (myclass->parent_phases.exit) {
88
* and to improve SGI efficiency.
43
- myclass->parent_phases.exit(obj);
89
*/
44
+ myclass->parent_phases.exit(obj, type);
90
- if (vms->gic_version == 3) {
45
}
91
+ if (vms->gic_version == VIRT_GIC_VERSION_3) {
46
/* clear an IO */
92
clustersz = GICV3_TARGETLIST_BITS;
47
qemu_set_irq(mydev->irq, 0);
93
} else {
94
clustersz = GIC_TARGETLIST_BITS;
95
@@ -XXX,XX +XXX,XX @@ static void machvirt_init(MachineState *machine)
96
/* We can probe only here because during property set
97
* KVM is not available yet
98
*/
99
- if (vms->gic_version <= 0) {
100
- /* "host" or "max" */
101
+ if (vms->gic_version == VIRT_GIC_VERSION_HOST ||
102
+ vms->gic_version == VIRT_GIC_VERSION_MAX) {
103
if (!kvm_enabled()) {
104
- if (vms->gic_version == 0) {
105
+ if (vms->gic_version == VIRT_GIC_VERSION_HOST) {
106
error_report("gic-version=host requires KVM");
107
exit(1);
108
} else {
109
/* "max": currently means 3 for TCG */
110
- vms->gic_version = 3;
111
+ vms->gic_version = VIRT_GIC_VERSION_3;
112
}
113
} else {
114
vms->gic_version = kvm_arm_vgic_probe();
115
@@ -XXX,XX +XXX,XX @@ static void machvirt_init(MachineState *machine)
116
/* The maximum number of CPUs depends on the GIC version, or on how
117
* many redistributors we can fit into the memory map.
118
*/
119
- if (vms->gic_version == 3) {
120
+ if (vms->gic_version == VIRT_GIC_VERSION_3) {
121
virt_max_cpus =
122
vms->memmap[VIRT_GIC_REDIST].size / GICV3_REDIST_SIZE;
123
virt_max_cpus +=
124
@@ -XXX,XX +XXX,XX @@ static void virt_set_its(Object *obj, bool value, Error **errp)
125
static char *virt_get_gic_version(Object *obj, Error **errp)
126
{
127
VirtMachineState *vms = VIRT_MACHINE(obj);
128
- const char *val = vms->gic_version == 3 ? "3" : "2";
129
+ const char *val = vms->gic_version == VIRT_GIC_VERSION_3 ? "3" : "2";
130
131
return g_strdup(val);
132
}
133
@@ -XXX,XX +XXX,XX @@ static void virt_set_gic_version(Object *obj, const char *value, Error **errp)
134
VirtMachineState *vms = VIRT_MACHINE(obj);
135
136
if (!strcmp(value, "3")) {
137
- vms->gic_version = 3;
138
+ vms->gic_version = VIRT_GIC_VERSION_3;
139
} else if (!strcmp(value, "2")) {
140
- vms->gic_version = 2;
141
+ vms->gic_version = VIRT_GIC_VERSION_2;
142
} else if (!strcmp(value, "host")) {
143
- vms->gic_version = 0; /* Will probe later */
144
+ vms->gic_version = VIRT_GIC_VERSION_HOST; /* Will probe later */
145
} else if (!strcmp(value, "max")) {
146
- vms->gic_version = -1; /* Will probe later */
147
+ vms->gic_version = VIRT_GIC_VERSION_MAX; /* Will probe later */
148
} else {
149
error_setg(errp, "Invalid gic-version value");
150
error_append_hint(errp, "Valid values are 3, 2, host, max.\n");
151
@@ -XXX,XX +XXX,XX @@ static void virt_instance_init(Object *obj)
152
"physical address space above 32 bits",
153
NULL);
154
/* Default GIC type is v2 */
155
- vms->gic_version = 2;
156
+ vms->gic_version = VIRT_GIC_VERSION_2;
157
object_property_add_str(obj, "gic-version", virt_get_gic_version,
158
virt_set_gic_version, NULL);
159
object_property_set_description(obj, "gic-version",
160
--
48
--
161
2.20.1
49
2.34.1
162
50
163
51
diff view generated by jsdifflib
1
A write to the CONTROL register can change our current EL (by
1
Some devices and machines need to handle the reset before a vmsave
2
writing to the nPRIV bit). That means that we can't assume
2
snapshot is loaded differently -- the main user is the handling of
3
that s->current_el is still valid in trans_MSR_v7m() when
3
RNG seed information, which does not want to put a new RNG seed into
4
we try to rebuild the hflags.
4
a ROM blob when we are doing a snapshot load.
5
5
6
Add a new helper rebuild_hflags_m32_newel() which, like the
6
Currently this kind of reset handling is supported only for:
7
existing rebuild_hflags_a32_newel(), recalculates the current
7
* TYPE_MACHINE reset methods, which take a ShutdownCause argument
8
EL from scratch, and use it in trans_MSR_v7m().
8
* reset functions registered with qemu_register_reset_nosnapshotload
9
9
10
This fixes an assertion about an hflags mismatch when the
10
To allow a three-phase-reset device to also distinguish "snapshot
11
guest changes privilege by writing to CONTROL.
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().
12
19
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
20
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
14
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
21
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
15
Message-id: 20200303174950.3298-4-peter.maydell@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
16
---
25
---
17
target/arm/helper.h | 1 +
26
docs/devel/reset.rst | 17 ++++++++++++++---
18
target/arm/helper.c | 12 ++++++++++++
27
include/hw/resettable.h | 1 +
19
target/arm/translate.c | 7 +++----
28
hw/core/reset.c | 15 ++++-----------
20
3 files changed, 16 insertions(+), 4 deletions(-)
29
hw/core/resettable.c | 4 ----
30
4 files changed, 19 insertions(+), 18 deletions(-)
21
31
22
diff --git a/target/arm/helper.h b/target/arm/helper.h
32
diff --git a/docs/devel/reset.rst b/docs/devel/reset.rst
23
index XXXXXXX..XXXXXXX 100644
33
index XXXXXXX..XXXXXXX 100644
24
--- a/target/arm/helper.h
34
--- a/docs/devel/reset.rst
25
+++ b/target/arm/helper.h
35
+++ b/docs/devel/reset.rst
26
@@ -XXX,XX +XXX,XX @@ DEF_HELPER_4(msr_banked, void, env, i32, i32, i32)
36
@@ -XXX,XX +XXX,XX @@ instantly reset an object, without keeping it in reset state, just call
27
DEF_HELPER_2(get_user_reg, i32, env, i32)
37
``resettable_reset()``. These functions take two parameters: a pointer to the
28
DEF_HELPER_3(set_user_reg, void, env, i32, i32)
38
object to reset and a reset type.
29
39
30
+DEF_HELPER_FLAGS_1(rebuild_hflags_m32_newel, TCG_CALL_NO_RWG, void, env)
40
-Several types of reset will be supported. For now only cold reset is defined;
31
DEF_HELPER_FLAGS_2(rebuild_hflags_m32, TCG_CALL_NO_RWG, void, env, int)
41
-others may be added later. The Resettable interface handles reset types with an
32
DEF_HELPER_FLAGS_1(rebuild_hflags_a32_newel, TCG_CALL_NO_RWG, void, env)
42
-enum:
33
DEF_HELPER_FLAGS_2(rebuild_hflags_a32, TCG_CALL_NO_RWG, void, env, int)
43
+The Resettable interface handles reset types with an enum ``ResetType``:
34
diff --git a/target/arm/helper.c b/target/arm/helper.c
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
35
index XXXXXXX..XXXXXXX 100644
68
index XXXXXXX..XXXXXXX 100644
36
--- a/target/arm/helper.c
69
--- a/include/hw/resettable.h
37
+++ b/target/arm/helper.c
70
+++ b/include/hw/resettable.h
38
@@ -XXX,XX +XXX,XX @@ void arm_rebuild_hflags(CPUARMState *env)
71
@@ -XXX,XX +XXX,XX @@ typedef struct ResettableState ResettableState;
39
env->hflags = rebuild_hflags_internal(env);
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;
40
}
85
}
41
86
42
+/*
87
-/*
43
+ * If we have triggered a EL state change we can't rely on the
88
- * Reason why the currently in-progress qemu_devices_reset() was called.
44
+ * translator having passed it to us, we need to recompute.
89
- * If we made at least SHUTDOWN_CAUSE_SNAPSHOT_LOAD have a corresponding
45
+ */
90
- * ResetType we could perhaps avoid the need for this global.
46
+void HELPER(rebuild_hflags_m32_newel)(CPUARMState *env)
91
- */
47
+{
92
-static ShutdownCause device_reset_reason;
48
+ int el = arm_current_el(env);
93
-
49
+ int fp_el = fp_exception_el(env, el);
94
/*
50
+ ARMMMUIdx mmu_idx = arm_mmu_idx_el(env, el);
95
* This is an Object which implements Resettable simply to call the
51
+ env->hflags = rebuild_hflags_m32(env, fp_el, mmu_idx);
96
* callback function in the hold phase.
52
+}
97
@@ -XXX,XX +XXX,XX @@ static void legacy_reset_hold(Object *obj, ResetType type)
53
+
54
void HELPER(rebuild_hflags_m32)(CPUARMState *env, int el)
55
{
98
{
56
int fp_el = fp_exception_el(env, el);
99
LegacyReset *lr = LEGACY_RESET(obj);
57
diff --git a/target/arm/translate.c b/target/arm/translate.c
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
58
index XXXXXXX..XXXXXXX 100644
120
index XXXXXXX..XXXXXXX 100644
59
--- a/target/arm/translate.c
121
--- a/hw/core/resettable.c
60
+++ b/target/arm/translate.c
122
+++ b/hw/core/resettable.c
61
@@ -XXX,XX +XXX,XX @@ static bool trans_MRS_v7m(DisasContext *s, arg_MRS_v7m *a)
123
@@ -XXX,XX +XXX,XX @@ void resettable_reset(Object *obj, ResetType type)
62
124
63
static bool trans_MSR_v7m(DisasContext *s, arg_MSR_v7m *a)
125
void resettable_assert_reset(Object *obj, ResetType type)
64
{
126
{
65
- TCGv_i32 addr, reg, el;
127
- /* TODO: change this assert when adding support for other reset types */
66
+ TCGv_i32 addr, reg;
128
- assert(type == RESET_TYPE_COLD);
67
129
trace_resettable_reset_assert_begin(obj, type);
68
if (!arm_dc_feature(s, ARM_FEATURE_M)) {
130
assert(!enter_phase_in_progress);
69
return false;
131
70
@@ -XXX,XX +XXX,XX @@ static bool trans_MSR_v7m(DisasContext *s, arg_MSR_v7m *a)
132
@@ -XXX,XX +XXX,XX @@ void resettable_assert_reset(Object *obj, ResetType type)
71
gen_helper_v7m_msr(cpu_env, addr, reg);
133
72
tcg_temp_free_i32(addr);
134
void resettable_release_reset(Object *obj, ResetType type)
73
tcg_temp_free_i32(reg);
135
{
74
- el = tcg_const_i32(s->current_el);
136
- /* TODO: change this assert when adding support for other reset types */
75
- gen_helper_rebuild_hflags_m32(cpu_env, el);
137
- assert(type == RESET_TYPE_COLD);
76
- tcg_temp_free_i32(el);
138
trace_resettable_reset_release_begin(obj, type);
77
+ /* If we wrote to CONTROL, the EL might have changed */
139
assert(!enter_phase_in_progress);
78
+ gen_helper_rebuild_hflags_m32_newel(cpu_env);
140
79
gen_lookup_tb(s);
80
return true;
81
}
82
--
141
--
83
2.20.1
142
2.34.1
84
143
85
144
diff view generated by jsdifflib
1
From: Niek Linnenbank <nieklinnenbank@gmail.com>
1
From: Arnaud Minier <arnaud.minier@telecom-paris.fr>
2
2
3
The Security Identifier device found in various Allwinner System on Chip
3
Add the basic infrastructure (register read/write, type...)
4
designs gives applications a per-board unique identifier. This commit
4
to implement the STM32L4x5 USART.
5
adds support for the Allwinner Security Identifier using a 128-bit
6
UUID value as input.
7
5
8
Signed-off-by: Niek Linnenbank <nieklinnenbank@gmail.com>
6
Also create different types for the USART, UART and LPUART
9
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
7
of the STM32L4x5 to deduplicate code and enable the
10
Message-id: 20200311221854.30370-8-nieklinnenbank@gmail.com
8
implementation of different behaviors depending on the type.
9
10
Signed-off-by: Arnaud Minier <arnaud.minier@telecom-paris.fr>
11
Signed-off-by: Inès Varhol <ines.varhol@telecom-paris.fr>
12
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
13
Message-id: 20240329174402.60382-2-arnaud.minier@telecom-paris.fr
14
[PMM: update to new reset hold method signature;
15
fixed a few checkpatch nits]
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
16
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
---
17
---
13
hw/misc/Makefile.objs | 1 +
18
MAINTAINERS | 1 +
14
include/hw/arm/allwinner-h3.h | 3 +
19
include/hw/char/stm32l4x5_usart.h | 66 +++++
15
include/hw/misc/allwinner-sid.h | 60 ++++++++++++
20
hw/char/stm32l4x5_usart.c | 396 ++++++++++++++++++++++++++++++
16
hw/arm/allwinner-h3.c | 11 ++-
21
hw/char/Kconfig | 3 +
17
hw/arm/orangepi.c | 8 ++
22
hw/char/meson.build | 1 +
18
hw/misc/allwinner-sid.c | 168 ++++++++++++++++++++++++++++++++
23
hw/char/trace-events | 4 +
19
hw/misc/trace-events | 4 +
24
6 files changed, 471 insertions(+)
20
7 files changed, 254 insertions(+), 1 deletion(-)
25
create mode 100644 include/hw/char/stm32l4x5_usart.h
21
create mode 100644 include/hw/misc/allwinner-sid.h
26
create mode 100644 hw/char/stm32l4x5_usart.c
22
create mode 100644 hw/misc/allwinner-sid.c
23
27
24
diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs
28
diff --git a/MAINTAINERS b/MAINTAINERS
25
index XXXXXXX..XXXXXXX 100644
29
index XXXXXXX..XXXXXXX 100644
26
--- a/hw/misc/Makefile.objs
30
--- a/MAINTAINERS
27
+++ b/hw/misc/Makefile.objs
31
+++ b/MAINTAINERS
28
@@ -XXX,XX +XXX,XX @@ common-obj-$(CONFIG_IVSHMEM_DEVICE) += ivshmem.o
32
@@ -XXX,XX +XXX,XX @@ M: Inès Varhol <ines.varhol@telecom-paris.fr>
29
common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-ccu.o
33
L: qemu-arm@nongnu.org
30
obj-$(CONFIG_ALLWINNER_H3) += allwinner-cpucfg.o
34
S: Maintained
31
common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-sysctrl.o
35
F: hw/arm/stm32l4x5_soc.c
32
+common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-sid.o
36
+F: hw/char/stm32l4x5_usart.c
33
common-obj-$(CONFIG_REALVIEW) += arm_sysctl.o
37
F: hw/misc/stm32l4x5_exti.c
34
common-obj-$(CONFIG_NSERIES) += cbus.o
38
F: hw/misc/stm32l4x5_syscfg.c
35
common-obj-$(CONFIG_ECCMEMCTL) += eccmemctl.o
39
F: hw/misc/stm32l4x5_rcc.c
36
diff --git a/include/hw/arm/allwinner-h3.h b/include/hw/arm/allwinner-h3.h
40
diff --git a/include/hw/char/stm32l4x5_usart.h b/include/hw/char/stm32l4x5_usart.h
37
index XXXXXXX..XXXXXXX 100644
38
--- a/include/hw/arm/allwinner-h3.h
39
+++ b/include/hw/arm/allwinner-h3.h
40
@@ -XXX,XX +XXX,XX @@
41
#include "hw/misc/allwinner-h3-ccu.h"
42
#include "hw/misc/allwinner-cpucfg.h"
43
#include "hw/misc/allwinner-h3-sysctrl.h"
44
+#include "hw/misc/allwinner-sid.h"
45
#include "target/arm/cpu.h"
46
47
/**
48
@@ -XXX,XX +XXX,XX @@ enum {
49
AW_H3_SRAM_A2,
50
AW_H3_SRAM_C,
51
AW_H3_SYSCTRL,
52
+ AW_H3_SID,
53
AW_H3_EHCI0,
54
AW_H3_OHCI0,
55
AW_H3_EHCI1,
56
@@ -XXX,XX +XXX,XX @@ typedef struct AwH3State {
57
AwH3ClockCtlState ccu;
58
AwCpuCfgState cpucfg;
59
AwH3SysCtrlState sysctrl;
60
+ AwSidState sid;
61
GICState gic;
62
MemoryRegion sram_a1;
63
MemoryRegion sram_a2;
64
diff --git a/include/hw/misc/allwinner-sid.h b/include/hw/misc/allwinner-sid.h
65
new file mode 100644
41
new file mode 100644
66
index XXXXXXX..XXXXXXX
42
index XXXXXXX..XXXXXXX
67
--- /dev/null
43
--- /dev/null
68
+++ b/include/hw/misc/allwinner-sid.h
44
+++ b/include/hw/char/stm32l4x5_usart.h
69
@@ -XXX,XX +XXX,XX @@
45
@@ -XXX,XX +XXX,XX @@
70
+/*
46
+/*
71
+ * Allwinner Security ID emulation
47
+ * STM32L4X5 USART (Universal Synchronous Asynchronous Receiver Transmitter)
72
+ *
48
+ *
73
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
49
+ * Copyright (c) 2023 Arnaud Minier <arnaud.minier@telecom-paris.fr>
74
+ *
50
+ * Copyright (c) 2023 Inès Varhol <ines.varhol@telecom-paris.fr>
75
+ * This program is free software: you can redistribute it and/or modify
51
+ *
76
+ * it under the terms of the GNU General Public License as published by
52
+ * SPDX-License-Identifier: GPL-2.0-or-later
77
+ * the Free Software Foundation, either version 2 of the License, or
53
+ *
78
+ * (at your option) any later version.
54
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
79
+ *
55
+ * See the COPYING file in the top-level directory.
80
+ * This program is distributed in the hope that it will be useful,
56
+ *
81
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
57
+ * The STM32L4X5 USART is heavily inspired by the stm32f2xx_usart
82
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
58
+ * by Alistair Francis.
83
+ * GNU General Public License for more details.
59
+ * The reference used is the STMicroElectronics RM0351 Reference manual
84
+ *
60
+ * for STM32L4x5 and STM32L4x6 advanced Arm ® -based 32-bit MCUs.
85
+ * You should have received a copy of the GNU General Public License
86
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
87
+ */
61
+ */
88
+
62
+
89
+#ifndef HW_MISC_ALLWINNER_SID_H
63
+#ifndef HW_STM32L4X5_USART_H
90
+#define HW_MISC_ALLWINNER_SID_H
64
+#define HW_STM32L4X5_USART_H
91
+
65
+
66
+#include "hw/sysbus.h"
67
+#include "chardev/char-fe.h"
92
+#include "qom/object.h"
68
+#include "qom/object.h"
93
+#include "hw/sysbus.h"
69
+
94
+#include "qemu/uuid.h"
70
+#define TYPE_STM32L4X5_USART_BASE "stm32l4x5-usart-base"
95
+
71
+#define TYPE_STM32L4X5_USART "stm32l4x5-usart"
96
+/**
72
+#define TYPE_STM32L4X5_UART "stm32l4x5-uart"
97
+ * Object model
73
+#define TYPE_STM32L4X5_LPUART "stm32l4x5-lpuart"
98
+ * @{
74
+OBJECT_DECLARE_TYPE(Stm32l4x5UsartBaseState, Stm32l4x5UsartBaseClass,
99
+ */
75
+ STM32L4X5_USART_BASE)
100
+
76
+
101
+#define TYPE_AW_SID "allwinner-sid"
77
+typedef enum {
102
+#define AW_SID(obj) \
78
+ STM32L4x5_USART,
103
+ OBJECT_CHECK(AwSidState, (obj), TYPE_AW_SID)
79
+ STM32L4x5_UART,
104
+
80
+ STM32L4x5_LPUART,
105
+/** @} */
81
+} Stm32l4x5UsartType;
106
+
82
+
107
+/**
83
+struct Stm32l4x5UsartBaseState {
108
+ * Allwinner Security ID object instance state
109
+ */
110
+typedef struct AwSidState {
111
+ /*< private >*/
112
+ SysBusDevice parent_obj;
84
+ SysBusDevice parent_obj;
113
+ /*< public >*/
85
+
114
+
86
+ MemoryRegion mmio;
115
+ /** Maps I/O registers in physical memory */
87
+
116
+ MemoryRegion iomem;
88
+ uint32_t cr1;
117
+
89
+ uint32_t cr2;
118
+ /** Control register defines how and what to read */
90
+ uint32_t cr3;
119
+ uint32_t control;
91
+ uint32_t brr;
120
+
92
+ uint32_t gtpr;
121
+ /** RdKey register contains the data retrieved by the device */
93
+ uint32_t rtor;
122
+ uint32_t rdkey;
94
+ /* rqr is write-only */
123
+
95
+ uint32_t isr;
124
+ /** Stores the emulated device identifier */
96
+ /* icr is a clear register */
125
+ QemuUUID identifier;
97
+ uint32_t rdr;
126
+
98
+ uint32_t tdr;
127
+} AwSidState;
99
+
128
+
100
+ Clock *clk;
129
+#endif /* HW_MISC_ALLWINNER_SID_H */
101
+ CharBackend chr;
130
diff --git a/hw/arm/allwinner-h3.c b/hw/arm/allwinner-h3.c
102
+ qemu_irq irq;
131
index XXXXXXX..XXXXXXX 100644
103
+};
132
--- a/hw/arm/allwinner-h3.c
104
+
133
+++ b/hw/arm/allwinner-h3.c
105
+struct Stm32l4x5UsartBaseClass {
134
@@ -XXX,XX +XXX,XX @@ const hwaddr allwinner_h3_memmap[] = {
106
+ SysBusDeviceClass parent_class;
135
[AW_H3_SRAM_A2] = 0x00044000,
107
+
136
[AW_H3_SRAM_C] = 0x00010000,
108
+ Stm32l4x5UsartType type;
137
[AW_H3_SYSCTRL] = 0x01c00000,
109
+};
138
+ [AW_H3_SID] = 0x01c14000,
110
+
139
[AW_H3_EHCI0] = 0x01c1a000,
111
+#endif /* HW_STM32L4X5_USART_H */
140
[AW_H3_OHCI0] = 0x01c1a400,
112
diff --git a/hw/char/stm32l4x5_usart.c b/hw/char/stm32l4x5_usart.c
141
[AW_H3_EHCI1] = 0x01c1b000,
142
@@ -XXX,XX +XXX,XX @@ struct AwH3Unimplemented {
143
{ "mmc0", 0x01c0f000, 4 * KiB },
144
{ "mmc1", 0x01c10000, 4 * KiB },
145
{ "mmc2", 0x01c11000, 4 * KiB },
146
- { "sid", 0x01c14000, 1 * KiB },
147
{ "crypto", 0x01c15000, 4 * KiB },
148
{ "msgbox", 0x01c17000, 4 * KiB },
149
{ "spinlock", 0x01c18000, 4 * KiB },
150
@@ -XXX,XX +XXX,XX @@ static void allwinner_h3_init(Object *obj)
151
152
sysbus_init_child_obj(obj, "cpucfg", &s->cpucfg, sizeof(s->cpucfg),
153
TYPE_AW_CPUCFG);
154
+
155
+ sysbus_init_child_obj(obj, "sid", &s->sid, sizeof(s->sid),
156
+ TYPE_AW_SID);
157
+ object_property_add_alias(obj, "identifier", OBJECT(&s->sid),
158
+ "identifier", &error_abort);
159
}
160
161
static void allwinner_h3_realize(DeviceState *dev, Error **errp)
162
@@ -XXX,XX +XXX,XX @@ static void allwinner_h3_realize(DeviceState *dev, Error **errp)
163
qdev_init_nofail(DEVICE(&s->cpucfg));
164
sysbus_mmio_map(SYS_BUS_DEVICE(&s->cpucfg), 0, s->memmap[AW_H3_CPUCFG]);
165
166
+ /* Security Identifier */
167
+ qdev_init_nofail(DEVICE(&s->sid));
168
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->sid), 0, s->memmap[AW_H3_SID]);
169
+
170
/* Universal Serial Bus */
171
sysbus_create_simple(TYPE_AW_H3_EHCI, s->memmap[AW_H3_EHCI0],
172
qdev_get_gpio_in(DEVICE(&s->gic),
173
diff --git a/hw/arm/orangepi.c b/hw/arm/orangepi.c
174
index XXXXXXX..XXXXXXX 100644
175
--- a/hw/arm/orangepi.c
176
+++ b/hw/arm/orangepi.c
177
@@ -XXX,XX +XXX,XX @@ static void orangepi_init(MachineState *machine)
178
object_property_set_int(OBJECT(h3), 24 * 1000 * 1000, "clk1-freq",
179
&error_abort);
180
181
+ /* Setup SID properties. Currently using a default fixed SID identifier. */
182
+ if (qemu_uuid_is_null(&h3->sid.identifier)) {
183
+ qdev_prop_set_string(DEVICE(h3), "identifier",
184
+ "02c00081-1111-2222-3333-000044556677");
185
+ } else if (ldl_be_p(&h3->sid.identifier.data[0]) != 0x02c00081) {
186
+ warn_report("Security Identifier value does not include H3 prefix");
187
+ }
188
+
189
/* Mark H3 object realized */
190
object_property_set_bool(OBJECT(h3), true, "realized", &error_abort);
191
192
diff --git a/hw/misc/allwinner-sid.c b/hw/misc/allwinner-sid.c
193
new file mode 100644
113
new file mode 100644
194
index XXXXXXX..XXXXXXX
114
index XXXXXXX..XXXXXXX
195
--- /dev/null
115
--- /dev/null
196
+++ b/hw/misc/allwinner-sid.c
116
+++ b/hw/char/stm32l4x5_usart.c
197
@@ -XXX,XX +XXX,XX @@
117
@@ -XXX,XX +XXX,XX @@
198
+/*
118
+/*
199
+ * Allwinner Security ID emulation
119
+ * STM32L4X5 USART (Universal Synchronous Asynchronous Receiver Transmitter)
200
+ *
120
+ *
201
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
121
+ * Copyright (c) 2023 Arnaud Minier <arnaud.minier@telecom-paris.fr>
202
+ *
122
+ * Copyright (c) 2023 Inès Varhol <ines.varhol@telecom-paris.fr>
203
+ * This program is free software: you can redistribute it and/or modify
123
+ *
204
+ * it under the terms of the GNU General Public License as published by
124
+ * SPDX-License-Identifier: GPL-2.0-or-later
205
+ * the Free Software Foundation, either version 2 of the License, or
125
+ *
206
+ * (at your option) any later version.
126
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
207
+ *
127
+ * See the COPYING file in the top-level directory.
208
+ * This program is distributed in the hope that it will be useful,
128
+ *
209
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
129
+ * The STM32L4X5 USART is heavily inspired by the stm32f2xx_usart
210
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
130
+ * by Alistair Francis.
211
+ * GNU General Public License for more details.
131
+ * The reference used is the STMicroElectronics RM0351 Reference manual
212
+ *
132
+ * for STM32L4x5 and STM32L4x6 advanced Arm ® -based 32-bit MCUs.
213
+ * You should have received a copy of the GNU General Public License
214
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
215
+ */
133
+ */
216
+
134
+
217
+#include "qemu/osdep.h"
135
+#include "qemu/osdep.h"
218
+#include "qemu/units.h"
219
+#include "hw/sysbus.h"
220
+#include "migration/vmstate.h"
221
+#include "qemu/log.h"
136
+#include "qemu/log.h"
222
+#include "qemu/module.h"
137
+#include "qemu/module.h"
223
+#include "qemu/guest-random.h"
224
+#include "qapi/error.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"
144
+#include "hw/irq.h"
145
+#include "hw/qdev-clock.h"
225
+#include "hw/qdev-properties.h"
146
+#include "hw/qdev-properties.h"
226
+#include "hw/misc/allwinner-sid.h"
147
+#include "hw/qdev-properties-system.h"
148
+#include "hw/registerfields.h"
227
+#include "trace.h"
149
+#include "trace.h"
228
+
150
+
229
+/* SID register offsets */
151
+
230
+enum {
152
+REG32(CR1, 0x00)
231
+ REG_PRCTL = 0x40, /* Control */
153
+ FIELD(CR1, M1, 28, 1) /* Word length (part 2, see M0) */
232
+ REG_RDKEY = 0x60, /* Read Key */
154
+ FIELD(CR1, EOBIE, 27, 1) /* End of Block interrupt enable */
233
+};
155
+ FIELD(CR1, RTOIE, 26, 1) /* Receiver timeout interrupt enable */
234
+
156
+ FIELD(CR1, DEAT, 21, 5) /* Driver Enable assertion time */
235
+/* SID register flags */
157
+ FIELD(CR1, DEDT, 16, 5) /* Driver Enable de-assertion time */
236
+enum {
158
+ FIELD(CR1, OVER8, 15, 1) /* Oversampling mode */
237
+ REG_PRCTL_WRITE = 0x0002, /* Unknown write flag */
159
+ FIELD(CR1, CMIE, 14, 1) /* Character match interrupt enable */
238
+ REG_PRCTL_OP_LOCK = 0xAC00, /* Lock operation */
160
+ FIELD(CR1, MME, 13, 1) /* Mute mode enable */
239
+};
161
+ FIELD(CR1, M0, 12, 1) /* Word length (part 1, see M1) */
240
+
162
+ FIELD(CR1, WAKE, 11, 1) /* Receiver wakeup method */
241
+static uint64_t allwinner_sid_read(void *opaque, hwaddr offset,
163
+ FIELD(CR1, PCE, 10, 1) /* Parity control enable */
242
+ unsigned size)
164
+ FIELD(CR1, PS, 9, 1) /* Parity selection */
243
+{
165
+ FIELD(CR1, PEIE, 8, 1) /* PE interrupt enable */
244
+ const AwSidState *s = AW_SID(opaque);
166
+ FIELD(CR1, TXEIE, 7, 1) /* TXE interrupt enable */
245
+ uint64_t val = 0;
167
+ FIELD(CR1, TCIE, 6, 1) /* Transmission complete interrupt enable */
246
+
168
+ FIELD(CR1, RXNEIE, 5, 1) /* RXNE interrupt enable */
247
+ switch (offset) {
169
+ FIELD(CR1, IDLEIE, 4, 1) /* IDLE interrupt enable */
248
+ case REG_PRCTL: /* Control */
170
+ FIELD(CR1, TE, 3, 1) /* Transmitter enable */
249
+ val = s->control;
171
+ FIELD(CR1, RE, 2, 1) /* Receiver enable */
250
+ break;
172
+ FIELD(CR1, UESM, 1, 1) /* USART enable in Stop mode */
251
+ case REG_RDKEY: /* Read Key */
173
+ FIELD(CR1, UE, 0, 1) /* USART enable */
252
+ val = s->rdkey;
174
+REG32(CR2, 0x04)
175
+ FIELD(CR2, ADD_1, 28, 4) /* ADD[7:4] */
176
+ FIELD(CR2, ADD_0, 24, 1) /* ADD[3:0] */
177
+ FIELD(CR2, RTOEN, 23, 1) /* Receiver timeout enable */
178
+ FIELD(CR2, ABRMOD, 21, 2) /* Auto baud rate mode */
179
+ FIELD(CR2, ABREN, 20, 1) /* Auto baud rate enable */
180
+ FIELD(CR2, MSBFIRST, 19, 1) /* Most significant bit first */
181
+ FIELD(CR2, DATAINV, 18, 1) /* Binary data inversion */
182
+ FIELD(CR2, TXINV, 17, 1) /* TX pin active level inversion */
183
+ FIELD(CR2, RXINV, 16, 1) /* RX pin active level inversion */
184
+ FIELD(CR2, SWAP, 15, 1) /* Swap RX/TX pins */
185
+ FIELD(CR2, LINEN, 14, 1) /* LIN mode enable */
186
+ FIELD(CR2, STOP, 12, 2) /* STOP bits */
187
+ FIELD(CR2, CLKEN, 11, 1) /* Clock enable */
188
+ FIELD(CR2, CPOL, 10, 1) /* Clock polarity */
189
+ FIELD(CR2, CPHA, 9, 1) /* Clock phase */
190
+ FIELD(CR2, LBCL, 8, 1) /* Last bit clock pulse */
191
+ FIELD(CR2, LBDIE, 6, 1) /* LIN break detection interrupt enable */
192
+ FIELD(CR2, LBDL, 5, 1) /* LIN break detection length */
193
+ FIELD(CR2, ADDM7, 4, 1) /* 7-bit / 4-bit Address Detection */
194
+
195
+REG32(CR3, 0x08)
196
+ /* TCBGTIE only on STM32L496xx/4A6xx devices */
197
+ FIELD(CR3, UCESM, 23, 1) /* USART Clock Enable in Stop Mode */
198
+ FIELD(CR3, WUFIE, 22, 1) /* Wakeup from Stop mode interrupt enable */
199
+ FIELD(CR3, WUS, 20, 2) /* Wakeup from Stop mode interrupt flag selection */
200
+ FIELD(CR3, SCARCNT, 17, 3) /* Smartcard auto-retry count */
201
+ FIELD(CR3, DEP, 15, 1) /* Driver enable polarity selection */
202
+ FIELD(CR3, DEM, 14, 1) /* Driver enable mode */
203
+ FIELD(CR3, DDRE, 13, 1) /* DMA Disable on Reception Error */
204
+ FIELD(CR3, OVRDIS, 12, 1) /* Overrun Disable */
205
+ FIELD(CR3, ONEBIT, 11, 1) /* One sample bit method enable */
206
+ FIELD(CR3, CTSIE, 10, 1) /* CTS interrupt enable */
207
+ FIELD(CR3, CTSE, 9, 1) /* CTS enable */
208
+ FIELD(CR3, RTSE, 8, 1) /* RTS enable */
209
+ FIELD(CR3, DMAT, 7, 1) /* DMA enable transmitter */
210
+ FIELD(CR3, DMAR, 6, 1) /* DMA enable receiver */
211
+ FIELD(CR3, SCEN, 5, 1) /* Smartcard mode enable */
212
+ FIELD(CR3, NACK, 4, 1) /* Smartcard NACK enable */
213
+ FIELD(CR3, HDSEL, 3, 1) /* Half-duplex selection */
214
+ FIELD(CR3, IRLP, 2, 1) /* IrDA low-power */
215
+ FIELD(CR3, IREN, 1, 1) /* IrDA mode enable */
216
+ FIELD(CR3, EIE, 0, 1) /* Error interrupt enable */
217
+REG32(BRR, 0x0C)
218
+ FIELD(BRR, BRR, 0, 16)
219
+REG32(GTPR, 0x10)
220
+ FIELD(GTPR, GT, 8, 8) /* Guard time value */
221
+ FIELD(GTPR, PSC, 0, 8) /* Prescaler value */
222
+REG32(RTOR, 0x14)
223
+ FIELD(RTOR, BLEN, 24, 8) /* Block Length */
224
+ FIELD(RTOR, RTO, 0, 24) /* Receiver timeout value */
225
+REG32(RQR, 0x18)
226
+ FIELD(RQR, TXFRQ, 4, 1) /* Transmit data flush request */
227
+ FIELD(RQR, RXFRQ, 3, 1) /* Receive data flush request */
228
+ FIELD(RQR, MMRQ, 2, 1) /* Mute mode request */
229
+ FIELD(RQR, SBKRQ, 1, 1) /* Send break request */
230
+ FIELD(RQR, ABBRRQ, 0, 1) /* Auto baud rate request */
231
+REG32(ISR, 0x1C)
232
+ /* TCBGT only for STM32L475xx/476xx/486xx devices */
233
+ FIELD(ISR, REACK, 22, 1) /* Receive enable acknowledge flag */
234
+ FIELD(ISR, TEACK, 21, 1) /* Transmit enable acknowledge flag */
235
+ FIELD(ISR, WUF, 20, 1) /* Wakeup from Stop mode flag */
236
+ FIELD(ISR, RWU, 19, 1) /* Receiver wakeup from Mute mode */
237
+ FIELD(ISR, SBKF, 18, 1) /* Send break flag */
238
+ FIELD(ISR, CMF, 17, 1) /* Character match flag */
239
+ FIELD(ISR, BUSY, 16, 1) /* Busy flag */
240
+ FIELD(ISR, ABRF, 15, 1) /* Auto Baud rate flag */
241
+ FIELD(ISR, ABRE, 14, 1) /* Auto Baud rate error */
242
+ FIELD(ISR, EOBF, 12, 1) /* End of block flag */
243
+ FIELD(ISR, RTOF, 11, 1) /* Receiver timeout */
244
+ FIELD(ISR, CTS, 10, 1) /* CTS flag */
245
+ FIELD(ISR, CTSIF, 9, 1) /* CTS interrupt flag */
246
+ FIELD(ISR, LBDF, 8, 1) /* LIN break detection flag */
247
+ FIELD(ISR, TXE, 7, 1) /* Transmit data register empty */
248
+ FIELD(ISR, TC, 6, 1) /* Transmission complete */
249
+ FIELD(ISR, RXNE, 5, 1) /* Read data register not empty */
250
+ FIELD(ISR, IDLE, 4, 1) /* Idle line detected */
251
+ FIELD(ISR, ORE, 3, 1) /* Overrun error */
252
+ FIELD(ISR, NF, 2, 1) /* START bit Noise detection flag */
253
+ FIELD(ISR, FE, 1, 1) /* Framing Error */
254
+ FIELD(ISR, PE, 0, 1) /* Parity Error */
255
+REG32(ICR, 0x20)
256
+ FIELD(ICR, WUCF, 20, 1) /* Wakeup from Stop mode clear flag */
257
+ FIELD(ICR, CMCF, 17, 1) /* Character match clear flag */
258
+ FIELD(ICR, EOBCF, 12, 1) /* End of block clear flag */
259
+ FIELD(ICR, RTOCF, 11, 1) /* Receiver timeout clear flag */
260
+ FIELD(ICR, CTSCF, 9, 1) /* CTS clear flag */
261
+ FIELD(ICR, LBDCF, 8, 1) /* LIN break detection clear flag */
262
+ /* TCBGTCF only on STM32L496xx/4A6xx devices */
263
+ FIELD(ICR, TCCF, 6, 1) /* Transmission complete clear flag */
264
+ FIELD(ICR, IDLECF, 4, 1) /* Idle line detected clear flag */
265
+ FIELD(ICR, ORECF, 3, 1) /* Overrun error clear flag */
266
+ FIELD(ICR, NCF, 2, 1) /* Noise detected clear flag */
267
+ FIELD(ICR, FECF, 1, 1) /* Framing error clear flag */
268
+ FIELD(ICR, PECF, 0, 1) /* Parity error clear flag */
269
+REG32(RDR, 0x24)
270
+ FIELD(RDR, RDR, 0, 9)
271
+REG32(TDR, 0x28)
272
+ FIELD(TDR, TDR, 0, 9)
273
+
274
+static void stm32l4x5_usart_base_reset_hold(Object *obj, ResetType type)
275
+{
276
+ Stm32l4x5UsartBaseState *s = STM32L4X5_USART_BASE(obj);
277
+
278
+ s->cr1 = 0x00000000;
279
+ s->cr2 = 0x00000000;
280
+ s->cr3 = 0x00000000;
281
+ s->brr = 0x00000000;
282
+ s->gtpr = 0x00000000;
283
+ s->rtor = 0x00000000;
284
+ s->isr = 0x020000C0;
285
+ s->rdr = 0x00000000;
286
+ s->tdr = 0x00000000;
287
+}
288
+
289
+static uint64_t stm32l4x5_usart_base_read(void *opaque, hwaddr addr,
290
+ unsigned int size)
291
+{
292
+ Stm32l4x5UsartBaseState *s = opaque;
293
+ uint64_t retvalue = 0;
294
+
295
+ switch (addr) {
296
+ case A_CR1:
297
+ retvalue = s->cr1;
298
+ break;
299
+ case A_CR2:
300
+ retvalue = s->cr2;
301
+ break;
302
+ case A_CR3:
303
+ retvalue = s->cr3;
304
+ break;
305
+ case A_BRR:
306
+ retvalue = FIELD_EX32(s->brr, BRR, BRR);
307
+ break;
308
+ case A_GTPR:
309
+ retvalue = s->gtpr;
310
+ break;
311
+ case A_RTOR:
312
+ retvalue = s->rtor;
313
+ break;
314
+ case A_RQR:
315
+ /* RQR is a write only register */
316
+ retvalue = 0x00000000;
317
+ break;
318
+ case A_ISR:
319
+ retvalue = s->isr;
320
+ break;
321
+ case A_ICR:
322
+ /* ICR is a clear register */
323
+ retvalue = 0x00000000;
324
+ break;
325
+ case A_RDR:
326
+ retvalue = FIELD_EX32(s->rdr, RDR, RDR);
327
+ /* Reset RXNE flag */
328
+ s->isr &= ~R_ISR_RXNE_MASK;
329
+ break;
330
+ case A_TDR:
331
+ retvalue = FIELD_EX32(s->tdr, TDR, TDR);
253
+ break;
332
+ break;
254
+ default:
333
+ default:
255
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset 0x%04x\n",
334
+ qemu_log_mask(LOG_GUEST_ERROR,
256
+ __func__, (uint32_t)offset);
335
+ "%s: Bad offset 0x%"HWADDR_PRIx"\n", __func__, addr);
257
+ return 0;
336
+ break;
258
+ }
337
+ }
259
+
338
+
260
+ trace_allwinner_sid_read(offset, val, size);
339
+ trace_stm32l4x5_usart_read(addr, retvalue);
261
+
340
+
262
+ return val;
341
+ return retvalue;
263
+}
342
+}
264
+
343
+
265
+static void allwinner_sid_write(void *opaque, hwaddr offset,
344
+static void stm32l4x5_usart_base_write(void *opaque, hwaddr addr,
266
+ uint64_t val, unsigned size)
345
+ uint64_t val64, unsigned int size)
267
+{
346
+{
268
+ AwSidState *s = AW_SID(opaque);
347
+ Stm32l4x5UsartBaseState *s = opaque;
269
+
348
+ const uint32_t value = val64;
270
+ trace_allwinner_sid_write(offset, val, size);
349
+
271
+
350
+ trace_stm32l4x5_usart_write(addr, value);
272
+ switch (offset) {
351
+
273
+ case REG_PRCTL: /* Control */
352
+ switch (addr) {
274
+ s->control = val;
353
+ case A_CR1:
275
+
354
+ s->cr1 = value;
276
+ if ((s->control & REG_PRCTL_OP_LOCK) &&
355
+ return;
277
+ (s->control & REG_PRCTL_WRITE)) {
356
+ case A_CR2:
278
+ uint32_t id = s->control >> 16;
357
+ s->cr2 = value;
279
+
358
+ return;
280
+ if (id <= sizeof(QemuUUID) - sizeof(s->rdkey)) {
359
+ case A_CR3:
281
+ s->rdkey = ldl_be_p(&s->identifier.data[id]);
360
+ s->cr3 = value;
282
+ }
361
+ return;
283
+ }
362
+ case A_BRR:
284
+ s->control &= ~REG_PRCTL_WRITE;
363
+ s->brr = value;
285
+ break;
364
+ return;
286
+ case REG_RDKEY: /* Read Key */
365
+ case A_GTPR:
287
+ break;
366
+ s->gtpr = value;
367
+ return;
368
+ case A_RTOR:
369
+ s->rtor = value;
370
+ return;
371
+ case A_RQR:
372
+ return;
373
+ case A_ISR:
374
+ qemu_log_mask(LOG_GUEST_ERROR,
375
+ "%s: ISR is read only !\n", __func__);
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;
288
+ default:
388
+ default:
289
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset 0x%04x\n",
389
+ qemu_log_mask(LOG_GUEST_ERROR,
290
+ __func__, (uint32_t)offset);
390
+ "%s: Bad offset 0x%"HWADDR_PRIx"\n", __func__, addr);
291
+ break;
292
+ }
391
+ }
293
+}
392
+}
294
+
393
+
295
+static const MemoryRegionOps allwinner_sid_ops = {
394
+static const MemoryRegionOps stm32l4x5_usart_base_ops = {
296
+ .read = allwinner_sid_read,
395
+ .read = stm32l4x5_usart_base_read,
297
+ .write = allwinner_sid_write,
396
+ .write = stm32l4x5_usart_base_write,
298
+ .endianness = DEVICE_NATIVE_ENDIAN,
397
+ .endianness = DEVICE_NATIVE_ENDIAN,
299
+ .valid = {
398
+ .valid = {
399
+ .max_access_size = 4,
300
+ .min_access_size = 4,
400
+ .min_access_size = 4,
401
+ .unaligned = false
402
+ },
403
+ .impl = {
301
+ .max_access_size = 4,
404
+ .max_access_size = 4,
405
+ .min_access_size = 4,
406
+ .unaligned = false
302
+ },
407
+ },
303
+ .impl.min_access_size = 4,
304
+};
408
+};
305
+
409
+
306
+static void allwinner_sid_reset(DeviceState *dev)
410
+static Property stm32l4x5_usart_base_properties[] = {
307
+{
411
+ DEFINE_PROP_CHR("chardev", Stm32l4x5UsartBaseState, chr),
308
+ AwSidState *s = AW_SID(dev);
412
+ DEFINE_PROP_END_OF_LIST(),
309
+
310
+ /* Set default values for registers */
311
+ s->control = 0;
312
+ s->rdkey = 0;
313
+}
314
+
315
+static void allwinner_sid_init(Object *obj)
316
+{
317
+ SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
318
+ AwSidState *s = AW_SID(obj);
319
+
320
+ /* Memory mapping */
321
+ memory_region_init_io(&s->iomem, OBJECT(s), &allwinner_sid_ops, s,
322
+ TYPE_AW_SID, 1 * KiB);
323
+ sysbus_init_mmio(sbd, &s->iomem);
324
+}
325
+
326
+static Property allwinner_sid_properties[] = {
327
+ DEFINE_PROP_UUID_NODEFAULT("identifier", AwSidState, identifier),
328
+ DEFINE_PROP_END_OF_LIST()
329
+};
413
+};
330
+
414
+
331
+static const VMStateDescription allwinner_sid_vmstate = {
415
+static void stm32l4x5_usart_base_init(Object *obj)
332
+ .name = "allwinner-sid",
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);
423
+ sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->mmio);
424
+
425
+ s->clk = qdev_init_clock_in(DEVICE(s), "clk", NULL, s, 0);
426
+}
427
+
428
+static const VMStateDescription vmstate_stm32l4x5_usart_base = {
429
+ .name = TYPE_STM32L4X5_USART_BASE,
333
+ .version_id = 1,
430
+ .version_id = 1,
334
+ .minimum_version_id = 1,
431
+ .minimum_version_id = 1,
335
+ .fields = (VMStateField[]) {
432
+ .fields = (VMStateField[]) {
336
+ VMSTATE_UINT32(control, AwSidState),
433
+ VMSTATE_UINT32(cr1, Stm32l4x5UsartBaseState),
337
+ VMSTATE_UINT32(rdkey, AwSidState),
434
+ VMSTATE_UINT32(cr2, Stm32l4x5UsartBaseState),
338
+ VMSTATE_UINT8_ARRAY_V(identifier.data, AwSidState, sizeof(QemuUUID), 1),
435
+ VMSTATE_UINT32(cr3, Stm32l4x5UsartBaseState),
436
+ VMSTATE_UINT32(brr, Stm32l4x5UsartBaseState),
437
+ VMSTATE_UINT32(gtpr, Stm32l4x5UsartBaseState),
438
+ VMSTATE_UINT32(rtor, Stm32l4x5UsartBaseState),
439
+ VMSTATE_UINT32(isr, Stm32l4x5UsartBaseState),
440
+ VMSTATE_UINT32(rdr, Stm32l4x5UsartBaseState),
441
+ VMSTATE_UINT32(tdr, Stm32l4x5UsartBaseState),
442
+ VMSTATE_CLOCK(clk, Stm32l4x5UsartBaseState),
339
+ VMSTATE_END_OF_LIST()
443
+ VMSTATE_END_OF_LIST()
340
+ }
444
+ }
341
+};
445
+};
342
+
446
+
343
+static void allwinner_sid_class_init(ObjectClass *klass, void *data)
447
+
448
+static void stm32l4x5_usart_base_realize(DeviceState *dev, Error **errp)
449
+{
450
+ ERRP_GUARD();
451
+ Stm32l4x5UsartBaseState *s = STM32L4X5_USART_BASE(dev);
452
+ if (!clock_has_source(s->clk)) {
453
+ error_setg(errp, "USART clock must be wired up by SoC code");
454
+ return;
455
+ }
456
+}
457
+
458
+static void stm32l4x5_usart_base_class_init(ObjectClass *klass, void *data)
344
+{
459
+{
345
+ DeviceClass *dc = DEVICE_CLASS(klass);
460
+ DeviceClass *dc = DEVICE_CLASS(klass);
346
+
461
+ ResettableClass *rc = RESETTABLE_CLASS(klass);
347
+ dc->reset = allwinner_sid_reset;
462
+
348
+ dc->vmsd = &allwinner_sid_vmstate;
463
+ rc->phases.hold = stm32l4x5_usart_base_reset_hold;
349
+ device_class_set_props(dc, allwinner_sid_properties);
464
+ device_class_set_props(dc, stm32l4x5_usart_base_properties);
350
+}
465
+ dc->realize = stm32l4x5_usart_base_realize;
351
+
466
+ dc->vmsd = &vmstate_stm32l4x5_usart_base;
352
+static const TypeInfo allwinner_sid_info = {
467
+}
353
+ .name = TYPE_AW_SID,
468
+
354
+ .parent = TYPE_SYS_BUS_DEVICE,
469
+static void stm32l4x5_usart_class_init(ObjectClass *oc, void *data)
355
+ .instance_init = allwinner_sid_init,
470
+{
356
+ .instance_size = sizeof(AwSidState),
471
+ Stm32l4x5UsartBaseClass *subc = STM32L4X5_USART_BASE_CLASS(oc);
357
+ .class_init = allwinner_sid_class_init,
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[] = {
491
+ {
492
+ .name = TYPE_STM32L4X5_USART_BASE,
493
+ .parent = TYPE_SYS_BUS_DEVICE,
494
+ .instance_size = sizeof(Stm32l4x5UsartBaseState),
495
+ .instance_init = stm32l4x5_usart_base_init,
496
+ .class_init = stm32l4x5_usart_base_class_init,
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
+ }
358
+};
511
+};
359
+
512
+
360
+static void allwinner_sid_register(void)
513
+DEFINE_TYPES(stm32l4x5_usart_types)
361
+{
514
diff --git a/hw/char/Kconfig b/hw/char/Kconfig
362
+ type_register_static(&allwinner_sid_info);
363
+}
364
+
365
+type_init(allwinner_sid_register)
366
diff --git a/hw/misc/trace-events b/hw/misc/trace-events
367
index XXXXXXX..XXXXXXX 100644
515
index XXXXXXX..XXXXXXX 100644
368
--- a/hw/misc/trace-events
516
--- a/hw/char/Kconfig
369
+++ b/hw/misc/trace-events
517
+++ b/hw/char/Kconfig
370
@@ -XXX,XX +XXX,XX @@ allwinner_cpucfg_cpu_reset(uint8_t cpu_id, uint32_t reset_addr) "id %u, reset_ad
518
@@ -XXX,XX +XXX,XX @@ config VIRTIO_SERIAL
371
allwinner_cpucfg_read(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
519
config STM32F2XX_USART
372
allwinner_cpucfg_write(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
520
bool
373
521
374
+# allwinner-sid.c
522
+config STM32L4X5_USART
375
+allwinner_sid_read(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
523
+ bool
376
+allwinner_sid_write(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
524
+
377
+
525
config CMSDK_APB_UART
378
# eccmemctl.c
526
bool
379
ecc_mem_writel_mer(uint32_t val) "Write memory enable 0x%08x"
527
380
ecc_mem_writel_mdr(uint32_t val) "Write memory delay 0x%08x"
528
diff --git a/hw/char/meson.build b/hw/char/meson.build
529
index XXXXXXX..XXXXXXX 100644
530
--- a/hw/char/meson.build
531
+++ b/hw/char/meson.build
532
@@ -XXX,XX +XXX,XX @@ system_ss.add(when: 'CONFIG_RENESAS_SCI', if_true: files('renesas_sci.c'))
533
system_ss.add(when: 'CONFIG_SIFIVE_UART', if_true: files('sifive_uart.c'))
534
system_ss.add(when: 'CONFIG_SH_SCI', if_true: files('sh_serial.c'))
535
system_ss.add(when: 'CONFIG_STM32F2XX_USART', if_true: files('stm32f2xx_usart.c'))
536
+system_ss.add(when: 'CONFIG_STM32L4X5_USART', if_true: files('stm32l4x5_usart.c'))
537
system_ss.add(when: 'CONFIG_MCHP_PFSOC_MMUART', if_true: files('mchp_pfsoc_mmuart.c'))
538
system_ss.add(when: 'CONFIG_HTIF', if_true: files('riscv_htif.c'))
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
541
index XXXXXXX..XXXXXXX 100644
542
--- a/hw/char/trace-events
543
+++ b/hw/char/trace-events
544
@@ -XXX,XX +XXX,XX @@ cadence_uart_baudrate(unsigned baudrate) "baudrate %u"
545
sh_serial_read(char *id, unsigned size, uint64_t offs, uint64_t val) " %s size %d offs 0x%02" PRIx64 " -> 0x%02" 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
547
548
+# stm32l4x5_usart.c
549
+stm32l4x5_usart_read(uint64_t addr, uint32_t data) "USART: Read <0x%" PRIx64 "> -> 0x%" PRIx32 ""
550
+stm32l4x5_usart_write(uint64_t addr, uint32_t data) "USART: Write <0x%" PRIx64 "> <- 0x%" PRIx32 ""
551
+
552
# xen_console.c
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"
381
--
555
--
382
2.20.1
556
2.34.1
383
557
384
558
diff view generated by jsdifflib
1
From: Guenter Roeck <linux@roeck-us.net>
1
From: Arnaud Minier <arnaud.minier@telecom-paris.fr>
2
2
3
Wire up eSDHC controllers in fsl-imx25. For imx25-pdk, connect drives
3
Implement the ability to read and write characters to the
4
provided on the command line to available eSDHC controllers.
4
usart using the serial port.
5
5
6
This patch enables booting the imx25-pdk emulation from SD card.
6
The character transmission is based on the
7
7
cmsdk-apb-uart implementation.
8
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
8
9
Message-id: 20200310215146.19688-2-linux@roeck-us.net
9
Signed-off-by: Arnaud Minier <arnaud.minier@telecom-paris.fr>
10
Signed-off-by: Inès Varhol <ines.varhol@telecom-paris.fr>
10
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
11
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
11
[PMM: made commit subject consistent with other patch]
12
Message-id: 20240329174402.60382-3-arnaud.minier@telecom-paris.fr
13
[PMM: fixed a few checkpatch nits]
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
14
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
---
15
---
14
include/hw/arm/fsl-imx25.h | 9 +++++++++
16
include/hw/char/stm32l4x5_usart.h | 1 +
15
hw/arm/fsl-imx25.c | 32 ++++++++++++++++++++++++++++++++
17
hw/char/stm32l4x5_usart.c | 143 ++++++++++++++++++++++++++++++
16
hw/arm/imx25_pdk.c | 16 ++++++++++++++++
18
hw/char/trace-events | 7 ++
17
3 files changed, 57 insertions(+)
19
3 files changed, 151 insertions(+)
18
20
19
diff --git a/include/hw/arm/fsl-imx25.h b/include/hw/arm/fsl-imx25.h
21
diff --git a/include/hw/char/stm32l4x5_usart.h b/include/hw/char/stm32l4x5_usart.h
20
index XXXXXXX..XXXXXXX 100644
22
index XXXXXXX..XXXXXXX 100644
21
--- a/include/hw/arm/fsl-imx25.h
23
--- a/include/hw/char/stm32l4x5_usart.h
22
+++ b/include/hw/arm/fsl-imx25.h
24
+++ b/include/hw/char/stm32l4x5_usart.h
23
@@ -XXX,XX +XXX,XX @@
25
@@ -XXX,XX +XXX,XX @@ struct Stm32l4x5UsartBaseState {
24
#include "hw/misc/imx_rngc.h"
26
Clock *clk;
25
#include "hw/i2c/imx_i2c.h"
27
CharBackend chr;
26
#include "hw/gpio/imx_gpio.h"
28
qemu_irq irq;
27
+#include "hw/sd/sdhci.h"
29
+ guint watch_tag;
28
#include "exec/memory.h"
30
};
29
#include "target/arm/cpu.h"
31
30
32
struct Stm32l4x5UsartBaseClass {
31
@@ -XXX,XX +XXX,XX @@
33
diff --git a/hw/char/stm32l4x5_usart.c b/hw/char/stm32l4x5_usart.c
32
#define FSL_IMX25_NUM_EPITS 2
33
#define FSL_IMX25_NUM_I2CS 3
34
#define FSL_IMX25_NUM_GPIOS 4
35
+#define FSL_IMX25_NUM_ESDHCS 2
36
37
typedef struct FslIMX25State {
38
/*< private >*/
39
@@ -XXX,XX +XXX,XX @@ typedef struct FslIMX25State {
40
IMXRNGCState rngc;
41
IMXI2CState i2c[FSL_IMX25_NUM_I2CS];
42
IMXGPIOState gpio[FSL_IMX25_NUM_GPIOS];
43
+ SDHCIState esdhc[FSL_IMX25_NUM_ESDHCS];
44
MemoryRegion rom[2];
45
MemoryRegion iram;
46
MemoryRegion iram_alias;
47
@@ -XXX,XX +XXX,XX @@ typedef struct FslIMX25State {
48
#define FSL_IMX25_GPIO3_SIZE 0x4000
49
#define FSL_IMX25_RNGC_ADDR 0x53FB0000
50
#define FSL_IMX25_RNGC_SIZE 0x4000
51
+#define FSL_IMX25_ESDHC1_ADDR 0x53FB4000
52
+#define FSL_IMX25_ESDHC1_SIZE 0x4000
53
+#define FSL_IMX25_ESDHC2_ADDR 0x53FB8000
54
+#define FSL_IMX25_ESDHC2_SIZE 0x4000
55
#define FSL_IMX25_GPIO1_ADDR 0x53FCC000
56
#define FSL_IMX25_GPIO1_SIZE 0x4000
57
#define FSL_IMX25_GPIO2_ADDR 0x53FD0000
58
@@ -XXX,XX +XXX,XX @@ typedef struct FslIMX25State {
59
#define FSL_IMX25_GPIO2_IRQ 51
60
#define FSL_IMX25_GPIO3_IRQ 16
61
#define FSL_IMX25_GPIO4_IRQ 23
62
+#define FSL_IMX25_ESDHC1_IRQ 9
63
+#define FSL_IMX25_ESDHC2_IRQ 8
64
65
#endif /* FSL_IMX25_H */
66
diff --git a/hw/arm/fsl-imx25.c b/hw/arm/fsl-imx25.c
67
index XXXXXXX..XXXXXXX 100644
34
index XXXXXXX..XXXXXXX 100644
68
--- a/hw/arm/fsl-imx25.c
35
--- a/hw/char/stm32l4x5_usart.c
69
+++ b/hw/arm/fsl-imx25.c
36
+++ b/hw/char/stm32l4x5_usart.c
70
@@ -XXX,XX +XXX,XX @@
37
@@ -XXX,XX +XXX,XX @@ REG32(RDR, 0x24)
71
#include "hw/qdev-properties.h"
38
REG32(TDR, 0x28)
72
#include "chardev/char.h"
39
FIELD(TDR, TDR, 0, 9)
73
40
74
+#define IMX25_ESDHC_CAPABILITIES 0x07e20000
41
+static void stm32l4x5_update_irq(Stm32l4x5UsartBaseState *s)
75
+
42
+{
76
static void fsl_imx25_init(Object *obj)
43
+ if (((s->isr & R_ISR_WUF_MASK) && (s->cr3 & R_CR3_WUFIE_MASK)) ||
44
+ ((s->isr & R_ISR_CMF_MASK) && (s->cr1 & R_CR1_CMIE_MASK)) ||
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)
77
{
159
{
78
FslIMX25State *s = FSL_IMX25(obj);
160
Stm32l4x5UsartBaseState *s = STM32L4X5_USART_BASE(obj);
79
@@ -XXX,XX +XXX,XX @@ static void fsl_imx25_init(Object *obj)
161
@@ -XXX,XX +XXX,XX @@ static void stm32l4x5_usart_base_reset_hold(Object *obj, ResetType type)
80
sysbus_init_child_obj(obj, "gpio[*]", &s->gpio[i], sizeof(s->gpio[i]),
162
s->isr = 0x020000C0;
81
TYPE_IMX_GPIO);
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;
82
}
228
}
83
+
229
+
84
+ for (i = 0; i < FSL_IMX25_NUM_ESDHCS; i++) {
230
+ qemu_chr_fe_set_handlers(&s->chr, stm32l4x5_usart_base_can_receive,
85
+ sysbus_init_child_obj(obj, "sdhc[*]", &s->esdhc[i], sizeof(s->esdhc[i]),
231
+ stm32l4x5_usart_base_receive, NULL, NULL,
86
+ TYPE_IMX_USDHC);
232
+ s, NULL, true);
87
+ }
88
}
233
}
89
234
90
static void fsl_imx25_realize(DeviceState *dev, Error **errp)
235
static void stm32l4x5_usart_base_class_init(ObjectClass *klass, void *data)
91
@@ -XXX,XX +XXX,XX @@ static void fsl_imx25_realize(DeviceState *dev, Error **errp)
236
diff --git a/hw/char/trace-events b/hw/char/trace-events
92
gpio_table[i].irq));
93
}
94
95
+ /* Initialize all SDHC */
96
+ for (i = 0; i < FSL_IMX25_NUM_ESDHCS; i++) {
97
+ static const struct {
98
+ hwaddr addr;
99
+ unsigned int irq;
100
+ } esdhc_table[FSL_IMX25_NUM_ESDHCS] = {
101
+ { FSL_IMX25_ESDHC1_ADDR, FSL_IMX25_ESDHC1_IRQ },
102
+ { FSL_IMX25_ESDHC2_ADDR, FSL_IMX25_ESDHC2_IRQ },
103
+ };
104
+
105
+ object_property_set_uint(OBJECT(&s->esdhc[i]), 2, "sd-spec-version",
106
+ &err);
107
+ object_property_set_uint(OBJECT(&s->esdhc[i]), IMX25_ESDHC_CAPABILITIES,
108
+ "capareg", &err);
109
+ object_property_set_bool(OBJECT(&s->esdhc[i]), true, "realized", &err);
110
+ if (err) {
111
+ error_propagate(errp, err);
112
+ return;
113
+ }
114
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->esdhc[i]), 0, esdhc_table[i].addr);
115
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->esdhc[i]), 0,
116
+ qdev_get_gpio_in(DEVICE(&s->avic),
117
+ esdhc_table[i].irq));
118
+ }
119
+
120
/* initialize 2 x 16 KB ROM */
121
memory_region_init_rom(&s->rom[0], NULL,
122
"imx25.rom0", FSL_IMX25_ROM0_SIZE, &err);
123
diff --git a/hw/arm/imx25_pdk.c b/hw/arm/imx25_pdk.c
124
index XXXXXXX..XXXXXXX 100644
237
index XXXXXXX..XXXXXXX 100644
125
--- a/hw/arm/imx25_pdk.c
238
--- a/hw/char/trace-events
126
+++ b/hw/arm/imx25_pdk.c
239
+++ b/hw/char/trace-events
127
@@ -XXX,XX +XXX,XX @@
240
@@ -XXX,XX +XXX,XX @@ sh_serial_write(char *id, unsigned size, uint64_t offs, uint64_t val) "%s size %
128
#include "qemu/osdep.h"
241
# stm32l4x5_usart.c
129
#include "qapi/error.h"
242
stm32l4x5_usart_read(uint64_t addr, uint32_t data) "USART: Read <0x%" PRIx64 "> -> 0x%" PRIx32 ""
130
#include "cpu.h"
243
stm32l4x5_usart_write(uint64_t addr, uint32_t data) "USART: Write <0x%" PRIx64 "> <- 0x%" PRIx32 ""
131
+#include "hw/qdev-properties.h"
244
+stm32l4x5_usart_rx(uint8_t c) "USART: got character 0x%x from backend"
132
#include "hw/arm/fsl-imx25.h"
245
+stm32l4x5_usart_tx(uint8_t c) "USART: character 0x%x sent to backend"
133
#include "hw/boards.h"
246
+stm32l4x5_usart_tx_pending(void) "USART: character send to backend pending"
134
#include "qemu/error-report.h"
247
+stm32l4x5_usart_irq_raised(uint32_t reg) "USART: IRQ raised: 0x%08"PRIx32
135
@@ -XXX,XX +XXX,XX @@ static void imx25_pdk_init(MachineState *machine)
248
+stm32l4x5_usart_irq_lowered(void) "USART: IRQ lowered"
136
imx25_pdk_binfo.board_id = 1771,
249
+stm32l4x5_usart_overrun_detected(uint8_t current, uint8_t received) "USART: Overrun detected, RDR='0x%x', received 0x%x"
137
imx25_pdk_binfo.nb_cpus = 1;
250
+stm32l4x5_usart_receiver_not_enabled(uint8_t ue_bit, uint8_t re_bit) "USART: Receiver not enabled, UE=0x%x, RE=0x%x"
138
251
139
+ for (i = 0; i < FSL_IMX25_NUM_ESDHCS; i++) {
252
# xen_console.c
140
+ BusState *bus;
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"
141
+ DeviceState *carddev;
142
+ DriveInfo *di;
143
+ BlockBackend *blk;
144
+
145
+ di = drive_get_next(IF_SD);
146
+ blk = di ? blk_by_legacy_dinfo(di) : NULL;
147
+ bus = qdev_get_child_bus(DEVICE(&s->soc.esdhc[i]), "sd-bus");
148
+ carddev = qdev_create(bus, TYPE_SD_CARD);
149
+ qdev_prop_set_drive(carddev, "drive", blk, &error_fatal);
150
+ object_property_set_bool(OBJECT(carddev), true,
151
+ "realized", &error_fatal);
152
+ }
153
+
154
/*
155
* We test explicitly for qtest here as it is not done (yet?) in
156
* arm_load_kernel(). Without this the "make check" command would
157
--
254
--
158
2.20.1
255
2.34.1
159
256
160
257
diff view generated by jsdifflib
1
From: Niek Linnenbank <nieklinnenbank@gmail.com>
1
From: Arnaud Minier <arnaud.minier@telecom-paris.fr>
2
2
3
In the Allwinner H3 SoC the SDRAM controller is responsible
3
Add a function to change the settings of the
4
for interfacing with the external Synchronous Dynamic Random
4
serial connection.
5
Access Memory (SDRAM). Types of memory that the SDRAM controller
6
supports are DDR2/DDR3 and capacities of up to 2GiB. This commit
7
adds emulation support of the Allwinner H3 SDRAM controller.
8
5
9
Signed-off-by: Niek Linnenbank <nieklinnenbank@gmail.com>
6
Signed-off-by: Arnaud Minier <arnaud.minier@telecom-paris.fr>
10
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
7
Signed-off-by: Inès Varhol <ines.varhol@telecom-paris.fr>
11
Message-id: 20200311221854.30370-12-nieklinnenbank@gmail.com
8
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
9
Message-id: 20240329174402.60382-4-arnaud.minier@telecom-paris.fr
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
---
11
---
14
hw/misc/Makefile.objs | 1 +
12
hw/char/stm32l4x5_usart.c | 98 +++++++++++++++++++++++++++++++++++++++
15
include/hw/arm/allwinner-h3.h | 5 +
13
hw/char/trace-events | 1 +
16
include/hw/misc/allwinner-h3-dramc.h | 106 ++++++++
14
2 files changed, 99 insertions(+)
17
hw/arm/allwinner-h3.c | 19 +-
18
hw/arm/orangepi.c | 6 +
19
hw/misc/allwinner-h3-dramc.c | 358 +++++++++++++++++++++++++++
20
hw/misc/trace-events | 10 +
21
7 files changed, 502 insertions(+), 3 deletions(-)
22
create mode 100644 include/hw/misc/allwinner-h3-dramc.h
23
create mode 100644 hw/misc/allwinner-h3-dramc.c
24
15
25
diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs
16
diff --git a/hw/char/stm32l4x5_usart.c b/hw/char/stm32l4x5_usart.c
26
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
27
--- a/hw/misc/Makefile.objs
18
--- a/hw/char/stm32l4x5_usart.c
28
+++ b/hw/misc/Makefile.objs
19
+++ b/hw/char/stm32l4x5_usart.c
29
@@ -XXX,XX +XXX,XX @@ common-obj-$(CONFIG_IVSHMEM_DEVICE) += ivshmem.o
20
@@ -XXX,XX +XXX,XX @@ static void usart_cancel_transmit(Stm32l4x5UsartBaseState *s)
30
21
}
31
common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-ccu.o
22
}
32
obj-$(CONFIG_ALLWINNER_H3) += allwinner-cpucfg.o
23
33
+common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-dramc.o
24
+static void stm32l4x5_update_params(Stm32l4x5UsartBaseState *s)
34
common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3-sysctrl.o
25
+{
35
common-obj-$(CONFIG_ALLWINNER_H3) += allwinner-sid.o
26
+ int speed, parity, data_bits, stop_bits;
36
common-obj-$(CONFIG_REALVIEW) += arm_sysctl.o
27
+ uint32_t value, usart_div;
37
diff --git a/include/hw/arm/allwinner-h3.h b/include/hw/arm/allwinner-h3.h
28
+ QEMUSerialSetParams ssp;
38
index XXXXXXX..XXXXXXX 100644
39
--- a/include/hw/arm/allwinner-h3.h
40
+++ b/include/hw/arm/allwinner-h3.h
41
@@ -XXX,XX +XXX,XX @@
42
#include "hw/intc/arm_gic.h"
43
#include "hw/misc/allwinner-h3-ccu.h"
44
#include "hw/misc/allwinner-cpucfg.h"
45
+#include "hw/misc/allwinner-h3-dramc.h"
46
#include "hw/misc/allwinner-h3-sysctrl.h"
47
#include "hw/misc/allwinner-sid.h"
48
#include "hw/sd/allwinner-sdhost.h"
49
@@ -XXX,XX +XXX,XX @@ enum {
50
AW_H3_UART2,
51
AW_H3_UART3,
52
AW_H3_EMAC,
53
+ AW_H3_DRAMCOM,
54
+ AW_H3_DRAMCTL,
55
+ AW_H3_DRAMPHY,
56
AW_H3_GIC_DIST,
57
AW_H3_GIC_CPU,
58
AW_H3_GIC_HYP,
59
@@ -XXX,XX +XXX,XX @@ typedef struct AwH3State {
60
AwA10PITState timer;
61
AwH3ClockCtlState ccu;
62
AwCpuCfgState cpucfg;
63
+ AwH3DramCtlState dramc;
64
AwH3SysCtrlState sysctrl;
65
AwSidState sid;
66
AwSdHostState mmc0;
67
diff --git a/include/hw/misc/allwinner-h3-dramc.h b/include/hw/misc/allwinner-h3-dramc.h
68
new file mode 100644
69
index XXXXXXX..XXXXXXX
70
--- /dev/null
71
+++ b/include/hw/misc/allwinner-h3-dramc.h
72
@@ -XXX,XX +XXX,XX @@
73
+/*
74
+ * Allwinner H3 SDRAM Controller emulation
75
+ *
76
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
77
+ *
78
+ * This program is free software: you can redistribute it and/or modify
79
+ * it under the terms of the GNU General Public License as published by
80
+ * the Free Software Foundation, either version 2 of the License, or
81
+ * (at your option) any later version.
82
+ *
83
+ * This program is distributed in the hope that it will be useful,
84
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
85
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
86
+ * GNU General Public License for more details.
87
+ *
88
+ * You should have received a copy of the GNU General Public License
89
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
90
+ */
91
+
29
+
92
+#ifndef HW_MISC_ALLWINNER_H3_DRAMC_H
30
+ /* Select the parity type */
93
+#define HW_MISC_ALLWINNER_H3_DRAMC_H
31
+ if (s->cr1 & R_CR1_PCE_MASK) {
94
+
32
+ if (s->cr1 & R_CR1_PS_MASK) {
95
+#include "qom/object.h"
33
+ parity = 'O';
96
+#include "hw/sysbus.h"
34
+ } else {
97
+#include "exec/hwaddr.h"
35
+ parity = 'E';
98
+
99
+/**
100
+ * Constants
101
+ * @{
102
+ */
103
+
104
+/** Highest register address used by DRAMCOM module */
105
+#define AW_H3_DRAMCOM_REGS_MAXADDR (0x804)
106
+
107
+/** Total number of known DRAMCOM registers */
108
+#define AW_H3_DRAMCOM_REGS_NUM (AW_H3_DRAMCOM_REGS_MAXADDR / \
109
+ sizeof(uint32_t))
110
+
111
+/** Highest register address used by DRAMCTL module */
112
+#define AW_H3_DRAMCTL_REGS_MAXADDR (0x88c)
113
+
114
+/** Total number of known DRAMCTL registers */
115
+#define AW_H3_DRAMCTL_REGS_NUM (AW_H3_DRAMCTL_REGS_MAXADDR / \
116
+ sizeof(uint32_t))
117
+
118
+/** Highest register address used by DRAMPHY module */
119
+#define AW_H3_DRAMPHY_REGS_MAXADDR (0x4)
120
+
121
+/** Total number of known DRAMPHY registers */
122
+#define AW_H3_DRAMPHY_REGS_NUM (AW_H3_DRAMPHY_REGS_MAXADDR / \
123
+ sizeof(uint32_t))
124
+
125
+/** @} */
126
+
127
+/**
128
+ * Object model
129
+ * @{
130
+ */
131
+
132
+#define TYPE_AW_H3_DRAMC "allwinner-h3-dramc"
133
+#define AW_H3_DRAMC(obj) \
134
+ OBJECT_CHECK(AwH3DramCtlState, (obj), TYPE_AW_H3_DRAMC)
135
+
136
+/** @} */
137
+
138
+/**
139
+ * Allwinner H3 SDRAM Controller object instance state.
140
+ */
141
+typedef struct AwH3DramCtlState {
142
+ /*< private >*/
143
+ SysBusDevice parent_obj;
144
+ /*< public >*/
145
+
146
+ /** Physical base address for start of RAM */
147
+ hwaddr ram_addr;
148
+
149
+ /** Total RAM size in megabytes */
150
+ uint32_t ram_size;
151
+
152
+ /**
153
+ * @name Memory Regions
154
+ * @{
155
+ */
156
+
157
+ MemoryRegion row_mirror; /**< Simulates rows for RAM size detection */
158
+ MemoryRegion row_mirror_alias; /**< Alias of the row which is mirrored */
159
+ MemoryRegion dramcom_iomem; /**< DRAMCOM module I/O registers */
160
+ MemoryRegion dramctl_iomem; /**< DRAMCTL module I/O registers */
161
+ MemoryRegion dramphy_iomem; /**< DRAMPHY module I/O registers */
162
+
163
+ /** @} */
164
+
165
+ /**
166
+ * @name Hardware Registers
167
+ * @{
168
+ */
169
+
170
+ uint32_t dramcom[AW_H3_DRAMCOM_REGS_NUM]; /**< Array of DRAMCOM registers */
171
+ uint32_t dramctl[AW_H3_DRAMCTL_REGS_NUM]; /**< Array of DRAMCTL registers */
172
+ uint32_t dramphy[AW_H3_DRAMPHY_REGS_NUM] ;/**< Array of DRAMPHY registers */
173
+
174
+ /** @} */
175
+
176
+} AwH3DramCtlState;
177
+
178
+#endif /* HW_MISC_ALLWINNER_H3_DRAMC_H */
179
diff --git a/hw/arm/allwinner-h3.c b/hw/arm/allwinner-h3.c
180
index XXXXXXX..XXXXXXX 100644
181
--- a/hw/arm/allwinner-h3.c
182
+++ b/hw/arm/allwinner-h3.c
183
@@ -XXX,XX +XXX,XX @@ const hwaddr allwinner_h3_memmap[] = {
184
[AW_H3_UART2] = 0x01c28800,
185
[AW_H3_UART3] = 0x01c28c00,
186
[AW_H3_EMAC] = 0x01c30000,
187
+ [AW_H3_DRAMCOM] = 0x01c62000,
188
+ [AW_H3_DRAMCTL] = 0x01c63000,
189
+ [AW_H3_DRAMPHY] = 0x01c65000,
190
[AW_H3_GIC_DIST] = 0x01c81000,
191
[AW_H3_GIC_CPU] = 0x01c82000,
192
[AW_H3_GIC_HYP] = 0x01c84000,
193
@@ -XXX,XX +XXX,XX @@ struct AwH3Unimplemented {
194
{ "scr", 0x01c2c400, 1 * KiB },
195
{ "gpu", 0x01c40000, 64 * KiB },
196
{ "hstmr", 0x01c60000, 4 * KiB },
197
- { "dramcom", 0x01c62000, 4 * KiB },
198
- { "dramctl0", 0x01c63000, 4 * KiB },
199
- { "dramphy0", 0x01c65000, 4 * KiB },
200
{ "spi0", 0x01c68000, 4 * KiB },
201
{ "spi1", 0x01c69000, 4 * KiB },
202
{ "csi", 0x01cb0000, 320 * KiB },
203
@@ -XXX,XX +XXX,XX @@ static void allwinner_h3_init(Object *obj)
204
205
sysbus_init_child_obj(obj, "emac", &s->emac, sizeof(s->emac),
206
TYPE_AW_SUN8I_EMAC);
207
+
208
+ sysbus_init_child_obj(obj, "dramc", &s->dramc, sizeof(s->dramc),
209
+ TYPE_AW_H3_DRAMC);
210
+ object_property_add_alias(obj, "ram-addr", OBJECT(&s->dramc),
211
+ "ram-addr", &error_abort);
212
+ object_property_add_alias(obj, "ram-size", OBJECT(&s->dramc),
213
+ "ram-size", &error_abort);
214
}
215
216
static void allwinner_h3_realize(DeviceState *dev, Error **errp)
217
@@ -XXX,XX +XXX,XX @@ static void allwinner_h3_realize(DeviceState *dev, Error **errp)
218
qdev_get_gpio_in(DEVICE(&s->gic), AW_H3_GIC_SPI_UART3),
219
115200, serial_hd(3), DEVICE_NATIVE_ENDIAN);
220
221
+ /* DRAMC */
222
+ qdev_init_nofail(DEVICE(&s->dramc));
223
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->dramc), 0, s->memmap[AW_H3_DRAMCOM]);
224
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->dramc), 1, s->memmap[AW_H3_DRAMCTL]);
225
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->dramc), 2, s->memmap[AW_H3_DRAMPHY]);
226
+
227
/* Unimplemented devices */
228
for (i = 0; i < ARRAY_SIZE(unimplemented); i++) {
229
create_unimplemented_device(unimplemented[i].device_name,
230
diff --git a/hw/arm/orangepi.c b/hw/arm/orangepi.c
231
index XXXXXXX..XXXXXXX 100644
232
--- a/hw/arm/orangepi.c
233
+++ b/hw/arm/orangepi.c
234
@@ -XXX,XX +XXX,XX @@ static void orangepi_init(MachineState *machine)
235
/* Setup EMAC properties */
236
object_property_set_int(OBJECT(&h3->emac), 1, "phy-addr", &error_abort);
237
238
+ /* DRAMC */
239
+ object_property_set_uint(OBJECT(h3), h3->memmap[AW_H3_SDRAM],
240
+ "ram-addr", &error_abort);
241
+ object_property_set_int(OBJECT(h3), machine->ram_size / MiB, "ram-size",
242
+ &error_abort);
243
+
244
/* Mark H3 object realized */
245
object_property_set_bool(OBJECT(h3), true, "realized", &error_abort);
246
247
diff --git a/hw/misc/allwinner-h3-dramc.c b/hw/misc/allwinner-h3-dramc.c
248
new file mode 100644
249
index XXXXXXX..XXXXXXX
250
--- /dev/null
251
+++ b/hw/misc/allwinner-h3-dramc.c
252
@@ -XXX,XX +XXX,XX @@
253
+/*
254
+ * Allwinner H3 SDRAM Controller emulation
255
+ *
256
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
257
+ *
258
+ * This program is free software: you can redistribute it and/or modify
259
+ * it under the terms of the GNU General Public License as published by
260
+ * the Free Software Foundation, either version 2 of the License, or
261
+ * (at your option) any later version.
262
+ *
263
+ * This program is distributed in the hope that it will be useful,
264
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
265
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
266
+ * GNU General Public License for more details.
267
+ *
268
+ * You should have received a copy of the GNU General Public License
269
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
270
+ */
271
+
272
+#include "qemu/osdep.h"
273
+#include "qemu/units.h"
274
+#include "qemu/error-report.h"
275
+#include "hw/sysbus.h"
276
+#include "migration/vmstate.h"
277
+#include "qemu/log.h"
278
+#include "qemu/module.h"
279
+#include "exec/address-spaces.h"
280
+#include "hw/qdev-properties.h"
281
+#include "qapi/error.h"
282
+#include "hw/misc/allwinner-h3-dramc.h"
283
+#include "trace.h"
284
+
285
+#define REG_INDEX(offset) (offset / sizeof(uint32_t))
286
+
287
+/* DRAMCOM register offsets */
288
+enum {
289
+ REG_DRAMCOM_CR = 0x0000, /* Control Register */
290
+};
291
+
292
+/* DRAMCTL register offsets */
293
+enum {
294
+ REG_DRAMCTL_PIR = 0x0000, /* PHY Initialization Register */
295
+ REG_DRAMCTL_PGSR = 0x0010, /* PHY General Status Register */
296
+ REG_DRAMCTL_STATR = 0x0018, /* Status Register */
297
+};
298
+
299
+/* DRAMCTL register flags */
300
+enum {
301
+ REG_DRAMCTL_PGSR_INITDONE = (1 << 0),
302
+};
303
+
304
+enum {
305
+ REG_DRAMCTL_STATR_ACTIVE = (1 << 0),
306
+};
307
+
308
+static void allwinner_h3_dramc_map_rows(AwH3DramCtlState *s, uint8_t row_bits,
309
+ uint8_t bank_bits, uint16_t page_size)
310
+{
311
+ /*
312
+ * This function simulates row addressing behavior when bootloader
313
+ * software attempts to detect the amount of available SDRAM. In U-Boot
314
+ * the controller is configured with the widest row addressing available.
315
+ * Then a pattern is written to RAM at an offset on the row boundary size.
316
+ * If the value read back equals the value read back from the
317
+ * start of RAM, the bootloader knows the amount of row bits.
318
+ *
319
+ * This function inserts a mirrored memory region when the configured row
320
+ * bits are not matching the actual emulated memory, to simulate the
321
+ * same behavior on hardware as expected by the bootloader.
322
+ */
323
+ uint8_t row_bits_actual = 0;
324
+
325
+ /* Calculate the actual row bits using the ram_size property */
326
+ for (uint8_t i = 8; i < 12; i++) {
327
+ if (1 << i == s->ram_size) {
328
+ row_bits_actual = i + 3;
329
+ break;
330
+ }
36
+ }
37
+ } else {
38
+ parity = 'N';
331
+ }
39
+ }
332
+
40
+
333
+ if (s->ram_size == (1 << (row_bits - 3))) {
41
+ /* Select the number of stop bits */
334
+ /* When row bits is the expected value, remove the mirror */
42
+ switch (FIELD_EX32(s->cr2, CR2, STOP)) {
335
+ memory_region_set_enabled(&s->row_mirror_alias, false);
43
+ case 0:
336
+ trace_allwinner_h3_dramc_rowmirror_disable();
44
+ stop_bits = 1;
337
+
45
+ break;
338
+ } else if (row_bits_actual) {
46
+ case 2:
339
+ /* Row bits not matching ram_size, install the rows mirror */
47
+ stop_bits = 2;
340
+ hwaddr row_mirror = s->ram_addr + ((1 << (row_bits_actual +
48
+ break;
341
+ bank_bits)) * page_size);
49
+ default:
342
+
50
+ qemu_log_mask(LOG_UNIMP,
343
+ memory_region_set_enabled(&s->row_mirror_alias, true);
51
+ "UNIMPLEMENTED: fractionnal stop bits; CR2[13:12] = %u",
344
+ memory_region_set_address(&s->row_mirror_alias, row_mirror);
52
+ FIELD_EX32(s->cr2, CR2, STOP));
345
+
346
+ trace_allwinner_h3_dramc_rowmirror_enable(row_mirror);
347
+ }
348
+}
349
+
350
+static uint64_t allwinner_h3_dramcom_read(void *opaque, hwaddr offset,
351
+ unsigned size)
352
+{
353
+ const AwH3DramCtlState *s = AW_H3_DRAMC(opaque);
354
+ const uint32_t idx = REG_INDEX(offset);
355
+
356
+ if (idx >= AW_H3_DRAMCOM_REGS_NUM) {
357
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset 0x%04x\n",
358
+ __func__, (uint32_t)offset);
359
+ return 0;
360
+ }
361
+
362
+ trace_allwinner_h3_dramcom_read(offset, s->dramcom[idx], size);
363
+
364
+ return s->dramcom[idx];
365
+}
366
+
367
+static void allwinner_h3_dramcom_write(void *opaque, hwaddr offset,
368
+ uint64_t val, unsigned size)
369
+{
370
+ AwH3DramCtlState *s = AW_H3_DRAMC(opaque);
371
+ const uint32_t idx = REG_INDEX(offset);
372
+
373
+ trace_allwinner_h3_dramcom_write(offset, val, size);
374
+
375
+ if (idx >= AW_H3_DRAMCOM_REGS_NUM) {
376
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset 0x%04x\n",
377
+ __func__, (uint32_t)offset);
378
+ return;
53
+ return;
379
+ }
54
+ }
380
+
55
+
381
+ switch (offset) {
56
+ /* Select the length of the word */
382
+ case REG_DRAMCOM_CR: /* Control Register */
57
+ switch ((FIELD_EX32(s->cr1, CR1, M1) << 1) | FIELD_EX32(s->cr1, CR1, M0)) {
383
+ allwinner_h3_dramc_map_rows(s, ((val >> 4) & 0xf) + 1,
58
+ case 0:
384
+ ((val >> 2) & 0x1) + 2,
59
+ data_bits = 8;
385
+ 1 << (((val >> 8) & 0xf) + 3));
60
+ break;
61
+ case 1:
62
+ data_bits = 9;
63
+ break;
64
+ case 2:
65
+ data_bits = 7;
386
+ break;
66
+ break;
387
+ default:
67
+ default:
388
+ break;
68
+ qemu_log_mask(LOG_GUEST_ERROR,
389
+ };
69
+ "UNDEFINED: invalid word length, CR1.M = 0b11");
390
+
391
+ s->dramcom[idx] = (uint32_t) val;
392
+}
393
+
394
+static uint64_t allwinner_h3_dramctl_read(void *opaque, hwaddr offset,
395
+ unsigned size)
396
+{
397
+ const AwH3DramCtlState *s = AW_H3_DRAMC(opaque);
398
+ const uint32_t idx = REG_INDEX(offset);
399
+
400
+ if (idx >= AW_H3_DRAMCTL_REGS_NUM) {
401
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset 0x%04x\n",
402
+ __func__, (uint32_t)offset);
403
+ return 0;
404
+ }
405
+
406
+ trace_allwinner_h3_dramctl_read(offset, s->dramctl[idx], size);
407
+
408
+ return s->dramctl[idx];
409
+}
410
+
411
+static void allwinner_h3_dramctl_write(void *opaque, hwaddr offset,
412
+ uint64_t val, unsigned size)
413
+{
414
+ AwH3DramCtlState *s = AW_H3_DRAMC(opaque);
415
+ const uint32_t idx = REG_INDEX(offset);
416
+
417
+ trace_allwinner_h3_dramctl_write(offset, val, size);
418
+
419
+ if (idx >= AW_H3_DRAMCTL_REGS_NUM) {
420
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset 0x%04x\n",
421
+ __func__, (uint32_t)offset);
422
+ return;
70
+ return;
423
+ }
71
+ }
424
+
72
+
425
+ switch (offset) {
73
+ /* Select the baud rate */
426
+ case REG_DRAMCTL_PIR: /* PHY Initialization Register */
74
+ value = FIELD_EX32(s->brr, BRR, BRR);
427
+ s->dramctl[REG_INDEX(REG_DRAMCTL_PGSR)] |= REG_DRAMCTL_PGSR_INITDONE;
75
+ if (value < 16) {
428
+ s->dramctl[REG_INDEX(REG_DRAMCTL_STATR)] |= REG_DRAMCTL_STATR_ACTIVE;
76
+ qemu_log_mask(LOG_GUEST_ERROR,
429
+ break;
77
+ "UNDEFINED: BRR less than 16: %u", value);
430
+ default:
431
+ break;
432
+ }
433
+
434
+ s->dramctl[idx] = (uint32_t) val;
435
+}
436
+
437
+static uint64_t allwinner_h3_dramphy_read(void *opaque, hwaddr offset,
438
+ unsigned size)
439
+{
440
+ const AwH3DramCtlState *s = AW_H3_DRAMC(opaque);
441
+ const uint32_t idx = REG_INDEX(offset);
442
+
443
+ if (idx >= AW_H3_DRAMPHY_REGS_NUM) {
444
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset 0x%04x\n",
445
+ __func__, (uint32_t)offset);
446
+ return 0;
447
+ }
448
+
449
+ trace_allwinner_h3_dramphy_read(offset, s->dramphy[idx], size);
450
+
451
+ return s->dramphy[idx];
452
+}
453
+
454
+static void allwinner_h3_dramphy_write(void *opaque, hwaddr offset,
455
+ uint64_t val, unsigned size)
456
+{
457
+ AwH3DramCtlState *s = AW_H3_DRAMC(opaque);
458
+ const uint32_t idx = REG_INDEX(offset);
459
+
460
+ trace_allwinner_h3_dramphy_write(offset, val, size);
461
+
462
+ if (idx >= AW_H3_DRAMPHY_REGS_NUM) {
463
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: out-of-bounds offset 0x%04x\n",
464
+ __func__, (uint32_t)offset);
465
+ return;
78
+ return;
466
+ }
79
+ }
467
+
80
+
468
+ s->dramphy[idx] = (uint32_t) val;
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);
469
+}
108
+}
470
+
109
+
471
+static const MemoryRegionOps allwinner_h3_dramcom_ops = {
110
static void stm32l4x5_usart_base_reset_hold(Object *obj, ResetType type)
472
+ .read = allwinner_h3_dramcom_read,
111
{
473
+ .write = allwinner_h3_dramcom_write,
112
Stm32l4x5UsartBaseState *s = STM32L4X5_USART_BASE(obj);
474
+ .endianness = DEVICE_NATIVE_ENDIAN,
113
@@ -XXX,XX +XXX,XX @@ static void stm32l4x5_usart_base_write(void *opaque, hwaddr addr,
475
+ .valid = {
114
switch (addr) {
476
+ .min_access_size = 4,
115
case A_CR1:
477
+ .max_access_size = 4,
116
s->cr1 = value;
478
+ },
117
+ stm32l4x5_update_params(s);
479
+ .impl.min_access_size = 4,
118
stm32l4x5_update_irq(s);
480
+};
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);
135
}
136
137
+static int stm32l4x5_usart_base_post_load(void *opaque, int version_id)
138
+{
139
+ Stm32l4x5UsartBaseState *s = (Stm32l4x5UsartBaseState *)opaque;
481
+
140
+
482
+static const MemoryRegionOps allwinner_h3_dramctl_ops = {
141
+ stm32l4x5_update_params(s);
483
+ .read = allwinner_h3_dramctl_read,
142
+ return 0;
484
+ .write = allwinner_h3_dramctl_write,
485
+ .endianness = DEVICE_NATIVE_ENDIAN,
486
+ .valid = {
487
+ .min_access_size = 4,
488
+ .max_access_size = 4,
489
+ },
490
+ .impl.min_access_size = 4,
491
+};
492
+
493
+static const MemoryRegionOps allwinner_h3_dramphy_ops = {
494
+ .read = allwinner_h3_dramphy_read,
495
+ .write = allwinner_h3_dramphy_write,
496
+ .endianness = DEVICE_NATIVE_ENDIAN,
497
+ .valid = {
498
+ .min_access_size = 4,
499
+ .max_access_size = 4,
500
+ },
501
+ .impl.min_access_size = 4,
502
+};
503
+
504
+static void allwinner_h3_dramc_reset(DeviceState *dev)
505
+{
506
+ AwH3DramCtlState *s = AW_H3_DRAMC(dev);
507
+
508
+ /* Set default values for registers */
509
+ memset(&s->dramcom, 0, sizeof(s->dramcom));
510
+ memset(&s->dramctl, 0, sizeof(s->dramctl));
511
+ memset(&s->dramphy, 0, sizeof(s->dramphy));
512
+}
143
+}
513
+
144
+
514
+static void allwinner_h3_dramc_realize(DeviceState *dev, Error **errp)
145
static const VMStateDescription vmstate_stm32l4x5_usart_base = {
515
+{
146
.name = TYPE_STM32L4X5_USART_BASE,
516
+ AwH3DramCtlState *s = AW_H3_DRAMC(dev);
147
.version_id = 1,
517
+
148
.minimum_version_id = 1,
518
+ /* Only power of 2 RAM sizes from 256MiB up to 2048MiB are supported */
149
+ .post_load = stm32l4x5_usart_base_post_load,
519
+ for (uint8_t i = 8; i < 13; i++) {
150
.fields = (VMStateField[]) {
520
+ if (1 << i == s->ram_size) {
151
VMSTATE_UINT32(cr1, Stm32l4x5UsartBaseState),
521
+ break;
152
VMSTATE_UINT32(cr2, Stm32l4x5UsartBaseState),
522
+ } else if (i == 12) {
153
diff --git a/hw/char/trace-events b/hw/char/trace-events
523
+ error_report("%s: ram-size %u MiB is not supported",
524
+ __func__, s->ram_size);
525
+ exit(1);
526
+ }
527
+ }
528
+
529
+ /* Setup row mirror mappings */
530
+ memory_region_init_ram(&s->row_mirror, OBJECT(s),
531
+ "allwinner-h3-dramc.row-mirror",
532
+ 4 * KiB, &error_abort);
533
+ memory_region_add_subregion_overlap(get_system_memory(), s->ram_addr,
534
+ &s->row_mirror, 10);
535
+
536
+ memory_region_init_alias(&s->row_mirror_alias, OBJECT(s),
537
+ "allwinner-h3-dramc.row-mirror-alias",
538
+ &s->row_mirror, 0, 4 * KiB);
539
+ memory_region_add_subregion_overlap(get_system_memory(),
540
+ s->ram_addr + 1 * MiB,
541
+ &s->row_mirror_alias, 10);
542
+ memory_region_set_enabled(&s->row_mirror_alias, false);
543
+}
544
+
545
+static void allwinner_h3_dramc_init(Object *obj)
546
+{
547
+ SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
548
+ AwH3DramCtlState *s = AW_H3_DRAMC(obj);
549
+
550
+ /* DRAMCOM registers */
551
+ memory_region_init_io(&s->dramcom_iomem, OBJECT(s),
552
+ &allwinner_h3_dramcom_ops, s,
553
+ TYPE_AW_H3_DRAMC, 4 * KiB);
554
+ sysbus_init_mmio(sbd, &s->dramcom_iomem);
555
+
556
+ /* DRAMCTL registers */
557
+ memory_region_init_io(&s->dramctl_iomem, OBJECT(s),
558
+ &allwinner_h3_dramctl_ops, s,
559
+ TYPE_AW_H3_DRAMC, 4 * KiB);
560
+ sysbus_init_mmio(sbd, &s->dramctl_iomem);
561
+
562
+ /* DRAMPHY registers */
563
+ memory_region_init_io(&s->dramphy_iomem, OBJECT(s),
564
+ &allwinner_h3_dramphy_ops, s,
565
+ TYPE_AW_H3_DRAMC, 4 * KiB);
566
+ sysbus_init_mmio(sbd, &s->dramphy_iomem);
567
+}
568
+
569
+static Property allwinner_h3_dramc_properties[] = {
570
+ DEFINE_PROP_UINT64("ram-addr", AwH3DramCtlState, ram_addr, 0x0),
571
+ DEFINE_PROP_UINT32("ram-size", AwH3DramCtlState, ram_size, 256 * MiB),
572
+ DEFINE_PROP_END_OF_LIST()
573
+};
574
+
575
+static const VMStateDescription allwinner_h3_dramc_vmstate = {
576
+ .name = "allwinner-h3-dramc",
577
+ .version_id = 1,
578
+ .minimum_version_id = 1,
579
+ .fields = (VMStateField[]) {
580
+ VMSTATE_UINT32_ARRAY(dramcom, AwH3DramCtlState, AW_H3_DRAMCOM_REGS_NUM),
581
+ VMSTATE_UINT32_ARRAY(dramctl, AwH3DramCtlState, AW_H3_DRAMCTL_REGS_NUM),
582
+ VMSTATE_UINT32_ARRAY(dramphy, AwH3DramCtlState, AW_H3_DRAMPHY_REGS_NUM),
583
+ VMSTATE_END_OF_LIST()
584
+ }
585
+};
586
+
587
+static void allwinner_h3_dramc_class_init(ObjectClass *klass, void *data)
588
+{
589
+ DeviceClass *dc = DEVICE_CLASS(klass);
590
+
591
+ dc->reset = allwinner_h3_dramc_reset;
592
+ dc->vmsd = &allwinner_h3_dramc_vmstate;
593
+ dc->realize = allwinner_h3_dramc_realize;
594
+ device_class_set_props(dc, allwinner_h3_dramc_properties);
595
+}
596
+
597
+static const TypeInfo allwinner_h3_dramc_info = {
598
+ .name = TYPE_AW_H3_DRAMC,
599
+ .parent = TYPE_SYS_BUS_DEVICE,
600
+ .instance_init = allwinner_h3_dramc_init,
601
+ .instance_size = sizeof(AwH3DramCtlState),
602
+ .class_init = allwinner_h3_dramc_class_init,
603
+};
604
+
605
+static void allwinner_h3_dramc_register(void)
606
+{
607
+ type_register_static(&allwinner_h3_dramc_info);
608
+}
609
+
610
+type_init(allwinner_h3_dramc_register)
611
diff --git a/hw/misc/trace-events b/hw/misc/trace-events
612
index XXXXXXX..XXXXXXX 100644
154
index XXXXXXX..XXXXXXX 100644
613
--- a/hw/misc/trace-events
155
--- a/hw/char/trace-events
614
+++ b/hw/misc/trace-events
156
+++ b/hw/char/trace-events
615
@@ -XXX,XX +XXX,XX @@ allwinner_cpucfg_cpu_reset(uint8_t cpu_id, uint32_t reset_addr) "id %u, reset_ad
157
@@ -XXX,XX +XXX,XX @@ stm32l4x5_usart_irq_raised(uint32_t reg) "USART: IRQ raised: 0x%08"PRIx32
616
allwinner_cpucfg_read(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
158
stm32l4x5_usart_irq_lowered(void) "USART: IRQ lowered"
617
allwinner_cpucfg_write(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
159
stm32l4x5_usart_overrun_detected(uint8_t current, uint8_t received) "USART: Overrun detected, RDR='0x%x', received 0x%x"
618
160
stm32l4x5_usart_receiver_not_enabled(uint8_t ue_bit, uint8_t re_bit) "USART: Receiver not enabled, UE=0x%x, RE=0x%x"
619
+# allwinner-h3-dramc.c
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"
620
+allwinner_h3_dramc_rowmirror_disable(void) "Disable row mirror"
162
621
+allwinner_h3_dramc_rowmirror_enable(uint64_t addr) "Enable row mirror: addr 0x%" PRIx64
163
# xen_console.c
622
+allwinner_h3_dramcom_read(uint64_t offset, uint64_t data, unsigned size) "Read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
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"
623
+allwinner_h3_dramcom_write(uint64_t offset, uint64_t data, unsigned size) "Write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
624
+allwinner_h3_dramctl_read(uint64_t offset, uint64_t data, unsigned size) "Read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
625
+allwinner_h3_dramctl_write(uint64_t offset, uint64_t data, unsigned size) "Write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
626
+allwinner_h3_dramphy_read(uint64_t offset, uint64_t data, unsigned size) "Read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
627
+allwinner_h3_dramphy_write(uint64_t offset, uint64_t data, unsigned size) "write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
628
+
629
# allwinner-sid.c
630
allwinner_sid_read(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
631
allwinner_sid_write(uint64_t offset, uint64_t data, unsigned size) "offset 0x%" PRIx64 " data 0x%" PRIx64 " size %" PRIu32
632
--
165
--
633
2.20.1
166
2.34.1
634
167
635
168
diff view generated by jsdifflib
1
From: Niek Linnenbank <nieklinnenbank@gmail.com>
1
From: Arnaud Minier <arnaud.minier@telecom-paris.fr>
2
2
3
The Allwinner H3 System on Chip contains multiple USB 2.0 bus
3
Add the USART to the SoC and connect it to the other implemented devices.
4
connections which provide software access using the Enhanced
4
5
Host Controller Interface (EHCI) and Open Host Controller
5
Signed-off-by: Arnaud Minier <arnaud.minier@telecom-paris.fr>
6
Interface (OHCI) interfaces. This commit adds support for
6
Signed-off-by: Inès Varhol <ines.varhol@telecom-paris.fr>
7
both interfaces in the Allwinner H3 System on Chip.
7
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
8
8
Message-id: 20240329174402.60382-5-arnaud.minier@telecom-paris.fr
9
Signed-off-by: Niek Linnenbank <nieklinnenbank@gmail.com>
9
[PMM: fixed a few checkpatch nits]
10
Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
11
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
12
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
13
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
14
Message-id: 20200311221854.30370-5-nieklinnenbank@gmail.com
15
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
16
---
11
---
17
hw/usb/hcd-ehci.h | 1 +
12
docs/system/arm/b-l475e-iot01a.rst | 2 +-
18
include/hw/arm/allwinner-h3.h | 8 +++++++
13
include/hw/arm/stm32l4x5_soc.h | 7 +++
19
hw/arm/allwinner-h3.c | 44 +++++++++++++++++++++++++++++++++++
14
hw/arm/stm32l4x5_soc.c | 83 +++++++++++++++++++++++++++---
20
hw/usb/hcd-ehci-sysbus.c | 17 ++++++++++++++
15
hw/arm/Kconfig | 1 +
21
hw/arm/Kconfig | 2 ++
16
4 files changed, 86 insertions(+), 7 deletions(-)
22
5 files changed, 72 insertions(+)
17
23
18
diff --git a/docs/system/arm/b-l475e-iot01a.rst b/docs/system/arm/b-l475e-iot01a.rst
24
diff --git a/hw/usb/hcd-ehci.h b/hw/usb/hcd-ehci.h
19
index XXXXXXX..XXXXXXX 100644
25
index XXXXXXX..XXXXXXX 100644
20
--- a/docs/system/arm/b-l475e-iot01a.rst
26
--- a/hw/usb/hcd-ehci.h
21
+++ b/docs/system/arm/b-l475e-iot01a.rst
27
+++ b/hw/usb/hcd-ehci.h
22
@@ -XXX,XX +XXX,XX @@ Currently B-L475E-IOT01A machine's only supports the following devices:
28
@@ -XXX,XX +XXX,XX @@ typedef struct EHCIPCIState {
23
- STM32L4x5 SYSCFG (System configuration controller)
29
#define TYPE_SYS_BUS_EHCI "sysbus-ehci-usb"
24
- STM32L4x5 RCC (Reset and clock control)
30
#define TYPE_PLATFORM_EHCI "platform-ehci-usb"
25
- STM32L4x5 GPIOs (General-purpose I/Os)
31
#define TYPE_EXYNOS4210_EHCI "exynos4210-ehci-usb"
26
+- STM32L4x5 USARTs, UARTs and LPUART (Serial ports)
32
+#define TYPE_AW_H3_EHCI "aw-h3-ehci-usb"
27
33
#define TYPE_TEGRA2_EHCI "tegra2-ehci-usb"
28
Missing devices
34
#define TYPE_PPC4xx_EHCI "ppc4xx-ehci-usb"
29
"""""""""""""""
35
#define TYPE_FUSBH200_EHCI "fusbh200-ehci-usb"
30
36
diff --git a/include/hw/arm/allwinner-h3.h b/include/hw/arm/allwinner-h3.h
31
The B-L475E-IOT01A does *not* support the following devices:
37
index XXXXXXX..XXXXXXX 100644
32
38
--- a/include/hw/arm/allwinner-h3.h
33
-- Serial ports (UART)
39
+++ b/include/hw/arm/allwinner-h3.h
34
- Analog to Digital Converter (ADC)
40
@@ -XXX,XX +XXX,XX @@ enum {
35
- SPI controller
41
AW_H3_SRAM_A1,
36
- Timer controller (TIMER)
42
AW_H3_SRAM_A2,
37
diff --git a/include/hw/arm/stm32l4x5_soc.h b/include/hw/arm/stm32l4x5_soc.h
43
AW_H3_SRAM_C,
38
index XXXXXXX..XXXXXXX 100644
44
+ AW_H3_EHCI0,
39
--- a/include/hw/arm/stm32l4x5_soc.h
45
+ AW_H3_OHCI0,
40
+++ b/include/hw/arm/stm32l4x5_soc.h
46
+ AW_H3_EHCI1,
47
+ AW_H3_OHCI1,
48
+ AW_H3_EHCI2,
49
+ AW_H3_OHCI2,
50
+ AW_H3_EHCI3,
51
+ AW_H3_OHCI3,
52
AW_H3_CCU,
53
AW_H3_PIT,
54
AW_H3_UART0,
55
diff --git a/hw/arm/allwinner-h3.c b/hw/arm/allwinner-h3.c
56
index XXXXXXX..XXXXXXX 100644
57
--- a/hw/arm/allwinner-h3.c
58
+++ b/hw/arm/allwinner-h3.c
59
@@ -XXX,XX +XXX,XX @@
41
@@ -XXX,XX +XXX,XX @@
60
#include "hw/sysbus.h"
42
#include "hw/misc/stm32l4x5_exti.h"
61
#include "hw/char/serial.h"
43
#include "hw/misc/stm32l4x5_rcc.h"
44
#include "hw/gpio/stm32l4x5_gpio.h"
45
+#include "hw/char/stm32l4x5_usart.h"
46
#include "qom/object.h"
47
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
59
@@ -XXX,XX +XXX,XX @@ struct Stm32l4x5SocState {
60
Stm32l4x5SyscfgState syscfg;
61
Stm32l4x5RccState rcc;
62
Stm32l4x5GpioState gpio[NUM_GPIOS];
63
+ Stm32l4x5UsartBaseState usart[STM_NUM_USARTS];
64
+ Stm32l4x5UsartBaseState uart[STM_NUM_UARTS];
65
+ Stm32l4x5UsartBaseState lpuart;
66
67
MemoryRegion sram1;
68
MemoryRegion sram2;
69
diff --git a/hw/arm/stm32l4x5_soc.c b/hw/arm/stm32l4x5_soc.c
70
index XXXXXXX..XXXXXXX 100644
71
--- a/hw/arm/stm32l4x5_soc.c
72
+++ b/hw/arm/stm32l4x5_soc.c
73
@@ -XXX,XX +XXX,XX @@
74
#include "sysemu/sysemu.h"
75
#include "hw/or-irq.h"
76
#include "hw/arm/stm32l4x5_soc.h"
77
+#include "hw/char/stm32l4x5_usart.h"
78
#include "hw/gpio/stm32l4x5_gpio.h"
79
#include "hw/qdev-clock.h"
62
#include "hw/misc/unimp.h"
80
#include "hw/misc/unimp.h"
63
+#include "hw/usb/hcd-ehci.h"
81
@@ -XXX,XX +XXX,XX @@ static const struct {
64
#include "sysemu/sysemu.h"
82
{ 0x48001C00, 0x0000000F, 0x00000000, 0x00000000 },
65
#include "hw/arm/allwinner-h3.h"
66
67
@@ -XXX,XX +XXX,XX @@ const hwaddr allwinner_h3_memmap[] = {
68
[AW_H3_SRAM_A1] = 0x00000000,
69
[AW_H3_SRAM_A2] = 0x00044000,
70
[AW_H3_SRAM_C] = 0x00010000,
71
+ [AW_H3_EHCI0] = 0x01c1a000,
72
+ [AW_H3_OHCI0] = 0x01c1a400,
73
+ [AW_H3_EHCI1] = 0x01c1b000,
74
+ [AW_H3_OHCI1] = 0x01c1b400,
75
+ [AW_H3_EHCI2] = 0x01c1c000,
76
+ [AW_H3_OHCI2] = 0x01c1c400,
77
+ [AW_H3_EHCI3] = 0x01c1d000,
78
+ [AW_H3_OHCI3] = 0x01c1d400,
79
[AW_H3_CCU] = 0x01c20000,
80
[AW_H3_PIT] = 0x01c20c00,
81
[AW_H3_UART0] = 0x01c28000,
82
@@ -XXX,XX +XXX,XX @@ enum {
83
AW_H3_GIC_SPI_UART3 = 3,
84
AW_H3_GIC_SPI_TIMER0 = 18,
85
AW_H3_GIC_SPI_TIMER1 = 19,
86
+ AW_H3_GIC_SPI_EHCI0 = 72,
87
+ AW_H3_GIC_SPI_OHCI0 = 73,
88
+ AW_H3_GIC_SPI_EHCI1 = 74,
89
+ AW_H3_GIC_SPI_OHCI1 = 75,
90
+ AW_H3_GIC_SPI_EHCI2 = 76,
91
+ AW_H3_GIC_SPI_OHCI2 = 77,
92
+ AW_H3_GIC_SPI_EHCI3 = 78,
93
+ AW_H3_GIC_SPI_OHCI3 = 79,
94
};
83
};
95
84
96
/* Allwinner H3 general constants */
85
+static const hwaddr usart_addr[] = {
97
@@ -XXX,XX +XXX,XX @@ static void allwinner_h3_realize(DeviceState *dev, Error **errp)
86
+ 0x40013800, /* "USART1", 0x400 */
98
qdev_init_nofail(DEVICE(&s->ccu));
87
+ 0x40004400, /* "USART2", 0x400 */
99
sysbus_mmio_map(SYS_BUS_DEVICE(&s->ccu), 0, s->memmap[AW_H3_CCU]);
88
+ 0x40004800, /* "USART3", 0x400 */
100
101
+ /* Universal Serial Bus */
102
+ sysbus_create_simple(TYPE_AW_H3_EHCI, s->memmap[AW_H3_EHCI0],
103
+ qdev_get_gpio_in(DEVICE(&s->gic),
104
+ AW_H3_GIC_SPI_EHCI0));
105
+ sysbus_create_simple(TYPE_AW_H3_EHCI, s->memmap[AW_H3_EHCI1],
106
+ qdev_get_gpio_in(DEVICE(&s->gic),
107
+ AW_H3_GIC_SPI_EHCI1));
108
+ sysbus_create_simple(TYPE_AW_H3_EHCI, s->memmap[AW_H3_EHCI2],
109
+ qdev_get_gpio_in(DEVICE(&s->gic),
110
+ AW_H3_GIC_SPI_EHCI2));
111
+ sysbus_create_simple(TYPE_AW_H3_EHCI, s->memmap[AW_H3_EHCI3],
112
+ qdev_get_gpio_in(DEVICE(&s->gic),
113
+ AW_H3_GIC_SPI_EHCI3));
114
+
115
+ sysbus_create_simple("sysbus-ohci", s->memmap[AW_H3_OHCI0],
116
+ qdev_get_gpio_in(DEVICE(&s->gic),
117
+ AW_H3_GIC_SPI_OHCI0));
118
+ sysbus_create_simple("sysbus-ohci", s->memmap[AW_H3_OHCI1],
119
+ qdev_get_gpio_in(DEVICE(&s->gic),
120
+ AW_H3_GIC_SPI_OHCI1));
121
+ sysbus_create_simple("sysbus-ohci", s->memmap[AW_H3_OHCI2],
122
+ qdev_get_gpio_in(DEVICE(&s->gic),
123
+ AW_H3_GIC_SPI_OHCI2));
124
+ sysbus_create_simple("sysbus-ohci", s->memmap[AW_H3_OHCI3],
125
+ qdev_get_gpio_in(DEVICE(&s->gic),
126
+ AW_H3_GIC_SPI_OHCI3));
127
+
128
/* UART0. For future clocktree API: All UARTS are connected to APB2_CLK. */
129
serial_mm_init(get_system_memory(), s->memmap[AW_H3_UART0], 2,
130
qdev_get_gpio_in(DEVICE(&s->gic), AW_H3_GIC_SPI_UART0),
131
diff --git a/hw/usb/hcd-ehci-sysbus.c b/hw/usb/hcd-ehci-sysbus.c
132
index XXXXXXX..XXXXXXX 100644
133
--- a/hw/usb/hcd-ehci-sysbus.c
134
+++ b/hw/usb/hcd-ehci-sysbus.c
135
@@ -XXX,XX +XXX,XX @@ static const TypeInfo ehci_exynos4210_type_info = {
136
.class_init = ehci_exynos4210_class_init,
137
};
138
139
+static void ehci_aw_h3_class_init(ObjectClass *oc, void *data)
140
+{
141
+ SysBusEHCIClass *sec = SYS_BUS_EHCI_CLASS(oc);
142
+ DeviceClass *dc = DEVICE_CLASS(oc);
143
+
144
+ sec->capsbase = 0x0;
145
+ sec->opregbase = 0x10;
146
+ set_bit(DEVICE_CATEGORY_USB, dc->categories);
147
+}
148
+
149
+static const TypeInfo ehci_aw_h3_type_info = {
150
+ .name = TYPE_AW_H3_EHCI,
151
+ .parent = TYPE_SYS_BUS_EHCI,
152
+ .class_init = ehci_aw_h3_class_init,
153
+};
89
+};
154
+
90
+static const hwaddr uart_addr[] = {
155
static void ehci_tegra2_class_init(ObjectClass *oc, void *data)
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
100
+
101
static void stm32l4x5_soc_initfn(Object *obj)
156
{
102
{
157
SysBusEHCIClass *sec = SYS_BUS_EHCI_CLASS(oc);
103
Stm32l4x5SocState *s = STM32L4X5_SOC(obj);
158
@@ -XXX,XX +XXX,XX @@ static void ehci_sysbus_register_types(void)
104
@@ -XXX,XX +XXX,XX @@ static void stm32l4x5_soc_initfn(Object *obj)
159
type_register_static(&ehci_type_info);
105
g_autofree char *name = g_strdup_printf("gpio%c", 'a' + i);
160
type_register_static(&ehci_platform_type_info);
106
object_initialize_child(obj, name, &s->gpio[i], TYPE_STM32L4X5_GPIO);
161
type_register_static(&ehci_exynos4210_type_info);
107
}
162
+ type_register_static(&ehci_aw_h3_type_info);
108
+
163
type_register_static(&ehci_tegra2_type_info);
109
+ for (int i = 0; i < STM_NUM_USARTS; i++) {
164
type_register_static(&ehci_ppc4xx_type_info);
110
+ object_initialize_child(obj, "usart[*]", &s->usart[i],
165
type_register_static(&ehci_fusbh200_type_info);
111
+ TYPE_STM32L4X5_USART);
112
+ }
113
+
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);
120
}
121
122
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)
124
sysbus_mmio_map(busdev, 0, RCC_BASE_ADDRESS);
125
sysbus_connect_irq(busdev, 0, qdev_get_gpio_in(armv7m, RCC_IRQ));
126
127
+ /* USART devices */
128
+ for (int i = 0; i < STM_NUM_USARTS; i++) {
129
+ g_autofree char *name = g_strdup_printf("usart%d-out", i + 1);
130
+ dev = DEVICE(&(s->usart[i]));
131
+ qdev_prop_set_chr(dev, "chardev", serial_hd(i));
132
+ qdev_connect_clock_in(dev, "clk",
133
+ qdev_get_clock_out(DEVICE(&(s->rcc)), name));
134
+ busdev = SYS_BUS_DEVICE(dev);
135
+ if (!sysbus_realize(busdev, errp)) {
136
+ return;
137
+ }
138
+ sysbus_mmio_map(busdev, 0, usart_addr[i]);
139
+ sysbus_connect_irq(busdev, 0, qdev_get_gpio_in(armv7m, usart_irq[i]));
140
+ }
141
+
142
+ /*
143
+ * TODO: Connect the USARTs, UARTs and LPUART to the EXTI once the EXTI
144
+ * can handle other gpio-in than the gpios. (e.g. Direct Lines for the
145
+ * usarts)
146
+ */
147
+
148
+ /* UART devices */
149
+ for (int i = 0; i < STM_NUM_UARTS; i++) {
150
+ g_autofree char *name = g_strdup_printf("uart%d-out", STM_NUM_USARTS + i + 1);
151
+ dev = DEVICE(&(s->uart[i]));
152
+ qdev_prop_set_chr(dev, "chardev", serial_hd(STM_NUM_USARTS + i));
153
+ qdev_connect_clock_in(dev, "clk",
154
+ qdev_get_clock_out(DEVICE(&(s->rcc)), name));
155
+ busdev = SYS_BUS_DEVICE(dev);
156
+ if (!sysbus_realize(busdev, errp)) {
157
+ return;
158
+ }
159
+ sysbus_mmio_map(busdev, 0, uart_addr[i]);
160
+ sysbus_connect_irq(busdev, 0, qdev_get_gpio_in(armv7m, uart_irq[i]));
161
+ }
162
+
163
+ /* LPUART device*/
164
+ dev = DEVICE(&(s->lpuart));
165
+ qdev_prop_set_chr(dev, "chardev", serial_hd(STM_NUM_USARTS + STM_NUM_UARTS));
166
+ qdev_connect_clock_in(dev, "clk",
167
+ qdev_get_clock_out(DEVICE(&(s->rcc)), "lpuart1-out"));
168
+ busdev = SYS_BUS_DEVICE(dev);
169
+ if (!sysbus_realize(busdev, errp)) {
170
+ return;
171
+ }
172
+ sysbus_mmio_map(busdev, 0, LPUART_BASE_ADDRESS);
173
+ sysbus_connect_irq(busdev, 0, qdev_get_gpio_in(armv7m, LPUART_IRQ));
174
+
175
/* APB1 BUS */
176
create_unimplemented_device("TIM2", 0x40000000, 0x400);
177
create_unimplemented_device("TIM3", 0x40000400, 0x400);
178
@@ -XXX,XX +XXX,XX @@ static void stm32l4x5_soc_realize(DeviceState *dev_soc, Error **errp)
179
create_unimplemented_device("SPI2", 0x40003800, 0x400);
180
create_unimplemented_device("SPI3", 0x40003C00, 0x400);
181
/* RESERVED: 0x40004000, 0x400 */
182
- create_unimplemented_device("USART2", 0x40004400, 0x400);
183
- create_unimplemented_device("USART3", 0x40004800, 0x400);
184
- create_unimplemented_device("UART4", 0x40004C00, 0x400);
185
- create_unimplemented_device("UART5", 0x40005000, 0x400);
186
create_unimplemented_device("I2C1", 0x40005400, 0x400);
187
create_unimplemented_device("I2C2", 0x40005800, 0x400);
188
create_unimplemented_device("I2C3", 0x40005C00, 0x400);
189
@@ -XXX,XX +XXX,XX @@ static void stm32l4x5_soc_realize(DeviceState *dev_soc, Error **errp)
190
create_unimplemented_device("DAC1", 0x40007400, 0x400);
191
create_unimplemented_device("OPAMP", 0x40007800, 0x400);
192
create_unimplemented_device("LPTIM1", 0x40007C00, 0x400);
193
- create_unimplemented_device("LPUART1", 0x40008000, 0x400);
194
/* RESERVED: 0x40008400, 0x400 */
195
create_unimplemented_device("SWPMI1", 0x40008800, 0x400);
196
/* RESERVED: 0x40008C00, 0x800 */
197
@@ -XXX,XX +XXX,XX @@ static void stm32l4x5_soc_realize(DeviceState *dev_soc, Error **errp)
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);
166
diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
205
diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
167
index XXXXXXX..XXXXXXX 100644
206
index XXXXXXX..XXXXXXX 100644
168
--- a/hw/arm/Kconfig
207
--- a/hw/arm/Kconfig
169
+++ b/hw/arm/Kconfig
208
+++ b/hw/arm/Kconfig
170
@@ -XXX,XX +XXX,XX @@ config ALLWINNER_H3
209
@@ -XXX,XX +XXX,XX @@ config STM32L4X5_SOC
171
select ARM_TIMER
210
select STM32L4X5_SYSCFG
172
select ARM_GIC
211
select STM32L4X5_RCC
173
select UNIMP
212
select STM32L4X5_GPIO
174
+ select USB_OHCI
213
+ select STM32L4X5_USART
175
+ select USB_EHCI_SYSBUS
214
176
215
config XLNX_ZYNQMP_ARM
177
config RASPI
178
bool
216
bool
179
--
217
--
180
2.20.1
218
2.34.1
181
219
182
220
diff view generated by jsdifflib
1
From: Niek Linnenbank <nieklinnenbank@gmail.com>
1
From: Arnaud Minier <arnaud.minier@telecom-paris.fr>
2
2
3
The Xunlong Orange Pi PC is an Allwinner H3 System on Chip
3
Test:
4
based embedded computer with mainline support in both U-Boot
4
- read/write from/to the usart registers
5
and Linux. The board comes with a Quad Core Cortex A7 @ 1.3GHz,
5
- send/receive a character/string over the serial port
6
1GiB RAM, 100Mbit ethernet, USB, SD/MMC, USB, HDMI and
6
7
various other I/O. This commit add support for the Xunlong
7
Signed-off-by: Arnaud Minier <arnaud.minier@telecom-paris.fr>
8
Orange Pi PC machine.
8
Signed-off-by: Inès Varhol <ines.varhol@telecom-paris.fr>
9
9
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Niek Linnenbank <nieklinnenbank@gmail.com>
10
Message-id: 20240329174402.60382-6-arnaud.minier@telecom-paris.fr
11
Tested-by: KONRAD Frederic <frederic.konrad@adacore.com>
11
[PMM: fix checkpatch nits, remove commented out code]
12
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
13
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
14
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
15
Acked-by: Igor Mammedov <imammedo@redhat.com>
16
Message-id: 20200311221854.30370-3-nieklinnenbank@gmail.com
17
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
18
---
13
---
19
hw/arm/Makefile.objs | 2 +-
14
tests/qtest/stm32l4x5_usart-test.c | 315 +++++++++++++++++++++++++++++
20
hw/arm/orangepi.c | 92 ++++++++++++++++++++++++++++++++++++++++++++
15
tests/qtest/meson.build | 4 +-
21
MAINTAINERS | 1 +
16
2 files changed, 318 insertions(+), 1 deletion(-)
22
3 files changed, 94 insertions(+), 1 deletion(-)
17
create mode 100644 tests/qtest/stm32l4x5_usart-test.c
23
create mode 100644 hw/arm/orangepi.c
18
24
19
diff --git a/tests/qtest/stm32l4x5_usart-test.c b/tests/qtest/stm32l4x5_usart-test.c
25
diff --git a/hw/arm/Makefile.objs b/hw/arm/Makefile.objs
26
index XXXXXXX..XXXXXXX 100644
27
--- a/hw/arm/Makefile.objs
28
+++ b/hw/arm/Makefile.objs
29
@@ -XXX,XX +XXX,XX @@ obj-$(CONFIG_DIGIC) += digic.o
30
obj-$(CONFIG_OMAP) += omap1.o omap2.o
31
obj-$(CONFIG_STRONGARM) += strongarm.o
32
obj-$(CONFIG_ALLWINNER_A10) += allwinner-a10.o cubieboard.o
33
-obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3.o
34
+obj-$(CONFIG_ALLWINNER_H3) += allwinner-h3.o orangepi.o
35
obj-$(CONFIG_RASPI) += bcm2835_peripherals.o bcm2836.o raspi.o
36
obj-$(CONFIG_STM32F205_SOC) += stm32f205_soc.o
37
obj-$(CONFIG_STM32F405_SOC) += stm32f405_soc.o
38
diff --git a/hw/arm/orangepi.c b/hw/arm/orangepi.c
39
new file mode 100644
20
new file mode 100644
40
index XXXXXXX..XXXXXXX
21
index XXXXXXX..XXXXXXX
41
--- /dev/null
22
--- /dev/null
42
+++ b/hw/arm/orangepi.c
23
+++ b/tests/qtest/stm32l4x5_usart-test.c
43
@@ -XXX,XX +XXX,XX @@
24
@@ -XXX,XX +XXX,XX @@
44
+/*
25
+/*
45
+ * Orange Pi emulation
26
+ * QTest testcase for STML4X5_USART
46
+ *
27
+ *
47
+ * Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
28
+ * Copyright (c) 2023 Arnaud Minier <arnaud.minier@telecom-paris.fr>
29
+ * Copyright (c) 2023 Inès Varhol <ines.varhol@telecom-paris.fr>
48
+ *
30
+ *
49
+ * This program is free software: you can redistribute it and/or modify
31
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
50
+ * it under the terms of the GNU General Public License as published by
32
+ * See the COPYING file in the top-level directory.
51
+ * the Free Software Foundation, either version 2 of the License, or
52
+ * (at your option) any later version.
53
+ *
54
+ * This program is distributed in the hope that it will be useful,
55
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
56
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
57
+ * GNU General Public License for more details.
58
+ *
59
+ * You should have received a copy of the GNU General Public License
60
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
61
+ */
33
+ */
62
+
34
+
63
+#include "qemu/osdep.h"
35
+#include "qemu/osdep.h"
64
+#include "qemu/units.h"
36
+#include "libqtest.h"
65
+#include "exec/address-spaces.h"
37
+#include "hw/misc/stm32l4x5_rcc_internals.h"
66
+#include "qapi/error.h"
38
+#include "hw/registerfields.h"
67
+#include "cpu.h"
39
+
68
+#include "hw/sysbus.h"
40
+#define RCC_BASE_ADDR 0x40021000
69
+#include "hw/boards.h"
41
+/* Use USART 1 ADDR, assume the others work the same */
70
+#include "hw/qdev-properties.h"
42
+#define USART1_BASE_ADDR 0x40013800
71
+#include "hw/arm/allwinner-h3.h"
43
+
72
+#include "sysemu/sysemu.h"
44
+/* See stm32l4x5_usart for definitions */
73
+
45
+REG32(CR1, 0x00)
74
+static struct arm_boot_info orangepi_binfo = {
46
+ FIELD(CR1, M1, 28, 1)
75
+ .nb_cpus = AW_H3_NUM_CPUS,
47
+ FIELD(CR1, OVER8, 15, 1)
76
+};
48
+ FIELD(CR1, M0, 12, 1)
77
+
49
+ FIELD(CR1, PCE, 10, 1)
78
+static void orangepi_init(MachineState *machine)
50
+ FIELD(CR1, TXEIE, 7, 1)
79
+{
51
+ FIELD(CR1, RXNEIE, 5, 1)
80
+ AwH3State *h3;
52
+ FIELD(CR1, TE, 3, 1)
81
+
53
+ FIELD(CR1, RE, 2, 1)
82
+ /* BIOS is not supported by this board */
54
+ FIELD(CR1, UE, 0, 1)
83
+ if (bios_name) {
55
+REG32(CR2, 0x04)
84
+ error_report("BIOS not supported for this machine");
56
+REG32(CR3, 0x08)
85
+ exit(1);
57
+ FIELD(CR3, OVRDIS, 12, 1)
58
+REG32(BRR, 0x0C)
59
+REG32(GTPR, 0x10)
60
+REG32(RTOR, 0x14)
61
+REG32(RQR, 0x18)
62
+REG32(ISR, 0x1C)
63
+ FIELD(ISR, TXE, 7, 1)
64
+ FIELD(ISR, RXNE, 5, 1)
65
+ FIELD(ISR, ORE, 3, 1)
66
+REG32(ICR, 0x20)
67
+REG32(RDR, 0x24)
68
+REG32(TDR, 0x28)
69
+
70
+#define NVIC_ISPR1 0XE000E204
71
+#define NVIC_ICPR1 0xE000E284
72
+#define USART1_IRQ 37
73
+
74
+static bool check_nvic_pending(QTestState *qts, unsigned int n)
75
+{
76
+ /* No USART interrupts are less than 32 */
77
+ assert(n > 32);
78
+ n -= 32;
79
+ return qtest_readl(qts, NVIC_ISPR1) & (1 << n);
80
+}
81
+
82
+static bool clear_nvic_pending(QTestState *qts, unsigned int n)
83
+{
84
+ /* No USART interrupts are less than 32 */
85
+ assert(n > 32);
86
+ n -= 32;
87
+ qtest_writel(qts, NVIC_ICPR1, (1 << n));
88
+ return true;
89
+}
90
+
91
+/*
92
+ * Wait indefinitely for the flag to be updated.
93
+ * If this is run on a slow CI runner,
94
+ * the meson harness will timeout after 10 minutes for us.
95
+ */
96
+static bool usart_wait_for_flag(QTestState *qts, uint32_t event_addr,
97
+ uint32_t flag)
98
+{
99
+ while (true) {
100
+ if ((qtest_readl(qts, event_addr) & flag)) {
101
+ return true;
102
+ }
103
+ g_usleep(1000);
86
+ }
104
+ }
87
+
105
+
88
+ /* This board has fixed size RAM */
106
+ return false;
89
+ if (machine->ram_size != 1 * GiB) {
107
+}
90
+ error_report("This machine can only be used with 1GiB of RAM");
108
+
91
+ exit(1);
109
+static void usart_receive_string(QTestState *qts, int sock_fd, const char *in,
110
+ char *out)
111
+{
112
+ int i, in_len = strlen(in);
113
+
114
+ g_assert_true(send(sock_fd, in, in_len, 0) == in_len);
115
+ for (i = 0; i < in_len; i++) {
116
+ g_assert_true(usart_wait_for_flag(qts,
117
+ USART1_BASE_ADDR + A_ISR, R_ISR_RXNE_MASK));
118
+ out[i] = qtest_readl(qts, USART1_BASE_ADDR + A_RDR);
92
+ }
119
+ }
93
+
120
+ out[i] = '\0';
94
+ /* Only allow Cortex-A7 for this board */
121
+}
95
+ if (strcmp(machine->cpu_type, ARM_CPU_TYPE_NAME("cortex-a7")) != 0) {
122
+
96
+ error_report("This board can only be used with cortex-a7 CPU");
123
+static void usart_send_string(QTestState *qts, const char *in)
97
+ exit(1);
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));
98
+ }
131
+ }
99
+
132
+}
100
+ h3 = AW_H3(object_new(TYPE_AW_H3));
133
+
101
+ object_property_add_child(OBJECT(machine), "soc", OBJECT(h3),
134
+/* Init the RCC clocks to run at 80 MHz */
102
+ &error_abort);
135
+static void init_clocks(QTestState *qts)
103
+ object_unref(OBJECT(h3));
136
+{
104
+
137
+ uint32_t value;
105
+ /* Setup timer properties */
138
+
106
+ object_property_set_int(OBJECT(h3), 32768, "clk0-freq",
139
+ /* MSIRANGE can be set only when MSI is OFF or READY */
107
+ &error_abort);
140
+ qtest_writel(qts, (RCC_BASE_ADDR + A_CR), R_CR_MSION_MASK);
108
+ object_property_set_int(OBJECT(h3), 24 * 1000 * 1000, "clk1-freq",
141
+
109
+ &error_abort);
142
+ /* Clocking from MSI, in case MSI was not the default source */
110
+
143
+ qtest_writel(qts, (RCC_BASE_ADDR + A_CFGR), 0);
111
+ /* Mark H3 object realized */
144
+
112
+ object_property_set_bool(OBJECT(h3), true, "realized", &error_abort);
145
+ /*
113
+
146
+ * Update PLL and set MSI as the source clock.
114
+ /* SDRAM */
147
+ * PLLM = 1 --> 000
115
+ memory_region_add_subregion(get_system_memory(), h3->memmap[AW_H3_SDRAM],
148
+ * PLLN = 40 --> 40
116
+ machine->ram);
149
+ * PPLLR = 2 --> 00
117
+
150
+ * PLLDIV = unused, PLLP = unused (SAI3), PLLQ = unused (48M1)
118
+ orangepi_binfo.loader_start = h3->memmap[AW_H3_SDRAM];
151
+ * SRC = MSI --> 01
119
+ orangepi_binfo.ram_size = machine->ram_size;
152
+ */
120
+ arm_load_kernel(ARM_CPU(first_cpu), machine, &orangepi_binfo);
153
+ qtest_writel(qts, (RCC_BASE_ADDR + A_PLLCFGR), R_PLLCFGR_PLLREN_MASK |
121
+}
154
+ (40 << R_PLLCFGR_PLLN_SHIFT) |
122
+
155
+ (0b01 << R_PLLCFGR_PLLSRC_SHIFT));
123
+static void orangepi_machine_init(MachineClass *mc)
156
+
124
+{
157
+ /* PLL activation */
125
+ mc->desc = "Orange Pi PC";
158
+
126
+ mc->init = orangepi_init;
159
+ value = qtest_readl(qts, (RCC_BASE_ADDR + A_CR));
127
+ mc->min_cpus = AW_H3_NUM_CPUS;
160
+ qtest_writel(qts, (RCC_BASE_ADDR + A_CR), value | R_CR_PLLON_MASK);
128
+ mc->max_cpus = AW_H3_NUM_CPUS;
161
+
129
+ mc->default_cpus = AW_H3_NUM_CPUS;
162
+ /* RCC_CFGR is OK by defaut */
130
+ mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-a7");
163
+ qtest_writel(qts, (RCC_BASE_ADDR + A_CFGR), 0);
131
+ mc->default_ram_size = 1 * GiB;
164
+
132
+ mc->default_ram_id = "orangepi.ram";
165
+ /* CCIPR : no periph clock by default */
133
+}
166
+ qtest_writel(qts, (RCC_BASE_ADDR + A_CCIPR), 0);
134
+
167
+
135
+DEFINE_MACHINE("orangepi-pc", orangepi_machine_init)
168
+ /* Switches on the PLL clock source */
136
diff --git a/MAINTAINERS b/MAINTAINERS
169
+ value = qtest_readl(qts, (RCC_BASE_ADDR + A_CFGR));
170
+ qtest_writel(qts, (RCC_BASE_ADDR + A_CFGR), (value & ~R_CFGR_SW_MASK) |
171
+ (0b11 << R_CFGR_SW_SHIFT));
172
+
173
+ /* Enable SYSCFG clock enabled */
174
+ qtest_writel(qts, (RCC_BASE_ADDR + A_APB2ENR), R_APB2ENR_SYSCFGEN_MASK);
175
+
176
+ /* Enable the IO port B clock (See p.252) */
177
+ qtest_writel(qts, (RCC_BASE_ADDR + A_AHB2ENR), R_AHB2ENR_GPIOBEN_MASK);
178
+
179
+ /* Enable the clock for USART1 (cf p.259) */
180
+ /* We rewrite SYSCFGEN to not disable it */
181
+ qtest_writel(qts, (RCC_BASE_ADDR + A_APB2ENR),
182
+ R_APB2ENR_SYSCFGEN_MASK | R_APB2ENR_USART1EN_MASK);
183
+
184
+ /* TODO: Enable usart via gpio */
185
+
186
+ /* Set PCLK as the clock for USART1(cf p.272) i.e. reset both bits */
187
+ qtest_writel(qts, (RCC_BASE_ADDR + A_CCIPR), 0);
188
+
189
+ /* Reset USART1 (see p.249) */
190
+ qtest_writel(qts, (RCC_BASE_ADDR + A_APB2RSTR), 1 << 14);
191
+ qtest_writel(qts, (RCC_BASE_ADDR + A_APB2RSTR), 0);
192
+}
193
+
194
+static void init_uart(QTestState *qts)
195
+{
196
+ uint32_t cr1;
197
+
198
+ init_clocks(qts);
199
+
200
+ /*
201
+ * For 115200 bauds, see p.1349.
202
+ * The clock has a frequency of 80Mhz,
203
+ * for 115200, we have to put a divider of 695 = 0x2B7.
204
+ */
205
+ qtest_writel(qts, (USART1_BASE_ADDR + A_BRR), 0x2B7);
206
+
207
+ /*
208
+ * Set the oversampling by 16,
209
+ * disable the parity control and
210
+ * set the word length to 8. (cf p.1377)
211
+ */
212
+ cr1 = qtest_readl(qts, (USART1_BASE_ADDR + A_CR1));
213
+ cr1 &= ~(R_CR1_M1_MASK | R_CR1_M0_MASK | R_CR1_OVER8_MASK | R_CR1_PCE_MASK);
214
+ qtest_writel(qts, (USART1_BASE_ADDR + A_CR1), cr1);
215
+
216
+ /* Enable the transmitter, the receiver and the USART. */
217
+ qtest_writel(qts, (USART1_BASE_ADDR + A_CR1),
218
+ R_CR1_UE_MASK | R_CR1_RE_MASK | R_CR1_TE_MASK);
219
+}
220
+
221
+static void test_write_read(void)
222
+{
223
+ QTestState *qts = qtest_init("-M b-l475e-iot01a");
224
+
225
+ /* Test that we can write and retrieve a value from the device */
226
+ qtest_writel(qts, USART1_BASE_ADDR + A_TDR, 0xFFFFFFFF);
227
+ const uint32_t tdr = qtest_readl(qts, USART1_BASE_ADDR + A_TDR);
228
+ g_assert_cmpuint(tdr, ==, 0x000001FF);
229
+}
230
+
231
+static void test_receive_char(void)
232
+{
233
+ int sock_fd;
234
+ uint32_t cr1;
235
+ QTestState *qts = qtest_init_with_serial("-M b-l475e-iot01a", &sock_fd);
236
+
237
+ init_uart(qts);
238
+
239
+ /* Try without initializing IRQ */
240
+ g_assert_true(send(sock_fd, "a", 1, 0) == 1);
241
+ usart_wait_for_flag(qts, USART1_BASE_ADDR + A_ISR, R_ISR_RXNE_MASK);
242
+ g_assert_cmphex(qtest_readl(qts, USART1_BASE_ADDR + A_RDR), ==, 'a');
243
+ g_assert_false(check_nvic_pending(qts, USART1_IRQ));
244
+
245
+ /* Now with the IRQ */
246
+ cr1 = qtest_readl(qts, (USART1_BASE_ADDR + A_CR1));
247
+ cr1 |= R_CR1_RXNEIE_MASK;
248
+ qtest_writel(qts, USART1_BASE_ADDR + A_CR1, cr1);
249
+ g_assert_true(send(sock_fd, "b", 1, 0) == 1);
250
+ usart_wait_for_flag(qts, USART1_BASE_ADDR + A_ISR, R_ISR_RXNE_MASK);
251
+ g_assert_cmphex(qtest_readl(qts, USART1_BASE_ADDR + A_RDR), ==, 'b');
252
+ g_assert_true(check_nvic_pending(qts, USART1_IRQ));
253
+ clear_nvic_pending(qts, USART1_IRQ);
254
+
255
+ close(sock_fd);
256
+
257
+ qtest_quit(qts);
258
+}
259
+
260
+static void test_send_char(void)
261
+{
262
+ int sock_fd;
263
+ char s[1];
264
+ uint32_t cr1;
265
+ QTestState *qts = qtest_init_with_serial("-M b-l475e-iot01a", &sock_fd);
266
+
267
+ init_uart(qts);
268
+
269
+ /* Try without initializing IRQ */
270
+ qtest_writel(qts, USART1_BASE_ADDR + A_TDR, 'c');
271
+ g_assert_true(recv(sock_fd, s, 1, 0) == 1);
272
+ g_assert_cmphex(s[0], ==, 'c');
273
+ g_assert_false(check_nvic_pending(qts, USART1_IRQ));
274
+
275
+ /* Now with the IRQ */
276
+ cr1 = qtest_readl(qts, (USART1_BASE_ADDR + A_CR1));
277
+ cr1 |= R_CR1_TXEIE_MASK;
278
+ qtest_writel(qts, USART1_BASE_ADDR + A_CR1, cr1);
279
+ qtest_writel(qts, USART1_BASE_ADDR + A_TDR, 'd');
280
+ g_assert_true(recv(sock_fd, s, 1, 0) == 1);
281
+ g_assert_cmphex(s[0], ==, 'd');
282
+ g_assert_true(check_nvic_pending(qts, USART1_IRQ));
283
+ clear_nvic_pending(qts, USART1_IRQ);
284
+
285
+ close(sock_fd);
286
+
287
+ qtest_quit(qts);
288
+}
289
+
290
+static void test_receive_str(void)
291
+{
292
+ int sock_fd;
293
+ char s[10];
294
+ QTestState *qts = qtest_init_with_serial("-M b-l475e-iot01a", &sock_fd);
295
+
296
+ init_uart(qts);
297
+
298
+ usart_receive_string(qts, sock_fd, "hello", s);
299
+ g_assert_true(memcmp(s, "hello", 5) == 0);
300
+
301
+ close(sock_fd);
302
+
303
+ qtest_quit(qts);
304
+}
305
+
306
+static void test_send_str(void)
307
+{
308
+ int sock_fd;
309
+ char s[10];
310
+ QTestState *qts = qtest_init_with_serial("-M b-l475e-iot01a", &sock_fd);
311
+
312
+ init_uart(qts);
313
+
314
+ usart_send_string(qts, "world");
315
+ g_assert_true(recv(sock_fd, s, 10, 0) == 5);
316
+ g_assert_true(memcmp(s, "world", 5) == 0);
317
+
318
+ close(sock_fd);
319
+
320
+ qtest_quit(qts);
321
+}
322
+
323
+int main(int argc, char **argv)
324
+{
325
+ int ret;
326
+
327
+ g_test_init(&argc, &argv, NULL);
328
+ g_test_set_nonfatal_assertions();
329
+
330
+ qtest_add_func("stm32l4x5/usart/write_read", test_write_read);
331
+ qtest_add_func("stm32l4x5/usart/receive_char", test_receive_char);
332
+ qtest_add_func("stm32l4x5/usart/send_char", test_send_char);
333
+ qtest_add_func("stm32l4x5/usart/receive_str", test_receive_str);
334
+ qtest_add_func("stm32l4x5/usart/send_str", test_send_str);
335
+ ret = g_test_run();
336
+
337
+ return ret;
338
+}
339
+
340
diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
137
index XXXXXXX..XXXXXXX 100644
341
index XXXXXXX..XXXXXXX 100644
138
--- a/MAINTAINERS
342
--- a/tests/qtest/meson.build
139
+++ b/MAINTAINERS
343
+++ b/tests/qtest/meson.build
140
@@ -XXX,XX +XXX,XX @@ L: qemu-arm@nongnu.org
344
@@ -XXX,XX +XXX,XX @@ slow_qtests = {
141
S: Maintained
345
'npcm7xx_pwm-test': 300,
142
F: hw/*/allwinner-h3*
346
'npcm7xx_watchdog_timer-test': 120,
143
F: include/hw/*/allwinner-h3*
347
'qom-test' : 900,
144
+F: hw/arm/orangepi.c
348
+ 'stm32l4x5_usart-test' : 600,
145
349
'test-hmp' : 240,
146
ARM PrimeCell and CMSDK devices
350
'pxe-test': 610,
147
M: Peter Maydell <peter.maydell@linaro.org>
351
'prom-env-test': 360,
352
@@ -XXX,XX +XXX,XX @@ qtests_stm32l4x5 = \
353
['stm32l4x5_exti-test',
354
'stm32l4x5_syscfg-test',
355
'stm32l4x5_rcc-test',
356
- 'stm32l4x5_gpio-test']
357
+ 'stm32l4x5_gpio-test',
358
+ 'stm32l4x5_usart-test']
359
360
qtests_arm = \
361
(config_all_devices.has_key('CONFIG_MPS2') ? ['sse-timer-test'] : []) + \
148
--
362
--
149
2.20.1
363
2.34.1
150
364
151
365
diff view generated by jsdifflib