1
A large arm pullreq, mostly because of 3 series:
1
Last minute pullreq for arm related patches; quite large because
2
* aspeed 2600 support
2
there were several series that only just made it through code review
3
* semihosting v2.0 support
3
in time.
4
* transaction-based ptimers
5
4
6
thanks
5
thanks
7
-- PMM
6
-- PMM
8
7
9
The following changes since commit 22dbfdecc3c52228d3489da3fe81da92b21197bf:
8
The following changes since commit 091e3e3dbc499d84c004e1c50bc9870af37f6e99:
10
9
11
Merge remote-tracking branch 'remotes/awilliam/tags/vfio-update-20191010.0' into staging (2019-10-14 15:09:08 +0100)
10
Merge remote-tracking branch 'remotes/ericb/tags/pull-bitmaps-2020-10-26' into staging (2020-10-26 22:36:35 +0000)
12
11
13
are available in the Git repository at:
12
are available in the Git repository at:
14
13
15
https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20191014
14
https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20201027-1
16
15
17
for you to fetch changes up to bca1936f8f66c5f8a111569ffd14969de208bf3b:
16
for you to fetch changes up to 32bd322a0134ed89db00f2b9b3894982db3dedcb:
18
17
19
hw/misc/bcm2835_mbox: Add trace events (2019-10-14 16:48:56 +0100)
18
hw/timer/armv7m_systick: Rewrite to use ptimers (2020-10-27 11:15:31 +0000)
20
19
21
----------------------------------------------------------------
20
----------------------------------------------------------------
22
target-arm queue:
21
target-arm queue:
23
* Add Aspeed AST2600 SoC and board support
22
* raspi: add model of cprman clock manager
24
* aspeed/wdt: Check correct register for clock source
23
* sbsa-ref: add an SBSA generic watchdog device
25
* bcm2835: code cleanups, better logging, trace events
24
* arm/trace: Fix hex printing
26
* implement v2.0 of the Arm semihosting specification
25
* raspi: Add models of Pi 3 model A+, Pi Zero and Pi A+
27
* provide new 'transaction-based' ptimer API and use it
26
* hw/arm/smmuv3: Set the restoration priority of the vSMMUv3 explicitly
28
for the Arm devices that use ptimers
27
* Nuvoton NPCM7xx: Add USB, RNG, GPIO and watchdog support
29
* ARM: KVM: support more than 256 CPUs
28
* hw/arm: fix min_cpus for xlnx-versal-virt platform
29
* hw/arm/highbank: Silence warnings about missing fallthrough statements
30
* linux-user: Support Aarch64 BTI
31
* Armv7M systick: fix corner case bugs by rewriting to use ptimer
30
32
31
----------------------------------------------------------------
33
----------------------------------------------------------------
32
Amithash Prasad (1):
34
Dr. David Alan Gilbert (1):
33
aspeed/wdt: Check correct register for clock source
35
arm/trace: Fix hex printing
34
36
35
Cédric Le Goater (15):
37
Hao Wu (1):
36
aspeed/timer: Introduce an object class per SoC
38
hw/timer: Adding watchdog for NPCM7XX Timer.
37
aspeed/timer: Add support for control register 3
38
aspeed/timer: Add AST2600 support
39
aspeed/timer: Add support for IRQ status register on the AST2600
40
aspeed/sdmc: Introduce an object class per SoC
41
watchdog/aspeed: Introduce an object class per SoC
42
aspeed/smc: Introduce segment operations
43
aspeed/smc: Add AST2600 support
44
aspeed/i2c: Introduce an object class per SoC
45
aspeed/i2c: Add AST2600 support
46
aspeed: Introduce an object class per SoC
47
aspeed/soc: Add AST2600 support
48
m25p80: Add support for w25q512jv
49
aspeed: Add an AST2600 eval board
50
aspeed: add support for the Aspeed MII controller of the AST2600
51
39
52
Eddie James (1):
40
Havard Skinnemoen (4):
53
hw/sd/aspeed_sdhci: New device
41
Move npcm7xx_timer_reached_zero call out of npcm7xx_timer_pause
42
hw/misc: Add npcm7xx random number generator
43
hw/arm/npcm7xx: Add EHCI and OHCI controllers
44
hw/gpio: Add GPIO model for Nuvoton NPCM7xx
54
45
55
Eric Auger (3):
46
Luc Michel (14):
56
linux headers: update against v5.4-rc1
47
hw/core/clock: provide the VMSTATE_ARRAY_CLOCK macro
57
intc/arm_gic: Support IRQ injection for more than 256 vpus
48
hw/core/clock: trace clock values in Hz instead of ns
58
ARM: KVM: Check KVM_CAP_ARM_IRQ_LINE_LAYOUT_2 for smp_cpus > 256
49
hw/arm/raspi: fix CPRMAN base address
50
hw/arm/raspi: add a skeleton implementation of the CPRMAN
51
hw/misc/bcm2835_cprman: add a PLL skeleton implementation
52
hw/misc/bcm2835_cprman: implement PLLs behaviour
53
hw/misc/bcm2835_cprman: add a PLL channel skeleton implementation
54
hw/misc/bcm2835_cprman: implement PLL channels behaviour
55
hw/misc/bcm2835_cprman: add a clock mux skeleton implementation
56
hw/misc/bcm2835_cprman: implement clock mux behaviour
57
hw/misc/bcm2835_cprman: add the DSI0HSCK multiplexer
58
hw/misc/bcm2835_cprman: add sane reset values to the registers
59
hw/char/pl011: add a clock input
60
hw/arm/bcm2835_peripherals: connect the UART clock
59
61
60
Joel Stanley (5):
62
Pavel Dovgalyuk (1):
61
hw: aspeed_scu: Add AST2600 support
63
hw/arm: fix min_cpus for xlnx-versal-virt platform
62
aspeed/sdmc: Add AST2600 support
63
hw: wdt_aspeed: Add AST2600 support
64
aspeed: Parameterise number of MACs
65
aspeed/soc: Add ASPEED Video stub
66
64
67
Peter Maydell (36):
65
Peter Maydell (2):
68
ptimer: Rename ptimer_init() to ptimer_init_with_bh()
66
hw/core/ptimer: Support ptimer being disabled by timer callback
69
ptimer: Provide new transaction-based API
67
hw/timer/armv7m_systick: Rewrite to use ptimers
70
tests/ptimer-test: Switch to transaction-based ptimer API
71
hw/timer/arm_timer.c: Switch to transaction-based ptimer API
72
hw/arm/musicpal.c: Switch to transaction-based ptimer API
73
hw/timer/allwinner-a10-pit.c: Switch to transaction-based ptimer API
74
hw/timer/arm_mptimer.c: Switch to transaction-based ptimer API
75
hw/timer/cmsdk-apb-dualtimer.c: Switch to transaction-based ptimer API
76
hw/timer/cmsdk-apb-timer.c: Switch to transaction-based ptimer API
77
hw/timer/digic-timer.c: Switch to transaction-based ptimer API
78
hw/timer/exynos4210_mct.c: Switch GFRC to transaction-based ptimer API
79
hw/timer/exynos4210_mct.c: Switch LFRC to transaction-based ptimer API
80
hw/timer/exynos4210_mct.c: Switch ltick to transaction-based ptimer API
81
hw/timer/exynos4210_pwm.c: Switch to transaction-based ptimer API
82
hw/timer/exynos4210_rtc.c: Switch 1Hz ptimer to transaction-based API
83
hw/timer/exynos4210_rtc.c: Switch main ptimer to transaction-based API
84
hw/timer/imx_epit.c: Switch to transaction-based ptimer API
85
hw/timer/imx_gpt.c: Switch to transaction-based ptimer API
86
hw/timer/mss-timerc: Switch to transaction-based ptimer API
87
hw/watchdog/cmsdk-apb-watchdog.c: Switch to transaction-based ptimer API
88
hw/net/lan9118.c: Switch to transaction-based ptimer API
89
target/arm/arm-semi: Capture errno in softmmu version of set_swi_errno()
90
target/arm/arm-semi: Always set some kind of errno for failed calls
91
target/arm/arm-semi: Correct comment about gdb syscall races
92
target/arm/arm-semi: Make semihosting code hand out its own file descriptors
93
target/arm/arm-semi: Restrict use of TaskState*
94
target/arm/arm-semi: Use set_swi_errno() in gdbstub callback functions
95
target/arm/arm-semi: Factor out implementation of SYS_CLOSE
96
target/arm/arm-semi: Factor out implementation of SYS_WRITE
97
target/arm/arm-semi: Factor out implementation of SYS_READ
98
target/arm/arm-semi: Factor out implementation of SYS_ISTTY
99
target/arm/arm-semi: Factor out implementation of SYS_SEEK
100
target/arm/arm-semi: Factor out implementation of SYS_FLEN
101
target/arm/arm-semi: Implement support for semihosting feature detection
102
target/arm/arm-semi: Implement SH_EXT_EXIT_EXTENDED extension
103
target/arm/arm-semi: Implement SH_EXT_STDOUT_STDERR extension
104
68
105
Philippe Mathieu-Daudé (6):
69
Philippe Mathieu-Daudé (10):
106
hw/arm/raspi: Use the IEC binary prefix definitions
70
linux-user/elfload: Avoid leaking interp_name using GLib memory API
107
hw/arm/bcm2835_peripherals: Improve logging
71
hw/arm/bcm2836: Restrict BCM283XInfo declaration to C source
108
hw/arm/bcm2835_peripherals: Name various address spaces
72
hw/arm/bcm2836: QOM'ify more by adding class_init() to each SoC type
109
hw/arm/bcm2835: Rename some definitions
73
hw/arm/bcm2836: Introduce BCM283XClass::core_count
110
hw/arm/bcm2835: Add various unimplemented peripherals
74
hw/arm/bcm2836: Only provide "enabled-cpus" property to multicore SoCs
111
hw/misc/bcm2835_mbox: Add trace events
75
hw/arm/bcm2836: Split out common realize() code
76
hw/arm/bcm2836: Introduce the BCM2835 SoC
77
hw/arm/raspi: Add the Raspberry Pi A+ machine
78
hw/arm/raspi: Add the Raspberry Pi Zero machine
79
hw/arm/raspi: Add the Raspberry Pi 3 model A+
112
80
113
Rashmica Gupta (1):
81
Richard Henderson (11):
114
hw/gpio: Add in AST2600 specific implementation
82
linux-user/aarch64: Reset btype for signals
83
linux-user: Set PAGE_TARGET_1 for TARGET_PROT_BTI
84
include/elf: Add defines related to GNU property notes for AArch64
85
linux-user/elfload: Fix coding style in load_elf_image
86
linux-user/elfload: Adjust iteration over phdr
87
linux-user/elfload: Move PT_INTERP detection to first loop
88
linux-user/elfload: Use Error for load_elf_image
89
linux-user/elfload: Use Error for load_elf_interp
90
linux-user/elfload: Parse NT_GNU_PROPERTY_TYPE_0 notes
91
linux-user/elfload: Parse GNU_PROPERTY_AARCH64_FEATURE_1_AND
92
tests/tcg/aarch64: Add bti smoke tests
115
93
116
hw/arm/Makefile.objs | 2 +-
94
Shashi Mallela (2):
117
hw/sd/Makefile.objs | 1 +
95
hw/watchdog: Implement SBSA watchdog device
118
include/hw/arm/aspeed.h | 1 +
96
hw/arm/sbsa-ref: add SBSA watchdog device
119
include/hw/arm/aspeed_soc.h | 29 +-
120
include/hw/arm/bcm2835_peripherals.h | 15 +
121
include/hw/arm/raspi_platform.h | 24 +-
122
include/hw/i2c/aspeed_i2c.h | 20 +-
123
include/hw/misc/aspeed_scu.h | 7 +-
124
include/hw/misc/aspeed_sdmc.h | 20 +-
125
include/hw/net/ftgmac100.h | 17 +
126
include/hw/ptimer.h | 83 ++-
127
include/hw/sd/aspeed_sdhci.h | 34 ++
128
include/hw/ssi/aspeed_smc.h | 4 +
129
include/hw/timer/aspeed_timer.h | 18 +
130
include/hw/timer/mss-timer.h | 1 -
131
include/hw/watchdog/wdt_aspeed.h | 19 +-
132
include/standard-headers/asm-x86/bootparam.h | 2 +
133
include/standard-headers/asm-x86/kvm_para.h | 1 +
134
include/standard-headers/linux/ethtool.h | 24 +
135
include/standard-headers/linux/pci_regs.h | 19 +-
136
include/standard-headers/linux/virtio_fs.h | 19 +
137
include/standard-headers/linux/virtio_ids.h | 2 +
138
include/standard-headers/linux/virtio_iommu.h | 165 ++++++
139
include/standard-headers/linux/virtio_pmem.h | 6 +-
140
linux-headers/asm-arm/kvm.h | 16 +-
141
linux-headers/asm-arm/unistd-common.h | 2 +
142
linux-headers/asm-arm64/kvm.h | 21 +-
143
linux-headers/asm-generic/mman-common.h | 18 +-
144
linux-headers/asm-generic/mman.h | 10 +-
145
linux-headers/asm-generic/unistd.h | 10 +-
146
linux-headers/asm-mips/mman.h | 3 +
147
linux-headers/asm-mips/unistd_n32.h | 1 +
148
linux-headers/asm-mips/unistd_n64.h | 1 +
149
linux-headers/asm-mips/unistd_o32.h | 1 +
150
linux-headers/asm-powerpc/mman.h | 6 +-
151
linux-headers/asm-powerpc/unistd_32.h | 2 +
152
linux-headers/asm-powerpc/unistd_64.h | 2 +
153
linux-headers/asm-s390/kvm.h | 6 +
154
linux-headers/asm-s390/unistd_32.h | 2 +
155
linux-headers/asm-s390/unistd_64.h | 2 +
156
linux-headers/asm-x86/kvm.h | 28 +-
157
linux-headers/asm-x86/unistd.h | 2 +-
158
linux-headers/asm-x86/unistd_32.h | 2 +
159
linux-headers/asm-x86/unistd_64.h | 2 +
160
linux-headers/asm-x86/unistd_x32.h | 2 +
161
linux-headers/linux/kvm.h | 12 +-
162
linux-headers/linux/psp-sev.h | 5 +-
163
linux-headers/linux/vfio.h | 71 ++-
164
target/arm/kvm_arm.h | 1 +
165
hw/arm/aspeed.c | 42 +-
166
hw/arm/aspeed_ast2600.c | 523 +++++++++++++++++++
167
hw/arm/aspeed_soc.c | 199 +++++---
168
hw/arm/bcm2835_peripherals.c | 38 +-
169
hw/arm/bcm2836.c | 2 +-
170
hw/arm/musicpal.c | 16 +-
171
hw/arm/raspi.c | 4 +-
172
hw/block/m25p80.c | 1 +
173
hw/char/bcm2835_aux.c | 5 +-
174
hw/core/ptimer.c | 154 +++++-
175
hw/display/bcm2835_fb.c | 2 +-
176
hw/dma/bcm2835_dma.c | 10 +-
177
hw/dma/xilinx_axidma.c | 2 +-
178
hw/gpio/aspeed_gpio.c | 142 +++++-
179
hw/i2c/aspeed_i2c.c | 106 +++-
180
hw/intc/arm_gic_kvm.c | 7 +-
181
hw/intc/bcm2836_control.c | 7 +-
182
hw/m68k/mcf5206.c | 2 +-
183
hw/m68k/mcf5208.c | 2 +-
184
hw/misc/aspeed_scu.c | 194 ++++++-
185
hw/misc/aspeed_sdmc.c | 250 ++++++---
186
hw/misc/bcm2835_mbox.c | 14 +-
187
hw/misc/bcm2835_property.c | 20 +-
188
hw/net/fsl_etsec/etsec.c | 2 +-
189
hw/net/ftgmac100.c | 162 ++++++
190
hw/net/lan9118.c | 11 +-
191
hw/sd/aspeed_sdhci.c | 198 ++++++++
192
hw/ssi/aspeed_smc.c | 177 ++++++-
193
hw/timer/allwinner-a10-pit.c | 12 +-
194
hw/timer/altera_timer.c | 2 +-
195
hw/timer/arm_mptimer.c | 18 +-
196
hw/timer/arm_timer.c | 16 +-
197
hw/timer/aspeed_timer.c | 213 +++++++-
198
hw/timer/cmsdk-apb-dualtimer.c | 14 +-
199
hw/timer/cmsdk-apb-timer.c | 15 +-
200
hw/timer/digic-timer.c | 16 +-
201
hw/timer/etraxfs_timer.c | 6 +-
202
hw/timer/exynos4210_mct.c | 107 +++-
203
hw/timer/exynos4210_pwm.c | 17 +-
204
hw/timer/exynos4210_rtc.c | 22 +-
205
hw/timer/grlib_gptimer.c | 2 +-
206
hw/timer/imx_epit.c | 32 +-
207
hw/timer/imx_gpt.c | 21 +-
208
hw/timer/lm32_timer.c | 2 +-
209
hw/timer/milkymist-sysctl.c | 4 +-
210
hw/timer/mss-timer.c | 11 +-
211
hw/timer/puv3_ost.c | 2 +-
212
hw/timer/sh_timer.c | 2 +-
213
hw/timer/slavio_timer.c | 2 +-
214
hw/timer/xilinx_timer.c | 2 +-
215
hw/watchdog/cmsdk-apb-watchdog.c | 13 +-
216
hw/watchdog/wdt_aspeed.c | 153 +++---
217
target/arm/arm-semi.c | 707 +++++++++++++++++++++-----
218
target/arm/cpu.c | 10 +-
219
target/arm/kvm.c | 22 +-
220
tests/ptimer-test.c | 106 +++-
221
hw/misc/trace-events | 6 +
222
106 files changed, 3958 insertions(+), 650 deletions(-)
223
create mode 100644 include/hw/sd/aspeed_sdhci.h
224
create mode 100644 include/standard-headers/linux/virtio_fs.h
225
create mode 100644 include/standard-headers/linux/virtio_iommu.h
226
create mode 100644 hw/arm/aspeed_ast2600.c
227
create mode 100644 hw/sd/aspeed_sdhci.c
228
97
98
Thomas Huth (1):
99
hw/arm/highbank: Silence warnings about missing fallthrough statements
100
101
Zenghui Yu (1):
102
hw/arm/smmuv3: Set the restoration priority of the vSMMUv3 explicitly
103
104
docs/system/arm/nuvoton.rst | 6 +-
105
hw/usb/hcd-ehci.h | 1 +
106
include/elf.h | 22 +
107
include/exec/cpu-all.h | 2 +
108
include/hw/arm/bcm2835_peripherals.h | 5 +-
109
include/hw/arm/bcm2836.h | 9 +-
110
include/hw/arm/npcm7xx.h | 8 +
111
include/hw/arm/raspi_platform.h | 5 +-
112
include/hw/char/pl011.h | 1 +
113
include/hw/clock.h | 5 +
114
include/hw/gpio/npcm7xx_gpio.h | 55 ++
115
include/hw/misc/bcm2835_cprman.h | 210 ++++++
116
include/hw/misc/bcm2835_cprman_internals.h | 1019 ++++++++++++++++++++++++++++
117
include/hw/misc/npcm7xx_clk.h | 2 +
118
include/hw/misc/npcm7xx_rng.h | 34 +
119
include/hw/timer/armv7m_systick.h | 3 +-
120
include/hw/timer/npcm7xx_timer.h | 48 +-
121
include/hw/watchdog/sbsa_gwdt.h | 79 +++
122
linux-user/qemu.h | 4 +
123
linux-user/syscall_defs.h | 4 +
124
target/arm/cpu.h | 5 +
125
hw/arm/bcm2835_peripherals.c | 15 +-
126
hw/arm/bcm2836.c | 182 +++--
127
hw/arm/highbank.c | 2 +
128
hw/arm/npcm7xx.c | 126 +++-
129
hw/arm/raspi.c | 41 ++
130
hw/arm/sbsa-ref.c | 23 +
131
hw/arm/smmuv3.c | 1 +
132
hw/arm/xlnx-versal-virt.c | 1 +
133
hw/char/pl011.c | 45 ++
134
hw/core/clock.c | 6 +-
135
hw/core/ptimer.c | 4 +
136
hw/gpio/npcm7xx_gpio.c | 424 ++++++++++++
137
hw/misc/bcm2835_cprman.c | 808 ++++++++++++++++++++++
138
hw/misc/npcm7xx_clk.c | 28 +
139
hw/misc/npcm7xx_rng.c | 180 +++++
140
hw/timer/armv7m_systick.c | 124 ++--
141
hw/timer/npcm7xx_timer.c | 270 ++++++--
142
hw/usb/hcd-ehci-sysbus.c | 19 +
143
hw/watchdog/sbsa_gwdt.c | 293 ++++++++
144
linux-user/aarch64/signal.c | 10 +-
145
linux-user/elfload.c | 326 +++++++--
146
linux-user/mmap.c | 16 +
147
target/arm/translate-a64.c | 6 +-
148
tests/qtest/npcm7xx_gpio-test.c | 385 +++++++++++
149
tests/qtest/npcm7xx_rng-test.c | 278 ++++++++
150
tests/qtest/npcm7xx_watchdog_timer-test.c | 319 +++++++++
151
tests/tcg/aarch64/bti-1.c | 62 ++
152
tests/tcg/aarch64/bti-2.c | 116 ++++
153
tests/tcg/aarch64/bti-crt.inc.c | 51 ++
154
MAINTAINERS | 1 +
155
hw/arm/Kconfig | 1 +
156
hw/arm/trace-events | 2 +-
157
hw/char/trace-events | 1 +
158
hw/core/trace-events | 4 +-
159
hw/gpio/meson.build | 1 +
160
hw/gpio/trace-events | 7 +
161
hw/misc/meson.build | 2 +
162
hw/misc/trace-events | 9 +
163
hw/watchdog/Kconfig | 3 +
164
hw/watchdog/meson.build | 1 +
165
tests/qtest/meson.build | 6 +-
166
tests/tcg/aarch64/Makefile.target | 10 +
167
tests/tcg/configure.sh | 4 +
168
64 files changed, 5461 insertions(+), 279 deletions(-)
169
create mode 100644 include/hw/gpio/npcm7xx_gpio.h
170
create mode 100644 include/hw/misc/bcm2835_cprman.h
171
create mode 100644 include/hw/misc/bcm2835_cprman_internals.h
172
create mode 100644 include/hw/misc/npcm7xx_rng.h
173
create mode 100644 include/hw/watchdog/sbsa_gwdt.h
174
create mode 100644 hw/gpio/npcm7xx_gpio.c
175
create mode 100644 hw/misc/bcm2835_cprman.c
176
create mode 100644 hw/misc/npcm7xx_rng.c
177
create mode 100644 hw/watchdog/sbsa_gwdt.c
178
create mode 100644 tests/qtest/npcm7xx_gpio-test.c
179
create mode 100644 tests/qtest/npcm7xx_rng-test.c
180
create mode 100644 tests/qtest/npcm7xx_watchdog_timer-test.c
181
create mode 100644 tests/tcg/aarch64/bti-1.c
182
create mode 100644 tests/tcg/aarch64/bti-2.c
183
create mode 100644 tests/tcg/aarch64/bti-crt.inc.c
184
diff view generated by jsdifflib
1
From: Eric Auger <eric.auger@redhat.com>
1
From: Richard Henderson <richard.henderson@linaro.org>
2
2
3
Host kernel within [4.18, 5.3] report an erroneous KVM_MAX_VCPUS=512
3
The kernel sets btype for the signal handler as if for a call.
4
for ARM. The actual capability to instantiate more than 256 vcpus
5
was fixed in 5.4 with the upgrade of the KVM_IRQ_LINE ABI to support
6
vcpu id encoded on 12 bits instead of 8 and a redistributor consuming
7
a single KVM IO device instead of 2.
8
4
9
So let's check this capability when attempting to use more than 256
5
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
10
vcpus within any ARM kvm accelerated machine.
6
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
11
7
Message-id: 20201021173749.111103-2-richard.henderson@linaro.org
12
Signed-off-by: Eric Auger <eric.auger@redhat.com>
13
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
14
Reviewed-by: Andrew Jones <drjones@redhat.com>
15
Acked-by: Marc Zyngier <maz@kernel.org>
16
Message-id: 20191003154640.22451-4-eric.auger@redhat.com
17
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
18
---
9
---
19
target/arm/kvm.c | 10 +++++++++-
10
linux-user/aarch64/signal.c | 10 ++++++++--
20
1 file changed, 9 insertions(+), 1 deletion(-)
11
1 file changed, 8 insertions(+), 2 deletions(-)
21
12
22
diff --git a/target/arm/kvm.c b/target/arm/kvm.c
13
diff --git a/linux-user/aarch64/signal.c b/linux-user/aarch64/signal.c
23
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
24
--- a/target/arm/kvm.c
15
--- a/linux-user/aarch64/signal.c
25
+++ b/target/arm/kvm.c
16
+++ b/linux-user/aarch64/signal.c
26
@@ -XXX,XX +XXX,XX @@ int kvm_arm_get_max_vm_ipa_size(MachineState *ms)
17
@@ -XXX,XX +XXX,XX @@ static void target_setup_frame(int usig, struct target_sigaction *ka,
27
18
+ offsetof(struct target_rt_frame_record, tramp);
28
int kvm_arch_init(MachineState *ms, KVMState *s)
19
}
29
{
20
env->xregs[0] = usig;
30
+ int ret = 0;
21
- env->xregs[31] = frame_addr;
31
/* For ARM interrupt delivery is always asynchronous,
22
env->xregs[29] = frame_addr + fr_ofs;
32
* whether we are using an in-kernel VGIC or not.
23
- env->pc = ka->_sa_handler;
33
*/
24
env->xregs[30] = return_addr;
34
@@ -XXX,XX +XXX,XX @@ int kvm_arch_init(MachineState *ms, KVMState *s)
25
+ env->xregs[31] = frame_addr;
35
26
+ env->pc = ka->_sa_handler;
36
cap_has_mp_state = kvm_check_extension(s, KVM_CAP_MP_STATE);
27
+
37
28
+ /* Invoke the signal handler as if by indirect call. */
38
- return 0;
29
+ if (cpu_isar_feature(aa64_bti, env_archcpu(env))) {
39
+ if (ms->smp.cpus > 256 &&
30
+ env->btype = 2;
40
+ !kvm_check_extension(s, KVM_CAP_ARM_IRQ_LINE_LAYOUT_2)) {
41
+ error_report("Using more than 256 vcpus requires a host kernel "
42
+ "with KVM_CAP_ARM_IRQ_LINE_LAYOUT_2");
43
+ ret = -EINVAL;
44
+ }
31
+ }
45
+
32
+
46
+ return ret;
33
if (info) {
47
}
34
tswap_siginfo(&frame->info, info);
48
35
env->xregs[1] = frame_addr + offsetof(struct target_rt_sigframe, info);
49
unsigned long kvm_arch_vcpu_id(CPUState *cpu)
50
--
36
--
51
2.20.1
37
2.20.1
52
38
53
39
diff view generated by jsdifflib
1
From: Cédric Le Goater <clg@kaod.org>
1
From: Richard Henderson <richard.henderson@linaro.org>
2
2
3
Signed-off-by: Cédric Le Goater <clg@kaod.org>
3
Transform the prot bit to a qemu internal page bit, and save
4
Reviewed-by: Joel Stanley <joel@jms.id.au>
4
it in the page tables.
5
Message-id: 20190925143248.10000-21-clg@kaod.org
5
6
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
7
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
8
Message-id: 20201021173749.111103-3-richard.henderson@linaro.org
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
---
10
---
8
include/hw/arm/aspeed.h | 1 +
11
include/exec/cpu-all.h | 2 ++
9
hw/arm/aspeed.c | 23 +++++++++++++++++++++++
12
linux-user/syscall_defs.h | 4 ++++
10
2 files changed, 24 insertions(+)
13
target/arm/cpu.h | 5 +++++
14
linux-user/mmap.c | 16 ++++++++++++++++
15
target/arm/translate-a64.c | 6 +++---
16
5 files changed, 30 insertions(+), 3 deletions(-)
11
17
12
diff --git a/include/hw/arm/aspeed.h b/include/hw/arm/aspeed.h
18
diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
13
index XXXXXXX..XXXXXXX 100644
19
index XXXXXXX..XXXXXXX 100644
14
--- a/include/hw/arm/aspeed.h
20
--- a/include/exec/cpu-all.h
15
+++ b/include/hw/arm/aspeed.h
21
+++ b/include/exec/cpu-all.h
16
@@ -XXX,XX +XXX,XX @@ typedef struct AspeedBoardConfig {
22
@@ -XXX,XX +XXX,XX @@ extern intptr_t qemu_host_page_mask;
17
const char *desc;
23
/* FIXME: Code that sets/uses this is broken and needs to go away. */
18
const char *soc_name;
24
#define PAGE_RESERVED 0x0020
19
uint32_t hw_strap1;
25
#endif
20
+ uint32_t hw_strap2;
26
+/* Target-specific bits that will be used via page_get_flags(). */
21
const char *fmc_model;
27
+#define PAGE_TARGET_1 0x0080
22
const char *spi_model;
28
23
uint32_t num_cs;
29
#if defined(CONFIG_USER_ONLY)
24
diff --git a/hw/arm/aspeed.c b/hw/arm/aspeed.c
30
void page_dump(FILE *f);
31
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
25
index XXXXXXX..XXXXXXX 100644
32
index XXXXXXX..XXXXXXX 100644
26
--- a/hw/arm/aspeed.c
33
--- a/linux-user/syscall_defs.h
27
+++ b/hw/arm/aspeed.c
34
+++ b/linux-user/syscall_defs.h
28
@@ -XXX,XX +XXX,XX @@ struct AspeedBoardState {
35
@@ -XXX,XX +XXX,XX @@ struct target_winsize {
29
/* Witherspoon hardware value: 0xF10AD216 (but use romulus definition) */
36
#define TARGET_PROT_SEM 0x08
30
#define WITHERSPOON_BMC_HW_STRAP1 ROMULUS_BMC_HW_STRAP1
37
#endif
31
38
32
+/* AST2600 evb hardware value */
39
+#ifdef TARGET_AARCH64
33
+#define AST2600_EVB_HW_STRAP1 0x000000C0
40
+#define TARGET_PROT_BTI 0x10
34
+#define AST2600_EVB_HW_STRAP2 0x00000003
41
+#endif
42
+
43
/* Common */
44
#define TARGET_MAP_SHARED    0x01        /* Share changes */
45
#define TARGET_MAP_PRIVATE    0x02        /* Changes are private */
46
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
47
index XXXXXXX..XXXXXXX 100644
48
--- a/target/arm/cpu.h
49
+++ b/target/arm/cpu.h
50
@@ -XXX,XX +XXX,XX @@ static inline MemTxAttrs *typecheck_memtxattrs(MemTxAttrs *x)
51
#define arm_tlb_bti_gp(x) (typecheck_memtxattrs(x)->target_tlb_bit0)
52
#define arm_tlb_mte_tagged(x) (typecheck_memtxattrs(x)->target_tlb_bit1)
53
54
+/*
55
+ * AArch64 usage of the PAGE_TARGET_* bits for linux-user.
56
+ */
57
+#define PAGE_BTI PAGE_TARGET_1
35
+
58
+
36
/*
59
/*
37
* The max ram region is for firmwares that scan the address space
60
* Naming convention for isar_feature functions:
38
* with load/store to guess how much RAM the SoC has.
61
* Functions which test 32-bit ID registers should have _aa32_ in
39
@@ -XXX,XX +XXX,XX @@ static void aspeed_board_init(MachineState *machine,
62
diff --git a/linux-user/mmap.c b/linux-user/mmap.c
40
&error_abort);
63
index XXXXXXX..XXXXXXX 100644
41
object_property_set_int(OBJECT(&bmc->soc), cfg->hw_strap1, "hw-strap1",
64
--- a/linux-user/mmap.c
42
&error_abort);
65
+++ b/linux-user/mmap.c
43
+ object_property_set_int(OBJECT(&bmc->soc), cfg->hw_strap2, "hw-strap2",
66
@@ -XXX,XX +XXX,XX @@ static int validate_prot_to_pageflags(int *host_prot, int prot)
44
+ &error_abort);
67
*host_prot = (prot & (PROT_READ | PROT_WRITE))
45
object_property_set_int(OBJECT(&bmc->soc), cfg->num_cs, "num-cs",
68
| (prot & PROT_EXEC ? PROT_READ : 0);
46
&error_abort);
69
47
object_property_set_int(OBJECT(&bmc->soc), machine->smp.cpus, "num-cpus",
70
+#ifdef TARGET_AARCH64
48
@@ -XXX,XX +XXX,XX @@ static void ast2500_evb_i2c_init(AspeedBoardState *bmc)
71
+ /*
49
i2c_create_slave(aspeed_i2c_get_bus(DEVICE(&soc->i2c), 11), "ds1338", 0x32);
72
+ * The PROT_BTI bit is only accepted if the cpu supports the feature.
73
+ * Since this is the unusual case, don't bother checking unless
74
+ * the bit has been requested. If set and valid, record the bit
75
+ * within QEMU's page_flags.
76
+ */
77
+ if (prot & TARGET_PROT_BTI) {
78
+ ARMCPU *cpu = ARM_CPU(thread_cpu);
79
+ if (cpu_isar_feature(aa64_bti, cpu)) {
80
+ valid |= TARGET_PROT_BTI;
81
+ page_flags |= PAGE_BTI;
82
+ }
83
+ }
84
+#endif
85
+
86
return prot & ~valid ? 0 : page_flags;
50
}
87
}
51
88
52
+static void ast2600_evb_i2c_init(AspeedBoardState *bmc)
89
diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c
53
+{
90
index XXXXXXX..XXXXXXX 100644
54
+ /* Start with some devices on our I2C busses */
91
--- a/target/arm/translate-a64.c
55
+ ast2500_evb_i2c_init(bmc);
92
+++ b/target/arm/translate-a64.c
56
+}
93
@@ -XXX,XX +XXX,XX @@ static void disas_data_proc_simd_fp(DisasContext *s, uint32_t insn)
57
+
94
*/
58
static void romulus_bmc_i2c_init(AspeedBoardState *bmc)
95
static bool is_guarded_page(CPUARMState *env, DisasContext *s)
59
{
96
{
60
AspeedSoCState *soc = &bmc->soc;
97
-#ifdef CONFIG_USER_ONLY
61
@@ -XXX,XX +XXX,XX @@ static const AspeedBoardConfig aspeed_boards[] = {
98
- return false; /* FIXME */
62
.num_cs = 2,
99
-#else
63
.i2c_init = witherspoon_bmc_i2c_init,
100
uint64_t addr = s->base.pc_first;
64
.ram = 512 * MiB,
101
+#ifdef CONFIG_USER_ONLY
65
+ }, {
102
+ return page_get_flags(addr) & PAGE_BTI;
66
+ .name = MACHINE_TYPE_NAME("ast2600-evb"),
103
+#else
67
+ .desc = "Aspeed AST2600 EVB (Cortex A7)",
104
int mmu_idx = arm_to_core_mmu_idx(s->mmu_idx);
68
+ .soc_name = "ast2600-a0",
105
unsigned int index = tlb_index(env, mmu_idx, addr);
69
+ .hw_strap1 = AST2600_EVB_HW_STRAP1,
106
CPUTLBEntry *entry = tlb_entry(env, mmu_idx, addr);
70
+ .hw_strap2 = AST2600_EVB_HW_STRAP2,
71
+ .fmc_model = "w25q512jv",
72
+ .spi_model = "mx66u51235f",
73
+ .num_cs = 1,
74
+ .i2c_init = ast2600_evb_i2c_init,
75
+ .ram = 2 * GiB,
76
},
77
};
78
79
--
107
--
80
2.20.1
108
2.20.1
81
109
82
110
diff view generated by jsdifflib
1
Switch the ltick ptimer over to the ptimer transaction API.
1
From: Richard Henderson <richard.henderson@linaro.org>
2
2
3
These are all of the defines required to parse
4
GNU_PROPERTY_AARCH64_FEATURE_1_AND, copied from binutils.
5
Other missing defines related to other GNU program headers
6
and notes are elided for now.
7
8
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
10
Message-id: 20201021173749.111103-4-richard.henderson@linaro.org
3
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
4
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
5
Message-id: 20191008171740.9679-14-peter.maydell@linaro.org
6
---
12
---
7
hw/timer/exynos4210_mct.c | 31 +++++++++++++++++++++++++------
13
include/elf.h | 22 ++++++++++++++++++++++
8
1 file changed, 25 insertions(+), 6 deletions(-)
14
1 file changed, 22 insertions(+)
9
15
10
diff --git a/hw/timer/exynos4210_mct.c b/hw/timer/exynos4210_mct.c
16
diff --git a/include/elf.h b/include/elf.h
11
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
12
--- a/hw/timer/exynos4210_mct.c
18
--- a/include/elf.h
13
+++ b/hw/timer/exynos4210_mct.c
19
+++ b/include/elf.h
14
@@ -XXX,XX +XXX,XX @@
20
@@ -XXX,XX +XXX,XX @@ typedef int64_t Elf64_Sxword;
15
#include "hw/sysbus.h"
21
#define PT_NOTE 4
16
#include "migration/vmstate.h"
22
#define PT_SHLIB 5
17
#include "qemu/timer.h"
23
#define PT_PHDR 6
18
-#include "qemu/main-loop.h"
24
+#define PT_LOOS 0x60000000
19
#include "qemu/module.h"
25
+#define PT_HIOS 0x6fffffff
20
#include "hw/ptimer.h"
26
#define PT_LOPROC 0x70000000
21
27
#define PT_HIPROC 0x7fffffff
22
@@ -XXX,XX +XXX,XX @@ static uint32_t exynos4210_ltick_int_get_cnto(struct tick_timer *s)
28
23
29
+#define PT_GNU_PROPERTY (PT_LOOS + 0x474e553)
24
/*
25
* Start local tick cnt timer.
26
+ * Must be called within exynos4210_ltick_tx_begin/commit block.
27
*/
28
static void exynos4210_ltick_cnt_start(struct tick_timer *s)
29
{
30
@@ -XXX,XX +XXX,XX @@ static void exynos4210_ltick_cnt_start(struct tick_timer *s)
31
32
/*
33
* Stop local tick cnt timer.
34
+ * Must be called within exynos4210_ltick_tx_begin/commit block.
35
*/
36
static void exynos4210_ltick_cnt_stop(struct tick_timer *s)
37
{
38
@@ -XXX,XX +XXX,XX @@ static void exynos4210_ltick_cnt_stop(struct tick_timer *s)
39
}
40
}
41
42
+/* Start ptimer transaction for local tick timer */
43
+static void exynos4210_ltick_tx_begin(struct tick_timer *s)
44
+{
45
+ ptimer_transaction_begin(s->ptimer_tick);
46
+}
47
+
30
+
48
+/* Commit ptimer transaction for local tick timer */
31
#define PT_MIPS_REGINFO 0x70000000
49
+static void exynos4210_ltick_tx_commit(struct tick_timer *s)
32
#define PT_MIPS_RTPROC 0x70000001
50
+{
33
#define PT_MIPS_OPTIONS 0x70000002
51
+ ptimer_transaction_commit(s->ptimer_tick);
34
@@ -XXX,XX +XXX,XX @@ typedef struct elf64_shdr {
52
+}
35
#define NT_ARM_SYSTEM_CALL 0x404 /* ARM system call number */
36
#define NT_ARM_SVE 0x405 /* ARM Scalable Vector Extension regs */
37
38
+/* Defined note types for GNU systems. */
39
+
40
+#define NT_GNU_PROPERTY_TYPE_0 5 /* Program property */
41
+
42
+/* Values used in GNU .note.gnu.property notes (NT_GNU_PROPERTY_TYPE_0). */
43
+
44
+#define GNU_PROPERTY_STACK_SIZE 1
45
+#define GNU_PROPERTY_NO_COPY_ON_PROTECTED 2
46
+
47
+#define GNU_PROPERTY_LOPROC 0xc0000000
48
+#define GNU_PROPERTY_HIPROC 0xdfffffff
49
+#define GNU_PROPERTY_LOUSER 0xe0000000
50
+#define GNU_PROPERTY_HIUSER 0xffffffff
51
+
52
+#define GNU_PROPERTY_AARCH64_FEATURE_1_AND 0xc0000000
53
+#define GNU_PROPERTY_AARCH64_FEATURE_1_BTI (1u << 0)
54
+#define GNU_PROPERTY_AARCH64_FEATURE_1_PAC (1u << 1)
53
+
55
+
54
/*
56
/*
55
* Get counter for CNT timer
57
* Physical entry point into the kernel.
56
*/
58
*
57
@@ -XXX,XX +XXX,XX @@ static uint32_t exynos4210_ltick_cnt_get_cnto(struct tick_timer *s)
58
59
/*
60
* Set new values of counters for CNT and INT timers
61
+ * Must be called within exynos4210_ltick_tx_begin/commit block.
62
*/
63
static void exynos4210_ltick_set_cntb(struct tick_timer *s, uint32_t new_cnt,
64
uint32_t new_int)
65
@@ -XXX,XX +XXX,XX @@ static void exynos4210_ltick_recalc_count(struct tick_timer *s)
66
static void exynos4210_ltick_timer_init(struct tick_timer *s)
67
{
68
exynos4210_ltick_int_stop(s);
69
+ exynos4210_ltick_tx_begin(s);
70
exynos4210_ltick_cnt_stop(s);
71
+ exynos4210_ltick_tx_commit(s);
72
73
s->count = 0;
74
s->distance = 0;
75
@@ -XXX,XX +XXX,XX @@ static void exynos4210_mct_update_freq(Exynos4210MCTState *s)
76
tx_ptimer_set_freq(s->g_timer.ptimer_frc, s->freq);
77
78
/* local timer */
79
- ptimer_set_freq(s->l_timer[0].tick_timer.ptimer_tick, s->freq);
80
+ tx_ptimer_set_freq(s->l_timer[0].tick_timer.ptimer_tick, s->freq);
81
tx_ptimer_set_freq(s->l_timer[0].ptimer_frc, s->freq);
82
- ptimer_set_freq(s->l_timer[1].tick_timer.ptimer_tick, s->freq);
83
+ tx_ptimer_set_freq(s->l_timer[1].tick_timer.ptimer_tick, s->freq);
84
tx_ptimer_set_freq(s->l_timer[1].ptimer_frc, s->freq);
85
}
86
}
87
@@ -XXX,XX +XXX,XX @@ static void exynos4210_mct_write(void *opaque, hwaddr offset,
88
s->l_timer[lt_i].reg.wstat |= L_WSTAT_TCON_WRITE;
89
s->l_timer[lt_i].reg.tcon = value;
90
91
+ exynos4210_ltick_tx_begin(&s->l_timer[lt_i].tick_timer);
92
/* Stop local CNT */
93
if ((value & L_TCON_TICK_START) <
94
(old_val & L_TCON_TICK_START)) {
95
@@ -XXX,XX +XXX,XX @@ static void exynos4210_mct_write(void *opaque, hwaddr offset,
96
DPRINTF("local timer[%d] start int\n", lt_i);
97
exynos4210_ltick_int_start(&s->l_timer[lt_i].tick_timer);
98
}
99
+ exynos4210_ltick_tx_commit(&s->l_timer[lt_i].tick_timer);
100
101
/* Start or Stop local FRC if TCON changed */
102
exynos4210_lfrc_tx_begin(&s->l_timer[lt_i]);
103
@@ -XXX,XX +XXX,XX @@ static void exynos4210_mct_write(void *opaque, hwaddr offset,
104
* Due to this we should reload timer to nearest moment when CNT is
105
* expired and then in event handler update tcntb to new TCNTB value.
106
*/
107
+ exynos4210_ltick_tx_begin(&s->l_timer[lt_i].tick_timer);
108
exynos4210_ltick_set_cntb(&s->l_timer[lt_i].tick_timer, value,
109
s->l_timer[lt_i].tick_timer.icntb);
110
+ exynos4210_ltick_tx_commit(&s->l_timer[lt_i].tick_timer);
111
112
s->l_timer[lt_i].reg.wstat |= L_WSTAT_TCNTB_WRITE;
113
s->l_timer[lt_i].reg.cnt[L_REG_CNT_TCNTB] = value;
114
@@ -XXX,XX +XXX,XX @@ static void exynos4210_mct_init(Object *obj)
115
int i;
116
Exynos4210MCTState *s = EXYNOS4210_MCT(obj);
117
SysBusDevice *dev = SYS_BUS_DEVICE(obj);
118
- QEMUBH *bh[2];
119
120
/* Global timer */
121
s->g_timer.ptimer_frc = ptimer_init(exynos4210_gfrc_event, s,
122
@@ -XXX,XX +XXX,XX @@ static void exynos4210_mct_init(Object *obj)
123
124
/* Local timers */
125
for (i = 0; i < 2; i++) {
126
- bh[0] = qemu_bh_new(exynos4210_ltick_event, &s->l_timer[i]);
127
s->l_timer[i].tick_timer.ptimer_tick =
128
- ptimer_init_with_bh(bh[0], PTIMER_POLICY_DEFAULT);
129
+ ptimer_init(exynos4210_ltick_event, &s->l_timer[i],
130
+ PTIMER_POLICY_DEFAULT);
131
s->l_timer[i].ptimer_frc =
132
ptimer_init(exynos4210_lfrc_event, &s->l_timer[i],
133
PTIMER_POLICY_DEFAULT);
134
--
59
--
135
2.20.1
60
2.20.1
136
61
137
62
diff view generated by jsdifflib
1
From: Joel Stanley <joel@jms.id.au>
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
2
2
3
To support the ast2600's four MACs allow SoCs to specify the number
3
Fix an unlikely memory leak in load_elf_image().
4
they have, and create that many.
5
4
6
Signed-off-by: Joel Stanley <joel@jms.id.au>
5
Fixes: bf858897b7 ("linux-user: Re-use load_elf_image for the main binary.")
7
Signed-off-by: Cédric Le Goater <clg@kaod.org>
6
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
8
Message-id: 20190925143248.10000-22-clg@kaod.org
7
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
9
[clg: - included a check on sc->macs_num when realizing the macs
8
Message-id: 20201021173749.111103-5-richard.henderson@linaro.org
10
- included interrupt definitions for the AST2600 ]
9
Message-Id: <20201003174944.1972444-1-f4bug@amsat.org>
11
Signed-off-by: Cédric Le Goater <clg@kaod.org>
10
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
11
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
---
13
---
14
include/hw/arm/aspeed_soc.h | 5 ++++-
14
linux-user/elfload.c | 8 ++++----
15
hw/arm/aspeed_ast2600.c | 10 ++++++++--
15
1 file changed, 4 insertions(+), 4 deletions(-)
16
hw/arm/aspeed_soc.c | 6 ++++--
17
3 files changed, 16 insertions(+), 5 deletions(-)
18
16
19
diff --git a/include/hw/arm/aspeed_soc.h b/include/hw/arm/aspeed_soc.h
17
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
20
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
21
--- a/include/hw/arm/aspeed_soc.h
19
--- a/linux-user/elfload.c
22
+++ b/include/hw/arm/aspeed_soc.h
20
+++ b/linux-user/elfload.c
23
@@ -XXX,XX +XXX,XX @@
21
@@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd,
24
#define ASPEED_SPIS_NUM 2
22
info->brk = vaddr_em;
25
#define ASPEED_WDTS_NUM 4
23
}
26
#define ASPEED_CPUS_NUM 2
24
} else if (eppnt->p_type == PT_INTERP && pinterp_name) {
27
-#define ASPEED_MACS_NUM 2
25
- char *interp_name;
28
+#define ASPEED_MACS_NUM 4
26
+ g_autofree char *interp_name = NULL;
29
27
30
typedef struct AspeedSoCState {
28
if (*pinterp_name) {
31
/*< private >*/
29
errmsg = "Multiple PT_INTERP entries";
32
@@ -XXX,XX +XXX,XX @@ typedef struct AspeedSoCClass {
30
goto exit_errmsg;
33
uint64_t sram_size;
31
}
34
int spis_num;
32
- interp_name = malloc(eppnt->p_filesz);
35
int wdts_num;
33
+ interp_name = g_malloc(eppnt->p_filesz);
36
+ int macs_num;
34
if (!interp_name) {
37
const int *irqmap;
35
goto exit_perror;
38
const hwaddr *memmap;
36
}
39
uint32_t num_cpus;
37
@@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd,
40
@@ -XXX,XX +XXX,XX @@ enum {
38
errmsg = "Invalid PT_INTERP entry";
41
ASPEED_I2C,
39
goto exit_errmsg;
42
ASPEED_ETH1,
40
}
43
ASPEED_ETH2,
41
- *pinterp_name = interp_name;
44
+ ASPEED_ETH3,
42
+ *pinterp_name = g_steal_pointer(&interp_name);
45
+ ASPEED_ETH4,
43
#ifdef TARGET_MIPS
46
ASPEED_SDRAM,
44
} else if (eppnt->p_type == PT_MIPS_ABIFLAGS) {
47
ASPEED_XDMA,
45
Mips_elf_abiflags_v0 abiflags;
48
};
46
@@ -XXX,XX +XXX,XX @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info)
49
diff --git a/hw/arm/aspeed_ast2600.c b/hw/arm/aspeed_ast2600.c
47
if (elf_interpreter) {
50
index XXXXXXX..XXXXXXX 100644
48
info->load_bias = interp_info.load_bias;
51
--- a/hw/arm/aspeed_ast2600.c
49
info->entry = interp_info.entry;
52
+++ b/hw/arm/aspeed_ast2600.c
50
- free(elf_interpreter);
53
@@ -XXX,XX +XXX,XX @@ static const hwaddr aspeed_soc_ast2600_memmap[] = {
51
+ g_free(elf_interpreter);
54
[ASPEED_SPI1] = 0x1E630000,
55
[ASPEED_SPI2] = 0x1E641000,
56
[ASPEED_ETH1] = 0x1E660000,
57
+ [ASPEED_ETH3] = 0x1E670000,
58
[ASPEED_ETH2] = 0x1E680000,
59
+ [ASPEED_ETH4] = 0x1E690000,
60
[ASPEED_VIC] = 0x1E6C0000,
61
[ASPEED_SDMC] = 0x1E6E0000,
62
[ASPEED_SCU] = 0x1E6E2000,
63
@@ -XXX,XX +XXX,XX @@ static const int aspeed_soc_ast2600_irqmap[] = {
64
[ASPEED_I2C] = 110, /* 110 -> 125 */
65
[ASPEED_ETH1] = 2,
66
[ASPEED_ETH2] = 3,
67
+ [ASPEED_ETH3] = 32,
68
+ [ASPEED_ETH4] = 33,
69
+
70
};
71
72
static qemu_irq aspeed_soc_get_irq(AspeedSoCState *s, int ctrl)
73
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_ast2600_init(Object *obj)
74
OBJECT(&s->scu), &error_abort);
75
}
52
}
76
53
77
- for (i = 0; i < ASPEED_MACS_NUM; i++) {
54
#ifdef USE_ELF_CORE_DUMP
78
+ for (i = 0; i < sc->macs_num; i++) {
79
sysbus_init_child_obj(obj, "ftgmac100[*]", OBJECT(&s->ftgmac100[i]),
80
sizeof(s->ftgmac100[i]), TYPE_FTGMAC100);
81
}
82
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_ast2600_realize(DeviceState *dev, Error **errp)
83
}
84
85
/* Net */
86
- for (i = 0; i < nb_nics; i++) {
87
+ for (i = 0; i < nb_nics && i < sc->macs_num; i++) {
88
qdev_set_nic_properties(DEVICE(&s->ftgmac100[i]), &nd_table[i]);
89
object_property_set_bool(OBJECT(&s->ftgmac100[i]), true, "aspeed",
90
&err);
91
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_ast2600_class_init(ObjectClass *oc, void *data)
92
sc->sram_size = 0x10000;
93
sc->spis_num = 2;
94
sc->wdts_num = 4;
95
+ sc->macs_num = 4;
96
sc->irqmap = aspeed_soc_ast2600_irqmap;
97
sc->memmap = aspeed_soc_ast2600_memmap;
98
sc->num_cpus = 2;
99
diff --git a/hw/arm/aspeed_soc.c b/hw/arm/aspeed_soc.c
100
index XXXXXXX..XXXXXXX 100644
101
--- a/hw/arm/aspeed_soc.c
102
+++ b/hw/arm/aspeed_soc.c
103
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_init(Object *obj)
104
OBJECT(&s->scu), &error_abort);
105
}
106
107
- for (i = 0; i < ASPEED_MACS_NUM; i++) {
108
+ for (i = 0; i < sc->macs_num; i++) {
109
sysbus_init_child_obj(obj, "ftgmac100[*]", OBJECT(&s->ftgmac100[i]),
110
sizeof(s->ftgmac100[i]), TYPE_FTGMAC100);
111
}
112
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
113
}
114
115
/* Net */
116
- for (i = 0; i < nb_nics; i++) {
117
+ for (i = 0; i < nb_nics && i < sc->macs_num; i++) {
118
qdev_set_nic_properties(DEVICE(&s->ftgmac100[i]), &nd_table[i]);
119
object_property_set_bool(OBJECT(&s->ftgmac100[i]), true, "aspeed",
120
&err);
121
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_ast2400_class_init(ObjectClass *oc, void *data)
122
sc->sram_size = 0x8000;
123
sc->spis_num = 1;
124
sc->wdts_num = 2;
125
+ sc->macs_num = 2;
126
sc->irqmap = aspeed_soc_ast2400_irqmap;
127
sc->memmap = aspeed_soc_ast2400_memmap;
128
sc->num_cpus = 1;
129
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_ast2500_class_init(ObjectClass *oc, void *data)
130
sc->sram_size = 0x9000;
131
sc->spis_num = 2;
132
sc->wdts_num = 3;
133
+ sc->macs_num = 2;
134
sc->irqmap = aspeed_soc_ast2500_irqmap;
135
sc->memmap = aspeed_soc_ast2500_memmap;
136
sc->num_cpus = 1;
137
--
55
--
138
2.20.1
56
2.20.1
139
57
140
58
diff view generated by jsdifflib
1
SH_EXT_STDOUT_STDERR is a v2.0 semihosting extension: the guest
1
From: Richard Henderson <richard.henderson@linaro.org>
2
can open ":tt" with a file mode requesting append access in
3
order to open stderr, in addition to the existing "open for
4
read for stdin or write for stdout". Implement this and
5
report it via the :semihosting-features data.
6
2
3
Fixing this now will clarify following patches.
4
5
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
6
Message-id: 20201021173749.111103-6-richard.henderson@linaro.org
7
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
7
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
9
Message-id: 20190916141544.17540-16-peter.maydell@linaro.org
10
---
9
---
11
target/arm/arm-semi.c | 19 +++++++++++++++++--
10
linux-user/elfload.c | 12 +++++++++---
12
1 file changed, 17 insertions(+), 2 deletions(-)
11
1 file changed, 9 insertions(+), 3 deletions(-)
13
12
14
diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c
13
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
15
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
16
--- a/target/arm/arm-semi.c
15
--- a/linux-user/elfload.c
17
+++ b/target/arm/arm-semi.c
16
+++ b/linux-user/elfload.c
18
@@ -XXX,XX +XXX,XX @@ static uint32_t gdb_flenfn(ARMCPU *cpu, GuestFD *gf)
17
@@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd,
19
18
abi_ulong vaddr, vaddr_po, vaddr_ps, vaddr_ef, vaddr_em, vaddr_len;
20
/* Feature bits reportable in feature byte 0 */
19
int elf_prot = 0;
21
#define SH_EXT_EXIT_EXTENDED (1 << 0)
20
22
+#define SH_EXT_STDOUT_STDERR (1 << 1)
21
- if (eppnt->p_flags & PF_R) elf_prot = PROT_READ;
23
22
- if (eppnt->p_flags & PF_W) elf_prot |= PROT_WRITE;
24
static const uint8_t featurefile_data[] = {
23
- if (eppnt->p_flags & PF_X) elf_prot |= PROT_EXEC;
25
SHFB_MAGIC_0,
24
+ if (eppnt->p_flags & PF_R) {
26
SHFB_MAGIC_1,
25
+ elf_prot |= PROT_READ;
27
SHFB_MAGIC_2,
28
SHFB_MAGIC_3,
29
- SH_EXT_EXIT_EXTENDED, /* Feature byte 0 */
30
+ SH_EXT_EXIT_EXTENDED | SH_EXT_STDOUT_STDERR, /* Feature byte 0 */
31
};
32
33
static void init_featurefile_guestfd(int guestfd)
34
@@ -XXX,XX +XXX,XX @@ target_ulong do_arm_semihosting(CPUARMState *env)
35
}
36
37
if (strcmp(s, ":tt") == 0) {
38
- int result_fileno = arg1 < 4 ? STDIN_FILENO : STDOUT_FILENO;
39
+ int result_fileno;
40
+
41
+ /*
42
+ * We implement SH_EXT_STDOUT_STDERR, so:
43
+ * open for read == stdin
44
+ * open for write == stdout
45
+ * open for append == stderr
46
+ */
47
+ if (arg1 < 4) {
48
+ result_fileno = STDIN_FILENO;
49
+ } else if (arg1 < 8) {
50
+ result_fileno = STDOUT_FILENO;
51
+ } else {
52
+ result_fileno = STDERR_FILENO;
53
+ }
26
+ }
54
associate_guestfd(guestfd, result_fileno);
27
+ if (eppnt->p_flags & PF_W) {
55
unlock_user(s, arg0, 0);
28
+ elf_prot |= PROT_WRITE;
56
return guestfd;
29
+ }
30
+ if (eppnt->p_flags & PF_X) {
31
+ elf_prot |= PROT_EXEC;
32
+ }
33
34
vaddr = load_bias + eppnt->p_vaddr;
35
vaddr_po = TARGET_ELF_PAGEOFFSET(vaddr);
57
--
36
--
58
2.20.1
37
2.20.1
59
38
60
39
diff view generated by jsdifflib
1
Switch the mss-timer code away from bottom-half based ptimers to
1
From: Richard Henderson <richard.henderson@linaro.org>
2
the new transaction-based ptimer API. This just requires adding
3
begin/commit calls around the various places that modify the ptimer
4
state, and using the new ptimer_init() function to create the timer.
5
2
3
The second loop uses a loop induction variable, and the first
4
does not. Transform the first to match the second, to simplify
5
a following patch moving code between them.
6
7
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
8
Message-id: 20201021173749.111103-7-richard.henderson@linaro.org
9
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Message-id: 20191008171740.9679-20-peter.maydell@linaro.org
9
---
11
---
10
include/hw/timer/mss-timer.h | 1 -
12
linux-user/elfload.c | 9 +++++----
11
hw/timer/mss-timer.c | 11 ++++++++---
13
1 file changed, 5 insertions(+), 4 deletions(-)
12
2 files changed, 8 insertions(+), 4 deletions(-)
13
14
14
diff --git a/include/hw/timer/mss-timer.h b/include/hw/timer/mss-timer.h
15
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
15
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
16
--- a/include/hw/timer/mss-timer.h
17
--- a/linux-user/elfload.c
17
+++ b/include/hw/timer/mss-timer.h
18
+++ b/linux-user/elfload.c
18
@@ -XXX,XX +XXX,XX @@
19
@@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd,
19
#define R_TIM1_MAX 6
20
loaddr = -1, hiaddr = 0;
20
21
info->alignment = 0;
21
struct Msf2Timer {
22
for (i = 0; i < ehdr->e_phnum; ++i) {
22
- QEMUBH *bh;
23
- if (phdr[i].p_type == PT_LOAD) {
23
ptimer_state *ptimer;
24
- abi_ulong a = phdr[i].p_vaddr - phdr[i].p_offset;
24
25
+ struct elf_phdr *eppnt = phdr + i;
25
uint32_t regs[R_TIM1_MAX];
26
+ if (eppnt->p_type == PT_LOAD) {
26
diff --git a/hw/timer/mss-timer.c b/hw/timer/mss-timer.c
27
+ abi_ulong a = eppnt->p_vaddr - eppnt->p_offset;
27
index XXXXXXX..XXXXXXX 100644
28
if (a < loaddr) {
28
--- a/hw/timer/mss-timer.c
29
loaddr = a;
29
+++ b/hw/timer/mss-timer.c
30
}
30
@@ -XXX,XX +XXX,XX @@
31
- a = phdr[i].p_vaddr + phdr[i].p_memsz;
31
*/
32
+ a = eppnt->p_vaddr + eppnt->p_memsz;
32
33
if (a > hiaddr) {
33
#include "qemu/osdep.h"
34
hiaddr = a;
34
-#include "qemu/main-loop.h"
35
}
35
#include "qemu/module.h"
36
++info->nsegs;
36
#include "qemu/log.h"
37
- info->alignment |= phdr[i].p_align;
37
#include "hw/irq.h"
38
+ info->alignment |= eppnt->p_align;
38
@@ -XXX,XX +XXX,XX @@ static void timer_update_irq(struct Msf2Timer *st)
39
qemu_set_irq(st->irq, (ier && isr));
40
}
41
42
+/* Must be called from within a ptimer_transaction_begin/commit block */
43
static void timer_update(struct Msf2Timer *st)
44
{
45
uint64_t count;
46
@@ -XXX,XX +XXX,XX @@ timer_write(void *opaque, hwaddr offset,
47
switch (addr) {
48
case R_TIM_CTRL:
49
st->regs[R_TIM_CTRL] = value;
50
+ ptimer_transaction_begin(st->ptimer);
51
timer_update(st);
52
+ ptimer_transaction_commit(st->ptimer);
53
break;
54
55
case R_TIM_RIS:
56
@@ -XXX,XX +XXX,XX @@ timer_write(void *opaque, hwaddr offset,
57
case R_TIM_LOADVAL:
58
st->regs[R_TIM_LOADVAL] = value;
59
if (st->regs[R_TIM_CTRL] & TIMER_CTRL_ENBL) {
60
+ ptimer_transaction_begin(st->ptimer);
61
timer_update(st);
62
+ ptimer_transaction_commit(st->ptimer);
63
}
39
}
64
break;
65
66
@@ -XXX,XX +XXX,XX @@ static void mss_timer_init(Object *obj)
67
for (i = 0; i < NUM_TIMERS; i++) {
68
struct Msf2Timer *st = &t->timers[i];
69
70
- st->bh = qemu_bh_new(timer_hit, st);
71
- st->ptimer = ptimer_init_with_bh(st->bh, PTIMER_POLICY_DEFAULT);
72
+ st->ptimer = ptimer_init(timer_hit, st, PTIMER_POLICY_DEFAULT);
73
+ ptimer_transaction_begin(st->ptimer);
74
ptimer_set_freq(st->ptimer, t->freq_hz);
75
+ ptimer_transaction_commit(st->ptimer);
76
sysbus_init_irq(SYS_BUS_DEVICE(obj), &st->irq);
77
}
40
}
78
41
79
--
42
--
80
2.20.1
43
2.20.1
81
44
82
45
diff view generated by jsdifflib
1
From: Cédric Le Goater <clg@kaod.org>
1
From: Richard Henderson <richard.henderson@linaro.org>
2
2
3
AST2600 will use a different encoding for the addresses defined in the
3
For BTI, we need to know if the executable is static or dynamic,
4
Segment Register.
4
which means looking for PT_INTERP earlier.
5
5
6
Signed-off-by: Cédric Le Goater <clg@kaod.org>
6
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
7
Acked-by: Joel Stanley <joel@jms.id.au>
7
Message-id: 20201021173749.111103-8-richard.henderson@linaro.org
8
Message-id: 20190925143248.10000-13-clg@kaod.org
8
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
---
10
---
11
include/hw/ssi/aspeed_smc.h | 4 ++++
11
linux-user/elfload.c | 60 +++++++++++++++++++++++---------------------
12
hw/ssi/aspeed_smc.c | 45 ++++++++++++++++++++++++-------------
12
1 file changed, 31 insertions(+), 29 deletions(-)
13
2 files changed, 34 insertions(+), 15 deletions(-)
14
13
15
diff --git a/include/hw/ssi/aspeed_smc.h b/include/hw/ssi/aspeed_smc.h
14
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
16
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
17
--- a/include/hw/ssi/aspeed_smc.h
16
--- a/linux-user/elfload.c
18
+++ b/include/hw/ssi/aspeed_smc.h
17
+++ b/linux-user/elfload.c
19
@@ -XXX,XX +XXX,XX @@ typedef struct AspeedSMCController {
18
@@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd,
20
hwaddr dma_flash_mask;
19
21
hwaddr dma_dram_mask;
20
mmap_lock();
22
uint32_t nregs;
21
23
+ uint32_t (*segment_to_reg)(const struct AspeedSMCState *s,
22
- /* Find the maximum size of the image and allocate an appropriate
24
+ const AspeedSegments *seg);
23
- amount of memory to handle that. */
25
+ void (*reg_to_segment)(const struct AspeedSMCState *s, uint32_t reg,
24
+ /*
26
+ AspeedSegments *seg);
25
+ * Find the maximum size of the image and allocate an appropriate
27
} AspeedSMCController;
26
+ * amount of memory to handle that. Locate the interpreter, if any.
28
27
+ */
29
typedef struct AspeedSMCFlash {
28
loaddr = -1, hiaddr = 0;
30
diff --git a/hw/ssi/aspeed_smc.c b/hw/ssi/aspeed_smc.c
29
info->alignment = 0;
31
index XXXXXXX..XXXXXXX 100644
30
for (i = 0; i < ehdr->e_phnum; ++i) {
32
--- a/hw/ssi/aspeed_smc.c
31
@@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd,
33
+++ b/hw/ssi/aspeed_smc.c
32
}
34
@@ -XXX,XX +XXX,XX @@ static const AspeedSegments aspeed_segments_ast2500_spi2[] = {
33
++info->nsegs;
35
{ 0x38000000, 32 * 1024 * 1024 }, /* start address is readonly */
34
info->alignment |= eppnt->p_align;
36
{ 0x3A000000, 96 * 1024 * 1024 }, /* end address is readonly */
35
+ } else if (eppnt->p_type == PT_INTERP && pinterp_name) {
37
};
36
+ g_autofree char *interp_name = NULL;
38
+static uint32_t aspeed_smc_segment_to_reg(const AspeedSMCState *s,
37
+
39
+ const AspeedSegments *seg);
38
+ if (*pinterp_name) {
40
+static void aspeed_smc_reg_to_segment(const AspeedSMCState *s, uint32_t reg,
39
+ errmsg = "Multiple PT_INTERP entries";
41
+ AspeedSegments *seg);
40
+ goto exit_errmsg;
42
41
+ }
43
static const AspeedSMCController controllers[] = {
42
+ interp_name = g_malloc(eppnt->p_filesz);
44
{
43
+ if (!interp_name) {
45
@@ -XXX,XX +XXX,XX @@ static const AspeedSMCController controllers[] = {
44
+ goto exit_perror;
46
.flash_window_size = 0x6000000,
45
+ }
47
.has_dma = false,
46
+
48
.nregs = ASPEED_SMC_R_SMC_MAX,
47
+ if (eppnt->p_offset + eppnt->p_filesz <= BPRM_BUF_SIZE) {
49
+ .segment_to_reg = aspeed_smc_segment_to_reg,
48
+ memcpy(interp_name, bprm_buf + eppnt->p_offset,
50
+ .reg_to_segment = aspeed_smc_reg_to_segment,
49
+ eppnt->p_filesz);
51
}, {
50
+ } else {
52
.name = "aspeed.fmc-ast2400",
51
+ retval = pread(image_fd, interp_name, eppnt->p_filesz,
53
.r_conf = R_CONF,
52
+ eppnt->p_offset);
54
@@ -XXX,XX +XXX,XX @@ static const AspeedSMCController controllers[] = {
53
+ if (retval != eppnt->p_filesz) {
55
.dma_flash_mask = 0x0FFFFFFC,
54
+ goto exit_perror;
56
.dma_dram_mask = 0x1FFFFFFC,
55
+ }
57
.nregs = ASPEED_SMC_R_MAX,
56
+ }
58
+ .segment_to_reg = aspeed_smc_segment_to_reg,
57
+ if (interp_name[eppnt->p_filesz - 1] != 0) {
59
+ .reg_to_segment = aspeed_smc_reg_to_segment,
58
+ errmsg = "Invalid PT_INTERP entry";
60
}, {
59
+ goto exit_errmsg;
61
.name = "aspeed.spi1-ast2400",
60
+ }
62
.r_conf = R_SPI_CONF,
61
+ *pinterp_name = g_steal_pointer(&interp_name);
63
@@ -XXX,XX +XXX,XX @@ static const AspeedSMCController controllers[] = {
64
.flash_window_size = 0x10000000,
65
.has_dma = false,
66
.nregs = ASPEED_SMC_R_SPI_MAX,
67
+ .segment_to_reg = aspeed_smc_segment_to_reg,
68
+ .reg_to_segment = aspeed_smc_reg_to_segment,
69
}, {
70
.name = "aspeed.fmc-ast2500",
71
.r_conf = R_CONF,
72
@@ -XXX,XX +XXX,XX @@ static const AspeedSMCController controllers[] = {
73
.dma_flash_mask = 0x0FFFFFFC,
74
.dma_dram_mask = 0x3FFFFFFC,
75
.nregs = ASPEED_SMC_R_MAX,
76
+ .segment_to_reg = aspeed_smc_segment_to_reg,
77
+ .reg_to_segment = aspeed_smc_reg_to_segment,
78
}, {
79
.name = "aspeed.spi1-ast2500",
80
.r_conf = R_CONF,
81
@@ -XXX,XX +XXX,XX @@ static const AspeedSMCController controllers[] = {
82
.flash_window_size = 0x8000000,
83
.has_dma = false,
84
.nregs = ASPEED_SMC_R_MAX,
85
+ .segment_to_reg = aspeed_smc_segment_to_reg,
86
+ .reg_to_segment = aspeed_smc_reg_to_segment,
87
}, {
88
.name = "aspeed.spi2-ast2500",
89
.r_conf = R_CONF,
90
@@ -XXX,XX +XXX,XX @@ static const AspeedSMCController controllers[] = {
91
.flash_window_size = 0x8000000,
92
.has_dma = false,
93
.nregs = ASPEED_SMC_R_MAX,
94
+ .segment_to_reg = aspeed_smc_segment_to_reg,
95
+ .reg_to_segment = aspeed_smc_reg_to_segment,
96
},
97
};
98
99
/*
100
- * The Segment Register uses a 8MB unit to encode the start address
101
- * and the end address of the mapping window of a flash SPI slave :
102
- *
103
- * | byte 1 | byte 2 | byte 3 | byte 4 |
104
- * +--------+--------+--------+--------+
105
- * | end | start | 0 | 0 |
106
- *
107
+ * The Segment Registers of the AST2400 and AST2500 have a 8MB
108
+ * unit. The address range of a flash SPI slave is encoded with
109
+ * absolute addresses which should be part of the overall controller
110
+ * window.
111
*/
112
-static inline uint32_t aspeed_smc_segment_to_reg(const AspeedSegments *seg)
113
+static uint32_t aspeed_smc_segment_to_reg(const AspeedSMCState *s,
114
+ const AspeedSegments *seg)
115
{
116
uint32_t reg = 0;
117
reg |= ((seg->addr >> 23) & SEG_START_MASK) << SEG_START_SHIFT;
118
@@ -XXX,XX +XXX,XX @@ static inline uint32_t aspeed_smc_segment_to_reg(const AspeedSegments *seg)
119
return reg;
120
}
121
122
-static inline void aspeed_smc_reg_to_segment(uint32_t reg, AspeedSegments *seg)
123
+static void aspeed_smc_reg_to_segment(const AspeedSMCState *s,
124
+ uint32_t reg, AspeedSegments *seg)
125
{
126
seg->addr = ((reg >> SEG_START_SHIFT) & SEG_START_MASK) << 23;
127
seg->size = (((reg >> SEG_END_SHIFT) & SEG_END_MASK) << 23) - seg->addr;
128
@@ -XXX,XX +XXX,XX @@ static bool aspeed_smc_flash_overlap(const AspeedSMCState *s,
129
continue;
130
}
62
}
131
132
- aspeed_smc_reg_to_segment(s->regs[R_SEG_ADDR0 + i], &seg);
133
+ s->ctrl->reg_to_segment(s, s->regs[R_SEG_ADDR0 + i], &seg);
134
135
if (new->addr + new->size > seg.addr &&
136
new->addr < seg.addr + seg.size) {
137
@@ -XXX,XX +XXX,XX @@ static void aspeed_smc_flash_set_segment(AspeedSMCState *s, int cs,
138
AspeedSMCFlash *fl = &s->flashes[cs];
139
AspeedSegments seg;
140
141
- aspeed_smc_reg_to_segment(new, &seg);
142
+ s->ctrl->reg_to_segment(s, new, &seg);
143
144
/* The start address of CS0 is read-only */
145
if (cs == 0 && seg.addr != s->ctrl->flash_window_base) {
146
@@ -XXX,XX +XXX,XX @@ static void aspeed_smc_flash_set_segment(AspeedSMCState *s, int cs,
147
"%s: Tried to change CS0 start address to 0x%"
148
HWADDR_PRIx "\n", s->ctrl->name, seg.addr);
149
seg.addr = s->ctrl->flash_window_base;
150
- new = aspeed_smc_segment_to_reg(&seg);
151
+ new = s->ctrl->segment_to_reg(s, &seg);
152
}
63
}
153
64
154
/*
65
@@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd,
155
@@ -XXX,XX +XXX,XX @@ static void aspeed_smc_flash_set_segment(AspeedSMCState *s, int cs,
66
if (vaddr_em > info->brk) {
156
HWADDR_PRIx "\n", s->ctrl->name, cs, seg.addr + seg.size);
67
info->brk = vaddr_em;
157
seg.size = s->ctrl->segments[cs].addr + s->ctrl->segments[cs].size -
68
}
158
seg.addr;
69
- } else if (eppnt->p_type == PT_INTERP && pinterp_name) {
159
- new = aspeed_smc_segment_to_reg(&seg);
70
- g_autofree char *interp_name = NULL;
160
+ new = s->ctrl->segment_to_reg(s, &seg);
71
-
161
}
72
- if (*pinterp_name) {
162
73
- errmsg = "Multiple PT_INTERP entries";
163
/* Keep the segment in the overall flash window */
74
- goto exit_errmsg;
164
@@ -XXX,XX +XXX,XX @@ static uint32_t aspeed_smc_check_segment_addr(const AspeedSMCFlash *fl,
75
- }
165
const AspeedSMCState *s = fl->controller;
76
- interp_name = g_malloc(eppnt->p_filesz);
166
AspeedSegments seg;
77
- if (!interp_name) {
167
78
- goto exit_perror;
168
- aspeed_smc_reg_to_segment(s->regs[R_SEG_ADDR0 + fl->id], &seg);
79
- }
169
+ s->ctrl->reg_to_segment(s, s->regs[R_SEG_ADDR0 + fl->id], &seg);
80
-
170
if ((addr % seg.size) != addr) {
81
- if (eppnt->p_offset + eppnt->p_filesz <= BPRM_BUF_SIZE) {
171
qemu_log_mask(LOG_GUEST_ERROR,
82
- memcpy(interp_name, bprm_buf + eppnt->p_offset,
172
"%s: invalid address 0x%08x for CS%d segment : "
83
- eppnt->p_filesz);
173
@@ -XXX,XX +XXX,XX @@ static void aspeed_smc_reset(DeviceState *d)
84
- } else {
174
/* setup default segment register values for all */
85
- retval = pread(image_fd, interp_name, eppnt->p_filesz,
175
for (i = 0; i < s->ctrl->max_slaves; ++i) {
86
- eppnt->p_offset);
176
s->regs[R_SEG_ADDR0 + i] =
87
- if (retval != eppnt->p_filesz) {
177
- aspeed_smc_segment_to_reg(&s->ctrl->segments[i]);
88
- goto exit_perror;
178
+ s->ctrl->segment_to_reg(s, &s->ctrl->segments[i]);
89
- }
179
}
90
- }
180
91
- if (interp_name[eppnt->p_filesz - 1] != 0) {
181
/* HW strapping flash type for FMC controllers */
92
- errmsg = "Invalid PT_INTERP entry";
93
- goto exit_errmsg;
94
- }
95
- *pinterp_name = g_steal_pointer(&interp_name);
96
#ifdef TARGET_MIPS
97
} else if (eppnt->p_type == PT_MIPS_ABIFLAGS) {
98
Mips_elf_abiflags_v0 abiflags;
182
--
99
--
183
2.20.1
100
2.20.1
184
101
185
102
diff view generated by jsdifflib
1
Switch the imx_epit.c code away from bottom-half based ptimers to
1
From: Richard Henderson <richard.henderson@linaro.org>
2
the new transaction-based ptimer API. This just requires adding
3
begin/commit calls around the various places that modify the ptimer
4
state, and using the new ptimer_init() function to create the timer.
5
2
3
This is a bit clearer than open-coding some of this
4
with a bare c string.
5
6
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
7
Message-id: 20201021173749.111103-9-richard.henderson@linaro.org
8
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Message-id: 20191008171740.9679-19-peter.maydell@linaro.org
9
---
10
---
10
hw/timer/imx_gpt.c | 21 +++++++++++++++++----
11
linux-user/elfload.c | 37 ++++++++++++++++++++-----------------
11
1 file changed, 17 insertions(+), 4 deletions(-)
12
1 file changed, 20 insertions(+), 17 deletions(-)
12
13
13
diff --git a/hw/timer/imx_gpt.c b/hw/timer/imx_gpt.c
14
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
14
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
15
--- a/hw/timer/imx_gpt.c
16
--- a/linux-user/elfload.c
16
+++ b/hw/timer/imx_gpt.c
17
+++ b/linux-user/elfload.c
17
@@ -XXX,XX +XXX,XX @@
18
@@ -XXX,XX +XXX,XX @@
18
#include "hw/irq.h"
19
#include "qemu/guest-random.h"
19
#include "hw/timer/imx_gpt.h"
20
#include "qemu/units.h"
20
#include "migration/vmstate.h"
21
#include "qemu/selfmap.h"
21
-#include "qemu/main-loop.h"
22
+#include "qapi/error.h"
22
#include "qemu/module.h"
23
23
#include "qemu/log.h"
24
#ifdef _ARCH_PPC64
24
25
#undef ARCH_DLINFO
25
@@ -XXX,XX +XXX,XX @@ static const IMXClk imx7_gpt_clocks[] = {
26
@@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd,
26
CLK_NONE, /* 111 not defined */
27
struct elf_phdr *phdr;
27
};
28
abi_ulong load_addr, load_bias, loaddr, hiaddr, error;
28
29
int i, retval;
29
+/* Must be called from within ptimer_transaction_begin/commit block */
30
- const char *errmsg;
30
static void imx_gpt_set_freq(IMXGPTState *s)
31
+ Error *err = NULL;
31
{
32
32
uint32_t clksrc = extract32(s->cr, GPT_CR_CLKSRC_SHIFT, 3);
33
/* First of all, some simple consistency checks */
33
@@ -XXX,XX +XXX,XX @@ static inline uint32_t imx_gpt_find_limit(uint32_t count, uint32_t reg,
34
- errmsg = "Invalid ELF image for this architecture";
34
return timeout;
35
if (!elf_check_ident(ehdr)) {
35
}
36
+ error_setg(&err, "Invalid ELF image for this architecture");
36
37
goto exit_errmsg;
37
+/* Must be called from within ptimer_transaction_begin/commit block */
38
static void imx_gpt_compute_next_timeout(IMXGPTState *s, bool event)
39
{
40
uint32_t timeout = GPT_TIMER_MAX;
41
@@ -XXX,XX +XXX,XX @@ static uint64_t imx_gpt_read(void *opaque, hwaddr offset, unsigned size)
42
43
static void imx_gpt_reset_common(IMXGPTState *s, bool is_soft_reset)
44
{
45
+ ptimer_transaction_begin(s->timer);
46
/* stop timer */
47
ptimer_stop(s->timer);
48
49
@@ -XXX,XX +XXX,XX @@ static void imx_gpt_reset_common(IMXGPTState *s, bool is_soft_reset)
50
if (s->freq && (s->cr & GPT_CR_EN)) {
51
ptimer_run(s->timer, 1);
52
}
38
}
53
+ ptimer_transaction_commit(s->timer);
39
bswap_ehdr(ehdr);
54
}
40
if (!elf_check_ehdr(ehdr)) {
55
41
+ error_setg(&err, "Invalid ELF image for this architecture");
56
static void imx_gpt_soft_reset(DeviceState *dev)
42
goto exit_errmsg;
57
@@ -XXX,XX +XXX,XX @@ static void imx_gpt_write(void *opaque, hwaddr offset, uint64_t value,
43
}
58
imx_gpt_soft_reset(DEVICE(s));
44
59
} else {
45
@@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd,
60
/* set our freq, as the source might have changed */
46
g_autofree char *interp_name = NULL;
61
+ ptimer_transaction_begin(s->timer);
47
62
imx_gpt_set_freq(s);
48
if (*pinterp_name) {
63
49
- errmsg = "Multiple PT_INTERP entries";
64
if ((oldreg ^ s->cr) & GPT_CR_EN) {
50
+ error_setg(&err, "Multiple PT_INTERP entries");
65
@@ -XXX,XX +XXX,XX @@ static void imx_gpt_write(void *opaque, hwaddr offset, uint64_t value,
51
goto exit_errmsg;
66
ptimer_stop(s->timer);
52
}
53
+
54
interp_name = g_malloc(eppnt->p_filesz);
55
- if (!interp_name) {
56
- goto exit_perror;
57
- }
58
59
if (eppnt->p_offset + eppnt->p_filesz <= BPRM_BUF_SIZE) {
60
memcpy(interp_name, bprm_buf + eppnt->p_offset,
61
@@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd,
62
retval = pread(image_fd, interp_name, eppnt->p_filesz,
63
eppnt->p_offset);
64
if (retval != eppnt->p_filesz) {
65
- goto exit_perror;
66
+ goto exit_read;
67
}
67
}
68
}
68
}
69
+ ptimer_transaction_commit(s->timer);
69
if (interp_name[eppnt->p_filesz - 1] != 0) {
70
}
70
- errmsg = "Invalid PT_INTERP entry";
71
break;
71
+ error_setg(&err, "Invalid PT_INTERP entry");
72
72
goto exit_errmsg;
73
case 1: /* Prescaler */
73
}
74
s->pr = value & 0xfff;
74
*pinterp_name = g_steal_pointer(&interp_name);
75
+ ptimer_transaction_begin(s->timer);
75
@@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd,
76
imx_gpt_set_freq(s);
76
(ehdr->e_type == ET_EXEC ? MAP_FIXED : 0),
77
+ ptimer_transaction_commit(s->timer);
77
-1, 0);
78
break;
78
if (load_addr == -1) {
79
79
- goto exit_perror;
80
case 2: /* SR */
80
+ goto exit_mmap;
81
@@ -XXX,XX +XXX,XX @@ static void imx_gpt_write(void *opaque, hwaddr offset, uint64_t value,
81
}
82
s->ir = value & 0x3f;
82
load_bias = load_addr - loaddr;
83
imx_gpt_update_int(s);
83
84
84
@@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd,
85
+ ptimer_transaction_begin(s->timer);
85
image_fd, eppnt->p_offset - vaddr_po);
86
imx_gpt_compute_next_timeout(s, false);
86
87
+ ptimer_transaction_commit(s->timer);
87
if (error == -1) {
88
88
- goto exit_perror;
89
break;
89
+ goto exit_mmap;
90
90
}
91
case 4: /* OCR1 -- output compare register */
91
}
92
s->ocr1 = value;
92
93
93
@@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd,
94
+ ptimer_transaction_begin(s->timer);
94
} else if (eppnt->p_type == PT_MIPS_ABIFLAGS) {
95
/* In non-freerun mode, reset count when this register is written */
95
Mips_elf_abiflags_v0 abiflags;
96
if (!(s->cr & GPT_CR_FRR)) {
96
if (eppnt->p_filesz < sizeof(Mips_elf_abiflags_v0)) {
97
s->next_timeout = GPT_TIMER_MAX;
97
- errmsg = "Invalid PT_MIPS_ABIFLAGS entry";
98
@@ -XXX,XX +XXX,XX @@ static void imx_gpt_write(void *opaque, hwaddr offset, uint64_t value,
98
+ error_setg(&err, "Invalid PT_MIPS_ABIFLAGS entry");
99
99
goto exit_errmsg;
100
/* compute the new timeout */
100
}
101
imx_gpt_compute_next_timeout(s, false);
101
if (eppnt->p_offset + eppnt->p_filesz <= BPRM_BUF_SIZE) {
102
+ ptimer_transaction_commit(s->timer);
102
@@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd,
103
103
retval = pread(image_fd, &abiflags, sizeof(Mips_elf_abiflags_v0),
104
break;
104
eppnt->p_offset);
105
105
if (retval != sizeof(Mips_elf_abiflags_v0)) {
106
@@ -XXX,XX +XXX,XX @@ static void imx_gpt_write(void *opaque, hwaddr offset, uint64_t value,
106
- goto exit_perror;
107
s->ocr2 = value;
107
+ goto exit_read;
108
108
}
109
/* compute the new timeout */
109
}
110
+ ptimer_transaction_begin(s->timer);
110
bswap_mips_abiflags(&abiflags);
111
imx_gpt_compute_next_timeout(s, false);
111
@@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd,
112
+ ptimer_transaction_commit(s->timer);
112
113
113
exit_read:
114
break;
114
if (retval >= 0) {
115
115
- errmsg = "Incomplete read of file header";
116
@@ -XXX,XX +XXX,XX @@ static void imx_gpt_write(void *opaque, hwaddr offset, uint64_t value,
116
- goto exit_errmsg;
117
s->ocr3 = value;
117
+ error_setg(&err, "Incomplete read of file header");
118
118
+ } else {
119
/* compute the new timeout */
119
+ error_setg_errno(&err, errno, "Error reading file header");
120
+ ptimer_transaction_begin(s->timer);
120
}
121
imx_gpt_compute_next_timeout(s, false);
121
- exit_perror:
122
+ ptimer_transaction_commit(s->timer);
122
- errmsg = strerror(errno);
123
123
+ goto exit_errmsg;
124
break;
124
+ exit_mmap:
125
125
+ error_setg_errno(&err, errno, "Error mapping file");
126
@@ -XXX,XX +XXX,XX @@ static void imx_gpt_realize(DeviceState *dev, Error **errp)
126
+ goto exit_errmsg;
127
{
127
exit_errmsg:
128
IMXGPTState *s = IMX_GPT(dev);
128
- fprintf(stderr, "%s: %s\n", image_name, errmsg);
129
SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
129
+ error_reportf_err(err, "%s: ", image_name);
130
- QEMUBH *bh;
130
exit(-1);
131
132
sysbus_init_irq(sbd, &s->irq);
133
memory_region_init_io(&s->iomem, OBJECT(s), &imx_gpt_ops, s, TYPE_IMX_GPT,
134
0x00001000);
135
sysbus_init_mmio(sbd, &s->iomem);
136
137
- bh = qemu_bh_new(imx_gpt_timeout, s);
138
- s->timer = ptimer_init_with_bh(bh, PTIMER_POLICY_DEFAULT);
139
+ s->timer = ptimer_init(imx_gpt_timeout, s, PTIMER_POLICY_DEFAULT);
140
}
131
}
141
132
142
static void imx_gpt_class_init(ObjectClass *klass, void *data)
143
--
133
--
144
2.20.1
134
2.20.1
145
135
146
136
diff view generated by jsdifflib
1
From: Cédric Le Goater <clg@kaod.org>
1
From: Richard Henderson <richard.henderson@linaro.org>
2
2
3
The AST2600 timer replaces control register 2 with a interrupt status
3
This is slightly clearer than just using strerror, though
4
register. It is set by hardware when an IRQ occurs and cleared by
4
the different forms produced by error_setg_file_open and
5
software.
5
error_setg_errno isn't entirely convenient.
6
6
7
Modify the vmstate version to take into account the new fields.
7
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
8
8
Message-id: 20201021173749.111103-10-richard.henderson@linaro.org
9
Based on previous work from Joel Stanley.
9
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
10
11
Signed-off-by: Cédric Le Goater <clg@kaod.org>
12
Reviewed-by: Joel Stanley <joel@jms.id.au>
13
Message-id: 20190925143248.10000-8-clg@kaod.org
14
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
15
---
11
---
16
include/hw/timer/aspeed_timer.h | 1 +
12
linux-user/elfload.c | 15 ++++++++-------
17
hw/timer/aspeed_timer.c | 36 +++++++++++++++++++++++++--------
13
1 file changed, 8 insertions(+), 7 deletions(-)
18
2 files changed, 29 insertions(+), 8 deletions(-)
19
14
20
diff --git a/include/hw/timer/aspeed_timer.h b/include/hw/timer/aspeed_timer.h
15
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
21
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
22
--- a/include/hw/timer/aspeed_timer.h
17
--- a/linux-user/elfload.c
23
+++ b/include/hw/timer/aspeed_timer.h
18
+++ b/linux-user/elfload.c
24
@@ -XXX,XX +XXX,XX @@ typedef struct AspeedTimerCtrlState {
19
@@ -XXX,XX +XXX,XX @@ static void load_elf_interp(const char *filename, struct image_info *info,
25
uint32_t ctrl;
20
char bprm_buf[BPRM_BUF_SIZE])
26
uint32_t ctrl2;
21
{
27
uint32_t ctrl3;
22
int fd, retval;
28
+ uint32_t irq_sts;
23
+ Error *err = NULL;
29
AspeedTimer timers[ASPEED_TIMER_NR_TIMERS];
24
30
25
fd = open(path(filename), O_RDONLY);
31
AspeedSCUState *scu;
26
if (fd < 0) {
32
diff --git a/hw/timer/aspeed_timer.c b/hw/timer/aspeed_timer.c
27
- goto exit_perror;
33
index XXXXXXX..XXXXXXX 100644
28
+ error_setg_file_open(&err, errno, filename);
34
--- a/hw/timer/aspeed_timer.c
29
+ error_report_err(err);
35
+++ b/hw/timer/aspeed_timer.c
30
+ exit(-1);
36
@@ -XXX,XX +XXX,XX @@ static uint64_t calculate_next(struct AspeedTimer *t)
37
timer_del(&t->timer);
38
39
if (timer_overflow_interrupt(t)) {
40
+ AspeedTimerCtrlState *s = timer_to_ctrl(t);
41
t->level = !t->level;
42
+ s->irq_sts |= BIT(t->id);
43
qemu_set_irq(t->irq, t->level);
44
}
31
}
45
32
46
@@ -XXX,XX +XXX,XX @@ static void aspeed_timer_expire(void *opaque)
33
retval = read(fd, bprm_buf, BPRM_BUF_SIZE);
34
if (retval < 0) {
35
- goto exit_perror;
36
+ error_setg_errno(&err, errno, "Error reading file header");
37
+ error_reportf_err(err, "%s: ", filename);
38
+ exit(-1);
47
}
39
}
48
40
+
49
if (interrupt) {
41
if (retval < BPRM_BUF_SIZE) {
50
+ AspeedTimerCtrlState *s = timer_to_ctrl(t);
42
memset(bprm_buf + retval, 0, BPRM_BUF_SIZE - retval);
51
t->level = !t->level;
52
+ s->irq_sts |= BIT(t->id);
53
qemu_set_irq(t->irq, t->level);
54
}
43
}
55
44
56
@@ -XXX,XX +XXX,XX @@ static uint64_t aspeed_timer_read(void *opaque, hwaddr offset, unsigned size)
45
load_elf_image(filename, fd, info, NULL, bprm_buf);
57
case 0x30: /* Control Register */
46
- return;
58
value = s->ctrl;
47
-
59
break;
48
- exit_perror:
60
- case 0x34: /* Control Register 2 */
49
- fprintf(stderr, "%s: %s\n", filename, strerror(errno));
61
- value = s->ctrl2;
50
- exit(-1);
62
- break;
63
case 0x00 ... 0x2c: /* Timers 1 - 4 */
64
value = aspeed_timer_get_value(&s->timers[(offset >> 4)], reg);
65
break;
66
@@ -XXX,XX +XXX,XX @@ static void aspeed_timer_write(void *opaque, hwaddr offset, uint64_t value,
67
case 0x30:
68
aspeed_timer_set_ctrl(s, tv);
69
break;
70
- case 0x34:
71
- aspeed_timer_set_ctrl2(s, tv);
72
- break;
73
/* Timer Registers */
74
case 0x00 ... 0x2c:
75
aspeed_timer_set_value(s, (offset >> TIMER_NR_REGS), reg, tv);
76
@@ -XXX,XX +XXX,XX @@ static uint64_t aspeed_2400_timer_read(AspeedTimerCtrlState *s, hwaddr offset)
77
uint64_t value;
78
79
switch (offset) {
80
+ case 0x34:
81
+ value = s->ctrl2;
82
+ break;
83
case 0x38:
84
case 0x3C:
85
default:
86
@@ -XXX,XX +XXX,XX @@ static uint64_t aspeed_2400_timer_read(AspeedTimerCtrlState *s, hwaddr offset)
87
static void aspeed_2400_timer_write(AspeedTimerCtrlState *s, hwaddr offset,
88
uint64_t value)
89
{
90
+ const uint32_t tv = (uint32_t)(value & 0xFFFFFFFF);
91
+
92
switch (offset) {
93
+ case 0x34:
94
+ aspeed_timer_set_ctrl2(s, tv);
95
+ break;
96
case 0x38:
97
case 0x3C:
98
default:
99
@@ -XXX,XX +XXX,XX @@ static uint64_t aspeed_2500_timer_read(AspeedTimerCtrlState *s, hwaddr offset)
100
uint64_t value;
101
102
switch (offset) {
103
+ case 0x34:
104
+ value = s->ctrl2;
105
+ break;
106
case 0x38:
107
value = s->ctrl3 & BIT(0);
108
break;
109
@@ -XXX,XX +XXX,XX @@ static void aspeed_2500_timer_write(AspeedTimerCtrlState *s, hwaddr offset,
110
uint8_t command;
111
112
switch (offset) {
113
+ case 0x34:
114
+ aspeed_timer_set_ctrl2(s, tv);
115
+ break;
116
case 0x38:
117
command = (value >> 1) & 0xFF;
118
if (command == 0xAE) {
119
@@ -XXX,XX +XXX,XX @@ static uint64_t aspeed_2600_timer_read(AspeedTimerCtrlState *s, hwaddr offset)
120
uint64_t value;
121
122
switch (offset) {
123
+ case 0x34:
124
+ value = s->irq_sts;
125
+ break;
126
case 0x38:
127
case 0x3C:
128
default:
129
@@ -XXX,XX +XXX,XX @@ static void aspeed_2600_timer_write(AspeedTimerCtrlState *s, hwaddr offset,
130
const uint32_t tv = (uint32_t)(value & 0xFFFFFFFF);
131
132
switch (offset) {
133
+ case 0x34:
134
+ s->irq_sts &= tv;
135
+ break;
136
case 0x3C:
137
aspeed_timer_set_ctrl(s, s->ctrl & ~tv);
138
break;
139
@@ -XXX,XX +XXX,XX @@ static void aspeed_timer_reset(DeviceState *dev)
140
s->ctrl = 0;
141
s->ctrl2 = 0;
142
s->ctrl3 = 0;
143
+ s->irq_sts = 0;
144
}
51
}
145
52
146
static const VMStateDescription vmstate_aspeed_timer = {
53
static int symfind(const void *s0, const void *s1)
147
@@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_aspeed_timer = {
148
149
static const VMStateDescription vmstate_aspeed_timer_state = {
150
.name = "aspeed.timerctrl",
151
- .version_id = 1,
152
- .minimum_version_id = 1,
153
+ .version_id = 2,
154
+ .minimum_version_id = 2,
155
.fields = (VMStateField[]) {
156
VMSTATE_UINT32(ctrl, AspeedTimerCtrlState),
157
VMSTATE_UINT32(ctrl2, AspeedTimerCtrlState),
158
VMSTATE_UINT32(ctrl3, AspeedTimerCtrlState),
159
+ VMSTATE_UINT32(irq_sts, AspeedTimerCtrlState),
160
VMSTATE_STRUCT_ARRAY(timers, AspeedTimerCtrlState,
161
ASPEED_TIMER_NR_TIMERS, 1, vmstate_aspeed_timer,
162
AspeedTimer),
163
--
54
--
164
2.20.1
55
2.20.1
165
56
166
57
diff view generated by jsdifflib
1
Factor out the implementation of SYS_SEEK via the new function
1
From: Richard Henderson <richard.henderson@linaro.org>
2
tables.
2
3
3
This is generic support, with the code disabled for all targets.
4
5
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
6
Message-id: 20201021173749.111103-11-richard.henderson@linaro.org
7
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
4
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
5
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
6
Message-id: 20190916141544.17540-12-peter.maydell@linaro.org
7
---
9
---
8
target/arm/arm-semi.c | 31 ++++++++++++++++++++++---------
10
linux-user/qemu.h | 4 ++
9
1 file changed, 22 insertions(+), 9 deletions(-)
11
linux-user/elfload.c | 157 +++++++++++++++++++++++++++++++++++++++++++
10
12
2 files changed, 161 insertions(+)
11
diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c
13
14
diff --git a/linux-user/qemu.h b/linux-user/qemu.h
12
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
13
--- a/target/arm/arm-semi.c
16
--- a/linux-user/qemu.h
14
+++ b/target/arm/arm-semi.c
17
+++ b/linux-user/qemu.h
15
@@ -XXX,XX +XXX,XX @@ typedef uint32_t sys_writefn(ARMCPU *cpu, GuestFD *gf,
18
@@ -XXX,XX +XXX,XX @@ struct image_info {
16
typedef uint32_t sys_readfn(ARMCPU *cpu, GuestFD *gf,
19
abi_ulong interpreter_loadmap_addr;
17
target_ulong buf, uint32_t len);
20
abi_ulong interpreter_pt_dynamic_addr;
18
typedef uint32_t sys_isattyfn(ARMCPU *cpu, GuestFD *gf);
21
struct image_info *other_info;
19
+typedef uint32_t sys_seekfn(ARMCPU *cpu, GuestFD *gf,
22
+
20
+ target_ulong offset);
23
+ /* For target-specific processing of NT_GNU_PROPERTY_TYPE_0. */
21
24
+ uint32_t note_flags;
22
static uint32_t host_closefn(ARMCPU *cpu, GuestFD *gf)
25
+
26
#ifdef TARGET_MIPS
27
int fp_abi;
28
int interp_fp_abi;
29
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
30
index XXXXXXX..XXXXXXX 100644
31
--- a/linux-user/elfload.c
32
+++ b/linux-user/elfload.c
33
@@ -XXX,XX +XXX,XX @@ static void elf_core_copy_regs(target_elf_gregset_t *regs,
34
35
#include "elf.h"
36
37
+static bool arch_parse_elf_property(uint32_t pr_type, uint32_t pr_datasz,
38
+ const uint32_t *data,
39
+ struct image_info *info,
40
+ Error **errp)
41
+{
42
+ g_assert_not_reached();
43
+}
44
+#define ARCH_USE_GNU_PROPERTY 0
45
+
46
struct exec
23
{
47
{
24
@@ -XXX,XX +XXX,XX @@ static uint32_t host_isattyfn(ARMCPU *cpu, GuestFD *gf)
48
unsigned int a_info; /* Use macros N_MAGIC, etc for access */
25
return isatty(gf->hostfd);
49
@@ -XXX,XX +XXX,XX @@ void probe_guest_base(const char *image_name, abi_ulong guest_loaddr,
50
"@ 0x%" PRIx64 "\n", (uint64_t)guest_base);
26
}
51
}
27
52
28
+static uint32_t host_seekfn(ARMCPU *cpu, GuestFD *gf, target_ulong offset)
53
+enum {
54
+ /* The string "GNU\0" as a magic number. */
55
+ GNU0_MAGIC = const_le32('G' | 'N' << 8 | 'U' << 16),
56
+ NOTE_DATA_SZ = 1 * KiB,
57
+ NOTE_NAME_SZ = 4,
58
+ ELF_GNU_PROPERTY_ALIGN = ELF_CLASS == ELFCLASS32 ? 4 : 8,
59
+};
60
+
61
+/*
62
+ * Process a single gnu_property entry.
63
+ * Return false for error.
64
+ */
65
+static bool parse_elf_property(const uint32_t *data, int *off, int datasz,
66
+ struct image_info *info, bool have_prev_type,
67
+ uint32_t *prev_type, Error **errp)
29
+{
68
+{
30
+ CPUARMState *env = &cpu->env;
69
+ uint32_t pr_type, pr_datasz, step;
31
+ uint32_t ret = set_swi_errno(env, lseek(gf->hostfd, offset, SEEK_SET));
70
+
32
+ if (ret == (uint32_t)-1) {
71
+ if (*off > datasz || !QEMU_IS_ALIGNED(*off, ELF_GNU_PROPERTY_ALIGN)) {
33
+ return -1;
72
+ goto error_data;
34
+ }
73
+ }
35
+ return 0;
74
+ datasz -= *off;
75
+ data += *off / sizeof(uint32_t);
76
+
77
+ if (datasz < 2 * sizeof(uint32_t)) {
78
+ goto error_data;
79
+ }
80
+ pr_type = data[0];
81
+ pr_datasz = data[1];
82
+ data += 2;
83
+ datasz -= 2 * sizeof(uint32_t);
84
+ step = ROUND_UP(pr_datasz, ELF_GNU_PROPERTY_ALIGN);
85
+ if (step > datasz) {
86
+ goto error_data;
87
+ }
88
+
89
+ /* Properties are supposed to be unique and sorted on pr_type. */
90
+ if (have_prev_type && pr_type <= *prev_type) {
91
+ if (pr_type == *prev_type) {
92
+ error_setg(errp, "Duplicate property in PT_GNU_PROPERTY");
93
+ } else {
94
+ error_setg(errp, "Unsorted property in PT_GNU_PROPERTY");
95
+ }
96
+ return false;
97
+ }
98
+ *prev_type = pr_type;
99
+
100
+ if (!arch_parse_elf_property(pr_type, pr_datasz, data, info, errp)) {
101
+ return false;
102
+ }
103
+
104
+ *off += 2 * sizeof(uint32_t) + step;
105
+ return true;
106
+
107
+ error_data:
108
+ error_setg(errp, "Ill-formed property in PT_GNU_PROPERTY");
109
+ return false;
36
+}
110
+}
37
+
111
+
38
static uint32_t gdb_closefn(ARMCPU *cpu, GuestFD *gf)
112
+/* Process NT_GNU_PROPERTY_TYPE_0. */
39
{
113
+static bool parse_elf_properties(int image_fd,
40
return arm_gdb_syscall(cpu, arm_semi_cb, "close,%x", gf->hostfd);
114
+ struct image_info *info,
41
@@ -XXX,XX +XXX,XX @@ static uint32_t gdb_isattyfn(ARMCPU *cpu, GuestFD *gf)
115
+ const struct elf_phdr *phdr,
42
return arm_gdb_syscall(cpu, arm_semi_cb, "isatty,%x", gf->hostfd);
116
+ char bprm_buf[BPRM_BUF_SIZE],
43
}
117
+ Error **errp)
44
45
+static uint32_t gdb_seekfn(ARMCPU *cpu, GuestFD *gf, target_ulong offset)
46
+{
118
+{
47
+ return arm_gdb_syscall(cpu, arm_semi_cb, "lseek,%x,%x,0",
119
+ union {
48
+ gf->hostfd, offset);
120
+ struct elf_note nhdr;
121
+ uint32_t data[NOTE_DATA_SZ / sizeof(uint32_t)];
122
+ } note;
123
+
124
+ int n, off, datasz;
125
+ bool have_prev_type;
126
+ uint32_t prev_type;
127
+
128
+ /* Unless the arch requires properties, ignore them. */
129
+ if (!ARCH_USE_GNU_PROPERTY) {
130
+ return true;
131
+ }
132
+
133
+ /* If the properties are crazy large, that's too bad. */
134
+ n = phdr->p_filesz;
135
+ if (n > sizeof(note)) {
136
+ error_setg(errp, "PT_GNU_PROPERTY too large");
137
+ return false;
138
+ }
139
+ if (n < sizeof(note.nhdr)) {
140
+ error_setg(errp, "PT_GNU_PROPERTY too small");
141
+ return false;
142
+ }
143
+
144
+ if (phdr->p_offset + n <= BPRM_BUF_SIZE) {
145
+ memcpy(&note, bprm_buf + phdr->p_offset, n);
146
+ } else {
147
+ ssize_t len = pread(image_fd, &note, n, phdr->p_offset);
148
+ if (len != n) {
149
+ error_setg_errno(errp, errno, "Error reading file header");
150
+ return false;
151
+ }
152
+ }
153
+
154
+ /*
155
+ * The contents of a valid PT_GNU_PROPERTY is a sequence
156
+ * of uint32_t -- swap them all now.
157
+ */
158
+#ifdef BSWAP_NEEDED
159
+ for (int i = 0; i < n / 4; i++) {
160
+ bswap32s(note.data + i);
161
+ }
162
+#endif
163
+
164
+ /*
165
+ * Note that nhdr is 3 words, and that the "name" described by namesz
166
+ * immediately follows nhdr and is thus at the 4th word. Further, all
167
+ * of the inputs to the kernel's round_up are multiples of 4.
168
+ */
169
+ if (note.nhdr.n_type != NT_GNU_PROPERTY_TYPE_0 ||
170
+ note.nhdr.n_namesz != NOTE_NAME_SZ ||
171
+ note.data[3] != GNU0_MAGIC) {
172
+ error_setg(errp, "Invalid note in PT_GNU_PROPERTY");
173
+ return false;
174
+ }
175
+ off = sizeof(note.nhdr) + NOTE_NAME_SZ;
176
+
177
+ datasz = note.nhdr.n_descsz + off;
178
+ if (datasz > n) {
179
+ error_setg(errp, "Invalid note size in PT_GNU_PROPERTY");
180
+ return false;
181
+ }
182
+
183
+ have_prev_type = false;
184
+ prev_type = 0;
185
+ while (1) {
186
+ if (off == datasz) {
187
+ return true; /* end, exit ok */
188
+ }
189
+ if (!parse_elf_property(note.data, &off, datasz, info,
190
+ have_prev_type, &prev_type, errp)) {
191
+ return false;
192
+ }
193
+ have_prev_type = true;
194
+ }
49
+}
195
+}
50
+
196
+
51
typedef struct GuestFDFunctions {
197
/* Load an ELF image into the address space.
52
sys_closefn *closefn;
198
53
sys_writefn *writefn;
199
IMAGE_NAME is the filename of the image, to use in error messages.
54
sys_readfn *readfn;
200
@@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd,
55
sys_isattyfn *isattyfn;
201
goto exit_errmsg;
56
+ sys_seekfn *seekfn;
202
}
57
} GuestFDFunctions;
203
*pinterp_name = g_steal_pointer(&interp_name);
58
204
+ } else if (eppnt->p_type == PT_GNU_PROPERTY) {
59
static const GuestFDFunctions guestfd_fns[] = {
205
+ if (!parse_elf_properties(image_fd, info, eppnt, bprm_buf, &err)) {
60
@@ -XXX,XX +XXX,XX @@ static const GuestFDFunctions guestfd_fns[] = {
206
+ goto exit_errmsg;
61
.writefn = host_writefn,
207
+ }
62
.readfn = host_readfn,
63
.isattyfn = host_isattyfn,
64
+ .seekfn = host_seekfn,
65
},
66
[GuestFDGDB] = {
67
.closefn = gdb_closefn,
68
.writefn = gdb_writefn,
69
.readfn = gdb_readfn,
70
.isattyfn = gdb_isattyfn,
71
+ .seekfn = gdb_seekfn,
72
},
73
};
74
75
@@ -XXX,XX +XXX,XX @@ target_ulong do_arm_semihosting(CPUARMState *env)
76
return set_swi_errno(env, -1);
77
}
208
}
78
209
}
79
- if (use_gdb_syscalls()) {
80
- return arm_gdb_syscall(cpu, arm_semi_cb, "lseek,%x,%x,0",
81
- gf->hostfd, arg1);
82
- } else {
83
- ret = set_swi_errno(env, lseek(gf->hostfd, arg1, SEEK_SET));
84
- if (ret == (uint32_t)-1)
85
- return -1;
86
- return 0;
87
- }
88
+ return guestfd_fns[gf->type].seekfn(cpu, gf, arg1);
89
case TARGET_SYS_FLEN:
90
GET_ARG(0);
91
210
92
--
211
--
93
2.20.1
212
2.20.1
94
213
95
214
diff view generated by jsdifflib
1
The semihosting code needs accuss to the linux-user only
1
From: Richard Henderson <richard.henderson@linaro.org>
2
TaskState pointer so it can set the semihosting errno per-thread
3
for linux-user mode. At the moment we do this by having some
4
ifdefs so that we define a 'ts' local in do_arm_semihosting()
5
which is either a real TaskState * or just a CPUARMState *,
6
depending on which mode we're compiling for.
7
2
8
This is awkward if we want to refactor do_arm_semihosting()
3
Use the new generic support for NT_GNU_PROPERTY_TYPE_0.
9
into other functions which might need to be passed the TaskState.
10
Restrict usage of the TaskState local by:
11
* making set_swi_errno() always take the CPUARMState pointer
12
and (for the linux-user version) get TaskState from that
13
* creating a new get_swi_errno() which reads the errno
14
* having the two semihosting calls which need the TaskState
15
for other purposes (SYS_GET_CMDLINE and SYS_HEAPINFO)
16
define a variable with scope restricted to just that code
17
4
5
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
6
Message-id: 20201021173749.111103-12-richard.henderson@linaro.org
7
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
18
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
19
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
20
Message-id: 20190916141544.17540-6-peter.maydell@linaro.org
21
---
9
---
22
target/arm/arm-semi.c | 111 ++++++++++++++++++++++++------------------
10
linux-user/elfload.c | 48 ++++++++++++++++++++++++++++++++++++++++++--
23
1 file changed, 63 insertions(+), 48 deletions(-)
11
1 file changed, 46 insertions(+), 2 deletions(-)
24
12
25
diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c
13
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
26
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
27
--- a/target/arm/arm-semi.c
15
--- a/linux-user/elfload.c
28
+++ b/target/arm/arm-semi.c
16
+++ b/linux-user/elfload.c
29
@@ -XXX,XX +XXX,XX @@ static GuestFD *get_guestfd(int guestfd)
17
@@ -XXX,XX +XXX,XX @@ static void elf_core_copy_regs(target_elf_gregset_t *regs,
30
return gf;
18
19
#include "elf.h"
20
21
+/* We must delay the following stanzas until after "elf.h". */
22
+#if defined(TARGET_AARCH64)
23
+
24
+static bool arch_parse_elf_property(uint32_t pr_type, uint32_t pr_datasz,
25
+ const uint32_t *data,
26
+ struct image_info *info,
27
+ Error **errp)
28
+{
29
+ if (pr_type == GNU_PROPERTY_AARCH64_FEATURE_1_AND) {
30
+ if (pr_datasz != sizeof(uint32_t)) {
31
+ error_setg(errp, "Ill-formed GNU_PROPERTY_AARCH64_FEATURE_1_AND");
32
+ return false;
33
+ }
34
+ /* We will extract GNU_PROPERTY_AARCH64_FEATURE_1_BTI later. */
35
+ info->note_flags = *data;
36
+ }
37
+ return true;
38
+}
39
+#define ARCH_USE_GNU_PROPERTY 1
40
+
41
+#else
42
+
43
static bool arch_parse_elf_property(uint32_t pr_type, uint32_t pr_datasz,
44
const uint32_t *data,
45
struct image_info *info,
46
@@ -XXX,XX +XXX,XX @@ static bool arch_parse_elf_property(uint32_t pr_type, uint32_t pr_datasz,
31
}
47
}
32
48
#define ARCH_USE_GNU_PROPERTY 0
33
-#ifdef CONFIG_USER_ONLY
49
34
-static inline uint32_t set_swi_errno(TaskState *ts, uint32_t code)
35
-{
36
- if (code == (uint32_t)-1)
37
- ts->swi_errno = errno;
38
- return code;
39
-}
40
-#else
41
+/*
42
+ * The semihosting API has no concept of its errno being thread-safe,
43
+ * as the API design predates SMP CPUs and was intended as a simple
44
+ * real-hardware set of debug functionality. For QEMU, we make the
45
+ * errno be per-thread in linux-user mode; in softmmu it is a simple
46
+ * global, and we assume that the guest takes care of avoiding any races.
47
+ */
48
+#ifndef CONFIG_USER_ONLY
49
static target_ulong syscall_err;
50
51
+#include "exec/softmmu-semi.h"
52
+#endif
50
+#endif
53
+
51
+
54
static inline uint32_t set_swi_errno(CPUARMState *env, uint32_t code)
52
struct exec
55
{
53
{
56
if (code == (uint32_t)-1) {
54
unsigned int a_info; /* Use macros N_MAGIC, etc for access */
57
+#ifdef CONFIG_USER_ONLY
55
@@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd,
58
+ CPUState *cs = env_cpu(env);
56
struct elfhdr *ehdr = (struct elfhdr *)bprm_buf;
59
+ TaskState *ts = cs->opaque;
57
struct elf_phdr *phdr;
58
abi_ulong load_addr, load_bias, loaddr, hiaddr, error;
59
- int i, retval;
60
+ int i, retval, prot_exec;
61
Error *err = NULL;
62
63
/* First of all, some simple consistency checks */
64
@@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd,
65
info->brk = 0;
66
info->elf_flags = ehdr->e_flags;
67
68
+ prot_exec = PROT_EXEC;
69
+#ifdef TARGET_AARCH64
70
+ /*
71
+ * If the BTI feature is present, this indicates that the executable
72
+ * pages of the startup binary should be mapped with PROT_BTI, so that
73
+ * branch targets are enforced.
74
+ *
75
+ * The startup binary is either the interpreter or the static executable.
76
+ * The interpreter is responsible for all pages of a dynamic executable.
77
+ *
78
+ * Elf notes are backward compatible to older cpus.
79
+ * Do not enable BTI unless it is supported.
80
+ */
81
+ if ((info->note_flags & GNU_PROPERTY_AARCH64_FEATURE_1_BTI)
82
+ && (pinterp_name == NULL || *pinterp_name == 0)
83
+ && cpu_isar_feature(aa64_bti, ARM_CPU(thread_cpu))) {
84
+ prot_exec |= TARGET_PROT_BTI;
85
+ }
86
+#endif
60
+
87
+
61
+ ts->swi_errno = errno;
88
for (i = 0; i < ehdr->e_phnum; i++) {
62
+#else
89
struct elf_phdr *eppnt = phdr + i;
63
syscall_err = errno;
90
if (eppnt->p_type == PT_LOAD) {
64
+#endif
91
@@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd,
65
}
92
elf_prot |= PROT_WRITE;
66
return code;
67
}
68
69
-#include "exec/softmmu-semi.h"
70
+static inline uint32_t get_swi_errno(CPUARMState *env)
71
+{
72
+#ifdef CONFIG_USER_ONLY
73
+ CPUState *cs = env_cpu(env);
74
+ TaskState *ts = cs->opaque;
75
+
76
+ return ts->swi_errno;
77
+#else
78
+ return syscall_err;
79
#endif
80
+}
81
82
static target_ulong arm_semi_syscall_len;
83
84
@@ -XXX,XX +XXX,XX @@ static target_ulong arm_gdb_syscall(ARMCPU *cpu, gdb_syscall_complete_cb cb,
85
if (is_a64(env)) { \
86
if (get_user_u64(arg ## n, args + (n) * 8)) { \
87
errno = EFAULT; \
88
- return set_swi_errno(ts, -1); \
89
+ return set_swi_errno(env, -1); \
90
} \
91
} else { \
92
if (get_user_u32(arg ## n, args + (n) * 4)) { \
93
errno = EFAULT; \
94
- return set_swi_errno(ts, -1); \
95
+ return set_swi_errno(env, -1); \
96
} \
97
} \
98
} while (0)
99
@@ -XXX,XX +XXX,XX @@ target_ulong do_arm_semihosting(CPUARMState *env)
100
int nr;
101
uint32_t ret;
102
uint32_t len;
103
-#ifdef CONFIG_USER_ONLY
104
- TaskState *ts = cs->opaque;
105
-#else
106
- CPUARMState *ts = env;
107
-#endif
108
GuestFD *gf;
109
110
if (is_a64(env)) {
111
@@ -XXX,XX +XXX,XX @@ target_ulong do_arm_semihosting(CPUARMState *env)
112
s = lock_user_string(arg0);
113
if (!s) {
114
errno = EFAULT;
115
- return set_swi_errno(ts, -1);
116
+ return set_swi_errno(env, -1);
117
}
118
if (arg1 >= 12) {
119
unlock_user(s, arg0, 0);
120
errno = EINVAL;
121
- return set_swi_errno(ts, -1);
122
+ return set_swi_errno(env, -1);
123
}
124
125
guestfd = alloc_guestfd();
126
if (guestfd < 0) {
127
unlock_user(s, arg0, 0);
128
errno = EMFILE;
129
- return set_swi_errno(ts, -1);
130
+ return set_swi_errno(env, -1);
131
}
132
133
if (strcmp(s, ":tt") == 0) {
134
@@ -XXX,XX +XXX,XX @@ target_ulong do_arm_semihosting(CPUARMState *env)
135
ret = arm_gdb_syscall(cpu, arm_semi_open_cb, "open,%s,%x,1a4", arg0,
136
(int)arg2+1, gdb_open_modeflags[arg1]);
137
} else {
138
- ret = set_swi_errno(ts, open(s, open_modeflags[arg1], 0644));
139
+ ret = set_swi_errno(env, open(s, open_modeflags[arg1], 0644));
140
if (ret == (uint32_t)-1) {
141
dealloc_guestfd(guestfd);
142
} else {
143
@@ -XXX,XX +XXX,XX @@ target_ulong do_arm_semihosting(CPUARMState *env)
144
gf = get_guestfd(arg0);
145
if (!gf) {
146
errno = EBADF;
147
- return set_swi_errno(ts, -1);
148
+ return set_swi_errno(env, -1);
149
}
150
151
if (use_gdb_syscalls()) {
152
ret = arm_gdb_syscall(cpu, arm_semi_cb, "close,%x", gf->hostfd);
153
} else {
154
- ret = set_swi_errno(ts, close(gf->hostfd));
155
+ ret = set_swi_errno(env, close(gf->hostfd));
156
}
157
dealloc_guestfd(arg0);
158
return ret;
159
@@ -XXX,XX +XXX,XX @@ target_ulong do_arm_semihosting(CPUARMState *env)
160
gf = get_guestfd(arg0);
161
if (!gf) {
162
errno = EBADF;
163
- return set_swi_errno(ts, -1);
164
+ return set_swi_errno(env, -1);
165
}
166
167
if (use_gdb_syscalls()) {
168
@@ -XXX,XX +XXX,XX @@ target_ulong do_arm_semihosting(CPUARMState *env)
169
/* Return bytes not written on error */
170
return len;
171
}
93
}
172
- ret = set_swi_errno(ts, write(gf->hostfd, s, len));
94
if (eppnt->p_flags & PF_X) {
173
+ ret = set_swi_errno(env, write(gf->hostfd, s, len));
95
- elf_prot |= PROT_EXEC;
174
unlock_user(s, arg1, 0);
96
+ elf_prot |= prot_exec;
175
if (ret == (uint32_t)-1) {
176
ret = 0;
177
@@ -XXX,XX +XXX,XX @@ target_ulong do_arm_semihosting(CPUARMState *env)
178
gf = get_guestfd(arg0);
179
if (!gf) {
180
errno = EBADF;
181
- return set_swi_errno(ts, -1);
182
+ return set_swi_errno(env, -1);
183
}
184
185
if (use_gdb_syscalls()) {
186
@@ -XXX,XX +XXX,XX @@ target_ulong do_arm_semihosting(CPUARMState *env)
187
return len;
188
}
97
}
189
do {
98
190
- ret = set_swi_errno(ts, read(gf->hostfd, s, len));
99
vaddr = load_bias + eppnt->p_vaddr;
191
+ ret = set_swi_errno(env, read(gf->hostfd, s, len));
192
} while (ret == -1 && errno == EINTR);
193
unlock_user(s, arg1, len);
194
if (ret == (uint32_t)-1) {
195
@@ -XXX,XX +XXX,XX @@ target_ulong do_arm_semihosting(CPUARMState *env)
196
gf = get_guestfd(arg0);
197
if (!gf) {
198
errno = EBADF;
199
- return set_swi_errno(ts, -1);
200
+ return set_swi_errno(env, -1);
201
}
202
203
if (use_gdb_syscalls()) {
204
@@ -XXX,XX +XXX,XX @@ target_ulong do_arm_semihosting(CPUARMState *env)
205
gf = get_guestfd(arg0);
206
if (!gf) {
207
errno = EBADF;
208
- return set_swi_errno(ts, -1);
209
+ return set_swi_errno(env, -1);
210
}
211
212
if (use_gdb_syscalls()) {
213
return arm_gdb_syscall(cpu, arm_semi_cb, "lseek,%x,%x,0",
214
gf->hostfd, arg1);
215
} else {
216
- ret = set_swi_errno(ts, lseek(gf->hostfd, arg1, SEEK_SET));
217
+ ret = set_swi_errno(env, lseek(gf->hostfd, arg1, SEEK_SET));
218
if (ret == (uint32_t)-1)
219
return -1;
220
return 0;
221
@@ -XXX,XX +XXX,XX @@ target_ulong do_arm_semihosting(CPUARMState *env)
222
gf = get_guestfd(arg0);
223
if (!gf) {
224
errno = EBADF;
225
- return set_swi_errno(ts, -1);
226
+ return set_swi_errno(env, -1);
227
}
228
229
if (use_gdb_syscalls()) {
230
@@ -XXX,XX +XXX,XX @@ target_ulong do_arm_semihosting(CPUARMState *env)
231
gf->hostfd, arm_flen_buf(cpu));
232
} else {
233
struct stat buf;
234
- ret = set_swi_errno(ts, fstat(gf->hostfd, &buf));
235
+ ret = set_swi_errno(env, fstat(gf->hostfd, &buf));
236
if (ret == (uint32_t)-1)
237
return -1;
238
return buf.st_size;
239
@@ -XXX,XX +XXX,XX @@ target_ulong do_arm_semihosting(CPUARMState *env)
240
s = lock_user_string(arg0);
241
if (!s) {
242
errno = EFAULT;
243
- return set_swi_errno(ts, -1);
244
+ return set_swi_errno(env, -1);
245
}
246
- ret = set_swi_errno(ts, remove(s));
247
+ ret = set_swi_errno(env, remove(s));
248
unlock_user(s, arg0, 0);
249
}
250
return ret;
251
@@ -XXX,XX +XXX,XX @@ target_ulong do_arm_semihosting(CPUARMState *env)
252
s2 = lock_user_string(arg2);
253
if (!s || !s2) {
254
errno = EFAULT;
255
- ret = set_swi_errno(ts, -1);
256
+ ret = set_swi_errno(env, -1);
257
} else {
258
- ret = set_swi_errno(ts, rename(s, s2));
259
+ ret = set_swi_errno(env, rename(s, s2));
260
}
261
if (s2)
262
unlock_user(s2, arg2, 0);
263
@@ -XXX,XX +XXX,XX @@ target_ulong do_arm_semihosting(CPUARMState *env)
264
case TARGET_SYS_CLOCK:
265
return clock() / (CLOCKS_PER_SEC / 100);
266
case TARGET_SYS_TIME:
267
- return set_swi_errno(ts, time(NULL));
268
+ return set_swi_errno(env, time(NULL));
269
case TARGET_SYS_SYSTEM:
270
GET_ARG(0);
271
GET_ARG(1);
272
@@ -XXX,XX +XXX,XX @@ target_ulong do_arm_semihosting(CPUARMState *env)
273
s = lock_user_string(arg0);
274
if (!s) {
275
errno = EFAULT;
276
- return set_swi_errno(ts, -1);
277
+ return set_swi_errno(env, -1);
278
}
279
- ret = set_swi_errno(ts, system(s));
280
+ ret = set_swi_errno(env, system(s));
281
unlock_user(s, arg0, 0);
282
return ret;
283
}
284
case TARGET_SYS_ERRNO:
285
-#ifdef CONFIG_USER_ONLY
286
- return ts->swi_errno;
287
-#else
288
- return syscall_err;
289
-#endif
290
+ return get_swi_errno(env);
291
case TARGET_SYS_GET_CMDLINE:
292
{
293
/* Build a command-line from the original argv.
294
@@ -XXX,XX +XXX,XX @@ target_ulong do_arm_semihosting(CPUARMState *env)
295
int status = 0;
296
#if !defined(CONFIG_USER_ONLY)
297
const char *cmdline;
298
+#else
299
+ TaskState *ts = cs->opaque;
300
#endif
301
GET_ARG(0);
302
GET_ARG(1);
303
@@ -XXX,XX +XXX,XX @@ target_ulong do_arm_semihosting(CPUARMState *env)
304
if (output_size > input_size) {
305
/* Not enough space to store command-line arguments. */
306
errno = E2BIG;
307
- return set_swi_errno(ts, -1);
308
+ return set_swi_errno(env, -1);
309
}
310
311
/* Adjust the command-line length. */
312
if (SET_ARG(1, output_size - 1)) {
313
/* Couldn't write back to argument block */
314
errno = EFAULT;
315
- return set_swi_errno(ts, -1);
316
+ return set_swi_errno(env, -1);
317
}
318
319
/* Lock the buffer on the ARM side. */
320
output_buffer = lock_user(VERIFY_WRITE, arg0, output_size, 0);
321
if (!output_buffer) {
322
errno = EFAULT;
323
- return set_swi_errno(ts, -1);
324
+ return set_swi_errno(env, -1);
325
}
326
327
/* Copy the command-line arguments. */
328
@@ -XXX,XX +XXX,XX @@ target_ulong do_arm_semihosting(CPUARMState *env)
329
if (copy_from_user(output_buffer, ts->info->arg_start,
330
output_size)) {
331
errno = EFAULT;
332
- status = set_swi_errno(ts, -1);
333
+ status = set_swi_errno(env, -1);
334
goto out;
335
}
336
337
@@ -XXX,XX +XXX,XX @@ target_ulong do_arm_semihosting(CPUARMState *env)
338
target_ulong retvals[4];
339
target_ulong limit;
340
int i;
341
+#ifdef CONFIG_USER_ONLY
342
+ TaskState *ts = cs->opaque;
343
+#endif
344
345
GET_ARG(0);
346
347
@@ -XXX,XX +XXX,XX @@ target_ulong do_arm_semihosting(CPUARMState *env)
348
if (fail) {
349
/* Couldn't write back to argument block */
350
errno = EFAULT;
351
- return set_swi_errno(ts, -1);
352
+ return set_swi_errno(env, -1);
353
}
354
}
355
return 0;
356
--
100
--
357
2.20.1
101
2.20.1
358
102
359
103
diff view generated by jsdifflib
1
From: Cédric Le Goater <clg@kaod.org>
1
From: Richard Henderson <richard.henderson@linaro.org>
2
2
3
Initial definitions for a simple machine using an AST2600 SoC (Cortex
3
The note test requires gcc 10 for -mbranch-protection=standard.
4
CPU).
4
The mmap test uses PROT_BTI and does not require special compiler support.
5
5
6
The Cortex CPU and its interrupt controller are too complex to handle
6
Acked-by: Alex Bennée <alex.bennee@linaro.org>
7
in the common Aspeed SoC framework. We introduce a new Aspeed SoC
7
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
8
class with instance_init and realize handlers to handle the differences
8
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
9
with the AST2400 and the AST2500 SoCs. This will add extra work to
9
Message-id: 20201021173749.111103-13-richard.henderson@linaro.org
10
keep in sync both models with future extensions but it makes the code
11
clearer.
12
13
Signed-off-by: Cédric Le Goater <clg@kaod.org>
14
Reviewed-by: Joel Stanley <joel@jms.id.au>
15
Message-id: 20190925143248.10000-19-clg@kaod.org
16
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
17
---
11
---
18
hw/arm/Makefile.objs | 2 +-
12
tests/tcg/aarch64/bti-1.c | 62 ++++++++++++++++
19
include/hw/arm/aspeed_soc.h | 4 +
13
tests/tcg/aarch64/bti-2.c | 116 ++++++++++++++++++++++++++++++
20
hw/arm/aspeed_ast2600.c | 492 ++++++++++++++++++++++++++++++++++++
14
tests/tcg/aarch64/bti-crt.inc.c | 51 +++++++++++++
21
3 files changed, 497 insertions(+), 1 deletion(-)
15
tests/tcg/aarch64/Makefile.target | 10 +++
22
create mode 100644 hw/arm/aspeed_ast2600.c
16
tests/tcg/configure.sh | 4 ++
23
17
5 files changed, 243 insertions(+)
24
diff --git a/hw/arm/Makefile.objs b/hw/arm/Makefile.objs
18
create mode 100644 tests/tcg/aarch64/bti-1.c
25
index XXXXXXX..XXXXXXX 100644
19
create mode 100644 tests/tcg/aarch64/bti-2.c
26
--- a/hw/arm/Makefile.objs
20
create mode 100644 tests/tcg/aarch64/bti-crt.inc.c
27
+++ b/hw/arm/Makefile.objs
21
28
@@ -XXX,XX +XXX,XX @@ obj-$(CONFIG_XLNX_VERSAL) += xlnx-versal.o xlnx-versal-virt.o
22
diff --git a/tests/tcg/aarch64/bti-1.c b/tests/tcg/aarch64/bti-1.c
29
obj-$(CONFIG_FSL_IMX25) += fsl-imx25.o imx25_pdk.o
30
obj-$(CONFIG_FSL_IMX31) += fsl-imx31.o kzm.o
31
obj-$(CONFIG_FSL_IMX6) += fsl-imx6.o
32
-obj-$(CONFIG_ASPEED_SOC) += aspeed_soc.o aspeed.o
33
+obj-$(CONFIG_ASPEED_SOC) += aspeed_soc.o aspeed.o aspeed_ast2600.o
34
obj-$(CONFIG_MPS2) += mps2.o
35
obj-$(CONFIG_MPS2) += mps2-tz.o
36
obj-$(CONFIG_MSF2) += msf2-soc.o
37
diff --git a/include/hw/arm/aspeed_soc.h b/include/hw/arm/aspeed_soc.h
38
index XXXXXXX..XXXXXXX 100644
39
--- a/include/hw/arm/aspeed_soc.h
40
+++ b/include/hw/arm/aspeed_soc.h
41
@@ -XXX,XX +XXX,XX @@
42
#ifndef ASPEED_SOC_H
43
#define ASPEED_SOC_H
44
45
+#include "hw/cpu/a15mpcore.h"
46
#include "hw/intc/aspeed_vic.h"
47
#include "hw/misc/aspeed_scu.h"
48
#include "hw/misc/aspeed_sdmc.h"
49
@@ -XXX,XX +XXX,XX @@ typedef struct AspeedSoCState {
50
/*< public >*/
51
ARMCPU cpu[ASPEED_CPUS_NUM];
52
uint32_t num_cpus;
53
+ A15MPPrivState a7mpcore;
54
MemoryRegion sram;
55
AspeedVICState vic;
56
AspeedRtcState rtc;
57
@@ -XXX,XX +XXX,XX @@ typedef struct AspeedSoCState {
58
AspeedWDTState wdt[ASPEED_WDTS_NUM];
59
FTGMAC100State ftgmac100[ASPEED_MACS_NUM];
60
AspeedGPIOState gpio;
61
+ AspeedGPIOState gpio_1_8v;
62
AspeedSDHCIState sdhci;
63
} AspeedSoCState;
64
65
@@ -XXX,XX +XXX,XX @@ enum {
66
ASPEED_SRAM,
67
ASPEED_SDHCI,
68
ASPEED_GPIO,
69
+ ASPEED_GPIO_1_8V,
70
ASPEED_RTC,
71
ASPEED_TIMER1,
72
ASPEED_TIMER2,
73
diff --git a/hw/arm/aspeed_ast2600.c b/hw/arm/aspeed_ast2600.c
74
new file mode 100644
23
new file mode 100644
75
index XXXXXXX..XXXXXXX
24
index XXXXXXX..XXXXXXX
76
--- /dev/null
25
--- /dev/null
77
+++ b/hw/arm/aspeed_ast2600.c
26
+++ b/tests/tcg/aarch64/bti-1.c
78
@@ -XXX,XX +XXX,XX @@
27
@@ -XXX,XX +XXX,XX @@
79
+/*
28
+/*
80
+ * ASPEED SoC 2600 family
29
+ * Branch target identification, basic notskip cases.
30
+ */
31
+
32
+#include "bti-crt.inc.c"
33
+
34
+static void skip2_sigill(int sig, siginfo_t *info, ucontext_t *uc)
35
+{
36
+ uc->uc_mcontext.pc += 8;
37
+ uc->uc_mcontext.pstate = 1;
38
+}
39
+
40
+#define NOP "nop"
41
+#define BTI_N "hint #32"
42
+#define BTI_C "hint #34"
43
+#define BTI_J "hint #36"
44
+#define BTI_JC "hint #38"
45
+
46
+#define BTYPE_1(DEST) \
47
+ asm("mov %0,#1; adr x16, 1f; br x16; 1: " DEST "; mov %0,#0" \
48
+ : "=r"(skipped) : : "x16")
49
+
50
+#define BTYPE_2(DEST) \
51
+ asm("mov %0,#1; adr x16, 1f; blr x16; 1: " DEST "; mov %0,#0" \
52
+ : "=r"(skipped) : : "x16", "x30")
53
+
54
+#define BTYPE_3(DEST) \
55
+ asm("mov %0,#1; adr x15, 1f; br x15; 1: " DEST "; mov %0,#0" \
56
+ : "=r"(skipped) : : "x15")
57
+
58
+#define TEST(WHICH, DEST, EXPECT) \
59
+ do { WHICH(DEST); fail += skipped ^ EXPECT; } while (0)
60
+
61
+
62
+int main()
63
+{
64
+ int fail = 0;
65
+ int skipped;
66
+
67
+ /* Signal-like with SA_SIGINFO. */
68
+ signal_info(SIGILL, skip2_sigill);
69
+
70
+ TEST(BTYPE_1, NOP, 1);
71
+ TEST(BTYPE_1, BTI_N, 1);
72
+ TEST(BTYPE_1, BTI_C, 0);
73
+ TEST(BTYPE_1, BTI_J, 0);
74
+ TEST(BTYPE_1, BTI_JC, 0);
75
+
76
+ TEST(BTYPE_2, NOP, 1);
77
+ TEST(BTYPE_2, BTI_N, 1);
78
+ TEST(BTYPE_2, BTI_C, 0);
79
+ TEST(BTYPE_2, BTI_J, 1);
80
+ TEST(BTYPE_2, BTI_JC, 0);
81
+
82
+ TEST(BTYPE_3, NOP, 1);
83
+ TEST(BTYPE_3, BTI_N, 1);
84
+ TEST(BTYPE_3, BTI_C, 1);
85
+ TEST(BTYPE_3, BTI_J, 0);
86
+ TEST(BTYPE_3, BTI_JC, 0);
87
+
88
+ return fail;
89
+}
90
diff --git a/tests/tcg/aarch64/bti-2.c b/tests/tcg/aarch64/bti-2.c
91
new file mode 100644
92
index XXXXXXX..XXXXXXX
93
--- /dev/null
94
+++ b/tests/tcg/aarch64/bti-2.c
95
@@ -XXX,XX +XXX,XX @@
96
+/*
97
+ * Branch target identification, basic notskip cases.
98
+ */
99
+
100
+#include <stdio.h>
101
+#include <signal.h>
102
+#include <string.h>
103
+#include <unistd.h>
104
+#include <sys/mman.h>
105
+
106
+#ifndef PROT_BTI
107
+#define PROT_BTI 0x10
108
+#endif
109
+
110
+static void skip2_sigill(int sig, siginfo_t *info, void *vuc)
111
+{
112
+ ucontext_t *uc = vuc;
113
+ uc->uc_mcontext.pc += 8;
114
+ uc->uc_mcontext.pstate = 1;
115
+}
116
+
117
+#define NOP "nop"
118
+#define BTI_N "hint #32"
119
+#define BTI_C "hint #34"
120
+#define BTI_J "hint #36"
121
+#define BTI_JC "hint #38"
122
+
123
+#define BTYPE_1(DEST) \
124
+ "mov x1, #1\n\t" \
125
+ "adr x16, 1f\n\t" \
126
+ "br x16\n" \
127
+"1: " DEST "\n\t" \
128
+ "mov x1, #0"
129
+
130
+#define BTYPE_2(DEST) \
131
+ "mov x1, #1\n\t" \
132
+ "adr x16, 1f\n\t" \
133
+ "blr x16\n" \
134
+"1: " DEST "\n\t" \
135
+ "mov x1, #0"
136
+
137
+#define BTYPE_3(DEST) \
138
+ "mov x1, #1\n\t" \
139
+ "adr x15, 1f\n\t" \
140
+ "br x15\n" \
141
+"1: " DEST "\n\t" \
142
+ "mov x1, #0"
143
+
144
+#define TEST(WHICH, DEST, EXPECT) \
145
+ WHICH(DEST) "\n" \
146
+ ".if " #EXPECT "\n\t" \
147
+ "eor x1, x1," #EXPECT "\n" \
148
+ ".endif\n\t" \
149
+ "add x0, x0, x1\n\t"
150
+
151
+asm("\n"
152
+"test_begin:\n\t"
153
+ BTI_C "\n\t"
154
+ "mov x2, x30\n\t"
155
+ "mov x0, #0\n\t"
156
+
157
+ TEST(BTYPE_1, NOP, 1)
158
+ TEST(BTYPE_1, BTI_N, 1)
159
+ TEST(BTYPE_1, BTI_C, 0)
160
+ TEST(BTYPE_1, BTI_J, 0)
161
+ TEST(BTYPE_1, BTI_JC, 0)
162
+
163
+ TEST(BTYPE_2, NOP, 1)
164
+ TEST(BTYPE_2, BTI_N, 1)
165
+ TEST(BTYPE_2, BTI_C, 0)
166
+ TEST(BTYPE_2, BTI_J, 1)
167
+ TEST(BTYPE_2, BTI_JC, 0)
168
+
169
+ TEST(BTYPE_3, NOP, 1)
170
+ TEST(BTYPE_3, BTI_N, 1)
171
+ TEST(BTYPE_3, BTI_C, 1)
172
+ TEST(BTYPE_3, BTI_J, 0)
173
+ TEST(BTYPE_3, BTI_JC, 0)
174
+
175
+ "ret x2\n"
176
+"test_end:"
177
+);
178
+
179
+int main()
180
+{
181
+ struct sigaction sa;
182
+ void *tb, *te;
183
+
184
+ void *p = mmap(0, getpagesize(),
185
+ PROT_EXEC | PROT_READ | PROT_WRITE | PROT_BTI,
186
+ MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
187
+ if (p == MAP_FAILED) {
188
+ perror("mmap");
189
+ return 1;
190
+ }
191
+
192
+ memset(&sa, 0, sizeof(sa));
193
+ sa.sa_sigaction = skip2_sigill;
194
+ sa.sa_flags = SA_SIGINFO;
195
+ if (sigaction(SIGILL, &sa, NULL) < 0) {
196
+ perror("sigaction");
197
+ return 1;
198
+ }
199
+
200
+ /*
201
+ * ??? With "extern char test_begin[]", some compiler versions
202
+ * will use :got references, and some linker versions will
203
+ * resolve this reference to a static symbol incorrectly.
204
+ * Bypass this error by using a pc-relative reference directly.
205
+ */
206
+ asm("adr %0, test_begin; adr %1, test_end" : "=r"(tb), "=r"(te));
207
+
208
+ memcpy(p, tb, te - tb);
209
+
210
+ return ((int (*)(void))p)();
211
+}
212
diff --git a/tests/tcg/aarch64/bti-crt.inc.c b/tests/tcg/aarch64/bti-crt.inc.c
213
new file mode 100644
214
index XXXXXXX..XXXXXXX
215
--- /dev/null
216
+++ b/tests/tcg/aarch64/bti-crt.inc.c
217
@@ -XXX,XX +XXX,XX @@
218
+/*
219
+ * Minimal user-environment for testing BTI.
81
+ *
220
+ *
82
+ * Copyright (c) 2016-2019, IBM Corporation.
221
+ * Normal libc is not (yet) built with BTI support enabled,
83
+ *
222
+ * and so could generate a BTI TRAP before ever reaching main.
84
+ * This code is licensed under the GPL version 2 or later. See
85
+ * the COPYING file in the top-level directory.
86
+ */
223
+ */
87
+
224
+
88
+#include "qemu/osdep.h"
225
+#include <stdlib.h>
89
+#include "qapi/error.h"
226
+#include <signal.h>
90
+#include "cpu.h"
227
+#include <ucontext.h>
91
+#include "exec/address-spaces.h"
228
+#include <asm/unistd.h>
92
+#include "hw/misc/unimp.h"
229
+
93
+#include "hw/arm/aspeed_soc.h"
230
+int main(void);
94
+#include "hw/char/serial.h"
231
+
95
+#include "qemu/log.h"
232
+void _start(void)
96
+#include "qemu/module.h"
233
+{
97
+#include "qemu/error-report.h"
234
+ exit(main());
98
+#include "hw/i2c/aspeed_i2c.h"
235
+}
99
+#include "net/net.h"
236
+
100
+#include "sysemu/sysemu.h"
237
+void exit(int ret)
101
+
238
+{
102
+#define ASPEED_SOC_IOMEM_SIZE 0x00200000
239
+ register int x0 __asm__("x0") = ret;
103
+
240
+ register int x8 __asm__("x8") = __NR_exit;
104
+static const hwaddr aspeed_soc_ast2600_memmap[] = {
241
+
105
+ [ASPEED_SRAM] = 0x10000000,
242
+ asm volatile("svc #0" : : "r"(x0), "r"(x8));
106
+ /* 0x16000000 0x17FFFFFF : AHB BUS do LPC Bus bridge */
243
+ __builtin_unreachable();
107
+ [ASPEED_IOMEM] = 0x1E600000,
108
+ [ASPEED_PWM] = 0x1E610000,
109
+ [ASPEED_FMC] = 0x1E620000,
110
+ [ASPEED_SPI1] = 0x1E630000,
111
+ [ASPEED_SPI2] = 0x1E641000,
112
+ [ASPEED_ETH1] = 0x1E660000,
113
+ [ASPEED_ETH2] = 0x1E680000,
114
+ [ASPEED_VIC] = 0x1E6C0000,
115
+ [ASPEED_SDMC] = 0x1E6E0000,
116
+ [ASPEED_SCU] = 0x1E6E2000,
117
+ [ASPEED_XDMA] = 0x1E6E7000,
118
+ [ASPEED_ADC] = 0x1E6E9000,
119
+ [ASPEED_SDHCI] = 0x1E740000,
120
+ [ASPEED_GPIO] = 0x1E780000,
121
+ [ASPEED_GPIO_1_8V] = 0x1E780800,
122
+ [ASPEED_RTC] = 0x1E781000,
123
+ [ASPEED_TIMER1] = 0x1E782000,
124
+ [ASPEED_WDT] = 0x1E785000,
125
+ [ASPEED_LPC] = 0x1E789000,
126
+ [ASPEED_IBT] = 0x1E789140,
127
+ [ASPEED_I2C] = 0x1E78A000,
128
+ [ASPEED_UART1] = 0x1E783000,
129
+ [ASPEED_UART5] = 0x1E784000,
130
+ [ASPEED_VUART] = 0x1E787000,
131
+ [ASPEED_SDRAM] = 0x80000000,
132
+};
133
+
134
+#define ASPEED_A7MPCORE_ADDR 0x40460000
135
+
136
+#define ASPEED_SOC_AST2600_MAX_IRQ 128
137
+
138
+static const int aspeed_soc_ast2600_irqmap[] = {
139
+ [ASPEED_UART1] = 47,
140
+ [ASPEED_UART2] = 48,
141
+ [ASPEED_UART3] = 49,
142
+ [ASPEED_UART4] = 50,
143
+ [ASPEED_UART5] = 8,
144
+ [ASPEED_VUART] = 8,
145
+ [ASPEED_FMC] = 39,
146
+ [ASPEED_SDMC] = 0,
147
+ [ASPEED_SCU] = 12,
148
+ [ASPEED_ADC] = 78,
149
+ [ASPEED_XDMA] = 6,
150
+ [ASPEED_SDHCI] = 43,
151
+ [ASPEED_GPIO] = 40,
152
+ [ASPEED_GPIO_1_8V] = 11,
153
+ [ASPEED_RTC] = 13,
154
+ [ASPEED_TIMER1] = 16,
155
+ [ASPEED_TIMER2] = 17,
156
+ [ASPEED_TIMER3] = 18,
157
+ [ASPEED_TIMER4] = 19,
158
+ [ASPEED_TIMER5] = 20,
159
+ [ASPEED_TIMER6] = 21,
160
+ [ASPEED_TIMER7] = 22,
161
+ [ASPEED_TIMER8] = 23,
162
+ [ASPEED_WDT] = 24,
163
+ [ASPEED_PWM] = 44,
164
+ [ASPEED_LPC] = 35,
165
+ [ASPEED_IBT] = 35, /* LPC */
166
+ [ASPEED_I2C] = 110, /* 110 -> 125 */
167
+ [ASPEED_ETH1] = 2,
168
+ [ASPEED_ETH2] = 3,
169
+};
170
+
171
+static qemu_irq aspeed_soc_get_irq(AspeedSoCState *s, int ctrl)
172
+{
173
+ AspeedSoCClass *sc = ASPEED_SOC_GET_CLASS(s);
174
+
175
+ return qdev_get_gpio_in(DEVICE(&s->a7mpcore), sc->irqmap[ctrl]);
176
+}
177
+
178
+static void aspeed_soc_ast2600_init(Object *obj)
179
+{
180
+ AspeedSoCState *s = ASPEED_SOC(obj);
181
+ AspeedSoCClass *sc = ASPEED_SOC_GET_CLASS(s);
182
+ int i;
183
+ char socname[8];
184
+ char typename[64];
185
+
186
+ if (sscanf(sc->name, "%7s", socname) != 1) {
187
+ g_assert_not_reached();
188
+ }
189
+
190
+ for (i = 0; i < sc->num_cpus; i++) {
191
+ object_initialize_child(obj, "cpu[*]", OBJECT(&s->cpu[i]),
192
+ sizeof(s->cpu[i]), sc->cpu_type,
193
+ &error_abort, NULL);
194
+ }
195
+
196
+ snprintf(typename, sizeof(typename), "aspeed.scu-%s", socname);
197
+ sysbus_init_child_obj(obj, "scu", OBJECT(&s->scu), sizeof(s->scu),
198
+ typename);
199
+ qdev_prop_set_uint32(DEVICE(&s->scu), "silicon-rev",
200
+ sc->silicon_rev);
201
+ object_property_add_alias(obj, "hw-strap1", OBJECT(&s->scu),
202
+ "hw-strap1", &error_abort);
203
+ object_property_add_alias(obj, "hw-strap2", OBJECT(&s->scu),
204
+ "hw-strap2", &error_abort);
205
+ object_property_add_alias(obj, "hw-prot-key", OBJECT(&s->scu),
206
+ "hw-prot-key", &error_abort);
207
+
208
+ sysbus_init_child_obj(obj, "a7mpcore", &s->a7mpcore,
209
+ sizeof(s->a7mpcore), TYPE_A15MPCORE_PRIV);
210
+
211
+ sysbus_init_child_obj(obj, "rtc", OBJECT(&s->rtc), sizeof(s->rtc),
212
+ TYPE_ASPEED_RTC);
213
+
214
+ snprintf(typename, sizeof(typename), "aspeed.timer-%s", socname);
215
+ sysbus_init_child_obj(obj, "timerctrl", OBJECT(&s->timerctrl),
216
+ sizeof(s->timerctrl), typename);
217
+ object_property_add_const_link(OBJECT(&s->timerctrl), "scu",
218
+ OBJECT(&s->scu), &error_abort);
219
+
220
+ snprintf(typename, sizeof(typename), "aspeed.i2c-%s", socname);
221
+ sysbus_init_child_obj(obj, "i2c", OBJECT(&s->i2c), sizeof(s->i2c),
222
+ typename);
223
+
224
+ snprintf(typename, sizeof(typename), "aspeed.fmc-%s", socname);
225
+ sysbus_init_child_obj(obj, "fmc", OBJECT(&s->fmc), sizeof(s->fmc),
226
+ typename);
227
+ object_property_add_alias(obj, "num-cs", OBJECT(&s->fmc), "num-cs",
228
+ &error_abort);
229
+ object_property_add_alias(obj, "dram", OBJECT(&s->fmc), "dram",
230
+ &error_abort);
231
+
232
+ for (i = 0; i < sc->spis_num; i++) {
233
+ snprintf(typename, sizeof(typename), "aspeed.spi%d-%s", i + 1, socname);
234
+ sysbus_init_child_obj(obj, "spi[*]", OBJECT(&s->spi[i]),
235
+ sizeof(s->spi[i]), typename);
236
+ }
237
+
238
+ snprintf(typename, sizeof(typename), "aspeed.sdmc-%s", socname);
239
+ sysbus_init_child_obj(obj, "sdmc", OBJECT(&s->sdmc), sizeof(s->sdmc),
240
+ typename);
241
+ object_property_add_alias(obj, "ram-size", OBJECT(&s->sdmc),
242
+ "ram-size", &error_abort);
243
+ object_property_add_alias(obj, "max-ram-size", OBJECT(&s->sdmc),
244
+ "max-ram-size", &error_abort);
245
+
246
+ for (i = 0; i < sc->wdts_num; i++) {
247
+ snprintf(typename, sizeof(typename), "aspeed.wdt-%s", socname);
248
+ sysbus_init_child_obj(obj, "wdt[*]", OBJECT(&s->wdt[i]),
249
+ sizeof(s->wdt[i]), typename);
250
+ object_property_add_const_link(OBJECT(&s->wdt[i]), "scu",
251
+ OBJECT(&s->scu), &error_abort);
252
+ }
253
+
254
+ for (i = 0; i < ASPEED_MACS_NUM; i++) {
255
+ sysbus_init_child_obj(obj, "ftgmac100[*]", OBJECT(&s->ftgmac100[i]),
256
+ sizeof(s->ftgmac100[i]), TYPE_FTGMAC100);
257
+ }
258
+
259
+ sysbus_init_child_obj(obj, "xdma", OBJECT(&s->xdma), sizeof(s->xdma),
260
+ TYPE_ASPEED_XDMA);
261
+
262
+ snprintf(typename, sizeof(typename), "aspeed.gpio-%s", socname);
263
+ sysbus_init_child_obj(obj, "gpio", OBJECT(&s->gpio), sizeof(s->gpio),
264
+ typename);
265
+
266
+ snprintf(typename, sizeof(typename), "aspeed.gpio-%s-1_8v", socname);
267
+ sysbus_init_child_obj(obj, "gpio_1_8v", OBJECT(&s->gpio_1_8v),
268
+ sizeof(s->gpio_1_8v), typename);
269
+
270
+ sysbus_init_child_obj(obj, "sdc", OBJECT(&s->sdhci), sizeof(s->sdhci),
271
+ TYPE_ASPEED_SDHCI);
272
+
273
+ /* Init sd card slot class here so that they're under the correct parent */
274
+ for (i = 0; i < ASPEED_SDHCI_NUM_SLOTS; ++i) {
275
+ sysbus_init_child_obj(obj, "sdhci[*]", OBJECT(&s->sdhci.slots[i]),
276
+ sizeof(s->sdhci.slots[i]), TYPE_SYSBUS_SDHCI);
277
+ }
278
+}
244
+}
279
+
245
+
280
+/*
246
+/*
281
+ * ASPEED ast2600 has 0xf as cluster ID
247
+ * Irritatingly, the user API struct sigaction does not match the
282
+ *
248
+ * kernel API struct sigaction. So for simplicity, isolate the
283
+ * http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0388e/CIHEBGFG.html
249
+ * kernel ABI here, and make this act like signal.
284
+ */
250
+ */
285
+static uint64_t aspeed_calc_affinity(int cpu)
251
+void signal_info(int sig, void (*fn)(int, siginfo_t *, ucontext_t *))
286
+{
252
+{
287
+ return (0xf << ARM_AFF1_SHIFT) | cpu;
253
+ struct kernel_sigaction {
288
+}
254
+ void (*handler)(int, siginfo_t *, ucontext_t *);
289
+
255
+ unsigned long flags;
290
+static void aspeed_soc_ast2600_realize(DeviceState *dev, Error **errp)
256
+ unsigned long restorer;
291
+{
257
+ unsigned long mask;
292
+ int i;
258
+ } sa = { fn, SA_SIGINFO, 0, 0 };
293
+ AspeedSoCState *s = ASPEED_SOC(dev);
259
+
294
+ AspeedSoCClass *sc = ASPEED_SOC_GET_CLASS(s);
260
+ register int x0 __asm__("x0") = sig;
295
+ Error *err = NULL, *local_err = NULL;
261
+ register void *x1 __asm__("x1") = &sa;
296
+ qemu_irq irq;
262
+ register void *x2 __asm__("x2") = 0;
297
+
263
+ register int x3 __asm__("x3") = sizeof(unsigned long);
298
+ /* IO space */
264
+ register int x8 __asm__("x8") = __NR_rt_sigaction;
299
+ create_unimplemented_device("aspeed_soc.io", sc->memmap[ASPEED_IOMEM],
265
+
300
+ ASPEED_SOC_IOMEM_SIZE);
266
+ asm volatile("svc #0"
301
+
267
+ : : "r"(x0), "r"(x1), "r"(x2), "r"(x3), "r"(x8) : "memory");
302
+ if (s->num_cpus > sc->num_cpus) {
268
+}
303
+ warn_report("%s: invalid number of CPUs %d, using default %d",
269
diff --git a/tests/tcg/aarch64/Makefile.target b/tests/tcg/aarch64/Makefile.target
304
+ sc->name, s->num_cpus, sc->num_cpus);
270
index XXXXXXX..XXXXXXX 100644
305
+ s->num_cpus = sc->num_cpus;
271
--- a/tests/tcg/aarch64/Makefile.target
306
+ }
272
+++ b/tests/tcg/aarch64/Makefile.target
307
+
273
@@ -XXX,XX +XXX,XX @@ run-pauth-%: QEMU_OPTS += -cpu max
308
+ /* CPU */
274
run-plugin-pauth-%: QEMU_OPTS += -cpu max
309
+ for (i = 0; i < s->num_cpus; i++) {
275
endif
310
+ object_property_set_int(OBJECT(&s->cpu[i]), QEMU_PSCI_CONDUIT_SMC,
276
311
+ "psci-conduit", &error_abort);
277
+# BTI Tests
312
+ if (s->num_cpus > 1) {
278
+# bti-1 tests the elf notes, so we require special compiler support.
313
+ object_property_set_int(OBJECT(&s->cpu[i]),
279
+ifneq ($(DOCKER_IMAGE)$(CROSS_CC_HAS_ARMV8_BTI),)
314
+ ASPEED_A7MPCORE_ADDR,
280
+AARCH64_TESTS += bti-1
315
+ "reset-cbar", &error_abort);
281
+bti-1: CFLAGS += -mbranch-protection=standard
316
+ }
282
+bti-1: LDFLAGS += -nostdlib
317
+ object_property_set_int(OBJECT(&s->cpu[i]), aspeed_calc_affinity(i),
283
+endif
318
+ "mp-affinity", &error_abort);
284
+# bti-2 tests PROT_BTI, so no special compiler support required.
319
+
285
+AARCH64_TESTS += bti-2
320
+ /*
286
+
321
+ * TODO: the secondary CPUs are started and a boot helper
287
# Semihosting smoke test for linux-user
322
+ * is needed when using -kernel
288
AARCH64_TESTS += semihosting
323
+ */
289
run-semihosting: semihosting
324
+
290
diff --git a/tests/tcg/configure.sh b/tests/tcg/configure.sh
325
+ object_property_set_bool(OBJECT(&s->cpu[i]), true, "realized", &err);
291
index XXXXXXX..XXXXXXX 100755
326
+ if (err) {
292
--- a/tests/tcg/configure.sh
327
+ error_propagate(errp, err);
293
+++ b/tests/tcg/configure.sh
328
+ return;
294
@@ -XXX,XX +XXX,XX @@ for target in $target_list; do
329
+ }
295
-march=armv8.3-a -o $TMPE $TMPC; then
330
+ }
296
echo "CROSS_CC_HAS_ARMV8_3=y" >> $config_target_mak
331
+
297
fi
332
+ /* A7MPCORE */
298
+ if do_compiler "$target_compiler" $target_compiler_cflags \
333
+ object_property_set_int(OBJECT(&s->a7mpcore), s->num_cpus, "num-cpu",
299
+ -mbranch-protection=standard -o $TMPE $TMPC; then
334
+ &error_abort);
300
+ echo "CROSS_CC_HAS_ARMV8_BTI=y" >> $config_target_mak
335
+ object_property_set_int(OBJECT(&s->a7mpcore),
301
+ fi
336
+ ASPEED_SOC_AST2600_MAX_IRQ + GIC_INTERNAL,
302
;;
337
+ "num-irq", &error_abort);
303
esac
338
+
304
339
+ object_property_set_bool(OBJECT(&s->a7mpcore), true, "realized",
340
+ &error_abort);
341
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->a7mpcore), 0, ASPEED_A7MPCORE_ADDR);
342
+
343
+ for (i = 0; i < s->num_cpus; i++) {
344
+ SysBusDevice *sbd = SYS_BUS_DEVICE(&s->a7mpcore);
345
+ DeviceState *d = DEVICE(qemu_get_cpu(i));
346
+
347
+ irq = qdev_get_gpio_in(d, ARM_CPU_IRQ);
348
+ sysbus_connect_irq(sbd, i, irq);
349
+ irq = qdev_get_gpio_in(d, ARM_CPU_FIQ);
350
+ sysbus_connect_irq(sbd, i + s->num_cpus, irq);
351
+ irq = qdev_get_gpio_in(d, ARM_CPU_VIRQ);
352
+ sysbus_connect_irq(sbd, i + 2 * s->num_cpus, irq);
353
+ irq = qdev_get_gpio_in(d, ARM_CPU_VFIQ);
354
+ sysbus_connect_irq(sbd, i + 3 * s->num_cpus, irq);
355
+ }
356
+
357
+ /* SRAM */
358
+ memory_region_init_ram(&s->sram, OBJECT(dev), "aspeed.sram",
359
+ sc->sram_size, &err);
360
+ if (err) {
361
+ error_propagate(errp, err);
362
+ return;
363
+ }
364
+ memory_region_add_subregion(get_system_memory(),
365
+ sc->memmap[ASPEED_SRAM], &s->sram);
366
+
367
+ /* SCU */
368
+ object_property_set_bool(OBJECT(&s->scu), true, "realized", &err);
369
+ if (err) {
370
+ error_propagate(errp, err);
371
+ return;
372
+ }
373
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->scu), 0, sc->memmap[ASPEED_SCU]);
374
+
375
+ /* RTC */
376
+ object_property_set_bool(OBJECT(&s->rtc), true, "realized", &err);
377
+ if (err) {
378
+ error_propagate(errp, err);
379
+ return;
380
+ }
381
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->rtc), 0, sc->memmap[ASPEED_RTC]);
382
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->rtc), 0,
383
+ aspeed_soc_get_irq(s, ASPEED_RTC));
384
+
385
+ /* Timer */
386
+ object_property_set_bool(OBJECT(&s->timerctrl), true, "realized", &err);
387
+ if (err) {
388
+ error_propagate(errp, err);
389
+ return;
390
+ }
391
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->timerctrl), 0,
392
+ sc->memmap[ASPEED_TIMER1]);
393
+ for (i = 0; i < ASPEED_TIMER_NR_TIMERS; i++) {
394
+ qemu_irq irq = aspeed_soc_get_irq(s, ASPEED_TIMER1 + i);
395
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->timerctrl), i, irq);
396
+ }
397
+
398
+ /* UART - attach an 8250 to the IO space as our UART5 */
399
+ if (serial_hd(0)) {
400
+ qemu_irq uart5 = aspeed_soc_get_irq(s, ASPEED_UART5);
401
+ serial_mm_init(get_system_memory(), sc->memmap[ASPEED_UART5], 2,
402
+ uart5, 38400, serial_hd(0), DEVICE_LITTLE_ENDIAN);
403
+ }
404
+
405
+ /* I2C */
406
+ object_property_set_bool(OBJECT(&s->i2c), true, "realized", &err);
407
+ if (err) {
408
+ error_propagate(errp, err);
409
+ return;
410
+ }
411
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->i2c), 0, sc->memmap[ASPEED_I2C]);
412
+ for (i = 0; i < ASPEED_I2C_GET_CLASS(&s->i2c)->num_busses; i++) {
413
+ qemu_irq irq = qdev_get_gpio_in(DEVICE(&s->a7mpcore),
414
+ sc->irqmap[ASPEED_I2C] + i);
415
+ /*
416
+ * The AST2600 SoC has one IRQ per I2C bus. Skip the common
417
+ * IRQ (AST2400 and AST2500) and connect all bussses.
418
+ */
419
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->i2c), i + 1, irq);
420
+ }
421
+
422
+ /* FMC, The number of CS is set at the board level */
423
+ object_property_set_int(OBJECT(&s->fmc), sc->memmap[ASPEED_SDRAM],
424
+ "sdram-base", &err);
425
+ if (err) {
426
+ error_propagate(errp, err);
427
+ return;
428
+ }
429
+ object_property_set_bool(OBJECT(&s->fmc), true, "realized", &err);
430
+ if (err) {
431
+ error_propagate(errp, err);
432
+ return;
433
+ }
434
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->fmc), 0, sc->memmap[ASPEED_FMC]);
435
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->fmc), 1,
436
+ s->fmc.ctrl->flash_window_base);
437
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->fmc), 0,
438
+ aspeed_soc_get_irq(s, ASPEED_FMC));
439
+
440
+ /* SPI */
441
+ for (i = 0; i < sc->spis_num; i++) {
442
+ object_property_set_int(OBJECT(&s->spi[i]), 1, "num-cs", &err);
443
+ object_property_set_bool(OBJECT(&s->spi[i]), true, "realized",
444
+ &local_err);
445
+ error_propagate(&err, local_err);
446
+ if (err) {
447
+ error_propagate(errp, err);
448
+ return;
449
+ }
450
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->spi[i]), 0,
451
+ sc->memmap[ASPEED_SPI1 + i]);
452
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->spi[i]), 1,
453
+ s->spi[i].ctrl->flash_window_base);
454
+ }
455
+
456
+ /* SDMC - SDRAM Memory Controller */
457
+ object_property_set_bool(OBJECT(&s->sdmc), true, "realized", &err);
458
+ if (err) {
459
+ error_propagate(errp, err);
460
+ return;
461
+ }
462
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->sdmc), 0, sc->memmap[ASPEED_SDMC]);
463
+
464
+ /* Watch dog */
465
+ for (i = 0; i < sc->wdts_num; i++) {
466
+ AspeedWDTClass *awc = ASPEED_WDT_GET_CLASS(&s->wdt[i]);
467
+
468
+ object_property_set_bool(OBJECT(&s->wdt[i]), true, "realized", &err);
469
+ if (err) {
470
+ error_propagate(errp, err);
471
+ return;
472
+ }
473
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->wdt[i]), 0,
474
+ sc->memmap[ASPEED_WDT] + i * awc->offset);
475
+ }
476
+
477
+ /* Net */
478
+ for (i = 0; i < nb_nics; i++) {
479
+ qdev_set_nic_properties(DEVICE(&s->ftgmac100[i]), &nd_table[i]);
480
+ object_property_set_bool(OBJECT(&s->ftgmac100[i]), true, "aspeed",
481
+ &err);
482
+ object_property_set_bool(OBJECT(&s->ftgmac100[i]), true, "realized",
483
+ &local_err);
484
+ error_propagate(&err, local_err);
485
+ if (err) {
486
+ error_propagate(errp, err);
487
+ return;
488
+ }
489
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->ftgmac100[i]), 0,
490
+ sc->memmap[ASPEED_ETH1 + i]);
491
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->ftgmac100[i]), 0,
492
+ aspeed_soc_get_irq(s, ASPEED_ETH1 + i));
493
+ }
494
+
495
+ /* XDMA */
496
+ object_property_set_bool(OBJECT(&s->xdma), true, "realized", &err);
497
+ if (err) {
498
+ error_propagate(errp, err);
499
+ return;
500
+ }
501
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->xdma), 0,
502
+ sc->memmap[ASPEED_XDMA]);
503
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->xdma), 0,
504
+ aspeed_soc_get_irq(s, ASPEED_XDMA));
505
+
506
+ /* GPIO */
507
+ object_property_set_bool(OBJECT(&s->gpio), true, "realized", &err);
508
+ if (err) {
509
+ error_propagate(errp, err);
510
+ return;
511
+ }
512
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->gpio), 0, sc->memmap[ASPEED_GPIO]);
513
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->gpio), 0,
514
+ aspeed_soc_get_irq(s, ASPEED_GPIO));
515
+
516
+ object_property_set_bool(OBJECT(&s->gpio_1_8v), true, "realized", &err);
517
+ if (err) {
518
+ error_propagate(errp, err);
519
+ return;
520
+ }
521
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->gpio_1_8v), 0,
522
+ sc->memmap[ASPEED_GPIO_1_8V]);
523
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->gpio_1_8v), 0,
524
+ aspeed_soc_get_irq(s, ASPEED_GPIO_1_8V));
525
+
526
+ /* SDHCI */
527
+ object_property_set_bool(OBJECT(&s->sdhci), true, "realized", &err);
528
+ if (err) {
529
+ error_propagate(errp, err);
530
+ return;
531
+ }
532
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->sdhci), 0,
533
+ sc->memmap[ASPEED_SDHCI]);
534
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->sdhci), 0,
535
+ aspeed_soc_get_irq(s, ASPEED_SDHCI));
536
+}
537
+
538
+static void aspeed_soc_ast2600_class_init(ObjectClass *oc, void *data)
539
+{
540
+ DeviceClass *dc = DEVICE_CLASS(oc);
541
+ AspeedSoCClass *sc = ASPEED_SOC_CLASS(oc);
542
+
543
+ dc->realize = aspeed_soc_ast2600_realize;
544
+
545
+ sc->name = "ast2600-a0";
546
+ sc->cpu_type = ARM_CPU_TYPE_NAME("cortex-a7");
547
+ sc->silicon_rev = AST2600_A0_SILICON_REV;
548
+ sc->sram_size = 0x10000;
549
+ sc->spis_num = 2;
550
+ sc->wdts_num = 4;
551
+ sc->irqmap = aspeed_soc_ast2600_irqmap;
552
+ sc->memmap = aspeed_soc_ast2600_memmap;
553
+ sc->num_cpus = 2;
554
+}
555
+
556
+static const TypeInfo aspeed_soc_ast2600_type_info = {
557
+ .name = "ast2600-a0",
558
+ .parent = TYPE_ASPEED_SOC,
559
+ .instance_size = sizeof(AspeedSoCState),
560
+ .instance_init = aspeed_soc_ast2600_init,
561
+ .class_init = aspeed_soc_ast2600_class_init,
562
+ .class_size = sizeof(AspeedSoCClass),
563
+};
564
+
565
+static void aspeed_soc_register_types(void)
566
+{
567
+ type_register_static(&aspeed_soc_ast2600_type_info);
568
+};
569
+
570
+type_init(aspeed_soc_register_types)
571
--
305
--
572
2.20.1
306
2.20.1
573
307
574
308
diff view generated by jsdifflib
1
From: Joel Stanley <joel@jms.id.au>
1
From: Thomas Huth <thuth@redhat.com>
2
2
3
Signed-off-by: Joel Stanley <joel@jms.id.au>
3
When compiling with -Werror=implicit-fallthrough, gcc complains about
4
Signed-off-by: Cédric Le Goater <clg@kaod.org>
4
missing fallthrough annotations in this file. Looking at the code,
5
Message-id: 20190925143248.10000-24-clg@kaod.org
5
the fallthrough is very likely intended here, so add some comments
6
to silence the compiler warnings.
7
8
Signed-off-by: Thomas Huth <thuth@redhat.com>
9
Message-id: 20201020105938.23209-1-thuth@redhat.com
10
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
---
12
---
8
include/hw/arm/aspeed_soc.h | 1 +
13
hw/arm/highbank.c | 2 ++
9
hw/arm/aspeed_ast2600.c | 5 +++++
14
1 file changed, 2 insertions(+)
10
hw/arm/aspeed_soc.c | 6 ++++++
11
3 files changed, 12 insertions(+)
12
15
13
diff --git a/include/hw/arm/aspeed_soc.h b/include/hw/arm/aspeed_soc.h
16
diff --git a/hw/arm/highbank.c b/hw/arm/highbank.c
14
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
15
--- a/include/hw/arm/aspeed_soc.h
18
--- a/hw/arm/highbank.c
16
+++ b/include/hw/arm/aspeed_soc.h
19
+++ b/hw/arm/highbank.c
17
@@ -XXX,XX +XXX,XX @@ enum {
20
@@ -XXX,XX +XXX,XX @@ static void hb_reset_secondary(ARMCPU *cpu, const struct arm_boot_info *info)
18
ASPEED_SDMC,
21
address_space_stl_notdirty(&address_space_memory,
19
ASPEED_SCU,
22
SMP_BOOT_REG + 0x30, 0,
20
ASPEED_ADC,
23
MEMTXATTRS_UNSPECIFIED, NULL);
21
+ ASPEED_VIDEO,
24
+ /* fallthrough */
22
ASPEED_SRAM,
25
case 3:
23
ASPEED_SDHCI,
26
address_space_stl_notdirty(&address_space_memory,
24
ASPEED_GPIO,
27
SMP_BOOT_REG + 0x20, 0,
25
diff --git a/hw/arm/aspeed_ast2600.c b/hw/arm/aspeed_ast2600.c
28
MEMTXATTRS_UNSPECIFIED, NULL);
26
index XXXXXXX..XXXXXXX 100644
29
+ /* fallthrough */
27
--- a/hw/arm/aspeed_ast2600.c
30
case 2:
28
+++ b/hw/arm/aspeed_ast2600.c
31
address_space_stl_notdirty(&address_space_memory,
29
@@ -XXX,XX +XXX,XX @@ static const hwaddr aspeed_soc_ast2600_memmap[] = {
32
SMP_BOOT_REG + 0x10, 0,
30
[ASPEED_SCU] = 0x1E6E2000,
31
[ASPEED_XDMA] = 0x1E6E7000,
32
[ASPEED_ADC] = 0x1E6E9000,
33
+ [ASPEED_VIDEO] = 0x1E700000,
34
[ASPEED_SDHCI] = 0x1E740000,
35
[ASPEED_GPIO] = 0x1E780000,
36
[ASPEED_GPIO_1_8V] = 0x1E780800,
37
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_ast2600_realize(DeviceState *dev, Error **errp)
38
create_unimplemented_device("aspeed_soc.io", sc->memmap[ASPEED_IOMEM],
39
ASPEED_SOC_IOMEM_SIZE);
40
41
+ /* Video engine stub */
42
+ create_unimplemented_device("aspeed.video", sc->memmap[ASPEED_VIDEO],
43
+ 0x1000);
44
+
45
if (s->num_cpus > sc->num_cpus) {
46
warn_report("%s: invalid number of CPUs %d, using default %d",
47
sc->name, s->num_cpus, sc->num_cpus);
48
diff --git a/hw/arm/aspeed_soc.c b/hw/arm/aspeed_soc.c
49
index XXXXXXX..XXXXXXX 100644
50
--- a/hw/arm/aspeed_soc.c
51
+++ b/hw/arm/aspeed_soc.c
52
@@ -XXX,XX +XXX,XX @@ static const hwaddr aspeed_soc_ast2400_memmap[] = {
53
[ASPEED_SDMC] = 0x1E6E0000,
54
[ASPEED_SCU] = 0x1E6E2000,
55
[ASPEED_XDMA] = 0x1E6E7000,
56
+ [ASPEED_VIDEO] = 0x1E700000,
57
[ASPEED_ADC] = 0x1E6E9000,
58
[ASPEED_SRAM] = 0x1E720000,
59
[ASPEED_SDHCI] = 0x1E740000,
60
@@ -XXX,XX +XXX,XX @@ static const hwaddr aspeed_soc_ast2500_memmap[] = {
61
[ASPEED_SCU] = 0x1E6E2000,
62
[ASPEED_XDMA] = 0x1E6E7000,
63
[ASPEED_ADC] = 0x1E6E9000,
64
+ [ASPEED_VIDEO] = 0x1E700000,
65
[ASPEED_SRAM] = 0x1E720000,
66
[ASPEED_SDHCI] = 0x1E740000,
67
[ASPEED_GPIO] = 0x1E780000,
68
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
69
create_unimplemented_device("aspeed_soc.io", sc->memmap[ASPEED_IOMEM],
70
ASPEED_SOC_IOMEM_SIZE);
71
72
+ /* Video engine stub */
73
+ create_unimplemented_device("aspeed.video", sc->memmap[ASPEED_VIDEO],
74
+ 0x1000);
75
+
76
if (s->num_cpus > sc->num_cpus) {
77
warn_report("%s: invalid number of CPUs %d, using default %d",
78
sc->name, s->num_cpus, sc->num_cpus);
79
--
33
--
80
2.20.1
34
2.20.1
81
35
82
36
diff view generated by jsdifflib
1
From: Joel Stanley <joel@jms.id.au>
1
From: Pavel Dovgalyuk <pavel.dovgalyuk@ispras.ru>
2
2
3
The AST2600 has four watchdogs, and they each have a 0x40 of registers.
3
This patch sets min_cpus field for xlnx-versal-virt platform,
4
because it always creates XLNX_VERSAL_NR_ACPUS cpus even with
5
-smp 1 command line option.
4
6
5
When running as part of an ast2600 system we must check a different
7
Signed-off-by: Pavel Dovgalyuk <pavel.dovgalyuk@ispras.ru>
6
offset for the system reset control register in the SCU.
8
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
7
9
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
8
Signed-off-by: Joel Stanley <joel@jms.id.au>
10
Message-id: 160343854912.8460.17915238517799132371.stgit@pasha-ThinkPad-X280
9
Signed-off-by: Cédric Le Goater <clg@kaod.org>
10
Message-id: 20190925143248.10000-12-clg@kaod.org
11
[clg: - reworked model integration into new object class ]
12
Signed-off-by: Cédric Le Goater <clg@kaod.org>
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
14
---
12
---
15
include/hw/arm/aspeed_soc.h | 2 +-
13
hw/arm/xlnx-versal-virt.c | 1 +
16
include/hw/watchdog/wdt_aspeed.h | 1 +
14
1 file changed, 1 insertion(+)
17
hw/watchdog/wdt_aspeed.c | 29 +++++++++++++++++++++++++++++
18
3 files changed, 31 insertions(+), 1 deletion(-)
19
15
20
diff --git a/include/hw/arm/aspeed_soc.h b/include/hw/arm/aspeed_soc.h
16
diff --git a/hw/arm/xlnx-versal-virt.c b/hw/arm/xlnx-versal-virt.c
21
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
22
--- a/include/hw/arm/aspeed_soc.h
18
--- a/hw/arm/xlnx-versal-virt.c
23
+++ b/include/hw/arm/aspeed_soc.h
19
+++ b/hw/arm/xlnx-versal-virt.c
24
@@ -XXX,XX +XXX,XX @@
20
@@ -XXX,XX +XXX,XX @@ static void versal_virt_machine_class_init(ObjectClass *oc, void *data)
25
#include "hw/sd/aspeed_sdhci.h"
21
26
22
mc->desc = "Xilinx Versal Virtual development board";
27
#define ASPEED_SPIS_NUM 2
23
mc->init = versal_virt_init;
28
-#define ASPEED_WDTS_NUM 3
24
+ mc->min_cpus = XLNX_VERSAL_NR_ACPUS;
29
+#define ASPEED_WDTS_NUM 4
25
mc->max_cpus = XLNX_VERSAL_NR_ACPUS;
30
#define ASPEED_CPUS_NUM 2
26
mc->default_cpus = XLNX_VERSAL_NR_ACPUS;
31
#define ASPEED_MACS_NUM 2
27
mc->no_cdrom = true;
32
33
diff --git a/include/hw/watchdog/wdt_aspeed.h b/include/hw/watchdog/wdt_aspeed.h
34
index XXXXXXX..XXXXXXX 100644
35
--- a/include/hw/watchdog/wdt_aspeed.h
36
+++ b/include/hw/watchdog/wdt_aspeed.h
37
@@ -XXX,XX +XXX,XX @@
38
OBJECT_CHECK(AspeedWDTState, (obj), TYPE_ASPEED_WDT)
39
#define TYPE_ASPEED_2400_WDT TYPE_ASPEED_WDT "-ast2400"
40
#define TYPE_ASPEED_2500_WDT TYPE_ASPEED_WDT "-ast2500"
41
+#define TYPE_ASPEED_2600_WDT TYPE_ASPEED_WDT "-ast2600"
42
43
#define ASPEED_WDT_REGS_MAX (0x20 / 4)
44
45
diff --git a/hw/watchdog/wdt_aspeed.c b/hw/watchdog/wdt_aspeed.c
46
index XXXXXXX..XXXXXXX 100644
47
--- a/hw/watchdog/wdt_aspeed.c
48
+++ b/hw/watchdog/wdt_aspeed.c
49
@@ -XXX,XX +XXX,XX @@
50
#define WDT_DRIVE_TYPE_MASK (0xFF << 24)
51
#define WDT_PUSH_PULL_MAGIC (0xA8 << 24)
52
#define WDT_OPEN_DRAIN_MAGIC (0x8A << 24)
53
+#define WDT_RESET_MASK1 (0x1c / 4)
54
55
#define WDT_TIMEOUT_STATUS (0x10 / 4)
56
#define WDT_TIMEOUT_CLEAR (0x14 / 4)
57
58
#define WDT_RESTART_MAGIC 0x4755
59
60
+#define AST2600_SCU_RESET_CONTROL1 (0x40 / 4)
61
#define SCU_RESET_CONTROL1 (0x04 / 4)
62
#define SCU_RESET_SDRAM BIT(0)
63
64
@@ -XXX,XX +XXX,XX @@ static uint64_t aspeed_wdt_read(void *opaque, hwaddr offset, unsigned size)
65
return s->regs[WDT_CTRL];
66
case WDT_RESET_WIDTH:
67
return s->regs[WDT_RESET_WIDTH];
68
+ case WDT_RESET_MASK1:
69
+ return s->regs[WDT_RESET_MASK1];
70
case WDT_TIMEOUT_STATUS:
71
case WDT_TIMEOUT_CLEAR:
72
qemu_log_mask(LOG_UNIMP,
73
@@ -XXX,XX +XXX,XX @@ static void aspeed_wdt_write(void *opaque, hwaddr offset, uint64_t data,
74
s->regs[WDT_RESET_WIDTH] |= data & awc->ext_pulse_width_mask;
75
break;
76
77
+ case WDT_RESET_MASK1:
78
+ /* TODO: implement */
79
+ s->regs[WDT_RESET_MASK1] = data;
80
+ break;
81
+
82
case WDT_TIMEOUT_STATUS:
83
case WDT_TIMEOUT_CLEAR:
84
qemu_log_mask(LOG_UNIMP,
85
@@ -XXX,XX +XXX,XX @@ static const TypeInfo aspeed_2500_wdt_info = {
86
.class_init = aspeed_2500_wdt_class_init,
87
};
88
89
+static void aspeed_2600_wdt_class_init(ObjectClass *klass, void *data)
90
+{
91
+ DeviceClass *dc = DEVICE_CLASS(klass);
92
+ AspeedWDTClass *awc = ASPEED_WDT_CLASS(klass);
93
+
94
+ dc->desc = "ASPEED 2600 Watchdog Controller";
95
+ awc->offset = 0x40;
96
+ awc->ext_pulse_width_mask = 0xfffff; /* TODO */
97
+ awc->reset_ctrl_reg = AST2600_SCU_RESET_CONTROL1;
98
+ awc->reset_pulse = aspeed_2500_wdt_reset_pulse;
99
+}
100
+
101
+static const TypeInfo aspeed_2600_wdt_info = {
102
+ .name = TYPE_ASPEED_2600_WDT,
103
+ .parent = TYPE_ASPEED_WDT,
104
+ .instance_size = sizeof(AspeedWDTState),
105
+ .class_init = aspeed_2600_wdt_class_init,
106
+};
107
+
108
static void wdt_aspeed_register_types(void)
109
{
110
watchdog_add_model(&model);
111
type_register_static(&aspeed_wdt_info);
112
type_register_static(&aspeed_2400_wdt_info);
113
type_register_static(&aspeed_2500_wdt_info);
114
+ type_register_static(&aspeed_2600_wdt_info);
115
}
116
117
type_init(wdt_aspeed_register_types)
118
--
28
--
119
2.20.1
29
2.20.1
120
30
121
31
diff view generated by jsdifflib
1
From: Cédric Le Goater <clg@kaod.org>
1
From: Havard Skinnemoen <hskinnemoen@google.com>
2
2
3
It prepares ground for register differences between SoCs.
3
This allows us to reuse npcm7xx_timer_pause for the watchdog timer.
4
4
5
Signed-off-by: Cédric Le Goater <clg@kaod.org>
5
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
6
Reviewed-by: Joel Stanley <joel@jms.id.au>
6
Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
7
Message-id: 20190925143248.10000-16-clg@kaod.org
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
---
8
---
10
include/hw/i2c/aspeed_i2c.h | 15 ++++++++++
9
hw/timer/npcm7xx_timer.c | 6 +++---
11
hw/arm/aspeed_soc.c | 3 +-
10
1 file changed, 3 insertions(+), 3 deletions(-)
12
hw/i2c/aspeed_i2c.c | 60 ++++++++++++++++++++++++++++++++-----
13
3 files changed, 69 insertions(+), 9 deletions(-)
14
11
15
diff --git a/include/hw/i2c/aspeed_i2c.h b/include/hw/i2c/aspeed_i2c.h
12
diff --git a/hw/timer/npcm7xx_timer.c b/hw/timer/npcm7xx_timer.c
16
index XXXXXXX..XXXXXXX 100644
13
index XXXXXXX..XXXXXXX 100644
17
--- a/include/hw/i2c/aspeed_i2c.h
14
--- a/hw/timer/npcm7xx_timer.c
18
+++ b/include/hw/i2c/aspeed_i2c.h
15
+++ b/hw/timer/npcm7xx_timer.c
19
@@ -XXX,XX +XXX,XX @@
16
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_pause(NPCM7xxTimer *t)
20
#include "hw/sysbus.h"
17
timer_del(&t->qtimer);
21
18
now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
22
#define TYPE_ASPEED_I2C "aspeed.i2c"
19
t->remaining_ns = t->expires_ns - now;
23
+#define TYPE_ASPEED_2400_I2C TYPE_ASPEED_I2C "-ast2400"
20
- if (t->remaining_ns <= 0) {
24
+#define TYPE_ASPEED_2500_I2C TYPE_ASPEED_I2C "-ast2500"
21
- npcm7xx_timer_reached_zero(t);
25
#define ASPEED_I2C(obj) \
22
- }
26
OBJECT_CHECK(AspeedI2CState, (obj), TYPE_ASPEED_I2C)
27
28
@@ -XXX,XX +XXX,XX @@ typedef struct AspeedI2CState {
29
AspeedI2CBus busses[ASPEED_I2C_NR_BUSSES];
30
} AspeedI2CState;
31
32
+#define ASPEED_I2C_CLASS(klass) \
33
+ OBJECT_CLASS_CHECK(AspeedI2CClass, (klass), TYPE_ASPEED_I2C)
34
+#define ASPEED_I2C_GET_CLASS(obj) \
35
+ OBJECT_GET_CLASS(AspeedI2CClass, (obj), TYPE_ASPEED_I2C)
36
+
37
+typedef struct AspeedI2CClass {
38
+ SysBusDeviceClass parent_class;
39
+
40
+ uint8_t num_busses;
41
+ uint8_t reg_size;
42
+ uint8_t gap;
43
+} AspeedI2CClass;
44
+
45
I2CBus *aspeed_i2c_get_bus(DeviceState *dev, int busnr);
46
47
#endif /* ASPEED_I2C_H */
48
diff --git a/hw/arm/aspeed_soc.c b/hw/arm/aspeed_soc.c
49
index XXXXXXX..XXXXXXX 100644
50
--- a/hw/arm/aspeed_soc.c
51
+++ b/hw/arm/aspeed_soc.c
52
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_init(Object *obj)
53
object_property_add_const_link(OBJECT(&s->timerctrl), "scu",
54
OBJECT(&s->scu), &error_abort);
55
56
+ snprintf(typename, sizeof(typename), "aspeed.i2c-%s", socname);
57
sysbus_init_child_obj(obj, "i2c", OBJECT(&s->i2c), sizeof(s->i2c),
58
- TYPE_ASPEED_I2C);
59
+ typename);
60
61
snprintf(typename, sizeof(typename), "aspeed.fmc-%s", socname);
62
sysbus_init_child_obj(obj, "fmc", OBJECT(&s->fmc), sizeof(s->fmc),
63
diff --git a/hw/i2c/aspeed_i2c.c b/hw/i2c/aspeed_i2c.c
64
index XXXXXXX..XXXXXXX 100644
65
--- a/hw/i2c/aspeed_i2c.c
66
+++ b/hw/i2c/aspeed_i2c.c
67
@@ -XXX,XX +XXX,XX @@ static void aspeed_i2c_reset(DeviceState *dev)
68
{
69
int i;
70
AspeedI2CState *s = ASPEED_I2C(dev);
71
+ AspeedI2CClass *aic = ASPEED_I2C_GET_CLASS(s);
72
73
s->intr_status = 0;
74
75
- for (i = 0; i < ASPEED_I2C_NR_BUSSES; i++) {
76
+ for (i = 0; i < aic->num_busses; i++) {
77
s->busses[i].intr_ctrl = 0;
78
s->busses[i].intr_status = 0;
79
s->busses[i].cmd = 0;
80
@@ -XXX,XX +XXX,XX @@ static void aspeed_i2c_reset(DeviceState *dev)
81
}
23
}
82
24
83
/*
25
/*
84
- * Address Definitions
26
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_write_tcsr(NPCM7xxTimer *t, uint32_t new_tcsr)
85
+ * Address Definitions (AST2400 and AST2500)
27
} else {
86
*
28
t->tcsr &= ~NPCM7XX_TCSR_CACT;
87
* 0x000 ... 0x03F: Global Register
29
npcm7xx_timer_pause(t);
88
* 0x040 ... 0x07F: Device 1
30
+ if (t->remaining_ns <= 0) {
89
@@ -XXX,XX +XXX,XX @@ static void aspeed_i2c_realize(DeviceState *dev, Error **errp)
31
+ npcm7xx_timer_reached_zero(t);
90
int i;
32
+ }
91
SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
33
}
92
AspeedI2CState *s = ASPEED_I2C(dev);
93
+ AspeedI2CClass *aic = ASPEED_I2C_GET_CLASS(s);
94
95
sysbus_init_irq(sbd, &s->irq);
96
memory_region_init_io(&s->iomem, OBJECT(s), &aspeed_i2c_ctrl_ops, s,
97
"aspeed.i2c", 0x1000);
98
sysbus_init_mmio(sbd, &s->iomem);
99
100
- for (i = 0; i < ASPEED_I2C_NR_BUSSES; i++) {
101
- char name[16];
102
- int offset = i < 7 ? 1 : 5;
103
+ for (i = 0; i < aic->num_busses; i++) {
104
+ char name[32];
105
+ int offset = i < aic->gap ? 1 : 5;
106
snprintf(name, sizeof(name), "aspeed.i2c.%d", i);
107
s->busses[i].controller = s;
108
s->busses[i].id = i;
109
s->busses[i].bus = i2c_init_bus(dev, name);
110
memory_region_init_io(&s->busses[i].mr, OBJECT(dev),
111
- &aspeed_i2c_bus_ops, &s->busses[i], name, 0x40);
112
- memory_region_add_subregion(&s->iomem, 0x40 * (i + offset),
113
+ &aspeed_i2c_bus_ops, &s->busses[i], name,
114
+ aic->reg_size);
115
+ memory_region_add_subregion(&s->iomem, aic->reg_size * (i + offset),
116
&s->busses[i].mr);
117
}
34
}
118
}
35
}
119
@@ -XXX,XX +XXX,XX @@ static const TypeInfo aspeed_i2c_info = {
120
.parent = TYPE_SYS_BUS_DEVICE,
121
.instance_size = sizeof(AspeedI2CState),
122
.class_init = aspeed_i2c_class_init,
123
+ .class_size = sizeof(AspeedI2CClass),
124
+ .abstract = true,
125
+};
126
+
127
+static void aspeed_2400_i2c_class_init(ObjectClass *klass, void *data)
128
+{
129
+ DeviceClass *dc = DEVICE_CLASS(klass);
130
+ AspeedI2CClass *aic = ASPEED_I2C_CLASS(klass);
131
+
132
+ dc->desc = "ASPEED 2400 I2C Controller";
133
+
134
+ aic->num_busses = 14;
135
+ aic->reg_size = 0x40;
136
+ aic->gap = 7;
137
+}
138
+
139
+static const TypeInfo aspeed_2400_i2c_info = {
140
+ .name = TYPE_ASPEED_2400_I2C,
141
+ .parent = TYPE_ASPEED_I2C,
142
+ .class_init = aspeed_2400_i2c_class_init,
143
+};
144
+
145
+static void aspeed_2500_i2c_class_init(ObjectClass *klass, void *data)
146
+{
147
+ DeviceClass *dc = DEVICE_CLASS(klass);
148
+ AspeedI2CClass *aic = ASPEED_I2C_CLASS(klass);
149
+
150
+ dc->desc = "ASPEED 2500 I2C Controller";
151
+
152
+ aic->num_busses = 14;
153
+ aic->reg_size = 0x40;
154
+ aic->gap = 7;
155
+}
156
+
157
+static const TypeInfo aspeed_2500_i2c_info = {
158
+ .name = TYPE_ASPEED_2500_I2C,
159
+ .parent = TYPE_ASPEED_I2C,
160
+ .class_init = aspeed_2500_i2c_class_init,
161
};
162
163
static void aspeed_i2c_register_types(void)
164
{
165
type_register_static(&aspeed_i2c_info);
166
+ type_register_static(&aspeed_2400_i2c_info);
167
+ type_register_static(&aspeed_2500_i2c_info);
168
}
169
170
type_init(aspeed_i2c_register_types)
171
@@ -XXX,XX +XXX,XX @@ type_init(aspeed_i2c_register_types)
172
I2CBus *aspeed_i2c_get_bus(DeviceState *dev, int busnr)
173
{
174
AspeedI2CState *s = ASPEED_I2C(dev);
175
+ AspeedI2CClass *aic = ASPEED_I2C_GET_CLASS(s);
176
I2CBus *bus = NULL;
177
178
- if (busnr >= 0 && busnr < ASPEED_I2C_NR_BUSSES) {
179
+ if (busnr >= 0 && busnr < aic->num_busses) {
180
bus = s->busses[busnr].bus;
181
}
182
183
--
36
--
184
2.20.1
37
2.20.1
185
38
186
39
diff view generated by jsdifflib
1
Currently the ptimer design uses a QEMU bottom-half as its
1
From: Hao Wu <wuhaotsh@google.com>
2
mechanism for calling back into the device model using the
3
ptimer when the timer has expired. Unfortunately this design
4
is fatally flawed, because it means that there is a lag
5
between the ptimer updating its own state and the device
6
callback function updating device state, and guest accesses
7
to device registers between the two can return inconsistent
8
device state.
9
2
10
We want to replace the bottom-half design with one where
3
The watchdog is part of NPCM7XX's timer module. Its behavior is
11
the guest device's callback is called either immediately
4
controlled by the WTCR register in the timer.
12
(when the ptimer triggers by timeout) or when the device
13
model code closes a transaction-begin/end section (when the
14
ptimer triggers because the device model changed the
15
ptimer's count value or other state). As the first step,
16
rename ptimer_init() to ptimer_init_with_bh(), to free up
17
the ptimer_init() name for the new API. We can then convert
18
all the ptimer users away from ptimer_init_with_bh() before
19
removing it entirely.
20
5
21
(Commit created with
6
When enabled, the watchdog issues an interrupt signal after a pre-set
22
git grep -l ptimer_init | xargs sed -i -e 's/ptimer_init/ptimer_init_with_bh/'
7
amount of cycles, and issues a reset signal shortly after that.
23
and three overlong lines folded by hand.)
24
8
9
Reviewed-by: Tyrone Ting <kfting@nuvoton.com>
10
Signed-off-by: Hao Wu <wuhaotsh@google.com>
11
Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
12
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
13
[PMM: deleted blank line at end of npcm_watchdog_timer-test.c]
25
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
14
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
26
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
27
Message-id: 20191008171740.9679-2-peter.maydell@linaro.org
28
---
15
---
29
include/hw/ptimer.h | 11 ++++++-----
16
include/hw/misc/npcm7xx_clk.h | 2 +
30
hw/arm/musicpal.c | 2 +-
17
include/hw/timer/npcm7xx_timer.h | 48 +++-
31
hw/core/ptimer.c | 2 +-
18
hw/arm/npcm7xx.c | 12 +
32
hw/dma/xilinx_axidma.c | 2 +-
19
hw/misc/npcm7xx_clk.c | 28 ++
33
hw/m68k/mcf5206.c | 2 +-
20
hw/timer/npcm7xx_timer.c | 266 ++++++++++++++----
34
hw/m68k/mcf5208.c | 2 +-
21
tests/qtest/npcm7xx_watchdog_timer-test.c | 319 ++++++++++++++++++++++
35
hw/net/fsl_etsec/etsec.c | 2 +-
22
MAINTAINERS | 1 +
36
hw/net/lan9118.c | 2 +-
23
tests/qtest/meson.build | 2 +-
37
hw/timer/allwinner-a10-pit.c | 2 +-
24
8 files changed, 624 insertions(+), 54 deletions(-)
38
hw/timer/altera_timer.c | 2 +-
25
create mode 100644 tests/qtest/npcm7xx_watchdog_timer-test.c
39
hw/timer/arm_mptimer.c | 6 +++---
40
hw/timer/arm_timer.c | 2 +-
41
hw/timer/cmsdk-apb-dualtimer.c | 2 +-
42
hw/timer/cmsdk-apb-timer.c | 2 +-
43
hw/timer/digic-timer.c | 2 +-
44
hw/timer/etraxfs_timer.c | 6 +++---
45
hw/timer/exynos4210_mct.c | 7 ++++---
46
hw/timer/exynos4210_pwm.c | 2 +-
47
hw/timer/exynos4210_rtc.c | 4 ++--
48
hw/timer/grlib_gptimer.c | 2 +-
49
hw/timer/imx_epit.c | 4 ++--
50
hw/timer/imx_gpt.c | 2 +-
51
hw/timer/lm32_timer.c | 2 +-
52
hw/timer/milkymist-sysctl.c | 4 ++--
53
hw/timer/mss-timer.c | 2 +-
54
hw/timer/puv3_ost.c | 2 +-
55
hw/timer/sh_timer.c | 2 +-
56
hw/timer/slavio_timer.c | 2 +-
57
hw/timer/xilinx_timer.c | 2 +-
58
hw/watchdog/cmsdk-apb-watchdog.c | 2 +-
59
tests/ptimer-test.c | 22 +++++++++++-----------
60
31 files changed, 56 insertions(+), 54 deletions(-)
61
26
62
diff --git a/include/hw/ptimer.h b/include/hw/ptimer.h
27
diff --git a/include/hw/misc/npcm7xx_clk.h b/include/hw/misc/npcm7xx_clk.h
63
index XXXXXXX..XXXXXXX 100644
28
index XXXXXXX..XXXXXXX 100644
64
--- a/include/hw/ptimer.h
29
--- a/include/hw/misc/npcm7xx_clk.h
65
+++ b/include/hw/ptimer.h
30
+++ b/include/hw/misc/npcm7xx_clk.h
66
@@ -XXX,XX +XXX,XX @@
31
@@ -XXX,XX +XXX,XX @@
67
* ptimer_set_count() or ptimer_set_limit() will not trigger the timer
68
* (though it will cause a reload). Only a counter decrement to "0"
69
* will cause a trigger. Not compatible with NO_IMMEDIATE_TRIGGER;
70
- * ptimer_init() will assert() that you don't set both.
71
+ * ptimer_init_with_bh() will assert() that you don't set both.
72
*/
32
*/
73
#define PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT (1 << 5)
33
#define NPCM7XX_CLK_NR_REGS (0x70 / sizeof(uint32_t))
74
34
75
@@ -XXX,XX +XXX,XX @@ typedef struct ptimer_state ptimer_state;
35
+#define NPCM7XX_WATCHDOG_RESET_GPIO_IN "npcm7xx-clk-watchdog-reset-gpio-in"
76
typedef void (*ptimer_cb)(void *opaque);
36
+
37
typedef struct NPCM7xxCLKState {
38
SysBusDevice parent;
39
40
diff --git a/include/hw/timer/npcm7xx_timer.h b/include/hw/timer/npcm7xx_timer.h
41
index XXXXXXX..XXXXXXX 100644
42
--- a/include/hw/timer/npcm7xx_timer.h
43
+++ b/include/hw/timer/npcm7xx_timer.h
44
@@ -XXX,XX +XXX,XX @@
45
*/
46
#define NPCM7XX_TIMER_NR_REGS (0x54 / sizeof(uint32_t))
47
48
+/* The basic watchdog timer period is 2^14 clock cycles. */
49
+#define NPCM7XX_WATCHDOG_BASETIME_SHIFT 14
50
+
51
+#define NPCM7XX_WATCHDOG_RESET_GPIO_OUT "npcm7xx-clk-watchdog-reset-gpio-out"
52
+
53
typedef struct NPCM7xxTimerCtrlState NPCM7xxTimerCtrlState;
77
54
78
/**
55
/**
79
- * ptimer_init - Allocate and return a new ptimer
56
- * struct NPCM7xxTimer - Individual timer state.
80
+ * ptimer_init_with_bh - Allocate and return a new ptimer
57
- * @irq: GIC interrupt line to fire on expiration (if enabled).
81
* @bh: QEMU bottom half which is run on timer expiry
58
+ * struct NPCM7xxBaseTimer - Basic functionality that both regular timer and
82
* @policy: PTIMER_POLICY_* bits specifying behaviour
59
+ * watchdog timer use.
83
*
60
* @qtimer: QEMU timer that notifies us on expiration.
84
@@ -XXX,XX +XXX,XX @@ typedef void (*ptimer_cb)(void *opaque);
61
* @expires_ns: Absolute virtual expiration time.
85
* The ptimer takes ownership of @bh and will delete it
62
* @remaining_ns: Remaining time until expiration if timer is paused.
86
* when the ptimer is eventually freed.
63
+ */
64
+typedef struct NPCM7xxBaseTimer {
65
+ QEMUTimer qtimer;
66
+ int64_t expires_ns;
67
+ int64_t remaining_ns;
68
+} NPCM7xxBaseTimer;
69
+
70
+/**
71
+ * struct NPCM7xxTimer - Individual timer state.
72
+ * @ctrl: The timer module that owns this timer.
73
+ * @irq: GIC interrupt line to fire on expiration (if enabled).
74
+ * @base_timer: The basic timer functionality for this timer.
75
* @tcsr: The Timer Control and Status Register.
76
* @ticr: The Timer Initial Count Register.
87
*/
77
*/
88
-ptimer_state *ptimer_init(QEMUBH *bh, uint8_t policy_mask);
78
@@ -XXX,XX +XXX,XX @@ typedef struct NPCM7xxTimer {
89
+ptimer_state *ptimer_init_with_bh(QEMUBH *bh, uint8_t policy_mask);
79
NPCM7xxTimerCtrlState *ctrl;
90
80
81
qemu_irq irq;
82
- QEMUTimer qtimer;
83
- int64_t expires_ns;
84
- int64_t remaining_ns;
85
+ NPCM7xxBaseTimer base_timer;
86
87
uint32_t tcsr;
88
uint32_t ticr;
89
} NPCM7xxTimer;
90
91
+/**
92
+ * struct NPCM7xxWatchdogTimer - The watchdog timer state.
93
+ * @ctrl: The timer module that owns this timer.
94
+ * @irq: GIC interrupt line to fire on expiration (if enabled).
95
+ * @reset_signal: The GPIO used to send a reset signal.
96
+ * @base_timer: The basic timer functionality for this timer.
97
+ * @wtcr: The Watchdog Timer Control Register.
98
+ */
99
+typedef struct NPCM7xxWatchdogTimer {
100
+ NPCM7xxTimerCtrlState *ctrl;
101
+
102
+ qemu_irq irq;
103
+ qemu_irq reset_signal;
104
+ NPCM7xxBaseTimer base_timer;
105
+
106
+ uint32_t wtcr;
107
+} NPCM7xxWatchdogTimer;
108
+
91
/**
109
/**
92
* ptimer_free - Free a ptimer
110
* struct NPCM7xxTimerCtrlState - Timer Module device state.
93
* @s: timer to free
111
* @parent: System bus device.
94
*
112
* @iomem: Memory region through which registers are accessed.
95
- * Free a ptimer created using ptimer_init() (including
113
+ * @index: The index of this timer module.
96
+ * Free a ptimer created using ptimer_init_with_bh() (including
114
* @tisr: The Timer Interrupt Status Register.
97
* deleting the bottom half which it is using).
115
- * @wtcr: The Watchdog Timer Control Register.
116
* @timer: The five individual timers managed by this module.
117
+ * @watchdog_timer: The watchdog timer managed by this module.
98
*/
118
*/
99
void ptimer_free(ptimer_state *s);
119
struct NPCM7xxTimerCtrlState {
100
@@ -XXX,XX +XXX,XX @@ void ptimer_set_count(ptimer_state *s, uint64_t count);
120
SysBusDevice parent;
101
* @oneshot: non-zero if this timer should only count down once
121
@@ -XXX,XX +XXX,XX @@ struct NPCM7xxTimerCtrlState {
102
*
122
MemoryRegion iomem;
103
* Start a ptimer counting down; when it reaches zero the bottom half
123
104
- * passed to ptimer_init() will be invoked. If the @oneshot argument is zero,
124
uint32_t tisr;
105
+ * passed to ptimer_init_with_bh() will be invoked.
125
- uint32_t wtcr;
106
+ * If the @oneshot argument is zero,
126
107
* the counter value will then be reloaded from the limit and it will
127
NPCM7xxTimer timer[NPCM7XX_TIMERS_PER_CTRL];
108
* start counting down again. If @oneshot is non-zero, then the counter
128
+ NPCM7xxWatchdogTimer watchdog_timer;
109
* will disable itself when it reaches zero.
129
};
110
diff --git a/hw/arm/musicpal.c b/hw/arm/musicpal.c
130
131
#define TYPE_NPCM7XX_TIMER "npcm7xx-timer"
132
diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c
111
index XXXXXXX..XXXXXXX 100644
133
index XXXXXXX..XXXXXXX 100644
112
--- a/hw/arm/musicpal.c
134
--- a/hw/arm/npcm7xx.c
113
+++ b/hw/arm/musicpal.c
135
+++ b/hw/arm/npcm7xx.c
114
@@ -XXX,XX +XXX,XX @@ static void mv88w8618_timer_init(SysBusDevice *dev, mv88w8618_timer_state *s,
136
@@ -XXX,XX +XXX,XX @@ enum NPCM7xxInterrupt {
115
s->freq = freq;
137
NPCM7XX_TIMER12_IRQ,
116
138
NPCM7XX_TIMER13_IRQ,
117
bh = qemu_bh_new(mv88w8618_timer_tick, s);
139
NPCM7XX_TIMER14_IRQ,
118
- s->ptimer = ptimer_init(bh, PTIMER_POLICY_DEFAULT);
140
+ NPCM7XX_WDG0_IRQ = 47, /* Timer Module 0 Watchdog */
119
+ s->ptimer = ptimer_init_with_bh(bh, PTIMER_POLICY_DEFAULT);
141
+ NPCM7XX_WDG1_IRQ, /* Timer Module 1 Watchdog */
142
+ NPCM7XX_WDG2_IRQ, /* Timer Module 2 Watchdog */
143
};
144
145
/* Total number of GIC interrupts, including internal Cortex-A9 interrupts. */
146
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp)
147
qemu_irq irq = npcm7xx_irq(s, first_irq + j);
148
sysbus_connect_irq(sbd, j, irq);
149
}
150
+
151
+ /* IRQ for watchdogs */
152
+ sysbus_connect_irq(sbd, NPCM7XX_TIMERS_PER_CTRL,
153
+ npcm7xx_irq(s, NPCM7XX_WDG0_IRQ + i));
154
+ /* GPIO that connects clk module with watchdog */
155
+ qdev_connect_gpio_out_named(DEVICE(&s->tim[i]),
156
+ NPCM7XX_WATCHDOG_RESET_GPIO_OUT, 0,
157
+ qdev_get_gpio_in_named(DEVICE(&s->clk),
158
+ NPCM7XX_WATCHDOG_RESET_GPIO_IN, i));
159
}
160
161
/* UART0..3 (16550 compatible) */
162
diff --git a/hw/misc/npcm7xx_clk.c b/hw/misc/npcm7xx_clk.c
163
index XXXXXXX..XXXXXXX 100644
164
--- a/hw/misc/npcm7xx_clk.c
165
+++ b/hw/misc/npcm7xx_clk.c
166
@@ -XXX,XX +XXX,XX @@
167
#include "qemu/osdep.h"
168
169
#include "hw/misc/npcm7xx_clk.h"
170
+#include "hw/timer/npcm7xx_timer.h"
171
#include "migration/vmstate.h"
172
#include "qemu/error-report.h"
173
#include "qemu/log.h"
174
@@ -XXX,XX +XXX,XX @@
175
#include "qemu/timer.h"
176
#include "qemu/units.h"
177
#include "trace.h"
178
+#include "sysemu/watchdog.h"
179
180
#define PLLCON_LOKI BIT(31)
181
#define PLLCON_LOKS BIT(30)
182
@@ -XXX,XX +XXX,XX @@ static const uint32_t cold_reset_values[NPCM7XX_CLK_NR_REGS] = {
183
[NPCM7XX_CLK_AHBCKFI] = 0x000000c8,
184
};
185
186
+/* Register Field Definitions */
187
+#define NPCM7XX_CLK_WDRCR_CA9C BIT(0) /* Cortex A9 Cores */
188
+
189
+/* The number of watchdogs that can trigger a reset. */
190
+#define NPCM7XX_NR_WATCHDOGS (3)
191
+
192
static uint64_t npcm7xx_clk_read(void *opaque, hwaddr offset, unsigned size)
193
{
194
uint32_t reg = offset / sizeof(uint32_t);
195
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_clk_write(void *opaque, hwaddr offset,
196
s->regs[reg] = value;
120
}
197
}
121
198
122
static uint64_t mv88w8618_pit_read(void *opaque, hwaddr offset,
199
+/* Perform reset action triggered by a watchdog */
123
diff --git a/hw/core/ptimer.c b/hw/core/ptimer.c
200
+static void npcm7xx_clk_perform_watchdog_reset(void *opaque, int n,
201
+ int level)
202
+{
203
+ NPCM7xxCLKState *clk = NPCM7XX_CLK(opaque);
204
+ uint32_t rcr;
205
+
206
+ g_assert(n >= 0 && n <= NPCM7XX_NR_WATCHDOGS);
207
+ rcr = clk->regs[NPCM7XX_CLK_WD0RCR + n];
208
+ if (rcr & NPCM7XX_CLK_WDRCR_CA9C) {
209
+ watchdog_perform_action();
210
+ } else {
211
+ qemu_log_mask(LOG_UNIMP,
212
+ "%s: only CPU reset is implemented. (requested 0x%" PRIx32")\n",
213
+ __func__, rcr);
214
+ }
215
+}
216
+
217
static const struct MemoryRegionOps npcm7xx_clk_ops = {
218
.read = npcm7xx_clk_read,
219
.write = npcm7xx_clk_write,
220
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_clk_init(Object *obj)
221
memory_region_init_io(&s->iomem, obj, &npcm7xx_clk_ops, s,
222
TYPE_NPCM7XX_CLK, 4 * KiB);
223
sysbus_init_mmio(&s->parent, &s->iomem);
224
+ qdev_init_gpio_in_named(DEVICE(s), npcm7xx_clk_perform_watchdog_reset,
225
+ NPCM7XX_WATCHDOG_RESET_GPIO_IN, NPCM7XX_NR_WATCHDOGS);
226
}
227
228
static const VMStateDescription vmstate_npcm7xx_clk = {
229
diff --git a/hw/timer/npcm7xx_timer.c b/hw/timer/npcm7xx_timer.c
124
index XXXXXXX..XXXXXXX 100644
230
index XXXXXXX..XXXXXXX 100644
125
--- a/hw/core/ptimer.c
231
--- a/hw/timer/npcm7xx_timer.c
126
+++ b/hw/core/ptimer.c
232
+++ b/hw/timer/npcm7xx_timer.c
127
@@ -XXX,XX +XXX,XX @@ const VMStateDescription vmstate_ptimer = {
233
@@ -XXX,XX +XXX,XX @@
128
}
234
#include "qemu/osdep.h"
129
};
235
130
236
#include "hw/irq.h"
131
-ptimer_state *ptimer_init(QEMUBH *bh, uint8_t policy_mask)
237
+#include "hw/qdev-properties.h"
132
+ptimer_state *ptimer_init_with_bh(QEMUBH *bh, uint8_t policy_mask)
238
#include "hw/misc/npcm7xx_clk.h"
239
#include "hw/timer/npcm7xx_timer.h"
240
#include "migration/vmstate.h"
241
@@ -XXX,XX +XXX,XX @@ enum NPCM7xxTimerRegisters {
242
#define NPCM7XX_TCSR_PRESCALE_START 0
243
#define NPCM7XX_TCSR_PRESCALE_LEN 8
244
245
+#define NPCM7XX_WTCR_WTCLK(rv) extract32(rv, 10, 2)
246
+#define NPCM7XX_WTCR_FREEZE_EN BIT(9)
247
+#define NPCM7XX_WTCR_WTE BIT(7)
248
+#define NPCM7XX_WTCR_WTIE BIT(6)
249
+#define NPCM7XX_WTCR_WTIS(rv) extract32(rv, 4, 2)
250
+#define NPCM7XX_WTCR_WTIF BIT(3)
251
+#define NPCM7XX_WTCR_WTRF BIT(2)
252
+#define NPCM7XX_WTCR_WTRE BIT(1)
253
+#define NPCM7XX_WTCR_WTR BIT(0)
254
+
255
+/*
256
+ * The number of clock cycles between interrupt and reset in watchdog, used
257
+ * by the software to handle the interrupt before system is reset.
258
+ */
259
+#define NPCM7XX_WATCHDOG_INTERRUPT_TO_RESET_CYCLES 1024
260
+
261
+/* Start or resume the timer. */
262
+static void npcm7xx_timer_start(NPCM7xxBaseTimer *t)
263
+{
264
+ int64_t now;
265
+
266
+ now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
267
+ t->expires_ns = now + t->remaining_ns;
268
+ timer_mod(&t->qtimer, t->expires_ns);
269
+}
270
+
271
+/* Stop counting. Record the time remaining so we can continue later. */
272
+static void npcm7xx_timer_pause(NPCM7xxBaseTimer *t)
273
+{
274
+ int64_t now;
275
+
276
+ timer_del(&t->qtimer);
277
+ now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
278
+ t->remaining_ns = t->expires_ns - now;
279
+}
280
+
281
+/* Delete the timer and reset it to default state. */
282
+static void npcm7xx_timer_clear(NPCM7xxBaseTimer *t)
283
+{
284
+ timer_del(&t->qtimer);
285
+ t->expires_ns = 0;
286
+ t->remaining_ns = 0;
287
+}
288
+
289
/*
290
* Returns the index of timer in the tc->timer array. This can be used to
291
* locate the registers that belong to this timer.
292
@@ -XXX,XX +XXX,XX @@ static uint32_t npcm7xx_timer_ns_to_count(NPCM7xxTimer *t, int64_t ns)
293
return count;
294
}
295
296
+static uint32_t npcm7xx_watchdog_timer_prescaler(const NPCM7xxWatchdogTimer *t)
297
+{
298
+ switch (NPCM7XX_WTCR_WTCLK(t->wtcr)) {
299
+ case 0:
300
+ return 1;
301
+ case 1:
302
+ return 256;
303
+ case 2:
304
+ return 2048;
305
+ case 3:
306
+ return 65536;
307
+ default:
308
+ g_assert_not_reached();
309
+ }
310
+}
311
+
312
+static void npcm7xx_watchdog_timer_reset_cycles(NPCM7xxWatchdogTimer *t,
313
+ int64_t cycles)
314
+{
315
+ uint32_t prescaler = npcm7xx_watchdog_timer_prescaler(t);
316
+ int64_t ns = (NANOSECONDS_PER_SECOND / NPCM7XX_TIMER_REF_HZ) * cycles;
317
+
318
+ /*
319
+ * The reset function always clears the current timer. The caller of the
320
+ * this needs to decide whether to start the watchdog timer based on
321
+ * specific flag in WTCR.
322
+ */
323
+ npcm7xx_timer_clear(&t->base_timer);
324
+
325
+ ns *= prescaler;
326
+ t->base_timer.remaining_ns = ns;
327
+}
328
+
329
+static void npcm7xx_watchdog_timer_reset(NPCM7xxWatchdogTimer *t)
330
+{
331
+ int64_t cycles = 1;
332
+ uint32_t s = NPCM7XX_WTCR_WTIS(t->wtcr);
333
+
334
+ g_assert(s <= 3);
335
+
336
+ cycles <<= NPCM7XX_WATCHDOG_BASETIME_SHIFT;
337
+ cycles <<= 2 * s;
338
+
339
+ npcm7xx_watchdog_timer_reset_cycles(t, cycles);
340
+}
341
+
342
/*
343
* Raise the interrupt line if there's a pending interrupt and interrupts are
344
* enabled for this timer. If not, lower it.
345
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_check_interrupt(NPCM7xxTimer *t)
346
trace_npcm7xx_timer_irq(DEVICE(tc)->canonical_path, index, pending);
347
}
348
349
-/* Start or resume the timer. */
350
-static void npcm7xx_timer_start(NPCM7xxTimer *t)
351
-{
352
- int64_t now;
353
-
354
- now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
355
- t->expires_ns = now + t->remaining_ns;
356
- timer_mod(&t->qtimer, t->expires_ns);
357
-}
358
-
359
/*
360
* Called when the counter reaches zero. Sets the interrupt flag, and either
361
* restarts or disables the timer.
362
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_reached_zero(NPCM7xxTimer *t)
363
tc->tisr |= BIT(index);
364
365
if (t->tcsr & NPCM7XX_TCSR_PERIODIC) {
366
- t->remaining_ns = npcm7xx_timer_count_to_ns(t, t->ticr);
367
+ t->base_timer.remaining_ns = npcm7xx_timer_count_to_ns(t, t->ticr);
368
if (t->tcsr & NPCM7XX_TCSR_CEN) {
369
- npcm7xx_timer_start(t);
370
+ npcm7xx_timer_start(&t->base_timer);
371
}
372
} else {
373
t->tcsr &= ~(NPCM7XX_TCSR_CEN | NPCM7XX_TCSR_CACT);
374
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_reached_zero(NPCM7xxTimer *t)
375
npcm7xx_timer_check_interrupt(t);
376
}
377
378
-/* Stop counting. Record the time remaining so we can continue later. */
379
-static void npcm7xx_timer_pause(NPCM7xxTimer *t)
380
-{
381
- int64_t now;
382
-
383
- timer_del(&t->qtimer);
384
- now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
385
- t->remaining_ns = t->expires_ns - now;
386
-}
387
388
/*
389
* Restart the timer from its initial value. If the timer was enabled and stays
390
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_pause(NPCM7xxTimer *t)
391
*/
392
static void npcm7xx_timer_restart(NPCM7xxTimer *t, uint32_t old_tcsr)
133
{
393
{
134
ptimer_state *s;
394
- t->remaining_ns = npcm7xx_timer_count_to_ns(t, t->ticr);
135
395
+ t->base_timer.remaining_ns = npcm7xx_timer_count_to_ns(t, t->ticr);
136
diff --git a/hw/dma/xilinx_axidma.c b/hw/dma/xilinx_axidma.c
396
137
index XXXXXXX..XXXXXXX 100644
397
if (old_tcsr & t->tcsr & NPCM7XX_TCSR_CEN) {
138
--- a/hw/dma/xilinx_axidma.c
398
- npcm7xx_timer_start(t);
139
+++ b/hw/dma/xilinx_axidma.c
399
+ npcm7xx_timer_start(&t->base_timer);
140
@@ -XXX,XX +XXX,XX @@ static void xilinx_axidma_realize(DeviceState *dev, Error **errp)
141
142
st->nr = i;
143
st->bh = qemu_bh_new(timer_hit, st);
144
- st->ptimer = ptimer_init(st->bh, PTIMER_POLICY_DEFAULT);
145
+ st->ptimer = ptimer_init_with_bh(st->bh, PTIMER_POLICY_DEFAULT);
146
ptimer_set_freq(st->ptimer, s->freqhz);
147
}
148
return;
149
diff --git a/hw/m68k/mcf5206.c b/hw/m68k/mcf5206.c
150
index XXXXXXX..XXXXXXX 100644
151
--- a/hw/m68k/mcf5206.c
152
+++ b/hw/m68k/mcf5206.c
153
@@ -XXX,XX +XXX,XX @@ static m5206_timer_state *m5206_timer_init(qemu_irq irq)
154
155
s = g_new0(m5206_timer_state, 1);
156
bh = qemu_bh_new(m5206_timer_trigger, s);
157
- s->timer = ptimer_init(bh, PTIMER_POLICY_DEFAULT);
158
+ s->timer = ptimer_init_with_bh(bh, PTIMER_POLICY_DEFAULT);
159
s->irq = irq;
160
m5206_timer_reset(s);
161
return s;
162
diff --git a/hw/m68k/mcf5208.c b/hw/m68k/mcf5208.c
163
index XXXXXXX..XXXXXXX 100644
164
--- a/hw/m68k/mcf5208.c
165
+++ b/hw/m68k/mcf5208.c
166
@@ -XXX,XX +XXX,XX @@ static void mcf5208_sys_init(MemoryRegion *address_space, qemu_irq *pic)
167
for (i = 0; i < 2; i++) {
168
s = g_new0(m5208_timer_state, 1);
169
bh = qemu_bh_new(m5208_timer_trigger, s);
170
- s->timer = ptimer_init(bh, PTIMER_POLICY_DEFAULT);
171
+ s->timer = ptimer_init_with_bh(bh, PTIMER_POLICY_DEFAULT);
172
memory_region_init_io(&s->iomem, NULL, &m5208_timer_ops, s,
173
"m5208-timer", 0x00004000);
174
memory_region_add_subregion(address_space, 0xfc080000 + 0x4000 * i,
175
diff --git a/hw/net/fsl_etsec/etsec.c b/hw/net/fsl_etsec/etsec.c
176
index XXXXXXX..XXXXXXX 100644
177
--- a/hw/net/fsl_etsec/etsec.c
178
+++ b/hw/net/fsl_etsec/etsec.c
179
@@ -XXX,XX +XXX,XX @@ static void etsec_realize(DeviceState *dev, Error **errp)
180
181
182
etsec->bh = qemu_bh_new(etsec_timer_hit, etsec);
183
- etsec->ptimer = ptimer_init(etsec->bh, PTIMER_POLICY_DEFAULT);
184
+ etsec->ptimer = ptimer_init_with_bh(etsec->bh, PTIMER_POLICY_DEFAULT);
185
ptimer_set_freq(etsec->ptimer, 100);
186
}
187
188
diff --git a/hw/net/lan9118.c b/hw/net/lan9118.c
189
index XXXXXXX..XXXXXXX 100644
190
--- a/hw/net/lan9118.c
191
+++ b/hw/net/lan9118.c
192
@@ -XXX,XX +XXX,XX @@ static void lan9118_realize(DeviceState *dev, Error **errp)
193
s->txp = &s->tx_packet;
194
195
bh = qemu_bh_new(lan9118_tick, s);
196
- s->timer = ptimer_init(bh, PTIMER_POLICY_DEFAULT);
197
+ s->timer = ptimer_init_with_bh(bh, PTIMER_POLICY_DEFAULT);
198
ptimer_set_freq(s->timer, 10000);
199
ptimer_set_limit(s->timer, 0xffff, 1);
200
}
201
diff --git a/hw/timer/allwinner-a10-pit.c b/hw/timer/allwinner-a10-pit.c
202
index XXXXXXX..XXXXXXX 100644
203
--- a/hw/timer/allwinner-a10-pit.c
204
+++ b/hw/timer/allwinner-a10-pit.c
205
@@ -XXX,XX +XXX,XX @@ static void a10_pit_init(Object *obj)
206
tc->container = s;
207
tc->index = i;
208
bh[i] = qemu_bh_new(a10_pit_timer_cb, tc);
209
- s->timer[i] = ptimer_init(bh[i], PTIMER_POLICY_DEFAULT);
210
+ s->timer[i] = ptimer_init_with_bh(bh[i], PTIMER_POLICY_DEFAULT);
211
}
400
}
212
}
401
}
213
402
214
diff --git a/hw/timer/altera_timer.c b/hw/timer/altera_timer.c
403
@@ -XXX,XX +XXX,XX @@ static uint32_t npcm7xx_timer_read_tdr(NPCM7xxTimer *t)
215
index XXXXXXX..XXXXXXX 100644
404
if (t->tcsr & NPCM7XX_TCSR_CEN) {
216
--- a/hw/timer/altera_timer.c
405
int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
217
+++ b/hw/timer/altera_timer.c
406
218
@@ -XXX,XX +XXX,XX @@ static void altera_timer_realize(DeviceState *dev, Error **errp)
407
- return npcm7xx_timer_ns_to_count(t, t->expires_ns - now);
408
+ return npcm7xx_timer_ns_to_count(t, t->base_timer.expires_ns - now);
219
}
409
}
220
410
221
t->bh = qemu_bh_new(timer_hit, t);
411
- return npcm7xx_timer_ns_to_count(t, t->remaining_ns);
222
- t->ptimer = ptimer_init(t->bh, PTIMER_POLICY_DEFAULT);
412
+ return npcm7xx_timer_ns_to_count(t, t->base_timer.remaining_ns);
223
+ t->ptimer = ptimer_init_with_bh(t->bh, PTIMER_POLICY_DEFAULT);
413
}
224
ptimer_set_freq(t->ptimer, t->freq_hz);
414
225
415
static void npcm7xx_timer_write_tcsr(NPCM7xxTimer *t, uint32_t new_tcsr)
226
memory_region_init_io(&t->mmio, OBJECT(t), &timer_ops, t,
416
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_write_tcsr(NPCM7xxTimer *t, uint32_t new_tcsr)
227
diff --git a/hw/timer/arm_mptimer.c b/hw/timer/arm_mptimer.c
417
228
index XXXXXXX..XXXXXXX 100644
418
if (npcm7xx_tcsr_prescaler(old_tcsr) != npcm7xx_tcsr_prescaler(new_tcsr)) {
229
--- a/hw/timer/arm_mptimer.c
419
/* Recalculate time remaining based on the current TDR value. */
230
+++ b/hw/timer/arm_mptimer.c
420
- t->remaining_ns = npcm7xx_timer_count_to_ns(t, tdr);
231
@@ -XXX,XX +XXX,XX @@ static void arm_mptimer_reset(DeviceState *dev)
421
+ t->base_timer.remaining_ns = npcm7xx_timer_count_to_ns(t, tdr);
422
if (old_tcsr & t->tcsr & NPCM7XX_TCSR_CEN) {
423
- npcm7xx_timer_start(t);
424
+ npcm7xx_timer_start(&t->base_timer);
425
}
426
}
427
428
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_write_tcsr(NPCM7xxTimer *t, uint32_t new_tcsr)
429
if ((old_tcsr ^ new_tcsr) & NPCM7XX_TCSR_CEN) {
430
if (new_tcsr & NPCM7XX_TCSR_CEN) {
431
t->tcsr |= NPCM7XX_TCSR_CACT;
432
- npcm7xx_timer_start(t);
433
+ npcm7xx_timer_start(&t->base_timer);
434
} else {
435
t->tcsr &= ~NPCM7XX_TCSR_CACT;
436
- npcm7xx_timer_pause(t);
437
- if (t->remaining_ns <= 0) {
438
+ npcm7xx_timer_pause(&t->base_timer);
439
+ if (t->base_timer.remaining_ns <= 0) {
440
npcm7xx_timer_reached_zero(t);
441
}
442
}
443
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_write_tisr(NPCM7xxTimerCtrlState *s, uint32_t value)
444
if (value & (1U << i)) {
445
npcm7xx_timer_check_interrupt(&s->timer[i]);
446
}
447
+
232
}
448
}
233
}
449
}
234
450
235
-static void arm_mptimer_init(Object *obj)
451
+static void npcm7xx_timer_write_wtcr(NPCM7xxWatchdogTimer *t, uint32_t new_wtcr)
236
+static void arm_mptimer_init_with_bh(Object *obj)
452
+{
453
+ uint32_t old_wtcr = t->wtcr;
454
+
455
+ /*
456
+ * WTIF and WTRF are cleared by writing 1. Writing 0 makes these bits
457
+ * unchanged.
458
+ */
459
+ if (new_wtcr & NPCM7XX_WTCR_WTIF) {
460
+ new_wtcr &= ~NPCM7XX_WTCR_WTIF;
461
+ } else if (old_wtcr & NPCM7XX_WTCR_WTIF) {
462
+ new_wtcr |= NPCM7XX_WTCR_WTIF;
463
+ }
464
+ if (new_wtcr & NPCM7XX_WTCR_WTRF) {
465
+ new_wtcr &= ~NPCM7XX_WTCR_WTRF;
466
+ } else if (old_wtcr & NPCM7XX_WTCR_WTRF) {
467
+ new_wtcr |= NPCM7XX_WTCR_WTRF;
468
+ }
469
+
470
+ t->wtcr = new_wtcr;
471
+
472
+ if (new_wtcr & NPCM7XX_WTCR_WTR) {
473
+ t->wtcr &= ~NPCM7XX_WTCR_WTR;
474
+ npcm7xx_watchdog_timer_reset(t);
475
+ if (new_wtcr & NPCM7XX_WTCR_WTE) {
476
+ npcm7xx_timer_start(&t->base_timer);
477
+ }
478
+ } else if ((old_wtcr ^ new_wtcr) & NPCM7XX_WTCR_WTE) {
479
+ if (new_wtcr & NPCM7XX_WTCR_WTE) {
480
+ npcm7xx_timer_start(&t->base_timer);
481
+ } else {
482
+ npcm7xx_timer_pause(&t->base_timer);
483
+ }
484
+ }
485
+
486
+}
487
+
488
static hwaddr npcm7xx_tcsr_index(hwaddr reg)
237
{
489
{
238
ARMMPTimerState *s = ARM_MPTIMER(obj);
490
switch (reg) {
239
491
@@ -XXX,XX +XXX,XX @@ static uint64_t npcm7xx_timer_read(void *opaque, hwaddr offset, unsigned size)
240
@@ -XXX,XX +XXX,XX @@ static void arm_mptimer_realize(DeviceState *dev, Error **errp)
492
break;
241
for (i = 0; i < s->num_cpu; i++) {
493
242
TimerBlock *tb = &s->timerblock[i];
494
case NPCM7XX_TIMER_WTCR:
243
QEMUBH *bh = qemu_bh_new(timerblock_tick, tb);
495
- value = s->wtcr;
244
- tb->timer = ptimer_init(bh, PTIMER_POLICY);
496
+ value = s->watchdog_timer.wtcr;
245
+ tb->timer = ptimer_init_with_bh(bh, PTIMER_POLICY);
497
break;
246
sysbus_init_irq(sbd, &tb->irq);
498
247
memory_region_init_io(&tb->iomem, OBJECT(s), &timerblock_ops, tb,
499
default:
248
"arm_mptimer_timerblock", 0x20);
500
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_write(void *opaque, hwaddr offset,
249
@@ -XXX,XX +XXX,XX @@ static const TypeInfo arm_mptimer_info = {
501
return;
250
.name = TYPE_ARM_MPTIMER,
502
251
.parent = TYPE_SYS_BUS_DEVICE,
503
case NPCM7XX_TIMER_WTCR:
252
.instance_size = sizeof(ARMMPTimerState),
504
- qemu_log_mask(LOG_UNIMP, "%s: WTCR write not implemented: 0x%08x\n",
253
- .instance_init = arm_mptimer_init,
505
- __func__, value);
254
+ .instance_init = arm_mptimer_init_with_bh,
506
+ npcm7xx_timer_write_wtcr(&s->watchdog_timer, value);
255
.class_init = arm_mptimer_class_init,
507
return;
508
}
509
510
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_enter_reset(Object *obj, ResetType type)
511
for (i = 0; i < NPCM7XX_TIMERS_PER_CTRL; i++) {
512
NPCM7xxTimer *t = &s->timer[i];
513
514
- timer_del(&t->qtimer);
515
- t->expires_ns = 0;
516
- t->remaining_ns = 0;
517
+ npcm7xx_timer_clear(&t->base_timer);
518
t->tcsr = 0x00000005;
519
t->ticr = 0x00000000;
520
}
521
522
s->tisr = 0x00000000;
523
- s->wtcr = 0x00000400;
524
+ /*
525
+ * Set WTCLK to 1(default) and reset all flags except WTRF.
526
+ * WTRF is not reset during a core domain reset.
527
+ */
528
+ s->watchdog_timer.wtcr = 0x00000400 | (s->watchdog_timer.wtcr &
529
+ NPCM7XX_WTCR_WTRF);
530
+}
531
+
532
+static void npcm7xx_watchdog_timer_expired(void *opaque)
533
+{
534
+ NPCM7xxWatchdogTimer *t = opaque;
535
+
536
+ if (t->wtcr & NPCM7XX_WTCR_WTE) {
537
+ if (t->wtcr & NPCM7XX_WTCR_WTIF) {
538
+ if (t->wtcr & NPCM7XX_WTCR_WTRE) {
539
+ t->wtcr |= NPCM7XX_WTCR_WTRF;
540
+ /* send reset signal to CLK module*/
541
+ qemu_irq_raise(t->reset_signal);
542
+ }
543
+ } else {
544
+ t->wtcr |= NPCM7XX_WTCR_WTIF;
545
+ if (t->wtcr & NPCM7XX_WTCR_WTIE) {
546
+ /* send interrupt */
547
+ qemu_irq_raise(t->irq);
548
+ }
549
+ npcm7xx_watchdog_timer_reset_cycles(t,
550
+ NPCM7XX_WATCHDOG_INTERRUPT_TO_RESET_CYCLES);
551
+ npcm7xx_timer_start(&t->base_timer);
552
+ }
553
+ }
554
}
555
556
static void npcm7xx_timer_hold_reset(Object *obj)
557
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_hold_reset(Object *obj)
558
for (i = 0; i < NPCM7XX_TIMERS_PER_CTRL; i++) {
559
qemu_irq_lower(s->timer[i].irq);
560
}
561
+ qemu_irq_lower(s->watchdog_timer.irq);
562
}
563
564
static void npcm7xx_timer_realize(DeviceState *dev, Error **errp)
565
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_realize(DeviceState *dev, Error **errp)
566
NPCM7xxTimerCtrlState *s = NPCM7XX_TIMER(dev);
567
SysBusDevice *sbd = &s->parent;
568
int i;
569
+ NPCM7xxWatchdogTimer *w;
570
571
for (i = 0; i < NPCM7XX_TIMERS_PER_CTRL; i++) {
572
NPCM7xxTimer *t = &s->timer[i];
573
t->ctrl = s;
574
- timer_init_ns(&t->qtimer, QEMU_CLOCK_VIRTUAL, npcm7xx_timer_expired, t);
575
+ timer_init_ns(&t->base_timer.qtimer, QEMU_CLOCK_VIRTUAL,
576
+ npcm7xx_timer_expired, t);
577
sysbus_init_irq(sbd, &t->irq);
578
}
579
580
+ w = &s->watchdog_timer;
581
+ w->ctrl = s;
582
+ timer_init_ns(&w->base_timer.qtimer, QEMU_CLOCK_VIRTUAL,
583
+ npcm7xx_watchdog_timer_expired, w);
584
+ sysbus_init_irq(sbd, &w->irq);
585
+
586
memory_region_init_io(&s->iomem, OBJECT(s), &npcm7xx_timer_ops, s,
587
TYPE_NPCM7XX_TIMER, 4 * KiB);
588
sysbus_init_mmio(sbd, &s->iomem);
589
+ qdev_init_gpio_out_named(dev, &w->reset_signal,
590
+ NPCM7XX_WATCHDOG_RESET_GPIO_OUT, 1);
591
}
592
593
-static const VMStateDescription vmstate_npcm7xx_timer = {
594
- .name = "npcm7xx-timer",
595
+static const VMStateDescription vmstate_npcm7xx_base_timer = {
596
+ .name = "npcm7xx-base-timer",
597
.version_id = 0,
598
.minimum_version_id = 0,
599
.fields = (VMStateField[]) {
600
- VMSTATE_TIMER(qtimer, NPCM7xxTimer),
601
- VMSTATE_INT64(expires_ns, NPCM7xxTimer),
602
- VMSTATE_INT64(remaining_ns, NPCM7xxTimer),
603
+ VMSTATE_TIMER(qtimer, NPCM7xxBaseTimer),
604
+ VMSTATE_INT64(expires_ns, NPCM7xxBaseTimer),
605
+ VMSTATE_INT64(remaining_ns, NPCM7xxBaseTimer),
606
+ VMSTATE_END_OF_LIST(),
607
+ },
608
+};
609
+
610
+static const VMStateDescription vmstate_npcm7xx_timer = {
611
+ .name = "npcm7xx-timer",
612
+ .version_id = 1,
613
+ .minimum_version_id = 1,
614
+ .fields = (VMStateField[]) {
615
+ VMSTATE_STRUCT(base_timer, NPCM7xxTimer,
616
+ 0, vmstate_npcm7xx_base_timer,
617
+ NPCM7xxBaseTimer),
618
VMSTATE_UINT32(tcsr, NPCM7xxTimer),
619
VMSTATE_UINT32(ticr, NPCM7xxTimer),
620
VMSTATE_END_OF_LIST(),
621
},
256
};
622
};
257
623
258
diff --git a/hw/timer/arm_timer.c b/hw/timer/arm_timer.c
624
-static const VMStateDescription vmstate_npcm7xx_timer_ctrl = {
625
- .name = "npcm7xx-timer-ctrl",
626
+static const VMStateDescription vmstate_npcm7xx_watchdog_timer = {
627
+ .name = "npcm7xx-watchdog-timer",
628
.version_id = 0,
629
.minimum_version_id = 0,
630
+ .fields = (VMStateField[]) {
631
+ VMSTATE_STRUCT(base_timer, NPCM7xxWatchdogTimer,
632
+ 0, vmstate_npcm7xx_base_timer,
633
+ NPCM7xxBaseTimer),
634
+ VMSTATE_UINT32(wtcr, NPCM7xxWatchdogTimer),
635
+ VMSTATE_END_OF_LIST(),
636
+ },
637
+};
638
+
639
+static const VMStateDescription vmstate_npcm7xx_timer_ctrl = {
640
+ .name = "npcm7xx-timer-ctrl",
641
+ .version_id = 1,
642
+ .minimum_version_id = 1,
643
.fields = (VMStateField[]) {
644
VMSTATE_UINT32(tisr, NPCM7xxTimerCtrlState),
645
- VMSTATE_UINT32(wtcr, NPCM7xxTimerCtrlState),
646
VMSTATE_STRUCT_ARRAY(timer, NPCM7xxTimerCtrlState,
647
NPCM7XX_TIMERS_PER_CTRL, 0, vmstate_npcm7xx_timer,
648
NPCM7xxTimer),
649
+ VMSTATE_STRUCT(watchdog_timer, NPCM7xxTimerCtrlState,
650
+ 0, vmstate_npcm7xx_watchdog_timer,
651
+ NPCM7xxWatchdogTimer),
652
VMSTATE_END_OF_LIST(),
653
},
654
};
655
diff --git a/tests/qtest/npcm7xx_watchdog_timer-test.c b/tests/qtest/npcm7xx_watchdog_timer-test.c
656
new file mode 100644
657
index XXXXXXX..XXXXXXX
658
--- /dev/null
659
+++ b/tests/qtest/npcm7xx_watchdog_timer-test.c
660
@@ -XXX,XX +XXX,XX @@
661
+/*
662
+ * QTests for Nuvoton NPCM7xx Timer Watchdog Modules.
663
+ *
664
+ * Copyright 2020 Google LLC
665
+ *
666
+ * This program is free software; you can redistribute it and/or modify it
667
+ * under the terms of the GNU General Public License as published by the
668
+ * Free Software Foundation; either version 2 of the License, or
669
+ * (at your option) any later version.
670
+ *
671
+ * This program is distributed in the hope that it will be useful, but WITHOUT
672
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
673
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
674
+ * for more details.
675
+ */
676
+
677
+#include "qemu/osdep.h"
678
+#include "qemu/timer.h"
679
+
680
+#include "libqos/libqtest.h"
681
+#include "qapi/qmp/qdict.h"
682
+
683
+#define WTCR_OFFSET 0x1c
684
+#define REF_HZ (25000000)
685
+
686
+/* WTCR bit fields */
687
+#define WTCLK(rv) ((rv) << 10)
688
+#define WTE BIT(7)
689
+#define WTIE BIT(6)
690
+#define WTIS(rv) ((rv) << 4)
691
+#define WTIF BIT(3)
692
+#define WTRF BIT(2)
693
+#define WTRE BIT(1)
694
+#define WTR BIT(0)
695
+
696
+typedef struct Watchdog {
697
+ int irq;
698
+ uint64_t base_addr;
699
+} Watchdog;
700
+
701
+static const Watchdog watchdog_list[] = {
702
+ {
703
+ .irq = 47,
704
+ .base_addr = 0xf0008000
705
+ },
706
+ {
707
+ .irq = 48,
708
+ .base_addr = 0xf0009000
709
+ },
710
+ {
711
+ .irq = 49,
712
+ .base_addr = 0xf000a000
713
+ }
714
+};
715
+
716
+static int watchdog_index(const Watchdog *wd)
717
+{
718
+ ptrdiff_t diff = wd - watchdog_list;
719
+
720
+ g_assert(diff >= 0 && diff < ARRAY_SIZE(watchdog_list));
721
+
722
+ return diff;
723
+}
724
+
725
+static uint32_t watchdog_read_wtcr(QTestState *qts, const Watchdog *wd)
726
+{
727
+ return qtest_readl(qts, wd->base_addr + WTCR_OFFSET);
728
+}
729
+
730
+static void watchdog_write_wtcr(QTestState *qts, const Watchdog *wd,
731
+ uint32_t value)
732
+{
733
+ qtest_writel(qts, wd->base_addr + WTCR_OFFSET, value);
734
+}
735
+
736
+static uint32_t watchdog_prescaler(QTestState *qts, const Watchdog *wd)
737
+{
738
+ switch (extract32(watchdog_read_wtcr(qts, wd), 10, 2)) {
739
+ case 0:
740
+ return 1;
741
+ case 1:
742
+ return 256;
743
+ case 2:
744
+ return 2048;
745
+ case 3:
746
+ return 65536;
747
+ default:
748
+ g_assert_not_reached();
749
+ }
750
+}
751
+
752
+static QDict *get_watchdog_action(QTestState *qts)
753
+{
754
+ QDict *ev = qtest_qmp_eventwait_ref(qts, "WATCHDOG");
755
+ QDict *data;
756
+
757
+ data = qdict_get_qdict(ev, "data");
758
+ qobject_ref(data);
759
+ qobject_unref(ev);
760
+ return data;
761
+}
762
+
763
+#define RESET_CYCLES 1024
764
+static uint32_t watchdog_interrupt_cycles(QTestState *qts, const Watchdog *wd)
765
+{
766
+ uint32_t wtis = extract32(watchdog_read_wtcr(qts, wd), 4, 2);
767
+ return 1 << (14 + 2 * wtis);
768
+}
769
+
770
+static int64_t watchdog_calculate_steps(uint32_t count, uint32_t prescale)
771
+{
772
+ return (NANOSECONDS_PER_SECOND / REF_HZ) * count * prescale;
773
+}
774
+
775
+static int64_t watchdog_interrupt_steps(QTestState *qts, const Watchdog *wd)
776
+{
777
+ return watchdog_calculate_steps(watchdog_interrupt_cycles(qts, wd),
778
+ watchdog_prescaler(qts, wd));
779
+}
780
+
781
+/* Check wtcr can be reset to default value */
782
+static void test_init(gconstpointer watchdog)
783
+{
784
+ const Watchdog *wd = watchdog;
785
+ QTestState *qts = qtest_init("-machine quanta-gsj");
786
+
787
+ qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic");
788
+
789
+ watchdog_write_wtcr(qts, wd, WTCLK(1) | WTRF | WTIF | WTR);
790
+ g_assert_cmphex(watchdog_read_wtcr(qts, wd), ==, WTCLK(1));
791
+
792
+ qtest_quit(qts);
793
+}
794
+
795
+/* Check a watchdog can generate interrupt and reset actions */
796
+static void test_reset_action(gconstpointer watchdog)
797
+{
798
+ const Watchdog *wd = watchdog;
799
+ QTestState *qts = qtest_init("-machine quanta-gsj");
800
+ QDict *ad;
801
+
802
+ qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic");
803
+
804
+ watchdog_write_wtcr(qts, wd,
805
+ WTCLK(0) | WTE | WTRF | WTRE | WTIF | WTIE | WTR);
806
+ g_assert_cmphex(watchdog_read_wtcr(qts, wd), ==,
807
+ WTCLK(0) | WTE | WTRE | WTIE);
808
+
809
+ /* Check a watchdog can generate an interrupt */
810
+ qtest_clock_step(qts, watchdog_interrupt_steps(qts, wd));
811
+ g_assert_cmphex(watchdog_read_wtcr(qts, wd), ==,
812
+ WTCLK(0) | WTE | WTIF | WTIE | WTRE);
813
+ g_assert_true(qtest_get_irq(qts, wd->irq));
814
+
815
+ /* Check a watchdog can generate a reset signal */
816
+ qtest_clock_step(qts, watchdog_calculate_steps(RESET_CYCLES,
817
+ watchdog_prescaler(qts, wd)));
818
+ ad = get_watchdog_action(qts);
819
+ /* The signal is a reset signal */
820
+ g_assert_false(strcmp(qdict_get_str(ad, "action"), "reset"));
821
+ qobject_unref(ad);
822
+ qtest_qmp_eventwait(qts, "RESET");
823
+ /*
824
+ * Make sure WTCR is reset to default except for WTRF bit which shouldn't
825
+ * be reset.
826
+ */
827
+ g_assert_cmphex(watchdog_read_wtcr(qts, wd), ==, WTCLK(1) | WTRF);
828
+ qtest_quit(qts);
829
+}
830
+
831
+/* Check a watchdog works with all possible WTCLK prescalers and WTIS cycles */
832
+static void test_prescaler(gconstpointer watchdog)
833
+{
834
+ const Watchdog *wd = watchdog;
835
+
836
+ for (int wtclk = 0; wtclk < 4; ++wtclk) {
837
+ for (int wtis = 0; wtis < 4; ++wtis) {
838
+ QTestState *qts = qtest_init("-machine quanta-gsj");
839
+
840
+ qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic");
841
+ watchdog_write_wtcr(qts, wd,
842
+ WTCLK(wtclk) | WTE | WTIF | WTIS(wtis) | WTIE | WTR);
843
+ /*
844
+ * The interrupt doesn't fire until watchdog_interrupt_steps()
845
+ * cycles passed
846
+ */
847
+ qtest_clock_step(qts, watchdog_interrupt_steps(qts, wd) - 1);
848
+ g_assert_false(watchdog_read_wtcr(qts, wd) & WTIF);
849
+ g_assert_false(qtest_get_irq(qts, wd->irq));
850
+ qtest_clock_step(qts, 1);
851
+ g_assert_true(watchdog_read_wtcr(qts, wd) & WTIF);
852
+ g_assert_true(qtest_get_irq(qts, wd->irq));
853
+
854
+ qtest_quit(qts);
855
+ }
856
+ }
857
+}
858
+
859
+/*
860
+ * Check a watchdog doesn't fire if corresponding flags (WTIE and WTRE) are not
861
+ * set.
862
+ */
863
+static void test_enabling_flags(gconstpointer watchdog)
864
+{
865
+ const Watchdog *wd = watchdog;
866
+ QTestState *qts;
867
+
868
+ /* Neither WTIE or WTRE is set, no interrupt or reset should happen */
869
+ qts = qtest_init("-machine quanta-gsj");
870
+ qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic");
871
+ watchdog_write_wtcr(qts, wd, WTCLK(0) | WTE | WTIF | WTRF | WTR);
872
+ qtest_clock_step(qts, watchdog_interrupt_steps(qts, wd));
873
+ g_assert_true(watchdog_read_wtcr(qts, wd) & WTIF);
874
+ g_assert_false(qtest_get_irq(qts, wd->irq));
875
+ qtest_clock_step(qts, watchdog_calculate_steps(RESET_CYCLES,
876
+ watchdog_prescaler(qts, wd)));
877
+ g_assert_true(watchdog_read_wtcr(qts, wd) & WTIF);
878
+ g_assert_false(watchdog_read_wtcr(qts, wd) & WTRF);
879
+ qtest_quit(qts);
880
+
881
+ /* Only WTIE is set, interrupt is triggered but reset should not happen */
882
+ qts = qtest_init("-machine quanta-gsj");
883
+ qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic");
884
+ watchdog_write_wtcr(qts, wd, WTCLK(0) | WTE | WTIF | WTIE | WTRF | WTR);
885
+ qtest_clock_step(qts, watchdog_interrupt_steps(qts, wd));
886
+ g_assert_true(watchdog_read_wtcr(qts, wd) & WTIF);
887
+ g_assert_true(qtest_get_irq(qts, wd->irq));
888
+ qtest_clock_step(qts, watchdog_calculate_steps(RESET_CYCLES,
889
+ watchdog_prescaler(qts, wd)));
890
+ g_assert_true(watchdog_read_wtcr(qts, wd) & WTIF);
891
+ g_assert_false(watchdog_read_wtcr(qts, wd) & WTRF);
892
+ qtest_quit(qts);
893
+
894
+ /* Only WTRE is set, interrupt is triggered but reset should not happen */
895
+ qts = qtest_init("-machine quanta-gsj");
896
+ qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic");
897
+ watchdog_write_wtcr(qts, wd, WTCLK(0) | WTE | WTIF | WTRE | WTRF | WTR);
898
+ qtest_clock_step(qts, watchdog_interrupt_steps(qts, wd));
899
+ g_assert_true(watchdog_read_wtcr(qts, wd) & WTIF);
900
+ g_assert_false(qtest_get_irq(qts, wd->irq));
901
+ qtest_clock_step(qts, watchdog_calculate_steps(RESET_CYCLES,
902
+ watchdog_prescaler(qts, wd)));
903
+ g_assert_false(strcmp(qdict_get_str(get_watchdog_action(qts), "action"),
904
+ "reset"));
905
+ qtest_qmp_eventwait(qts, "RESET");
906
+ qtest_quit(qts);
907
+
908
+ /*
909
+ * The case when both flags are set is already tested in
910
+ * test_reset_action().
911
+ */
912
+}
913
+
914
+/* Check a watchdog can pause and resume by setting WTE bits */
915
+static void test_pause(gconstpointer watchdog)
916
+{
917
+ const Watchdog *wd = watchdog;
918
+ QTestState *qts;
919
+ int64_t remaining_steps, steps;
920
+
921
+ qts = qtest_init("-machine quanta-gsj");
922
+ qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic");
923
+ watchdog_write_wtcr(qts, wd, WTCLK(0) | WTE | WTIF | WTIE | WTRF | WTR);
924
+ remaining_steps = watchdog_interrupt_steps(qts, wd);
925
+ g_assert_cmphex(watchdog_read_wtcr(qts, wd), ==, WTCLK(0) | WTE | WTIE);
926
+
927
+ /* Run for half of the execution period. */
928
+ steps = remaining_steps / 2;
929
+ remaining_steps -= steps;
930
+ qtest_clock_step(qts, steps);
931
+
932
+ /* Pause the watchdog */
933
+ watchdog_write_wtcr(qts, wd, WTCLK(0) | WTIE);
934
+ g_assert_cmphex(watchdog_read_wtcr(qts, wd), ==, WTCLK(0) | WTIE);
935
+
936
+ /* Run for a long period of time, the watchdog shouldn't fire */
937
+ qtest_clock_step(qts, steps << 4);
938
+ g_assert_cmphex(watchdog_read_wtcr(qts, wd), ==, WTCLK(0) | WTIE);
939
+ g_assert_false(qtest_get_irq(qts, wd->irq));
940
+
941
+ /* Resume the watchdog */
942
+ watchdog_write_wtcr(qts, wd, WTCLK(0) | WTE | WTIE);
943
+ g_assert_cmphex(watchdog_read_wtcr(qts, wd), ==, WTCLK(0) | WTE | WTIE);
944
+
945
+ /* Run for the reset of the execution period, the watchdog should fire */
946
+ qtest_clock_step(qts, remaining_steps);
947
+ g_assert_cmphex(watchdog_read_wtcr(qts, wd), ==,
948
+ WTCLK(0) | WTE | WTIF | WTIE);
949
+ g_assert_true(qtest_get_irq(qts, wd->irq));
950
+
951
+ qtest_quit(qts);
952
+}
953
+
954
+static void watchdog_add_test(const char *name, const Watchdog* wd,
955
+ GTestDataFunc fn)
956
+{
957
+ g_autofree char *full_name = g_strdup_printf(
958
+ "npcm7xx_watchdog_timer[%d]/%s", watchdog_index(wd), name);
959
+ qtest_add_data_func(full_name, wd, fn);
960
+}
961
+#define add_test(name, td) watchdog_add_test(#name, td, test_##name)
962
+
963
+int main(int argc, char **argv)
964
+{
965
+ g_test_init(&argc, &argv, NULL);
966
+ g_test_set_nonfatal_assertions();
967
+
968
+ for (int i = 0; i < ARRAY_SIZE(watchdog_list); ++i) {
969
+ const Watchdog *wd = &watchdog_list[i];
970
+
971
+ add_test(init, wd);
972
+ add_test(reset_action, wd);
973
+ add_test(prescaler, wd);
974
+ add_test(enabling_flags, wd);
975
+ add_test(pause, wd);
976
+ }
977
+
978
+ return g_test_run();
979
+}
980
diff --git a/MAINTAINERS b/MAINTAINERS
259
index XXXXXXX..XXXXXXX 100644
981
index XXXXXXX..XXXXXXX 100644
260
--- a/hw/timer/arm_timer.c
982
--- a/MAINTAINERS
261
+++ b/hw/timer/arm_timer.c
983
+++ b/MAINTAINERS
262
@@ -XXX,XX +XXX,XX @@ static arm_timer_state *arm_timer_init(uint32_t freq)
984
@@ -XXX,XX +XXX,XX @@ L: qemu-arm@nongnu.org
263
s->control = TIMER_CTRL_IE;
985
S: Supported
264
986
F: hw/*/npcm7xx*
265
bh = qemu_bh_new(arm_timer_tick, s);
987
F: include/hw/*/npcm7xx*
266
- s->timer = ptimer_init(bh, PTIMER_POLICY_DEFAULT);
988
+F: tests/qtest/npcm7xx*
267
+ s->timer = ptimer_init_with_bh(bh, PTIMER_POLICY_DEFAULT);
989
F: pc-bios/npcm7xx_bootrom.bin
268
vmstate_register(NULL, -1, &vmstate_arm_timer, s);
990
F: roms/vbootrom
269
return s;
991
270
}
992
diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
271
diff --git a/hw/timer/cmsdk-apb-dualtimer.c b/hw/timer/cmsdk-apb-dualtimer.c
272
index XXXXXXX..XXXXXXX 100644
993
index XXXXXXX..XXXXXXX 100644
273
--- a/hw/timer/cmsdk-apb-dualtimer.c
994
--- a/tests/qtest/meson.build
274
+++ b/hw/timer/cmsdk-apb-dualtimer.c
995
+++ b/tests/qtest/meson.build
275
@@ -XXX,XX +XXX,XX @@ static void cmsdk_apb_dualtimer_realize(DeviceState *dev, Error **errp)
996
@@ -XXX,XX +XXX,XX @@ qtests_sparc64 = \
276
QEMUBH *bh = qemu_bh_new(cmsdk_dualtimermod_tick, m);
997
(config_all_devices.has_key('CONFIG_ISA_TESTDEV') ? ['endianness-test'] : []) + \
277
998
['prom-env-test', 'boot-serial-test']
278
m->parent = s;
999
279
- m->timer = ptimer_init(bh,
1000
-qtests_npcm7xx = ['npcm7xx_timer-test']
280
+ m->timer = ptimer_init_with_bh(bh,
1001
+qtests_npcm7xx = ['npcm7xx_timer-test', 'npcm7xx_watchdog_timer-test']
281
PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD |
1002
qtests_arm = \
282
PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT |
1003
(config_all_devices.has_key('CONFIG_PFLASH_CFI02') ? ['pflash-cfi02-test'] : []) + \
283
PTIMER_POLICY_NO_IMMEDIATE_RELOAD |
1004
(config_all_devices.has_key('CONFIG_NPCM7XX') ? qtests_npcm7xx : []) + \
284
diff --git a/hw/timer/cmsdk-apb-timer.c b/hw/timer/cmsdk-apb-timer.c
285
index XXXXXXX..XXXXXXX 100644
286
--- a/hw/timer/cmsdk-apb-timer.c
287
+++ b/hw/timer/cmsdk-apb-timer.c
288
@@ -XXX,XX +XXX,XX @@ static void cmsdk_apb_timer_realize(DeviceState *dev, Error **errp)
289
}
290
291
bh = qemu_bh_new(cmsdk_apb_timer_tick, s);
292
- s->timer = ptimer_init(bh,
293
+ s->timer = ptimer_init_with_bh(bh,
294
PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD |
295
PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT |
296
PTIMER_POLICY_NO_IMMEDIATE_RELOAD |
297
diff --git a/hw/timer/digic-timer.c b/hw/timer/digic-timer.c
298
index XXXXXXX..XXXXXXX 100644
299
--- a/hw/timer/digic-timer.c
300
+++ b/hw/timer/digic-timer.c
301
@@ -XXX,XX +XXX,XX @@ static void digic_timer_init(Object *obj)
302
{
303
DigicTimerState *s = DIGIC_TIMER(obj);
304
305
- s->ptimer = ptimer_init(NULL, PTIMER_POLICY_DEFAULT);
306
+ s->ptimer = ptimer_init_with_bh(NULL, PTIMER_POLICY_DEFAULT);
307
308
/*
309
* FIXME: there is no documentation on Digic timer
310
diff --git a/hw/timer/etraxfs_timer.c b/hw/timer/etraxfs_timer.c
311
index XXXXXXX..XXXXXXX 100644
312
--- a/hw/timer/etraxfs_timer.c
313
+++ b/hw/timer/etraxfs_timer.c
314
@@ -XXX,XX +XXX,XX @@ static void etraxfs_timer_realize(DeviceState *dev, Error **errp)
315
t->bh_t0 = qemu_bh_new(timer0_hit, t);
316
t->bh_t1 = qemu_bh_new(timer1_hit, t);
317
t->bh_wd = qemu_bh_new(watchdog_hit, t);
318
- t->ptimer_t0 = ptimer_init(t->bh_t0, PTIMER_POLICY_DEFAULT);
319
- t->ptimer_t1 = ptimer_init(t->bh_t1, PTIMER_POLICY_DEFAULT);
320
- t->ptimer_wd = ptimer_init(t->bh_wd, PTIMER_POLICY_DEFAULT);
321
+ t->ptimer_t0 = ptimer_init_with_bh(t->bh_t0, PTIMER_POLICY_DEFAULT);
322
+ t->ptimer_t1 = ptimer_init_with_bh(t->bh_t1, PTIMER_POLICY_DEFAULT);
323
+ t->ptimer_wd = ptimer_init_with_bh(t->bh_wd, PTIMER_POLICY_DEFAULT);
324
325
sysbus_init_irq(sbd, &t->irq);
326
sysbus_init_irq(sbd, &t->nmi);
327
diff --git a/hw/timer/exynos4210_mct.c b/hw/timer/exynos4210_mct.c
328
index XXXXXXX..XXXXXXX 100644
329
--- a/hw/timer/exynos4210_mct.c
330
+++ b/hw/timer/exynos4210_mct.c
331
@@ -XXX,XX +XXX,XX @@ static void exynos4210_mct_init(Object *obj)
332
333
/* Global timer */
334
bh[0] = qemu_bh_new(exynos4210_gfrc_event, s);
335
- s->g_timer.ptimer_frc = ptimer_init(bh[0], PTIMER_POLICY_DEFAULT);
336
+ s->g_timer.ptimer_frc = ptimer_init_with_bh(bh[0], PTIMER_POLICY_DEFAULT);
337
memset(&s->g_timer.reg, 0, sizeof(struct gregs));
338
339
/* Local timers */
340
@@ -XXX,XX +XXX,XX @@ static void exynos4210_mct_init(Object *obj)
341
bh[0] = qemu_bh_new(exynos4210_ltick_event, &s->l_timer[i]);
342
bh[1] = qemu_bh_new(exynos4210_lfrc_event, &s->l_timer[i]);
343
s->l_timer[i].tick_timer.ptimer_tick =
344
- ptimer_init(bh[0], PTIMER_POLICY_DEFAULT);
345
- s->l_timer[i].ptimer_frc = ptimer_init(bh[1], PTIMER_POLICY_DEFAULT);
346
+ ptimer_init_with_bh(bh[0], PTIMER_POLICY_DEFAULT);
347
+ s->l_timer[i].ptimer_frc =
348
+ ptimer_init_with_bh(bh[1], PTIMER_POLICY_DEFAULT);
349
s->l_timer[i].id = i;
350
}
351
352
diff --git a/hw/timer/exynos4210_pwm.c b/hw/timer/exynos4210_pwm.c
353
index XXXXXXX..XXXXXXX 100644
354
--- a/hw/timer/exynos4210_pwm.c
355
+++ b/hw/timer/exynos4210_pwm.c
356
@@ -XXX,XX +XXX,XX @@ static void exynos4210_pwm_init(Object *obj)
357
for (i = 0; i < EXYNOS4210_PWM_TIMERS_NUM; i++) {
358
bh = qemu_bh_new(exynos4210_pwm_tick, &s->timer[i]);
359
sysbus_init_irq(dev, &s->timer[i].irq);
360
- s->timer[i].ptimer = ptimer_init(bh, PTIMER_POLICY_DEFAULT);
361
+ s->timer[i].ptimer = ptimer_init_with_bh(bh, PTIMER_POLICY_DEFAULT);
362
s->timer[i].id = i;
363
s->timer[i].parent = s;
364
}
365
diff --git a/hw/timer/exynos4210_rtc.c b/hw/timer/exynos4210_rtc.c
366
index XXXXXXX..XXXXXXX 100644
367
--- a/hw/timer/exynos4210_rtc.c
368
+++ b/hw/timer/exynos4210_rtc.c
369
@@ -XXX,XX +XXX,XX @@ static void exynos4210_rtc_init(Object *obj)
370
QEMUBH *bh;
371
372
bh = qemu_bh_new(exynos4210_rtc_tick, s);
373
- s->ptimer = ptimer_init(bh, PTIMER_POLICY_DEFAULT);
374
+ s->ptimer = ptimer_init_with_bh(bh, PTIMER_POLICY_DEFAULT);
375
ptimer_set_freq(s->ptimer, RTC_BASE_FREQ);
376
exynos4210_rtc_update_freq(s, 0);
377
378
bh = qemu_bh_new(exynos4210_rtc_1Hz_tick, s);
379
- s->ptimer_1Hz = ptimer_init(bh, PTIMER_POLICY_DEFAULT);
380
+ s->ptimer_1Hz = ptimer_init_with_bh(bh, PTIMER_POLICY_DEFAULT);
381
ptimer_set_freq(s->ptimer_1Hz, RTC_BASE_FREQ);
382
383
sysbus_init_irq(dev, &s->alm_irq);
384
diff --git a/hw/timer/grlib_gptimer.c b/hw/timer/grlib_gptimer.c
385
index XXXXXXX..XXXXXXX 100644
386
--- a/hw/timer/grlib_gptimer.c
387
+++ b/hw/timer/grlib_gptimer.c
388
@@ -XXX,XX +XXX,XX @@ static void grlib_gptimer_realize(DeviceState *dev, Error **errp)
389
390
timer->unit = unit;
391
timer->bh = qemu_bh_new(grlib_gptimer_hit, timer);
392
- timer->ptimer = ptimer_init(timer->bh, PTIMER_POLICY_DEFAULT);
393
+ timer->ptimer = ptimer_init_with_bh(timer->bh, PTIMER_POLICY_DEFAULT);
394
timer->id = i;
395
396
/* One IRQ line for each timer */
397
diff --git a/hw/timer/imx_epit.c b/hw/timer/imx_epit.c
398
index XXXXXXX..XXXXXXX 100644
399
--- a/hw/timer/imx_epit.c
400
+++ b/hw/timer/imx_epit.c
401
@@ -XXX,XX +XXX,XX @@ static void imx_epit_realize(DeviceState *dev, Error **errp)
402
0x00001000);
403
sysbus_init_mmio(sbd, &s->iomem);
404
405
- s->timer_reload = ptimer_init(NULL, PTIMER_POLICY_DEFAULT);
406
+ s->timer_reload = ptimer_init_with_bh(NULL, PTIMER_POLICY_DEFAULT);
407
408
bh = qemu_bh_new(imx_epit_cmp, s);
409
- s->timer_cmp = ptimer_init(bh, PTIMER_POLICY_DEFAULT);
410
+ s->timer_cmp = ptimer_init_with_bh(bh, PTIMER_POLICY_DEFAULT);
411
}
412
413
static void imx_epit_class_init(ObjectClass *klass, void *data)
414
diff --git a/hw/timer/imx_gpt.c b/hw/timer/imx_gpt.c
415
index XXXXXXX..XXXXXXX 100644
416
--- a/hw/timer/imx_gpt.c
417
+++ b/hw/timer/imx_gpt.c
418
@@ -XXX,XX +XXX,XX @@ static void imx_gpt_realize(DeviceState *dev, Error **errp)
419
sysbus_init_mmio(sbd, &s->iomem);
420
421
bh = qemu_bh_new(imx_gpt_timeout, s);
422
- s->timer = ptimer_init(bh, PTIMER_POLICY_DEFAULT);
423
+ s->timer = ptimer_init_with_bh(bh, PTIMER_POLICY_DEFAULT);
424
}
425
426
static void imx_gpt_class_init(ObjectClass *klass, void *data)
427
diff --git a/hw/timer/lm32_timer.c b/hw/timer/lm32_timer.c
428
index XXXXXXX..XXXXXXX 100644
429
--- a/hw/timer/lm32_timer.c
430
+++ b/hw/timer/lm32_timer.c
431
@@ -XXX,XX +XXX,XX @@ static void lm32_timer_realize(DeviceState *dev, Error **errp)
432
LM32TimerState *s = LM32_TIMER(dev);
433
434
s->bh = qemu_bh_new(timer_hit, s);
435
- s->ptimer = ptimer_init(s->bh, PTIMER_POLICY_DEFAULT);
436
+ s->ptimer = ptimer_init_with_bh(s->bh, PTIMER_POLICY_DEFAULT);
437
438
ptimer_set_freq(s->ptimer, s->freq_hz);
439
}
440
diff --git a/hw/timer/milkymist-sysctl.c b/hw/timer/milkymist-sysctl.c
441
index XXXXXXX..XXXXXXX 100644
442
--- a/hw/timer/milkymist-sysctl.c
443
+++ b/hw/timer/milkymist-sysctl.c
444
@@ -XXX,XX +XXX,XX @@ static void milkymist_sysctl_realize(DeviceState *dev, Error **errp)
445
446
s->bh0 = qemu_bh_new(timer0_hit, s);
447
s->bh1 = qemu_bh_new(timer1_hit, s);
448
- s->ptimer0 = ptimer_init(s->bh0, PTIMER_POLICY_DEFAULT);
449
- s->ptimer1 = ptimer_init(s->bh1, PTIMER_POLICY_DEFAULT);
450
+ s->ptimer0 = ptimer_init_with_bh(s->bh0, PTIMER_POLICY_DEFAULT);
451
+ s->ptimer1 = ptimer_init_with_bh(s->bh1, PTIMER_POLICY_DEFAULT);
452
453
ptimer_set_freq(s->ptimer0, s->freq_hz);
454
ptimer_set_freq(s->ptimer1, s->freq_hz);
455
diff --git a/hw/timer/mss-timer.c b/hw/timer/mss-timer.c
456
index XXXXXXX..XXXXXXX 100644
457
--- a/hw/timer/mss-timer.c
458
+++ b/hw/timer/mss-timer.c
459
@@ -XXX,XX +XXX,XX @@ static void mss_timer_init(Object *obj)
460
struct Msf2Timer *st = &t->timers[i];
461
462
st->bh = qemu_bh_new(timer_hit, st);
463
- st->ptimer = ptimer_init(st->bh, PTIMER_POLICY_DEFAULT);
464
+ st->ptimer = ptimer_init_with_bh(st->bh, PTIMER_POLICY_DEFAULT);
465
ptimer_set_freq(st->ptimer, t->freq_hz);
466
sysbus_init_irq(SYS_BUS_DEVICE(obj), &st->irq);
467
}
468
diff --git a/hw/timer/puv3_ost.c b/hw/timer/puv3_ost.c
469
index XXXXXXX..XXXXXXX 100644
470
--- a/hw/timer/puv3_ost.c
471
+++ b/hw/timer/puv3_ost.c
472
@@ -XXX,XX +XXX,XX @@ static void puv3_ost_realize(DeviceState *dev, Error **errp)
473
sysbus_init_irq(sbd, &s->irq);
474
475
s->bh = qemu_bh_new(puv3_ost_tick, s);
476
- s->ptimer = ptimer_init(s->bh, PTIMER_POLICY_DEFAULT);
477
+ s->ptimer = ptimer_init_with_bh(s->bh, PTIMER_POLICY_DEFAULT);
478
ptimer_set_freq(s->ptimer, 50 * 1000 * 1000);
479
480
memory_region_init_io(&s->iomem, OBJECT(s), &puv3_ost_ops, s, "puv3_ost",
481
diff --git a/hw/timer/sh_timer.c b/hw/timer/sh_timer.c
482
index XXXXXXX..XXXXXXX 100644
483
--- a/hw/timer/sh_timer.c
484
+++ b/hw/timer/sh_timer.c
485
@@ -XXX,XX +XXX,XX @@ static void *sh_timer_init(uint32_t freq, int feat, qemu_irq irq)
486
s->irq = irq;
487
488
bh = qemu_bh_new(sh_timer_tick, s);
489
- s->timer = ptimer_init(bh, PTIMER_POLICY_DEFAULT);
490
+ s->timer = ptimer_init_with_bh(bh, PTIMER_POLICY_DEFAULT);
491
492
sh_timer_write(s, OFFSET_TCOR >> 2, s->tcor);
493
sh_timer_write(s, OFFSET_TCNT >> 2, s->tcnt);
494
diff --git a/hw/timer/slavio_timer.c b/hw/timer/slavio_timer.c
495
index XXXXXXX..XXXXXXX 100644
496
--- a/hw/timer/slavio_timer.c
497
+++ b/hw/timer/slavio_timer.c
498
@@ -XXX,XX +XXX,XX @@ static void slavio_timer_init(Object *obj)
499
tc->timer_index = i;
500
501
bh = qemu_bh_new(slavio_timer_irq, tc);
502
- s->cputimer[i].timer = ptimer_init(bh, PTIMER_POLICY_DEFAULT);
503
+ s->cputimer[i].timer = ptimer_init_with_bh(bh, PTIMER_POLICY_DEFAULT);
504
ptimer_set_period(s->cputimer[i].timer, TIMER_PERIOD);
505
506
size = i == 0 ? SYS_TIMER_SIZE : CPU_TIMER_SIZE;
507
diff --git a/hw/timer/xilinx_timer.c b/hw/timer/xilinx_timer.c
508
index XXXXXXX..XXXXXXX 100644
509
--- a/hw/timer/xilinx_timer.c
510
+++ b/hw/timer/xilinx_timer.c
511
@@ -XXX,XX +XXX,XX @@ static void xilinx_timer_realize(DeviceState *dev, Error **errp)
512
xt->parent = t;
513
xt->nr = i;
514
xt->bh = qemu_bh_new(timer_hit, xt);
515
- xt->ptimer = ptimer_init(xt->bh, PTIMER_POLICY_DEFAULT);
516
+ xt->ptimer = ptimer_init_with_bh(xt->bh, PTIMER_POLICY_DEFAULT);
517
ptimer_set_freq(xt->ptimer, t->freq_hz);
518
}
519
520
diff --git a/hw/watchdog/cmsdk-apb-watchdog.c b/hw/watchdog/cmsdk-apb-watchdog.c
521
index XXXXXXX..XXXXXXX 100644
522
--- a/hw/watchdog/cmsdk-apb-watchdog.c
523
+++ b/hw/watchdog/cmsdk-apb-watchdog.c
524
@@ -XXX,XX +XXX,XX @@ static void cmsdk_apb_watchdog_realize(DeviceState *dev, Error **errp)
525
}
526
527
bh = qemu_bh_new(cmsdk_apb_watchdog_tick, s);
528
- s->timer = ptimer_init(bh,
529
+ s->timer = ptimer_init_with_bh(bh,
530
PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD |
531
PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT |
532
PTIMER_POLICY_NO_IMMEDIATE_RELOAD |
533
diff --git a/tests/ptimer-test.c b/tests/ptimer-test.c
534
index XXXXXXX..XXXXXXX 100644
535
--- a/tests/ptimer-test.c
536
+++ b/tests/ptimer-test.c
537
@@ -XXX,XX +XXX,XX @@ static void check_set_count(gconstpointer arg)
538
{
539
const uint8_t *policy = arg;
540
QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
541
- ptimer_state *ptimer = ptimer_init(bh, *policy);
542
+ ptimer_state *ptimer = ptimer_init_with_bh(bh, *policy);
543
544
triggered = false;
545
546
@@ -XXX,XX +XXX,XX @@ static void check_set_limit(gconstpointer arg)
547
{
548
const uint8_t *policy = arg;
549
QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
550
- ptimer_state *ptimer = ptimer_init(bh, *policy);
551
+ ptimer_state *ptimer = ptimer_init_with_bh(bh, *policy);
552
553
triggered = false;
554
555
@@ -XXX,XX +XXX,XX @@ static void check_oneshot(gconstpointer arg)
556
{
557
const uint8_t *policy = arg;
558
QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
559
- ptimer_state *ptimer = ptimer_init(bh, *policy);
560
+ ptimer_state *ptimer = ptimer_init_with_bh(bh, *policy);
561
bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
562
563
triggered = false;
564
@@ -XXX,XX +XXX,XX @@ static void check_periodic(gconstpointer arg)
565
{
566
const uint8_t *policy = arg;
567
QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
568
- ptimer_state *ptimer = ptimer_init(bh, *policy);
569
+ ptimer_state *ptimer = ptimer_init_with_bh(bh, *policy);
570
bool wrap_policy = (*policy & PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD);
571
bool no_immediate_trigger = (*policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER);
572
bool no_immediate_reload = (*policy & PTIMER_POLICY_NO_IMMEDIATE_RELOAD);
573
@@ -XXX,XX +XXX,XX @@ static void check_on_the_fly_mode_change(gconstpointer arg)
574
{
575
const uint8_t *policy = arg;
576
QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
577
- ptimer_state *ptimer = ptimer_init(bh, *policy);
578
+ ptimer_state *ptimer = ptimer_init_with_bh(bh, *policy);
579
bool wrap_policy = (*policy & PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD);
580
bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
581
582
@@ -XXX,XX +XXX,XX @@ static void check_on_the_fly_period_change(gconstpointer arg)
583
{
584
const uint8_t *policy = arg;
585
QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
586
- ptimer_state *ptimer = ptimer_init(bh, *policy);
587
+ ptimer_state *ptimer = ptimer_init_with_bh(bh, *policy);
588
bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
589
590
triggered = false;
591
@@ -XXX,XX +XXX,XX @@ static void check_on_the_fly_freq_change(gconstpointer arg)
592
{
593
const uint8_t *policy = arg;
594
QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
595
- ptimer_state *ptimer = ptimer_init(bh, *policy);
596
+ ptimer_state *ptimer = ptimer_init_with_bh(bh, *policy);
597
bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
598
599
triggered = false;
600
@@ -XXX,XX +XXX,XX @@ static void check_run_with_period_0(gconstpointer arg)
601
{
602
const uint8_t *policy = arg;
603
QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
604
- ptimer_state *ptimer = ptimer_init(bh, *policy);
605
+ ptimer_state *ptimer = ptimer_init_with_bh(bh, *policy);
606
607
triggered = false;
608
609
@@ -XXX,XX +XXX,XX @@ static void check_run_with_delta_0(gconstpointer arg)
610
{
611
const uint8_t *policy = arg;
612
QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
613
- ptimer_state *ptimer = ptimer_init(bh, *policy);
614
+ ptimer_state *ptimer = ptimer_init_with_bh(bh, *policy);
615
bool wrap_policy = (*policy & PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD);
616
bool no_immediate_trigger = (*policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER);
617
bool no_immediate_reload = (*policy & PTIMER_POLICY_NO_IMMEDIATE_RELOAD);
618
@@ -XXX,XX +XXX,XX @@ static void check_periodic_with_load_0(gconstpointer arg)
619
{
620
const uint8_t *policy = arg;
621
QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
622
- ptimer_state *ptimer = ptimer_init(bh, *policy);
623
+ ptimer_state *ptimer = ptimer_init_with_bh(bh, *policy);
624
bool continuous_trigger = (*policy & PTIMER_POLICY_CONTINUOUS_TRIGGER);
625
bool no_immediate_trigger = (*policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER);
626
bool trig_only_on_dec = (*policy & PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT);
627
@@ -XXX,XX +XXX,XX @@ static void check_oneshot_with_load_0(gconstpointer arg)
628
{
629
const uint8_t *policy = arg;
630
QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
631
- ptimer_state *ptimer = ptimer_init(bh, *policy);
632
+ ptimer_state *ptimer = ptimer_init_with_bh(bh, *policy);
633
bool no_immediate_trigger = (*policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER);
634
bool trig_only_on_dec = (*policy & PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT);
635
636
--
1005
--
637
2.20.1
1006
2.20.1
638
1007
639
1008
diff view generated by jsdifflib
1
From: Cédric Le Goater <clg@kaod.org>
1
From: Havard Skinnemoen <hskinnemoen@google.com>
2
2
3
The AST2600 timer has a third control register that is used to
3
The RNG module returns a byte of randomness when the Data Valid bit is
4
implement a set-to-clear feature for the main control register.
4
set.
5
5
6
On the AST2600, it is not configurable via 0x38 (control register 3)
6
This implementation ignores the prescaler setting, and loads a new value
7
as it is on the AST2500.
7
into RNGD every time RNGCS is read while the RNG is enabled and random
8
data is available.
8
9
9
Based on previous work from Joel Stanley.
10
A qtest featuring some simple randomness tests is included.
10
11
11
Signed-off-by: Cédric Le Goater <clg@kaod.org>
12
Reviewed-by: Tyrone Ting <kfting@nuvoton.com>
12
Reviewed-by: Joel Stanley <joel@jms.id.au>
13
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
13
Message-id: 20190925143248.10000-7-clg@kaod.org
14
Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
14
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
15
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
15
---
16
---
16
include/hw/timer/aspeed_timer.h | 1 +
17
docs/system/arm/nuvoton.rst | 2 +-
17
hw/timer/aspeed_timer.c | 51 +++++++++++++++++++++++++++++++++
18
include/hw/arm/npcm7xx.h | 2 +
18
2 files changed, 52 insertions(+)
19
include/hw/misc/npcm7xx_rng.h | 34 ++++
20
hw/arm/npcm7xx.c | 7 +-
21
hw/misc/npcm7xx_rng.c | 180 +++++++++++++++++++++
22
tests/qtest/npcm7xx_rng-test.c | 278 +++++++++++++++++++++++++++++++++
23
hw/misc/meson.build | 1 +
24
hw/misc/trace-events | 4 +
25
tests/qtest/meson.build | 5 +-
26
9 files changed, 510 insertions(+), 3 deletions(-)
27
create mode 100644 include/hw/misc/npcm7xx_rng.h
28
create mode 100644 hw/misc/npcm7xx_rng.c
29
create mode 100644 tests/qtest/npcm7xx_rng-test.c
19
30
20
diff --git a/include/hw/timer/aspeed_timer.h b/include/hw/timer/aspeed_timer.h
31
diff --git a/docs/system/arm/nuvoton.rst b/docs/system/arm/nuvoton.rst
21
index XXXXXXX..XXXXXXX 100644
32
index XXXXXXX..XXXXXXX 100644
22
--- a/include/hw/timer/aspeed_timer.h
33
--- a/docs/system/arm/nuvoton.rst
23
+++ b/include/hw/timer/aspeed_timer.h
34
+++ b/docs/system/arm/nuvoton.rst
35
@@ -XXX,XX +XXX,XX @@ Supported devices
36
* DDR4 memory controller (dummy interface indicating memory training is done)
37
* OTP controllers (no protection features)
38
* Flash Interface Unit (FIU; no protection features)
39
+ * Random Number Generator (RNG)
40
41
Missing devices
42
---------------
43
@@ -XXX,XX +XXX,XX @@ Missing devices
44
* Peripheral SPI controller (PSPI)
45
* Analog to Digital Converter (ADC)
46
* SD/MMC host
47
- * Random Number Generator (RNG)
48
* PECI interface
49
* Pulse Width Modulation (PWM)
50
* Tachometer
51
diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h
52
index XXXXXXX..XXXXXXX 100644
53
--- a/include/hw/arm/npcm7xx.h
54
+++ b/include/hw/arm/npcm7xx.h
24
@@ -XXX,XX +XXX,XX @@
55
@@ -XXX,XX +XXX,XX @@
25
#define TYPE_ASPEED_TIMER "aspeed.timer"
56
#include "hw/mem/npcm7xx_mc.h"
26
#define TYPE_ASPEED_2400_TIMER TYPE_ASPEED_TIMER "-ast2400"
57
#include "hw/misc/npcm7xx_clk.h"
27
#define TYPE_ASPEED_2500_TIMER TYPE_ASPEED_TIMER "-ast2500"
58
#include "hw/misc/npcm7xx_gcr.h"
28
+#define TYPE_ASPEED_2600_TIMER TYPE_ASPEED_TIMER "-ast2600"
59
+#include "hw/misc/npcm7xx_rng.h"
29
60
#include "hw/nvram/npcm7xx_otp.h"
30
#define ASPEED_TIMER_NR_TIMERS 8
61
#include "hw/timer/npcm7xx_timer.h"
31
62
#include "hw/ssi/npcm7xx_fiu.h"
32
diff --git a/hw/timer/aspeed_timer.c b/hw/timer/aspeed_timer.c
63
@@ -XXX,XX +XXX,XX @@ typedef struct NPCM7xxState {
64
NPCM7xxOTPState key_storage;
65
NPCM7xxOTPState fuse_array;
66
NPCM7xxMCState mc;
67
+ NPCM7xxRNGState rng;
68
NPCM7xxFIUState fiu[2];
69
} NPCM7xxState;
70
71
diff --git a/include/hw/misc/npcm7xx_rng.h b/include/hw/misc/npcm7xx_rng.h
72
new file mode 100644
73
index XXXXXXX..XXXXXXX
74
--- /dev/null
75
+++ b/include/hw/misc/npcm7xx_rng.h
76
@@ -XXX,XX +XXX,XX @@
77
+/*
78
+ * Nuvoton NPCM7xx Random Number Generator.
79
+ *
80
+ * Copyright 2020 Google LLC
81
+ *
82
+ * This program is free software; you can redistribute it and/or modify it
83
+ * under the terms of the GNU General Public License as published by the
84
+ * Free Software Foundation; either version 2 of the License, or
85
+ * (at your option) any later version.
86
+ *
87
+ * This program is distributed in the hope that it will be useful, but WITHOUT
88
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
89
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
90
+ * for more details.
91
+ */
92
+#ifndef NPCM7XX_RNG_H
93
+#define NPCM7XX_RNG_H
94
+
95
+#include "hw/sysbus.h"
96
+
97
+typedef struct NPCM7xxRNGState {
98
+ SysBusDevice parent;
99
+
100
+ MemoryRegion iomem;
101
+
102
+ uint8_t rngcs;
103
+ uint8_t rngd;
104
+ uint8_t rngmode;
105
+} NPCM7xxRNGState;
106
+
107
+#define TYPE_NPCM7XX_RNG "npcm7xx-rng"
108
+#define NPCM7XX_RNG(obj) OBJECT_CHECK(NPCM7xxRNGState, (obj), TYPE_NPCM7XX_RNG)
109
+
110
+#endif /* NPCM7XX_RNG_H */
111
diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c
33
index XXXXXXX..XXXXXXX 100644
112
index XXXXXXX..XXXXXXX 100644
34
--- a/hw/timer/aspeed_timer.c
113
--- a/hw/arm/npcm7xx.c
35
+++ b/hw/timer/aspeed_timer.c
114
+++ b/hw/arm/npcm7xx.c
36
@@ -XXX,XX +XXX,XX @@ static void aspeed_2500_timer_write(AspeedTimerCtrlState *s, hwaddr offset,
115
@@ -XXX,XX +XXX,XX @@
116
#define NPCM7XX_GCR_BA (0xf0800000)
117
#define NPCM7XX_CLK_BA (0xf0801000)
118
#define NPCM7XX_MC_BA (0xf0824000)
119
+#define NPCM7XX_RNG_BA (0xf000b000)
120
121
/* Internal AHB SRAM */
122
#define NPCM7XX_RAM3_BA (0xc0008000)
123
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_init(Object *obj)
124
object_initialize_child(obj, "otp2", &s->fuse_array,
125
TYPE_NPCM7XX_FUSE_ARRAY);
126
object_initialize_child(obj, "mc", &s->mc, TYPE_NPCM7XX_MC);
127
+ object_initialize_child(obj, "rng", &s->rng, TYPE_NPCM7XX_RNG);
128
129
for (i = 0; i < ARRAY_SIZE(s->tim); i++) {
130
object_initialize_child(obj, "tim[*]", &s->tim[i], TYPE_NPCM7XX_TIMER);
131
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp)
132
serial_hd(i), DEVICE_LITTLE_ENDIAN);
37
}
133
}
38
}
134
39
135
+ /* Random Number Generator. Cannot fail. */
40
+static uint64_t aspeed_2600_timer_read(AspeedTimerCtrlState *s, hwaddr offset)
136
+ sysbus_realize(SYS_BUS_DEVICE(&s->rng), &error_abort);
41
+{
137
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->rng), 0, NPCM7XX_RNG_BA);
42
+ uint64_t value;
138
+
139
/*
140
* Flash Interface Unit (FIU). Can fail if incorrect number of chip selects
141
* specified, but this is a programming error.
142
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp)
143
create_unimplemented_device("npcm7xx.vdmx", 0xe0800000, 4 * KiB);
144
create_unimplemented_device("npcm7xx.pcierc", 0xe1000000, 64 * KiB);
145
create_unimplemented_device("npcm7xx.kcs", 0xf0007000, 4 * KiB);
146
- create_unimplemented_device("npcm7xx.rng", 0xf000b000, 4 * KiB);
147
create_unimplemented_device("npcm7xx.adc", 0xf000c000, 4 * KiB);
148
create_unimplemented_device("npcm7xx.gfxi", 0xf000e000, 4 * KiB);
149
create_unimplemented_device("npcm7xx.gpio[0]", 0xf0010000, 4 * KiB);
150
diff --git a/hw/misc/npcm7xx_rng.c b/hw/misc/npcm7xx_rng.c
151
new file mode 100644
152
index XXXXXXX..XXXXXXX
153
--- /dev/null
154
+++ b/hw/misc/npcm7xx_rng.c
155
@@ -XXX,XX +XXX,XX @@
156
+/*
157
+ * Nuvoton NPCM7xx Random Number Generator.
158
+ *
159
+ * Copyright 2020 Google LLC
160
+ *
161
+ * This program is free software; you can redistribute it and/or modify it
162
+ * under the terms of the GNU General Public License as published by the
163
+ * 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, but WITHOUT
167
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
168
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
169
+ * for more details.
170
+ */
171
+
172
+#include "qemu/osdep.h"
173
+
174
+#include "hw/misc/npcm7xx_rng.h"
175
+#include "migration/vmstate.h"
176
+#include "qemu/bitops.h"
177
+#include "qemu/guest-random.h"
178
+#include "qemu/log.h"
179
+#include "qemu/module.h"
180
+#include "qemu/units.h"
181
+
182
+#include "trace.h"
183
+
184
+#define NPCM7XX_RNG_REGS_SIZE (4 * KiB)
185
+
186
+#define NPCM7XX_RNGCS (0x00)
187
+#define NPCM7XX_RNGCS_CLKP(rv) extract32(rv, 2, 4)
188
+#define NPCM7XX_RNGCS_DVALID BIT(1)
189
+#define NPCM7XX_RNGCS_RNGE BIT(0)
190
+
191
+#define NPCM7XX_RNGD (0x04)
192
+#define NPCM7XX_RNGMODE (0x08)
193
+#define NPCM7XX_RNGMODE_NORMAL (0x02)
194
+
195
+static bool npcm7xx_rng_is_enabled(NPCM7xxRNGState *s)
196
+{
197
+ return (s->rngcs & NPCM7XX_RNGCS_RNGE) &&
198
+ (s->rngmode == NPCM7XX_RNGMODE_NORMAL);
199
+}
200
+
201
+static uint64_t npcm7xx_rng_read(void *opaque, hwaddr offset, unsigned size)
202
+{
203
+ NPCM7xxRNGState *s = opaque;
204
+ uint64_t value = 0;
43
+
205
+
44
+ switch (offset) {
206
+ switch (offset) {
45
+ case 0x38:
207
+ case NPCM7XX_RNGCS:
46
+ case 0x3C:
208
+ /*
209
+ * If the RNG is enabled, but we don't have any valid random data, try
210
+ * obtaining some and update the DVALID bit accordingly.
211
+ */
212
+ if (!npcm7xx_rng_is_enabled(s)) {
213
+ s->rngcs &= ~NPCM7XX_RNGCS_DVALID;
214
+ } else if (!(s->rngcs & NPCM7XX_RNGCS_DVALID)) {
215
+ uint8_t byte = 0;
216
+
217
+ if (qemu_guest_getrandom(&byte, sizeof(byte), NULL) == 0) {
218
+ s->rngd = byte;
219
+ s->rngcs |= NPCM7XX_RNGCS_DVALID;
220
+ }
221
+ }
222
+ value = s->rngcs;
223
+ break;
224
+ case NPCM7XX_RNGD:
225
+ if (npcm7xx_rng_is_enabled(s) && s->rngcs & NPCM7XX_RNGCS_DVALID) {
226
+ s->rngcs &= ~NPCM7XX_RNGCS_DVALID;
227
+ value = s->rngd;
228
+ s->rngd = 0;
229
+ }
230
+ break;
231
+ case NPCM7XX_RNGMODE:
232
+ value = s->rngmode;
233
+ break;
234
+
47
+ default:
235
+ default:
48
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%" HWADDR_PRIx "\n",
236
+ qemu_log_mask(LOG_GUEST_ERROR,
49
+ __func__, offset);
237
+ "%s: read from invalid offset 0x%" HWADDR_PRIx "\n",
50
+ value = 0;
238
+ DEVICE(s)->canonical_path, offset);
51
+ break;
239
+ break;
52
+ }
240
+ }
241
+
242
+ trace_npcm7xx_rng_read(offset, value, size);
243
+
53
+ return value;
244
+ return value;
54
+}
245
+}
55
+
246
+
56
+static void aspeed_2600_timer_write(AspeedTimerCtrlState *s, hwaddr offset,
247
+static void npcm7xx_rng_write(void *opaque, hwaddr offset, uint64_t value,
57
+ uint64_t value)
248
+ unsigned size)
58
+{
249
+{
59
+ const uint32_t tv = (uint32_t)(value & 0xFFFFFFFF);
250
+ NPCM7xxRNGState *s = opaque;
251
+
252
+ trace_npcm7xx_rng_write(offset, value, size);
60
+
253
+
61
+ switch (offset) {
254
+ switch (offset) {
62
+ case 0x3C:
255
+ case NPCM7XX_RNGCS:
63
+ aspeed_timer_set_ctrl(s, s->ctrl & ~tv);
256
+ s->rngcs &= NPCM7XX_RNGCS_DVALID;
64
+ break;
257
+ s->rngcs |= value & ~NPCM7XX_RNGCS_DVALID;
65
+
258
+ break;
66
+ case 0x38:
259
+ case NPCM7XX_RNGD:
260
+ qemu_log_mask(LOG_GUEST_ERROR,
261
+ "%s: write to read-only register @ 0x%" HWADDR_PRIx "\n",
262
+ DEVICE(s)->canonical_path, offset);
263
+ break;
264
+ case NPCM7XX_RNGMODE:
265
+ s->rngmode = value;
266
+ break;
67
+ default:
267
+ default:
68
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%" HWADDR_PRIx "\n",
268
+ qemu_log_mask(LOG_GUEST_ERROR,
69
+ __func__, offset);
269
+ "%s: write to invalid offset 0x%" HWADDR_PRIx "\n",
70
+ break;
270
+ DEVICE(s)->canonical_path, offset);
71
+ }
271
+ break;
72
+}
272
+ }
73
+
273
+}
74
static void aspeed_init_one_timer(AspeedTimerCtrlState *s, uint8_t id)
274
+
75
{
275
+static const MemoryRegionOps npcm7xx_rng_ops = {
76
AspeedTimer *t = &s->timers[id];
276
+ .read = npcm7xx_rng_read,
77
@@ -XXX,XX +XXX,XX @@ static const TypeInfo aspeed_2500_timer_info = {
277
+ .write = npcm7xx_rng_write,
78
.class_init = aspeed_2500_timer_class_init,
278
+ .endianness = DEVICE_LITTLE_ENDIAN,
79
};
279
+ .valid = {
80
280
+ .min_access_size = 1,
81
+static void aspeed_2600_timer_class_init(ObjectClass *klass, void *data)
281
+ .max_access_size = 4,
82
+{
282
+ .unaligned = false,
283
+ },
284
+};
285
+
286
+static void npcm7xx_rng_enter_reset(Object *obj, ResetType type)
287
+{
288
+ NPCM7xxRNGState *s = NPCM7XX_RNG(obj);
289
+
290
+ s->rngcs = 0;
291
+ s->rngd = 0;
292
+ s->rngmode = 0;
293
+}
294
+
295
+static void npcm7xx_rng_init(Object *obj)
296
+{
297
+ NPCM7xxRNGState *s = NPCM7XX_RNG(obj);
298
+
299
+ memory_region_init_io(&s->iomem, obj, &npcm7xx_rng_ops, s, "regs",
300
+ NPCM7XX_RNG_REGS_SIZE);
301
+ sysbus_init_mmio(&s->parent, &s->iomem);
302
+}
303
+
304
+static const VMStateDescription vmstate_npcm7xx_rng = {
305
+ .name = "npcm7xx-rng",
306
+ .version_id = 0,
307
+ .minimum_version_id = 0,
308
+ .fields = (VMStateField[]) {
309
+ VMSTATE_UINT8(rngcs, NPCM7xxRNGState),
310
+ VMSTATE_UINT8(rngd, NPCM7xxRNGState),
311
+ VMSTATE_UINT8(rngmode, NPCM7xxRNGState),
312
+ VMSTATE_END_OF_LIST(),
313
+ },
314
+};
315
+
316
+static void npcm7xx_rng_class_init(ObjectClass *klass, void *data)
317
+{
318
+ ResettableClass *rc = RESETTABLE_CLASS(klass);
83
+ DeviceClass *dc = DEVICE_CLASS(klass);
319
+ DeviceClass *dc = DEVICE_CLASS(klass);
84
+ AspeedTimerClass *awc = ASPEED_TIMER_CLASS(klass);
320
+
85
+
321
+ dc->desc = "NPCM7xx Random Number Generator";
86
+ dc->desc = "ASPEED 2600 Timer";
322
+ dc->vmsd = &vmstate_npcm7xx_rng;
87
+ awc->read = aspeed_2600_timer_read;
323
+ rc->phases.enter = npcm7xx_rng_enter_reset;
88
+ awc->write = aspeed_2600_timer_write;
324
+}
89
+}
325
+
90
+
326
+static const TypeInfo npcm7xx_rng_types[] = {
91
+static const TypeInfo aspeed_2600_timer_info = {
327
+ {
92
+ .name = TYPE_ASPEED_2600_TIMER,
328
+ .name = TYPE_NPCM7XX_RNG,
93
+ .parent = TYPE_ASPEED_TIMER,
329
+ .parent = TYPE_SYS_BUS_DEVICE,
94
+ .class_init = aspeed_2600_timer_class_init,
330
+ .instance_size = sizeof(NPCM7xxRNGState),
331
+ .class_init = npcm7xx_rng_class_init,
332
+ .instance_init = npcm7xx_rng_init,
333
+ },
95
+};
334
+};
96
+
335
+DEFINE_TYPES(npcm7xx_rng_types);
97
static void aspeed_timer_register_types(void)
336
diff --git a/tests/qtest/npcm7xx_rng-test.c b/tests/qtest/npcm7xx_rng-test.c
98
{
337
new file mode 100644
99
type_register_static(&aspeed_timer_info);
338
index XXXXXXX..XXXXXXX
100
type_register_static(&aspeed_2400_timer_info);
339
--- /dev/null
101
type_register_static(&aspeed_2500_timer_info);
340
+++ b/tests/qtest/npcm7xx_rng-test.c
102
+ type_register_static(&aspeed_2600_timer_info);
341
@@ -XXX,XX +XXX,XX @@
103
}
342
+/*
104
343
+ * QTest testcase for the Nuvoton NPCM7xx Random Number Generator
105
type_init(aspeed_timer_register_types)
344
+ *
345
+ * Copyright 2020 Google LLC
346
+ *
347
+ * This program is free software; you can redistribute it and/or modify it
348
+ * under the terms of the GNU General Public License as published by the
349
+ * Free Software Foundation; either version 2 of the License, or
350
+ * (at your option) any later version.
351
+ *
352
+ * This program is distributed in the hope that it will be useful, but WITHOUT
353
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
354
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
355
+ * for more details.
356
+ */
357
+
358
+#include "qemu/osdep.h"
359
+
360
+#include <math.h>
361
+
362
+#include "libqtest-single.h"
363
+#include "qemu/bitops.h"
364
+
365
+#define RNG_BASE_ADDR 0xf000b000
366
+
367
+/* Control and Status Register */
368
+#define RNGCS 0x00
369
+# define DVALID BIT(1) /* Data Valid */
370
+# define RNGE BIT(0) /* RNG Enable */
371
+/* Data Register */
372
+#define RNGD 0x04
373
+/* Mode Register */
374
+#define RNGMODE 0x08
375
+# define ROSEL_NORMAL (2) /* RNG only works in this mode */
376
+
377
+/* Number of bits to collect for randomness tests. */
378
+#define TEST_INPUT_BITS (128)
379
+
380
+static void rng_writeb(unsigned int offset, uint8_t value)
381
+{
382
+ writeb(RNG_BASE_ADDR + offset, value);
383
+}
384
+
385
+static uint8_t rng_readb(unsigned int offset)
386
+{
387
+ return readb(RNG_BASE_ADDR + offset);
388
+}
389
+
390
+/* Disable RNG and set normal ring oscillator mode. */
391
+static void rng_reset(void)
392
+{
393
+ rng_writeb(RNGCS, 0);
394
+ rng_writeb(RNGMODE, ROSEL_NORMAL);
395
+}
396
+
397
+/* Reset RNG and then enable it. */
398
+static void rng_reset_enable(void)
399
+{
400
+ rng_reset();
401
+ rng_writeb(RNGCS, RNGE);
402
+}
403
+
404
+/* Wait until Data Valid bit is set. */
405
+static bool rng_wait_ready(void)
406
+{
407
+ /* qemu_guest_getrandom may fail. Assume it won't fail 10 times in a row. */
408
+ int retries = 10;
409
+
410
+ while (retries-- > 0) {
411
+ if (rng_readb(RNGCS) & DVALID) {
412
+ return true;
413
+ }
414
+ }
415
+
416
+ return false;
417
+}
418
+
419
+/*
420
+ * Perform a frequency (monobit) test, as defined by NIST SP 800-22, on the
421
+ * sequence in buf and return the P-value. This represents the probability of a
422
+ * truly random sequence having the same proportion of zeros and ones as the
423
+ * sequence in buf.
424
+ *
425
+ * An RNG which always returns 0x00 or 0xff, or has some bits stuck at 0 or 1,
426
+ * will fail this test. However, an RNG which always returns 0x55, 0xf0 or some
427
+ * other value with an equal number of zeroes and ones will pass.
428
+ */
429
+static double calc_monobit_p(const uint8_t *buf, unsigned int len)
430
+{
431
+ unsigned int i;
432
+ double s_obs;
433
+ int sn = 0;
434
+
435
+ for (i = 0; i < len; i++) {
436
+ /*
437
+ * Each 1 counts as 1, each 0 counts as -1.
438
+ * s = cp - (8 - cp) = 2 * cp - 8
439
+ */
440
+ sn += 2 * ctpop8(buf[i]) - 8;
441
+ }
442
+
443
+ s_obs = abs(sn) / sqrt(len * BITS_PER_BYTE);
444
+
445
+ return erfc(s_obs / sqrt(2));
446
+}
447
+
448
+/*
449
+ * Perform a runs test, as defined by NIST SP 800-22, and return the P-value.
450
+ * This represents the probability of a truly random sequence having the same
451
+ * number of runs (i.e. uninterrupted sequences of identical bits) as the
452
+ * sequence in buf.
453
+ */
454
+static double calc_runs_p(const unsigned long *buf, unsigned int nr_bits)
455
+{
456
+ unsigned int j;
457
+ unsigned int k;
458
+ int nr_ones = 0;
459
+ int vn_obs = 0;
460
+ double pi;
461
+
462
+ g_assert(nr_bits % BITS_PER_LONG == 0);
463
+
464
+ for (j = 0; j < nr_bits / BITS_PER_LONG; j++) {
465
+ nr_ones += __builtin_popcountl(buf[j]);
466
+ }
467
+ pi = (double)nr_ones / nr_bits;
468
+
469
+ for (k = 0; k < nr_bits - 1; k++) {
470
+ vn_obs += !(test_bit(k, buf) ^ test_bit(k + 1, buf));
471
+ }
472
+ vn_obs += 1;
473
+
474
+ return erfc(fabs(vn_obs - 2 * nr_bits * pi * (1.0 - pi))
475
+ / (2 * sqrt(2 * nr_bits) * pi * (1.0 - pi)));
476
+}
477
+
478
+/*
479
+ * Verifies that DVALID is clear, and RNGD reads zero, when RNGE is cleared,
480
+ * and DVALID eventually becomes set when RNGE is set.
481
+ */
482
+static void test_enable_disable(void)
483
+{
484
+ /* Disable: DVALID should not be set, and RNGD should read zero */
485
+ rng_reset();
486
+ g_assert_cmphex(rng_readb(RNGCS), ==, 0);
487
+ g_assert_cmphex(rng_readb(RNGD), ==, 0);
488
+
489
+ /* Enable: DVALID should be set, but we can't make assumptions about RNGD */
490
+ rng_writeb(RNGCS, RNGE);
491
+ g_assert_true(rng_wait_ready());
492
+ g_assert_cmphex(rng_readb(RNGCS), ==, DVALID | RNGE);
493
+
494
+ /* Disable: DVALID should not be set, and RNGD should read zero */
495
+ rng_writeb(RNGCS, 0);
496
+ g_assert_cmphex(rng_readb(RNGCS), ==, 0);
497
+ g_assert_cmphex(rng_readb(RNGD), ==, 0);
498
+}
499
+
500
+/*
501
+ * Verifies that the RNG only produces data when RNGMODE is set to 'normal'
502
+ * ring oscillator mode.
503
+ */
504
+static void test_rosel(void)
505
+{
506
+ rng_reset_enable();
507
+ g_assert_true(rng_wait_ready());
508
+ rng_writeb(RNGMODE, 0);
509
+ g_assert_false(rng_wait_ready());
510
+ rng_writeb(RNGMODE, ROSEL_NORMAL);
511
+ g_assert_true(rng_wait_ready());
512
+ rng_writeb(RNGMODE, 0);
513
+ g_assert_false(rng_wait_ready());
514
+}
515
+
516
+/*
517
+ * Verifies that a continuous sequence of bits collected after enabling the RNG
518
+ * satisfies a monobit test.
519
+ */
520
+static void test_continuous_monobit(void)
521
+{
522
+ uint8_t buf[TEST_INPUT_BITS / BITS_PER_BYTE];
523
+ unsigned int i;
524
+
525
+ rng_reset_enable();
526
+ for (i = 0; i < sizeof(buf); i++) {
527
+ g_assert_true(rng_wait_ready());
528
+ buf[i] = rng_readb(RNGD);
529
+ }
530
+
531
+ g_assert_cmpfloat(calc_monobit_p(buf, sizeof(buf)), >, 0.01);
532
+}
533
+
534
+/*
535
+ * Verifies that a continuous sequence of bits collected after enabling the RNG
536
+ * satisfies a runs test.
537
+ */
538
+static void test_continuous_runs(void)
539
+{
540
+ union {
541
+ unsigned long l[TEST_INPUT_BITS / BITS_PER_LONG];
542
+ uint8_t c[TEST_INPUT_BITS / BITS_PER_BYTE];
543
+ } buf;
544
+ unsigned int i;
545
+
546
+ rng_reset_enable();
547
+ for (i = 0; i < sizeof(buf); i++) {
548
+ g_assert_true(rng_wait_ready());
549
+ buf.c[i] = rng_readb(RNGD);
550
+ }
551
+
552
+ g_assert_cmpfloat(calc_runs_p(buf.l, sizeof(buf) * BITS_PER_BYTE), >, 0.01);
553
+}
554
+
555
+/*
556
+ * Verifies that the first data byte collected after enabling the RNG satisfies
557
+ * a monobit test.
558
+ */
559
+static void test_first_byte_monobit(void)
560
+{
561
+ /* Enable, collect one byte, disable. Repeat until we have 100 bits. */
562
+ uint8_t buf[TEST_INPUT_BITS / BITS_PER_BYTE];
563
+ unsigned int i;
564
+
565
+ rng_reset();
566
+ for (i = 0; i < sizeof(buf); i++) {
567
+ rng_writeb(RNGCS, RNGE);
568
+ g_assert_true(rng_wait_ready());
569
+ buf[i] = rng_readb(RNGD);
570
+ rng_writeb(RNGCS, 0);
571
+ }
572
+
573
+ g_assert_cmpfloat(calc_monobit_p(buf, sizeof(buf)), >, 0.01);
574
+}
575
+
576
+/*
577
+ * Verifies that the first data byte collected after enabling the RNG satisfies
578
+ * a runs test.
579
+ */
580
+static void test_first_byte_runs(void)
581
+{
582
+ /* Enable, collect one byte, disable. Repeat until we have 100 bits. */
583
+ union {
584
+ unsigned long l[TEST_INPUT_BITS / BITS_PER_LONG];
585
+ uint8_t c[TEST_INPUT_BITS / BITS_PER_BYTE];
586
+ } buf;
587
+ unsigned int i;
588
+
589
+ rng_reset();
590
+ for (i = 0; i < sizeof(buf); i++) {
591
+ rng_writeb(RNGCS, RNGE);
592
+ g_assert_true(rng_wait_ready());
593
+ buf.c[i] = rng_readb(RNGD);
594
+ rng_writeb(RNGCS, 0);
595
+ }
596
+
597
+ g_assert_cmpfloat(calc_runs_p(buf.l, sizeof(buf) * BITS_PER_BYTE), >, 0.01);
598
+}
599
+
600
+int main(int argc, char **argv)
601
+{
602
+ int ret;
603
+
604
+ g_test_init(&argc, &argv, NULL);
605
+ g_test_set_nonfatal_assertions();
606
+
607
+ qtest_add_func("npcm7xx_rng/enable_disable", test_enable_disable);
608
+ qtest_add_func("npcm7xx_rng/rosel", test_rosel);
609
+ qtest_add_func("npcm7xx_rng/continuous/monobit", test_continuous_monobit);
610
+ qtest_add_func("npcm7xx_rng/continuous/runs", test_continuous_runs);
611
+ qtest_add_func("npcm7xx_rng/first_byte/monobit", test_first_byte_monobit);
612
+ qtest_add_func("npcm7xx_rng/first_byte/runs", test_first_byte_runs);
613
+
614
+ qtest_start("-machine npcm750-evb");
615
+ ret = g_test_run();
616
+ qtest_end();
617
+
618
+ return ret;
619
+}
620
diff --git a/hw/misc/meson.build b/hw/misc/meson.build
621
index XXXXXXX..XXXXXXX 100644
622
--- a/hw/misc/meson.build
623
+++ b/hw/misc/meson.build
624
@@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_MAINSTONE', if_true: files('mst_fpga.c'))
625
softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files(
626
'npcm7xx_clk.c',
627
'npcm7xx_gcr.c',
628
+ 'npcm7xx_rng.c',
629
))
630
softmmu_ss.add(when: 'CONFIG_OMAP', if_true: files(
631
'omap_clk.c',
632
diff --git a/hw/misc/trace-events b/hw/misc/trace-events
633
index XXXXXXX..XXXXXXX 100644
634
--- a/hw/misc/trace-events
635
+++ b/hw/misc/trace-events
636
@@ -XXX,XX +XXX,XX @@ npcm7xx_clk_write(uint64_t offset, uint32_t value) "offset: 0x%04" PRIx64 " valu
637
npcm7xx_gcr_read(uint64_t offset, uint32_t value) " offset: 0x%04" PRIx64 " value: 0x%08" PRIx32
638
npcm7xx_gcr_write(uint64_t offset, uint32_t value) "offset: 0x%04" PRIx64 " value: 0x%08" PRIx32
639
640
+# npcm7xx_rng.c
641
+npcm7xx_rng_read(uint64_t offset, uint64_t value, unsigned size) "offset: 0x%04" PRIx64 " value: 0x%02" PRIx64 " size: %u"
642
+npcm7xx_rng_write(uint64_t offset, uint64_t value, unsigned size) "offset: 0x%04" PRIx64 " value: 0x%02" PRIx64 " size: %u"
643
+
644
# stm32f4xx_syscfg.c
645
stm32f4xx_syscfg_set_irq(int gpio, int line, int level) "Interupt: GPIO: %d, Line: %d; Level: %d"
646
stm32f4xx_pulse_exti(int irq) "Pulse EXTI: %d"
647
diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
648
index XXXXXXX..XXXXXXX 100644
649
--- a/tests/qtest/meson.build
650
+++ b/tests/qtest/meson.build
651
@@ -XXX,XX +XXX,XX @@ qtests_sparc64 = \
652
(config_all_devices.has_key('CONFIG_ISA_TESTDEV') ? ['endianness-test'] : []) + \
653
['prom-env-test', 'boot-serial-test']
654
655
-qtests_npcm7xx = ['npcm7xx_timer-test', 'npcm7xx_watchdog_timer-test']
656
+qtests_npcm7xx = \
657
+ ['npcm7xx_rng-test',
658
+ 'npcm7xx_timer-test',
659
+ 'npcm7xx_watchdog_timer-test']
660
qtests_arm = \
661
(config_all_devices.has_key('CONFIG_PFLASH_CFI02') ? ['pflash-cfi02-test'] : []) + \
662
(config_all_devices.has_key('CONFIG_NPCM7XX') ? qtests_npcm7xx : []) + \
106
--
663
--
107
2.20.1
664
2.20.1
108
665
109
666
diff view generated by jsdifflib
1
From: Cédric Le Goater <clg@kaod.org>
1
From: Havard Skinnemoen <hskinnemoen@google.com>
2
2
3
The most important changes will be on the register range 0x34 - 0x3C
3
The NPCM730 and NPCM750 chips have a single USB host port shared between
4
memops. Introduce class read/write operations to handle the
4
a USB 2.0 EHCI host controller and a USB 1.1 OHCI host controller. This
5
differences between SoCs.
5
adds support for both of them.
6
6
7
Signed-off-by: Cédric Le Goater <clg@kaod.org>
7
Testing notes:
8
Reviewed-by: Joel Stanley <joel@jms.id.au>
8
* With -device usb-kbd, qemu will automatically insert a full-speed
9
Message-id: 20190925143248.10000-5-clg@kaod.org
9
hub, and the keyboard becomes controlled by the OHCI controller.
10
* With -device usb-kbd,bus=usb-bus.0,port=1, the keyboard is directly
11
attached to the port without any hubs, and the device becomes
12
controlled by the EHCI controller since it's high speed capable.
13
* With -device usb-kbd,bus=usb-bus.0,port=1,usb_version=1, the
14
keyboard is directly attached to the port, but it only advertises
15
itself as full-speed capable, so it becomes controlled by the OHCI
16
controller.
17
18
In all cases, the keyboard device enumerates correctly.
19
20
Reviewed-by: Tyrone Ting <kfting@nuvoton.com>
21
Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
22
Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
23
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
---
24
---
12
include/hw/timer/aspeed_timer.h | 15 +++++
25
docs/system/arm/nuvoton.rst | 2 +-
13
hw/arm/aspeed_soc.c | 3 +-
26
hw/usb/hcd-ehci.h | 1 +
14
hw/timer/aspeed_timer.c | 107 ++++++++++++++++++++++++++++----
27
include/hw/arm/npcm7xx.h | 4 ++++
15
3 files changed, 113 insertions(+), 12 deletions(-)
28
hw/arm/npcm7xx.c | 27 +++++++++++++++++++++++++--
29
hw/usb/hcd-ehci-sysbus.c | 19 +++++++++++++++++++
30
5 files changed, 50 insertions(+), 3 deletions(-)
16
31
17
diff --git a/include/hw/timer/aspeed_timer.h b/include/hw/timer/aspeed_timer.h
32
diff --git a/docs/system/arm/nuvoton.rst b/docs/system/arm/nuvoton.rst
18
index XXXXXXX..XXXXXXX 100644
33
index XXXXXXX..XXXXXXX 100644
19
--- a/include/hw/timer/aspeed_timer.h
34
--- a/docs/system/arm/nuvoton.rst
20
+++ b/include/hw/timer/aspeed_timer.h
35
+++ b/docs/system/arm/nuvoton.rst
36
@@ -XXX,XX +XXX,XX @@ Supported devices
37
* OTP controllers (no protection features)
38
* Flash Interface Unit (FIU; no protection features)
39
* Random Number Generator (RNG)
40
+ * USB host (USBH)
41
42
Missing devices
43
---------------
44
@@ -XXX,XX +XXX,XX @@ Missing devices
45
* eSPI slave interface
46
47
* Ethernet controllers (GMAC and EMC)
48
- * USB host (USBH)
49
* USB device (USBD)
50
* SMBus controller (SMBF)
51
* Peripheral SPI controller (PSPI)
52
diff --git a/hw/usb/hcd-ehci.h b/hw/usb/hcd-ehci.h
53
index XXXXXXX..XXXXXXX 100644
54
--- a/hw/usb/hcd-ehci.h
55
+++ b/hw/usb/hcd-ehci.h
56
@@ -XXX,XX +XXX,XX @@ struct EHCIPCIState {
57
#define TYPE_PLATFORM_EHCI "platform-ehci-usb"
58
#define TYPE_EXYNOS4210_EHCI "exynos4210-ehci-usb"
59
#define TYPE_AW_H3_EHCI "aw-h3-ehci-usb"
60
+#define TYPE_NPCM7XX_EHCI "npcm7xx-ehci-usb"
61
#define TYPE_TEGRA2_EHCI "tegra2-ehci-usb"
62
#define TYPE_PPC4xx_EHCI "ppc4xx-ehci-usb"
63
#define TYPE_FUSBH200_EHCI "fusbh200-ehci-usb"
64
diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h
65
index XXXXXXX..XXXXXXX 100644
66
--- a/include/hw/arm/npcm7xx.h
67
+++ b/include/hw/arm/npcm7xx.h
21
@@ -XXX,XX +XXX,XX @@
68
@@ -XXX,XX +XXX,XX @@
22
#define ASPEED_TIMER(obj) \
69
#include "hw/nvram/npcm7xx_otp.h"
23
OBJECT_CHECK(AspeedTimerCtrlState, (obj), TYPE_ASPEED_TIMER);
70
#include "hw/timer/npcm7xx_timer.h"
24
#define TYPE_ASPEED_TIMER "aspeed.timer"
71
#include "hw/ssi/npcm7xx_fiu.h"
25
+#define TYPE_ASPEED_2400_TIMER TYPE_ASPEED_TIMER "-ast2400"
72
+#include "hw/usb/hcd-ehci.h"
26
+#define TYPE_ASPEED_2500_TIMER TYPE_ASPEED_TIMER "-ast2500"
73
+#include "hw/usb/hcd-ohci.h"
74
#include "target/arm/cpu.h"
75
76
#define NPCM7XX_MAX_NUM_CPUS (2)
77
@@ -XXX,XX +XXX,XX @@ typedef struct NPCM7xxState {
78
NPCM7xxOTPState fuse_array;
79
NPCM7xxMCState mc;
80
NPCM7xxRNGState rng;
81
+ EHCISysBusState ehci;
82
+ OHCISysBusState ohci;
83
NPCM7xxFIUState fiu[2];
84
} NPCM7xxState;
85
86
diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c
87
index XXXXXXX..XXXXXXX 100644
88
--- a/hw/arm/npcm7xx.c
89
+++ b/hw/arm/npcm7xx.c
90
@@ -XXX,XX +XXX,XX @@
91
#define NPCM7XX_MC_BA (0xf0824000)
92
#define NPCM7XX_RNG_BA (0xf000b000)
93
94
+/* USB Host modules */
95
+#define NPCM7XX_EHCI_BA (0xf0806000)
96
+#define NPCM7XX_OHCI_BA (0xf0807000)
27
+
97
+
28
#define ASPEED_TIMER_NR_TIMERS 8
98
/* Internal AHB SRAM */
29
99
#define NPCM7XX_RAM3_BA (0xc0008000)
30
typedef struct AspeedTimer {
100
#define NPCM7XX_RAM3_SZ (4 * KiB)
31
@@ -XXX,XX +XXX,XX @@ typedef struct AspeedTimerCtrlState {
101
@@ -XXX,XX +XXX,XX @@ enum NPCM7xxInterrupt {
32
AspeedSCUState *scu;
102
NPCM7XX_WDG0_IRQ = 47, /* Timer Module 0 Watchdog */
33
} AspeedTimerCtrlState;
103
NPCM7XX_WDG1_IRQ, /* Timer Module 1 Watchdog */
34
104
NPCM7XX_WDG2_IRQ, /* Timer Module 2 Watchdog */
35
+#define ASPEED_TIMER_CLASS(klass) \
105
+ NPCM7XX_EHCI_IRQ = 61,
36
+ OBJECT_CLASS_CHECK(AspeedTimerClass, (klass), TYPE_ASPEED_TIMER)
106
+ NPCM7XX_OHCI_IRQ = 62,
37
+#define ASPEED_TIMER_GET_CLASS(obj) \
107
};
38
+ OBJECT_GET_CLASS(AspeedTimerClass, (obj), TYPE_ASPEED_TIMER)
108
109
/* Total number of GIC interrupts, including internal Cortex-A9 interrupts. */
110
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_init(Object *obj)
111
object_initialize_child(obj, "tim[*]", &s->tim[i], TYPE_NPCM7XX_TIMER);
112
}
113
114
+ object_initialize_child(obj, "ehci", &s->ehci, TYPE_NPCM7XX_EHCI);
115
+ object_initialize_child(obj, "ohci", &s->ohci, TYPE_SYSBUS_OHCI);
39
+
116
+
40
+typedef struct AspeedTimerClass {
117
QEMU_BUILD_BUG_ON(ARRAY_SIZE(npcm7xx_fiu) != ARRAY_SIZE(s->fiu));
41
+ SysBusDeviceClass parent_class;
118
for (i = 0; i < ARRAY_SIZE(s->fiu); i++) {
119
object_initialize_child(obj, npcm7xx_fiu[i].name, &s->fiu[i],
120
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp)
121
sysbus_realize(SYS_BUS_DEVICE(&s->rng), &error_abort);
122
sysbus_mmio_map(SYS_BUS_DEVICE(&s->rng), 0, NPCM7XX_RNG_BA);
123
124
+ /* USB Host */
125
+ object_property_set_bool(OBJECT(&s->ehci), "companion-enable", true,
126
+ &error_abort);
127
+ sysbus_realize(SYS_BUS_DEVICE(&s->ehci), &error_abort);
128
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->ehci), 0, NPCM7XX_EHCI_BA);
129
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->ehci), 0,
130
+ npcm7xx_irq(s, NPCM7XX_EHCI_IRQ));
42
+
131
+
43
+ uint64_t (*read)(AspeedTimerCtrlState *s, hwaddr offset);
132
+ object_property_set_str(OBJECT(&s->ohci), "masterbus", "usb-bus.0",
44
+ void (*write)(AspeedTimerCtrlState *s, hwaddr offset, uint64_t value);
133
+ &error_abort);
45
+} AspeedTimerClass;
134
+ object_property_set_uint(OBJECT(&s->ohci), "num-ports", 1, &error_abort);
135
+ sysbus_realize(SYS_BUS_DEVICE(&s->ohci), &error_abort);
136
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->ohci), 0, NPCM7XX_OHCI_BA);
137
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->ohci), 0,
138
+ npcm7xx_irq(s, NPCM7XX_OHCI_IRQ));
46
+
139
+
47
#endif /* ASPEED_TIMER_H */
140
/*
48
diff --git a/hw/arm/aspeed_soc.c b/hw/arm/aspeed_soc.c
141
* Flash Interface Unit (FIU). Can fail if incorrect number of chip selects
142
* specified, but this is a programming error.
143
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp)
144
create_unimplemented_device("npcm7xx.mcphy", 0xf05f0000, 64 * KiB);
145
create_unimplemented_device("npcm7xx.gmac1", 0xf0802000, 8 * KiB);
146
create_unimplemented_device("npcm7xx.gmac2", 0xf0804000, 8 * KiB);
147
- create_unimplemented_device("npcm7xx.ehci", 0xf0806000, 4 * KiB);
148
- create_unimplemented_device("npcm7xx.ohci", 0xf0807000, 4 * KiB);
149
create_unimplemented_device("npcm7xx.vcd", 0xf0810000, 64 * KiB);
150
create_unimplemented_device("npcm7xx.ece", 0xf0820000, 8 * KiB);
151
create_unimplemented_device("npcm7xx.vdma", 0xf0822000, 8 * KiB);
152
diff --git a/hw/usb/hcd-ehci-sysbus.c b/hw/usb/hcd-ehci-sysbus.c
49
index XXXXXXX..XXXXXXX 100644
153
index XXXXXXX..XXXXXXX 100644
50
--- a/hw/arm/aspeed_soc.c
154
--- a/hw/usb/hcd-ehci-sysbus.c
51
+++ b/hw/arm/aspeed_soc.c
155
+++ b/hw/usb/hcd-ehci-sysbus.c
52
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_init(Object *obj)
156
@@ -XXX,XX +XXX,XX @@ static const TypeInfo ehci_aw_h3_type_info = {
53
sysbus_init_child_obj(obj, "rtc", OBJECT(&s->rtc), sizeof(s->rtc),
157
.class_init = ehci_aw_h3_class_init,
54
TYPE_ASPEED_RTC);
55
56
+ snprintf(typename, sizeof(typename), "aspeed.timer-%s", socname);
57
sysbus_init_child_obj(obj, "timerctrl", OBJECT(&s->timerctrl),
58
- sizeof(s->timerctrl), TYPE_ASPEED_TIMER);
59
+ sizeof(s->timerctrl), typename);
60
object_property_add_const_link(OBJECT(&s->timerctrl), "scu",
61
OBJECT(&s->scu), &error_abort);
62
63
diff --git a/hw/timer/aspeed_timer.c b/hw/timer/aspeed_timer.c
64
index XXXXXXX..XXXXXXX 100644
65
--- a/hw/timer/aspeed_timer.c
66
+++ b/hw/timer/aspeed_timer.c
67
@@ -XXX,XX +XXX,XX @@ static uint64_t aspeed_timer_read(void *opaque, hwaddr offset, unsigned size)
68
case 0x40 ... 0x8c: /* Timers 5 - 8 */
69
value = aspeed_timer_get_value(&s->timers[(offset >> 4) - 1], reg);
70
break;
71
- /* Illegal */
72
- case 0x38:
73
- case 0x3C:
74
default:
75
- qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%" HWADDR_PRIx "\n",
76
- __func__, offset);
77
- value = 0;
78
+ value = ASPEED_TIMER_GET_CLASS(s)->read(s, offset);
79
break;
80
}
81
trace_aspeed_timer_read(offset, size, value);
82
@@ -XXX,XX +XXX,XX @@ static void aspeed_timer_write(void *opaque, hwaddr offset, uint64_t value,
83
case 0x40 ... 0x8c:
84
aspeed_timer_set_value(s, (offset >> TIMER_NR_REGS) - 1, reg, tv);
85
break;
86
- /* Illegal */
87
- case 0x38:
88
- case 0x3C:
89
default:
90
- qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%" HWADDR_PRIx "\n",
91
- __func__, offset);
92
+ ASPEED_TIMER_GET_CLASS(s)->write(s, offset, value);
93
break;
94
}
95
}
96
@@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps aspeed_timer_ops = {
97
.valid.unaligned = false,
98
};
158
};
99
159
100
+static uint64_t aspeed_2400_timer_read(AspeedTimerCtrlState *s, hwaddr offset)
160
+static void ehci_npcm7xx_class_init(ObjectClass *oc, void *data)
101
+{
161
+{
102
+ uint64_t value;
162
+ SysBusEHCIClass *sec = SYS_BUS_EHCI_CLASS(oc);
163
+ DeviceClass *dc = DEVICE_CLASS(oc);
103
+
164
+
104
+ switch (offset) {
165
+ sec->capsbase = 0x0;
105
+ case 0x38:
166
+ sec->opregbase = 0x10;
106
+ case 0x3C:
167
+ sec->portscbase = 0x44;
107
+ default:
168
+ sec->portnr = 1;
108
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%" HWADDR_PRIx "\n",
169
+ set_bit(DEVICE_CATEGORY_USB, dc->categories);
109
+ __func__, offset);
110
+ value = 0;
111
+ break;
112
+ }
113
+ return value;
114
+}
170
+}
115
+
171
+
116
+static void aspeed_2400_timer_write(AspeedTimerCtrlState *s, hwaddr offset,
172
+static const TypeInfo ehci_npcm7xx_type_info = {
117
+ uint64_t value)
173
+ .name = TYPE_NPCM7XX_EHCI,
118
+{
174
+ .parent = TYPE_SYS_BUS_EHCI,
119
+ switch (offset) {
175
+ .class_init = ehci_npcm7xx_class_init,
120
+ case 0x38:
121
+ case 0x3C:
122
+ default:
123
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%" HWADDR_PRIx "\n",
124
+ __func__, offset);
125
+ break;
126
+ }
127
+}
128
+
129
+static uint64_t aspeed_2500_timer_read(AspeedTimerCtrlState *s, hwaddr offset)
130
+{
131
+ uint64_t value;
132
+
133
+ switch (offset) {
134
+ case 0x38:
135
+ case 0x3C:
136
+ default:
137
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%" HWADDR_PRIx "\n",
138
+ __func__, offset);
139
+ value = 0;
140
+ break;
141
+ }
142
+ return value;
143
+}
144
+
145
+static void aspeed_2500_timer_write(AspeedTimerCtrlState *s, hwaddr offset,
146
+ uint64_t value)
147
+{
148
+ switch (offset) {
149
+ case 0x38:
150
+ case 0x3C:
151
+ default:
152
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%" HWADDR_PRIx "\n",
153
+ __func__, offset);
154
+ break;
155
+ }
156
+}
157
+
158
static void aspeed_init_one_timer(AspeedTimerCtrlState *s, uint8_t id)
159
{
160
AspeedTimer *t = &s->timers[id];
161
@@ -XXX,XX +XXX,XX @@ static const TypeInfo aspeed_timer_info = {
162
.parent = TYPE_SYS_BUS_DEVICE,
163
.instance_size = sizeof(AspeedTimerCtrlState),
164
.class_init = timer_class_init,
165
+ .class_size = sizeof(AspeedTimerClass),
166
+ .abstract = true,
167
+};
176
+};
168
+
177
+
169
+static void aspeed_2400_timer_class_init(ObjectClass *klass, void *data)
178
static void ehci_tegra2_class_init(ObjectClass *oc, void *data)
170
+{
171
+ DeviceClass *dc = DEVICE_CLASS(klass);
172
+ AspeedTimerClass *awc = ASPEED_TIMER_CLASS(klass);
173
+
174
+ dc->desc = "ASPEED 2400 Timer";
175
+ awc->read = aspeed_2400_timer_read;
176
+ awc->write = aspeed_2400_timer_write;
177
+}
178
+
179
+static const TypeInfo aspeed_2400_timer_info = {
180
+ .name = TYPE_ASPEED_2400_TIMER,
181
+ .parent = TYPE_ASPEED_TIMER,
182
+ .class_init = aspeed_2400_timer_class_init,
183
+};
184
+
185
+static void aspeed_2500_timer_class_init(ObjectClass *klass, void *data)
186
+{
187
+ DeviceClass *dc = DEVICE_CLASS(klass);
188
+ AspeedTimerClass *awc = ASPEED_TIMER_CLASS(klass);
189
+
190
+ dc->desc = "ASPEED 2500 Timer";
191
+ awc->read = aspeed_2500_timer_read;
192
+ awc->write = aspeed_2500_timer_write;
193
+}
194
+
195
+static const TypeInfo aspeed_2500_timer_info = {
196
+ .name = TYPE_ASPEED_2500_TIMER,
197
+ .parent = TYPE_ASPEED_TIMER,
198
+ .class_init = aspeed_2500_timer_class_init,
199
};
200
201
static void aspeed_timer_register_types(void)
202
{
179
{
203
type_register_static(&aspeed_timer_info);
180
SysBusEHCIClass *sec = SYS_BUS_EHCI_CLASS(oc);
204
+ type_register_static(&aspeed_2400_timer_info);
181
@@ -XXX,XX +XXX,XX @@ static void ehci_sysbus_register_types(void)
205
+ type_register_static(&aspeed_2500_timer_info);
182
type_register_static(&ehci_platform_type_info);
206
}
183
type_register_static(&ehci_exynos4210_type_info);
207
184
type_register_static(&ehci_aw_h3_type_info);
208
type_init(aspeed_timer_register_types)
185
+ type_register_static(&ehci_npcm7xx_type_info);
186
type_register_static(&ehci_tegra2_type_info);
187
type_register_static(&ehci_ppc4xx_type_info);
188
type_register_static(&ehci_fusbh200_type_info);
209
--
189
--
210
2.20.1
190
2.20.1
211
191
212
192
diff view generated by jsdifflib
1
From: Eddie James <eajames@linux.ibm.com>
1
From: Havard Skinnemoen <hskinnemoen@google.com>
2
2
3
The Aspeed SOCs have two SD/MMC controllers. Add a device that
3
The NPCM7xx chips have multiple GPIO controllers that are mostly
4
encapsulates both of these controllers and models the Aspeed-specific
4
identical except for some minor differences like the reset values of
5
registers and behavior.
5
some registers. Each controller controls up to 32 pins.
6
6
7
Tested by reading from mmcblk0 in Linux:
7
Each individual pin is modeled as a pair of unnamed GPIOs -- one for
8
qemu-system-arm -machine romulus-bmc -nographic \
8
emitting the actual pin state, and one for driving the pin externally.
9
-drive file=flash-romulus,format=raw,if=mtd \
9
Like the nRF51 GPIO controller, a gpio level may be negative, which
10
-device sd-card,drive=sd0 -drive file=_tmp/kernel,format=raw,if=sd,id=sd0
10
means the pin is not driven, or floating.
11
11
12
Signed-off-by: Eddie James <eajames@linux.ibm.com>
12
Reviewed-by: Tyrone Ting <kfting@nuvoton.com>
13
Reviewed-by: Cédric Le Goater <clg@kaod.org>
13
Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
14
Reviewed-by: Joel Stanley <joel@jms.id.au>
14
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
15
Signed-off-by: Cédric Le Goater <clg@kaod.org>
16
Message-id: 20190925143248.10000-3-clg@kaod.org
17
[clg: - changed the controller MMIO window size to 0x1000
18
- moved the MMIO mapping of the SDHCI slots at the SoC level
19
- merged code to add SD drives on the SD buses at the machine level ]
20
Signed-off-by: Cédric Le Goater <clg@kaod.org>
21
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
15
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
22
---
16
---
23
hw/sd/Makefile.objs | 1 +
17
docs/system/arm/nuvoton.rst | 2 +-
24
include/hw/arm/aspeed_soc.h | 3 +
18
include/hw/arm/npcm7xx.h | 2 +
25
include/hw/sd/aspeed_sdhci.h | 34 ++++++
19
include/hw/gpio/npcm7xx_gpio.h | 55 +++++
26
hw/arm/aspeed.c | 15 ++-
20
hw/arm/npcm7xx.c | 80 ++++++
27
hw/arm/aspeed_soc.c | 23 ++++
21
hw/gpio/npcm7xx_gpio.c | 424 ++++++++++++++++++++++++++++++++
28
hw/sd/aspeed_sdhci.c | 198 +++++++++++++++++++++++++++++++++++
22
tests/qtest/npcm7xx_gpio-test.c | 385 +++++++++++++++++++++++++++++
29
6 files changed, 273 insertions(+), 1 deletion(-)
23
hw/gpio/meson.build | 1 +
30
create mode 100644 include/hw/sd/aspeed_sdhci.h
24
hw/gpio/trace-events | 7 +
31
create mode 100644 hw/sd/aspeed_sdhci.c
25
tests/qtest/meson.build | 3 +-
26
9 files changed, 957 insertions(+), 2 deletions(-)
27
create mode 100644 include/hw/gpio/npcm7xx_gpio.h
28
create mode 100644 hw/gpio/npcm7xx_gpio.c
29
create mode 100644 tests/qtest/npcm7xx_gpio-test.c
32
30
33
diff --git a/hw/sd/Makefile.objs b/hw/sd/Makefile.objs
31
diff --git a/docs/system/arm/nuvoton.rst b/docs/system/arm/nuvoton.rst
34
index XXXXXXX..XXXXXXX 100644
32
index XXXXXXX..XXXXXXX 100644
35
--- a/hw/sd/Makefile.objs
33
--- a/docs/system/arm/nuvoton.rst
36
+++ b/hw/sd/Makefile.objs
34
+++ b/docs/system/arm/nuvoton.rst
37
@@ -XXX,XX +XXX,XX @@ obj-$(CONFIG_MILKYMIST) += milkymist-memcard.o
35
@@ -XXX,XX +XXX,XX @@ Supported devices
38
obj-$(CONFIG_OMAP) += omap_mmc.o
36
* Flash Interface Unit (FIU; no protection features)
39
obj-$(CONFIG_PXA2XX) += pxa2xx_mmci.o
37
* Random Number Generator (RNG)
40
obj-$(CONFIG_RASPI) += bcm2835_sdhost.o
38
* USB host (USBH)
41
+obj-$(CONFIG_ASPEED_SOC) += aspeed_sdhci.o
39
+ * GPIO controller
42
diff --git a/include/hw/arm/aspeed_soc.h b/include/hw/arm/aspeed_soc.h
40
41
Missing devices
42
---------------
43
44
- * GPIO controller
45
* LPC/eSPI host-to-BMC interface, including
46
47
* Keyboard and mouse controller interface (KBCI)
48
diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h
43
index XXXXXXX..XXXXXXX 100644
49
index XXXXXXX..XXXXXXX 100644
44
--- a/include/hw/arm/aspeed_soc.h
50
--- a/include/hw/arm/npcm7xx.h
45
+++ b/include/hw/arm/aspeed_soc.h
51
+++ b/include/hw/arm/npcm7xx.h
46
@@ -XXX,XX +XXX,XX @@
52
@@ -XXX,XX +XXX,XX @@
47
#include "hw/net/ftgmac100.h"
53
48
#include "target/arm/cpu.h"
54
#include "hw/boards.h"
49
#include "hw/gpio/aspeed_gpio.h"
55
#include "hw/cpu/a9mpcore.h"
50
+#include "hw/sd/aspeed_sdhci.h"
56
+#include "hw/gpio/npcm7xx_gpio.h"
51
57
#include "hw/mem/npcm7xx_mc.h"
52
#define ASPEED_SPIS_NUM 2
58
#include "hw/misc/npcm7xx_clk.h"
53
#define ASPEED_WDTS_NUM 3
59
#include "hw/misc/npcm7xx_gcr.h"
54
@@ -XXX,XX +XXX,XX @@ typedef struct AspeedSoCState {
60
@@ -XXX,XX +XXX,XX @@ typedef struct NPCM7xxState {
55
AspeedWDTState wdt[ASPEED_WDTS_NUM];
61
NPCM7xxOTPState fuse_array;
56
FTGMAC100State ftgmac100[ASPEED_MACS_NUM];
62
NPCM7xxMCState mc;
57
AspeedGPIOState gpio;
63
NPCM7xxRNGState rng;
58
+ AspeedSDHCIState sdhci;
64
+ NPCM7xxGPIOState gpio[8];
59
} AspeedSoCState;
65
EHCISysBusState ehci;
60
66
OHCISysBusState ohci;
61
#define TYPE_ASPEED_SOC "aspeed-soc"
67
NPCM7xxFIUState fiu[2];
62
@@ -XXX,XX +XXX,XX @@ enum {
68
diff --git a/include/hw/gpio/npcm7xx_gpio.h b/include/hw/gpio/npcm7xx_gpio.h
63
ASPEED_SCU,
64
ASPEED_ADC,
65
ASPEED_SRAM,
66
+ ASPEED_SDHCI,
67
ASPEED_GPIO,
68
ASPEED_RTC,
69
ASPEED_TIMER1,
70
diff --git a/include/hw/sd/aspeed_sdhci.h b/include/hw/sd/aspeed_sdhci.h
71
new file mode 100644
69
new file mode 100644
72
index XXXXXXX..XXXXXXX
70
index XXXXXXX..XXXXXXX
73
--- /dev/null
71
--- /dev/null
74
+++ b/include/hw/sd/aspeed_sdhci.h
72
+++ b/include/hw/gpio/npcm7xx_gpio.h
75
@@ -XXX,XX +XXX,XX @@
73
@@ -XXX,XX +XXX,XX @@
76
+/*
74
+/*
77
+ * Aspeed SD Host Controller
75
+ * Nuvoton NPCM7xx General Purpose Input / Output (GPIO)
78
+ * Eddie James <eajames@linux.ibm.com>
79
+ *
76
+ *
80
+ * Copyright (C) 2019 IBM Corp
77
+ * Copyright 2020 Google LLC
81
+ * SPDX-License-Identifer: GPL-2.0-or-later
78
+ *
79
+ * This program is free software; you can redistribute it and/or
80
+ * modify it under the terms of the GNU General Public License
81
+ * version 2 as published by the Free Software Foundation.
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.
82
+ */
87
+ */
83
+
88
+#ifndef NPCM7XX_GPIO_H
84
+#ifndef ASPEED_SDHCI_H
89
+#define NPCM7XX_GPIO_H
85
+#define ASPEED_SDHCI_H
90
+
86
+
91
+#include "exec/memory.h"
87
+#include "hw/sd/sdhci.h"
92
+#include "hw/sysbus.h"
88
+
93
+
89
+#define TYPE_ASPEED_SDHCI "aspeed.sdhci"
94
+/* Number of pins managed by each controller. */
90
+#define ASPEED_SDHCI(obj) OBJECT_CHECK(AspeedSDHCIState, (obj), \
95
+#define NPCM7XX_GPIO_NR_PINS (32)
91
+ TYPE_ASPEED_SDHCI)
96
+
92
+
97
+/*
93
+#define ASPEED_SDHCI_CAPABILITIES 0x01E80080
98
+ * Number of registers in our device state structure. Don't change this without
94
+#define ASPEED_SDHCI_NUM_SLOTS 2
99
+ * incrementing the version_id in the vmstate.
95
+#define ASPEED_SDHCI_NUM_REGS (ASPEED_SDHCI_REG_SIZE / sizeof(uint32_t))
100
+ */
96
+#define ASPEED_SDHCI_REG_SIZE 0x100
101
+#define NPCM7XX_GPIO_NR_REGS (0x80 / sizeof(uint32_t))
97
+
102
+
98
+typedef struct AspeedSDHCIState {
103
+typedef struct NPCM7xxGPIOState {
99
+ SysBusDevice parent;
104
+ SysBusDevice parent;
100
+
105
+
101
+ SDHCIState slots[ASPEED_SDHCI_NUM_SLOTS];
106
+ /* Properties to be defined by the SoC */
102
+
107
+ uint32_t reset_pu;
103
+ MemoryRegion iomem;
108
+ uint32_t reset_pd;
109
+ uint32_t reset_osrc;
110
+ uint32_t reset_odsc;
111
+
112
+ MemoryRegion mmio;
113
+
104
+ qemu_irq irq;
114
+ qemu_irq irq;
105
+
115
+ qemu_irq output[NPCM7XX_GPIO_NR_PINS];
106
+ uint32_t regs[ASPEED_SDHCI_NUM_REGS];
116
+
107
+} AspeedSDHCIState;
117
+ uint32_t pin_level;
108
+
118
+ uint32_t ext_level;
109
+#endif /* ASPEED_SDHCI_H */
119
+ uint32_t ext_driven;
110
diff --git a/hw/arm/aspeed.c b/hw/arm/aspeed.c
120
+
121
+ uint32_t regs[NPCM7XX_GPIO_NR_REGS];
122
+} NPCM7xxGPIOState;
123
+
124
+#define TYPE_NPCM7XX_GPIO "npcm7xx-gpio"
125
+#define NPCM7XX_GPIO(obj) \
126
+ OBJECT_CHECK(NPCM7xxGPIOState, (obj), TYPE_NPCM7XX_GPIO)
127
+
128
+#endif /* NPCM7XX_GPIO_H */
129
diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c
111
index XXXXXXX..XXXXXXX 100644
130
index XXXXXXX..XXXXXXX 100644
112
--- a/hw/arm/aspeed.c
131
--- a/hw/arm/npcm7xx.c
113
+++ b/hw/arm/aspeed.c
132
+++ b/hw/arm/npcm7xx.c
114
@@ -XXX,XX +XXX,XX @@ static void aspeed_board_init(MachineState *machine,
133
@@ -XXX,XX +XXX,XX @@ enum NPCM7xxInterrupt {
115
AspeedSoCClass *sc;
134
NPCM7XX_WDG2_IRQ, /* Timer Module 2 Watchdog */
116
DriveInfo *drive0 = drive_get(IF_MTD, 0, 0);
135
NPCM7XX_EHCI_IRQ = 61,
117
ram_addr_t max_ram_size;
136
NPCM7XX_OHCI_IRQ = 62,
118
+ int i;
137
+ NPCM7XX_GPIO0_IRQ = 116,
119
138
+ NPCM7XX_GPIO1_IRQ,
120
bmc = g_new0(AspeedBoardState, 1);
139
+ NPCM7XX_GPIO2_IRQ,
121
140
+ NPCM7XX_GPIO3_IRQ,
122
@@ -XXX,XX +XXX,XX @@ static void aspeed_board_init(MachineState *machine,
141
+ NPCM7XX_GPIO4_IRQ,
123
cfg->i2c_init(bmc);
142
+ NPCM7XX_GPIO5_IRQ,
143
+ NPCM7XX_GPIO6_IRQ,
144
+ NPCM7XX_GPIO7_IRQ,
145
};
146
147
/* Total number of GIC interrupts, including internal Cortex-A9 interrupts. */
148
@@ -XXX,XX +XXX,XX @@ static const hwaddr npcm7xx_fiu3_flash_addr[] = {
149
0xb8000000, /* CS3 */
150
};
151
152
+static const struct {
153
+ hwaddr regs_addr;
154
+ uint32_t unconnected_pins;
155
+ uint32_t reset_pu;
156
+ uint32_t reset_pd;
157
+ uint32_t reset_osrc;
158
+ uint32_t reset_odsc;
159
+} npcm7xx_gpio[] = {
160
+ {
161
+ .regs_addr = 0xf0010000,
162
+ .reset_pu = 0xff03ffff,
163
+ .reset_pd = 0x00fc0000,
164
+ }, {
165
+ .regs_addr = 0xf0011000,
166
+ .unconnected_pins = 0x0000001e,
167
+ .reset_pu = 0xfefffe07,
168
+ .reset_pd = 0x010001e0,
169
+ }, {
170
+ .regs_addr = 0xf0012000,
171
+ .reset_pu = 0x780fffff,
172
+ .reset_pd = 0x07f00000,
173
+ .reset_odsc = 0x00700000,
174
+ }, {
175
+ .regs_addr = 0xf0013000,
176
+ .reset_pu = 0x00fc0000,
177
+ .reset_pd = 0xff000000,
178
+ }, {
179
+ .regs_addr = 0xf0014000,
180
+ .reset_pu = 0xffffffff,
181
+ }, {
182
+ .regs_addr = 0xf0015000,
183
+ .reset_pu = 0xbf83f801,
184
+ .reset_pd = 0x007c0000,
185
+ .reset_osrc = 0x000000f1,
186
+ .reset_odsc = 0x3f9f80f1,
187
+ }, {
188
+ .regs_addr = 0xf0016000,
189
+ .reset_pu = 0xfc00f801,
190
+ .reset_pd = 0x000007fe,
191
+ .reset_odsc = 0x00000800,
192
+ }, {
193
+ .regs_addr = 0xf0017000,
194
+ .unconnected_pins = 0xffffff00,
195
+ .reset_pu = 0x0000007f,
196
+ .reset_osrc = 0x0000007f,
197
+ .reset_odsc = 0x0000007f,
198
+ },
199
+};
200
+
201
static const struct {
202
const char *name;
203
hwaddr regs_addr;
204
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_init(Object *obj)
205
object_initialize_child(obj, "tim[*]", &s->tim[i], TYPE_NPCM7XX_TIMER);
124
}
206
}
125
207
126
+ for (i = 0; i < ARRAY_SIZE(bmc->soc.sdhci.slots); i++) {
208
+ for (i = 0; i < ARRAY_SIZE(s->gpio); i++) {
127
+ SDHCIState *sdhci = &bmc->soc.sdhci.slots[i];
209
+ object_initialize_child(obj, "gpio[*]", &s->gpio[i], TYPE_NPCM7XX_GPIO);
128
+ DriveInfo *dinfo = drive_get_next(IF_SD);
129
+ BlockBackend *blk;
130
+ DeviceState *card;
131
+
132
+ blk = dinfo ? blk_by_legacy_dinfo(dinfo) : NULL;
133
+ card = qdev_create(qdev_get_child_bus(DEVICE(sdhci), "sd-bus"),
134
+ TYPE_SD_CARD);
135
+ qdev_prop_set_drive(card, "drive", blk, &error_fatal);
136
+ object_property_set_bool(OBJECT(card), true, "realized", &error_fatal);
137
+ }
210
+ }
138
+
211
+
139
arm_load_kernel(ARM_CPU(first_cpu), machine, &aspeed_board_binfo);
212
object_initialize_child(obj, "ehci", &s->ehci, TYPE_NPCM7XX_EHCI);
140
}
213
object_initialize_child(obj, "ohci", &s->ohci, TYPE_SYSBUS_OHCI);
141
214
142
@@ -XXX,XX +XXX,XX @@ static void aspeed_machine_class_init(ObjectClass *oc, void *data)
215
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp)
143
mc->desc = board->desc;
216
sysbus_realize(SYS_BUS_DEVICE(&s->rng), &error_abort);
144
mc->init = aspeed_machine_init;
217
sysbus_mmio_map(SYS_BUS_DEVICE(&s->rng), 0, NPCM7XX_RNG_BA);
145
mc->max_cpus = ASPEED_CPUS_NUM;
218
146
- mc->no_sdcard = 1;
219
+ /* GPIO modules. Cannot fail. */
147
mc->no_floppy = 1;
220
+ QEMU_BUILD_BUG_ON(ARRAY_SIZE(npcm7xx_gpio) != ARRAY_SIZE(s->gpio));
148
mc->no_cdrom = 1;
221
+ for (i = 0; i < ARRAY_SIZE(s->gpio); i++) {
149
mc->no_parallel = 1;
222
+ Object *obj = OBJECT(&s->gpio[i]);
150
diff --git a/hw/arm/aspeed_soc.c b/hw/arm/aspeed_soc.c
223
+
151
index XXXXXXX..XXXXXXX 100644
224
+ object_property_set_uint(obj, "reset-pullup",
152
--- a/hw/arm/aspeed_soc.c
225
+ npcm7xx_gpio[i].reset_pu, &error_abort);
153
+++ b/hw/arm/aspeed_soc.c
226
+ object_property_set_uint(obj, "reset-pulldown",
154
@@ -XXX,XX +XXX,XX @@ static const hwaddr aspeed_soc_ast2400_memmap[] = {
227
+ npcm7xx_gpio[i].reset_pd, &error_abort);
155
[ASPEED_XDMA] = 0x1E6E7000,
228
+ object_property_set_uint(obj, "reset-osrc",
156
[ASPEED_ADC] = 0x1E6E9000,
229
+ npcm7xx_gpio[i].reset_osrc, &error_abort);
157
[ASPEED_SRAM] = 0x1E720000,
230
+ object_property_set_uint(obj, "reset-odsc",
158
+ [ASPEED_SDHCI] = 0x1E740000,
231
+ npcm7xx_gpio[i].reset_odsc, &error_abort);
159
[ASPEED_GPIO] = 0x1E780000,
232
+ sysbus_realize(SYS_BUS_DEVICE(obj), &error_abort);
160
[ASPEED_RTC] = 0x1E781000,
233
+ sysbus_mmio_map(SYS_BUS_DEVICE(obj), 0, npcm7xx_gpio[i].regs_addr);
161
[ASPEED_TIMER1] = 0x1E782000,
234
+ sysbus_connect_irq(SYS_BUS_DEVICE(obj), 0,
162
@@ -XXX,XX +XXX,XX @@ static const hwaddr aspeed_soc_ast2500_memmap[] = {
235
+ npcm7xx_irq(s, NPCM7XX_GPIO0_IRQ + i));
163
[ASPEED_XDMA] = 0x1E6E7000,
164
[ASPEED_ADC] = 0x1E6E9000,
165
[ASPEED_SRAM] = 0x1E720000,
166
+ [ASPEED_SDHCI] = 0x1E740000,
167
[ASPEED_GPIO] = 0x1E780000,
168
[ASPEED_RTC] = 0x1E781000,
169
[ASPEED_TIMER1] = 0x1E782000,
170
@@ -XXX,XX +XXX,XX @@ static const int aspeed_soc_ast2400_irqmap[] = {
171
[ASPEED_ETH1] = 2,
172
[ASPEED_ETH2] = 3,
173
[ASPEED_XDMA] = 6,
174
+ [ASPEED_SDHCI] = 26,
175
};
176
177
#define aspeed_soc_ast2500_irqmap aspeed_soc_ast2400_irqmap
178
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_init(Object *obj)
179
snprintf(typename, sizeof(typename), "aspeed.gpio-%s", socname);
180
sysbus_init_child_obj(obj, "gpio", OBJECT(&s->gpio), sizeof(s->gpio),
181
typename);
182
+
183
+ sysbus_init_child_obj(obj, "sdc", OBJECT(&s->sdhci), sizeof(s->sdhci),
184
+ TYPE_ASPEED_SDHCI);
185
+
186
+ /* Init sd card slot class here so that they're under the correct parent */
187
+ for (i = 0; i < ASPEED_SDHCI_NUM_SLOTS; ++i) {
188
+ sysbus_init_child_obj(obj, "sdhci[*]", OBJECT(&s->sdhci.slots[i]),
189
+ sizeof(s->sdhci.slots[i]), TYPE_SYSBUS_SDHCI);
190
+ }
236
+ }
191
}
237
+
192
238
/* USB Host */
193
static void aspeed_soc_realize(DeviceState *dev, Error **errp)
239
object_property_set_bool(OBJECT(&s->ehci), "companion-enable", true,
194
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
240
&error_abort);
195
sysbus_mmio_map(SYS_BUS_DEVICE(&s->gpio), 0, sc->info->memmap[ASPEED_GPIO]);
241
diff --git a/hw/gpio/npcm7xx_gpio.c b/hw/gpio/npcm7xx_gpio.c
196
sysbus_connect_irq(SYS_BUS_DEVICE(&s->gpio), 0,
197
aspeed_soc_get_irq(s, ASPEED_GPIO));
198
+
199
+ /* SDHCI */
200
+ object_property_set_bool(OBJECT(&s->sdhci), true, "realized", &err);
201
+ if (err) {
202
+ error_propagate(errp, err);
203
+ return;
204
+ }
205
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->sdhci), 0,
206
+ sc->info->memmap[ASPEED_SDHCI]);
207
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->sdhci), 0,
208
+ aspeed_soc_get_irq(s, ASPEED_SDHCI));
209
}
210
static Property aspeed_soc_properties[] = {
211
DEFINE_PROP_UINT32("num-cpus", AspeedSoCState, num_cpus, 0),
212
diff --git a/hw/sd/aspeed_sdhci.c b/hw/sd/aspeed_sdhci.c
213
new file mode 100644
242
new file mode 100644
214
index XXXXXXX..XXXXXXX
243
index XXXXXXX..XXXXXXX
215
--- /dev/null
244
--- /dev/null
216
+++ b/hw/sd/aspeed_sdhci.c
245
+++ b/hw/gpio/npcm7xx_gpio.c
217
@@ -XXX,XX +XXX,XX @@
246
@@ -XXX,XX +XXX,XX @@
218
+/*
247
+/*
219
+ * Aspeed SD Host Controller
248
+ * Nuvoton NPCM7xx General Purpose Input / Output (GPIO)
220
+ * Eddie James <eajames@linux.ibm.com>
221
+ *
249
+ *
222
+ * Copyright (C) 2019 IBM Corp
250
+ * Copyright 2020 Google LLC
223
+ * SPDX-License-Identifer: GPL-2.0-or-later
251
+ *
252
+ * This program is free software; you can redistribute it and/or
253
+ * modify it under the terms of the GNU General Public License
254
+ * version 2 as published by the Free Software Foundation.
255
+ *
256
+ * This program is distributed in the hope that it will be useful,
257
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
258
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
259
+ * GNU General Public License for more details.
224
+ */
260
+ */
225
+
261
+
226
+#include "qemu/osdep.h"
262
+#include "qemu/osdep.h"
263
+
264
+#include "hw/gpio/npcm7xx_gpio.h"
265
+#include "hw/irq.h"
266
+#include "hw/qdev-properties.h"
267
+#include "migration/vmstate.h"
268
+#include "qapi/error.h"
227
+#include "qemu/log.h"
269
+#include "qemu/log.h"
228
+#include "qemu/error-report.h"
270
+#include "qemu/module.h"
229
+#include "hw/sd/aspeed_sdhci.h"
271
+#include "qemu/units.h"
230
+#include "qapi/error.h"
272
+#include "trace.h"
231
+#include "hw/irq.h"
273
+
232
+#include "migration/vmstate.h"
274
+/* 32-bit register indices. */
233
+
275
+enum NPCM7xxGPIORegister {
234
+#define ASPEED_SDHCI_INFO 0x00
276
+ NPCM7XX_GPIO_TLOCK1,
235
+#define ASPEED_SDHCI_INFO_RESET 0x00030000
277
+ NPCM7XX_GPIO_DIN,
236
+#define ASPEED_SDHCI_DEBOUNCE 0x04
278
+ NPCM7XX_GPIO_POL,
237
+#define ASPEED_SDHCI_DEBOUNCE_RESET 0x00000005
279
+ NPCM7XX_GPIO_DOUT,
238
+#define ASPEED_SDHCI_BUS 0x08
280
+ NPCM7XX_GPIO_OE,
239
+#define ASPEED_SDHCI_SDIO_140 0x10
281
+ NPCM7XX_GPIO_OTYP,
240
+#define ASPEED_SDHCI_SDIO_148 0x18
282
+ NPCM7XX_GPIO_MP,
241
+#define ASPEED_SDHCI_SDIO_240 0x20
283
+ NPCM7XX_GPIO_PU,
242
+#define ASPEED_SDHCI_SDIO_248 0x28
284
+ NPCM7XX_GPIO_PD,
243
+#define ASPEED_SDHCI_WP_POL 0xec
285
+ NPCM7XX_GPIO_DBNC,
244
+#define ASPEED_SDHCI_CARD_DET 0xf0
286
+ NPCM7XX_GPIO_EVTYP,
245
+#define ASPEED_SDHCI_IRQ_STAT 0xfc
287
+ NPCM7XX_GPIO_EVBE,
246
+
288
+ NPCM7XX_GPIO_OBL0,
247
+#define TO_REG(addr) ((addr) / sizeof(uint32_t))
289
+ NPCM7XX_GPIO_OBL1,
248
+
290
+ NPCM7XX_GPIO_OBL2,
249
+static uint64_t aspeed_sdhci_read(void *opaque, hwaddr addr, unsigned int size)
291
+ NPCM7XX_GPIO_OBL3,
250
+{
292
+ NPCM7XX_GPIO_EVEN,
251
+ uint32_t val = 0;
293
+ NPCM7XX_GPIO_EVENS,
252
+ AspeedSDHCIState *sdhci = opaque;
294
+ NPCM7XX_GPIO_EVENC,
253
+
295
+ NPCM7XX_GPIO_EVST,
254
+ switch (addr) {
296
+ NPCM7XX_GPIO_SPLCK,
255
+ case ASPEED_SDHCI_SDIO_140:
297
+ NPCM7XX_GPIO_MPLCK,
256
+ val = (uint32_t)sdhci->slots[0].capareg;
298
+ NPCM7XX_GPIO_IEM,
257
+ break;
299
+ NPCM7XX_GPIO_OSRC,
258
+ case ASPEED_SDHCI_SDIO_148:
300
+ NPCM7XX_GPIO_ODSC,
259
+ val = (uint32_t)sdhci->slots[0].maxcurr;
301
+ NPCM7XX_GPIO_DOS = 0x68 / sizeof(uint32_t),
260
+ break;
302
+ NPCM7XX_GPIO_DOC,
261
+ case ASPEED_SDHCI_SDIO_240:
303
+ NPCM7XX_GPIO_OES,
262
+ val = (uint32_t)sdhci->slots[1].capareg;
304
+ NPCM7XX_GPIO_OEC,
263
+ break;
305
+ NPCM7XX_GPIO_TLOCK2 = 0x7c / sizeof(uint32_t),
264
+ case ASPEED_SDHCI_SDIO_248:
306
+ NPCM7XX_GPIO_REGS_END,
265
+ val = (uint32_t)sdhci->slots[1].maxcurr;
307
+};
266
+ break;
308
+
267
+ default:
309
+#define NPCM7XX_GPIO_REGS_SIZE (4 * KiB)
268
+ if (addr < ASPEED_SDHCI_REG_SIZE) {
310
+
269
+ val = sdhci->regs[TO_REG(addr)];
311
+#define NPCM7XX_GPIO_LOCK_MAGIC1 (0xc0defa73)
270
+ } else {
312
+#define NPCM7XX_GPIO_LOCK_MAGIC2 (0xc0de1248)
271
+ qemu_log_mask(LOG_GUEST_ERROR,
313
+
272
+ "%s: Out-of-bounds read at 0x%" HWADDR_PRIx "\n",
314
+static void npcm7xx_gpio_update_events(NPCM7xxGPIOState *s, uint32_t din_diff)
273
+ __func__, addr);
315
+{
316
+ uint32_t din_new = s->regs[NPCM7XX_GPIO_DIN];
317
+
318
+ /* Trigger on high level */
319
+ s->regs[NPCM7XX_GPIO_EVST] |= din_new & ~s->regs[NPCM7XX_GPIO_EVTYP];
320
+ /* Trigger on both edges */
321
+ s->regs[NPCM7XX_GPIO_EVST] |= (din_diff & s->regs[NPCM7XX_GPIO_EVTYP]
322
+ & s->regs[NPCM7XX_GPIO_EVBE]);
323
+ /* Trigger on rising edge */
324
+ s->regs[NPCM7XX_GPIO_EVST] |= (din_diff & din_new
325
+ & s->regs[NPCM7XX_GPIO_EVTYP]);
326
+
327
+ trace_npcm7xx_gpio_update_events(DEVICE(s)->canonical_path,
328
+ s->regs[NPCM7XX_GPIO_EVST],
329
+ s->regs[NPCM7XX_GPIO_EVEN]);
330
+ qemu_set_irq(s->irq, !!(s->regs[NPCM7XX_GPIO_EVST]
331
+ & s->regs[NPCM7XX_GPIO_EVEN]));
332
+}
333
+
334
+static void npcm7xx_gpio_update_pins(NPCM7xxGPIOState *s, uint32_t diff)
335
+{
336
+ uint32_t drive_en;
337
+ uint32_t drive_lvl;
338
+ uint32_t not_driven;
339
+ uint32_t undefined;
340
+ uint32_t pin_diff;
341
+ uint32_t din_old;
342
+
343
+ /* Calculate level of each pin driven by GPIO controller. */
344
+ drive_lvl = s->regs[NPCM7XX_GPIO_DOUT] ^ s->regs[NPCM7XX_GPIO_POL];
345
+ /* If OTYP=1, only drive low (open drain) */
346
+ drive_en = s->regs[NPCM7XX_GPIO_OE] & ~(s->regs[NPCM7XX_GPIO_OTYP]
347
+ & drive_lvl);
348
+ /*
349
+ * If a pin is driven to opposite levels by the GPIO controller and the
350
+ * external driver, the result is undefined.
351
+ */
352
+ undefined = drive_en & s->ext_driven & (drive_lvl ^ s->ext_level);
353
+ if (undefined) {
354
+ qemu_log_mask(LOG_GUEST_ERROR,
355
+ "%s: pins have multiple drivers: 0x%" PRIx32 "\n",
356
+ DEVICE(s)->canonical_path, undefined);
357
+ }
358
+
359
+ not_driven = ~(drive_en | s->ext_driven);
360
+ pin_diff = s->pin_level;
361
+
362
+ /* Set pins to externally driven level. */
363
+ s->pin_level = s->ext_level & s->ext_driven;
364
+ /* Set internally driven pins, ignoring any conflicts. */
365
+ s->pin_level |= drive_lvl & drive_en;
366
+ /* Pull up undriven pins with internal pull-up enabled. */
367
+ s->pin_level |= not_driven & s->regs[NPCM7XX_GPIO_PU];
368
+ /* Pins not driven, pulled up or pulled down are undefined */
369
+ undefined |= not_driven & ~(s->regs[NPCM7XX_GPIO_PU]
370
+ | s->regs[NPCM7XX_GPIO_PD]);
371
+
372
+ /* If any pins changed state, update the outgoing GPIOs. */
373
+ pin_diff ^= s->pin_level;
374
+ pin_diff |= undefined & diff;
375
+ if (pin_diff) {
376
+ int i;
377
+
378
+ for (i = 0; i < NPCM7XX_GPIO_NR_PINS; i++) {
379
+ uint32_t mask = BIT(i);
380
+ if (pin_diff & mask) {
381
+ int level = (undefined & mask) ? -1 : !!(s->pin_level & mask);
382
+ trace_npcm7xx_gpio_set_output(DEVICE(s)->canonical_path,
383
+ i, level);
384
+ qemu_set_irq(s->output[i], level);
385
+ }
274
+ }
386
+ }
275
+ }
387
+ }
276
+
388
+
277
+ return (uint64_t)val;
389
+ /* Calculate new value of DIN after masking and polarity setting. */
278
+}
390
+ din_old = s->regs[NPCM7XX_GPIO_DIN];
279
+
391
+ s->regs[NPCM7XX_GPIO_DIN] = ((s->pin_level & s->regs[NPCM7XX_GPIO_IEM])
280
+static void aspeed_sdhci_write(void *opaque, hwaddr addr, uint64_t val,
392
+ ^ s->regs[NPCM7XX_GPIO_POL]);
281
+ unsigned int size)
393
+
282
+{
394
+ /* See if any new events triggered because of all this. */
283
+ AspeedSDHCIState *sdhci = opaque;
395
+ npcm7xx_gpio_update_events(s, din_old ^ s->regs[NPCM7XX_GPIO_DIN]);
284
+
396
+}
285
+ switch (addr) {
397
+
286
+ case ASPEED_SDHCI_SDIO_140:
398
+static bool npcm7xx_gpio_is_locked(NPCM7xxGPIOState *s)
287
+ sdhci->slots[0].capareg = (uint64_t)(uint32_t)val;
399
+{
288
+ break;
400
+ return s->regs[NPCM7XX_GPIO_TLOCK1] == 1;
289
+ case ASPEED_SDHCI_SDIO_148:
401
+}
290
+ sdhci->slots[0].maxcurr = (uint64_t)(uint32_t)val;
402
+
291
+ break;
403
+static uint64_t npcm7xx_gpio_regs_read(void *opaque, hwaddr addr,
292
+ case ASPEED_SDHCI_SDIO_240:
404
+ unsigned int size)
293
+ sdhci->slots[1].capareg = (uint64_t)(uint32_t)val;
405
+{
294
+ break;
406
+ hwaddr reg = addr / sizeof(uint32_t);
295
+ case ASPEED_SDHCI_SDIO_248:
407
+ NPCM7xxGPIOState *s = opaque;
296
+ sdhci->slots[1].maxcurr = (uint64_t)(uint32_t)val;
408
+ uint64_t value = 0;
297
+ break;
409
+
410
+ switch (reg) {
411
+ case NPCM7XX_GPIO_TLOCK1 ... NPCM7XX_GPIO_EVEN:
412
+ case NPCM7XX_GPIO_EVST ... NPCM7XX_GPIO_ODSC:
413
+ value = s->regs[reg];
414
+ break;
415
+
416
+ case NPCM7XX_GPIO_EVENS ... NPCM7XX_GPIO_EVENC:
417
+ case NPCM7XX_GPIO_DOS ... NPCM7XX_GPIO_TLOCK2:
418
+ qemu_log_mask(LOG_GUEST_ERROR,
419
+ "%s: read from write-only register 0x%" HWADDR_PRIx "\n",
420
+ DEVICE(s)->canonical_path, addr);
421
+ break;
422
+
298
+ default:
423
+ default:
299
+ if (addr < ASPEED_SDHCI_REG_SIZE) {
424
+ qemu_log_mask(LOG_GUEST_ERROR,
300
+ sdhci->regs[TO_REG(addr)] = (uint32_t)val;
425
+ "%s: read from invalid offset 0x%" HWADDR_PRIx "\n",
301
+ } else {
426
+ DEVICE(s)->canonical_path, addr);
427
+ break;
428
+ }
429
+
430
+ trace_npcm7xx_gpio_read(DEVICE(s)->canonical_path, addr, value);
431
+
432
+ return value;
433
+}
434
+
435
+static void npcm7xx_gpio_regs_write(void *opaque, hwaddr addr, uint64_t v,
436
+ unsigned int size)
437
+{
438
+ hwaddr reg = addr / sizeof(uint32_t);
439
+ NPCM7xxGPIOState *s = opaque;
440
+ uint32_t value = v;
441
+ uint32_t diff;
442
+
443
+ trace_npcm7xx_gpio_write(DEVICE(s)->canonical_path, addr, v);
444
+
445
+ if (npcm7xx_gpio_is_locked(s)) {
446
+ switch (reg) {
447
+ case NPCM7XX_GPIO_TLOCK1:
448
+ if (s->regs[NPCM7XX_GPIO_TLOCK2] == NPCM7XX_GPIO_LOCK_MAGIC2 &&
449
+ value == NPCM7XX_GPIO_LOCK_MAGIC1) {
450
+ s->regs[NPCM7XX_GPIO_TLOCK1] = 0;
451
+ s->regs[NPCM7XX_GPIO_TLOCK2] = 0;
452
+ }
453
+ break;
454
+
455
+ case NPCM7XX_GPIO_TLOCK2:
456
+ s->regs[reg] = value;
457
+ break;
458
+
459
+ default:
302
+ qemu_log_mask(LOG_GUEST_ERROR,
460
+ qemu_log_mask(LOG_GUEST_ERROR,
303
+ "%s: Out-of-bounds write at 0x%" HWADDR_PRIx "\n",
461
+ "%s: write to locked register @ 0x%" HWADDR_PRIx "\n",
304
+ __func__, addr);
462
+ DEVICE(s)->canonical_path, addr);
463
+ break;
305
+ }
464
+ }
465
+
466
+ return;
306
+ }
467
+ }
307
+}
468
+
308
+
469
+ diff = s->regs[reg] ^ value;
309
+static const MemoryRegionOps aspeed_sdhci_ops = {
470
+
310
+ .read = aspeed_sdhci_read,
471
+ switch (reg) {
311
+ .write = aspeed_sdhci_write,
472
+ case NPCM7XX_GPIO_TLOCK1:
473
+ case NPCM7XX_GPIO_TLOCK2:
474
+ s->regs[NPCM7XX_GPIO_TLOCK1] = 1;
475
+ s->regs[NPCM7XX_GPIO_TLOCK2] = 0;
476
+ break;
477
+
478
+ case NPCM7XX_GPIO_DIN:
479
+ qemu_log_mask(LOG_GUEST_ERROR,
480
+ "%s: write to read-only register @ 0x%" HWADDR_PRIx "\n",
481
+ DEVICE(s)->canonical_path, addr);
482
+ break;
483
+
484
+ case NPCM7XX_GPIO_POL:
485
+ case NPCM7XX_GPIO_DOUT:
486
+ case NPCM7XX_GPIO_OE:
487
+ case NPCM7XX_GPIO_OTYP:
488
+ case NPCM7XX_GPIO_PU:
489
+ case NPCM7XX_GPIO_PD:
490
+ case NPCM7XX_GPIO_IEM:
491
+ s->regs[reg] = value;
492
+ npcm7xx_gpio_update_pins(s, diff);
493
+ break;
494
+
495
+ case NPCM7XX_GPIO_DOS:
496
+ s->regs[NPCM7XX_GPIO_DOUT] |= value;
497
+ npcm7xx_gpio_update_pins(s, value);
498
+ break;
499
+ case NPCM7XX_GPIO_DOC:
500
+ s->regs[NPCM7XX_GPIO_DOUT] &= ~value;
501
+ npcm7xx_gpio_update_pins(s, value);
502
+ break;
503
+ case NPCM7XX_GPIO_OES:
504
+ s->regs[NPCM7XX_GPIO_OE] |= value;
505
+ npcm7xx_gpio_update_pins(s, value);
506
+ break;
507
+ case NPCM7XX_GPIO_OEC:
508
+ s->regs[NPCM7XX_GPIO_OE] &= ~value;
509
+ npcm7xx_gpio_update_pins(s, value);
510
+ break;
511
+
512
+ case NPCM7XX_GPIO_EVTYP:
513
+ case NPCM7XX_GPIO_EVBE:
514
+ case NPCM7XX_GPIO_EVEN:
515
+ s->regs[reg] = value;
516
+ npcm7xx_gpio_update_events(s, 0);
517
+ break;
518
+
519
+ case NPCM7XX_GPIO_EVENS:
520
+ s->regs[NPCM7XX_GPIO_EVEN] |= value;
521
+ npcm7xx_gpio_update_events(s, 0);
522
+ break;
523
+ case NPCM7XX_GPIO_EVENC:
524
+ s->regs[NPCM7XX_GPIO_EVEN] &= ~value;
525
+ npcm7xx_gpio_update_events(s, 0);
526
+ break;
527
+
528
+ case NPCM7XX_GPIO_EVST:
529
+ s->regs[reg] &= ~value;
530
+ npcm7xx_gpio_update_events(s, 0);
531
+ break;
532
+
533
+ case NPCM7XX_GPIO_MP:
534
+ case NPCM7XX_GPIO_DBNC:
535
+ case NPCM7XX_GPIO_OSRC:
536
+ case NPCM7XX_GPIO_ODSC:
537
+ /* Nothing to do; just store the value. */
538
+ s->regs[reg] = value;
539
+ break;
540
+
541
+ case NPCM7XX_GPIO_OBL0:
542
+ case NPCM7XX_GPIO_OBL1:
543
+ case NPCM7XX_GPIO_OBL2:
544
+ case NPCM7XX_GPIO_OBL3:
545
+ s->regs[reg] = value;
546
+ qemu_log_mask(LOG_UNIMP, "%s: Blinking is not implemented\n",
547
+ __func__);
548
+ break;
549
+
550
+ case NPCM7XX_GPIO_SPLCK:
551
+ case NPCM7XX_GPIO_MPLCK:
552
+ qemu_log_mask(LOG_UNIMP, "%s: Per-pin lock is not implemented\n",
553
+ __func__);
554
+ break;
555
+
556
+ default:
557
+ qemu_log_mask(LOG_GUEST_ERROR,
558
+ "%s: write to invalid offset 0x%" HWADDR_PRIx "\n",
559
+ DEVICE(s)->canonical_path, addr);
560
+ break;
561
+ }
562
+}
563
+
564
+static const MemoryRegionOps npcm7xx_gpio_regs_ops = {
565
+ .read = npcm7xx_gpio_regs_read,
566
+ .write = npcm7xx_gpio_regs_write,
312
+ .endianness = DEVICE_NATIVE_ENDIAN,
567
+ .endianness = DEVICE_NATIVE_ENDIAN,
313
+ .valid.min_access_size = 4,
568
+ .valid = {
314
+ .valid.max_access_size = 4,
569
+ .min_access_size = 4,
570
+ .max_access_size = 4,
571
+ .unaligned = false,
572
+ },
315
+};
573
+};
316
+
574
+
317
+static void aspeed_sdhci_set_irq(void *opaque, int n, int level)
575
+static void npcm7xx_gpio_set_input(void *opaque, int line, int level)
318
+{
576
+{
319
+ AspeedSDHCIState *sdhci = opaque;
577
+ NPCM7xxGPIOState *s = opaque;
320
+
578
+
321
+ if (level) {
579
+ trace_npcm7xx_gpio_set_input(DEVICE(s)->canonical_path, line, level);
322
+ sdhci->regs[TO_REG(ASPEED_SDHCI_IRQ_STAT)] |= BIT(n);
580
+
323
+
581
+ g_assert(line >= 0 && line < NPCM7XX_GPIO_NR_PINS);
324
+ qemu_irq_raise(sdhci->irq);
582
+
325
+ } else {
583
+ s->ext_driven = deposit32(s->ext_driven, line, 1, level >= 0);
326
+ sdhci->regs[TO_REG(ASPEED_SDHCI_IRQ_STAT)] &= ~BIT(n);
584
+ s->ext_level = deposit32(s->ext_level, line, 1, level > 0);
327
+
585
+
328
+ qemu_irq_lower(sdhci->irq);
586
+ npcm7xx_gpio_update_pins(s, BIT(line));
329
+ }
587
+}
330
+}
588
+
331
+
589
+static void npcm7xx_gpio_enter_reset(Object *obj, ResetType type)
332
+static void aspeed_sdhci_realize(DeviceState *dev, Error **errp)
590
+{
333
+{
591
+ NPCM7xxGPIOState *s = NPCM7XX_GPIO(obj);
334
+ Error *err = NULL;
592
+
335
+ SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
593
+ memset(s->regs, 0, sizeof(s->regs));
336
+ AspeedSDHCIState *sdhci = ASPEED_SDHCI(dev);
594
+
337
+
595
+ s->regs[NPCM7XX_GPIO_PU] = s->reset_pu;
338
+ /* Create input irqs for the slots */
596
+ s->regs[NPCM7XX_GPIO_PD] = s->reset_pd;
339
+ qdev_init_gpio_in_named_with_opaque(DEVICE(sbd), aspeed_sdhci_set_irq,
597
+ s->regs[NPCM7XX_GPIO_OSRC] = s->reset_osrc;
340
+ sdhci, NULL, ASPEED_SDHCI_NUM_SLOTS);
598
+ s->regs[NPCM7XX_GPIO_ODSC] = s->reset_odsc;
341
+
599
+}
342
+ sysbus_init_irq(sbd, &sdhci->irq);
600
+
343
+ memory_region_init_io(&sdhci->iomem, OBJECT(sdhci), &aspeed_sdhci_ops,
601
+static void npcm7xx_gpio_hold_reset(Object *obj)
344
+ sdhci, TYPE_ASPEED_SDHCI, 0x1000);
602
+{
345
+ sysbus_init_mmio(sbd, &sdhci->iomem);
603
+ NPCM7xxGPIOState *s = NPCM7XX_GPIO(obj);
346
+
604
+
347
+ for (int i = 0; i < ASPEED_SDHCI_NUM_SLOTS; ++i) {
605
+ npcm7xx_gpio_update_pins(s, -1);
348
+ Object *sdhci_slot = OBJECT(&sdhci->slots[i]);
606
+}
349
+ SysBusDevice *sbd_slot = SYS_BUS_DEVICE(&sdhci->slots[i]);
607
+
350
+
608
+static void npcm7xx_gpio_init(Object *obj)
351
+ object_property_set_int(sdhci_slot, 2, "sd-spec-version", &err);
609
+{
352
+ if (err) {
610
+ NPCM7xxGPIOState *s = NPCM7XX_GPIO(obj);
353
+ error_propagate(errp, err);
611
+ DeviceState *dev = DEVICE(obj);
354
+ return;
612
+
355
+ }
613
+ memory_region_init_io(&s->mmio, obj, &npcm7xx_gpio_regs_ops, s,
356
+
614
+ "regs", NPCM7XX_GPIO_REGS_SIZE);
357
+ object_property_set_uint(sdhci_slot, ASPEED_SDHCI_CAPABILITIES,
615
+ sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->mmio);
358
+ "capareg", &err);
616
+ sysbus_init_irq(SYS_BUS_DEVICE(obj), &s->irq);
359
+ if (err) {
617
+
360
+ error_propagate(errp, err);
618
+ qdev_init_gpio_in(dev, npcm7xx_gpio_set_input, NPCM7XX_GPIO_NR_PINS);
361
+ return;
619
+ qdev_init_gpio_out(dev, s->output, NPCM7XX_GPIO_NR_PINS);
362
+ }
620
+}
363
+
621
+
364
+ object_property_set_bool(sdhci_slot, true, "realized", &err);
622
+static const VMStateDescription vmstate_npcm7xx_gpio = {
365
+ if (err) {
623
+ .name = "npcm7xx-gpio",
366
+ error_propagate(errp, err);
624
+ .version_id = 0,
367
+ return;
625
+ .minimum_version_id = 0,
368
+ }
369
+
370
+ sysbus_connect_irq(sbd_slot, 0, qdev_get_gpio_in(DEVICE(sbd), i));
371
+ memory_region_add_subregion(&sdhci->iomem, (i + 1) * 0x100,
372
+ &sdhci->slots[i].iomem);
373
+ }
374
+}
375
+
376
+static void aspeed_sdhci_reset(DeviceState *dev)
377
+{
378
+ AspeedSDHCIState *sdhci = ASPEED_SDHCI(dev);
379
+
380
+ memset(sdhci->regs, 0, ASPEED_SDHCI_REG_SIZE);
381
+ sdhci->regs[TO_REG(ASPEED_SDHCI_INFO)] = ASPEED_SDHCI_INFO_RESET;
382
+ sdhci->regs[TO_REG(ASPEED_SDHCI_DEBOUNCE)] = ASPEED_SDHCI_DEBOUNCE_RESET;
383
+}
384
+
385
+static const VMStateDescription vmstate_aspeed_sdhci = {
386
+ .name = TYPE_ASPEED_SDHCI,
387
+ .version_id = 1,
388
+ .fields = (VMStateField[]) {
626
+ .fields = (VMStateField[]) {
389
+ VMSTATE_UINT32_ARRAY(regs, AspeedSDHCIState, ASPEED_SDHCI_NUM_REGS),
627
+ VMSTATE_UINT32(pin_level, NPCM7xxGPIOState),
628
+ VMSTATE_UINT32(ext_level, NPCM7xxGPIOState),
629
+ VMSTATE_UINT32(ext_driven, NPCM7xxGPIOState),
630
+ VMSTATE_UINT32_ARRAY(regs, NPCM7xxGPIOState, NPCM7XX_GPIO_NR_REGS),
390
+ VMSTATE_END_OF_LIST(),
631
+ VMSTATE_END_OF_LIST(),
391
+ },
632
+ },
392
+};
633
+};
393
+
634
+
394
+static void aspeed_sdhci_class_init(ObjectClass *classp, void *data)
635
+static Property npcm7xx_gpio_properties[] = {
395
+{
636
+ /* Bit n set => pin n has pullup enabled by default. */
396
+ DeviceClass *dc = DEVICE_CLASS(classp);
637
+ DEFINE_PROP_UINT32("reset-pullup", NPCM7xxGPIOState, reset_pu, 0),
397
+
638
+ /* Bit n set => pin n has pulldown enabled by default. */
398
+ dc->realize = aspeed_sdhci_realize;
639
+ DEFINE_PROP_UINT32("reset-pulldown", NPCM7xxGPIOState, reset_pd, 0),
399
+ dc->reset = aspeed_sdhci_reset;
640
+ /* Bit n set => pin n has high slew rate by default. */
400
+ dc->vmsd = &vmstate_aspeed_sdhci;
641
+ DEFINE_PROP_UINT32("reset-osrc", NPCM7xxGPIOState, reset_osrc, 0),
401
+}
642
+ /* Bit n set => pin n has high drive strength by default. */
402
+
643
+ DEFINE_PROP_UINT32("reset-odsc", NPCM7xxGPIOState, reset_odsc, 0),
403
+static TypeInfo aspeed_sdhci_info = {
644
+ DEFINE_PROP_END_OF_LIST(),
404
+ .name = TYPE_ASPEED_SDHCI,
405
+ .parent = TYPE_SYS_BUS_DEVICE,
406
+ .instance_size = sizeof(AspeedSDHCIState),
407
+ .class_init = aspeed_sdhci_class_init,
408
+};
645
+};
409
+
646
+
410
+static void aspeed_sdhci_register_types(void)
647
+static void npcm7xx_gpio_class_init(ObjectClass *klass, void *data)
411
+{
648
+{
412
+ type_register_static(&aspeed_sdhci_info);
649
+ ResettableClass *reset = RESETTABLE_CLASS(klass);
413
+}
650
+ DeviceClass *dc = DEVICE_CLASS(klass);
414
+
651
+
415
+type_init(aspeed_sdhci_register_types)
652
+ QEMU_BUILD_BUG_ON(NPCM7XX_GPIO_REGS_END > NPCM7XX_GPIO_NR_REGS);
653
+
654
+ dc->desc = "NPCM7xx GPIO Controller";
655
+ dc->vmsd = &vmstate_npcm7xx_gpio;
656
+ reset->phases.enter = npcm7xx_gpio_enter_reset;
657
+ reset->phases.hold = npcm7xx_gpio_hold_reset;
658
+ device_class_set_props(dc, npcm7xx_gpio_properties);
659
+}
660
+
661
+static const TypeInfo npcm7xx_gpio_types[] = {
662
+ {
663
+ .name = TYPE_NPCM7XX_GPIO,
664
+ .parent = TYPE_SYS_BUS_DEVICE,
665
+ .instance_size = sizeof(NPCM7xxGPIOState),
666
+ .class_init = npcm7xx_gpio_class_init,
667
+ .instance_init = npcm7xx_gpio_init,
668
+ },
669
+};
670
+DEFINE_TYPES(npcm7xx_gpio_types);
671
diff --git a/tests/qtest/npcm7xx_gpio-test.c b/tests/qtest/npcm7xx_gpio-test.c
672
new file mode 100644
673
index XXXXXXX..XXXXXXX
674
--- /dev/null
675
+++ b/tests/qtest/npcm7xx_gpio-test.c
676
@@ -XXX,XX +XXX,XX @@
677
+/*
678
+ * QTest testcase for the Nuvoton NPCM7xx GPIO modules.
679
+ *
680
+ * Copyright 2020 Google LLC
681
+ *
682
+ * This program is free software; you can redistribute it and/or modify it
683
+ * under the terms of the GNU General Public License as published by the
684
+ * Free Software Foundation; either version 2 of the License, or
685
+ * (at your option) any later version.
686
+ *
687
+ * This program is distributed in the hope that it will be useful, but WITHOUT
688
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
689
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
690
+ * for more details.
691
+ */
692
+
693
+#include "qemu/osdep.h"
694
+#include "libqtest-single.h"
695
+
696
+#define NR_GPIO_DEVICES (8)
697
+#define GPIO(x) (0xf0010000 + (x) * 0x1000)
698
+#define GPIO_IRQ(x) (116 + (x))
699
+
700
+/* GPIO registers */
701
+#define GP_N_TLOCK1 0x00
702
+#define GP_N_DIN 0x04 /* Data IN */
703
+#define GP_N_POL 0x08 /* Polarity */
704
+#define GP_N_DOUT 0x0c /* Data OUT */
705
+#define GP_N_OE 0x10 /* Output Enable */
706
+#define GP_N_OTYP 0x14
707
+#define GP_N_MP 0x18
708
+#define GP_N_PU 0x1c /* Pull-up */
709
+#define GP_N_PD 0x20 /* Pull-down */
710
+#define GP_N_DBNC 0x24 /* Debounce */
711
+#define GP_N_EVTYP 0x28 /* Event Type */
712
+#define GP_N_EVBE 0x2c /* Event Both Edge */
713
+#define GP_N_OBL0 0x30
714
+#define GP_N_OBL1 0x34
715
+#define GP_N_OBL2 0x38
716
+#define GP_N_OBL3 0x3c
717
+#define GP_N_EVEN 0x40 /* Event Enable */
718
+#define GP_N_EVENS 0x44 /* Event Set (enable) */
719
+#define GP_N_EVENC 0x48 /* Event Clear (disable) */
720
+#define GP_N_EVST 0x4c /* Event Status */
721
+#define GP_N_SPLCK 0x50
722
+#define GP_N_MPLCK 0x54
723
+#define GP_N_IEM 0x58 /* Input Enable */
724
+#define GP_N_OSRC 0x5c
725
+#define GP_N_ODSC 0x60
726
+#define GP_N_DOS 0x68 /* Data OUT Set */
727
+#define GP_N_DOC 0x6c /* Data OUT Clear */
728
+#define GP_N_OES 0x70 /* Output Enable Set */
729
+#define GP_N_OEC 0x74 /* Output Enable Clear */
730
+#define GP_N_TLOCK2 0x7c
731
+
732
+static void gpio_unlock(int n)
733
+{
734
+ if (readl(GPIO(n) + GP_N_TLOCK1) != 0) {
735
+ writel(GPIO(n) + GP_N_TLOCK2, 0xc0de1248);
736
+ writel(GPIO(n) + GP_N_TLOCK1, 0xc0defa73);
737
+ }
738
+}
739
+
740
+/* Restore the GPIO controller to a sensible default state. */
741
+static void gpio_reset(int n)
742
+{
743
+ gpio_unlock(0);
744
+
745
+ writel(GPIO(n) + GP_N_EVEN, 0x00000000);
746
+ writel(GPIO(n) + GP_N_EVST, 0xffffffff);
747
+ writel(GPIO(n) + GP_N_POL, 0x00000000);
748
+ writel(GPIO(n) + GP_N_DOUT, 0x00000000);
749
+ writel(GPIO(n) + GP_N_OE, 0x00000000);
750
+ writel(GPIO(n) + GP_N_OTYP, 0x00000000);
751
+ writel(GPIO(n) + GP_N_PU, 0xffffffff);
752
+ writel(GPIO(n) + GP_N_PD, 0x00000000);
753
+ writel(GPIO(n) + GP_N_IEM, 0xffffffff);
754
+}
755
+
756
+static void test_dout_to_din(void)
757
+{
758
+ gpio_reset(0);
759
+
760
+ /* When output is enabled, DOUT should be reflected on DIN. */
761
+ writel(GPIO(0) + GP_N_OE, 0xffffffff);
762
+ /* PU and PD shouldn't have any impact on DIN. */
763
+ writel(GPIO(0) + GP_N_PU, 0xffff0000);
764
+ writel(GPIO(0) + GP_N_PD, 0x0000ffff);
765
+ writel(GPIO(0) + GP_N_DOUT, 0x12345678);
766
+ g_assert_cmphex(readl(GPIO(0) + GP_N_DOUT), ==, 0x12345678);
767
+ g_assert_cmphex(readl(GPIO(0) + GP_N_DIN), ==, 0x12345678);
768
+}
769
+
770
+static void test_pullup_pulldown(void)
771
+{
772
+ gpio_reset(0);
773
+
774
+ /*
775
+ * When output is disabled, and PD is the inverse of PU, PU should be
776
+ * reflected on DIN. If PD is not the inverse of PU, the state of DIN is
777
+ * undefined, so we don't test that.
778
+ */
779
+ writel(GPIO(0) + GP_N_OE, 0x00000000);
780
+ /* DOUT shouldn't have any impact on DIN. */
781
+ writel(GPIO(0) + GP_N_DOUT, 0xffff0000);
782
+ writel(GPIO(0) + GP_N_PU, 0x23456789);
783
+ writel(GPIO(0) + GP_N_PD, ~0x23456789U);
784
+ g_assert_cmphex(readl(GPIO(0) + GP_N_PU), ==, 0x23456789);
785
+ g_assert_cmphex(readl(GPIO(0) + GP_N_PD), ==, ~0x23456789U);
786
+ g_assert_cmphex(readl(GPIO(0) + GP_N_DIN), ==, 0x23456789);
787
+}
788
+
789
+static void test_output_enable(void)
790
+{
791
+ gpio_reset(0);
792
+
793
+ /*
794
+ * With all pins weakly pulled down, and DOUT all-ones, OE should be
795
+ * reflected on DIN.
796
+ */
797
+ writel(GPIO(0) + GP_N_DOUT, 0xffffffff);
798
+ writel(GPIO(0) + GP_N_PU, 0x00000000);
799
+ writel(GPIO(0) + GP_N_PD, 0xffffffff);
800
+ writel(GPIO(0) + GP_N_OE, 0x3456789a);
801
+ g_assert_cmphex(readl(GPIO(0) + GP_N_OE), ==, 0x3456789a);
802
+ g_assert_cmphex(readl(GPIO(0) + GP_N_DIN), ==, 0x3456789a);
803
+
804
+ writel(GPIO(0) + GP_N_OEC, 0x00030002);
805
+ g_assert_cmphex(readl(GPIO(0) + GP_N_OE), ==, 0x34547898);
806
+ g_assert_cmphex(readl(GPIO(0) + GP_N_DIN), ==, 0x34547898);
807
+
808
+ writel(GPIO(0) + GP_N_OES, 0x0000f001);
809
+ g_assert_cmphex(readl(GPIO(0) + GP_N_OE), ==, 0x3454f899);
810
+ g_assert_cmphex(readl(GPIO(0) + GP_N_DIN), ==, 0x3454f899);
811
+}
812
+
813
+static void test_open_drain(void)
814
+{
815
+ gpio_reset(0);
816
+
817
+ /*
818
+ * Upper half of DOUT drives a 1 only if the corresponding bit in OTYP is
819
+ * not set. If OTYP is set, DIN is determined by PU/PD. Lower half of
820
+ * DOUT always drives a 0 regardless of OTYP; PU/PD have no effect. When
821
+ * OE is 0, output is determined by PU/PD; OTYP has no effect.
822
+ */
823
+ writel(GPIO(0) + GP_N_OTYP, 0x456789ab);
824
+ writel(GPIO(0) + GP_N_OE, 0xf0f0f0f0);
825
+ writel(GPIO(0) + GP_N_DOUT, 0xffff0000);
826
+ writel(GPIO(0) + GP_N_PU, 0xff00ff00);
827
+ writel(GPIO(0) + GP_N_PD, 0x00ff00ff);
828
+ g_assert_cmphex(readl(GPIO(0) + GP_N_OTYP), ==, 0x456789ab);
829
+ g_assert_cmphex(readl(GPIO(0) + GP_N_DIN), ==, 0xff900f00);
830
+}
831
+
832
+static void test_polarity(void)
833
+{
834
+ gpio_reset(0);
835
+
836
+ /*
837
+ * In push-pull mode, DIN should reflect DOUT because the signal is
838
+ * inverted in both directions.
839
+ */
840
+ writel(GPIO(0) + GP_N_OTYP, 0x00000000);
841
+ writel(GPIO(0) + GP_N_OE, 0xffffffff);
842
+ writel(GPIO(0) + GP_N_DOUT, 0x56789abc);
843
+ writel(GPIO(0) + GP_N_POL, 0x6789abcd);
844
+ g_assert_cmphex(readl(GPIO(0) + GP_N_POL), ==, 0x6789abcd);
845
+ g_assert_cmphex(readl(GPIO(0) + GP_N_DIN), ==, 0x56789abc);
846
+
847
+ /*
848
+ * When turning off the drivers, DIN should reflect the inverse of the
849
+ * pulled-up lines.
850
+ */
851
+ writel(GPIO(0) + GP_N_OE, 0x00000000);
852
+ writel(GPIO(0) + GP_N_POL, 0xffffffff);
853
+ writel(GPIO(0) + GP_N_PU, 0x789abcde);
854
+ writel(GPIO(0) + GP_N_PD, ~0x789abcdeU);
855
+ g_assert_cmphex(readl(GPIO(0) + GP_N_DIN), ==, ~0x789abcdeU);
856
+
857
+ /*
858
+ * In open-drain mode, DOUT=1 will appear to drive the pin high (since DIN
859
+ * is inverted), while DOUT=0 will leave the pin floating.
860
+ */
861
+ writel(GPIO(0) + GP_N_OTYP, 0xffffffff);
862
+ writel(GPIO(0) + GP_N_OE, 0xffffffff);
863
+ writel(GPIO(0) + GP_N_PU, 0xffff0000);
864
+ writel(GPIO(0) + GP_N_PD, 0x0000ffff);
865
+ writel(GPIO(0) + GP_N_DOUT, 0xff00ff00);
866
+ g_assert_cmphex(readl(GPIO(0) + GP_N_DIN), ==, 0xff00ffff);
867
+}
868
+
869
+static void test_input_mask(void)
870
+{
871
+ gpio_reset(0);
872
+
873
+ /* IEM=0 forces the input to zero before polarity inversion. */
874
+ writel(GPIO(0) + GP_N_OE, 0xffffffff);
875
+ writel(GPIO(0) + GP_N_DOUT, 0xff00ff00);
876
+ writel(GPIO(0) + GP_N_POL, 0xffff0000);
877
+ writel(GPIO(0) + GP_N_IEM, 0x87654321);
878
+ g_assert_cmphex(readl(GPIO(0) + GP_N_DIN), ==, 0xff9a4300);
879
+}
880
+
881
+static void test_temp_lock(void)
882
+{
883
+ gpio_reset(0);
884
+
885
+ writel(GPIO(0) + GP_N_DOUT, 0x98765432);
886
+
887
+ /* Make sure we're unlocked initially. */
888
+ g_assert_cmphex(readl(GPIO(0) + GP_N_TLOCK1), ==, 0);
889
+ /* Writing any value to TLOCK1 will lock. */
890
+ writel(GPIO(0) + GP_N_TLOCK1, 0);
891
+ g_assert_cmphex(readl(GPIO(0) + GP_N_TLOCK1), ==, 1);
892
+ writel(GPIO(0) + GP_N_DOUT, 0xa9876543);
893
+ g_assert_cmphex(readl(GPIO(0) + GP_N_DOUT), ==, 0x98765432);
894
+ /* Now, try to unlock. */
895
+ gpio_unlock(0);
896
+ g_assert_cmphex(readl(GPIO(0) + GP_N_TLOCK1), ==, 0);
897
+ writel(GPIO(0) + GP_N_DOUT, 0xa9876543);
898
+ g_assert_cmphex(readl(GPIO(0) + GP_N_DOUT), ==, 0xa9876543);
899
+
900
+ /* Try it again, but write TLOCK2 to lock. */
901
+ writel(GPIO(0) + GP_N_TLOCK2, 0);
902
+ g_assert_cmphex(readl(GPIO(0) + GP_N_TLOCK1), ==, 1);
903
+ writel(GPIO(0) + GP_N_DOUT, 0x98765432);
904
+ g_assert_cmphex(readl(GPIO(0) + GP_N_DOUT), ==, 0xa9876543);
905
+ /* Now, try to unlock. */
906
+ gpio_unlock(0);
907
+ g_assert_cmphex(readl(GPIO(0) + GP_N_TLOCK1), ==, 0);
908
+ writel(GPIO(0) + GP_N_DOUT, 0x98765432);
909
+ g_assert_cmphex(readl(GPIO(0) + GP_N_DOUT), ==, 0x98765432);
910
+}
911
+
912
+static void test_events_level(void)
913
+{
914
+ gpio_reset(0);
915
+
916
+ writel(GPIO(0) + GP_N_EVTYP, 0x00000000);
917
+ writel(GPIO(0) + GP_N_DOUT, 0xba987654);
918
+ writel(GPIO(0) + GP_N_OE, 0xffffffff);
919
+ writel(GPIO(0) + GP_N_EVST, 0xffffffff);
920
+
921
+ g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0xba987654);
922
+ g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0)));
923
+ writel(GPIO(0) + GP_N_DOUT, 0x00000000);
924
+ g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0xba987654);
925
+ g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0)));
926
+ writel(GPIO(0) + GP_N_EVST, 0x00007654);
927
+ g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0xba980000);
928
+ g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0)));
929
+ writel(GPIO(0) + GP_N_EVST, 0xba980000);
930
+ g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0x00000000);
931
+ g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0)));
932
+}
933
+
934
+static void test_events_rising_edge(void)
935
+{
936
+ gpio_reset(0);
937
+
938
+ writel(GPIO(0) + GP_N_EVTYP, 0xffffffff);
939
+ writel(GPIO(0) + GP_N_EVBE, 0x00000000);
940
+ writel(GPIO(0) + GP_N_DOUT, 0xffff0000);
941
+ writel(GPIO(0) + GP_N_OE, 0xffffffff);
942
+ writel(GPIO(0) + GP_N_EVST, 0xffffffff);
943
+
944
+ g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0x00000000);
945
+ g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0)));
946
+ writel(GPIO(0) + GP_N_DOUT, 0xff00ff00);
947
+ g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0x0000ff00);
948
+ g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0)));
949
+ writel(GPIO(0) + GP_N_DOUT, 0x00ff0000);
950
+ g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0x00ffff00);
951
+ g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0)));
952
+ writel(GPIO(0) + GP_N_EVST, 0x0000f000);
953
+ g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0x00ff0f00);
954
+ g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0)));
955
+ writel(GPIO(0) + GP_N_EVST, 0x00ff0f00);
956
+ g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0x00000000);
957
+ g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0)));
958
+}
959
+
960
+static void test_events_both_edges(void)
961
+{
962
+ gpio_reset(0);
963
+
964
+ writel(GPIO(0) + GP_N_EVTYP, 0xffffffff);
965
+ writel(GPIO(0) + GP_N_EVBE, 0xffffffff);
966
+ writel(GPIO(0) + GP_N_DOUT, 0xffff0000);
967
+ writel(GPIO(0) + GP_N_OE, 0xffffffff);
968
+ writel(GPIO(0) + GP_N_EVST, 0xffffffff);
969
+
970
+ g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0x00000000);
971
+ g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0)));
972
+ writel(GPIO(0) + GP_N_DOUT, 0xff00ff00);
973
+ g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0x00ffff00);
974
+ g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0)));
975
+ writel(GPIO(0) + GP_N_DOUT, 0xef00ff08);
976
+ g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0x10ffff08);
977
+ g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0)));
978
+ writel(GPIO(0) + GP_N_EVST, 0x0000f000);
979
+ g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0x10ff0f08);
980
+ g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0)));
981
+ writel(GPIO(0) + GP_N_EVST, 0x10ff0f08);
982
+ g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0x00000000);
983
+ g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0)));
984
+}
985
+
986
+static void test_gpion_irq(gconstpointer test_data)
987
+{
988
+ intptr_t n = (intptr_t)test_data;
989
+
990
+ gpio_reset(n);
991
+
992
+ writel(GPIO(n) + GP_N_EVTYP, 0x00000000);
993
+ writel(GPIO(n) + GP_N_DOUT, 0x00000000);
994
+ writel(GPIO(n) + GP_N_OE, 0xffffffff);
995
+ writel(GPIO(n) + GP_N_EVST, 0xffffffff);
996
+ writel(GPIO(n) + GP_N_EVEN, 0x00000000);
997
+
998
+ /* Trigger an event; interrupts are masked. */
999
+ g_assert_cmphex(readl(GPIO(n) + GP_N_EVST), ==, 0x00000000);
1000
+ g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(n)));
1001
+ writel(GPIO(n) + GP_N_DOS, 0x00008000);
1002
+ g_assert_cmphex(readl(GPIO(n) + GP_N_EVST), ==, 0x00008000);
1003
+ g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(n)));
1004
+
1005
+ /* Unmask all event interrupts; verify that the interrupt fired. */
1006
+ writel(GPIO(n) + GP_N_EVEN, 0xffffffff);
1007
+ g_assert_true(qtest_get_irq(global_qtest, GPIO_IRQ(n)));
1008
+
1009
+ /* Clear the current bit, set a new bit, irq stays asserted. */
1010
+ writel(GPIO(n) + GP_N_DOC, 0x00008000);
1011
+ g_assert_true(qtest_get_irq(global_qtest, GPIO_IRQ(n)));
1012
+ writel(GPIO(n) + GP_N_DOS, 0x00000200);
1013
+ g_assert_true(qtest_get_irq(global_qtest, GPIO_IRQ(n)));
1014
+ writel(GPIO(n) + GP_N_EVST, 0x00008000);
1015
+ g_assert_true(qtest_get_irq(global_qtest, GPIO_IRQ(n)));
1016
+
1017
+ /* Mask/unmask the event that's currently active. */
1018
+ writel(GPIO(n) + GP_N_EVENC, 0x00000200);
1019
+ g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(n)));
1020
+ writel(GPIO(n) + GP_N_EVENS, 0x00000200);
1021
+ g_assert_true(qtest_get_irq(global_qtest, GPIO_IRQ(n)));
1022
+
1023
+ /* Clear the input and the status bit, irq is deasserted. */
1024
+ writel(GPIO(n) + GP_N_DOC, 0x00000200);
1025
+ g_assert_true(qtest_get_irq(global_qtest, GPIO_IRQ(n)));
1026
+ writel(GPIO(n) + GP_N_EVST, 0x00000200);
1027
+ g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(n)));
1028
+}
1029
+
1030
+int main(int argc, char **argv)
1031
+{
1032
+ int ret;
1033
+ int i;
1034
+
1035
+ g_test_init(&argc, &argv, NULL);
1036
+ g_test_set_nonfatal_assertions();
1037
+
1038
+ qtest_add_func("/npcm7xx_gpio/dout_to_din", test_dout_to_din);
1039
+ qtest_add_func("/npcm7xx_gpio/pullup_pulldown", test_pullup_pulldown);
1040
+ qtest_add_func("/npcm7xx_gpio/output_enable", test_output_enable);
1041
+ qtest_add_func("/npcm7xx_gpio/open_drain", test_open_drain);
1042
+ qtest_add_func("/npcm7xx_gpio/polarity", test_polarity);
1043
+ qtest_add_func("/npcm7xx_gpio/input_mask", test_input_mask);
1044
+ qtest_add_func("/npcm7xx_gpio/temp_lock", test_temp_lock);
1045
+ qtest_add_func("/npcm7xx_gpio/events/level", test_events_level);
1046
+ qtest_add_func("/npcm7xx_gpio/events/rising_edge", test_events_rising_edge);
1047
+ qtest_add_func("/npcm7xx_gpio/events/both_edges", test_events_both_edges);
1048
+
1049
+ for (i = 0; i < NR_GPIO_DEVICES; i++) {
1050
+ g_autofree char *test_name =
1051
+ g_strdup_printf("/npcm7xx_gpio/gpio[%d]/irq", i);
1052
+ qtest_add_data_func(test_name, (void *)(intptr_t)i, test_gpion_irq);
1053
+ }
1054
+
1055
+ qtest_start("-machine npcm750-evb");
1056
+ qtest_irq_intercept_in(global_qtest, "/machine/soc/a9mpcore/gic");
1057
+ ret = g_test_run();
1058
+ qtest_end();
1059
+
1060
+ return ret;
1061
+}
1062
diff --git a/hw/gpio/meson.build b/hw/gpio/meson.build
1063
index XXXXXXX..XXXXXXX 100644
1064
--- a/hw/gpio/meson.build
1065
+++ b/hw/gpio/meson.build
1066
@@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_PUV3', if_true: files('puv3_gpio.c'))
1067
softmmu_ss.add(when: 'CONFIG_ZAURUS', if_true: files('zaurus.c'))
1068
1069
softmmu_ss.add(when: 'CONFIG_IMX', if_true: files('imx_gpio.c'))
1070
+softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_gpio.c'))
1071
softmmu_ss.add(when: 'CONFIG_NRF51_SOC', if_true: files('nrf51_gpio.c'))
1072
softmmu_ss.add(when: 'CONFIG_OMAP', if_true: files('omap_gpio.c'))
1073
softmmu_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2835_gpio.c'))
1074
diff --git a/hw/gpio/trace-events b/hw/gpio/trace-events
1075
index XXXXXXX..XXXXXXX 100644
1076
--- a/hw/gpio/trace-events
1077
+++ b/hw/gpio/trace-events
1078
@@ -XXX,XX +XXX,XX @@
1079
# See docs/devel/tracing.txt for syntax documentation.
1080
1081
+# npcm7xx_gpio.c
1082
+npcm7xx_gpio_read(const char *id, uint64_t offset, uint64_t value) " %s offset: 0x%04" PRIx64 " value 0x%08" PRIx64
1083
+npcm7xx_gpio_write(const char *id, uint64_t offset, uint64_t value) "%s offset: 0x%04" PRIx64 " value 0x%08" PRIx64
1084
+npcm7xx_gpio_set_input(const char *id, int32_t line, int32_t level) "%s line: %" PRIi32 " level: %" PRIi32
1085
+npcm7xx_gpio_set_output(const char *id, int32_t line, int32_t level) "%s line: %" PRIi32 " level: %" PRIi32
1086
+npcm7xx_gpio_update_events(const char *id, uint32_t evst, uint32_t even) "%s evst: 0x%08" PRIx32 " even: 0x%08" PRIx32
1087
+
1088
# nrf51_gpio.c
1089
nrf51_gpio_read(uint64_t offset, uint64_t r) "offset 0x%" PRIx64 " value 0x%" PRIx64
1090
nrf51_gpio_write(uint64_t offset, uint64_t value) "offset 0x%" PRIx64 " value 0x%" PRIx64
1091
diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
1092
index XXXXXXX..XXXXXXX 100644
1093
--- a/tests/qtest/meson.build
1094
+++ b/tests/qtest/meson.build
1095
@@ -XXX,XX +XXX,XX @@ qtests_sparc64 = \
1096
['prom-env-test', 'boot-serial-test']
1097
1098
qtests_npcm7xx = \
1099
- ['npcm7xx_rng-test',
1100
+ ['npcm7xx_gpio-test',
1101
+ 'npcm7xx_rng-test',
1102
'npcm7xx_timer-test',
1103
'npcm7xx_watchdog_timer-test']
1104
qtests_arm = \
416
--
1105
--
417
2.20.1
1106
2.20.1
418
1107
419
1108
diff view generated by jsdifflib
1
From: Cédric Le Goater <clg@kaod.org>
1
From: Zenghui Yu <yuzenghui@huawei.com>
2
2
3
Signed-off-by: Cédric Le Goater <clg@kaod.org>
3
Ensure the vSMMUv3 will be restored before all PCIe devices so that DMA
4
Reviewed-by: Joel Stanley <joel@jms.id.au>
4
translation can work properly during migration.
5
Message-id: 20190925143248.10000-20-clg@kaod.org
5
6
Signed-off-by: Zenghui Yu <yuzenghui@huawei.com>
7
Message-id: 20201019091508.197-1-yuzenghui@huawei.com
8
Acked-by: Eric Auger <eric.auger@redhat.com>
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
---
10
---
8
hw/block/m25p80.c | 1 +
11
hw/arm/smmuv3.c | 1 +
9
1 file changed, 1 insertion(+)
12
1 file changed, 1 insertion(+)
10
13
11
diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c
14
diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c
12
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
13
--- a/hw/block/m25p80.c
16
--- a/hw/arm/smmuv3.c
14
+++ b/hw/block/m25p80.c
17
+++ b/hw/arm/smmuv3.c
15
@@ -XXX,XX +XXX,XX @@ static const FlashPartInfo known_devices[] = {
18
@@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_smmuv3 = {
16
{ INFO("w25q80", 0xef5014, 0, 64 << 10, 16, ER_4K) },
19
.name = "smmuv3",
17
{ INFO("w25q80bl", 0xef4014, 0, 64 << 10, 16, ER_4K) },
20
.version_id = 1,
18
{ INFO("w25q256", 0xef4019, 0, 64 << 10, 512, ER_4K) },
21
.minimum_version_id = 1,
19
+ { INFO("w25q512jv", 0xef4020, 0, 64 << 10, 1024, ER_4K) },
22
+ .priority = MIG_PRI_IOMMU,
20
};
23
.fields = (VMStateField[]) {
21
24
VMSTATE_UINT32(features, SMMUv3State),
22
typedef enum {
25
VMSTATE_UINT8(sid_size, SMMUv3State),
23
--
26
--
24
2.20.1
27
2.20.1
25
28
26
29
diff view generated by jsdifflib
1
From: Cédric Le Goater <clg@kaod.org>
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
2
2
3
It cleanups the current models for the Aspeed AST2400 and AST2500 SoCs
3
No code out of bcm2836.c uses (or requires) the BCM283XInfo
4
and prepares ground for future SoCs.
4
declarations. Move it locally to the C source file.
5
5
6
Signed-off-by: Cédric Le Goater <clg@kaod.org>
6
Reviewed-by: Luc Michel <luc.michel@greensocs.com>
7
Reviewed-by: Joel Stanley <joel@jms.id.au>
7
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
8
Message-id: 20190925143248.10000-11-clg@kaod.org
8
Message-id: 20201024170127.3592182-2-f4bug@amsat.org
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
---
10
---
11
include/hw/watchdog/wdt_aspeed.h | 18 ++++-
11
include/hw/arm/bcm2836.h | 8 --------
12
hw/arm/aspeed_soc.c | 9 ++-
12
hw/arm/bcm2836.c | 14 ++++++++++++++
13
hw/watchdog/wdt_aspeed.c | 122 ++++++++++++++++---------------
13
2 files changed, 14 insertions(+), 8 deletions(-)
14
3 files changed, 86 insertions(+), 63 deletions(-)
15
14
16
diff --git a/include/hw/watchdog/wdt_aspeed.h b/include/hw/watchdog/wdt_aspeed.h
15
diff --git a/include/hw/arm/bcm2836.h b/include/hw/arm/bcm2836.h
17
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
18
--- a/include/hw/watchdog/wdt_aspeed.h
17
--- a/include/hw/arm/bcm2836.h
19
+++ b/include/hw/watchdog/wdt_aspeed.h
18
+++ b/include/hw/arm/bcm2836.h
20
@@ -XXX,XX +XXX,XX @@
19
@@ -XXX,XX +XXX,XX @@ struct BCM283XState {
21
#define TYPE_ASPEED_WDT "aspeed.wdt"
20
BCM2835PeripheralState peripherals;
22
#define ASPEED_WDT(obj) \
21
};
23
OBJECT_CHECK(AspeedWDTState, (obj), TYPE_ASPEED_WDT)
22
24
+#define TYPE_ASPEED_2400_WDT TYPE_ASPEED_WDT "-ast2400"
23
-typedef struct BCM283XInfo BCM283XInfo;
25
+#define TYPE_ASPEED_2500_WDT TYPE_ASPEED_WDT "-ast2500"
26
27
#define ASPEED_WDT_REGS_MAX (0x20 / 4)
28
29
@@ -XXX,XX +XXX,XX @@ typedef struct AspeedWDTState {
30
31
AspeedSCUState *scu;
32
uint32_t pclk_freq;
33
- uint32_t silicon_rev;
34
- uint32_t ext_pulse_width_mask;
35
} AspeedWDTState;
36
37
+#define ASPEED_WDT_CLASS(klass) \
38
+ OBJECT_CLASS_CHECK(AspeedWDTClass, (klass), TYPE_ASPEED_WDT)
39
+#define ASPEED_WDT_GET_CLASS(obj) \
40
+ OBJECT_GET_CLASS(AspeedWDTClass, (obj), TYPE_ASPEED_WDT)
41
+
42
+typedef struct AspeedWDTClass {
43
+ SysBusDeviceClass parent_class;
44
+
45
+ uint32_t offset;
46
+ uint32_t ext_pulse_width_mask;
47
+ uint32_t reset_ctrl_reg;
48
+ void (*reset_pulse)(AspeedWDTState *s, uint32_t property);
49
+} AspeedWDTClass;
50
+
51
#endif /* WDT_ASPEED_H */
52
diff --git a/hw/arm/aspeed_soc.c b/hw/arm/aspeed_soc.c
53
index XXXXXXX..XXXXXXX 100644
54
--- a/hw/arm/aspeed_soc.c
55
+++ b/hw/arm/aspeed_soc.c
56
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_init(Object *obj)
57
"max-ram-size", &error_abort);
58
59
for (i = 0; i < sc->info->wdts_num; i++) {
60
+ snprintf(typename, sizeof(typename), "aspeed.wdt-%s", socname);
61
sysbus_init_child_obj(obj, "wdt[*]", OBJECT(&s->wdt[i]),
62
- sizeof(s->wdt[i]), TYPE_ASPEED_WDT);
63
- qdev_prop_set_uint32(DEVICE(&s->wdt[i]), "silicon-rev",
64
- sc->info->silicon_rev);
65
+ sizeof(s->wdt[i]), typename);
66
object_property_add_const_link(OBJECT(&s->wdt[i]), "scu",
67
OBJECT(&s->scu), &error_abort);
68
}
69
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
70
71
/* Watch dog */
72
for (i = 0; i < sc->info->wdts_num; i++) {
73
+ AspeedWDTClass *awc = ASPEED_WDT_GET_CLASS(&s->wdt[i]);
74
+
75
object_property_set_bool(OBJECT(&s->wdt[i]), true, "realized", &err);
76
if (err) {
77
error_propagate(errp, err);
78
return;
79
}
80
sysbus_mmio_map(SYS_BUS_DEVICE(&s->wdt[i]), 0,
81
- sc->info->memmap[ASPEED_WDT] + i * 0x20);
82
+ sc->info->memmap[ASPEED_WDT] + i * awc->offset);
83
}
84
85
/* Net */
86
diff --git a/hw/watchdog/wdt_aspeed.c b/hw/watchdog/wdt_aspeed.c
87
index XXXXXXX..XXXXXXX 100644
88
--- a/hw/watchdog/wdt_aspeed.c
89
+++ b/hw/watchdog/wdt_aspeed.c
90
@@ -XXX,XX +XXX,XX @@ static bool aspeed_wdt_is_enabled(const AspeedWDTState *s)
91
return s->regs[WDT_CTRL] & WDT_CTRL_ENABLE;
92
}
93
94
-static bool is_ast2500(const AspeedWDTState *s)
95
-{
96
- switch (s->silicon_rev) {
97
- case AST2500_A0_SILICON_REV:
98
- case AST2500_A1_SILICON_REV:
99
- return true;
100
- case AST2400_A0_SILICON_REV:
101
- case AST2400_A1_SILICON_REV:
102
- default:
103
- break;
104
- }
105
-
24
-
106
- return false;
25
-struct BCM283XClass {
107
-}
26
- DeviceClass parent_class;
108
-
27
- const BCM283XInfo *info;
109
static uint64_t aspeed_wdt_read(void *opaque, hwaddr offset, unsigned size)
110
{
111
AspeedWDTState *s = ASPEED_WDT(opaque);
112
@@ -XXX,XX +XXX,XX @@ static void aspeed_wdt_write(void *opaque, hwaddr offset, uint64_t data,
113
unsigned size)
114
{
115
AspeedWDTState *s = ASPEED_WDT(opaque);
116
+ AspeedWDTClass *awc = ASPEED_WDT_GET_CLASS(s);
117
bool enable = data & WDT_CTRL_ENABLE;
118
119
offset >>= 2;
120
@@ -XXX,XX +XXX,XX @@ static void aspeed_wdt_write(void *opaque, hwaddr offset, uint64_t data,
121
}
122
break;
123
case WDT_RESET_WIDTH:
124
- {
125
- uint32_t property = data & WDT_POLARITY_MASK;
126
-
127
- if (property && is_ast2500(s)) {
128
- if (property == WDT_ACTIVE_HIGH_MAGIC) {
129
- s->regs[WDT_RESET_WIDTH] |= WDT_RESET_WIDTH_ACTIVE_HIGH;
130
- } else if (property == WDT_ACTIVE_LOW_MAGIC) {
131
- s->regs[WDT_RESET_WIDTH] &= ~WDT_RESET_WIDTH_ACTIVE_HIGH;
132
- } else if (property == WDT_PUSH_PULL_MAGIC) {
133
- s->regs[WDT_RESET_WIDTH] |= WDT_RESET_WIDTH_PUSH_PULL;
134
- } else if (property == WDT_OPEN_DRAIN_MAGIC) {
135
- s->regs[WDT_RESET_WIDTH] &= ~WDT_RESET_WIDTH_PUSH_PULL;
136
- }
137
+ if (awc->reset_pulse) {
138
+ awc->reset_pulse(s, data & WDT_POLARITY_MASK);
139
}
140
- s->regs[WDT_RESET_WIDTH] &= ~s->ext_pulse_width_mask;
141
- s->regs[WDT_RESET_WIDTH] |= data & s->ext_pulse_width_mask;
142
+ s->regs[WDT_RESET_WIDTH] &= ~awc->ext_pulse_width_mask;
143
+ s->regs[WDT_RESET_WIDTH] |= data & awc->ext_pulse_width_mask;
144
break;
145
- }
146
+
147
case WDT_TIMEOUT_STATUS:
148
case WDT_TIMEOUT_CLEAR:
149
qemu_log_mask(LOG_UNIMP,
150
@@ -XXX,XX +XXX,XX @@ static void aspeed_wdt_reset(DeviceState *dev)
151
static void aspeed_wdt_timer_expired(void *dev)
152
{
153
AspeedWDTState *s = ASPEED_WDT(dev);
154
+ uint32_t reset_ctrl_reg = ASPEED_WDT_GET_CLASS(s)->reset_ctrl_reg;
155
156
/* Do not reset on SDRAM controller reset */
157
- if (s->scu->regs[SCU_RESET_CONTROL1] & SCU_RESET_SDRAM) {
158
+ if (s->scu->regs[reset_ctrl_reg] & SCU_RESET_SDRAM) {
159
timer_del(s->timer);
160
s->regs[WDT_CTRL] = 0;
161
return;
162
@@ -XXX,XX +XXX,XX @@ static void aspeed_wdt_realize(DeviceState *dev, Error **errp)
163
}
164
s->scu = ASPEED_SCU(obj);
165
166
- if (!is_supported_silicon_rev(s->silicon_rev)) {
167
- error_setg(errp, "Unknown silicon revision: 0x%" PRIx32,
168
- s->silicon_rev);
169
- return;
170
- }
171
-
172
- switch (s->silicon_rev) {
173
- case AST2400_A0_SILICON_REV:
174
- case AST2400_A1_SILICON_REV:
175
- s->ext_pulse_width_mask = 0xff;
176
- break;
177
- case AST2500_A0_SILICON_REV:
178
- case AST2500_A1_SILICON_REV:
179
- s->ext_pulse_width_mask = 0xfffff;
180
- break;
181
- default:
182
- g_assert_not_reached();
183
- }
184
-
185
s->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, aspeed_wdt_timer_expired, dev);
186
187
/* FIXME: This setting should be derived from the SCU hw strapping
188
@@ -XXX,XX +XXX,XX @@ static void aspeed_wdt_realize(DeviceState *dev, Error **errp)
189
sysbus_init_mmio(sbd, &s->iomem);
190
}
191
192
-static Property aspeed_wdt_properties[] = {
193
- DEFINE_PROP_UINT32("silicon-rev", AspeedWDTState, silicon_rev, 0),
194
- DEFINE_PROP_END_OF_LIST(),
195
-};
28
-};
196
-
29
-
197
static void aspeed_wdt_class_init(ObjectClass *klass, void *data)
30
-
198
{
31
#endif /* BCM2836_H */
199
DeviceClass *dc = DEVICE_CLASS(klass);
32
diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c
200
33
index XXXXXXX..XXXXXXX 100644
201
+ dc->desc = "ASPEED Watchdog Controller";
34
--- a/hw/arm/bcm2836.c
202
dc->realize = aspeed_wdt_realize;
35
+++ b/hw/arm/bcm2836.c
203
dc->reset = aspeed_wdt_reset;
36
@@ -XXX,XX +XXX,XX @@
204
set_bit(DEVICE_CATEGORY_MISC, dc->categories);
37
#include "hw/arm/raspi_platform.h"
205
dc->vmsd = &vmstate_aspeed_wdt;
38
#include "hw/sysbus.h"
206
- dc->props = aspeed_wdt_properties;
39
207
}
40
+typedef struct BCM283XInfo BCM283XInfo;
208
209
static const TypeInfo aspeed_wdt_info = {
210
@@ -XXX,XX +XXX,XX @@ static const TypeInfo aspeed_wdt_info = {
211
.name = TYPE_ASPEED_WDT,
212
.instance_size = sizeof(AspeedWDTState),
213
.class_init = aspeed_wdt_class_init,
214
+ .class_size = sizeof(AspeedWDTClass),
215
+ .abstract = true,
216
+};
217
+
41
+
218
+static void aspeed_2400_wdt_class_init(ObjectClass *klass, void *data)
42
+typedef struct BCM283XClass {
219
+{
43
+ /*< private >*/
220
+ DeviceClass *dc = DEVICE_CLASS(klass);
44
+ DeviceClass parent_class;
221
+ AspeedWDTClass *awc = ASPEED_WDT_CLASS(klass);
45
+ /*< public >*/
46
+ const BCM283XInfo *info;
47
+} BCM283XClass;
222
+
48
+
223
+ dc->desc = "ASPEED 2400 Watchdog Controller";
49
struct BCM283XInfo {
224
+ awc->offset = 0x20;
50
const char *name;
225
+ awc->ext_pulse_width_mask = 0xff;
51
const char *cpu_type;
226
+ awc->reset_ctrl_reg = SCU_RESET_CONTROL1;
52
@@ -XXX,XX +XXX,XX @@ struct BCM283XInfo {
227
+}
53
int clusterid;
54
};
55
56
+#define BCM283X_CLASS(klass) \
57
+ OBJECT_CLASS_CHECK(BCM283XClass, (klass), TYPE_BCM283X)
58
+#define BCM283X_GET_CLASS(obj) \
59
+ OBJECT_GET_CLASS(BCM283XClass, (obj), TYPE_BCM283X)
228
+
60
+
229
+static const TypeInfo aspeed_2400_wdt_info = {
61
static const BCM283XInfo bcm283x_socs[] = {
230
+ .name = TYPE_ASPEED_2400_WDT,
62
{
231
+ .parent = TYPE_ASPEED_WDT,
63
.name = TYPE_BCM2836,
232
+ .instance_size = sizeof(AspeedWDTState),
233
+ .class_init = aspeed_2400_wdt_class_init,
234
+};
235
+
236
+static void aspeed_2500_wdt_reset_pulse(AspeedWDTState *s, uint32_t property)
237
+{
238
+ if (property) {
239
+ if (property == WDT_ACTIVE_HIGH_MAGIC) {
240
+ s->regs[WDT_RESET_WIDTH] |= WDT_RESET_WIDTH_ACTIVE_HIGH;
241
+ } else if (property == WDT_ACTIVE_LOW_MAGIC) {
242
+ s->regs[WDT_RESET_WIDTH] &= ~WDT_RESET_WIDTH_ACTIVE_HIGH;
243
+ } else if (property == WDT_PUSH_PULL_MAGIC) {
244
+ s->regs[WDT_RESET_WIDTH] |= WDT_RESET_WIDTH_PUSH_PULL;
245
+ } else if (property == WDT_OPEN_DRAIN_MAGIC) {
246
+ s->regs[WDT_RESET_WIDTH] &= ~WDT_RESET_WIDTH_PUSH_PULL;
247
+ }
248
+ }
249
+}
250
+
251
+static void aspeed_2500_wdt_class_init(ObjectClass *klass, void *data)
252
+{
253
+ DeviceClass *dc = DEVICE_CLASS(klass);
254
+ AspeedWDTClass *awc = ASPEED_WDT_CLASS(klass);
255
+
256
+ dc->desc = "ASPEED 2500 Watchdog Controller";
257
+ awc->offset = 0x20;
258
+ awc->ext_pulse_width_mask = 0xfffff;
259
+ awc->reset_ctrl_reg = SCU_RESET_CONTROL1;
260
+ awc->reset_pulse = aspeed_2500_wdt_reset_pulse;
261
+}
262
+
263
+static const TypeInfo aspeed_2500_wdt_info = {
264
+ .name = TYPE_ASPEED_2500_WDT,
265
+ .parent = TYPE_ASPEED_WDT,
266
+ .instance_size = sizeof(AspeedWDTState),
267
+ .class_init = aspeed_2500_wdt_class_init,
268
};
269
270
static void wdt_aspeed_register_types(void)
271
{
272
watchdog_add_model(&model);
273
type_register_static(&aspeed_wdt_info);
274
+ type_register_static(&aspeed_2400_wdt_info);
275
+ type_register_static(&aspeed_2500_wdt_info);
276
}
277
278
type_init(wdt_aspeed_register_types)
279
--
64
--
280
2.20.1
65
2.20.1
281
66
282
67
diff view generated by jsdifflib
1
From: Cédric Le Goater <clg@kaod.org>
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
2
2
3
It prepares ground for the AST2600.
3
Remove usage of TypeInfo::class_data. Instead fill the fields in
4
4
the corresponding class_init().
5
Signed-off-by: Cédric Le Goater <clg@kaod.org>
5
6
Reviewed-by: Joel Stanley <joel@jms.id.au>
6
So far all children use the same values for almost all fields,
7
Message-id: 20190925143248.10000-18-clg@kaod.org
7
but we are going to add the BCM2711/BCM2838 SoC for the raspi4
8
machine which use different fields.
9
10
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
11
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
12
Message-id: 20201024170127.3592182-3-f4bug@amsat.org
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
---
14
---
10
include/hw/arm/aspeed_soc.h | 9 +--
15
hw/arm/bcm2836.c | 108 ++++++++++++++++++++++-------------------------
11
hw/arm/aspeed.c | 4 +-
16
1 file changed, 51 insertions(+), 57 deletions(-)
12
hw/arm/aspeed_soc.c | 148 +++++++++++++++++++-----------------
17
13
3 files changed, 84 insertions(+), 77 deletions(-)
18
diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c
14
15
diff --git a/include/hw/arm/aspeed_soc.h b/include/hw/arm/aspeed_soc.h
16
index XXXXXXX..XXXXXXX 100644
19
index XXXXXXX..XXXXXXX 100644
17
--- a/include/hw/arm/aspeed_soc.h
20
--- a/hw/arm/bcm2836.c
18
+++ b/include/hw/arm/aspeed_soc.h
21
+++ b/hw/arm/bcm2836.c
19
@@ -XXX,XX +XXX,XX @@ typedef struct AspeedSoCState {
22
@@ -XXX,XX +XXX,XX @@
20
#define TYPE_ASPEED_SOC "aspeed-soc"
23
#include "hw/arm/raspi_platform.h"
21
#define ASPEED_SOC(obj) OBJECT_CHECK(AspeedSoCState, (obj), TYPE_ASPEED_SOC)
24
#include "hw/sysbus.h"
22
25
23
-typedef struct AspeedSoCInfo {
26
-typedef struct BCM283XInfo BCM283XInfo;
24
+typedef struct AspeedSoCClass {
27
-
25
+ DeviceClass parent_class;
28
typedef struct BCM283XClass {
26
+
29
/*< private >*/
30
DeviceClass parent_class;
31
/*< public >*/
32
- const BCM283XInfo *info;
33
-} BCM283XClass;
34
-
35
-struct BCM283XInfo {
27
const char *name;
36
const char *name;
28
const char *cpu_type;
37
const char *cpu_type;
29
uint32_t silicon_rev;
38
hwaddr peri_base; /* Peripheral base address seen by the CPU */
30
@@ -XXX,XX +XXX,XX @@ typedef struct AspeedSoCInfo {
39
hwaddr ctrl_base; /* Interrupt controller and mailboxes etc. */
31
const int *irqmap;
40
int clusterid;
32
const hwaddr *memmap;
41
-};
33
uint32_t num_cpus;
42
+} BCM283XClass;
34
-} AspeedSoCInfo;
43
35
-
44
#define BCM283X_CLASS(klass) \
36
-typedef struct AspeedSoCClass {
45
OBJECT_CLASS_CHECK(BCM283XClass, (klass), TYPE_BCM283X)
37
- DeviceClass parent_class;
46
#define BCM283X_GET_CLASS(obj) \
38
- AspeedSoCInfo *info;
47
OBJECT_GET_CLASS(BCM283XClass, (obj), TYPE_BCM283X)
39
} AspeedSoCClass;
48
40
49
-static const BCM283XInfo bcm283x_socs[] = {
41
#define ASPEED_SOC_CLASS(klass) \
42
diff --git a/hw/arm/aspeed.c b/hw/arm/aspeed.c
43
index XXXXXXX..XXXXXXX 100644
44
--- a/hw/arm/aspeed.c
45
+++ b/hw/arm/aspeed.c
46
@@ -XXX,XX +XXX,XX @@ static void aspeed_board_init(MachineState *machine,
47
memory_region_allocate_system_memory(&bmc->ram, NULL, "ram", ram_size);
48
memory_region_add_subregion(&bmc->ram_container, 0, &bmc->ram);
49
memory_region_add_subregion(get_system_memory(),
50
- sc->info->memmap[ASPEED_SDRAM],
51
+ sc->memmap[ASPEED_SDRAM],
52
&bmc->ram_container);
53
54
max_ram_size = object_property_get_uint(OBJECT(&bmc->soc), "max-ram-size",
55
@@ -XXX,XX +XXX,XX @@ static void aspeed_board_init(MachineState *machine,
56
}
57
58
aspeed_board_binfo.ram_size = ram_size;
59
- aspeed_board_binfo.loader_start = sc->info->memmap[ASPEED_SDRAM];
60
+ aspeed_board_binfo.loader_start = sc->memmap[ASPEED_SDRAM];
61
aspeed_board_binfo.nb_cpus = bmc->soc.num_cpus;
62
63
if (cfg->i2c_init) {
64
diff --git a/hw/arm/aspeed_soc.c b/hw/arm/aspeed_soc.c
65
index XXXXXXX..XXXXXXX 100644
66
--- a/hw/arm/aspeed_soc.c
67
+++ b/hw/arm/aspeed_soc.c
68
@@ -XXX,XX +XXX,XX @@ static const int aspeed_soc_ast2400_irqmap[] = {
69
70
#define aspeed_soc_ast2500_irqmap aspeed_soc_ast2400_irqmap
71
72
-static const AspeedSoCInfo aspeed_socs[] = {
73
- {
50
- {
74
- .name = "ast2400-a1",
51
- .name = TYPE_BCM2836,
75
- .cpu_type = ARM_CPU_TYPE_NAME("arm926"),
52
- .cpu_type = ARM_CPU_TYPE_NAME("cortex-a7"),
76
- .silicon_rev = AST2400_A1_SILICON_REV,
53
- .peri_base = 0x3f000000,
77
- .sram_size = 0x8000,
54
- .ctrl_base = 0x40000000,
78
- .spis_num = 1,
55
- .clusterid = 0xf,
79
- .wdts_num = 2,
80
- .irqmap = aspeed_soc_ast2400_irqmap,
81
- .memmap = aspeed_soc_ast2400_memmap,
82
- .num_cpus = 1,
83
- }, {
84
- .name = "ast2500-a1",
85
- .cpu_type = ARM_CPU_TYPE_NAME("arm1176"),
86
- .silicon_rev = AST2500_A1_SILICON_REV,
87
- .sram_size = 0x9000,
88
- .spis_num = 2,
89
- .wdts_num = 3,
90
- .irqmap = aspeed_soc_ast2500_irqmap,
91
- .memmap = aspeed_soc_ast2500_memmap,
92
- .num_cpus = 1,
93
- },
56
- },
57
-#ifdef TARGET_AARCH64
58
- {
59
- .name = TYPE_BCM2837,
60
- .cpu_type = ARM_CPU_TYPE_NAME("cortex-a53"),
61
- .peri_base = 0x3f000000,
62
- .ctrl_base = 0x40000000,
63
- .clusterid = 0x0,
64
- },
65
-#endif
94
-};
66
-};
95
-
67
-
96
static qemu_irq aspeed_soc_get_irq(AspeedSoCState *s, int ctrl)
68
static void bcm2836_init(Object *obj)
97
{
69
{
98
AspeedSoCClass *sc = ASPEED_SOC_GET_CLASS(s);
70
BCM283XState *s = BCM283X(obj);
99
71
BCM283XClass *bc = BCM283X_GET_CLASS(obj);
100
- return qdev_get_gpio_in(DEVICE(&s->vic), sc->info->irqmap[ctrl]);
72
- const BCM283XInfo *info = bc->info;
101
+ return qdev_get_gpio_in(DEVICE(&s->vic), sc->irqmap[ctrl]);
73
int n;
102
}
74
103
75
for (n = 0; n < BCM283X_NCPUS; n++) {
104
static void aspeed_soc_init(Object *obj)
76
object_initialize_child(obj, "cpu[*]", &s->cpu[n].core,
105
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_init(Object *obj)
77
- info->cpu_type);
106
char socname[8];
78
+ bc->cpu_type);
107
char typename[64];
108
109
- if (sscanf(sc->info->name, "%7s", socname) != 1) {
110
+ if (sscanf(sc->name, "%7s", socname) != 1) {
111
g_assert_not_reached();
112
}
79
}
113
80
114
- for (i = 0; i < sc->info->num_cpus; i++) {
81
object_initialize_child(obj, "control", &s->control, TYPE_BCM2836_CONTROL);
115
+ for (i = 0; i < sc->num_cpus; i++) {
82
@@ -XXX,XX +XXX,XX @@ static void bcm2836_realize(DeviceState *dev, Error **errp)
116
object_initialize_child(obj, "cpu[*]", OBJECT(&s->cpu[i]),
83
{
117
- sizeof(s->cpu[i]), sc->info->cpu_type,
84
BCM283XState *s = BCM283X(dev);
118
+ sizeof(s->cpu[i]), sc->cpu_type,
85
BCM283XClass *bc = BCM283X_GET_CLASS(dev);
119
&error_abort, NULL);
86
- const BCM283XInfo *info = bc->info;
120
}
87
Object *obj;
121
88
int n;
122
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_init(Object *obj)
89
123
sysbus_init_child_obj(obj, "scu", OBJECT(&s->scu), sizeof(s->scu),
90
@@ -XXX,XX +XXX,XX @@ static void bcm2836_realize(DeviceState *dev, Error **errp)
124
typename);
91
"sd-bus");
125
qdev_prop_set_uint32(DEVICE(&s->scu), "silicon-rev",
92
126
- sc->info->silicon_rev);
93
sysbus_mmio_map_overlap(SYS_BUS_DEVICE(&s->peripherals), 0,
127
+ sc->silicon_rev);
94
- info->peri_base, 1);
128
object_property_add_alias(obj, "hw-strap1", OBJECT(&s->scu),
95
+ bc->peri_base, 1);
129
"hw-strap1", &error_abort);
96
130
object_property_add_alias(obj, "hw-strap2", OBJECT(&s->scu),
97
/* bcm2836 interrupt controller (and mailboxes, etc.) */
131
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_init(Object *obj)
98
if (!sysbus_realize(SYS_BUS_DEVICE(&s->control), errp)) {
132
object_property_add_alias(obj, "dram", OBJECT(&s->fmc), "dram",
133
&error_abort);
134
135
- for (i = 0; i < sc->info->spis_num; i++) {
136
+ for (i = 0; i < sc->spis_num; i++) {
137
snprintf(typename, sizeof(typename), "aspeed.spi%d-%s", i + 1, socname);
138
sysbus_init_child_obj(obj, "spi[*]", OBJECT(&s->spi[i]),
139
sizeof(s->spi[i]), typename);
140
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_init(Object *obj)
141
object_property_add_alias(obj, "max-ram-size", OBJECT(&s->sdmc),
142
"max-ram-size", &error_abort);
143
144
- for (i = 0; i < sc->info->wdts_num; i++) {
145
+ for (i = 0; i < sc->wdts_num; i++) {
146
snprintf(typename, sizeof(typename), "aspeed.wdt-%s", socname);
147
sysbus_init_child_obj(obj, "wdt[*]", OBJECT(&s->wdt[i]),
148
sizeof(s->wdt[i]), typename);
149
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
150
Error *err = NULL, *local_err = NULL;
151
152
/* IO space */
153
- create_unimplemented_device("aspeed_soc.io", sc->info->memmap[ASPEED_IOMEM],
154
+ create_unimplemented_device("aspeed_soc.io", sc->memmap[ASPEED_IOMEM],
155
ASPEED_SOC_IOMEM_SIZE);
156
157
- if (s->num_cpus > sc->info->num_cpus) {
158
+ if (s->num_cpus > sc->num_cpus) {
159
warn_report("%s: invalid number of CPUs %d, using default %d",
160
- sc->info->name, s->num_cpus, sc->info->num_cpus);
161
- s->num_cpus = sc->info->num_cpus;
162
+ sc->name, s->num_cpus, sc->num_cpus);
163
+ s->num_cpus = sc->num_cpus;
164
}
165
166
/* CPU */
167
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
168
169
/* SRAM */
170
memory_region_init_ram(&s->sram, OBJECT(dev), "aspeed.sram",
171
- sc->info->sram_size, &err);
172
+ sc->sram_size, &err);
173
if (err) {
174
error_propagate(errp, err);
175
return;
99
return;
176
}
100
}
177
memory_region_add_subregion(get_system_memory(),
101
178
- sc->info->memmap[ASPEED_SRAM], &s->sram);
102
- sysbus_mmio_map(SYS_BUS_DEVICE(&s->control), 0, info->ctrl_base);
179
+ sc->memmap[ASPEED_SRAM], &s->sram);
103
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->control), 0, bc->ctrl_base);
180
104
181
/* SCU */
105
sysbus_connect_irq(SYS_BUS_DEVICE(&s->peripherals), 0,
182
object_property_set_bool(OBJECT(&s->scu), true, "realized", &err);
106
qdev_get_gpio_in_named(DEVICE(&s->control), "gpu-irq", 0));
183
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
107
@@ -XXX,XX +XXX,XX @@ static void bcm2836_realize(DeviceState *dev, Error **errp)
184
error_propagate(errp, err);
108
185
return;
109
for (n = 0; n < BCM283X_NCPUS; n++) {
186
}
110
/* TODO: this should be converted to a property of ARM_CPU */
187
- sysbus_mmio_map(SYS_BUS_DEVICE(&s->scu), 0, sc->info->memmap[ASPEED_SCU]);
111
- s->cpu[n].core.mp_affinity = (info->clusterid << 8) | n;
188
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->scu), 0, sc->memmap[ASPEED_SCU]);
112
+ s->cpu[n].core.mp_affinity = (bc->clusterid << 8) | n;
189
113
190
/* VIC */
114
/* set periphbase/CBAR value for CPU-local registers */
191
object_property_set_bool(OBJECT(&s->vic), true, "realized", &err);
115
if (!object_property_set_int(OBJECT(&s->cpu[n].core), "reset-cbar",
192
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
116
- info->peri_base, errp)) {
193
error_propagate(errp, err);
117
+ bc->peri_base, errp)) {
194
return;
195
}
196
- sysbus_mmio_map(SYS_BUS_DEVICE(&s->vic), 0, sc->info->memmap[ASPEED_VIC]);
197
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->vic), 0, sc->memmap[ASPEED_VIC]);
198
sysbus_connect_irq(SYS_BUS_DEVICE(&s->vic), 0,
199
qdev_get_gpio_in(DEVICE(&s->cpu), ARM_CPU_IRQ));
200
sysbus_connect_irq(SYS_BUS_DEVICE(&s->vic), 1,
201
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
202
error_propagate(errp, err);
203
return;
204
}
205
- sysbus_mmio_map(SYS_BUS_DEVICE(&s->rtc), 0, sc->info->memmap[ASPEED_RTC]);
206
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->rtc), 0, sc->memmap[ASPEED_RTC]);
207
sysbus_connect_irq(SYS_BUS_DEVICE(&s->rtc), 0,
208
aspeed_soc_get_irq(s, ASPEED_RTC));
209
210
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
211
return;
212
}
213
sysbus_mmio_map(SYS_BUS_DEVICE(&s->timerctrl), 0,
214
- sc->info->memmap[ASPEED_TIMER1]);
215
+ sc->memmap[ASPEED_TIMER1]);
216
for (i = 0; i < ASPEED_TIMER_NR_TIMERS; i++) {
217
qemu_irq irq = aspeed_soc_get_irq(s, ASPEED_TIMER1 + i);
218
sysbus_connect_irq(SYS_BUS_DEVICE(&s->timerctrl), i, irq);
219
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
220
/* UART - attach an 8250 to the IO space as our UART5 */
221
if (serial_hd(0)) {
222
qemu_irq uart5 = aspeed_soc_get_irq(s, ASPEED_UART5);
223
- serial_mm_init(get_system_memory(), sc->info->memmap[ASPEED_UART5], 2,
224
+ serial_mm_init(get_system_memory(), sc->memmap[ASPEED_UART5], 2,
225
uart5, 38400, serial_hd(0), DEVICE_LITTLE_ENDIAN);
226
}
227
228
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
229
error_propagate(errp, err);
230
return;
231
}
232
- sysbus_mmio_map(SYS_BUS_DEVICE(&s->i2c), 0, sc->info->memmap[ASPEED_I2C]);
233
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->i2c), 0, sc->memmap[ASPEED_I2C]);
234
sysbus_connect_irq(SYS_BUS_DEVICE(&s->i2c), 0,
235
aspeed_soc_get_irq(s, ASPEED_I2C));
236
237
/* FMC, The number of CS is set at the board level */
238
- object_property_set_int(OBJECT(&s->fmc), sc->info->memmap[ASPEED_SDRAM],
239
+ object_property_set_int(OBJECT(&s->fmc), sc->memmap[ASPEED_SDRAM],
240
"sdram-base", &err);
241
if (err) {
242
error_propagate(errp, err);
243
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
244
error_propagate(errp, err);
245
return;
246
}
247
- sysbus_mmio_map(SYS_BUS_DEVICE(&s->fmc), 0, sc->info->memmap[ASPEED_FMC]);
248
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->fmc), 0, sc->memmap[ASPEED_FMC]);
249
sysbus_mmio_map(SYS_BUS_DEVICE(&s->fmc), 1,
250
s->fmc.ctrl->flash_window_base);
251
sysbus_connect_irq(SYS_BUS_DEVICE(&s->fmc), 0,
252
aspeed_soc_get_irq(s, ASPEED_FMC));
253
254
/* SPI */
255
- for (i = 0; i < sc->info->spis_num; i++) {
256
+ for (i = 0; i < sc->spis_num; i++) {
257
object_property_set_int(OBJECT(&s->spi[i]), 1, "num-cs", &err);
258
object_property_set_bool(OBJECT(&s->spi[i]), true, "realized",
259
&local_err);
260
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
261
return;
118
return;
262
}
119
}
263
sysbus_mmio_map(SYS_BUS_DEVICE(&s->spi[i]), 0,
120
264
- sc->info->memmap[ASPEED_SPI1 + i]);
121
@@ -XXX,XX +XXX,XX @@ static Property bcm2836_props[] = {
265
+ sc->memmap[ASPEED_SPI1 + i]);
122
static void bcm283x_class_init(ObjectClass *oc, void *data)
266
sysbus_mmio_map(SYS_BUS_DEVICE(&s->spi[i]), 1,
123
{
267
s->spi[i].ctrl->flash_window_base);
124
DeviceClass *dc = DEVICE_CLASS(oc);
268
}
125
- BCM283XClass *bc = BCM283X_CLASS(oc);
269
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
126
270
error_propagate(errp, err);
127
- bc->info = data;
271
return;
128
- dc->realize = bcm2836_realize;
272
}
129
- device_class_set_props(dc, bcm2836_props);
273
- sysbus_mmio_map(SYS_BUS_DEVICE(&s->sdmc), 0, sc->info->memmap[ASPEED_SDMC]);
130
/* Reason: Must be wired up in code (see raspi_init() function) */
274
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->sdmc), 0, sc->memmap[ASPEED_SDMC]);
131
dc->user_creatable = false;
275
276
/* Watch dog */
277
- for (i = 0; i < sc->info->wdts_num; i++) {
278
+ for (i = 0; i < sc->wdts_num; i++) {
279
AspeedWDTClass *awc = ASPEED_WDT_GET_CLASS(&s->wdt[i]);
280
281
object_property_set_bool(OBJECT(&s->wdt[i]), true, "realized", &err);
282
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
283
return;
284
}
285
sysbus_mmio_map(SYS_BUS_DEVICE(&s->wdt[i]), 0,
286
- sc->info->memmap[ASPEED_WDT] + i * awc->offset);
287
+ sc->memmap[ASPEED_WDT] + i * awc->offset);
288
}
289
290
/* Net */
291
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
292
return;
293
}
294
sysbus_mmio_map(SYS_BUS_DEVICE(&s->ftgmac100[i]), 0,
295
- sc->info->memmap[ASPEED_ETH1 + i]);
296
+ sc->memmap[ASPEED_ETH1 + i]);
297
sysbus_connect_irq(SYS_BUS_DEVICE(&s->ftgmac100[i]), 0,
298
aspeed_soc_get_irq(s, ASPEED_ETH1 + i));
299
}
300
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
301
return;
302
}
303
sysbus_mmio_map(SYS_BUS_DEVICE(&s->xdma), 0,
304
- sc->info->memmap[ASPEED_XDMA]);
305
+ sc->memmap[ASPEED_XDMA]);
306
sysbus_connect_irq(SYS_BUS_DEVICE(&s->xdma), 0,
307
aspeed_soc_get_irq(s, ASPEED_XDMA));
308
309
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
310
error_propagate(errp, err);
311
return;
312
}
313
- sysbus_mmio_map(SYS_BUS_DEVICE(&s->gpio), 0, sc->info->memmap[ASPEED_GPIO]);
314
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->gpio), 0, sc->memmap[ASPEED_GPIO]);
315
sysbus_connect_irq(SYS_BUS_DEVICE(&s->gpio), 0,
316
aspeed_soc_get_irq(s, ASPEED_GPIO));
317
318
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp)
319
return;
320
}
321
sysbus_mmio_map(SYS_BUS_DEVICE(&s->sdhci), 0,
322
- sc->info->memmap[ASPEED_SDHCI]);
323
+ sc->memmap[ASPEED_SDHCI]);
324
sysbus_connect_irq(SYS_BUS_DEVICE(&s->sdhci), 0,
325
aspeed_soc_get_irq(s, ASPEED_SDHCI));
326
}
132
}
327
@@ -XXX,XX +XXX,XX @@ static Property aspeed_soc_properties[] = {
133
328
static void aspeed_soc_class_init(ObjectClass *oc, void *data)
134
-static const TypeInfo bcm283x_type_info = {
329
{
135
- .name = TYPE_BCM283X,
330
DeviceClass *dc = DEVICE_CLASS(oc);
136
- .parent = TYPE_DEVICE,
331
- AspeedSoCClass *sc = ASPEED_SOC_CLASS(oc);
137
- .instance_size = sizeof(BCM283XState),
332
138
- .instance_init = bcm2836_init,
333
- sc->info = (AspeedSoCInfo *) data;
139
- .class_size = sizeof(BCM283XClass),
334
dc->realize = aspeed_soc_realize;
140
- .abstract = true,
335
/* Reason: Uses serial_hds and nd_table in realize() directly */
141
+static void bcm2836_class_init(ObjectClass *oc, void *data)
336
dc->user_creatable = false;
142
+{
337
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_class_init(ObjectClass *oc, void *data)
143
+ DeviceClass *dc = DEVICE_CLASS(oc);
338
static const TypeInfo aspeed_soc_type_info = {
144
+ BCM283XClass *bc = BCM283X_CLASS(oc);
339
.name = TYPE_ASPEED_SOC,
145
+
340
.parent = TYPE_DEVICE,
146
+ bc->cpu_type = ARM_CPU_TYPE_NAME("cortex-a7");
341
- .instance_init = aspeed_soc_init,
147
+ bc->peri_base = 0x3f000000;
342
.instance_size = sizeof(AspeedSoCState),
148
+ bc->ctrl_base = 0x40000000;
343
.class_size = sizeof(AspeedSoCClass),
149
+ bc->clusterid = 0xf;
344
+ .class_init = aspeed_soc_class_init,
150
+ dc->realize = bcm2836_realize;
345
.abstract = true,
151
+ device_class_set_props(dc, bcm2836_props);
346
};
152
};
347
153
348
-static void aspeed_soc_register_types(void)
154
-static void bcm2836_register_types(void)
349
+static void aspeed_soc_ast2400_class_init(ObjectClass *oc, void *data)
155
+#ifdef TARGET_AARCH64
156
+static void bcm2837_class_init(ObjectClass *oc, void *data)
350
{
157
{
351
- int i;
158
- int i;
352
+ AspeedSoCClass *sc = ASPEED_SOC_CLASS(oc);
159
+ DeviceClass *dc = DEVICE_CLASS(oc);
353
160
+ BCM283XClass *bc = BCM283X_CLASS(oc);
354
- type_register_static(&aspeed_soc_type_info);
161
355
- for (i = 0; i < ARRAY_SIZE(aspeed_socs); ++i) {
162
- type_register_static(&bcm283x_type_info);
163
- for (i = 0; i < ARRAY_SIZE(bcm283x_socs); i++) {
356
- TypeInfo ti = {
164
- TypeInfo ti = {
357
- .name = aspeed_socs[i].name,
165
- .name = bcm283x_socs[i].name,
358
- .parent = TYPE_ASPEED_SOC,
166
- .parent = TYPE_BCM283X,
359
- .class_init = aspeed_soc_class_init,
167
- .class_init = bcm283x_class_init,
360
- .class_data = (void *) &aspeed_socs[i],
168
- .class_data = (void *) &bcm283x_socs[i],
361
- };
169
- };
362
- type_register(&ti);
170
- type_register(&ti);
363
- }
171
+ bc->cpu_type = ARM_CPU_TYPE_NAME("cortex-a53");
364
+ sc->name = "ast2400-a1";
172
+ bc->peri_base = 0x3f000000;
365
+ sc->cpu_type = ARM_CPU_TYPE_NAME("arm926");
173
+ bc->ctrl_base = 0x40000000;
366
+ sc->silicon_rev = AST2400_A1_SILICON_REV;
174
+ bc->clusterid = 0x0;
367
+ sc->sram_size = 0x8000;
175
+ dc->realize = bcm2836_realize;
368
+ sc->spis_num = 1;
176
+ device_class_set_props(dc, bcm2836_props);
369
+ sc->wdts_num = 2;
370
+ sc->irqmap = aspeed_soc_ast2400_irqmap;
371
+ sc->memmap = aspeed_soc_ast2400_memmap;
372
+ sc->num_cpus = 1;
373
}
374
375
+static const TypeInfo aspeed_soc_ast2400_type_info = {
376
+ .name = "ast2400-a1",
377
+ .parent = TYPE_ASPEED_SOC,
378
+ .instance_init = aspeed_soc_init,
379
+ .instance_size = sizeof(AspeedSoCState),
380
+ .class_init = aspeed_soc_ast2400_class_init,
381
+};
177
+};
178
+#endif
382
+
179
+
383
+static void aspeed_soc_ast2500_class_init(ObjectClass *oc, void *data)
180
+static const TypeInfo bcm283x_types[] = {
384
+{
181
+ {
385
+ AspeedSoCClass *sc = ASPEED_SOC_CLASS(oc);
182
+ .name = TYPE_BCM2836,
386
+
183
+ .parent = TYPE_BCM283X,
387
+ sc->name = "ast2500-a1";
184
+ .class_init = bcm2836_class_init,
388
+ sc->cpu_type = ARM_CPU_TYPE_NAME("arm1176");
185
+#ifdef TARGET_AARCH64
389
+ sc->silicon_rev = AST2500_A1_SILICON_REV;
186
+ }, {
390
+ sc->sram_size = 0x9000;
187
+ .name = TYPE_BCM2837,
391
+ sc->spis_num = 2;
188
+ .parent = TYPE_BCM283X,
392
+ sc->wdts_num = 3;
189
+ .class_init = bcm2837_class_init,
393
+ sc->irqmap = aspeed_soc_ast2500_irqmap;
190
+#endif
394
+ sc->memmap = aspeed_soc_ast2500_memmap;
191
+ }, {
395
+ sc->num_cpus = 1;
192
+ .name = TYPE_BCM283X,
396
+}
193
+ .parent = TYPE_DEVICE,
397
+
194
+ .instance_size = sizeof(BCM283XState),
398
+static const TypeInfo aspeed_soc_ast2500_type_info = {
195
+ .instance_init = bcm2836_init,
399
+ .name = "ast2500-a1",
196
+ .class_size = sizeof(BCM283XClass),
400
+ .parent = TYPE_ASPEED_SOC,
197
+ .class_init = bcm283x_class_init,
401
+ .instance_init = aspeed_soc_init,
198
+ .abstract = true,
402
+ .instance_size = sizeof(AspeedSoCState),
199
}
403
+ .class_init = aspeed_soc_ast2500_class_init,
200
-}
404
+};
201
+};
405
+static void aspeed_soc_register_types(void)
202
406
+{
203
-type_init(bcm2836_register_types)
407
+ type_register_static(&aspeed_soc_type_info);
204
+DEFINE_TYPES(bcm283x_types)
408
+ type_register_static(&aspeed_soc_ast2400_type_info);
409
+ type_register_static(&aspeed_soc_ast2500_type_info);
410
+};
411
+
412
type_init(aspeed_soc_register_types)
413
--
205
--
414
2.20.1
206
2.20.1
415
207
416
208
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
2
2
3
Add trace events for read/write accesses and IRQ.
3
The BCM2835 has only one core. Introduce the core_count field to
4
be able to use values different than BCM283X_NCPUS (4).
4
5
5
Properties are structures used for the ARM particular MBOX.
6
Reviewed-by: Luc Michel <luc.michel@greensocs.com>
6
Since one call in bcm2835_property.c concerns the mbox block,
7
name this trace event in the same bcm2835_mbox* namespace.
8
9
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
7
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
10
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
8
Message-id: 20201024170127.3592182-4-f4bug@amsat.org
11
Message-id: 20190926173428.10713-8-f4bug@amsat.org
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
---
10
---
14
hw/misc/bcm2835_mbox.c | 5 +++++
11
hw/arm/bcm2836.c | 5 ++++-
15
hw/misc/bcm2835_property.c | 2 ++
12
1 file changed, 4 insertions(+), 1 deletion(-)
16
hw/misc/trace-events | 6 ++++++
17
3 files changed, 13 insertions(+)
18
13
19
diff --git a/hw/misc/bcm2835_mbox.c b/hw/misc/bcm2835_mbox.c
14
diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c
20
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
21
--- a/hw/misc/bcm2835_mbox.c
16
--- a/hw/arm/bcm2836.c
22
+++ b/hw/misc/bcm2835_mbox.c
17
+++ b/hw/arm/bcm2836.c
23
@@ -XXX,XX +XXX,XX @@
18
@@ -XXX,XX +XXX,XX @@ typedef struct BCM283XClass {
24
#include "migration/vmstate.h"
19
/*< public >*/
25
#include "qemu/log.h"
20
const char *name;
26
#include "qemu/module.h"
21
const char *cpu_type;
27
+#include "trace.h"
22
+ unsigned core_count;
28
23
hwaddr peri_base; /* Peripheral base address seen by the CPU */
29
#define MAIL0_PEEK 0x90
24
hwaddr ctrl_base; /* Interrupt controller and mailboxes etc. */
30
#define MAIL0_SENDER 0x94
25
int clusterid;
31
@@ -XXX,XX +XXX,XX @@ static void bcm2835_mbox_update(BCM2835MboxState *s)
26
@@ -XXX,XX +XXX,XX @@ static void bcm2836_init(Object *obj)
32
set = true;
27
BCM283XClass *bc = BCM283X_GET_CLASS(obj);
33
}
28
int n;
29
30
- for (n = 0; n < BCM283X_NCPUS; n++) {
31
+ for (n = 0; n < bc->core_count; n++) {
32
object_initialize_child(obj, "cpu[*]", &s->cpu[n].core,
33
bc->cpu_type);
34
}
34
}
35
+ trace_bcm2835_mbox_irq(set);
35
@@ -XXX,XX +XXX,XX @@ static void bcm2836_class_init(ObjectClass *oc, void *data)
36
qemu_set_irq(s->arm_irq, set);
36
BCM283XClass *bc = BCM283X_CLASS(oc);
37
}
37
38
38
bc->cpu_type = ARM_CPU_TYPE_NAME("cortex-a7");
39
@@ -XXX,XX +XXX,XX @@ static uint64_t bcm2835_mbox_read(void *opaque, hwaddr offset, unsigned size)
39
+ bc->core_count = BCM283X_NCPUS;
40
default:
40
bc->peri_base = 0x3f000000;
41
qemu_log_mask(LOG_UNIMP, "%s: Unsupported offset 0x%"HWADDR_PRIx"\n",
41
bc->ctrl_base = 0x40000000;
42
__func__, offset);
42
bc->clusterid = 0xf;
43
+ trace_bcm2835_mbox_read(size, offset, res);
43
@@ -XXX,XX +XXX,XX @@ static void bcm2837_class_init(ObjectClass *oc, void *data)
44
return 0;
44
BCM283XClass *bc = BCM283X_CLASS(oc);
45
}
45
46
+ trace_bcm2835_mbox_read(size, offset, res);
46
bc->cpu_type = ARM_CPU_TYPE_NAME("cortex-a53");
47
47
+ bc->core_count = BCM283X_NCPUS;
48
bcm2835_mbox_update(s);
48
bc->peri_base = 0x3f000000;
49
49
bc->ctrl_base = 0x40000000;
50
@@ -XXX,XX +XXX,XX @@ static void bcm2835_mbox_write(void *opaque, hwaddr offset,
50
bc->clusterid = 0x0;
51
52
offset &= 0xff;
53
54
+ trace_bcm2835_mbox_write(size, offset, value);
55
switch (offset) {
56
case MAIL0_SENDER:
57
break;
58
diff --git a/hw/misc/bcm2835_property.c b/hw/misc/bcm2835_property.c
59
index XXXXXXX..XXXXXXX 100644
60
--- a/hw/misc/bcm2835_property.c
61
+++ b/hw/misc/bcm2835_property.c
62
@@ -XXX,XX +XXX,XX @@
63
#include "sysemu/dma.h"
64
#include "qemu/log.h"
65
#include "qemu/module.h"
66
+#include "trace.h"
67
68
/* https://github.com/raspberrypi/firmware/wiki/Mailbox-property-interface */
69
70
@@ -XXX,XX +XXX,XX @@ static void bcm2835_property_mbox_push(BCM2835PropertyState *s, uint32_t value)
71
break;
72
}
73
74
+ trace_bcm2835_mbox_property(tag, bufsize, resplen);
75
if (tag == 0) {
76
break;
77
}
78
diff --git a/hw/misc/trace-events b/hw/misc/trace-events
79
index XXXXXXX..XXXXXXX 100644
80
--- a/hw/misc/trace-events
81
+++ b/hw/misc/trace-events
82
@@ -XXX,XX +XXX,XX @@ armsse_mhu_write(uint64_t offset, uint64_t data, unsigned size) "SSE-200 MHU wri
83
84
# aspeed_xdma.c
85
aspeed_xdma_write(uint64_t offset, uint64_t data) "XDMA write: offset 0x%" PRIx64 " data 0x%" PRIx64
86
+
87
+# bcm2835_mbox.c
88
+bcm2835_mbox_write(unsigned int size, uint64_t addr, uint64_t value) "mbox write sz:%u addr:0x%"PRIx64" data:0x%"PRIx64
89
+bcm2835_mbox_read(unsigned int size, uint64_t addr, uint64_t value) "mbox read sz:%u addr:0x%"PRIx64" data:0x%"PRIx64
90
+bcm2835_mbox_irq(unsigned level) "mbox irq:ARM level:%u"
91
+bcm2835_mbox_property(uint32_t tag, uint32_t bufsize, size_t resplen) "mbox property tag:0x%08x in_sz:%u out_sz:%zu"
92
--
51
--
93
2.20.1
52
2.20.1
94
53
95
54
diff view generated by jsdifflib
1
Switch the exynos MCT LFRC timers over to the ptimer transaction API.
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
2
2
3
It makes no sense to set enabled-cpus=0 on single core SoCs.
4
5
Reviewed-by: Luc Michel <luc.michel@greensocs.com>
6
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
7
Message-id: 20201024170127.3592182-5-f4bug@amsat.org
3
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
4
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
5
Message-id: 20191008171740.9679-13-peter.maydell@linaro.org
6
---
9
---
7
hw/timer/exynos4210_mct.c | 27 +++++++++++++++++++++++----
10
hw/arm/bcm2836.c | 15 +++++++--------
8
1 file changed, 23 insertions(+), 4 deletions(-)
11
1 file changed, 7 insertions(+), 8 deletions(-)
9
12
10
diff --git a/hw/timer/exynos4210_mct.c b/hw/timer/exynos4210_mct.c
13
diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c
11
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
12
--- a/hw/timer/exynos4210_mct.c
15
--- a/hw/arm/bcm2836.c
13
+++ b/hw/timer/exynos4210_mct.c
16
+++ b/hw/arm/bcm2836.c
14
@@ -XXX,XX +XXX,XX @@ static uint64_t exynos4210_lfrc_get_count(Exynos4210MCTLT *s)
17
@@ -XXX,XX +XXX,XX @@ typedef struct BCM283XClass {
15
18
#define BCM283X_GET_CLASS(obj) \
16
/*
19
OBJECT_GET_CLASS(BCM283XClass, (obj), TYPE_BCM283X)
17
* Set counter of FRC local timer.
20
18
+ * Must be called from within exynos4210_lfrc_tx_begin/commit block.
21
+static Property bcm2836_enabled_cores_property =
19
*/
22
+ DEFINE_PROP_UINT32("enabled-cpus", BCM283XState, enabled_cpus, 0);
20
static void exynos4210_lfrc_update_count(Exynos4210MCTLT *s)
23
+
24
static void bcm2836_init(Object *obj)
21
{
25
{
22
@@ -XXX,XX +XXX,XX @@ static void exynos4210_lfrc_update_count(Exynos4210MCTLT *s)
26
BCM283XState *s = BCM283X(obj);
23
27
@@ -XXX,XX +XXX,XX @@ static void bcm2836_init(Object *obj)
24
/*
28
object_initialize_child(obj, "cpu[*]", &s->cpu[n].core,
25
* Start local FRC timer
29
bc->cpu_type);
26
+ * Must be called from within exynos4210_lfrc_tx_begin/commit block.
30
}
27
*/
31
+ if (bc->core_count > 1) {
28
static void exynos4210_lfrc_start(Exynos4210MCTLT *s)
32
+ qdev_property_add_static(DEVICE(obj), &bcm2836_enabled_cores_property);
29
{
33
+ qdev_prop_set_uint32(DEVICE(obj), "enabled-cpus", bc->core_count);
30
@@ -XXX,XX +XXX,XX @@ static void exynos4210_lfrc_start(Exynos4210MCTLT *s)
34
+ }
31
35
32
/*
36
object_initialize_child(obj, "control", &s->control, TYPE_BCM2836_CONTROL);
33
* Stop local FRC timer
37
34
+ * Must be called from within exynos4210_lfrc_tx_begin/commit block.
38
@@ -XXX,XX +XXX,XX @@ static void bcm2836_realize(DeviceState *dev, Error **errp)
35
*/
36
static void exynos4210_lfrc_stop(Exynos4210MCTLT *s)
37
{
38
ptimer_stop(s->ptimer_frc);
39
}
40
41
+/* Start ptimer transaction for local FRC timer */
42
+static void exynos4210_lfrc_tx_begin(Exynos4210MCTLT *s)
43
+{
44
+ ptimer_transaction_begin(s->ptimer_frc);
45
+}
46
+
47
+/* Commit ptimer transaction for local FRC timer */
48
+static void exynos4210_lfrc_tx_commit(Exynos4210MCTLT *s)
49
+{
50
+ ptimer_transaction_commit(s->ptimer_frc);
51
+}
52
+
53
/*
54
* Local timer free running counter tick handler
55
*/
56
@@ -XXX,XX +XXX,XX @@ static void exynos4210_mct_update_freq(Exynos4210MCTState *s)
57
58
/* local timer */
59
ptimer_set_freq(s->l_timer[0].tick_timer.ptimer_tick, s->freq);
60
- ptimer_set_freq(s->l_timer[0].ptimer_frc, s->freq);
61
+ tx_ptimer_set_freq(s->l_timer[0].ptimer_frc, s->freq);
62
ptimer_set_freq(s->l_timer[1].tick_timer.ptimer_tick, s->freq);
63
- ptimer_set_freq(s->l_timer[1].ptimer_frc, s->freq);
64
+ tx_ptimer_set_freq(s->l_timer[1].ptimer_frc, s->freq);
65
}
39
}
66
}
40
}
67
41
68
@@ -XXX,XX +XXX,XX @@ static void exynos4210_mct_reset(DeviceState *d)
42
-static Property bcm2836_props[] = {
69
s->l_timer[i].tick_timer.count = 0;
43
- DEFINE_PROP_UINT32("enabled-cpus", BCM283XState, enabled_cpus,
70
s->l_timer[i].tick_timer.distance = 0;
44
- BCM283X_NCPUS),
71
s->l_timer[i].tick_timer.progress = 0;
45
- DEFINE_PROP_END_OF_LIST()
72
+ exynos4210_lfrc_tx_begin(&s->l_timer[i]);
46
-};
73
ptimer_stop(s->l_timer[i].ptimer_frc);
47
-
74
+ exynos4210_lfrc_tx_commit(&s->l_timer[i]);
48
static void bcm283x_class_init(ObjectClass *oc, void *data)
75
49
{
76
exynos4210_ltick_timer_init(&s->l_timer[i].tick_timer);
50
DeviceClass *dc = DEVICE_CLASS(oc);
77
}
51
@@ -XXX,XX +XXX,XX @@ static void bcm2836_class_init(ObjectClass *oc, void *data)
78
@@ -XXX,XX +XXX,XX @@ static void exynos4210_mct_write(void *opaque, hwaddr offset,
52
bc->ctrl_base = 0x40000000;
79
}
53
bc->clusterid = 0xf;
80
54
dc->realize = bcm2836_realize;
81
/* Start or Stop local FRC if TCON changed */
55
- device_class_set_props(dc, bcm2836_props);
82
+ exynos4210_lfrc_tx_begin(&s->l_timer[lt_i]);
56
};
83
if ((value & L_TCON_FRC_START) >
57
84
(s->l_timer[lt_i].reg.tcon & L_TCON_FRC_START)) {
58
#ifdef TARGET_AARCH64
85
DPRINTF("local timer[%d] start frc\n", lt_i);
59
@@ -XXX,XX +XXX,XX @@ static void bcm2837_class_init(ObjectClass *oc, void *data)
86
@@ -XXX,XX +XXX,XX @@ static void exynos4210_mct_write(void *opaque, hwaddr offset,
60
bc->ctrl_base = 0x40000000;
87
DPRINTF("local timer[%d] stop frc\n", lt_i);
61
bc->clusterid = 0x0;
88
exynos4210_lfrc_stop(&s->l_timer[lt_i]);
62
dc->realize = bcm2836_realize;
89
}
63
- device_class_set_props(dc, bcm2836_props);
90
+ exynos4210_lfrc_tx_commit(&s->l_timer[lt_i]);
64
};
91
break;
65
#endif
92
93
case L0_TCNTB: case L1_TCNTB:
94
@@ -XXX,XX +XXX,XX @@ static void exynos4210_mct_init(Object *obj)
95
/* Local timers */
96
for (i = 0; i < 2; i++) {
97
bh[0] = qemu_bh_new(exynos4210_ltick_event, &s->l_timer[i]);
98
- bh[1] = qemu_bh_new(exynos4210_lfrc_event, &s->l_timer[i]);
99
s->l_timer[i].tick_timer.ptimer_tick =
100
ptimer_init_with_bh(bh[0], PTIMER_POLICY_DEFAULT);
101
s->l_timer[i].ptimer_frc =
102
- ptimer_init_with_bh(bh[1], PTIMER_POLICY_DEFAULT);
103
+ ptimer_init(exynos4210_lfrc_event, &s->l_timer[i],
104
+ PTIMER_POLICY_DEFAULT);
105
s->l_timer[i].id = i;
106
}
107
66
108
--
67
--
109
2.20.1
68
2.20.1
110
69
111
70
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
2
2
3
Various address spaces from the BCM2835 are reported as
3
The realize() function is clearly composed of two parts,
4
'anonymous' in memory tree:
4
each described by a comment:
5
5
6
(qemu) info mtree
6
void realize()
7
{
8
/* common peripherals from bcm2835 */
9
...
10
/* bcm2836 interrupt controller (and mailboxes, etc.) */
11
...
12
}
7
13
8
address-space: anonymous
14
Split the two part, so we can reuse the common part with other
9
0000000000000000-000000000000008f (prio 0, i/o): bcm2835-mbox
15
SoCs from this family.
10
0000000000000010-000000000000001f (prio 0, i/o): bcm2835-fb
11
0000000000000080-000000000000008f (prio 0, i/o): bcm2835-property
12
16
13
address-space: anonymous
17
Reviewed-by: Luc Michel <luc.michel@greensocs.com>
14
0000000000000000-00000000ffffffff (prio 0, i/o): bcm2835-gpu
15
0000000000000000-000000003fffffff (prio 0, i/o): alias bcm2835-gpu-ram-alias[*] @ram 0000000000000000-000000003fffffff
16
0000000040000000-000000007fffffff (prio 0, i/o): alias bcm2835-gpu-ram-alias[*] @ram 0000000000000000-000000003fffffff
17
000000007e000000-000000007effffff (prio 1, i/o): alias bcm2835-peripherals @bcm2835-peripherals 0000000000000000-0000000000ffffff
18
0000000080000000-00000000bfffffff (prio 0, i/o): alias bcm2835-gpu-ram-alias[*] @ram 0000000000000000-000000003fffffff
19
00000000c0000000-00000000ffffffff (prio 0, i/o): alias bcm2835-gpu-ram-alias[*] @ram 0000000000000000-000000003fffffff
20
21
[...]
22
23
Since the address_space_init() function takes a 'name' argument,
24
set it to correctly describe each address space:
25
26
(qemu) info mtree
27
28
address-space: bcm2835-mbox-memory
29
0000000000000000-000000000000008f (prio 0, i/o): bcm2835-mbox
30
0000000000000010-000000000000001f (prio 0, i/o): bcm2835-fb
31
0000000000000080-000000000000008f (prio 0, i/o): bcm2835-property
32
33
address-space: bcm2835-fb-memory
34
0000000000000000-00000000ffffffff (prio 0, i/o): bcm2835-gpu
35
0000000000000000-000000003fffffff (prio 0, i/o): alias bcm2835-gpu-ram-alias[*] @ram 0000000000000000-000000003fffffff
36
0000000040000000-000000007fffffff (prio 0, i/o): alias bcm2835-gpu-ram-alias[*] @ram 0000000000000000-000000003fffffff
37
000000007e000000-000000007effffff (prio 1, i/o): alias bcm2835-peripherals @bcm2835-peripherals 0000000000000000-0000000000ffffff
38
0000000080000000-00000000bfffffff (prio 0, i/o): alias bcm2835-gpu-ram-alias[*] @ram 0000000000000000-000000003fffffff
39
00000000c0000000-00000000ffffffff (prio 0, i/o): alias bcm2835-gpu-ram-alias[*] @ram 0000000000000000-000000003fffffff
40
41
address-space: bcm2835-property-memory
42
0000000000000000-00000000ffffffff (prio 0, i/o): bcm2835-gpu
43
0000000000000000-000000003fffffff (prio 0, i/o): alias bcm2835-gpu-ram-alias[*] @ram 0000000000000000-000000003fffffff
44
0000000040000000-000000007fffffff (prio 0, i/o): alias bcm2835-gpu-ram-alias[*] @ram 0000000000000000-000000003fffffff
45
000000007e000000-000000007effffff (prio 1, i/o): alias bcm2835-peripherals @bcm2835-peripherals 0000000000000000-0000000000ffffff
46
0000000080000000-00000000bfffffff (prio 0, i/o): alias bcm2835-gpu-ram-alias[*] @ram 0000000000000000-000000003fffffff
47
00000000c0000000-00000000ffffffff (prio 0, i/o): alias bcm2835-gpu-ram-alias[*] @ram 0000000000000000-000000003fffffff
48
49
address-space: bcm2835-dma-memory
50
0000000000000000-00000000ffffffff (prio 0, i/o): bcm2835-gpu
51
0000000000000000-000000003fffffff (prio 0, i/o): alias bcm2835-gpu-ram-alias[*] @ram 0000000000000000-000000003fffffff
52
0000000040000000-000000007fffffff (prio 0, i/o): alias bcm2835-gpu-ram-alias[*] @ram 0000000000000000-000000003fffffff
53
000000007e000000-000000007effffff (prio 1, i/o): alias bcm2835-peripherals @bcm2835-peripherals 0000000000000000-0000000000ffffff
54
0000000080000000-00000000bfffffff (prio 0, i/o): alias bcm2835-gpu-ram-alias[*] @ram 0000000000000000-000000003fffffff
55
00000000c0000000-00000000ffffffff (prio 0, i/o): alias bcm2835-gpu-ram-alias[*] @ram 0000000000000000-000000003fffffff
56
57
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
18
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
58
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
19
Message-id: 20201024170127.3592182-6-f4bug@amsat.org
59
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
60
Reviewed-by: Cleber Rosa <crosa@redhat.com>
61
Message-id: 20190926173428.10713-4-f4bug@amsat.org
62
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
20
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
63
---
21
---
64
hw/display/bcm2835_fb.c | 2 +-
22
hw/arm/bcm2836.c | 22 ++++++++++++++++++----
65
hw/dma/bcm2835_dma.c | 2 +-
23
1 file changed, 18 insertions(+), 4 deletions(-)
66
hw/misc/bcm2835_mbox.c | 2 +-
67
hw/misc/bcm2835_property.c | 2 +-
68
4 files changed, 4 insertions(+), 4 deletions(-)
69
24
70
diff --git a/hw/display/bcm2835_fb.c b/hw/display/bcm2835_fb.c
25
diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c
71
index XXXXXXX..XXXXXXX 100644
26
index XXXXXXX..XXXXXXX 100644
72
--- a/hw/display/bcm2835_fb.c
27
--- a/hw/arm/bcm2836.c
73
+++ b/hw/display/bcm2835_fb.c
28
+++ b/hw/arm/bcm2836.c
74
@@ -XXX,XX +XXX,XX @@ static void bcm2835_fb_realize(DeviceState *dev, Error **errp)
29
@@ -XXX,XX +XXX,XX @@ static void bcm2836_init(Object *obj)
75
s->initial_config.base = s->vcram_base + BCM2835_FB_OFFSET;
30
qdev_prop_set_uint32(DEVICE(obj), "enabled-cpus", bc->core_count);
76
77
s->dma_mr = MEMORY_REGION(obj);
78
- address_space_init(&s->dma_as, s->dma_mr, NULL);
79
+ address_space_init(&s->dma_as, s->dma_mr, TYPE_BCM2835_FB "-memory");
80
81
bcm2835_fb_reset(dev);
82
83
diff --git a/hw/dma/bcm2835_dma.c b/hw/dma/bcm2835_dma.c
84
index XXXXXXX..XXXXXXX 100644
85
--- a/hw/dma/bcm2835_dma.c
86
+++ b/hw/dma/bcm2835_dma.c
87
@@ -XXX,XX +XXX,XX @@ static void bcm2835_dma_realize(DeviceState *dev, Error **errp)
88
}
31
}
89
32
90
s->dma_mr = MEMORY_REGION(obj);
33
- object_initialize_child(obj, "control", &s->control, TYPE_BCM2836_CONTROL);
91
- address_space_init(&s->dma_as, s->dma_mr, NULL);
34
+ if (bc->ctrl_base) {
92
+ address_space_init(&s->dma_as, s->dma_mr, TYPE_BCM2835_DMA "-memory");
35
+ object_initialize_child(obj, "control", &s->control,
93
36
+ TYPE_BCM2836_CONTROL);
94
bcm2835_dma_reset(dev);
37
+ }
38
39
object_initialize_child(obj, "peripherals", &s->peripherals,
40
TYPE_BCM2835_PERIPHERALS);
41
@@ -XXX,XX +XXX,XX @@ static void bcm2836_init(Object *obj)
42
"vcram-size");
95
}
43
}
96
diff --git a/hw/misc/bcm2835_mbox.c b/hw/misc/bcm2835_mbox.c
44
97
index XXXXXXX..XXXXXXX 100644
45
-static void bcm2836_realize(DeviceState *dev, Error **errp)
98
--- a/hw/misc/bcm2835_mbox.c
46
+static bool bcm283x_common_realize(DeviceState *dev, Error **errp)
99
+++ b/hw/misc/bcm2835_mbox.c
47
{
100
@@ -XXX,XX +XXX,XX @@ static void bcm2835_mbox_realize(DeviceState *dev, Error **errp)
48
BCM283XState *s = BCM283X(dev);
49
BCM283XClass *bc = BCM283X_GET_CLASS(dev);
50
Object *obj;
51
- int n;
52
53
/* common peripherals from bcm2835 */
54
55
@@ -XXX,XX +XXX,XX @@ static void bcm2836_realize(DeviceState *dev, Error **errp)
56
object_property_add_const_link(OBJECT(&s->peripherals), "ram", obj);
57
58
if (!sysbus_realize(SYS_BUS_DEVICE(&s->peripherals), errp)) {
59
- return;
60
+ return false;
101
}
61
}
102
62
103
s->mbox_mr = MEMORY_REGION(obj);
63
object_property_add_alias(OBJECT(s), "sd-bus", OBJECT(&s->peripherals),
104
- address_space_init(&s->mbox_as, s->mbox_mr, NULL);
64
@@ -XXX,XX +XXX,XX @@ static void bcm2836_realize(DeviceState *dev, Error **errp)
105
+ address_space_init(&s->mbox_as, s->mbox_mr, TYPE_BCM2835_MBOX "-memory");
65
106
bcm2835_mbox_reset(dev);
66
sysbus_mmio_map_overlap(SYS_BUS_DEVICE(&s->peripherals), 0,
107
}
67
bc->peri_base, 1);
108
68
+ return true;
109
diff --git a/hw/misc/bcm2835_property.c b/hw/misc/bcm2835_property.c
69
+}
110
index XXXXXXX..XXXXXXX 100644
70
+
111
--- a/hw/misc/bcm2835_property.c
71
+static void bcm2836_realize(DeviceState *dev, Error **errp)
112
+++ b/hw/misc/bcm2835_property.c
72
+{
113
@@ -XXX,XX +XXX,XX @@ static void bcm2835_property_realize(DeviceState *dev, Error **errp)
73
+ BCM283XState *s = BCM283X(dev);
114
}
74
+ BCM283XClass *bc = BCM283X_GET_CLASS(dev);
115
75
+ int n;
116
s->dma_mr = MEMORY_REGION(obj);
76
+
117
- address_space_init(&s->dma_as, s->dma_mr, NULL);
77
+ if (!bcm283x_common_realize(dev, errp)) {
118
+ address_space_init(&s->dma_as, s->dma_mr, TYPE_BCM2835_PROPERTY "-memory");
78
+ return;
119
79
+ }
120
/* TODO: connect to MAC address of USB NIC device, once we emulate it */
80
121
qemu_macaddr_default_if_unset(&s->macaddr);
81
/* bcm2836 interrupt controller (and mailboxes, etc.) */
82
if (!sysbus_realize(SYS_BUS_DEVICE(&s->control), errp)) {
122
--
83
--
123
2.20.1
84
2.20.1
124
85
125
86
diff view generated by jsdifflib
1
Factor out the implementation of SYS_FLEN via the new
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
2
function tables.
3
2
3
Reviewed-by: Luc Michel <luc.michel@greensocs.com>
4
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
5
Message-id: 20201024170127.3592182-7-f4bug@amsat.org
4
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
5
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
6
Message-id: 20190916141544.17540-13-peter.maydell@linaro.org
7
---
7
---
8
target/arm/arm-semi.c | 32 ++++++++++++++++++++++----------
8
include/hw/arm/bcm2836.h | 1 +
9
1 file changed, 22 insertions(+), 10 deletions(-)
9
hw/arm/bcm2836.c | 34 ++++++++++++++++++++++++++++++++++
10
hw/arm/raspi.c | 2 ++
11
3 files changed, 37 insertions(+)
10
12
11
diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c
13
diff --git a/include/hw/arm/bcm2836.h b/include/hw/arm/bcm2836.h
12
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
13
--- a/target/arm/arm-semi.c
15
--- a/include/hw/arm/bcm2836.h
14
+++ b/target/arm/arm-semi.c
16
+++ b/include/hw/arm/bcm2836.h
15
@@ -XXX,XX +XXX,XX @@ typedef uint32_t sys_readfn(ARMCPU *cpu, GuestFD *gf,
17
@@ -XXX,XX +XXX,XX @@ OBJECT_DECLARE_TYPE(BCM283XState, BCM283XClass, BCM283X)
16
typedef uint32_t sys_isattyfn(ARMCPU *cpu, GuestFD *gf);
18
* them, code using these devices should always handle them via the
17
typedef uint32_t sys_seekfn(ARMCPU *cpu, GuestFD *gf,
19
* BCM283x base class, so they have no BCM2836(obj) etc macros.
18
target_ulong offset);
20
*/
19
+typedef uint32_t sys_flenfn(ARMCPU *cpu, GuestFD *gf);
21
+#define TYPE_BCM2835 "bcm2835"
20
22
#define TYPE_BCM2836 "bcm2836"
21
static uint32_t host_closefn(ARMCPU *cpu, GuestFD *gf)
23
#define TYPE_BCM2837 "bcm2837"
22
{
24
23
@@ -XXX,XX +XXX,XX @@ static uint32_t host_seekfn(ARMCPU *cpu, GuestFD *gf, target_ulong offset)
25
diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c
24
return 0;
26
index XXXXXXX..XXXXXXX 100644
27
--- a/hw/arm/bcm2836.c
28
+++ b/hw/arm/bcm2836.c
29
@@ -XXX,XX +XXX,XX @@ static bool bcm283x_common_realize(DeviceState *dev, Error **errp)
30
return true;
25
}
31
}
26
32
27
+static uint32_t host_flenfn(ARMCPU *cpu, GuestFD *gf)
33
+static void bcm2835_realize(DeviceState *dev, Error **errp)
28
+{
34
+{
29
+ CPUARMState *env = &cpu->env;
35
+ BCM283XState *s = BCM283X(dev);
30
+ struct stat buf;
36
+
31
+ uint32_t ret = set_swi_errno(env, fstat(gf->hostfd, &buf));
37
+ if (!bcm283x_common_realize(dev, errp)) {
32
+ if (ret == (uint32_t)-1) {
38
+ return;
33
+ return -1;
34
+ }
39
+ }
35
+ return buf.st_size;
40
+
41
+ if (!qdev_realize(DEVICE(&s->cpu[0].core), NULL, errp)) {
42
+ return;
43
+ }
44
+
45
+ /* Connect irq/fiq outputs from the interrupt controller. */
46
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->peripherals), 0,
47
+ qdev_get_gpio_in(DEVICE(&s->cpu[0].core), ARM_CPU_IRQ));
48
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->peripherals), 1,
49
+ qdev_get_gpio_in(DEVICE(&s->cpu[0].core), ARM_CPU_FIQ));
36
+}
50
+}
37
+
51
+
38
static uint32_t gdb_closefn(ARMCPU *cpu, GuestFD *gf)
52
static void bcm2836_realize(DeviceState *dev, Error **errp)
39
{
53
{
40
return arm_gdb_syscall(cpu, arm_semi_cb, "close,%x", gf->hostfd);
54
BCM283XState *s = BCM283X(dev);
41
@@ -XXX,XX +XXX,XX @@ static uint32_t gdb_seekfn(ARMCPU *cpu, GuestFD *gf, target_ulong offset)
55
@@ -XXX,XX +XXX,XX @@ static void bcm283x_class_init(ObjectClass *oc, void *data)
42
gf->hostfd, offset);
56
dc->user_creatable = false;
43
}
57
}
44
58
45
+static uint32_t gdb_flenfn(ARMCPU *cpu, GuestFD *gf)
59
+static void bcm2835_class_init(ObjectClass *oc, void *data)
46
+{
60
+{
47
+ return arm_gdb_syscall(cpu, arm_semi_flen_cb, "fstat,%x,%x",
61
+ DeviceClass *dc = DEVICE_CLASS(oc);
48
+ gf->hostfd, arm_flen_buf(cpu));
62
+ BCM283XClass *bc = BCM283X_CLASS(oc);
49
+}
50
+
63
+
51
typedef struct GuestFDFunctions {
64
+ bc->cpu_type = ARM_CPU_TYPE_NAME("arm1176");
52
sys_closefn *closefn;
65
+ bc->core_count = 1;
53
sys_writefn *writefn;
66
+ bc->peri_base = 0x20000000;
54
sys_readfn *readfn;
67
+ dc->realize = bcm2835_realize;
55
sys_isattyfn *isattyfn;
68
+};
56
sys_seekfn *seekfn;
69
+
57
+ sys_flenfn *flenfn;
70
static void bcm2836_class_init(ObjectClass *oc, void *data)
58
} GuestFDFunctions;
71
{
59
72
DeviceClass *dc = DEVICE_CLASS(oc);
60
static const GuestFDFunctions guestfd_fns[] = {
73
@@ -XXX,XX +XXX,XX @@ static void bcm2837_class_init(ObjectClass *oc, void *data)
61
@@ -XXX,XX +XXX,XX @@ static const GuestFDFunctions guestfd_fns[] = {
74
62
.readfn = host_readfn,
75
static const TypeInfo bcm283x_types[] = {
63
.isattyfn = host_isattyfn,
76
{
64
.seekfn = host_seekfn,
77
+ .name = TYPE_BCM2835,
65
+ .flenfn = host_flenfn,
78
+ .parent = TYPE_BCM283X,
66
},
79
+ .class_init = bcm2835_class_init,
67
[GuestFDGDB] = {
80
+ }, {
68
.closefn = gdb_closefn,
81
.name = TYPE_BCM2836,
69
@@ -XXX,XX +XXX,XX @@ static const GuestFDFunctions guestfd_fns[] = {
82
.parent = TYPE_BCM283X,
70
.readfn = gdb_readfn,
83
.class_init = bcm2836_class_init,
71
.isattyfn = gdb_isattyfn,
84
diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c
72
.seekfn = gdb_seekfn,
85
index XXXXXXX..XXXXXXX 100644
73
+ .flenfn = gdb_flenfn,
86
--- a/hw/arm/raspi.c
74
},
87
+++ b/hw/arm/raspi.c
88
@@ -XXX,XX +XXX,XX @@ FIELD(REV_CODE, MEMORY_SIZE, 20, 3);
89
FIELD(REV_CODE, STYLE, 23, 1);
90
91
typedef enum RaspiProcessorId {
92
+ PROCESSOR_ID_BCM2835 = 0,
93
PROCESSOR_ID_BCM2836 = 1,
94
PROCESSOR_ID_BCM2837 = 2,
95
} RaspiProcessorId;
96
@@ -XXX,XX +XXX,XX @@ static const struct {
97
const char *type;
98
int cores_count;
99
} soc_property[] = {
100
+ [PROCESSOR_ID_BCM2835] = {TYPE_BCM2835, 1},
101
[PROCESSOR_ID_BCM2836] = {TYPE_BCM2836, BCM283X_NCPUS},
102
[PROCESSOR_ID_BCM2837] = {TYPE_BCM2837, BCM283X_NCPUS},
75
};
103
};
76
77
@@ -XXX,XX +XXX,XX @@ target_ulong do_arm_semihosting(CPUARMState *env)
78
return set_swi_errno(env, -1);
79
}
80
81
- if (use_gdb_syscalls()) {
82
- return arm_gdb_syscall(cpu, arm_semi_flen_cb, "fstat,%x,%x",
83
- gf->hostfd, arm_flen_buf(cpu));
84
- } else {
85
- struct stat buf;
86
- ret = set_swi_errno(env, fstat(gf->hostfd, &buf));
87
- if (ret == (uint32_t)-1)
88
- return -1;
89
- return buf.st_size;
90
- }
91
+ return guestfd_fns[gf->type].flenfn(cpu, gf);
92
case TARGET_SYS_TMPNAM:
93
qemu_log_mask(LOG_UNIMP, "%s: SYS_TMPNAM not implemented", __func__);
94
return -1;
95
--
104
--
96
2.20.1
105
2.20.1
97
106
98
107
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
2
2
3
Various logging improvements as once:
3
The Pi A is almost the first machine released.
4
- Use 0x prefix for hex numbers
4
It uses a BCM2835 SoC which includes a ARMv6Z core.
5
- Display value written during write accesses
6
- Move some logs from GUEST_ERROR to UNIMP
7
5
6
Example booting the machine using content from [*]
7
(we use the device tree from the B model):
8
9
$ qemu-system-arm -M raspi1ap -serial stdio \
10
-kernel raspberrypi/firmware/boot/kernel.img \
11
-dtb raspberrypi/firmware/boot/bcm2708-rpi-b-plus.dtb \
12
-append 'earlycon=pl011,0x20201000 console=ttyAMA0'
13
[ 0.000000] Booting Linux on physical CPU 0x0
14
[ 0.000000] Linux version 4.19.118+ (dom@buildbot) (gcc version 4.9.3 (crosstool-NG crosstool-ng-1.22.0-88-g8460611)) #1311 Mon Apr 27 14:16:15 BST 2020
15
[ 0.000000] CPU: ARMv6-compatible processor [410fb767] revision 7 (ARMv7), cr=00c5387d
16
[ 0.000000] CPU: VIPT aliasing data cache, unknown instruction cache
17
[ 0.000000] OF: fdt: Machine model: Raspberry Pi Model B+
18
...
19
20
[*] http://archive.raspberrypi.org/debian/pool/main/r/raspberrypi-firmware/raspberrypi-kernel_1.20200512-2_armhf.deb
21
22
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
8
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
23
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
9
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
24
Message-id: 20201024170127.3592182-8-f4bug@amsat.org
10
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
11
Reviewed-by: Cleber Rosa <crosa@redhat.com>
12
Message-id: 20190926173428.10713-3-f4bug@amsat.org
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
25
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
14
---
26
---
15
hw/char/bcm2835_aux.c | 5 +++--
27
hw/arm/raspi.c | 13 +++++++++++++
16
hw/dma/bcm2835_dma.c | 8 ++++----
28
1 file changed, 13 insertions(+)
17
hw/intc/bcm2836_control.c | 7 ++++---
18
hw/misc/bcm2835_mbox.c | 7 ++++---
19
hw/misc/bcm2835_property.c | 16 ++++++++++------
20
5 files changed, 25 insertions(+), 18 deletions(-)
21
29
22
diff --git a/hw/char/bcm2835_aux.c b/hw/char/bcm2835_aux.c
30
diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c
23
index XXXXXXX..XXXXXXX 100644
31
index XXXXXXX..XXXXXXX 100644
24
--- a/hw/char/bcm2835_aux.c
32
--- a/hw/arm/raspi.c
25
+++ b/hw/char/bcm2835_aux.c
33
+++ b/hw/arm/raspi.c
26
@@ -XXX,XX +XXX,XX @@ static void bcm2835_aux_write(void *opaque, hwaddr offset, uint64_t value,
34
@@ -XXX,XX +XXX,XX @@ static void raspi_machine_class_common_init(MachineClass *mc,
27
switch (offset) {
35
mc->default_ram_id = "ram";
28
case AUX_ENABLES:
36
};
29
if (value != 1) {
37
30
- qemu_log_mask(LOG_UNIMP, "%s: unsupported attempt to enable SPI "
38
+static void raspi1ap_machine_class_init(ObjectClass *oc, void *data)
31
- "or disable UART\n", __func__);
39
+{
32
+ qemu_log_mask(LOG_UNIMP, "%s: unsupported attempt to enable SPI"
40
+ MachineClass *mc = MACHINE_CLASS(oc);
33
+ " or disable UART: 0x%"PRIx64"\n",
41
+ RaspiMachineClass *rmc = RASPI_MACHINE_CLASS(oc);
34
+ __func__, value);
42
+
35
}
43
+ rmc->board_rev = 0x900021; /* Revision 1.1 */
36
break;
44
+ raspi_machine_class_common_init(mc, rmc->board_rev);
37
45
+};
38
diff --git a/hw/dma/bcm2835_dma.c b/hw/dma/bcm2835_dma.c
46
+
39
index XXXXXXX..XXXXXXX 100644
47
static void raspi2b_machine_class_init(ObjectClass *oc, void *data)
40
--- a/hw/dma/bcm2835_dma.c
48
{
41
+++ b/hw/dma/bcm2835_dma.c
49
MachineClass *mc = MACHINE_CLASS(oc);
42
@@ -XXX,XX +XXX,XX @@ static uint64_t bcm2835_dma_read(BCM2835DMAState *s, hwaddr offset,
50
@@ -XXX,XX +XXX,XX @@ static void raspi3b_machine_class_init(ObjectClass *oc, void *data)
43
res = ch->debug;
51
44
break;
52
static const TypeInfo raspi_machine_types[] = {
45
default:
53
{
46
- qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset %"HWADDR_PRIx"\n",
54
+ .name = MACHINE_TYPE_NAME("raspi1ap"),
47
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%"HWADDR_PRIx"\n",
55
+ .parent = TYPE_RASPI_MACHINE,
48
__func__, offset);
56
+ .class_init = raspi1ap_machine_class_init,
49
break;
57
+ }, {
50
}
58
.name = MACHINE_TYPE_NAME("raspi2b"),
51
@@ -XXX,XX +XXX,XX @@ static void bcm2835_dma_write(BCM2835DMAState *s, hwaddr offset,
59
.parent = TYPE_RASPI_MACHINE,
52
ch->debug = value;
60
.class_init = raspi2b_machine_class_init,
53
break;
54
default:
55
- qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset %"HWADDR_PRIx"\n",
56
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%"HWADDR_PRIx"\n",
57
__func__, offset);
58
break;
59
}
60
@@ -XXX,XX +XXX,XX @@ static uint64_t bcm2835_dma0_read(void *opaque, hwaddr offset, unsigned size)
61
case BCM2708_DMA_ENABLE:
62
return s->enable;
63
default:
64
- qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset %"HWADDR_PRIx"\n",
65
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%"HWADDR_PRIx"\n",
66
__func__, offset);
67
return 0;
68
}
69
@@ -XXX,XX +XXX,XX @@ static void bcm2835_dma0_write(void *opaque, hwaddr offset, uint64_t value,
70
s->enable = (value & 0xffff);
71
break;
72
default:
73
- qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset %"HWADDR_PRIx"\n",
74
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%"HWADDR_PRIx"\n",
75
__func__, offset);
76
}
77
}
78
diff --git a/hw/intc/bcm2836_control.c b/hw/intc/bcm2836_control.c
79
index XXXXXXX..XXXXXXX 100644
80
--- a/hw/intc/bcm2836_control.c
81
+++ b/hw/intc/bcm2836_control.c
82
@@ -XXX,XX +XXX,XX @@ static uint64_t bcm2836_control_read(void *opaque, hwaddr offset, unsigned size)
83
} else if (offset >= REG_MBOX0_RDCLR && offset < REG_LIMIT) {
84
return s->mailboxes[(offset - REG_MBOX0_RDCLR) >> 2];
85
} else {
86
- qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset %"HWADDR_PRIx"\n",
87
+ qemu_log_mask(LOG_UNIMP, "%s: Unsupported offset 0x%"HWADDR_PRIx"\n",
88
__func__, offset);
89
return 0;
90
}
91
@@ -XXX,XX +XXX,XX @@ static void bcm2836_control_write(void *opaque, hwaddr offset,
92
} else if (offset >= REG_MBOX0_RDCLR && offset < REG_LIMIT) {
93
s->mailboxes[(offset - REG_MBOX0_RDCLR) >> 2] &= ~val;
94
} else {
95
- qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset %"HWADDR_PRIx"\n",
96
- __func__, offset);
97
+ qemu_log_mask(LOG_UNIMP, "%s: Unsupported offset 0x%"HWADDR_PRIx
98
+ " value 0x%"PRIx64"\n",
99
+ __func__, offset, val);
100
return;
101
}
102
103
diff --git a/hw/misc/bcm2835_mbox.c b/hw/misc/bcm2835_mbox.c
104
index XXXXXXX..XXXXXXX 100644
105
--- a/hw/misc/bcm2835_mbox.c
106
+++ b/hw/misc/bcm2835_mbox.c
107
@@ -XXX,XX +XXX,XX @@ static uint64_t bcm2835_mbox_read(void *opaque, hwaddr offset, unsigned size)
108
break;
109
110
default:
111
- qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset %"HWADDR_PRIx"\n",
112
+ qemu_log_mask(LOG_UNIMP, "%s: Unsupported offset 0x%"HWADDR_PRIx"\n",
113
__func__, offset);
114
return 0;
115
}
116
@@ -XXX,XX +XXX,XX @@ static void bcm2835_mbox_write(void *opaque, hwaddr offset,
117
break;
118
119
default:
120
- qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset %"HWADDR_PRIx"\n",
121
- __func__, offset);
122
+ qemu_log_mask(LOG_UNIMP, "%s: Unsupported offset 0x%"HWADDR_PRIx
123
+ " value 0x%"PRIx64"\n",
124
+ __func__, offset, value);
125
return;
126
}
127
128
diff --git a/hw/misc/bcm2835_property.c b/hw/misc/bcm2835_property.c
129
index XXXXXXX..XXXXXXX 100644
130
--- a/hw/misc/bcm2835_property.c
131
+++ b/hw/misc/bcm2835_property.c
132
@@ -XXX,XX +XXX,XX @@ static void bcm2835_property_mbox_push(BCM2835PropertyState *s, uint32_t value)
133
break;
134
case 0x00010001: /* Get board model */
135
qemu_log_mask(LOG_UNIMP,
136
- "bcm2835_property: %x get board model NYI\n", tag);
137
+ "bcm2835_property: 0x%08x get board model NYI\n",
138
+ tag);
139
resplen = 4;
140
break;
141
case 0x00010002: /* Get board revision */
142
@@ -XXX,XX +XXX,XX @@ static void bcm2835_property_mbox_push(BCM2835PropertyState *s, uint32_t value)
143
break;
144
case 0x00010004: /* Get board serial */
145
qemu_log_mask(LOG_UNIMP,
146
- "bcm2835_property: %x get board serial NYI\n", tag);
147
+ "bcm2835_property: 0x%08x get board serial NYI\n",
148
+ tag);
149
resplen = 8;
150
break;
151
case 0x00010005: /* Get ARM memory */
152
@@ -XXX,XX +XXX,XX @@ static void bcm2835_property_mbox_push(BCM2835PropertyState *s, uint32_t value)
153
154
case 0x00038001: /* Set clock state */
155
qemu_log_mask(LOG_UNIMP,
156
- "bcm2835_property: %x set clock state NYI\n", tag);
157
+ "bcm2835_property: 0x%08x set clock state NYI\n",
158
+ tag);
159
resplen = 8;
160
break;
161
162
@@ -XXX,XX +XXX,XX @@ static void bcm2835_property_mbox_push(BCM2835PropertyState *s, uint32_t value)
163
case 0x00038004: /* Set max clock rate */
164
case 0x00038007: /* Set min clock rate */
165
qemu_log_mask(LOG_UNIMP,
166
- "bcm2835_property: %x set clock rates NYI\n", tag);
167
+ "bcm2835_property: 0x%08x set clock rate NYI\n",
168
+ tag);
169
resplen = 8;
170
break;
171
172
@@ -XXX,XX +XXX,XX @@ static void bcm2835_property_mbox_push(BCM2835PropertyState *s, uint32_t value)
173
break;
174
175
default:
176
- qemu_log_mask(LOG_GUEST_ERROR,
177
- "bcm2835_property: unhandled tag %08x\n", tag);
178
+ qemu_log_mask(LOG_UNIMP,
179
+ "bcm2835_property: unhandled tag 0x%08x\n", tag);
180
break;
181
}
182
183
--
61
--
184
2.20.1
62
2.20.1
185
63
186
64
diff view generated by jsdifflib
1
From: Joel Stanley <joel@jms.id.au>
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
2
2
3
The AST2600 SDMC controller is slightly different from its predecessor
3
Similarly to the Pi A, the Pi Zero uses a BCM2835 SoC (ARMv6Z core).
4
(DRAM training). Max memory is now 2G on the AST2600.
5
4
6
Signed-off-by: Joel Stanley <joel@jms.id.au>
5
The only difference between the revision 1.2 and 1.3 is the latter
7
Signed-off-by: Cédric Le Goater <clg@kaod.org>
6
exposes a CSI camera connector. As we do not implement the Unicam
8
Message-id: 20190925143248.10000-10-clg@kaod.org
7
peripheral, there is no point in exposing a camera connector :)
9
[clg: - improved commit log
8
Therefore we choose to model the 1.2 revision.
10
- reworked model integration into new object class ]
9
11
Signed-off-by: Cédric Le Goater <clg@kaod.org>
10
Example booting the machine using content from [*]:
11
12
$ qemu-system-arm -M raspi0 -serial stdio \
13
-kernel raspberrypi/firmware/boot/kernel.img \
14
-dtb raspberrypi/firmware/boot/bcm2708-rpi-zero.dtb \
15
-append 'printk.time=0 earlycon=pl011,0x20201000 console=ttyAMA0'
16
[ 0.000000] Booting Linux on physical CPU 0x0
17
[ 0.000000] Linux version 4.19.118+ (dom@buildbot) (gcc version 4.9.3 (crosstool-NG crosstool-ng-1.22.0-88-g8460611)) #1311 Mon Apr 27 14:16:15 BST 2020
18
[ 0.000000] CPU: ARMv6-compatible processor [410fb767] revision 7 (ARMv7), cr=00c5387d
19
[ 0.000000] CPU: VIPT aliasing data cache, unknown instruction cache
20
[ 0.000000] OF: fdt: Machine model: Raspberry Pi Zero
21
...
22
23
[*] http://archive.raspberrypi.org/debian/pool/main/r/raspberrypi-firmware/raspberrypi-kernel_1.20200512-2_armhf.deb
24
25
Reviewed-by: Luc Michel <luc.michel@greensocs.com>
26
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
27
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
28
Message-id: 20201024170127.3592182-9-f4bug@amsat.org
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
29
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
---
30
---
14
include/hw/misc/aspeed_sdmc.h | 1 +
31
hw/arm/raspi.c | 13 +++++++++++++
15
hw/misc/aspeed_scu.c | 2 +
32
1 file changed, 13 insertions(+)
16
hw/misc/aspeed_sdmc.c | 82 +++++++++++++++++++++++++++++++++++
17
3 files changed, 85 insertions(+)
18
33
19
diff --git a/include/hw/misc/aspeed_sdmc.h b/include/hw/misc/aspeed_sdmc.h
34
diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c
20
index XXXXXXX..XXXXXXX 100644
35
index XXXXXXX..XXXXXXX 100644
21
--- a/include/hw/misc/aspeed_sdmc.h
36
--- a/hw/arm/raspi.c
22
+++ b/include/hw/misc/aspeed_sdmc.h
37
+++ b/hw/arm/raspi.c
23
@@ -XXX,XX +XXX,XX @@
38
@@ -XXX,XX +XXX,XX @@ static void raspi_machine_class_common_init(MachineClass *mc,
24
#define ASPEED_SDMC(obj) OBJECT_CHECK(AspeedSDMCState, (obj), TYPE_ASPEED_SDMC)
39
mc->default_ram_id = "ram";
25
#define TYPE_ASPEED_2400_SDMC TYPE_ASPEED_SDMC "-ast2400"
26
#define TYPE_ASPEED_2500_SDMC TYPE_ASPEED_SDMC "-ast2500"
27
+#define TYPE_ASPEED_2600_SDMC TYPE_ASPEED_SDMC "-ast2600"
28
29
#define ASPEED_SDMC_NR_REGS (0x174 >> 2)
30
31
diff --git a/hw/misc/aspeed_scu.c b/hw/misc/aspeed_scu.c
32
index XXXXXXX..XXXXXXX 100644
33
--- a/hw/misc/aspeed_scu.c
34
+++ b/hw/misc/aspeed_scu.c
35
@@ -XXX,XX +XXX,XX @@
36
#define AST2600_CLK_STOP_CTRL_CLR TO_REG(0x84)
37
#define AST2600_CLK_STOP_CTRL2 TO_REG(0x90)
38
#define AST2600_CLK_STOP_CTR2L_CLR TO_REG(0x94)
39
+#define AST2600_SDRAM_HANDSHAKE TO_REG(0x100)
40
#define AST2600_HPLL_PARAM TO_REG(0x200)
41
#define AST2600_HPLL_EXT TO_REG(0x204)
42
#define AST2600_MPLL_EXT TO_REG(0x224)
43
@@ -XXX,XX +XXX,XX @@ static const uint32_t ast2600_a0_resets[ASPEED_AST2600_SCU_NR_REGS] = {
44
[AST2600_SYS_RST_CTRL2] = 0xFFFFFFFC,
45
[AST2600_CLK_STOP_CTRL] = 0xEFF43E8B,
46
[AST2600_CLK_STOP_CTRL2] = 0xFFF0FFF0,
47
+ [AST2600_SDRAM_HANDSHAKE] = 0x00000040, /* SoC completed DRAM init */
48
[AST2600_HPLL_PARAM] = 0x1000405F,
49
};
40
};
50
41
51
diff --git a/hw/misc/aspeed_sdmc.c b/hw/misc/aspeed_sdmc.c
42
+static void raspi0_machine_class_init(ObjectClass *oc, void *data)
52
index XXXXXXX..XXXXXXX 100644
43
+{
53
--- a/hw/misc/aspeed_sdmc.c
44
+ MachineClass *mc = MACHINE_CLASS(oc);
54
+++ b/hw/misc/aspeed_sdmc.c
45
+ RaspiMachineClass *rmc = RASPI_MACHINE_CLASS(oc);
55
@@ -XXX,XX +XXX,XX @@
56
/* Control/Status Register #1 (ast2500) */
57
#define R_STATUS1 (0x60 / 4)
58
#define PHY_BUSY_STATE BIT(0)
59
+#define PHY_PLL_LOCK_STATUS BIT(4)
60
61
#define R_ECC_TEST_CTRL (0x70 / 4)
62
#define ECC_TEST_FINISHED BIT(12)
63
@@ -XXX,XX +XXX,XX @@
64
#define ASPEED_SDMC_AST2500_512MB 0x2
65
#define ASPEED_SDMC_AST2500_1024MB 0x3
66
67
+#define ASPEED_SDMC_AST2600_256MB 0x0
68
+#define ASPEED_SDMC_AST2600_512MB 0x1
69
+#define ASPEED_SDMC_AST2600_1024MB 0x2
70
+#define ASPEED_SDMC_AST2600_2048MB 0x3
71
+
46
+
72
#define ASPEED_SDMC_AST2500_READONLY_MASK \
47
+ rmc->board_rev = 0x920092; /* Revision 1.2 */
73
(ASPEED_SDMC_HW_VERSION(0xf) | ASPEED_SDMC_CACHE_INITIAL_DONE | \
48
+ raspi_machine_class_common_init(mc, rmc->board_rev);
74
ASPEED_SDMC_AST2500_RESERVED | ASPEED_SDMC_VGA_COMPAT | \
75
@@ -XXX,XX +XXX,XX @@ static int ast2500_rambits(AspeedSDMCState *s)
76
return ASPEED_SDMC_AST2500_512MB;
77
}
78
79
+static int ast2600_rambits(AspeedSDMCState *s)
80
+{
81
+ switch (s->ram_size >> 20) {
82
+ case 256:
83
+ return ASPEED_SDMC_AST2600_256MB;
84
+ case 512:
85
+ return ASPEED_SDMC_AST2600_512MB;
86
+ case 1024:
87
+ return ASPEED_SDMC_AST2600_1024MB;
88
+ case 2048:
89
+ return ASPEED_SDMC_AST2600_2048MB;
90
+ default:
91
+ break;
92
+ }
93
+
94
+ /* use a common default */
95
+ warn_report("Invalid RAM size 0x%" PRIx64 ". Using default 512M",
96
+ s->ram_size);
97
+ s->ram_size = 512 << 20;
98
+ return ASPEED_SDMC_AST2600_512MB;
99
+}
100
+
101
static void aspeed_sdmc_reset(DeviceState *dev)
102
{
103
AspeedSDMCState *s = ASPEED_SDMC(dev);
104
@@ -XXX,XX +XXX,XX @@ static const TypeInfo aspeed_2500_sdmc_info = {
105
.class_init = aspeed_2500_sdmc_class_init,
106
};
107
108
+static uint32_t aspeed_2600_sdmc_compute_conf(AspeedSDMCState *s, uint32_t data)
109
+{
110
+ uint32_t fixed_conf = ASPEED_SDMC_HW_VERSION(3) |
111
+ ASPEED_SDMC_VGA_APERTURE(ASPEED_SDMC_VGA_64MB) |
112
+ ASPEED_SDMC_DRAM_SIZE(ast2600_rambits(s));
113
+
114
+ /* Make sure readonly bits are kept (use ast2500 mask) */
115
+ data &= ~ASPEED_SDMC_AST2500_READONLY_MASK;
116
+
117
+ return data | fixed_conf;
118
+}
119
+
120
+static void aspeed_2600_sdmc_write(AspeedSDMCState *s, uint32_t reg,
121
+ uint32_t data)
122
+{
123
+ switch (reg) {
124
+ case R_CONF:
125
+ data = aspeed_2600_sdmc_compute_conf(s, data);
126
+ break;
127
+ case R_STATUS1:
128
+ /* Will never return 'busy'. 'lock status' is always set */
129
+ data &= ~PHY_BUSY_STATE;
130
+ data |= PHY_PLL_LOCK_STATUS;
131
+ break;
132
+ case R_ECC_TEST_CTRL:
133
+ /* Always done, always happy */
134
+ data |= ECC_TEST_FINISHED;
135
+ data &= ~ECC_TEST_FAIL;
136
+ break;
137
+ default:
138
+ break;
139
+ }
140
+
141
+ s->regs[reg] = data;
142
+}
143
+
144
+static void aspeed_2600_sdmc_class_init(ObjectClass *klass, void *data)
145
+{
146
+ DeviceClass *dc = DEVICE_CLASS(klass);
147
+ AspeedSDMCClass *asc = ASPEED_SDMC_CLASS(klass);
148
+
149
+ dc->desc = "ASPEED 2600 SDRAM Memory Controller";
150
+ asc->max_ram_size = 2048 << 20;
151
+ asc->compute_conf = aspeed_2600_sdmc_compute_conf;
152
+ asc->write = aspeed_2600_sdmc_write;
153
+}
154
+
155
+static const TypeInfo aspeed_2600_sdmc_info = {
156
+ .name = TYPE_ASPEED_2600_SDMC,
157
+ .parent = TYPE_ASPEED_SDMC,
158
+ .class_init = aspeed_2600_sdmc_class_init,
159
+};
49
+};
160
+
50
+
161
static void aspeed_sdmc_register_types(void)
51
static void raspi1ap_machine_class_init(ObjectClass *oc, void *data)
162
{
52
{
163
type_register_static(&aspeed_sdmc_info);
53
MachineClass *mc = MACHINE_CLASS(oc);
164
type_register_static(&aspeed_2400_sdmc_info);
54
@@ -XXX,XX +XXX,XX @@ static void raspi3b_machine_class_init(ObjectClass *oc, void *data)
165
type_register_static(&aspeed_2500_sdmc_info);
55
166
+ type_register_static(&aspeed_2600_sdmc_info);
56
static const TypeInfo raspi_machine_types[] = {
167
}
57
{
168
58
+ .name = MACHINE_TYPE_NAME("raspi0"),
169
type_init(aspeed_sdmc_register_types);
59
+ .parent = TYPE_RASPI_MACHINE,
60
+ .class_init = raspi0_machine_class_init,
61
+ }, {
62
.name = MACHINE_TYPE_NAME("raspi1ap"),
63
.parent = TYPE_RASPI_MACHINE,
64
.class_init = raspi1ap_machine_class_init,
170
--
65
--
171
2.20.1
66
2.20.1
172
67
173
68
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
2
2
3
IEC binary prefixes ease code review: the unit is explicit.
3
The Pi 3A+ is a stripped down version of the 3B:
4
- 512 MiB of RAM instead of 1 GiB
5
- no on-board ethernet chipset
4
6
7
Add it as it is a closer match to what we model.
8
9
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
5
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
10
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
6
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
11
Message-id: 20201024170127.3592182-10-f4bug@amsat.org
7
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
8
Reviewed-by: Cleber Rosa <crosa@redhat.com>
9
Message-id: 20190926173428.10713-2-f4bug@amsat.org
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
---
13
---
12
hw/arm/raspi.c | 4 ++--
14
hw/arm/raspi.c | 13 +++++++++++++
13
1 file changed, 2 insertions(+), 2 deletions(-)
15
1 file changed, 13 insertions(+)
14
16
15
diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c
17
diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c
16
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
17
--- a/hw/arm/raspi.c
19
--- a/hw/arm/raspi.c
18
+++ b/hw/arm/raspi.c
20
+++ b/hw/arm/raspi.c
19
@@ -XXX,XX +XXX,XX @@ static void raspi2_machine_init(MachineClass *mc)
21
@@ -XXX,XX +XXX,XX @@ static void raspi2b_machine_class_init(ObjectClass *oc, void *data)
20
mc->max_cpus = BCM283X_NCPUS;
21
mc->min_cpus = BCM283X_NCPUS;
22
mc->default_cpus = BCM283X_NCPUS;
23
- mc->default_ram_size = 1024 * 1024 * 1024;
24
+ mc->default_ram_size = 1 * GiB;
25
mc->ignore_memory_transaction_failures = true;
26
};
22
};
27
DEFINE_MACHINE("raspi2", raspi2_machine_init)
23
28
@@ -XXX,XX +XXX,XX @@ static void raspi3_machine_init(MachineClass *mc)
24
#ifdef TARGET_AARCH64
29
mc->max_cpus = BCM283X_NCPUS;
25
+static void raspi3ap_machine_class_init(ObjectClass *oc, void *data)
30
mc->min_cpus = BCM283X_NCPUS;
26
+{
31
mc->default_cpus = BCM283X_NCPUS;
27
+ MachineClass *mc = MACHINE_CLASS(oc);
32
- mc->default_ram_size = 1024 * 1024 * 1024;
28
+ RaspiMachineClass *rmc = RASPI_MACHINE_CLASS(oc);
33
+ mc->default_ram_size = 1 * GiB;
29
+
34
}
30
+ rmc->board_rev = 0x9020e0; /* Revision 1.0 */
35
DEFINE_MACHINE("raspi3", raspi3_machine_init)
31
+ raspi_machine_class_common_init(mc, rmc->board_rev);
36
#endif
32
+};
33
+
34
static void raspi3b_machine_class_init(ObjectClass *oc, void *data)
35
{
36
MachineClass *mc = MACHINE_CLASS(oc);
37
@@ -XXX,XX +XXX,XX @@ static const TypeInfo raspi_machine_types[] = {
38
.parent = TYPE_RASPI_MACHINE,
39
.class_init = raspi2b_machine_class_init,
40
#ifdef TARGET_AARCH64
41
+ }, {
42
+ .name = MACHINE_TYPE_NAME("raspi3ap"),
43
+ .parent = TYPE_RASPI_MACHINE,
44
+ .class_init = raspi3ap_machine_class_init,
45
}, {
46
.name = MACHINE_TYPE_NAME("raspi3b"),
47
.parent = TYPE_RASPI_MACHINE,
37
--
48
--
38
2.20.1
49
2.20.1
39
50
40
51
diff view generated by jsdifflib
1
From: Amithash Prasad <amithash@fb.com>
1
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
2
2
3
When WDT_RESTART is written, the data is not the contents
3
Use of 0x%d - make up our mind as 0x%x
4
of the WDT_CTRL register. Hence ensure we are looking at
5
WDT_CTRL to check if bit WDT_CTRL_1MHZ_CLK is set or not.
6
4
7
Signed-off-by: Amithash Prasad <amithash@fb.com>
5
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
8
Reviewed-by: Joel Stanley <joel@jms.id.au>
6
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
9
Signed-off-by: Cédric Le Goater <clg@kaod.org>
7
Acked-by: Eric Auger <eric.auger@redhat.com>
10
Message-id: 20190925143248.10000-2-clg@kaod.org
8
Message-id: 20201014193355.53074-1-dgilbert@redhat.com
11
[clg: improved Suject prefix ]
12
Signed-off-by: Cédric Le Goater <clg@kaod.org>
13
Reviewed-by: Joel Stanley <joel@jms.id.au>
14
Signed-off-by: Cédric Le Goater <clg@kaod.org>
15
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
16
---
10
---
17
hw/watchdog/wdt_aspeed.c | 2 +-
11
hw/arm/trace-events | 2 +-
18
1 file changed, 1 insertion(+), 1 deletion(-)
12
1 file changed, 1 insertion(+), 1 deletion(-)
19
13
20
diff --git a/hw/watchdog/wdt_aspeed.c b/hw/watchdog/wdt_aspeed.c
14
diff --git a/hw/arm/trace-events b/hw/arm/trace-events
21
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
22
--- a/hw/watchdog/wdt_aspeed.c
16
--- a/hw/arm/trace-events
23
+++ b/hw/watchdog/wdt_aspeed.c
17
+++ b/hw/arm/trace-events
24
@@ -XXX,XX +XXX,XX @@ static void aspeed_wdt_write(void *opaque, hwaddr offset, uint64_t data,
18
@@ -XXX,XX +XXX,XX @@ smmuv3_get_cd(uint64_t addr) "CD addr: 0x%"PRIx64
25
case WDT_RESTART:
19
smmuv3_decode_cd(uint32_t oas) "oas=%d"
26
if ((data & 0xFFFF) == WDT_RESTART_MAGIC) {
20
smmuv3_decode_cd_tt(int i, uint32_t tsz, uint64_t ttb, uint32_t granule_sz, bool had) "TT[%d]:tsz:%d ttb:0x%"PRIx64" granule_sz:%d had:%d"
27
s->regs[WDT_STATUS] = s->regs[WDT_RELOAD_VALUE];
21
smmuv3_cmdq_cfgi_ste(int streamid) "streamid =%d"
28
- aspeed_wdt_reload(s, !(data & WDT_CTRL_1MHZ_CLK));
22
-smmuv3_cmdq_cfgi_ste_range(int start, int end) "start=0x%d - end=0x%d"
29
+ aspeed_wdt_reload(s, !(s->regs[WDT_CTRL] & WDT_CTRL_1MHZ_CLK));
23
+smmuv3_cmdq_cfgi_ste_range(int start, int end) "start=0x%x - end=0x%x"
30
}
24
smmuv3_cmdq_cfgi_cd(uint32_t sid) "streamid = %d"
31
break;
25
smmuv3_config_cache_hit(uint32_t sid, uint32_t hits, uint32_t misses, uint32_t perc) "Config cache HIT for sid %d (hits=%d, misses=%d, hit rate=%d)"
32
case WDT_CTRL:
26
smmuv3_config_cache_miss(uint32_t sid, uint32_t hits, uint32_t misses, uint32_t perc) "Config cache MISS for sid %d (hits=%d, misses=%d, hit rate=%d)"
33
--
27
--
34
2.20.1
28
2.20.1
35
29
36
30
diff view generated by jsdifflib
1
SH_EXT_EXIT_EXTENDED is a v2.0 semihosting extension: it
1
From: Luc Michel <luc@lmichel.fr>
2
indicates that the implementation supports the SYS_EXIT_EXTENDED
3
function. This function allows both A64 and A32/T32 guests to
4
exit with a specified exit status, unlike the older SYS_EXIT
5
function which only allowed this for A64 guests. Implement
6
this extension.
7
2
3
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
4
Reviewed-by: Damien Hedde <damien.hedde@greensocs.com>
5
Signed-off-by: Luc Michel <luc@lmichel.fr>
6
Tested-by: Guenter Roeck <linux@roeck-us.net>
7
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
10
Message-id: 20190916141544.17540-15-peter.maydell@linaro.org
11
---
9
---
12
target/arm/arm-semi.c | 19 ++++++++++++++-----
10
include/hw/clock.h | 5 +++++
13
1 file changed, 14 insertions(+), 5 deletions(-)
11
1 file changed, 5 insertions(+)
14
12
15
diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c
13
diff --git a/include/hw/clock.h b/include/hw/clock.h
16
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
17
--- a/target/arm/arm-semi.c
15
--- a/include/hw/clock.h
18
+++ b/target/arm/arm-semi.c
16
+++ b/include/hw/clock.h
19
@@ -XXX,XX +XXX,XX @@
17
@@ -XXX,XX +XXX,XX @@ extern const VMStateDescription vmstate_clock;
20
#define TARGET_SYS_HEAPINFO 0x16
18
VMSTATE_CLOCK_V(field, state, 0)
21
#define TARGET_SYS_EXIT 0x18
19
#define VMSTATE_CLOCK_V(field, state, version) \
22
#define TARGET_SYS_SYNCCACHE 0x19
20
VMSTATE_STRUCT_POINTER_V(field, state, version, vmstate_clock, Clock)
23
+#define TARGET_SYS_EXIT_EXTENDED 0x20
21
+#define VMSTATE_ARRAY_CLOCK(field, state, num) \
24
22
+ VMSTATE_ARRAY_CLOCK_V(field, state, num, 0)
25
/* ADP_Stopped_ApplicationExit is used for exit(0),
23
+#define VMSTATE_ARRAY_CLOCK_V(field, state, num, version) \
26
* anything else is implemented as exit(1) */
24
+ VMSTATE_ARRAY_OF_POINTER_TO_STRUCT(field, state, num, version, \
27
@@ -XXX,XX +XXX,XX @@ static uint32_t gdb_flenfn(ARMCPU *cpu, GuestFD *gf)
25
+ vmstate_clock, Clock)
28
#define SHFB_MAGIC_2 0x46
26
29
#define SHFB_MAGIC_3 0x42
27
/**
30
28
* clock_setup_canonical_path:
31
+/* Feature bits reportable in feature byte 0 */
32
+#define SH_EXT_EXIT_EXTENDED (1 << 0)
33
+
34
static const uint8_t featurefile_data[] = {
35
SHFB_MAGIC_0,
36
SHFB_MAGIC_1,
37
SHFB_MAGIC_2,
38
SHFB_MAGIC_3,
39
- 0, /* Feature byte 0 */
40
+ SH_EXT_EXIT_EXTENDED, /* Feature byte 0 */
41
};
42
43
static void init_featurefile_guestfd(int guestfd)
44
@@ -XXX,XX +XXX,XX @@ target_ulong do_arm_semihosting(CPUARMState *env)
45
return 0;
46
}
47
case TARGET_SYS_EXIT:
48
- if (is_a64(env)) {
49
+ case TARGET_SYS_EXIT_EXTENDED:
50
+ if (nr == TARGET_SYS_EXIT_EXTENDED || is_a64(env)) {
51
/*
52
- * The A64 version of this call takes a parameter block,
53
+ * The A64 version of SYS_EXIT takes a parameter block,
54
* so the application-exit type can return a subcode which
55
* is the exit status code from the application.
56
+ * SYS_EXIT_EXTENDED is an a new-in-v2.0 optional function
57
+ * which allows A32/T32 guests to also provide a status code.
58
*/
59
GET_ARG(0);
60
GET_ARG(1);
61
@@ -XXX,XX +XXX,XX @@ target_ulong do_arm_semihosting(CPUARMState *env)
62
}
63
} else {
64
/*
65
- * ARM specifies only Stopped_ApplicationExit as normal
66
- * exit, everything else is considered an error
67
+ * The A32/T32 version of SYS_EXIT specifies only
68
+ * Stopped_ApplicationExit as normal exit, but does not
69
+ * allow the guest to specify the exit status code.
70
+ * Everything else is considered an error.
71
*/
72
ret = (args == ADP_Stopped_ApplicationExit) ? 0 : 1;
73
}
74
--
29
--
75
2.20.1
30
2.20.1
76
31
77
32
diff view generated by jsdifflib
1
From: Cédric Le Goater <clg@kaod.org>
1
From: Luc Michel <luc@lmichel.fr>
2
2
3
The AST2500 timer has a third control register that is used to
3
The nanosecond unit greatly limits the dynamic range we can display in
4
implement a set-to-clear feature for the main control register.
4
clock value traces, for values in the order of 1GHz and more. The
5
internal representation can go way beyond this value and it is quite
6
common for today's clocks to be within those ranges.
5
7
6
This models the behaviour expected by the AST2500 while maintaining
8
For example, a frequency between 500MHz+ and 1GHz will be displayed as
7
the same behaviour for the AST2400.
9
1ns. Beyond 1GHz, it will show up as 0ns.
8
10
9
The vmstate version is not increased yet because the structure is
11
Replace nanosecond periods traces with frequencies in the Hz unit
10
modified again in the following patches.
12
to have more dynamic range in the trace output.
11
13
12
Based on previous work from Joel Stanley.
14
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
13
15
Reviewed-by: Damien Hedde <damien.hedde@greensocs.com>
14
Signed-off-by: Cédric Le Goater <clg@kaod.org>
16
Signed-off-by: Luc Michel <luc@lmichel.fr>
15
Reviewed-by: Joel Stanley <joel@jms.id.au>
17
Tested-by: Guenter Roeck <linux@roeck-us.net>
16
Message-id: 20190925143248.10000-6-clg@kaod.org
18
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
17
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
19
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
18
---
20
---
19
include/hw/timer/aspeed_timer.h | 1 +
21
hw/core/clock.c | 6 +++---
20
hw/timer/aspeed_timer.c | 19 +++++++++++++++++++
22
hw/core/trace-events | 4 ++--
21
2 files changed, 20 insertions(+)
23
2 files changed, 5 insertions(+), 5 deletions(-)
22
24
23
diff --git a/include/hw/timer/aspeed_timer.h b/include/hw/timer/aspeed_timer.h
25
diff --git a/hw/core/clock.c b/hw/core/clock.c
24
index XXXXXXX..XXXXXXX 100644
26
index XXXXXXX..XXXXXXX 100644
25
--- a/include/hw/timer/aspeed_timer.h
27
--- a/hw/core/clock.c
26
+++ b/include/hw/timer/aspeed_timer.h
28
+++ b/hw/core/clock.c
27
@@ -XXX,XX +XXX,XX @@ typedef struct AspeedTimerCtrlState {
29
@@ -XXX,XX +XXX,XX @@ bool clock_set(Clock *clk, uint64_t period)
28
30
if (clk->period == period) {
29
uint32_t ctrl;
31
return false;
30
uint32_t ctrl2;
32
}
31
+ uint32_t ctrl3;
33
- trace_clock_set(CLOCK_PATH(clk), CLOCK_PERIOD_TO_NS(clk->period),
32
AspeedTimer timers[ASPEED_TIMER_NR_TIMERS];
34
- CLOCK_PERIOD_TO_NS(period));
33
35
+ trace_clock_set(CLOCK_PATH(clk), CLOCK_PERIOD_TO_HZ(clk->period),
34
AspeedSCUState *scu;
36
+ CLOCK_PERIOD_TO_HZ(period));
35
diff --git a/hw/timer/aspeed_timer.c b/hw/timer/aspeed_timer.c
37
clk->period = period;
38
39
return true;
40
@@ -XXX,XX +XXX,XX @@ static void clock_propagate_period(Clock *clk, bool call_callbacks)
41
if (child->period != clk->period) {
42
child->period = clk->period;
43
trace_clock_update(CLOCK_PATH(child), CLOCK_PATH(clk),
44
- CLOCK_PERIOD_TO_NS(clk->period),
45
+ CLOCK_PERIOD_TO_HZ(clk->period),
46
call_callbacks);
47
if (call_callbacks && child->callback) {
48
child->callback(child->callback_opaque);
49
diff --git a/hw/core/trace-events b/hw/core/trace-events
36
index XXXXXXX..XXXXXXX 100644
50
index XXXXXXX..XXXXXXX 100644
37
--- a/hw/timer/aspeed_timer.c
51
--- a/hw/core/trace-events
38
+++ b/hw/timer/aspeed_timer.c
52
+++ b/hw/core/trace-events
39
@@ -XXX,XX +XXX,XX @@ static uint64_t aspeed_2500_timer_read(AspeedTimerCtrlState *s, hwaddr offset)
53
@@ -XXX,XX +XXX,XX @@ resettable_transitional_function(void *obj, const char *objtype) "obj=%p(%s)"
40
54
# clock.c
41
switch (offset) {
55
clock_set_source(const char *clk, const char *src) "'%s', src='%s'"
42
case 0x38:
56
clock_disconnect(const char *clk) "'%s'"
43
+ value = s->ctrl3 & BIT(0);
57
-clock_set(const char *clk, uint64_t old, uint64_t new) "'%s', ns=%"PRIu64"->%"PRIu64
44
+ break;
58
+clock_set(const char *clk, uint64_t old, uint64_t new) "'%s', %"PRIu64"Hz->%"PRIu64"Hz"
45
case 0x3C:
59
clock_propagate(const char *clk) "'%s'"
46
default:
60
-clock_update(const char *clk, const char *src, uint64_t val, int cb) "'%s', src='%s', ns=%"PRIu64", cb=%d"
47
qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%" HWADDR_PRIx "\n",
61
+clock_update(const char *clk, const char *src, uint64_t hz, int cb) "'%s', src='%s', val=%"PRIu64"Hz cb=%d"
48
@@ -XXX,XX +XXX,XX @@ static uint64_t aspeed_2500_timer_read(AspeedTimerCtrlState *s, hwaddr offset)
49
static void aspeed_2500_timer_write(AspeedTimerCtrlState *s, hwaddr offset,
50
uint64_t value)
51
{
52
+ const uint32_t tv = (uint32_t)(value & 0xFFFFFFFF);
53
+ uint8_t command;
54
+
55
switch (offset) {
56
case 0x38:
57
+ command = (value >> 1) & 0xFF;
58
+ if (command == 0xAE) {
59
+ s->ctrl3 = 0x1;
60
+ } else if (command == 0xEA) {
61
+ s->ctrl3 = 0x0;
62
+ }
63
+ break;
64
case 0x3C:
65
+ if (s->ctrl3 & BIT(0)) {
66
+ aspeed_timer_set_ctrl(s, s->ctrl & ~tv);
67
+ }
68
+ break;
69
+
70
default:
71
qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%" HWADDR_PRIx "\n",
72
__func__, offset);
73
@@ -XXX,XX +XXX,XX @@ static void aspeed_timer_reset(DeviceState *dev)
74
}
75
s->ctrl = 0;
76
s->ctrl2 = 0;
77
+ s->ctrl3 = 0;
78
}
79
80
static const VMStateDescription vmstate_aspeed_timer = {
81
@@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_aspeed_timer_state = {
82
.fields = (VMStateField[]) {
83
VMSTATE_UINT32(ctrl, AspeedTimerCtrlState),
84
VMSTATE_UINT32(ctrl2, AspeedTimerCtrlState),
85
+ VMSTATE_UINT32(ctrl3, AspeedTimerCtrlState),
86
VMSTATE_STRUCT_ARRAY(timers, AspeedTimerCtrlState,
87
ASPEED_TIMER_NR_TIMERS, 1, vmstate_aspeed_timer,
88
AspeedTimer),
89
--
62
--
90
2.20.1
63
2.20.1
91
64
92
65
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
1
From: Luc Michel <luc@lmichel.fr>
2
2
3
Base addresses and sizes taken from the "BCM2835 ARM Peripherals"
3
The CPRMAN (clock controller) was mapped at the watchdog/power manager
4
datasheet from February 06 2012:
4
address. It was also split into two unimplemented peripherals (CM and
5
https://www.raspberrypi.org/app/uploads/2012/02/BCM2835-ARM-Peripherals.pdf
5
A2W) but this is really the same one, as shown by this extract of the
6
Raspberry Pi 3 Linux device tree:
6
7
7
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
8
watchdog@7e100000 {
8
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
9
compatible = "brcm,bcm2835-pm\0brcm,bcm2835-pm-wdt";
9
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
10
[...]
10
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
11
reg = <0x7e100000 0x114 0x7e00a000 0x24>;
11
Message-id: 20190926173428.10713-6-f4bug@amsat.org
12
[...]
13
};
14
15
[...]
16
cprman@7e101000 {
17
compatible = "brcm,bcm2835-cprman";
18
[...]
19
reg = <0x7e101000 0x2000>;
20
[...]
21
};
22
23
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
24
Signed-off-by: Luc Michel <luc@lmichel.fr>
25
Tested-by: Guenter Roeck <linux@roeck-us.net>
26
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
27
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
---
28
---
14
include/hw/arm/bcm2835_peripherals.h | 15 ++++++++++++++
29
include/hw/arm/bcm2835_peripherals.h | 2 +-
15
include/hw/arm/raspi_platform.h | 8 +++++++
30
include/hw/arm/raspi_platform.h | 5 ++---
16
hw/arm/bcm2835_peripherals.c | 31 ++++++++++++++++++++++++++++
31
hw/arm/bcm2835_peripherals.c | 4 ++--
17
3 files changed, 54 insertions(+)
32
3 files changed, 5 insertions(+), 6 deletions(-)
18
33
19
diff --git a/include/hw/arm/bcm2835_peripherals.h b/include/hw/arm/bcm2835_peripherals.h
34
diff --git a/include/hw/arm/bcm2835_peripherals.h b/include/hw/arm/bcm2835_peripherals.h
20
index XXXXXXX..XXXXXXX 100644
35
index XXXXXXX..XXXXXXX 100644
21
--- a/include/hw/arm/bcm2835_peripherals.h
36
--- a/include/hw/arm/bcm2835_peripherals.h
22
+++ b/include/hw/arm/bcm2835_peripherals.h
37
+++ b/include/hw/arm/bcm2835_peripherals.h
23
@@ -XXX,XX +XXX,XX @@
38
@@ -XXX,XX +XXX,XX @@ struct BCM2835PeripheralState {
24
#include "hw/sd/sdhci.h"
39
BCM2835MphiState mphi;
25
#include "hw/sd/bcm2835_sdhost.h"
40
UnimplementedDeviceState txp;
26
#include "hw/gpio/bcm2835_gpio.h"
41
UnimplementedDeviceState armtmr;
27
+#include "hw/misc/unimp.h"
42
+ UnimplementedDeviceState powermgt;
28
43
UnimplementedDeviceState cprman;
29
#define TYPE_BCM2835_PERIPHERALS "bcm2835-peripherals"
44
- UnimplementedDeviceState a2w;
30
#define BCM2835_PERIPHERALS(obj) \
31
@@ -XXX,XX +XXX,XX @@ typedef struct BCM2835PeripheralState {
32
MemoryRegion ram_alias[4];
33
qemu_irq irq, fiq;
34
35
+ UnimplementedDeviceState systmr;
36
+ UnimplementedDeviceState armtmr;
37
+ UnimplementedDeviceState cprman;
38
+ UnimplementedDeviceState a2w;
39
PL011State uart0;
45
PL011State uart0;
40
BCM2835AuxState aux;
46
BCM2835AuxState aux;
41
BCM2835FBState fb;
47
BCM2835FBState fb;
42
@@ -XXX,XX +XXX,XX @@ typedef struct BCM2835PeripheralState {
43
SDHCIState sdhci;
44
BCM2835SDHostState sdhost;
45
BCM2835GpioState gpio;
46
+ UnimplementedDeviceState i2s;
47
+ UnimplementedDeviceState spi[1];
48
+ UnimplementedDeviceState i2c[3];
49
+ UnimplementedDeviceState otp;
50
+ UnimplementedDeviceState dbus;
51
+ UnimplementedDeviceState ave0;
52
+ UnimplementedDeviceState bscsl;
53
+ UnimplementedDeviceState smi;
54
+ UnimplementedDeviceState dwc2;
55
+ UnimplementedDeviceState sdramc;
56
} BCM2835PeripheralState;
57
58
#endif /* BCM2835_PERIPHERALS_H */
59
diff --git a/include/hw/arm/raspi_platform.h b/include/hw/arm/raspi_platform.h
48
diff --git a/include/hw/arm/raspi_platform.h b/include/hw/arm/raspi_platform.h
60
index XXXXXXX..XXXXXXX 100644
49
index XXXXXXX..XXXXXXX 100644
61
--- a/include/hw/arm/raspi_platform.h
50
--- a/include/hw/arm/raspi_platform.h
62
+++ b/include/hw/arm/raspi_platform.h
51
+++ b/include/hw/arm/raspi_platform.h
63
@@ -XXX,XX +XXX,XX @@
52
@@ -XXX,XX +XXX,XX @@
53
#define ARMCTRL_TIMER0_1_OFFSET (ARM_OFFSET + 0x400) /* Timer 0 and 1 (SP804) */
54
#define ARMCTRL_0_SBM_OFFSET (ARM_OFFSET + 0x800) /* User 0 (ARM) Semaphores
64
* Doorbells & Mailboxes */
55
* Doorbells & Mailboxes */
65
#define CPRMAN_OFFSET 0x100000 /* Power Management, Watchdog */
56
-#define CPRMAN_OFFSET 0x100000 /* Power Management, Watchdog */
66
#define CM_OFFSET 0x101000 /* Clock Management */
57
-#define CM_OFFSET 0x101000 /* Clock Management */
67
+#define A2W_OFFSET 0x102000 /* Reset controller */
58
-#define A2W_OFFSET 0x102000 /* Reset controller */
68
+#define AVS_OFFSET 0x103000 /* Audio Video Standard */
59
+#define PM_OFFSET 0x100000 /* Power Management */
60
+#define CPRMAN_OFFSET 0x101000 /* Clock Management */
61
#define AVS_OFFSET 0x103000 /* Audio Video Standard */
69
#define RNG_OFFSET 0x104000
62
#define RNG_OFFSET 0x104000
70
#define GPIO_OFFSET 0x200000
63
#define GPIO_OFFSET 0x200000
71
#define UART0_OFFSET 0x201000
72
@@ -XXX,XX +XXX,XX @@
73
#define I2S_OFFSET 0x203000
74
#define SPI0_OFFSET 0x204000
75
#define BSC0_OFFSET 0x205000 /* BSC0 I2C/TWI */
76
+#define OTP_OFFSET 0x20f000
77
+#define BSC_SL_OFFSET 0x214000 /* SPI slave */
78
#define AUX_OFFSET 0x215000 /* AUX: UART1/SPI1/SPI2 */
79
#define EMMC1_OFFSET 0x300000
80
#define SMI_OFFSET 0x600000
81
#define BSC1_OFFSET 0x804000 /* BSC1 I2C/TWI */
82
+#define BSC2_OFFSET 0x805000 /* BSC2 I2C/TWI */
83
+#define DBUS_OFFSET 0x900000
84
+#define AVE0_OFFSET 0x910000
85
#define USB_OTG_OFFSET 0x980000 /* DTC_OTG USB controller */
86
+#define SDRAMC_OFFSET 0xe00000
87
#define DMA15_OFFSET 0xE05000 /* DMA controller, channel 15 */
88
89
/* GPU interrupts */
90
diff --git a/hw/arm/bcm2835_peripherals.c b/hw/arm/bcm2835_peripherals.c
64
diff --git a/hw/arm/bcm2835_peripherals.c b/hw/arm/bcm2835_peripherals.c
91
index XXXXXXX..XXXXXXX 100644
65
index XXXXXXX..XXXXXXX 100644
92
--- a/hw/arm/bcm2835_peripherals.c
66
--- a/hw/arm/bcm2835_peripherals.c
93
+++ b/hw/arm/bcm2835_peripherals.c
67
+++ b/hw/arm/bcm2835_peripherals.c
94
@@ -XXX,XX +XXX,XX @@
95
/* Capabilities for SD controller: no DMA, high-speed, default clocks etc. */
96
#define BCM2835_SDHC_CAPAREG 0x52134b4
97
98
+static void create_unimp(BCM2835PeripheralState *ps,
99
+ UnimplementedDeviceState *uds,
100
+ const char *name, hwaddr ofs, hwaddr size)
101
+{
102
+ sysbus_init_child_obj(OBJECT(ps), name, uds,
103
+ sizeof(UnimplementedDeviceState),
104
+ TYPE_UNIMPLEMENTED_DEVICE);
105
+ qdev_prop_set_string(DEVICE(uds), "name", name);
106
+ qdev_prop_set_uint64(DEVICE(uds), "size", size);
107
+ object_property_set_bool(OBJECT(uds), true, "realized", &error_fatal);
108
+ memory_region_add_subregion_overlap(&ps->peri_mr, ofs,
109
+ sysbus_mmio_get_region(SYS_BUS_DEVICE(uds), 0), -1000);
110
+}
111
+
112
static void bcm2835_peripherals_init(Object *obj)
113
{
114
BCM2835PeripheralState *s = BCM2835_PERIPHERALS(obj);
115
@@ -XXX,XX +XXX,XX @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)
68
@@ -XXX,XX +XXX,XX @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)
116
error_propagate(errp, err);
69
117
return;
70
create_unimp(s, &s->txp, "bcm2835-txp", TXP_OFFSET, 0x1000);
118
}
71
create_unimp(s, &s->armtmr, "bcm2835-sp804", ARMCTRL_TIMER0_1_OFFSET, 0x40);
119
+
72
- create_unimp(s, &s->cprman, "bcm2835-cprman", CPRMAN_OFFSET, 0x1000);
120
+ create_unimp(s, &s->armtmr, "bcm2835-sp804", ARMCTRL_TIMER0_1_OFFSET, 0x40);
73
- create_unimp(s, &s->a2w, "bcm2835-a2w", A2W_OFFSET, 0x1000);
121
+ create_unimp(s, &s->systmr, "bcm2835-systimer", ST_OFFSET, 0x20);
74
+ create_unimp(s, &s->powermgt, "bcm2835-powermgt", PM_OFFSET, 0x114);
122
+ create_unimp(s, &s->cprman, "bcm2835-cprman", CPRMAN_OFFSET, 0x1000);
75
+ create_unimp(s, &s->cprman, "bcm2835-cprman", CPRMAN_OFFSET, 0x2000);
123
+ create_unimp(s, &s->a2w, "bcm2835-a2w", A2W_OFFSET, 0x1000);
76
create_unimp(s, &s->i2s, "bcm2835-i2s", I2S_OFFSET, 0x100);
124
+ create_unimp(s, &s->i2s, "bcm2835-i2s", I2S_OFFSET, 0x100);
77
create_unimp(s, &s->smi, "bcm2835-smi", SMI_OFFSET, 0x100);
125
+ create_unimp(s, &s->smi, "bcm2835-smi", SMI_OFFSET, 0x100);
78
create_unimp(s, &s->spi[0], "bcm2835-spi0", SPI0_OFFSET, 0x20);
126
+ create_unimp(s, &s->spi[0], "bcm2835-spi0", SPI0_OFFSET, 0x20);
127
+ create_unimp(s, &s->bscsl, "bcm2835-spis", BSC_SL_OFFSET, 0x100);
128
+ create_unimp(s, &s->i2c[0], "bcm2835-i2c0", BSC0_OFFSET, 0x20);
129
+ create_unimp(s, &s->i2c[1], "bcm2835-i2c1", BSC1_OFFSET, 0x20);
130
+ create_unimp(s, &s->i2c[2], "bcm2835-i2c2", BSC2_OFFSET, 0x20);
131
+ create_unimp(s, &s->otp, "bcm2835-otp", OTP_OFFSET, 0x80);
132
+ create_unimp(s, &s->dbus, "bcm2835-dbus", DBUS_OFFSET, 0x8000);
133
+ create_unimp(s, &s->ave0, "bcm2835-ave0", AVE0_OFFSET, 0x8000);
134
+ create_unimp(s, &s->dwc2, "dwc-usb2", USB_OTG_OFFSET, 0x1000);
135
+ create_unimp(s, &s->sdramc, "bcm2835-sdramc", SDRAMC_OFFSET, 0x100);
136
}
137
138
static void bcm2835_peripherals_class_init(ObjectClass *oc, void *data)
139
--
79
--
140
2.20.1
80
2.20.1
141
81
142
82
diff view generated by jsdifflib
1
From: Cédric Le Goater <clg@kaod.org>
1
From: Luc Michel <luc@lmichel.fr>
2
2
3
The AST2600 SoC has an extra controller to set the PHY registers.
3
The BCM2835 CPRMAN is the clock manager of the SoC. It is composed of a
4
4
main oscillator, and several sub-components (PLLs, multiplexers, ...) to
5
Signed-off-by: Cédric Le Goater <clg@kaod.org>
5
generate the BCM2835 clock tree.
6
Reviewed-by: Joel Stanley <joel@jms.id.au>
6
7
Message-id: 20190925143248.10000-23-clg@kaod.org
7
This commit adds a skeleton of the CPRMAN, with a dummy register
8
read/write implementation. It embeds the main oscillator (xosc) from
9
which all the clocks will be derived.
10
11
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
12
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
13
Signed-off-by: Luc Michel <luc@lmichel.fr>
14
Tested-by: Guenter Roeck <linux@roeck-us.net>
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
15
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
---
16
---
10
include/hw/arm/aspeed_soc.h | 5 ++
17
include/hw/arm/bcm2835_peripherals.h | 3 +-
11
include/hw/net/ftgmac100.h | 17 ++++
18
include/hw/misc/bcm2835_cprman.h | 37 +++++
12
hw/arm/aspeed_ast2600.c | 20 +++++
19
include/hw/misc/bcm2835_cprman_internals.h | 24 +++
13
hw/net/ftgmac100.c | 162 ++++++++++++++++++++++++++++++++++++
20
hw/arm/bcm2835_peripherals.c | 11 +-
14
4 files changed, 204 insertions(+)
21
hw/misc/bcm2835_cprman.c | 163 +++++++++++++++++++++
15
22
hw/misc/meson.build | 1 +
16
diff --git a/include/hw/arm/aspeed_soc.h b/include/hw/arm/aspeed_soc.h
23
hw/misc/trace-events | 5 +
24
7 files changed, 242 insertions(+), 2 deletions(-)
25
create mode 100644 include/hw/misc/bcm2835_cprman.h
26
create mode 100644 include/hw/misc/bcm2835_cprman_internals.h
27
create mode 100644 hw/misc/bcm2835_cprman.c
28
29
diff --git a/include/hw/arm/bcm2835_peripherals.h b/include/hw/arm/bcm2835_peripherals.h
17
index XXXXXXX..XXXXXXX 100644
30
index XXXXXXX..XXXXXXX 100644
18
--- a/include/hw/arm/aspeed_soc.h
31
--- a/include/hw/arm/bcm2835_peripherals.h
19
+++ b/include/hw/arm/aspeed_soc.h
32
+++ b/include/hw/arm/bcm2835_peripherals.h
20
@@ -XXX,XX +XXX,XX @@ typedef struct AspeedSoCState {
33
@@ -XXX,XX +XXX,XX @@
21
AspeedSDMCState sdmc;
34
#include "hw/misc/bcm2835_mbox.h"
22
AspeedWDTState wdt[ASPEED_WDTS_NUM];
35
#include "hw/misc/bcm2835_mphi.h"
23
FTGMAC100State ftgmac100[ASPEED_MACS_NUM];
36
#include "hw/misc/bcm2835_thermal.h"
24
+ AspeedMiiState mii[ASPEED_MACS_NUM];
37
+#include "hw/misc/bcm2835_cprman.h"
25
AspeedGPIOState gpio;
38
#include "hw/sd/sdhci.h"
26
AspeedGPIOState gpio_1_8v;
39
#include "hw/sd/bcm2835_sdhost.h"
27
AspeedSDHCIState sdhci;
40
#include "hw/gpio/bcm2835_gpio.h"
28
@@ -XXX,XX +XXX,XX @@ enum {
41
@@ -XXX,XX +XXX,XX @@ struct BCM2835PeripheralState {
29
ASPEED_ETH2,
42
UnimplementedDeviceState txp;
30
ASPEED_ETH3,
43
UnimplementedDeviceState armtmr;
31
ASPEED_ETH4,
44
UnimplementedDeviceState powermgt;
32
+ ASPEED_MII1,
45
- UnimplementedDeviceState cprman;
33
+ ASPEED_MII2,
46
+ BCM2835CprmanState cprman;
34
+ ASPEED_MII3,
47
PL011State uart0;
35
+ ASPEED_MII4,
48
BCM2835AuxState aux;
36
ASPEED_SDRAM,
49
BCM2835FBState fb;
37
ASPEED_XDMA,
50
diff --git a/include/hw/misc/bcm2835_cprman.h b/include/hw/misc/bcm2835_cprman.h
38
};
51
new file mode 100644
39
diff --git a/include/hw/net/ftgmac100.h b/include/hw/net/ftgmac100.h
52
index XXXXXXX..XXXXXXX
40
index XXXXXXX..XXXXXXX 100644
53
--- /dev/null
41
--- a/include/hw/net/ftgmac100.h
54
+++ b/include/hw/misc/bcm2835_cprman.h
42
+++ b/include/hw/net/ftgmac100.h
55
@@ -XXX,XX +XXX,XX @@
43
@@ -XXX,XX +XXX,XX @@ typedef struct FTGMAC100State {
56
+/*
44
uint32_t rxdes0_edorr;
57
+ * BCM2835 CPRMAN clock manager
45
} FTGMAC100State;
58
+ *
46
59
+ * Copyright (c) 2020 Luc Michel <luc@lmichel.fr>
47
+#define TYPE_ASPEED_MII "aspeed-mmi"
60
+ *
48
+#define ASPEED_MII(obj) OBJECT_CHECK(AspeedMiiState, (obj), TYPE_ASPEED_MII)
61
+ * SPDX-License-Identifier: GPL-2.0-or-later
49
+
62
+ */
50
+/*
63
+
51
+ * AST2600 MII controller
64
+#ifndef HW_MISC_CPRMAN_H
52
+ */
65
+#define HW_MISC_CPRMAN_H
53
+typedef struct AspeedMiiState {
66
+
67
+#include "hw/sysbus.h"
68
+#include "hw/qdev-clock.h"
69
+
70
+#define TYPE_BCM2835_CPRMAN "bcm2835-cprman"
71
+
72
+typedef struct BCM2835CprmanState BCM2835CprmanState;
73
+
74
+DECLARE_INSTANCE_CHECKER(BCM2835CprmanState, CPRMAN,
75
+ TYPE_BCM2835_CPRMAN)
76
+
77
+#define CPRMAN_NUM_REGS (0x2000 / sizeof(uint32_t))
78
+
79
+struct BCM2835CprmanState {
54
+ /*< private >*/
80
+ /*< private >*/
55
+ SysBusDevice parent_obj;
81
+ SysBusDevice parent_obj;
56
+
82
+
57
+ FTGMAC100State *nic;
83
+ /*< public >*/
58
+
59
+ MemoryRegion iomem;
84
+ MemoryRegion iomem;
60
+ uint32_t phycr;
85
+
61
+ uint32_t phydata;
86
+ uint32_t regs[CPRMAN_NUM_REGS];
62
+} AspeedMiiState;
87
+ uint32_t xosc_freq;
63
+
88
+
64
#endif
89
+ Clock *xosc;
65
diff --git a/hw/arm/aspeed_ast2600.c b/hw/arm/aspeed_ast2600.c
90
+};
91
+
92
+#endif
93
diff --git a/include/hw/misc/bcm2835_cprman_internals.h b/include/hw/misc/bcm2835_cprman_internals.h
94
new file mode 100644
95
index XXXXXXX..XXXXXXX
96
--- /dev/null
97
+++ b/include/hw/misc/bcm2835_cprman_internals.h
98
@@ -XXX,XX +XXX,XX @@
99
+/*
100
+ * BCM2835 CPRMAN clock manager
101
+ *
102
+ * Copyright (c) 2020 Luc Michel <luc@lmichel.fr>
103
+ *
104
+ * SPDX-License-Identifier: GPL-2.0-or-later
105
+ */
106
+
107
+#ifndef HW_MISC_CPRMAN_INTERNALS_H
108
+#define HW_MISC_CPRMAN_INTERNALS_H
109
+
110
+#include "hw/registerfields.h"
111
+#include "hw/misc/bcm2835_cprman.h"
112
+
113
+/* Register map */
114
+
115
+/*
116
+ * This field is common to all registers. Each register write value must match
117
+ * the CPRMAN_PASSWORD magic value in its 8 MSB.
118
+ */
119
+FIELD(CPRMAN, PASSWORD, 24, 8)
120
+#define CPRMAN_PASSWORD 0x5a
121
+
122
+#endif
123
diff --git a/hw/arm/bcm2835_peripherals.c b/hw/arm/bcm2835_peripherals.c
66
index XXXXXXX..XXXXXXX 100644
124
index XXXXXXX..XXXXXXX 100644
67
--- a/hw/arm/aspeed_ast2600.c
125
--- a/hw/arm/bcm2835_peripherals.c
68
+++ b/hw/arm/aspeed_ast2600.c
126
+++ b/hw/arm/bcm2835_peripherals.c
69
@@ -XXX,XX +XXX,XX @@ static const hwaddr aspeed_soc_ast2600_memmap[] = {
127
@@ -XXX,XX +XXX,XX @@ static void bcm2835_peripherals_init(Object *obj)
70
[ASPEED_FMC] = 0x1E620000,
128
/* DWC2 */
71
[ASPEED_SPI1] = 0x1E630000,
129
object_initialize_child(obj, "dwc2", &s->dwc2, TYPE_DWC2_USB);
72
[ASPEED_SPI2] = 0x1E641000,
130
73
+ [ASPEED_MII1] = 0x1E650000,
131
+ /* CPRMAN clock manager */
74
+ [ASPEED_MII2] = 0x1E650008,
132
+ object_initialize_child(obj, "cprman", &s->cprman, TYPE_BCM2835_CPRMAN);
75
+ [ASPEED_MII3] = 0x1E650010,
133
+
76
+ [ASPEED_MII4] = 0x1E650018,
134
object_property_add_const_link(OBJECT(&s->dwc2), "dma-mr",
77
[ASPEED_ETH1] = 0x1E660000,
135
OBJECT(&s->gpu_bus_mr));
78
[ASPEED_ETH3] = 0x1E670000,
136
}
79
[ASPEED_ETH2] = 0x1E680000,
137
@@ -XXX,XX +XXX,XX @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)
80
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_ast2600_init(Object *obj)
138
return;
81
for (i = 0; i < sc->macs_num; i++) {
82
sysbus_init_child_obj(obj, "ftgmac100[*]", OBJECT(&s->ftgmac100[i]),
83
sizeof(s->ftgmac100[i]), TYPE_FTGMAC100);
84
+
85
+ sysbus_init_child_obj(obj, "mii[*]", &s->mii[i], sizeof(s->mii[i]),
86
+ TYPE_ASPEED_MII);
87
+ object_property_add_const_link(OBJECT(&s->mii[i]), "nic",
88
+ OBJECT(&s->ftgmac100[i]),
89
+ &error_abort);
90
}
139
}
91
140
92
sysbus_init_child_obj(obj, "xdma", OBJECT(&s->xdma), sizeof(s->xdma),
141
+ /* CPRMAN clock manager */
93
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_ast2600_realize(DeviceState *dev, Error **errp)
142
+ if (!sysbus_realize(SYS_BUS_DEVICE(&s->cprman), errp)) {
94
sc->memmap[ASPEED_ETH1 + i]);
95
sysbus_connect_irq(SYS_BUS_DEVICE(&s->ftgmac100[i]), 0,
96
aspeed_soc_get_irq(s, ASPEED_ETH1 + i));
97
+
98
+ object_property_set_bool(OBJECT(&s->mii[i]), true, "realized",
99
+ &err);
100
+ if (err) {
101
+ error_propagate(errp, err);
102
+ return;
103
+ }
104
+
105
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->mii[i]), 0,
106
+ sc->memmap[ASPEED_MII1 + i]);
107
}
108
109
/* XDMA */
110
diff --git a/hw/net/ftgmac100.c b/hw/net/ftgmac100.c
111
index XXXXXXX..XXXXXXX 100644
112
--- a/hw/net/ftgmac100.c
113
+++ b/hw/net/ftgmac100.c
114
@@ -XXX,XX +XXX,XX @@
115
#include "hw/irq.h"
116
#include "hw/net/ftgmac100.h"
117
#include "sysemu/dma.h"
118
+#include "qapi/error.h"
119
#include "qemu/log.h"
120
#include "qemu/module.h"
121
#include "net/checksum.h"
122
@@ -XXX,XX +XXX,XX @@ static const TypeInfo ftgmac100_info = {
123
.class_init = ftgmac100_class_init,
124
};
125
126
+/*
127
+ * AST2600 MII controller
128
+ */
129
+#define ASPEED_MII_PHYCR_FIRE BIT(31)
130
+#define ASPEED_MII_PHYCR_ST_22 BIT(28)
131
+#define ASPEED_MII_PHYCR_OP(x) ((x) & (ASPEED_MII_PHYCR_OP_WRITE | \
132
+ ASPEED_MII_PHYCR_OP_READ))
133
+#define ASPEED_MII_PHYCR_OP_WRITE BIT(26)
134
+#define ASPEED_MII_PHYCR_OP_READ BIT(27)
135
+#define ASPEED_MII_PHYCR_DATA(x) (x & 0xffff)
136
+#define ASPEED_MII_PHYCR_PHY(x) (((x) >> 21) & 0x1f)
137
+#define ASPEED_MII_PHYCR_REG(x) (((x) >> 16) & 0x1f)
138
+
139
+#define ASPEED_MII_PHYDATA_IDLE BIT(16)
140
+
141
+static void aspeed_mii_transition(AspeedMiiState *s, bool fire)
142
+{
143
+ if (fire) {
144
+ s->phycr |= ASPEED_MII_PHYCR_FIRE;
145
+ s->phydata &= ~ASPEED_MII_PHYDATA_IDLE;
146
+ } else {
147
+ s->phycr &= ~ASPEED_MII_PHYCR_FIRE;
148
+ s->phydata |= ASPEED_MII_PHYDATA_IDLE;
149
+ }
150
+}
151
+
152
+static void aspeed_mii_do_phy_ctl(AspeedMiiState *s)
153
+{
154
+ uint8_t reg;
155
+ uint16_t data;
156
+
157
+ if (!(s->phycr & ASPEED_MII_PHYCR_ST_22)) {
158
+ aspeed_mii_transition(s, !ASPEED_MII_PHYCR_FIRE);
159
+ qemu_log_mask(LOG_UNIMP, "%s: unsupported ST code\n", __func__);
160
+ return;
143
+ return;
161
+ }
144
+ }
162
+
145
+ memory_region_add_subregion(&s->peri_mr, CPRMAN_OFFSET,
163
+ /* Nothing to do */
146
+ sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->cprman), 0));
164
+ if (!(s->phycr & ASPEED_MII_PHYCR_FIRE)) {
147
+
148
memory_region_add_subregion(&s->peri_mr, ARMCTRL_IC_OFFSET,
149
sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->ic), 0));
150
sysbus_pass_irq(SYS_BUS_DEVICE(s), SYS_BUS_DEVICE(&s->ic));
151
@@ -XXX,XX +XXX,XX @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)
152
create_unimp(s, &s->txp, "bcm2835-txp", TXP_OFFSET, 0x1000);
153
create_unimp(s, &s->armtmr, "bcm2835-sp804", ARMCTRL_TIMER0_1_OFFSET, 0x40);
154
create_unimp(s, &s->powermgt, "bcm2835-powermgt", PM_OFFSET, 0x114);
155
- create_unimp(s, &s->cprman, "bcm2835-cprman", CPRMAN_OFFSET, 0x2000);
156
create_unimp(s, &s->i2s, "bcm2835-i2s", I2S_OFFSET, 0x100);
157
create_unimp(s, &s->smi, "bcm2835-smi", SMI_OFFSET, 0x100);
158
create_unimp(s, &s->spi[0], "bcm2835-spi0", SPI0_OFFSET, 0x20);
159
diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c
160
new file mode 100644
161
index XXXXXXX..XXXXXXX
162
--- /dev/null
163
+++ b/hw/misc/bcm2835_cprman.c
164
@@ -XXX,XX +XXX,XX @@
165
+/*
166
+ * BCM2835 CPRMAN clock manager
167
+ *
168
+ * Copyright (c) 2020 Luc Michel <luc@lmichel.fr>
169
+ *
170
+ * SPDX-License-Identifier: GPL-2.0-or-later
171
+ */
172
+
173
+/*
174
+ * This peripheral is roughly divided into 3 main parts:
175
+ * - the PLLs
176
+ * - the PLL channels
177
+ * - the clock muxes
178
+ *
179
+ * A main oscillator (xosc) feeds all the PLLs. Each PLLs has one or more
180
+ * channels. Those channel are then connected to the clock muxes. Each mux has
181
+ * multiples sources (usually the xosc, some of the PLL channels and some "test
182
+ * debug" clocks). A mux is configured to select a given source through its
183
+ * control register. Each mux has one output clock that also goes out of the
184
+ * CPRMAN. This output clock usually connects to another peripheral in the SoC
185
+ * (so a given mux is dedicated to a peripheral).
186
+ *
187
+ * At each level (PLL, channel and mux), the clock can be altered through
188
+ * dividers (and multipliers in case of the PLLs), and can be disabled (in this
189
+ * case, the next levels see no clock).
190
+ *
191
+ * This can be sum-up as follows (this is an example and not the actual BCM2835
192
+ * clock tree):
193
+ *
194
+ * /-->[PLL]-|->[PLL channel]--... [mux]--> to peripherals
195
+ * | |->[PLL channel] muxes takes [mux]
196
+ * | \->[PLL channel] inputs from [mux]
197
+ * | some channels [mux]
198
+ * [xosc]---|-->[PLL]-|->[PLL channel] and other srcs [mux]
199
+ * | \->[PLL channel] ...-->[mux]
200
+ * | [mux]
201
+ * \-->[PLL]--->[PLL channel] [mux]
202
+ *
203
+ * The page at https://elinux.org/The_Undocumented_Pi gives the actual clock
204
+ * tree configuration.
205
+ */
206
+
207
+#include "qemu/osdep.h"
208
+#include "qemu/log.h"
209
+#include "migration/vmstate.h"
210
+#include "hw/qdev-properties.h"
211
+#include "hw/misc/bcm2835_cprman.h"
212
+#include "hw/misc/bcm2835_cprman_internals.h"
213
+#include "trace.h"
214
+
215
+/* CPRMAN "top level" model */
216
+
217
+static uint64_t cprman_read(void *opaque, hwaddr offset,
218
+ unsigned size)
219
+{
220
+ BCM2835CprmanState *s = CPRMAN(opaque);
221
+ uint64_t r = 0;
222
+ size_t idx = offset / sizeof(uint32_t);
223
+
224
+ switch (idx) {
225
+ default:
226
+ r = s->regs[idx];
227
+ }
228
+
229
+ trace_bcm2835_cprman_read(offset, r);
230
+ return r;
231
+}
232
+
233
+static void cprman_write(void *opaque, hwaddr offset,
234
+ uint64_t value, unsigned size)
235
+{
236
+ BCM2835CprmanState *s = CPRMAN(opaque);
237
+ size_t idx = offset / sizeof(uint32_t);
238
+
239
+ if (FIELD_EX32(value, CPRMAN, PASSWORD) != CPRMAN_PASSWORD) {
240
+ trace_bcm2835_cprman_write_invalid_magic(offset, value);
165
+ return;
241
+ return;
166
+ }
242
+ }
167
+
243
+
168
+ reg = ASPEED_MII_PHYCR_REG(s->phycr);
244
+ value &= ~R_CPRMAN_PASSWORD_MASK;
169
+ data = ASPEED_MII_PHYCR_DATA(s->phycr);
245
+
170
+
246
+ trace_bcm2835_cprman_write(offset, value);
171
+ switch (ASPEED_MII_PHYCR_OP(s->phycr)) {
247
+ s->regs[idx] = value;
172
+ case ASPEED_MII_PHYCR_OP_WRITE:
248
+
173
+ do_phy_write(s->nic, reg, data);
249
+}
174
+ break;
250
+
175
+ case ASPEED_MII_PHYCR_OP_READ:
251
+static const MemoryRegionOps cprman_ops = {
176
+ s->phydata = (s->phydata & ~0xffff) | do_phy_read(s->nic, reg);
252
+ .read = cprman_read,
177
+ break;
253
+ .write = cprman_write,
178
+ default:
179
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid OP code %08x\n",
180
+ __func__, s->phycr);
181
+ }
182
+
183
+ aspeed_mii_transition(s, !ASPEED_MII_PHYCR_FIRE);
184
+}
185
+
186
+static uint64_t aspeed_mii_read(void *opaque, hwaddr addr, unsigned size)
187
+{
188
+ AspeedMiiState *s = ASPEED_MII(opaque);
189
+
190
+ switch (addr) {
191
+ case 0x0:
192
+ return s->phycr;
193
+ case 0x4:
194
+ return s->phydata;
195
+ default:
196
+ g_assert_not_reached();
197
+ }
198
+}
199
+
200
+static void aspeed_mii_write(void *opaque, hwaddr addr,
201
+ uint64_t value, unsigned size)
202
+{
203
+ AspeedMiiState *s = ASPEED_MII(opaque);
204
+
205
+ switch (addr) {
206
+ case 0x0:
207
+ s->phycr = value & ~(s->phycr & ASPEED_MII_PHYCR_FIRE);
208
+ break;
209
+ case 0x4:
210
+ s->phydata = value & ~(0xffff | ASPEED_MII_PHYDATA_IDLE);
211
+ break;
212
+ default:
213
+ g_assert_not_reached();
214
+ }
215
+
216
+ aspeed_mii_transition(s, !!(s->phycr & ASPEED_MII_PHYCR_FIRE));
217
+ aspeed_mii_do_phy_ctl(s);
218
+}
219
+
220
+static const MemoryRegionOps aspeed_mii_ops = {
221
+ .read = aspeed_mii_read,
222
+ .write = aspeed_mii_write,
223
+ .valid.min_access_size = 4,
224
+ .valid.max_access_size = 4,
225
+ .endianness = DEVICE_LITTLE_ENDIAN,
254
+ .endianness = DEVICE_LITTLE_ENDIAN,
226
+};
255
+ .valid = {
227
+
256
+ /*
228
+static void aspeed_mii_reset(DeviceState *dev)
257
+ * Although this hasn't been checked against real hardware, nor the
229
+{
258
+ * information can be found in a datasheet, it seems reasonable because
230
+ AspeedMiiState *s = ASPEED_MII(dev);
259
+ * of the "PASSWORD" magic value found in every registers.
231
+
260
+ */
232
+ s->phycr = 0;
261
+ .min_access_size = 4,
233
+ s->phydata = 0;
262
+ .max_access_size = 4,
234
+
263
+ .unaligned = false,
235
+ aspeed_mii_transition(s, !!(s->phycr & ASPEED_MII_PHYCR_FIRE));
264
+ },
236
+};
265
+ .impl = {
237
+
266
+ .max_access_size = 4,
238
+static void aspeed_mii_realize(DeviceState *dev, Error **errp)
267
+ },
239
+{
268
+};
240
+ AspeedMiiState *s = ASPEED_MII(dev);
269
+
241
+ SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
270
+static void cprman_reset(DeviceState *dev)
242
+ Object *obj;
271
+{
243
+ Error *local_err = NULL;
272
+ BCM2835CprmanState *s = CPRMAN(dev);
244
+
273
+
245
+ obj = object_property_get_link(OBJECT(dev), "nic", &local_err);
274
+ memset(s->regs, 0, sizeof(s->regs));
246
+ if (!obj) {
275
+
247
+ error_propagate(errp, local_err);
276
+ clock_update_hz(s->xosc, s->xosc_freq);
248
+ error_prepend(errp, "required link 'nic' not found: ");
277
+}
249
+ return;
278
+
250
+ }
279
+static void cprman_init(Object *obj)
251
+
280
+{
252
+ s->nic = FTGMAC100(obj);
281
+ BCM2835CprmanState *s = CPRMAN(obj);
253
+
282
+
254
+ memory_region_init_io(&s->iomem, OBJECT(dev), &aspeed_mii_ops, s,
283
+ s->xosc = clock_new(obj, "xosc");
255
+ TYPE_ASPEED_MII, 0x8);
284
+
256
+ sysbus_init_mmio(sbd, &s->iomem);
285
+ memory_region_init_io(&s->iomem, obj, &cprman_ops,
257
+}
286
+ s, "bcm2835-cprman", 0x2000);
258
+
287
+ sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->iomem);
259
+static const VMStateDescription vmstate_aspeed_mii = {
288
+}
260
+ .name = TYPE_ASPEED_MII,
289
+
290
+static const VMStateDescription cprman_vmstate = {
291
+ .name = TYPE_BCM2835_CPRMAN,
261
+ .version_id = 1,
292
+ .version_id = 1,
262
+ .minimum_version_id = 1,
293
+ .minimum_version_id = 1,
263
+ .fields = (VMStateField[]) {
294
+ .fields = (VMStateField[]) {
264
+ VMSTATE_UINT32(phycr, FTGMAC100State),
295
+ VMSTATE_UINT32_ARRAY(regs, BCM2835CprmanState, CPRMAN_NUM_REGS),
265
+ VMSTATE_UINT32(phydata, FTGMAC100State),
266
+ VMSTATE_END_OF_LIST()
296
+ VMSTATE_END_OF_LIST()
267
+ }
297
+ }
268
+};
298
+};
269
+static void aspeed_mii_class_init(ObjectClass *klass, void *data)
299
+
300
+static Property cprman_properties[] = {
301
+ DEFINE_PROP_UINT32("xosc-freq-hz", BCM2835CprmanState, xosc_freq, 19200000),
302
+ DEFINE_PROP_END_OF_LIST()
303
+};
304
+
305
+static void cprman_class_init(ObjectClass *klass, void *data)
270
+{
306
+{
271
+ DeviceClass *dc = DEVICE_CLASS(klass);
307
+ DeviceClass *dc = DEVICE_CLASS(klass);
272
+
308
+
273
+ dc->vmsd = &vmstate_aspeed_mii;
309
+ dc->reset = cprman_reset;
274
+ dc->reset = aspeed_mii_reset;
310
+ dc->vmsd = &cprman_vmstate;
275
+ dc->realize = aspeed_mii_realize;
311
+ device_class_set_props(dc, cprman_properties);
276
+ dc->desc = "Aspeed MII controller";
312
+}
277
+}
313
+
278
+
314
+static const TypeInfo cprman_info = {
279
+static const TypeInfo aspeed_mii_info = {
315
+ .name = TYPE_BCM2835_CPRMAN,
280
+ .name = TYPE_ASPEED_MII,
281
+ .parent = TYPE_SYS_BUS_DEVICE,
316
+ .parent = TYPE_SYS_BUS_DEVICE,
282
+ .instance_size = sizeof(AspeedMiiState),
317
+ .instance_size = sizeof(BCM2835CprmanState),
283
+ .class_init = aspeed_mii_class_init,
318
+ .class_init = cprman_class_init,
284
+};
319
+ .instance_init = cprman_init,
285
+
320
+};
286
static void ftgmac100_register_types(void)
321
+
287
{
322
+static void cprman_register_types(void)
288
type_register_static(&ftgmac100_info);
323
+{
289
+ type_register_static(&aspeed_mii_info);
324
+ type_register_static(&cprman_info);
290
}
325
+}
291
326
+
292
type_init(ftgmac100_register_types)
327
+type_init(cprman_register_types);
328
diff --git a/hw/misc/meson.build b/hw/misc/meson.build
329
index XXXXXXX..XXXXXXX 100644
330
--- a/hw/misc/meson.build
331
+++ b/hw/misc/meson.build
332
@@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_RASPI', if_true: files(
333
'bcm2835_property.c',
334
'bcm2835_rng.c',
335
'bcm2835_thermal.c',
336
+ 'bcm2835_cprman.c',
337
))
338
softmmu_ss.add(when: 'CONFIG_SLAVIO', if_true: files('slavio_misc.c'))
339
softmmu_ss.add(when: 'CONFIG_ZYNQ', if_true: files('zynq_slcr.c', 'zynq-xadc.c'))
340
diff --git a/hw/misc/trace-events b/hw/misc/trace-events
341
index XXXXXXX..XXXXXXX 100644
342
--- a/hw/misc/trace-events
343
+++ b/hw/misc/trace-events
344
@@ -XXX,XX +XXX,XX @@ grlib_apb_pnp_read(uint64_t addr, uint32_t value) "APB PnP read addr:0x%03"PRIx6
345
# pca9552.c
346
pca955x_gpio_status(const char *description, const char *buf) "%s GPIOs 0-15 [%s]"
347
pca955x_gpio_change(const char *description, unsigned id, unsigned prev_state, unsigned current_state) "%s GPIO id:%u status: %u -> %u"
348
+
349
+# bcm2835_cprman.c
350
+bcm2835_cprman_read(uint64_t offset, uint64_t value) "offset:0x%" PRIx64 " value:0x%" PRIx64
351
+bcm2835_cprman_write(uint64_t offset, uint64_t value) "offset:0x%" PRIx64 " value:0x%" PRIx64
352
+bcm2835_cprman_write_invalid_magic(uint64_t offset, uint64_t value) "offset:0x%" PRIx64 " value:0x%" PRIx64
293
--
353
--
294
2.20.1
354
2.20.1
295
355
296
356
diff view generated by jsdifflib
1
Switch the imx_epit.c code away from bottom-half based ptimers to
1
From: Luc Michel <luc@lmichel.fr>
2
the new transaction-based ptimer API. This just requires adding
2
3
begin/commit calls around the various places that modify the ptimer
3
There are 5 PLLs in the CPRMAN, namely PLL A, C, D, H and B. All of them
4
state, and using the new ptimer_init() function to create the timer.
4
take the xosc clock as input and produce a new clock.
5
5
6
This commit adds a skeleton implementation for the PLLs as sub-devices
7
of the CPRMAN. The PLLs are instantiated and connected internally to the
8
main oscillator.
9
10
Each PLL has 6 registers : CM, A2W_CTRL, A2W_ANA[0,1,2,3], A2W_FRAC. A
11
write to any of them triggers a call to the (not yet implemented)
12
pll_update function.
13
14
If the main oscillator changes frequency, an update is also triggered.
15
16
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
17
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
18
Signed-off-by: Luc Michel <luc@lmichel.fr>
19
Tested-by: Guenter Roeck <linux@roeck-us.net>
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
20
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Message-id: 20191008171740.9679-18-peter.maydell@linaro.org
9
---
21
---
10
hw/timer/imx_epit.c | 32 +++++++++++++++++++++++++++-----
22
include/hw/misc/bcm2835_cprman.h | 29 +++++
11
1 file changed, 27 insertions(+), 5 deletions(-)
23
include/hw/misc/bcm2835_cprman_internals.h | 144 +++++++++++++++++++++
12
24
hw/misc/bcm2835_cprman.c | 108 ++++++++++++++++
13
diff --git a/hw/timer/imx_epit.c b/hw/timer/imx_epit.c
25
3 files changed, 281 insertions(+)
26
27
diff --git a/include/hw/misc/bcm2835_cprman.h b/include/hw/misc/bcm2835_cprman.h
14
index XXXXXXX..XXXXXXX 100644
28
index XXXXXXX..XXXXXXX 100644
15
--- a/hw/timer/imx_epit.c
29
--- a/include/hw/misc/bcm2835_cprman.h
16
+++ b/hw/timer/imx_epit.c
30
+++ b/include/hw/misc/bcm2835_cprman.h
31
@@ -XXX,XX +XXX,XX @@ DECLARE_INSTANCE_CHECKER(BCM2835CprmanState, CPRMAN,
32
33
#define CPRMAN_NUM_REGS (0x2000 / sizeof(uint32_t))
34
35
+typedef enum CprmanPll {
36
+ CPRMAN_PLLA = 0,
37
+ CPRMAN_PLLC,
38
+ CPRMAN_PLLD,
39
+ CPRMAN_PLLH,
40
+ CPRMAN_PLLB,
41
+
42
+ CPRMAN_NUM_PLL
43
+} CprmanPll;
44
+
45
+typedef struct CprmanPllState {
46
+ /*< private >*/
47
+ DeviceState parent_obj;
48
+
49
+ /*< public >*/
50
+ CprmanPll id;
51
+
52
+ uint32_t *reg_cm;
53
+ uint32_t *reg_a2w_ctrl;
54
+ uint32_t *reg_a2w_ana; /* ANA[0] .. ANA[3] */
55
+ uint32_t prediv_mask; /* prediv bit in ana[1] */
56
+ uint32_t *reg_a2w_frac;
57
+
58
+ Clock *xosc_in;
59
+ Clock *out;
60
+} CprmanPllState;
61
+
62
struct BCM2835CprmanState {
63
/*< private >*/
64
SysBusDevice parent_obj;
65
@@ -XXX,XX +XXX,XX @@ struct BCM2835CprmanState {
66
/*< public >*/
67
MemoryRegion iomem;
68
69
+ CprmanPllState plls[CPRMAN_NUM_PLL];
70
+
71
uint32_t regs[CPRMAN_NUM_REGS];
72
uint32_t xosc_freq;
73
74
diff --git a/include/hw/misc/bcm2835_cprman_internals.h b/include/hw/misc/bcm2835_cprman_internals.h
75
index XXXXXXX..XXXXXXX 100644
76
--- a/include/hw/misc/bcm2835_cprman_internals.h
77
+++ b/include/hw/misc/bcm2835_cprman_internals.h
17
@@ -XXX,XX +XXX,XX @@
78
@@ -XXX,XX +XXX,XX @@
18
#include "migration/vmstate.h"
79
#include "hw/registerfields.h"
19
#include "hw/irq.h"
80
#include "hw/misc/bcm2835_cprman.h"
20
#include "hw/misc/imx_ccm.h"
81
21
-#include "qemu/main-loop.h"
82
+#define TYPE_CPRMAN_PLL "bcm2835-cprman-pll"
22
#include "qemu/module.h"
83
+
23
#include "qemu/log.h"
84
+DECLARE_INSTANCE_CHECKER(CprmanPllState, CPRMAN_PLL,
24
85
+ TYPE_CPRMAN_PLL)
25
@@ -XXX,XX +XXX,XX @@ static void imx_epit_update_int(IMXEPITState *s)
86
+
26
}
87
/* Register map */
88
89
+/* PLLs */
90
+REG32(CM_PLLA, 0x104)
91
+ FIELD(CM_PLLA, LOADDSI0, 0, 1)
92
+ FIELD(CM_PLLA, HOLDDSI0, 1, 1)
93
+ FIELD(CM_PLLA, LOADCCP2, 2, 1)
94
+ FIELD(CM_PLLA, HOLDCCP2, 3, 1)
95
+ FIELD(CM_PLLA, LOADCORE, 4, 1)
96
+ FIELD(CM_PLLA, HOLDCORE, 5, 1)
97
+ FIELD(CM_PLLA, LOADPER, 6, 1)
98
+ FIELD(CM_PLLA, HOLDPER, 7, 1)
99
+ FIELD(CM_PLLx, ANARST, 8, 1)
100
+REG32(CM_PLLC, 0x108)
101
+ FIELD(CM_PLLC, LOADCORE0, 0, 1)
102
+ FIELD(CM_PLLC, HOLDCORE0, 1, 1)
103
+ FIELD(CM_PLLC, LOADCORE1, 2, 1)
104
+ FIELD(CM_PLLC, HOLDCORE1, 3, 1)
105
+ FIELD(CM_PLLC, LOADCORE2, 4, 1)
106
+ FIELD(CM_PLLC, HOLDCORE2, 5, 1)
107
+ FIELD(CM_PLLC, LOADPER, 6, 1)
108
+ FIELD(CM_PLLC, HOLDPER, 7, 1)
109
+REG32(CM_PLLD, 0x10c)
110
+ FIELD(CM_PLLD, LOADDSI0, 0, 1)
111
+ FIELD(CM_PLLD, HOLDDSI0, 1, 1)
112
+ FIELD(CM_PLLD, LOADDSI1, 2, 1)
113
+ FIELD(CM_PLLD, HOLDDSI1, 3, 1)
114
+ FIELD(CM_PLLD, LOADCORE, 4, 1)
115
+ FIELD(CM_PLLD, HOLDCORE, 5, 1)
116
+ FIELD(CM_PLLD, LOADPER, 6, 1)
117
+ FIELD(CM_PLLD, HOLDPER, 7, 1)
118
+REG32(CM_PLLH, 0x110)
119
+ FIELD(CM_PLLH, LOADPIX, 0, 1)
120
+ FIELD(CM_PLLH, LOADAUX, 1, 1)
121
+ FIELD(CM_PLLH, LOADRCAL, 2, 1)
122
+REG32(CM_PLLB, 0x170)
123
+ FIELD(CM_PLLB, LOADARM, 0, 1)
124
+ FIELD(CM_PLLB, HOLDARM, 1, 1)
125
+
126
+REG32(A2W_PLLA_CTRL, 0x1100)
127
+ FIELD(A2W_PLLx_CTRL, NDIV, 0, 10)
128
+ FIELD(A2W_PLLx_CTRL, PDIV, 12, 3)
129
+ FIELD(A2W_PLLx_CTRL, PWRDN, 16, 1)
130
+ FIELD(A2W_PLLx_CTRL, PRST_DISABLE, 17, 1)
131
+REG32(A2W_PLLC_CTRL, 0x1120)
132
+REG32(A2W_PLLD_CTRL, 0x1140)
133
+REG32(A2W_PLLH_CTRL, 0x1160)
134
+REG32(A2W_PLLB_CTRL, 0x11e0)
135
+
136
+REG32(A2W_PLLA_ANA0, 0x1010)
137
+REG32(A2W_PLLA_ANA1, 0x1014)
138
+ FIELD(A2W_PLLx_ANA1, FB_PREDIV, 14, 1)
139
+REG32(A2W_PLLA_ANA2, 0x1018)
140
+REG32(A2W_PLLA_ANA3, 0x101c)
141
+
142
+REG32(A2W_PLLC_ANA0, 0x1030)
143
+REG32(A2W_PLLC_ANA1, 0x1034)
144
+REG32(A2W_PLLC_ANA2, 0x1038)
145
+REG32(A2W_PLLC_ANA3, 0x103c)
146
+
147
+REG32(A2W_PLLD_ANA0, 0x1050)
148
+REG32(A2W_PLLD_ANA1, 0x1054)
149
+REG32(A2W_PLLD_ANA2, 0x1058)
150
+REG32(A2W_PLLD_ANA3, 0x105c)
151
+
152
+REG32(A2W_PLLH_ANA0, 0x1070)
153
+REG32(A2W_PLLH_ANA1, 0x1074)
154
+ FIELD(A2W_PLLH_ANA1, FB_PREDIV, 11, 1)
155
+REG32(A2W_PLLH_ANA2, 0x1078)
156
+REG32(A2W_PLLH_ANA3, 0x107c)
157
+
158
+REG32(A2W_PLLB_ANA0, 0x10f0)
159
+REG32(A2W_PLLB_ANA1, 0x10f4)
160
+REG32(A2W_PLLB_ANA2, 0x10f8)
161
+REG32(A2W_PLLB_ANA3, 0x10fc)
162
+
163
+REG32(A2W_PLLA_FRAC, 0x1200)
164
+ FIELD(A2W_PLLx_FRAC, FRAC, 0, 20)
165
+REG32(A2W_PLLC_FRAC, 0x1220)
166
+REG32(A2W_PLLD_FRAC, 0x1240)
167
+REG32(A2W_PLLH_FRAC, 0x1260)
168
+REG32(A2W_PLLB_FRAC, 0x12e0)
169
+
170
/*
171
* This field is common to all registers. Each register write value must match
172
* the CPRMAN_PASSWORD magic value in its 8 MSB.
173
@@ -XXX,XX +XXX,XX @@
174
FIELD(CPRMAN, PASSWORD, 24, 8)
175
#define CPRMAN_PASSWORD 0x5a
176
177
+/* PLL init info */
178
+typedef struct PLLInitInfo {
179
+ const char *name;
180
+ size_t cm_offset;
181
+ size_t a2w_ctrl_offset;
182
+ size_t a2w_ana_offset;
183
+ uint32_t prediv_mask; /* Prediv bit in ana[1] */
184
+ size_t a2w_frac_offset;
185
+} PLLInitInfo;
186
+
187
+#define FILL_PLL_INIT_INFO(pll_) \
188
+ .cm_offset = R_CM_ ## pll_, \
189
+ .a2w_ctrl_offset = R_A2W_ ## pll_ ## _CTRL, \
190
+ .a2w_ana_offset = R_A2W_ ## pll_ ## _ANA0, \
191
+ .a2w_frac_offset = R_A2W_ ## pll_ ## _FRAC
192
+
193
+static const PLLInitInfo PLL_INIT_INFO[] = {
194
+ [CPRMAN_PLLA] = {
195
+ .name = "plla",
196
+ .prediv_mask = R_A2W_PLLx_ANA1_FB_PREDIV_MASK,
197
+ FILL_PLL_INIT_INFO(PLLA),
198
+ },
199
+ [CPRMAN_PLLC] = {
200
+ .name = "pllc",
201
+ .prediv_mask = R_A2W_PLLx_ANA1_FB_PREDIV_MASK,
202
+ FILL_PLL_INIT_INFO(PLLC),
203
+ },
204
+ [CPRMAN_PLLD] = {
205
+ .name = "plld",
206
+ .prediv_mask = R_A2W_PLLx_ANA1_FB_PREDIV_MASK,
207
+ FILL_PLL_INIT_INFO(PLLD),
208
+ },
209
+ [CPRMAN_PLLH] = {
210
+ .name = "pllh",
211
+ .prediv_mask = R_A2W_PLLH_ANA1_FB_PREDIV_MASK,
212
+ FILL_PLL_INIT_INFO(PLLH),
213
+ },
214
+ [CPRMAN_PLLB] = {
215
+ .name = "pllb",
216
+ .prediv_mask = R_A2W_PLLx_ANA1_FB_PREDIV_MASK,
217
+ FILL_PLL_INIT_INFO(PLLB),
218
+ },
219
+};
220
+
221
+#undef FILL_PLL_CHANNEL_INIT_INFO
222
+
223
+static inline void set_pll_init_info(BCM2835CprmanState *s,
224
+ CprmanPllState *pll,
225
+ CprmanPll id)
226
+{
227
+ pll->id = id;
228
+ pll->reg_cm = &s->regs[PLL_INIT_INFO[id].cm_offset];
229
+ pll->reg_a2w_ctrl = &s->regs[PLL_INIT_INFO[id].a2w_ctrl_offset];
230
+ pll->reg_a2w_ana = &s->regs[PLL_INIT_INFO[id].a2w_ana_offset];
231
+ pll->prediv_mask = PLL_INIT_INFO[id].prediv_mask;
232
+ pll->reg_a2w_frac = &s->regs[PLL_INIT_INFO[id].a2w_frac_offset];
233
+}
234
+
235
#endif
236
diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c
237
index XXXXXXX..XXXXXXX 100644
238
--- a/hw/misc/bcm2835_cprman.c
239
+++ b/hw/misc/bcm2835_cprman.c
240
@@ -XXX,XX +XXX,XX @@
241
#include "hw/misc/bcm2835_cprman_internals.h"
242
#include "trace.h"
243
244
+/* PLL */
245
+
246
+static void pll_update(CprmanPllState *pll)
247
+{
248
+ clock_update(pll->out, 0);
249
+}
250
+
251
+static void pll_xosc_update(void *opaque)
252
+{
253
+ pll_update(CPRMAN_PLL(opaque));
254
+}
255
+
256
+static void pll_init(Object *obj)
257
+{
258
+ CprmanPllState *s = CPRMAN_PLL(obj);
259
+
260
+ s->xosc_in = qdev_init_clock_in(DEVICE(s), "xosc-in", pll_xosc_update, s);
261
+ s->out = qdev_init_clock_out(DEVICE(s), "out");
262
+}
263
+
264
+static const VMStateDescription pll_vmstate = {
265
+ .name = TYPE_CPRMAN_PLL,
266
+ .version_id = 1,
267
+ .minimum_version_id = 1,
268
+ .fields = (VMStateField[]) {
269
+ VMSTATE_CLOCK(xosc_in, CprmanPllState),
270
+ VMSTATE_END_OF_LIST()
271
+ }
272
+};
273
+
274
+static void pll_class_init(ObjectClass *klass, void *data)
275
+{
276
+ DeviceClass *dc = DEVICE_CLASS(klass);
277
+
278
+ dc->vmsd = &pll_vmstate;
279
+}
280
+
281
+static const TypeInfo cprman_pll_info = {
282
+ .name = TYPE_CPRMAN_PLL,
283
+ .parent = TYPE_DEVICE,
284
+ .instance_size = sizeof(CprmanPllState),
285
+ .class_init = pll_class_init,
286
+ .instance_init = pll_init,
287
+};
288
+
289
+
290
/* CPRMAN "top level" model */
291
292
static uint64_t cprman_read(void *opaque, hwaddr offset,
293
@@ -XXX,XX +XXX,XX @@ static uint64_t cprman_read(void *opaque, hwaddr offset,
294
return r;
27
}
295
}
28
296
29
+/*
297
+#define CASE_PLL_REGS(pll_) \
30
+ * Must be called from within a ptimer_transaction_begin/commit block
298
+ case R_CM_ ## pll_: \
31
+ * for both s->timer_cmp and s->timer_reload.
299
+ case R_A2W_ ## pll_ ## _CTRL: \
32
+ */
300
+ case R_A2W_ ## pll_ ## _ANA0: \
33
static void imx_epit_set_freq(IMXEPITState *s)
301
+ case R_A2W_ ## pll_ ## _ANA1: \
302
+ case R_A2W_ ## pll_ ## _ANA2: \
303
+ case R_A2W_ ## pll_ ## _ANA3: \
304
+ case R_A2W_ ## pll_ ## _FRAC
305
+
306
static void cprman_write(void *opaque, hwaddr offset,
307
uint64_t value, unsigned size)
34
{
308
{
35
uint32_t clksrc;
309
@@ -XXX,XX +XXX,XX @@ static void cprman_write(void *opaque, hwaddr offset,
36
@@ -XXX,XX +XXX,XX @@ static void imx_epit_reset(DeviceState *dev)
310
trace_bcm2835_cprman_write(offset, value);
37
s->lr = EPIT_TIMER_MAX;
311
s->regs[idx] = value;
38
s->cmp = 0;
312
39
s->cnt = 0;
313
+ switch (idx) {
40
+ ptimer_transaction_begin(s->timer_cmp);
314
+ CASE_PLL_REGS(PLLA) :
41
+ ptimer_transaction_begin(s->timer_reload);
315
+ pll_update(&s->plls[CPRMAN_PLLA]);
42
/* stop both timers */
316
+ break;
43
ptimer_stop(s->timer_cmp);
317
+
44
ptimer_stop(s->timer_reload);
318
+ CASE_PLL_REGS(PLLC) :
45
@@ -XXX,XX +XXX,XX @@ static void imx_epit_reset(DeviceState *dev)
319
+ pll_update(&s->plls[CPRMAN_PLLC]);
46
/* if the timer is still enabled, restart it */
320
+ break;
47
ptimer_run(s->timer_reload, 0);
321
+
48
}
322
+ CASE_PLL_REGS(PLLD) :
49
+ ptimer_transaction_commit(s->timer_cmp);
323
+ pll_update(&s->plls[CPRMAN_PLLD]);
50
+ ptimer_transaction_commit(s->timer_reload);
324
+ break;
325
+
326
+ CASE_PLL_REGS(PLLH) :
327
+ pll_update(&s->plls[CPRMAN_PLLH]);
328
+ break;
329
+
330
+ CASE_PLL_REGS(PLLB) :
331
+ pll_update(&s->plls[CPRMAN_PLLB]);
332
+ break;
333
+ }
51
}
334
}
52
335
53
static uint32_t imx_epit_update_count(IMXEPITState *s)
336
+#undef CASE_PLL_REGS
54
@@ -XXX,XX +XXX,XX @@ static uint64_t imx_epit_read(void *opaque, hwaddr offset, unsigned size)
337
+
55
return reg_value;
338
static const MemoryRegionOps cprman_ops = {
339
.read = cprman_read,
340
.write = cprman_write,
341
@@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps cprman_ops = {
342
static void cprman_reset(DeviceState *dev)
343
{
344
BCM2835CprmanState *s = CPRMAN(dev);
345
+ size_t i;
346
347
memset(s->regs, 0, sizeof(s->regs));
348
349
+ for (i = 0; i < CPRMAN_NUM_PLL; i++) {
350
+ device_cold_reset(DEVICE(&s->plls[i]));
351
+ }
352
+
353
clock_update_hz(s->xosc, s->xosc_freq);
56
}
354
}
57
355
58
+/* Must be called from ptimer_transaction_begin/commit block for s->timer_cmp */
356
static void cprman_init(Object *obj)
59
static void imx_epit_reload_compare_timer(IMXEPITState *s)
60
{
357
{
61
if ((s->cr & (CR_EN | CR_OCIEN)) == (CR_EN | CR_OCIEN)) {
358
BCM2835CprmanState *s = CPRMAN(obj);
62
@@ -XXX,XX +XXX,XX @@ static void imx_epit_write(void *opaque, hwaddr offset, uint64_t value,
359
+ size_t i;
63
360
+
64
switch (offset >> 2) {
361
+ for (i = 0; i < CPRMAN_NUM_PLL; i++) {
65
case 0: /* CR */
362
+ object_initialize_child(obj, PLL_INIT_INFO[i].name,
66
+ ptimer_transaction_begin(s->timer_cmp);
363
+ &s->plls[i], TYPE_CPRMAN_PLL);
67
+ ptimer_transaction_begin(s->timer_reload);
364
+ set_pll_init_info(s, &s->plls[i], i);
68
365
+ }
69
oldcr = s->cr;
366
70
s->cr = value & 0x03ffffff;
367
s->xosc = clock_new(obj, "xosc");
71
@@ -XXX,XX +XXX,XX @@ static void imx_epit_write(void *opaque, hwaddr offset, uint64_t value,
368
72
} else {
369
@@ -XXX,XX +XXX,XX @@ static void cprman_init(Object *obj)
73
ptimer_stop(s->timer_cmp);
370
sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->iomem);
74
}
75
+
76
+ ptimer_transaction_commit(s->timer_cmp);
77
+ ptimer_transaction_commit(s->timer_reload);
78
break;
79
80
case 1: /* SR - ACK*/
81
@@ -XXX,XX +XXX,XX @@ static void imx_epit_write(void *opaque, hwaddr offset, uint64_t value,
82
case 2: /* LR - set ticks */
83
s->lr = value;
84
85
+ ptimer_transaction_begin(s->timer_cmp);
86
+ ptimer_transaction_begin(s->timer_reload);
87
if (s->cr & CR_RLD) {
88
/* Also set the limit if the LRD bit is set */
89
/* If IOVW bit is set then set the timer value */
90
@@ -XXX,XX +XXX,XX @@ static void imx_epit_write(void *opaque, hwaddr offset, uint64_t value,
91
}
92
93
imx_epit_reload_compare_timer(s);
94
+ ptimer_transaction_commit(s->timer_cmp);
95
+ ptimer_transaction_commit(s->timer_reload);
96
break;
97
98
case 3: /* CMP */
99
s->cmp = value;
100
101
+ ptimer_transaction_begin(s->timer_cmp);
102
imx_epit_reload_compare_timer(s);
103
+ ptimer_transaction_commit(s->timer_cmp);
104
105
break;
106
107
@@ -XXX,XX +XXX,XX @@ static void imx_epit_cmp(void *opaque)
108
imx_epit_update_int(s);
109
}
371
}
110
372
111
+static void imx_epit_reload(void *opaque)
373
+static void cprman_realize(DeviceState *dev, Error **errp)
112
+{
374
+{
113
+ /* No action required on rollover of timer_reload */
375
+ BCM2835CprmanState *s = CPRMAN(dev);
114
+}
376
+ size_t i;
115
+
377
+
116
static const MemoryRegionOps imx_epit_ops = {
378
+ for (i = 0; i < CPRMAN_NUM_PLL; i++) {
117
.read = imx_epit_read,
379
+ CprmanPllState *pll = &s->plls[i];
118
.write = imx_epit_write,
380
+
119
@@ -XXX,XX +XXX,XX @@ static void imx_epit_realize(DeviceState *dev, Error **errp)
381
+ clock_set_source(pll->xosc_in, s->xosc);
382
+
383
+ if (!qdev_realize(DEVICE(pll), NULL, errp)) {
384
+ return;
385
+ }
386
+ }
387
+}
388
+
389
static const VMStateDescription cprman_vmstate = {
390
.name = TYPE_BCM2835_CPRMAN,
391
.version_id = 1,
392
@@ -XXX,XX +XXX,XX @@ static void cprman_class_init(ObjectClass *klass, void *data)
120
{
393
{
121
IMXEPITState *s = IMX_EPIT(dev);
394
DeviceClass *dc = DEVICE_CLASS(klass);
122
SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
395
123
- QEMUBH *bh;
396
+ dc->realize = cprman_realize;
124
397
dc->reset = cprman_reset;
125
DPRINTF("\n");
398
dc->vmsd = &cprman_vmstate;
126
399
device_class_set_props(dc, cprman_properties);
127
@@ -XXX,XX +XXX,XX @@ static void imx_epit_realize(DeviceState *dev, Error **errp)
400
@@ -XXX,XX +XXX,XX @@ static const TypeInfo cprman_info = {
128
0x00001000);
401
static void cprman_register_types(void)
129
sysbus_init_mmio(sbd, &s->iomem);
402
{
130
403
type_register_static(&cprman_info);
131
- s->timer_reload = ptimer_init_with_bh(NULL, PTIMER_POLICY_DEFAULT);
404
+ type_register_static(&cprman_pll_info);
132
+ s->timer_reload = ptimer_init(imx_epit_reload, s, PTIMER_POLICY_DEFAULT);
133
134
- bh = qemu_bh_new(imx_epit_cmp, s);
135
- s->timer_cmp = ptimer_init_with_bh(bh, PTIMER_POLICY_DEFAULT);
136
+ s->timer_cmp = ptimer_init(imx_epit_cmp, s, PTIMER_POLICY_DEFAULT);
137
}
405
}
138
406
139
static void imx_epit_class_init(ObjectClass *klass, void *data)
407
type_init(cprman_register_types);
140
--
408
--
141
2.20.1
409
2.20.1
142
410
143
411
diff view generated by jsdifflib
1
Factor out the implementation of SYS_ISTTY via the new function
1
From: Luc Michel <luc@lmichel.fr>
2
tables.
3
2
3
The CPRMAN PLLs generate a clock based on a prescaler, a multiplier and
4
a divider. The prescaler doubles the parent (xosc) frequency, then the
5
multiplier/divider are applied. The multiplier has an integer and a
6
fractional part.
7
8
This commit also implements the CPRMAN CM_LOCK register. This register
9
reports which PLL is currently locked. We consider a PLL has being
10
locked as soon as it is enabled (on real hardware, there is a delay
11
after turning a PLL on, for it to stabilize).
12
13
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
14
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
15
Signed-off-by: Luc Michel <luc@lmichel.fr>
16
Tested-by: Guenter Roeck <linux@roeck-us.net>
4
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
17
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
5
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
6
Message-id: 20190916141544.17540-11-peter.maydell@linaro.org
7
---
18
---
8
target/arm/arm-semi.c | 20 +++++++++++++++-----
19
include/hw/misc/bcm2835_cprman_internals.h | 8 +++
9
1 file changed, 15 insertions(+), 5 deletions(-)
20
hw/misc/bcm2835_cprman.c | 64 +++++++++++++++++++++-
21
2 files changed, 71 insertions(+), 1 deletion(-)
10
22
11
diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c
23
diff --git a/include/hw/misc/bcm2835_cprman_internals.h b/include/hw/misc/bcm2835_cprman_internals.h
12
index XXXXXXX..XXXXXXX 100644
24
index XXXXXXX..XXXXXXX 100644
13
--- a/target/arm/arm-semi.c
25
--- a/include/hw/misc/bcm2835_cprman_internals.h
14
+++ b/target/arm/arm-semi.c
26
+++ b/include/hw/misc/bcm2835_cprman_internals.h
15
@@ -XXX,XX +XXX,XX @@ typedef uint32_t sys_writefn(ARMCPU *cpu, GuestFD *gf,
27
@@ -XXX,XX +XXX,XX @@ REG32(A2W_PLLD_FRAC, 0x1240)
16
target_ulong buf, uint32_t len);
28
REG32(A2W_PLLH_FRAC, 0x1260)
17
typedef uint32_t sys_readfn(ARMCPU *cpu, GuestFD *gf,
29
REG32(A2W_PLLB_FRAC, 0x12e0)
18
target_ulong buf, uint32_t len);
30
19
+typedef uint32_t sys_isattyfn(ARMCPU *cpu, GuestFD *gf);
31
+/* misc registers */
20
32
+REG32(CM_LOCK, 0x114)
21
static uint32_t host_closefn(ARMCPU *cpu, GuestFD *gf)
33
+ FIELD(CM_LOCK, FLOCKH, 12, 1)
22
{
34
+ FIELD(CM_LOCK, FLOCKD, 11, 1)
23
@@ -XXX,XX +XXX,XX @@ static uint32_t host_readfn(ARMCPU *cpu, GuestFD *gf,
35
+ FIELD(CM_LOCK, FLOCKC, 10, 1)
24
return len - ret;
36
+ FIELD(CM_LOCK, FLOCKB, 9, 1)
25
}
37
+ FIELD(CM_LOCK, FLOCKA, 8, 1)
26
38
+
27
+static uint32_t host_isattyfn(ARMCPU *cpu, GuestFD *gf)
39
/*
40
* This field is common to all registers. Each register write value must match
41
* the CPRMAN_PASSWORD magic value in its 8 MSB.
42
diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c
43
index XXXXXXX..XXXXXXX 100644
44
--- a/hw/misc/bcm2835_cprman.c
45
+++ b/hw/misc/bcm2835_cprman.c
46
@@ -XXX,XX +XXX,XX @@
47
48
/* PLL */
49
50
+static bool pll_is_locked(const CprmanPllState *pll)
28
+{
51
+{
29
+ return isatty(gf->hostfd);
52
+ return !FIELD_EX32(*pll->reg_a2w_ctrl, A2W_PLLx_CTRL, PWRDN)
53
+ && !FIELD_EX32(*pll->reg_cm, CM_PLLx, ANARST);
30
+}
54
+}
31
+
55
+
32
static uint32_t gdb_closefn(ARMCPU *cpu, GuestFD *gf)
56
static void pll_update(CprmanPllState *pll)
33
{
57
{
34
return arm_gdb_syscall(cpu, arm_semi_cb, "close,%x", gf->hostfd);
58
- clock_update(pll->out, 0);
35
@@ -XXX,XX +XXX,XX @@ static uint32_t gdb_readfn(ARMCPU *cpu, GuestFD *gf,
59
+ uint64_t freq, ndiv, fdiv, pdiv;
36
gf->hostfd, buf, len);
60
+
61
+ if (!pll_is_locked(pll)) {
62
+ clock_update(pll->out, 0);
63
+ return;
64
+ }
65
+
66
+ pdiv = FIELD_EX32(*pll->reg_a2w_ctrl, A2W_PLLx_CTRL, PDIV);
67
+
68
+ if (!pdiv) {
69
+ clock_update(pll->out, 0);
70
+ return;
71
+ }
72
+
73
+ ndiv = FIELD_EX32(*pll->reg_a2w_ctrl, A2W_PLLx_CTRL, NDIV);
74
+ fdiv = FIELD_EX32(*pll->reg_a2w_frac, A2W_PLLx_FRAC, FRAC);
75
+
76
+ if (pll->reg_a2w_ana[1] & pll->prediv_mask) {
77
+ /* The prescaler doubles the parent frequency */
78
+ ndiv *= 2;
79
+ fdiv *= 2;
80
+ }
81
+
82
+ /*
83
+ * We have a multiplier with an integer part (ndiv) and a fractional part
84
+ * (fdiv), and a divider (pdiv).
85
+ */
86
+ freq = clock_get_hz(pll->xosc_in) *
87
+ ((ndiv << R_A2W_PLLx_FRAC_FRAC_LENGTH) + fdiv);
88
+ freq /= pdiv;
89
+ freq >>= R_A2W_PLLx_FRAC_FRAC_LENGTH;
90
+
91
+ clock_update_hz(pll->out, freq);
37
}
92
}
38
93
39
+static uint32_t gdb_isattyfn(ARMCPU *cpu, GuestFD *gf)
94
static void pll_xosc_update(void *opaque)
95
@@ -XXX,XX +XXX,XX @@ static const TypeInfo cprman_pll_info = {
96
97
/* CPRMAN "top level" model */
98
99
+static uint32_t get_cm_lock(const BCM2835CprmanState *s)
40
+{
100
+{
41
+ return arm_gdb_syscall(cpu, arm_semi_cb, "isatty,%x", gf->hostfd);
101
+ static const int CM_LOCK_MAPPING[CPRMAN_NUM_PLL] = {
102
+ [CPRMAN_PLLA] = R_CM_LOCK_FLOCKA_SHIFT,
103
+ [CPRMAN_PLLC] = R_CM_LOCK_FLOCKC_SHIFT,
104
+ [CPRMAN_PLLD] = R_CM_LOCK_FLOCKD_SHIFT,
105
+ [CPRMAN_PLLH] = R_CM_LOCK_FLOCKH_SHIFT,
106
+ [CPRMAN_PLLB] = R_CM_LOCK_FLOCKB_SHIFT,
107
+ };
108
+
109
+ uint32_t r = 0;
110
+ size_t i;
111
+
112
+ for (i = 0; i < CPRMAN_NUM_PLL; i++) {
113
+ r |= pll_is_locked(&s->plls[i]) << CM_LOCK_MAPPING[i];
114
+ }
115
+
116
+ return r;
42
+}
117
+}
43
+
118
+
44
typedef struct GuestFDFunctions {
119
static uint64_t cprman_read(void *opaque, hwaddr offset,
45
sys_closefn *closefn;
120
unsigned size)
46
sys_writefn *writefn;
121
{
47
sys_readfn *readfn;
122
@@ -XXX,XX +XXX,XX @@ static uint64_t cprman_read(void *opaque, hwaddr offset,
48
+ sys_isattyfn *isattyfn;
123
size_t idx = offset / sizeof(uint32_t);
49
} GuestFDFunctions;
124
50
125
switch (idx) {
51
static const GuestFDFunctions guestfd_fns[] = {
126
+ case R_CM_LOCK:
52
@@ -XXX,XX +XXX,XX @@ static const GuestFDFunctions guestfd_fns[] = {
127
+ r = get_cm_lock(s);
53
.closefn = host_closefn,
128
+ break;
54
.writefn = host_writefn,
129
+
55
.readfn = host_readfn,
130
default:
56
+ .isattyfn = host_isattyfn,
131
r = s->regs[idx];
57
},
132
}
58
[GuestFDGDB] = {
59
.closefn = gdb_closefn,
60
.writefn = gdb_writefn,
61
.readfn = gdb_readfn,
62
+ .isattyfn = gdb_isattyfn,
63
},
64
};
65
66
@@ -XXX,XX +XXX,XX @@ target_ulong do_arm_semihosting(CPUARMState *env)
67
return set_swi_errno(env, -1);
68
}
69
70
- if (use_gdb_syscalls()) {
71
- return arm_gdb_syscall(cpu, arm_semi_cb, "isatty,%x", gf->hostfd);
72
- } else {
73
- return isatty(gf->hostfd);
74
- }
75
+ return guestfd_fns[gf->type].isattyfn(cpu, gf);
76
case TARGET_SYS_SEEK:
77
GET_ARG(0);
78
GET_ARG(1);
79
--
133
--
80
2.20.1
134
2.20.1
81
135
82
136
diff view generated by jsdifflib
1
From: Rashmica Gupta <rashmica.g@gmail.com>
1
From: Luc Michel <luc@lmichel.fr>
2
2
3
The AST2600 has the same sets of 3.6v gpios as the AST2400 plus an
3
PLLs are composed of multiple channels. Each channel outputs one clock
4
addtional two sets of 1.8V gpios.
4
signal. They are modeled as one device taking the PLL generated clock as
5
5
input, and outputting a new clock.
6
Signed-off-by: Rashmica Gupta <rashmica.g@gmail.com>
6
7
Reviewed-by: Cédric Le Goater <clg@kaod.org>
7
A channel shares the CM register with its parent PLL, and has its own
8
Signed-off-by: Cédric Le Goater <clg@kaod.org>
8
A2W_CTRL register. A write to the CM register will trigger an update of
9
Acked-by: Joel Stanley <joel@jms.id.au>
9
the PLL and all its channels, while a write to an A2W_CTRL channel
10
Message-id: 20190925143248.10000-15-clg@kaod.org
10
register will update the required channel only.
11
12
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
13
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
14
Signed-off-by: Luc Michel <luc@lmichel.fr>
15
Tested-by: Guenter Roeck <linux@roeck-us.net>
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
16
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
---
17
---
13
hw/gpio/aspeed_gpio.c | 142 ++++++++++++++++++++++++++++++++++++++++--
18
include/hw/misc/bcm2835_cprman.h | 44 ++++++
14
1 file changed, 137 insertions(+), 5 deletions(-)
19
include/hw/misc/bcm2835_cprman_internals.h | 146 +++++++++++++++++++
15
20
hw/misc/bcm2835_cprman.c | 155 +++++++++++++++++++--
16
diff --git a/hw/gpio/aspeed_gpio.c b/hw/gpio/aspeed_gpio.c
21
3 files changed, 337 insertions(+), 8 deletions(-)
22
23
diff --git a/include/hw/misc/bcm2835_cprman.h b/include/hw/misc/bcm2835_cprman.h
17
index XXXXXXX..XXXXXXX 100644
24
index XXXXXXX..XXXXXXX 100644
18
--- a/hw/gpio/aspeed_gpio.c
25
--- a/include/hw/misc/bcm2835_cprman.h
19
+++ b/hw/gpio/aspeed_gpio.c
26
+++ b/include/hw/misc/bcm2835_cprman.h
27
@@ -XXX,XX +XXX,XX @@ typedef enum CprmanPll {
28
CPRMAN_NUM_PLL
29
} CprmanPll;
30
31
+typedef enum CprmanPllChannel {
32
+ CPRMAN_PLLA_CHANNEL_DSI0 = 0,
33
+ CPRMAN_PLLA_CHANNEL_CORE,
34
+ CPRMAN_PLLA_CHANNEL_PER,
35
+ CPRMAN_PLLA_CHANNEL_CCP2,
36
+
37
+ CPRMAN_PLLC_CHANNEL_CORE2,
38
+ CPRMAN_PLLC_CHANNEL_CORE1,
39
+ CPRMAN_PLLC_CHANNEL_PER,
40
+ CPRMAN_PLLC_CHANNEL_CORE0,
41
+
42
+ CPRMAN_PLLD_CHANNEL_DSI0,
43
+ CPRMAN_PLLD_CHANNEL_CORE,
44
+ CPRMAN_PLLD_CHANNEL_PER,
45
+ CPRMAN_PLLD_CHANNEL_DSI1,
46
+
47
+ CPRMAN_PLLH_CHANNEL_AUX,
48
+ CPRMAN_PLLH_CHANNEL_RCAL,
49
+ CPRMAN_PLLH_CHANNEL_PIX,
50
+
51
+ CPRMAN_PLLB_CHANNEL_ARM,
52
+
53
+ CPRMAN_NUM_PLL_CHANNEL,
54
+} CprmanPllChannel;
55
+
56
typedef struct CprmanPllState {
57
/*< private >*/
58
DeviceState parent_obj;
59
@@ -XXX,XX +XXX,XX @@ typedef struct CprmanPllState {
60
Clock *out;
61
} CprmanPllState;
62
63
+typedef struct CprmanPllChannelState {
64
+ /*< private >*/
65
+ DeviceState parent_obj;
66
+
67
+ /*< public >*/
68
+ CprmanPllChannel id;
69
+ CprmanPll parent;
70
+
71
+ uint32_t *reg_cm;
72
+ uint32_t hold_mask;
73
+ uint32_t load_mask;
74
+ uint32_t *reg_a2w_ctrl;
75
+ int fixed_divider;
76
+
77
+ Clock *pll_in;
78
+ Clock *out;
79
+} CprmanPllChannelState;
80
+
81
struct BCM2835CprmanState {
82
/*< private >*/
83
SysBusDevice parent_obj;
84
@@ -XXX,XX +XXX,XX @@ struct BCM2835CprmanState {
85
MemoryRegion iomem;
86
87
CprmanPllState plls[CPRMAN_NUM_PLL];
88
+ CprmanPllChannelState channels[CPRMAN_NUM_PLL_CHANNEL];
89
90
uint32_t regs[CPRMAN_NUM_REGS];
91
uint32_t xosc_freq;
92
diff --git a/include/hw/misc/bcm2835_cprman_internals.h b/include/hw/misc/bcm2835_cprman_internals.h
93
index XXXXXXX..XXXXXXX 100644
94
--- a/include/hw/misc/bcm2835_cprman_internals.h
95
+++ b/include/hw/misc/bcm2835_cprman_internals.h
20
@@ -XXX,XX +XXX,XX @@
96
@@ -XXX,XX +XXX,XX @@
21
#define GPIO_3_6V_MEM_SIZE 0x1F0
97
#include "hw/misc/bcm2835_cprman.h"
22
#define GPIO_3_6V_REG_ARRAY_SIZE (GPIO_3_6V_MEM_SIZE >> 2)
98
23
99
#define TYPE_CPRMAN_PLL "bcm2835-cprman-pll"
24
+/* AST2600 only - 1.8V gpios */
100
+#define TYPE_CPRMAN_PLL_CHANNEL "bcm2835-cprman-pll-channel"
25
+/*
101
26
+ * The AST2600 has same 3.6V gpios as the AST2400 (memory offsets 0x0-0x198)
102
DECLARE_INSTANCE_CHECKER(CprmanPllState, CPRMAN_PLL,
27
+ * and addtional 1.8V gpios (memory offsets 0x800-0x9D4).
103
TYPE_CPRMAN_PLL)
28
+ */
104
+DECLARE_INSTANCE_CHECKER(CprmanPllChannelState, CPRMAN_PLL_CHANNEL,
29
+#define GPIO_1_8V_REG_OFFSET 0x800
105
+ TYPE_CPRMAN_PLL_CHANNEL)
30
+#define GPIO_1_8V_ABCD_DATA_VALUE ((0x800 - GPIO_1_8V_REG_OFFSET) >> 2)
106
31
+#define GPIO_1_8V_ABCD_DIRECTION ((0x804 - GPIO_1_8V_REG_OFFSET) >> 2)
107
/* Register map */
32
+#define GPIO_1_8V_ABCD_INT_ENABLE ((0x808 - GPIO_1_8V_REG_OFFSET) >> 2)
108
33
+#define GPIO_1_8V_ABCD_INT_SENS_0 ((0x80C - GPIO_1_8V_REG_OFFSET) >> 2)
109
@@ -XXX,XX +XXX,XX @@ REG32(A2W_PLLD_FRAC, 0x1240)
34
+#define GPIO_1_8V_ABCD_INT_SENS_1 ((0x810 - GPIO_1_8V_REG_OFFSET) >> 2)
110
REG32(A2W_PLLH_FRAC, 0x1260)
35
+#define GPIO_1_8V_ABCD_INT_SENS_2 ((0x814 - GPIO_1_8V_REG_OFFSET) >> 2)
111
REG32(A2W_PLLB_FRAC, 0x12e0)
36
+#define GPIO_1_8V_ABCD_INT_STATUS ((0x818 - GPIO_1_8V_REG_OFFSET) >> 2)
112
37
+#define GPIO_1_8V_ABCD_RESET_TOLERANT ((0x81C - GPIO_1_8V_REG_OFFSET) >> 2)
113
+/* PLL channels */
38
+#define GPIO_1_8V_E_DATA_VALUE ((0x820 - GPIO_1_8V_REG_OFFSET) >> 2)
114
+REG32(A2W_PLLA_DSI0, 0x1300)
39
+#define GPIO_1_8V_E_DIRECTION ((0x824 - GPIO_1_8V_REG_OFFSET) >> 2)
115
+ FIELD(A2W_PLLx_CHANNELy, DIV, 0, 8)
40
+#define GPIO_1_8V_E_INT_ENABLE ((0x828 - GPIO_1_8V_REG_OFFSET) >> 2)
116
+ FIELD(A2W_PLLx_CHANNELy, DISABLE, 8, 1)
41
+#define GPIO_1_8V_E_INT_SENS_0 ((0x82C - GPIO_1_8V_REG_OFFSET) >> 2)
117
+REG32(A2W_PLLA_CORE, 0x1400)
42
+#define GPIO_1_8V_E_INT_SENS_1 ((0x830 - GPIO_1_8V_REG_OFFSET) >> 2)
118
+REG32(A2W_PLLA_PER, 0x1500)
43
+#define GPIO_1_8V_E_INT_SENS_2 ((0x834 - GPIO_1_8V_REG_OFFSET) >> 2)
119
+REG32(A2W_PLLA_CCP2, 0x1600)
44
+#define GPIO_1_8V_E_INT_STATUS ((0x838 - GPIO_1_8V_REG_OFFSET) >> 2)
120
+
45
+#define GPIO_1_8V_E_RESET_TOLERANT ((0x83C - GPIO_1_8V_REG_OFFSET) >> 2)
121
+REG32(A2W_PLLC_CORE2, 0x1320)
46
+#define GPIO_1_8V_ABCD_DEBOUNCE_1 ((0x840 - GPIO_1_8V_REG_OFFSET) >> 2)
122
+REG32(A2W_PLLC_CORE1, 0x1420)
47
+#define GPIO_1_8V_ABCD_DEBOUNCE_2 ((0x844 - GPIO_1_8V_REG_OFFSET) >> 2)
123
+REG32(A2W_PLLC_PER, 0x1520)
48
+#define GPIO_1_8V_E_DEBOUNCE_1 ((0x848 - GPIO_1_8V_REG_OFFSET) >> 2)
124
+REG32(A2W_PLLC_CORE0, 0x1620)
49
+#define GPIO_1_8V_E_DEBOUNCE_2 ((0x84C - GPIO_1_8V_REG_OFFSET) >> 2)
125
+
50
+#define GPIO_1_8V_DEBOUNCE_TIME_1 ((0x850 - GPIO_1_8V_REG_OFFSET) >> 2)
126
+REG32(A2W_PLLD_DSI0, 0x1340)
51
+#define GPIO_1_8V_DEBOUNCE_TIME_2 ((0x854 - GPIO_1_8V_REG_OFFSET) >> 2)
127
+REG32(A2W_PLLD_CORE, 0x1440)
52
+#define GPIO_1_8V_DEBOUNCE_TIME_3 ((0x858 - GPIO_1_8V_REG_OFFSET) >> 2)
128
+REG32(A2W_PLLD_PER, 0x1540)
53
+#define GPIO_1_8V_ABCD_COMMAND_SRC_0 ((0x860 - GPIO_1_8V_REG_OFFSET) >> 2)
129
+REG32(A2W_PLLD_DSI1, 0x1640)
54
+#define GPIO_1_8V_ABCD_COMMAND_SRC_1 ((0x864 - GPIO_1_8V_REG_OFFSET) >> 2)
130
+
55
+#define GPIO_1_8V_E_COMMAND_SRC_0 ((0x868 - GPIO_1_8V_REG_OFFSET) >> 2)
131
+REG32(A2W_PLLH_AUX, 0x1360)
56
+#define GPIO_1_8V_E_COMMAND_SRC_1 ((0x86C - GPIO_1_8V_REG_OFFSET) >> 2)
132
+REG32(A2W_PLLH_RCAL, 0x1460)
57
+#define GPIO_1_8V_ABCD_DATA_READ ((0x8C0 - GPIO_1_8V_REG_OFFSET) >> 2)
133
+REG32(A2W_PLLH_PIX, 0x1560)
58
+#define GPIO_1_8V_E_DATA_READ ((0x8C4 - GPIO_1_8V_REG_OFFSET) >> 2)
134
+REG32(A2W_PLLH_STS, 0x1660)
59
+#define GPIO_1_8V_ABCD_INPUT_MASK ((0x9D0 - GPIO_1_8V_REG_OFFSET) >> 2)
135
+
60
+#define GPIO_1_8V_E_INPUT_MASK ((0x9D4 - GPIO_1_8V_REG_OFFSET) >> 2)
136
+REG32(A2W_PLLB_ARM, 0x13e0)
61
+#define GPIO_1_8V_MEM_SIZE 0x9D8
137
+
62
+#define GPIO_1_8V_REG_ARRAY_SIZE ((GPIO_1_8V_MEM_SIZE - \
138
/* misc registers */
63
+ GPIO_1_8V_REG_OFFSET) >> 2)
139
REG32(CM_LOCK, 0x114)
64
+#define GPIO_MAX_MEM_SIZE MAX(GPIO_3_6V_MEM_SIZE, GPIO_1_8V_MEM_SIZE)
140
FIELD(CM_LOCK, FLOCKH, 12, 1)
65
+
141
@@ -XXX,XX +XXX,XX @@ static inline void set_pll_init_info(BCM2835CprmanState *s,
66
static int aspeed_evaluate_irq(GPIOSets *regs, int gpio_prev_high, int gpio)
142
pll->reg_a2w_frac = &s->regs[PLL_INIT_INFO[id].a2w_frac_offset];
67
{
143
}
68
uint32_t falling_edge = 0, rising_edge = 0;
144
69
@@ -XXX,XX +XXX,XX @@ static const AspeedGPIOReg aspeed_3_6v_gpios[GPIO_3_6V_REG_ARRAY_SIZE] = {
145
+
70
[GPIO_AC_INPUT_MASK] = { 7, gpio_reg_input_mask },
146
+/* PLL channel init info */
147
+typedef struct PLLChannelInitInfo {
148
+ const char *name;
149
+ CprmanPll parent;
150
+ size_t cm_offset;
151
+ uint32_t cm_hold_mask;
152
+ uint32_t cm_load_mask;
153
+ size_t a2w_ctrl_offset;
154
+ unsigned int fixed_divider;
155
+} PLLChannelInitInfo;
156
+
157
+#define FILL_PLL_CHANNEL_INIT_INFO_common(pll_, channel_) \
158
+ .parent = CPRMAN_ ## pll_, \
159
+ .cm_offset = R_CM_ ## pll_, \
160
+ .cm_load_mask = R_CM_ ## pll_ ## _ ## LOAD ## channel_ ## _MASK, \
161
+ .a2w_ctrl_offset = R_A2W_ ## pll_ ## _ ## channel_
162
+
163
+#define FILL_PLL_CHANNEL_INIT_INFO(pll_, channel_) \
164
+ FILL_PLL_CHANNEL_INIT_INFO_common(pll_, channel_), \
165
+ .cm_hold_mask = R_CM_ ## pll_ ## _ ## HOLD ## channel_ ## _MASK, \
166
+ .fixed_divider = 1
167
+
168
+#define FILL_PLL_CHANNEL_INIT_INFO_nohold(pll_, channel_) \
169
+ FILL_PLL_CHANNEL_INIT_INFO_common(pll_, channel_), \
170
+ .cm_hold_mask = 0
171
+
172
+static PLLChannelInitInfo PLL_CHANNEL_INIT_INFO[] = {
173
+ [CPRMAN_PLLA_CHANNEL_DSI0] = {
174
+ .name = "plla-dsi0",
175
+ FILL_PLL_CHANNEL_INIT_INFO(PLLA, DSI0),
176
+ },
177
+ [CPRMAN_PLLA_CHANNEL_CORE] = {
178
+ .name = "plla-core",
179
+ FILL_PLL_CHANNEL_INIT_INFO(PLLA, CORE),
180
+ },
181
+ [CPRMAN_PLLA_CHANNEL_PER] = {
182
+ .name = "plla-per",
183
+ FILL_PLL_CHANNEL_INIT_INFO(PLLA, PER),
184
+ },
185
+ [CPRMAN_PLLA_CHANNEL_CCP2] = {
186
+ .name = "plla-ccp2",
187
+ FILL_PLL_CHANNEL_INIT_INFO(PLLA, CCP2),
188
+ },
189
+
190
+ [CPRMAN_PLLC_CHANNEL_CORE2] = {
191
+ .name = "pllc-core2",
192
+ FILL_PLL_CHANNEL_INIT_INFO(PLLC, CORE2),
193
+ },
194
+ [CPRMAN_PLLC_CHANNEL_CORE1] = {
195
+ .name = "pllc-core1",
196
+ FILL_PLL_CHANNEL_INIT_INFO(PLLC, CORE1),
197
+ },
198
+ [CPRMAN_PLLC_CHANNEL_PER] = {
199
+ .name = "pllc-per",
200
+ FILL_PLL_CHANNEL_INIT_INFO(PLLC, PER),
201
+ },
202
+ [CPRMAN_PLLC_CHANNEL_CORE0] = {
203
+ .name = "pllc-core0",
204
+ FILL_PLL_CHANNEL_INIT_INFO(PLLC, CORE0),
205
+ },
206
+
207
+ [CPRMAN_PLLD_CHANNEL_DSI0] = {
208
+ .name = "plld-dsi0",
209
+ FILL_PLL_CHANNEL_INIT_INFO(PLLD, DSI0),
210
+ },
211
+ [CPRMAN_PLLD_CHANNEL_CORE] = {
212
+ .name = "plld-core",
213
+ FILL_PLL_CHANNEL_INIT_INFO(PLLD, CORE),
214
+ },
215
+ [CPRMAN_PLLD_CHANNEL_PER] = {
216
+ .name = "plld-per",
217
+ FILL_PLL_CHANNEL_INIT_INFO(PLLD, PER),
218
+ },
219
+ [CPRMAN_PLLD_CHANNEL_DSI1] = {
220
+ .name = "plld-dsi1",
221
+ FILL_PLL_CHANNEL_INIT_INFO(PLLD, DSI1),
222
+ },
223
+
224
+ [CPRMAN_PLLH_CHANNEL_AUX] = {
225
+ .name = "pllh-aux",
226
+ .fixed_divider = 1,
227
+ FILL_PLL_CHANNEL_INIT_INFO_nohold(PLLH, AUX),
228
+ },
229
+ [CPRMAN_PLLH_CHANNEL_RCAL] = {
230
+ .name = "pllh-rcal",
231
+ .fixed_divider = 10,
232
+ FILL_PLL_CHANNEL_INIT_INFO_nohold(PLLH, RCAL),
233
+ },
234
+ [CPRMAN_PLLH_CHANNEL_PIX] = {
235
+ .name = "pllh-pix",
236
+ .fixed_divider = 10,
237
+ FILL_PLL_CHANNEL_INIT_INFO_nohold(PLLH, PIX),
238
+ },
239
+
240
+ [CPRMAN_PLLB_CHANNEL_ARM] = {
241
+ .name = "pllb-arm",
242
+ FILL_PLL_CHANNEL_INIT_INFO(PLLB, ARM),
243
+ },
244
+};
245
+
246
+#undef FILL_PLL_CHANNEL_INIT_INFO_nohold
247
+#undef FILL_PLL_CHANNEL_INIT_INFO
248
+#undef FILL_PLL_CHANNEL_INIT_INFO_common
249
+
250
+static inline void set_pll_channel_init_info(BCM2835CprmanState *s,
251
+ CprmanPllChannelState *channel,
252
+ CprmanPllChannel id)
253
+{
254
+ channel->id = id;
255
+ channel->parent = PLL_CHANNEL_INIT_INFO[id].parent;
256
+ channel->reg_cm = &s->regs[PLL_CHANNEL_INIT_INFO[id].cm_offset];
257
+ channel->hold_mask = PLL_CHANNEL_INIT_INFO[id].cm_hold_mask;
258
+ channel->load_mask = PLL_CHANNEL_INIT_INFO[id].cm_load_mask;
259
+ channel->reg_a2w_ctrl = &s->regs[PLL_CHANNEL_INIT_INFO[id].a2w_ctrl_offset];
260
+ channel->fixed_divider = PLL_CHANNEL_INIT_INFO[id].fixed_divider;
261
+}
262
+
263
#endif
264
diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c
265
index XXXXXXX..XXXXXXX 100644
266
--- a/hw/misc/bcm2835_cprman.c
267
+++ b/hw/misc/bcm2835_cprman.c
268
@@ -XXX,XX +XXX,XX @@ static const TypeInfo cprman_pll_info = {
71
};
269
};
72
270
73
+static const AspeedGPIOReg aspeed_1_8v_gpios[GPIO_1_8V_REG_ARRAY_SIZE] = {
271
74
+ /* 1.8V Set ABCD */
272
+/* PLL channel */
75
+ [GPIO_1_8V_ABCD_DATA_VALUE] = {0, gpio_reg_data_value},
273
+
76
+ [GPIO_1_8V_ABCD_DIRECTION] = {0, gpio_reg_direction},
274
+static void pll_channel_update(CprmanPllChannelState *channel)
77
+ [GPIO_1_8V_ABCD_INT_ENABLE] = {0, gpio_reg_int_enable},
275
+{
78
+ [GPIO_1_8V_ABCD_INT_SENS_0] = {0, gpio_reg_int_sens_0},
276
+ clock_update(channel->out, 0);
79
+ [GPIO_1_8V_ABCD_INT_SENS_1] = {0, gpio_reg_int_sens_1},
277
+}
80
+ [GPIO_1_8V_ABCD_INT_SENS_2] = {0, gpio_reg_int_sens_2},
278
+
81
+ [GPIO_1_8V_ABCD_INT_STATUS] = {0, gpio_reg_int_status},
279
+/* Update a PLL and all its channels */
82
+ [GPIO_1_8V_ABCD_RESET_TOLERANT] = {0, gpio_reg_reset_tolerant},
280
+static void pll_update_all_channels(BCM2835CprmanState *s,
83
+ [GPIO_1_8V_ABCD_DEBOUNCE_1] = {0, gpio_reg_debounce_1},
281
+ CprmanPllState *pll)
84
+ [GPIO_1_8V_ABCD_DEBOUNCE_2] = {0, gpio_reg_debounce_2},
282
+{
85
+ [GPIO_1_8V_ABCD_COMMAND_SRC_0] = {0, gpio_reg_cmd_source_0},
283
+ size_t i;
86
+ [GPIO_1_8V_ABCD_COMMAND_SRC_1] = {0, gpio_reg_cmd_source_1},
284
+
87
+ [GPIO_1_8V_ABCD_DATA_READ] = {0, gpio_reg_data_read},
285
+ pll_update(pll);
88
+ [GPIO_1_8V_ABCD_INPUT_MASK] = {0, gpio_reg_input_mask},
286
+
89
+ /* 1.8V Set E */
287
+ for (i = 0; i < CPRMAN_NUM_PLL_CHANNEL; i++) {
90
+ [GPIO_1_8V_E_DATA_VALUE] = {1, gpio_reg_data_value},
288
+ CprmanPllChannelState *channel = &s->channels[i];
91
+ [GPIO_1_8V_E_DIRECTION] = {1, gpio_reg_direction},
289
+ if (channel->parent == pll->id) {
92
+ [GPIO_1_8V_E_INT_ENABLE] = {1, gpio_reg_int_enable},
290
+ pll_channel_update(channel);
93
+ [GPIO_1_8V_E_INT_SENS_0] = {1, gpio_reg_int_sens_0},
291
+ }
94
+ [GPIO_1_8V_E_INT_SENS_1] = {1, gpio_reg_int_sens_1},
292
+ }
95
+ [GPIO_1_8V_E_INT_SENS_2] = {1, gpio_reg_int_sens_2},
293
+}
96
+ [GPIO_1_8V_E_INT_STATUS] = {1, gpio_reg_int_status},
294
+
97
+ [GPIO_1_8V_E_RESET_TOLERANT] = {1, gpio_reg_reset_tolerant},
295
+static void pll_channel_pll_in_update(void *opaque)
98
+ [GPIO_1_8V_E_DEBOUNCE_1] = {1, gpio_reg_debounce_1},
296
+{
99
+ [GPIO_1_8V_E_DEBOUNCE_2] = {1, gpio_reg_debounce_2},
297
+ pll_channel_update(CPRMAN_PLL_CHANNEL(opaque));
100
+ [GPIO_1_8V_E_COMMAND_SRC_0] = {1, gpio_reg_cmd_source_0},
298
+}
101
+ [GPIO_1_8V_E_COMMAND_SRC_1] = {1, gpio_reg_cmd_source_1},
299
+
102
+ [GPIO_1_8V_E_DATA_READ] = {1, gpio_reg_data_read},
300
+static void pll_channel_init(Object *obj)
103
+ [GPIO_1_8V_E_INPUT_MASK] = {1, gpio_reg_input_mask},
301
+{
302
+ CprmanPllChannelState *s = CPRMAN_PLL_CHANNEL(obj);
303
+
304
+ s->pll_in = qdev_init_clock_in(DEVICE(s), "pll-in",
305
+ pll_channel_pll_in_update, s);
306
+ s->out = qdev_init_clock_out(DEVICE(s), "out");
307
+}
308
+
309
+static const VMStateDescription pll_channel_vmstate = {
310
+ .name = TYPE_CPRMAN_PLL_CHANNEL,
311
+ .version_id = 1,
312
+ .minimum_version_id = 1,
313
+ .fields = (VMStateField[]) {
314
+ VMSTATE_CLOCK(pll_in, CprmanPllChannelState),
315
+ VMSTATE_END_OF_LIST()
316
+ }
104
+};
317
+};
105
+
318
+
106
static uint64_t aspeed_gpio_read(void *opaque, hwaddr offset, uint32_t size)
319
+static void pll_channel_class_init(ObjectClass *klass, void *data)
107
{
320
+{
108
AspeedGPIOState *s = ASPEED_GPIO(opaque);
321
+ DeviceClass *dc = DEVICE_CLASS(klass);
109
@@ -XXX,XX +XXX,XX @@ static void aspeed_gpio_get_pin(Object *obj, Visitor *v, const char *name,
322
+
110
int set_idx, group_idx = 0;
323
+ dc->vmsd = &pll_channel_vmstate;
111
324
+}
112
if (sscanf(name, "gpio%2[A-Z]%1d", group, &pin) != 2) {
325
+
113
- error_setg(errp, "%s: error reading %s", __func__, name);
326
+static const TypeInfo cprman_pll_channel_info = {
114
- return;
327
+ .name = TYPE_CPRMAN_PLL_CHANNEL,
115
+ /* 1.8V gpio */
328
+ .parent = TYPE_DEVICE,
116
+ if (sscanf(name, "gpio%3s%1d", group, &pin) != 2) {
329
+ .instance_size = sizeof(CprmanPllChannelState),
117
+ error_setg(errp, "%s: error reading %s", __func__, name);
330
+ .class_init = pll_channel_class_init,
331
+ .instance_init = pll_channel_init,
332
+};
333
+
334
+
335
/* CPRMAN "top level" model */
336
337
static uint32_t get_cm_lock(const BCM2835CprmanState *s)
338
@@ -XXX,XX +XXX,XX @@ static uint64_t cprman_read(void *opaque, hwaddr offset,
339
return r;
340
}
341
342
-#define CASE_PLL_REGS(pll_) \
343
- case R_CM_ ## pll_: \
344
+static inline void update_pll_and_channels_from_cm(BCM2835CprmanState *s,
345
+ size_t idx)
346
+{
347
+ size_t i;
348
+
349
+ for (i = 0; i < CPRMAN_NUM_PLL; i++) {
350
+ if (PLL_INIT_INFO[i].cm_offset == idx) {
351
+ pll_update_all_channels(s, &s->plls[i]);
118
+ return;
352
+ return;
119
+ }
353
+ }
120
}
354
+ }
121
set_idx = get_set_idx(s, group, &group_idx);
355
+}
122
if (set_idx == -1) {
356
+
123
@@ -XXX,XX +XXX,XX @@ static void aspeed_gpio_set_pin(Object *obj, Visitor *v, const char *name,
357
+static inline void update_channel_from_a2w(BCM2835CprmanState *s, size_t idx)
124
return;
358
+{
125
}
359
+ size_t i;
126
if (sscanf(name, "gpio%2[A-Z]%1d", group, &pin) != 2) {
360
+
127
- error_setg(errp, "%s: error reading %s", __func__, name);
361
+ for (i = 0; i < CPRMAN_NUM_PLL_CHANNEL; i++) {
128
- return;
362
+ if (PLL_CHANNEL_INIT_INFO[i].a2w_ctrl_offset == idx) {
129
+ /* 1.8V gpio */
363
+ pll_channel_update(&s->channels[i]);
130
+ if (sscanf(name, "gpio%3s%1d", group, &pin) != 2) {
131
+ error_setg(errp, "%s: error reading %s", __func__, name);
132
+ return;
364
+ return;
133
+ }
365
+ }
366
+ }
367
+}
368
+
369
+#define CASE_PLL_A2W_REGS(pll_) \
370
case R_A2W_ ## pll_ ## _CTRL: \
371
case R_A2W_ ## pll_ ## _ANA0: \
372
case R_A2W_ ## pll_ ## _ANA1: \
373
@@ -XXX,XX +XXX,XX @@ static void cprman_write(void *opaque, hwaddr offset,
374
s->regs[idx] = value;
375
376
switch (idx) {
377
- CASE_PLL_REGS(PLLA) :
378
+ case R_CM_PLLA ... R_CM_PLLH:
379
+ case R_CM_PLLB:
380
+ /*
381
+ * A given CM_PLLx register is shared by both the PLL and the channels
382
+ * of this PLL.
383
+ */
384
+ update_pll_and_channels_from_cm(s, idx);
385
+ break;
386
+
387
+ CASE_PLL_A2W_REGS(PLLA) :
388
pll_update(&s->plls[CPRMAN_PLLA]);
389
break;
390
391
- CASE_PLL_REGS(PLLC) :
392
+ CASE_PLL_A2W_REGS(PLLC) :
393
pll_update(&s->plls[CPRMAN_PLLC]);
394
break;
395
396
- CASE_PLL_REGS(PLLD) :
397
+ CASE_PLL_A2W_REGS(PLLD) :
398
pll_update(&s->plls[CPRMAN_PLLD]);
399
break;
400
401
- CASE_PLL_REGS(PLLH) :
402
+ CASE_PLL_A2W_REGS(PLLH) :
403
pll_update(&s->plls[CPRMAN_PLLH]);
404
break;
405
406
- CASE_PLL_REGS(PLLB) :
407
+ CASE_PLL_A2W_REGS(PLLB) :
408
pll_update(&s->plls[CPRMAN_PLLB]);
409
break;
410
+
411
+ case R_A2W_PLLA_DSI0:
412
+ case R_A2W_PLLA_CORE:
413
+ case R_A2W_PLLA_PER:
414
+ case R_A2W_PLLA_CCP2:
415
+ case R_A2W_PLLC_CORE2:
416
+ case R_A2W_PLLC_CORE1:
417
+ case R_A2W_PLLC_PER:
418
+ case R_A2W_PLLC_CORE0:
419
+ case R_A2W_PLLD_DSI0:
420
+ case R_A2W_PLLD_CORE:
421
+ case R_A2W_PLLD_PER:
422
+ case R_A2W_PLLD_DSI1:
423
+ case R_A2W_PLLH_AUX:
424
+ case R_A2W_PLLH_RCAL:
425
+ case R_A2W_PLLH_PIX:
426
+ case R_A2W_PLLB_ARM:
427
+ update_channel_from_a2w(s, idx);
428
+ break;
134
}
429
}
135
set_idx = get_set_idx(s, group, &group_idx);
430
}
136
if (set_idx == -1) {
431
137
@@ -XXX,XX +XXX,XX @@ static const GPIOSetProperties ast2500_set_props[] = {
432
-#undef CASE_PLL_REGS
138
[7] = {0x000000ff, 0x000000ff, {"AC"} },
433
+#undef CASE_PLL_A2W_REGS
139
};
434
140
435
static const MemoryRegionOps cprman_ops = {
141
+static GPIOSetProperties ast2600_3_6v_set_props[] = {
436
.read = cprman_read,
142
+ [0] = {0xffffffff, 0xffffffff, {"A", "B", "C", "D"} },
437
@@ -XXX,XX +XXX,XX @@ static void cprman_reset(DeviceState *dev)
143
+ [1] = {0xffffffff, 0xffffffff, {"E", "F", "G", "H"} },
438
device_cold_reset(DEVICE(&s->plls[i]));
144
+ [2] = {0xffffffff, 0xffffffff, {"I", "J", "K", "L"} },
145
+ [3] = {0xffffffff, 0xffffffff, {"M", "N", "O", "P"} },
146
+ [4] = {0xffffffff, 0xffffffff, {"Q", "R", "S", "T"} },
147
+ [5] = {0xffffffff, 0x0000ffff, {"U", "V", "W", "X"} },
148
+ [6] = {0xffff0000, 0x0fff0000, {"Y", "Z", "", ""} },
149
+};
150
+
151
+static GPIOSetProperties ast2600_1_8v_set_props[] = {
152
+ [0] = {0xffffffff, 0xffffffff, {"18A", "18B", "18C", "18D"} },
153
+ [1] = {0x0000000f, 0x0000000f, {"18E"} },
154
+};
155
+
156
static const MemoryRegionOps aspeed_gpio_ops = {
157
.read = aspeed_gpio_read,
158
.write = aspeed_gpio_write,
159
@@ -XXX,XX +XXX,XX @@ static void aspeed_gpio_realize(DeviceState *dev, Error **errp)
160
}
439
}
161
440
162
memory_region_init_io(&s->iomem, OBJECT(s), &aspeed_gpio_ops, s,
441
+ for (i = 0; i < CPRMAN_NUM_PLL_CHANNEL; i++) {
163
- TYPE_ASPEED_GPIO, GPIO_3_6V_MEM_SIZE);
442
+ device_cold_reset(DEVICE(&s->channels[i]));
164
+ TYPE_ASPEED_GPIO, GPIO_MAX_MEM_SIZE);
443
+ }
165
444
+
166
sysbus_init_mmio(sbd, &s->iomem);
445
clock_update_hz(s->xosc, s->xosc_freq);
167
}
446
}
168
@@ -XXX,XX +XXX,XX @@ static void aspeed_gpio_2500_class_init(ObjectClass *klass, void *data)
447
169
agc->reg_table = aspeed_3_6v_gpios;
448
@@ -XXX,XX +XXX,XX @@ static void cprman_init(Object *obj)
170
}
449
set_pll_init_info(s, &s->plls[i], i);
171
450
}
172
+static void aspeed_gpio_ast2600_3_6v_class_init(ObjectClass *klass, void *data)
451
173
+{
452
+ for (i = 0; i < CPRMAN_NUM_PLL_CHANNEL; i++) {
174
+ AspeedGPIOClass *agc = ASPEED_GPIO_CLASS(klass);
453
+ object_initialize_child(obj, PLL_CHANNEL_INIT_INFO[i].name,
175
+
454
+ &s->channels[i],
176
+ agc->props = ast2600_3_6v_set_props;
455
+ TYPE_CPRMAN_PLL_CHANNEL);
177
+ agc->nr_gpio_pins = 208;
456
+ set_pll_channel_init_info(s, &s->channels[i], i);
178
+ agc->nr_gpio_sets = 7;
457
+ }
179
+ agc->reg_table = aspeed_3_6v_gpios;
458
+
180
+}
459
s->xosc = clock_new(obj, "xosc");
181
+
460
182
+static void aspeed_gpio_ast2600_1_8v_class_init(ObjectClass *klass, void *data)
461
memory_region_init_io(&s->iomem, obj, &cprman_ops,
183
+{
462
@@ -XXX,XX +XXX,XX @@ static void cprman_realize(DeviceState *dev, Error **errp)
184
+ AspeedGPIOClass *agc = ASPEED_GPIO_CLASS(klass);
463
return;
185
+
464
}
186
+ agc->props = ast2600_1_8v_set_props;
465
}
187
+ agc->nr_gpio_pins = 36;
466
+
188
+ agc->nr_gpio_sets = 2;
467
+ for (i = 0; i < CPRMAN_NUM_PLL_CHANNEL; i++) {
189
+ agc->reg_table = aspeed_1_8v_gpios;
468
+ CprmanPllChannelState *channel = &s->channels[i];
190
+}
469
+ CprmanPll parent = PLL_CHANNEL_INIT_INFO[i].parent;
191
+
470
+ Clock *parent_clk = s->plls[parent].out;
192
static const TypeInfo aspeed_gpio_info = {
471
+
193
.name = TYPE_ASPEED_GPIO,
472
+ clock_set_source(channel->pll_in, parent_clk);
194
.parent = TYPE_SYS_BUS_DEVICE,
473
+
195
@@ -XXX,XX +XXX,XX @@ static const TypeInfo aspeed_gpio_ast2500_info = {
474
+ if (!qdev_realize(DEVICE(channel), NULL, errp)) {
196
.instance_init = aspeed_gpio_init,
475
+ return;
197
};
476
+ }
198
477
+ }
199
+static const TypeInfo aspeed_gpio_ast2600_3_6v_info = {
478
}
200
+ .name = TYPE_ASPEED_GPIO "-ast2600",
479
201
+ .parent = TYPE_ASPEED_GPIO,
480
static const VMStateDescription cprman_vmstate = {
202
+ .class_init = aspeed_gpio_ast2600_3_6v_class_init,
481
@@ -XXX,XX +XXX,XX @@ static void cprman_register_types(void)
203
+ .instance_init = aspeed_gpio_init,
204
+};
205
+
206
+static const TypeInfo aspeed_gpio_ast2600_1_8v_info = {
207
+ .name = TYPE_ASPEED_GPIO "-ast2600-1_8v",
208
+ .parent = TYPE_ASPEED_GPIO,
209
+ .class_init = aspeed_gpio_ast2600_1_8v_class_init,
210
+ .instance_init = aspeed_gpio_init,
211
+};
212
+
213
static void aspeed_gpio_register_types(void)
214
{
482
{
215
type_register_static(&aspeed_gpio_info);
483
type_register_static(&cprman_info);
216
type_register_static(&aspeed_gpio_ast2400_info);
484
type_register_static(&cprman_pll_info);
217
type_register_static(&aspeed_gpio_ast2500_info);
485
+ type_register_static(&cprman_pll_channel_info);
218
+ type_register_static(&aspeed_gpio_ast2600_3_6v_info);
486
}
219
+ type_register_static(&aspeed_gpio_ast2600_1_8v_info);
487
220
}
488
type_init(cprman_register_types);
221
222
type_init(aspeed_gpio_register_types);
223
--
489
--
224
2.20.1
490
2.20.1
225
491
226
492
diff view generated by jsdifflib
1
Version 2.0 of the semihosting specification added support for
1
From: Luc Michel <luc@lmichel.fr>
2
allowing a guest to detect whether the implementation supported
3
particular features. This works by the guest opening a magic
4
file ":semihosting-features", which contains a fixed set of
5
data with some magic numbers followed by a sequence of bytes
6
with feature flags. The file is expected to behave sensibly
7
for the various semihosting calls which operate on files
8
(SYS_FLEN, SYS_SEEK, etc).
9
2
10
Implement this as another kind of guest FD using our function
3
A PLL channel is able to further divide the generated PLL frequency.
11
table dispatch mechanism. Initially we report no extended
4
The divider is given in the CTRL_A2W register. Some channels have an
12
features, so we have just one feature flag byte which is zero.
5
additional fixed divider which is always applied to the signal.
13
6
7
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
8
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
9
Signed-off-by: Luc Michel <luc@lmichel.fr>
10
Tested-by: Guenter Roeck <linux@roeck-us.net>
14
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
15
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
16
Message-id: 20190916141544.17540-14-peter.maydell@linaro.org
17
---
12
---
18
target/arm/arm-semi.c | 109 +++++++++++++++++++++++++++++++++++++++++-
13
hw/misc/bcm2835_cprman.c | 33 ++++++++++++++++++++++++++++++++-
19
1 file changed, 108 insertions(+), 1 deletion(-)
14
1 file changed, 32 insertions(+), 1 deletion(-)
20
15
21
diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c
16
diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c
22
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
23
--- a/target/arm/arm-semi.c
18
--- a/hw/misc/bcm2835_cprman.c
24
+++ b/target/arm/arm-semi.c
19
+++ b/hw/misc/bcm2835_cprman.c
25
@@ -XXX,XX +XXX,XX @@ typedef enum GuestFDType {
20
@@ -XXX,XX +XXX,XX @@ static const TypeInfo cprman_pll_info = {
26
GuestFDUnused = 0,
21
27
GuestFDHost = 1,
22
/* PLL channel */
28
GuestFDGDB = 2,
23
29
+ GuestFDFeatureFile = 3,
24
+static bool pll_channel_is_enabled(CprmanPllChannelState *channel)
30
} GuestFDType;
31
32
/*
33
@@ -XXX,XX +XXX,XX @@ typedef enum GuestFDType {
34
*/
35
typedef struct GuestFD {
36
GuestFDType type;
37
- int hostfd;
38
+ union {
39
+ int hostfd;
40
+ target_ulong featurefile_offset;
41
+ };
42
} GuestFD;
43
44
static GArray *guestfd_array;
45
@@ -XXX,XX +XXX,XX @@ static uint32_t gdb_flenfn(ARMCPU *cpu, GuestFD *gf)
46
gf->hostfd, arm_flen_buf(cpu));
47
}
48
49
+#define SHFB_MAGIC_0 0x53
50
+#define SHFB_MAGIC_1 0x48
51
+#define SHFB_MAGIC_2 0x46
52
+#define SHFB_MAGIC_3 0x42
53
+
54
+static const uint8_t featurefile_data[] = {
55
+ SHFB_MAGIC_0,
56
+ SHFB_MAGIC_1,
57
+ SHFB_MAGIC_2,
58
+ SHFB_MAGIC_3,
59
+ 0, /* Feature byte 0 */
60
+};
61
+
62
+static void init_featurefile_guestfd(int guestfd)
63
+{
25
+{
64
+ GuestFD *gf = do_get_guestfd(guestfd);
26
+ /*
65
+
27
+ * XXX I'm not sure of the purpose of the LOAD field. The Linux driver does
66
+ assert(gf);
28
+ * not set it when enabling the channel, but does clear it when disabling
67
+ gf->type = GuestFDFeatureFile;
29
+ * it.
68
+ gf->featurefile_offset = 0;
30
+ */
31
+ return !FIELD_EX32(*channel->reg_a2w_ctrl, A2W_PLLx_CHANNELy, DISABLE)
32
+ && !(*channel->reg_cm & channel->hold_mask);
69
+}
33
+}
70
+
34
+
71
+static uint32_t featurefile_closefn(ARMCPU *cpu, GuestFD *gf)
35
static void pll_channel_update(CprmanPllChannelState *channel)
72
+{
36
{
73
+ /* Nothing to do */
37
- clock_update(channel->out, 0);
74
+ return 0;
38
+ uint64_t freq, div;
75
+}
76
+
39
+
77
+static uint32_t featurefile_writefn(ARMCPU *cpu, GuestFD *gf,
40
+ if (!pll_channel_is_enabled(channel)) {
78
+ target_ulong buf, uint32_t len)
41
+ clock_update(channel->out, 0);
79
+{
42
+ return;
80
+ /* This fd can never be open for writing */
81
+ CPUARMState *env = &cpu->env;
82
+
83
+ errno = EBADF;
84
+ return set_swi_errno(env, -1);
85
+}
86
+
87
+static uint32_t featurefile_readfn(ARMCPU *cpu, GuestFD *gf,
88
+ target_ulong buf, uint32_t len)
89
+{
90
+ uint32_t i;
91
+#ifndef CONFIG_USER_ONLY
92
+ CPUARMState *env = &cpu->env;
93
+#endif
94
+ char *s;
95
+
96
+ s = lock_user(VERIFY_WRITE, buf, len, 0);
97
+ if (!s) {
98
+ return len;
99
+ }
43
+ }
100
+
44
+
101
+ for (i = 0; i < len; i++) {
45
+ div = FIELD_EX32(*channel->reg_a2w_ctrl, A2W_PLLx_CHANNELy, DIV);
102
+ if (gf->featurefile_offset >= sizeof(featurefile_data)) {
46
+
103
+ break;
47
+ if (!div) {
104
+ }
48
+ /*
105
+ s[i] = featurefile_data[gf->featurefile_offset];
49
+ * It seems that when the divider value is 0, it is considered as
106
+ gf->featurefile_offset++;
50
+ * being maximum by the hardware (see the Linux driver).
51
+ */
52
+ div = R_A2W_PLLx_CHANNELy_DIV_MASK;
107
+ }
53
+ }
108
+
54
+
109
+ unlock_user(s, buf, len);
55
+ /* Some channels have an additional fixed divider */
56
+ freq = clock_get_hz(channel->pll_in) / (div * channel->fixed_divider);
110
+
57
+
111
+ /* Return number of bytes not read */
58
+ clock_update_hz(channel->out, freq);
112
+ return len - i;
59
}
113
+}
60
114
+
61
/* Update a PLL and all its channels */
115
+static uint32_t featurefile_isattyfn(ARMCPU *cpu, GuestFD *gf)
116
+{
117
+ return 0;
118
+}
119
+
120
+static uint32_t featurefile_seekfn(ARMCPU *cpu, GuestFD *gf,
121
+ target_ulong offset)
122
+{
123
+ gf->featurefile_offset = offset;
124
+ return 0;
125
+}
126
+
127
+static uint32_t featurefile_flenfn(ARMCPU *cpu, GuestFD *gf)
128
+{
129
+ return sizeof(featurefile_data);
130
+}
131
+
132
typedef struct GuestFDFunctions {
133
sys_closefn *closefn;
134
sys_writefn *writefn;
135
@@ -XXX,XX +XXX,XX @@ static const GuestFDFunctions guestfd_fns[] = {
136
.seekfn = gdb_seekfn,
137
.flenfn = gdb_flenfn,
138
},
139
+ [GuestFDFeatureFile] = {
140
+ .closefn = featurefile_closefn,
141
+ .writefn = featurefile_writefn,
142
+ .readfn = featurefile_readfn,
143
+ .isattyfn = featurefile_isattyfn,
144
+ .seekfn = featurefile_seekfn,
145
+ .flenfn = featurefile_flenfn,
146
+ },
147
};
148
149
/* Read the input value from the argument block; fail the semihosting
150
@@ -XXX,XX +XXX,XX @@ target_ulong do_arm_semihosting(CPUARMState *env)
151
unlock_user(s, arg0, 0);
152
return guestfd;
153
}
154
+ if (strcmp(s, ":semihosting-features") == 0) {
155
+ unlock_user(s, arg0, 0);
156
+ /* We must fail opens for modes other than 0 ('r') or 1 ('rb') */
157
+ if (arg1 != 0 && arg1 != 1) {
158
+ dealloc_guestfd(guestfd);
159
+ errno = EACCES;
160
+ return set_swi_errno(env, -1);
161
+ }
162
+ init_featurefile_guestfd(guestfd);
163
+ return guestfd;
164
+ }
165
+
166
if (use_gdb_syscalls()) {
167
arm_semi_open_guestfd = guestfd;
168
ret = arm_gdb_syscall(cpu, arm_semi_open_cb, "open,%s,%x,1a4", arg0,
169
--
62
--
170
2.20.1
63
2.20.1
171
64
172
65
diff view generated by jsdifflib
1
From: Cédric Le Goater <clg@kaod.org>
1
From: Luc Michel <luc@lmichel.fr>
2
2
3
Use class handlers and class constants to differentiate the
3
The clock multiplexers are the last clock stage in the CPRMAN. Each mux
4
characteristics of the memory controller and remove the 'silicon_rev'
4
outputs one clock signal that goes out of the CPRMAN to the SoC
5
property.
5
peripherals.
6
6
7
Signed-off-by: Cédric Le Goater <clg@kaod.org>
7
Each mux has at most 10 sources. The sources 0 to 3 are common to all
8
Reviewed-by: Joel Stanley <joel@jms.id.au>
8
muxes. They are:
9
Message-id: 20190925143248.10000-9-clg@kaod.org
9
0. ground (no clock signal)
10
1. the main oscillator (xosc)
11
2. "test debug 0" clock
12
3. "test debug 1" clock
13
14
Test debug 0 and 1 are actual clock muxes that can be used as sources to
15
other muxes (for debug purpose).
16
17
Sources 4 to 9 are mux specific and can be unpopulated (grounded). Those
18
sources are fed by the PLL channels outputs.
19
20
One corner case exists for DSI0E and DSI0P muxes. They have their source
21
number 4 connected to an intermediate multiplexer that can select
22
between PLLA-DSI0 and PLLD-DSI0 channel. This multiplexer is called
23
DSI0HSCK and is not a clock mux as such. It is really a simple mux from
24
the hardware point of view (see https://elinux.org/The_Undocumented_Pi).
25
This mux is not implemented in this commit.
26
27
Note that there is some muxes for which sources are unknown (because of
28
a lack of documentation). For those cases all the sources are connected
29
to ground in this implementation.
30
31
Each clock mux output is exported by the CPRMAN at the qdev level,
32
adding the suffix '-out' to the mux name to form the output clock name.
33
(E.g. the 'uart' mux sees its output exported as 'uart-out' at the
34
CPRMAN level.)
35
36
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
37
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
38
Signed-off-by: Luc Michel <luc@lmichel.fr>
39
Tested-by: Guenter Roeck <linux@roeck-us.net>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
40
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
---
41
---
12
include/hw/misc/aspeed_sdmc.h | 19 +++-
42
include/hw/misc/bcm2835_cprman.h | 85 +++++
13
hw/arm/aspeed_soc.c | 5 +-
43
include/hw/misc/bcm2835_cprman_internals.h | 422 +++++++++++++++++++++
14
hw/misc/aspeed_sdmc.c | 168 +++++++++++++++++++++-------------
44
hw/misc/bcm2835_cprman.c | 151 ++++++++
15
3 files changed, 122 insertions(+), 70 deletions(-)
45
3 files changed, 658 insertions(+)
16
46
17
diff --git a/include/hw/misc/aspeed_sdmc.h b/include/hw/misc/aspeed_sdmc.h
47
diff --git a/include/hw/misc/bcm2835_cprman.h b/include/hw/misc/bcm2835_cprman.h
18
index XXXXXXX..XXXXXXX 100644
48
index XXXXXXX..XXXXXXX 100644
19
--- a/include/hw/misc/aspeed_sdmc.h
49
--- a/include/hw/misc/bcm2835_cprman.h
20
+++ b/include/hw/misc/aspeed_sdmc.h
50
+++ b/include/hw/misc/bcm2835_cprman.h
51
@@ -XXX,XX +XXX,XX @@ typedef enum CprmanPllChannel {
52
CPRMAN_PLLB_CHANNEL_ARM,
53
54
CPRMAN_NUM_PLL_CHANNEL,
55
+
56
+ /* Special values used when connecting clock sources to clocks */
57
+ CPRMAN_CLOCK_SRC_NORMAL = -1,
58
+ CPRMAN_CLOCK_SRC_FORCE_GROUND = -2,
59
+ CPRMAN_CLOCK_SRC_DSI0HSCK = -3,
60
} CprmanPllChannel;
61
62
+typedef enum CprmanClockMux {
63
+ CPRMAN_CLOCK_GNRIC,
64
+ CPRMAN_CLOCK_VPU,
65
+ CPRMAN_CLOCK_SYS,
66
+ CPRMAN_CLOCK_PERIA,
67
+ CPRMAN_CLOCK_PERII,
68
+ CPRMAN_CLOCK_H264,
69
+ CPRMAN_CLOCK_ISP,
70
+ CPRMAN_CLOCK_V3D,
71
+ CPRMAN_CLOCK_CAM0,
72
+ CPRMAN_CLOCK_CAM1,
73
+ CPRMAN_CLOCK_CCP2,
74
+ CPRMAN_CLOCK_DSI0E,
75
+ CPRMAN_CLOCK_DSI0P,
76
+ CPRMAN_CLOCK_DPI,
77
+ CPRMAN_CLOCK_GP0,
78
+ CPRMAN_CLOCK_GP1,
79
+ CPRMAN_CLOCK_GP2,
80
+ CPRMAN_CLOCK_HSM,
81
+ CPRMAN_CLOCK_OTP,
82
+ CPRMAN_CLOCK_PCM,
83
+ CPRMAN_CLOCK_PWM,
84
+ CPRMAN_CLOCK_SLIM,
85
+ CPRMAN_CLOCK_SMI,
86
+ CPRMAN_CLOCK_TEC,
87
+ CPRMAN_CLOCK_TD0,
88
+ CPRMAN_CLOCK_TD1,
89
+ CPRMAN_CLOCK_TSENS,
90
+ CPRMAN_CLOCK_TIMER,
91
+ CPRMAN_CLOCK_UART,
92
+ CPRMAN_CLOCK_VEC,
93
+ CPRMAN_CLOCK_PULSE,
94
+ CPRMAN_CLOCK_SDC,
95
+ CPRMAN_CLOCK_ARM,
96
+ CPRMAN_CLOCK_AVEO,
97
+ CPRMAN_CLOCK_EMMC,
98
+ CPRMAN_CLOCK_EMMC2,
99
+
100
+ CPRMAN_NUM_CLOCK_MUX
101
+} CprmanClockMux;
102
+
103
+typedef enum CprmanClockMuxSource {
104
+ CPRMAN_CLOCK_SRC_GND = 0,
105
+ CPRMAN_CLOCK_SRC_XOSC,
106
+ CPRMAN_CLOCK_SRC_TD0,
107
+ CPRMAN_CLOCK_SRC_TD1,
108
+ CPRMAN_CLOCK_SRC_PLLA,
109
+ CPRMAN_CLOCK_SRC_PLLC,
110
+ CPRMAN_CLOCK_SRC_PLLD,
111
+ CPRMAN_CLOCK_SRC_PLLH,
112
+ CPRMAN_CLOCK_SRC_PLLC_CORE1,
113
+ CPRMAN_CLOCK_SRC_PLLC_CORE2,
114
+
115
+ CPRMAN_NUM_CLOCK_MUX_SRC
116
+} CprmanClockMuxSource;
117
+
118
typedef struct CprmanPllState {
119
/*< private >*/
120
DeviceState parent_obj;
121
@@ -XXX,XX +XXX,XX @@ typedef struct CprmanPllChannelState {
122
Clock *out;
123
} CprmanPllChannelState;
124
125
+typedef struct CprmanClockMuxState {
126
+ /*< private >*/
127
+ DeviceState parent_obj;
128
+
129
+ /*< public >*/
130
+ CprmanClockMux id;
131
+
132
+ uint32_t *reg_ctl;
133
+ uint32_t *reg_div;
134
+ int int_bits;
135
+ int frac_bits;
136
+
137
+ Clock *srcs[CPRMAN_NUM_CLOCK_MUX_SRC];
138
+ Clock *out;
139
+
140
+ /*
141
+ * Used by clock srcs update callback to retrieve both the clock and the
142
+ * source number.
143
+ */
144
+ struct CprmanClockMuxState *backref[CPRMAN_NUM_CLOCK_MUX_SRC];
145
+} CprmanClockMuxState;
146
+
147
struct BCM2835CprmanState {
148
/*< private >*/
149
SysBusDevice parent_obj;
150
@@ -XXX,XX +XXX,XX @@ struct BCM2835CprmanState {
151
152
CprmanPllState plls[CPRMAN_NUM_PLL];
153
CprmanPllChannelState channels[CPRMAN_NUM_PLL_CHANNEL];
154
+ CprmanClockMuxState clock_muxes[CPRMAN_NUM_CLOCK_MUX];
155
156
uint32_t regs[CPRMAN_NUM_REGS];
157
uint32_t xosc_freq;
158
159
Clock *xosc;
160
+ Clock *gnd;
161
};
162
163
#endif
164
diff --git a/include/hw/misc/bcm2835_cprman_internals.h b/include/hw/misc/bcm2835_cprman_internals.h
165
index XXXXXXX..XXXXXXX 100644
166
--- a/include/hw/misc/bcm2835_cprman_internals.h
167
+++ b/include/hw/misc/bcm2835_cprman_internals.h
21
@@ -XXX,XX +XXX,XX @@
168
@@ -XXX,XX +XXX,XX @@
22
169
23
#define TYPE_ASPEED_SDMC "aspeed.sdmc"
170
#define TYPE_CPRMAN_PLL "bcm2835-cprman-pll"
24
#define ASPEED_SDMC(obj) OBJECT_CHECK(AspeedSDMCState, (obj), TYPE_ASPEED_SDMC)
171
#define TYPE_CPRMAN_PLL_CHANNEL "bcm2835-cprman-pll-channel"
25
+#define TYPE_ASPEED_2400_SDMC TYPE_ASPEED_SDMC "-ast2400"
172
+#define TYPE_CPRMAN_CLOCK_MUX "bcm2835-cprman-clock-mux"
26
+#define TYPE_ASPEED_2500_SDMC TYPE_ASPEED_SDMC "-ast2500"
173
27
174
DECLARE_INSTANCE_CHECKER(CprmanPllState, CPRMAN_PLL,
28
#define ASPEED_SDMC_NR_REGS (0x174 >> 2)
175
TYPE_CPRMAN_PLL)
29
176
DECLARE_INSTANCE_CHECKER(CprmanPllChannelState, CPRMAN_PLL_CHANNEL,
30
@@ -XXX,XX +XXX,XX @@ typedef struct AspeedSDMCState {
177
TYPE_CPRMAN_PLL_CHANNEL)
31
MemoryRegion iomem;
178
+DECLARE_INSTANCE_CHECKER(CprmanClockMuxState, CPRMAN_CLOCK_MUX,
32
179
+ TYPE_CPRMAN_CLOCK_MUX)
33
uint32_t regs[ASPEED_SDMC_NR_REGS];
180
34
- uint32_t silicon_rev;
181
/* Register map */
35
- uint32_t ram_bits;
182
36
uint64_t ram_size;
183
@@ -XXX,XX +XXX,XX @@ REG32(A2W_PLLH_STS, 0x1660)
37
uint64_t max_ram_size;
184
38
- uint32_t fixed_conf;
185
REG32(A2W_PLLB_ARM, 0x13e0)
39
-
186
40
} AspeedSDMCState;
187
+/* Clock muxes */
41
188
+REG32(CM_GNRICCTL, 0x000)
42
+#define ASPEED_SDMC_CLASS(klass) \
189
+ FIELD(CM_CLOCKx_CTL, SRC, 0, 4)
43
+ OBJECT_CLASS_CHECK(AspeedSDMCClass, (klass), TYPE_ASPEED_SDMC)
190
+ FIELD(CM_CLOCKx_CTL, ENABLE, 4, 1)
44
+#define ASPEED_SDMC_GET_CLASS(obj) \
191
+ FIELD(CM_CLOCKx_CTL, KILL, 5, 1)
45
+ OBJECT_GET_CLASS(AspeedSDMCClass, (obj), TYPE_ASPEED_SDMC)
192
+ FIELD(CM_CLOCKx_CTL, GATE, 6, 1)
46
+
193
+ FIELD(CM_CLOCKx_CTL, BUSY, 7, 1)
47
+typedef struct AspeedSDMCClass {
194
+ FIELD(CM_CLOCKx_CTL, BUSYD, 8, 1)
48
+ SysBusDeviceClass parent_class;
195
+ FIELD(CM_CLOCKx_CTL, MASH, 9, 2)
49
+
196
+ FIELD(CM_CLOCKx_CTL, FLIP, 11, 1)
50
+ uint64_t max_ram_size;
197
+REG32(CM_GNRICDIV, 0x004)
51
+ uint32_t (*compute_conf)(AspeedSDMCState *s, uint32_t data);
198
+ FIELD(CM_CLOCKx_DIV, FRAC, 0, 12)
52
+ void (*write)(AspeedSDMCState *s, uint32_t reg, uint32_t data);
199
+REG32(CM_VPUCTL, 0x008)
53
+} AspeedSDMCClass;
200
+REG32(CM_VPUDIV, 0x00c)
54
+
201
+REG32(CM_SYSCTL, 0x010)
55
#endif /* ASPEED_SDMC_H */
202
+REG32(CM_SYSDIV, 0x014)
56
diff --git a/hw/arm/aspeed_soc.c b/hw/arm/aspeed_soc.c
203
+REG32(CM_PERIACTL, 0x018)
204
+REG32(CM_PERIADIV, 0x01c)
205
+REG32(CM_PERIICTL, 0x020)
206
+REG32(CM_PERIIDIV, 0x024)
207
+REG32(CM_H264CTL, 0x028)
208
+REG32(CM_H264DIV, 0x02c)
209
+REG32(CM_ISPCTL, 0x030)
210
+REG32(CM_ISPDIV, 0x034)
211
+REG32(CM_V3DCTL, 0x038)
212
+REG32(CM_V3DDIV, 0x03c)
213
+REG32(CM_CAM0CTL, 0x040)
214
+REG32(CM_CAM0DIV, 0x044)
215
+REG32(CM_CAM1CTL, 0x048)
216
+REG32(CM_CAM1DIV, 0x04c)
217
+REG32(CM_CCP2CTL, 0x050)
218
+REG32(CM_CCP2DIV, 0x054)
219
+REG32(CM_DSI0ECTL, 0x058)
220
+REG32(CM_DSI0EDIV, 0x05c)
221
+REG32(CM_DSI0PCTL, 0x060)
222
+REG32(CM_DSI0PDIV, 0x064)
223
+REG32(CM_DPICTL, 0x068)
224
+REG32(CM_DPIDIV, 0x06c)
225
+REG32(CM_GP0CTL, 0x070)
226
+REG32(CM_GP0DIV, 0x074)
227
+REG32(CM_GP1CTL, 0x078)
228
+REG32(CM_GP1DIV, 0x07c)
229
+REG32(CM_GP2CTL, 0x080)
230
+REG32(CM_GP2DIV, 0x084)
231
+REG32(CM_HSMCTL, 0x088)
232
+REG32(CM_HSMDIV, 0x08c)
233
+REG32(CM_OTPCTL, 0x090)
234
+REG32(CM_OTPDIV, 0x094)
235
+REG32(CM_PCMCTL, 0x098)
236
+REG32(CM_PCMDIV, 0x09c)
237
+REG32(CM_PWMCTL, 0x0a0)
238
+REG32(CM_PWMDIV, 0x0a4)
239
+REG32(CM_SLIMCTL, 0x0a8)
240
+REG32(CM_SLIMDIV, 0x0ac)
241
+REG32(CM_SMICTL, 0x0b0)
242
+REG32(CM_SMIDIV, 0x0b4)
243
+REG32(CM_TCNTCTL, 0x0c0)
244
+REG32(CM_TCNTCNT, 0x0c4)
245
+REG32(CM_TECCTL, 0x0c8)
246
+REG32(CM_TECDIV, 0x0cc)
247
+REG32(CM_TD0CTL, 0x0d0)
248
+REG32(CM_TD0DIV, 0x0d4)
249
+REG32(CM_TD1CTL, 0x0d8)
250
+REG32(CM_TD1DIV, 0x0dc)
251
+REG32(CM_TSENSCTL, 0x0e0)
252
+REG32(CM_TSENSDIV, 0x0e4)
253
+REG32(CM_TIMERCTL, 0x0e8)
254
+REG32(CM_TIMERDIV, 0x0ec)
255
+REG32(CM_UARTCTL, 0x0f0)
256
+REG32(CM_UARTDIV, 0x0f4)
257
+REG32(CM_VECCTL, 0x0f8)
258
+REG32(CM_VECDIV, 0x0fc)
259
+REG32(CM_PULSECTL, 0x190)
260
+REG32(CM_PULSEDIV, 0x194)
261
+REG32(CM_SDCCTL, 0x1a8)
262
+REG32(CM_SDCDIV, 0x1ac)
263
+REG32(CM_ARMCTL, 0x1b0)
264
+REG32(CM_AVEOCTL, 0x1b8)
265
+REG32(CM_AVEODIV, 0x1bc)
266
+REG32(CM_EMMCCTL, 0x1c0)
267
+REG32(CM_EMMCDIV, 0x1c4)
268
+REG32(CM_EMMC2CTL, 0x1d0)
269
+REG32(CM_EMMC2DIV, 0x1d4)
270
+
271
/* misc registers */
272
REG32(CM_LOCK, 0x114)
273
FIELD(CM_LOCK, FLOCKH, 12, 1)
274
@@ -XXX,XX +XXX,XX @@ static inline void set_pll_channel_init_info(BCM2835CprmanState *s,
275
channel->fixed_divider = PLL_CHANNEL_INIT_INFO[id].fixed_divider;
276
}
277
278
+/* Clock mux init info */
279
+typedef struct ClockMuxInitInfo {
280
+ const char *name;
281
+ size_t cm_offset; /* cm_offset[0]->CM_CTL, cm_offset[1]->CM_DIV */
282
+ int int_bits;
283
+ int frac_bits;
284
+
285
+ CprmanPllChannel src_mapping[CPRMAN_NUM_CLOCK_MUX_SRC];
286
+} ClockMuxInitInfo;
287
+
288
+/*
289
+ * Each clock mux can have up to 10 sources. Sources 0 to 3 are always the
290
+ * same (ground, xosc, td0, td1). Sources 4 to 9 are mux specific, and are not
291
+ * always populated. The following macros catch all those cases.
292
+ */
293
+
294
+/* Unknown mapping. Connect everything to ground */
295
+#define SRC_MAPPING_INFO_unknown \
296
+ .src_mapping = { \
297
+ CPRMAN_CLOCK_SRC_FORCE_GROUND, /* gnd */ \
298
+ CPRMAN_CLOCK_SRC_FORCE_GROUND, /* xosc */ \
299
+ CPRMAN_CLOCK_SRC_FORCE_GROUND, /* test debug 0 */ \
300
+ CPRMAN_CLOCK_SRC_FORCE_GROUND, /* test debug 1 */ \
301
+ CPRMAN_CLOCK_SRC_FORCE_GROUND, /* pll a */ \
302
+ CPRMAN_CLOCK_SRC_FORCE_GROUND, /* pll c */ \
303
+ CPRMAN_CLOCK_SRC_FORCE_GROUND, /* pll d */ \
304
+ CPRMAN_CLOCK_SRC_FORCE_GROUND, /* pll h */ \
305
+ CPRMAN_CLOCK_SRC_FORCE_GROUND, /* pll c, core1 */ \
306
+ CPRMAN_CLOCK_SRC_FORCE_GROUND, /* pll c, core2 */ \
307
+ }
308
+
309
+/* Only the oscillator and the two test debug clocks */
310
+#define SRC_MAPPING_INFO_xosc \
311
+ .src_mapping = { \
312
+ CPRMAN_CLOCK_SRC_NORMAL, \
313
+ CPRMAN_CLOCK_SRC_NORMAL, \
314
+ CPRMAN_CLOCK_SRC_NORMAL, \
315
+ CPRMAN_CLOCK_SRC_NORMAL, \
316
+ CPRMAN_CLOCK_SRC_FORCE_GROUND, \
317
+ CPRMAN_CLOCK_SRC_FORCE_GROUND, \
318
+ CPRMAN_CLOCK_SRC_FORCE_GROUND, \
319
+ CPRMAN_CLOCK_SRC_FORCE_GROUND, \
320
+ CPRMAN_CLOCK_SRC_FORCE_GROUND, \
321
+ CPRMAN_CLOCK_SRC_FORCE_GROUND, \
322
+ }
323
+
324
+/* All the PLL "core" channels */
325
+#define SRC_MAPPING_INFO_core \
326
+ .src_mapping = { \
327
+ CPRMAN_CLOCK_SRC_NORMAL, \
328
+ CPRMAN_CLOCK_SRC_NORMAL, \
329
+ CPRMAN_CLOCK_SRC_NORMAL, \
330
+ CPRMAN_CLOCK_SRC_NORMAL, \
331
+ CPRMAN_PLLA_CHANNEL_CORE, \
332
+ CPRMAN_PLLC_CHANNEL_CORE0, \
333
+ CPRMAN_PLLD_CHANNEL_CORE, \
334
+ CPRMAN_PLLH_CHANNEL_AUX, \
335
+ CPRMAN_PLLC_CHANNEL_CORE1, \
336
+ CPRMAN_PLLC_CHANNEL_CORE2, \
337
+ }
338
+
339
+/* All the PLL "per" channels */
340
+#define SRC_MAPPING_INFO_periph \
341
+ .src_mapping = { \
342
+ CPRMAN_CLOCK_SRC_NORMAL, \
343
+ CPRMAN_CLOCK_SRC_NORMAL, \
344
+ CPRMAN_CLOCK_SRC_NORMAL, \
345
+ CPRMAN_CLOCK_SRC_NORMAL, \
346
+ CPRMAN_PLLA_CHANNEL_PER, \
347
+ CPRMAN_PLLC_CHANNEL_PER, \
348
+ CPRMAN_PLLD_CHANNEL_PER, \
349
+ CPRMAN_CLOCK_SRC_FORCE_GROUND, \
350
+ CPRMAN_CLOCK_SRC_FORCE_GROUND, \
351
+ CPRMAN_CLOCK_SRC_FORCE_GROUND, \
352
+ }
353
+
354
+/*
355
+ * The DSI0 channels. This one got an intermediate mux between the PLL channels
356
+ * and the clock input.
357
+ */
358
+#define SRC_MAPPING_INFO_dsi0 \
359
+ .src_mapping = { \
360
+ CPRMAN_CLOCK_SRC_NORMAL, \
361
+ CPRMAN_CLOCK_SRC_NORMAL, \
362
+ CPRMAN_CLOCK_SRC_NORMAL, \
363
+ CPRMAN_CLOCK_SRC_NORMAL, \
364
+ CPRMAN_CLOCK_SRC_DSI0HSCK, \
365
+ CPRMAN_CLOCK_SRC_FORCE_GROUND, \
366
+ CPRMAN_CLOCK_SRC_FORCE_GROUND, \
367
+ CPRMAN_CLOCK_SRC_FORCE_GROUND, \
368
+ CPRMAN_CLOCK_SRC_FORCE_GROUND, \
369
+ CPRMAN_CLOCK_SRC_FORCE_GROUND, \
370
+ }
371
+
372
+/* The DSI1 channel */
373
+#define SRC_MAPPING_INFO_dsi1 \
374
+ .src_mapping = { \
375
+ CPRMAN_CLOCK_SRC_NORMAL, \
376
+ CPRMAN_CLOCK_SRC_NORMAL, \
377
+ CPRMAN_CLOCK_SRC_NORMAL, \
378
+ CPRMAN_CLOCK_SRC_NORMAL, \
379
+ CPRMAN_PLLD_CHANNEL_DSI1, \
380
+ CPRMAN_CLOCK_SRC_FORCE_GROUND, \
381
+ CPRMAN_CLOCK_SRC_FORCE_GROUND, \
382
+ CPRMAN_CLOCK_SRC_FORCE_GROUND, \
383
+ CPRMAN_CLOCK_SRC_FORCE_GROUND, \
384
+ CPRMAN_CLOCK_SRC_FORCE_GROUND, \
385
+ }
386
+
387
+#define FILL_CLOCK_MUX_SRC_MAPPING_INIT_INFO(kind_) \
388
+ SRC_MAPPING_INFO_ ## kind_
389
+
390
+#define FILL_CLOCK_MUX_INIT_INFO(clock_, kind_) \
391
+ .cm_offset = R_CM_ ## clock_ ## CTL, \
392
+ FILL_CLOCK_MUX_SRC_MAPPING_INIT_INFO(kind_)
393
+
394
+static ClockMuxInitInfo CLOCK_MUX_INIT_INFO[] = {
395
+ [CPRMAN_CLOCK_GNRIC] = {
396
+ .name = "gnric",
397
+ FILL_CLOCK_MUX_INIT_INFO(GNRIC, unknown),
398
+ },
399
+ [CPRMAN_CLOCK_VPU] = {
400
+ .name = "vpu",
401
+ .int_bits = 12,
402
+ .frac_bits = 8,
403
+ FILL_CLOCK_MUX_INIT_INFO(VPU, core),
404
+ },
405
+ [CPRMAN_CLOCK_SYS] = {
406
+ .name = "sys",
407
+ FILL_CLOCK_MUX_INIT_INFO(SYS, unknown),
408
+ },
409
+ [CPRMAN_CLOCK_PERIA] = {
410
+ .name = "peria",
411
+ FILL_CLOCK_MUX_INIT_INFO(PERIA, unknown),
412
+ },
413
+ [CPRMAN_CLOCK_PERII] = {
414
+ .name = "perii",
415
+ FILL_CLOCK_MUX_INIT_INFO(PERII, unknown),
416
+ },
417
+ [CPRMAN_CLOCK_H264] = {
418
+ .name = "h264",
419
+ .int_bits = 4,
420
+ .frac_bits = 8,
421
+ FILL_CLOCK_MUX_INIT_INFO(H264, core),
422
+ },
423
+ [CPRMAN_CLOCK_ISP] = {
424
+ .name = "isp",
425
+ .int_bits = 4,
426
+ .frac_bits = 8,
427
+ FILL_CLOCK_MUX_INIT_INFO(ISP, core),
428
+ },
429
+ [CPRMAN_CLOCK_V3D] = {
430
+ .name = "v3d",
431
+ FILL_CLOCK_MUX_INIT_INFO(V3D, core),
432
+ },
433
+ [CPRMAN_CLOCK_CAM0] = {
434
+ .name = "cam0",
435
+ .int_bits = 4,
436
+ .frac_bits = 8,
437
+ FILL_CLOCK_MUX_INIT_INFO(CAM0, periph),
438
+ },
439
+ [CPRMAN_CLOCK_CAM1] = {
440
+ .name = "cam1",
441
+ .int_bits = 4,
442
+ .frac_bits = 8,
443
+ FILL_CLOCK_MUX_INIT_INFO(CAM1, periph),
444
+ },
445
+ [CPRMAN_CLOCK_CCP2] = {
446
+ .name = "ccp2",
447
+ FILL_CLOCK_MUX_INIT_INFO(CCP2, unknown),
448
+ },
449
+ [CPRMAN_CLOCK_DSI0E] = {
450
+ .name = "dsi0e",
451
+ .int_bits = 4,
452
+ .frac_bits = 8,
453
+ FILL_CLOCK_MUX_INIT_INFO(DSI0E, dsi0),
454
+ },
455
+ [CPRMAN_CLOCK_DSI0P] = {
456
+ .name = "dsi0p",
457
+ .int_bits = 0,
458
+ .frac_bits = 0,
459
+ FILL_CLOCK_MUX_INIT_INFO(DSI0P, dsi0),
460
+ },
461
+ [CPRMAN_CLOCK_DPI] = {
462
+ .name = "dpi",
463
+ .int_bits = 4,
464
+ .frac_bits = 8,
465
+ FILL_CLOCK_MUX_INIT_INFO(DPI, periph),
466
+ },
467
+ [CPRMAN_CLOCK_GP0] = {
468
+ .name = "gp0",
469
+ .int_bits = 12,
470
+ .frac_bits = 12,
471
+ FILL_CLOCK_MUX_INIT_INFO(GP0, periph),
472
+ },
473
+ [CPRMAN_CLOCK_GP1] = {
474
+ .name = "gp1",
475
+ .int_bits = 12,
476
+ .frac_bits = 12,
477
+ FILL_CLOCK_MUX_INIT_INFO(GP1, periph),
478
+ },
479
+ [CPRMAN_CLOCK_GP2] = {
480
+ .name = "gp2",
481
+ .int_bits = 12,
482
+ .frac_bits = 12,
483
+ FILL_CLOCK_MUX_INIT_INFO(GP2, periph),
484
+ },
485
+ [CPRMAN_CLOCK_HSM] = {
486
+ .name = "hsm",
487
+ .int_bits = 4,
488
+ .frac_bits = 8,
489
+ FILL_CLOCK_MUX_INIT_INFO(HSM, periph),
490
+ },
491
+ [CPRMAN_CLOCK_OTP] = {
492
+ .name = "otp",
493
+ .int_bits = 4,
494
+ .frac_bits = 0,
495
+ FILL_CLOCK_MUX_INIT_INFO(OTP, xosc),
496
+ },
497
+ [CPRMAN_CLOCK_PCM] = {
498
+ .name = "pcm",
499
+ .int_bits = 12,
500
+ .frac_bits = 12,
501
+ FILL_CLOCK_MUX_INIT_INFO(PCM, periph),
502
+ },
503
+ [CPRMAN_CLOCK_PWM] = {
504
+ .name = "pwm",
505
+ .int_bits = 12,
506
+ .frac_bits = 12,
507
+ FILL_CLOCK_MUX_INIT_INFO(PWM, periph),
508
+ },
509
+ [CPRMAN_CLOCK_SLIM] = {
510
+ .name = "slim",
511
+ .int_bits = 12,
512
+ .frac_bits = 12,
513
+ FILL_CLOCK_MUX_INIT_INFO(SLIM, periph),
514
+ },
515
+ [CPRMAN_CLOCK_SMI] = {
516
+ .name = "smi",
517
+ .int_bits = 4,
518
+ .frac_bits = 8,
519
+ FILL_CLOCK_MUX_INIT_INFO(SMI, periph),
520
+ },
521
+ [CPRMAN_CLOCK_TEC] = {
522
+ .name = "tec",
523
+ .int_bits = 6,
524
+ .frac_bits = 0,
525
+ FILL_CLOCK_MUX_INIT_INFO(TEC, xosc),
526
+ },
527
+ [CPRMAN_CLOCK_TD0] = {
528
+ .name = "td0",
529
+ FILL_CLOCK_MUX_INIT_INFO(TD0, unknown),
530
+ },
531
+ [CPRMAN_CLOCK_TD1] = {
532
+ .name = "td1",
533
+ FILL_CLOCK_MUX_INIT_INFO(TD1, unknown),
534
+ },
535
+ [CPRMAN_CLOCK_TSENS] = {
536
+ .name = "tsens",
537
+ .int_bits = 5,
538
+ .frac_bits = 0,
539
+ FILL_CLOCK_MUX_INIT_INFO(TSENS, xosc),
540
+ },
541
+ [CPRMAN_CLOCK_TIMER] = {
542
+ .name = "timer",
543
+ .int_bits = 6,
544
+ .frac_bits = 12,
545
+ FILL_CLOCK_MUX_INIT_INFO(TIMER, xosc),
546
+ },
547
+ [CPRMAN_CLOCK_UART] = {
548
+ .name = "uart",
549
+ .int_bits = 10,
550
+ .frac_bits = 12,
551
+ FILL_CLOCK_MUX_INIT_INFO(UART, periph),
552
+ },
553
+ [CPRMAN_CLOCK_VEC] = {
554
+ .name = "vec",
555
+ .int_bits = 4,
556
+ .frac_bits = 0,
557
+ FILL_CLOCK_MUX_INIT_INFO(VEC, periph),
558
+ },
559
+ [CPRMAN_CLOCK_PULSE] = {
560
+ .name = "pulse",
561
+ FILL_CLOCK_MUX_INIT_INFO(PULSE, xosc),
562
+ },
563
+ [CPRMAN_CLOCK_SDC] = {
564
+ .name = "sdram",
565
+ .int_bits = 6,
566
+ .frac_bits = 0,
567
+ FILL_CLOCK_MUX_INIT_INFO(SDC, core),
568
+ },
569
+ [CPRMAN_CLOCK_ARM] = {
570
+ .name = "arm",
571
+ FILL_CLOCK_MUX_INIT_INFO(ARM, unknown),
572
+ },
573
+ [CPRMAN_CLOCK_AVEO] = {
574
+ .name = "aveo",
575
+ .int_bits = 4,
576
+ .frac_bits = 0,
577
+ FILL_CLOCK_MUX_INIT_INFO(AVEO, periph),
578
+ },
579
+ [CPRMAN_CLOCK_EMMC] = {
580
+ .name = "emmc",
581
+ .int_bits = 4,
582
+ .frac_bits = 8,
583
+ FILL_CLOCK_MUX_INIT_INFO(EMMC, periph),
584
+ },
585
+ [CPRMAN_CLOCK_EMMC2] = {
586
+ .name = "emmc2",
587
+ .int_bits = 4,
588
+ .frac_bits = 8,
589
+ FILL_CLOCK_MUX_INIT_INFO(EMMC2, unknown),
590
+ },
591
+};
592
+
593
+#undef FILL_CLOCK_MUX_INIT_INFO
594
+#undef FILL_CLOCK_MUX_SRC_MAPPING_INIT_INFO
595
+#undef SRC_MAPPING_INFO_dsi1
596
+#undef SRC_MAPPING_INFO_dsi0
597
+#undef SRC_MAPPING_INFO_periph
598
+#undef SRC_MAPPING_INFO_core
599
+#undef SRC_MAPPING_INFO_xosc
600
+#undef SRC_MAPPING_INFO_unknown
601
+
602
+static inline void set_clock_mux_init_info(BCM2835CprmanState *s,
603
+ CprmanClockMuxState *mux,
604
+ CprmanClockMux id)
605
+{
606
+ mux->id = id;
607
+ mux->reg_ctl = &s->regs[CLOCK_MUX_INIT_INFO[id].cm_offset];
608
+ mux->reg_div = &s->regs[CLOCK_MUX_INIT_INFO[id].cm_offset + 1];
609
+ mux->int_bits = CLOCK_MUX_INIT_INFO[id].int_bits;
610
+ mux->frac_bits = CLOCK_MUX_INIT_INFO[id].frac_bits;
611
+}
612
+
613
#endif
614
diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c
57
index XXXXXXX..XXXXXXX 100644
615
index XXXXXXX..XXXXXXX 100644
58
--- a/hw/arm/aspeed_soc.c
616
--- a/hw/misc/bcm2835_cprman.c
59
+++ b/hw/arm/aspeed_soc.c
617
+++ b/hw/misc/bcm2835_cprman.c
60
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_init(Object *obj)
618
@@ -XXX,XX +XXX,XX @@
61
sizeof(s->spi[i]), typename);
619
*
62
}
620
* The page at https://elinux.org/The_Undocumented_Pi gives the actual clock
63
621
* tree configuration.
64
+ snprintf(typename, sizeof(typename), "aspeed.sdmc-%s", socname);
622
+ *
65
sysbus_init_child_obj(obj, "sdmc", OBJECT(&s->sdmc), sizeof(s->sdmc),
623
+ * The CPRMAN exposes clock outputs with the name of the clock mux suffixed
66
- TYPE_ASPEED_SDMC);
624
+ * with "-out" (e.g. "uart-out", "h264-out", ...).
67
- qdev_prop_set_uint32(DEVICE(&s->sdmc), "silicon-rev",
625
*/
68
- sc->info->silicon_rev);
626
69
+ typename);
627
#include "qemu/osdep.h"
70
object_property_add_alias(obj, "ram-size", OBJECT(&s->sdmc),
628
@@ -XXX,XX +XXX,XX @@ static const TypeInfo cprman_pll_channel_info = {
71
"ram-size", &error_abort);
72
object_property_add_alias(obj, "max-ram-size", OBJECT(&s->sdmc),
73
diff --git a/hw/misc/aspeed_sdmc.c b/hw/misc/aspeed_sdmc.c
74
index XXXXXXX..XXXXXXX 100644
75
--- a/hw/misc/aspeed_sdmc.c
76
+++ b/hw/misc/aspeed_sdmc.c
77
@@ -XXX,XX +XXX,XX @@ static void aspeed_sdmc_write(void *opaque, hwaddr addr, uint64_t data,
78
unsigned int size)
79
{
80
AspeedSDMCState *s = ASPEED_SDMC(opaque);
81
+ AspeedSDMCClass *asc = ASPEED_SDMC_GET_CLASS(s);
82
83
addr >>= 2;
84
85
@@ -XXX,XX +XXX,XX @@ static void aspeed_sdmc_write(void *opaque, hwaddr addr, uint64_t data,
86
return;
87
}
88
89
- if (addr == R_CONF) {
90
- /* Make sure readonly bits are kept */
91
- switch (s->silicon_rev) {
92
- case AST2400_A0_SILICON_REV:
93
- case AST2400_A1_SILICON_REV:
94
- data &= ~ASPEED_SDMC_READONLY_MASK;
95
- data |= s->fixed_conf;
96
- break;
97
- case AST2500_A0_SILICON_REV:
98
- case AST2500_A1_SILICON_REV:
99
- data &= ~ASPEED_SDMC_AST2500_READONLY_MASK;
100
- data |= s->fixed_conf;
101
- break;
102
- default:
103
- g_assert_not_reached();
104
- }
105
- }
106
- if (s->silicon_rev == AST2500_A0_SILICON_REV ||
107
- s->silicon_rev == AST2500_A1_SILICON_REV) {
108
- switch (addr) {
109
- case R_STATUS1:
110
- /* Will never return 'busy' */
111
- data &= ~PHY_BUSY_STATE;
112
- break;
113
- case R_ECC_TEST_CTRL:
114
- /* Always done, always happy */
115
- data |= ECC_TEST_FINISHED;
116
- data &= ~ECC_TEST_FAIL;
117
- break;
118
- default:
119
- break;
120
- }
121
- }
122
-
123
- s->regs[addr] = data;
124
+ asc->write(s, addr, data);
125
}
126
127
static const MemoryRegionOps aspeed_sdmc_ops = {
128
@@ -XXX,XX +XXX,XX @@ static int ast2500_rambits(AspeedSDMCState *s)
129
static void aspeed_sdmc_reset(DeviceState *dev)
130
{
131
AspeedSDMCState *s = ASPEED_SDMC(dev);
132
+ AspeedSDMCClass *asc = ASPEED_SDMC_GET_CLASS(s);
133
134
memset(s->regs, 0, sizeof(s->regs));
135
136
/* Set ram size bit and defaults values */
137
- s->regs[R_CONF] = s->fixed_conf;
138
+ s->regs[R_CONF] = asc->compute_conf(s, 0);
139
}
140
141
static void aspeed_sdmc_realize(DeviceState *dev, Error **errp)
142
{
143
SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
144
AspeedSDMCState *s = ASPEED_SDMC(dev);
145
+ AspeedSDMCClass *asc = ASPEED_SDMC_GET_CLASS(s);
146
147
- if (!is_supported_silicon_rev(s->silicon_rev)) {
148
- error_setg(errp, "Unknown silicon revision: 0x%" PRIx32,
149
- s->silicon_rev);
150
- return;
151
- }
152
-
153
- switch (s->silicon_rev) {
154
- case AST2400_A0_SILICON_REV:
155
- case AST2400_A1_SILICON_REV:
156
- s->ram_bits = ast2400_rambits(s);
157
- s->max_ram_size = 512 << 20;
158
- s->fixed_conf = ASPEED_SDMC_VGA_COMPAT |
159
- ASPEED_SDMC_DRAM_SIZE(s->ram_bits);
160
- break;
161
- case AST2500_A0_SILICON_REV:
162
- case AST2500_A1_SILICON_REV:
163
- s->ram_bits = ast2500_rambits(s);
164
- s->max_ram_size = 1024 << 20;
165
- s->fixed_conf = ASPEED_SDMC_HW_VERSION(1) |
166
- ASPEED_SDMC_VGA_APERTURE(ASPEED_SDMC_VGA_64MB) |
167
- ASPEED_SDMC_CACHE_INITIAL_DONE |
168
- ASPEED_SDMC_DRAM_SIZE(s->ram_bits);
169
- break;
170
- default:
171
- g_assert_not_reached();
172
- }
173
+ s->max_ram_size = asc->max_ram_size;
174
175
memory_region_init_io(&s->iomem, OBJECT(s), &aspeed_sdmc_ops, s,
176
TYPE_ASPEED_SDMC, 0x1000);
177
@@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_aspeed_sdmc = {
178
};
629
};
179
630
180
static Property aspeed_sdmc_properties[] = {
631
181
- DEFINE_PROP_UINT32("silicon-rev", AspeedSDMCState, silicon_rev, 0),
632
+/* clock mux */
182
DEFINE_PROP_UINT64("ram-size", AspeedSDMCState, ram_size, 0),
633
+
183
DEFINE_PROP_UINT64("max-ram-size", AspeedSDMCState, max_ram_size, 0),
634
+static void clock_mux_update(CprmanClockMuxState *mux)
184
DEFINE_PROP_END_OF_LIST(),
635
+{
185
@@ -XXX,XX +XXX,XX @@ static const TypeInfo aspeed_sdmc_info = {
636
+ clock_update(mux->out, 0);
186
.parent = TYPE_SYS_BUS_DEVICE,
637
+}
187
.instance_size = sizeof(AspeedSDMCState),
638
+
188
.class_init = aspeed_sdmc_class_init,
639
+static void clock_mux_src_update(void *opaque)
189
+ .class_size = sizeof(AspeedSDMCClass),
640
+{
190
+ .abstract = true,
641
+ CprmanClockMuxState **backref = opaque;
642
+ CprmanClockMuxState *s = *backref;
643
+
644
+ clock_mux_update(s);
645
+}
646
+
647
+static void clock_mux_init(Object *obj)
648
+{
649
+ CprmanClockMuxState *s = CPRMAN_CLOCK_MUX(obj);
650
+ size_t i;
651
+
652
+ for (i = 0; i < CPRMAN_NUM_CLOCK_MUX_SRC; i++) {
653
+ char *name = g_strdup_printf("srcs[%zu]", i);
654
+ s->backref[i] = s;
655
+ s->srcs[i] = qdev_init_clock_in(DEVICE(s), name,
656
+ clock_mux_src_update,
657
+ &s->backref[i]);
658
+ g_free(name);
659
+ }
660
+
661
+ s->out = qdev_init_clock_out(DEVICE(s), "out");
662
+}
663
+
664
+static const VMStateDescription clock_mux_vmstate = {
665
+ .name = TYPE_CPRMAN_CLOCK_MUX,
666
+ .version_id = 1,
667
+ .minimum_version_id = 1,
668
+ .fields = (VMStateField[]) {
669
+ VMSTATE_ARRAY_CLOCK(srcs, CprmanClockMuxState,
670
+ CPRMAN_NUM_CLOCK_MUX_SRC),
671
+ VMSTATE_END_OF_LIST()
672
+ }
191
+};
673
+};
192
+
674
+
193
+static uint32_t aspeed_2400_sdmc_compute_conf(AspeedSDMCState *s, uint32_t data)
675
+static void clock_mux_class_init(ObjectClass *klass, void *data)
194
+{
195
+ uint32_t fixed_conf = ASPEED_SDMC_VGA_COMPAT |
196
+ ASPEED_SDMC_DRAM_SIZE(ast2400_rambits(s));
197
+
198
+ /* Make sure readonly bits are kept */
199
+ data &= ~ASPEED_SDMC_READONLY_MASK;
200
+
201
+ return data | fixed_conf;
202
+}
203
+
204
+static void aspeed_2400_sdmc_write(AspeedSDMCState *s, uint32_t reg,
205
+ uint32_t data)
206
+{
207
+ switch (reg) {
208
+ case R_CONF:
209
+ data = aspeed_2400_sdmc_compute_conf(s, data);
210
+ break;
211
+ default:
212
+ break;
213
+ }
214
+
215
+ s->regs[reg] = data;
216
+}
217
+
218
+static void aspeed_2400_sdmc_class_init(ObjectClass *klass, void *data)
219
+{
676
+{
220
+ DeviceClass *dc = DEVICE_CLASS(klass);
677
+ DeviceClass *dc = DEVICE_CLASS(klass);
221
+ AspeedSDMCClass *asc = ASPEED_SDMC_CLASS(klass);
678
+
222
+
679
+ dc->vmsd = &clock_mux_vmstate;
223
+ dc->desc = "ASPEED 2400 SDRAM Memory Controller";
224
+ asc->max_ram_size = 512 << 20;
225
+ asc->compute_conf = aspeed_2400_sdmc_compute_conf;
226
+ asc->write = aspeed_2400_sdmc_write;
227
+}
680
+}
228
+
681
+
229
+static const TypeInfo aspeed_2400_sdmc_info = {
682
+static const TypeInfo cprman_clock_mux_info = {
230
+ .name = TYPE_ASPEED_2400_SDMC,
683
+ .name = TYPE_CPRMAN_CLOCK_MUX,
231
+ .parent = TYPE_ASPEED_SDMC,
684
+ .parent = TYPE_DEVICE,
232
+ .class_init = aspeed_2400_sdmc_class_init,
685
+ .instance_size = sizeof(CprmanClockMuxState),
686
+ .class_init = clock_mux_class_init,
687
+ .instance_init = clock_mux_init,
233
+};
688
+};
234
+
689
+
235
+static uint32_t aspeed_2500_sdmc_compute_conf(AspeedSDMCState *s, uint32_t data)
690
+
691
/* CPRMAN "top level" model */
692
693
static uint32_t get_cm_lock(const BCM2835CprmanState *s)
694
@@ -XXX,XX +XXX,XX @@ static inline void update_channel_from_a2w(BCM2835CprmanState *s, size_t idx)
695
}
696
}
697
698
+static inline void update_mux_from_cm(BCM2835CprmanState *s, size_t idx)
236
+{
699
+{
237
+ uint32_t fixed_conf = ASPEED_SDMC_HW_VERSION(1) |
700
+ size_t i;
238
+ ASPEED_SDMC_VGA_APERTURE(ASPEED_SDMC_VGA_64MB) |
701
+
239
+ ASPEED_SDMC_CACHE_INITIAL_DONE |
702
+ for (i = 0; i < CPRMAN_NUM_CLOCK_MUX; i++) {
240
+ ASPEED_SDMC_DRAM_SIZE(ast2500_rambits(s));
703
+ if ((CLOCK_MUX_INIT_INFO[i].cm_offset == idx) ||
241
+
704
+ (CLOCK_MUX_INIT_INFO[i].cm_offset + 4 == idx)) {
242
+ /* Make sure readonly bits are kept */
705
+ /* matches CM_CTL or CM_DIV mux register */
243
+ data &= ~ASPEED_SDMC_AST2500_READONLY_MASK;
706
+ clock_mux_update(&s->clock_muxes[i]);
244
+
707
+ return;
245
+ return data | fixed_conf;
708
+ }
709
+ }
246
+}
710
+}
247
+
711
+
248
+static void aspeed_2500_sdmc_write(AspeedSDMCState *s, uint32_t reg,
712
#define CASE_PLL_A2W_REGS(pll_) \
249
+ uint32_t data)
713
case R_A2W_ ## pll_ ## _CTRL: \
714
case R_A2W_ ## pll_ ## _ANA0: \
715
@@ -XXX,XX +XXX,XX @@ static void cprman_write(void *opaque, hwaddr offset,
716
case R_A2W_PLLB_ARM:
717
update_channel_from_a2w(s, idx);
718
break;
719
+
720
+ case R_CM_GNRICCTL ... R_CM_SMIDIV:
721
+ case R_CM_TCNTCNT ... R_CM_VECDIV:
722
+ case R_CM_PULSECTL ... R_CM_PULSEDIV:
723
+ case R_CM_SDCCTL ... R_CM_ARMCTL:
724
+ case R_CM_AVEOCTL ... R_CM_EMMCDIV:
725
+ case R_CM_EMMC2CTL ... R_CM_EMMC2DIV:
726
+ update_mux_from_cm(s, idx);
727
+ break;
728
}
729
}
730
731
@@ -XXX,XX +XXX,XX @@ static void cprman_reset(DeviceState *dev)
732
device_cold_reset(DEVICE(&s->channels[i]));
733
}
734
735
+ for (i = 0; i < CPRMAN_NUM_CLOCK_MUX; i++) {
736
+ device_cold_reset(DEVICE(&s->clock_muxes[i]));
737
+ }
738
+
739
clock_update_hz(s->xosc, s->xosc_freq);
740
}
741
742
@@ -XXX,XX +XXX,XX @@ static void cprman_init(Object *obj)
743
set_pll_channel_init_info(s, &s->channels[i], i);
744
}
745
746
+ for (i = 0; i < CPRMAN_NUM_CLOCK_MUX; i++) {
747
+ char *alias;
748
+
749
+ object_initialize_child(obj, CLOCK_MUX_INIT_INFO[i].name,
750
+ &s->clock_muxes[i],
751
+ TYPE_CPRMAN_CLOCK_MUX);
752
+ set_clock_mux_init_info(s, &s->clock_muxes[i], i);
753
+
754
+ /* Expose muxes output as CPRMAN outputs */
755
+ alias = g_strdup_printf("%s-out", CLOCK_MUX_INIT_INFO[i].name);
756
+ qdev_alias_clock(DEVICE(&s->clock_muxes[i]), "out", DEVICE(obj), alias);
757
+ g_free(alias);
758
+ }
759
+
760
s->xosc = clock_new(obj, "xosc");
761
+ s->gnd = clock_new(obj, "gnd");
762
+
763
+ clock_set(s->gnd, 0);
764
765
memory_region_init_io(&s->iomem, obj, &cprman_ops,
766
s, "bcm2835-cprman", 0x2000);
767
sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->iomem);
768
}
769
770
+static void connect_mux_sources(BCM2835CprmanState *s,
771
+ CprmanClockMuxState *mux,
772
+ const CprmanPllChannel *clk_mapping)
250
+{
773
+{
251
+ switch (reg) {
774
+ size_t i;
252
+ case R_CONF:
775
+ Clock *td0 = s->clock_muxes[CPRMAN_CLOCK_TD0].out;
253
+ data = aspeed_2500_sdmc_compute_conf(s, data);
776
+ Clock *td1 = s->clock_muxes[CPRMAN_CLOCK_TD1].out;
254
+ break;
777
+
255
+ case R_STATUS1:
778
+ /* For sources from 0 to 3. Source 4 to 9 are mux specific */
256
+ /* Will never return 'busy' */
779
+ Clock * const CLK_SRC_MAPPING[] = {
257
+ data &= ~PHY_BUSY_STATE;
780
+ [CPRMAN_CLOCK_SRC_GND] = s->gnd,
258
+ break;
781
+ [CPRMAN_CLOCK_SRC_XOSC] = s->xosc,
259
+ case R_ECC_TEST_CTRL:
782
+ [CPRMAN_CLOCK_SRC_TD0] = td0,
260
+ /* Always done, always happy */
783
+ [CPRMAN_CLOCK_SRC_TD1] = td1,
261
+ data |= ECC_TEST_FINISHED;
784
+ };
262
+ data &= ~ECC_TEST_FAIL;
785
+
263
+ break;
786
+ for (i = 0; i < CPRMAN_NUM_CLOCK_MUX_SRC; i++) {
264
+ default:
787
+ CprmanPllChannel mapping = clk_mapping[i];
265
+ break;
788
+ Clock *src;
266
+ }
789
+
267
+
790
+ if (mapping == CPRMAN_CLOCK_SRC_FORCE_GROUND) {
268
+ s->regs[reg] = data;
791
+ src = s->gnd;
792
+ } else if (mapping == CPRMAN_CLOCK_SRC_DSI0HSCK) {
793
+ src = s->gnd; /* TODO */
794
+ } else if (i < CPRMAN_CLOCK_SRC_PLLA) {
795
+ src = CLK_SRC_MAPPING[i];
796
+ } else {
797
+ src = s->channels[mapping].out;
798
+ }
799
+
800
+ clock_set_source(mux->srcs[i], src);
801
+ }
269
+}
802
+}
270
+
803
+
271
+static void aspeed_2500_sdmc_class_init(ObjectClass *klass, void *data)
804
static void cprman_realize(DeviceState *dev, Error **errp)
272
+{
273
+ DeviceClass *dc = DEVICE_CLASS(klass);
274
+ AspeedSDMCClass *asc = ASPEED_SDMC_CLASS(klass);
275
+
276
+ dc->desc = "ASPEED 2500 SDRAM Memory Controller";
277
+ asc->max_ram_size = 1024 << 20;
278
+ asc->compute_conf = aspeed_2500_sdmc_compute_conf;
279
+ asc->write = aspeed_2500_sdmc_write;
280
+}
281
+
282
+static const TypeInfo aspeed_2500_sdmc_info = {
283
+ .name = TYPE_ASPEED_2500_SDMC,
284
+ .parent = TYPE_ASPEED_SDMC,
285
+ .class_init = aspeed_2500_sdmc_class_init,
286
};
287
288
static void aspeed_sdmc_register_types(void)
289
{
805
{
290
type_register_static(&aspeed_sdmc_info);
806
BCM2835CprmanState *s = CPRMAN(dev);
291
+ type_register_static(&aspeed_2400_sdmc_info);
807
@@ -XXX,XX +XXX,XX @@ static void cprman_realize(DeviceState *dev, Error **errp)
292
+ type_register_static(&aspeed_2500_sdmc_info);
808
return;
809
}
810
}
811
+
812
+ for (i = 0; i < CPRMAN_NUM_CLOCK_MUX; i++) {
813
+ CprmanClockMuxState *clock_mux = &s->clock_muxes[i];
814
+
815
+ connect_mux_sources(s, clock_mux, CLOCK_MUX_INIT_INFO[i].src_mapping);
816
+
817
+ if (!qdev_realize(DEVICE(clock_mux), NULL, errp)) {
818
+ return;
819
+ }
820
+ }
293
}
821
}
294
822
295
type_init(aspeed_sdmc_register_types);
823
static const VMStateDescription cprman_vmstate = {
824
@@ -XXX,XX +XXX,XX @@ static void cprman_register_types(void)
825
type_register_static(&cprman_info);
826
type_register_static(&cprman_pll_info);
827
type_register_static(&cprman_pll_channel_info);
828
+ type_register_static(&cprman_clock_mux_info);
829
}
830
831
type_init(cprman_register_types);
296
--
832
--
297
2.20.1
833
2.20.1
298
834
299
835
diff view generated by jsdifflib
1
Currently the Arm semihosting code returns the guest file descriptors
1
From: Luc Michel <luc@lmichel.fr>
2
(handles) which are simply the fd values from the host OS or the
3
remote gdbstub. Part of the semihosting 2.0 specification requires
4
that we implement special handling of opening a ":semihosting-features"
5
filename. Guest fds which result from opening the special file
6
won't correspond to host fds, so to ensure that we don't end up
7
with duplicate fds we need to have QEMU code control the allocation
8
of the fd values we give the guest.
9
2
10
Add in an abstraction layer which lets us allocate new guest FD
3
A clock mux can be configured to select one of its 10 sources through
11
values, and translate from a guest FD value back to the host one.
4
the CM_CTL register. It also embeds yet another clock divider, composed
12
This also fixes an odd hole where a semihosting guest could
5
of an integer part and a fractional part. The number of bits of each
13
use the semihosting API to read, write or close file descriptors
6
part is mux dependent.
14
that it had never allocated but which were being used by QEMU itself.
15
(This isn't a security hole, because enabling semihosting permits
16
the guest to do arbitrary file access to the whole host filesystem,
17
and so should only be done if the guest is completely trusted.)
18
7
19
Currently the only kind of guest fd is one which maps to a
8
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
20
host fd, but in a following commit we will add one which maps
9
Signed-off-by: Luc Michel <luc@lmichel.fr>
21
to the :semihosting-features magic data.
10
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
11
Tested-by: Guenter Roeck <linux@roeck-us.net>
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
---
14
hw/misc/bcm2835_cprman.c | 53 +++++++++++++++++++++++++++++++++++++++-
15
1 file changed, 52 insertions(+), 1 deletion(-)
22
16
23
If the guest is migrated with an open semihosting file descriptor
17
diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c
24
then subsequent attempts to use the fd will all fail; this is
25
not a change from the previous situation (where the host fd
26
being used on the source end would not be re-opened on the
27
destination end).
28
29
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
30
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
31
Message-id: 20190916141544.17540-5-peter.maydell@linaro.org
32
---
33
target/arm/arm-semi.c | 232 +++++++++++++++++++++++++++++++++++++++---
34
1 file changed, 216 insertions(+), 16 deletions(-)
35
36
diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c
37
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
38
--- a/target/arm/arm-semi.c
19
--- a/hw/misc/bcm2835_cprman.c
39
+++ b/target/arm/arm-semi.c
20
+++ b/hw/misc/bcm2835_cprman.c
40
@@ -XXX,XX +XXX,XX @@ static int open_modeflags[12] = {
21
@@ -XXX,XX +XXX,XX @@ static const TypeInfo cprman_pll_channel_info = {
41
O_RDWR | O_CREAT | O_APPEND | O_BINARY
22
42
};
23
/* clock mux */
43
24
44
+typedef enum GuestFDType {
25
+static bool clock_mux_is_enabled(CprmanClockMuxState *mux)
45
+ GuestFDUnused = 0,
26
+{
46
+ GuestFDHost = 1,
27
+ return FIELD_EX32(*mux->reg_ctl, CM_CLOCKx_CTL, ENABLE);
47
+} GuestFDType;
28
+}
48
+
29
+
49
+/*
30
static void clock_mux_update(CprmanClockMuxState *mux)
50
+ * Guest file descriptors are integer indexes into an array of
31
{
51
+ * these structures (we will dynamically resize as necessary).
32
- clock_update(mux->out, 0);
52
+ */
33
+ uint64_t freq;
53
+typedef struct GuestFD {
34
+ uint32_t div, src = FIELD_EX32(*mux->reg_ctl, CM_CLOCKx_CTL, SRC);
54
+ GuestFDType type;
35
+ bool enabled = clock_mux_is_enabled(mux);
55
+ int hostfd;
56
+} GuestFD;
57
+
36
+
58
+static GArray *guestfd_array;
37
+ *mux->reg_ctl = FIELD_DP32(*mux->reg_ctl, CM_CLOCKx_CTL, BUSY, enabled);
59
+
38
+
60
+/*
39
+ if (!enabled) {
61
+ * Allocate a new guest file descriptor and return it; if we
40
+ clock_update(mux->out, 0);
62
+ * couldn't allocate a new fd then return -1.
41
+ return;
63
+ * This is a fairly simplistic implementation because we don't
64
+ * expect that most semihosting guest programs will make very
65
+ * heavy use of opening and closing fds.
66
+ */
67
+static int alloc_guestfd(void)
68
+{
69
+ guint i;
70
+
71
+ if (!guestfd_array) {
72
+ /* New entries zero-initialized, i.e. type GuestFDUnused */
73
+ guestfd_array = g_array_new(FALSE, TRUE, sizeof(GuestFD));
74
+ }
42
+ }
75
+
43
+
76
+ for (i = 0; i < guestfd_array->len; i++) {
44
+ freq = clock_get_hz(mux->srcs[src]);
77
+ GuestFD *gf = &g_array_index(guestfd_array, GuestFD, i);
78
+
45
+
79
+ if (gf->type == GuestFDUnused) {
46
+ if (mux->int_bits == 0 && mux->frac_bits == 0) {
80
+ return i;
47
+ clock_update_hz(mux->out, freq);
81
+ }
48
+ return;
82
+ }
49
+ }
83
+
50
+
84
+ /* All elements already in use: expand the array */
51
+ /*
85
+ g_array_set_size(guestfd_array, i + 1);
52
+ * The divider has an integer and a fractional part. The size of each part
86
+ return i;
53
+ * varies with the muxes (int_bits and frac_bits). Both parts are
87
+}
54
+ * concatenated, with the integer part always starting at bit 12.
55
+ *
56
+ * 31 12 11 0
57
+ * ------------------------------
58
+ * CM_DIV | | int | frac | |
59
+ * ------------------------------
60
+ * <-----> <------>
61
+ * int_bits frac_bits
62
+ */
63
+ div = extract32(*mux->reg_div,
64
+ R_CM_CLOCKx_DIV_FRAC_LENGTH - mux->frac_bits,
65
+ mux->int_bits + mux->frac_bits);
88
+
66
+
89
+/*
67
+ if (!div) {
90
+ * Look up the guestfd in the data structure; return NULL
68
+ clock_update(mux->out, 0);
91
+ * for out of bounds, but don't check whether the slot is unused.
69
+ return;
92
+ * This is used internally by the other guestfd functions.
93
+ */
94
+static GuestFD *do_get_guestfd(int guestfd)
95
+{
96
+ if (!guestfd_array) {
97
+ return NULL;
98
+ }
70
+ }
99
+
71
+
100
+ if (guestfd < 0 || guestfd >= guestfd_array->len) {
72
+ freq = muldiv64(freq, 1 << mux->frac_bits, div);
101
+ return NULL;
73
+
74
+ clock_update_hz(mux->out, freq);
75
}
76
77
static void clock_mux_src_update(void *opaque)
78
{
79
CprmanClockMuxState **backref = opaque;
80
CprmanClockMuxState *s = *backref;
81
+ CprmanClockMuxSource src = backref - s->backref;
82
+
83
+ if (FIELD_EX32(*s->reg_ctl, CM_CLOCKx_CTL, SRC) != src) {
84
+ return;
102
+ }
85
+ }
103
+
86
104
+ return &g_array_index(guestfd_array, GuestFD, guestfd);
87
clock_mux_update(s);
105
+}
106
+
107
+/*
108
+ * Associate the specified guest fd (which must have been
109
+ * allocated via alloc_fd() and not previously used) with
110
+ * the specified host fd.
111
+ */
112
+static void associate_guestfd(int guestfd, int hostfd)
113
+{
114
+ GuestFD *gf = do_get_guestfd(guestfd);
115
+
116
+ assert(gf);
117
+ gf->type = GuestFDHost;
118
+ gf->hostfd = hostfd;
119
+}
120
+
121
+/*
122
+ * Deallocate the specified guest file descriptor. This doesn't
123
+ * close the host fd, it merely undoes the work of alloc_fd().
124
+ */
125
+static void dealloc_guestfd(int guestfd)
126
+{
127
+ GuestFD *gf = do_get_guestfd(guestfd);
128
+
129
+ assert(gf);
130
+ gf->type = GuestFDUnused;
131
+}
132
+
133
+/*
134
+ * Given a guest file descriptor, get the associated struct.
135
+ * If the fd is not valid, return NULL. This is the function
136
+ * used by the various semihosting calls to validate a handle
137
+ * from the guest.
138
+ * Note: calling alloc_guestfd() or dealloc_guestfd() will
139
+ * invalidate any GuestFD* obtained by calling this function.
140
+ */
141
+static GuestFD *get_guestfd(int guestfd)
142
+{
143
+ GuestFD *gf = do_get_guestfd(guestfd);
144
+
145
+ if (!gf || gf->type == GuestFDUnused) {
146
+ return NULL;
147
+ }
148
+ return gf;
149
+}
150
+
151
#ifdef CONFIG_USER_ONLY
152
static inline uint32_t set_swi_errno(TaskState *ts, uint32_t code)
153
{
154
@@ -XXX,XX +XXX,XX @@ static void arm_semi_flen_cb(CPUState *cs, target_ulong ret, target_ulong err)
155
#endif
156
}
88
}
157
158
+static int arm_semi_open_guestfd;
159
+
160
+static void arm_semi_open_cb(CPUState *cs, target_ulong ret, target_ulong err)
161
+{
162
+ ARMCPU *cpu = ARM_CPU(cs);
163
+ CPUARMState *env = &cpu->env;
164
+#ifdef CONFIG_USER_ONLY
165
+ TaskState *ts = cs->opaque;
166
+#endif
167
+ if (ret == (target_ulong)-1) {
168
+#ifdef CONFIG_USER_ONLY
169
+ ts->swi_errno = err;
170
+#else
171
+ syscall_err = err;
172
+#endif
173
+ dealloc_guestfd(arm_semi_open_guestfd);
174
+ } else {
175
+ associate_guestfd(arm_semi_open_guestfd, ret);
176
+ ret = arm_semi_open_guestfd;
177
+ }
178
+
179
+ if (is_a64(env)) {
180
+ env->xregs[0] = ret;
181
+ } else {
182
+ env->regs[0] = ret;
183
+ }
184
+}
185
+
186
static target_ulong arm_gdb_syscall(ARMCPU *cpu, gdb_syscall_complete_cb cb,
187
const char *fmt, ...)
188
{
189
@@ -XXX,XX +XXX,XX @@ target_ulong do_arm_semihosting(CPUARMState *env)
190
#else
191
CPUARMState *ts = env;
192
#endif
193
+ GuestFD *gf;
194
195
if (is_a64(env)) {
196
/* Note that the syscall number is in W0, not X0 */
197
@@ -XXX,XX +XXX,XX @@ target_ulong do_arm_semihosting(CPUARMState *env)
198
199
switch (nr) {
200
case TARGET_SYS_OPEN:
201
+ {
202
+ int guestfd;
203
+
204
GET_ARG(0);
205
GET_ARG(1);
206
GET_ARG(2);
207
@@ -XXX,XX +XXX,XX @@ target_ulong do_arm_semihosting(CPUARMState *env)
208
errno = EINVAL;
209
return set_swi_errno(ts, -1);
210
}
211
+
212
+ guestfd = alloc_guestfd();
213
+ if (guestfd < 0) {
214
+ unlock_user(s, arg0, 0);
215
+ errno = EMFILE;
216
+ return set_swi_errno(ts, -1);
217
+ }
218
+
219
if (strcmp(s, ":tt") == 0) {
220
int result_fileno = arg1 < 4 ? STDIN_FILENO : STDOUT_FILENO;
221
+ associate_guestfd(guestfd, result_fileno);
222
unlock_user(s, arg0, 0);
223
- return result_fileno;
224
+ return guestfd;
225
}
226
if (use_gdb_syscalls()) {
227
- ret = arm_gdb_syscall(cpu, arm_semi_cb, "open,%s,%x,1a4", arg0,
228
+ arm_semi_open_guestfd = guestfd;
229
+ ret = arm_gdb_syscall(cpu, arm_semi_open_cb, "open,%s,%x,1a4", arg0,
230
(int)arg2+1, gdb_open_modeflags[arg1]);
231
} else {
232
ret = set_swi_errno(ts, open(s, open_modeflags[arg1], 0644));
233
+ if (ret == (uint32_t)-1) {
234
+ dealloc_guestfd(guestfd);
235
+ } else {
236
+ associate_guestfd(guestfd, ret);
237
+ ret = guestfd;
238
+ }
239
}
240
unlock_user(s, arg0, 0);
241
return ret;
242
+ }
243
case TARGET_SYS_CLOSE:
244
GET_ARG(0);
245
- if (use_gdb_syscalls()) {
246
- return arm_gdb_syscall(cpu, arm_semi_cb, "close,%x", arg0);
247
- } else {
248
- return set_swi_errno(ts, close(arg0));
249
+
250
+ gf = get_guestfd(arg0);
251
+ if (!gf) {
252
+ errno = EBADF;
253
+ return set_swi_errno(ts, -1);
254
}
255
+
256
+ if (use_gdb_syscalls()) {
257
+ ret = arm_gdb_syscall(cpu, arm_semi_cb, "close,%x", gf->hostfd);
258
+ } else {
259
+ ret = set_swi_errno(ts, close(gf->hostfd));
260
+ }
261
+ dealloc_guestfd(arg0);
262
+ return ret;
263
case TARGET_SYS_WRITEC:
264
qemu_semihosting_console_outc(env, args);
265
return 0xdeadbeef;
266
@@ -XXX,XX +XXX,XX @@ target_ulong do_arm_semihosting(CPUARMState *env)
267
GET_ARG(1);
268
GET_ARG(2);
269
len = arg2;
270
+
271
+ gf = get_guestfd(arg0);
272
+ if (!gf) {
273
+ errno = EBADF;
274
+ return set_swi_errno(ts, -1);
275
+ }
276
+
277
if (use_gdb_syscalls()) {
278
arm_semi_syscall_len = len;
279
return arm_gdb_syscall(cpu, arm_semi_cb, "write,%x,%x,%x",
280
- arg0, arg1, len);
281
+ gf->hostfd, arg1, len);
282
} else {
283
s = lock_user(VERIFY_READ, arg1, len, 1);
284
if (!s) {
285
/* Return bytes not written on error */
286
return len;
287
}
288
- ret = set_swi_errno(ts, write(arg0, s, len));
289
+ ret = set_swi_errno(ts, write(gf->hostfd, s, len));
290
unlock_user(s, arg1, 0);
291
if (ret == (uint32_t)-1) {
292
ret = 0;
293
@@ -XXX,XX +XXX,XX @@ target_ulong do_arm_semihosting(CPUARMState *env)
294
GET_ARG(1);
295
GET_ARG(2);
296
len = arg2;
297
+
298
+ gf = get_guestfd(arg0);
299
+ if (!gf) {
300
+ errno = EBADF;
301
+ return set_swi_errno(ts, -1);
302
+ }
303
+
304
if (use_gdb_syscalls()) {
305
arm_semi_syscall_len = len;
306
return arm_gdb_syscall(cpu, arm_semi_cb, "read,%x,%x,%x",
307
- arg0, arg1, len);
308
+ gf->hostfd, arg1, len);
309
} else {
310
s = lock_user(VERIFY_WRITE, arg1, len, 0);
311
if (!s) {
312
@@ -XXX,XX +XXX,XX @@ target_ulong do_arm_semihosting(CPUARMState *env)
313
return len;
314
}
315
do {
316
- ret = set_swi_errno(ts, read(arg0, s, len));
317
+ ret = set_swi_errno(ts, read(gf->hostfd, s, len));
318
} while (ret == -1 && errno == EINTR);
319
unlock_user(s, arg1, len);
320
if (ret == (uint32_t)-1) {
321
@@ -XXX,XX +XXX,XX @@ target_ulong do_arm_semihosting(CPUARMState *env)
322
return 0;
323
case TARGET_SYS_ISTTY:
324
GET_ARG(0);
325
+
326
+ gf = get_guestfd(arg0);
327
+ if (!gf) {
328
+ errno = EBADF;
329
+ return set_swi_errno(ts, -1);
330
+ }
331
+
332
if (use_gdb_syscalls()) {
333
- return arm_gdb_syscall(cpu, arm_semi_cb, "isatty,%x", arg0);
334
+ return arm_gdb_syscall(cpu, arm_semi_cb, "isatty,%x", gf->hostfd);
335
} else {
336
- return isatty(arg0);
337
+ return isatty(gf->hostfd);
338
}
339
case TARGET_SYS_SEEK:
340
GET_ARG(0);
341
GET_ARG(1);
342
+
343
+ gf = get_guestfd(arg0);
344
+ if (!gf) {
345
+ errno = EBADF;
346
+ return set_swi_errno(ts, -1);
347
+ }
348
+
349
if (use_gdb_syscalls()) {
350
return arm_gdb_syscall(cpu, arm_semi_cb, "lseek,%x,%x,0",
351
- arg0, arg1);
352
+ gf->hostfd, arg1);
353
} else {
354
- ret = set_swi_errno(ts, lseek(arg0, arg1, SEEK_SET));
355
+ ret = set_swi_errno(ts, lseek(gf->hostfd, arg1, SEEK_SET));
356
if (ret == (uint32_t)-1)
357
return -1;
358
return 0;
359
}
360
case TARGET_SYS_FLEN:
361
GET_ARG(0);
362
+
363
+ gf = get_guestfd(arg0);
364
+ if (!gf) {
365
+ errno = EBADF;
366
+ return set_swi_errno(ts, -1);
367
+ }
368
+
369
if (use_gdb_syscalls()) {
370
return arm_gdb_syscall(cpu, arm_semi_flen_cb, "fstat,%x,%x",
371
- arg0, arm_flen_buf(cpu));
372
+ gf->hostfd, arm_flen_buf(cpu));
373
} else {
374
struct stat buf;
375
- ret = set_swi_errno(ts, fstat(arg0, &buf));
376
+ ret = set_swi_errno(ts, fstat(gf->hostfd, &buf));
377
if (ret == (uint32_t)-1)
378
return -1;
379
return buf.st_size;
380
--
89
--
381
2.20.1
90
2.20.1
382
91
383
92
diff view generated by jsdifflib
1
From: Cédric Le Goater <clg@kaod.org>
1
From: Luc Michel <luc@lmichel.fr>
2
2
3
The AST2600 SoC SMC controller is a SPI only controller now and has a
3
This simple mux sits between the PLL channels and the DSI0E and DSI0P
4
few extensions which we will need to take into account when SW
4
clock muxes. This mux selects between PLLA-DSI0 and PLLD-DSI0 channel
5
requires it. This is enough to support u-boot and Linux.
5
and outputs the selected signal to source number 4 of DSI0E/P clock
6
6
muxes. It is controlled by the cm_dsi0hsck register.
7
Signed-off-by: Cédric Le Goater <clg@kaod.org>
7
8
Acked-by: Joel Stanley <joel@jms.id.au>
8
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
9
Message-id: 20190925143248.10000-14-clg@kaod.org
9
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
10
Signed-off-by: Luc Michel <luc@lmichel.fr>
11
Tested-by: Guenter Roeck <linux@roeck-us.net>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
---
13
---
12
hw/ssi/aspeed_smc.c | 132 ++++++++++++++++++++++++++++++++++++++++++--
14
include/hw/misc/bcm2835_cprman.h | 15 +++++
13
1 file changed, 128 insertions(+), 4 deletions(-)
15
include/hw/misc/bcm2835_cprman_internals.h | 6 ++
14
16
hw/misc/bcm2835_cprman.c | 74 +++++++++++++++++++++-
15
diff --git a/hw/ssi/aspeed_smc.c b/hw/ssi/aspeed_smc.c
17
3 files changed, 94 insertions(+), 1 deletion(-)
18
19
diff --git a/include/hw/misc/bcm2835_cprman.h b/include/hw/misc/bcm2835_cprman.h
16
index XXXXXXX..XXXXXXX 100644
20
index XXXXXXX..XXXXXXX 100644
17
--- a/hw/ssi/aspeed_smc.c
21
--- a/include/hw/misc/bcm2835_cprman.h
18
+++ b/hw/ssi/aspeed_smc.c
22
+++ b/include/hw/misc/bcm2835_cprman.h
23
@@ -XXX,XX +XXX,XX @@ typedef struct CprmanClockMuxState {
24
struct CprmanClockMuxState *backref[CPRMAN_NUM_CLOCK_MUX_SRC];
25
} CprmanClockMuxState;
26
27
+typedef struct CprmanDsi0HsckMuxState {
28
+ /*< private >*/
29
+ DeviceState parent_obj;
30
+
31
+ /*< public >*/
32
+ CprmanClockMux id;
33
+
34
+ uint32_t *reg_cm;
35
+
36
+ Clock *plla_in;
37
+ Clock *plld_in;
38
+ Clock *out;
39
+} CprmanDsi0HsckMuxState;
40
+
41
struct BCM2835CprmanState {
42
/*< private >*/
43
SysBusDevice parent_obj;
44
@@ -XXX,XX +XXX,XX @@ struct BCM2835CprmanState {
45
CprmanPllState plls[CPRMAN_NUM_PLL];
46
CprmanPllChannelState channels[CPRMAN_NUM_PLL_CHANNEL];
47
CprmanClockMuxState clock_muxes[CPRMAN_NUM_CLOCK_MUX];
48
+ CprmanDsi0HsckMuxState dsi0hsck_mux;
49
50
uint32_t regs[CPRMAN_NUM_REGS];
51
uint32_t xosc_freq;
52
diff --git a/include/hw/misc/bcm2835_cprman_internals.h b/include/hw/misc/bcm2835_cprman_internals.h
53
index XXXXXXX..XXXXXXX 100644
54
--- a/include/hw/misc/bcm2835_cprman_internals.h
55
+++ b/include/hw/misc/bcm2835_cprman_internals.h
19
@@ -XXX,XX +XXX,XX @@
56
@@ -XXX,XX +XXX,XX @@
20
#include "qemu/error-report.h"
57
#define TYPE_CPRMAN_PLL "bcm2835-cprman-pll"
21
#include "qapi/error.h"
58
#define TYPE_CPRMAN_PLL_CHANNEL "bcm2835-cprman-pll-channel"
22
#include "exec/address-spaces.h"
59
#define TYPE_CPRMAN_CLOCK_MUX "bcm2835-cprman-clock-mux"
23
+#include "qemu/units.h"
60
+#define TYPE_CPRMAN_DSI0HSCK_MUX "bcm2835-cprman-dsi0hsck-mux"
24
61
25
#include "hw/irq.h"
62
DECLARE_INSTANCE_CHECKER(CprmanPllState, CPRMAN_PLL,
26
#include "hw/qdev-properties.h"
63
TYPE_CPRMAN_PLL)
27
@@ -XXX,XX +XXX,XX @@
64
@@ -XXX,XX +XXX,XX @@ DECLARE_INSTANCE_CHECKER(CprmanPllChannelState, CPRMAN_PLL_CHANNEL,
28
#define CONF_FLASH_TYPE0 0
65
TYPE_CPRMAN_PLL_CHANNEL)
29
#define CONF_FLASH_TYPE_NOR 0x0
66
DECLARE_INSTANCE_CHECKER(CprmanClockMuxState, CPRMAN_CLOCK_MUX,
30
#define CONF_FLASH_TYPE_NAND 0x1
67
TYPE_CPRMAN_CLOCK_MUX)
31
-#define CONF_FLASH_TYPE_SPI 0x2
68
+DECLARE_INSTANCE_CHECKER(CprmanDsi0HsckMuxState, CPRMAN_DSI0HSCK_MUX,
32
+#define CONF_FLASH_TYPE_SPI 0x2 /* AST2600 is SPI only */
69
+ TYPE_CPRMAN_DSI0HSCK_MUX)
33
70
34
/* CE Control Register */
71
/* Register map */
35
#define R_CE_CTRL (0x04 / 4)
72
36
@@ -XXX,XX +XXX,XX @@
73
@@ -XXX,XX +XXX,XX @@ REG32(CM_LOCK, 0x114)
37
74
FIELD(CM_LOCK, FLOCKB, 9, 1)
38
/* CEx Control Register */
75
FIELD(CM_LOCK, FLOCKA, 8, 1)
39
#define R_CTRL0 (0x10 / 4)
76
40
+#define CTRL_IO_QPI (1 << 31)
77
+REG32(CM_DSI0HSCK, 0x120)
41
+#define CTRL_IO_QUAD_DATA (1 << 30)
78
+ FIELD(CM_DSI0HSCK, SELPLLD, 0, 1)
42
#define CTRL_IO_DUAL_DATA (1 << 29)
79
+
43
#define CTRL_IO_DUAL_ADDR_DATA (1 << 28) /* Includes dummies */
80
/*
44
+#define CTRL_IO_QUAD_ADDR_DATA (1 << 28) /* Includes dummies */
81
* This field is common to all registers. Each register write value must match
45
#define CTRL_CMD_SHIFT 16
82
* the CPRMAN_PASSWORD magic value in its 8 MSB.
46
#define CTRL_CMD_MASK 0xff
83
diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c
47
#define CTRL_DUMMY_HIGH_SHIFT 14
84
index XXXXXXX..XXXXXXX 100644
48
@@ -XXX,XX +XXX,XX @@
85
--- a/hw/misc/bcm2835_cprman.c
49
/* Misc Control Register #2 */
86
+++ b/hw/misc/bcm2835_cprman.c
50
#define R_TIMINGS (0x94 / 4)
87
@@ -XXX,XX +XXX,XX @@ static const TypeInfo cprman_clock_mux_info = {
51
88
};
52
-/* SPI controller registers and bits */
89
53
+/* SPI controller registers and bits (AST2400) */
90
54
#define R_SPI_CONF (0x00 / 4)
91
+/* DSI0HSCK mux */
55
#define SPI_CONF_ENABLE_W0 0
92
+
56
#define R_SPI_CTRL0 (0x4 / 4)
93
+static void dsi0hsck_mux_update(CprmanDsi0HsckMuxState *s)
57
@@ -XXX,XX +XXX,XX @@ static uint32_t aspeed_smc_segment_to_reg(const AspeedSMCState *s,
94
+{
58
static void aspeed_smc_reg_to_segment(const AspeedSMCState *s, uint32_t reg,
95
+ bool src_is_plld = FIELD_EX32(*s->reg_cm, CM_DSI0HSCK, SELPLLD);
59
AspeedSegments *seg);
96
+ Clock *src = src_is_plld ? s->plld_in : s->plla_in;
60
97
+
61
+/*
98
+ clock_update(s->out, clock_get(src));
62
+ * AST2600 definitions
99
+}
63
+ */
100
+
64
+#define ASPEED26_SOC_FMC_FLASH_BASE 0x20000000
101
+static void dsi0hsck_mux_in_update(void *opaque)
65
+#define ASPEED26_SOC_SPI_FLASH_BASE 0x30000000
102
+{
66
+#define ASPEED26_SOC_SPI2_FLASH_BASE 0x50000000
103
+ dsi0hsck_mux_update(CPRMAN_DSI0HSCK_MUX(opaque));
67
+
104
+}
68
+static const AspeedSegments aspeed_segments_ast2600_fmc[] = {
105
+
69
+ { 0x0, 128 * MiB }, /* start address is readonly */
106
+static void dsi0hsck_mux_init(Object *obj)
70
+ { 0x0, 0 }, /* disabled */
107
+{
71
+ { 0x0, 0 }, /* disabled */
108
+ CprmanDsi0HsckMuxState *s = CPRMAN_DSI0HSCK_MUX(obj);
109
+ DeviceState *dev = DEVICE(obj);
110
+
111
+ s->plla_in = qdev_init_clock_in(dev, "plla-in", dsi0hsck_mux_in_update, s);
112
+ s->plld_in = qdev_init_clock_in(dev, "plld-in", dsi0hsck_mux_in_update, s);
113
+ s->out = qdev_init_clock_out(DEVICE(s), "out");
114
+}
115
+
116
+static const VMStateDescription dsi0hsck_mux_vmstate = {
117
+ .name = TYPE_CPRMAN_DSI0HSCK_MUX,
118
+ .version_id = 1,
119
+ .minimum_version_id = 1,
120
+ .fields = (VMStateField[]) {
121
+ VMSTATE_CLOCK(plla_in, CprmanDsi0HsckMuxState),
122
+ VMSTATE_CLOCK(plld_in, CprmanDsi0HsckMuxState),
123
+ VMSTATE_END_OF_LIST()
124
+ }
72
+};
125
+};
73
+
126
+
74
+static const AspeedSegments aspeed_segments_ast2600_spi1[] = {
127
+static void dsi0hsck_mux_class_init(ObjectClass *klass, void *data)
75
+ { 0x0, 128 * MiB }, /* start address is readonly */
128
+{
76
+ { 0x0, 0 }, /* disabled */
129
+ DeviceClass *dc = DEVICE_CLASS(klass);
130
+
131
+ dc->vmsd = &dsi0hsck_mux_vmstate;
132
+}
133
+
134
+static const TypeInfo cprman_dsi0hsck_mux_info = {
135
+ .name = TYPE_CPRMAN_DSI0HSCK_MUX,
136
+ .parent = TYPE_DEVICE,
137
+ .instance_size = sizeof(CprmanDsi0HsckMuxState),
138
+ .class_init = dsi0hsck_mux_class_init,
139
+ .instance_init = dsi0hsck_mux_init,
77
+};
140
+};
78
+
141
+
79
+static const AspeedSegments aspeed_segments_ast2600_spi2[] = {
142
+
80
+ { 0x0, 128 * MiB }, /* start address is readonly */
143
/* CPRMAN "top level" model */
81
+ { 0x0, 0 }, /* disabled */
144
82
+ { 0x0, 0 }, /* disabled */
145
static uint32_t get_cm_lock(const BCM2835CprmanState *s)
83
+};
146
@@ -XXX,XX +XXX,XX @@ static void cprman_write(void *opaque, hwaddr offset,
84
+
147
case R_CM_EMMC2CTL ... R_CM_EMMC2DIV:
85
+static uint32_t aspeed_2600_smc_segment_to_reg(const AspeedSMCState *s,
148
update_mux_from_cm(s, idx);
86
+ const AspeedSegments *seg);
149
break;
87
+static void aspeed_2600_smc_reg_to_segment(const AspeedSMCState *s,
150
+
88
+ uint32_t reg, AspeedSegments *seg);
151
+ case R_CM_DSI0HSCK:
89
+
152
+ dsi0hsck_mux_update(&s->dsi0hsck_mux);
90
static const AspeedSMCController controllers[] = {
153
+ break;
91
{
154
}
92
.name = "aspeed.smc-ast2400",
93
@@ -XXX,XX +XXX,XX @@ static const AspeedSMCController controllers[] = {
94
.nregs = ASPEED_SMC_R_MAX,
95
.segment_to_reg = aspeed_smc_segment_to_reg,
96
.reg_to_segment = aspeed_smc_reg_to_segment,
97
+ }, {
98
+ .name = "aspeed.fmc-ast2600",
99
+ .r_conf = R_CONF,
100
+ .r_ce_ctrl = R_CE_CTRL,
101
+ .r_ctrl0 = R_CTRL0,
102
+ .r_timings = R_TIMINGS,
103
+ .conf_enable_w0 = CONF_ENABLE_W0,
104
+ .max_slaves = 3,
105
+ .segments = aspeed_segments_ast2600_fmc,
106
+ .flash_window_base = ASPEED26_SOC_FMC_FLASH_BASE,
107
+ .flash_window_size = 0x10000000,
108
+ .has_dma = true,
109
+ .nregs = ASPEED_SMC_R_MAX,
110
+ .segment_to_reg = aspeed_2600_smc_segment_to_reg,
111
+ .reg_to_segment = aspeed_2600_smc_reg_to_segment,
112
+ }, {
113
+ .name = "aspeed.spi1-ast2600",
114
+ .r_conf = R_CONF,
115
+ .r_ce_ctrl = R_CE_CTRL,
116
+ .r_ctrl0 = R_CTRL0,
117
+ .r_timings = R_TIMINGS,
118
+ .conf_enable_w0 = CONF_ENABLE_W0,
119
+ .max_slaves = 2,
120
+ .segments = aspeed_segments_ast2600_spi1,
121
+ .flash_window_base = ASPEED26_SOC_SPI_FLASH_BASE,
122
+ .flash_window_size = 0x10000000,
123
+ .has_dma = false,
124
+ .nregs = ASPEED_SMC_R_MAX,
125
+ .segment_to_reg = aspeed_2600_smc_segment_to_reg,
126
+ .reg_to_segment = aspeed_2600_smc_reg_to_segment,
127
+ }, {
128
+ .name = "aspeed.spi2-ast2600",
129
+ .r_conf = R_CONF,
130
+ .r_ce_ctrl = R_CE_CTRL,
131
+ .r_ctrl0 = R_CTRL0,
132
+ .r_timings = R_TIMINGS,
133
+ .conf_enable_w0 = CONF_ENABLE_W0,
134
+ .max_slaves = 3,
135
+ .segments = aspeed_segments_ast2600_spi2,
136
+ .flash_window_base = ASPEED26_SOC_SPI2_FLASH_BASE,
137
+ .flash_window_size = 0x10000000,
138
+ .has_dma = false,
139
+ .nregs = ASPEED_SMC_R_MAX,
140
+ .segment_to_reg = aspeed_2600_smc_segment_to_reg,
141
+ .reg_to_segment = aspeed_2600_smc_reg_to_segment,
142
},
143
};
144
145
@@ -XXX,XX +XXX,XX @@ static void aspeed_smc_reg_to_segment(const AspeedSMCState *s,
146
seg->size = (((reg >> SEG_END_SHIFT) & SEG_END_MASK) << 23) - seg->addr;
147
}
155
}
148
156
149
+/*
157
@@ -XXX,XX +XXX,XX @@ static void cprman_reset(DeviceState *dev)
150
+ * The Segment Registers of the AST2600 have a 1MB unit. The address
158
device_cold_reset(DEVICE(&s->channels[i]));
151
+ * range of a flash SPI slave is encoded with offsets in the overall
159
}
152
+ * controller window. The previous SoC AST2400 and AST2500 used
160
153
+ * absolute addresses. Only bits [27:20] are relevant and the end
161
+ device_cold_reset(DEVICE(&s->dsi0hsck_mux));
154
+ * address is an upper bound limit.
162
+
155
+ */
163
for (i = 0; i < CPRMAN_NUM_CLOCK_MUX; i++) {
156
+#define AST2600_SEG_ADDR_MASK 0x0ff00000
164
device_cold_reset(DEVICE(&s->clock_muxes[i]));
157
+
165
}
158
+static uint32_t aspeed_2600_smc_segment_to_reg(const AspeedSMCState *s,
166
@@ -XXX,XX +XXX,XX @@ static void cprman_init(Object *obj)
159
+ const AspeedSegments *seg)
167
set_pll_channel_init_info(s, &s->channels[i], i);
160
+{
168
}
161
+ uint32_t reg = 0;
169
162
+
170
+ object_initialize_child(obj, "dsi0hsck-mux",
163
+ /* Disabled segments have a nil register */
171
+ &s->dsi0hsck_mux, TYPE_CPRMAN_DSI0HSCK_MUX);
164
+ if (!seg->size) {
172
+ s->dsi0hsck_mux.reg_cm = &s->regs[R_CM_DSI0HSCK];
165
+ return 0;
173
+
174
for (i = 0; i < CPRMAN_NUM_CLOCK_MUX; i++) {
175
char *alias;
176
177
@@ -XXX,XX +XXX,XX @@ static void connect_mux_sources(BCM2835CprmanState *s,
178
if (mapping == CPRMAN_CLOCK_SRC_FORCE_GROUND) {
179
src = s->gnd;
180
} else if (mapping == CPRMAN_CLOCK_SRC_DSI0HSCK) {
181
- src = s->gnd; /* TODO */
182
+ src = s->dsi0hsck_mux.out;
183
} else if (i < CPRMAN_CLOCK_SRC_PLLA) {
184
src = CLK_SRC_MAPPING[i];
185
} else {
186
@@ -XXX,XX +XXX,XX @@ static void cprman_realize(DeviceState *dev, Error **errp)
187
}
188
}
189
190
+ clock_set_source(s->dsi0hsck_mux.plla_in,
191
+ s->channels[CPRMAN_PLLA_CHANNEL_DSI0].out);
192
+ clock_set_source(s->dsi0hsck_mux.plld_in,
193
+ s->channels[CPRMAN_PLLD_CHANNEL_DSI0].out);
194
+
195
+ if (!qdev_realize(DEVICE(&s->dsi0hsck_mux), NULL, errp)) {
196
+ return;
166
+ }
197
+ }
167
+
198
+
168
+ reg |= (seg->addr & AST2600_SEG_ADDR_MASK) >> 16; /* start offset */
199
for (i = 0; i < CPRMAN_NUM_CLOCK_MUX; i++) {
169
+ reg |= (seg->addr + seg->size - 1) & AST2600_SEG_ADDR_MASK; /* end offset */
200
CprmanClockMuxState *clock_mux = &s->clock_muxes[i];
170
+ return reg;
201
171
+}
202
@@ -XXX,XX +XXX,XX @@ static void cprman_register_types(void)
172
+
203
type_register_static(&cprman_pll_info);
173
+static void aspeed_2600_smc_reg_to_segment(const AspeedSMCState *s,
204
type_register_static(&cprman_pll_channel_info);
174
+ uint32_t reg, AspeedSegments *seg)
205
type_register_static(&cprman_clock_mux_info);
175
+{
206
+ type_register_static(&cprman_dsi0hsck_mux_info);
176
+ uint32_t start_offset = (reg << 16) & AST2600_SEG_ADDR_MASK;
207
}
177
+ uint32_t end_offset = reg & AST2600_SEG_ADDR_MASK;
208
178
+
209
type_init(cprman_register_types);
179
+ seg->addr = s->ctrl->flash_window_base + start_offset;
180
+ seg->size = end_offset + MiB - start_offset;
181
+}
182
+
183
static bool aspeed_smc_flash_overlap(const AspeedSMCState *s,
184
const AspeedSegments *new,
185
int cs)
186
@@ -XXX,XX +XXX,XX @@ static inline int aspeed_smc_flash_cmd(const AspeedSMCFlash *fl)
187
const AspeedSMCState *s = fl->controller;
188
int cmd = (s->regs[s->r_ctrl0 + fl->id] >> CTRL_CMD_SHIFT) & CTRL_CMD_MASK;
189
190
- /* In read mode, the default SPI command is READ (0x3). In other
191
- * modes, the command should necessarily be defined */
192
+ /*
193
+ * In read mode, the default SPI command is READ (0x3). In other
194
+ * modes, the command should necessarily be defined
195
+ *
196
+ * TODO: add support for READ4 (0x13) on AST2600
197
+ */
198
if (aspeed_smc_flash_mode(fl) == CTRL_READMODE) {
199
cmd = SPI_OP_READ;
200
}
201
@@ -XXX,XX +XXX,XX @@ static void aspeed_smc_reset(DeviceState *d)
202
s->ctrl->segment_to_reg(s, &s->ctrl->segments[i]);
203
}
204
205
+ /* HW strapping flash type for the AST2600 controllers */
206
+ if (s->ctrl->segments == aspeed_segments_ast2600_fmc) {
207
+ /* flash type is fixed to SPI for all */
208
+ s->regs[s->r_conf] |= (CONF_FLASH_TYPE_SPI << CONF_FLASH_TYPE0);
209
+ s->regs[s->r_conf] |= (CONF_FLASH_TYPE_SPI << CONF_FLASH_TYPE1);
210
+ s->regs[s->r_conf] |= (CONF_FLASH_TYPE_SPI << CONF_FLASH_TYPE2);
211
+ }
212
+
213
/* HW strapping flash type for FMC controllers */
214
if (s->ctrl->segments == aspeed_segments_ast2500_fmc) {
215
/* flash type is fixed to SPI for CE0 and CE1 */
216
--
210
--
217
2.20.1
211
2.20.1
218
212
219
213
diff view generated by jsdifflib
1
From: Cédric Le Goater <clg@kaod.org>
1
From: Luc Michel <luc@lmichel.fr>
2
2
3
The I2C controller of the AST2400 and AST2500 SoCs have one IRQ shared
3
Those reset values have been extracted from a Raspberry Pi 3 model B
4
by all I2C busses. The AST2600 SoC I2C controller has one IRQ per bus
4
v1.2, using the 2020-08-20 version of raspios. The dump was done using
5
and 16 busses.
5
the debugfs interface of the CPRMAN driver in Linux (under
6
6
'/sys/kernel/debug/clk'). Each exposed clock tree stage (PLLs, channels
7
Signed-off-by: Cédric Le Goater <clg@kaod.org>
7
and muxes) can be observed by reading the 'regdump' file (e.g.
8
Reviewed-by: Joel Stanley <joel@jms.id.au>
8
'plla/regdump').
9
Message-id: 20190925143248.10000-17-clg@kaod.org
9
10
Those values are set by the Raspberry Pi firmware at boot time (Linux
11
expects them to be set when it boots up).
12
13
Some stages are not exposed by the Linux driver (e.g. the PLL B). For
14
those, the reset values are unknown and left to 0 which implies a
15
disabled output.
16
17
Once booted in QEMU, the final clock tree is very similar to the one
18
visible on real hardware. The differences come from some unimplemented
19
devices for which the driver simply disable the corresponding clock.
20
21
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
22
Signed-off-by: Luc Michel <luc@lmichel.fr>
23
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
24
Tested-by: Guenter Roeck <linux@roeck-us.net>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
25
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
---
26
---
12
include/hw/i2c/aspeed_i2c.h | 5 +++-
27
include/hw/misc/bcm2835_cprman_internals.h | 269 +++++++++++++++++++++
13
hw/i2c/aspeed_i2c.c | 46 +++++++++++++++++++++++++++++++++++--
28
hw/misc/bcm2835_cprman.c | 31 +++
14
2 files changed, 48 insertions(+), 3 deletions(-)
29
2 files changed, 300 insertions(+)
15
30
16
diff --git a/include/hw/i2c/aspeed_i2c.h b/include/hw/i2c/aspeed_i2c.h
31
diff --git a/include/hw/misc/bcm2835_cprman_internals.h b/include/hw/misc/bcm2835_cprman_internals.h
17
index XXXXXXX..XXXXXXX 100644
32
index XXXXXXX..XXXXXXX 100644
18
--- a/include/hw/i2c/aspeed_i2c.h
33
--- a/include/hw/misc/bcm2835_cprman_internals.h
19
+++ b/include/hw/i2c/aspeed_i2c.h
34
+++ b/include/hw/misc/bcm2835_cprman_internals.h
35
@@ -XXX,XX +XXX,XX @@ static inline void set_clock_mux_init_info(BCM2835CprmanState *s,
36
mux->frac_bits = CLOCK_MUX_INIT_INFO[id].frac_bits;
37
}
38
39
+
40
+/*
41
+ * Object reset info
42
+ * Those values have been dumped from a Raspberry Pi 3 Model B v1.2 using the
43
+ * clk debugfs interface in Linux.
44
+ */
45
+typedef struct PLLResetInfo {
46
+ uint32_t cm;
47
+ uint32_t a2w_ctrl;
48
+ uint32_t a2w_ana[4];
49
+ uint32_t a2w_frac;
50
+} PLLResetInfo;
51
+
52
+static const PLLResetInfo PLL_RESET_INFO[] = {
53
+ [CPRMAN_PLLA] = {
54
+ .cm = 0x0000008a,
55
+ .a2w_ctrl = 0x0002103a,
56
+ .a2w_frac = 0x00098000,
57
+ .a2w_ana = { 0x00000000, 0x00144000, 0x00000000, 0x00000100 }
58
+ },
59
+
60
+ [CPRMAN_PLLC] = {
61
+ .cm = 0x00000228,
62
+ .a2w_ctrl = 0x0002103e,
63
+ .a2w_frac = 0x00080000,
64
+ .a2w_ana = { 0x00000000, 0x00144000, 0x00000000, 0x00000100 }
65
+ },
66
+
67
+ [CPRMAN_PLLD] = {
68
+ .cm = 0x0000020a,
69
+ .a2w_ctrl = 0x00021034,
70
+ .a2w_frac = 0x00015556,
71
+ .a2w_ana = { 0x00000000, 0x00144000, 0x00000000, 0x00000100 }
72
+ },
73
+
74
+ [CPRMAN_PLLH] = {
75
+ .cm = 0x00000000,
76
+ .a2w_ctrl = 0x0002102d,
77
+ .a2w_frac = 0x00000000,
78
+ .a2w_ana = { 0x00900000, 0x0000000c, 0x00000000, 0x00000000 }
79
+ },
80
+
81
+ [CPRMAN_PLLB] = {
82
+ /* unknown */
83
+ .cm = 0x00000000,
84
+ .a2w_ctrl = 0x00000000,
85
+ .a2w_frac = 0x00000000,
86
+ .a2w_ana = { 0x00000000, 0x00000000, 0x00000000, 0x00000000 }
87
+ }
88
+};
89
+
90
+typedef struct PLLChannelResetInfo {
91
+ /*
92
+ * Even though a PLL channel has a CM register, it shares it with its
93
+ * parent PLL. The parent already takes care of the reset value.
94
+ */
95
+ uint32_t a2w_ctrl;
96
+} PLLChannelResetInfo;
97
+
98
+static const PLLChannelResetInfo PLL_CHANNEL_RESET_INFO[] = {
99
+ [CPRMAN_PLLA_CHANNEL_DSI0] = { .a2w_ctrl = 0x00000100 },
100
+ [CPRMAN_PLLA_CHANNEL_CORE] = { .a2w_ctrl = 0x00000003 },
101
+ [CPRMAN_PLLA_CHANNEL_PER] = { .a2w_ctrl = 0x00000000 }, /* unknown */
102
+ [CPRMAN_PLLA_CHANNEL_CCP2] = { .a2w_ctrl = 0x00000100 },
103
+
104
+ [CPRMAN_PLLC_CHANNEL_CORE2] = { .a2w_ctrl = 0x00000100 },
105
+ [CPRMAN_PLLC_CHANNEL_CORE1] = { .a2w_ctrl = 0x00000100 },
106
+ [CPRMAN_PLLC_CHANNEL_PER] = { .a2w_ctrl = 0x00000002 },
107
+ [CPRMAN_PLLC_CHANNEL_CORE0] = { .a2w_ctrl = 0x00000002 },
108
+
109
+ [CPRMAN_PLLD_CHANNEL_DSI0] = { .a2w_ctrl = 0x00000100 },
110
+ [CPRMAN_PLLD_CHANNEL_CORE] = { .a2w_ctrl = 0x00000004 },
111
+ [CPRMAN_PLLD_CHANNEL_PER] = { .a2w_ctrl = 0x00000004 },
112
+ [CPRMAN_PLLD_CHANNEL_DSI1] = { .a2w_ctrl = 0x00000100 },
113
+
114
+ [CPRMAN_PLLH_CHANNEL_AUX] = { .a2w_ctrl = 0x00000004 },
115
+ [CPRMAN_PLLH_CHANNEL_RCAL] = { .a2w_ctrl = 0x00000000 },
116
+ [CPRMAN_PLLH_CHANNEL_PIX] = { .a2w_ctrl = 0x00000000 },
117
+
118
+ [CPRMAN_PLLB_CHANNEL_ARM] = { .a2w_ctrl = 0x00000000 }, /* unknown */
119
+};
120
+
121
+typedef struct ClockMuxResetInfo {
122
+ uint32_t cm_ctl;
123
+ uint32_t cm_div;
124
+} ClockMuxResetInfo;
125
+
126
+static const ClockMuxResetInfo CLOCK_MUX_RESET_INFO[] = {
127
+ [CPRMAN_CLOCK_GNRIC] = {
128
+ .cm_ctl = 0, /* unknown */
129
+ .cm_div = 0
130
+ },
131
+
132
+ [CPRMAN_CLOCK_VPU] = {
133
+ .cm_ctl = 0x00000245,
134
+ .cm_div = 0x00003000,
135
+ },
136
+
137
+ [CPRMAN_CLOCK_SYS] = {
138
+ .cm_ctl = 0, /* unknown */
139
+ .cm_div = 0
140
+ },
141
+
142
+ [CPRMAN_CLOCK_PERIA] = {
143
+ .cm_ctl = 0, /* unknown */
144
+ .cm_div = 0
145
+ },
146
+
147
+ [CPRMAN_CLOCK_PERII] = {
148
+ .cm_ctl = 0, /* unknown */
149
+ .cm_div = 0
150
+ },
151
+
152
+ [CPRMAN_CLOCK_H264] = {
153
+ .cm_ctl = 0x00000244,
154
+ .cm_div = 0x00003000,
155
+ },
156
+
157
+ [CPRMAN_CLOCK_ISP] = {
158
+ .cm_ctl = 0x00000244,
159
+ .cm_div = 0x00003000,
160
+ },
161
+
162
+ [CPRMAN_CLOCK_V3D] = {
163
+ .cm_ctl = 0, /* unknown */
164
+ .cm_div = 0
165
+ },
166
+
167
+ [CPRMAN_CLOCK_CAM0] = {
168
+ .cm_ctl = 0x00000000,
169
+ .cm_div = 0x00000000,
170
+ },
171
+
172
+ [CPRMAN_CLOCK_CAM1] = {
173
+ .cm_ctl = 0x00000000,
174
+ .cm_div = 0x00000000,
175
+ },
176
+
177
+ [CPRMAN_CLOCK_CCP2] = {
178
+ .cm_ctl = 0, /* unknown */
179
+ .cm_div = 0
180
+ },
181
+
182
+ [CPRMAN_CLOCK_DSI0E] = {
183
+ .cm_ctl = 0x00000000,
184
+ .cm_div = 0x00000000,
185
+ },
186
+
187
+ [CPRMAN_CLOCK_DSI0P] = {
188
+ .cm_ctl = 0x00000000,
189
+ .cm_div = 0x00000000,
190
+ },
191
+
192
+ [CPRMAN_CLOCK_DPI] = {
193
+ .cm_ctl = 0x00000000,
194
+ .cm_div = 0x00000000,
195
+ },
196
+
197
+ [CPRMAN_CLOCK_GP0] = {
198
+ .cm_ctl = 0x00000200,
199
+ .cm_div = 0x00000000,
200
+ },
201
+
202
+ [CPRMAN_CLOCK_GP1] = {
203
+ .cm_ctl = 0x00000096,
204
+ .cm_div = 0x00014000,
205
+ },
206
+
207
+ [CPRMAN_CLOCK_GP2] = {
208
+ .cm_ctl = 0x00000291,
209
+ .cm_div = 0x00249f00,
210
+ },
211
+
212
+ [CPRMAN_CLOCK_HSM] = {
213
+ .cm_ctl = 0x00000000,
214
+ .cm_div = 0x00000000,
215
+ },
216
+
217
+ [CPRMAN_CLOCK_OTP] = {
218
+ .cm_ctl = 0x00000091,
219
+ .cm_div = 0x00004000,
220
+ },
221
+
222
+ [CPRMAN_CLOCK_PCM] = {
223
+ .cm_ctl = 0x00000200,
224
+ .cm_div = 0x00000000,
225
+ },
226
+
227
+ [CPRMAN_CLOCK_PWM] = {
228
+ .cm_ctl = 0x00000200,
229
+ .cm_div = 0x00000000,
230
+ },
231
+
232
+ [CPRMAN_CLOCK_SLIM] = {
233
+ .cm_ctl = 0x00000200,
234
+ .cm_div = 0x00000000,
235
+ },
236
+
237
+ [CPRMAN_CLOCK_SMI] = {
238
+ .cm_ctl = 0x00000000,
239
+ .cm_div = 0x00000000,
240
+ },
241
+
242
+ [CPRMAN_CLOCK_TEC] = {
243
+ .cm_ctl = 0x00000000,
244
+ .cm_div = 0x00000000,
245
+ },
246
+
247
+ [CPRMAN_CLOCK_TD0] = {
248
+ .cm_ctl = 0, /* unknown */
249
+ .cm_div = 0
250
+ },
251
+
252
+ [CPRMAN_CLOCK_TD1] = {
253
+ .cm_ctl = 0, /* unknown */
254
+ .cm_div = 0
255
+ },
256
+
257
+ [CPRMAN_CLOCK_TSENS] = {
258
+ .cm_ctl = 0x00000091,
259
+ .cm_div = 0x0000a000,
260
+ },
261
+
262
+ [CPRMAN_CLOCK_TIMER] = {
263
+ .cm_ctl = 0x00000291,
264
+ .cm_div = 0x00013333,
265
+ },
266
+
267
+ [CPRMAN_CLOCK_UART] = {
268
+ .cm_ctl = 0x00000296,
269
+ .cm_div = 0x0000a6ab,
270
+ },
271
+
272
+ [CPRMAN_CLOCK_VEC] = {
273
+ .cm_ctl = 0x00000097,
274
+ .cm_div = 0x00002000,
275
+ },
276
+
277
+ [CPRMAN_CLOCK_PULSE] = {
278
+ .cm_ctl = 0, /* unknown */
279
+ .cm_div = 0
280
+ },
281
+
282
+ [CPRMAN_CLOCK_SDC] = {
283
+ .cm_ctl = 0x00004006,
284
+ .cm_div = 0x00003000,
285
+ },
286
+
287
+ [CPRMAN_CLOCK_ARM] = {
288
+ .cm_ctl = 0, /* unknown */
289
+ .cm_div = 0
290
+ },
291
+
292
+ [CPRMAN_CLOCK_AVEO] = {
293
+ .cm_ctl = 0x00000000,
294
+ .cm_div = 0x00000000,
295
+ },
296
+
297
+ [CPRMAN_CLOCK_EMMC] = {
298
+ .cm_ctl = 0x00000295,
299
+ .cm_div = 0x00006000,
300
+ },
301
+
302
+ [CPRMAN_CLOCK_EMMC2] = {
303
+ .cm_ctl = 0, /* unknown */
304
+ .cm_div = 0
305
+ },
306
+};
307
+
308
#endif
309
diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c
310
index XXXXXXX..XXXXXXX 100644
311
--- a/hw/misc/bcm2835_cprman.c
312
+++ b/hw/misc/bcm2835_cprman.c
20
@@ -XXX,XX +XXX,XX @@
313
@@ -XXX,XX +XXX,XX @@
21
#define TYPE_ASPEED_I2C "aspeed.i2c"
314
22
#define TYPE_ASPEED_2400_I2C TYPE_ASPEED_I2C "-ast2400"
315
/* PLL */
23
#define TYPE_ASPEED_2500_I2C TYPE_ASPEED_I2C "-ast2500"
316
24
+#define TYPE_ASPEED_2600_I2C TYPE_ASPEED_I2C "-ast2600"
317
+static void pll_reset(DeviceState *dev)
25
#define ASPEED_I2C(obj) \
26
OBJECT_CHECK(AspeedI2CState, (obj), TYPE_ASPEED_I2C)
27
28
-#define ASPEED_I2C_NR_BUSSES 14
29
+#define ASPEED_I2C_NR_BUSSES 16
30
31
struct AspeedI2CState;
32
33
@@ -XXX,XX +XXX,XX @@ typedef struct AspeedI2CBus {
34
35
I2CBus *bus;
36
uint8_t id;
37
+ qemu_irq irq;
38
39
uint32_t ctrl;
40
uint32_t timing[2];
41
@@ -XXX,XX +XXX,XX @@ typedef struct AspeedI2CClass {
42
uint8_t num_busses;
43
uint8_t reg_size;
44
uint8_t gap;
45
+ qemu_irq (*bus_get_irq)(AspeedI2CBus *);
46
} AspeedI2CClass;
47
48
I2CBus *aspeed_i2c_get_bus(DeviceState *dev, int busnr);
49
diff --git a/hw/i2c/aspeed_i2c.c b/hw/i2c/aspeed_i2c.c
50
index XXXXXXX..XXXXXXX 100644
51
--- a/hw/i2c/aspeed_i2c.c
52
+++ b/hw/i2c/aspeed_i2c.c
53
@@ -XXX,XX +XXX,XX @@ static inline bool aspeed_i2c_bus_is_enabled(AspeedI2CBus *bus)
54
55
static inline void aspeed_i2c_bus_raise_interrupt(AspeedI2CBus *bus)
56
{
57
+ AspeedI2CClass *aic = ASPEED_I2C_GET_CLASS(bus->controller);
58
+
59
bus->intr_status &= bus->intr_ctrl;
60
if (bus->intr_status) {
61
bus->controller->intr_status |= 1 << bus->id;
62
- qemu_irq_raise(bus->controller->irq);
63
+ qemu_irq_raise(aic->bus_get_irq(bus));
64
}
65
}
66
67
@@ -XXX,XX +XXX,XX @@ static void aspeed_i2c_bus_write(void *opaque, hwaddr offset,
68
uint64_t value, unsigned size)
69
{
70
AspeedI2CBus *bus = opaque;
71
+ AspeedI2CClass *aic = ASPEED_I2C_GET_CLASS(bus->controller);
72
bool handle_rx;
73
74
switch (offset) {
75
@@ -XXX,XX +XXX,XX @@ static void aspeed_i2c_bus_write(void *opaque, hwaddr offset,
76
bus->intr_status &= ~(value & 0x7FFF);
77
if (!bus->intr_status) {
78
bus->controller->intr_status &= ~(1 << bus->id);
79
- qemu_irq_lower(bus->controller->irq);
80
+ qemu_irq_lower(aic->bus_get_irq(bus));
81
}
82
if (handle_rx && (bus->cmd & (I2CD_M_RX_CMD | I2CD_M_S_RX_CMD_LAST))) {
83
aspeed_i2c_handle_rx_cmd(bus);
84
@@ -XXX,XX +XXX,XX @@ static void aspeed_i2c_realize(DeviceState *dev, Error **errp)
85
for (i = 0; i < aic->num_busses; i++) {
86
char name[32];
87
int offset = i < aic->gap ? 1 : 5;
88
+
89
+ sysbus_init_irq(sbd, &s->busses[i].irq);
90
snprintf(name, sizeof(name), "aspeed.i2c.%d", i);
91
s->busses[i].controller = s;
92
s->busses[i].id = i;
93
@@ -XXX,XX +XXX,XX @@ static const TypeInfo aspeed_i2c_info = {
94
.abstract = true,
95
};
96
97
+static qemu_irq aspeed_2400_i2c_bus_get_irq(AspeedI2CBus *bus)
98
+{
318
+{
99
+ return bus->controller->irq;
319
+ CprmanPllState *s = CPRMAN_PLL(dev);
320
+ const PLLResetInfo *info = &PLL_RESET_INFO[s->id];
321
+
322
+ *s->reg_cm = info->cm;
323
+ *s->reg_a2w_ctrl = info->a2w_ctrl;
324
+ memcpy(s->reg_a2w_ana, info->a2w_ana, sizeof(info->a2w_ana));
325
+ *s->reg_a2w_frac = info->a2w_frac;
100
+}
326
+}
101
+
327
+
102
static void aspeed_2400_i2c_class_init(ObjectClass *klass, void *data)
328
static bool pll_is_locked(const CprmanPllState *pll)
329
{
330
return !FIELD_EX32(*pll->reg_a2w_ctrl, A2W_PLLx_CTRL, PWRDN)
331
@@ -XXX,XX +XXX,XX @@ static void pll_class_init(ObjectClass *klass, void *data)
103
{
332
{
104
DeviceClass *dc = DEVICE_CLASS(klass);
333
DeviceClass *dc = DEVICE_CLASS(klass);
105
@@ -XXX,XX +XXX,XX @@ static void aspeed_2400_i2c_class_init(ObjectClass *klass, void *data)
334
106
aic->num_busses = 14;
335
+ dc->reset = pll_reset;
107
aic->reg_size = 0x40;
336
dc->vmsd = &pll_vmstate;
108
aic->gap = 7;
337
}
109
+ aic->bus_get_irq = aspeed_2400_i2c_bus_get_irq;
338
110
}
339
@@ -XXX,XX +XXX,XX @@ static const TypeInfo cprman_pll_info = {
111
340
112
static const TypeInfo aspeed_2400_i2c_info = {
341
/* PLL channel */
113
@@ -XXX,XX +XXX,XX @@ static const TypeInfo aspeed_2400_i2c_info = {
342
114
.class_init = aspeed_2400_i2c_class_init,
343
+static void pll_channel_reset(DeviceState *dev)
115
};
116
117
+static qemu_irq aspeed_2500_i2c_bus_get_irq(AspeedI2CBus *bus)
118
+{
344
+{
119
+ return bus->controller->irq;
345
+ CprmanPllChannelState *s = CPRMAN_PLL_CHANNEL(dev);
346
+ const PLLChannelResetInfo *info = &PLL_CHANNEL_RESET_INFO[s->id];
347
+
348
+ *s->reg_a2w_ctrl = info->a2w_ctrl;
120
+}
349
+}
121
+
350
+
122
static void aspeed_2500_i2c_class_init(ObjectClass *klass, void *data)
351
static bool pll_channel_is_enabled(CprmanPllChannelState *channel)
352
{
353
/*
354
@@ -XXX,XX +XXX,XX @@ static void pll_channel_class_init(ObjectClass *klass, void *data)
123
{
355
{
124
DeviceClass *dc = DEVICE_CLASS(klass);
356
DeviceClass *dc = DEVICE_CLASS(klass);
125
@@ -XXX,XX +XXX,XX @@ static void aspeed_2500_i2c_class_init(ObjectClass *klass, void *data)
357
126
aic->num_busses = 14;
358
+ dc->reset = pll_channel_reset;
127
aic->reg_size = 0x40;
359
dc->vmsd = &pll_channel_vmstate;
128
aic->gap = 7;
360
}
129
+ aic->bus_get_irq = aspeed_2500_i2c_bus_get_irq;
361
130
}
362
@@ -XXX,XX +XXX,XX @@ static void clock_mux_src_update(void *opaque)
131
363
clock_mux_update(s);
132
static const TypeInfo aspeed_2500_i2c_info = {
364
}
133
@@ -XXX,XX +XXX,XX @@ static const TypeInfo aspeed_2500_i2c_info = {
365
134
.class_init = aspeed_2500_i2c_class_init,
366
+static void clock_mux_reset(DeviceState *dev)
135
};
136
137
+static qemu_irq aspeed_2600_i2c_bus_get_irq(AspeedI2CBus *bus)
138
+{
367
+{
139
+ return bus->irq;
368
+ CprmanClockMuxState *clock = CPRMAN_CLOCK_MUX(dev);
369
+ const ClockMuxResetInfo *info = &CLOCK_MUX_RESET_INFO[clock->id];
370
+
371
+ *clock->reg_ctl = info->cm_ctl;
372
+ *clock->reg_div = info->cm_div;
140
+}
373
+}
141
+
374
+
142
+static void aspeed_2600_i2c_class_init(ObjectClass *klass, void *data)
375
static void clock_mux_init(Object *obj)
143
+{
376
{
144
+ DeviceClass *dc = DEVICE_CLASS(klass);
377
CprmanClockMuxState *s = CPRMAN_CLOCK_MUX(obj);
145
+ AspeedI2CClass *aic = ASPEED_I2C_CLASS(klass);
378
@@ -XXX,XX +XXX,XX @@ static void clock_mux_class_init(ObjectClass *klass, void *data)
146
+
379
{
147
+ dc->desc = "ASPEED 2600 I2C Controller";
380
DeviceClass *dc = DEVICE_CLASS(klass);
148
+
381
149
+ aic->num_busses = 16;
382
+ dc->reset = clock_mux_reset;
150
+ aic->reg_size = 0x80;
383
dc->vmsd = &clock_mux_vmstate;
151
+ aic->gap = -1; /* no gap */
384
}
152
+ aic->bus_get_irq = aspeed_2600_i2c_bus_get_irq;
385
153
+}
154
+
155
+static const TypeInfo aspeed_2600_i2c_info = {
156
+ .name = TYPE_ASPEED_2600_I2C,
157
+ .parent = TYPE_ASPEED_I2C,
158
+ .class_init = aspeed_2600_i2c_class_init,
159
+};
160
+
161
static void aspeed_i2c_register_types(void)
162
{
163
type_register_static(&aspeed_i2c_info);
164
type_register_static(&aspeed_2400_i2c_info);
165
type_register_static(&aspeed_2500_i2c_info);
166
+ type_register_static(&aspeed_2600_i2c_info);
167
}
168
169
type_init(aspeed_i2c_register_types)
170
--
386
--
171
2.20.1
387
2.20.1
172
388
173
389
diff view generated by jsdifflib
1
We want to switch the exynos MCT code away from bottom-half based ptimers to
1
From: Luc Michel <luc@lmichel.fr>
2
the new transaction-based ptimer API. The MCT is complicated
3
and uses multiple different ptimers, so it's clearer to switch
4
it a piece at a time. Here we change over only the GFRC.
5
2
3
Add a clock input to the PL011 UART so we can compute the current baud
4
rate and trace it. This is intended for developers who wish to use QEMU
5
to e.g. debug their firmware or to figure out the baud rate configured
6
by an unknown/closed source binary.
7
8
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
9
Signed-off-by: Luc Michel <luc@lmichel.fr>
10
Tested-by: Guenter Roeck <linux@roeck-us.net>
11
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Message-id: 20191008171740.9679-12-peter.maydell@linaro.org
9
---
13
---
10
hw/timer/exynos4210_mct.c | 48 ++++++++++++++++++++++++++++++++++++---
14
include/hw/char/pl011.h | 1 +
11
1 file changed, 45 insertions(+), 3 deletions(-)
15
hw/char/pl011.c | 45 +++++++++++++++++++++++++++++++++++++++++
16
hw/char/trace-events | 1 +
17
3 files changed, 47 insertions(+)
12
18
13
diff --git a/hw/timer/exynos4210_mct.c b/hw/timer/exynos4210_mct.c
19
diff --git a/include/hw/char/pl011.h b/include/hw/char/pl011.h
14
index XXXXXXX..XXXXXXX 100644
20
index XXXXXXX..XXXXXXX 100644
15
--- a/hw/timer/exynos4210_mct.c
21
--- a/include/hw/char/pl011.h
16
+++ b/hw/timer/exynos4210_mct.c
22
+++ b/include/hw/char/pl011.h
17
@@ -XXX,XX +XXX,XX @@ static void exynos4210_mct_update_freq(Exynos4210MCTState *s);
23
@@ -XXX,XX +XXX,XX @@ struct PL011State {
18
24
int read_trigger;
19
/*
25
CharBackend chr;
20
* Set counter of FRC global timer.
26
qemu_irq irq[6];
21
+ * Must be called within exynos4210_gfrc_tx_begin/commit block.
27
+ Clock *clk;
22
*/
28
const unsigned char *id;
23
static void exynos4210_gfrc_set_count(Exynos4210MCTGT *s, uint64_t count)
29
};
24
{
30
25
@@ -XXX,XX +XXX,XX @@ static uint64_t exynos4210_gfrc_get_count(Exynos4210MCTGT *s)
31
diff --git a/hw/char/pl011.c b/hw/char/pl011.c
26
32
index XXXXXXX..XXXXXXX 100644
27
/*
33
--- a/hw/char/pl011.c
28
* Stop global FRC timer
34
+++ b/hw/char/pl011.c
29
+ * Must be called within exynos4210_gfrc_tx_begin/commit block.
35
@@ -XXX,XX +XXX,XX @@
30
*/
36
#include "hw/char/pl011.h"
31
static void exynos4210_gfrc_stop(Exynos4210MCTGT *s)
37
#include "hw/irq.h"
32
{
38
#include "hw/sysbus.h"
33
@@ -XXX,XX +XXX,XX @@ static void exynos4210_gfrc_stop(Exynos4210MCTGT *s)
39
+#include "hw/qdev-clock.h"
34
40
#include "migration/vmstate.h"
35
/*
41
#include "chardev/char-fe.h"
36
* Start global FRC timer
42
#include "qemu/log.h"
37
+ * Must be called within exynos4210_gfrc_tx_begin/commit block.
43
@@ -XXX,XX +XXX,XX @@ static void pl011_set_read_trigger(PL011State *s)
38
*/
44
s->read_trigger = 1;
39
static void exynos4210_gfrc_start(Exynos4210MCTGT *s)
40
{
41
@@ -XXX,XX +XXX,XX @@ static void exynos4210_gfrc_start(Exynos4210MCTGT *s)
42
ptimer_run(s->ptimer_frc, 1);
43
}
45
}
44
46
45
+/*
47
+static unsigned int pl011_get_baudrate(const PL011State *s)
46
+ * Start ptimer transaction for global FRC timer; this is just for
47
+ * consistency with the way we wrap operations like stop and run.
48
+ */
49
+static void exynos4210_gfrc_tx_begin(Exynos4210MCTGT *s)
50
+{
48
+{
51
+ ptimer_transaction_begin(s->ptimer_frc);
49
+ uint64_t clk;
50
+
51
+ if (s->fbrd == 0) {
52
+ return 0;
53
+ }
54
+
55
+ clk = clock_get_hz(s->clk);
56
+ return (clk / ((s->ibrd << 6) + s->fbrd)) << 2;
52
+}
57
+}
53
+
58
+
54
+/* Commit ptimer transaction for global FRC timer. */
59
+static void pl011_trace_baudrate_change(const PL011State *s)
55
+static void exynos4210_gfrc_tx_commit(Exynos4210MCTGT *s)
56
+{
60
+{
57
+ ptimer_transaction_commit(s->ptimer_frc);
61
+ trace_pl011_baudrate_change(pl011_get_baudrate(s),
62
+ clock_get_hz(s->clk),
63
+ s->ibrd, s->fbrd);
58
+}
64
+}
59
+
65
+
60
/*
66
static void pl011_write(void *opaque, hwaddr offset,
61
* Find next nearest Comparator. If current Comparator value equals to other
67
uint64_t value, unsigned size)
62
* Comparator value, skip them both
63
@@ -XXX,XX +XXX,XX @@ static uint64_t exynos4210_gcomp_get_distance(Exynos4210MCTState *s, int32_t id)
64
65
/*
66
* Restart global FRC timer
67
+ * Must be called within exynos4210_gfrc_tx_begin/commit block.
68
*/
69
static void exynos4210_gfrc_restart(Exynos4210MCTState *s)
70
{
68
{
71
@@ -XXX,XX +XXX,XX @@ static void exynos4210_ltick_event(void *opaque)
69
@@ -XXX,XX +XXX,XX @@ static void pl011_write(void *opaque, hwaddr offset,
72
exynos4210_ltick_int_start(&s->tick_timer);
70
break;
71
case 9: /* UARTIBRD */
72
s->ibrd = value;
73
+ pl011_trace_baudrate_change(s);
74
break;
75
case 10: /* UARTFBRD */
76
s->fbrd = value;
77
+ pl011_trace_baudrate_change(s);
78
break;
79
case 11: /* UARTLCR_H */
80
/* Reset the FIFO state on FIFO enable or disable */
81
@@ -XXX,XX +XXX,XX @@ static void pl011_event(void *opaque, QEMUChrEvent event)
82
pl011_put_fifo(opaque, 0x400);
73
}
83
}
74
84
75
+static void tx_ptimer_set_freq(ptimer_state *s, uint32_t freq)
85
+static void pl011_clock_update(void *opaque)
76
+{
86
+{
77
+ /*
87
+ PL011State *s = PL011(opaque);
78
+ * callers of exynos4210_mct_update_freq() never do anything
88
+
79
+ * else that needs to be in the same ptimer transaction, so
89
+ pl011_trace_baudrate_change(s);
80
+ * to avoid a lot of repetition we have a convenience function
81
+ * for begin/set_freq/commit.
82
+ */
83
+ ptimer_transaction_begin(s);
84
+ ptimer_set_freq(s, freq);
85
+ ptimer_transaction_commit(s);
86
+}
90
+}
87
+
91
+
88
/* update timer frequency */
92
static const MemoryRegionOps pl011_ops = {
89
static void exynos4210_mct_update_freq(Exynos4210MCTState *s)
93
.read = pl011_read,
90
{
94
.write = pl011_write,
91
@@ -XXX,XX +XXX,XX @@ static void exynos4210_mct_update_freq(Exynos4210MCTState *s)
95
.endianness = DEVICE_NATIVE_ENDIAN,
92
DPRINTF("freq=%dHz\n", s->freq);
96
};
93
97
94
/* global timer */
98
+static const VMStateDescription vmstate_pl011_clock = {
95
- ptimer_set_freq(s->g_timer.ptimer_frc, s->freq);
99
+ .name = "pl011/clock",
96
+ tx_ptimer_set_freq(s->g_timer.ptimer_frc, s->freq);
100
+ .version_id = 1,
97
101
+ .minimum_version_id = 1,
98
/* local timer */
102
+ .fields = (VMStateField[]) {
99
ptimer_set_freq(s->l_timer[0].tick_timer.ptimer_tick, s->freq);
103
+ VMSTATE_CLOCK(clk, PL011State),
100
@@ -XXX,XX +XXX,XX @@ static void exynos4210_mct_reset(DeviceState *d)
104
+ VMSTATE_END_OF_LIST()
101
105
+ }
102
/* global timer */
106
+};
103
memset(&s->g_timer.reg, 0, sizeof(s->g_timer.reg));
104
+ exynos4210_gfrc_tx_begin(&s->g_timer);
105
exynos4210_gfrc_stop(&s->g_timer);
106
+ exynos4210_gfrc_tx_commit(&s->g_timer);
107
108
/* local timer */
109
memset(s->l_timer[0].reg.cnt, 0, sizeof(s->l_timer[0].reg.cnt));
110
@@ -XXX,XX +XXX,XX @@ static void exynos4210_mct_write(void *opaque, hwaddr offset,
111
}
112
113
s->g_timer.reg.cnt = new_frc;
114
+ exynos4210_gfrc_tx_begin(&s->g_timer);
115
exynos4210_gfrc_restart(s);
116
+ exynos4210_gfrc_tx_commit(&s->g_timer);
117
break;
118
119
case G_CNT_WSTAT:
120
@@ -XXX,XX +XXX,XX @@ static void exynos4210_mct_write(void *opaque, hwaddr offset,
121
s->g_timer.reg.wstat |= G_WSTAT_COMP_L(index);
122
}
123
124
+ exynos4210_gfrc_tx_begin(&s->g_timer);
125
exynos4210_gfrc_restart(s);
126
+ exynos4210_gfrc_tx_commit(&s->g_timer);
127
break;
128
129
case G_TCON:
130
@@ -XXX,XX +XXX,XX @@ static void exynos4210_mct_write(void *opaque, hwaddr offset,
131
132
DPRINTF("global timer write to reg.g_tcon %llx\n", value);
133
134
+ exynos4210_gfrc_tx_begin(&s->g_timer);
135
+
107
+
136
/* Start FRC if transition from disabled to enabled */
108
static const VMStateDescription vmstate_pl011 = {
137
if ((value & G_TCON_TIMER_ENABLE) > (old_val &
109
.name = "pl011",
138
G_TCON_TIMER_ENABLE)) {
110
.version_id = 2,
139
@@ -XXX,XX +XXX,XX @@ static void exynos4210_mct_write(void *opaque, hwaddr offset,
111
@@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_pl011 = {
140
exynos4210_gfrc_restart(s);
112
VMSTATE_INT32(read_count, PL011State),
141
}
113
VMSTATE_INT32(read_trigger, PL011State),
142
}
114
VMSTATE_END_OF_LIST()
115
+ },
116
+ .subsections = (const VMStateDescription * []) {
117
+ &vmstate_pl011_clock,
118
+ NULL
119
}
120
};
121
122
@@ -XXX,XX +XXX,XX @@ static void pl011_init(Object *obj)
123
sysbus_init_irq(sbd, &s->irq[i]);
124
}
125
126
+ s->clk = qdev_init_clock_in(DEVICE(obj), "clk", pl011_clock_update, s);
143
+
127
+
144
+ exynos4210_gfrc_tx_commit(&s->g_timer);
128
s->read_trigger = 1;
145
break;
129
s->ifl = 0x12;
146
130
s->cr = 0x300;
147
case G_INT_CSTAT:
131
diff --git a/hw/char/trace-events b/hw/char/trace-events
148
@@ -XXX,XX +XXX,XX @@ static void exynos4210_mct_init(Object *obj)
132
index XXXXXXX..XXXXXXX 100644
149
QEMUBH *bh[2];
133
--- a/hw/char/trace-events
150
134
+++ b/hw/char/trace-events
151
/* Global timer */
135
@@ -XXX,XX +XXX,XX @@ pl011_write(uint32_t addr, uint32_t value) "addr 0x%08x value 0x%08x"
152
- bh[0] = qemu_bh_new(exynos4210_gfrc_event, s);
136
pl011_can_receive(uint32_t lcr, int read_count, int r) "LCR 0x%08x read_count %d returning %d"
153
- s->g_timer.ptimer_frc = ptimer_init_with_bh(bh[0], PTIMER_POLICY_DEFAULT);
137
pl011_put_fifo(uint32_t c, int read_count) "new char 0x%x read_count now %d"
154
+ s->g_timer.ptimer_frc = ptimer_init(exynos4210_gfrc_event, s,
138
pl011_put_fifo_full(void) "FIFO now full, RXFF set"
155
+ PTIMER_POLICY_DEFAULT);
139
+pl011_baudrate_change(unsigned int baudrate, uint64_t clock, uint32_t ibrd, uint32_t fbrd) "new baudrate %u (clk: %" PRIu64 "hz, ibrd: %" PRIu32 ", fbrd: %" PRIu32 ")"
156
memset(&s->g_timer.reg, 0, sizeof(struct gregs));
140
157
141
# cmsdk-apb-uart.c
158
/* Local timers */
142
cmsdk_apb_uart_read(uint64_t offset, uint64_t data, unsigned size) "CMSDK APB UART read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u"
159
--
143
--
160
2.20.1
144
2.20.1
161
145
162
146
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
1
From: Luc Michel <luc@lmichel.fr>
2
2
3
The UART1 is part of the AUX peripheral,
3
Connect the 'uart-out' clock from the CPRMAN to the PL011 instance.
4
the PCM_CLOCK (yet unimplemented) is part of the CPRMAN.
5
4
6
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
5
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
7
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
6
Signed-off-by: Luc Michel <luc@lmichel.fr>
8
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
7
Tested-by: Guenter Roeck <linux@roeck-us.net>
9
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
8
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
10
Message-id: 20190926173428.10713-5-f4bug@amsat.org
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
---
10
---
13
include/hw/arm/raspi_platform.h | 16 +++++++---------
11
hw/arm/bcm2835_peripherals.c | 2 ++
14
hw/arm/bcm2835_peripherals.c | 7 ++++---
12
1 file changed, 2 insertions(+)
15
hw/arm/bcm2836.c | 2 +-
16
3 files changed, 12 insertions(+), 13 deletions(-)
17
13
18
diff --git a/include/hw/arm/raspi_platform.h b/include/hw/arm/raspi_platform.h
19
index XXXXXXX..XXXXXXX 100644
20
--- a/include/hw/arm/raspi_platform.h
21
+++ b/include/hw/arm/raspi_platform.h
22
@@ -XXX,XX +XXX,XX @@
23
#ifndef HW_ARM_RASPI_PLATFORM_H
24
#define HW_ARM_RASPI_PLATFORM_H
25
26
-#define MCORE_OFFSET 0x0000 /* Fake frame buffer device
27
- * (the multicore sync block) */
28
+#define MSYNC_OFFSET 0x0000 /* Multicore Sync Block */
29
#define IC0_OFFSET 0x2000
30
#define ST_OFFSET 0x3000 /* System Timer */
31
#define MPHI_OFFSET 0x6000 /* Message-based Parallel Host Intf. */
32
@@ -XXX,XX +XXX,XX @@
33
#define ARMCTRL_TIMER0_1_OFFSET (ARM_OFFSET + 0x400) /* Timer 0 and 1 */
34
#define ARMCTRL_0_SBM_OFFSET (ARM_OFFSET + 0x800) /* User 0 (ARM) Semaphores
35
* Doorbells & Mailboxes */
36
-#define PM_OFFSET 0x100000 /* Power Management, Reset controller
37
- * and Watchdog registers */
38
-#define PCM_CLOCK_OFFSET 0x101098
39
+#define CPRMAN_OFFSET 0x100000 /* Power Management, Watchdog */
40
+#define CM_OFFSET 0x101000 /* Clock Management */
41
#define RNG_OFFSET 0x104000
42
#define GPIO_OFFSET 0x200000
43
#define UART0_OFFSET 0x201000
44
@@ -XXX,XX +XXX,XX @@
45
#define I2S_OFFSET 0x203000
46
#define SPI0_OFFSET 0x204000
47
#define BSC0_OFFSET 0x205000 /* BSC0 I2C/TWI */
48
-#define UART1_OFFSET 0x215000
49
-#define EMMC_OFFSET 0x300000
50
+#define AUX_OFFSET 0x215000 /* AUX: UART1/SPI1/SPI2 */
51
+#define EMMC1_OFFSET 0x300000
52
#define SMI_OFFSET 0x600000
53
#define BSC1_OFFSET 0x804000 /* BSC1 I2C/TWI */
54
-#define USB_OFFSET 0x980000 /* DTC_OTG USB controller */
55
+#define USB_OTG_OFFSET 0x980000 /* DTC_OTG USB controller */
56
#define DMA15_OFFSET 0xE05000 /* DMA controller, channel 15 */
57
58
/* GPU interrupts */
59
@@ -XXX,XX +XXX,XX @@
60
#define INTERRUPT_SPI 54
61
#define INTERRUPT_I2SPCM 55
62
#define INTERRUPT_SDIO 56
63
-#define INTERRUPT_UART 57
64
+#define INTERRUPT_UART0 57
65
#define INTERRUPT_SLIMBUS 58
66
#define INTERRUPT_VEC 59
67
#define INTERRUPT_CPG 60
68
diff --git a/hw/arm/bcm2835_peripherals.c b/hw/arm/bcm2835_peripherals.c
14
diff --git a/hw/arm/bcm2835_peripherals.c b/hw/arm/bcm2835_peripherals.c
69
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
70
--- a/hw/arm/bcm2835_peripherals.c
16
--- a/hw/arm/bcm2835_peripherals.c
71
+++ b/hw/arm/bcm2835_peripherals.c
17
+++ b/hw/arm/bcm2835_peripherals.c
72
@@ -XXX,XX +XXX,XX @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)
18
@@ -XXX,XX +XXX,XX @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)
73
sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->uart0), 0));
74
sysbus_connect_irq(SYS_BUS_DEVICE(&s->uart0), 0,
75
qdev_get_gpio_in_named(DEVICE(&s->ic), BCM2835_IC_GPU_IRQ,
76
- INTERRUPT_UART));
77
+ INTERRUPT_UART0));
78
+
79
/* AUX / UART1 */
80
qdev_prop_set_chr(DEVICE(&s->aux), "chardev", serial_hd(1));
81
82
@@ -XXX,XX +XXX,XX @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)
83
return;
84
}
19
}
85
20
memory_region_add_subregion(&s->peri_mr, CPRMAN_OFFSET,
86
- memory_region_add_subregion(&s->peri_mr, UART1_OFFSET,
21
sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->cprman), 0));
87
+ memory_region_add_subregion(&s->peri_mr, AUX_OFFSET,
22
+ qdev_connect_clock_in(DEVICE(&s->uart0), "clk",
88
sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->aux), 0));
23
+ qdev_get_clock_out(DEVICE(&s->cprman), "uart-out"));
89
sysbus_connect_irq(SYS_BUS_DEVICE(&s->aux), 0,
24
90
qdev_get_gpio_in_named(DEVICE(&s->ic), BCM2835_IC_GPU_IRQ,
25
memory_region_add_subregion(&s->peri_mr, ARMCTRL_IC_OFFSET,
91
@@ -XXX,XX +XXX,XX @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)
26
sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->ic), 0));
92
return;
93
}
94
95
- memory_region_add_subregion(&s->peri_mr, EMMC_OFFSET,
96
+ memory_region_add_subregion(&s->peri_mr, EMMC1_OFFSET,
97
sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->sdhci), 0));
98
sysbus_connect_irq(SYS_BUS_DEVICE(&s->sdhci), 0,
99
qdev_get_gpio_in_named(DEVICE(&s->ic), BCM2835_IC_GPU_IRQ,
100
diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c
101
index XXXXXXX..XXXXXXX 100644
102
--- a/hw/arm/bcm2836.c
103
+++ b/hw/arm/bcm2836.c
104
@@ -XXX,XX +XXX,XX @@ static void bcm2836_realize(DeviceState *dev, Error **errp)
105
106
/* set periphbase/CBAR value for CPU-local registers */
107
object_property_set_int(OBJECT(&s->cpus[n]),
108
- BCM2836_PERI_BASE + MCORE_OFFSET,
109
+ BCM2836_PERI_BASE + MSYNC_OFFSET,
110
"reset-cbar", &err);
111
if (err) {
112
error_propagate(errp, err);
113
--
27
--
114
2.20.1
28
2.20.1
115
29
116
30
diff view generated by jsdifflib
1
From: Eric Auger <eric.auger@redhat.com>
1
From: Shashi Mallela <shashi.mallela@linaro.org>
2
2
3
Update the headers against commit:
3
Generic watchdog device model implementation as per ARM SBSA v6.0
4
0f1a7b3fac05 ("timer-of: don't use conditional expression
5
with mixed 'void' types")
6
4
7
Signed-off-by: Eric Auger <eric.auger@redhat.com>
5
Signed-off-by: Shashi Mallela <shashi.mallela@linaro.org>
8
Acked-by: Marc Zyngier <maz@kernel.org>
6
Message-id: 20201027015927.29495-2-shashi.mallela@linaro.org
9
Message-id: 20191003154640.22451-2-eric.auger@redhat.com
7
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
---
9
---
12
include/standard-headers/asm-x86/bootparam.h | 2 +
10
include/hw/watchdog/sbsa_gwdt.h | 79 +++++++++
13
include/standard-headers/asm-x86/kvm_para.h | 1 +
11
hw/watchdog/sbsa_gwdt.c | 293 ++++++++++++++++++++++++++++++++
14
include/standard-headers/linux/ethtool.h | 24 +++
12
hw/arm/Kconfig | 1 +
15
include/standard-headers/linux/pci_regs.h | 19 +-
13
hw/watchdog/Kconfig | 3 +
16
include/standard-headers/linux/virtio_fs.h | 19 ++
14
hw/watchdog/meson.build | 1 +
17
include/standard-headers/linux/virtio_ids.h | 2 +
15
5 files changed, 377 insertions(+)
18
include/standard-headers/linux/virtio_iommu.h | 165 ++++++++++++++++++
16
create mode 100644 include/hw/watchdog/sbsa_gwdt.h
19
include/standard-headers/linux/virtio_pmem.h | 6 +-
17
create mode 100644 hw/watchdog/sbsa_gwdt.c
20
linux-headers/asm-arm/kvm.h | 16 +-
21
linux-headers/asm-arm/unistd-common.h | 2 +
22
linux-headers/asm-arm64/kvm.h | 21 ++-
23
linux-headers/asm-generic/mman-common.h | 18 +-
24
linux-headers/asm-generic/mman.h | 10 +-
25
linux-headers/asm-generic/unistd.h | 10 +-
26
linux-headers/asm-mips/mman.h | 3 +
27
linux-headers/asm-mips/unistd_n32.h | 1 +
28
linux-headers/asm-mips/unistd_n64.h | 1 +
29
linux-headers/asm-mips/unistd_o32.h | 1 +
30
linux-headers/asm-powerpc/mman.h | 6 +-
31
linux-headers/asm-powerpc/unistd_32.h | 2 +
32
linux-headers/asm-powerpc/unistd_64.h | 2 +
33
linux-headers/asm-s390/kvm.h | 6 +
34
linux-headers/asm-s390/unistd_32.h | 2 +
35
linux-headers/asm-s390/unistd_64.h | 2 +
36
linux-headers/asm-x86/kvm.h | 28 ++-
37
linux-headers/asm-x86/unistd.h | 2 +-
38
linux-headers/asm-x86/unistd_32.h | 2 +
39
linux-headers/asm-x86/unistd_64.h | 2 +
40
linux-headers/asm-x86/unistd_x32.h | 2 +
41
linux-headers/linux/kvm.h | 12 +-
42
linux-headers/linux/psp-sev.h | 5 +-
43
linux-headers/linux/vfio.h | 71 +++++---
44
32 files changed, 406 insertions(+), 59 deletions(-)
45
create mode 100644 include/standard-headers/linux/virtio_fs.h
46
create mode 100644 include/standard-headers/linux/virtio_iommu.h
47
18
48
diff --git a/include/standard-headers/asm-x86/bootparam.h b/include/standard-headers/asm-x86/bootparam.h
19
diff --git a/include/hw/watchdog/sbsa_gwdt.h b/include/hw/watchdog/sbsa_gwdt.h
49
index XXXXXXX..XXXXXXX 100644
50
--- a/include/standard-headers/asm-x86/bootparam.h
51
+++ b/include/standard-headers/asm-x86/bootparam.h
52
@@ -XXX,XX +XXX,XX @@
53
#define XLF_EFI_HANDOVER_32        (1<<2)
54
#define XLF_EFI_HANDOVER_64        (1<<3)
55
#define XLF_EFI_KEXEC            (1<<4)
56
+#define XLF_5LEVEL            (1<<5)
57
+#define XLF_5LEVEL_ENABLED        (1<<6)
58
59
60
#endif /* _ASM_X86_BOOTPARAM_H */
61
diff --git a/include/standard-headers/asm-x86/kvm_para.h b/include/standard-headers/asm-x86/kvm_para.h
62
index XXXXXXX..XXXXXXX 100644
63
--- a/include/standard-headers/asm-x86/kvm_para.h
64
+++ b/include/standard-headers/asm-x86/kvm_para.h
65
@@ -XXX,XX +XXX,XX @@
66
#define KVM_FEATURE_ASYNC_PF_VMEXIT    10
67
#define KVM_FEATURE_PV_SEND_IPI    11
68
#define KVM_FEATURE_POLL_CONTROL    12
69
+#define KVM_FEATURE_PV_SCHED_YIELD    13
70
71
#define KVM_HINTS_REALTIME 0
72
73
diff --git a/include/standard-headers/linux/ethtool.h b/include/standard-headers/linux/ethtool.h
74
index XXXXXXX..XXXXXXX 100644
75
--- a/include/standard-headers/linux/ethtool.h
76
+++ b/include/standard-headers/linux/ethtool.h
77
@@ -XXX,XX +XXX,XX @@ struct ethtool_tunable {
78
#define ETHTOOL_PHY_FAST_LINK_DOWN_ON    0
79
#define ETHTOOL_PHY_FAST_LINK_DOWN_OFF    0xff
80
81
+/* Energy Detect Power Down (EDPD) is a feature supported by some PHYs, where
82
+ * the PHY's RX & TX blocks are put into a low-power mode when there is no
83
+ * link detected (typically cable is un-plugged). For RX, only a minimal
84
+ * link-detection is available, and for TX the PHY wakes up to send link pulses
85
+ * to avoid any lock-ups in case the peer PHY may also be running in EDPD mode.
86
+ *
87
+ * Some PHYs may support configuration of the wake-up interval for TX pulses,
88
+ * and some PHYs may support only disabling TX pulses entirely. For the latter
89
+ * a special value is required (ETHTOOL_PHY_EDPD_NO_TX) so that this can be
90
+ * configured from userspace (should the user want it).
91
+ *
92
+ * The interval units for TX wake-up are in milliseconds, since this should
93
+ * cover a reasonable range of intervals:
94
+ * - from 1 millisecond, which does not sound like much of a power-saver
95
+ * - to ~65 seconds which is quite a lot to wait for a link to come up when
96
+ * plugging a cable
97
+ */
98
+#define ETHTOOL_PHY_EDPD_DFLT_TX_MSECS        0xffff
99
+#define ETHTOOL_PHY_EDPD_NO_TX            0xfffe
100
+#define ETHTOOL_PHY_EDPD_DISABLE        0
101
+
102
enum phy_tunable_id {
103
    ETHTOOL_PHY_ID_UNSPEC,
104
    ETHTOOL_PHY_DOWNSHIFT,
105
    ETHTOOL_PHY_FAST_LINK_DOWN,
106
+    ETHTOOL_PHY_EDPD,
107
    /*
108
     * Add your fresh new phy tunable attribute above and remember to update
109
     * phy_tunable_strings[] in net/core/ethtool.c
110
@@ -XXX,XX +XXX,XX @@ enum ethtool_link_mode_bit_indices {
111
    ETHTOOL_LINK_MODE_200000baseLR4_ER4_FR4_Full_BIT = 64,
112
    ETHTOOL_LINK_MODE_200000baseDR4_Full_BIT     = 65,
113
    ETHTOOL_LINK_MODE_200000baseCR4_Full_BIT     = 66,
114
+    ETHTOOL_LINK_MODE_100baseT1_Full_BIT         = 67,
115
+    ETHTOOL_LINK_MODE_1000baseT1_Full_BIT         = 68,
116
117
    /* must be last entry */
118
    __ETHTOOL_LINK_MODE_MASK_NBITS
119
diff --git a/include/standard-headers/linux/pci_regs.h b/include/standard-headers/linux/pci_regs.h
120
index XXXXXXX..XXXXXXX 100644
121
--- a/include/standard-headers/linux/pci_regs.h
122
+++ b/include/standard-headers/linux/pci_regs.h
123
@@ -XXX,XX +XXX,XX @@
124
#define PCI_EXP_LNKCAP_SLS_5_0GB 0x00000002 /* LNKCAP2 SLS Vector bit 1 */
125
#define PCI_EXP_LNKCAP_SLS_8_0GB 0x00000003 /* LNKCAP2 SLS Vector bit 2 */
126
#define PCI_EXP_LNKCAP_SLS_16_0GB 0x00000004 /* LNKCAP2 SLS Vector bit 3 */
127
+#define PCI_EXP_LNKCAP_SLS_32_0GB 0x00000005 /* LNKCAP2 SLS Vector bit 4 */
128
#define PCI_EXP_LNKCAP_MLW    0x000003f0 /* Maximum Link Width */
129
#define PCI_EXP_LNKCAP_ASPMS    0x00000c00 /* ASPM Support */
130
#define PCI_EXP_LNKCAP_L0SEL    0x00007000 /* L0s Exit Latency */
131
@@ -XXX,XX +XXX,XX @@
132
#define PCI_EXP_LNKSTA_CLS_5_0GB 0x0002 /* Current Link Speed 5.0GT/s */
133
#define PCI_EXP_LNKSTA_CLS_8_0GB 0x0003 /* Current Link Speed 8.0GT/s */
134
#define PCI_EXP_LNKSTA_CLS_16_0GB 0x0004 /* Current Link Speed 16.0GT/s */
135
+#define PCI_EXP_LNKSTA_CLS_32_0GB 0x0005 /* Current Link Speed 32.0GT/s */
136
#define PCI_EXP_LNKSTA_NLW    0x03f0    /* Negotiated Link Width */
137
#define PCI_EXP_LNKSTA_NLW_X1    0x0010    /* Current Link Width x1 */
138
#define PCI_EXP_LNKSTA_NLW_X2    0x0020    /* Current Link Width x2 */
139
@@ -XXX,XX +XXX,XX @@
140
#define PCI_EXP_SLTCTL_CCIE    0x0010    /* Command Completed Interrupt Enable */
141
#define PCI_EXP_SLTCTL_HPIE    0x0020    /* Hot-Plug Interrupt Enable */
142
#define PCI_EXP_SLTCTL_AIC    0x00c0    /* Attention Indicator Control */
143
+#define PCI_EXP_SLTCTL_ATTN_IND_SHIFT 6 /* Attention Indicator shift */
144
#define PCI_EXP_SLTCTL_ATTN_IND_ON 0x0040 /* Attention Indicator on */
145
#define PCI_EXP_SLTCTL_ATTN_IND_BLINK 0x0080 /* Attention Indicator blinking */
146
#define PCI_EXP_SLTCTL_ATTN_IND_OFF 0x00c0 /* Attention Indicator off */
147
@@ -XXX,XX +XXX,XX @@
148
#define PCI_EXP_LNKCAP2_SLS_5_0GB    0x00000004 /* Supported Speed 5GT/s */
149
#define PCI_EXP_LNKCAP2_SLS_8_0GB    0x00000008 /* Supported Speed 8GT/s */
150
#define PCI_EXP_LNKCAP2_SLS_16_0GB    0x00000010 /* Supported Speed 16GT/s */
151
+#define PCI_EXP_LNKCAP2_SLS_32_0GB    0x00000020 /* Supported Speed 32GT/s */
152
#define PCI_EXP_LNKCAP2_CROSSLINK    0x00000100 /* Crosslink supported */
153
#define PCI_EXP_LNKCTL2        48    /* Link Control 2 */
154
#define PCI_EXP_LNKCTL2_TLS        0x000f
155
@@ -XXX,XX +XXX,XX @@
156
#define PCI_EXP_LNKCTL2_TLS_5_0GT    0x0002 /* Supported Speed 5GT/s */
157
#define PCI_EXP_LNKCTL2_TLS_8_0GT    0x0003 /* Supported Speed 8GT/s */
158
#define PCI_EXP_LNKCTL2_TLS_16_0GT    0x0004 /* Supported Speed 16GT/s */
159
+#define PCI_EXP_LNKCTL2_TLS_32_0GT    0x0005 /* Supported Speed 32GT/s */
160
#define PCI_EXP_LNKSTA2        50    /* Link Status 2 */
161
#define PCI_CAP_EXP_ENDPOINT_SIZEOF_V2    52    /* v2 endpoints with link end here */
162
#define PCI_EXP_SLTCAP2        52    /* Slot Capabilities 2 */
163
@@ -XXX,XX +XXX,XX @@
164
#define PCI_EXT_CAP_ID_DPC    0x1D    /* Downstream Port Containment */
165
#define PCI_EXT_CAP_ID_L1SS    0x1E    /* L1 PM Substates */
166
#define PCI_EXT_CAP_ID_PTM    0x1F    /* Precision Time Measurement */
167
-#define PCI_EXT_CAP_ID_MAX    PCI_EXT_CAP_ID_PTM
168
+#define PCI_EXT_CAP_ID_DLF    0x25    /* Data Link Feature */
169
+#define PCI_EXT_CAP_ID_PL_16GT    0x26    /* Physical Layer 16.0 GT/s */
170
+#define PCI_EXT_CAP_ID_MAX    PCI_EXT_CAP_ID_PL_16GT
171
172
#define PCI_EXT_CAP_DSN_SIZEOF    12
173
#define PCI_EXT_CAP_MCAST_ENDPOINT_SIZEOF 40
174
@@ -XXX,XX +XXX,XX @@
175
#define PCI_L1SS_CTL1_LTR_L12_TH_SCALE    0xe0000000 /* LTR_L1.2_THRESHOLD_Scale */
176
#define PCI_L1SS_CTL2        0x0c    /* Control 2 Register */
177
178
+/* Data Link Feature */
179
+#define PCI_DLF_CAP        0x04    /* Capabilities Register */
180
+#define PCI_DLF_EXCHANGE_ENABLE    0x80000000 /* Data Link Feature Exchange Enable */
181
+
182
+/* Physical Layer 16.0 GT/s */
183
+#define PCI_PL_16GT_LE_CTRL    0x20    /* Lane Equalization Control Register */
184
+#define PCI_PL_16GT_LE_CTRL_DSP_TX_PRESET_MASK        0x0000000F
185
+#define PCI_PL_16GT_LE_CTRL_USP_TX_PRESET_MASK        0x000000F0
186
+#define PCI_PL_16GT_LE_CTRL_USP_TX_PRESET_SHIFT    4
187
+
188
#endif /* LINUX_PCI_REGS_H */
189
diff --git a/include/standard-headers/linux/virtio_fs.h b/include/standard-headers/linux/virtio_fs.h
190
new file mode 100644
20
new file mode 100644
191
index XXXXXXX..XXXXXXX
21
index XXXXXXX..XXXXXXX
192
--- /dev/null
22
--- /dev/null
193
+++ b/include/standard-headers/linux/virtio_fs.h
23
+++ b/include/hw/watchdog/sbsa_gwdt.h
194
@@ -XXX,XX +XXX,XX @@
24
@@ -XXX,XX +XXX,XX @@
195
+/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */
25
+/*
196
+
26
+ * Copyright (c) 2020 Linaro Limited
197
+#ifndef _LINUX_VIRTIO_FS_H
27
+ *
198
+#define _LINUX_VIRTIO_FS_H
28
+ * Authors:
199
+
29
+ * Shashi Mallela <shashi.mallela@linaro.org>
200
+#include "standard-headers/linux/types.h"
30
+ *
201
+#include "standard-headers/linux/virtio_ids.h"
31
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at your
202
+#include "standard-headers/linux/virtio_config.h"
32
+ * option) any later version. See the COPYING file in the top-level directory.
203
+#include "standard-headers/linux/virtio_types.h"
33
+ *
204
+
34
+ */
205
+struct virtio_fs_config {
35
+
206
+    /* Filesystem name (UTF-8, not NUL-terminated, padded with NULs) */
36
+#ifndef WDT_SBSA_GWDT_H
207
+    uint8_t tag[36];
37
+#define WDT_SBSA_GWDT_H
208
+
38
+
209
+    /* Number of request queues */
39
+#include "qemu/bitops.h"
210
+    uint32_t num_request_queues;
40
+#include "hw/sysbus.h"
211
+} QEMU_PACKED;
41
+#include "hw/irq.h"
212
+
42
+
213
+#endif /* _LINUX_VIRTIO_FS_H */
43
+#define TYPE_WDT_SBSA "sbsa_gwdt"
214
diff --git a/include/standard-headers/linux/virtio_ids.h b/include/standard-headers/linux/virtio_ids.h
44
+#define SBSA_GWDT(obj) \
215
index XXXXXXX..XXXXXXX 100644
45
+ OBJECT_CHECK(SBSA_GWDTState, (obj), TYPE_WDT_SBSA)
216
--- a/include/standard-headers/linux/virtio_ids.h
46
+#define SBSA_GWDT_CLASS(klass) \
217
+++ b/include/standard-headers/linux/virtio_ids.h
47
+ OBJECT_CLASS_CHECK(SBSA_GWDTClass, (klass), TYPE_WDT_SBSA)
218
@@ -XXX,XX +XXX,XX @@
48
+#define SBSA_GWDT_GET_CLASS(obj) \
219
#define VIRTIO_ID_INPUT 18 /* virtio input */
49
+ OBJECT_GET_CLASS(SBSA_GWDTClass, (obj), TYPE_WDT_SBSA)
220
#define VIRTIO_ID_VSOCK 19 /* virtio vsock transport */
50
+
221
#define VIRTIO_ID_CRYPTO 20 /* virtio crypto */
51
+/* SBSA Generic Watchdog register definitions */
222
+#define VIRTIO_ID_IOMMU 23 /* virtio IOMMU */
52
+/* refresh frame */
223
+#define VIRTIO_ID_FS 26 /* virtio filesystem */
53
+#define SBSA_GWDT_WRR 0x000
224
#define VIRTIO_ID_PMEM 27 /* virtio pmem */
54
+
225
55
+/* control frame */
226
#endif /* _LINUX_VIRTIO_IDS_H */
56
+#define SBSA_GWDT_WCS 0x000
227
diff --git a/include/standard-headers/linux/virtio_iommu.h b/include/standard-headers/linux/virtio_iommu.h
57
+#define SBSA_GWDT_WOR 0x008
58
+#define SBSA_GWDT_WORU 0x00C
59
+#define SBSA_GWDT_WCV 0x010
60
+#define SBSA_GWDT_WCVU 0x014
61
+
62
+/* Watchdog Interface Identification Register */
63
+#define SBSA_GWDT_W_IIDR 0xFCC
64
+
65
+/* Watchdog Control and Status Register Bits */
66
+#define SBSA_GWDT_WCS_EN BIT(0)
67
+#define SBSA_GWDT_WCS_WS0 BIT(1)
68
+#define SBSA_GWDT_WCS_WS1 BIT(2)
69
+
70
+#define SBSA_GWDT_WOR_MASK 0x0000FFFF
71
+
72
+/*
73
+ * Watchdog Interface Identification Register definition
74
+ * considering JEP106 code for ARM in Bits [11:0]
75
+ */
76
+#define SBSA_GWDT_ID 0x1043B
77
+
78
+/* 2 Separate memory regions for each of refresh & control register frames */
79
+#define SBSA_GWDT_RMMIO_SIZE 0x1000
80
+#define SBSA_GWDT_CMMIO_SIZE 0x1000
81
+
82
+#define SBSA_TIMER_FREQ 62500000 /* Hz */
83
+
84
+typedef struct SBSA_GWDTState {
85
+ /* <private> */
86
+ SysBusDevice parent_obj;
87
+
88
+ /*< public >*/
89
+ MemoryRegion rmmio;
90
+ MemoryRegion cmmio;
91
+ qemu_irq irq;
92
+
93
+ QEMUTimer *timer;
94
+
95
+ uint32_t id;
96
+ uint32_t wcs;
97
+ uint32_t worl;
98
+ uint32_t woru;
99
+ uint32_t wcvl;
100
+ uint32_t wcvu;
101
+} SBSA_GWDTState;
102
+
103
+#endif /* WDT_SBSA_GWDT_H */
104
diff --git a/hw/watchdog/sbsa_gwdt.c b/hw/watchdog/sbsa_gwdt.c
228
new file mode 100644
105
new file mode 100644
229
index XXXXXXX..XXXXXXX
106
index XXXXXXX..XXXXXXX
230
--- /dev/null
107
--- /dev/null
231
+++ b/include/standard-headers/linux/virtio_iommu.h
108
+++ b/hw/watchdog/sbsa_gwdt.c
232
@@ -XXX,XX +XXX,XX @@
109
@@ -XXX,XX +XXX,XX @@
233
+/* SPDX-License-Identifier: BSD-3-Clause */
234
+/*
110
+/*
235
+ * Virtio-iommu definition v0.12
111
+ * Generic watchdog device model for SBSA
236
+ *
112
+ *
237
+ * Copyright (C) 2019 Arm Ltd.
113
+ * The watchdog device has been implemented as revision 1 variant of
114
+ * the ARM SBSA specification v6.0
115
+ * (https://developer.arm.com/documentation/den0029/d?lang=en)
116
+ *
117
+ * Copyright Linaro.org 2020
118
+ *
119
+ * Authors:
120
+ * Shashi Mallela <shashi.mallela@linaro.org>
121
+ *
122
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at your
123
+ * option) any later version. See the COPYING file in the top-level directory.
124
+ *
238
+ */
125
+ */
239
+#ifndef _LINUX_VIRTIO_IOMMU_H
126
+
240
+#define _LINUX_VIRTIO_IOMMU_H
127
+#include "qemu/osdep.h"
241
+
128
+#include "sysemu/reset.h"
242
+#include "standard-headers/linux/types.h"
129
+#include "sysemu/watchdog.h"
243
+
130
+#include "hw/watchdog/sbsa_gwdt.h"
244
+/* Feature bits */
131
+#include "qemu/timer.h"
245
+#define VIRTIO_IOMMU_F_INPUT_RANGE        0
132
+#include "migration/vmstate.h"
246
+#define VIRTIO_IOMMU_F_DOMAIN_RANGE        1
133
+#include "qemu/log.h"
247
+#define VIRTIO_IOMMU_F_MAP_UNMAP        2
134
+#include "qemu/module.h"
248
+#define VIRTIO_IOMMU_F_BYPASS            3
135
+
249
+#define VIRTIO_IOMMU_F_PROBE            4
136
+static WatchdogTimerModel model = {
250
+#define VIRTIO_IOMMU_F_MMIO            5
137
+ .wdt_name = TYPE_WDT_SBSA,
251
+
138
+ .wdt_description = "SBSA-compliant generic watchdog device",
252
+struct virtio_iommu_range_64 {
253
+    uint64_t                    start;
254
+    uint64_t                    end;
255
+};
139
+};
256
+
140
+
257
+struct virtio_iommu_range_32 {
141
+static const VMStateDescription vmstate_sbsa_gwdt = {
258
+    uint32_t                    start;
142
+ .name = "sbsa-gwdt",
259
+    uint32_t                    end;
143
+ .version_id = 1,
144
+ .minimum_version_id = 1,
145
+ .fields = (VMStateField[]) {
146
+ VMSTATE_TIMER_PTR(timer, SBSA_GWDTState),
147
+ VMSTATE_UINT32(wcs, SBSA_GWDTState),
148
+ VMSTATE_UINT32(worl, SBSA_GWDTState),
149
+ VMSTATE_UINT32(woru, SBSA_GWDTState),
150
+ VMSTATE_UINT32(wcvl, SBSA_GWDTState),
151
+ VMSTATE_UINT32(wcvu, SBSA_GWDTState),
152
+ VMSTATE_END_OF_LIST()
153
+ }
260
+};
154
+};
261
+
155
+
262
+struct virtio_iommu_config {
156
+typedef enum WdtRefreshType {
263
+    /* Supported page sizes */
157
+ EXPLICIT_REFRESH = 0,
264
+    uint64_t                    page_size_mask;
158
+ TIMEOUT_REFRESH = 1,
265
+    /* Supported IOVA range */
159
+} WdtRefreshType;
266
+    struct virtio_iommu_range_64        input_range;
160
+
267
+    /* Max domain ID size */
161
+static uint64_t sbsa_gwdt_rread(void *opaque, hwaddr addr, unsigned int size)
268
+    struct virtio_iommu_range_32        domain_range;
162
+{
269
+    /* Probe buffer size */
163
+ SBSA_GWDTState *s = SBSA_GWDT(opaque);
270
+    uint32_t                    probe_size;
164
+ uint32_t ret = 0;
165
+
166
+ switch (addr) {
167
+ case SBSA_GWDT_WRR:
168
+ /* watch refresh read has no effect and returns 0 */
169
+ ret = 0;
170
+ break;
171
+ case SBSA_GWDT_W_IIDR:
172
+ ret = s->id;
173
+ break;
174
+ default:
175
+ qemu_log_mask(LOG_GUEST_ERROR, "bad address in refresh frame read :"
176
+ " 0x%x\n", (int)addr);
177
+ }
178
+ return ret;
179
+}
180
+
181
+static uint64_t sbsa_gwdt_read(void *opaque, hwaddr addr, unsigned int size)
182
+{
183
+ SBSA_GWDTState *s = SBSA_GWDT(opaque);
184
+ uint32_t ret = 0;
185
+
186
+ switch (addr) {
187
+ case SBSA_GWDT_WCS:
188
+ ret = s->wcs;
189
+ break;
190
+ case SBSA_GWDT_WOR:
191
+ ret = s->worl;
192
+ break;
193
+ case SBSA_GWDT_WORU:
194
+ ret = s->woru;
195
+ break;
196
+ case SBSA_GWDT_WCV:
197
+ ret = s->wcvl;
198
+ break;
199
+ case SBSA_GWDT_WCVU:
200
+ ret = s->wcvu;
201
+ break;
202
+ case SBSA_GWDT_W_IIDR:
203
+ ret = s->id;
204
+ break;
205
+ default:
206
+ qemu_log_mask(LOG_GUEST_ERROR, "bad address in control frame read :"
207
+ " 0x%x\n", (int)addr);
208
+ }
209
+ return ret;
210
+}
211
+
212
+static void sbsa_gwdt_update_timer(SBSA_GWDTState *s, WdtRefreshType rtype)
213
+{
214
+ uint64_t timeout = 0;
215
+
216
+ timer_del(s->timer);
217
+
218
+ if (s->wcs & SBSA_GWDT_WCS_EN) {
219
+ /*
220
+ * Extract the upper 16 bits from woru & 32 bits from worl
221
+ * registers to construct the 48 bit offset value
222
+ */
223
+ timeout = s->woru;
224
+ timeout <<= 32;
225
+ timeout |= s->worl;
226
+ timeout = muldiv64(timeout, NANOSECONDS_PER_SECOND, SBSA_TIMER_FREQ);
227
+ timeout += qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
228
+
229
+ if ((rtype == EXPLICIT_REFRESH) || ((rtype == TIMEOUT_REFRESH) &&
230
+ (!(s->wcs & SBSA_GWDT_WCS_WS0)))) {
231
+ /* store the current timeout value into compare registers */
232
+ s->wcvu = timeout >> 32;
233
+ s->wcvl = timeout;
234
+ }
235
+ timer_mod(s->timer, timeout);
236
+ }
237
+}
238
+
239
+static void sbsa_gwdt_rwrite(void *opaque, hwaddr offset, uint64_t data,
240
+ unsigned size) {
241
+ SBSA_GWDTState *s = SBSA_GWDT(opaque);
242
+
243
+ if (offset == SBSA_GWDT_WRR) {
244
+ s->wcs &= ~(SBSA_GWDT_WCS_WS0 | SBSA_GWDT_WCS_WS1);
245
+
246
+ sbsa_gwdt_update_timer(s, EXPLICIT_REFRESH);
247
+ } else {
248
+ qemu_log_mask(LOG_GUEST_ERROR, "bad address in refresh frame write :"
249
+ " 0x%x\n", (int)offset);
250
+ }
251
+}
252
+
253
+static void sbsa_gwdt_write(void *opaque, hwaddr offset, uint64_t data,
254
+ unsigned size) {
255
+ SBSA_GWDTState *s = SBSA_GWDT(opaque);
256
+
257
+ switch (offset) {
258
+ case SBSA_GWDT_WCS:
259
+ s->wcs = data & SBSA_GWDT_WCS_EN;
260
+ qemu_set_irq(s->irq, 0);
261
+ sbsa_gwdt_update_timer(s, EXPLICIT_REFRESH);
262
+ break;
263
+
264
+ case SBSA_GWDT_WOR:
265
+ s->worl = data;
266
+ s->wcs &= ~(SBSA_GWDT_WCS_WS0 | SBSA_GWDT_WCS_WS1);
267
+ qemu_set_irq(s->irq, 0);
268
+ sbsa_gwdt_update_timer(s, EXPLICIT_REFRESH);
269
+ break;
270
+
271
+ case SBSA_GWDT_WORU:
272
+ s->woru = data & SBSA_GWDT_WOR_MASK;
273
+ s->wcs &= ~(SBSA_GWDT_WCS_WS0 | SBSA_GWDT_WCS_WS1);
274
+ qemu_set_irq(s->irq, 0);
275
+ sbsa_gwdt_update_timer(s, EXPLICIT_REFRESH);
276
+ break;
277
+
278
+ case SBSA_GWDT_WCV:
279
+ s->wcvl = data;
280
+ break;
281
+
282
+ case SBSA_GWDT_WCVU:
283
+ s->wcvu = data;
284
+ break;
285
+
286
+ default:
287
+ qemu_log_mask(LOG_GUEST_ERROR, "bad address in control frame write :"
288
+ " 0x%x\n", (int)offset);
289
+ }
290
+ return;
291
+}
292
+
293
+static void wdt_sbsa_gwdt_reset(DeviceState *dev)
294
+{
295
+ SBSA_GWDTState *s = SBSA_GWDT(dev);
296
+
297
+ timer_del(s->timer);
298
+
299
+ s->wcs = 0;
300
+ s->wcvl = 0;
301
+ s->wcvu = 0;
302
+ s->worl = 0;
303
+ s->woru = 0;
304
+ s->id = SBSA_GWDT_ID;
305
+}
306
+
307
+static void sbsa_gwdt_timer_sysinterrupt(void *opaque)
308
+{
309
+ SBSA_GWDTState *s = SBSA_GWDT(opaque);
310
+
311
+ if (!(s->wcs & SBSA_GWDT_WCS_WS0)) {
312
+ s->wcs |= SBSA_GWDT_WCS_WS0;
313
+ sbsa_gwdt_update_timer(s, TIMEOUT_REFRESH);
314
+ qemu_set_irq(s->irq, 1);
315
+ } else {
316
+ s->wcs |= SBSA_GWDT_WCS_WS1;
317
+ qemu_log_mask(CPU_LOG_RESET, "Watchdog timer expired.\n");
318
+ /*
319
+ * Reset the watchdog only if the guest gets notified about
320
+ * expiry. watchdog_perform_action() may temporarily relinquish
321
+ * the BQL; reset before triggering the action to avoid races with
322
+ * sbsa_gwdt instructions.
323
+ */
324
+ switch (get_watchdog_action()) {
325
+ case WATCHDOG_ACTION_DEBUG:
326
+ case WATCHDOG_ACTION_NONE:
327
+ case WATCHDOG_ACTION_PAUSE:
328
+ break;
329
+ default:
330
+ wdt_sbsa_gwdt_reset(DEVICE(s));
331
+ }
332
+ watchdog_perform_action();
333
+ }
334
+}
335
+
336
+static const MemoryRegionOps sbsa_gwdt_rops = {
337
+ .read = sbsa_gwdt_rread,
338
+ .write = sbsa_gwdt_rwrite,
339
+ .endianness = DEVICE_LITTLE_ENDIAN,
340
+ .valid.min_access_size = 4,
341
+ .valid.max_access_size = 4,
342
+ .valid.unaligned = false,
271
+};
343
+};
272
+
344
+
273
+/* Request types */
345
+static const MemoryRegionOps sbsa_gwdt_ops = {
274
+#define VIRTIO_IOMMU_T_ATTACH            0x01
346
+ .read = sbsa_gwdt_read,
275
+#define VIRTIO_IOMMU_T_DETACH            0x02
347
+ .write = sbsa_gwdt_write,
276
+#define VIRTIO_IOMMU_T_MAP            0x03
348
+ .endianness = DEVICE_LITTLE_ENDIAN,
277
+#define VIRTIO_IOMMU_T_UNMAP            0x04
349
+ .valid.min_access_size = 4,
278
+#define VIRTIO_IOMMU_T_PROBE            0x05
350
+ .valid.max_access_size = 4,
279
+
351
+ .valid.unaligned = false,
280
+/* Status types */
281
+#define VIRTIO_IOMMU_S_OK            0x00
282
+#define VIRTIO_IOMMU_S_IOERR            0x01
283
+#define VIRTIO_IOMMU_S_UNSUPP            0x02
284
+#define VIRTIO_IOMMU_S_DEVERR            0x03
285
+#define VIRTIO_IOMMU_S_INVAL            0x04
286
+#define VIRTIO_IOMMU_S_RANGE            0x05
287
+#define VIRTIO_IOMMU_S_NOENT            0x06
288
+#define VIRTIO_IOMMU_S_FAULT            0x07
289
+#define VIRTIO_IOMMU_S_NOMEM            0x08
290
+
291
+struct virtio_iommu_req_head {
292
+    uint8_t                    type;
293
+    uint8_t                    reserved[3];
294
+};
352
+};
295
+
353
+
296
+struct virtio_iommu_req_tail {
354
+static void wdt_sbsa_gwdt_realize(DeviceState *dev, Error **errp)
297
+    uint8_t                    status;
355
+{
298
+    uint8_t                    reserved[3];
356
+ SBSA_GWDTState *s = SBSA_GWDT(dev);
357
+ SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
358
+
359
+ memory_region_init_io(&s->rmmio, OBJECT(dev),
360
+ &sbsa_gwdt_rops, s,
361
+ "sbsa_gwdt.refresh",
362
+ SBSA_GWDT_RMMIO_SIZE);
363
+
364
+ memory_region_init_io(&s->cmmio, OBJECT(dev),
365
+ &sbsa_gwdt_ops, s,
366
+ "sbsa_gwdt.control",
367
+ SBSA_GWDT_CMMIO_SIZE);
368
+
369
+ sysbus_init_mmio(sbd, &s->rmmio);
370
+ sysbus_init_mmio(sbd, &s->cmmio);
371
+
372
+ sysbus_init_irq(sbd, &s->irq);
373
+
374
+ s->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, sbsa_gwdt_timer_sysinterrupt,
375
+ dev);
376
+}
377
+
378
+static void wdt_sbsa_gwdt_class_init(ObjectClass *klass, void *data)
379
+{
380
+ DeviceClass *dc = DEVICE_CLASS(klass);
381
+
382
+ dc->realize = wdt_sbsa_gwdt_realize;
383
+ dc->reset = wdt_sbsa_gwdt_reset;
384
+ dc->hotpluggable = false;
385
+ set_bit(DEVICE_CATEGORY_MISC, dc->categories);
386
+ dc->vmsd = &vmstate_sbsa_gwdt;
387
+}
388
+
389
+static const TypeInfo wdt_sbsa_gwdt_info = {
390
+ .class_init = wdt_sbsa_gwdt_class_init,
391
+ .parent = TYPE_SYS_BUS_DEVICE,
392
+ .name = TYPE_WDT_SBSA,
393
+ .instance_size = sizeof(SBSA_GWDTState),
299
+};
394
+};
300
+
395
+
301
+struct virtio_iommu_req_attach {
396
+static void wdt_sbsa_gwdt_register_types(void)
302
+    struct virtio_iommu_req_head        head;
397
+{
303
+    uint32_t                    domain;
398
+ watchdog_add_model(&model);
304
+    uint32_t                    endpoint;
399
+ type_register_static(&wdt_sbsa_gwdt_info);
305
+    uint8_t                    reserved[8];
400
+}
306
+    struct virtio_iommu_req_tail        tail;
401
+
307
+};
402
+type_init(wdt_sbsa_gwdt_register_types)
308
+
403
diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
309
+struct virtio_iommu_req_detach {
310
+    struct virtio_iommu_req_head        head;
311
+    uint32_t                    domain;
312
+    uint32_t                    endpoint;
313
+    uint8_t                    reserved[8];
314
+    struct virtio_iommu_req_tail        tail;
315
+};
316
+
317
+#define VIRTIO_IOMMU_MAP_F_READ            (1 << 0)
318
+#define VIRTIO_IOMMU_MAP_F_WRITE        (1 << 1)
319
+#define VIRTIO_IOMMU_MAP_F_MMIO            (1 << 2)
320
+
321
+#define VIRTIO_IOMMU_MAP_F_MASK            (VIRTIO_IOMMU_MAP_F_READ |    \
322
+                         VIRTIO_IOMMU_MAP_F_WRITE |    \
323
+                         VIRTIO_IOMMU_MAP_F_MMIO)
324
+
325
+struct virtio_iommu_req_map {
326
+    struct virtio_iommu_req_head        head;
327
+    uint32_t                    domain;
328
+    uint64_t                    virt_start;
329
+    uint64_t                    virt_end;
330
+    uint64_t                    phys_start;
331
+    uint32_t                    flags;
332
+    struct virtio_iommu_req_tail        tail;
333
+};
334
+
335
+struct virtio_iommu_req_unmap {
336
+    struct virtio_iommu_req_head        head;
337
+    uint32_t                    domain;
338
+    uint64_t                    virt_start;
339
+    uint64_t                    virt_end;
340
+    uint8_t                    reserved[4];
341
+    struct virtio_iommu_req_tail        tail;
342
+};
343
+
344
+#define VIRTIO_IOMMU_PROBE_T_NONE        0
345
+#define VIRTIO_IOMMU_PROBE_T_RESV_MEM        1
346
+
347
+#define VIRTIO_IOMMU_PROBE_T_MASK        0xfff
348
+
349
+struct virtio_iommu_probe_property {
350
+    uint16_t                    type;
351
+    uint16_t                    length;
352
+};
353
+
354
+#define VIRTIO_IOMMU_RESV_MEM_T_RESERVED    0
355
+#define VIRTIO_IOMMU_RESV_MEM_T_MSI        1
356
+
357
+struct virtio_iommu_probe_resv_mem {
358
+    struct virtio_iommu_probe_property    head;
359
+    uint8_t                    subtype;
360
+    uint8_t                    reserved[3];
361
+    uint64_t                    start;
362
+    uint64_t                    end;
363
+};
364
+
365
+struct virtio_iommu_req_probe {
366
+    struct virtio_iommu_req_head        head;
367
+    uint32_t                    endpoint;
368
+    uint8_t                    reserved[64];
369
+
370
+    uint8_t                    properties[];
371
+
372
+    /*
373
+     * Tail follows the variable-length properties array. No padding,
374
+     * property lengths are all aligned on 8 bytes.
375
+     */
376
+};
377
+
378
+/* Fault types */
379
+#define VIRTIO_IOMMU_FAULT_R_UNKNOWN        0
380
+#define VIRTIO_IOMMU_FAULT_R_DOMAIN        1
381
+#define VIRTIO_IOMMU_FAULT_R_MAPPING        2
382
+
383
+#define VIRTIO_IOMMU_FAULT_F_READ        (1 << 0)
384
+#define VIRTIO_IOMMU_FAULT_F_WRITE        (1 << 1)
385
+#define VIRTIO_IOMMU_FAULT_F_EXEC        (1 << 2)
386
+#define VIRTIO_IOMMU_FAULT_F_ADDRESS        (1 << 8)
387
+
388
+struct virtio_iommu_fault {
389
+    uint8_t                    reason;
390
+    uint8_t                    reserved[3];
391
+    uint32_t                    flags;
392
+    uint32_t                    endpoint;
393
+    uint8_t                    reserved2[4];
394
+    uint64_t                    address;
395
+};
396
+
397
+#endif
398
diff --git a/include/standard-headers/linux/virtio_pmem.h b/include/standard-headers/linux/virtio_pmem.h
399
index XXXXXXX..XXXXXXX 100644
404
index XXXXXXX..XXXXXXX 100644
400
--- a/include/standard-headers/linux/virtio_pmem.h
405
--- a/hw/arm/Kconfig
401
+++ b/include/standard-headers/linux/virtio_pmem.h
406
+++ b/hw/arm/Kconfig
402
@@ -XXX,XX +XXX,XX @@
407
@@ -XXX,XX +XXX,XX @@ config SBSA_REF
403
-/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
408
select PL031 # RTC
404
+/* SPDX-License-Identifier: (GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause */
409
select PL061 # GPIO
405
/*
410
select USB_EHCI_SYSBUS
406
* Definitions for virtio-pmem devices.
411
+ select WDT_SBSA
407
*
412
408
@@ -XXX,XX +XXX,XX @@
413
config SABRELITE
409
* Author(s): Pankaj Gupta <pagupta@redhat.com>
414
bool
410
*/
415
diff --git a/hw/watchdog/Kconfig b/hw/watchdog/Kconfig
411
412
-#ifndef _UAPI_LINUX_VIRTIO_PMEM_H
413
-#define _UAPI_LINUX_VIRTIO_PMEM_H
414
+#ifndef _LINUX_VIRTIO_PMEM_H
415
+#define _LINUX_VIRTIO_PMEM_H
416
417
#include "standard-headers/linux/types.h"
418
#include "standard-headers/linux/virtio_ids.h"
419
diff --git a/linux-headers/asm-arm/kvm.h b/linux-headers/asm-arm/kvm.h
420
index XXXXXXX..XXXXXXX 100644
416
index XXXXXXX..XXXXXXX 100644
421
--- a/linux-headers/asm-arm/kvm.h
417
--- a/hw/watchdog/Kconfig
422
+++ b/linux-headers/asm-arm/kvm.h
418
+++ b/hw/watchdog/Kconfig
423
@@ -XXX,XX +XXX,XX @@ struct kvm_vcpu_events {
419
@@ -XXX,XX +XXX,XX @@ config WDT_DIAG288
424
#define KVM_REG_ARM_FW_REG(r)        (KVM_REG_ARM | KVM_REG_SIZE_U64 | \
420
425
                     KVM_REG_ARM_FW | ((r) & 0xffff))
421
config WDT_IMX2
426
#define KVM_REG_ARM_PSCI_VERSION    KVM_REG_ARM_FW_REG(0)
422
bool
427
+#define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1    KVM_REG_ARM_FW_REG(1)
423
+
428
+    /* Higher values mean better protection. */
424
+config WDT_SBSA
429
+#define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1_NOT_AVAIL        0
425
+ bool
430
+#define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1_AVAIL        1
426
diff --git a/hw/watchdog/meson.build b/hw/watchdog/meson.build
431
+#define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1_NOT_REQUIRED    2
432
+#define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2    KVM_REG_ARM_FW_REG(2)
433
+    /* Higher values mean better protection. */
434
+#define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_NOT_AVAIL        0
435
+#define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_UNKNOWN        1
436
+#define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_AVAIL        2
437
+#define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_NOT_REQUIRED    3
438
+#define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_ENABLED    (1U << 4)
439
440
/* Device Control API: ARM VGIC */
441
#define KVM_DEV_ARM_VGIC_GRP_ADDR    0
442
@@ -XXX,XX +XXX,XX @@ struct kvm_vcpu_events {
443
#define KVM_DEV_ARM_ITS_CTRL_RESET        4
444
445
/* KVM_IRQ_LINE irq field index values */
446
+#define KVM_ARM_IRQ_VCPU2_SHIFT        28
447
+#define KVM_ARM_IRQ_VCPU2_MASK        0xf
448
#define KVM_ARM_IRQ_TYPE_SHIFT        24
449
-#define KVM_ARM_IRQ_TYPE_MASK        0xff
450
+#define KVM_ARM_IRQ_TYPE_MASK        0xf
451
#define KVM_ARM_IRQ_VCPU_SHIFT        16
452
#define KVM_ARM_IRQ_VCPU_MASK        0xff
453
#define KVM_ARM_IRQ_NUM_SHIFT        0
454
diff --git a/linux-headers/asm-arm/unistd-common.h b/linux-headers/asm-arm/unistd-common.h
455
index XXXXXXX..XXXXXXX 100644
427
index XXXXXXX..XXXXXXX 100644
456
--- a/linux-headers/asm-arm/unistd-common.h
428
--- a/hw/watchdog/meson.build
457
+++ b/linux-headers/asm-arm/unistd-common.h
429
+++ b/hw/watchdog/meson.build
458
@@ -XXX,XX +XXX,XX @@
430
@@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_WDT_IB700', if_true: files('wdt_ib700.c'))
459
#define __NR_fsconfig (__NR_SYSCALL_BASE + 431)
431
softmmu_ss.add(when: 'CONFIG_WDT_DIAG288', if_true: files('wdt_diag288.c'))
460
#define __NR_fsmount (__NR_SYSCALL_BASE + 432)
432
softmmu_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('wdt_aspeed.c'))
461
#define __NR_fspick (__NR_SYSCALL_BASE + 433)
433
softmmu_ss.add(when: 'CONFIG_WDT_IMX2', if_true: files('wdt_imx2.c'))
462
+#define __NR_pidfd_open (__NR_SYSCALL_BASE + 434)
434
+softmmu_ss.add(when: 'CONFIG_WDT_SBSA', if_true: files('sbsa_gwdt.c'))
463
+#define __NR_clone3 (__NR_SYSCALL_BASE + 435)
464
465
#endif /* _ASM_ARM_UNISTD_COMMON_H */
466
diff --git a/linux-headers/asm-arm64/kvm.h b/linux-headers/asm-arm64/kvm.h
467
index XXXXXXX..XXXXXXX 100644
468
--- a/linux-headers/asm-arm64/kvm.h
469
+++ b/linux-headers/asm-arm64/kvm.h
470
@@ -XXX,XX +XXX,XX @@ struct kvm_vcpu_events {
471
#define KVM_REG_ARM_FW_REG(r)        (KVM_REG_ARM64 | KVM_REG_SIZE_U64 | \
472
                     KVM_REG_ARM_FW | ((r) & 0xffff))
473
#define KVM_REG_ARM_PSCI_VERSION    KVM_REG_ARM_FW_REG(0)
474
+#define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1    KVM_REG_ARM_FW_REG(1)
475
+#define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1_NOT_AVAIL        0
476
+#define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1_AVAIL        1
477
+#define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1_NOT_REQUIRED    2
478
+#define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2    KVM_REG_ARM_FW_REG(2)
479
+#define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_NOT_AVAIL        0
480
+#define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_UNKNOWN        1
481
+#define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_AVAIL        2
482
+#define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_NOT_REQUIRED    3
483
+#define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_ENABLED     (1U << 4)
484
485
/* SVE registers */
486
#define KVM_REG_ARM64_SVE        (0x15 << KVM_REG_ARM_COPROC_SHIFT)
487
@@ -XXX,XX +XXX,XX @@ struct kvm_vcpu_events {
488
     KVM_REG_SIZE_U256 |                        \
489
     ((i) & (KVM_ARM64_SVE_MAX_SLICES - 1)))
490
491
+/*
492
+ * Register values for KVM_REG_ARM64_SVE_ZREG(), KVM_REG_ARM64_SVE_PREG() and
493
+ * KVM_REG_ARM64_SVE_FFR() are represented in memory in an endianness-
494
+ * invariant layout which differs from the layout used for the FPSIMD
495
+ * V-registers on big-endian systems: see sigcontext.h for more explanation.
496
+ */
497
+
498
#define KVM_ARM64_SVE_VQ_MIN __SVE_VQ_MIN
499
#define KVM_ARM64_SVE_VQ_MAX __SVE_VQ_MAX
500
501
@@ -XXX,XX +XXX,XX @@ struct kvm_vcpu_events {
502
#define KVM_ARM_VCPU_TIMER_IRQ_PTIMER        1
503
504
/* KVM_IRQ_LINE irq field index values */
505
+#define KVM_ARM_IRQ_VCPU2_SHIFT        28
506
+#define KVM_ARM_IRQ_VCPU2_MASK        0xf
507
#define KVM_ARM_IRQ_TYPE_SHIFT        24
508
-#define KVM_ARM_IRQ_TYPE_MASK        0xff
509
+#define KVM_ARM_IRQ_TYPE_MASK        0xf
510
#define KVM_ARM_IRQ_VCPU_SHIFT        16
511
#define KVM_ARM_IRQ_VCPU_MASK        0xff
512
#define KVM_ARM_IRQ_NUM_SHIFT        0
513
diff --git a/linux-headers/asm-generic/mman-common.h b/linux-headers/asm-generic/mman-common.h
514
index XXXXXXX..XXXXXXX 100644
515
--- a/linux-headers/asm-generic/mman-common.h
516
+++ b/linux-headers/asm-generic/mman-common.h
517
@@ -XXX,XX +XXX,XX @@
518
#define MAP_TYPE    0x0f        /* Mask for type of mapping */
519
#define MAP_FIXED    0x10        /* Interpret addr exactly */
520
#define MAP_ANONYMOUS    0x20        /* don't use a file */
521
-#ifdef CONFIG_MMAP_ALLOW_UNINITIALIZED
522
-# define MAP_UNINITIALIZED 0x4000000    /* For anonymous mmap, memory could be uninitialized */
523
-#else
524
-# define MAP_UNINITIALIZED 0x0        /* Don't support this flag */
525
-#endif
526
527
-/* 0x0100 - 0x80000 flags are defined in asm-generic/mman.h */
528
+/* 0x0100 - 0x4000 flags are defined in asm-generic/mman.h */
529
+#define MAP_POPULATE        0x008000    /* populate (prefault) pagetables */
530
+#define MAP_NONBLOCK        0x010000    /* do not block on IO */
531
+#define MAP_STACK        0x020000    /* give out an address that is best suited for process/thread stacks */
532
+#define MAP_HUGETLB        0x040000    /* create a huge page mapping */
533
+#define MAP_SYNC        0x080000 /* perform synchronous page faults for the mapping */
534
#define MAP_FIXED_NOREPLACE    0x100000    /* MAP_FIXED which doesn't unmap underlying mapping */
535
536
+#define MAP_UNINITIALIZED 0x4000000    /* For anonymous mmap, memory could be
537
+                     * uninitialized */
538
+
539
/*
540
* Flags for mlock
541
*/
542
@@ -XXX,XX +XXX,XX @@
543
#define MADV_WIPEONFORK 18        /* Zero memory on fork, child only */
544
#define MADV_KEEPONFORK 19        /* Undo MADV_WIPEONFORK */
545
546
+#define MADV_COLD    20        /* deactivate these pages */
547
+#define MADV_PAGEOUT    21        /* reclaim these pages */
548
+
549
/* compatibility flags */
550
#define MAP_FILE    0
551
552
diff --git a/linux-headers/asm-generic/mman.h b/linux-headers/asm-generic/mman.h
553
index XXXXXXX..XXXXXXX 100644
554
--- a/linux-headers/asm-generic/mman.h
555
+++ b/linux-headers/asm-generic/mman.h
556
@@ -XXX,XX +XXX,XX @@
557
#define MAP_EXECUTABLE    0x1000        /* mark it as an executable */
558
#define MAP_LOCKED    0x2000        /* pages are locked */
559
#define MAP_NORESERVE    0x4000        /* don't check for reservations */
560
-#define MAP_POPULATE    0x8000        /* populate (prefault) pagetables */
561
-#define MAP_NONBLOCK    0x10000        /* do not block on IO */
562
-#define MAP_STACK    0x20000        /* give out an address that is best suited for process/thread stacks */
563
-#define MAP_HUGETLB    0x40000        /* create a huge page mapping */
564
-#define MAP_SYNC    0x80000        /* perform synchronous page faults for the mapping */
565
566
-/* Bits [26:31] are reserved, see mman-common.h for MAP_HUGETLB usage */
567
+/*
568
+ * Bits [26:31] are reserved, see asm-generic/hugetlb_encode.h
569
+ * for MAP_HUGETLB usage
570
+ */
571
572
#define MCL_CURRENT    1        /* lock all current mappings */
573
#define MCL_FUTURE    2        /* lock all future mappings */
574
diff --git a/linux-headers/asm-generic/unistd.h b/linux-headers/asm-generic/unistd.h
575
index XXXXXXX..XXXXXXX 100644
576
--- a/linux-headers/asm-generic/unistd.h
577
+++ b/linux-headers/asm-generic/unistd.h
578
@@ -XXX,XX +XXX,XX @@ __SYSCALL(__NR_semget, sys_semget)
579
__SC_COMP(__NR_semctl, sys_semctl, compat_sys_semctl)
580
#if defined(__ARCH_WANT_TIME32_SYSCALLS) || __BITS_PER_LONG != 32
581
#define __NR_semtimedop 192
582
-__SC_COMP(__NR_semtimedop, sys_semtimedop, sys_semtimedop_time32)
583
+__SC_3264(__NR_semtimedop, sys_semtimedop_time32, sys_semtimedop)
584
#endif
585
#define __NR_semop 193
586
__SYSCALL(__NR_semop, sys_semop)
587
@@ -XXX,XX +XXX,XX @@ __SYSCALL(__NR_fsconfig, sys_fsconfig)
588
__SYSCALL(__NR_fsmount, sys_fsmount)
589
#define __NR_fspick 433
590
__SYSCALL(__NR_fspick, sys_fspick)
591
+#define __NR_pidfd_open 434
592
+__SYSCALL(__NR_pidfd_open, sys_pidfd_open)
593
+#ifdef __ARCH_WANT_SYS_CLONE3
594
+#define __NR_clone3 435
595
+__SYSCALL(__NR_clone3, sys_clone3)
596
+#endif
597
598
#undef __NR_syscalls
599
-#define __NR_syscalls 434
600
+#define __NR_syscalls 436
601
602
/*
603
* 32 bit systems traditionally used different
604
diff --git a/linux-headers/asm-mips/mman.h b/linux-headers/asm-mips/mman.h
605
index XXXXXXX..XXXXXXX 100644
606
--- a/linux-headers/asm-mips/mman.h
607
+++ b/linux-headers/asm-mips/mman.h
608
@@ -XXX,XX +XXX,XX @@
609
#define MADV_WIPEONFORK 18        /* Zero memory on fork, child only */
610
#define MADV_KEEPONFORK 19        /* Undo MADV_WIPEONFORK */
611
612
+#define MADV_COLD    20        /* deactivate these pages */
613
+#define MADV_PAGEOUT    21        /* reclaim these pages */
614
+
615
/* compatibility flags */
616
#define MAP_FILE    0
617
618
diff --git a/linux-headers/asm-mips/unistd_n32.h b/linux-headers/asm-mips/unistd_n32.h
619
index XXXXXXX..XXXXXXX 100644
620
--- a/linux-headers/asm-mips/unistd_n32.h
621
+++ b/linux-headers/asm-mips/unistd_n32.h
622
@@ -XXX,XX +XXX,XX @@
623
#define __NR_fsconfig    (__NR_Linux + 431)
624
#define __NR_fsmount    (__NR_Linux + 432)
625
#define __NR_fspick    (__NR_Linux + 433)
626
+#define __NR_pidfd_open    (__NR_Linux + 434)
627
628
629
#endif /* _ASM_MIPS_UNISTD_N32_H */
630
diff --git a/linux-headers/asm-mips/unistd_n64.h b/linux-headers/asm-mips/unistd_n64.h
631
index XXXXXXX..XXXXXXX 100644
632
--- a/linux-headers/asm-mips/unistd_n64.h
633
+++ b/linux-headers/asm-mips/unistd_n64.h
634
@@ -XXX,XX +XXX,XX @@
635
#define __NR_fsconfig    (__NR_Linux + 431)
636
#define __NR_fsmount    (__NR_Linux + 432)
637
#define __NR_fspick    (__NR_Linux + 433)
638
+#define __NR_pidfd_open    (__NR_Linux + 434)
639
640
641
#endif /* _ASM_MIPS_UNISTD_N64_H */
642
diff --git a/linux-headers/asm-mips/unistd_o32.h b/linux-headers/asm-mips/unistd_o32.h
643
index XXXXXXX..XXXXXXX 100644
644
--- a/linux-headers/asm-mips/unistd_o32.h
645
+++ b/linux-headers/asm-mips/unistd_o32.h
646
@@ -XXX,XX +XXX,XX @@
647
#define __NR_fsconfig    (__NR_Linux + 431)
648
#define __NR_fsmount    (__NR_Linux + 432)
649
#define __NR_fspick    (__NR_Linux + 433)
650
+#define __NR_pidfd_open    (__NR_Linux + 434)
651
652
653
#endif /* _ASM_MIPS_UNISTD_O32_H */
654
diff --git a/linux-headers/asm-powerpc/mman.h b/linux-headers/asm-powerpc/mman.h
655
index XXXXXXX..XXXXXXX 100644
656
--- a/linux-headers/asm-powerpc/mman.h
657
+++ b/linux-headers/asm-powerpc/mman.h
658
@@ -XXX,XX +XXX,XX @@
659
#define MAP_DENYWRITE    0x0800        /* ETXTBSY */
660
#define MAP_EXECUTABLE    0x1000        /* mark it as an executable */
661
662
+
663
#define MCL_CURRENT 0x2000 /* lock all currently mapped pages */
664
#define MCL_FUTURE 0x4000 /* lock all additions to address space */
665
#define MCL_ONFAULT    0x8000        /* lock all pages that are faulted in */
666
667
-#define MAP_POPULATE    0x8000        /* populate (prefault) pagetables */
668
-#define MAP_NONBLOCK    0x10000        /* do not block on IO */
669
-#define MAP_STACK    0x20000        /* give out an address that is best suited for process/thread stacks */
670
-#define MAP_HUGETLB    0x40000        /* create a huge page mapping */
671
-
672
/* Override any generic PKEY permission defines */
673
#define PKEY_DISABLE_EXECUTE 0x4
674
#undef PKEY_ACCESS_MASK
675
diff --git a/linux-headers/asm-powerpc/unistd_32.h b/linux-headers/asm-powerpc/unistd_32.h
676
index XXXXXXX..XXXXXXX 100644
677
--- a/linux-headers/asm-powerpc/unistd_32.h
678
+++ b/linux-headers/asm-powerpc/unistd_32.h
679
@@ -XXX,XX +XXX,XX @@
680
#define __NR_fsconfig    431
681
#define __NR_fsmount    432
682
#define __NR_fspick    433
683
+#define __NR_pidfd_open    434
684
+#define __NR_clone3    435
685
686
687
#endif /* _ASM_POWERPC_UNISTD_32_H */
688
diff --git a/linux-headers/asm-powerpc/unistd_64.h b/linux-headers/asm-powerpc/unistd_64.h
689
index XXXXXXX..XXXXXXX 100644
690
--- a/linux-headers/asm-powerpc/unistd_64.h
691
+++ b/linux-headers/asm-powerpc/unistd_64.h
692
@@ -XXX,XX +XXX,XX @@
693
#define __NR_fsconfig    431
694
#define __NR_fsmount    432
695
#define __NR_fspick    433
696
+#define __NR_pidfd_open    434
697
+#define __NR_clone3    435
698
699
700
#endif /* _ASM_POWERPC_UNISTD_64_H */
701
diff --git a/linux-headers/asm-s390/kvm.h b/linux-headers/asm-s390/kvm.h
702
index XXXXXXX..XXXXXXX 100644
703
--- a/linux-headers/asm-s390/kvm.h
704
+++ b/linux-headers/asm-s390/kvm.h
705
@@ -XXX,XX +XXX,XX @@ struct kvm_guest_debug_arch {
706
#define KVM_SYNC_GSCB (1UL << 9)
707
#define KVM_SYNC_BPBC (1UL << 10)
708
#define KVM_SYNC_ETOKEN (1UL << 11)
709
+
710
+#define KVM_SYNC_S390_VALID_FIELDS \
711
+    (KVM_SYNC_PREFIX | KVM_SYNC_GPRS | KVM_SYNC_ACRS | KVM_SYNC_CRS | \
712
+     KVM_SYNC_ARCH0 | KVM_SYNC_PFAULT | KVM_SYNC_VRS | KVM_SYNC_RICCB | \
713
+     KVM_SYNC_FPRS | KVM_SYNC_GSCB | KVM_SYNC_BPBC | KVM_SYNC_ETOKEN)
714
+
715
/* length and alignment of the sdnx as a power of two */
716
#define SDNXC 8
717
#define SDNXL (1UL << SDNXC)
718
diff --git a/linux-headers/asm-s390/unistd_32.h b/linux-headers/asm-s390/unistd_32.h
719
index XXXXXXX..XXXXXXX 100644
720
--- a/linux-headers/asm-s390/unistd_32.h
721
+++ b/linux-headers/asm-s390/unistd_32.h
722
@@ -XXX,XX +XXX,XX @@
723
#define __NR_fsconfig 431
724
#define __NR_fsmount 432
725
#define __NR_fspick 433
726
+#define __NR_pidfd_open 434
727
+#define __NR_clone3 435
728
729
#endif /* _ASM_S390_UNISTD_32_H */
730
diff --git a/linux-headers/asm-s390/unistd_64.h b/linux-headers/asm-s390/unistd_64.h
731
index XXXXXXX..XXXXXXX 100644
732
--- a/linux-headers/asm-s390/unistd_64.h
733
+++ b/linux-headers/asm-s390/unistd_64.h
734
@@ -XXX,XX +XXX,XX @@
735
#define __NR_fsconfig 431
736
#define __NR_fsmount 432
737
#define __NR_fspick 433
738
+#define __NR_pidfd_open 434
739
+#define __NR_clone3 435
740
741
#endif /* _ASM_S390_UNISTD_64_H */
742
diff --git a/linux-headers/asm-x86/kvm.h b/linux-headers/asm-x86/kvm.h
743
index XXXXXXX..XXXXXXX 100644
744
--- a/linux-headers/asm-x86/kvm.h
745
+++ b/linux-headers/asm-x86/kvm.h
746
@@ -XXX,XX +XXX,XX @@ struct kvm_sync_regs {
747
    struct kvm_vcpu_events events;
748
};
749
750
-#define KVM_X86_QUIRK_LINT0_REENABLED    (1 << 0)
751
-#define KVM_X86_QUIRK_CD_NW_CLEARED    (1 << 1)
752
-#define KVM_X86_QUIRK_LAPIC_MMIO_HOLE    (1 << 2)
753
-#define KVM_X86_QUIRK_OUT_7E_INC_RIP    (1 << 3)
754
+#define KVM_X86_QUIRK_LINT0_REENABLED     (1 << 0)
755
+#define KVM_X86_QUIRK_CD_NW_CLEARED     (1 << 1)
756
+#define KVM_X86_QUIRK_LAPIC_MMIO_HOLE     (1 << 2)
757
+#define KVM_X86_QUIRK_OUT_7E_INC_RIP     (1 << 3)
758
+#define KVM_X86_QUIRK_MISC_ENABLE_NO_MWAIT (1 << 4)
759
760
#define KVM_STATE_NESTED_FORMAT_VMX    0
761
-#define KVM_STATE_NESTED_FORMAT_SVM    1
762
+#define KVM_STATE_NESTED_FORMAT_SVM    1    /* unused */
763
764
#define KVM_STATE_NESTED_GUEST_MODE    0x00000001
765
#define KVM_STATE_NESTED_RUN_PENDING    0x00000002
766
#define KVM_STATE_NESTED_EVMCS        0x00000004
767
768
-#define KVM_STATE_NESTED_VMX_VMCS_SIZE    0x1000
769
-
770
#define KVM_STATE_NESTED_SMM_GUEST_MODE    0x00000001
771
#define KVM_STATE_NESTED_SMM_VMXON    0x00000002
772
773
+#define KVM_STATE_NESTED_VMX_VMCS_SIZE    0x1000
774
+
775
struct kvm_vmx_nested_state_data {
776
    __u8 vmcs12[KVM_STATE_NESTED_VMX_VMCS_SIZE];
777
    __u8 shadow_vmcs12[KVM_STATE_NESTED_VMX_VMCS_SIZE];
778
@@ -XXX,XX +XXX,XX @@ struct kvm_nested_state {
779
    } data;
780
};
781
782
+/* for KVM_CAP_PMU_EVENT_FILTER */
783
+struct kvm_pmu_event_filter {
784
+    __u32 action;
785
+    __u32 nevents;
786
+    __u32 fixed_counter_bitmap;
787
+    __u32 flags;
788
+    __u32 pad[4];
789
+    __u64 events[0];
790
+};
791
+
792
+#define KVM_PMU_EVENT_ALLOW 0
793
+#define KVM_PMU_EVENT_DENY 1
794
+
795
#endif /* _ASM_X86_KVM_H */
796
diff --git a/linux-headers/asm-x86/unistd.h b/linux-headers/asm-x86/unistd.h
797
index XXXXXXX..XXXXXXX 100644
798
--- a/linux-headers/asm-x86/unistd.h
799
+++ b/linux-headers/asm-x86/unistd.h
800
@@ -XXX,XX +XXX,XX @@
801
#define _ASM_X86_UNISTD_H
802
803
/* x32 syscall flag bit */
804
-#define __X32_SYSCALL_BIT    0x40000000
805
+#define __X32_SYSCALL_BIT    0x40000000UL
806
807
# ifdef __i386__
808
# include <asm/unistd_32.h>
809
diff --git a/linux-headers/asm-x86/unistd_32.h b/linux-headers/asm-x86/unistd_32.h
810
index XXXXXXX..XXXXXXX 100644
811
--- a/linux-headers/asm-x86/unistd_32.h
812
+++ b/linux-headers/asm-x86/unistd_32.h
813
@@ -XXX,XX +XXX,XX @@
814
#define __NR_fsconfig 431
815
#define __NR_fsmount 432
816
#define __NR_fspick 433
817
+#define __NR_pidfd_open 434
818
+#define __NR_clone3 435
819
820
#endif /* _ASM_X86_UNISTD_32_H */
821
diff --git a/linux-headers/asm-x86/unistd_64.h b/linux-headers/asm-x86/unistd_64.h
822
index XXXXXXX..XXXXXXX 100644
823
--- a/linux-headers/asm-x86/unistd_64.h
824
+++ b/linux-headers/asm-x86/unistd_64.h
825
@@ -XXX,XX +XXX,XX @@
826
#define __NR_fsconfig 431
827
#define __NR_fsmount 432
828
#define __NR_fspick 433
829
+#define __NR_pidfd_open 434
830
+#define __NR_clone3 435
831
832
#endif /* _ASM_X86_UNISTD_64_H */
833
diff --git a/linux-headers/asm-x86/unistd_x32.h b/linux-headers/asm-x86/unistd_x32.h
834
index XXXXXXX..XXXXXXX 100644
835
--- a/linux-headers/asm-x86/unistd_x32.h
836
+++ b/linux-headers/asm-x86/unistd_x32.h
837
@@ -XXX,XX +XXX,XX @@
838
#define __NR_fsconfig (__X32_SYSCALL_BIT + 431)
839
#define __NR_fsmount (__X32_SYSCALL_BIT + 432)
840
#define __NR_fspick (__X32_SYSCALL_BIT + 433)
841
+#define __NR_pidfd_open (__X32_SYSCALL_BIT + 434)
842
+#define __NR_clone3 (__X32_SYSCALL_BIT + 435)
843
#define __NR_rt_sigaction (__X32_SYSCALL_BIT + 512)
844
#define __NR_rt_sigreturn (__X32_SYSCALL_BIT + 513)
845
#define __NR_ioctl (__X32_SYSCALL_BIT + 514)
846
diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h
847
index XXXXXXX..XXXXXXX 100644
848
--- a/linux-headers/linux/kvm.h
849
+++ b/linux-headers/linux/kvm.h
850
@@ -XXX,XX +XXX,XX @@ struct kvm_irq_level {
851
     * ACPI gsi notion of irq.
852
     * For IA-64 (APIC model) IOAPIC0: irq 0-23; IOAPIC1: irq 24-47..
853
     * For X86 (standard AT mode) PIC0/1: irq 0-15. IOAPIC0: 0-23..
854
-     * For ARM: See Documentation/virtual/kvm/api.txt
855
+     * For ARM: See Documentation/virt/kvm/api.txt
856
     */
857
    union {
858
        __u32 irq;
859
@@ -XXX,XX +XXX,XX @@ struct kvm_hyperv_exit {
860
#define KVM_INTERNAL_ERROR_SIMUL_EX    2
861
/* Encounter unexpected vm-exit due to delivery event. */
862
#define KVM_INTERNAL_ERROR_DELIVERY_EV    3
863
+/* Encounter unexpected vm-exit reason */
864
+#define KVM_INTERNAL_ERROR_UNEXPECTED_EXIT_REASON    4
865
866
/* for KVM_RUN, returned by mmap(vcpu_fd, offset=0) */
867
struct kvm_run {
868
@@ -XXX,XX +XXX,XX @@ struct kvm_ppc_resize_hpt {
869
#define KVM_CAP_ARM_SVE 170
870
#define KVM_CAP_ARM_PTRAUTH_ADDRESS 171
871
#define KVM_CAP_ARM_PTRAUTH_GENERIC 172
872
+#define KVM_CAP_PMU_EVENT_FILTER 173
873
+#define KVM_CAP_ARM_IRQ_LINE_LAYOUT_2 174
874
+#define KVM_CAP_HYPERV_DIRECT_TLBFLUSH 175
875
876
#ifdef KVM_CAP_IRQ_ROUTING
877
878
@@ -XXX,XX +XXX,XX @@ struct kvm_xen_hvm_config {
879
*
880
* KVM_IRQFD_FLAG_RESAMPLE indicates resamplefd is valid and specifies
881
* the irqfd to operate in resampling mode for level triggered interrupt
882
- * emulation. See Documentation/virtual/kvm/api.txt.
883
+ * emulation. See Documentation/virt/kvm/api.txt.
884
*/
885
#define KVM_IRQFD_FLAG_RESAMPLE (1 << 1)
886
887
@@ -XXX,XX +XXX,XX @@ struct kvm_dirty_tlb {
888
#define KVM_REG_S390        0x5000000000000000ULL
889
#define KVM_REG_ARM64        0x6000000000000000ULL
890
#define KVM_REG_MIPS        0x7000000000000000ULL
891
+#define KVM_REG_RISCV        0x8000000000000000ULL
892
893
#define KVM_REG_SIZE_SHIFT    52
894
#define KVM_REG_SIZE_MASK    0x00f0000000000000ULL
895
@@ -XXX,XX +XXX,XX @@ struct kvm_s390_ucas_mapping {
896
#define KVM_PPC_GET_RMMU_INFO     _IOW(KVMIO, 0xb0, struct kvm_ppc_rmmu_info)
897
/* Available with KVM_CAP_PPC_GET_CPU_CHAR */
898
#define KVM_PPC_GET_CPU_CHAR     _IOR(KVMIO, 0xb1, struct kvm_ppc_cpu_char)
899
+/* Available with KVM_CAP_PMU_EVENT_FILTER */
900
+#define KVM_SET_PMU_EVENT_FILTER _IOW(KVMIO, 0xb2, struct kvm_pmu_event_filter)
901
902
/* ioctl for vm fd */
903
#define KVM_CREATE_DEVICE     _IOWR(KVMIO, 0xe0, struct kvm_create_device)
904
diff --git a/linux-headers/linux/psp-sev.h b/linux-headers/linux/psp-sev.h
905
index XXXXXXX..XXXXXXX 100644
906
--- a/linux-headers/linux/psp-sev.h
907
+++ b/linux-headers/linux/psp-sev.h
908
@@ -XXX,XX +XXX,XX @@
909
+/* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */
910
/*
911
* Userspace interface for AMD Secure Encrypted Virtualization (SEV)
912
* platform management commands.
913
@@ -XXX,XX +XXX,XX @@
914
* Author: Brijesh Singh <brijesh.singh@amd.com>
915
*
916
* SEV API specification is available at: https://developer.amd.com/sev/
917
- *
918
- * This program is free software; you can redistribute it and/or modify
919
- * it under the terms of the GNU General Public License version 2 as
920
- * published by the Free Software Foundation.
921
*/
922
923
#ifndef __PSP_SEV_USER_H__
924
diff --git a/linux-headers/linux/vfio.h b/linux-headers/linux/vfio.h
925
index XXXXXXX..XXXXXXX 100644
926
--- a/linux-headers/linux/vfio.h
927
+++ b/linux-headers/linux/vfio.h
928
@@ -XXX,XX +XXX,XX @@ struct vfio_region_info_cap_type {
929
    __u32 subtype;    /* type specific */
930
};
931
932
+/*
933
+ * List of region types, global per bus driver.
934
+ * If you introduce a new type, please add it here.
935
+ */
936
+
937
+/* PCI region type containing a PCI vendor part */
938
#define VFIO_REGION_TYPE_PCI_VENDOR_TYPE    (1 << 31)
939
#define VFIO_REGION_TYPE_PCI_VENDOR_MASK    (0xffff)
940
+#define VFIO_REGION_TYPE_GFX (1)
941
+#define VFIO_REGION_TYPE_CCW            (2)
942
943
-/* 8086 Vendor sub-types */
944
+/* sub-types for VFIO_REGION_TYPE_PCI_* */
945
+
946
+/* 8086 vendor PCI sub-types */
947
#define VFIO_REGION_SUBTYPE_INTEL_IGD_OPREGION    (1)
948
#define VFIO_REGION_SUBTYPE_INTEL_IGD_HOST_CFG    (2)
949
#define VFIO_REGION_SUBTYPE_INTEL_IGD_LPC_CFG    (3)
950
951
-#define VFIO_REGION_TYPE_GFX (1)
952
+/* 10de vendor PCI sub-types */
953
+/*
954
+ * NVIDIA GPU NVlink2 RAM is coherent RAM mapped onto the host address space.
955
+ */
956
+#define VFIO_REGION_SUBTYPE_NVIDIA_NVLINK2_RAM    (1)
957
+
958
+/* 1014 vendor PCI sub-types */
959
+/*
960
+ * IBM NPU NVlink2 ATSD (Address Translation Shootdown) register of NPU
961
+ * to do TLB invalidation on a GPU.
962
+ */
963
+#define VFIO_REGION_SUBTYPE_IBM_NVLINK2_ATSD    (1)
964
+
965
+/* sub-types for VFIO_REGION_TYPE_GFX */
966
#define VFIO_REGION_SUBTYPE_GFX_EDID (1)
967
968
/**
969
@@ -XXX,XX +XXX,XX @@ struct vfio_region_gfx_edid {
970
#define VFIO_DEVICE_GFX_LINK_STATE_DOWN 2
971
};
972
973
-#define VFIO_REGION_TYPE_CCW            (2)
974
-/* ccw sub-types */
975
+/* sub-types for VFIO_REGION_TYPE_CCW */
976
#define VFIO_REGION_SUBTYPE_CCW_ASYNC_CMD    (1)
977
978
-/*
979
- * 10de vendor sub-type
980
- *
981
- * NVIDIA GPU NVlink2 RAM is coherent RAM mapped onto the host address space.
982
- */
983
-#define VFIO_REGION_SUBTYPE_NVIDIA_NVLINK2_RAM    (1)
984
-
985
-/*
986
- * 1014 vendor sub-type
987
- *
988
- * IBM NPU NVlink2 ATSD (Address Translation Shootdown) register of NPU
989
- * to do TLB invalidation on a GPU.
990
- */
991
-#define VFIO_REGION_SUBTYPE_IBM_NVLINK2_ATSD    (1)
992
-
993
/*
994
* The MSIX mappable capability informs that MSIX data of a BAR can be mmapped
995
* which allows direct access to non-MSIX registers which happened to be within
996
@@ -XXX,XX +XXX,XX @@ struct vfio_iommu_type1_info {
997
    __u32    argsz;
998
    __u32    flags;
999
#define VFIO_IOMMU_INFO_PGSIZES (1 << 0)    /* supported page sizes info */
1000
-    __u64    iova_pgsizes;        /* Bitmap of supported page sizes */
1001
+#define VFIO_IOMMU_INFO_CAPS    (1 << 1)    /* Info supports caps */
1002
+    __u64    iova_pgsizes;    /* Bitmap of supported page sizes */
1003
+    __u32 cap_offset;    /* Offset within info struct of first cap */
1004
+};
1005
+
1006
+/*
1007
+ * The IOVA capability allows to report the valid IOVA range(s)
1008
+ * excluding any non-relaxable reserved regions exposed by
1009
+ * devices attached to the container. Any DMA map attempt
1010
+ * outside the valid iova range will return error.
1011
+ *
1012
+ * The structures below define version 1 of this capability.
1013
+ */
1014
+#define VFIO_IOMMU_TYPE1_INFO_CAP_IOVA_RANGE 1
1015
+
1016
+struct vfio_iova_range {
1017
+    __u64    start;
1018
+    __u64    end;
1019
+};
1020
+
1021
+struct vfio_iommu_type1_info_cap_iova_range {
1022
+    struct    vfio_info_cap_header header;
1023
+    __u32    nr_iovas;
1024
+    __u32    reserved;
1025
+    struct    vfio_iova_range iova_ranges[];
1026
};
1027
1028
#define VFIO_IOMMU_GET_INFO _IO(VFIO_TYPE, VFIO_BASE + 12)
1029
--
435
--
1030
2.20.1
436
2.20.1
1031
437
1032
438
diff view generated by jsdifflib
1
From: Eric Auger <eric.auger@redhat.com>
1
From: Shashi Mallela <shashi.mallela@linaro.org>
2
2
3
Host kernels that expose the KVM_CAP_ARM_IRQ_LINE_LAYOUT_2 capability
3
Included the newly implemented SBSA generic watchdog device model into
4
allow injection of interrupts along with vcpu ids larger than 255.
4
SBSA platform
5
Let's encode the vpcu id on 12 bits according to the upgraded KVM_IRQ_LINE
6
ABI when needed.
7
5
8
Given that we have two callsites that need to assemble
6
Signed-off-by: Shashi Mallela <shashi.mallela@linaro.org>
9
the value for kvm_set_irq(), a new helper routine, kvm_arm_set_irq
7
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
10
is introduced.
8
Message-id: 20201027015927.29495-3-shashi.mallela@linaro.org
11
12
Without that patch qemu exits with "kvm_set_irq: Invalid argument"
13
message.
14
15
Signed-off-by: Eric Auger <eric.auger@redhat.com>
16
Reported-by: Zenghui Yu <yuzenghui@huawei.com>
17
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
18
Reviewed-by: Andrew Jones <drjones@redhat.com>
19
Acked-by: Marc Zyngier <maz@kernel.org>
20
Message-id: 20191003154640.22451-3-eric.auger@redhat.com
21
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
22
---
10
---
23
target/arm/kvm_arm.h | 1 +
11
hw/arm/sbsa-ref.c | 23 +++++++++++++++++++++++
24
hw/intc/arm_gic_kvm.c | 7 ++-----
12
1 file changed, 23 insertions(+)
25
target/arm/cpu.c | 10 ++++------
26
target/arm/kvm.c | 12 ++++++++++++
27
4 files changed, 19 insertions(+), 11 deletions(-)
28
13
29
diff --git a/target/arm/kvm_arm.h b/target/arm/kvm_arm.h
14
diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c
30
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
31
--- a/target/arm/kvm_arm.h
16
--- a/hw/arm/sbsa-ref.c
32
+++ b/target/arm/kvm_arm.h
17
+++ b/hw/arm/sbsa-ref.c
33
@@ -XXX,XX +XXX,XX @@ int kvm_arm_vgic_probe(void);
18
@@ -XXX,XX +XXX,XX @@
34
19
#include "hw/qdev-properties.h"
35
void kvm_arm_pmu_set_irq(CPUState *cs, int irq);
20
#include "hw/usb.h"
36
void kvm_arm_pmu_init(CPUState *cs);
21
#include "hw/char/pl011.h"
37
+int kvm_arm_set_irq(int cpu, int irqtype, int irq, int level);
22
+#include "hw/watchdog/sbsa_gwdt.h"
38
23
#include "net/net.h"
39
#else
24
#include "qom/object.h"
40
25
41
diff --git a/hw/intc/arm_gic_kvm.c b/hw/intc/arm_gic_kvm.c
26
@@ -XXX,XX +XXX,XX @@ enum {
42
index XXXXXXX..XXXXXXX 100644
27
SBSA_GIC_DIST,
43
--- a/hw/intc/arm_gic_kvm.c
28
SBSA_GIC_REDIST,
44
+++ b/hw/intc/arm_gic_kvm.c
29
SBSA_SECURE_EC,
45
@@ -XXX,XX +XXX,XX @@ void kvm_arm_gic_set_irq(uint32_t num_irq, int irq, int level)
30
+ SBSA_GWDT,
46
* has separate fields in the irq number for type,
31
+ SBSA_GWDT_REFRESH,
47
* CPU number and interrupt number.
32
+ SBSA_GWDT_CONTROL,
48
*/
33
SBSA_SMMU,
49
- int kvm_irq, irqtype, cpu;
34
SBSA_UART,
50
+ int irqtype, cpu;
35
SBSA_RTC,
51
36
@@ -XXX,XX +XXX,XX @@ static const MemMapEntry sbsa_ref_memmap[] = {
52
if (irq < (num_irq - GIC_INTERNAL)) {
37
[SBSA_GIC_DIST] = { 0x40060000, 0x00010000 },
53
/* External interrupt. The kernel numbers these like the GIC
38
[SBSA_GIC_REDIST] = { 0x40080000, 0x04000000 },
54
@@ -XXX,XX +XXX,XX @@ void kvm_arm_gic_set_irq(uint32_t num_irq, int irq, int level)
39
[SBSA_SECURE_EC] = { 0x50000000, 0x00001000 },
55
cpu = irq / GIC_INTERNAL;
40
+ [SBSA_GWDT_REFRESH] = { 0x50010000, 0x00001000 },
56
irq %= GIC_INTERNAL;
41
+ [SBSA_GWDT_CONTROL] = { 0x50011000, 0x00001000 },
57
}
42
[SBSA_UART] = { 0x60000000, 0x00001000 },
58
- kvm_irq = (irqtype << KVM_ARM_IRQ_TYPE_SHIFT)
43
[SBSA_RTC] = { 0x60010000, 0x00001000 },
59
- | (cpu << KVM_ARM_IRQ_VCPU_SHIFT) | irq;
44
[SBSA_GPIO] = { 0x60020000, 0x00001000 },
60
-
45
@@ -XXX,XX +XXX,XX @@ static const int sbsa_ref_irqmap[] = {
61
- kvm_set_irq(kvm_state, kvm_irq, !!level);
46
[SBSA_AHCI] = 10,
62
+ kvm_arm_set_irq(cpu, irqtype, irq, !!level);
47
[SBSA_EHCI] = 11,
48
[SBSA_SMMU] = 12, /* ... to 15 */
49
+ [SBSA_GWDT] = 16,
50
};
51
52
static uint64_t sbsa_ref_cpu_mp_affinity(SBSAMachineState *sms, int idx)
53
@@ -XXX,XX +XXX,XX @@ static void create_rtc(const SBSAMachineState *sms)
54
sysbus_create_simple("pl031", base, qdev_get_gpio_in(sms->gic, irq));
63
}
55
}
64
56
65
static void kvm_arm_gicv2_set_irq(void *opaque, int irq, int level)
57
+static void create_wdt(const SBSAMachineState *sms)
66
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
67
index XXXXXXX..XXXXXXX 100644
68
--- a/target/arm/cpu.c
69
+++ b/target/arm/cpu.c
70
@@ -XXX,XX +XXX,XX @@ static void arm_cpu_kvm_set_irq(void *opaque, int irq, int level)
71
ARMCPU *cpu = opaque;
72
CPUARMState *env = &cpu->env;
73
CPUState *cs = CPU(cpu);
74
- int kvm_irq = KVM_ARM_IRQ_TYPE_CPU << KVM_ARM_IRQ_TYPE_SHIFT;
75
uint32_t linestate_bit;
76
+ int irq_id;
77
78
switch (irq) {
79
case ARM_CPU_IRQ:
80
- kvm_irq |= KVM_ARM_IRQ_CPU_IRQ;
81
+ irq_id = KVM_ARM_IRQ_CPU_IRQ;
82
linestate_bit = CPU_INTERRUPT_HARD;
83
break;
84
case ARM_CPU_FIQ:
85
- kvm_irq |= KVM_ARM_IRQ_CPU_FIQ;
86
+ irq_id = KVM_ARM_IRQ_CPU_FIQ;
87
linestate_bit = CPU_INTERRUPT_FIQ;
88
break;
89
default:
90
@@ -XXX,XX +XXX,XX @@ static void arm_cpu_kvm_set_irq(void *opaque, int irq, int level)
91
} else {
92
env->irq_line_state &= ~linestate_bit;
93
}
94
-
95
- kvm_irq |= cs->cpu_index << KVM_ARM_IRQ_VCPU_SHIFT;
96
- kvm_set_irq(kvm_state, kvm_irq, level ? 1 : 0);
97
+ kvm_arm_set_irq(cs->cpu_index, KVM_ARM_IRQ_TYPE_CPU, irq_id, !!level);
98
#endif
99
}
100
101
diff --git a/target/arm/kvm.c b/target/arm/kvm.c
102
index XXXXXXX..XXXXXXX 100644
103
--- a/target/arm/kvm.c
104
+++ b/target/arm/kvm.c
105
@@ -XXX,XX +XXX,XX @@ int kvm_arm_vgic_probe(void)
106
}
107
}
108
109
+int kvm_arm_set_irq(int cpu, int irqtype, int irq, int level)
110
+{
58
+{
111
+ int kvm_irq = (irqtype << KVM_ARM_IRQ_TYPE_SHIFT) | irq;
59
+ hwaddr rbase = sbsa_ref_memmap[SBSA_GWDT_REFRESH].base;
112
+ int cpu_idx1 = cpu % 256;
60
+ hwaddr cbase = sbsa_ref_memmap[SBSA_GWDT_CONTROL].base;
113
+ int cpu_idx2 = cpu / 256;
61
+ DeviceState *dev = qdev_new(TYPE_WDT_SBSA);
62
+ SysBusDevice *s = SYS_BUS_DEVICE(dev);
63
+ int irq = sbsa_ref_irqmap[SBSA_GWDT];
114
+
64
+
115
+ kvm_irq |= (cpu_idx1 << KVM_ARM_IRQ_VCPU_SHIFT) |
65
+ sysbus_realize_and_unref(s, &error_fatal);
116
+ (cpu_idx2 << KVM_ARM_IRQ_VCPU2_SHIFT);
66
+ sysbus_mmio_map(s, 0, rbase);
117
+
67
+ sysbus_mmio_map(s, 1, cbase);
118
+ return kvm_set_irq(kvm_state, kvm_irq, !!level);
68
+ sysbus_connect_irq(s, 0, qdev_get_gpio_in(sms->gic, irq));
119
+}
69
+}
120
+
70
+
121
int kvm_arch_fixup_msi_route(struct kvm_irq_routing_entry *route,
71
static DeviceState *gpio_key_dev;
122
uint64_t address, uint32_t data, PCIDevice *dev)
72
static void sbsa_ref_powerdown_req(Notifier *n, void *opaque)
123
{
73
{
74
@@ -XXX,XX +XXX,XX @@ static void sbsa_ref_init(MachineState *machine)
75
76
create_rtc(sms);
77
78
+ create_wdt(sms);
79
+
80
create_gpio(sms);
81
82
create_ahci(sms);
124
--
83
--
125
2.20.1
84
2.20.1
126
85
127
86
diff view generated by jsdifflib
1
Provide the new transaction-based API. If a ptimer is created
1
In ptimer_reload(), we call the callback function provided by the
2
using ptimer_init() rather than ptimer_init_with_bh(), then
2
timer device that is using the ptimer. This callback might disable
3
instead of providing a QEMUBH, it provides a pointer to the
3
the ptimer. The code mostly handles this correctly, except that
4
callback function directly, and has opted into the transaction
4
we'll still print the warning about "Timer with delta zero,
5
API. All calls to functions which modify ptimer state:
5
disabling" if the now-disabled timer happened to be set such that it
6
- ptimer_set_period()
6
would fire again immediately if it were enabled (eg because the
7
- ptimer_set_freq()
7
limit/reload value is zero).
8
- ptimer_set_limit()
9
- ptimer_set_count()
10
- ptimer_run()
11
- ptimer_stop()
12
must be between matched calls to ptimer_transaction_begin()
13
and ptimer_transaction_commit(). When ptimer_transaction_commit()
14
is called it will evaluate the state of the timer after all the
15
changes in the transaction, and call the callback if necessary.
16
8
17
In the old API the individual update functions generally would
9
Suppress the spurious warning message and the unnecessary
18
call ptimer_trigger() immediately, which would schedule the QEMUBH.
10
repeat-deletion of the underlying timer in this case.
19
In the new API the update functions will instead defer the
20
"set s->next_event and call ptimer_reload()" work to
21
ptimer_transaction_commit().
22
23
Because ptimer_trigger() can now immediately call into the
24
device code which may then call other ptimer functions that
25
update ptimer_state fields, we must be more careful in
26
ptimer_reload() not to cache fields from ptimer_state across
27
the ptimer_trigger() call. (This was harmless with the QEMUBH
28
mechanism as the BH would not be invoked until much later.)
29
30
We use assertions to check that:
31
* the functions modifying ptimer state are not called outside
32
a transaction block
33
* ptimer_transaction_begin() and _commit() calls are paired
34
* the transaction API is not used with a QEMUBH ptimer
35
36
There is some slight repetition of code:
37
* most of the set functions have similar looking "if s->bh
38
call ptimer_reload, otherwise set s->need_reload" code
39
* ptimer_init() and ptimer_init_with_bh() have similar code
40
We deliberately don't try to avoid this repetition, because
41
it will all be deleted when the QEMUBH version of the API
42
is removed.
43
11
44
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
45
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
13
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
46
Message-id: 20191008171740.9679-3-peter.maydell@linaro.org
14
Message-id: 20201015151829.14656-2-peter.maydell@linaro.org
47
---
15
---
48
include/hw/ptimer.h | 72 +++++++++++++++++++++
16
hw/core/ptimer.c | 4 ++++
49
hw/core/ptimer.c | 152 +++++++++++++++++++++++++++++++++++++++-----
17
1 file changed, 4 insertions(+)
50
2 files changed, 209 insertions(+), 15 deletions(-)
51
18
52
diff --git a/include/hw/ptimer.h b/include/hw/ptimer.h
53
index XXXXXXX..XXXXXXX 100644
54
--- a/include/hw/ptimer.h
55
+++ b/include/hw/ptimer.h
56
@@ -XXX,XX +XXX,XX @@ typedef void (*ptimer_cb)(void *opaque);
57
*/
58
ptimer_state *ptimer_init_with_bh(QEMUBH *bh, uint8_t policy_mask);
59
60
+/**
61
+ * ptimer_init - Allocate and return a new ptimer
62
+ * @callback: function to call on ptimer expiry
63
+ * @callback_opaque: opaque pointer passed to @callback
64
+ * @policy: PTIMER_POLICY_* bits specifying behaviour
65
+ *
66
+ * The ptimer returned must be freed using ptimer_free().
67
+ *
68
+ * If a ptimer is created using this API then will use the
69
+ * transaction-based API for modifying ptimer state: all calls
70
+ * to functions which modify ptimer state:
71
+ * - ptimer_set_period()
72
+ * - ptimer_set_freq()
73
+ * - ptimer_set_limit()
74
+ * - ptimer_set_count()
75
+ * - ptimer_run()
76
+ * - ptimer_stop()
77
+ * must be between matched calls to ptimer_transaction_begin()
78
+ * and ptimer_transaction_commit(). When ptimer_transaction_commit()
79
+ * is called it will evaluate the state of the timer after all the
80
+ * changes in the transaction, and call the callback if necessary.
81
+ *
82
+ * The callback function is always called from within a transaction
83
+ * begin/commit block, so the callback should not call the
84
+ * ptimer_transaction_begin() function itself. If the callback changes
85
+ * the ptimer state such that another ptimer expiry is triggered, then
86
+ * the callback will be called a second time after the first call returns.
87
+ */
88
+ptimer_state *ptimer_init(ptimer_cb callback,
89
+ void *callback_opaque,
90
+ uint8_t policy_mask);
91
+
92
/**
93
* ptimer_free - Free a ptimer
94
* @s: timer to free
95
@@ -XXX,XX +XXX,XX @@ ptimer_state *ptimer_init_with_bh(QEMUBH *bh, uint8_t policy_mask);
96
*/
97
void ptimer_free(ptimer_state *s);
98
99
+/**
100
+ * ptimer_transaction_begin() - Start a ptimer modification transaction
101
+ *
102
+ * This function must be called before making any calls to functions
103
+ * which modify the ptimer's state (see the ptimer_init() documentation
104
+ * for a list of these), and must always have a matched call to
105
+ * ptimer_transaction_commit().
106
+ * It is an error to call this function for a BH-based ptimer;
107
+ * attempting to do this will trigger an assert.
108
+ */
109
+void ptimer_transaction_begin(ptimer_state *s);
110
+
111
+/**
112
+ * ptimer_transaction_commit() - Commit a ptimer modification transaction
113
+ *
114
+ * This function must be called after calls to functions which modify
115
+ * the ptimer's state, and completes the update of the ptimer. If the
116
+ * ptimer state now means that we should trigger the timer expiry
117
+ * callback, it will be called directly.
118
+ */
119
+void ptimer_transaction_commit(ptimer_state *s);
120
+
121
/**
122
* ptimer_set_period - Set counter increment interval in nanoseconds
123
* @s: ptimer to configure
124
@@ -XXX,XX +XXX,XX @@ void ptimer_free(ptimer_state *s);
125
* Note that if your counter behaviour is specified as having a
126
* particular frequency rather than a period then ptimer_set_freq()
127
* may be more appropriate.
128
+ *
129
+ * This function will assert if it is called outside a
130
+ * ptimer_transaction_begin/commit block, unless this is a bottom-half ptimer.
131
*/
132
void ptimer_set_period(ptimer_state *s, int64_t period);
133
134
@@ -XXX,XX +XXX,XX @@ void ptimer_set_period(ptimer_state *s, int64_t period);
135
* as setting the frequency then this function is more appropriate,
136
* because it allows specifying an effective period which is
137
* precise to fractions of a nanosecond, avoiding rounding errors.
138
+ *
139
+ * This function will assert if it is called outside a
140
+ * ptimer_transaction_begin/commit block, unless this is a bottom-half ptimer.
141
*/
142
void ptimer_set_freq(ptimer_state *s, uint32_t freq);
143
144
@@ -XXX,XX +XXX,XX @@ uint64_t ptimer_get_limit(ptimer_state *s);
145
* Set the limit value of the down-counter. The @reload flag can
146
* be used to emulate the behaviour of timers which immediately
147
* reload the counter when their reload register is written to.
148
+ *
149
+ * This function will assert if it is called outside a
150
+ * ptimer_transaction_begin/commit block, unless this is a bottom-half ptimer.
151
*/
152
void ptimer_set_limit(ptimer_state *s, uint64_t limit, int reload);
153
154
@@ -XXX,XX +XXX,XX @@ uint64_t ptimer_get_count(ptimer_state *s);
155
* Set the value of the down-counter. If the counter is currently
156
* enabled this will arrange for a timer callback at the appropriate
157
* point in the future.
158
+ *
159
+ * This function will assert if it is called outside a
160
+ * ptimer_transaction_begin/commit block, unless this is a bottom-half ptimer.
161
*/
162
void ptimer_set_count(ptimer_state *s, uint64_t count);
163
164
@@ -XXX,XX +XXX,XX @@ void ptimer_set_count(ptimer_state *s, uint64_t count);
165
* the counter value will then be reloaded from the limit and it will
166
* start counting down again. If @oneshot is non-zero, then the counter
167
* will disable itself when it reaches zero.
168
+ *
169
+ * This function will assert if it is called outside a
170
+ * ptimer_transaction_begin/commit block, unless this is a bottom-half ptimer.
171
*/
172
void ptimer_run(ptimer_state *s, int oneshot);
173
174
@@ -XXX,XX +XXX,XX @@ void ptimer_run(ptimer_state *s, int oneshot);
175
*
176
* Note that this can cause it to "lose" time, even if it is immediately
177
* restarted.
178
+ *
179
+ * This function will assert if it is called outside a
180
+ * ptimer_transaction_begin/commit block, unless this is a bottom-half ptimer.
181
*/
182
void ptimer_stop(ptimer_state *s);
183
184
diff --git a/hw/core/ptimer.c b/hw/core/ptimer.c
19
diff --git a/hw/core/ptimer.c b/hw/core/ptimer.c
185
index XXXXXXX..XXXXXXX 100644
20
index XXXXXXX..XXXXXXX 100644
186
--- a/hw/core/ptimer.c
21
--- a/hw/core/ptimer.c
187
+++ b/hw/core/ptimer.c
22
+++ b/hw/core/ptimer.c
188
@@ -XXX,XX +XXX,XX @@ struct ptimer_state
23
@@ -XXX,XX +XXX,XX @@ static void ptimer_reload(ptimer_state *s, int delta_adjust)
189
uint8_t policy_mask;
190
QEMUBH *bh;
191
QEMUTimer *timer;
192
+ ptimer_cb callback;
193
+ void *callback_opaque;
194
+ /*
195
+ * These track whether we're in a transaction block, and if we
196
+ * need to do a timer reload when the block finishes. They don't
197
+ * need to be migrated because migration can never happen in the
198
+ * middle of a transaction block.
199
+ */
200
+ bool in_transaction;
201
+ bool need_reload;
202
};
203
204
/* Use a bottom-half routine to avoid reentrancy issues. */
205
@@ -XXX,XX +XXX,XX @@ static void ptimer_trigger(ptimer_state *s)
206
if (s->bh) {
207
replay_bh_schedule_event(s->bh);
208
}
24
}
209
+ if (s->callback) {
25
210
+ s->callback(s->callback_opaque);
26
if (delta == 0) {
211
+ }
27
+ if (s->enabled == 0) {
212
}
28
+ /* trigger callback disabled the timer already */
213
29
+ return;
214
static void ptimer_reload(ptimer_state *s, int delta_adjust)
215
{
216
- uint32_t period_frac = s->period_frac;
217
- uint64_t period = s->period;
218
- uint64_t delta = s->delta;
219
+ uint32_t period_frac;
220
+ uint64_t period;
221
+ uint64_t delta;
222
bool suppress_trigger = false;
223
224
/*
225
@@ -XXX,XX +XXX,XX @@ static void ptimer_reload(ptimer_state *s, int delta_adjust)
226
(s->policy_mask & PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT)) {
227
suppress_trigger = true;
228
}
229
- if (delta == 0 && !(s->policy_mask & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER)
230
+ if (s->delta == 0 && !(s->policy_mask & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER)
231
&& !suppress_trigger) {
232
ptimer_trigger(s);
233
}
234
235
+ /*
236
+ * Note that ptimer_trigger() might call the device callback function,
237
+ * which can then modify timer state, so we must not cache any fields
238
+ * from ptimer_state until after we have called it.
239
+ */
240
+ delta = s->delta;
241
+ period = s->period;
242
+ period_frac = s->period_frac;
243
+
244
if (delta == 0 && !(s->policy_mask & PTIMER_POLICY_NO_IMMEDIATE_RELOAD)) {
245
delta = s->delta = s->limit;
246
}
247
@@ -XXX,XX +XXX,XX @@ static void ptimer_tick(void *opaque)
248
ptimer_state *s = (ptimer_state *)opaque;
249
bool trigger = true;
250
251
+ /*
252
+ * We perform all the tick actions within a begin/commit block
253
+ * because the callback function that ptimer_trigger() calls
254
+ * might make calls into the ptimer APIs that provoke another
255
+ * trigger, and we want that to cause the callback function
256
+ * to be called iteratively, not recursively.
257
+ */
258
+ ptimer_transaction_begin(s);
259
+
260
if (s->enabled == 2) {
261
s->delta = 0;
262
s->enabled = 0;
263
@@ -XXX,XX +XXX,XX @@ static void ptimer_tick(void *opaque)
264
if (trigger) {
265
ptimer_trigger(s);
266
}
267
+
268
+ ptimer_transaction_commit(s);
269
}
270
271
uint64_t ptimer_get_count(ptimer_state *s)
272
@@ -XXX,XX +XXX,XX @@ uint64_t ptimer_get_count(ptimer_state *s)
273
274
void ptimer_set_count(ptimer_state *s, uint64_t count)
275
{
276
+ assert(s->in_transaction || !s->callback);
277
s->delta = count;
278
if (s->enabled) {
279
- s->next_event = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
280
- ptimer_reload(s, 0);
281
+ if (!s->callback) {
282
+ s->next_event = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
283
+ ptimer_reload(s, 0);
284
+ } else {
285
+ s->need_reload = true;
286
+ }
30
+ }
287
}
288
}
289
290
@@ -XXX,XX +XXX,XX @@ void ptimer_run(ptimer_state *s, int oneshot)
291
{
292
bool was_disabled = !s->enabled;
293
294
+ assert(s->in_transaction || !s->callback);
295
+
296
if (was_disabled && s->period == 0) {
297
if (!qtest_enabled()) {
31
if (!qtest_enabled()) {
298
fprintf(stderr, "Timer with period zero, disabling\n");
32
fprintf(stderr, "Timer with delta zero, disabling\n");
299
@@ -XXX,XX +XXX,XX @@ void ptimer_run(ptimer_state *s, int oneshot)
33
}
300
}
301
s->enabled = oneshot ? 2 : 1;
302
if (was_disabled) {
303
- s->next_event = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
304
- ptimer_reload(s, 0);
305
+ if (!s->callback) {
306
+ s->next_event = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
307
+ ptimer_reload(s, 0);
308
+ } else {
309
+ s->need_reload = true;
310
+ }
311
}
312
}
313
314
@@ -XXX,XX +XXX,XX @@ void ptimer_run(ptimer_state *s, int oneshot)
315
is immediately restarted. */
316
void ptimer_stop(ptimer_state *s)
317
{
318
+ assert(s->in_transaction || !s->callback);
319
+
320
if (!s->enabled)
321
return;
322
323
s->delta = ptimer_get_count(s);
324
timer_del(s->timer);
325
s->enabled = 0;
326
+ if (s->callback) {
327
+ s->need_reload = false;
328
+ }
329
}
330
331
/* Set counter increment interval in nanoseconds. */
332
void ptimer_set_period(ptimer_state *s, int64_t period)
333
{
334
+ assert(s->in_transaction || !s->callback);
335
s->delta = ptimer_get_count(s);
336
s->period = period;
337
s->period_frac = 0;
338
if (s->enabled) {
339
- s->next_event = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
340
- ptimer_reload(s, 0);
341
+ if (!s->callback) {
342
+ s->next_event = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
343
+ ptimer_reload(s, 0);
344
+ } else {
345
+ s->need_reload = true;
346
+ }
347
}
348
}
349
350
/* Set counter frequency in Hz. */
351
void ptimer_set_freq(ptimer_state *s, uint32_t freq)
352
{
353
+ assert(s->in_transaction || !s->callback);
354
s->delta = ptimer_get_count(s);
355
s->period = 1000000000ll / freq;
356
s->period_frac = (1000000000ll << 32) / freq;
357
if (s->enabled) {
358
- s->next_event = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
359
- ptimer_reload(s, 0);
360
+ if (!s->callback) {
361
+ s->next_event = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
362
+ ptimer_reload(s, 0);
363
+ } else {
364
+ s->need_reload = true;
365
+ }
366
}
367
}
368
369
@@ -XXX,XX +XXX,XX @@ void ptimer_set_freq(ptimer_state *s, uint32_t freq)
370
count = limit. */
371
void ptimer_set_limit(ptimer_state *s, uint64_t limit, int reload)
372
{
373
+ assert(s->in_transaction || !s->callback);
374
s->limit = limit;
375
if (reload)
376
s->delta = limit;
377
if (s->enabled && reload) {
378
- s->next_event = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
379
- ptimer_reload(s, 0);
380
+ if (!s->callback) {
381
+ s->next_event = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
382
+ ptimer_reload(s, 0);
383
+ } else {
384
+ s->need_reload = true;
385
+ }
386
}
387
}
388
389
@@ -XXX,XX +XXX,XX @@ uint64_t ptimer_get_limit(ptimer_state *s)
390
return s->limit;
391
}
392
393
+void ptimer_transaction_begin(ptimer_state *s)
394
+{
395
+ assert(!s->in_transaction || !s->callback);
396
+ s->in_transaction = true;
397
+ s->need_reload = false;
398
+}
399
+
400
+void ptimer_transaction_commit(ptimer_state *s)
401
+{
402
+ assert(s->in_transaction);
403
+ /*
404
+ * We must loop here because ptimer_reload() can call the callback
405
+ * function, which might then update ptimer state in a way that
406
+ * means we need to do another reload and possibly another callback.
407
+ * A disabled timer never needs reloading (and if we don't check
408
+ * this then we loop forever if ptimer_reload() disables the timer).
409
+ */
410
+ while (s->need_reload && s->enabled) {
411
+ s->need_reload = false;
412
+ s->next_event = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
413
+ ptimer_reload(s, 0);
414
+ }
415
+ /* Now we've finished reload we can leave the transaction block. */
416
+ s->in_transaction = false;
417
+}
418
+
419
const VMStateDescription vmstate_ptimer = {
420
.name = "ptimer",
421
.version_id = 1,
422
@@ -XXX,XX +XXX,XX @@ ptimer_state *ptimer_init_with_bh(QEMUBH *bh, uint8_t policy_mask)
423
return s;
424
}
425
426
+ptimer_state *ptimer_init(ptimer_cb callback, void *callback_opaque,
427
+ uint8_t policy_mask)
428
+{
429
+ ptimer_state *s;
430
+
431
+ /*
432
+ * The callback function is mandatory; so we use it to distinguish
433
+ * old-style QEMUBH ptimers from new transaction API ptimers.
434
+ * (ptimer_init_with_bh() allows a NULL bh pointer and at least
435
+ * one device (digic-timer) passes NULL, so it's not the case
436
+ * that either s->bh != NULL or s->callback != NULL.)
437
+ */
438
+ assert(callback);
439
+
440
+ s = g_new0(ptimer_state, 1);
441
+ s->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, ptimer_tick, s);
442
+ s->policy_mask = policy_mask;
443
+ s->callback = callback;
444
+ s->callback_opaque = callback_opaque;
445
+
446
+ /*
447
+ * These two policies are incompatible -- trigger-on-decrement implies
448
+ * a timer trigger when the count becomes 0, but no-immediate-trigger
449
+ * implies a trigger when the count stops being 0.
450
+ */
451
+ assert(!((policy_mask & PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT) &&
452
+ (policy_mask & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER)));
453
+ return s;
454
+}
455
+
456
void ptimer_free(ptimer_state *s)
457
{
458
- qemu_bh_delete(s->bh);
459
+ if (s->bh) {
460
+ qemu_bh_delete(s->bh);
461
+ }
462
timer_free(s->timer);
463
g_free(s);
464
}
465
--
34
--
466
2.20.1
35
2.20.1
467
36
468
37
diff view generated by jsdifflib
Deleted patch
1
Convert the ptimer test cases to the transaction-based ptimer API,
2
by changing to ptimer_init(), dropping the now-unused QEMUBH
3
variables, and surrounding each set of changes to the ptimer
4
state in ptimer_transaction_begin/commit calls.
5
1
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Message-id: 20191008171740.9679-4-peter.maydell@linaro.org
9
---
10
tests/ptimer-test.c | 106 +++++++++++++++++++++++++++++++++++---------
11
1 file changed, 84 insertions(+), 22 deletions(-)
12
13
diff --git a/tests/ptimer-test.c b/tests/ptimer-test.c
14
index XXXXXXX..XXXXXXX 100644
15
--- a/tests/ptimer-test.c
16
+++ b/tests/ptimer-test.c
17
@@ -XXX,XX +XXX,XX @@ static void qemu_clock_step(uint64_t ns)
18
static void check_set_count(gconstpointer arg)
19
{
20
const uint8_t *policy = arg;
21
- QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
22
- ptimer_state *ptimer = ptimer_init_with_bh(bh, *policy);
23
+ ptimer_state *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
24
25
triggered = false;
26
27
+ ptimer_transaction_begin(ptimer);
28
ptimer_set_count(ptimer, 1000);
29
+ ptimer_transaction_commit(ptimer);
30
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 1000);
31
g_assert_false(triggered);
32
ptimer_free(ptimer);
33
@@ -XXX,XX +XXX,XX @@ static void check_set_count(gconstpointer arg)
34
static void check_set_limit(gconstpointer arg)
35
{
36
const uint8_t *policy = arg;
37
- QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
38
- ptimer_state *ptimer = ptimer_init_with_bh(bh, *policy);
39
+ ptimer_state *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
40
41
triggered = false;
42
43
+ ptimer_transaction_begin(ptimer);
44
ptimer_set_limit(ptimer, 1000, 0);
45
+ ptimer_transaction_commit(ptimer);
46
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
47
g_assert_cmpuint(ptimer_get_limit(ptimer), ==, 1000);
48
g_assert_false(triggered);
49
50
+ ptimer_transaction_begin(ptimer);
51
ptimer_set_limit(ptimer, 2000, 1);
52
+ ptimer_transaction_commit(ptimer);
53
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 2000);
54
g_assert_cmpuint(ptimer_get_limit(ptimer), ==, 2000);
55
g_assert_false(triggered);
56
@@ -XXX,XX +XXX,XX @@ static void check_set_limit(gconstpointer arg)
57
static void check_oneshot(gconstpointer arg)
58
{
59
const uint8_t *policy = arg;
60
- QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
61
- ptimer_state *ptimer = ptimer_init_with_bh(bh, *policy);
62
+ ptimer_state *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
63
bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
64
65
triggered = false;
66
67
+ ptimer_transaction_begin(ptimer);
68
ptimer_set_period(ptimer, 2000000);
69
ptimer_set_count(ptimer, 10);
70
ptimer_run(ptimer, 1);
71
+ ptimer_transaction_commit(ptimer);
72
73
qemu_clock_step(2000000 * 2 + 1);
74
75
g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 8 : 7);
76
g_assert_false(triggered);
77
78
+ ptimer_transaction_begin(ptimer);
79
ptimer_stop(ptimer);
80
+ ptimer_transaction_commit(ptimer);
81
82
g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 8 : 7);
83
g_assert_false(triggered);
84
@@ -XXX,XX +XXX,XX @@ static void check_oneshot(gconstpointer arg)
85
g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 8 : 7);
86
g_assert_false(triggered);
87
88
+ ptimer_transaction_begin(ptimer);
89
ptimer_run(ptimer, 1);
90
+ ptimer_transaction_commit(ptimer);
91
92
qemu_clock_step(2000000 * 7 + 1);
93
94
@@ -XXX,XX +XXX,XX @@ static void check_oneshot(gconstpointer arg)
95
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
96
g_assert_false(triggered);
97
98
+ ptimer_transaction_begin(ptimer);
99
ptimer_set_count(ptimer, 10);
100
+ ptimer_transaction_commit(ptimer);
101
102
qemu_clock_step(20000000 + 1);
103
104
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 10);
105
g_assert_false(triggered);
106
107
+ ptimer_transaction_begin(ptimer);
108
ptimer_set_limit(ptimer, 9, 1);
109
+ ptimer_transaction_commit(ptimer);
110
111
qemu_clock_step(20000000 + 1);
112
113
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 9);
114
g_assert_false(triggered);
115
116
+ ptimer_transaction_begin(ptimer);
117
ptimer_run(ptimer, 1);
118
+ ptimer_transaction_commit(ptimer);
119
120
qemu_clock_step(2000000 + 1);
121
122
g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 8 : 7);
123
g_assert_false(triggered);
124
125
+ ptimer_transaction_begin(ptimer);
126
ptimer_set_count(ptimer, 20);
127
+ ptimer_transaction_commit(ptimer);
128
129
qemu_clock_step(2000000 * 19 + 1);
130
131
@@ -XXX,XX +XXX,XX @@ static void check_oneshot(gconstpointer arg)
132
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
133
g_assert_true(triggered);
134
135
+ ptimer_transaction_begin(ptimer);
136
ptimer_stop(ptimer);
137
+ ptimer_transaction_commit(ptimer);
138
139
triggered = false;
140
141
@@ -XXX,XX +XXX,XX @@ static void check_oneshot(gconstpointer arg)
142
static void check_periodic(gconstpointer arg)
143
{
144
const uint8_t *policy = arg;
145
- QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
146
- ptimer_state *ptimer = ptimer_init_with_bh(bh, *policy);
147
+ ptimer_state *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
148
bool wrap_policy = (*policy & PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD);
149
bool no_immediate_trigger = (*policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER);
150
bool no_immediate_reload = (*policy & PTIMER_POLICY_NO_IMMEDIATE_RELOAD);
151
@@ -XXX,XX +XXX,XX @@ static void check_periodic(gconstpointer arg)
152
153
triggered = false;
154
155
+ ptimer_transaction_begin(ptimer);
156
ptimer_set_period(ptimer, 2000000);
157
ptimer_set_limit(ptimer, 10, 1);
158
ptimer_run(ptimer, 0);
159
+ ptimer_transaction_commit(ptimer);
160
161
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 10);
162
g_assert_false(triggered);
163
@@ -XXX,XX +XXX,XX @@ static void check_periodic(gconstpointer arg)
164
(no_round_down ? 9 : 8) + (wrap_policy ? 1 : 0));
165
g_assert_false(triggered);
166
167
+ ptimer_transaction_begin(ptimer);
168
ptimer_set_count(ptimer, 20);
169
+ ptimer_transaction_commit(ptimer);
170
171
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 20);
172
g_assert_false(triggered);
173
@@ -XXX,XX +XXX,XX @@ static void check_periodic(gconstpointer arg)
174
175
triggered = false;
176
177
+ ptimer_transaction_begin(ptimer);
178
ptimer_set_count(ptimer, 3);
179
+ ptimer_transaction_commit(ptimer);
180
181
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 3);
182
g_assert_false(triggered);
183
@@ -XXX,XX +XXX,XX @@ static void check_periodic(gconstpointer arg)
184
(no_round_down ? 9 : 8) + (wrap_policy ? 1 : 0));
185
g_assert_true(triggered);
186
187
+ ptimer_transaction_begin(ptimer);
188
ptimer_stop(ptimer);
189
+ ptimer_transaction_commit(ptimer);
190
triggered = false;
191
192
qemu_clock_step(2000000);
193
@@ -XXX,XX +XXX,XX @@ static void check_periodic(gconstpointer arg)
194
(no_round_down ? 9 : 8) + (wrap_policy ? 1 : 0));
195
g_assert_false(triggered);
196
197
+ ptimer_transaction_begin(ptimer);
198
ptimer_set_count(ptimer, 3);
199
ptimer_run(ptimer, 0);
200
+ ptimer_transaction_commit(ptimer);
201
202
qemu_clock_step(2000000 * 3 + 1);
203
204
@@ -XXX,XX +XXX,XX @@ static void check_periodic(gconstpointer arg)
205
(no_round_down ? 9 : 8) + (wrap_policy ? 1 : 0));
206
g_assert_false(triggered);
207
208
+ ptimer_transaction_begin(ptimer);
209
ptimer_set_count(ptimer, 0);
210
+ ptimer_transaction_commit(ptimer);
211
g_assert_cmpuint(ptimer_get_count(ptimer), ==,
212
no_immediate_reload ? 0 : 10);
213
214
@@ -XXX,XX +XXX,XX @@ static void check_periodic(gconstpointer arg)
215
(no_round_down ? 8 : 7) + (wrap_policy ? 1 : 0));
216
g_assert_true(triggered);
217
218
+ ptimer_transaction_begin(ptimer);
219
ptimer_stop(ptimer);
220
+ ptimer_transaction_commit(ptimer);
221
222
triggered = false;
223
224
@@ -XXX,XX +XXX,XX @@ static void check_periodic(gconstpointer arg)
225
(no_round_down ? 8 : 7) + (wrap_policy ? 1 : 0));
226
g_assert_false(triggered);
227
228
+ ptimer_transaction_begin(ptimer);
229
ptimer_run(ptimer, 0);
230
+ ptimer_transaction_commit(ptimer);
231
+
232
+ ptimer_transaction_begin(ptimer);
233
ptimer_set_period(ptimer, 0);
234
+ ptimer_transaction_commit(ptimer);
235
236
qemu_clock_step(2000000 + 1);
237
238
@@ -XXX,XX +XXX,XX @@ static void check_periodic(gconstpointer arg)
239
static void check_on_the_fly_mode_change(gconstpointer arg)
240
{
241
const uint8_t *policy = arg;
242
- QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
243
- ptimer_state *ptimer = ptimer_init_with_bh(bh, *policy);
244
+ ptimer_state *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
245
bool wrap_policy = (*policy & PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD);
246
bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
247
248
triggered = false;
249
250
+ ptimer_transaction_begin(ptimer);
251
ptimer_set_period(ptimer, 2000000);
252
ptimer_set_limit(ptimer, 10, 1);
253
ptimer_run(ptimer, 1);
254
+ ptimer_transaction_commit(ptimer);
255
256
qemu_clock_step(2000000 * 9 + 1);
257
258
g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 1 : 0);
259
g_assert_false(triggered);
260
261
+ ptimer_transaction_begin(ptimer);
262
ptimer_run(ptimer, 0);
263
+ ptimer_transaction_commit(ptimer);
264
265
g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 1 : 0);
266
g_assert_false(triggered);
267
@@ -XXX,XX +XXX,XX @@ static void check_on_the_fly_mode_change(gconstpointer arg)
268
269
qemu_clock_step(2000000 * 9);
270
271
+ ptimer_transaction_begin(ptimer);
272
ptimer_run(ptimer, 1);
273
+ ptimer_transaction_commit(ptimer);
274
275
g_assert_cmpuint(ptimer_get_count(ptimer), ==,
276
(no_round_down ? 1 : 0) + (wrap_policy ? 1 : 0));
277
@@ -XXX,XX +XXX,XX @@ static void check_on_the_fly_mode_change(gconstpointer arg)
278
static void check_on_the_fly_period_change(gconstpointer arg)
279
{
280
const uint8_t *policy = arg;
281
- QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
282
- ptimer_state *ptimer = ptimer_init_with_bh(bh, *policy);
283
+ ptimer_state *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
284
bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
285
286
triggered = false;
287
288
+ ptimer_transaction_begin(ptimer);
289
ptimer_set_period(ptimer, 2000000);
290
ptimer_set_limit(ptimer, 8, 1);
291
ptimer_run(ptimer, 1);
292
+ ptimer_transaction_commit(ptimer);
293
294
qemu_clock_step(2000000 * 4 + 1);
295
296
g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 4 : 3);
297
g_assert_false(triggered);
298
299
+ ptimer_transaction_begin(ptimer);
300
ptimer_set_period(ptimer, 4000000);
301
+ ptimer_transaction_commit(ptimer);
302
g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 4 : 3);
303
304
qemu_clock_step(4000000 * 2 + 1);
305
@@ -XXX,XX +XXX,XX @@ static void check_on_the_fly_period_change(gconstpointer arg)
306
static void check_on_the_fly_freq_change(gconstpointer arg)
307
{
308
const uint8_t *policy = arg;
309
- QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
310
- ptimer_state *ptimer = ptimer_init_with_bh(bh, *policy);
311
+ ptimer_state *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
312
bool no_round_down = (*policy & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
313
314
triggered = false;
315
316
+ ptimer_transaction_begin(ptimer);
317
ptimer_set_freq(ptimer, 500);
318
ptimer_set_limit(ptimer, 8, 1);
319
ptimer_run(ptimer, 1);
320
+ ptimer_transaction_commit(ptimer);
321
322
qemu_clock_step(2000000 * 4 + 1);
323
324
g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 4 : 3);
325
g_assert_false(triggered);
326
327
+ ptimer_transaction_begin(ptimer);
328
ptimer_set_freq(ptimer, 250);
329
+ ptimer_transaction_commit(ptimer);
330
g_assert_cmpuint(ptimer_get_count(ptimer), ==, no_round_down ? 4 : 3);
331
332
qemu_clock_step(2000000 * 4 + 1);
333
@@ -XXX,XX +XXX,XX @@ static void check_on_the_fly_freq_change(gconstpointer arg)
334
static void check_run_with_period_0(gconstpointer arg)
335
{
336
const uint8_t *policy = arg;
337
- QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
338
- ptimer_state *ptimer = ptimer_init_with_bh(bh, *policy);
339
+ ptimer_state *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
340
341
triggered = false;
342
343
+ ptimer_transaction_begin(ptimer);
344
ptimer_set_count(ptimer, 99);
345
ptimer_run(ptimer, 1);
346
+ ptimer_transaction_commit(ptimer);
347
348
qemu_clock_step(10 * NANOSECONDS_PER_SECOND);
349
350
@@ -XXX,XX +XXX,XX @@ static void check_run_with_period_0(gconstpointer arg)
351
static void check_run_with_delta_0(gconstpointer arg)
352
{
353
const uint8_t *policy = arg;
354
- QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
355
- ptimer_state *ptimer = ptimer_init_with_bh(bh, *policy);
356
+ ptimer_state *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
357
bool wrap_policy = (*policy & PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD);
358
bool no_immediate_trigger = (*policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER);
359
bool no_immediate_reload = (*policy & PTIMER_POLICY_NO_IMMEDIATE_RELOAD);
360
@@ -XXX,XX +XXX,XX @@ static void check_run_with_delta_0(gconstpointer arg)
361
362
triggered = false;
363
364
+ ptimer_transaction_begin(ptimer);
365
ptimer_set_period(ptimer, 2000000);
366
ptimer_set_limit(ptimer, 99, 0);
367
ptimer_run(ptimer, 1);
368
+ ptimer_transaction_commit(ptimer);
369
g_assert_cmpuint(ptimer_get_count(ptimer), ==,
370
no_immediate_reload ? 0 : 99);
371
372
@@ -XXX,XX +XXX,XX @@ static void check_run_with_delta_0(gconstpointer arg)
373
g_assert_false(triggered);
374
}
375
376
+ ptimer_transaction_begin(ptimer);
377
ptimer_set_count(ptimer, 99);
378
ptimer_run(ptimer, 1);
379
+ ptimer_transaction_commit(ptimer);
380
}
381
382
qemu_clock_step(2000000 + 1);
383
@@ -XXX,XX +XXX,XX @@ static void check_run_with_delta_0(gconstpointer arg)
384
385
triggered = false;
386
387
+ ptimer_transaction_begin(ptimer);
388
ptimer_set_count(ptimer, 0);
389
ptimer_run(ptimer, 0);
390
+ ptimer_transaction_commit(ptimer);
391
g_assert_cmpuint(ptimer_get_count(ptimer), ==,
392
no_immediate_reload ? 0 : 99);
393
394
@@ -XXX,XX +XXX,XX @@ static void check_run_with_delta_0(gconstpointer arg)
395
wrap_policy ? 0 : (no_round_down ? 99 : 98));
396
g_assert_true(triggered);
397
398
+ ptimer_transaction_begin(ptimer);
399
ptimer_stop(ptimer);
400
+ ptimer_transaction_commit(ptimer);
401
ptimer_free(ptimer);
402
}
403
404
static void check_periodic_with_load_0(gconstpointer arg)
405
{
406
const uint8_t *policy = arg;
407
- QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
408
- ptimer_state *ptimer = ptimer_init_with_bh(bh, *policy);
409
+ ptimer_state *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
410
bool continuous_trigger = (*policy & PTIMER_POLICY_CONTINUOUS_TRIGGER);
411
bool no_immediate_trigger = (*policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER);
412
bool trig_only_on_dec = (*policy & PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT);
413
414
triggered = false;
415
416
+ ptimer_transaction_begin(ptimer);
417
ptimer_set_period(ptimer, 2000000);
418
ptimer_run(ptimer, 0);
419
+ ptimer_transaction_commit(ptimer);
420
421
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
422
423
@@ -XXX,XX +XXX,XX @@ static void check_periodic_with_load_0(gconstpointer arg)
424
425
triggered = false;
426
427
+ ptimer_transaction_begin(ptimer);
428
ptimer_set_count(ptimer, 10);
429
ptimer_run(ptimer, 0);
430
+ ptimer_transaction_commit(ptimer);
431
432
qemu_clock_step(2000000 * 10 + 1);
433
434
@@ -XXX,XX +XXX,XX @@ static void check_periodic_with_load_0(gconstpointer arg)
435
g_assert_false(triggered);
436
}
437
438
+ ptimer_transaction_begin(ptimer);
439
ptimer_stop(ptimer);
440
+ ptimer_transaction_commit(ptimer);
441
ptimer_free(ptimer);
442
}
443
444
static void check_oneshot_with_load_0(gconstpointer arg)
445
{
446
const uint8_t *policy = arg;
447
- QEMUBH *bh = qemu_bh_new(ptimer_trigger, NULL);
448
- ptimer_state *ptimer = ptimer_init_with_bh(bh, *policy);
449
+ ptimer_state *ptimer = ptimer_init(ptimer_trigger, NULL, *policy);
450
bool no_immediate_trigger = (*policy & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER);
451
bool trig_only_on_dec = (*policy & PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT);
452
453
triggered = false;
454
455
+ ptimer_transaction_begin(ptimer);
456
ptimer_set_period(ptimer, 2000000);
457
ptimer_run(ptimer, 1);
458
+ ptimer_transaction_commit(ptimer);
459
460
g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
461
462
--
463
2.20.1
464
465
diff view generated by jsdifflib
Deleted patch
1
Switch the arm_timer.c code away from bottom-half based ptimers
2
to the new transaction-based ptimer API. This just requires
3
adding begin/commit calls around the various arms of
4
arm_timer_write() that modify the ptimer state, and using the
5
new ptimer_init() function to create the timer.
6
1
7
Fixes: https://bugs.launchpad.net/qemu/+bug/1777777
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
10
Message-id: 20191008171740.9679-5-peter.maydell@linaro.org
11
---
12
hw/timer/arm_timer.c | 16 +++++++++++-----
13
1 file changed, 11 insertions(+), 5 deletions(-)
14
15
diff --git a/hw/timer/arm_timer.c b/hw/timer/arm_timer.c
16
index XXXXXXX..XXXXXXX 100644
17
--- a/hw/timer/arm_timer.c
18
+++ b/hw/timer/arm_timer.c
19
@@ -XXX,XX +XXX,XX @@
20
#include "hw/irq.h"
21
#include "hw/ptimer.h"
22
#include "hw/qdev-properties.h"
23
-#include "qemu/main-loop.h"
24
#include "qemu/module.h"
25
#include "qemu/log.h"
26
27
@@ -XXX,XX +XXX,XX @@ static uint32_t arm_timer_read(void *opaque, hwaddr offset)
28
}
29
}
30
31
-/* Reset the timer limit after settings have changed. */
32
+/*
33
+ * Reset the timer limit after settings have changed.
34
+ * May only be called from inside a ptimer transaction block.
35
+ */
36
static void arm_timer_recalibrate(arm_timer_state *s, int reload)
37
{
38
uint32_t limit;
39
@@ -XXX,XX +XXX,XX @@ static void arm_timer_write(void *opaque, hwaddr offset,
40
switch (offset >> 2) {
41
case 0: /* TimerLoad */
42
s->limit = value;
43
+ ptimer_transaction_begin(s->timer);
44
arm_timer_recalibrate(s, 1);
45
+ ptimer_transaction_commit(s->timer);
46
break;
47
case 1: /* TimerValue */
48
/* ??? Linux seems to want to write to this readonly register.
49
Ignore it. */
50
break;
51
case 2: /* TimerControl */
52
+ ptimer_transaction_begin(s->timer);
53
if (s->control & TIMER_CTRL_ENABLE) {
54
/* Pause the timer if it is running. This may cause some
55
inaccuracy dure to rounding, but avoids a whole lot of other
56
@@ -XXX,XX +XXX,XX @@ static void arm_timer_write(void *opaque, hwaddr offset,
57
/* Restart the timer if still enabled. */
58
ptimer_run(s->timer, (s->control & TIMER_CTRL_ONESHOT) != 0);
59
}
60
+ ptimer_transaction_commit(s->timer);
61
break;
62
case 3: /* TimerIntClr */
63
s->int_level = 0;
64
break;
65
case 6: /* TimerBGLoad */
66
s->limit = value;
67
+ ptimer_transaction_begin(s->timer);
68
arm_timer_recalibrate(s, 0);
69
+ ptimer_transaction_commit(s->timer);
70
break;
71
default:
72
qemu_log_mask(LOG_GUEST_ERROR,
73
@@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_arm_timer = {
74
static arm_timer_state *arm_timer_init(uint32_t freq)
75
{
76
arm_timer_state *s;
77
- QEMUBH *bh;
78
79
s = (arm_timer_state *)g_malloc0(sizeof(arm_timer_state));
80
s->freq = freq;
81
s->control = TIMER_CTRL_IE;
82
83
- bh = qemu_bh_new(arm_timer_tick, s);
84
- s->timer = ptimer_init_with_bh(bh, PTIMER_POLICY_DEFAULT);
85
+ s->timer = ptimer_init(arm_timer_tick, s, PTIMER_POLICY_DEFAULT);
86
vmstate_register(NULL, -1, &vmstate_arm_timer, s);
87
return s;
88
}
89
--
90
2.20.1
91
92
diff view generated by jsdifflib
Deleted patch
1
Switch the musicpal code away from bottom-half based ptimers to
2
the new transaction-based ptimer API. This just requires adding
3
begin/commit calls around the various places that modify the ptimer
4
state, and using the new ptimer_init() function to create the timer.
5
1
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Message-id: 20191008171740.9679-6-peter.maydell@linaro.org
9
---
10
hw/arm/musicpal.c | 16 ++++++++++------
11
1 file changed, 10 insertions(+), 6 deletions(-)
12
13
diff --git a/hw/arm/musicpal.c b/hw/arm/musicpal.c
14
index XXXXXXX..XXXXXXX 100644
15
--- a/hw/arm/musicpal.c
16
+++ b/hw/arm/musicpal.c
17
@@ -XXX,XX +XXX,XX @@ static void mv88w8618_timer_tick(void *opaque)
18
static void mv88w8618_timer_init(SysBusDevice *dev, mv88w8618_timer_state *s,
19
uint32_t freq)
20
{
21
- QEMUBH *bh;
22
-
23
sysbus_init_irq(dev, &s->irq);
24
s->freq = freq;
25
26
- bh = qemu_bh_new(mv88w8618_timer_tick, s);
27
- s->ptimer = ptimer_init_with_bh(bh, PTIMER_POLICY_DEFAULT);
28
+ s->ptimer = ptimer_init(mv88w8618_timer_tick, s, PTIMER_POLICY_DEFAULT);
29
}
30
31
static uint64_t mv88w8618_pit_read(void *opaque, hwaddr offset,
32
@@ -XXX,XX +XXX,XX @@ static void mv88w8618_pit_write(void *opaque, hwaddr offset,
33
case MP_PIT_TIMER1_LENGTH ... MP_PIT_TIMER4_LENGTH:
34
t = &s->timer[offset >> 2];
35
t->limit = value;
36
+ ptimer_transaction_begin(t->ptimer);
37
if (t->limit > 0) {
38
ptimer_set_limit(t->ptimer, t->limit, 1);
39
} else {
40
ptimer_stop(t->ptimer);
41
}
42
+ ptimer_transaction_commit(t->ptimer);
43
break;
44
45
case MP_PIT_CONTROL:
46
for (i = 0; i < 4; i++) {
47
t = &s->timer[i];
48
+ ptimer_transaction_begin(t->ptimer);
49
if (value & 0xf && t->limit > 0) {
50
ptimer_set_limit(t->ptimer, t->limit, 0);
51
ptimer_set_freq(t->ptimer, t->freq);
52
@@ -XXX,XX +XXX,XX @@ static void mv88w8618_pit_write(void *opaque, hwaddr offset,
53
} else {
54
ptimer_stop(t->ptimer);
55
}
56
+ ptimer_transaction_commit(t->ptimer);
57
value >>= 4;
58
}
59
break;
60
@@ -XXX,XX +XXX,XX @@ static void mv88w8618_pit_reset(DeviceState *d)
61
int i;
62
63
for (i = 0; i < 4; i++) {
64
- ptimer_stop(s->timer[i].ptimer);
65
- s->timer[i].limit = 0;
66
+ mv88w8618_timer_state *t = &s->timer[i];
67
+ ptimer_transaction_begin(t->ptimer);
68
+ ptimer_stop(t->ptimer);
69
+ ptimer_transaction_commit(t->ptimer);
70
+ t->limit = 0;
71
}
72
}
73
74
--
75
2.20.1
76
77
diff view generated by jsdifflib
Deleted patch
1
Switch the allwinner-a10-pit code away from bottom-half based ptimers to
2
the new transaction-based ptimer API. This just requires adding
3
begin/commit calls around the various places that modify the ptimer
4
state, and using the new ptimer_init() function to create the timer.
5
1
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Message-id: 20191008171740.9679-7-peter.maydell@linaro.org
9
---
10
hw/timer/allwinner-a10-pit.c | 12 ++++++++----
11
1 file changed, 8 insertions(+), 4 deletions(-)
12
13
diff --git a/hw/timer/allwinner-a10-pit.c b/hw/timer/allwinner-a10-pit.c
14
index XXXXXXX..XXXXXXX 100644
15
--- a/hw/timer/allwinner-a10-pit.c
16
+++ b/hw/timer/allwinner-a10-pit.c
17
@@ -XXX,XX +XXX,XX @@
18
#include "hw/timer/allwinner-a10-pit.h"
19
#include "migration/vmstate.h"
20
#include "qemu/log.h"
21
-#include "qemu/main-loop.h"
22
#include "qemu/module.h"
23
24
static void a10_pit_update_irq(AwA10PITState *s)
25
@@ -XXX,XX +XXX,XX @@ static uint64_t a10_pit_read(void *opaque, hwaddr offset, unsigned size)
26
return 0;
27
}
28
29
+/* Must be called inside a ptimer transaction block for s->timer[index] */
30
static void a10_pit_set_freq(AwA10PITState *s, int index)
31
{
32
uint32_t prescaler, source, source_freq;
33
@@ -XXX,XX +XXX,XX @@ static void a10_pit_write(void *opaque, hwaddr offset, uint64_t value,
34
switch (offset & 0x0f) {
35
case AW_A10_PIT_TIMER_CONTROL:
36
s->control[index] = value;
37
+ ptimer_transaction_begin(s->timer[index]);
38
a10_pit_set_freq(s, index);
39
if (s->control[index] & AW_A10_PIT_TIMER_RELOAD) {
40
ptimer_set_count(s->timer[index], s->interval[index]);
41
@@ -XXX,XX +XXX,XX @@ static void a10_pit_write(void *opaque, hwaddr offset, uint64_t value,
42
} else {
43
ptimer_stop(s->timer[index]);
44
}
45
+ ptimer_transaction_commit(s->timer[index]);
46
break;
47
case AW_A10_PIT_TIMER_INTERVAL:
48
s->interval[index] = value;
49
+ ptimer_transaction_begin(s->timer[index]);
50
ptimer_set_limit(s->timer[index], s->interval[index], 1);
51
+ ptimer_transaction_commit(s->timer[index]);
52
break;
53
case AW_A10_PIT_TIMER_COUNT:
54
s->count[index] = value;
55
@@ -XXX,XX +XXX,XX @@ static void a10_pit_reset(DeviceState *dev)
56
s->control[i] = AW_A10_PIT_DEFAULT_CLOCK;
57
s->interval[i] = 0;
58
s->count[i] = 0;
59
+ ptimer_transaction_begin(s->timer[i]);
60
ptimer_stop(s->timer[i]);
61
a10_pit_set_freq(s, i);
62
+ ptimer_transaction_commit(s->timer[i]);
63
}
64
s->watch_dog_mode = 0;
65
s->watch_dog_control = 0;
66
@@ -XXX,XX +XXX,XX @@ static void a10_pit_init(Object *obj)
67
{
68
AwA10PITState *s = AW_A10_PIT(obj);
69
SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
70
- QEMUBH * bh[AW_A10_PIT_TIMER_NR];
71
uint8_t i;
72
73
for (i = 0; i < AW_A10_PIT_TIMER_NR; i++) {
74
@@ -XXX,XX +XXX,XX @@ static void a10_pit_init(Object *obj)
75
76
tc->container = s;
77
tc->index = i;
78
- bh[i] = qemu_bh_new(a10_pit_timer_cb, tc);
79
- s->timer[i] = ptimer_init_with_bh(bh[i], PTIMER_POLICY_DEFAULT);
80
+ s->timer[i] = ptimer_init(a10_pit_timer_cb, tc, PTIMER_POLICY_DEFAULT);
81
}
82
}
83
84
--
85
2.20.1
86
87
diff view generated by jsdifflib
Deleted patch
1
Switch the arm_mptimer.c code away from bottom-half based ptimers to
2
the new transaction-based ptimer API. This just requires adding
3
begin/commit calls around the various places that modify the ptimer
4
state, and using the new ptimer_init() function to create the timer.
5
1
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Message-id: 20191008171740.9679-8-peter.maydell@linaro.org
9
---
10
hw/timer/arm_mptimer.c | 14 +++++++++++---
11
1 file changed, 11 insertions(+), 3 deletions(-)
12
13
diff --git a/hw/timer/arm_mptimer.c b/hw/timer/arm_mptimer.c
14
index XXXXXXX..XXXXXXX 100644
15
--- a/hw/timer/arm_mptimer.c
16
+++ b/hw/timer/arm_mptimer.c
17
@@ -XXX,XX +XXX,XX @@
18
#include "hw/timer/arm_mptimer.h"
19
#include "migration/vmstate.h"
20
#include "qapi/error.h"
21
-#include "qemu/main-loop.h"
22
#include "qemu/module.h"
23
#include "hw/core/cpu.h"
24
25
@@ -XXX,XX +XXX,XX @@ static inline uint32_t timerblock_scale(uint32_t control)
26
return (((control >> 8) & 0xff) + 1) * 10;
27
}
28
29
+/* Must be called within a ptimer transaction block */
30
static inline void timerblock_set_count(struct ptimer_state *timer,
31
uint32_t control, uint64_t *count)
32
{
33
@@ -XXX,XX +XXX,XX @@ static inline void timerblock_set_count(struct ptimer_state *timer,
34
ptimer_set_count(timer, *count);
35
}
36
37
+/* Must be called within a ptimer transaction block */
38
static inline void timerblock_run(struct ptimer_state *timer,
39
uint32_t control, uint32_t load)
40
{
41
@@ -XXX,XX +XXX,XX @@ static void timerblock_write(void *opaque, hwaddr addr,
42
uint32_t control = tb->control;
43
switch (addr) {
44
case 0: /* Load */
45
+ ptimer_transaction_begin(tb->timer);
46
/* Setting load to 0 stops the timer without doing the tick if
47
* prescaler = 0.
48
*/
49
@@ -XXX,XX +XXX,XX @@ static void timerblock_write(void *opaque, hwaddr addr,
50
}
51
ptimer_set_limit(tb->timer, value, 1);
52
timerblock_run(tb->timer, control, value);
53
+ ptimer_transaction_commit(tb->timer);
54
break;
55
case 4: /* Counter. */
56
+ ptimer_transaction_begin(tb->timer);
57
/* Setting counter to 0 stops the one-shot timer, or periodic with
58
* load = 0, without doing the tick if prescaler = 0.
59
*/
60
@@ -XXX,XX +XXX,XX @@ static void timerblock_write(void *opaque, hwaddr addr,
61
}
62
timerblock_set_count(tb->timer, control, &value);
63
timerblock_run(tb->timer, control, value);
64
+ ptimer_transaction_commit(tb->timer);
65
break;
66
case 8: /* Control. */
67
+ ptimer_transaction_begin(tb->timer);
68
if ((control & 3) != (value & 3)) {
69
ptimer_stop(tb->timer);
70
}
71
@@ -XXX,XX +XXX,XX @@ static void timerblock_write(void *opaque, hwaddr addr,
72
timerblock_run(tb->timer, value, count);
73
}
74
tb->control = value;
75
+ ptimer_transaction_commit(tb->timer);
76
break;
77
case 12: /* Interrupt status. */
78
tb->status &= ~value;
79
@@ -XXX,XX +XXX,XX @@ static void timerblock_reset(TimerBlock *tb)
80
tb->control = 0;
81
tb->status = 0;
82
if (tb->timer) {
83
+ ptimer_transaction_begin(tb->timer);
84
ptimer_stop(tb->timer);
85
ptimer_set_limit(tb->timer, 0, 1);
86
ptimer_set_period(tb->timer, timerblock_scale(0));
87
+ ptimer_transaction_commit(tb->timer);
88
}
89
}
90
91
@@ -XXX,XX +XXX,XX @@ static void arm_mptimer_realize(DeviceState *dev, Error **errp)
92
*/
93
for (i = 0; i < s->num_cpu; i++) {
94
TimerBlock *tb = &s->timerblock[i];
95
- QEMUBH *bh = qemu_bh_new(timerblock_tick, tb);
96
- tb->timer = ptimer_init_with_bh(bh, PTIMER_POLICY);
97
+ tb->timer = ptimer_init(timerblock_tick, tb, PTIMER_POLICY);
98
sysbus_init_irq(sbd, &tb->irq);
99
memory_region_init_io(&tb->iomem, OBJECT(s), &timerblock_ops, tb,
100
"arm_mptimer_timerblock", 0x20);
101
--
102
2.20.1
103
104
diff view generated by jsdifflib
Deleted patch
1
Switch the cmsdk-apb-dualtimer code away from bottom-half based
2
ptimers to the new transaction-based ptimer API. This just requires
3
adding begin/commit calls around the various places that modify the
4
ptimer state, and using the new ptimer_init() function to create the
5
timer.
6
1
7
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
9
Message-id: 20191008171740.9679-9-peter.maydell@linaro.org
10
---
11
hw/timer/cmsdk-apb-dualtimer.c | 14 +++++++++++---
12
1 file changed, 11 insertions(+), 3 deletions(-)
13
14
diff --git a/hw/timer/cmsdk-apb-dualtimer.c b/hw/timer/cmsdk-apb-dualtimer.c
15
index XXXXXXX..XXXXXXX 100644
16
--- a/hw/timer/cmsdk-apb-dualtimer.c
17
+++ b/hw/timer/cmsdk-apb-dualtimer.c
18
@@ -XXX,XX +XXX,XX @@
19
#include "qemu/log.h"
20
#include "trace.h"
21
#include "qapi/error.h"
22
-#include "qemu/main-loop.h"
23
#include "qemu/module.h"
24
#include "hw/sysbus.h"
25
#include "hw/irq.h"
26
@@ -XXX,XX +XXX,XX @@ static void cmsdk_dualtimermod_write_control(CMSDKAPBDualTimerModule *m,
27
/* Handle a write to the CONTROL register */
28
uint32_t changed;
29
30
+ ptimer_transaction_begin(m->timer);
31
+
32
newctrl &= R_CONTROL_VALID_MASK;
33
34
changed = m->control ^ newctrl;
35
@@ -XXX,XX +XXX,XX @@ static void cmsdk_dualtimermod_write_control(CMSDKAPBDualTimerModule *m,
36
}
37
38
m->control = newctrl;
39
+
40
+ ptimer_transaction_commit(m->timer);
41
}
42
43
static uint64_t cmsdk_apb_dualtimer_read(void *opaque, hwaddr offset,
44
@@ -XXX,XX +XXX,XX @@ static void cmsdk_apb_dualtimer_write(void *opaque, hwaddr offset,
45
if (!(m->control & R_CONTROL_SIZE_MASK)) {
46
value &= 0xffff;
47
}
48
+ ptimer_transaction_begin(m->timer);
49
if (!(m->control & R_CONTROL_MODE_MASK)) {
50
/*
51
* In free-running mode this won't set the limit but will
52
@@ -XXX,XX +XXX,XX @@ static void cmsdk_apb_dualtimer_write(void *opaque, hwaddr offset,
53
ptimer_run(m->timer, 1);
54
}
55
}
56
+ ptimer_transaction_commit(m->timer);
57
break;
58
case A_TIMER1BGLOAD:
59
/* Set the limit, but not the current count */
60
@@ -XXX,XX +XXX,XX @@ static void cmsdk_apb_dualtimer_write(void *opaque, hwaddr offset,
61
if (!(m->control & R_CONTROL_SIZE_MASK)) {
62
value &= 0xffff;
63
}
64
+ ptimer_transaction_begin(m->timer);
65
ptimer_set_limit(m->timer, value, 0);
66
+ ptimer_transaction_commit(m->timer);
67
break;
68
case A_TIMER1CONTROL:
69
cmsdk_dualtimermod_write_control(m, value);
70
@@ -XXX,XX +XXX,XX @@ static void cmsdk_dualtimermod_reset(CMSDKAPBDualTimerModule *m)
71
m->intstatus = 0;
72
m->load = 0;
73
m->value = 0xffffffff;
74
+ ptimer_transaction_begin(m->timer);
75
ptimer_stop(m->timer);
76
/*
77
* We start in free-running mode, with VALUE at 0xffffffff, and
78
@@ -XXX,XX +XXX,XX @@ static void cmsdk_dualtimermod_reset(CMSDKAPBDualTimerModule *m)
79
*/
80
ptimer_set_limit(m->timer, 0xffff, 1);
81
ptimer_set_freq(m->timer, m->parent->pclk_frq);
82
+ ptimer_transaction_commit(m->timer);
83
}
84
85
static void cmsdk_apb_dualtimer_reset(DeviceState *dev)
86
@@ -XXX,XX +XXX,XX @@ static void cmsdk_apb_dualtimer_realize(DeviceState *dev, Error **errp)
87
88
for (i = 0; i < ARRAY_SIZE(s->timermod); i++) {
89
CMSDKAPBDualTimerModule *m = &s->timermod[i];
90
- QEMUBH *bh = qemu_bh_new(cmsdk_dualtimermod_tick, m);
91
92
m->parent = s;
93
- m->timer = ptimer_init_with_bh(bh,
94
+ m->timer = ptimer_init(cmsdk_dualtimermod_tick, m,
95
PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD |
96
PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT |
97
PTIMER_POLICY_NO_IMMEDIATE_RELOAD |
98
--
99
2.20.1
100
101
diff view generated by jsdifflib
Deleted patch
1
Switch the cmsdk-apb-timer code away from bottom-half based ptimers
2
to the new transaction-based ptimer API. This just requires adding
3
begin/commit calls around the various places that modify the ptimer
4
state, and using the new ptimer_init() function to create the timer.
5
1
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Message-id: 20191008171740.9679-10-peter.maydell@linaro.org
9
---
10
hw/timer/cmsdk-apb-timer.c | 15 +++++++++++----
11
1 file changed, 11 insertions(+), 4 deletions(-)
12
13
diff --git a/hw/timer/cmsdk-apb-timer.c b/hw/timer/cmsdk-apb-timer.c
14
index XXXXXXX..XXXXXXX 100644
15
--- a/hw/timer/cmsdk-apb-timer.c
16
+++ b/hw/timer/cmsdk-apb-timer.c
17
@@ -XXX,XX +XXX,XX @@
18
19
#include "qemu/osdep.h"
20
#include "qemu/log.h"
21
-#include "qemu/main-loop.h"
22
#include "qemu/module.h"
23
#include "qapi/error.h"
24
#include "trace.h"
25
@@ -XXX,XX +XXX,XX @@ static void cmsdk_apb_timer_write(void *opaque, hwaddr offset, uint64_t value,
26
"CMSDK APB timer: EXTIN input not supported\n");
27
}
28
s->ctrl = value & 0xf;
29
+ ptimer_transaction_begin(s->timer);
30
if (s->ctrl & R_CTRL_EN_MASK) {
31
ptimer_run(s->timer, ptimer_get_limit(s->timer) == 0);
32
} else {
33
ptimer_stop(s->timer);
34
}
35
+ ptimer_transaction_commit(s->timer);
36
break;
37
case A_RELOAD:
38
/* Writing to reload also sets the current timer value */
39
+ ptimer_transaction_begin(s->timer);
40
if (!value) {
41
ptimer_stop(s->timer);
42
}
43
@@ -XXX,XX +XXX,XX @@ static void cmsdk_apb_timer_write(void *opaque, hwaddr offset, uint64_t value,
44
*/
45
ptimer_run(s->timer, 0);
46
}
47
+ ptimer_transaction_commit(s->timer);
48
break;
49
case A_VALUE:
50
+ ptimer_transaction_begin(s->timer);
51
if (!value && !ptimer_get_limit(s->timer)) {
52
ptimer_stop(s->timer);
53
}
54
@@ -XXX,XX +XXX,XX @@ static void cmsdk_apb_timer_write(void *opaque, hwaddr offset, uint64_t value,
55
if (value && (s->ctrl & R_CTRL_EN_MASK)) {
56
ptimer_run(s->timer, ptimer_get_limit(s->timer) == 0);
57
}
58
+ ptimer_transaction_commit(s->timer);
59
break;
60
case A_INTSTATUS:
61
/* Just one bit, which is W1C. */
62
@@ -XXX,XX +XXX,XX @@ static void cmsdk_apb_timer_reset(DeviceState *dev)
63
trace_cmsdk_apb_timer_reset();
64
s->ctrl = 0;
65
s->intstatus = 0;
66
+ ptimer_transaction_begin(s->timer);
67
ptimer_stop(s->timer);
68
/* Set the limit and the count */
69
ptimer_set_limit(s->timer, 0, 1);
70
+ ptimer_transaction_commit(s->timer);
71
}
72
73
static void cmsdk_apb_timer_init(Object *obj)
74
@@ -XXX,XX +XXX,XX @@ static void cmsdk_apb_timer_init(Object *obj)
75
static void cmsdk_apb_timer_realize(DeviceState *dev, Error **errp)
76
{
77
CMSDKAPBTIMER *s = CMSDK_APB_TIMER(dev);
78
- QEMUBH *bh;
79
80
if (s->pclk_frq == 0) {
81
error_setg(errp, "CMSDK APB timer: pclk-frq property must be set");
82
return;
83
}
84
85
- bh = qemu_bh_new(cmsdk_apb_timer_tick, s);
86
- s->timer = ptimer_init_with_bh(bh,
87
+ s->timer = ptimer_init(cmsdk_apb_timer_tick, s,
88
PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD |
89
PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT |
90
PTIMER_POLICY_NO_IMMEDIATE_RELOAD |
91
PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
92
93
+ ptimer_transaction_begin(s->timer);
94
ptimer_set_freq(s->timer, s->pclk_frq);
95
+ ptimer_transaction_commit(s->timer);
96
}
97
98
static const VMStateDescription cmsdk_apb_timer_vmstate = {
99
--
100
2.20.1
101
102
diff view generated by jsdifflib
Deleted patch
1
Switch the digic-timer.c code away from bottom-half based ptimers to
2
the new transaction-based ptimer API. This just requires adding
3
begin/commit calls around the various places that modify the ptimer
4
state, and using the new ptimer_init() function to create the timer.
5
1
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Message-id: 20191008171740.9679-11-peter.maydell@linaro.org
9
---
10
hw/timer/digic-timer.c | 16 ++++++++++++++--
11
1 file changed, 14 insertions(+), 2 deletions(-)
12
13
diff --git a/hw/timer/digic-timer.c b/hw/timer/digic-timer.c
14
index XXXXXXX..XXXXXXX 100644
15
--- a/hw/timer/digic-timer.c
16
+++ b/hw/timer/digic-timer.c
17
@@ -XXX,XX +XXX,XX @@
18
#include "qemu/osdep.h"
19
#include "hw/sysbus.h"
20
#include "hw/ptimer.h"
21
-#include "qemu/main-loop.h"
22
#include "qemu/module.h"
23
#include "qemu/log.h"
24
25
@@ -XXX,XX +XXX,XX @@ static void digic_timer_reset(DeviceState *dev)
26
{
27
DigicTimerState *s = DIGIC_TIMER(dev);
28
29
+ ptimer_transaction_begin(s->ptimer);
30
ptimer_stop(s->ptimer);
31
+ ptimer_transaction_commit(s->ptimer);
32
s->control = 0;
33
s->relvalue = 0;
34
}
35
@@ -XXX,XX +XXX,XX @@ static void digic_timer_write(void *opaque, hwaddr offset,
36
break;
37
}
38
39
+ ptimer_transaction_begin(s->ptimer);
40
if (value & DIGIC_TIMER_CONTROL_EN) {
41
ptimer_run(s->ptimer, 0);
42
}
43
44
s->control = (uint32_t)value;
45
+ ptimer_transaction_commit(s->ptimer);
46
break;
47
48
case DIGIC_TIMER_RELVALUE:
49
s->relvalue = extract32(value, 0, 16);
50
+ ptimer_transaction_begin(s->ptimer);
51
ptimer_set_limit(s->ptimer, s->relvalue, 1);
52
+ ptimer_transaction_commit(s->ptimer);
53
break;
54
55
case DIGIC_TIMER_VALUE:
56
@@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps digic_timer_ops = {
57
.endianness = DEVICE_NATIVE_ENDIAN,
58
};
59
60
+static void digic_timer_tick(void *opaque)
61
+{
62
+ /* Nothing to do on timer rollover */
63
+}
64
+
65
static void digic_timer_init(Object *obj)
66
{
67
DigicTimerState *s = DIGIC_TIMER(obj);
68
69
- s->ptimer = ptimer_init_with_bh(NULL, PTIMER_POLICY_DEFAULT);
70
+ s->ptimer = ptimer_init(digic_timer_tick, NULL, PTIMER_POLICY_DEFAULT);
71
72
/*
73
* FIXME: there is no documentation on Digic timer
74
* frequency setup so let it always run at 1 MHz
75
*/
76
+ ptimer_transaction_begin(s->ptimer);
77
ptimer_set_freq(s->ptimer, 1 * 1000 * 1000);
78
+ ptimer_transaction_commit(s->ptimer);
79
80
memory_region_init_io(&s->iomem, OBJECT(s), &digic_timer_ops, s,
81
TYPE_DIGIC_TIMER, 0x100);
82
--
83
2.20.1
84
85
diff view generated by jsdifflib
Deleted patch
1
Switch the exynos4210_pwm code away from bottom-half based ptimers to
2
the new transaction-based ptimer API. This just requires adding
3
begin/commit calls around the various places that modify the ptimer
4
state, and using the new ptimer_init() function to create the timer.
5
1
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Message-id: 20191008171740.9679-15-peter.maydell@linaro.org
9
---
10
hw/timer/exynos4210_pwm.c | 17 ++++++++++++-----
11
1 file changed, 12 insertions(+), 5 deletions(-)
12
13
diff --git a/hw/timer/exynos4210_pwm.c b/hw/timer/exynos4210_pwm.c
14
index XXXXXXX..XXXXXXX 100644
15
--- a/hw/timer/exynos4210_pwm.c
16
+++ b/hw/timer/exynos4210_pwm.c
17
@@ -XXX,XX +XXX,XX @@
18
#include "hw/sysbus.h"
19
#include "migration/vmstate.h"
20
#include "qemu/timer.h"
21
-#include "qemu/main-loop.h"
22
#include "qemu/module.h"
23
#include "hw/ptimer.h"
24
25
@@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_exynos4210_pwm_state = {
26
};
27
28
/*
29
- * PWM update frequency
30
+ * PWM update frequency.
31
+ * Must be called within a ptimer_transaction_begin/commit block
32
+ * for s->timer[id].ptimer.
33
*/
34
static void exynos4210_pwm_update_freq(Exynos4210PWMState *s, uint32_t id)
35
{
36
@@ -XXX,XX +XXX,XX @@ static void exynos4210_pwm_write(void *opaque, hwaddr offset,
37
38
/* update timers frequencies */
39
for (i = 0; i < EXYNOS4210_PWM_TIMERS_NUM; i++) {
40
+ ptimer_transaction_begin(s->timer[i].ptimer);
41
exynos4210_pwm_update_freq(s, s->timer[i].id);
42
+ ptimer_transaction_commit(s->timer[i].ptimer);
43
}
44
break;
45
46
case TCON:
47
for (i = 0; i < EXYNOS4210_PWM_TIMERS_NUM; i++) {
48
+ ptimer_transaction_begin(s->timer[i].ptimer);
49
if ((value & TCON_TIMER_MANUAL_UPD(i)) >
50
(s->reg_tcon & TCON_TIMER_MANUAL_UPD(i))) {
51
/*
52
@@ -XXX,XX +XXX,XX @@ static void exynos4210_pwm_write(void *opaque, hwaddr offset,
53
ptimer_stop(s->timer[i].ptimer);
54
DPRINTF("stop timer %d\n", i);
55
}
56
+ ptimer_transaction_commit(s->timer[i].ptimer);
57
}
58
s->reg_tcon = value;
59
break;
60
@@ -XXX,XX +XXX,XX @@ static void exynos4210_pwm_reset(DeviceState *d)
61
s->timer[i].reg_tcmpb = 0;
62
s->timer[i].reg_tcntb = 0;
63
64
+ ptimer_transaction_begin(s->timer[i].ptimer);
65
exynos4210_pwm_update_freq(s, s->timer[i].id);
66
ptimer_stop(s->timer[i].ptimer);
67
+ ptimer_transaction_commit(s->timer[i].ptimer);
68
}
69
}
70
71
@@ -XXX,XX +XXX,XX @@ static void exynos4210_pwm_init(Object *obj)
72
Exynos4210PWMState *s = EXYNOS4210_PWM(obj);
73
SysBusDevice *dev = SYS_BUS_DEVICE(obj);
74
int i;
75
- QEMUBH *bh;
76
77
for (i = 0; i < EXYNOS4210_PWM_TIMERS_NUM; i++) {
78
- bh = qemu_bh_new(exynos4210_pwm_tick, &s->timer[i]);
79
sysbus_init_irq(dev, &s->timer[i].irq);
80
- s->timer[i].ptimer = ptimer_init_with_bh(bh, PTIMER_POLICY_DEFAULT);
81
+ s->timer[i].ptimer = ptimer_init(exynos4210_pwm_tick,
82
+ &s->timer[i],
83
+ PTIMER_POLICY_DEFAULT);
84
s->timer[i].id = i;
85
s->timer[i].parent = s;
86
}
87
--
88
2.20.1
89
90
diff view generated by jsdifflib
Deleted patch
1
Switch the exynos41210_rtc 1Hz ptimer over to the transaction-based
2
API. (We will switch the other ptimer used by this device in a
3
separate commit.)
4
1
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Message-id: 20191008171740.9679-16-peter.maydell@linaro.org
8
---
9
hw/timer/exynos4210_rtc.c | 10 ++++++++--
10
1 file changed, 8 insertions(+), 2 deletions(-)
11
12
diff --git a/hw/timer/exynos4210_rtc.c b/hw/timer/exynos4210_rtc.c
13
index XXXXXXX..XXXXXXX 100644
14
--- a/hw/timer/exynos4210_rtc.c
15
+++ b/hw/timer/exynos4210_rtc.c
16
@@ -XXX,XX +XXX,XX @@ static void exynos4210_rtc_write(void *opaque, hwaddr offset,
17
}
18
break;
19
case RTCCON:
20
+ ptimer_transaction_begin(s->ptimer_1Hz);
21
if (value & RTC_ENABLE) {
22
exynos4210_rtc_update_freq(s, value);
23
}
24
@@ -XXX,XX +XXX,XX @@ static void exynos4210_rtc_write(void *opaque, hwaddr offset,
25
ptimer_stop(s->ptimer);
26
}
27
}
28
+ ptimer_transaction_commit(s->ptimer_1Hz);
29
s->reg_rtccon = value;
30
break;
31
case TICCNT:
32
@@ -XXX,XX +XXX,XX @@ static void exynos4210_rtc_reset(DeviceState *d)
33
34
exynos4210_rtc_update_freq(s, s->reg_rtccon);
35
ptimer_stop(s->ptimer);
36
+ ptimer_transaction_begin(s->ptimer_1Hz);
37
ptimer_stop(s->ptimer_1Hz);
38
+ ptimer_transaction_commit(s->ptimer_1Hz);
39
}
40
41
static const MemoryRegionOps exynos4210_rtc_ops = {
42
@@ -XXX,XX +XXX,XX @@ static void exynos4210_rtc_init(Object *obj)
43
ptimer_set_freq(s->ptimer, RTC_BASE_FREQ);
44
exynos4210_rtc_update_freq(s, 0);
45
46
- bh = qemu_bh_new(exynos4210_rtc_1Hz_tick, s);
47
- s->ptimer_1Hz = ptimer_init_with_bh(bh, PTIMER_POLICY_DEFAULT);
48
+ s->ptimer_1Hz = ptimer_init(exynos4210_rtc_1Hz_tick,
49
+ s, PTIMER_POLICY_DEFAULT);
50
+ ptimer_transaction_begin(s->ptimer_1Hz);
51
ptimer_set_freq(s->ptimer_1Hz, RTC_BASE_FREQ);
52
+ ptimer_transaction_commit(s->ptimer_1Hz);
53
54
sysbus_init_irq(dev, &s->alm_irq);
55
sysbus_init_irq(dev, &s->tick_irq);
56
--
57
2.20.1
58
59
diff view generated by jsdifflib
Deleted patch
1
Switch the exynos41210_rtc main ptimer over to the transaction-based
2
API, completing the transition for this device.
3
1
4
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
5
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
6
Message-id: 20191008171740.9679-17-peter.maydell@linaro.org
7
---
8
hw/timer/exynos4210_rtc.c | 12 ++++++++----
9
1 file changed, 8 insertions(+), 4 deletions(-)
10
11
diff --git a/hw/timer/exynos4210_rtc.c b/hw/timer/exynos4210_rtc.c
12
index XXXXXXX..XXXXXXX 100644
13
--- a/hw/timer/exynos4210_rtc.c
14
+++ b/hw/timer/exynos4210_rtc.c
15
@@ -XXX,XX +XXX,XX @@
16
#include "qemu/osdep.h"
17
#include "qemu-common.h"
18
#include "qemu/log.h"
19
-#include "qemu/main-loop.h"
20
#include "qemu/module.h"
21
#include "hw/sysbus.h"
22
#include "migration/vmstate.h"
23
@@ -XXX,XX +XXX,XX @@ static void check_alarm_raise(Exynos4210RTCState *s)
24
* RTC update frequency
25
* Parameters:
26
* reg_value - current RTCCON register or his new value
27
+ * Must be called within a ptimer_transaction_begin/commit block for s->ptimer.
28
*/
29
static void exynos4210_rtc_update_freq(Exynos4210RTCState *s,
30
uint32_t reg_value)
31
@@ -XXX,XX +XXX,XX @@ static void exynos4210_rtc_write(void *opaque, hwaddr offset,
32
break;
33
case RTCCON:
34
ptimer_transaction_begin(s->ptimer_1Hz);
35
+ ptimer_transaction_begin(s->ptimer);
36
if (value & RTC_ENABLE) {
37
exynos4210_rtc_update_freq(s, value);
38
}
39
@@ -XXX,XX +XXX,XX @@ static void exynos4210_rtc_write(void *opaque, hwaddr offset,
40
}
41
}
42
ptimer_transaction_commit(s->ptimer_1Hz);
43
+ ptimer_transaction_commit(s->ptimer);
44
s->reg_rtccon = value;
45
break;
46
case TICCNT:
47
@@ -XXX,XX +XXX,XX @@ static void exynos4210_rtc_reset(DeviceState *d)
48
49
s->reg_curticcnt = 0;
50
51
+ ptimer_transaction_begin(s->ptimer);
52
exynos4210_rtc_update_freq(s, s->reg_rtccon);
53
ptimer_stop(s->ptimer);
54
+ ptimer_transaction_commit(s->ptimer);
55
ptimer_transaction_begin(s->ptimer_1Hz);
56
ptimer_stop(s->ptimer_1Hz);
57
ptimer_transaction_commit(s->ptimer_1Hz);
58
@@ -XXX,XX +XXX,XX @@ static void exynos4210_rtc_init(Object *obj)
59
{
60
Exynos4210RTCState *s = EXYNOS4210_RTC(obj);
61
SysBusDevice *dev = SYS_BUS_DEVICE(obj);
62
- QEMUBH *bh;
63
64
- bh = qemu_bh_new(exynos4210_rtc_tick, s);
65
- s->ptimer = ptimer_init_with_bh(bh, PTIMER_POLICY_DEFAULT);
66
+ s->ptimer = ptimer_init(exynos4210_rtc_tick, s, PTIMER_POLICY_DEFAULT);
67
+ ptimer_transaction_begin(s->ptimer);
68
ptimer_set_freq(s->ptimer, RTC_BASE_FREQ);
69
exynos4210_rtc_update_freq(s, 0);
70
+ ptimer_transaction_commit(s->ptimer);
71
72
s->ptimer_1Hz = ptimer_init(exynos4210_rtc_1Hz_tick,
73
s, PTIMER_POLICY_DEFAULT);
74
--
75
2.20.1
76
77
diff view generated by jsdifflib
Deleted patch
1
Switch the cmsdk-apb-watchdog code away from bottom-half based
2
ptimers to the new transaction-based ptimer API. This just requires
3
adding begin/commit calls around the various places that modify the
4
ptimer state, and using the new ptimer_init() function to create the
5
timer.
6
1
7
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
9
Message-id: 20191008171740.9679-21-peter.maydell@linaro.org
10
---
11
hw/watchdog/cmsdk-apb-watchdog.c | 13 +++++++++----
12
1 file changed, 9 insertions(+), 4 deletions(-)
13
14
diff --git a/hw/watchdog/cmsdk-apb-watchdog.c b/hw/watchdog/cmsdk-apb-watchdog.c
15
index XXXXXXX..XXXXXXX 100644
16
--- a/hw/watchdog/cmsdk-apb-watchdog.c
17
+++ b/hw/watchdog/cmsdk-apb-watchdog.c
18
@@ -XXX,XX +XXX,XX @@
19
#include "qemu/log.h"
20
#include "trace.h"
21
#include "qapi/error.h"
22
-#include "qemu/main-loop.h"
23
#include "qemu/module.h"
24
#include "sysemu/watchdog.h"
25
#include "hw/sysbus.h"
26
@@ -XXX,XX +XXX,XX @@ static void cmsdk_apb_watchdog_write(void *opaque, hwaddr offset,
27
* Reset the load value and the current count, and make sure
28
* we're counting.
29
*/
30
+ ptimer_transaction_begin(s->timer);
31
ptimer_set_limit(s->timer, value, 1);
32
ptimer_run(s->timer, 0);
33
+ ptimer_transaction_commit(s->timer);
34
break;
35
case A_WDOGCONTROL:
36
if (s->is_luminary && 0 != (R_WDOGCONTROL_INTEN_MASK & s->control)) {
37
@@ -XXX,XX +XXX,XX @@ static void cmsdk_apb_watchdog_write(void *opaque, hwaddr offset,
38
break;
39
case A_WDOGINTCLR:
40
s->intstatus = 0;
41
+ ptimer_transaction_begin(s->timer);
42
ptimer_set_count(s->timer, ptimer_get_limit(s->timer));
43
+ ptimer_transaction_commit(s->timer);
44
cmsdk_apb_watchdog_update(s);
45
break;
46
case A_WDOGLOCK:
47
@@ -XXX,XX +XXX,XX @@ static void cmsdk_apb_watchdog_reset(DeviceState *dev)
48
s->itop = 0;
49
s->resetstatus = 0;
50
/* Set the limit and the count */
51
+ ptimer_transaction_begin(s->timer);
52
ptimer_set_limit(s->timer, 0xffffffff, 1);
53
ptimer_run(s->timer, 0);
54
+ ptimer_transaction_commit(s->timer);
55
}
56
57
static void cmsdk_apb_watchdog_init(Object *obj)
58
@@ -XXX,XX +XXX,XX @@ static void cmsdk_apb_watchdog_init(Object *obj)
59
static void cmsdk_apb_watchdog_realize(DeviceState *dev, Error **errp)
60
{
61
CMSDKAPBWatchdog *s = CMSDK_APB_WATCHDOG(dev);
62
- QEMUBH *bh;
63
64
if (s->wdogclk_frq == 0) {
65
error_setg(errp,
66
@@ -XXX,XX +XXX,XX @@ static void cmsdk_apb_watchdog_realize(DeviceState *dev, Error **errp)
67
return;
68
}
69
70
- bh = qemu_bh_new(cmsdk_apb_watchdog_tick, s);
71
- s->timer = ptimer_init_with_bh(bh,
72
+ s->timer = ptimer_init(cmsdk_apb_watchdog_tick, s,
73
PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD |
74
PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT |
75
PTIMER_POLICY_NO_IMMEDIATE_RELOAD |
76
PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
77
78
+ ptimer_transaction_begin(s->timer);
79
ptimer_set_freq(s->timer, s->wdogclk_frq);
80
+ ptimer_transaction_commit(s->timer);
81
}
82
83
static const VMStateDescription cmsdk_apb_watchdog_vmstate = {
84
--
85
2.20.1
86
87
diff view generated by jsdifflib
Deleted patch
1
Switch the cmsdk-apb-watchdog code away from bottom-half based
2
ptimers to the new transaction-based ptimer API. This just requires
3
adding begin/commit calls around the various places that modify the
4
ptimer state, and using the new ptimer_init() function to create the
5
timer.
6
1
7
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
9
Message-id: 20191008171740.9679-22-peter.maydell@linaro.org
10
---
11
hw/net/lan9118.c | 11 +++++++----
12
1 file changed, 7 insertions(+), 4 deletions(-)
13
14
diff --git a/hw/net/lan9118.c b/hw/net/lan9118.c
15
index XXXXXXX..XXXXXXX 100644
16
--- a/hw/net/lan9118.c
17
+++ b/hw/net/lan9118.c
18
@@ -XXX,XX +XXX,XX @@
19
#include "hw/ptimer.h"
20
#include "hw/qdev-properties.h"
21
#include "qemu/log.h"
22
-#include "qemu/main-loop.h"
23
#include "qemu/module.h"
24
/* For crc32 */
25
#include <zlib.h>
26
@@ -XXX,XX +XXX,XX @@ static void lan9118_reset(DeviceState *d)
27
s->e2p_data = 0;
28
s->free_timer_start = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) / 40;
29
30
+ ptimer_transaction_begin(s->timer);
31
ptimer_stop(s->timer);
32
ptimer_set_count(s->timer, 0xffff);
33
+ ptimer_transaction_commit(s->timer);
34
s->gpt_cfg = 0xffff;
35
36
s->mac_cr = MAC_CR_PRMS;
37
@@ -XXX,XX +XXX,XX @@ static void lan9118_writel(void *opaque, hwaddr offset,
38
break;
39
case CSR_GPT_CFG:
40
if ((s->gpt_cfg ^ val) & GPT_TIMER_EN) {
41
+ ptimer_transaction_begin(s->timer);
42
if (val & GPT_TIMER_EN) {
43
ptimer_set_count(s->timer, val & 0xffff);
44
ptimer_run(s->timer, 0);
45
@@ -XXX,XX +XXX,XX @@ static void lan9118_writel(void *opaque, hwaddr offset,
46
ptimer_stop(s->timer);
47
ptimer_set_count(s->timer, 0xffff);
48
}
49
+ ptimer_transaction_commit(s->timer);
50
}
51
s->gpt_cfg = val & (GPT_TIMER_EN | 0xffff);
52
break;
53
@@ -XXX,XX +XXX,XX @@ static void lan9118_realize(DeviceState *dev, Error **errp)
54
{
55
SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
56
lan9118_state *s = LAN9118(dev);
57
- QEMUBH *bh;
58
int i;
59
const MemoryRegionOps *mem_ops =
60
s->mode_16bit ? &lan9118_16bit_mem_ops : &lan9118_mem_ops;
61
@@ -XXX,XX +XXX,XX @@ static void lan9118_realize(DeviceState *dev, Error **errp)
62
s->pmt_ctrl = 1;
63
s->txp = &s->tx_packet;
64
65
- bh = qemu_bh_new(lan9118_tick, s);
66
- s->timer = ptimer_init_with_bh(bh, PTIMER_POLICY_DEFAULT);
67
+ s->timer = ptimer_init(lan9118_tick, s, PTIMER_POLICY_DEFAULT);
68
+ ptimer_transaction_begin(s->timer);
69
ptimer_set_freq(s->timer, 10000);
70
ptimer_set_limit(s->timer, 0xffff, 1);
71
+ ptimer_transaction_commit(s->timer);
72
}
73
74
static Property lan9118_properties[] = {
75
--
76
2.20.1
77
78
diff view generated by jsdifflib
Deleted patch
1
The set_swi_errno() function is called to capture the errno
2
from a host system call, so that we can return -1 from the
3
semihosting function and later allow the guest to get a more
4
specific error code with the SYS_ERRNO function. It comes in
5
two versions, one for user-only and one for softmmu. We forgot
6
to capture the errno in the softmmu version; fix the error.
7
1
8
(Semihosting calls directed to gdb are unaffected because
9
they go through a different code path that captures the
10
error return from the gdbstub call in arm_semi_cb() or
11
arm_semi_flen_cb().)
12
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
14
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
15
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
16
Message-id: 20190916141544.17540-2-peter.maydell@linaro.org
17
---
18
target/arm/arm-semi.c | 9 +++++----
19
1 file changed, 5 insertions(+), 4 deletions(-)
20
21
diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c
22
index XXXXXXX..XXXXXXX 100644
23
--- a/target/arm/arm-semi.c
24
+++ b/target/arm/arm-semi.c
25
@@ -XXX,XX +XXX,XX @@ static inline uint32_t set_swi_errno(TaskState *ts, uint32_t code)
26
return code;
27
}
28
#else
29
+static target_ulong syscall_err;
30
+
31
static inline uint32_t set_swi_errno(CPUARMState *env, uint32_t code)
32
{
33
+ if (code == (uint32_t)-1) {
34
+ syscall_err = errno;
35
+ }
36
return code;
37
}
38
39
@@ -XXX,XX +XXX,XX @@ static inline uint32_t set_swi_errno(CPUARMState *env, uint32_t code)
40
41
static target_ulong arm_semi_syscall_len;
42
43
-#if !defined(CONFIG_USER_ONLY)
44
-static target_ulong syscall_err;
45
-#endif
46
-
47
static void arm_semi_cb(CPUState *cs, target_ulong ret, target_ulong err)
48
{
49
ARMCPU *cpu = ARM_CPU(cs);
50
--
51
2.20.1
52
53
diff view generated by jsdifflib
Deleted patch
1
If we fail a semihosting call we should always set the
2
semihosting errno to something; we were failing to do
3
this for some of the "check inputs for sanity" cases.
4
1
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
7
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
8
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
9
Message-id: 20190916141544.17540-3-peter.maydell@linaro.org
10
---
11
target/arm/arm-semi.c | 45 ++++++++++++++++++++++++++-----------------
12
1 file changed, 27 insertions(+), 18 deletions(-)
13
14
diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c
15
index XXXXXXX..XXXXXXX 100644
16
--- a/target/arm/arm-semi.c
17
+++ b/target/arm/arm-semi.c
18
@@ -XXX,XX +XXX,XX @@ static target_ulong arm_gdb_syscall(ARMCPU *cpu, gdb_syscall_complete_cb cb,
19
#define GET_ARG(n) do { \
20
if (is_a64(env)) { \
21
if (get_user_u64(arg ## n, args + (n) * 8)) { \
22
- return -1; \
23
+ errno = EFAULT; \
24
+ return set_swi_errno(ts, -1); \
25
} \
26
} else { \
27
if (get_user_u32(arg ## n, args + (n) * 4)) { \
28
- return -1; \
29
+ errno = EFAULT; \
30
+ return set_swi_errno(ts, -1); \
31
} \
32
} \
33
} while (0)
34
@@ -XXX,XX +XXX,XX @@ target_ulong do_arm_semihosting(CPUARMState *env)
35
GET_ARG(2);
36
s = lock_user_string(arg0);
37
if (!s) {
38
- /* FIXME - should this error code be -TARGET_EFAULT ? */
39
- return (uint32_t)-1;
40
+ errno = EFAULT;
41
+ return set_swi_errno(ts, -1);
42
}
43
if (arg1 >= 12) {
44
unlock_user(s, arg0, 0);
45
- return (uint32_t)-1;
46
+ errno = EINVAL;
47
+ return set_swi_errno(ts, -1);
48
}
49
if (strcmp(s, ":tt") == 0) {
50
int result_fileno = arg1 < 4 ? STDIN_FILENO : STDOUT_FILENO;
51
@@ -XXX,XX +XXX,XX @@ target_ulong do_arm_semihosting(CPUARMState *env)
52
} else {
53
s = lock_user_string(arg0);
54
if (!s) {
55
- /* FIXME - should this error code be -TARGET_EFAULT ? */
56
- return (uint32_t)-1;
57
+ errno = EFAULT;
58
+ return set_swi_errno(ts, -1);
59
}
60
ret = set_swi_errno(ts, remove(s));
61
unlock_user(s, arg0, 0);
62
@@ -XXX,XX +XXX,XX @@ target_ulong do_arm_semihosting(CPUARMState *env)
63
char *s2;
64
s = lock_user_string(arg0);
65
s2 = lock_user_string(arg2);
66
- if (!s || !s2)
67
- /* FIXME - should this error code be -TARGET_EFAULT ? */
68
- ret = (uint32_t)-1;
69
- else
70
+ if (!s || !s2) {
71
+ errno = EFAULT;
72
+ ret = set_swi_errno(ts, -1);
73
+ } else {
74
ret = set_swi_errno(ts, rename(s, s2));
75
+ }
76
if (s2)
77
unlock_user(s2, arg2, 0);
78
if (s)
79
@@ -XXX,XX +XXX,XX @@ target_ulong do_arm_semihosting(CPUARMState *env)
80
} else {
81
s = lock_user_string(arg0);
82
if (!s) {
83
- /* FIXME - should this error code be -TARGET_EFAULT ? */
84
- return (uint32_t)-1;
85
+ errno = EFAULT;
86
+ return set_swi_errno(ts, -1);
87
}
88
ret = set_swi_errno(ts, system(s));
89
unlock_user(s, arg0, 0);
90
@@ -XXX,XX +XXX,XX @@ target_ulong do_arm_semihosting(CPUARMState *env)
91
92
if (output_size > input_size) {
93
/* Not enough space to store command-line arguments. */
94
- return -1;
95
+ errno = E2BIG;
96
+ return set_swi_errno(ts, -1);
97
}
98
99
/* Adjust the command-line length. */
100
if (SET_ARG(1, output_size - 1)) {
101
/* Couldn't write back to argument block */
102
- return -1;
103
+ errno = EFAULT;
104
+ return set_swi_errno(ts, -1);
105
}
106
107
/* Lock the buffer on the ARM side. */
108
output_buffer = lock_user(VERIFY_WRITE, arg0, output_size, 0);
109
if (!output_buffer) {
110
- return -1;
111
+ errno = EFAULT;
112
+ return set_swi_errno(ts, -1);
113
}
114
115
/* Copy the command-line arguments. */
116
@@ -XXX,XX +XXX,XX @@ target_ulong do_arm_semihosting(CPUARMState *env)
117
118
if (copy_from_user(output_buffer, ts->info->arg_start,
119
output_size)) {
120
- status = -1;
121
+ errno = EFAULT;
122
+ status = set_swi_errno(ts, -1);
123
goto out;
124
}
125
126
@@ -XXX,XX +XXX,XX @@ target_ulong do_arm_semihosting(CPUARMState *env)
127
128
if (fail) {
129
/* Couldn't write back to argument block */
130
- return -1;
131
+ errno = EFAULT;
132
+ return set_swi_errno(ts, -1);
133
}
134
}
135
return 0;
136
--
137
2.20.1
138
139
diff view generated by jsdifflib
Deleted patch
1
In arm_gdb_syscall() we have a comment suggesting a race
2
because the syscall completion callback might not happen
3
before the gdb_do_syscallv() call returns. The comment is
4
correct that the callback may not happen but incorrect about
5
the effects. Correct it and note the important caveat that
6
callers must never do any work of any kind after return from
7
arm_gdb_syscall() that depends on its return value.
8
1
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
11
Message-id: 20190916141544.17540-4-peter.maydell@linaro.org
12
---
13
target/arm/arm-semi.c | 19 +++++++++++++++----
14
1 file changed, 15 insertions(+), 4 deletions(-)
15
16
diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c
17
index XXXXXXX..XXXXXXX 100644
18
--- a/target/arm/arm-semi.c
19
+++ b/target/arm/arm-semi.c
20
@@ -XXX,XX +XXX,XX @@ static target_ulong arm_gdb_syscall(ARMCPU *cpu, gdb_syscall_complete_cb cb,
21
gdb_do_syscallv(cb, fmt, va);
22
va_end(va);
23
24
- /* FIXME: we are implicitly relying on the syscall completing
25
- * before this point, which is not guaranteed. We should
26
- * put in an explicit synchronization between this and
27
- * the callback function.
28
+ /*
29
+ * FIXME: in softmmu mode, the gdbstub will schedule our callback
30
+ * to occur, but will not actually call it to complete the syscall
31
+ * until after this function has returned and we are back in the
32
+ * CPU main loop. Therefore callers to this function must not
33
+ * do anything with its return value, because it is not necessarily
34
+ * the result of the syscall, but could just be the old value of X0.
35
+ * The only thing safe to do with this is that the callers of
36
+ * do_arm_semihosting() will write it straight back into X0.
37
+ * (In linux-user mode, the callback will have happened before
38
+ * gdb_do_syscallv() returns.)
39
+ *
40
+ * We should tidy this up so neither this function nor
41
+ * do_arm_semihosting() return a value, so the mistake of
42
+ * doing something with the return value is not possible to make.
43
*/
44
45
return is_a64(env) ? env->xregs[0] : env->regs[0];
46
--
47
2.20.1
48
49
diff view generated by jsdifflib
Deleted patch
1
When we are routing semihosting operations through the gdbstub, the
2
work of sorting out the return value and setting errno if necessary
3
is done by callback functions which are invoked by the gdbstub code.
4
Clean up some ifdeffery in those functions by having them call
5
set_swi_errno() to set the semihosting errno.
6
1
7
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
9
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
10
Message-id: 20190916141544.17540-7-peter.maydell@linaro.org
11
---
12
target/arm/arm-semi.c | 27 ++++++---------------------
13
1 file changed, 6 insertions(+), 21 deletions(-)
14
15
diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c
16
index XXXXXXX..XXXXXXX 100644
17
--- a/target/arm/arm-semi.c
18
+++ b/target/arm/arm-semi.c
19
@@ -XXX,XX +XXX,XX @@ static void arm_semi_cb(CPUState *cs, target_ulong ret, target_ulong err)
20
{
21
ARMCPU *cpu = ARM_CPU(cs);
22
CPUARMState *env = &cpu->env;
23
-#ifdef CONFIG_USER_ONLY
24
- TaskState *ts = cs->opaque;
25
-#endif
26
target_ulong reg0 = is_a64(env) ? env->xregs[0] : env->regs[0];
27
28
if (ret == (target_ulong)-1) {
29
-#ifdef CONFIG_USER_ONLY
30
- ts->swi_errno = err;
31
-#else
32
- syscall_err = err;
33
-#endif
34
+ errno = err;
35
+ set_swi_errno(env, -1);
36
reg0 = ret;
37
} else {
38
/* Fixup syscalls that use nonstardard return conventions. */
39
@@ -XXX,XX +XXX,XX @@ static void arm_semi_flen_cb(CPUState *cs, target_ulong ret, target_ulong err)
40
} else {
41
env->regs[0] = size;
42
}
43
-#ifdef CONFIG_USER_ONLY
44
- ((TaskState *)cs->opaque)->swi_errno = err;
45
-#else
46
- syscall_err = err;
47
-#endif
48
+ errno = err;
49
+ set_swi_errno(env, -1);
50
}
51
52
static int arm_semi_open_guestfd;
53
@@ -XXX,XX +XXX,XX @@ static void arm_semi_open_cb(CPUState *cs, target_ulong ret, target_ulong err)
54
{
55
ARMCPU *cpu = ARM_CPU(cs);
56
CPUARMState *env = &cpu->env;
57
-#ifdef CONFIG_USER_ONLY
58
- TaskState *ts = cs->opaque;
59
-#endif
60
if (ret == (target_ulong)-1) {
61
-#ifdef CONFIG_USER_ONLY
62
- ts->swi_errno = err;
63
-#else
64
- syscall_err = err;
65
-#endif
66
+ errno = err;
67
+ set_swi_errno(env, -1);
68
dealloc_guestfd(arm_semi_open_guestfd);
69
} else {
70
associate_guestfd(arm_semi_open_guestfd, ret);
71
--
72
2.20.1
73
74
diff view generated by jsdifflib
Deleted patch
1
Currently for the semihosting calls which take a file descriptor
2
(SYS_CLOSE, SYS_WRITE, SYS_READ, SYS_ISTTY, SYS_SEEK, SYS_FLEN)
3
we have effectively two implementations, one for real host files
4
and one for when we indirect via the gdbstub. We want to add a
5
third one to deal with the magic :semihosting-features file.
6
1
7
Instead of having a three-way if statement in each of these
8
cases, factor out the implementation of the calls to separate
9
functions which we dispatch to via function pointers selected
10
via the GuestFDType for the guest fd.
11
12
In this commit, we set up the framework for the dispatch,
13
and convert the SYS_CLOSE call to use it.
14
15
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
16
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
17
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
18
Message-id: 20190916141544.17540-8-peter.maydell@linaro.org
19
---
20
target/arm/arm-semi.c | 44 ++++++++++++++++++++++++++++++++++++-------
21
1 file changed, 37 insertions(+), 7 deletions(-)
22
23
diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c
24
index XXXXXXX..XXXXXXX 100644
25
--- a/target/arm/arm-semi.c
26
+++ b/target/arm/arm-semi.c
27
@@ -XXX,XX +XXX,XX @@ static int open_modeflags[12] = {
28
typedef enum GuestFDType {
29
GuestFDUnused = 0,
30
GuestFDHost = 1,
31
+ GuestFDGDB = 2,
32
} GuestFDType;
33
34
/*
35
@@ -XXX,XX +XXX,XX @@ static GuestFD *do_get_guestfd(int guestfd)
36
/*
37
* Associate the specified guest fd (which must have been
38
* allocated via alloc_fd() and not previously used) with
39
- * the specified host fd.
40
+ * the specified host/gdb fd.
41
*/
42
static void associate_guestfd(int guestfd, int hostfd)
43
{
44
GuestFD *gf = do_get_guestfd(guestfd);
45
46
assert(gf);
47
- gf->type = GuestFDHost;
48
+ gf->type = use_gdb_syscalls() ? GuestFDGDB : GuestFDHost;
49
gf->hostfd = hostfd;
50
}
51
52
@@ -XXX,XX +XXX,XX @@ static target_ulong arm_gdb_syscall(ARMCPU *cpu, gdb_syscall_complete_cb cb,
53
return is_a64(env) ? env->xregs[0] : env->regs[0];
54
}
55
56
+/*
57
+ * Types for functions implementing various semihosting calls
58
+ * for specific types of guest file descriptor. These must all
59
+ * do the work and return the required return value for the guest,
60
+ * setting the guest errno if appropriate.
61
+ */
62
+typedef uint32_t sys_closefn(ARMCPU *cpu, GuestFD *gf);
63
+
64
+static uint32_t host_closefn(ARMCPU *cpu, GuestFD *gf)
65
+{
66
+ CPUARMState *env = &cpu->env;
67
+
68
+ return set_swi_errno(env, close(gf->hostfd));
69
+}
70
+
71
+static uint32_t gdb_closefn(ARMCPU *cpu, GuestFD *gf)
72
+{
73
+ return arm_gdb_syscall(cpu, arm_semi_cb, "close,%x", gf->hostfd);
74
+}
75
+
76
+typedef struct GuestFDFunctions {
77
+ sys_closefn *closefn;
78
+} GuestFDFunctions;
79
+
80
+static const GuestFDFunctions guestfd_fns[] = {
81
+ [GuestFDHost] = {
82
+ .closefn = host_closefn,
83
+ },
84
+ [GuestFDGDB] = {
85
+ .closefn = gdb_closefn,
86
+ },
87
+};
88
+
89
/* Read the input value from the argument block; fail the semihosting
90
* call if the memory read fails.
91
*/
92
@@ -XXX,XX +XXX,XX @@ target_ulong do_arm_semihosting(CPUARMState *env)
93
return set_swi_errno(env, -1);
94
}
95
96
- if (use_gdb_syscalls()) {
97
- ret = arm_gdb_syscall(cpu, arm_semi_cb, "close,%x", gf->hostfd);
98
- } else {
99
- ret = set_swi_errno(env, close(gf->hostfd));
100
- }
101
+ ret = guestfd_fns[gf->type].closefn(cpu, gf);
102
dealloc_guestfd(arg0);
103
return ret;
104
case TARGET_SYS_WRITEC:
105
--
106
2.20.1
107
108
diff view generated by jsdifflib
Deleted patch
1
Factor out the implementation of SYS_WRITE via the
2
new function tables.
3
1
4
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
5
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Message-id: 20190916141544.17540-9-peter.maydell@linaro.org
8
---
9
target/arm/arm-semi.c | 51 ++++++++++++++++++++++++++++---------------
10
1 file changed, 33 insertions(+), 18 deletions(-)
11
12
diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c
13
index XXXXXXX..XXXXXXX 100644
14
--- a/target/arm/arm-semi.c
15
+++ b/target/arm/arm-semi.c
16
@@ -XXX,XX +XXX,XX @@ static target_ulong arm_gdb_syscall(ARMCPU *cpu, gdb_syscall_complete_cb cb,
17
* setting the guest errno if appropriate.
18
*/
19
typedef uint32_t sys_closefn(ARMCPU *cpu, GuestFD *gf);
20
+typedef uint32_t sys_writefn(ARMCPU *cpu, GuestFD *gf,
21
+ target_ulong buf, uint32_t len);
22
23
static uint32_t host_closefn(ARMCPU *cpu, GuestFD *gf)
24
{
25
@@ -XXX,XX +XXX,XX @@ static uint32_t host_closefn(ARMCPU *cpu, GuestFD *gf)
26
return set_swi_errno(env, close(gf->hostfd));
27
}
28
29
+static uint32_t host_writefn(ARMCPU *cpu, GuestFD *gf,
30
+ target_ulong buf, uint32_t len)
31
+{
32
+ uint32_t ret;
33
+ CPUARMState *env = &cpu->env;
34
+ char *s = lock_user(VERIFY_READ, buf, len, 1);
35
+ if (!s) {
36
+ /* Return bytes not written on error */
37
+ return len;
38
+ }
39
+ ret = set_swi_errno(env, write(gf->hostfd, s, len));
40
+ unlock_user(s, buf, 0);
41
+ if (ret == (uint32_t)-1) {
42
+ ret = 0;
43
+ }
44
+ /* Return bytes not written */
45
+ return len - ret;
46
+}
47
+
48
static uint32_t gdb_closefn(ARMCPU *cpu, GuestFD *gf)
49
{
50
return arm_gdb_syscall(cpu, arm_semi_cb, "close,%x", gf->hostfd);
51
}
52
53
+static uint32_t gdb_writefn(ARMCPU *cpu, GuestFD *gf,
54
+ target_ulong buf, uint32_t len)
55
+{
56
+ arm_semi_syscall_len = len;
57
+ return arm_gdb_syscall(cpu, arm_semi_cb, "write,%x,%x,%x",
58
+ gf->hostfd, buf, len);
59
+}
60
+
61
typedef struct GuestFDFunctions {
62
sys_closefn *closefn;
63
+ sys_writefn *writefn;
64
} GuestFDFunctions;
65
66
static const GuestFDFunctions guestfd_fns[] = {
67
[GuestFDHost] = {
68
.closefn = host_closefn,
69
+ .writefn = host_writefn,
70
},
71
[GuestFDGDB] = {
72
.closefn = gdb_closefn,
73
+ .writefn = gdb_writefn,
74
},
75
};
76
77
@@ -XXX,XX +XXX,XX @@ target_ulong do_arm_semihosting(CPUARMState *env)
78
return set_swi_errno(env, -1);
79
}
80
81
- if (use_gdb_syscalls()) {
82
- arm_semi_syscall_len = len;
83
- return arm_gdb_syscall(cpu, arm_semi_cb, "write,%x,%x,%x",
84
- gf->hostfd, arg1, len);
85
- } else {
86
- s = lock_user(VERIFY_READ, arg1, len, 1);
87
- if (!s) {
88
- /* Return bytes not written on error */
89
- return len;
90
- }
91
- ret = set_swi_errno(env, write(gf->hostfd, s, len));
92
- unlock_user(s, arg1, 0);
93
- if (ret == (uint32_t)-1) {
94
- ret = 0;
95
- }
96
- /* Return bytes not written */
97
- return len - ret;
98
- }
99
+ return guestfd_fns[gf->type].writefn(cpu, gf, arg1, len);
100
case TARGET_SYS_READ:
101
GET_ARG(0);
102
GET_ARG(1);
103
--
104
2.20.1
105
106
diff view generated by jsdifflib
Deleted patch
1
Factor out the implementation of SYS_READ via the
2
new function tables.
3
1
4
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
5
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
6
Message-id: 20190916141544.17540-10-peter.maydell@linaro.org
7
---
8
target/arm/arm-semi.c | 55 +++++++++++++++++++++++++++----------------
9
1 file changed, 35 insertions(+), 20 deletions(-)
10
11
diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c
12
index XXXXXXX..XXXXXXX 100644
13
--- a/target/arm/arm-semi.c
14
+++ b/target/arm/arm-semi.c
15
@@ -XXX,XX +XXX,XX @@ static target_ulong arm_gdb_syscall(ARMCPU *cpu, gdb_syscall_complete_cb cb,
16
typedef uint32_t sys_closefn(ARMCPU *cpu, GuestFD *gf);
17
typedef uint32_t sys_writefn(ARMCPU *cpu, GuestFD *gf,
18
target_ulong buf, uint32_t len);
19
+typedef uint32_t sys_readfn(ARMCPU *cpu, GuestFD *gf,
20
+ target_ulong buf, uint32_t len);
21
22
static uint32_t host_closefn(ARMCPU *cpu, GuestFD *gf)
23
{
24
@@ -XXX,XX +XXX,XX @@ static uint32_t host_writefn(ARMCPU *cpu, GuestFD *gf,
25
return len - ret;
26
}
27
28
+static uint32_t host_readfn(ARMCPU *cpu, GuestFD *gf,
29
+ target_ulong buf, uint32_t len)
30
+{
31
+ uint32_t ret;
32
+ CPUARMState *env = &cpu->env;
33
+ char *s = lock_user(VERIFY_WRITE, buf, len, 0);
34
+ if (!s) {
35
+ /* return bytes not read */
36
+ return len;
37
+ }
38
+ do {
39
+ ret = set_swi_errno(env, read(gf->hostfd, s, len));
40
+ } while (ret == -1 && errno == EINTR);
41
+ unlock_user(s, buf, len);
42
+ if (ret == (uint32_t)-1) {
43
+ ret = 0;
44
+ }
45
+ /* Return bytes not read */
46
+ return len - ret;
47
+}
48
+
49
static uint32_t gdb_closefn(ARMCPU *cpu, GuestFD *gf)
50
{
51
return arm_gdb_syscall(cpu, arm_semi_cb, "close,%x", gf->hostfd);
52
@@ -XXX,XX +XXX,XX @@ static uint32_t gdb_writefn(ARMCPU *cpu, GuestFD *gf,
53
gf->hostfd, buf, len);
54
}
55
56
+static uint32_t gdb_readfn(ARMCPU *cpu, GuestFD *gf,
57
+ target_ulong buf, uint32_t len)
58
+{
59
+ arm_semi_syscall_len = len;
60
+ return arm_gdb_syscall(cpu, arm_semi_cb, "read,%x,%x,%x",
61
+ gf->hostfd, buf, len);
62
+}
63
+
64
typedef struct GuestFDFunctions {
65
sys_closefn *closefn;
66
sys_writefn *writefn;
67
+ sys_readfn *readfn;
68
} GuestFDFunctions;
69
70
static const GuestFDFunctions guestfd_fns[] = {
71
[GuestFDHost] = {
72
.closefn = host_closefn,
73
.writefn = host_writefn,
74
+ .readfn = host_readfn,
75
},
76
[GuestFDGDB] = {
77
.closefn = gdb_closefn,
78
.writefn = gdb_writefn,
79
+ .readfn = gdb_readfn,
80
},
81
};
82
83
@@ -XXX,XX +XXX,XX @@ target_ulong do_arm_semihosting(CPUARMState *env)
84
return set_swi_errno(env, -1);
85
}
86
87
- if (use_gdb_syscalls()) {
88
- arm_semi_syscall_len = len;
89
- return arm_gdb_syscall(cpu, arm_semi_cb, "read,%x,%x,%x",
90
- gf->hostfd, arg1, len);
91
- } else {
92
- s = lock_user(VERIFY_WRITE, arg1, len, 0);
93
- if (!s) {
94
- /* return bytes not read */
95
- return len;
96
- }
97
- do {
98
- ret = set_swi_errno(env, read(gf->hostfd, s, len));
99
- } while (ret == -1 && errno == EINTR);
100
- unlock_user(s, arg1, len);
101
- if (ret == (uint32_t)-1) {
102
- ret = 0;
103
- }
104
- /* Return bytes not read */
105
- return len - ret;
106
- }
107
+ return guestfd_fns[gf->type].readfn(cpu, gf, arg1, len);
108
case TARGET_SYS_READC:
109
qemu_log_mask(LOG_UNIMP, "%s: SYS_READC not implemented", __func__);
110
return 0;
111
--
112
2.20.1
113
114
diff view generated by jsdifflib
1
From: Joel Stanley <joel@jms.id.au>
1
The armv7m systick timer is a 24-bit decrementing, wrap-on-zero,
2
2
clear-on-write counter. Our current implementation has various
3
The SCU controller on the AST2600 SoC has extra registers. Increase
3
bugs and dubious workarounds in it (for instance see
4
the number of regs of the model and introduce a new field in the class
4
https://bugs.launchpad.net/qemu/+bug/1872237).
5
to customize the MemoryRegion operations depending on the SoC model.
5
6
6
We have an implementation of a simple decrementing counter
7
Signed-off-by: Joel Stanley <joel@jms.id.au>
7
and we put a lot of effort into making sure it handles the
8
Signed-off-by: Cédric Le Goater <clg@kaod.org>
8
interesting corner cases (like "spend a cycle at 0 before
9
Message-id: 20190925143248.10000-4-clg@kaod.org
9
reloading") -- ptimer.
10
[clg: - improved commit log
10
11
- changed vmstate version
11
Rewrite the systick timer to use a ptimer rather than
12
- reworked model integration into new object class
12
a raw QEMU timer.
13
- included AST2600_HPLL_PARAM value ]
13
14
Signed-off-by: Cédric Le Goater <clg@kaod.org>
14
Unfortunately this is a migration compatibility break,
15
which will affect all M-profile boards.
16
17
Among other bugs, this fixes
18
https://bugs.launchpad.net/qemu/+bug/1872237 :
19
now writes to SYST_CVR when the timer is enabled correctly
20
do nothing; when the timer is enabled via SYST_CSR.ENABLE,
21
the ptimer code will (because of POLICY_NO_IMMEDIATE_RELOAD)
22
arrange that after one timer tick the counter is reloaded
23
from SYST_RVR and then counts down from there, as the
24
architecture requires.
25
15
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
26
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
27
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
28
Message-id: 20201015151829.14656-3-peter.maydell@linaro.org
16
---
29
---
17
include/hw/misc/aspeed_scu.h | 7 +-
30
include/hw/timer/armv7m_systick.h | 3 +-
18
hw/misc/aspeed_scu.c | 192 +++++++++++++++++++++++++++++++++--
31
hw/timer/armv7m_systick.c | 124 +++++++++++++-----------------
19
2 files changed, 191 insertions(+), 8 deletions(-)
32
2 files changed, 54 insertions(+), 73 deletions(-)
20
33
21
diff --git a/include/hw/misc/aspeed_scu.h b/include/hw/misc/aspeed_scu.h
34
diff --git a/include/hw/timer/armv7m_systick.h b/include/hw/timer/armv7m_systick.h
22
index XXXXXXX..XXXXXXX 100644
35
index XXXXXXX..XXXXXXX 100644
23
--- a/include/hw/misc/aspeed_scu.h
36
--- a/include/hw/timer/armv7m_systick.h
24
+++ b/include/hw/misc/aspeed_scu.h
37
+++ b/include/hw/timer/armv7m_systick.h
25
@@ -XXX,XX +XXX,XX @@
38
@@ -XXX,XX +XXX,XX @@
26
#define ASPEED_SCU(obj) OBJECT_CHECK(AspeedSCUState, (obj), TYPE_ASPEED_SCU)
39
27
#define TYPE_ASPEED_2400_SCU TYPE_ASPEED_SCU "-ast2400"
40
#include "hw/sysbus.h"
28
#define TYPE_ASPEED_2500_SCU TYPE_ASPEED_SCU "-ast2500"
41
#include "qom/object.h"
29
+#define TYPE_ASPEED_2600_SCU TYPE_ASPEED_SCU "-ast2600"
42
+#include "hw/ptimer.h"
30
43
31
#define ASPEED_SCU_NR_REGS (0x1A8 >> 2)
44
#define TYPE_SYSTICK "armv7m_systick"
32
+#define ASPEED_AST2600_SCU_NR_REGS (0xE20 >> 2)
45
33
46
@@ -XXX,XX +XXX,XX @@ struct SysTickState {
34
typedef struct AspeedSCUState {
47
uint32_t control;
35
/*< private >*/
48
uint32_t reload;
36
@@ -XXX,XX +XXX,XX @@ typedef struct AspeedSCUState {
49
int64_t tick;
37
/*< public >*/
50
- QEMUTimer *timer;
51
+ ptimer_state *ptimer;
38
MemoryRegion iomem;
52
MemoryRegion iomem;
39
53
qemu_irq irq;
40
- uint32_t regs[ASPEED_SCU_NR_REGS];
54
};
41
+ uint32_t regs[ASPEED_AST2600_SCU_NR_REGS];
55
diff --git a/hw/timer/armv7m_systick.c b/hw/timer/armv7m_systick.c
42
uint32_t silicon_rev;
43
uint32_t hw_strap1;
44
uint32_t hw_strap2;
45
@@ -XXX,XX +XXX,XX @@ typedef struct AspeedSCUState {
46
#define AST2400_A1_SILICON_REV 0x02010303U
47
#define AST2500_A0_SILICON_REV 0x04000303U
48
#define AST2500_A1_SILICON_REV 0x04010303U
49
+#define AST2600_A0_SILICON_REV 0x05000303U
50
51
#define ASPEED_IS_AST2500(si_rev) ((((si_rev) >> 24) & 0xff) == 0x04)
52
53
@@ -XXX,XX +XXX,XX @@ typedef struct AspeedSCUClass {
54
const uint32_t *resets;
55
uint32_t (*calc_hpll)(AspeedSCUState *s, uint32_t hpll_reg);
56
uint32_t apb_divider;
57
+ uint32_t nr_regs;
58
+ const MemoryRegionOps *ops;
59
} AspeedSCUClass;
60
61
#define ASPEED_SCU_PROT_KEY 0x1688A8A8
62
diff --git a/hw/misc/aspeed_scu.c b/hw/misc/aspeed_scu.c
63
index XXXXXXX..XXXXXXX 100644
56
index XXXXXXX..XXXXXXX 100644
64
--- a/hw/misc/aspeed_scu.c
57
--- a/hw/timer/armv7m_systick.c
65
+++ b/hw/misc/aspeed_scu.c
58
+++ b/hw/timer/armv7m_systick.c
66
@@ -XXX,XX +XXX,XX @@
59
@@ -XXX,XX +XXX,XX @@ static inline int64_t systick_scale(SysTickState *s)
67
#define BMC_REV TO_REG(0x19C)
60
}
68
#define BMC_DEV_ID TO_REG(0x1A4)
61
}
69
62
70
+#define AST2600_PROT_KEY TO_REG(0x00)
63
-static void systick_reload(SysTickState *s, int reset)
71
+#define AST2600_SILICON_REV TO_REG(0x04)
64
-{
72
+#define AST2600_SILICON_REV2 TO_REG(0x14)
65
- /* The Cortex-M3 Devices Generic User Guide says that "When the
73
+#define AST2600_SYS_RST_CTRL TO_REG(0x40)
66
- * ENABLE bit is set to 1, the counter loads the RELOAD value from the
74
+#define AST2600_SYS_RST_CTRL_CLR TO_REG(0x44)
67
- * SYST RVR register and then counts down". So, we need to check the
75
+#define AST2600_SYS_RST_CTRL2 TO_REG(0x50)
68
- * ENABLE bit before reloading the value.
76
+#define AST2600_SYS_RST_CTRL2_CLR TO_REG(0x54)
69
- */
77
+#define AST2600_CLK_STOP_CTRL TO_REG(0x80)
70
- trace_systick_reload();
78
+#define AST2600_CLK_STOP_CTRL_CLR TO_REG(0x84)
71
-
79
+#define AST2600_CLK_STOP_CTRL2 TO_REG(0x90)
72
- if ((s->control & SYSTICK_ENABLE) == 0) {
80
+#define AST2600_CLK_STOP_CTR2L_CLR TO_REG(0x94)
73
- return;
81
+#define AST2600_HPLL_PARAM TO_REG(0x200)
74
- }
82
+#define AST2600_HPLL_EXT TO_REG(0x204)
75
-
83
+#define AST2600_MPLL_EXT TO_REG(0x224)
76
- if (reset) {
84
+#define AST2600_EPLL_EXT TO_REG(0x244)
77
- s->tick = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
85
+#define AST2600_CLK_SEL TO_REG(0x300)
78
- }
86
+#define AST2600_CLK_SEL2 TO_REG(0x304)
79
- s->tick += (s->reload + 1) * systick_scale(s);
87
+#define AST2600_CLK_SEL3 TO_REG(0x310)
80
- timer_mod(s->timer, s->tick);
88
+#define AST2600_HW_STRAP1 TO_REG(0x500)
81
-}
89
+#define AST2600_HW_STRAP1_CLR TO_REG(0x504)
82
-
90
+#define AST2600_HW_STRAP1_PROT TO_REG(0x508)
83
static void systick_timer_tick(void *opaque)
91
+#define AST2600_HW_STRAP2 TO_REG(0x510)
84
{
92
+#define AST2600_HW_STRAP2_CLR TO_REG(0x514)
85
SysTickState *s = (SysTickState *)opaque;
93
+#define AST2600_HW_STRAP2_PROT TO_REG(0x518)
86
@@ -XXX,XX +XXX,XX @@ static void systick_timer_tick(void *opaque)
94
+#define AST2600_RNG_CTRL TO_REG(0x524)
87
/* Tell the NVIC to pend the SysTick exception */
95
+#define AST2600_RNG_DATA TO_REG(0x540)
88
qemu_irq_pulse(s->irq);
89
}
90
- if (s->reload == 0) {
91
- s->control &= ~SYSTICK_ENABLE;
92
- } else {
93
- systick_reload(s, 0);
94
+ if (ptimer_get_limit(s->ptimer) == 0) {
95
+ /*
96
+ * Timer expiry with SYST_RVR zero disables the timer
97
+ * (but doesn't clear SYST_CSR.ENABLE)
98
+ */
99
+ ptimer_stop(s->ptimer);
100
}
101
}
102
103
@@ -XXX,XX +XXX,XX @@ static MemTxResult systick_read(void *opaque, hwaddr addr, uint64_t *data,
104
s->control &= ~SYSTICK_COUNTFLAG;
105
break;
106
case 0x4: /* SysTick Reload Value. */
107
- val = s->reload;
108
+ val = ptimer_get_limit(s->ptimer);
109
break;
110
case 0x8: /* SysTick Current Value. */
111
- {
112
- int64_t t;
113
-
114
- if ((s->control & SYSTICK_ENABLE) == 0) {
115
- val = 0;
116
- break;
117
- }
118
- t = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
119
- if (t >= s->tick) {
120
- val = 0;
121
- break;
122
- }
123
- val = ((s->tick - (t + 1)) / systick_scale(s)) + 1;
124
- /* The interrupt in triggered when the timer reaches zero.
125
- However the counter is not reloaded until the next clock
126
- tick. This is a hack to return zero during the first tick. */
127
- if (val > s->reload) {
128
- val = 0;
129
- }
130
+ val = ptimer_get_count(s->ptimer);
131
break;
132
- }
133
case 0xc: /* SysTick Calibration Value. */
134
val = 10000;
135
break;
136
@@ -XXX,XX +XXX,XX @@ static MemTxResult systick_write(void *opaque, hwaddr addr,
137
switch (addr) {
138
case 0x0: /* SysTick Control and Status. */
139
{
140
- uint32_t oldval = s->control;
141
+ uint32_t oldval;
142
143
+ ptimer_transaction_begin(s->ptimer);
144
+ oldval = s->control;
145
s->control &= 0xfffffff8;
146
s->control |= value & 7;
96
+
147
+
97
+#define AST2600_CLK TO_REG(0x40)
148
if ((oldval ^ value) & SYSTICK_ENABLE) {
98
+
149
- int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
99
#define SCU_IO_REGION_SIZE 0x1000
150
if (value & SYSTICK_ENABLE) {
100
151
- if (s->tick) {
101
static const uint32_t ast2400_a0_resets[ASPEED_SCU_NR_REGS] = {
152
- s->tick += now;
102
@@ -XXX,XX +XXX,XX @@ static uint64_t aspeed_scu_read(void *opaque, hwaddr offset, unsigned size)
153
- timer_mod(s->timer, s->tick);
103
AspeedSCUState *s = ASPEED_SCU(opaque);
154
- } else {
104
int reg = TO_REG(offset);
155
- systick_reload(s, 1);
105
156
- }
106
- if (reg >= ARRAY_SIZE(s->regs)) {
157
+ /*
107
+ if (reg >= ASPEED_SCU_NR_REGS) {
158
+ * Always reload the period in case board code has
159
+ * changed system_clock_scale. If we ever replace that
160
+ * global with a more sensible API then we might be able
161
+ * to set the period only when it actually changes.
162
+ */
163
+ ptimer_set_period(s->ptimer, systick_scale(s));
164
+ ptimer_run(s->ptimer, 0);
165
} else {
166
- timer_del(s->timer);
167
- s->tick -= now;
168
- if (s->tick < 0) {
169
- s->tick = 0;
170
- }
171
+ ptimer_stop(s->ptimer);
172
}
173
} else if ((oldval ^ value) & SYSTICK_CLKSOURCE) {
174
- /* This is a hack. Force the timer to be reloaded
175
- when the reference clock is changed. */
176
- systick_reload(s, 1);
177
+ ptimer_set_period(s->ptimer, systick_scale(s));
178
}
179
+ ptimer_transaction_commit(s->ptimer);
180
break;
181
}
182
case 0x4: /* SysTick Reload Value. */
183
- s->reload = value;
184
+ ptimer_transaction_begin(s->ptimer);
185
+ ptimer_set_limit(s->ptimer, value & 0xffffff, 0);
186
+ ptimer_transaction_commit(s->ptimer);
187
break;
188
- case 0x8: /* SysTick Current Value. Writes reload the timer. */
189
- systick_reload(s, 1);
190
+ case 0x8: /* SysTick Current Value. */
191
+ /*
192
+ * Writing any value clears SYST_CVR to zero and clears
193
+ * SYST_CSR.COUNTFLAG. The counter will then reload from SYST_RVR
194
+ * on the next clock edge unless SYST_RVR is zero.
195
+ */
196
+ ptimer_transaction_begin(s->ptimer);
197
+ if (ptimer_get_limit(s->ptimer) == 0) {
198
+ ptimer_stop(s->ptimer);
199
+ }
200
+ ptimer_set_count(s->ptimer, 0);
201
s->control &= ~SYSTICK_COUNTFLAG;
202
+ ptimer_transaction_commit(s->ptimer);
203
break;
204
default:
108
qemu_log_mask(LOG_GUEST_ERROR,
205
qemu_log_mask(LOG_GUEST_ERROR,
109
"%s: Out-of-bounds read at offset 0x%" HWADDR_PRIx "\n",
206
@@ -XXX,XX +XXX,XX @@ static void systick_reset(DeviceState *dev)
110
__func__, offset);
207
*/
111
@@ -XXX,XX +XXX,XX @@ static void aspeed_scu_write(void *opaque, hwaddr offset, uint64_t data,
208
assert(system_clock_scale != 0);
112
AspeedSCUState *s = ASPEED_SCU(opaque);
209
113
int reg = TO_REG(offset);
210
+ ptimer_transaction_begin(s->ptimer);
114
211
s->control = 0;
115
- if (reg >= ARRAY_SIZE(s->regs)) {
212
- s->reload = 0;
116
+ if (reg >= ASPEED_SCU_NR_REGS) {
213
- s->tick = 0;
117
qemu_log_mask(LOG_GUEST_ERROR,
214
- timer_del(s->timer);
118
"%s: Out-of-bounds write at offset 0x%" HWADDR_PRIx "\n",
215
+ ptimer_stop(s->ptimer);
119
__func__, offset);
216
+ ptimer_set_count(s->ptimer, 0);
120
@@ -XXX,XX +XXX,XX @@ static void aspeed_scu_reset(DeviceState *dev)
217
+ ptimer_set_limit(s->ptimer, 0, 0);
121
AspeedSCUState *s = ASPEED_SCU(dev);
218
+ ptimer_set_period(s->ptimer, systick_scale(s));
122
AspeedSCUClass *asc = ASPEED_SCU_GET_CLASS(dev);
219
+ ptimer_transaction_commit(s->ptimer);
123
220
}
124
- memcpy(s->regs, asc->resets, sizeof(s->regs));
221
125
+ memcpy(s->regs, asc->resets, asc->nr_regs * 4);
222
static void systick_instance_init(Object *obj)
126
s->regs[SILICON_REV] = s->silicon_rev;
223
@@ -XXX,XX +XXX,XX @@ static void systick_instance_init(Object *obj)
127
s->regs[HW_STRAP1] = s->hw_strap1;
224
static void systick_realize(DeviceState *dev, Error **errp)
128
s->regs[HW_STRAP2] = s->hw_strap2;
129
@@ -XXX,XX +XXX,XX @@ static uint32_t aspeed_silicon_revs[] = {
130
AST2400_A1_SILICON_REV,
131
AST2500_A0_SILICON_REV,
132
AST2500_A1_SILICON_REV,
133
+ AST2600_A0_SILICON_REV,
134
};
135
136
bool is_supported_silicon_rev(uint32_t silicon_rev)
137
@@ -XXX,XX +XXX,XX @@ static void aspeed_scu_realize(DeviceState *dev, Error **errp)
138
{
225
{
139
SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
226
SysTickState *s = SYSTICK(dev);
140
AspeedSCUState *s = ASPEED_SCU(dev);
227
- s->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, systick_timer_tick, s);
141
+ AspeedSCUClass *asc = ASPEED_SCU_GET_CLASS(dev);
228
+ s->ptimer = ptimer_init(systick_timer_tick, s,
142
229
+ PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD |
143
if (!is_supported_silicon_rev(s->silicon_rev)) {
230
+ PTIMER_POLICY_NO_COUNTER_ROUND_DOWN |
144
error_setg(errp, "Unknown silicon revision: 0x%" PRIx32,
231
+ PTIMER_POLICY_NO_IMMEDIATE_RELOAD |
145
@@ -XXX,XX +XXX,XX @@ static void aspeed_scu_realize(DeviceState *dev, Error **errp)
232
+ PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT);
146
return;
233
}
147
}
234
148
235
static const VMStateDescription vmstate_systick = {
149
- memory_region_init_io(&s->iomem, OBJECT(s), &aspeed_scu_ops, s,
236
.name = "armv7m_systick",
150
+ memory_region_init_io(&s->iomem, OBJECT(s), asc->ops, s,
151
TYPE_ASPEED_SCU, SCU_IO_REGION_SIZE);
152
153
sysbus_init_mmio(sbd, &s->iomem);
154
@@ -XXX,XX +XXX,XX @@ static void aspeed_scu_realize(DeviceState *dev, Error **errp)
155
156
static const VMStateDescription vmstate_aspeed_scu = {
157
.name = "aspeed.scu",
158
- .version_id = 1,
237
- .version_id = 1,
159
- .minimum_version_id = 1,
238
- .minimum_version_id = 1,
160
+ .version_id = 2,
239
+ .version_id = 2,
161
+ .minimum_version_id = 2,
240
+ .minimum_version_id = 2,
162
.fields = (VMStateField[]) {
241
.fields = (VMStateField[]) {
163
- VMSTATE_UINT32_ARRAY(regs, AspeedSCUState, ASPEED_SCU_NR_REGS),
242
VMSTATE_UINT32(control, SysTickState),
164
+ VMSTATE_UINT32_ARRAY(regs, AspeedSCUState, ASPEED_AST2600_SCU_NR_REGS),
243
- VMSTATE_UINT32(reload, SysTickState),
244
VMSTATE_INT64(tick, SysTickState),
245
- VMSTATE_TIMER_PTR(timer, SysTickState),
246
+ VMSTATE_PTIMER(ptimer, SysTickState),
165
VMSTATE_END_OF_LIST()
247
VMSTATE_END_OF_LIST()
166
}
248
}
167
};
249
};
168
@@ -XXX,XX +XXX,XX @@ static void aspeed_2400_scu_class_init(ObjectClass *klass, void *data)
169
asc->resets = ast2400_a0_resets;
170
asc->calc_hpll = aspeed_2400_scu_calc_hpll;
171
asc->apb_divider = 2;
172
+ asc->nr_regs = ASPEED_SCU_NR_REGS;
173
+ asc->ops = &aspeed_scu_ops;
174
}
175
176
static const TypeInfo aspeed_2400_scu_info = {
177
@@ -XXX,XX +XXX,XX @@ static void aspeed_2500_scu_class_init(ObjectClass *klass, void *data)
178
asc->resets = ast2500_a1_resets;
179
asc->calc_hpll = aspeed_2500_scu_calc_hpll;
180
asc->apb_divider = 4;
181
+ asc->nr_regs = ASPEED_SCU_NR_REGS;
182
+ asc->ops = &aspeed_scu_ops;
183
}
184
185
static const TypeInfo aspeed_2500_scu_info = {
186
@@ -XXX,XX +XXX,XX @@ static const TypeInfo aspeed_2500_scu_info = {
187
.class_init = aspeed_2500_scu_class_init,
188
};
189
190
+static uint64_t aspeed_ast2600_scu_read(void *opaque, hwaddr offset,
191
+ unsigned size)
192
+{
193
+ AspeedSCUState *s = ASPEED_SCU(opaque);
194
+ int reg = TO_REG(offset);
195
+
196
+ if (reg >= ASPEED_AST2600_SCU_NR_REGS) {
197
+ qemu_log_mask(LOG_GUEST_ERROR,
198
+ "%s: Out-of-bounds read at offset 0x%" HWADDR_PRIx "\n",
199
+ __func__, offset);
200
+ return 0;
201
+ }
202
+
203
+ switch (reg) {
204
+ case AST2600_HPLL_EXT:
205
+ case AST2600_EPLL_EXT:
206
+ case AST2600_MPLL_EXT:
207
+ /* PLLs are always "locked" */
208
+ return s->regs[reg] | BIT(31);
209
+ case AST2600_RNG_DATA:
210
+ /*
211
+ * On hardware, RNG_DATA works regardless of the state of the
212
+ * enable bit in RNG_CTRL
213
+ *
214
+ * TODO: Check this is true for ast2600
215
+ */
216
+ s->regs[AST2600_RNG_DATA] = aspeed_scu_get_random();
217
+ break;
218
+ }
219
+
220
+ return s->regs[reg];
221
+}
222
+
223
+static void aspeed_ast2600_scu_write(void *opaque, hwaddr offset, uint64_t data,
224
+ unsigned size)
225
+{
226
+ AspeedSCUState *s = ASPEED_SCU(opaque);
227
+ int reg = TO_REG(offset);
228
+
229
+ if (reg >= ASPEED_AST2600_SCU_NR_REGS) {
230
+ qemu_log_mask(LOG_GUEST_ERROR,
231
+ "%s: Out-of-bounds write at offset 0x%" HWADDR_PRIx "\n",
232
+ __func__, offset);
233
+ return;
234
+ }
235
+
236
+ if (reg > PROT_KEY && !s->regs[PROT_KEY]) {
237
+ qemu_log_mask(LOG_GUEST_ERROR, "%s: SCU is locked!\n", __func__);
238
+ }
239
+
240
+ trace_aspeed_scu_write(offset, size, data);
241
+
242
+ switch (reg) {
243
+ case AST2600_PROT_KEY:
244
+ s->regs[reg] = (data == ASPEED_SCU_PROT_KEY) ? 1 : 0;
245
+ return;
246
+ case AST2600_HW_STRAP1:
247
+ case AST2600_HW_STRAP2:
248
+ if (s->regs[reg + 2]) {
249
+ return;
250
+ }
251
+ /* fall through */
252
+ case AST2600_SYS_RST_CTRL:
253
+ case AST2600_SYS_RST_CTRL2:
254
+ /* W1S (Write 1 to set) registers */
255
+ s->regs[reg] |= data;
256
+ return;
257
+ case AST2600_SYS_RST_CTRL_CLR:
258
+ case AST2600_SYS_RST_CTRL2_CLR:
259
+ case AST2600_HW_STRAP1_CLR:
260
+ case AST2600_HW_STRAP2_CLR:
261
+ /* W1C (Write 1 to clear) registers */
262
+ s->regs[reg] &= ~data;
263
+ return;
264
+
265
+ case AST2600_RNG_DATA:
266
+ case AST2600_SILICON_REV:
267
+ case AST2600_SILICON_REV2:
268
+ /* Add read only registers here */
269
+ qemu_log_mask(LOG_GUEST_ERROR,
270
+ "%s: Write to read-only offset 0x%" HWADDR_PRIx "\n",
271
+ __func__, offset);
272
+ return;
273
+ }
274
+
275
+ s->regs[reg] = data;
276
+}
277
+
278
+static const MemoryRegionOps aspeed_ast2600_scu_ops = {
279
+ .read = aspeed_ast2600_scu_read,
280
+ .write = aspeed_ast2600_scu_write,
281
+ .endianness = DEVICE_LITTLE_ENDIAN,
282
+ .valid.min_access_size = 4,
283
+ .valid.max_access_size = 4,
284
+ .valid.unaligned = false,
285
+};
286
+
287
+static const uint32_t ast2600_a0_resets[ASPEED_AST2600_SCU_NR_REGS] = {
288
+ [AST2600_SILICON_REV] = AST2600_SILICON_REV,
289
+ [AST2600_SILICON_REV2] = AST2600_SILICON_REV,
290
+ [AST2600_SYS_RST_CTRL] = 0xF7CFFEDC | 0x100,
291
+ [AST2600_SYS_RST_CTRL2] = 0xFFFFFFFC,
292
+ [AST2600_CLK_STOP_CTRL] = 0xEFF43E8B,
293
+ [AST2600_CLK_STOP_CTRL2] = 0xFFF0FFF0,
294
+ [AST2600_HPLL_PARAM] = 0x1000405F,
295
+};
296
+
297
+static void aspeed_ast2600_scu_reset(DeviceState *dev)
298
+{
299
+ AspeedSCUState *s = ASPEED_SCU(dev);
300
+ AspeedSCUClass *asc = ASPEED_SCU_GET_CLASS(dev);
301
+
302
+ memcpy(s->regs, asc->resets, asc->nr_regs * 4);
303
+
304
+ s->regs[AST2600_SILICON_REV] = s->silicon_rev;
305
+ s->regs[AST2600_SILICON_REV2] = s->silicon_rev;
306
+ s->regs[AST2600_HW_STRAP1] = s->hw_strap1;
307
+ s->regs[AST2600_HW_STRAP2] = s->hw_strap2;
308
+ s->regs[PROT_KEY] = s->hw_prot_key;
309
+}
310
+
311
+static void aspeed_2600_scu_class_init(ObjectClass *klass, void *data)
312
+{
313
+ DeviceClass *dc = DEVICE_CLASS(klass);
314
+ AspeedSCUClass *asc = ASPEED_SCU_CLASS(klass);
315
+
316
+ dc->desc = "ASPEED 2600 System Control Unit";
317
+ dc->reset = aspeed_ast2600_scu_reset;
318
+ asc->resets = ast2600_a0_resets;
319
+ asc->calc_hpll = aspeed_2500_scu_calc_hpll; /* No change since AST2500 */
320
+ asc->apb_divider = 4;
321
+ asc->nr_regs = ASPEED_AST2600_SCU_NR_REGS;
322
+ asc->ops = &aspeed_ast2600_scu_ops;
323
+}
324
+
325
+static const TypeInfo aspeed_2600_scu_info = {
326
+ .name = TYPE_ASPEED_2600_SCU,
327
+ .parent = TYPE_ASPEED_SCU,
328
+ .instance_size = sizeof(AspeedSCUState),
329
+ .class_init = aspeed_2600_scu_class_init,
330
+};
331
+
332
static void aspeed_scu_register_types(void)
333
{
334
type_register_static(&aspeed_scu_info);
335
type_register_static(&aspeed_2400_scu_info);
336
type_register_static(&aspeed_2500_scu_info);
337
+ type_register_static(&aspeed_2600_scu_info);
338
}
339
340
type_init(aspeed_scu_register_types);
341
--
250
--
342
2.20.1
251
2.20.1
343
252
344
253
diff view generated by jsdifflib