1
Last minute pullreq for arm related patches; quite large because
1
Hi; here's the latest target-arm queue. Mostly this is refactoring
2
there were several series that only just made it through code review
2
and cleanup type patches.
3
in time.
4
3
5
thanks
4
thanks
6
-- PMM
5
-- PMM
7
6
8
The following changes since commit 091e3e3dbc499d84c004e1c50bc9870af37f6e99:
7
The following changes since commit c60be6e3e38cb36dc66129e757ec4b34152232be:
9
8
10
Merge remote-tracking branch 'remotes/ericb/tags/pull-bitmaps-2020-10-26' into staging (2020-10-26 22:36:35 +0000)
9
Merge tag 'pull-sp-20231025' of https://gitlab.com/rth7680/qemu into staging (2023-10-27 09:43:53 +0900)
11
10
12
are available in the Git repository at:
11
are available in the Git repository at:
13
12
14
https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20201027-1
13
https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20231027
15
14
16
for you to fetch changes up to 32bd322a0134ed89db00f2b9b3894982db3dedcb:
15
for you to fetch changes up to df93de987f423a0ed918c425f5dbd9a25d3c6229:
17
16
18
hw/timer/armv7m_systick: Rewrite to use ptimers (2020-10-27 11:15:31 +0000)
17
hw/net/cadence_gem: enforce 32 bits variable size for CRC (2023-10-27 15:27:06 +0100)
19
18
20
----------------------------------------------------------------
19
----------------------------------------------------------------
21
target-arm queue:
20
target-arm queue:
22
* raspi: add model of cprman clock manager
21
* Correct minor errors in Cortex-A710 definition
23
* sbsa-ref: add an SBSA generic watchdog device
22
* Implement Neoverse N2 CPU model
24
* arm/trace: Fix hex printing
23
* Refactor feature test functions out into separate header
25
* raspi: Add models of Pi 3 model A+, Pi Zero and Pi A+
24
* Fix syndrome for FGT traps on ERET
26
* hw/arm/smmuv3: Set the restoration priority of the vSMMUv3 explicitly
25
* Remove 'hw/arm/boot.h' includes from various header files
27
* Nuvoton NPCM7xx: Add USB, RNG, GPIO and watchdog support
26
* pxa2xx: Refactoring/cleanup
28
* hw/arm: fix min_cpus for xlnx-versal-virt platform
27
* Avoid using 'first_cpu' when first ARM CPU is reachable
29
* hw/arm/highbank: Silence warnings about missing fallthrough statements
28
* misc/led: LED state is set opposite of what is expected
30
* linux-user: Support Aarch64 BTI
29
* hw/net/cadence_gen: clean up to use FIELD macros
31
* Armv7M systick: fix corner case bugs by rewriting to use ptimer
30
* hw/net/cadence_gem: perform PHY access on write only
31
* hw/net/cadence_gem: enforce 32 bits variable size for CRC
32
32
33
----------------------------------------------------------------
33
----------------------------------------------------------------
34
Dr. David Alan Gilbert (1):
34
Glenn Miles (1):
35
arm/trace: Fix hex printing
35
misc/led: LED state is set opposite of what is expected
36
36
37
Hao Wu (1):
37
Luc Michel (11):
38
hw/timer: Adding watchdog for NPCM7XX Timer.
38
hw/net/cadence_gem: use REG32 macro for register definitions
39
hw/net/cadence_gem: use FIELD for screening registers
40
hw/net/cadence_gem: use FIELD to describe NWCTRL register fields
41
hw/net/cadence_gem: use FIELD to describe NWCFG register fields
42
hw/net/cadence_gem: use FIELD to describe DMACFG register fields
43
hw/net/cadence_gem: use FIELD to describe [TX|RX]STATUS register fields
44
hw/net/cadence_gem: use FIELD to describe IRQ register fields
45
hw/net/cadence_gem: use FIELD to describe DESCONF6 register fields
46
hw/net/cadence_gem: use FIELD to describe PHYMNTNC register fields
47
hw/net/cadence_gem: perform PHY access on write only
48
hw/net/cadence_gem: enforce 32 bits variable size for CRC
39
49
40
Havard Skinnemoen (4):
50
Peter Maydell (9):
41
Move npcm7xx_timer_reached_zero call out of npcm7xx_timer_pause
51
target/arm: Correct minor errors in Cortex-A710 definition
42
hw/misc: Add npcm7xx random number generator
52
target/arm: Implement Neoverse N2 CPU model
43
hw/arm/npcm7xx: Add EHCI and OHCI controllers
53
target/arm: Move feature test functions to their own header
44
hw/gpio: Add GPIO model for Nuvoton NPCM7xx
54
target/arm: Move ID_AA64MMFR1 and ID_AA64MMFR2 tests together
55
target/arm: Move ID_AA64MMFR0 tests up to before MMFR1 and MMFR2
56
target/arm: Move ID_AA64ISAR* test functions together
57
target/arm: Move ID_AA64PFR* tests together
58
target/arm: Move ID_AA64DFR* feature tests together
59
target/arm: Fix syndrome for FGT traps on ERET
45
60
46
Luc Michel (14):
61
Philippe Mathieu-Daudé (20):
47
hw/core/clock: provide the VMSTATE_ARRAY_CLOCK macro
62
hw/arm/allwinner-a10: Remove 'hw/arm/boot.h' from header
48
hw/core/clock: trace clock values in Hz instead of ns
63
hw/arm/allwinner-h3: Remove 'hw/arm/boot.h' from header
49
hw/arm/raspi: fix CPRMAN base address
64
hw/arm/allwinner-r40: Remove 'hw/arm/boot.h' from header
50
hw/arm/raspi: add a skeleton implementation of the CPRMAN
65
hw/arm/fsl-imx25: Remove 'hw/arm/boot.h' from header
51
hw/misc/bcm2835_cprman: add a PLL skeleton implementation
66
hw/arm/fsl-imx31: Remove 'hw/arm/boot.h' from header
52
hw/misc/bcm2835_cprman: implement PLLs behaviour
67
hw/arm/fsl-imx6: Remove 'hw/arm/boot.h' from header
53
hw/misc/bcm2835_cprman: add a PLL channel skeleton implementation
68
hw/arm/fsl-imx6ul: Remove 'hw/arm/boot.h' from header
54
hw/misc/bcm2835_cprman: implement PLL channels behaviour
69
hw/arm/fsl-imx7: Remove 'hw/arm/boot.h' from header
55
hw/misc/bcm2835_cprman: add a clock mux skeleton implementation
70
hw/arm/xlnx-versal: Remove 'hw/arm/boot.h' from header
56
hw/misc/bcm2835_cprman: implement clock mux behaviour
71
hw/arm/xlnx-zynqmp: Remove 'hw/arm/boot.h' from header
57
hw/misc/bcm2835_cprman: add the DSI0HSCK multiplexer
72
hw/sd/pxa2xx: Realize sysbus device before accessing it
58
hw/misc/bcm2835_cprman: add sane reset values to the registers
73
hw/sd/pxa2xx: Do not open-code sysbus_create_simple()
59
hw/char/pl011: add a clock input
74
hw/pcmcia/pxa2xx: Realize sysbus device before accessing it
60
hw/arm/bcm2835_peripherals: connect the UART clock
75
hw/pcmcia/pxa2xx: Do not open-code sysbus_create_simple()
76
hw/pcmcia/pxa2xx: Inline pxa2xx_pcmcia_init()
77
hw/intc/pxa2xx: Convert to Resettable interface
78
hw/intc/pxa2xx: Pass CPU reference using QOM link property
79
hw/intc/pxa2xx: Factor pxa2xx_pic_realize() out of pxa2xx_pic_init()
80
hw/arm/pxa2xx: Realize PXA2XX_I2C device before accessing it
81
hw/arm: Avoid using 'first_cpu' when first ARM CPU is reachable
61
82
62
Pavel Dovgalyuk (1):
83
docs/system/arm/virt.rst | 1 +
63
hw/arm: fix min_cpus for xlnx-versal-virt platform
84
bsd-user/arm/target_arch.h | 1 +
85
include/hw/arm/allwinner-a10.h | 1 -
86
include/hw/arm/allwinner-h3.h | 1 -
87
include/hw/arm/allwinner-r40.h | 1 -
88
include/hw/arm/fsl-imx25.h | 1 -
89
include/hw/arm/fsl-imx31.h | 1 -
90
include/hw/arm/fsl-imx6.h | 1 -
91
include/hw/arm/fsl-imx6ul.h | 1 -
92
include/hw/arm/fsl-imx7.h | 1 -
93
include/hw/arm/pxa.h | 2 -
94
include/hw/arm/xlnx-versal.h | 1 -
95
include/hw/arm/xlnx-zynqmp.h | 1 -
96
linux-user/aarch64/target_prctl.h | 2 +
97
target/arm/cpu-features.h | 994 ++++++++++++++++++++++++++++++++++++++
98
target/arm/cpu.h | 971 -------------------------------------
99
target/arm/internals.h | 1 +
100
target/arm/tcg/translate.h | 2 +-
101
hw/arm/armv7m.c | 1 +
102
hw/arm/bananapi_m2u.c | 3 +-
103
hw/arm/cubieboard.c | 1 +
104
hw/arm/exynos4_boards.c | 7 +-
105
hw/arm/imx25_pdk.c | 1 +
106
hw/arm/kzm.c | 1 +
107
hw/arm/mcimx6ul-evk.c | 1 +
108
hw/arm/mcimx7d-sabre.c | 1 +
109
hw/arm/orangepi.c | 3 +-
110
hw/arm/pxa2xx.c | 17 +-
111
hw/arm/pxa2xx_pic.c | 38 +-
112
hw/arm/realview.c | 2 +-
113
hw/arm/sabrelite.c | 1 +
114
hw/arm/sbsa-ref.c | 1 +
115
hw/arm/virt.c | 1 +
116
hw/arm/xilinx_zynq.c | 2 +-
117
hw/arm/xlnx-versal-virt.c | 1 +
118
hw/arm/xlnx-zcu102.c | 1 +
119
hw/intc/armv7m_nvic.c | 1 +
120
hw/misc/led.c | 2 +-
121
hw/net/cadence_gem.c | 884 ++++++++++++++++++---------------
122
hw/pcmcia/pxa2xx.c | 15 -
123
hw/sd/pxa2xx_mmci.c | 7 +-
124
linux-user/aarch64/cpu_loop.c | 1 +
125
linux-user/aarch64/signal.c | 1 +
126
linux-user/arm/signal.c | 1 +
127
linux-user/elfload.c | 4 +
128
linux-user/mmap.c | 4 +
129
target/arm/arch_dump.c | 1 +
130
target/arm/cpu.c | 1 +
131
target/arm/cpu64.c | 1 +
132
target/arm/debug_helper.c | 1 +
133
target/arm/gdbstub.c | 1 +
134
target/arm/helper.c | 1 +
135
target/arm/kvm64.c | 1 +
136
target/arm/machine.c | 1 +
137
target/arm/ptw.c | 1 +
138
target/arm/tcg/cpu64.c | 115 ++++-
139
target/arm/tcg/hflags.c | 1 +
140
target/arm/tcg/m_helper.c | 1 +
141
target/arm/tcg/op_helper.c | 1 +
142
target/arm/tcg/pauth_helper.c | 1 +
143
target/arm/tcg/tlb_helper.c | 1 +
144
target/arm/tcg/translate-a64.c | 4 +-
145
target/arm/vfp_helper.c | 1 +
146
63 files changed, 1702 insertions(+), 1419 deletions(-)
147
create mode 100644 target/arm/cpu-features.h
64
148
65
Peter Maydell (2):
66
hw/core/ptimer: Support ptimer being disabled by timer callback
67
hw/timer/armv7m_systick: Rewrite to use ptimers
68
69
Philippe Mathieu-Daudé (10):
70
linux-user/elfload: Avoid leaking interp_name using GLib memory API
71
hw/arm/bcm2836: Restrict BCM283XInfo declaration to C source
72
hw/arm/bcm2836: QOM'ify more by adding class_init() to each SoC type
73
hw/arm/bcm2836: Introduce BCM283XClass::core_count
74
hw/arm/bcm2836: Only provide "enabled-cpus" property to multicore SoCs
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+
80
81
Richard Henderson (11):
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
93
94
Shashi Mallela (2):
95
hw/watchdog: Implement SBSA watchdog device
96
hw/arm/sbsa-ref: add SBSA watchdog device
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
Deleted patch
1
From: Richard Henderson <richard.henderson@linaro.org>
2
1
3
The kernel sets btype for the signal handler as if for a call.
4
5
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
6
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
7
Message-id: 20201021173749.111103-2-richard.henderson@linaro.org
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
---
10
linux-user/aarch64/signal.c | 10 ++++++++--
11
1 file changed, 8 insertions(+), 2 deletions(-)
12
13
diff --git a/linux-user/aarch64/signal.c b/linux-user/aarch64/signal.c
14
index XXXXXXX..XXXXXXX 100644
15
--- a/linux-user/aarch64/signal.c
16
+++ b/linux-user/aarch64/signal.c
17
@@ -XXX,XX +XXX,XX @@ static void target_setup_frame(int usig, struct target_sigaction *ka,
18
+ offsetof(struct target_rt_frame_record, tramp);
19
}
20
env->xregs[0] = usig;
21
- env->xregs[31] = frame_addr;
22
env->xregs[29] = frame_addr + fr_ofs;
23
- env->pc = ka->_sa_handler;
24
env->xregs[30] = return_addr;
25
+ env->xregs[31] = frame_addr;
26
+ env->pc = ka->_sa_handler;
27
+
28
+ /* Invoke the signal handler as if by indirect call. */
29
+ if (cpu_isar_feature(aa64_bti, env_archcpu(env))) {
30
+ env->btype = 2;
31
+ }
32
+
33
if (info) {
34
tswap_siginfo(&frame->info, info);
35
env->xregs[1] = frame_addr + offsetof(struct target_rt_sigframe, info);
36
--
37
2.20.1
38
39
diff view generated by jsdifflib
1
The armv7m systick timer is a 24-bit decrementing, wrap-on-zero,
1
Correct a couple of minor errors in the Cortex-A710 definition:
2
clear-on-write counter. Our current implementation has various
2
* ID_AA64DFR0_EL1.DebugVer is 9 (indicating Armv8.4 debug architecture)
3
bugs and dubious workarounds in it (for instance see
3
* ID_AA64ISAR1_EL1.APA is 5 (indicating more PAuth support)
4
https://bugs.launchpad.net/qemu/+bug/1872237).
4
* there is an IMPDEF CPUCFR_EL1, like that on the Neoverse-N1
5
5
6
We have an implementation of a simple decrementing counter
6
Fixes: e3d45c0a89576 ("target/arm: Implement cortex-a710")
7
and we put a lot of effort into making sure it handles the
7
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
interesting corner cases (like "spend a cycle at 0 before
8
Tested-by: Marcin Juszkiewicz <marcin.juszkiewicz@linaro.org>
9
reloading") -- ptimer.
9
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
10
Message-id: 20230915185453.1871167-2-peter.maydell@linaro.org
11
---
12
target/arm/tcg/cpu64.c | 11 +++++++++--
13
1 file changed, 9 insertions(+), 2 deletions(-)
10
14
11
Rewrite the systick timer to use a ptimer rather than
15
diff --git a/target/arm/tcg/cpu64.c b/target/arm/tcg/cpu64.c
12
a raw QEMU timer.
13
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
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
29
---
30
include/hw/timer/armv7m_systick.h | 3 +-
31
hw/timer/armv7m_systick.c | 124 +++++++++++++-----------------
32
2 files changed, 54 insertions(+), 73 deletions(-)
33
34
diff --git a/include/hw/timer/armv7m_systick.h b/include/hw/timer/armv7m_systick.h
35
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
36
--- a/include/hw/timer/armv7m_systick.h
17
--- a/target/arm/tcg/cpu64.c
37
+++ b/include/hw/timer/armv7m_systick.h
18
+++ b/target/arm/tcg/cpu64.c
38
@@ -XXX,XX +XXX,XX @@
19
@@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo cortex_a710_cp_reginfo[] = {
39
20
{ .name = "CPUPFR_EL3", .state = ARM_CP_STATE_AA64,
40
#include "hw/sysbus.h"
21
.opc0 = 3, .opc1 = 6, .crn = 15, .crm = 8, .opc2 = 6,
41
#include "qom/object.h"
22
.access = PL3_RW, .type = ARM_CP_CONST, .resetvalue = 0 },
42
+#include "hw/ptimer.h"
23
+ /*
43
24
+ * Report CPUCFR_EL1.SCU as 1, as we do not implement the DSU
44
#define TYPE_SYSTICK "armv7m_systick"
25
+ * (and in particular its system registers).
45
26
+ */
46
@@ -XXX,XX +XXX,XX @@ struct SysTickState {
27
+ { .name = "CPUCFR_EL1", .state = ARM_CP_STATE_AA64,
47
uint32_t control;
28
+ .opc0 = 3, .opc1 = 0, .crn = 15, .crm = 0, .opc2 = 0,
48
uint32_t reload;
29
+ .access = PL1_R, .type = ARM_CP_CONST, .resetvalue = 4 },
49
int64_t tick;
30
50
- QEMUTimer *timer;
31
/*
51
+ ptimer_state *ptimer;
32
* Stub RAMINDEX, as we don't actually implement caches, BTB,
52
MemoryRegion iomem;
33
@@ -XXX,XX +XXX,XX @@ static void aarch64_a710_initfn(Object *obj)
53
qemu_irq irq;
34
cpu->isar.id_aa64pfr0 = 0x1201111120111112ull; /* GIC filled in later */
54
};
35
cpu->isar.id_aa64pfr1 = 0x0000000000000221ull;
55
diff --git a/hw/timer/armv7m_systick.c b/hw/timer/armv7m_systick.c
36
cpu->isar.id_aa64zfr0 = 0x0000110100110021ull; /* with Crypto */
56
index XXXXXXX..XXXXXXX 100644
37
- cpu->isar.id_aa64dfr0 = 0x000011f010305611ull;
57
--- a/hw/timer/armv7m_systick.c
38
+ cpu->isar.id_aa64dfr0 = 0x000011f010305619ull;
58
+++ b/hw/timer/armv7m_systick.c
39
cpu->isar.id_aa64dfr1 = 0;
59
@@ -XXX,XX +XXX,XX @@ static inline int64_t systick_scale(SysTickState *s)
40
cpu->id_aa64afr0 = 0;
60
}
41
cpu->id_aa64afr1 = 0;
61
}
42
cpu->isar.id_aa64isar0 = 0x0221111110212120ull; /* with Crypto */
62
43
- cpu->isar.id_aa64isar1 = 0x0010111101211032ull;
63
-static void systick_reload(SysTickState *s, int reset)
44
+ cpu->isar.id_aa64isar1 = 0x0010111101211052ull;
64
-{
45
cpu->isar.id_aa64mmfr0 = 0x0000022200101122ull;
65
- /* The Cortex-M3 Devices Generic User Guide says that "When the
46
cpu->isar.id_aa64mmfr1 = 0x0000000010212122ull;
66
- * ENABLE bit is set to 1, the counter loads the RELOAD value from the
47
cpu->isar.id_aa64mmfr2 = 0x1221011110101011ull;
67
- * SYST RVR register and then counts down". So, we need to check the
68
- * ENABLE bit before reloading the value.
69
- */
70
- trace_systick_reload();
71
-
72
- if ((s->control & SYSTICK_ENABLE) == 0) {
73
- return;
74
- }
75
-
76
- if (reset) {
77
- s->tick = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
78
- }
79
- s->tick += (s->reload + 1) * systick_scale(s);
80
- timer_mod(s->timer, s->tick);
81
-}
82
-
83
static void systick_timer_tick(void *opaque)
84
{
85
SysTickState *s = (SysTickState *)opaque;
86
@@ -XXX,XX +XXX,XX @@ static void systick_timer_tick(void *opaque)
87
/* Tell the NVIC to pend the SysTick exception */
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;
147
+
148
if ((oldval ^ value) & SYSTICK_ENABLE) {
149
- int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
150
if (value & SYSTICK_ENABLE) {
151
- if (s->tick) {
152
- s->tick += now;
153
- timer_mod(s->timer, s->tick);
154
- } else {
155
- systick_reload(s, 1);
156
- }
157
+ /*
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:
205
qemu_log_mask(LOG_GUEST_ERROR,
206
@@ -XXX,XX +XXX,XX @@ static void systick_reset(DeviceState *dev)
207
*/
208
assert(system_clock_scale != 0);
209
210
+ ptimer_transaction_begin(s->ptimer);
211
s->control = 0;
212
- s->reload = 0;
213
- s->tick = 0;
214
- timer_del(s->timer);
215
+ ptimer_stop(s->ptimer);
216
+ ptimer_set_count(s->ptimer, 0);
217
+ ptimer_set_limit(s->ptimer, 0, 0);
218
+ ptimer_set_period(s->ptimer, systick_scale(s));
219
+ ptimer_transaction_commit(s->ptimer);
220
}
221
222
static void systick_instance_init(Object *obj)
223
@@ -XXX,XX +XXX,XX @@ static void systick_instance_init(Object *obj)
224
static void systick_realize(DeviceState *dev, Error **errp)
225
{
226
SysTickState *s = SYSTICK(dev);
227
- s->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, systick_timer_tick, s);
228
+ s->ptimer = ptimer_init(systick_timer_tick, s,
229
+ PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD |
230
+ PTIMER_POLICY_NO_COUNTER_ROUND_DOWN |
231
+ PTIMER_POLICY_NO_IMMEDIATE_RELOAD |
232
+ PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT);
233
}
234
235
static const VMStateDescription vmstate_systick = {
236
.name = "armv7m_systick",
237
- .version_id = 1,
238
- .minimum_version_id = 1,
239
+ .version_id = 2,
240
+ .minimum_version_id = 2,
241
.fields = (VMStateField[]) {
242
VMSTATE_UINT32(control, SysTickState),
243
- VMSTATE_UINT32(reload, SysTickState),
244
VMSTATE_INT64(tick, SysTickState),
245
- VMSTATE_TIMER_PTR(timer, SysTickState),
246
+ VMSTATE_PTIMER(ptimer, SysTickState),
247
VMSTATE_END_OF_LIST()
248
}
249
};
250
--
48
--
251
2.20.1
49
2.34.1
252
50
253
51
diff view generated by jsdifflib
1
From: Shashi Mallela <shashi.mallela@linaro.org>
1
Implement a model of the Neoverse N2 CPU. This is an Armv9.0-A
2
processor very similar to the Cortex-A710. The differences are:
3
* no FEAT_EVT
4
* FEAT_DGH (data gathering hint)
5
* FEAT_NV (not yet implemented in QEMU)
6
* Statistical Profiling Extension (not implemented in QEMU)
7
* 48 bit physical address range, not 40
8
* CTR_EL0.DIC = 1 (no explicit icache cleaning needed)
9
* PMCR_EL0.N = 6 (always 6 PMU counters, not 20)
2
10
3
Included the newly implemented SBSA generic watchdog device model into
11
Because it has 48-bit physical address support, we can use
4
SBSA platform
12
this CPU in the sbsa-ref board as well as the virt board.
5
13
6
Signed-off-by: Shashi Mallela <shashi.mallela@linaro.org>
7
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
8
Message-id: 20201027015927.29495-3-shashi.mallela@linaro.org
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
14
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
15
Tested-by: Marcin Juszkiewicz <marcin.juszkiewicz@linaro.org>
16
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
17
Message-id: 20230915185453.1871167-3-peter.maydell@linaro.org
10
---
18
---
11
hw/arm/sbsa-ref.c | 23 +++++++++++++++++++++++
19
docs/system/arm/virt.rst | 1 +
12
1 file changed, 23 insertions(+)
20
hw/arm/sbsa-ref.c | 1 +
21
hw/arm/virt.c | 1 +
22
target/arm/tcg/cpu64.c | 103 +++++++++++++++++++++++++++++++++++++++
23
4 files changed, 106 insertions(+)
13
24
25
diff --git a/docs/system/arm/virt.rst b/docs/system/arm/virt.rst
26
index XXXXXXX..XXXXXXX 100644
27
--- a/docs/system/arm/virt.rst
28
+++ b/docs/system/arm/virt.rst
29
@@ -XXX,XX +XXX,XX @@ Supported guest CPU types:
30
- ``host`` (with KVM only)
31
- ``neoverse-n1`` (64-bit)
32
- ``neoverse-v1`` (64-bit)
33
+- ``neoverse-n2`` (64-bit)
34
- ``max`` (same as ``host`` for KVM; best possible emulation with TCG)
35
36
Note that the default is ``cortex-a15``, so for an AArch64 guest you must
14
diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c
37
diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c
15
index XXXXXXX..XXXXXXX 100644
38
index XXXXXXX..XXXXXXX 100644
16
--- a/hw/arm/sbsa-ref.c
39
--- a/hw/arm/sbsa-ref.c
17
+++ b/hw/arm/sbsa-ref.c
40
+++ b/hw/arm/sbsa-ref.c
18
@@ -XXX,XX +XXX,XX @@
41
@@ -XXX,XX +XXX,XX @@ static const char * const valid_cpus[] = {
19
#include "hw/qdev-properties.h"
42
ARM_CPU_TYPE_NAME("cortex-a72"),
20
#include "hw/usb.h"
43
ARM_CPU_TYPE_NAME("neoverse-n1"),
21
#include "hw/char/pl011.h"
44
ARM_CPU_TYPE_NAME("neoverse-v1"),
22
+#include "hw/watchdog/sbsa_gwdt.h"
45
+ ARM_CPU_TYPE_NAME("neoverse-n2"),
23
#include "net/net.h"
46
ARM_CPU_TYPE_NAME("max"),
24
#include "qom/object.h"
25
26
@@ -XXX,XX +XXX,XX @@ enum {
27
SBSA_GIC_DIST,
28
SBSA_GIC_REDIST,
29
SBSA_SECURE_EC,
30
+ SBSA_GWDT,
31
+ SBSA_GWDT_REFRESH,
32
+ SBSA_GWDT_CONTROL,
33
SBSA_SMMU,
34
SBSA_UART,
35
SBSA_RTC,
36
@@ -XXX,XX +XXX,XX @@ static const MemMapEntry sbsa_ref_memmap[] = {
37
[SBSA_GIC_DIST] = { 0x40060000, 0x00010000 },
38
[SBSA_GIC_REDIST] = { 0x40080000, 0x04000000 },
39
[SBSA_SECURE_EC] = { 0x50000000, 0x00001000 },
40
+ [SBSA_GWDT_REFRESH] = { 0x50010000, 0x00001000 },
41
+ [SBSA_GWDT_CONTROL] = { 0x50011000, 0x00001000 },
42
[SBSA_UART] = { 0x60000000, 0x00001000 },
43
[SBSA_RTC] = { 0x60010000, 0x00001000 },
44
[SBSA_GPIO] = { 0x60020000, 0x00001000 },
45
@@ -XXX,XX +XXX,XX @@ static const int sbsa_ref_irqmap[] = {
46
[SBSA_AHCI] = 10,
47
[SBSA_EHCI] = 11,
48
[SBSA_SMMU] = 12, /* ... to 15 */
49
+ [SBSA_GWDT] = 16,
50
};
47
};
51
48
52
static uint64_t sbsa_ref_cpu_mp_affinity(SBSAMachineState *sms, int idx)
49
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
53
@@ -XXX,XX +XXX,XX @@ static void create_rtc(const SBSAMachineState *sms)
50
index XXXXXXX..XXXXXXX 100644
54
sysbus_create_simple("pl031", base, qdev_get_gpio_in(sms->gic, irq));
51
--- a/hw/arm/virt.c
52
+++ b/hw/arm/virt.c
53
@@ -XXX,XX +XXX,XX @@ static const char *valid_cpus[] = {
54
ARM_CPU_TYPE_NAME("a64fx"),
55
ARM_CPU_TYPE_NAME("neoverse-n1"),
56
ARM_CPU_TYPE_NAME("neoverse-v1"),
57
+ ARM_CPU_TYPE_NAME("neoverse-n2"),
58
#endif
59
ARM_CPU_TYPE_NAME("cortex-a53"),
60
ARM_CPU_TYPE_NAME("cortex-a57"),
61
diff --git a/target/arm/tcg/cpu64.c b/target/arm/tcg/cpu64.c
62
index XXXXXXX..XXXXXXX 100644
63
--- a/target/arm/tcg/cpu64.c
64
+++ b/target/arm/tcg/cpu64.c
65
@@ -XXX,XX +XXX,XX @@ static void aarch64_a710_initfn(Object *obj)
66
aarch64_add_sve_properties(obj);
55
}
67
}
56
68
57
+static void create_wdt(const SBSAMachineState *sms)
69
+/* Extra IMPDEF regs in the N2 beyond those in the A710 */
70
+static const ARMCPRegInfo neoverse_n2_cp_reginfo[] = {
71
+ { .name = "CPURNDBR_EL3", .state = ARM_CP_STATE_AA64,
72
+ .opc0 = 3, .opc1 = 6, .crn = 15, .crm = 3, .opc2 = 0,
73
+ .access = PL3_RW, .type = ARM_CP_CONST, .resetvalue = 0 },
74
+ { .name = "CPURNDPEID_EL3", .state = ARM_CP_STATE_AA64,
75
+ .opc0 = 3, .opc1 = 6, .crn = 15, .crm = 3, .opc2 = 1,
76
+ .access = PL3_RW, .type = ARM_CP_CONST, .resetvalue = 0 },
77
+};
78
+
79
+static void aarch64_neoverse_n2_initfn(Object *obj)
58
+{
80
+{
59
+ hwaddr rbase = sbsa_ref_memmap[SBSA_GWDT_REFRESH].base;
81
+ ARMCPU *cpu = ARM_CPU(obj);
60
+ hwaddr cbase = sbsa_ref_memmap[SBSA_GWDT_CONTROL].base;
61
+ DeviceState *dev = qdev_new(TYPE_WDT_SBSA);
62
+ SysBusDevice *s = SYS_BUS_DEVICE(dev);
63
+ int irq = sbsa_ref_irqmap[SBSA_GWDT];
64
+
82
+
65
+ sysbus_realize_and_unref(s, &error_fatal);
83
+ cpu->dtb_compatible = "arm,neoverse-n2";
66
+ sysbus_mmio_map(s, 0, rbase);
84
+ set_feature(&cpu->env, ARM_FEATURE_V8);
67
+ sysbus_mmio_map(s, 1, cbase);
85
+ set_feature(&cpu->env, ARM_FEATURE_NEON);
68
+ sysbus_connect_irq(s, 0, qdev_get_gpio_in(sms->gic, irq));
86
+ set_feature(&cpu->env, ARM_FEATURE_GENERIC_TIMER);
87
+ set_feature(&cpu->env, ARM_FEATURE_AARCH64);
88
+ set_feature(&cpu->env, ARM_FEATURE_CBAR_RO);
89
+ set_feature(&cpu->env, ARM_FEATURE_EL2);
90
+ set_feature(&cpu->env, ARM_FEATURE_EL3);
91
+ set_feature(&cpu->env, ARM_FEATURE_PMU);
92
+
93
+ /* Ordered by Section B.5: AArch64 ID registers */
94
+ cpu->midr = 0x410FD493; /* r0p3 */
95
+ cpu->revidr = 0;
96
+ cpu->isar.id_pfr0 = 0x21110131;
97
+ cpu->isar.id_pfr1 = 0x00010000; /* GIC filled in later */
98
+ cpu->isar.id_dfr0 = 0x16011099;
99
+ cpu->id_afr0 = 0;
100
+ cpu->isar.id_mmfr0 = 0x10201105;
101
+ cpu->isar.id_mmfr1 = 0x40000000;
102
+ cpu->isar.id_mmfr2 = 0x01260000;
103
+ cpu->isar.id_mmfr3 = 0x02122211;
104
+ cpu->isar.id_isar0 = 0x02101110;
105
+ cpu->isar.id_isar1 = 0x13112111;
106
+ cpu->isar.id_isar2 = 0x21232042;
107
+ cpu->isar.id_isar3 = 0x01112131;
108
+ cpu->isar.id_isar4 = 0x00010142;
109
+ cpu->isar.id_isar5 = 0x11011121; /* with Crypto */
110
+ cpu->isar.id_mmfr4 = 0x01021110;
111
+ cpu->isar.id_isar6 = 0x01111111;
112
+ cpu->isar.mvfr0 = 0x10110222;
113
+ cpu->isar.mvfr1 = 0x13211111;
114
+ cpu->isar.mvfr2 = 0x00000043;
115
+ cpu->isar.id_pfr2 = 0x00000011;
116
+ cpu->isar.id_aa64pfr0 = 0x1201111120111112ull; /* GIC filled in later */
117
+ cpu->isar.id_aa64pfr1 = 0x0000000000000221ull;
118
+ cpu->isar.id_aa64zfr0 = 0x0000110100110021ull; /* with Crypto */
119
+ cpu->isar.id_aa64dfr0 = 0x000011f210305619ull;
120
+ cpu->isar.id_aa64dfr1 = 0;
121
+ cpu->id_aa64afr0 = 0;
122
+ cpu->id_aa64afr1 = 0;
123
+ cpu->isar.id_aa64isar0 = 0x0221111110212120ull; /* with Crypto */
124
+ cpu->isar.id_aa64isar1 = 0x0011111101211052ull;
125
+ cpu->isar.id_aa64mmfr0 = 0x0000022200101125ull;
126
+ cpu->isar.id_aa64mmfr1 = 0x0000000010212122ull;
127
+ cpu->isar.id_aa64mmfr2 = 0x1221011112101011ull;
128
+ cpu->clidr = 0x0000001482000023ull;
129
+ cpu->gm_blocksize = 4;
130
+ cpu->ctr = 0x00000004b444c004ull;
131
+ cpu->dcz_blocksize = 4;
132
+ /* TODO FEAT_MPAM: mpamidr_el1 = 0x0000_0001_001e_01ff */
133
+
134
+ /* Section B.7.2: PMCR_EL0 */
135
+ cpu->isar.reset_pmcr_el0 = 0x3000; /* with 6 counters */
136
+
137
+ /* Section B.8.9: ICH_VTR_EL2 */
138
+ cpu->gic_num_lrs = 4;
139
+ cpu->gic_vpribits = 5;
140
+ cpu->gic_vprebits = 5;
141
+ cpu->gic_pribits = 5;
142
+
143
+ /* Section 14: Scalable Vector Extensions support */
144
+ cpu->sve_vq.supported = 1 << 0; /* 128bit */
145
+
146
+ /*
147
+ * The Neoverse N2 TRM does not list CCSIDR values. The layout of
148
+ * the caches are in text in Table 7-1, Table 8-1, and Table 9-1.
149
+ *
150
+ * L1: 4-way set associative 64-byte line size, total 64K.
151
+ * L2: 8-way set associative 64 byte line size, total either 512K or 1024K.
152
+ */
153
+ cpu->ccsidr[0] = make_ccsidr64(4, 64, 64 * KiB); /* L1 dcache */
154
+ cpu->ccsidr[1] = cpu->ccsidr[0]; /* L1 icache */
155
+ cpu->ccsidr[2] = make_ccsidr64(8, 64, 512 * KiB); /* L2 cache */
156
+
157
+ /* FIXME: Not documented -- copied from neoverse-v1 */
158
+ cpu->reset_sctlr = 0x30c50838;
159
+
160
+ /*
161
+ * The Neoverse N2 has all of the Cortex-A710 IMPDEF registers,
162
+ * and a few more RNG related ones.
163
+ */
164
+ define_arm_cp_regs(cpu, cortex_a710_cp_reginfo);
165
+ define_arm_cp_regs(cpu, neoverse_n2_cp_reginfo);
166
+
167
+ aarch64_add_pauth_properties(obj);
168
+ aarch64_add_sve_properties(obj);
69
+}
169
+}
70
+
170
+
71
static DeviceState *gpio_key_dev;
171
/*
72
static void sbsa_ref_powerdown_req(Notifier *n, void *opaque)
172
* -cpu max: a CPU with as many features enabled as our emulation supports.
73
{
173
* The version of '-cpu max' for qemu-system-arm is defined in cpu32.c;
74
@@ -XXX,XX +XXX,XX @@ static void sbsa_ref_init(MachineState *machine)
174
@@ -XXX,XX +XXX,XX @@ static const ARMCPUInfo aarch64_cpus[] = {
75
175
{ .name = "a64fx", .initfn = aarch64_a64fx_initfn },
76
create_rtc(sms);
176
{ .name = "neoverse-n1", .initfn = aarch64_neoverse_n1_initfn },
77
177
{ .name = "neoverse-v1", .initfn = aarch64_neoverse_v1_initfn },
78
+ create_wdt(sms);
178
+ { .name = "neoverse-n2", .initfn = aarch64_neoverse_n2_initfn },
79
+
179
};
80
create_gpio(sms);
180
81
181
static void aarch64_cpu_register_types(void)
82
create_ahci(sms);
83
--
182
--
84
2.20.1
183
2.34.1
85
184
86
185
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
The feature test functions isar_feature_*() now take up nearly
2
a thousand lines in target/arm/cpu.h. This header file is included
3
by a lot of source files, most of which don't need these functions.
4
Move the feature test functions to their own header file.
2
5
3
Transform the prot bit to a qemu internal page bit, and save
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
4
it in the page tables.
7
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
8
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
9
Message-id: 20231024163510.2972081-2-peter.maydell@linaro.org
10
---
11
bsd-user/arm/target_arch.h | 1 +
12
linux-user/aarch64/target_prctl.h | 2 +
13
target/arm/cpu-features.h | 994 ++++++++++++++++++++++++++++++
14
target/arm/cpu.h | 971 -----------------------------
15
target/arm/internals.h | 1 +
16
target/arm/tcg/translate.h | 2 +-
17
hw/arm/armv7m.c | 1 +
18
hw/intc/armv7m_nvic.c | 1 +
19
linux-user/aarch64/cpu_loop.c | 1 +
20
linux-user/aarch64/signal.c | 1 +
21
linux-user/arm/signal.c | 1 +
22
linux-user/elfload.c | 4 +
23
linux-user/mmap.c | 4 +
24
target/arm/arch_dump.c | 1 +
25
target/arm/cpu.c | 1 +
26
target/arm/cpu64.c | 1 +
27
target/arm/debug_helper.c | 1 +
28
target/arm/gdbstub.c | 1 +
29
target/arm/helper.c | 1 +
30
target/arm/kvm64.c | 1 +
31
target/arm/machine.c | 1 +
32
target/arm/ptw.c | 1 +
33
target/arm/tcg/cpu64.c | 1 +
34
target/arm/tcg/hflags.c | 1 +
35
target/arm/tcg/m_helper.c | 1 +
36
target/arm/tcg/op_helper.c | 1 +
37
target/arm/tcg/pauth_helper.c | 1 +
38
target/arm/tcg/tlb_helper.c | 1 +
39
target/arm/vfp_helper.c | 1 +
40
29 files changed, 1028 insertions(+), 972 deletions(-)
41
create mode 100644 target/arm/cpu-features.h
5
42
6
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
43
diff --git a/bsd-user/arm/target_arch.h b/bsd-user/arm/target_arch.h
7
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
44
index XXXXXXX..XXXXXXX 100644
8
Message-id: 20201021173749.111103-3-richard.henderson@linaro.org
45
--- a/bsd-user/arm/target_arch.h
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
46
+++ b/bsd-user/arm/target_arch.h
10
---
47
@@ -XXX,XX +XXX,XX @@
11
include/exec/cpu-all.h | 2 ++
48
#define TARGET_ARCH_H
12
linux-user/syscall_defs.h | 4 ++++
49
13
target/arm/cpu.h | 5 +++++
50
#include "qemu.h"
14
linux-user/mmap.c | 16 ++++++++++++++++
51
+#include "target/arm/cpu-features.h"
15
target/arm/translate-a64.c | 6 +++---
52
16
5 files changed, 30 insertions(+), 3 deletions(-)
53
void target_cpu_set_tls(CPUARMState *env, target_ulong newtls);
17
54
target_ulong target_cpu_get_tls(CPUARMState *env);
18
diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
55
diff --git a/linux-user/aarch64/target_prctl.h b/linux-user/aarch64/target_prctl.h
19
index XXXXXXX..XXXXXXX 100644
56
index XXXXXXX..XXXXXXX 100644
20
--- a/include/exec/cpu-all.h
57
--- a/linux-user/aarch64/target_prctl.h
21
+++ b/include/exec/cpu-all.h
58
+++ b/linux-user/aarch64/target_prctl.h
22
@@ -XXX,XX +XXX,XX @@ extern intptr_t qemu_host_page_mask;
59
@@ -XXX,XX +XXX,XX @@
23
/* FIXME: Code that sets/uses this is broken and needs to go away. */
60
#ifndef AARCH64_TARGET_PRCTL_H
24
#define PAGE_RESERVED 0x0020
61
#define AARCH64_TARGET_PRCTL_H
25
#endif
62
26
+/* Target-specific bits that will be used via page_get_flags(). */
63
+#include "target/arm/cpu-features.h"
27
+#define PAGE_TARGET_1 0x0080
64
+
28
65
static abi_long do_prctl_sve_get_vl(CPUArchState *env)
29
#if defined(CONFIG_USER_ONLY)
66
{
30
void page_dump(FILE *f);
67
ARMCPU *cpu = env_archcpu(env);
31
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
68
diff --git a/target/arm/cpu-features.h b/target/arm/cpu-features.h
32
index XXXXXXX..XXXXXXX 100644
69
new file mode 100644
33
--- a/linux-user/syscall_defs.h
70
index XXXXXXX..XXXXXXX
34
+++ b/linux-user/syscall_defs.h
71
--- /dev/null
35
@@ -XXX,XX +XXX,XX @@ struct target_winsize {
72
+++ b/target/arm/cpu-features.h
36
#define TARGET_PROT_SEM 0x08
73
@@ -XXX,XX +XXX,XX @@
37
#endif
74
+/*
38
75
+ * QEMU Arm CPU -- feature test functions
39
+#ifdef TARGET_AARCH64
76
+ *
40
+#define TARGET_PROT_BTI 0x10
77
+ * Copyright (c) 2023 Linaro Ltd
78
+ *
79
+ * This library is free software; you can redistribute it and/or
80
+ * modify it under the terms of the GNU Lesser General Public
81
+ * License as published by the Free Software Foundation; either
82
+ * version 2.1 of the License, or (at your option) any later version.
83
+ *
84
+ * This library is distributed in the hope that it will be useful,
85
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
86
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
87
+ * Lesser General Public License for more details.
88
+ *
89
+ * You should have received a copy of the GNU Lesser General Public
90
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
91
+ */
92
+
93
+#ifndef TARGET_ARM_FEATURES_H
94
+#define TARGET_ARM_FEATURES_H
95
+
96
+/*
97
+ * Naming convention for isar_feature functions:
98
+ * Functions which test 32-bit ID registers should have _aa32_ in
99
+ * their name. Functions which test 64-bit ID registers should have
100
+ * _aa64_ in their name. These must only be used in code where we
101
+ * know for certain that the CPU has AArch32 or AArch64 respectively
102
+ * or where the correct answer for a CPU which doesn't implement that
103
+ * CPU state is "false" (eg when generating A32 or A64 code, if adding
104
+ * system registers that are specific to that CPU state, for "should
105
+ * we let this system register bit be set" tests where the 32-bit
106
+ * flavour of the register doesn't have the bit, and so on).
107
+ * Functions which simply ask "does this feature exist at all" have
108
+ * _any_ in their name, and always return the logical OR of the _aa64_
109
+ * and the _aa32_ function.
110
+ */
111
+
112
+/*
113
+ * 32-bit feature tests via id registers.
114
+ */
115
+static inline bool isar_feature_aa32_thumb_div(const ARMISARegisters *id)
116
+{
117
+ return FIELD_EX32(id->id_isar0, ID_ISAR0, DIVIDE) != 0;
118
+}
119
+
120
+static inline bool isar_feature_aa32_arm_div(const ARMISARegisters *id)
121
+{
122
+ return FIELD_EX32(id->id_isar0, ID_ISAR0, DIVIDE) > 1;
123
+}
124
+
125
+static inline bool isar_feature_aa32_lob(const ARMISARegisters *id)
126
+{
127
+ /* (M-profile) low-overhead loops and branch future */
128
+ return FIELD_EX32(id->id_isar0, ID_ISAR0, CMPBRANCH) >= 3;
129
+}
130
+
131
+static inline bool isar_feature_aa32_jazelle(const ARMISARegisters *id)
132
+{
133
+ return FIELD_EX32(id->id_isar1, ID_ISAR1, JAZELLE) != 0;
134
+}
135
+
136
+static inline bool isar_feature_aa32_aes(const ARMISARegisters *id)
137
+{
138
+ return FIELD_EX32(id->id_isar5, ID_ISAR5, AES) != 0;
139
+}
140
+
141
+static inline bool isar_feature_aa32_pmull(const ARMISARegisters *id)
142
+{
143
+ return FIELD_EX32(id->id_isar5, ID_ISAR5, AES) > 1;
144
+}
145
+
146
+static inline bool isar_feature_aa32_sha1(const ARMISARegisters *id)
147
+{
148
+ return FIELD_EX32(id->id_isar5, ID_ISAR5, SHA1) != 0;
149
+}
150
+
151
+static inline bool isar_feature_aa32_sha2(const ARMISARegisters *id)
152
+{
153
+ return FIELD_EX32(id->id_isar5, ID_ISAR5, SHA2) != 0;
154
+}
155
+
156
+static inline bool isar_feature_aa32_crc32(const ARMISARegisters *id)
157
+{
158
+ return FIELD_EX32(id->id_isar5, ID_ISAR5, CRC32) != 0;
159
+}
160
+
161
+static inline bool isar_feature_aa32_rdm(const ARMISARegisters *id)
162
+{
163
+ return FIELD_EX32(id->id_isar5, ID_ISAR5, RDM) != 0;
164
+}
165
+
166
+static inline bool isar_feature_aa32_vcma(const ARMISARegisters *id)
167
+{
168
+ return FIELD_EX32(id->id_isar5, ID_ISAR5, VCMA) != 0;
169
+}
170
+
171
+static inline bool isar_feature_aa32_jscvt(const ARMISARegisters *id)
172
+{
173
+ return FIELD_EX32(id->id_isar6, ID_ISAR6, JSCVT) != 0;
174
+}
175
+
176
+static inline bool isar_feature_aa32_dp(const ARMISARegisters *id)
177
+{
178
+ return FIELD_EX32(id->id_isar6, ID_ISAR6, DP) != 0;
179
+}
180
+
181
+static inline bool isar_feature_aa32_fhm(const ARMISARegisters *id)
182
+{
183
+ return FIELD_EX32(id->id_isar6, ID_ISAR6, FHM) != 0;
184
+}
185
+
186
+static inline bool isar_feature_aa32_sb(const ARMISARegisters *id)
187
+{
188
+ return FIELD_EX32(id->id_isar6, ID_ISAR6, SB) != 0;
189
+}
190
+
191
+static inline bool isar_feature_aa32_predinv(const ARMISARegisters *id)
192
+{
193
+ return FIELD_EX32(id->id_isar6, ID_ISAR6, SPECRES) != 0;
194
+}
195
+
196
+static inline bool isar_feature_aa32_bf16(const ARMISARegisters *id)
197
+{
198
+ return FIELD_EX32(id->id_isar6, ID_ISAR6, BF16) != 0;
199
+}
200
+
201
+static inline bool isar_feature_aa32_i8mm(const ARMISARegisters *id)
202
+{
203
+ return FIELD_EX32(id->id_isar6, ID_ISAR6, I8MM) != 0;
204
+}
205
+
206
+static inline bool isar_feature_aa32_ras(const ARMISARegisters *id)
207
+{
208
+ return FIELD_EX32(id->id_pfr0, ID_PFR0, RAS) != 0;
209
+}
210
+
211
+static inline bool isar_feature_aa32_mprofile(const ARMISARegisters *id)
212
+{
213
+ return FIELD_EX32(id->id_pfr1, ID_PFR1, MPROGMOD) != 0;
214
+}
215
+
216
+static inline bool isar_feature_aa32_m_sec_state(const ARMISARegisters *id)
217
+{
218
+ /*
219
+ * Return true if M-profile state handling insns
220
+ * (VSCCLRM, CLRM, FPCTX access insns) are implemented
221
+ */
222
+ return FIELD_EX32(id->id_pfr1, ID_PFR1, SECURITY) >= 3;
223
+}
224
+
225
+static inline bool isar_feature_aa32_fp16_arith(const ARMISARegisters *id)
226
+{
227
+ /* Sadly this is encoded differently for A-profile and M-profile */
228
+ if (isar_feature_aa32_mprofile(id)) {
229
+ return FIELD_EX32(id->mvfr1, MVFR1, FP16) > 0;
230
+ } else {
231
+ return FIELD_EX32(id->mvfr1, MVFR1, FPHP) >= 3;
232
+ }
233
+}
234
+
235
+static inline bool isar_feature_aa32_mve(const ARMISARegisters *id)
236
+{
237
+ /*
238
+ * Return true if MVE is supported (either integer or floating point).
239
+ * We must check for M-profile as the MVFR1 field means something
240
+ * else for A-profile.
241
+ */
242
+ return isar_feature_aa32_mprofile(id) &&
243
+ FIELD_EX32(id->mvfr1, MVFR1, MVE) > 0;
244
+}
245
+
246
+static inline bool isar_feature_aa32_mve_fp(const ARMISARegisters *id)
247
+{
248
+ /*
249
+ * Return true if MVE is supported (either integer or floating point).
250
+ * We must check for M-profile as the MVFR1 field means something
251
+ * else for A-profile.
252
+ */
253
+ return isar_feature_aa32_mprofile(id) &&
254
+ FIELD_EX32(id->mvfr1, MVFR1, MVE) >= 2;
255
+}
256
+
257
+static inline bool isar_feature_aa32_vfp_simd(const ARMISARegisters *id)
258
+{
259
+ /*
260
+ * Return true if either VFP or SIMD is implemented.
261
+ * In this case, a minimum of VFP w/ D0-D15.
262
+ */
263
+ return FIELD_EX32(id->mvfr0, MVFR0, SIMDREG) > 0;
264
+}
265
+
266
+static inline bool isar_feature_aa32_simd_r32(const ARMISARegisters *id)
267
+{
268
+ /* Return true if D16-D31 are implemented */
269
+ return FIELD_EX32(id->mvfr0, MVFR0, SIMDREG) >= 2;
270
+}
271
+
272
+static inline bool isar_feature_aa32_fpshvec(const ARMISARegisters *id)
273
+{
274
+ return FIELD_EX32(id->mvfr0, MVFR0, FPSHVEC) > 0;
275
+}
276
+
277
+static inline bool isar_feature_aa32_fpsp_v2(const ARMISARegisters *id)
278
+{
279
+ /* Return true if CPU supports single precision floating point, VFPv2 */
280
+ return FIELD_EX32(id->mvfr0, MVFR0, FPSP) > 0;
281
+}
282
+
283
+static inline bool isar_feature_aa32_fpsp_v3(const ARMISARegisters *id)
284
+{
285
+ /* Return true if CPU supports single precision floating point, VFPv3 */
286
+ return FIELD_EX32(id->mvfr0, MVFR0, FPSP) >= 2;
287
+}
288
+
289
+static inline bool isar_feature_aa32_fpdp_v2(const ARMISARegisters *id)
290
+{
291
+ /* Return true if CPU supports double precision floating point, VFPv2 */
292
+ return FIELD_EX32(id->mvfr0, MVFR0, FPDP) > 0;
293
+}
294
+
295
+static inline bool isar_feature_aa32_fpdp_v3(const ARMISARegisters *id)
296
+{
297
+ /* Return true if CPU supports double precision floating point, VFPv3 */
298
+ return FIELD_EX32(id->mvfr0, MVFR0, FPDP) >= 2;
299
+}
300
+
301
+static inline bool isar_feature_aa32_vfp(const ARMISARegisters *id)
302
+{
303
+ return isar_feature_aa32_fpsp_v2(id) || isar_feature_aa32_fpdp_v2(id);
304
+}
305
+
306
+/*
307
+ * We always set the FP and SIMD FP16 fields to indicate identical
308
+ * levels of support (assuming SIMD is implemented at all), so
309
+ * we only need one set of accessors.
310
+ */
311
+static inline bool isar_feature_aa32_fp16_spconv(const ARMISARegisters *id)
312
+{
313
+ return FIELD_EX32(id->mvfr1, MVFR1, FPHP) > 0;
314
+}
315
+
316
+static inline bool isar_feature_aa32_fp16_dpconv(const ARMISARegisters *id)
317
+{
318
+ return FIELD_EX32(id->mvfr1, MVFR1, FPHP) > 1;
319
+}
320
+
321
+/*
322
+ * Note that this ID register field covers both VFP and Neon FMAC,
323
+ * so should usually be tested in combination with some other
324
+ * check that confirms the presence of whichever of VFP or Neon is
325
+ * relevant, to avoid accidentally enabling a Neon feature on
326
+ * a VFP-no-Neon core or vice-versa.
327
+ */
328
+static inline bool isar_feature_aa32_simdfmac(const ARMISARegisters *id)
329
+{
330
+ return FIELD_EX32(id->mvfr1, MVFR1, SIMDFMAC) != 0;
331
+}
332
+
333
+static inline bool isar_feature_aa32_vsel(const ARMISARegisters *id)
334
+{
335
+ return FIELD_EX32(id->mvfr2, MVFR2, FPMISC) >= 1;
336
+}
337
+
338
+static inline bool isar_feature_aa32_vcvt_dr(const ARMISARegisters *id)
339
+{
340
+ return FIELD_EX32(id->mvfr2, MVFR2, FPMISC) >= 2;
341
+}
342
+
343
+static inline bool isar_feature_aa32_vrint(const ARMISARegisters *id)
344
+{
345
+ return FIELD_EX32(id->mvfr2, MVFR2, FPMISC) >= 3;
346
+}
347
+
348
+static inline bool isar_feature_aa32_vminmaxnm(const ARMISARegisters *id)
349
+{
350
+ return FIELD_EX32(id->mvfr2, MVFR2, FPMISC) >= 4;
351
+}
352
+
353
+static inline bool isar_feature_aa32_pxn(const ARMISARegisters *id)
354
+{
355
+ return FIELD_EX32(id->id_mmfr0, ID_MMFR0, VMSA) >= 4;
356
+}
357
+
358
+static inline bool isar_feature_aa32_pan(const ARMISARegisters *id)
359
+{
360
+ return FIELD_EX32(id->id_mmfr3, ID_MMFR3, PAN) != 0;
361
+}
362
+
363
+static inline bool isar_feature_aa32_ats1e1(const ARMISARegisters *id)
364
+{
365
+ return FIELD_EX32(id->id_mmfr3, ID_MMFR3, PAN) >= 2;
366
+}
367
+
368
+static inline bool isar_feature_aa32_pmuv3p1(const ARMISARegisters *id)
369
+{
370
+ /* 0xf means "non-standard IMPDEF PMU" */
371
+ return FIELD_EX32(id->id_dfr0, ID_DFR0, PERFMON) >= 4 &&
372
+ FIELD_EX32(id->id_dfr0, ID_DFR0, PERFMON) != 0xf;
373
+}
374
+
375
+static inline bool isar_feature_aa32_pmuv3p4(const ARMISARegisters *id)
376
+{
377
+ /* 0xf means "non-standard IMPDEF PMU" */
378
+ return FIELD_EX32(id->id_dfr0, ID_DFR0, PERFMON) >= 5 &&
379
+ FIELD_EX32(id->id_dfr0, ID_DFR0, PERFMON) != 0xf;
380
+}
381
+
382
+static inline bool isar_feature_aa32_pmuv3p5(const ARMISARegisters *id)
383
+{
384
+ /* 0xf means "non-standard IMPDEF PMU" */
385
+ return FIELD_EX32(id->id_dfr0, ID_DFR0, PERFMON) >= 6 &&
386
+ FIELD_EX32(id->id_dfr0, ID_DFR0, PERFMON) != 0xf;
387
+}
388
+
389
+static inline bool isar_feature_aa32_hpd(const ARMISARegisters *id)
390
+{
391
+ return FIELD_EX32(id->id_mmfr4, ID_MMFR4, HPDS) != 0;
392
+}
393
+
394
+static inline bool isar_feature_aa32_ac2(const ARMISARegisters *id)
395
+{
396
+ return FIELD_EX32(id->id_mmfr4, ID_MMFR4, AC2) != 0;
397
+}
398
+
399
+static inline bool isar_feature_aa32_ccidx(const ARMISARegisters *id)
400
+{
401
+ return FIELD_EX32(id->id_mmfr4, ID_MMFR4, CCIDX) != 0;
402
+}
403
+
404
+static inline bool isar_feature_aa32_tts2uxn(const ARMISARegisters *id)
405
+{
406
+ return FIELD_EX32(id->id_mmfr4, ID_MMFR4, XNX) != 0;
407
+}
408
+
409
+static inline bool isar_feature_aa32_half_evt(const ARMISARegisters *id)
410
+{
411
+ return FIELD_EX32(id->id_mmfr4, ID_MMFR4, EVT) >= 1;
412
+}
413
+
414
+static inline bool isar_feature_aa32_evt(const ARMISARegisters *id)
415
+{
416
+ return FIELD_EX32(id->id_mmfr4, ID_MMFR4, EVT) >= 2;
417
+}
418
+
419
+static inline bool isar_feature_aa32_dit(const ARMISARegisters *id)
420
+{
421
+ return FIELD_EX32(id->id_pfr0, ID_PFR0, DIT) != 0;
422
+}
423
+
424
+static inline bool isar_feature_aa32_ssbs(const ARMISARegisters *id)
425
+{
426
+ return FIELD_EX32(id->id_pfr2, ID_PFR2, SSBS) != 0;
427
+}
428
+
429
+static inline bool isar_feature_aa32_debugv7p1(const ARMISARegisters *id)
430
+{
431
+ return FIELD_EX32(id->id_dfr0, ID_DFR0, COPDBG) >= 5;
432
+}
433
+
434
+static inline bool isar_feature_aa32_debugv8p2(const ARMISARegisters *id)
435
+{
436
+ return FIELD_EX32(id->id_dfr0, ID_DFR0, COPDBG) >= 8;
437
+}
438
+
439
+static inline bool isar_feature_aa32_doublelock(const ARMISARegisters *id)
440
+{
441
+ return FIELD_EX32(id->dbgdevid, DBGDEVID, DOUBLELOCK) > 0;
442
+}
443
+
444
+/*
445
+ * 64-bit feature tests via id registers.
446
+ */
447
+static inline bool isar_feature_aa64_aes(const ARMISARegisters *id)
448
+{
449
+ return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, AES) != 0;
450
+}
451
+
452
+static inline bool isar_feature_aa64_pmull(const ARMISARegisters *id)
453
+{
454
+ return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, AES) > 1;
455
+}
456
+
457
+static inline bool isar_feature_aa64_sha1(const ARMISARegisters *id)
458
+{
459
+ return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, SHA1) != 0;
460
+}
461
+
462
+static inline bool isar_feature_aa64_sha256(const ARMISARegisters *id)
463
+{
464
+ return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, SHA2) != 0;
465
+}
466
+
467
+static inline bool isar_feature_aa64_sha512(const ARMISARegisters *id)
468
+{
469
+ return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, SHA2) > 1;
470
+}
471
+
472
+static inline bool isar_feature_aa64_crc32(const ARMISARegisters *id)
473
+{
474
+ return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, CRC32) != 0;
475
+}
476
+
477
+static inline bool isar_feature_aa64_atomics(const ARMISARegisters *id)
478
+{
479
+ return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, ATOMIC) != 0;
480
+}
481
+
482
+static inline bool isar_feature_aa64_rdm(const ARMISARegisters *id)
483
+{
484
+ return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, RDM) != 0;
485
+}
486
+
487
+static inline bool isar_feature_aa64_sha3(const ARMISARegisters *id)
488
+{
489
+ return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, SHA3) != 0;
490
+}
491
+
492
+static inline bool isar_feature_aa64_sm3(const ARMISARegisters *id)
493
+{
494
+ return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, SM3) != 0;
495
+}
496
+
497
+static inline bool isar_feature_aa64_sm4(const ARMISARegisters *id)
498
+{
499
+ return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, SM4) != 0;
500
+}
501
+
502
+static inline bool isar_feature_aa64_dp(const ARMISARegisters *id)
503
+{
504
+ return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, DP) != 0;
505
+}
506
+
507
+static inline bool isar_feature_aa64_fhm(const ARMISARegisters *id)
508
+{
509
+ return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, FHM) != 0;
510
+}
511
+
512
+static inline bool isar_feature_aa64_condm_4(const ARMISARegisters *id)
513
+{
514
+ return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, TS) != 0;
515
+}
516
+
517
+static inline bool isar_feature_aa64_condm_5(const ARMISARegisters *id)
518
+{
519
+ return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, TS) >= 2;
520
+}
521
+
522
+static inline bool isar_feature_aa64_rndr(const ARMISARegisters *id)
523
+{
524
+ return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, RNDR) != 0;
525
+}
526
+
527
+static inline bool isar_feature_aa64_jscvt(const ARMISARegisters *id)
528
+{
529
+ return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, JSCVT) != 0;
530
+}
531
+
532
+static inline bool isar_feature_aa64_fcma(const ARMISARegisters *id)
533
+{
534
+ return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, FCMA) != 0;
535
+}
536
+
537
+/*
538
+ * These are the values from APA/API/APA3.
539
+ * In general these must be compared '>=', per the normal Arm ARM
540
+ * treatment of fields in ID registers.
541
+ */
542
+typedef enum {
543
+ PauthFeat_None = 0,
544
+ PauthFeat_1 = 1,
545
+ PauthFeat_EPAC = 2,
546
+ PauthFeat_2 = 3,
547
+ PauthFeat_FPAC = 4,
548
+ PauthFeat_FPACCOMBINED = 5,
549
+} ARMPauthFeature;
550
+
551
+static inline ARMPauthFeature
552
+isar_feature_pauth_feature(const ARMISARegisters *id)
553
+{
554
+ /*
555
+ * Architecturally, only one of {APA,API,APA3} may be active (non-zero)
556
+ * and the other two must be zero. Thus we may avoid conditionals.
557
+ */
558
+ return (FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, APA) |
559
+ FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, API) |
560
+ FIELD_EX64(id->id_aa64isar2, ID_AA64ISAR2, APA3));
561
+}
562
+
563
+static inline bool isar_feature_aa64_pauth(const ARMISARegisters *id)
564
+{
565
+ /*
566
+ * Return true if any form of pauth is enabled, as this
567
+ * predicate controls migration of the 128-bit keys.
568
+ */
569
+ return isar_feature_pauth_feature(id) != PauthFeat_None;
570
+}
571
+
572
+static inline bool isar_feature_aa64_pauth_qarma5(const ARMISARegisters *id)
573
+{
574
+ /*
575
+ * Return true if pauth is enabled with the architected QARMA5 algorithm.
576
+ * QEMU will always enable or disable both APA and GPA.
577
+ */
578
+ return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, APA) != 0;
579
+}
580
+
581
+static inline bool isar_feature_aa64_pauth_qarma3(const ARMISARegisters *id)
582
+{
583
+ /*
584
+ * Return true if pauth is enabled with the architected QARMA3 algorithm.
585
+ * QEMU will always enable or disable both APA3 and GPA3.
586
+ */
587
+ return FIELD_EX64(id->id_aa64isar2, ID_AA64ISAR2, APA3) != 0;
588
+}
589
+
590
+static inline bool isar_feature_aa64_tlbirange(const ARMISARegisters *id)
591
+{
592
+ return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, TLB) == 2;
593
+}
594
+
595
+static inline bool isar_feature_aa64_tlbios(const ARMISARegisters *id)
596
+{
597
+ return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, TLB) != 0;
598
+}
599
+
600
+static inline bool isar_feature_aa64_sb(const ARMISARegisters *id)
601
+{
602
+ return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, SB) != 0;
603
+}
604
+
605
+static inline bool isar_feature_aa64_predinv(const ARMISARegisters *id)
606
+{
607
+ return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, SPECRES) != 0;
608
+}
609
+
610
+static inline bool isar_feature_aa64_frint(const ARMISARegisters *id)
611
+{
612
+ return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, FRINTTS) != 0;
613
+}
614
+
615
+static inline bool isar_feature_aa64_dcpop(const ARMISARegisters *id)
616
+{
617
+ return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, DPB) != 0;
618
+}
619
+
620
+static inline bool isar_feature_aa64_dcpodp(const ARMISARegisters *id)
621
+{
622
+ return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, DPB) >= 2;
623
+}
624
+
625
+static inline bool isar_feature_aa64_bf16(const ARMISARegisters *id)
626
+{
627
+ return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, BF16) != 0;
628
+}
629
+
630
+static inline bool isar_feature_aa64_fp_simd(const ARMISARegisters *id)
631
+{
632
+ /* We always set the AdvSIMD and FP fields identically. */
633
+ return FIELD_EX64(id->id_aa64pfr0, ID_AA64PFR0, FP) != 0xf;
634
+}
635
+
636
+static inline bool isar_feature_aa64_fp16(const ARMISARegisters *id)
637
+{
638
+ /* We always set the AdvSIMD and FP fields identically wrt FP16. */
639
+ return FIELD_EX64(id->id_aa64pfr0, ID_AA64PFR0, FP) == 1;
640
+}
641
+
642
+static inline bool isar_feature_aa64_aa32(const ARMISARegisters *id)
643
+{
644
+ return FIELD_EX64(id->id_aa64pfr0, ID_AA64PFR0, EL0) >= 2;
645
+}
646
+
647
+static inline bool isar_feature_aa64_aa32_el1(const ARMISARegisters *id)
648
+{
649
+ return FIELD_EX64(id->id_aa64pfr0, ID_AA64PFR0, EL1) >= 2;
650
+}
651
+
652
+static inline bool isar_feature_aa64_aa32_el2(const ARMISARegisters *id)
653
+{
654
+ return FIELD_EX64(id->id_aa64pfr0, ID_AA64PFR0, EL2) >= 2;
655
+}
656
+
657
+static inline bool isar_feature_aa64_ras(const ARMISARegisters *id)
658
+{
659
+ return FIELD_EX64(id->id_aa64pfr0, ID_AA64PFR0, RAS) != 0;
660
+}
661
+
662
+static inline bool isar_feature_aa64_doublefault(const ARMISARegisters *id)
663
+{
664
+ return FIELD_EX64(id->id_aa64pfr0, ID_AA64PFR0, RAS) >= 2;
665
+}
666
+
667
+static inline bool isar_feature_aa64_sve(const ARMISARegisters *id)
668
+{
669
+ return FIELD_EX64(id->id_aa64pfr0, ID_AA64PFR0, SVE) != 0;
670
+}
671
+
672
+static inline bool isar_feature_aa64_sel2(const ARMISARegisters *id)
673
+{
674
+ return FIELD_EX64(id->id_aa64pfr0, ID_AA64PFR0, SEL2) != 0;
675
+}
676
+
677
+static inline bool isar_feature_aa64_rme(const ARMISARegisters *id)
678
+{
679
+ return FIELD_EX64(id->id_aa64pfr0, ID_AA64PFR0, RME) != 0;
680
+}
681
+
682
+static inline bool isar_feature_aa64_vh(const ARMISARegisters *id)
683
+{
684
+ return FIELD_EX64(id->id_aa64mmfr1, ID_AA64MMFR1, VH) != 0;
685
+}
686
+
687
+static inline bool isar_feature_aa64_lor(const ARMISARegisters *id)
688
+{
689
+ return FIELD_EX64(id->id_aa64mmfr1, ID_AA64MMFR1, LO) != 0;
690
+}
691
+
692
+static inline bool isar_feature_aa64_pan(const ARMISARegisters *id)
693
+{
694
+ return FIELD_EX64(id->id_aa64mmfr1, ID_AA64MMFR1, PAN) != 0;
695
+}
696
+
697
+static inline bool isar_feature_aa64_ats1e1(const ARMISARegisters *id)
698
+{
699
+ return FIELD_EX64(id->id_aa64mmfr1, ID_AA64MMFR1, PAN) >= 2;
700
+}
701
+
702
+static inline bool isar_feature_aa64_pan3(const ARMISARegisters *id)
703
+{
704
+ return FIELD_EX64(id->id_aa64mmfr1, ID_AA64MMFR1, PAN) >= 3;
705
+}
706
+
707
+static inline bool isar_feature_aa64_hcx(const ARMISARegisters *id)
708
+{
709
+ return FIELD_EX64(id->id_aa64mmfr1, ID_AA64MMFR1, HCX) != 0;
710
+}
711
+
712
+static inline bool isar_feature_aa64_tidcp1(const ARMISARegisters *id)
713
+{
714
+ return FIELD_EX64(id->id_aa64mmfr2, ID_AA64MMFR1, TIDCP1) != 0;
715
+}
716
+
717
+static inline bool isar_feature_aa64_uao(const ARMISARegisters *id)
718
+{
719
+ return FIELD_EX64(id->id_aa64mmfr2, ID_AA64MMFR2, UAO) != 0;
720
+}
721
+
722
+static inline bool isar_feature_aa64_st(const ARMISARegisters *id)
723
+{
724
+ return FIELD_EX64(id->id_aa64mmfr2, ID_AA64MMFR2, ST) != 0;
725
+}
726
+
727
+static inline bool isar_feature_aa64_lse2(const ARMISARegisters *id)
728
+{
729
+ return FIELD_EX64(id->id_aa64mmfr2, ID_AA64MMFR2, AT) != 0;
730
+}
731
+
732
+static inline bool isar_feature_aa64_fwb(const ARMISARegisters *id)
733
+{
734
+ return FIELD_EX64(id->id_aa64mmfr2, ID_AA64MMFR2, FWB) != 0;
735
+}
736
+
737
+static inline bool isar_feature_aa64_ids(const ARMISARegisters *id)
738
+{
739
+ return FIELD_EX64(id->id_aa64mmfr2, ID_AA64MMFR2, IDS) != 0;
740
+}
741
+
742
+static inline bool isar_feature_aa64_half_evt(const ARMISARegisters *id)
743
+{
744
+ return FIELD_EX64(id->id_aa64mmfr2, ID_AA64MMFR2, EVT) >= 1;
745
+}
746
+
747
+static inline bool isar_feature_aa64_evt(const ARMISARegisters *id)
748
+{
749
+ return FIELD_EX64(id->id_aa64mmfr2, ID_AA64MMFR2, EVT) >= 2;
750
+}
751
+
752
+static inline bool isar_feature_aa64_bti(const ARMISARegisters *id)
753
+{
754
+ return FIELD_EX64(id->id_aa64pfr1, ID_AA64PFR1, BT) != 0;
755
+}
756
+
757
+static inline bool isar_feature_aa64_mte_insn_reg(const ARMISARegisters *id)
758
+{
759
+ return FIELD_EX64(id->id_aa64pfr1, ID_AA64PFR1, MTE) != 0;
760
+}
761
+
762
+static inline bool isar_feature_aa64_mte(const ARMISARegisters *id)
763
+{
764
+ return FIELD_EX64(id->id_aa64pfr1, ID_AA64PFR1, MTE) >= 2;
765
+}
766
+
767
+static inline bool isar_feature_aa64_sme(const ARMISARegisters *id)
768
+{
769
+ return FIELD_EX64(id->id_aa64pfr1, ID_AA64PFR1, SME) != 0;
770
+}
771
+
772
+static inline bool isar_feature_aa64_pmuv3p1(const ARMISARegisters *id)
773
+{
774
+ return FIELD_EX64(id->id_aa64dfr0, ID_AA64DFR0, PMUVER) >= 4 &&
775
+ FIELD_EX64(id->id_aa64dfr0, ID_AA64DFR0, PMUVER) != 0xf;
776
+}
777
+
778
+static inline bool isar_feature_aa64_pmuv3p4(const ARMISARegisters *id)
779
+{
780
+ return FIELD_EX64(id->id_aa64dfr0, ID_AA64DFR0, PMUVER) >= 5 &&
781
+ FIELD_EX64(id->id_aa64dfr0, ID_AA64DFR0, PMUVER) != 0xf;
782
+}
783
+
784
+static inline bool isar_feature_aa64_pmuv3p5(const ARMISARegisters *id)
785
+{
786
+ return FIELD_EX64(id->id_aa64dfr0, ID_AA64DFR0, PMUVER) >= 6 &&
787
+ FIELD_EX64(id->id_aa64dfr0, ID_AA64DFR0, PMUVER) != 0xf;
788
+}
789
+
790
+static inline bool isar_feature_aa64_rcpc_8_3(const ARMISARegisters *id)
791
+{
792
+ return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, LRCPC) != 0;
793
+}
794
+
795
+static inline bool isar_feature_aa64_rcpc_8_4(const ARMISARegisters *id)
796
+{
797
+ return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, LRCPC) >= 2;
798
+}
799
+
800
+static inline bool isar_feature_aa64_i8mm(const ARMISARegisters *id)
801
+{
802
+ return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, I8MM) != 0;
803
+}
804
+
805
+static inline bool isar_feature_aa64_hbc(const ARMISARegisters *id)
806
+{
807
+ return FIELD_EX64(id->id_aa64isar2, ID_AA64ISAR2, BC) != 0;
808
+}
809
+
810
+static inline bool isar_feature_aa64_tgran4_lpa2(const ARMISARegisters *id)
811
+{
812
+ return FIELD_SEX64(id->id_aa64mmfr0, ID_AA64MMFR0, TGRAN4) >= 1;
813
+}
814
+
815
+static inline bool isar_feature_aa64_tgran4_2_lpa2(const ARMISARegisters *id)
816
+{
817
+ unsigned t = FIELD_EX64(id->id_aa64mmfr0, ID_AA64MMFR0, TGRAN4_2);
818
+ return t >= 3 || (t == 0 && isar_feature_aa64_tgran4_lpa2(id));
819
+}
820
+
821
+static inline bool isar_feature_aa64_tgran16_lpa2(const ARMISARegisters *id)
822
+{
823
+ return FIELD_EX64(id->id_aa64mmfr0, ID_AA64MMFR0, TGRAN16) >= 2;
824
+}
825
+
826
+static inline bool isar_feature_aa64_tgran16_2_lpa2(const ARMISARegisters *id)
827
+{
828
+ unsigned t = FIELD_EX64(id->id_aa64mmfr0, ID_AA64MMFR0, TGRAN16_2);
829
+ return t >= 3 || (t == 0 && isar_feature_aa64_tgran16_lpa2(id));
830
+}
831
+
832
+static inline bool isar_feature_aa64_tgran4(const ARMISARegisters *id)
833
+{
834
+ return FIELD_SEX64(id->id_aa64mmfr0, ID_AA64MMFR0, TGRAN4) >= 0;
835
+}
836
+
837
+static inline bool isar_feature_aa64_tgran16(const ARMISARegisters *id)
838
+{
839
+ return FIELD_EX64(id->id_aa64mmfr0, ID_AA64MMFR0, TGRAN16) >= 1;
840
+}
841
+
842
+static inline bool isar_feature_aa64_tgran64(const ARMISARegisters *id)
843
+{
844
+ return FIELD_SEX64(id->id_aa64mmfr0, ID_AA64MMFR0, TGRAN64) >= 0;
845
+}
846
+
847
+static inline bool isar_feature_aa64_tgran4_2(const ARMISARegisters *id)
848
+{
849
+ unsigned t = FIELD_EX64(id->id_aa64mmfr0, ID_AA64MMFR0, TGRAN4_2);
850
+ return t >= 2 || (t == 0 && isar_feature_aa64_tgran4(id));
851
+}
852
+
853
+static inline bool isar_feature_aa64_tgran16_2(const ARMISARegisters *id)
854
+{
855
+ unsigned t = FIELD_EX64(id->id_aa64mmfr0, ID_AA64MMFR0, TGRAN16_2);
856
+ return t >= 2 || (t == 0 && isar_feature_aa64_tgran16(id));
857
+}
858
+
859
+static inline bool isar_feature_aa64_tgran64_2(const ARMISARegisters *id)
860
+{
861
+ unsigned t = FIELD_EX64(id->id_aa64mmfr0, ID_AA64MMFR0, TGRAN64_2);
862
+ return t >= 2 || (t == 0 && isar_feature_aa64_tgran64(id));
863
+}
864
+
865
+static inline bool isar_feature_aa64_fgt(const ARMISARegisters *id)
866
+{
867
+ return FIELD_EX64(id->id_aa64mmfr0, ID_AA64MMFR0, FGT) != 0;
868
+}
869
+
870
+static inline bool isar_feature_aa64_ccidx(const ARMISARegisters *id)
871
+{
872
+ return FIELD_EX64(id->id_aa64mmfr2, ID_AA64MMFR2, CCIDX) != 0;
873
+}
874
+
875
+static inline bool isar_feature_aa64_lva(const ARMISARegisters *id)
876
+{
877
+ return FIELD_EX64(id->id_aa64mmfr2, ID_AA64MMFR2, VARANGE) != 0;
878
+}
879
+
880
+static inline bool isar_feature_aa64_e0pd(const ARMISARegisters *id)
881
+{
882
+ return FIELD_EX64(id->id_aa64mmfr2, ID_AA64MMFR2, E0PD) != 0;
883
+}
884
+
885
+static inline bool isar_feature_aa64_hafs(const ARMISARegisters *id)
886
+{
887
+ return FIELD_EX64(id->id_aa64mmfr1, ID_AA64MMFR1, HAFDBS) != 0;
888
+}
889
+
890
+static inline bool isar_feature_aa64_hdbs(const ARMISARegisters *id)
891
+{
892
+ return FIELD_EX64(id->id_aa64mmfr1, ID_AA64MMFR1, HAFDBS) >= 2;
893
+}
894
+
895
+static inline bool isar_feature_aa64_tts2uxn(const ARMISARegisters *id)
896
+{
897
+ return FIELD_EX64(id->id_aa64mmfr1, ID_AA64MMFR1, XNX) != 0;
898
+}
899
+
900
+static inline bool isar_feature_aa64_dit(const ARMISARegisters *id)
901
+{
902
+ return FIELD_EX64(id->id_aa64pfr0, ID_AA64PFR0, DIT) != 0;
903
+}
904
+
905
+static inline bool isar_feature_aa64_scxtnum(const ARMISARegisters *id)
906
+{
907
+ int key = FIELD_EX64(id->id_aa64pfr0, ID_AA64PFR0, CSV2);
908
+ if (key >= 2) {
909
+ return true; /* FEAT_CSV2_2 */
910
+ }
911
+ if (key == 1) {
912
+ key = FIELD_EX64(id->id_aa64pfr1, ID_AA64PFR1, CSV2_FRAC);
913
+ return key >= 2; /* FEAT_CSV2_1p2 */
914
+ }
915
+ return false;
916
+}
917
+
918
+static inline bool isar_feature_aa64_ssbs(const ARMISARegisters *id)
919
+{
920
+ return FIELD_EX64(id->id_aa64pfr1, ID_AA64PFR1, SSBS) != 0;
921
+}
922
+
923
+static inline bool isar_feature_aa64_debugv8p2(const ARMISARegisters *id)
924
+{
925
+ return FIELD_EX64(id->id_aa64dfr0, ID_AA64DFR0, DEBUGVER) >= 8;
926
+}
927
+
928
+static inline bool isar_feature_aa64_sve2(const ARMISARegisters *id)
929
+{
930
+ return FIELD_EX64(id->id_aa64zfr0, ID_AA64ZFR0, SVEVER) != 0;
931
+}
932
+
933
+static inline bool isar_feature_aa64_sve2_aes(const ARMISARegisters *id)
934
+{
935
+ return FIELD_EX64(id->id_aa64zfr0, ID_AA64ZFR0, AES) != 0;
936
+}
937
+
938
+static inline bool isar_feature_aa64_sve2_pmull128(const ARMISARegisters *id)
939
+{
940
+ return FIELD_EX64(id->id_aa64zfr0, ID_AA64ZFR0, AES) >= 2;
941
+}
942
+
943
+static inline bool isar_feature_aa64_sve2_bitperm(const ARMISARegisters *id)
944
+{
945
+ return FIELD_EX64(id->id_aa64zfr0, ID_AA64ZFR0, BITPERM) != 0;
946
+}
947
+
948
+static inline bool isar_feature_aa64_sve_bf16(const ARMISARegisters *id)
949
+{
950
+ return FIELD_EX64(id->id_aa64zfr0, ID_AA64ZFR0, BFLOAT16) != 0;
951
+}
952
+
953
+static inline bool isar_feature_aa64_sve2_sha3(const ARMISARegisters *id)
954
+{
955
+ return FIELD_EX64(id->id_aa64zfr0, ID_AA64ZFR0, SHA3) != 0;
956
+}
957
+
958
+static inline bool isar_feature_aa64_sve2_sm4(const ARMISARegisters *id)
959
+{
960
+ return FIELD_EX64(id->id_aa64zfr0, ID_AA64ZFR0, SM4) != 0;
961
+}
962
+
963
+static inline bool isar_feature_aa64_sve_i8mm(const ARMISARegisters *id)
964
+{
965
+ return FIELD_EX64(id->id_aa64zfr0, ID_AA64ZFR0, I8MM) != 0;
966
+}
967
+
968
+static inline bool isar_feature_aa64_sve_f32mm(const ARMISARegisters *id)
969
+{
970
+ return FIELD_EX64(id->id_aa64zfr0, ID_AA64ZFR0, F32MM) != 0;
971
+}
972
+
973
+static inline bool isar_feature_aa64_sve_f64mm(const ARMISARegisters *id)
974
+{
975
+ return FIELD_EX64(id->id_aa64zfr0, ID_AA64ZFR0, F64MM) != 0;
976
+}
977
+
978
+static inline bool isar_feature_aa64_sme_f64f64(const ARMISARegisters *id)
979
+{
980
+ return FIELD_EX64(id->id_aa64smfr0, ID_AA64SMFR0, F64F64);
981
+}
982
+
983
+static inline bool isar_feature_aa64_sme_i16i64(const ARMISARegisters *id)
984
+{
985
+ return FIELD_EX64(id->id_aa64smfr0, ID_AA64SMFR0, I16I64) == 0xf;
986
+}
987
+
988
+static inline bool isar_feature_aa64_sme_fa64(const ARMISARegisters *id)
989
+{
990
+ return FIELD_EX64(id->id_aa64smfr0, ID_AA64SMFR0, FA64);
991
+}
992
+
993
+static inline bool isar_feature_aa64_doublelock(const ARMISARegisters *id)
994
+{
995
+ return FIELD_SEX64(id->id_aa64dfr0, ID_AA64DFR0, DOUBLELOCK) >= 0;
996
+}
997
+
998
+static inline bool isar_feature_aa64_mops(const ARMISARegisters *id)
999
+{
1000
+ return FIELD_EX64(id->id_aa64isar2, ID_AA64ISAR2, MOPS);
1001
+}
1002
+
1003
+/*
1004
+ * Feature tests for "does this exist in either 32-bit or 64-bit?"
1005
+ */
1006
+static inline bool isar_feature_any_fp16(const ARMISARegisters *id)
1007
+{
1008
+ return isar_feature_aa64_fp16(id) || isar_feature_aa32_fp16_arith(id);
1009
+}
1010
+
1011
+static inline bool isar_feature_any_predinv(const ARMISARegisters *id)
1012
+{
1013
+ return isar_feature_aa64_predinv(id) || isar_feature_aa32_predinv(id);
1014
+}
1015
+
1016
+static inline bool isar_feature_any_pmuv3p1(const ARMISARegisters *id)
1017
+{
1018
+ return isar_feature_aa64_pmuv3p1(id) || isar_feature_aa32_pmuv3p1(id);
1019
+}
1020
+
1021
+static inline bool isar_feature_any_pmuv3p4(const ARMISARegisters *id)
1022
+{
1023
+ return isar_feature_aa64_pmuv3p4(id) || isar_feature_aa32_pmuv3p4(id);
1024
+}
1025
+
1026
+static inline bool isar_feature_any_pmuv3p5(const ARMISARegisters *id)
1027
+{
1028
+ return isar_feature_aa64_pmuv3p5(id) || isar_feature_aa32_pmuv3p5(id);
1029
+}
1030
+
1031
+static inline bool isar_feature_any_ccidx(const ARMISARegisters *id)
1032
+{
1033
+ return isar_feature_aa64_ccidx(id) || isar_feature_aa32_ccidx(id);
1034
+}
1035
+
1036
+static inline bool isar_feature_any_tts2uxn(const ARMISARegisters *id)
1037
+{
1038
+ return isar_feature_aa64_tts2uxn(id) || isar_feature_aa32_tts2uxn(id);
1039
+}
1040
+
1041
+static inline bool isar_feature_any_debugv8p2(const ARMISARegisters *id)
1042
+{
1043
+ return isar_feature_aa64_debugv8p2(id) || isar_feature_aa32_debugv8p2(id);
1044
+}
1045
+
1046
+static inline bool isar_feature_any_ras(const ARMISARegisters *id)
1047
+{
1048
+ return isar_feature_aa64_ras(id) || isar_feature_aa32_ras(id);
1049
+}
1050
+
1051
+static inline bool isar_feature_any_half_evt(const ARMISARegisters *id)
1052
+{
1053
+ return isar_feature_aa64_half_evt(id) || isar_feature_aa32_half_evt(id);
1054
+}
1055
+
1056
+static inline bool isar_feature_any_evt(const ARMISARegisters *id)
1057
+{
1058
+ return isar_feature_aa64_evt(id) || isar_feature_aa32_evt(id);
1059
+}
1060
+
1061
+/*
1062
+ * Forward to the above feature tests given an ARMCPU pointer.
1063
+ */
1064
+#define cpu_isar_feature(name, cpu) \
1065
+ ({ ARMCPU *cpu_ = (cpu); isar_feature_##name(&cpu_->isar); })
1066
+
41
+#endif
1067
+#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
1068
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
47
index XXXXXXX..XXXXXXX 100644
1069
index XXXXXXX..XXXXXXX 100644
48
--- a/target/arm/cpu.h
1070
--- a/target/arm/cpu.h
49
+++ b/target/arm/cpu.h
1071
+++ b/target/arm/cpu.h
50
@@ -XXX,XX +XXX,XX @@ static inline MemTxAttrs *typecheck_memtxattrs(MemTxAttrs *x)
1072
@@ -XXX,XX +XXX,XX @@ static inline target_ulong cpu_untagged_addr(CPUState *cs, target_ulong x)
51
#define arm_tlb_bti_gp(x) (typecheck_memtxattrs(x)->target_tlb_bit0)
1073
}
52
#define arm_tlb_mte_tagged(x) (typecheck_memtxattrs(x)->target_tlb_bit1)
1074
#endif
53
1075
54
+/*
1076
-/*
55
+ * AArch64 usage of the PAGE_TARGET_* bits for linux-user.
1077
- * Naming convention for isar_feature functions:
56
+ */
1078
- * Functions which test 32-bit ID registers should have _aa32_ in
57
+#define PAGE_BTI PAGE_TARGET_1
1079
- * their name. Functions which test 64-bit ID registers should have
58
+
1080
- * _aa64_ in their name. These must only be used in code where we
59
/*
1081
- * know for certain that the CPU has AArch32 or AArch64 respectively
60
* Naming convention for isar_feature functions:
1082
- * or where the correct answer for a CPU which doesn't implement that
61
* Functions which test 32-bit ID registers should have _aa32_ in
1083
- * CPU state is "false" (eg when generating A32 or A64 code, if adding
1084
- * system registers that are specific to that CPU state, for "should
1085
- * we let this system register bit be set" tests where the 32-bit
1086
- * flavour of the register doesn't have the bit, and so on).
1087
- * Functions which simply ask "does this feature exist at all" have
1088
- * _any_ in their name, and always return the logical OR of the _aa64_
1089
- * and the _aa32_ function.
1090
- */
1091
-
1092
-/*
1093
- * 32-bit feature tests via id registers.
1094
- */
1095
-static inline bool isar_feature_aa32_thumb_div(const ARMISARegisters *id)
1096
-{
1097
- return FIELD_EX32(id->id_isar0, ID_ISAR0, DIVIDE) != 0;
1098
-}
1099
-
1100
-static inline bool isar_feature_aa32_arm_div(const ARMISARegisters *id)
1101
-{
1102
- return FIELD_EX32(id->id_isar0, ID_ISAR0, DIVIDE) > 1;
1103
-}
1104
-
1105
-static inline bool isar_feature_aa32_lob(const ARMISARegisters *id)
1106
-{
1107
- /* (M-profile) low-overhead loops and branch future */
1108
- return FIELD_EX32(id->id_isar0, ID_ISAR0, CMPBRANCH) >= 3;
1109
-}
1110
-
1111
-static inline bool isar_feature_aa32_jazelle(const ARMISARegisters *id)
1112
-{
1113
- return FIELD_EX32(id->id_isar1, ID_ISAR1, JAZELLE) != 0;
1114
-}
1115
-
1116
-static inline bool isar_feature_aa32_aes(const ARMISARegisters *id)
1117
-{
1118
- return FIELD_EX32(id->id_isar5, ID_ISAR5, AES) != 0;
1119
-}
1120
-
1121
-static inline bool isar_feature_aa32_pmull(const ARMISARegisters *id)
1122
-{
1123
- return FIELD_EX32(id->id_isar5, ID_ISAR5, AES) > 1;
1124
-}
1125
-
1126
-static inline bool isar_feature_aa32_sha1(const ARMISARegisters *id)
1127
-{
1128
- return FIELD_EX32(id->id_isar5, ID_ISAR5, SHA1) != 0;
1129
-}
1130
-
1131
-static inline bool isar_feature_aa32_sha2(const ARMISARegisters *id)
1132
-{
1133
- return FIELD_EX32(id->id_isar5, ID_ISAR5, SHA2) != 0;
1134
-}
1135
-
1136
-static inline bool isar_feature_aa32_crc32(const ARMISARegisters *id)
1137
-{
1138
- return FIELD_EX32(id->id_isar5, ID_ISAR5, CRC32) != 0;
1139
-}
1140
-
1141
-static inline bool isar_feature_aa32_rdm(const ARMISARegisters *id)
1142
-{
1143
- return FIELD_EX32(id->id_isar5, ID_ISAR5, RDM) != 0;
1144
-}
1145
-
1146
-static inline bool isar_feature_aa32_vcma(const ARMISARegisters *id)
1147
-{
1148
- return FIELD_EX32(id->id_isar5, ID_ISAR5, VCMA) != 0;
1149
-}
1150
-
1151
-static inline bool isar_feature_aa32_jscvt(const ARMISARegisters *id)
1152
-{
1153
- return FIELD_EX32(id->id_isar6, ID_ISAR6, JSCVT) != 0;
1154
-}
1155
-
1156
-static inline bool isar_feature_aa32_dp(const ARMISARegisters *id)
1157
-{
1158
- return FIELD_EX32(id->id_isar6, ID_ISAR6, DP) != 0;
1159
-}
1160
-
1161
-static inline bool isar_feature_aa32_fhm(const ARMISARegisters *id)
1162
-{
1163
- return FIELD_EX32(id->id_isar6, ID_ISAR6, FHM) != 0;
1164
-}
1165
-
1166
-static inline bool isar_feature_aa32_sb(const ARMISARegisters *id)
1167
-{
1168
- return FIELD_EX32(id->id_isar6, ID_ISAR6, SB) != 0;
1169
-}
1170
-
1171
-static inline bool isar_feature_aa32_predinv(const ARMISARegisters *id)
1172
-{
1173
- return FIELD_EX32(id->id_isar6, ID_ISAR6, SPECRES) != 0;
1174
-}
1175
-
1176
-static inline bool isar_feature_aa32_bf16(const ARMISARegisters *id)
1177
-{
1178
- return FIELD_EX32(id->id_isar6, ID_ISAR6, BF16) != 0;
1179
-}
1180
-
1181
-static inline bool isar_feature_aa32_i8mm(const ARMISARegisters *id)
1182
-{
1183
- return FIELD_EX32(id->id_isar6, ID_ISAR6, I8MM) != 0;
1184
-}
1185
-
1186
-static inline bool isar_feature_aa32_ras(const ARMISARegisters *id)
1187
-{
1188
- return FIELD_EX32(id->id_pfr0, ID_PFR0, RAS) != 0;
1189
-}
1190
-
1191
-static inline bool isar_feature_aa32_mprofile(const ARMISARegisters *id)
1192
-{
1193
- return FIELD_EX32(id->id_pfr1, ID_PFR1, MPROGMOD) != 0;
1194
-}
1195
-
1196
-static inline bool isar_feature_aa32_m_sec_state(const ARMISARegisters *id)
1197
-{
1198
- /*
1199
- * Return true if M-profile state handling insns
1200
- * (VSCCLRM, CLRM, FPCTX access insns) are implemented
1201
- */
1202
- return FIELD_EX32(id->id_pfr1, ID_PFR1, SECURITY) >= 3;
1203
-}
1204
-
1205
-static inline bool isar_feature_aa32_fp16_arith(const ARMISARegisters *id)
1206
-{
1207
- /* Sadly this is encoded differently for A-profile and M-profile */
1208
- if (isar_feature_aa32_mprofile(id)) {
1209
- return FIELD_EX32(id->mvfr1, MVFR1, FP16) > 0;
1210
- } else {
1211
- return FIELD_EX32(id->mvfr1, MVFR1, FPHP) >= 3;
1212
- }
1213
-}
1214
-
1215
-static inline bool isar_feature_aa32_mve(const ARMISARegisters *id)
1216
-{
1217
- /*
1218
- * Return true if MVE is supported (either integer or floating point).
1219
- * We must check for M-profile as the MVFR1 field means something
1220
- * else for A-profile.
1221
- */
1222
- return isar_feature_aa32_mprofile(id) &&
1223
- FIELD_EX32(id->mvfr1, MVFR1, MVE) > 0;
1224
-}
1225
-
1226
-static inline bool isar_feature_aa32_mve_fp(const ARMISARegisters *id)
1227
-{
1228
- /*
1229
- * Return true if MVE is supported (either integer or floating point).
1230
- * We must check for M-profile as the MVFR1 field means something
1231
- * else for A-profile.
1232
- */
1233
- return isar_feature_aa32_mprofile(id) &&
1234
- FIELD_EX32(id->mvfr1, MVFR1, MVE) >= 2;
1235
-}
1236
-
1237
-static inline bool isar_feature_aa32_vfp_simd(const ARMISARegisters *id)
1238
-{
1239
- /*
1240
- * Return true if either VFP or SIMD is implemented.
1241
- * In this case, a minimum of VFP w/ D0-D15.
1242
- */
1243
- return FIELD_EX32(id->mvfr0, MVFR0, SIMDREG) > 0;
1244
-}
1245
-
1246
-static inline bool isar_feature_aa32_simd_r32(const ARMISARegisters *id)
1247
-{
1248
- /* Return true if D16-D31 are implemented */
1249
- return FIELD_EX32(id->mvfr0, MVFR0, SIMDREG) >= 2;
1250
-}
1251
-
1252
-static inline bool isar_feature_aa32_fpshvec(const ARMISARegisters *id)
1253
-{
1254
- return FIELD_EX32(id->mvfr0, MVFR0, FPSHVEC) > 0;
1255
-}
1256
-
1257
-static inline bool isar_feature_aa32_fpsp_v2(const ARMISARegisters *id)
1258
-{
1259
- /* Return true if CPU supports single precision floating point, VFPv2 */
1260
- return FIELD_EX32(id->mvfr0, MVFR0, FPSP) > 0;
1261
-}
1262
-
1263
-static inline bool isar_feature_aa32_fpsp_v3(const ARMISARegisters *id)
1264
-{
1265
- /* Return true if CPU supports single precision floating point, VFPv3 */
1266
- return FIELD_EX32(id->mvfr0, MVFR0, FPSP) >= 2;
1267
-}
1268
-
1269
-static inline bool isar_feature_aa32_fpdp_v2(const ARMISARegisters *id)
1270
-{
1271
- /* Return true if CPU supports double precision floating point, VFPv2 */
1272
- return FIELD_EX32(id->mvfr0, MVFR0, FPDP) > 0;
1273
-}
1274
-
1275
-static inline bool isar_feature_aa32_fpdp_v3(const ARMISARegisters *id)
1276
-{
1277
- /* Return true if CPU supports double precision floating point, VFPv3 */
1278
- return FIELD_EX32(id->mvfr0, MVFR0, FPDP) >= 2;
1279
-}
1280
-
1281
-static inline bool isar_feature_aa32_vfp(const ARMISARegisters *id)
1282
-{
1283
- return isar_feature_aa32_fpsp_v2(id) || isar_feature_aa32_fpdp_v2(id);
1284
-}
1285
-
1286
-/*
1287
- * We always set the FP and SIMD FP16 fields to indicate identical
1288
- * levels of support (assuming SIMD is implemented at all), so
1289
- * we only need one set of accessors.
1290
- */
1291
-static inline bool isar_feature_aa32_fp16_spconv(const ARMISARegisters *id)
1292
-{
1293
- return FIELD_EX32(id->mvfr1, MVFR1, FPHP) > 0;
1294
-}
1295
-
1296
-static inline bool isar_feature_aa32_fp16_dpconv(const ARMISARegisters *id)
1297
-{
1298
- return FIELD_EX32(id->mvfr1, MVFR1, FPHP) > 1;
1299
-}
1300
-
1301
-/*
1302
- * Note that this ID register field covers both VFP and Neon FMAC,
1303
- * so should usually be tested in combination with some other
1304
- * check that confirms the presence of whichever of VFP or Neon is
1305
- * relevant, to avoid accidentally enabling a Neon feature on
1306
- * a VFP-no-Neon core or vice-versa.
1307
- */
1308
-static inline bool isar_feature_aa32_simdfmac(const ARMISARegisters *id)
1309
-{
1310
- return FIELD_EX32(id->mvfr1, MVFR1, SIMDFMAC) != 0;
1311
-}
1312
-
1313
-static inline bool isar_feature_aa32_vsel(const ARMISARegisters *id)
1314
-{
1315
- return FIELD_EX32(id->mvfr2, MVFR2, FPMISC) >= 1;
1316
-}
1317
-
1318
-static inline bool isar_feature_aa32_vcvt_dr(const ARMISARegisters *id)
1319
-{
1320
- return FIELD_EX32(id->mvfr2, MVFR2, FPMISC) >= 2;
1321
-}
1322
-
1323
-static inline bool isar_feature_aa32_vrint(const ARMISARegisters *id)
1324
-{
1325
- return FIELD_EX32(id->mvfr2, MVFR2, FPMISC) >= 3;
1326
-}
1327
-
1328
-static inline bool isar_feature_aa32_vminmaxnm(const ARMISARegisters *id)
1329
-{
1330
- return FIELD_EX32(id->mvfr2, MVFR2, FPMISC) >= 4;
1331
-}
1332
-
1333
-static inline bool isar_feature_aa32_pxn(const ARMISARegisters *id)
1334
-{
1335
- return FIELD_EX32(id->id_mmfr0, ID_MMFR0, VMSA) >= 4;
1336
-}
1337
-
1338
-static inline bool isar_feature_aa32_pan(const ARMISARegisters *id)
1339
-{
1340
- return FIELD_EX32(id->id_mmfr3, ID_MMFR3, PAN) != 0;
1341
-}
1342
-
1343
-static inline bool isar_feature_aa32_ats1e1(const ARMISARegisters *id)
1344
-{
1345
- return FIELD_EX32(id->id_mmfr3, ID_MMFR3, PAN) >= 2;
1346
-}
1347
-
1348
-static inline bool isar_feature_aa32_pmuv3p1(const ARMISARegisters *id)
1349
-{
1350
- /* 0xf means "non-standard IMPDEF PMU" */
1351
- return FIELD_EX32(id->id_dfr0, ID_DFR0, PERFMON) >= 4 &&
1352
- FIELD_EX32(id->id_dfr0, ID_DFR0, PERFMON) != 0xf;
1353
-}
1354
-
1355
-static inline bool isar_feature_aa32_pmuv3p4(const ARMISARegisters *id)
1356
-{
1357
- /* 0xf means "non-standard IMPDEF PMU" */
1358
- return FIELD_EX32(id->id_dfr0, ID_DFR0, PERFMON) >= 5 &&
1359
- FIELD_EX32(id->id_dfr0, ID_DFR0, PERFMON) != 0xf;
1360
-}
1361
-
1362
-static inline bool isar_feature_aa32_pmuv3p5(const ARMISARegisters *id)
1363
-{
1364
- /* 0xf means "non-standard IMPDEF PMU" */
1365
- return FIELD_EX32(id->id_dfr0, ID_DFR0, PERFMON) >= 6 &&
1366
- FIELD_EX32(id->id_dfr0, ID_DFR0, PERFMON) != 0xf;
1367
-}
1368
-
1369
-static inline bool isar_feature_aa32_hpd(const ARMISARegisters *id)
1370
-{
1371
- return FIELD_EX32(id->id_mmfr4, ID_MMFR4, HPDS) != 0;
1372
-}
1373
-
1374
-static inline bool isar_feature_aa32_ac2(const ARMISARegisters *id)
1375
-{
1376
- return FIELD_EX32(id->id_mmfr4, ID_MMFR4, AC2) != 0;
1377
-}
1378
-
1379
-static inline bool isar_feature_aa32_ccidx(const ARMISARegisters *id)
1380
-{
1381
- return FIELD_EX32(id->id_mmfr4, ID_MMFR4, CCIDX) != 0;
1382
-}
1383
-
1384
-static inline bool isar_feature_aa32_tts2uxn(const ARMISARegisters *id)
1385
-{
1386
- return FIELD_EX32(id->id_mmfr4, ID_MMFR4, XNX) != 0;
1387
-}
1388
-
1389
-static inline bool isar_feature_aa32_half_evt(const ARMISARegisters *id)
1390
-{
1391
- return FIELD_EX32(id->id_mmfr4, ID_MMFR4, EVT) >= 1;
1392
-}
1393
-
1394
-static inline bool isar_feature_aa32_evt(const ARMISARegisters *id)
1395
-{
1396
- return FIELD_EX32(id->id_mmfr4, ID_MMFR4, EVT) >= 2;
1397
-}
1398
-
1399
-static inline bool isar_feature_aa32_dit(const ARMISARegisters *id)
1400
-{
1401
- return FIELD_EX32(id->id_pfr0, ID_PFR0, DIT) != 0;
1402
-}
1403
-
1404
-static inline bool isar_feature_aa32_ssbs(const ARMISARegisters *id)
1405
-{
1406
- return FIELD_EX32(id->id_pfr2, ID_PFR2, SSBS) != 0;
1407
-}
1408
-
1409
-static inline bool isar_feature_aa32_debugv7p1(const ARMISARegisters *id)
1410
-{
1411
- return FIELD_EX32(id->id_dfr0, ID_DFR0, COPDBG) >= 5;
1412
-}
1413
-
1414
-static inline bool isar_feature_aa32_debugv8p2(const ARMISARegisters *id)
1415
-{
1416
- return FIELD_EX32(id->id_dfr0, ID_DFR0, COPDBG) >= 8;
1417
-}
1418
-
1419
-static inline bool isar_feature_aa32_doublelock(const ARMISARegisters *id)
1420
-{
1421
- return FIELD_EX32(id->dbgdevid, DBGDEVID, DOUBLELOCK) > 0;
1422
-}
1423
-
1424
-/*
1425
- * 64-bit feature tests via id registers.
1426
- */
1427
-static inline bool isar_feature_aa64_aes(const ARMISARegisters *id)
1428
-{
1429
- return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, AES) != 0;
1430
-}
1431
-
1432
-static inline bool isar_feature_aa64_pmull(const ARMISARegisters *id)
1433
-{
1434
- return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, AES) > 1;
1435
-}
1436
-
1437
-static inline bool isar_feature_aa64_sha1(const ARMISARegisters *id)
1438
-{
1439
- return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, SHA1) != 0;
1440
-}
1441
-
1442
-static inline bool isar_feature_aa64_sha256(const ARMISARegisters *id)
1443
-{
1444
- return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, SHA2) != 0;
1445
-}
1446
-
1447
-static inline bool isar_feature_aa64_sha512(const ARMISARegisters *id)
1448
-{
1449
- return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, SHA2) > 1;
1450
-}
1451
-
1452
-static inline bool isar_feature_aa64_crc32(const ARMISARegisters *id)
1453
-{
1454
- return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, CRC32) != 0;
1455
-}
1456
-
1457
-static inline bool isar_feature_aa64_atomics(const ARMISARegisters *id)
1458
-{
1459
- return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, ATOMIC) != 0;
1460
-}
1461
-
1462
-static inline bool isar_feature_aa64_rdm(const ARMISARegisters *id)
1463
-{
1464
- return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, RDM) != 0;
1465
-}
1466
-
1467
-static inline bool isar_feature_aa64_sha3(const ARMISARegisters *id)
1468
-{
1469
- return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, SHA3) != 0;
1470
-}
1471
-
1472
-static inline bool isar_feature_aa64_sm3(const ARMISARegisters *id)
1473
-{
1474
- return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, SM3) != 0;
1475
-}
1476
-
1477
-static inline bool isar_feature_aa64_sm4(const ARMISARegisters *id)
1478
-{
1479
- return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, SM4) != 0;
1480
-}
1481
-
1482
-static inline bool isar_feature_aa64_dp(const ARMISARegisters *id)
1483
-{
1484
- return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, DP) != 0;
1485
-}
1486
-
1487
-static inline bool isar_feature_aa64_fhm(const ARMISARegisters *id)
1488
-{
1489
- return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, FHM) != 0;
1490
-}
1491
-
1492
-static inline bool isar_feature_aa64_condm_4(const ARMISARegisters *id)
1493
-{
1494
- return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, TS) != 0;
1495
-}
1496
-
1497
-static inline bool isar_feature_aa64_condm_5(const ARMISARegisters *id)
1498
-{
1499
- return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, TS) >= 2;
1500
-}
1501
-
1502
-static inline bool isar_feature_aa64_rndr(const ARMISARegisters *id)
1503
-{
1504
- return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, RNDR) != 0;
1505
-}
1506
-
1507
-static inline bool isar_feature_aa64_jscvt(const ARMISARegisters *id)
1508
-{
1509
- return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, JSCVT) != 0;
1510
-}
1511
-
1512
-static inline bool isar_feature_aa64_fcma(const ARMISARegisters *id)
1513
-{
1514
- return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, FCMA) != 0;
1515
-}
1516
-
1517
-/*
1518
- * These are the values from APA/API/APA3.
1519
- * In general these must be compared '>=', per the normal Arm ARM
1520
- * treatment of fields in ID registers.
1521
- */
1522
-typedef enum {
1523
- PauthFeat_None = 0,
1524
- PauthFeat_1 = 1,
1525
- PauthFeat_EPAC = 2,
1526
- PauthFeat_2 = 3,
1527
- PauthFeat_FPAC = 4,
1528
- PauthFeat_FPACCOMBINED = 5,
1529
-} ARMPauthFeature;
1530
-
1531
-static inline ARMPauthFeature
1532
-isar_feature_pauth_feature(const ARMISARegisters *id)
1533
-{
1534
- /*
1535
- * Architecturally, only one of {APA,API,APA3} may be active (non-zero)
1536
- * and the other two must be zero. Thus we may avoid conditionals.
1537
- */
1538
- return (FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, APA) |
1539
- FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, API) |
1540
- FIELD_EX64(id->id_aa64isar2, ID_AA64ISAR2, APA3));
1541
-}
1542
-
1543
-static inline bool isar_feature_aa64_pauth(const ARMISARegisters *id)
1544
-{
1545
- /*
1546
- * Return true if any form of pauth is enabled, as this
1547
- * predicate controls migration of the 128-bit keys.
1548
- */
1549
- return isar_feature_pauth_feature(id) != PauthFeat_None;
1550
-}
1551
-
1552
-static inline bool isar_feature_aa64_pauth_qarma5(const ARMISARegisters *id)
1553
-{
1554
- /*
1555
- * Return true if pauth is enabled with the architected QARMA5 algorithm.
1556
- * QEMU will always enable or disable both APA and GPA.
1557
- */
1558
- return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, APA) != 0;
1559
-}
1560
-
1561
-static inline bool isar_feature_aa64_pauth_qarma3(const ARMISARegisters *id)
1562
-{
1563
- /*
1564
- * Return true if pauth is enabled with the architected QARMA3 algorithm.
1565
- * QEMU will always enable or disable both APA3 and GPA3.
1566
- */
1567
- return FIELD_EX64(id->id_aa64isar2, ID_AA64ISAR2, APA3) != 0;
1568
-}
1569
-
1570
-static inline bool isar_feature_aa64_tlbirange(const ARMISARegisters *id)
1571
-{
1572
- return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, TLB) == 2;
1573
-}
1574
-
1575
-static inline bool isar_feature_aa64_tlbios(const ARMISARegisters *id)
1576
-{
1577
- return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, TLB) != 0;
1578
-}
1579
-
1580
-static inline bool isar_feature_aa64_sb(const ARMISARegisters *id)
1581
-{
1582
- return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, SB) != 0;
1583
-}
1584
-
1585
-static inline bool isar_feature_aa64_predinv(const ARMISARegisters *id)
1586
-{
1587
- return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, SPECRES) != 0;
1588
-}
1589
-
1590
-static inline bool isar_feature_aa64_frint(const ARMISARegisters *id)
1591
-{
1592
- return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, FRINTTS) != 0;
1593
-}
1594
-
1595
-static inline bool isar_feature_aa64_dcpop(const ARMISARegisters *id)
1596
-{
1597
- return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, DPB) != 0;
1598
-}
1599
-
1600
-static inline bool isar_feature_aa64_dcpodp(const ARMISARegisters *id)
1601
-{
1602
- return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, DPB) >= 2;
1603
-}
1604
-
1605
-static inline bool isar_feature_aa64_bf16(const ARMISARegisters *id)
1606
-{
1607
- return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, BF16) != 0;
1608
-}
1609
-
1610
-static inline bool isar_feature_aa64_fp_simd(const ARMISARegisters *id)
1611
-{
1612
- /* We always set the AdvSIMD and FP fields identically. */
1613
- return FIELD_EX64(id->id_aa64pfr0, ID_AA64PFR0, FP) != 0xf;
1614
-}
1615
-
1616
-static inline bool isar_feature_aa64_fp16(const ARMISARegisters *id)
1617
-{
1618
- /* We always set the AdvSIMD and FP fields identically wrt FP16. */
1619
- return FIELD_EX64(id->id_aa64pfr0, ID_AA64PFR0, FP) == 1;
1620
-}
1621
-
1622
-static inline bool isar_feature_aa64_aa32(const ARMISARegisters *id)
1623
-{
1624
- return FIELD_EX64(id->id_aa64pfr0, ID_AA64PFR0, EL0) >= 2;
1625
-}
1626
-
1627
-static inline bool isar_feature_aa64_aa32_el1(const ARMISARegisters *id)
1628
-{
1629
- return FIELD_EX64(id->id_aa64pfr0, ID_AA64PFR0, EL1) >= 2;
1630
-}
1631
-
1632
-static inline bool isar_feature_aa64_aa32_el2(const ARMISARegisters *id)
1633
-{
1634
- return FIELD_EX64(id->id_aa64pfr0, ID_AA64PFR0, EL2) >= 2;
1635
-}
1636
-
1637
-static inline bool isar_feature_aa64_ras(const ARMISARegisters *id)
1638
-{
1639
- return FIELD_EX64(id->id_aa64pfr0, ID_AA64PFR0, RAS) != 0;
1640
-}
1641
-
1642
-static inline bool isar_feature_aa64_doublefault(const ARMISARegisters *id)
1643
-{
1644
- return FIELD_EX64(id->id_aa64pfr0, ID_AA64PFR0, RAS) >= 2;
1645
-}
1646
-
1647
-static inline bool isar_feature_aa64_sve(const ARMISARegisters *id)
1648
-{
1649
- return FIELD_EX64(id->id_aa64pfr0, ID_AA64PFR0, SVE) != 0;
1650
-}
1651
-
1652
-static inline bool isar_feature_aa64_sel2(const ARMISARegisters *id)
1653
-{
1654
- return FIELD_EX64(id->id_aa64pfr0, ID_AA64PFR0, SEL2) != 0;
1655
-}
1656
-
1657
-static inline bool isar_feature_aa64_rme(const ARMISARegisters *id)
1658
-{
1659
- return FIELD_EX64(id->id_aa64pfr0, ID_AA64PFR0, RME) != 0;
1660
-}
1661
-
1662
-static inline bool isar_feature_aa64_vh(const ARMISARegisters *id)
1663
-{
1664
- return FIELD_EX64(id->id_aa64mmfr1, ID_AA64MMFR1, VH) != 0;
1665
-}
1666
-
1667
-static inline bool isar_feature_aa64_lor(const ARMISARegisters *id)
1668
-{
1669
- return FIELD_EX64(id->id_aa64mmfr1, ID_AA64MMFR1, LO) != 0;
1670
-}
1671
-
1672
-static inline bool isar_feature_aa64_pan(const ARMISARegisters *id)
1673
-{
1674
- return FIELD_EX64(id->id_aa64mmfr1, ID_AA64MMFR1, PAN) != 0;
1675
-}
1676
-
1677
-static inline bool isar_feature_aa64_ats1e1(const ARMISARegisters *id)
1678
-{
1679
- return FIELD_EX64(id->id_aa64mmfr1, ID_AA64MMFR1, PAN) >= 2;
1680
-}
1681
-
1682
-static inline bool isar_feature_aa64_pan3(const ARMISARegisters *id)
1683
-{
1684
- return FIELD_EX64(id->id_aa64mmfr1, ID_AA64MMFR1, PAN) >= 3;
1685
-}
1686
-
1687
-static inline bool isar_feature_aa64_hcx(const ARMISARegisters *id)
1688
-{
1689
- return FIELD_EX64(id->id_aa64mmfr1, ID_AA64MMFR1, HCX) != 0;
1690
-}
1691
-
1692
-static inline bool isar_feature_aa64_tidcp1(const ARMISARegisters *id)
1693
-{
1694
- return FIELD_EX64(id->id_aa64mmfr2, ID_AA64MMFR1, TIDCP1) != 0;
1695
-}
1696
-
1697
-static inline bool isar_feature_aa64_uao(const ARMISARegisters *id)
1698
-{
1699
- return FIELD_EX64(id->id_aa64mmfr2, ID_AA64MMFR2, UAO) != 0;
1700
-}
1701
-
1702
-static inline bool isar_feature_aa64_st(const ARMISARegisters *id)
1703
-{
1704
- return FIELD_EX64(id->id_aa64mmfr2, ID_AA64MMFR2, ST) != 0;
1705
-}
1706
-
1707
-static inline bool isar_feature_aa64_lse2(const ARMISARegisters *id)
1708
-{
1709
- return FIELD_EX64(id->id_aa64mmfr2, ID_AA64MMFR2, AT) != 0;
1710
-}
1711
-
1712
-static inline bool isar_feature_aa64_fwb(const ARMISARegisters *id)
1713
-{
1714
- return FIELD_EX64(id->id_aa64mmfr2, ID_AA64MMFR2, FWB) != 0;
1715
-}
1716
-
1717
-static inline bool isar_feature_aa64_ids(const ARMISARegisters *id)
1718
-{
1719
- return FIELD_EX64(id->id_aa64mmfr2, ID_AA64MMFR2, IDS) != 0;
1720
-}
1721
-
1722
-static inline bool isar_feature_aa64_half_evt(const ARMISARegisters *id)
1723
-{
1724
- return FIELD_EX64(id->id_aa64mmfr2, ID_AA64MMFR2, EVT) >= 1;
1725
-}
1726
-
1727
-static inline bool isar_feature_aa64_evt(const ARMISARegisters *id)
1728
-{
1729
- return FIELD_EX64(id->id_aa64mmfr2, ID_AA64MMFR2, EVT) >= 2;
1730
-}
1731
-
1732
-static inline bool isar_feature_aa64_bti(const ARMISARegisters *id)
1733
-{
1734
- return FIELD_EX64(id->id_aa64pfr1, ID_AA64PFR1, BT) != 0;
1735
-}
1736
-
1737
-static inline bool isar_feature_aa64_mte_insn_reg(const ARMISARegisters *id)
1738
-{
1739
- return FIELD_EX64(id->id_aa64pfr1, ID_AA64PFR1, MTE) != 0;
1740
-}
1741
-
1742
-static inline bool isar_feature_aa64_mte(const ARMISARegisters *id)
1743
-{
1744
- return FIELD_EX64(id->id_aa64pfr1, ID_AA64PFR1, MTE) >= 2;
1745
-}
1746
-
1747
-static inline bool isar_feature_aa64_sme(const ARMISARegisters *id)
1748
-{
1749
- return FIELD_EX64(id->id_aa64pfr1, ID_AA64PFR1, SME) != 0;
1750
-}
1751
-
1752
-static inline bool isar_feature_aa64_pmuv3p1(const ARMISARegisters *id)
1753
-{
1754
- return FIELD_EX64(id->id_aa64dfr0, ID_AA64DFR0, PMUVER) >= 4 &&
1755
- FIELD_EX64(id->id_aa64dfr0, ID_AA64DFR0, PMUVER) != 0xf;
1756
-}
1757
-
1758
-static inline bool isar_feature_aa64_pmuv3p4(const ARMISARegisters *id)
1759
-{
1760
- return FIELD_EX64(id->id_aa64dfr0, ID_AA64DFR0, PMUVER) >= 5 &&
1761
- FIELD_EX64(id->id_aa64dfr0, ID_AA64DFR0, PMUVER) != 0xf;
1762
-}
1763
-
1764
-static inline bool isar_feature_aa64_pmuv3p5(const ARMISARegisters *id)
1765
-{
1766
- return FIELD_EX64(id->id_aa64dfr0, ID_AA64DFR0, PMUVER) >= 6 &&
1767
- FIELD_EX64(id->id_aa64dfr0, ID_AA64DFR0, PMUVER) != 0xf;
1768
-}
1769
-
1770
-static inline bool isar_feature_aa64_rcpc_8_3(const ARMISARegisters *id)
1771
-{
1772
- return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, LRCPC) != 0;
1773
-}
1774
-
1775
-static inline bool isar_feature_aa64_rcpc_8_4(const ARMISARegisters *id)
1776
-{
1777
- return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, LRCPC) >= 2;
1778
-}
1779
-
1780
-static inline bool isar_feature_aa64_i8mm(const ARMISARegisters *id)
1781
-{
1782
- return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, I8MM) != 0;
1783
-}
1784
-
1785
-static inline bool isar_feature_aa64_hbc(const ARMISARegisters *id)
1786
-{
1787
- return FIELD_EX64(id->id_aa64isar2, ID_AA64ISAR2, BC) != 0;
1788
-}
1789
-
1790
-static inline bool isar_feature_aa64_tgran4_lpa2(const ARMISARegisters *id)
1791
-{
1792
- return FIELD_SEX64(id->id_aa64mmfr0, ID_AA64MMFR0, TGRAN4) >= 1;
1793
-}
1794
-
1795
-static inline bool isar_feature_aa64_tgran4_2_lpa2(const ARMISARegisters *id)
1796
-{
1797
- unsigned t = FIELD_EX64(id->id_aa64mmfr0, ID_AA64MMFR0, TGRAN4_2);
1798
- return t >= 3 || (t == 0 && isar_feature_aa64_tgran4_lpa2(id));
1799
-}
1800
-
1801
-static inline bool isar_feature_aa64_tgran16_lpa2(const ARMISARegisters *id)
1802
-{
1803
- return FIELD_EX64(id->id_aa64mmfr0, ID_AA64MMFR0, TGRAN16) >= 2;
1804
-}
1805
-
1806
-static inline bool isar_feature_aa64_tgran16_2_lpa2(const ARMISARegisters *id)
1807
-{
1808
- unsigned t = FIELD_EX64(id->id_aa64mmfr0, ID_AA64MMFR0, TGRAN16_2);
1809
- return t >= 3 || (t == 0 && isar_feature_aa64_tgran16_lpa2(id));
1810
-}
1811
-
1812
-static inline bool isar_feature_aa64_tgran4(const ARMISARegisters *id)
1813
-{
1814
- return FIELD_SEX64(id->id_aa64mmfr0, ID_AA64MMFR0, TGRAN4) >= 0;
1815
-}
1816
-
1817
-static inline bool isar_feature_aa64_tgran16(const ARMISARegisters *id)
1818
-{
1819
- return FIELD_EX64(id->id_aa64mmfr0, ID_AA64MMFR0, TGRAN16) >= 1;
1820
-}
1821
-
1822
-static inline bool isar_feature_aa64_tgran64(const ARMISARegisters *id)
1823
-{
1824
- return FIELD_SEX64(id->id_aa64mmfr0, ID_AA64MMFR0, TGRAN64) >= 0;
1825
-}
1826
-
1827
-static inline bool isar_feature_aa64_tgran4_2(const ARMISARegisters *id)
1828
-{
1829
- unsigned t = FIELD_EX64(id->id_aa64mmfr0, ID_AA64MMFR0, TGRAN4_2);
1830
- return t >= 2 || (t == 0 && isar_feature_aa64_tgran4(id));
1831
-}
1832
-
1833
-static inline bool isar_feature_aa64_tgran16_2(const ARMISARegisters *id)
1834
-{
1835
- unsigned t = FIELD_EX64(id->id_aa64mmfr0, ID_AA64MMFR0, TGRAN16_2);
1836
- return t >= 2 || (t == 0 && isar_feature_aa64_tgran16(id));
1837
-}
1838
-
1839
-static inline bool isar_feature_aa64_tgran64_2(const ARMISARegisters *id)
1840
-{
1841
- unsigned t = FIELD_EX64(id->id_aa64mmfr0, ID_AA64MMFR0, TGRAN64_2);
1842
- return t >= 2 || (t == 0 && isar_feature_aa64_tgran64(id));
1843
-}
1844
-
1845
-static inline bool isar_feature_aa64_fgt(const ARMISARegisters *id)
1846
-{
1847
- return FIELD_EX64(id->id_aa64mmfr0, ID_AA64MMFR0, FGT) != 0;
1848
-}
1849
-
1850
-static inline bool isar_feature_aa64_ccidx(const ARMISARegisters *id)
1851
-{
1852
- return FIELD_EX64(id->id_aa64mmfr2, ID_AA64MMFR2, CCIDX) != 0;
1853
-}
1854
-
1855
-static inline bool isar_feature_aa64_lva(const ARMISARegisters *id)
1856
-{
1857
- return FIELD_EX64(id->id_aa64mmfr2, ID_AA64MMFR2, VARANGE) != 0;
1858
-}
1859
-
1860
-static inline bool isar_feature_aa64_e0pd(const ARMISARegisters *id)
1861
-{
1862
- return FIELD_EX64(id->id_aa64mmfr2, ID_AA64MMFR2, E0PD) != 0;
1863
-}
1864
-
1865
-static inline bool isar_feature_aa64_hafs(const ARMISARegisters *id)
1866
-{
1867
- return FIELD_EX64(id->id_aa64mmfr1, ID_AA64MMFR1, HAFDBS) != 0;
1868
-}
1869
-
1870
-static inline bool isar_feature_aa64_hdbs(const ARMISARegisters *id)
1871
-{
1872
- return FIELD_EX64(id->id_aa64mmfr1, ID_AA64MMFR1, HAFDBS) >= 2;
1873
-}
1874
-
1875
-static inline bool isar_feature_aa64_tts2uxn(const ARMISARegisters *id)
1876
-{
1877
- return FIELD_EX64(id->id_aa64mmfr1, ID_AA64MMFR1, XNX) != 0;
1878
-}
1879
-
1880
-static inline bool isar_feature_aa64_dit(const ARMISARegisters *id)
1881
-{
1882
- return FIELD_EX64(id->id_aa64pfr0, ID_AA64PFR0, DIT) != 0;
1883
-}
1884
-
1885
-static inline bool isar_feature_aa64_scxtnum(const ARMISARegisters *id)
1886
-{
1887
- int key = FIELD_EX64(id->id_aa64pfr0, ID_AA64PFR0, CSV2);
1888
- if (key >= 2) {
1889
- return true; /* FEAT_CSV2_2 */
1890
- }
1891
- if (key == 1) {
1892
- key = FIELD_EX64(id->id_aa64pfr1, ID_AA64PFR1, CSV2_FRAC);
1893
- return key >= 2; /* FEAT_CSV2_1p2 */
1894
- }
1895
- return false;
1896
-}
1897
-
1898
-static inline bool isar_feature_aa64_ssbs(const ARMISARegisters *id)
1899
-{
1900
- return FIELD_EX64(id->id_aa64pfr1, ID_AA64PFR1, SSBS) != 0;
1901
-}
1902
-
1903
-static inline bool isar_feature_aa64_debugv8p2(const ARMISARegisters *id)
1904
-{
1905
- return FIELD_EX64(id->id_aa64dfr0, ID_AA64DFR0, DEBUGVER) >= 8;
1906
-}
1907
-
1908
-static inline bool isar_feature_aa64_sve2(const ARMISARegisters *id)
1909
-{
1910
- return FIELD_EX64(id->id_aa64zfr0, ID_AA64ZFR0, SVEVER) != 0;
1911
-}
1912
-
1913
-static inline bool isar_feature_aa64_sve2_aes(const ARMISARegisters *id)
1914
-{
1915
- return FIELD_EX64(id->id_aa64zfr0, ID_AA64ZFR0, AES) != 0;
1916
-}
1917
-
1918
-static inline bool isar_feature_aa64_sve2_pmull128(const ARMISARegisters *id)
1919
-{
1920
- return FIELD_EX64(id->id_aa64zfr0, ID_AA64ZFR0, AES) >= 2;
1921
-}
1922
-
1923
-static inline bool isar_feature_aa64_sve2_bitperm(const ARMISARegisters *id)
1924
-{
1925
- return FIELD_EX64(id->id_aa64zfr0, ID_AA64ZFR0, BITPERM) != 0;
1926
-}
1927
-
1928
-static inline bool isar_feature_aa64_sve_bf16(const ARMISARegisters *id)
1929
-{
1930
- return FIELD_EX64(id->id_aa64zfr0, ID_AA64ZFR0, BFLOAT16) != 0;
1931
-}
1932
-
1933
-static inline bool isar_feature_aa64_sve2_sha3(const ARMISARegisters *id)
1934
-{
1935
- return FIELD_EX64(id->id_aa64zfr0, ID_AA64ZFR0, SHA3) != 0;
1936
-}
1937
-
1938
-static inline bool isar_feature_aa64_sve2_sm4(const ARMISARegisters *id)
1939
-{
1940
- return FIELD_EX64(id->id_aa64zfr0, ID_AA64ZFR0, SM4) != 0;
1941
-}
1942
-
1943
-static inline bool isar_feature_aa64_sve_i8mm(const ARMISARegisters *id)
1944
-{
1945
- return FIELD_EX64(id->id_aa64zfr0, ID_AA64ZFR0, I8MM) != 0;
1946
-}
1947
-
1948
-static inline bool isar_feature_aa64_sve_f32mm(const ARMISARegisters *id)
1949
-{
1950
- return FIELD_EX64(id->id_aa64zfr0, ID_AA64ZFR0, F32MM) != 0;
1951
-}
1952
-
1953
-static inline bool isar_feature_aa64_sve_f64mm(const ARMISARegisters *id)
1954
-{
1955
- return FIELD_EX64(id->id_aa64zfr0, ID_AA64ZFR0, F64MM) != 0;
1956
-}
1957
-
1958
-static inline bool isar_feature_aa64_sme_f64f64(const ARMISARegisters *id)
1959
-{
1960
- return FIELD_EX64(id->id_aa64smfr0, ID_AA64SMFR0, F64F64);
1961
-}
1962
-
1963
-static inline bool isar_feature_aa64_sme_i16i64(const ARMISARegisters *id)
1964
-{
1965
- return FIELD_EX64(id->id_aa64smfr0, ID_AA64SMFR0, I16I64) == 0xf;
1966
-}
1967
-
1968
-static inline bool isar_feature_aa64_sme_fa64(const ARMISARegisters *id)
1969
-{
1970
- return FIELD_EX64(id->id_aa64smfr0, ID_AA64SMFR0, FA64);
1971
-}
1972
-
1973
-static inline bool isar_feature_aa64_doublelock(const ARMISARegisters *id)
1974
-{
1975
- return FIELD_SEX64(id->id_aa64dfr0, ID_AA64DFR0, DOUBLELOCK) >= 0;
1976
-}
1977
-
1978
-static inline bool isar_feature_aa64_mops(const ARMISARegisters *id)
1979
-{
1980
- return FIELD_EX64(id->id_aa64isar2, ID_AA64ISAR2, MOPS);
1981
-}
1982
-
1983
-/*
1984
- * Feature tests for "does this exist in either 32-bit or 64-bit?"
1985
- */
1986
-static inline bool isar_feature_any_fp16(const ARMISARegisters *id)
1987
-{
1988
- return isar_feature_aa64_fp16(id) || isar_feature_aa32_fp16_arith(id);
1989
-}
1990
-
1991
-static inline bool isar_feature_any_predinv(const ARMISARegisters *id)
1992
-{
1993
- return isar_feature_aa64_predinv(id) || isar_feature_aa32_predinv(id);
1994
-}
1995
-
1996
-static inline bool isar_feature_any_pmuv3p1(const ARMISARegisters *id)
1997
-{
1998
- return isar_feature_aa64_pmuv3p1(id) || isar_feature_aa32_pmuv3p1(id);
1999
-}
2000
-
2001
-static inline bool isar_feature_any_pmuv3p4(const ARMISARegisters *id)
2002
-{
2003
- return isar_feature_aa64_pmuv3p4(id) || isar_feature_aa32_pmuv3p4(id);
2004
-}
2005
-
2006
-static inline bool isar_feature_any_pmuv3p5(const ARMISARegisters *id)
2007
-{
2008
- return isar_feature_aa64_pmuv3p5(id) || isar_feature_aa32_pmuv3p5(id);
2009
-}
2010
-
2011
-static inline bool isar_feature_any_ccidx(const ARMISARegisters *id)
2012
-{
2013
- return isar_feature_aa64_ccidx(id) || isar_feature_aa32_ccidx(id);
2014
-}
2015
-
2016
-static inline bool isar_feature_any_tts2uxn(const ARMISARegisters *id)
2017
-{
2018
- return isar_feature_aa64_tts2uxn(id) || isar_feature_aa32_tts2uxn(id);
2019
-}
2020
-
2021
-static inline bool isar_feature_any_debugv8p2(const ARMISARegisters *id)
2022
-{
2023
- return isar_feature_aa64_debugv8p2(id) || isar_feature_aa32_debugv8p2(id);
2024
-}
2025
-
2026
-static inline bool isar_feature_any_ras(const ARMISARegisters *id)
2027
-{
2028
- return isar_feature_aa64_ras(id) || isar_feature_aa32_ras(id);
2029
-}
2030
-
2031
-static inline bool isar_feature_any_half_evt(const ARMISARegisters *id)
2032
-{
2033
- return isar_feature_aa64_half_evt(id) || isar_feature_aa32_half_evt(id);
2034
-}
2035
-
2036
-static inline bool isar_feature_any_evt(const ARMISARegisters *id)
2037
-{
2038
- return isar_feature_aa64_evt(id) || isar_feature_aa32_evt(id);
2039
-}
2040
-
2041
-/*
2042
- * Forward to the above feature tests given an ARMCPU pointer.
2043
- */
2044
-#define cpu_isar_feature(name, cpu) \
2045
- ({ ARMCPU *cpu_ = (cpu); isar_feature_##name(&cpu_->isar); })
2046
-
2047
#endif
2048
diff --git a/target/arm/internals.h b/target/arm/internals.h
2049
index XXXXXXX..XXXXXXX 100644
2050
--- a/target/arm/internals.h
2051
+++ b/target/arm/internals.h
2052
@@ -XXX,XX +XXX,XX @@
2053
#include "hw/registerfields.h"
2054
#include "tcg/tcg-gvec-desc.h"
2055
#include "syndrome.h"
2056
+#include "cpu-features.h"
2057
2058
/* register banks for CPU modes */
2059
#define BANK_USRSYS 0
2060
diff --git a/target/arm/tcg/translate.h b/target/arm/tcg/translate.h
2061
index XXXXXXX..XXXXXXX 100644
2062
--- a/target/arm/tcg/translate.h
2063
+++ b/target/arm/tcg/translate.h
2064
@@ -XXX,XX +XXX,XX @@
2065
#include "exec/translator.h"
2066
#include "exec/helper-gen.h"
2067
#include "internals.h"
2068
-
2069
+#include "cpu-features.h"
2070
2071
/* internal defines */
2072
2073
diff --git a/hw/arm/armv7m.c b/hw/arm/armv7m.c
2074
index XXXXXXX..XXXXXXX 100644
2075
--- a/hw/arm/armv7m.c
2076
+++ b/hw/arm/armv7m.c
2077
@@ -XXX,XX +XXX,XX @@
2078
#include "qemu/module.h"
2079
#include "qemu/log.h"
2080
#include "target/arm/idau.h"
2081
+#include "target/arm/cpu-features.h"
2082
#include "migration/vmstate.h"
2083
2084
/* Bitbanded IO. Each word corresponds to a single bit. */
2085
diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c
2086
index XXXXXXX..XXXXXXX 100644
2087
--- a/hw/intc/armv7m_nvic.c
2088
+++ b/hw/intc/armv7m_nvic.c
2089
@@ -XXX,XX +XXX,XX @@
2090
#include "sysemu/tcg.h"
2091
#include "sysemu/runstate.h"
2092
#include "target/arm/cpu.h"
2093
+#include "target/arm/cpu-features.h"
2094
#include "exec/exec-all.h"
2095
#include "exec/memop.h"
2096
#include "qemu/log.h"
2097
diff --git a/linux-user/aarch64/cpu_loop.c b/linux-user/aarch64/cpu_loop.c
2098
index XXXXXXX..XXXXXXX 100644
2099
--- a/linux-user/aarch64/cpu_loop.c
2100
+++ b/linux-user/aarch64/cpu_loop.c
2101
@@ -XXX,XX +XXX,XX @@
2102
#include "qemu/guest-random.h"
2103
#include "semihosting/common-semi.h"
2104
#include "target/arm/syndrome.h"
2105
+#include "target/arm/cpu-features.h"
2106
2107
#define get_user_code_u32(x, gaddr, env) \
2108
({ abi_long __r = get_user_u32((x), (gaddr)); \
2109
diff --git a/linux-user/aarch64/signal.c b/linux-user/aarch64/signal.c
2110
index XXXXXXX..XXXXXXX 100644
2111
--- a/linux-user/aarch64/signal.c
2112
+++ b/linux-user/aarch64/signal.c
2113
@@ -XXX,XX +XXX,XX @@
2114
#include "user-internals.h"
2115
#include "signal-common.h"
2116
#include "linux-user/trace.h"
2117
+#include "target/arm/cpu-features.h"
2118
2119
struct target_sigcontext {
2120
uint64_t fault_address;
2121
diff --git a/linux-user/arm/signal.c b/linux-user/arm/signal.c
2122
index XXXXXXX..XXXXXXX 100644
2123
--- a/linux-user/arm/signal.c
2124
+++ b/linux-user/arm/signal.c
2125
@@ -XXX,XX +XXX,XX @@
2126
#include "user-internals.h"
2127
#include "signal-common.h"
2128
#include "linux-user/trace.h"
2129
+#include "target/arm/cpu-features.h"
2130
2131
struct target_sigcontext {
2132
abi_ulong trap_no;
2133
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
2134
index XXXXXXX..XXXXXXX 100644
2135
--- a/linux-user/elfload.c
2136
+++ b/linux-user/elfload.c
2137
@@ -XXX,XX +XXX,XX @@
2138
#include "target_signal.h"
2139
#include "accel/tcg/debuginfo.h"
2140
2141
+#ifdef TARGET_ARM
2142
+#include "target/arm/cpu-features.h"
2143
+#endif
2144
+
2145
#ifdef _ARCH_PPC64
2146
#undef ARCH_DLINFO
2147
#undef ELF_PLATFORM
62
diff --git a/linux-user/mmap.c b/linux-user/mmap.c
2148
diff --git a/linux-user/mmap.c b/linux-user/mmap.c
63
index XXXXXXX..XXXXXXX 100644
2149
index XXXXXXX..XXXXXXX 100644
64
--- a/linux-user/mmap.c
2150
--- a/linux-user/mmap.c
65
+++ b/linux-user/mmap.c
2151
+++ b/linux-user/mmap.c
66
@@ -XXX,XX +XXX,XX @@ static int validate_prot_to_pageflags(int *host_prot, int prot)
2152
@@ -XXX,XX +XXX,XX @@
67
*host_prot = (prot & (PROT_READ | PROT_WRITE))
2153
#include "target_mman.h"
68
| (prot & PROT_EXEC ? PROT_READ : 0);
2154
#include "qemu/interval-tree.h"
69
2155
70
+#ifdef TARGET_AARCH64
2156
+#ifdef TARGET_ARM
71
+ /*
2157
+#include "target/arm/cpu-features.h"
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
2158
+#endif
85
+
2159
+
86
return prot & ~valid ? 0 : page_flags;
2160
static pthread_mutex_t mmap_mutex = PTHREAD_MUTEX_INITIALIZER;
87
}
2161
static __thread int mmap_lock_count;
88
2162
89
diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c
2163
diff --git a/target/arm/arch_dump.c b/target/arm/arch_dump.c
90
index XXXXXXX..XXXXXXX 100644
2164
index XXXXXXX..XXXXXXX 100644
91
--- a/target/arm/translate-a64.c
2165
--- a/target/arm/arch_dump.c
92
+++ b/target/arm/translate-a64.c
2166
+++ b/target/arm/arch_dump.c
93
@@ -XXX,XX +XXX,XX @@ static void disas_data_proc_simd_fp(DisasContext *s, uint32_t insn)
2167
@@ -XXX,XX +XXX,XX @@
94
*/
2168
#include "cpu.h"
95
static bool is_guarded_page(CPUARMState *env, DisasContext *s)
2169
#include "elf.h"
96
{
2170
#include "sysemu/dump.h"
97
-#ifdef CONFIG_USER_ONLY
2171
+#include "cpu-features.h"
98
- return false; /* FIXME */
2172
99
-#else
2173
/* struct user_pt_regs from arch/arm64/include/uapi/asm/ptrace.h */
100
uint64_t addr = s->base.pc_first;
2174
struct aarch64_user_regs {
101
+#ifdef CONFIG_USER_ONLY
2175
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
102
+ return page_get_flags(addr) & PAGE_BTI;
2176
index XXXXXXX..XXXXXXX 100644
103
+#else
2177
--- a/target/arm/cpu.c
104
int mmu_idx = arm_to_core_mmu_idx(s->mmu_idx);
2178
+++ b/target/arm/cpu.c
105
unsigned int index = tlb_index(env, mmu_idx, addr);
2179
@@ -XXX,XX +XXX,XX @@
106
CPUTLBEntry *entry = tlb_entry(env, mmu_idx, addr);
2180
#include "hw/core/tcg-cpu-ops.h"
2181
#endif /* CONFIG_TCG */
2182
#include "internals.h"
2183
+#include "cpu-features.h"
2184
#include "exec/exec-all.h"
2185
#include "hw/qdev-properties.h"
2186
#if !defined(CONFIG_USER_ONLY)
2187
diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c
2188
index XXXXXXX..XXXXXXX 100644
2189
--- a/target/arm/cpu64.c
2190
+++ b/target/arm/cpu64.c
2191
@@ -XXX,XX +XXX,XX @@
2192
#include "qapi/visitor.h"
2193
#include "hw/qdev-properties.h"
2194
#include "internals.h"
2195
+#include "cpu-features.h"
2196
#include "cpregs.h"
2197
2198
void arm_cpu_sve_finalize(ARMCPU *cpu, Error **errp)
2199
diff --git a/target/arm/debug_helper.c b/target/arm/debug_helper.c
2200
index XXXXXXX..XXXXXXX 100644
2201
--- a/target/arm/debug_helper.c
2202
+++ b/target/arm/debug_helper.c
2203
@@ -XXX,XX +XXX,XX @@
2204
#include "qemu/log.h"
2205
#include "cpu.h"
2206
#include "internals.h"
2207
+#include "cpu-features.h"
2208
#include "cpregs.h"
2209
#include "exec/exec-all.h"
2210
#include "exec/helper-proto.h"
2211
diff --git a/target/arm/gdbstub.c b/target/arm/gdbstub.c
2212
index XXXXXXX..XXXXXXX 100644
2213
--- a/target/arm/gdbstub.c
2214
+++ b/target/arm/gdbstub.c
2215
@@ -XXX,XX +XXX,XX @@
2216
#include "gdbstub/helpers.h"
2217
#include "sysemu/tcg.h"
2218
#include "internals.h"
2219
+#include "cpu-features.h"
2220
#include "cpregs.h"
2221
2222
typedef struct RegisterSysregXmlParam {
2223
diff --git a/target/arm/helper.c b/target/arm/helper.c
2224
index XXXXXXX..XXXXXXX 100644
2225
--- a/target/arm/helper.c
2226
+++ b/target/arm/helper.c
2227
@@ -XXX,XX +XXX,XX @@
2228
#include "trace.h"
2229
#include "cpu.h"
2230
#include "internals.h"
2231
+#include "cpu-features.h"
2232
#include "exec/helper-proto.h"
2233
#include "qemu/main-loop.h"
2234
#include "qemu/timer.h"
2235
diff --git a/target/arm/kvm64.c b/target/arm/kvm64.c
2236
index XXXXXXX..XXXXXXX 100644
2237
--- a/target/arm/kvm64.c
2238
+++ b/target/arm/kvm64.c
2239
@@ -XXX,XX +XXX,XX @@
2240
#include "sysemu/kvm_int.h"
2241
#include "kvm_arm.h"
2242
#include "internals.h"
2243
+#include "cpu-features.h"
2244
#include "hw/acpi/acpi.h"
2245
#include "hw/acpi/ghes.h"
2246
2247
diff --git a/target/arm/machine.c b/target/arm/machine.c
2248
index XXXXXXX..XXXXXXX 100644
2249
--- a/target/arm/machine.c
2250
+++ b/target/arm/machine.c
2251
@@ -XXX,XX +XXX,XX @@
2252
#include "sysemu/tcg.h"
2253
#include "kvm_arm.h"
2254
#include "internals.h"
2255
+#include "cpu-features.h"
2256
#include "migration/cpu.h"
2257
2258
static bool vfp_needed(void *opaque)
2259
diff --git a/target/arm/ptw.c b/target/arm/ptw.c
2260
index XXXXXXX..XXXXXXX 100644
2261
--- a/target/arm/ptw.c
2262
+++ b/target/arm/ptw.c
2263
@@ -XXX,XX +XXX,XX @@
2264
#include "exec/exec-all.h"
2265
#include "cpu.h"
2266
#include "internals.h"
2267
+#include "cpu-features.h"
2268
#include "idau.h"
2269
#ifdef CONFIG_TCG
2270
# include "tcg/oversized-guest.h"
2271
diff --git a/target/arm/tcg/cpu64.c b/target/arm/tcg/cpu64.c
2272
index XXXXXXX..XXXXXXX 100644
2273
--- a/target/arm/tcg/cpu64.c
2274
+++ b/target/arm/tcg/cpu64.c
2275
@@ -XXX,XX +XXX,XX @@
2276
#include "hw/qdev-properties.h"
2277
#include "qemu/units.h"
2278
#include "internals.h"
2279
+#include "cpu-features.h"
2280
#include "cpregs.h"
2281
2282
static uint64_t make_ccsidr64(unsigned assoc, unsigned linesize,
2283
diff --git a/target/arm/tcg/hflags.c b/target/arm/tcg/hflags.c
2284
index XXXXXXX..XXXXXXX 100644
2285
--- a/target/arm/tcg/hflags.c
2286
+++ b/target/arm/tcg/hflags.c
2287
@@ -XXX,XX +XXX,XX @@
2288
#include "qemu/osdep.h"
2289
#include "cpu.h"
2290
#include "internals.h"
2291
+#include "cpu-features.h"
2292
#include "exec/helper-proto.h"
2293
#include "cpregs.h"
2294
2295
diff --git a/target/arm/tcg/m_helper.c b/target/arm/tcg/m_helper.c
2296
index XXXXXXX..XXXXXXX 100644
2297
--- a/target/arm/tcg/m_helper.c
2298
+++ b/target/arm/tcg/m_helper.c
2299
@@ -XXX,XX +XXX,XX @@
2300
#include "qemu/osdep.h"
2301
#include "cpu.h"
2302
#include "internals.h"
2303
+#include "cpu-features.h"
2304
#include "gdbstub/helpers.h"
2305
#include "exec/helper-proto.h"
2306
#include "qemu/main-loop.h"
2307
diff --git a/target/arm/tcg/op_helper.c b/target/arm/tcg/op_helper.c
2308
index XXXXXXX..XXXXXXX 100644
2309
--- a/target/arm/tcg/op_helper.c
2310
+++ b/target/arm/tcg/op_helper.c
2311
@@ -XXX,XX +XXX,XX @@
2312
#include "cpu.h"
2313
#include "exec/helper-proto.h"
2314
#include "internals.h"
2315
+#include "cpu-features.h"
2316
#include "exec/exec-all.h"
2317
#include "exec/cpu_ldst.h"
2318
#include "cpregs.h"
2319
diff --git a/target/arm/tcg/pauth_helper.c b/target/arm/tcg/pauth_helper.c
2320
index XXXXXXX..XXXXXXX 100644
2321
--- a/target/arm/tcg/pauth_helper.c
2322
+++ b/target/arm/tcg/pauth_helper.c
2323
@@ -XXX,XX +XXX,XX @@
2324
#include "qemu/osdep.h"
2325
#include "cpu.h"
2326
#include "internals.h"
2327
+#include "cpu-features.h"
2328
#include "exec/exec-all.h"
2329
#include "exec/cpu_ldst.h"
2330
#include "exec/helper-proto.h"
2331
diff --git a/target/arm/tcg/tlb_helper.c b/target/arm/tcg/tlb_helper.c
2332
index XXXXXXX..XXXXXXX 100644
2333
--- a/target/arm/tcg/tlb_helper.c
2334
+++ b/target/arm/tcg/tlb_helper.c
2335
@@ -XXX,XX +XXX,XX @@
2336
#include "qemu/osdep.h"
2337
#include "cpu.h"
2338
#include "internals.h"
2339
+#include "cpu-features.h"
2340
#include "exec/exec-all.h"
2341
#include "exec/helper-proto.h"
2342
2343
diff --git a/target/arm/vfp_helper.c b/target/arm/vfp_helper.c
2344
index XXXXXXX..XXXXXXX 100644
2345
--- a/target/arm/vfp_helper.c
2346
+++ b/target/arm/vfp_helper.c
2347
@@ -XXX,XX +XXX,XX @@
2348
#include "cpu.h"
2349
#include "exec/helper-proto.h"
2350
#include "internals.h"
2351
+#include "cpu-features.h"
2352
#ifdef CONFIG_TCG
2353
#include "qemu/log.h"
2354
#include "fpu/softfloat.h"
107
--
2355
--
108
2.20.1
2356
2.34.1
109
2357
110
2358
diff view generated by jsdifflib
Deleted patch
1
From: Richard Henderson <richard.henderson@linaro.org>
2
1
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
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
---
13
include/elf.h | 22 ++++++++++++++++++++++
14
1 file changed, 22 insertions(+)
15
16
diff --git a/include/elf.h b/include/elf.h
17
index XXXXXXX..XXXXXXX 100644
18
--- a/include/elf.h
19
+++ b/include/elf.h
20
@@ -XXX,XX +XXX,XX @@ typedef int64_t Elf64_Sxword;
21
#define PT_NOTE 4
22
#define PT_SHLIB 5
23
#define PT_PHDR 6
24
+#define PT_LOOS 0x60000000
25
+#define PT_HIOS 0x6fffffff
26
#define PT_LOPROC 0x70000000
27
#define PT_HIPROC 0x7fffffff
28
29
+#define PT_GNU_PROPERTY (PT_LOOS + 0x474e553)
30
+
31
#define PT_MIPS_REGINFO 0x70000000
32
#define PT_MIPS_RTPROC 0x70000001
33
#define PT_MIPS_OPTIONS 0x70000002
34
@@ -XXX,XX +XXX,XX @@ typedef struct elf64_shdr {
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)
55
+
56
/*
57
* Physical entry point into the kernel.
58
*
59
--
60
2.20.1
61
62
diff view generated by jsdifflib
Deleted patch
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
2
1
3
Fix an unlikely memory leak in load_elf_image().
4
5
Fixes: bf858897b7 ("linux-user: Re-use load_elf_image for the main binary.")
6
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
7
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
8
Message-id: 20201021173749.111103-5-richard.henderson@linaro.org
9
Message-Id: <20201003174944.1972444-1-f4bug@amsat.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>
13
---
14
linux-user/elfload.c | 8 ++++----
15
1 file changed, 4 insertions(+), 4 deletions(-)
16
17
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
18
index XXXXXXX..XXXXXXX 100644
19
--- a/linux-user/elfload.c
20
+++ b/linux-user/elfload.c
21
@@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd,
22
info->brk = vaddr_em;
23
}
24
} else if (eppnt->p_type == PT_INTERP && pinterp_name) {
25
- char *interp_name;
26
+ g_autofree char *interp_name = NULL;
27
28
if (*pinterp_name) {
29
errmsg = "Multiple PT_INTERP entries";
30
goto exit_errmsg;
31
}
32
- interp_name = malloc(eppnt->p_filesz);
33
+ interp_name = g_malloc(eppnt->p_filesz);
34
if (!interp_name) {
35
goto exit_perror;
36
}
37
@@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd,
38
errmsg = "Invalid PT_INTERP entry";
39
goto exit_errmsg;
40
}
41
- *pinterp_name = interp_name;
42
+ *pinterp_name = g_steal_pointer(&interp_name);
43
#ifdef TARGET_MIPS
44
} else if (eppnt->p_type == PT_MIPS_ABIFLAGS) {
45
Mips_elf_abiflags_v0 abiflags;
46
@@ -XXX,XX +XXX,XX @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info)
47
if (elf_interpreter) {
48
info->load_bias = interp_info.load_bias;
49
info->entry = interp_info.entry;
50
- free(elf_interpreter);
51
+ g_free(elf_interpreter);
52
}
53
54
#ifdef USE_ELF_CORE_DUMP
55
--
56
2.20.1
57
58
diff view generated by jsdifflib
Deleted patch
1
From: Richard Henderson <richard.henderson@linaro.org>
2
1
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>
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
---
10
linux-user/elfload.c | 12 +++++++++---
11
1 file changed, 9 insertions(+), 3 deletions(-)
12
13
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
14
index XXXXXXX..XXXXXXX 100644
15
--- a/linux-user/elfload.c
16
+++ b/linux-user/elfload.c
17
@@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd,
18
abi_ulong vaddr, vaddr_po, vaddr_ps, vaddr_ef, vaddr_em, vaddr_len;
19
int elf_prot = 0;
20
21
- if (eppnt->p_flags & PF_R) elf_prot = PROT_READ;
22
- if (eppnt->p_flags & PF_W) elf_prot |= PROT_WRITE;
23
- if (eppnt->p_flags & PF_X) elf_prot |= PROT_EXEC;
24
+ if (eppnt->p_flags & PF_R) {
25
+ elf_prot |= PROT_READ;
26
+ }
27
+ if (eppnt->p_flags & PF_W) {
28
+ elf_prot |= PROT_WRITE;
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);
36
--
37
2.20.1
38
39
diff view generated by jsdifflib
1
From: Shashi Mallela <shashi.mallela@linaro.org>
1
Our list of isar_feature functions is not in any particular order,
2
but tests on fields of the same ID register tend to be grouped
3
together. A few functions that are tests of fields in ID_AA64MMFR1
4
and ID_AA64MMFR2 are not in the same place as the rest; move them
5
into their groups.
2
6
3
Generic watchdog device model implementation as per ARM SBSA v6.0
7
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
9
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
10
Message-id: 20231024163510.2972081-3-peter.maydell@linaro.org
11
---
12
target/arm/cpu-features.h | 60 +++++++++++++++++++--------------------
13
1 file changed, 30 insertions(+), 30 deletions(-)
4
14
5
Signed-off-by: Shashi Mallela <shashi.mallela@linaro.org>
15
diff --git a/target/arm/cpu-features.h b/target/arm/cpu-features.h
6
Message-id: 20201027015927.29495-2-shashi.mallela@linaro.org
16
index XXXXXXX..XXXXXXX 100644
7
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
17
--- a/target/arm/cpu-features.h
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
18
+++ b/target/arm/cpu-features.h
9
---
19
@@ -XXX,XX +XXX,XX @@ static inline bool isar_feature_aa64_tidcp1(const ARMISARegisters *id)
10
include/hw/watchdog/sbsa_gwdt.h | 79 +++++++++
20
return FIELD_EX64(id->id_aa64mmfr2, ID_AA64MMFR1, TIDCP1) != 0;
11
hw/watchdog/sbsa_gwdt.c | 293 ++++++++++++++++++++++++++++++++
21
}
12
hw/arm/Kconfig | 1 +
22
13
hw/watchdog/Kconfig | 3 +
23
+static inline bool isar_feature_aa64_hafs(const ARMISARegisters *id)
14
hw/watchdog/meson.build | 1 +
15
5 files changed, 377 insertions(+)
16
create mode 100644 include/hw/watchdog/sbsa_gwdt.h
17
create mode 100644 hw/watchdog/sbsa_gwdt.c
18
19
diff --git a/include/hw/watchdog/sbsa_gwdt.h b/include/hw/watchdog/sbsa_gwdt.h
20
new file mode 100644
21
index XXXXXXX..XXXXXXX
22
--- /dev/null
23
+++ b/include/hw/watchdog/sbsa_gwdt.h
24
@@ -XXX,XX +XXX,XX @@
25
+/*
26
+ * Copyright (c) 2020 Linaro Limited
27
+ *
28
+ * Authors:
29
+ * Shashi Mallela <shashi.mallela@linaro.org>
30
+ *
31
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at your
32
+ * option) any later version. See the COPYING file in the top-level directory.
33
+ *
34
+ */
35
+
36
+#ifndef WDT_SBSA_GWDT_H
37
+#define WDT_SBSA_GWDT_H
38
+
39
+#include "qemu/bitops.h"
40
+#include "hw/sysbus.h"
41
+#include "hw/irq.h"
42
+
43
+#define TYPE_WDT_SBSA "sbsa_gwdt"
44
+#define SBSA_GWDT(obj) \
45
+ OBJECT_CHECK(SBSA_GWDTState, (obj), TYPE_WDT_SBSA)
46
+#define SBSA_GWDT_CLASS(klass) \
47
+ OBJECT_CLASS_CHECK(SBSA_GWDTClass, (klass), TYPE_WDT_SBSA)
48
+#define SBSA_GWDT_GET_CLASS(obj) \
49
+ OBJECT_GET_CLASS(SBSA_GWDTClass, (obj), TYPE_WDT_SBSA)
50
+
51
+/* SBSA Generic Watchdog register definitions */
52
+/* refresh frame */
53
+#define SBSA_GWDT_WRR 0x000
54
+
55
+/* control frame */
56
+#define SBSA_GWDT_WCS 0x000
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
105
new file mode 100644
106
index XXXXXXX..XXXXXXX
107
--- /dev/null
108
+++ b/hw/watchdog/sbsa_gwdt.c
109
@@ -XXX,XX +XXX,XX @@
110
+/*
111
+ * Generic watchdog device model for SBSA
112
+ *
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
+ *
125
+ */
126
+
127
+#include "qemu/osdep.h"
128
+#include "sysemu/reset.h"
129
+#include "sysemu/watchdog.h"
130
+#include "hw/watchdog/sbsa_gwdt.h"
131
+#include "qemu/timer.h"
132
+#include "migration/vmstate.h"
133
+#include "qemu/log.h"
134
+#include "qemu/module.h"
135
+
136
+static WatchdogTimerModel model = {
137
+ .wdt_name = TYPE_WDT_SBSA,
138
+ .wdt_description = "SBSA-compliant generic watchdog device",
139
+};
140
+
141
+static const VMStateDescription vmstate_sbsa_gwdt = {
142
+ .name = "sbsa-gwdt",
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
+ }
154
+};
155
+
156
+typedef enum WdtRefreshType {
157
+ EXPLICIT_REFRESH = 0,
158
+ TIMEOUT_REFRESH = 1,
159
+} WdtRefreshType;
160
+
161
+static uint64_t sbsa_gwdt_rread(void *opaque, hwaddr addr, unsigned int size)
162
+{
24
+{
163
+ SBSA_GWDTState *s = SBSA_GWDT(opaque);
25
+ return FIELD_EX64(id->id_aa64mmfr1, ID_AA64MMFR1, HAFDBS) != 0;
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
+}
26
+}
180
+
27
+
181
+static uint64_t sbsa_gwdt_read(void *opaque, hwaddr addr, unsigned int size)
28
+static inline bool isar_feature_aa64_hdbs(const ARMISARegisters *id)
182
+{
29
+{
183
+ SBSA_GWDTState *s = SBSA_GWDT(opaque);
30
+ return FIELD_EX64(id->id_aa64mmfr1, ID_AA64MMFR1, HAFDBS) >= 2;
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
+}
31
+}
211
+
32
+
212
+static void sbsa_gwdt_update_timer(SBSA_GWDTState *s, WdtRefreshType rtype)
33
+static inline bool isar_feature_aa64_tts2uxn(const ARMISARegisters *id)
213
+{
34
+{
214
+ uint64_t timeout = 0;
35
+ return FIELD_EX64(id->id_aa64mmfr1, ID_AA64MMFR1, XNX) != 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
+}
36
+}
238
+
37
+
239
+static void sbsa_gwdt_rwrite(void *opaque, hwaddr offset, uint64_t data,
38
static inline bool isar_feature_aa64_uao(const ARMISARegisters *id)
240
+ unsigned size) {
39
{
241
+ SBSA_GWDTState *s = SBSA_GWDT(opaque);
40
return FIELD_EX64(id->id_aa64mmfr2, ID_AA64MMFR2, UAO) != 0;
242
+
41
@@ -XXX,XX +XXX,XX @@ static inline bool isar_feature_aa64_evt(const ARMISARegisters *id)
243
+ if (offset == SBSA_GWDT_WRR) {
42
return FIELD_EX64(id->id_aa64mmfr2, ID_AA64MMFR2, EVT) >= 2;
244
+ s->wcs &= ~(SBSA_GWDT_WCS_WS0 | SBSA_GWDT_WCS_WS1);
43
}
245
+
44
246
+ sbsa_gwdt_update_timer(s, EXPLICIT_REFRESH);
45
+static inline bool isar_feature_aa64_ccidx(const ARMISARegisters *id)
247
+ } else {
46
+{
248
+ qemu_log_mask(LOG_GUEST_ERROR, "bad address in refresh frame write :"
47
+ return FIELD_EX64(id->id_aa64mmfr2, ID_AA64MMFR2, CCIDX) != 0;
249
+ " 0x%x\n", (int)offset);
250
+ }
251
+}
48
+}
252
+
49
+
253
+static void sbsa_gwdt_write(void *opaque, hwaddr offset, uint64_t data,
50
+static inline bool isar_feature_aa64_lva(const ARMISARegisters *id)
254
+ unsigned size) {
51
+{
255
+ SBSA_GWDTState *s = SBSA_GWDT(opaque);
52
+ return FIELD_EX64(id->id_aa64mmfr2, ID_AA64MMFR2, VARANGE) != 0;
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
+}
53
+}
292
+
54
+
293
+static void wdt_sbsa_gwdt_reset(DeviceState *dev)
55
+static inline bool isar_feature_aa64_e0pd(const ARMISARegisters *id)
294
+{
56
+{
295
+ SBSA_GWDTState *s = SBSA_GWDT(dev);
57
+ return FIELD_EX64(id->id_aa64mmfr2, ID_AA64MMFR2, E0PD) != 0;
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
+}
58
+}
306
+
59
+
307
+static void sbsa_gwdt_timer_sysinterrupt(void *opaque)
60
static inline bool isar_feature_aa64_bti(const ARMISARegisters *id)
308
+{
61
{
309
+ SBSA_GWDTState *s = SBSA_GWDT(opaque);
62
return FIELD_EX64(id->id_aa64pfr1, ID_AA64PFR1, BT) != 0;
310
+
63
@@ -XXX,XX +XXX,XX @@ static inline bool isar_feature_aa64_fgt(const ARMISARegisters *id)
311
+ if (!(s->wcs & SBSA_GWDT_WCS_WS0)) {
64
return FIELD_EX64(id->id_aa64mmfr0, ID_AA64MMFR0, FGT) != 0;
312
+ s->wcs |= SBSA_GWDT_WCS_WS0;
65
}
313
+ sbsa_gwdt_update_timer(s, TIMEOUT_REFRESH);
66
314
+ qemu_set_irq(s->irq, 1);
67
-static inline bool isar_feature_aa64_ccidx(const ARMISARegisters *id)
315
+ } else {
68
-{
316
+ s->wcs |= SBSA_GWDT_WCS_WS1;
69
- return FIELD_EX64(id->id_aa64mmfr2, ID_AA64MMFR2, CCIDX) != 0;
317
+ qemu_log_mask(CPU_LOG_RESET, "Watchdog timer expired.\n");
70
-}
318
+ /*
71
-
319
+ * Reset the watchdog only if the guest gets notified about
72
-static inline bool isar_feature_aa64_lva(const ARMISARegisters *id)
320
+ * expiry. watchdog_perform_action() may temporarily relinquish
73
-{
321
+ * the BQL; reset before triggering the action to avoid races with
74
- return FIELD_EX64(id->id_aa64mmfr2, ID_AA64MMFR2, VARANGE) != 0;
322
+ * sbsa_gwdt instructions.
75
-}
323
+ */
76
-
324
+ switch (get_watchdog_action()) {
77
-static inline bool isar_feature_aa64_e0pd(const ARMISARegisters *id)
325
+ case WATCHDOG_ACTION_DEBUG:
78
-{
326
+ case WATCHDOG_ACTION_NONE:
79
- return FIELD_EX64(id->id_aa64mmfr2, ID_AA64MMFR2, E0PD) != 0;
327
+ case WATCHDOG_ACTION_PAUSE:
80
-}
328
+ break;
81
-
329
+ default:
82
-static inline bool isar_feature_aa64_hafs(const ARMISARegisters *id)
330
+ wdt_sbsa_gwdt_reset(DEVICE(s));
83
-{
331
+ }
84
- return FIELD_EX64(id->id_aa64mmfr1, ID_AA64MMFR1, HAFDBS) != 0;
332
+ watchdog_perform_action();
85
-}
333
+ }
86
-
334
+}
87
-static inline bool isar_feature_aa64_hdbs(const ARMISARegisters *id)
335
+
88
-{
336
+static const MemoryRegionOps sbsa_gwdt_rops = {
89
- return FIELD_EX64(id->id_aa64mmfr1, ID_AA64MMFR1, HAFDBS) >= 2;
337
+ .read = sbsa_gwdt_rread,
90
-}
338
+ .write = sbsa_gwdt_rwrite,
91
-
339
+ .endianness = DEVICE_LITTLE_ENDIAN,
92
-static inline bool isar_feature_aa64_tts2uxn(const ARMISARegisters *id)
340
+ .valid.min_access_size = 4,
93
-{
341
+ .valid.max_access_size = 4,
94
- return FIELD_EX64(id->id_aa64mmfr1, ID_AA64MMFR1, XNX) != 0;
342
+ .valid.unaligned = false,
95
-}
343
+};
96
-
344
+
97
static inline bool isar_feature_aa64_dit(const ARMISARegisters *id)
345
+static const MemoryRegionOps sbsa_gwdt_ops = {
98
{
346
+ .read = sbsa_gwdt_read,
99
return FIELD_EX64(id->id_aa64pfr0, ID_AA64PFR0, DIT) != 0;
347
+ .write = sbsa_gwdt_write,
348
+ .endianness = DEVICE_LITTLE_ENDIAN,
349
+ .valid.min_access_size = 4,
350
+ .valid.max_access_size = 4,
351
+ .valid.unaligned = false,
352
+};
353
+
354
+static void wdt_sbsa_gwdt_realize(DeviceState *dev, Error **errp)
355
+{
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),
394
+};
395
+
396
+static void wdt_sbsa_gwdt_register_types(void)
397
+{
398
+ watchdog_add_model(&model);
399
+ type_register_static(&wdt_sbsa_gwdt_info);
400
+}
401
+
402
+type_init(wdt_sbsa_gwdt_register_types)
403
diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
404
index XXXXXXX..XXXXXXX 100644
405
--- a/hw/arm/Kconfig
406
+++ b/hw/arm/Kconfig
407
@@ -XXX,XX +XXX,XX @@ config SBSA_REF
408
select PL031 # RTC
409
select PL061 # GPIO
410
select USB_EHCI_SYSBUS
411
+ select WDT_SBSA
412
413
config SABRELITE
414
bool
415
diff --git a/hw/watchdog/Kconfig b/hw/watchdog/Kconfig
416
index XXXXXXX..XXXXXXX 100644
417
--- a/hw/watchdog/Kconfig
418
+++ b/hw/watchdog/Kconfig
419
@@ -XXX,XX +XXX,XX @@ config WDT_DIAG288
420
421
config WDT_IMX2
422
bool
423
+
424
+config WDT_SBSA
425
+ bool
426
diff --git a/hw/watchdog/meson.build b/hw/watchdog/meson.build
427
index XXXXXXX..XXXXXXX 100644
428
--- a/hw/watchdog/meson.build
429
+++ b/hw/watchdog/meson.build
430
@@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_WDT_IB700', if_true: files('wdt_ib700.c'))
431
softmmu_ss.add(when: 'CONFIG_WDT_DIAG288', if_true: files('wdt_diag288.c'))
432
softmmu_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('wdt_aspeed.c'))
433
softmmu_ss.add(when: 'CONFIG_WDT_IMX2', if_true: files('wdt_imx2.c'))
434
+softmmu_ss.add(when: 'CONFIG_WDT_SBSA', if_true: files('sbsa_gwdt.c'))
435
--
100
--
436
2.20.1
101
2.34.1
437
102
438
103
diff view generated by jsdifflib
1
From: Havard Skinnemoen <hskinnemoen@google.com>
1
Move the ID_AA64MMFR0 feature test functions up so they are
2
before the ones for ID_AA64MMFR1 and ID_AA64MMFR2.
2
3
3
The RNG module returns a byte of randomness when the Data Valid bit is
4
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
4
set.
5
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Message-id: 20231024163510.2972081-4-peter.maydell@linaro.org
8
---
9
target/arm/cpu-features.h | 120 +++++++++++++++++++-------------------
10
1 file changed, 60 insertions(+), 60 deletions(-)
5
11
6
This implementation ignores the prescaler setting, and loads a new value
12
diff --git a/target/arm/cpu-features.h b/target/arm/cpu-features.h
7
into RNGD every time RNGCS is read while the RNG is enabled and random
8
data is available.
9
10
A qtest featuring some simple randomness tests is included.
11
12
Reviewed-by: Tyrone Ting <kfting@nuvoton.com>
13
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
14
Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
15
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
16
---
17
docs/system/arm/nuvoton.rst | 2 +-
18
include/hw/arm/npcm7xx.h | 2 +
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
30
31
diff --git a/docs/system/arm/nuvoton.rst b/docs/system/arm/nuvoton.rst
32
index XXXXXXX..XXXXXXX 100644
13
index XXXXXXX..XXXXXXX 100644
33
--- a/docs/system/arm/nuvoton.rst
14
--- a/target/arm/cpu-features.h
34
+++ b/docs/system/arm/nuvoton.rst
15
+++ b/target/arm/cpu-features.h
35
@@ -XXX,XX +XXX,XX @@ Supported devices
16
@@ -XXX,XX +XXX,XX @@ static inline bool isar_feature_aa64_rme(const ARMISARegisters *id)
36
* DDR4 memory controller (dummy interface indicating memory training is done)
17
return FIELD_EX64(id->id_aa64pfr0, ID_AA64PFR0, RME) != 0;
37
* OTP controllers (no protection features)
18
}
38
* Flash Interface Unit (FIU; no protection features)
19
39
+ * Random Number Generator (RNG)
20
+static inline bool isar_feature_aa64_tgran4_lpa2(const ARMISARegisters *id)
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
55
@@ -XXX,XX +XXX,XX @@
56
#include "hw/mem/npcm7xx_mc.h"
57
#include "hw/misc/npcm7xx_clk.h"
58
#include "hw/misc/npcm7xx_gcr.h"
59
+#include "hw/misc/npcm7xx_rng.h"
60
#include "hw/nvram/npcm7xx_otp.h"
61
#include "hw/timer/npcm7xx_timer.h"
62
#include "hw/ssi/npcm7xx_fiu.h"
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
112
index XXXXXXX..XXXXXXX 100644
113
--- a/hw/arm/npcm7xx.c
114
+++ b/hw/arm/npcm7xx.c
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);
133
}
134
135
+ /* Random Number Generator. Cannot fail. */
136
+ sysbus_realize(SYS_BUS_DEVICE(&s->rng), &error_abort);
137
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->rng), 0, NPCM7XX_RNG_BA);
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
+{
21
+{
197
+ return (s->rngcs & NPCM7XX_RNGCS_RNGE) &&
22
+ return FIELD_SEX64(id->id_aa64mmfr0, ID_AA64MMFR0, TGRAN4) >= 1;
198
+ (s->rngmode == NPCM7XX_RNGMODE_NORMAL);
199
+}
23
+}
200
+
24
+
201
+static uint64_t npcm7xx_rng_read(void *opaque, hwaddr offset, unsigned size)
25
+static inline bool isar_feature_aa64_tgran4_2_lpa2(const ARMISARegisters *id)
202
+{
26
+{
203
+ NPCM7xxRNGState *s = opaque;
27
+ unsigned t = FIELD_EX64(id->id_aa64mmfr0, ID_AA64MMFR0, TGRAN4_2);
204
+ uint64_t value = 0;
28
+ return t >= 3 || (t == 0 && isar_feature_aa64_tgran4_lpa2(id));
205
+
206
+ switch (offset) {
207
+ case NPCM7XX_RNGCS:
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
+
235
+ default:
236
+ qemu_log_mask(LOG_GUEST_ERROR,
237
+ "%s: read from invalid offset 0x%" HWADDR_PRIx "\n",
238
+ DEVICE(s)->canonical_path, offset);
239
+ break;
240
+ }
241
+
242
+ trace_npcm7xx_rng_read(offset, value, size);
243
+
244
+ return value;
245
+}
29
+}
246
+
30
+
247
+static void npcm7xx_rng_write(void *opaque, hwaddr offset, uint64_t value,
31
+static inline bool isar_feature_aa64_tgran16_lpa2(const ARMISARegisters *id)
248
+ unsigned size)
249
+{
32
+{
250
+ NPCM7xxRNGState *s = opaque;
33
+ return FIELD_EX64(id->id_aa64mmfr0, ID_AA64MMFR0, TGRAN16) >= 2;
251
+
252
+ trace_npcm7xx_rng_write(offset, value, size);
253
+
254
+ switch (offset) {
255
+ case NPCM7XX_RNGCS:
256
+ s->rngcs &= NPCM7XX_RNGCS_DVALID;
257
+ s->rngcs |= value & ~NPCM7XX_RNGCS_DVALID;
258
+ break;
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;
267
+ default:
268
+ qemu_log_mask(LOG_GUEST_ERROR,
269
+ "%s: write to invalid offset 0x%" HWADDR_PRIx "\n",
270
+ DEVICE(s)->canonical_path, offset);
271
+ break;
272
+ }
273
+}
34
+}
274
+
35
+
275
+static const MemoryRegionOps npcm7xx_rng_ops = {
36
+static inline bool isar_feature_aa64_tgran16_2_lpa2(const ARMISARegisters *id)
276
+ .read = npcm7xx_rng_read,
277
+ .write = npcm7xx_rng_write,
278
+ .endianness = DEVICE_LITTLE_ENDIAN,
279
+ .valid = {
280
+ .min_access_size = 1,
281
+ .max_access_size = 4,
282
+ .unaligned = false,
283
+ },
284
+};
285
+
286
+static void npcm7xx_rng_enter_reset(Object *obj, ResetType type)
287
+{
37
+{
288
+ NPCM7xxRNGState *s = NPCM7XX_RNG(obj);
38
+ unsigned t = FIELD_EX64(id->id_aa64mmfr0, ID_AA64MMFR0, TGRAN16_2);
289
+
39
+ return t >= 3 || (t == 0 && isar_feature_aa64_tgran16_lpa2(id));
290
+ s->rngcs = 0;
291
+ s->rngd = 0;
292
+ s->rngmode = 0;
293
+}
40
+}
294
+
41
+
295
+static void npcm7xx_rng_init(Object *obj)
42
+static inline bool isar_feature_aa64_tgran4(const ARMISARegisters *id)
296
+{
43
+{
297
+ NPCM7xxRNGState *s = NPCM7XX_RNG(obj);
44
+ return FIELD_SEX64(id->id_aa64mmfr0, ID_AA64MMFR0, TGRAN4) >= 0;
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
+}
45
+}
303
+
46
+
304
+static const VMStateDescription vmstate_npcm7xx_rng = {
47
+static inline bool isar_feature_aa64_tgran16(const ARMISARegisters *id)
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
+{
48
+{
318
+ ResettableClass *rc = RESETTABLE_CLASS(klass);
49
+ return FIELD_EX64(id->id_aa64mmfr0, ID_AA64MMFR0, TGRAN16) >= 1;
319
+ DeviceClass *dc = DEVICE_CLASS(klass);
320
+
321
+ dc->desc = "NPCM7xx Random Number Generator";
322
+ dc->vmsd = &vmstate_npcm7xx_rng;
323
+ rc->phases.enter = npcm7xx_rng_enter_reset;
324
+}
50
+}
325
+
51
+
326
+static const TypeInfo npcm7xx_rng_types[] = {
52
+static inline bool isar_feature_aa64_tgran64(const ARMISARegisters *id)
327
+ {
328
+ .name = TYPE_NPCM7XX_RNG,
329
+ .parent = TYPE_SYS_BUS_DEVICE,
330
+ .instance_size = sizeof(NPCM7xxRNGState),
331
+ .class_init = npcm7xx_rng_class_init,
332
+ .instance_init = npcm7xx_rng_init,
333
+ },
334
+};
335
+DEFINE_TYPES(npcm7xx_rng_types);
336
diff --git a/tests/qtest/npcm7xx_rng-test.c b/tests/qtest/npcm7xx_rng-test.c
337
new file mode 100644
338
index XXXXXXX..XXXXXXX
339
--- /dev/null
340
+++ b/tests/qtest/npcm7xx_rng-test.c
341
@@ -XXX,XX +XXX,XX @@
342
+/*
343
+ * QTest testcase for the Nuvoton NPCM7xx Random Number Generator
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
+{
53
+{
382
+ writeb(RNG_BASE_ADDR + offset, value);
54
+ return FIELD_SEX64(id->id_aa64mmfr0, ID_AA64MMFR0, TGRAN64) >= 0;
383
+}
55
+}
384
+
56
+
385
+static uint8_t rng_readb(unsigned int offset)
57
+static inline bool isar_feature_aa64_tgran4_2(const ARMISARegisters *id)
386
+{
58
+{
387
+ return readb(RNG_BASE_ADDR + offset);
59
+ unsigned t = FIELD_EX64(id->id_aa64mmfr0, ID_AA64MMFR0, TGRAN4_2);
60
+ return t >= 2 || (t == 0 && isar_feature_aa64_tgran4(id));
388
+}
61
+}
389
+
62
+
390
+/* Disable RNG and set normal ring oscillator mode. */
63
+static inline bool isar_feature_aa64_tgran16_2(const ARMISARegisters *id)
391
+static void rng_reset(void)
392
+{
64
+{
393
+ rng_writeb(RNGCS, 0);
65
+ unsigned t = FIELD_EX64(id->id_aa64mmfr0, ID_AA64MMFR0, TGRAN16_2);
394
+ rng_writeb(RNGMODE, ROSEL_NORMAL);
66
+ return t >= 2 || (t == 0 && isar_feature_aa64_tgran16(id));
395
+}
67
+}
396
+
68
+
397
+/* Reset RNG and then enable it. */
69
+static inline bool isar_feature_aa64_tgran64_2(const ARMISARegisters *id)
398
+static void rng_reset_enable(void)
399
+{
70
+{
400
+ rng_reset();
71
+ unsigned t = FIELD_EX64(id->id_aa64mmfr0, ID_AA64MMFR0, TGRAN64_2);
401
+ rng_writeb(RNGCS, RNGE);
72
+ return t >= 2 || (t == 0 && isar_feature_aa64_tgran64(id));
402
+}
73
+}
403
+
74
+
404
+/* Wait until Data Valid bit is set. */
75
+static inline bool isar_feature_aa64_fgt(const ARMISARegisters *id)
405
+static bool rng_wait_ready(void)
406
+{
76
+{
407
+ /* qemu_guest_getrandom may fail. Assume it won't fail 10 times in a row. */
77
+ return FIELD_EX64(id->id_aa64mmfr0, ID_AA64MMFR0, FGT) != 0;
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
+}
78
+}
418
+
79
+
419
+/*
80
static inline bool isar_feature_aa64_vh(const ARMISARegisters *id)
420
+ * Perform a frequency (monobit) test, as defined by NIST SP 800-22, on the
81
{
421
+ * sequence in buf and return the P-value. This represents the probability of a
82
return FIELD_EX64(id->id_aa64mmfr1, ID_AA64MMFR1, VH) != 0;
422
+ * truly random sequence having the same proportion of zeros and ones as the
83
@@ -XXX,XX +XXX,XX @@ static inline bool isar_feature_aa64_hbc(const ARMISARegisters *id)
423
+ * sequence in buf.
84
return FIELD_EX64(id->id_aa64isar2, ID_AA64ISAR2, BC) != 0;
424
+ *
85
}
425
+ * An RNG which always returns 0x00 or 0xff, or has some bits stuck at 0 or 1,
86
426
+ * will fail this test. However, an RNG which always returns 0x55, 0xf0 or some
87
-static inline bool isar_feature_aa64_tgran4_lpa2(const ARMISARegisters *id)
427
+ * other value with an equal number of zeroes and ones will pass.
88
-{
428
+ */
89
- return FIELD_SEX64(id->id_aa64mmfr0, ID_AA64MMFR0, TGRAN4) >= 1;
429
+static double calc_monobit_p(const uint8_t *buf, unsigned int len)
90
-}
430
+{
91
-
431
+ unsigned int i;
92
-static inline bool isar_feature_aa64_tgran4_2_lpa2(const ARMISARegisters *id)
432
+ double s_obs;
93
-{
433
+ int sn = 0;
94
- unsigned t = FIELD_EX64(id->id_aa64mmfr0, ID_AA64MMFR0, TGRAN4_2);
434
+
95
- return t >= 3 || (t == 0 && isar_feature_aa64_tgran4_lpa2(id));
435
+ for (i = 0; i < len; i++) {
96
-}
436
+ /*
97
-
437
+ * Each 1 counts as 1, each 0 counts as -1.
98
-static inline bool isar_feature_aa64_tgran16_lpa2(const ARMISARegisters *id)
438
+ * s = cp - (8 - cp) = 2 * cp - 8
99
-{
439
+ */
100
- return FIELD_EX64(id->id_aa64mmfr0, ID_AA64MMFR0, TGRAN16) >= 2;
440
+ sn += 2 * ctpop8(buf[i]) - 8;
101
-}
441
+ }
102
-
442
+
103
-static inline bool isar_feature_aa64_tgran16_2_lpa2(const ARMISARegisters *id)
443
+ s_obs = abs(sn) / sqrt(len * BITS_PER_BYTE);
104
-{
444
+
105
- unsigned t = FIELD_EX64(id->id_aa64mmfr0, ID_AA64MMFR0, TGRAN16_2);
445
+ return erfc(s_obs / sqrt(2));
106
- return t >= 3 || (t == 0 && isar_feature_aa64_tgran16_lpa2(id));
446
+}
107
-}
447
+
108
-
448
+/*
109
-static inline bool isar_feature_aa64_tgran4(const ARMISARegisters *id)
449
+ * Perform a runs test, as defined by NIST SP 800-22, and return the P-value.
110
-{
450
+ * This represents the probability of a truly random sequence having the same
111
- return FIELD_SEX64(id->id_aa64mmfr0, ID_AA64MMFR0, TGRAN4) >= 0;
451
+ * number of runs (i.e. uninterrupted sequences of identical bits) as the
112
-}
452
+ * sequence in buf.
113
-
453
+ */
114
-static inline bool isar_feature_aa64_tgran16(const ARMISARegisters *id)
454
+static double calc_runs_p(const unsigned long *buf, unsigned int nr_bits)
115
-{
455
+{
116
- return FIELD_EX64(id->id_aa64mmfr0, ID_AA64MMFR0, TGRAN16) >= 1;
456
+ unsigned int j;
117
-}
457
+ unsigned int k;
118
-
458
+ int nr_ones = 0;
119
-static inline bool isar_feature_aa64_tgran64(const ARMISARegisters *id)
459
+ int vn_obs = 0;
120
-{
460
+ double pi;
121
- return FIELD_SEX64(id->id_aa64mmfr0, ID_AA64MMFR0, TGRAN64) >= 0;
461
+
122
-}
462
+ g_assert(nr_bits % BITS_PER_LONG == 0);
123
-
463
+
124
-static inline bool isar_feature_aa64_tgran4_2(const ARMISARegisters *id)
464
+ for (j = 0; j < nr_bits / BITS_PER_LONG; j++) {
125
-{
465
+ nr_ones += __builtin_popcountl(buf[j]);
126
- unsigned t = FIELD_EX64(id->id_aa64mmfr0, ID_AA64MMFR0, TGRAN4_2);
466
+ }
127
- return t >= 2 || (t == 0 && isar_feature_aa64_tgran4(id));
467
+ pi = (double)nr_ones / nr_bits;
128
-}
468
+
129
-
469
+ for (k = 0; k < nr_bits - 1; k++) {
130
-static inline bool isar_feature_aa64_tgran16_2(const ARMISARegisters *id)
470
+ vn_obs += !(test_bit(k, buf) ^ test_bit(k + 1, buf));
131
-{
471
+ }
132
- unsigned t = FIELD_EX64(id->id_aa64mmfr0, ID_AA64MMFR0, TGRAN16_2);
472
+ vn_obs += 1;
133
- return t >= 2 || (t == 0 && isar_feature_aa64_tgran16(id));
473
+
134
-}
474
+ return erfc(fabs(vn_obs - 2 * nr_bits * pi * (1.0 - pi))
135
-
475
+ / (2 * sqrt(2 * nr_bits) * pi * (1.0 - pi)));
136
-static inline bool isar_feature_aa64_tgran64_2(const ARMISARegisters *id)
476
+}
137
-{
477
+
138
- unsigned t = FIELD_EX64(id->id_aa64mmfr0, ID_AA64MMFR0, TGRAN64_2);
478
+/*
139
- return t >= 2 || (t == 0 && isar_feature_aa64_tgran64(id));
479
+ * Verifies that DVALID is clear, and RNGD reads zero, when RNGE is cleared,
140
-}
480
+ * and DVALID eventually becomes set when RNGE is set.
141
-
481
+ */
142
-static inline bool isar_feature_aa64_fgt(const ARMISARegisters *id)
482
+static void test_enable_disable(void)
143
-{
483
+{
144
- return FIELD_EX64(id->id_aa64mmfr0, ID_AA64MMFR0, FGT) != 0;
484
+ /* Disable: DVALID should not be set, and RNGD should read zero */
145
-}
485
+ rng_reset();
146
-
486
+ g_assert_cmphex(rng_readb(RNGCS), ==, 0);
147
static inline bool isar_feature_aa64_dit(const ARMISARegisters *id)
487
+ g_assert_cmphex(rng_readb(RNGD), ==, 0);
148
{
488
+
149
return FIELD_EX64(id->id_aa64pfr0, ID_AA64PFR0, DIT) != 0;
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 : []) + \
663
--
150
--
664
2.20.1
151
2.34.1
665
152
666
153
diff view generated by jsdifflib
1
From: Hao Wu <wuhaotsh@google.com>
1
Move the feature test functions that test ID_AA64ISAR* fields
2
together.
2
3
3
The watchdog is part of NPCM7XX's timer module. Its behavior is
4
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
4
controlled by the WTCR register in the timer.
5
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Message-id: 20231024163510.2972081-5-peter.maydell@linaro.org
8
---
9
target/arm/cpu-features.h | 70 +++++++++++++++++++--------------------
10
1 file changed, 35 insertions(+), 35 deletions(-)
5
11
6
When enabled, the watchdog issues an interrupt signal after a pre-set
12
diff --git a/target/arm/cpu-features.h b/target/arm/cpu-features.h
7
amount of cycles, and issues a reset signal shortly after that.
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]
14
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
15
---
16
include/hw/misc/npcm7xx_clk.h | 2 +
17
include/hw/timer/npcm7xx_timer.h | 48 +++-
18
hw/arm/npcm7xx.c | 12 +
19
hw/misc/npcm7xx_clk.c | 28 ++
20
hw/timer/npcm7xx_timer.c | 266 ++++++++++++++----
21
tests/qtest/npcm7xx_watchdog_timer-test.c | 319 ++++++++++++++++++++++
22
MAINTAINERS | 1 +
23
tests/qtest/meson.build | 2 +-
24
8 files changed, 624 insertions(+), 54 deletions(-)
25
create mode 100644 tests/qtest/npcm7xx_watchdog_timer-test.c
26
27
diff --git a/include/hw/misc/npcm7xx_clk.h b/include/hw/misc/npcm7xx_clk.h
28
index XXXXXXX..XXXXXXX 100644
13
index XXXXXXX..XXXXXXX 100644
29
--- a/include/hw/misc/npcm7xx_clk.h
14
--- a/target/arm/cpu-features.h
30
+++ b/include/hw/misc/npcm7xx_clk.h
15
+++ b/target/arm/cpu-features.h
31
@@ -XXX,XX +XXX,XX @@
16
@@ -XXX,XX +XXX,XX @@ static inline bool isar_feature_aa64_rndr(const ARMISARegisters *id)
32
*/
17
return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, RNDR) != 0;
33
#define NPCM7XX_CLK_NR_REGS (0x70 / sizeof(uint32_t))
34
35
+#define NPCM7XX_WATCHDOG_RESET_GPIO_IN "npcm7xx-clk-watchdog-reset-gpio-in"
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;
54
55
/**
56
- * struct NPCM7xxTimer - Individual timer state.
57
- * @irq: GIC interrupt line to fire on expiration (if enabled).
58
+ * struct NPCM7xxBaseTimer - Basic functionality that both regular timer and
59
+ * watchdog timer use.
60
* @qtimer: QEMU timer that notifies us on expiration.
61
* @expires_ns: Absolute virtual expiration time.
62
* @remaining_ns: Remaining time until expiration if timer is paused.
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.
77
*/
78
@@ -XXX,XX +XXX,XX @@ typedef struct NPCM7xxTimer {
79
NPCM7xxTimerCtrlState *ctrl;
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
+
109
/**
110
* struct NPCM7xxTimerCtrlState - Timer Module device state.
111
* @parent: System bus device.
112
* @iomem: Memory region through which registers are accessed.
113
+ * @index: The index of this timer module.
114
* @tisr: The Timer Interrupt Status Register.
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.
118
*/
119
struct NPCM7xxTimerCtrlState {
120
SysBusDevice parent;
121
@@ -XXX,XX +XXX,XX @@ struct NPCM7xxTimerCtrlState {
122
MemoryRegion iomem;
123
124
uint32_t tisr;
125
- uint32_t wtcr;
126
127
NPCM7xxTimer timer[NPCM7XX_TIMERS_PER_CTRL];
128
+ NPCM7xxWatchdogTimer watchdog_timer;
129
};
130
131
#define TYPE_NPCM7XX_TIMER "npcm7xx-timer"
132
diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c
133
index XXXXXXX..XXXXXXX 100644
134
--- a/hw/arm/npcm7xx.c
135
+++ b/hw/arm/npcm7xx.c
136
@@ -XXX,XX +XXX,XX @@ enum NPCM7xxInterrupt {
137
NPCM7XX_TIMER12_IRQ,
138
NPCM7XX_TIMER13_IRQ,
139
NPCM7XX_TIMER14_IRQ,
140
+ NPCM7XX_WDG0_IRQ = 47, /* Timer Module 0 Watchdog */
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;
197
}
18
}
198
19
199
+/* Perform reset action triggered by a watchdog */
20
+static inline bool isar_feature_aa64_tlbirange(const ARMISARegisters *id)
200
+static void npcm7xx_clk_perform_watchdog_reset(void *opaque, int n,
201
+ int level)
202
+{
21
+{
203
+ NPCM7xxCLKState *clk = NPCM7XX_CLK(opaque);
22
+ return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, TLB) == 2;
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
+}
23
+}
216
+
24
+
217
static const struct MemoryRegionOps npcm7xx_clk_ops = {
25
+static inline bool isar_feature_aa64_tlbios(const ARMISARegisters *id)
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
230
index XXXXXXX..XXXXXXX 100644
231
--- a/hw/timer/npcm7xx_timer.c
232
+++ b/hw/timer/npcm7xx_timer.c
233
@@ -XXX,XX +XXX,XX @@
234
#include "qemu/osdep.h"
235
236
#include "hw/irq.h"
237
+#include "hw/qdev-properties.h"
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
+{
26
+{
264
+ int64_t now;
27
+ return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, TLB) != 0;
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
+}
28
+}
270
+
29
+
271
+/* Stop counting. Record the time remaining so we can continue later. */
30
static inline bool isar_feature_aa64_jscvt(const ARMISARegisters *id)
272
+static void npcm7xx_timer_pause(NPCM7xxBaseTimer *t)
31
{
32
return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, JSCVT) != 0;
33
@@ -XXX,XX +XXX,XX @@ static inline bool isar_feature_aa64_pauth_qarma3(const ARMISARegisters *id)
34
return FIELD_EX64(id->id_aa64isar2, ID_AA64ISAR2, APA3) != 0;
35
}
36
37
-static inline bool isar_feature_aa64_tlbirange(const ARMISARegisters *id)
38
-{
39
- return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, TLB) == 2;
40
-}
41
-
42
-static inline bool isar_feature_aa64_tlbios(const ARMISARegisters *id)
43
-{
44
- return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, TLB) != 0;
45
-}
46
-
47
static inline bool isar_feature_aa64_sb(const ARMISARegisters *id)
48
{
49
return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, SB) != 0;
50
@@ -XXX,XX +XXX,XX @@ static inline bool isar_feature_aa64_bf16(const ARMISARegisters *id)
51
return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, BF16) != 0;
52
}
53
54
+static inline bool isar_feature_aa64_rcpc_8_3(const ARMISARegisters *id)
273
+{
55
+{
274
+ int64_t now;
56
+ return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, LRCPC) != 0;
275
+
276
+ timer_del(&t->qtimer);
277
+ now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
278
+ t->remaining_ns = t->expires_ns - now;
279
+}
57
+}
280
+
58
+
281
+/* Delete the timer and reset it to default state. */
59
+static inline bool isar_feature_aa64_rcpc_8_4(const ARMISARegisters *id)
282
+static void npcm7xx_timer_clear(NPCM7xxBaseTimer *t)
283
+{
60
+{
284
+ timer_del(&t->qtimer);
61
+ return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, LRCPC) >= 2;
285
+ t->expires_ns = 0;
286
+ t->remaining_ns = 0;
287
+}
62
+}
288
+
63
+
289
/*
64
+static inline bool isar_feature_aa64_i8mm(const ARMISARegisters *id)
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
+{
65
+{
298
+ switch (NPCM7XX_WTCR_WTCLK(t->wtcr)) {
66
+ return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, I8MM) != 0;
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
+}
67
+}
311
+
68
+
312
+static void npcm7xx_watchdog_timer_reset_cycles(NPCM7xxWatchdogTimer *t,
69
+static inline bool isar_feature_aa64_hbc(const ARMISARegisters *id)
313
+ int64_t cycles)
314
+{
70
+{
315
+ uint32_t prescaler = npcm7xx_watchdog_timer_prescaler(t);
71
+ return FIELD_EX64(id->id_aa64isar2, ID_AA64ISAR2, BC) != 0;
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
+}
72
+}
328
+
73
+
329
+static void npcm7xx_watchdog_timer_reset(NPCM7xxWatchdogTimer *t)
74
+static inline bool isar_feature_aa64_mops(const ARMISARegisters *id)
330
+{
75
+{
331
+ int64_t cycles = 1;
76
+ return FIELD_EX64(id->id_aa64isar2, ID_AA64ISAR2, MOPS);
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
+}
77
+}
341
+
78
+
342
/*
79
static inline bool isar_feature_aa64_fp_simd(const ARMISARegisters *id)
343
* Raise the interrupt line if there's a pending interrupt and interrupts are
80
{
344
* enabled for this timer. If not, lower it.
81
/* We always set the AdvSIMD and FP fields identically. */
345
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_check_interrupt(NPCM7xxTimer *t)
82
@@ -XXX,XX +XXX,XX @@ static inline bool isar_feature_aa64_pmuv3p5(const ARMISARegisters *id)
346
trace_npcm7xx_timer_irq(DEVICE(tc)->canonical_path, index, pending);
83
FIELD_EX64(id->id_aa64dfr0, ID_AA64DFR0, PMUVER) != 0xf;
347
}
84
}
348
85
349
-/* Start or resume the timer. */
86
-static inline bool isar_feature_aa64_rcpc_8_3(const ARMISARegisters *id)
350
-static void npcm7xx_timer_start(NPCM7xxTimer *t)
351
-{
87
-{
352
- int64_t now;
88
- return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, LRCPC) != 0;
89
-}
353
-
90
-
354
- now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
91
-static inline bool isar_feature_aa64_rcpc_8_4(const ARMISARegisters *id)
355
- t->expires_ns = now + t->remaining_ns;
92
-{
356
- timer_mod(&t->qtimer, t->expires_ns);
93
- return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, LRCPC) >= 2;
94
-}
95
-
96
-static inline bool isar_feature_aa64_i8mm(const ARMISARegisters *id)
97
-{
98
- return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, I8MM) != 0;
99
-}
100
-
101
-static inline bool isar_feature_aa64_hbc(const ARMISARegisters *id)
102
-{
103
- return FIELD_EX64(id->id_aa64isar2, ID_AA64ISAR2, BC) != 0;
104
-}
105
-
106
static inline bool isar_feature_aa64_dit(const ARMISARegisters *id)
107
{
108
return FIELD_EX64(id->id_aa64pfr0, ID_AA64PFR0, DIT) != 0;
109
@@ -XXX,XX +XXX,XX @@ static inline bool isar_feature_aa64_doublelock(const ARMISARegisters *id)
110
return FIELD_SEX64(id->id_aa64dfr0, ID_AA64DFR0, DOUBLELOCK) >= 0;
111
}
112
113
-static inline bool isar_feature_aa64_mops(const ARMISARegisters *id)
114
-{
115
- return FIELD_EX64(id->id_aa64isar2, ID_AA64ISAR2, MOPS);
357
-}
116
-}
358
-
117
-
359
/*
118
/*
360
* Called when the counter reaches zero. Sets the interrupt flag, and either
119
* Feature tests for "does this exist in either 32-bit or 64-bit?"
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
*/
120
*/
392
static void npcm7xx_timer_restart(NPCM7xxTimer *t, uint32_t old_tcsr)
393
{
394
- t->remaining_ns = npcm7xx_timer_count_to_ns(t, t->ticr);
395
+ t->base_timer.remaining_ns = npcm7xx_timer_count_to_ns(t, t->ticr);
396
397
if (old_tcsr & t->tcsr & NPCM7XX_TCSR_CEN) {
398
- npcm7xx_timer_start(t);
399
+ npcm7xx_timer_start(&t->base_timer);
400
}
401
}
402
403
@@ -XXX,XX +XXX,XX @@ static uint32_t npcm7xx_timer_read_tdr(NPCM7xxTimer *t)
404
if (t->tcsr & NPCM7XX_TCSR_CEN) {
405
int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
406
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);
409
}
410
411
- return npcm7xx_timer_ns_to_count(t, t->remaining_ns);
412
+ return npcm7xx_timer_ns_to_count(t, t->base_timer.remaining_ns);
413
}
414
415
static void npcm7xx_timer_write_tcsr(NPCM7xxTimer *t, uint32_t new_tcsr)
416
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_write_tcsr(NPCM7xxTimer *t, uint32_t new_tcsr)
417
418
if (npcm7xx_tcsr_prescaler(old_tcsr) != npcm7xx_tcsr_prescaler(new_tcsr)) {
419
/* Recalculate time remaining based on the current TDR value. */
420
- t->remaining_ns = npcm7xx_timer_count_to_ns(t, tdr);
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
+
448
}
449
}
450
451
+static void npcm7xx_timer_write_wtcr(NPCM7xxWatchdogTimer *t, uint32_t new_wtcr)
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)
489
{
490
switch (reg) {
491
@@ -XXX,XX +XXX,XX @@ static uint64_t npcm7xx_timer_read(void *opaque, hwaddr offset, unsigned size)
492
break;
493
494
case NPCM7XX_TIMER_WTCR:
495
- value = s->wtcr;
496
+ value = s->watchdog_timer.wtcr;
497
break;
498
499
default:
500
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_write(void *opaque, hwaddr offset,
501
return;
502
503
case NPCM7XX_TIMER_WTCR:
504
- qemu_log_mask(LOG_UNIMP, "%s: WTCR write not implemented: 0x%08x\n",
505
- __func__, value);
506
+ npcm7xx_timer_write_wtcr(&s->watchdog_timer, value);
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
},
622
};
623
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
981
index XXXXXXX..XXXXXXX 100644
982
--- a/MAINTAINERS
983
+++ b/MAINTAINERS
984
@@ -XXX,XX +XXX,XX @@ L: qemu-arm@nongnu.org
985
S: Supported
986
F: hw/*/npcm7xx*
987
F: include/hw/*/npcm7xx*
988
+F: tests/qtest/npcm7xx*
989
F: pc-bios/npcm7xx_bootrom.bin
990
F: roms/vbootrom
991
992
diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
993
index XXXXXXX..XXXXXXX 100644
994
--- a/tests/qtest/meson.build
995
+++ b/tests/qtest/meson.build
996
@@ -XXX,XX +XXX,XX @@ qtests_sparc64 = \
997
(config_all_devices.has_key('CONFIG_ISA_TESTDEV') ? ['endianness-test'] : []) + \
998
['prom-env-test', 'boot-serial-test']
999
1000
-qtests_npcm7xx = ['npcm7xx_timer-test']
1001
+qtests_npcm7xx = ['npcm7xx_timer-test', 'npcm7xx_watchdog_timer-test']
1002
qtests_arm = \
1003
(config_all_devices.has_key('CONFIG_PFLASH_CFI02') ? ['pflash-cfi02-test'] : []) + \
1004
(config_all_devices.has_key('CONFIG_NPCM7XX') ? qtests_npcm7xx : []) + \
1005
--
121
--
1006
2.20.1
122
2.34.1
1007
123
1008
124
diff view generated by jsdifflib
1
From: Luc Michel <luc@lmichel.fr>
1
Move all the ID_AA64PFR* feature test functions together.
2
2
3
PLLs are composed of multiple channels. Each channel outputs one clock
3
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
4
signal. They are modeled as one device taking the PLL generated clock as
4
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
5
input, and outputting a new clock.
5
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
6
Message-id: 20231024163510.2972081-6-peter.maydell@linaro.org
7
---
8
target/arm/cpu-features.h | 86 +++++++++++++++++++--------------------
9
1 file changed, 43 insertions(+), 43 deletions(-)
6
10
7
A channel shares the CM register with its parent PLL, and has its own
11
diff --git a/target/arm/cpu-features.h b/target/arm/cpu-features.h
8
A2W_CTRL register. A write to the CM register will trigger an update of
9
the PLL and all its channels, while a write to an A2W_CTRL channel
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>
16
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
17
---
18
include/hw/misc/bcm2835_cprman.h | 44 ++++++
19
include/hw/misc/bcm2835_cprman_internals.h | 146 +++++++++++++++++++
20
hw/misc/bcm2835_cprman.c | 155 +++++++++++++++++++--
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
24
index XXXXXXX..XXXXXXX 100644
12
index XXXXXXX..XXXXXXX 100644
25
--- a/include/hw/misc/bcm2835_cprman.h
13
--- a/target/arm/cpu-features.h
26
+++ b/include/hw/misc/bcm2835_cprman.h
14
+++ b/target/arm/cpu-features.h
27
@@ -XXX,XX +XXX,XX @@ typedef enum CprmanPll {
15
@@ -XXX,XX +XXX,XX @@ static inline bool isar_feature_aa64_rme(const ARMISARegisters *id)
28
CPRMAN_NUM_PLL
16
return FIELD_EX64(id->id_aa64pfr0, ID_AA64PFR0, RME) != 0;
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
96
@@ -XXX,XX +XXX,XX @@
97
#include "hw/misc/bcm2835_cprman.h"
98
99
#define TYPE_CPRMAN_PLL "bcm2835-cprman-pll"
100
+#define TYPE_CPRMAN_PLL_CHANNEL "bcm2835-cprman-pll-channel"
101
102
DECLARE_INSTANCE_CHECKER(CprmanPllState, CPRMAN_PLL,
103
TYPE_CPRMAN_PLL)
104
+DECLARE_INSTANCE_CHECKER(CprmanPllChannelState, CPRMAN_PLL_CHANNEL,
105
+ TYPE_CPRMAN_PLL_CHANNEL)
106
107
/* Register map */
108
109
@@ -XXX,XX +XXX,XX @@ REG32(A2W_PLLD_FRAC, 0x1240)
110
REG32(A2W_PLLH_FRAC, 0x1260)
111
REG32(A2W_PLLB_FRAC, 0x12e0)
112
113
+/* PLL channels */
114
+REG32(A2W_PLLA_DSI0, 0x1300)
115
+ FIELD(A2W_PLLx_CHANNELy, DIV, 0, 8)
116
+ FIELD(A2W_PLLx_CHANNELy, DISABLE, 8, 1)
117
+REG32(A2W_PLLA_CORE, 0x1400)
118
+REG32(A2W_PLLA_PER, 0x1500)
119
+REG32(A2W_PLLA_CCP2, 0x1600)
120
+
121
+REG32(A2W_PLLC_CORE2, 0x1320)
122
+REG32(A2W_PLLC_CORE1, 0x1420)
123
+REG32(A2W_PLLC_PER, 0x1520)
124
+REG32(A2W_PLLC_CORE0, 0x1620)
125
+
126
+REG32(A2W_PLLD_DSI0, 0x1340)
127
+REG32(A2W_PLLD_CORE, 0x1440)
128
+REG32(A2W_PLLD_PER, 0x1540)
129
+REG32(A2W_PLLD_DSI1, 0x1640)
130
+
131
+REG32(A2W_PLLH_AUX, 0x1360)
132
+REG32(A2W_PLLH_RCAL, 0x1460)
133
+REG32(A2W_PLLH_PIX, 0x1560)
134
+REG32(A2W_PLLH_STS, 0x1660)
135
+
136
+REG32(A2W_PLLB_ARM, 0x13e0)
137
+
138
/* misc registers */
139
REG32(CM_LOCK, 0x114)
140
FIELD(CM_LOCK, FLOCKH, 12, 1)
141
@@ -XXX,XX +XXX,XX @@ static inline void set_pll_init_info(BCM2835CprmanState *s,
142
pll->reg_a2w_frac = &s->regs[PLL_INIT_INFO[id].a2w_frac_offset];
143
}
17
}
144
18
145
+
19
+static inline bool isar_feature_aa64_dit(const ARMISARegisters *id)
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
+{
20
+{
254
+ channel->id = id;
21
+ return FIELD_EX64(id->id_aa64pfr0, ID_AA64PFR0, DIT) != 0;
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
+}
22
+}
262
+
23
+
263
#endif
24
+static inline bool isar_feature_aa64_scxtnum(const ARMISARegisters *id)
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 = {
269
};
270
271
272
+/* PLL channel */
273
+
274
+static void pll_channel_update(CprmanPllChannelState *channel)
275
+{
25
+{
276
+ clock_update(channel->out, 0);
26
+ int key = FIELD_EX64(id->id_aa64pfr0, ID_AA64PFR0, CSV2);
27
+ if (key >= 2) {
28
+ return true; /* FEAT_CSV2_2 */
29
+ }
30
+ if (key == 1) {
31
+ key = FIELD_EX64(id->id_aa64pfr1, ID_AA64PFR1, CSV2_FRAC);
32
+ return key >= 2; /* FEAT_CSV2_1p2 */
33
+ }
34
+ return false;
277
+}
35
+}
278
+
36
+
279
+/* Update a PLL and all its channels */
37
+static inline bool isar_feature_aa64_ssbs(const ARMISARegisters *id)
280
+static void pll_update_all_channels(BCM2835CprmanState *s,
281
+ CprmanPllState *pll)
282
+{
38
+{
283
+ size_t i;
39
+ return FIELD_EX64(id->id_aa64pfr1, ID_AA64PFR1, SSBS) != 0;
284
+
285
+ pll_update(pll);
286
+
287
+ for (i = 0; i < CPRMAN_NUM_PLL_CHANNEL; i++) {
288
+ CprmanPllChannelState *channel = &s->channels[i];
289
+ if (channel->parent == pll->id) {
290
+ pll_channel_update(channel);
291
+ }
292
+ }
293
+}
40
+}
294
+
41
+
295
+static void pll_channel_pll_in_update(void *opaque)
42
+static inline bool isar_feature_aa64_bti(const ARMISARegisters *id)
296
+{
43
+{
297
+ pll_channel_update(CPRMAN_PLL_CHANNEL(opaque));
44
+ return FIELD_EX64(id->id_aa64pfr1, ID_AA64PFR1, BT) != 0;
298
+}
45
+}
299
+
46
+
300
+static void pll_channel_init(Object *obj)
47
+static inline bool isar_feature_aa64_mte_insn_reg(const ARMISARegisters *id)
301
+{
48
+{
302
+ CprmanPllChannelState *s = CPRMAN_PLL_CHANNEL(obj);
49
+ return FIELD_EX64(id->id_aa64pfr1, ID_AA64PFR1, MTE) != 0;
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
+}
50
+}
308
+
51
+
309
+static const VMStateDescription pll_channel_vmstate = {
52
+static inline bool isar_feature_aa64_mte(const ARMISARegisters *id)
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
+ }
317
+};
318
+
319
+static void pll_channel_class_init(ObjectClass *klass, void *data)
320
+{
53
+{
321
+ DeviceClass *dc = DEVICE_CLASS(klass);
54
+ return FIELD_EX64(id->id_aa64pfr1, ID_AA64PFR1, MTE) >= 2;
322
+
323
+ dc->vmsd = &pll_channel_vmstate;
324
+}
55
+}
325
+
56
+
326
+static const TypeInfo cprman_pll_channel_info = {
57
+static inline bool isar_feature_aa64_sme(const ARMISARegisters *id)
327
+ .name = TYPE_CPRMAN_PLL_CHANNEL,
328
+ .parent = TYPE_DEVICE,
329
+ .instance_size = sizeof(CprmanPllChannelState),
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
+{
58
+{
347
+ size_t i;
59
+ return FIELD_EX64(id->id_aa64pfr1, ID_AA64PFR1, SME) != 0;
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]);
352
+ return;
353
+ }
354
+ }
355
+}
60
+}
356
+
61
+
357
+static inline void update_channel_from_a2w(BCM2835CprmanState *s, size_t idx)
62
static inline bool isar_feature_aa64_tgran4_lpa2(const ARMISARegisters *id)
358
+{
63
{
359
+ size_t i;
64
return FIELD_SEX64(id->id_aa64mmfr0, ID_AA64MMFR0, TGRAN4) >= 1;
360
+
65
@@ -XXX,XX +XXX,XX @@ static inline bool isar_feature_aa64_e0pd(const ARMISARegisters *id)
361
+ for (i = 0; i < CPRMAN_NUM_PLL_CHANNEL; i++) {
66
return FIELD_EX64(id->id_aa64mmfr2, ID_AA64MMFR2, E0PD) != 0;
362
+ if (PLL_CHANNEL_INIT_INFO[i].a2w_ctrl_offset == idx) {
363
+ pll_channel_update(&s->channels[i]);
364
+ return;
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;
429
}
430
}
67
}
431
68
432
-#undef CASE_PLL_REGS
69
-static inline bool isar_feature_aa64_bti(const ARMISARegisters *id)
433
+#undef CASE_PLL_A2W_REGS
70
-{
434
71
- return FIELD_EX64(id->id_aa64pfr1, ID_AA64PFR1, BT) != 0;
435
static const MemoryRegionOps cprman_ops = {
72
-}
436
.read = cprman_read,
73
-
437
@@ -XXX,XX +XXX,XX @@ static void cprman_reset(DeviceState *dev)
74
-static inline bool isar_feature_aa64_mte_insn_reg(const ARMISARegisters *id)
438
device_cold_reset(DEVICE(&s->plls[i]));
75
-{
439
}
76
- return FIELD_EX64(id->id_aa64pfr1, ID_AA64PFR1, MTE) != 0;
440
77
-}
441
+ for (i = 0; i < CPRMAN_NUM_PLL_CHANNEL; i++) {
78
-
442
+ device_cold_reset(DEVICE(&s->channels[i]));
79
-static inline bool isar_feature_aa64_mte(const ARMISARegisters *id)
443
+ }
80
-{
444
+
81
- return FIELD_EX64(id->id_aa64pfr1, ID_AA64PFR1, MTE) >= 2;
445
clock_update_hz(s->xosc, s->xosc_freq);
82
-}
83
-
84
-static inline bool isar_feature_aa64_sme(const ARMISARegisters *id)
85
-{
86
- return FIELD_EX64(id->id_aa64pfr1, ID_AA64PFR1, SME) != 0;
87
-}
88
-
89
static inline bool isar_feature_aa64_pmuv3p1(const ARMISARegisters *id)
90
{
91
return FIELD_EX64(id->id_aa64dfr0, ID_AA64DFR0, PMUVER) >= 4 &&
92
@@ -XXX,XX +XXX,XX @@ static inline bool isar_feature_aa64_pmuv3p5(const ARMISARegisters *id)
93
FIELD_EX64(id->id_aa64dfr0, ID_AA64DFR0, PMUVER) != 0xf;
446
}
94
}
447
95
448
@@ -XXX,XX +XXX,XX @@ static void cprman_init(Object *obj)
96
-static inline bool isar_feature_aa64_dit(const ARMISARegisters *id)
449
set_pll_init_info(s, &s->plls[i], i);
97
-{
450
}
98
- return FIELD_EX64(id->id_aa64pfr0, ID_AA64PFR0, DIT) != 0;
451
99
-}
452
+ for (i = 0; i < CPRMAN_NUM_PLL_CHANNEL; i++) {
100
-
453
+ object_initialize_child(obj, PLL_CHANNEL_INIT_INFO[i].name,
101
-static inline bool isar_feature_aa64_scxtnum(const ARMISARegisters *id)
454
+ &s->channels[i],
102
-{
455
+ TYPE_CPRMAN_PLL_CHANNEL);
103
- int key = FIELD_EX64(id->id_aa64pfr0, ID_AA64PFR0, CSV2);
456
+ set_pll_channel_init_info(s, &s->channels[i], i);
104
- if (key >= 2) {
457
+ }
105
- return true; /* FEAT_CSV2_2 */
458
+
106
- }
459
s->xosc = clock_new(obj, "xosc");
107
- if (key == 1) {
460
108
- key = FIELD_EX64(id->id_aa64pfr1, ID_AA64PFR1, CSV2_FRAC);
461
memory_region_init_io(&s->iomem, obj, &cprman_ops,
109
- return key >= 2; /* FEAT_CSV2_1p2 */
462
@@ -XXX,XX +XXX,XX @@ static void cprman_realize(DeviceState *dev, Error **errp)
110
- }
463
return;
111
- return false;
464
}
112
-}
465
}
113
-
466
+
114
-static inline bool isar_feature_aa64_ssbs(const ARMISARegisters *id)
467
+ for (i = 0; i < CPRMAN_NUM_PLL_CHANNEL; i++) {
115
-{
468
+ CprmanPllChannelState *channel = &s->channels[i];
116
- return FIELD_EX64(id->id_aa64pfr1, ID_AA64PFR1, SSBS) != 0;
469
+ CprmanPll parent = PLL_CHANNEL_INIT_INFO[i].parent;
117
-}
470
+ Clock *parent_clk = s->plls[parent].out;
118
-
471
+
119
static inline bool isar_feature_aa64_debugv8p2(const ARMISARegisters *id)
472
+ clock_set_source(channel->pll_in, parent_clk);
473
+
474
+ if (!qdev_realize(DEVICE(channel), NULL, errp)) {
475
+ return;
476
+ }
477
+ }
478
}
479
480
static const VMStateDescription cprman_vmstate = {
481
@@ -XXX,XX +XXX,XX @@ static void cprman_register_types(void)
482
{
120
{
483
type_register_static(&cprman_info);
121
return FIELD_EX64(id->id_aa64dfr0, ID_AA64DFR0, DEBUGVER) >= 8;
484
type_register_static(&cprman_pll_info);
485
+ type_register_static(&cprman_pll_channel_info);
486
}
487
488
type_init(cprman_register_types);
489
--
122
--
490
2.20.1
123
2.34.1
491
124
492
125
diff view generated by jsdifflib
1
From: Luc Michel <luc@lmichel.fr>
1
Move all the ID_AA64DFR* feature test functions together.
2
2
3
Add a clock input to the PL011 UART so we can compute the current baud
3
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
4
rate and trace it. This is intended for developers who wish to use QEMU
4
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
5
to e.g. debug their firmware or to figure out the baud rate configured
5
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
6
by an unknown/closed source binary.
6
Message-id: 20231024163510.2972081-7-peter.maydell@linaro.org
7
---
8
target/arm/cpu-features.h | 10 +++++-----
9
1 file changed, 5 insertions(+), 5 deletions(-)
7
10
8
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
11
diff --git a/target/arm/cpu-features.h b/target/arm/cpu-features.h
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>
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
---
14
include/hw/char/pl011.h | 1 +
15
hw/char/pl011.c | 45 +++++++++++++++++++++++++++++++++++++++++
16
hw/char/trace-events | 1 +
17
3 files changed, 47 insertions(+)
18
19
diff --git a/include/hw/char/pl011.h b/include/hw/char/pl011.h
20
index XXXXXXX..XXXXXXX 100644
12
index XXXXXXX..XXXXXXX 100644
21
--- a/include/hw/char/pl011.h
13
--- a/target/arm/cpu-features.h
22
+++ b/include/hw/char/pl011.h
14
+++ b/target/arm/cpu-features.h
23
@@ -XXX,XX +XXX,XX @@ struct PL011State {
15
@@ -XXX,XX +XXX,XX @@ static inline bool isar_feature_aa64_debugv8p2(const ARMISARegisters *id)
24
int read_trigger;
16
return FIELD_EX64(id->id_aa64dfr0, ID_AA64DFR0, DEBUGVER) >= 8;
25
CharBackend chr;
26
qemu_irq irq[6];
27
+ Clock *clk;
28
const unsigned char *id;
29
};
30
31
diff --git a/hw/char/pl011.c b/hw/char/pl011.c
32
index XXXXXXX..XXXXXXX 100644
33
--- a/hw/char/pl011.c
34
+++ b/hw/char/pl011.c
35
@@ -XXX,XX +XXX,XX @@
36
#include "hw/char/pl011.h"
37
#include "hw/irq.h"
38
#include "hw/sysbus.h"
39
+#include "hw/qdev-clock.h"
40
#include "migration/vmstate.h"
41
#include "chardev/char-fe.h"
42
#include "qemu/log.h"
43
@@ -XXX,XX +XXX,XX @@ static void pl011_set_read_trigger(PL011State *s)
44
s->read_trigger = 1;
45
}
17
}
46
18
47
+static unsigned int pl011_get_baudrate(const PL011State *s)
19
+static inline bool isar_feature_aa64_doublelock(const ARMISARegisters *id)
48
+{
20
+{
49
+ uint64_t clk;
21
+ return FIELD_SEX64(id->id_aa64dfr0, ID_AA64DFR0, DOUBLELOCK) >= 0;
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;
57
+}
22
+}
58
+
23
+
59
+static void pl011_trace_baudrate_change(const PL011State *s)
24
static inline bool isar_feature_aa64_sve2(const ARMISARegisters *id)
60
+{
61
+ trace_pl011_baudrate_change(pl011_get_baudrate(s),
62
+ clock_get_hz(s->clk),
63
+ s->ibrd, s->fbrd);
64
+}
65
+
66
static void pl011_write(void *opaque, hwaddr offset,
67
uint64_t value, unsigned size)
68
{
25
{
69
@@ -XXX,XX +XXX,XX @@ static void pl011_write(void *opaque, hwaddr offset,
26
return FIELD_EX64(id->id_aa64zfr0, ID_AA64ZFR0, SVEVER) != 0;
70
break;
27
@@ -XXX,XX +XXX,XX @@ static inline bool isar_feature_aa64_sme_fa64(const ARMISARegisters *id)
71
case 9: /* UARTIBRD */
28
return FIELD_EX64(id->id_aa64smfr0, ID_AA64SMFR0, FA64);
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);
83
}
29
}
84
30
85
+static void pl011_clock_update(void *opaque)
31
-static inline bool isar_feature_aa64_doublelock(const ARMISARegisters *id)
86
+{
32
-{
87
+ PL011State *s = PL011(opaque);
33
- return FIELD_SEX64(id->id_aa64dfr0, ID_AA64DFR0, DOUBLELOCK) >= 0;
88
+
34
-}
89
+ pl011_trace_baudrate_change(s);
35
-
90
+}
36
/*
91
+
37
* Feature tests for "does this exist in either 32-bit or 64-bit?"
92
static const MemoryRegionOps pl011_ops = {
38
*/
93
.read = pl011_read,
94
.write = pl011_write,
95
.endianness = DEVICE_NATIVE_ENDIAN,
96
};
97
98
+static const VMStateDescription vmstate_pl011_clock = {
99
+ .name = "pl011/clock",
100
+ .version_id = 1,
101
+ .minimum_version_id = 1,
102
+ .fields = (VMStateField[]) {
103
+ VMSTATE_CLOCK(clk, PL011State),
104
+ VMSTATE_END_OF_LIST()
105
+ }
106
+};
107
+
108
static const VMStateDescription vmstate_pl011 = {
109
.name = "pl011",
110
.version_id = 2,
111
@@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_pl011 = {
112
VMSTATE_INT32(read_count, PL011State),
113
VMSTATE_INT32(read_trigger, PL011State),
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);
127
+
128
s->read_trigger = 1;
129
s->ifl = 0x12;
130
s->cr = 0x300;
131
diff --git a/hw/char/trace-events b/hw/char/trace-events
132
index XXXXXXX..XXXXXXX 100644
133
--- a/hw/char/trace-events
134
+++ b/hw/char/trace-events
135
@@ -XXX,XX +XXX,XX @@ pl011_write(uint32_t addr, uint32_t value) "addr 0x%08x value 0x%08x"
136
pl011_can_receive(uint32_t lcr, int read_count, int r) "LCR 0x%08x read_count %d returning %d"
137
pl011_put_fifo(uint32_t c, int read_count) "new char 0x%x read_count now %d"
138
pl011_put_fifo_full(void) "FIFO now full, RXFF set"
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 ")"
140
141
# cmsdk-apb-uart.c
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"
143
--
39
--
144
2.20.1
40
2.34.1
145
41
146
42
diff view generated by jsdifflib
1
From: Luc Michel <luc@lmichel.fr>
1
In commit 442c9d682c94fc2 when we converted the ERET, ERETAA, ERETAB
2
instructions to decodetree, the conversion accidentally lost the
3
correct setting of the syndrome register when taking a trap because
4
of the FEAT_FGT HFGITR_EL1.ERET bit. Instead of reporting a correct
5
full syndrome value with the EC and IL bits, we only reported the low
6
two bits of the syndrome, because the call to syn_erettrap() got
7
dropped.
2
8
3
The nanosecond unit greatly limits the dynamic range we can display in
9
Fix the syndrome values for these traps by reinstating the
4
clock value traces, for values in the order of 1GHz and more. The
10
syn_erettrap() calls.
5
internal representation can go way beyond this value and it is quite
6
common for today's clocks to be within those ranges.
7
11
8
For example, a frequency between 500MHz+ and 1GHz will be displayed as
12
Fixes: 442c9d682c94fc2 ("target/arm: Convert ERET, ERETAA, ERETAB to decodetree")
9
1ns. Beyond 1GHz, it will show up as 0ns.
13
Cc: qemu-stable@nongnu.org
14
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
15
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
16
Message-id: 20231024172438.2990945-1-peter.maydell@linaro.org
17
---
18
target/arm/tcg/translate-a64.c | 4 ++--
19
1 file changed, 2 insertions(+), 2 deletions(-)
10
20
11
Replace nanosecond periods traces with frequencies in the Hz unit
21
diff --git a/target/arm/tcg/translate-a64.c b/target/arm/tcg/translate-a64.c
12
to have more dynamic range in the trace output.
13
14
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
15
Reviewed-by: Damien Hedde <damien.hedde@greensocs.com>
16
Signed-off-by: Luc Michel <luc@lmichel.fr>
17
Tested-by: Guenter Roeck <linux@roeck-us.net>
18
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
19
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
20
---
21
hw/core/clock.c | 6 +++---
22
hw/core/trace-events | 4 ++--
23
2 files changed, 5 insertions(+), 5 deletions(-)
24
25
diff --git a/hw/core/clock.c b/hw/core/clock.c
26
index XXXXXXX..XXXXXXX 100644
22
index XXXXXXX..XXXXXXX 100644
27
--- a/hw/core/clock.c
23
--- a/target/arm/tcg/translate-a64.c
28
+++ b/hw/core/clock.c
24
+++ b/target/arm/tcg/translate-a64.c
29
@@ -XXX,XX +XXX,XX @@ bool clock_set(Clock *clk, uint64_t period)
25
@@ -XXX,XX +XXX,XX @@ static bool trans_ERET(DisasContext *s, arg_ERET *a)
30
if (clk->period == period) {
31
return false;
26
return false;
32
}
27
}
33
- trace_clock_set(CLOCK_PATH(clk), CLOCK_PERIOD_TO_NS(clk->period),
28
if (s->fgt_eret) {
34
- CLOCK_PERIOD_TO_NS(period));
29
- gen_exception_insn_el(s, 0, EXCP_UDEF, 0, 2);
35
+ trace_clock_set(CLOCK_PATH(clk), CLOCK_PERIOD_TO_HZ(clk->period),
30
+ gen_exception_insn_el(s, 0, EXCP_UDEF, syn_erettrap(0), 2);
36
+ CLOCK_PERIOD_TO_HZ(period));
31
return true;
37
clk->period = period;
32
}
38
33
dst = tcg_temp_new_i64();
39
return true;
34
@@ -XXX,XX +XXX,XX @@ static bool trans_ERETA(DisasContext *s, arg_reta *a)
40
@@ -XXX,XX +XXX,XX @@ static void clock_propagate_period(Clock *clk, bool call_callbacks)
35
}
41
if (child->period != clk->period) {
36
/* The FGT trap takes precedence over an auth trap. */
42
child->period = clk->period;
37
if (s->fgt_eret) {
43
trace_clock_update(CLOCK_PATH(child), CLOCK_PATH(clk),
38
- gen_exception_insn_el(s, 0, EXCP_UDEF, a->m ? 3 : 2, 2);
44
- CLOCK_PERIOD_TO_NS(clk->period),
39
+ gen_exception_insn_el(s, 0, EXCP_UDEF, syn_erettrap(a->m ? 3 : 2), 2);
45
+ CLOCK_PERIOD_TO_HZ(clk->period),
40
return true;
46
call_callbacks);
41
}
47
if (call_callbacks && child->callback) {
42
dst = tcg_temp_new_i64();
48
child->callback(child->callback_opaque);
49
diff --git a/hw/core/trace-events b/hw/core/trace-events
50
index XXXXXXX..XXXXXXX 100644
51
--- a/hw/core/trace-events
52
+++ b/hw/core/trace-events
53
@@ -XXX,XX +XXX,XX @@ resettable_transitional_function(void *obj, const char *objtype) "obj=%p(%s)"
54
# clock.c
55
clock_set_source(const char *clk, const char *src) "'%s', src='%s'"
56
clock_disconnect(const char *clk) "'%s'"
57
-clock_set(const char *clk, uint64_t old, uint64_t new) "'%s', ns=%"PRIu64"->%"PRIu64
58
+clock_set(const char *clk, uint64_t old, uint64_t new) "'%s', %"PRIu64"Hz->%"PRIu64"Hz"
59
clock_propagate(const char *clk) "'%s'"
60
-clock_update(const char *clk, const char *src, uint64_t val, int cb) "'%s', src='%s', ns=%"PRIu64", cb=%d"
61
+clock_update(const char *clk, const char *src, uint64_t hz, int cb) "'%s', src='%s', val=%"PRIu64"Hz cb=%d"
62
--
43
--
63
2.20.1
44
2.34.1
64
65
diff view generated by jsdifflib
1
From: Luc Michel <luc@lmichel.fr>
1
From: Philippe Mathieu-Daudé <philmd@linaro.org>
2
2
3
Connect the 'uart-out' clock from the CPRMAN to the PL011 instance.
3
"hw/arm/boot.h" is only required on the source file.
4
4
5
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
5
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
6
Signed-off-by: Luc Michel <luc@lmichel.fr>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Tested-by: Guenter Roeck <linux@roeck-us.net>
7
Reviewed-by: Luc Michel <luc.michel@amd.com>
8
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
8
Message-id: 20231025065316.56817-2-philmd@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
hw/arm/bcm2835_peripherals.c | 2 ++
11
include/hw/arm/allwinner-a10.h | 1 -
12
1 file changed, 2 insertions(+)
12
hw/arm/cubieboard.c | 1 +
13
2 files changed, 1 insertion(+), 1 deletion(-)
13
14
14
diff --git a/hw/arm/bcm2835_peripherals.c b/hw/arm/bcm2835_peripherals.c
15
diff --git a/include/hw/arm/allwinner-a10.h b/include/hw/arm/allwinner-a10.h
15
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
16
--- a/hw/arm/bcm2835_peripherals.c
17
--- a/include/hw/arm/allwinner-a10.h
17
+++ b/hw/arm/bcm2835_peripherals.c
18
+++ b/include/hw/arm/allwinner-a10.h
18
@@ -XXX,XX +XXX,XX @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)
19
@@ -XXX,XX +XXX,XX @@
19
}
20
#ifndef HW_ARM_ALLWINNER_A10_H
20
memory_region_add_subregion(&s->peri_mr, CPRMAN_OFFSET,
21
#define HW_ARM_ALLWINNER_A10_H
21
sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->cprman), 0));
22
22
+ qdev_connect_clock_in(DEVICE(&s->uart0), "clk",
23
-#include "hw/arm/boot.h"
23
+ qdev_get_clock_out(DEVICE(&s->cprman), "uart-out"));
24
#include "hw/timer/allwinner-a10-pit.h"
24
25
#include "hw/intc/allwinner-a10-pic.h"
25
memory_region_add_subregion(&s->peri_mr, ARMCTRL_IC_OFFSET,
26
#include "hw/net/allwinner_emac.h"
26
sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->ic), 0));
27
diff --git a/hw/arm/cubieboard.c b/hw/arm/cubieboard.c
28
index XXXXXXX..XXXXXXX 100644
29
--- a/hw/arm/cubieboard.c
30
+++ b/hw/arm/cubieboard.c
31
@@ -XXX,XX +XXX,XX @@
32
#include "hw/boards.h"
33
#include "hw/qdev-properties.h"
34
#include "hw/arm/allwinner-a10.h"
35
+#include "hw/arm/boot.h"
36
#include "hw/i2c/i2c.h"
37
38
static struct arm_boot_info cubieboard_binfo = {
27
--
39
--
28
2.20.1
40
2.34.1
29
41
30
42
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
1
From: Philippe Mathieu-Daudé <philmd@linaro.org>
2
2
3
It makes no sense to set enabled-cpus=0 on single core SoCs.
3
"hw/arm/boot.h" is only required on the source file.
4
4
5
Reviewed-by: Luc Michel <luc.michel@greensocs.com>
5
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
6
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Message-id: 20201024170127.3592182-5-f4bug@amsat.org
7
Reviewed-by: Luc Michel <luc.michel@amd.com>
8
Message-id: 20231025065316.56817-3-philmd@linaro.org
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
---
10
---
10
hw/arm/bcm2836.c | 15 +++++++--------
11
include/hw/arm/allwinner-h3.h | 1 -
11
1 file changed, 7 insertions(+), 8 deletions(-)
12
hw/arm/orangepi.c | 1 +
13
2 files changed, 1 insertion(+), 1 deletion(-)
12
14
13
diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c
15
diff --git a/include/hw/arm/allwinner-h3.h b/include/hw/arm/allwinner-h3.h
14
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
15
--- a/hw/arm/bcm2836.c
17
--- a/include/hw/arm/allwinner-h3.h
16
+++ b/hw/arm/bcm2836.c
18
+++ b/include/hw/arm/allwinner-h3.h
17
@@ -XXX,XX +XXX,XX @@ typedef struct BCM283XClass {
19
@@ -XXX,XX +XXX,XX @@
18
#define BCM283X_GET_CLASS(obj) \
20
#define HW_ARM_ALLWINNER_H3_H
19
OBJECT_GET_CLASS(BCM283XClass, (obj), TYPE_BCM283X)
21
20
22
#include "qom/object.h"
21
+static Property bcm2836_enabled_cores_property =
23
-#include "hw/arm/boot.h"
22
+ DEFINE_PROP_UINT32("enabled-cpus", BCM283XState, enabled_cpus, 0);
24
#include "hw/timer/allwinner-a10-pit.h"
23
+
25
#include "hw/intc/arm_gic.h"
24
static void bcm2836_init(Object *obj)
26
#include "hw/misc/allwinner-h3-ccu.h"
25
{
27
diff --git a/hw/arm/orangepi.c b/hw/arm/orangepi.c
26
BCM283XState *s = BCM283X(obj);
28
index XXXXXXX..XXXXXXX 100644
27
@@ -XXX,XX +XXX,XX @@ static void bcm2836_init(Object *obj)
29
--- a/hw/arm/orangepi.c
28
object_initialize_child(obj, "cpu[*]", &s->cpu[n].core,
30
+++ b/hw/arm/orangepi.c
29
bc->cpu_type);
31
@@ -XXX,XX +XXX,XX @@
30
}
32
#include "hw/boards.h"
31
+ if (bc->core_count > 1) {
33
#include "hw/qdev-properties.h"
32
+ qdev_property_add_static(DEVICE(obj), &bcm2836_enabled_cores_property);
34
#include "hw/arm/allwinner-h3.h"
33
+ qdev_prop_set_uint32(DEVICE(obj), "enabled-cpus", bc->core_count);
35
+#include "hw/arm/boot.h"
34
+ }
36
35
37
static struct arm_boot_info orangepi_binfo;
36
object_initialize_child(obj, "control", &s->control, TYPE_BCM2836_CONTROL);
37
38
@@ -XXX,XX +XXX,XX @@ static void bcm2836_realize(DeviceState *dev, Error **errp)
39
}
40
}
41
42
-static Property bcm2836_props[] = {
43
- DEFINE_PROP_UINT32("enabled-cpus", BCM283XState, enabled_cpus,
44
- BCM283X_NCPUS),
45
- DEFINE_PROP_END_OF_LIST()
46
-};
47
-
48
static void bcm283x_class_init(ObjectClass *oc, void *data)
49
{
50
DeviceClass *dc = DEVICE_CLASS(oc);
51
@@ -XXX,XX +XXX,XX @@ static void bcm2836_class_init(ObjectClass *oc, void *data)
52
bc->ctrl_base = 0x40000000;
53
bc->clusterid = 0xf;
54
dc->realize = bcm2836_realize;
55
- device_class_set_props(dc, bcm2836_props);
56
};
57
58
#ifdef TARGET_AARCH64
59
@@ -XXX,XX +XXX,XX @@ static void bcm2837_class_init(ObjectClass *oc, void *data)
60
bc->ctrl_base = 0x40000000;
61
bc->clusterid = 0x0;
62
dc->realize = bcm2836_realize;
63
- device_class_set_props(dc, bcm2836_props);
64
};
65
#endif
66
38
67
--
39
--
68
2.20.1
40
2.34.1
69
41
70
42
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Philippe Mathieu-Daudé <philmd@linaro.org>
2
2
3
The note test requires gcc 10 for -mbranch-protection=standard.
3
"hw/arm/boot.h" is only required on the source file.
4
The mmap test uses PROT_BTI and does not require special compiler support.
5
4
6
Acked-by: Alex Bennée <alex.bennee@linaro.org>
5
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
7
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
7
Reviewed-by: Luc Michel <luc.michel@amd.com>
9
Message-id: 20201021173749.111103-13-richard.henderson@linaro.org
8
Message-id: 20231025065316.56817-4-philmd@linaro.org
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
---
10
---
12
tests/tcg/aarch64/bti-1.c | 62 ++++++++++++++++
11
include/hw/arm/allwinner-r40.h | 1 -
13
tests/tcg/aarch64/bti-2.c | 116 ++++++++++++++++++++++++++++++
12
hw/arm/bananapi_m2u.c | 1 +
14
tests/tcg/aarch64/bti-crt.inc.c | 51 +++++++++++++
13
2 files changed, 1 insertion(+), 1 deletion(-)
15
tests/tcg/aarch64/Makefile.target | 10 +++
16
tests/tcg/configure.sh | 4 ++
17
5 files changed, 243 insertions(+)
18
create mode 100644 tests/tcg/aarch64/bti-1.c
19
create mode 100644 tests/tcg/aarch64/bti-2.c
20
create mode 100644 tests/tcg/aarch64/bti-crt.inc.c
21
14
22
diff --git a/tests/tcg/aarch64/bti-1.c b/tests/tcg/aarch64/bti-1.c
15
diff --git a/include/hw/arm/allwinner-r40.h b/include/hw/arm/allwinner-r40.h
23
new file mode 100644
16
index XXXXXXX..XXXXXXX 100644
24
index XXXXXXX..XXXXXXX
17
--- a/include/hw/arm/allwinner-r40.h
25
--- /dev/null
18
+++ b/include/hw/arm/allwinner-r40.h
26
+++ b/tests/tcg/aarch64/bti-1.c
27
@@ -XXX,XX +XXX,XX @@
19
@@ -XXX,XX +XXX,XX @@
28
+/*
20
#define HW_ARM_ALLWINNER_R40_H
29
+ * Branch target identification, basic notskip cases.
21
30
+ */
22
#include "qom/object.h"
31
+
23
-#include "hw/arm/boot.h"
32
+#include "bti-crt.inc.c"
24
#include "hw/timer/allwinner-a10-pit.h"
33
+
25
#include "hw/intc/arm_gic.h"
34
+static void skip2_sigill(int sig, siginfo_t *info, ucontext_t *uc)
26
#include "hw/sd/allwinner-sdhost.h"
35
+{
27
diff --git a/hw/arm/bananapi_m2u.c b/hw/arm/bananapi_m2u.c
36
+ uc->uc_mcontext.pc += 8;
28
index XXXXXXX..XXXXXXX 100644
37
+ uc->uc_mcontext.pstate = 1;
29
--- a/hw/arm/bananapi_m2u.c
38
+}
30
+++ b/hw/arm/bananapi_m2u.c
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 @@
31
@@ -XXX,XX +XXX,XX @@
96
+/*
32
#include "hw/i2c/i2c.h"
97
+ * Branch target identification, basic notskip cases.
33
#include "hw/qdev-properties.h"
98
+ */
34
#include "hw/arm/allwinner-r40.h"
99
+
35
+#include "hw/arm/boot.h"
100
+#include <stdio.h>
36
101
+#include <signal.h>
37
static struct arm_boot_info bpim2u_binfo;
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.
220
+ *
221
+ * Normal libc is not (yet) built with BTI support enabled,
222
+ * and so could generate a BTI TRAP before ever reaching main.
223
+ */
224
+
225
+#include <stdlib.h>
226
+#include <signal.h>
227
+#include <ucontext.h>
228
+#include <asm/unistd.h>
229
+
230
+int main(void);
231
+
232
+void _start(void)
233
+{
234
+ exit(main());
235
+}
236
+
237
+void exit(int ret)
238
+{
239
+ register int x0 __asm__("x0") = ret;
240
+ register int x8 __asm__("x8") = __NR_exit;
241
+
242
+ asm volatile("svc #0" : : "r"(x0), "r"(x8));
243
+ __builtin_unreachable();
244
+}
245
+
246
+/*
247
+ * Irritatingly, the user API struct sigaction does not match the
248
+ * kernel API struct sigaction. So for simplicity, isolate the
249
+ * kernel ABI here, and make this act like signal.
250
+ */
251
+void signal_info(int sig, void (*fn)(int, siginfo_t *, ucontext_t *))
252
+{
253
+ struct kernel_sigaction {
254
+ void (*handler)(int, siginfo_t *, ucontext_t *);
255
+ unsigned long flags;
256
+ unsigned long restorer;
257
+ unsigned long mask;
258
+ } sa = { fn, SA_SIGINFO, 0, 0 };
259
+
260
+ register int x0 __asm__("x0") = sig;
261
+ register void *x1 __asm__("x1") = &sa;
262
+ register void *x2 __asm__("x2") = 0;
263
+ register int x3 __asm__("x3") = sizeof(unsigned long);
264
+ register int x8 __asm__("x8") = __NR_rt_sigaction;
265
+
266
+ asm volatile("svc #0"
267
+ : : "r"(x0), "r"(x1), "r"(x2), "r"(x3), "r"(x8) : "memory");
268
+}
269
diff --git a/tests/tcg/aarch64/Makefile.target b/tests/tcg/aarch64/Makefile.target
270
index XXXXXXX..XXXXXXX 100644
271
--- a/tests/tcg/aarch64/Makefile.target
272
+++ b/tests/tcg/aarch64/Makefile.target
273
@@ -XXX,XX +XXX,XX @@ run-pauth-%: QEMU_OPTS += -cpu max
274
run-plugin-pauth-%: QEMU_OPTS += -cpu max
275
endif
276
277
+# BTI Tests
278
+# bti-1 tests the elf notes, so we require special compiler support.
279
+ifneq ($(DOCKER_IMAGE)$(CROSS_CC_HAS_ARMV8_BTI),)
280
+AARCH64_TESTS += bti-1
281
+bti-1: CFLAGS += -mbranch-protection=standard
282
+bti-1: LDFLAGS += -nostdlib
283
+endif
284
+# bti-2 tests PROT_BTI, so no special compiler support required.
285
+AARCH64_TESTS += bti-2
286
+
287
# Semihosting smoke test for linux-user
288
AARCH64_TESTS += semihosting
289
run-semihosting: semihosting
290
diff --git a/tests/tcg/configure.sh b/tests/tcg/configure.sh
291
index XXXXXXX..XXXXXXX 100755
292
--- a/tests/tcg/configure.sh
293
+++ b/tests/tcg/configure.sh
294
@@ -XXX,XX +XXX,XX @@ for target in $target_list; do
295
-march=armv8.3-a -o $TMPE $TMPC; then
296
echo "CROSS_CC_HAS_ARMV8_3=y" >> $config_target_mak
297
fi
298
+ if do_compiler "$target_compiler" $target_compiler_cflags \
299
+ -mbranch-protection=standard -o $TMPE $TMPC; then
300
+ echo "CROSS_CC_HAS_ARMV8_BTI=y" >> $config_target_mak
301
+ fi
302
;;
303
esac
304
38
305
--
39
--
306
2.20.1
40
2.34.1
307
41
308
42
diff view generated by jsdifflib
1
From: Luc Michel <luc@lmichel.fr>
1
From: Philippe Mathieu-Daudé <philmd@linaro.org>
2
2
3
A PLL channel is able to further divide the generated PLL frequency.
3
"hw/arm/boot.h" is only required on the source file.
4
The divider is given in the CTRL_A2W register. Some channels have an
5
additional fixed divider which is always applied to the signal.
6
4
7
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
5
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
8
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
9
Signed-off-by: Luc Michel <luc@lmichel.fr>
7
Reviewed-by: Luc Michel <luc.michel@amd.com>
10
Tested-by: Guenter Roeck <linux@roeck-us.net>
8
Message-id: 20231025065316.56817-5-philmd@linaro.org
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
---
10
---
13
hw/misc/bcm2835_cprman.c | 33 ++++++++++++++++++++++++++++++++-
11
include/hw/arm/fsl-imx25.h | 1 -
14
1 file changed, 32 insertions(+), 1 deletion(-)
12
hw/arm/imx25_pdk.c | 1 +
13
2 files changed, 1 insertion(+), 1 deletion(-)
15
14
16
diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c
15
diff --git a/include/hw/arm/fsl-imx25.h b/include/hw/arm/fsl-imx25.h
17
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
18
--- a/hw/misc/bcm2835_cprman.c
17
--- a/include/hw/arm/fsl-imx25.h
19
+++ b/hw/misc/bcm2835_cprman.c
18
+++ b/include/hw/arm/fsl-imx25.h
20
@@ -XXX,XX +XXX,XX @@ static const TypeInfo cprman_pll_info = {
19
@@ -XXX,XX +XXX,XX @@
21
20
#ifndef FSL_IMX25_H
22
/* PLL channel */
21
#define FSL_IMX25_H
23
22
24
+static bool pll_channel_is_enabled(CprmanPllChannelState *channel)
23
-#include "hw/arm/boot.h"
25
+{
24
#include "hw/intc/imx_avic.h"
26
+ /*
25
#include "hw/misc/imx25_ccm.h"
27
+ * XXX I'm not sure of the purpose of the LOAD field. The Linux driver does
26
#include "hw/char/imx_serial.h"
28
+ * not set it when enabling the channel, but does clear it when disabling
27
diff --git a/hw/arm/imx25_pdk.c b/hw/arm/imx25_pdk.c
29
+ * it.
28
index XXXXXXX..XXXXXXX 100644
30
+ */
29
--- a/hw/arm/imx25_pdk.c
31
+ return !FIELD_EX32(*channel->reg_a2w_ctrl, A2W_PLLx_CHANNELy, DISABLE)
30
+++ b/hw/arm/imx25_pdk.c
32
+ && !(*channel->reg_cm & channel->hold_mask);
31
@@ -XXX,XX +XXX,XX @@
33
+}
32
#include "qapi/error.h"
34
+
33
#include "hw/qdev-properties.h"
35
static void pll_channel_update(CprmanPllChannelState *channel)
34
#include "hw/arm/fsl-imx25.h"
36
{
35
+#include "hw/arm/boot.h"
37
- clock_update(channel->out, 0);
36
#include "hw/boards.h"
38
+ uint64_t freq, div;
37
#include "qemu/error-report.h"
39
+
38
#include "sysemu/qtest.h"
40
+ if (!pll_channel_is_enabled(channel)) {
41
+ clock_update(channel->out, 0);
42
+ return;
43
+ }
44
+
45
+ div = FIELD_EX32(*channel->reg_a2w_ctrl, A2W_PLLx_CHANNELy, DIV);
46
+
47
+ if (!div) {
48
+ /*
49
+ * It seems that when the divider value is 0, it is considered as
50
+ * being maximum by the hardware (see the Linux driver).
51
+ */
52
+ div = R_A2W_PLLx_CHANNELy_DIV_MASK;
53
+ }
54
+
55
+ /* Some channels have an additional fixed divider */
56
+ freq = clock_get_hz(channel->pll_in) / (div * channel->fixed_divider);
57
+
58
+ clock_update_hz(channel->out, freq);
59
}
60
61
/* Update a PLL and all its channels */
62
--
39
--
63
2.20.1
40
2.34.1
64
41
65
42
diff view generated by jsdifflib
1
From: Luc Michel <luc@lmichel.fr>
1
From: Philippe Mathieu-Daudé <philmd@linaro.org>
2
2
3
The CPRMAN (clock controller) was mapped at the watchdog/power manager
3
"hw/arm/boot.h" is only required on the source file.
4
address. It was also split into two unimplemented peripherals (CM and
5
A2W) but this is really the same one, as shown by this extract of the
6
Raspberry Pi 3 Linux device tree:
7
4
8
watchdog@7e100000 {
5
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
9
compatible = "brcm,bcm2835-pm\0brcm,bcm2835-pm-wdt";
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
10
[...]
7
Reviewed-by: Luc Michel <luc.michel@amd.com>
11
reg = <0x7e100000 0x114 0x7e00a000 0x24>;
8
Message-id: 20231025065316.56817-6-philmd@linaro.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>
27
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
28
---
10
---
29
include/hw/arm/bcm2835_peripherals.h | 2 +-
11
include/hw/arm/fsl-imx31.h | 1 -
30
include/hw/arm/raspi_platform.h | 5 ++---
12
hw/arm/kzm.c | 1 +
31
hw/arm/bcm2835_peripherals.c | 4 ++--
13
2 files changed, 1 insertion(+), 1 deletion(-)
32
3 files changed, 5 insertions(+), 6 deletions(-)
33
14
34
diff --git a/include/hw/arm/bcm2835_peripherals.h b/include/hw/arm/bcm2835_peripherals.h
15
diff --git a/include/hw/arm/fsl-imx31.h b/include/hw/arm/fsl-imx31.h
35
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
36
--- a/include/hw/arm/bcm2835_peripherals.h
17
--- a/include/hw/arm/fsl-imx31.h
37
+++ b/include/hw/arm/bcm2835_peripherals.h
18
+++ b/include/hw/arm/fsl-imx31.h
38
@@ -XXX,XX +XXX,XX @@ struct BCM2835PeripheralState {
19
@@ -XXX,XX +XXX,XX @@
39
BCM2835MphiState mphi;
20
#ifndef FSL_IMX31_H
40
UnimplementedDeviceState txp;
21
#define FSL_IMX31_H
41
UnimplementedDeviceState armtmr;
22
42
+ UnimplementedDeviceState powermgt;
23
-#include "hw/arm/boot.h"
43
UnimplementedDeviceState cprman;
24
#include "hw/intc/imx_avic.h"
44
- UnimplementedDeviceState a2w;
25
#include "hw/misc/imx31_ccm.h"
45
PL011State uart0;
26
#include "hw/char/imx_serial.h"
46
BCM2835AuxState aux;
27
diff --git a/hw/arm/kzm.c b/hw/arm/kzm.c
47
BCM2835FBState fb;
48
diff --git a/include/hw/arm/raspi_platform.h b/include/hw/arm/raspi_platform.h
49
index XXXXXXX..XXXXXXX 100644
28
index XXXXXXX..XXXXXXX 100644
50
--- a/include/hw/arm/raspi_platform.h
29
--- a/hw/arm/kzm.c
51
+++ b/include/hw/arm/raspi_platform.h
30
+++ b/hw/arm/kzm.c
52
@@ -XXX,XX +XXX,XX @@
31
@@ -XXX,XX +XXX,XX @@
53
#define ARMCTRL_TIMER0_1_OFFSET (ARM_OFFSET + 0x400) /* Timer 0 and 1 (SP804) */
32
#include "qemu/osdep.h"
54
#define ARMCTRL_0_SBM_OFFSET (ARM_OFFSET + 0x800) /* User 0 (ARM) Semaphores
33
#include "qapi/error.h"
55
* Doorbells & Mailboxes */
34
#include "hw/arm/fsl-imx31.h"
56
-#define CPRMAN_OFFSET 0x100000 /* Power Management, Watchdog */
35
+#include "hw/arm/boot.h"
57
-#define CM_OFFSET 0x101000 /* Clock Management */
36
#include "hw/boards.h"
58
-#define A2W_OFFSET 0x102000 /* Reset controller */
37
#include "qemu/error-report.h"
59
+#define PM_OFFSET 0x100000 /* Power Management */
38
#include "exec/address-spaces.h"
60
+#define CPRMAN_OFFSET 0x101000 /* Clock Management */
61
#define AVS_OFFSET 0x103000 /* Audio Video Standard */
62
#define RNG_OFFSET 0x104000
63
#define GPIO_OFFSET 0x200000
64
diff --git a/hw/arm/bcm2835_peripherals.c b/hw/arm/bcm2835_peripherals.c
65
index XXXXXXX..XXXXXXX 100644
66
--- a/hw/arm/bcm2835_peripherals.c
67
+++ b/hw/arm/bcm2835_peripherals.c
68
@@ -XXX,XX +XXX,XX @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)
69
70
create_unimp(s, &s->txp, "bcm2835-txp", TXP_OFFSET, 0x1000);
71
create_unimp(s, &s->armtmr, "bcm2835-sp804", ARMCTRL_TIMER0_1_OFFSET, 0x40);
72
- create_unimp(s, &s->cprman, "bcm2835-cprman", CPRMAN_OFFSET, 0x1000);
73
- create_unimp(s, &s->a2w, "bcm2835-a2w", A2W_OFFSET, 0x1000);
74
+ create_unimp(s, &s->powermgt, "bcm2835-powermgt", PM_OFFSET, 0x114);
75
+ create_unimp(s, &s->cprman, "bcm2835-cprman", CPRMAN_OFFSET, 0x2000);
76
create_unimp(s, &s->i2s, "bcm2835-i2s", I2S_OFFSET, 0x100);
77
create_unimp(s, &s->smi, "bcm2835-smi", SMI_OFFSET, 0x100);
78
create_unimp(s, &s->spi[0], "bcm2835-spi0", SPI0_OFFSET, 0x20);
79
--
39
--
80
2.20.1
40
2.34.1
81
41
82
42
diff view generated by jsdifflib
1
From: Luc Michel <luc@lmichel.fr>
1
From: Philippe Mathieu-Daudé <philmd@linaro.org>
2
2
3
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
3
"hw/arm/boot.h" is only required on the source file.
4
Reviewed-by: Damien Hedde <damien.hedde@greensocs.com>
4
5
Signed-off-by: Luc Michel <luc@lmichel.fr>
5
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
6
Tested-by: Guenter Roeck <linux@roeck-us.net>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
7
Reviewed-by: Luc Michel <luc.michel@amd.com>
8
Message-id: 20231025065316.56817-7-philmd@linaro.org
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
---
10
---
10
include/hw/clock.h | 5 +++++
11
include/hw/arm/fsl-imx6.h | 1 -
11
1 file changed, 5 insertions(+)
12
hw/arm/sabrelite.c | 1 +
13
2 files changed, 1 insertion(+), 1 deletion(-)
12
14
13
diff --git a/include/hw/clock.h b/include/hw/clock.h
15
diff --git a/include/hw/arm/fsl-imx6.h b/include/hw/arm/fsl-imx6.h
14
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
15
--- a/include/hw/clock.h
17
--- a/include/hw/arm/fsl-imx6.h
16
+++ b/include/hw/clock.h
18
+++ b/include/hw/arm/fsl-imx6.h
17
@@ -XXX,XX +XXX,XX @@ extern const VMStateDescription vmstate_clock;
19
@@ -XXX,XX +XXX,XX @@
18
VMSTATE_CLOCK_V(field, state, 0)
20
#ifndef FSL_IMX6_H
19
#define VMSTATE_CLOCK_V(field, state, version) \
21
#define FSL_IMX6_H
20
VMSTATE_STRUCT_POINTER_V(field, state, version, vmstate_clock, Clock)
22
21
+#define VMSTATE_ARRAY_CLOCK(field, state, num) \
23
-#include "hw/arm/boot.h"
22
+ VMSTATE_ARRAY_CLOCK_V(field, state, num, 0)
24
#include "hw/cpu/a9mpcore.h"
23
+#define VMSTATE_ARRAY_CLOCK_V(field, state, num, version) \
25
#include "hw/misc/imx6_ccm.h"
24
+ VMSTATE_ARRAY_OF_POINTER_TO_STRUCT(field, state, num, version, \
26
#include "hw/misc/imx6_src.h"
25
+ vmstate_clock, Clock)
27
diff --git a/hw/arm/sabrelite.c b/hw/arm/sabrelite.c
26
28
index XXXXXXX..XXXXXXX 100644
27
/**
29
--- a/hw/arm/sabrelite.c
28
* clock_setup_canonical_path:
30
+++ b/hw/arm/sabrelite.c
31
@@ -XXX,XX +XXX,XX @@
32
#include "qemu/osdep.h"
33
#include "qapi/error.h"
34
#include "hw/arm/fsl-imx6.h"
35
+#include "hw/arm/boot.h"
36
#include "hw/boards.h"
37
#include "hw/qdev-properties.h"
38
#include "qemu/error-report.h"
29
--
39
--
30
2.20.1
40
2.34.1
31
41
32
42
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
1
From: Philippe Mathieu-Daudé <philmd@linaro.org>
2
2
3
The Pi 3A+ is a stripped down version of the 3B:
3
"hw/arm/boot.h" is only required on the source file.
4
- 512 MiB of RAM instead of 1 GiB
5
- no on-board ethernet chipset
6
4
7
Add it as it is a closer match to what we model.
5
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
8
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
9
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
7
Reviewed-by: Luc Michel <luc.michel@amd.com>
10
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
8
Message-id: 20231025065316.56817-8-philmd@linaro.org
11
Message-id: 20201024170127.3592182-10-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/arm/raspi.c | 13 +++++++++++++
11
include/hw/arm/fsl-imx6ul.h | 1 -
15
1 file changed, 13 insertions(+)
12
hw/arm/mcimx6ul-evk.c | 1 +
13
2 files changed, 1 insertion(+), 1 deletion(-)
16
14
17
diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c
15
diff --git a/include/hw/arm/fsl-imx6ul.h b/include/hw/arm/fsl-imx6ul.h
18
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
19
--- a/hw/arm/raspi.c
17
--- a/include/hw/arm/fsl-imx6ul.h
20
+++ b/hw/arm/raspi.c
18
+++ b/include/hw/arm/fsl-imx6ul.h
21
@@ -XXX,XX +XXX,XX @@ static void raspi2b_machine_class_init(ObjectClass *oc, void *data)
19
@@ -XXX,XX +XXX,XX @@
22
};
20
#ifndef FSL_IMX6UL_H
23
21
#define FSL_IMX6UL_H
24
#ifdef TARGET_AARCH64
22
25
+static void raspi3ap_machine_class_init(ObjectClass *oc, void *data)
23
-#include "hw/arm/boot.h"
26
+{
24
#include "hw/cpu/a15mpcore.h"
27
+ MachineClass *mc = MACHINE_CLASS(oc);
25
#include "hw/misc/imx6ul_ccm.h"
28
+ RaspiMachineClass *rmc = RASPI_MACHINE_CLASS(oc);
26
#include "hw/misc/imx6_src.h"
29
+
27
diff --git a/hw/arm/mcimx6ul-evk.c b/hw/arm/mcimx6ul-evk.c
30
+ rmc->board_rev = 0x9020e0; /* Revision 1.0 */
28
index XXXXXXX..XXXXXXX 100644
31
+ raspi_machine_class_common_init(mc, rmc->board_rev);
29
--- a/hw/arm/mcimx6ul-evk.c
32
+};
30
+++ b/hw/arm/mcimx6ul-evk.c
33
+
31
@@ -XXX,XX +XXX,XX @@
34
static void raspi3b_machine_class_init(ObjectClass *oc, void *data)
32
#include "qemu/osdep.h"
35
{
33
#include "qapi/error.h"
36
MachineClass *mc = MACHINE_CLASS(oc);
34
#include "hw/arm/fsl-imx6ul.h"
37
@@ -XXX,XX +XXX,XX @@ static const TypeInfo raspi_machine_types[] = {
35
+#include "hw/arm/boot.h"
38
.parent = TYPE_RASPI_MACHINE,
36
#include "hw/boards.h"
39
.class_init = raspi2b_machine_class_init,
37
#include "hw/qdev-properties.h"
40
#ifdef TARGET_AARCH64
38
#include "qemu/error-report.h"
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,
48
--
39
--
49
2.20.1
40
2.34.1
50
41
51
42
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
1
From: Philippe Mathieu-Daudé <philmd@linaro.org>
2
2
3
Similarly to the Pi A, the Pi Zero uses a BCM2835 SoC (ARMv6Z core).
3
"hw/arm/boot.h" is only required on the source file.
4
4
5
The only difference between the revision 1.2 and 1.3 is the latter
5
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
6
exposes a CSI camera connector. As we do not implement the Unicam
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
7
peripheral, there is no point in exposing a camera connector :)
7
Reviewed-by: Luc Michel <luc.michel@amd.com>
8
Therefore we choose to model the 1.2 revision.
8
Message-id: 20231025065316.56817-9-philmd@linaro.org
9
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
29
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
30
---
10
---
31
hw/arm/raspi.c | 13 +++++++++++++
11
include/hw/arm/fsl-imx7.h | 1 -
32
1 file changed, 13 insertions(+)
12
hw/arm/mcimx7d-sabre.c | 1 +
13
2 files changed, 1 insertion(+), 1 deletion(-)
33
14
34
diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c
15
diff --git a/include/hw/arm/fsl-imx7.h b/include/hw/arm/fsl-imx7.h
35
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
36
--- a/hw/arm/raspi.c
17
--- a/include/hw/arm/fsl-imx7.h
37
+++ b/hw/arm/raspi.c
18
+++ b/include/hw/arm/fsl-imx7.h
38
@@ -XXX,XX +XXX,XX @@ static void raspi_machine_class_common_init(MachineClass *mc,
19
@@ -XXX,XX +XXX,XX @@
39
mc->default_ram_id = "ram";
20
#ifndef FSL_IMX7_H
40
};
21
#define FSL_IMX7_H
41
22
42
+static void raspi0_machine_class_init(ObjectClass *oc, void *data)
23
-#include "hw/arm/boot.h"
43
+{
24
#include "hw/cpu/a15mpcore.h"
44
+ MachineClass *mc = MACHINE_CLASS(oc);
25
#include "hw/intc/imx_gpcv2.h"
45
+ RaspiMachineClass *rmc = RASPI_MACHINE_CLASS(oc);
26
#include "hw/misc/imx7_ccm.h"
46
+
27
diff --git a/hw/arm/mcimx7d-sabre.c b/hw/arm/mcimx7d-sabre.c
47
+ rmc->board_rev = 0x920092; /* Revision 1.2 */
28
index XXXXXXX..XXXXXXX 100644
48
+ raspi_machine_class_common_init(mc, rmc->board_rev);
29
--- a/hw/arm/mcimx7d-sabre.c
49
+};
30
+++ b/hw/arm/mcimx7d-sabre.c
50
+
31
@@ -XXX,XX +XXX,XX @@
51
static void raspi1ap_machine_class_init(ObjectClass *oc, void *data)
32
#include "qemu/osdep.h"
52
{
33
#include "qapi/error.h"
53
MachineClass *mc = MACHINE_CLASS(oc);
34
#include "hw/arm/fsl-imx7.h"
54
@@ -XXX,XX +XXX,XX @@ static void raspi3b_machine_class_init(ObjectClass *oc, void *data)
35
+#include "hw/arm/boot.h"
55
36
#include "hw/boards.h"
56
static const TypeInfo raspi_machine_types[] = {
37
#include "hw/qdev-properties.h"
57
{
38
#include "qemu/error-report.h"
58
+ .name = MACHINE_TYPE_NAME("raspi0"),
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,
65
--
39
--
66
2.20.1
40
2.34.1
67
41
68
42
diff view generated by jsdifflib
1
From: Pavel Dovgalyuk <pavel.dovgalyuk@ispras.ru>
1
From: Philippe Mathieu-Daudé <philmd@linaro.org>
2
2
3
This patch sets min_cpus field for xlnx-versal-virt platform,
3
"hw/arm/boot.h" is only required on the source file.
4
because it always creates XLNX_VERSAL_NR_ACPUS cpus even with
5
-smp 1 command line option.
6
4
7
Signed-off-by: Pavel Dovgalyuk <pavel.dovgalyuk@ispras.ru>
5
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
8
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
9
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
7
Reviewed-by: Luc Michel <luc.michel@amd.com>
10
Message-id: 160343854912.8460.17915238517799132371.stgit@pasha-ThinkPad-X280
8
Message-id: 20231025065316.56817-10-philmd@linaro.org
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
---
10
---
13
hw/arm/xlnx-versal-virt.c | 1 +
11
include/hw/arm/xlnx-versal.h | 1 -
14
1 file changed, 1 insertion(+)
12
hw/arm/xlnx-versal-virt.c | 1 +
13
2 files changed, 1 insertion(+), 1 deletion(-)
15
14
15
diff --git a/include/hw/arm/xlnx-versal.h b/include/hw/arm/xlnx-versal.h
16
index XXXXXXX..XXXXXXX 100644
17
--- a/include/hw/arm/xlnx-versal.h
18
+++ b/include/hw/arm/xlnx-versal.h
19
@@ -XXX,XX +XXX,XX @@
20
#define XLNX_VERSAL_H
21
22
#include "hw/sysbus.h"
23
-#include "hw/arm/boot.h"
24
#include "hw/cpu/cluster.h"
25
#include "hw/or-irq.h"
26
#include "hw/sd/sdhci.h"
16
diff --git a/hw/arm/xlnx-versal-virt.c b/hw/arm/xlnx-versal-virt.c
27
diff --git a/hw/arm/xlnx-versal-virt.c b/hw/arm/xlnx-versal-virt.c
17
index XXXXXXX..XXXXXXX 100644
28
index XXXXXXX..XXXXXXX 100644
18
--- a/hw/arm/xlnx-versal-virt.c
29
--- a/hw/arm/xlnx-versal-virt.c
19
+++ b/hw/arm/xlnx-versal-virt.c
30
+++ b/hw/arm/xlnx-versal-virt.c
20
@@ -XXX,XX +XXX,XX @@ static void versal_virt_machine_class_init(ObjectClass *oc, void *data)
31
@@ -XXX,XX +XXX,XX @@
21
32
#include "cpu.h"
22
mc->desc = "Xilinx Versal Virtual development board";
33
#include "hw/qdev-properties.h"
23
mc->init = versal_virt_init;
34
#include "hw/arm/xlnx-versal.h"
24
+ mc->min_cpus = XLNX_VERSAL_NR_ACPUS;
35
+#include "hw/arm/boot.h"
25
mc->max_cpus = XLNX_VERSAL_NR_ACPUS;
36
#include "qom/object.h"
26
mc->default_cpus = XLNX_VERSAL_NR_ACPUS;
37
27
mc->no_cdrom = true;
38
#define TYPE_XLNX_VERSAL_VIRT_MACHINE MACHINE_TYPE_NAME("xlnx-versal-virt")
28
--
39
--
29
2.20.1
40
2.34.1
30
41
31
42
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
1
From: Philippe Mathieu-Daudé <philmd@linaro.org>
2
2
3
The Pi A is almost the first machine released.
3
"hw/arm/boot.h" is only required on the source file.
4
It uses a BCM2835 SoC which includes a ARMv6Z core.
5
4
6
Example booting the machine using content from [*]
5
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
7
(we use the device tree from the B model):
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
7
Reviewed-by: Luc Michel <luc.michel@amd.com>
9
$ qemu-system-arm -M raspi1ap -serial stdio \
8
Message-id: 20231025065316.56817-11-philmd@linaro.org
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>
23
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
24
Message-id: 20201024170127.3592182-8-f4bug@amsat.org
25
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
26
---
10
---
27
hw/arm/raspi.c | 13 +++++++++++++
11
include/hw/arm/xlnx-zynqmp.h | 1 -
28
1 file changed, 13 insertions(+)
12
hw/arm/xlnx-zcu102.c | 1 +
13
2 files changed, 1 insertion(+), 1 deletion(-)
29
14
30
diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c
15
diff --git a/include/hw/arm/xlnx-zynqmp.h b/include/hw/arm/xlnx-zynqmp.h
31
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
32
--- a/hw/arm/raspi.c
17
--- a/include/hw/arm/xlnx-zynqmp.h
33
+++ b/hw/arm/raspi.c
18
+++ b/include/hw/arm/xlnx-zynqmp.h
34
@@ -XXX,XX +XXX,XX @@ static void raspi_machine_class_common_init(MachineClass *mc,
19
@@ -XXX,XX +XXX,XX @@
35
mc->default_ram_id = "ram";
20
#ifndef XLNX_ZYNQMP_H
36
};
21
#define XLNX_ZYNQMP_H
37
22
38
+static void raspi1ap_machine_class_init(ObjectClass *oc, void *data)
23
-#include "hw/arm/boot.h"
39
+{
24
#include "hw/intc/arm_gic.h"
40
+ MachineClass *mc = MACHINE_CLASS(oc);
25
#include "hw/net/cadence_gem.h"
41
+ RaspiMachineClass *rmc = RASPI_MACHINE_CLASS(oc);
26
#include "hw/char/cadence_uart.h"
42
+
27
diff --git a/hw/arm/xlnx-zcu102.c b/hw/arm/xlnx-zcu102.c
43
+ rmc->board_rev = 0x900021; /* Revision 1.1 */
28
index XXXXXXX..XXXXXXX 100644
44
+ raspi_machine_class_common_init(mc, rmc->board_rev);
29
--- a/hw/arm/xlnx-zcu102.c
45
+};
30
+++ b/hw/arm/xlnx-zcu102.c
46
+
31
@@ -XXX,XX +XXX,XX @@
47
static void raspi2b_machine_class_init(ObjectClass *oc, void *data)
32
#include "qemu/osdep.h"
48
{
33
#include "qapi/error.h"
49
MachineClass *mc = MACHINE_CLASS(oc);
34
#include "hw/arm/xlnx-zynqmp.h"
50
@@ -XXX,XX +XXX,XX @@ static void raspi3b_machine_class_init(ObjectClass *oc, void *data)
35
+#include "hw/arm/boot.h"
51
36
#include "hw/boards.h"
52
static const TypeInfo raspi_machine_types[] = {
37
#include "qemu/error-report.h"
53
{
38
#include "qemu/log.h"
54
+ .name = MACHINE_TYPE_NAME("raspi1ap"),
55
+ .parent = TYPE_RASPI_MACHINE,
56
+ .class_init = raspi1ap_machine_class_init,
57
+ }, {
58
.name = MACHINE_TYPE_NAME("raspi2b"),
59
.parent = TYPE_RASPI_MACHINE,
60
.class_init = raspi2b_machine_class_init,
61
--
39
--
62
2.20.1
40
2.34.1
63
41
64
42
diff view generated by jsdifflib
1
From: Luc Michel <luc@lmichel.fr>
1
From: Philippe Mathieu-Daudé <philmd@linaro.org>
2
2
3
A clock mux can be configured to select one of its 10 sources through
3
sysbus_mmio_map() and sysbus_connect_irq() should not be
4
the CM_CTL register. It also embeds yet another clock divider, composed
4
called on unrealized device.
5
of an integer part and a fractional part. The number of bits of each
6
part is mux dependent.
7
5
8
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
6
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
9
Signed-off-by: Luc Michel <luc@lmichel.fr>
7
Reviewed-by: Thomas Huth <thuth@redhat.com>
10
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
8
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
11
Tested-by: Guenter Roeck <linux@roeck-us.net>
9
Message-id: 20231020130331.50048-2-philmd@linaro.org
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
---
11
---
14
hw/misc/bcm2835_cprman.c | 53 +++++++++++++++++++++++++++++++++++++++-
12
hw/sd/pxa2xx_mmci.c | 2 +-
15
1 file changed, 52 insertions(+), 1 deletion(-)
13
1 file changed, 1 insertion(+), 1 deletion(-)
16
14
17
diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c
15
diff --git a/hw/sd/pxa2xx_mmci.c b/hw/sd/pxa2xx_mmci.c
18
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
19
--- a/hw/misc/bcm2835_cprman.c
17
--- a/hw/sd/pxa2xx_mmci.c
20
+++ b/hw/misc/bcm2835_cprman.c
18
+++ b/hw/sd/pxa2xx_mmci.c
21
@@ -XXX,XX +XXX,XX @@ static const TypeInfo cprman_pll_channel_info = {
19
@@ -XXX,XX +XXX,XX @@ PXA2xxMMCIState *pxa2xx_mmci_init(MemoryRegion *sysmem,
22
20
23
/* clock mux */
21
dev = qdev_new(TYPE_PXA2XX_MMCI);
24
22
sbd = SYS_BUS_DEVICE(dev);
25
+static bool clock_mux_is_enabled(CprmanClockMuxState *mux)
23
+ sysbus_realize_and_unref(sbd, &error_fatal);
26
+{
24
sysbus_mmio_map(sbd, 0, base);
27
+ return FIELD_EX32(*mux->reg_ctl, CM_CLOCKx_CTL, ENABLE);
25
sysbus_connect_irq(sbd, 0, irq);
28
+}
26
qdev_connect_gpio_out_named(dev, "rx-dma", 0, rx_dma);
29
+
27
qdev_connect_gpio_out_named(dev, "tx-dma", 0, tx_dma);
30
static void clock_mux_update(CprmanClockMuxState *mux)
28
- sysbus_realize_and_unref(sbd, &error_fatal);
31
{
29
32
- clock_update(mux->out, 0);
30
return PXA2XX_MMCI(dev);
33
+ uint64_t freq;
34
+ uint32_t div, src = FIELD_EX32(*mux->reg_ctl, CM_CLOCKx_CTL, SRC);
35
+ bool enabled = clock_mux_is_enabled(mux);
36
+
37
+ *mux->reg_ctl = FIELD_DP32(*mux->reg_ctl, CM_CLOCKx_CTL, BUSY, enabled);
38
+
39
+ if (!enabled) {
40
+ clock_update(mux->out, 0);
41
+ return;
42
+ }
43
+
44
+ freq = clock_get_hz(mux->srcs[src]);
45
+
46
+ if (mux->int_bits == 0 && mux->frac_bits == 0) {
47
+ clock_update_hz(mux->out, freq);
48
+ return;
49
+ }
50
+
51
+ /*
52
+ * The divider has an integer and a fractional part. The size of each part
53
+ * varies with the muxes (int_bits and frac_bits). Both parts are
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);
66
+
67
+ if (!div) {
68
+ clock_update(mux->out, 0);
69
+ return;
70
+ }
71
+
72
+ freq = muldiv64(freq, 1 << mux->frac_bits, div);
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;
85
+ }
86
87
clock_mux_update(s);
88
}
31
}
89
--
32
--
90
2.20.1
33
2.34.1
91
34
92
35
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Philippe Mathieu-Daudé <philmd@linaro.org>
2
2
3
This is generic support, with the code disabled for all targets.
3
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
4
4
Reviewed-by: Thomas Huth <thuth@redhat.com>
5
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
5
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
6
Message-id: 20201021173749.111103-11-richard.henderson@linaro.org
6
Message-id: 20231020130331.50048-3-philmd@linaro.org
7
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
---
8
---
10
linux-user/qemu.h | 4 ++
9
hw/sd/pxa2xx_mmci.c | 7 +------
11
linux-user/elfload.c | 157 +++++++++++++++++++++++++++++++++++++++++++
10
1 file changed, 1 insertion(+), 6 deletions(-)
12
2 files changed, 161 insertions(+)
13
11
14
diff --git a/linux-user/qemu.h b/linux-user/qemu.h
12
diff --git a/hw/sd/pxa2xx_mmci.c b/hw/sd/pxa2xx_mmci.c
15
index XXXXXXX..XXXXXXX 100644
13
index XXXXXXX..XXXXXXX 100644
16
--- a/linux-user/qemu.h
14
--- a/hw/sd/pxa2xx_mmci.c
17
+++ b/linux-user/qemu.h
15
+++ b/hw/sd/pxa2xx_mmci.c
18
@@ -XXX,XX +XXX,XX @@ struct image_info {
16
@@ -XXX,XX +XXX,XX @@ PXA2xxMMCIState *pxa2xx_mmci_init(MemoryRegion *sysmem,
19
abi_ulong interpreter_loadmap_addr;
17
qemu_irq irq, qemu_irq rx_dma, qemu_irq tx_dma)
20
abi_ulong interpreter_pt_dynamic_addr;
21
struct image_info *other_info;
22
+
23
+ /* For target-specific processing of NT_GNU_PROPERTY_TYPE_0. */
24
+ uint32_t note_flags;
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
47
{
18
{
48
unsigned int a_info; /* Use macros N_MAGIC, etc for access */
19
DeviceState *dev;
49
@@ -XXX,XX +XXX,XX @@ void probe_guest_base(const char *image_name, abi_ulong guest_loaddr,
20
- SysBusDevice *sbd;
50
"@ 0x%" PRIx64 "\n", (uint64_t)guest_base);
21
51
}
22
- dev = qdev_new(TYPE_PXA2XX_MMCI);
52
23
- sbd = SYS_BUS_DEVICE(dev);
53
+enum {
24
- sysbus_realize_and_unref(sbd, &error_fatal);
54
+ /* The string "GNU\0" as a magic number. */
25
- sysbus_mmio_map(sbd, 0, base);
55
+ GNU0_MAGIC = const_le32('G' | 'N' << 8 | 'U' << 16),
26
- sysbus_connect_irq(sbd, 0, irq);
56
+ NOTE_DATA_SZ = 1 * KiB,
27
+ dev = sysbus_create_simple(TYPE_PXA2XX_MMCI, base, irq);
57
+ NOTE_NAME_SZ = 4,
28
qdev_connect_gpio_out_named(dev, "rx-dma", 0, rx_dma);
58
+ ELF_GNU_PROPERTY_ALIGN = ELF_CLASS == ELFCLASS32 ? 4 : 8,
29
qdev_connect_gpio_out_named(dev, "tx-dma", 0, tx_dma);
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)
68
+{
69
+ uint32_t pr_type, pr_datasz, step;
70
+
71
+ if (*off > datasz || !QEMU_IS_ALIGNED(*off, ELF_GNU_PROPERTY_ALIGN)) {
72
+ goto error_data;
73
+ }
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;
110
+}
111
+
112
+/* Process NT_GNU_PROPERTY_TYPE_0. */
113
+static bool parse_elf_properties(int image_fd,
114
+ struct image_info *info,
115
+ const struct elf_phdr *phdr,
116
+ char bprm_buf[BPRM_BUF_SIZE],
117
+ Error **errp)
118
+{
119
+ union {
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
+ }
195
+}
196
+
197
/* Load an ELF image into the address space.
198
199
IMAGE_NAME is the filename of the image, to use in error messages.
200
@@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd,
201
goto exit_errmsg;
202
}
203
*pinterp_name = g_steal_pointer(&interp_name);
204
+ } else if (eppnt->p_type == PT_GNU_PROPERTY) {
205
+ if (!parse_elf_properties(image_fd, info, eppnt, bprm_buf, &err)) {
206
+ goto exit_errmsg;
207
+ }
208
}
209
}
210
30
211
--
31
--
212
2.20.1
32
2.34.1
213
33
214
34
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
1
From: Philippe Mathieu-Daudé <philmd@linaro.org>
2
2
3
Reviewed-by: Luc Michel <luc.michel@greensocs.com>
3
sysbus_mmio_map() should not be called on unrealized device.
4
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
4
5
Message-id: 20201024170127.3592182-7-f4bug@amsat.org
5
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
6
Reviewed-by: Thomas Huth <thuth@redhat.com>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Message-id: 20231020130331.50048-4-philmd@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/bcm2836.h | 1 +
11
hw/pcmcia/pxa2xx.c | 7 ++-----
9
hw/arm/bcm2836.c | 34 ++++++++++++++++++++++++++++++++++
12
1 file changed, 2 insertions(+), 5 deletions(-)
10
hw/arm/raspi.c | 2 ++
11
3 files changed, 37 insertions(+)
12
13
13
diff --git a/include/hw/arm/bcm2836.h b/include/hw/arm/bcm2836.h
14
diff --git a/hw/pcmcia/pxa2xx.c b/hw/pcmcia/pxa2xx.c
14
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
15
--- a/include/hw/arm/bcm2836.h
16
--- a/hw/pcmcia/pxa2xx.c
16
+++ b/include/hw/arm/bcm2836.h
17
+++ b/hw/pcmcia/pxa2xx.c
17
@@ -XXX,XX +XXX,XX @@ OBJECT_DECLARE_TYPE(BCM283XState, BCM283XClass, BCM283X)
18
@@ -XXX,XX +XXX,XX @@ PXA2xxPCMCIAState *pxa2xx_pcmcia_init(MemoryRegion *sysmem,
18
* them, code using these devices should always handle them via the
19
hwaddr base)
19
* BCM283x base class, so they have no BCM2836(obj) etc macros.
20
{
20
*/
21
DeviceState *dev;
21
+#define TYPE_BCM2835 "bcm2835"
22
- PXA2xxPCMCIAState *s;
22
#define TYPE_BCM2836 "bcm2836"
23
23
#define TYPE_BCM2837 "bcm2837"
24
dev = qdev_new(TYPE_PXA2XX_PCMCIA);
24
25
- sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base);
25
diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c
26
- s = PXA2XX_PCMCIA(dev);
26
index XXXXXXX..XXXXXXX 100644
27
-
27
--- a/hw/arm/bcm2836.c
28
sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
28
+++ b/hw/arm/bcm2836.c
29
+ sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base);
29
@@ -XXX,XX +XXX,XX @@ static bool bcm283x_common_realize(DeviceState *dev, Error **errp)
30
30
return true;
31
- return s;
32
+ return PXA2XX_PCMCIA(dev);
31
}
33
}
32
34
33
+static void bcm2835_realize(DeviceState *dev, Error **errp)
35
static void pxa2xx_pcmcia_initfn(Object *obj)
34
+{
35
+ BCM283XState *s = BCM283X(dev);
36
+
37
+ if (!bcm283x_common_realize(dev, errp)) {
38
+ return;
39
+ }
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));
50
+}
51
+
52
static void bcm2836_realize(DeviceState *dev, Error **errp)
53
{
54
BCM283XState *s = BCM283X(dev);
55
@@ -XXX,XX +XXX,XX @@ static void bcm283x_class_init(ObjectClass *oc, void *data)
56
dc->user_creatable = false;
57
}
58
59
+static void bcm2835_class_init(ObjectClass *oc, void *data)
60
+{
61
+ DeviceClass *dc = DEVICE_CLASS(oc);
62
+ BCM283XClass *bc = BCM283X_CLASS(oc);
63
+
64
+ bc->cpu_type = ARM_CPU_TYPE_NAME("arm1176");
65
+ bc->core_count = 1;
66
+ bc->peri_base = 0x20000000;
67
+ dc->realize = bcm2835_realize;
68
+};
69
+
70
static void bcm2836_class_init(ObjectClass *oc, void *data)
71
{
72
DeviceClass *dc = DEVICE_CLASS(oc);
73
@@ -XXX,XX +XXX,XX @@ static void bcm2837_class_init(ObjectClass *oc, void *data)
74
75
static const TypeInfo bcm283x_types[] = {
76
{
77
+ .name = TYPE_BCM2835,
78
+ .parent = TYPE_BCM283X,
79
+ .class_init = bcm2835_class_init,
80
+ }, {
81
.name = TYPE_BCM2836,
82
.parent = TYPE_BCM283X,
83
.class_init = bcm2836_class_init,
84
diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c
85
index XXXXXXX..XXXXXXX 100644
86
--- a/hw/arm/raspi.c
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},
103
};
104
--
36
--
105
2.20.1
37
2.34.1
106
38
107
39
diff view generated by jsdifflib
1
From: Havard Skinnemoen <hskinnemoen@google.com>
1
From: Philippe Mathieu-Daudé <philmd@linaro.org>
2
2
3
This allows us to reuse npcm7xx_timer_pause for the watchdog timer.
3
Reviewed-by: Thomas Huth <thuth@redhat.com>
4
4
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
5
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
5
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
6
Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
6
Message-id: 20231020130331.50048-5-philmd@linaro.org
7
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
---
8
---
9
hw/timer/npcm7xx_timer.c | 6 +++---
9
hw/pcmcia/pxa2xx.c | 4 +---
10
1 file changed, 3 insertions(+), 3 deletions(-)
10
1 file changed, 1 insertion(+), 3 deletions(-)
11
11
12
diff --git a/hw/timer/npcm7xx_timer.c b/hw/timer/npcm7xx_timer.c
12
diff --git a/hw/pcmcia/pxa2xx.c b/hw/pcmcia/pxa2xx.c
13
index XXXXXXX..XXXXXXX 100644
13
index XXXXXXX..XXXXXXX 100644
14
--- a/hw/timer/npcm7xx_timer.c
14
--- a/hw/pcmcia/pxa2xx.c
15
+++ b/hw/timer/npcm7xx_timer.c
15
+++ b/hw/pcmcia/pxa2xx.c
16
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_pause(NPCM7xxTimer *t)
16
@@ -XXX,XX +XXX,XX @@ PXA2xxPCMCIAState *pxa2xx_pcmcia_init(MemoryRegion *sysmem,
17
timer_del(&t->qtimer);
17
{
18
now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
18
DeviceState *dev;
19
t->remaining_ns = t->expires_ns - now;
19
20
- if (t->remaining_ns <= 0) {
20
- dev = qdev_new(TYPE_PXA2XX_PCMCIA);
21
- npcm7xx_timer_reached_zero(t);
21
- sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
22
- }
22
- sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base);
23
}
23
+ dev = sysbus_create_simple(TYPE_PXA2XX_PCMCIA, base, NULL);
24
24
25
/*
25
return PXA2XX_PCMCIA(dev);
26
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_write_tcsr(NPCM7xxTimer *t, uint32_t new_tcsr)
27
} else {
28
t->tcsr &= ~NPCM7XX_TCSR_CACT;
29
npcm7xx_timer_pause(t);
30
+ if (t->remaining_ns <= 0) {
31
+ npcm7xx_timer_reached_zero(t);
32
+ }
33
}
34
}
35
}
26
}
36
--
27
--
37
2.20.1
28
2.34.1
38
29
39
30
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
1
From: Philippe Mathieu-Daudé <philmd@linaro.org>
2
2
3
The realize() function is clearly composed of two parts,
3
Reviewed-by: Thomas Huth <thuth@redhat.com>
4
each described by a comment:
4
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
5
5
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
6
void realize()
6
Message-id: 20231020130331.50048-6-philmd@linaro.org
7
{
8
/* common peripherals from bcm2835 */
9
...
10
/* bcm2836 interrupt controller (and mailboxes, etc.) */
11
...
12
}
13
14
Split the two part, so we can reuse the common part with other
15
SoCs from this family.
16
17
Reviewed-by: Luc Michel <luc.michel@greensocs.com>
18
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
19
Message-id: 20201024170127.3592182-6-f4bug@amsat.org
20
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
21
---
8
---
22
hw/arm/bcm2836.c | 22 ++++++++++++++++++----
9
include/hw/arm/pxa.h | 2 --
23
1 file changed, 18 insertions(+), 4 deletions(-)
10
hw/arm/pxa2xx.c | 12 ++++++++----
11
hw/pcmcia/pxa2xx.c | 10 ----------
12
3 files changed, 8 insertions(+), 16 deletions(-)
24
13
25
diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c
14
diff --git a/include/hw/arm/pxa.h b/include/hw/arm/pxa.h
26
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
27
--- a/hw/arm/bcm2836.c
16
--- a/include/hw/arm/pxa.h
28
+++ b/hw/arm/bcm2836.c
17
+++ b/include/hw/arm/pxa.h
29
@@ -XXX,XX +XXX,XX @@ static void bcm2836_init(Object *obj)
18
@@ -XXX,XX +XXX,XX @@ void pxa2xx_mmci_handlers(PXA2xxMMCIState *s, qemu_irq readonly,
30
qdev_prop_set_uint32(DEVICE(obj), "enabled-cpus", bc->core_count);
19
#define TYPE_PXA2XX_PCMCIA "pxa2xx-pcmcia"
20
OBJECT_DECLARE_SIMPLE_TYPE(PXA2xxPCMCIAState, PXA2XX_PCMCIA)
21
22
-PXA2xxPCMCIAState *pxa2xx_pcmcia_init(MemoryRegion *sysmem,
23
- hwaddr base);
24
int pxa2xx_pcmcia_attach(void *opaque, PCMCIACardState *card);
25
int pxa2xx_pcmcia_detach(void *opaque);
26
void pxa2xx_pcmcia_set_irq_cb(void *opaque, qemu_irq irq, qemu_irq cd_irq);
27
diff --git a/hw/arm/pxa2xx.c b/hw/arm/pxa2xx.c
28
index XXXXXXX..XXXXXXX 100644
29
--- a/hw/arm/pxa2xx.c
30
+++ b/hw/arm/pxa2xx.c
31
@@ -XXX,XX +XXX,XX @@ PXA2xxState *pxa270_init(unsigned int sdram_size, const char *cpu_type)
32
sysbus_create_simple("sysbus-ohci", 0x4c000000,
33
qdev_get_gpio_in(s->pic, PXA2XX_PIC_USBH1));
34
35
- s->pcmcia[0] = pxa2xx_pcmcia_init(address_space, 0x20000000);
36
- s->pcmcia[1] = pxa2xx_pcmcia_init(address_space, 0x30000000);
37
+ s->pcmcia[0] = PXA2XX_PCMCIA(sysbus_create_simple(TYPE_PXA2XX_PCMCIA,
38
+ 0x20000000, NULL));
39
+ s->pcmcia[1] = PXA2XX_PCMCIA(sysbus_create_simple(TYPE_PXA2XX_PCMCIA,
40
+ 0x30000000, NULL));
41
42
sysbus_create_simple(TYPE_PXA2XX_RTC, 0x40900000,
43
qdev_get_gpio_in(s->pic, PXA2XX_PIC_RTCALARM));
44
@@ -XXX,XX +XXX,XX @@ PXA2xxState *pxa255_init(unsigned int sdram_size)
45
s->ssp[i] = (SSIBus *)qdev_get_child_bus(dev, "ssi");
31
}
46
}
32
47
33
- object_initialize_child(obj, "control", &s->control, TYPE_BCM2836_CONTROL);
48
- s->pcmcia[0] = pxa2xx_pcmcia_init(address_space, 0x20000000);
34
+ if (bc->ctrl_base) {
49
- s->pcmcia[1] = pxa2xx_pcmcia_init(address_space, 0x30000000);
35
+ object_initialize_child(obj, "control", &s->control,
50
+ s->pcmcia[0] = PXA2XX_PCMCIA(sysbus_create_simple(TYPE_PXA2XX_PCMCIA,
36
+ TYPE_BCM2836_CONTROL);
51
+ 0x20000000, NULL));
37
+ }
52
+ s->pcmcia[1] = PXA2XX_PCMCIA(sysbus_create_simple(TYPE_PXA2XX_PCMCIA,
38
53
+ 0x30000000, NULL));
39
object_initialize_child(obj, "peripherals", &s->peripherals,
54
40
TYPE_BCM2835_PERIPHERALS);
55
sysbus_create_simple(TYPE_PXA2XX_RTC, 0x40900000,
41
@@ -XXX,XX +XXX,XX @@ static void bcm2836_init(Object *obj)
56
qdev_get_gpio_in(s->pic, PXA2XX_PIC_RTCALARM));
42
"vcram-size");
57
diff --git a/hw/pcmcia/pxa2xx.c b/hw/pcmcia/pxa2xx.c
58
index XXXXXXX..XXXXXXX 100644
59
--- a/hw/pcmcia/pxa2xx.c
60
+++ b/hw/pcmcia/pxa2xx.c
61
@@ -XXX,XX +XXX,XX @@ static void pxa2xx_pcmcia_set_irq(void *opaque, int line, int level)
62
qemu_set_irq(s->irq, level);
43
}
63
}
44
64
45
-static void bcm2836_realize(DeviceState *dev, Error **errp)
65
-PXA2xxPCMCIAState *pxa2xx_pcmcia_init(MemoryRegion *sysmem,
46
+static bool bcm283x_common_realize(DeviceState *dev, Error **errp)
66
- hwaddr base)
67
-{
68
- DeviceState *dev;
69
-
70
- dev = sysbus_create_simple(TYPE_PXA2XX_PCMCIA, base, NULL);
71
-
72
- return PXA2XX_PCMCIA(dev);
73
-}
74
-
75
static void pxa2xx_pcmcia_initfn(Object *obj)
47
{
76
{
48
BCM283XState *s = BCM283X(dev);
77
SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
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;
61
}
62
63
object_property_add_alias(OBJECT(s), "sd-bus", OBJECT(&s->peripherals),
64
@@ -XXX,XX +XXX,XX @@ static void bcm2836_realize(DeviceState *dev, Error **errp)
65
66
sysbus_mmio_map_overlap(SYS_BUS_DEVICE(&s->peripherals), 0,
67
bc->peri_base, 1);
68
+ return true;
69
+}
70
+
71
+static void bcm2836_realize(DeviceState *dev, Error **errp)
72
+{
73
+ BCM283XState *s = BCM283X(dev);
74
+ BCM283XClass *bc = BCM283X_GET_CLASS(dev);
75
+ int n;
76
+
77
+ if (!bcm283x_common_realize(dev, errp)) {
78
+ return;
79
+ }
80
81
/* bcm2836 interrupt controller (and mailboxes, etc.) */
82
if (!sysbus_realize(SYS_BUS_DEVICE(&s->control), errp)) {
83
--
78
--
84
2.20.1
79
2.34.1
85
80
86
81
diff view generated by jsdifflib
1
From: Luc Michel <luc@lmichel.fr>
1
From: Philippe Mathieu-Daudé <philmd@linaro.org>
2
2
3
There are 5 PLLs in the CPRMAN, namely PLL A, C, D, H and B. All of them
3
Factor reset code out of the DeviceRealize() handler.
4
take the xosc clock as input and produce a new clock.
5
4
6
This commit adds a skeleton implementation for the PLLs as sub-devices
5
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
7
of the CPRMAN. The PLLs are instantiated and connected internally to the
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
main oscillator.
7
Reviewed-by: Thomas Huth <thuth@redhat.com>
9
8
Message-id: 20231020130331.50048-7-philmd@linaro.org
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>
20
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
21
---
10
---
22
include/hw/misc/bcm2835_cprman.h | 29 +++++
11
hw/arm/pxa2xx_pic.c | 17 ++++++++++++-----
23
include/hw/misc/bcm2835_cprman_internals.h | 144 +++++++++++++++++++++
12
1 file changed, 12 insertions(+), 5 deletions(-)
24
hw/misc/bcm2835_cprman.c | 108 ++++++++++++++++
25
3 files changed, 281 insertions(+)
26
13
27
diff --git a/include/hw/misc/bcm2835_cprman.h b/include/hw/misc/bcm2835_cprman.h
14
diff --git a/hw/arm/pxa2xx_pic.c b/hw/arm/pxa2xx_pic.c
28
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
29
--- a/include/hw/misc/bcm2835_cprman.h
16
--- a/hw/arm/pxa2xx_pic.c
30
+++ b/include/hw/misc/bcm2835_cprman.h
17
+++ b/hw/arm/pxa2xx_pic.c
31
@@ -XXX,XX +XXX,XX @@ DECLARE_INSTANCE_CHECKER(BCM2835CprmanState, CPRMAN,
18
@@ -XXX,XX +XXX,XX @@ static int pxa2xx_pic_post_load(void *opaque, int version_id)
32
19
return 0;
33
#define CPRMAN_NUM_REGS (0x2000 / sizeof(uint32_t))
20
}
34
21
35
+typedef enum CprmanPll {
22
-DeviceState *pxa2xx_pic_init(hwaddr base, ARMCPU *cpu)
36
+ CPRMAN_PLLA = 0,
23
+static void pxa2xx_pic_reset_hold(Object *obj)
37
+ CPRMAN_PLLC,
24
{
38
+ CPRMAN_PLLD,
25
- DeviceState *dev = qdev_new(TYPE_PXA2XX_PIC);
39
+ CPRMAN_PLLH,
26
- PXA2xxPICState *s = PXA2XX_PIC(dev);
40
+ CPRMAN_PLLB,
27
-
41
+
28
- s->cpu = cpu;
42
+ CPRMAN_NUM_PLL
29
+ PXA2xxPICState *s = PXA2XX_PIC(obj);
43
+} CprmanPll;
30
44
+
31
s->int_pending[0] = 0;
45
+typedef struct CprmanPllState {
32
s->int_pending[1] = 0;
46
+ /*< private >*/
33
@@ -XXX,XX +XXX,XX @@ DeviceState *pxa2xx_pic_init(hwaddr base, ARMCPU *cpu)
47
+ DeviceState parent_obj;
34
s->int_enabled[1] = 0;
48
+
35
s->is_fiq[0] = 0;
49
+ /*< public >*/
36
s->is_fiq[1] = 0;
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
78
@@ -XXX,XX +XXX,XX @@
79
#include "hw/registerfields.h"
80
#include "hw/misc/bcm2835_cprman.h"
81
82
+#define TYPE_CPRMAN_PLL "bcm2835-cprman-pll"
83
+
84
+DECLARE_INSTANCE_CHECKER(CprmanPllState, CPRMAN_PLL,
85
+ TYPE_CPRMAN_PLL)
86
+
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
+}
37
+}
234
+
38
+
235
#endif
39
+DeviceState *pxa2xx_pic_init(hwaddr base, ARMCPU *cpu)
236
diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c
40
+{
237
index XXXXXXX..XXXXXXX 100644
41
+ DeviceState *dev = qdev_new(TYPE_PXA2XX_PIC);
238
--- a/hw/misc/bcm2835_cprman.c
42
+ PXA2xxPICState *s = PXA2XX_PIC(dev);
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
+
43
+
246
+static void pll_update(CprmanPllState *pll)
44
+ s->cpu = cpu;
247
+{
45
248
+ clock_update(pll->out, 0);
46
sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
249
+}
47
250
+
48
@@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_pxa2xx_pic_regs = {
251
+static void pll_xosc_update(void *opaque)
49
static void pxa2xx_pic_class_init(ObjectClass *klass, void *data)
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;
295
}
296
297
+#define CASE_PLL_REGS(pll_) \
298
+ case R_CM_ ## pll_: \
299
+ case R_A2W_ ## pll_ ## _CTRL: \
300
+ case R_A2W_ ## pll_ ## _ANA0: \
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)
308
{
309
@@ -XXX,XX +XXX,XX @@ static void cprman_write(void *opaque, hwaddr offset,
310
trace_bcm2835_cprman_write(offset, value);
311
s->regs[idx] = value;
312
313
+ switch (idx) {
314
+ CASE_PLL_REGS(PLLA) :
315
+ pll_update(&s->plls[CPRMAN_PLLA]);
316
+ break;
317
+
318
+ CASE_PLL_REGS(PLLC) :
319
+ pll_update(&s->plls[CPRMAN_PLLC]);
320
+ break;
321
+
322
+ CASE_PLL_REGS(PLLD) :
323
+ pll_update(&s->plls[CPRMAN_PLLD]);
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
+ }
334
}
335
336
+#undef CASE_PLL_REGS
337
+
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);
354
}
355
356
static void cprman_init(Object *obj)
357
{
358
BCM2835CprmanState *s = CPRMAN(obj);
359
+ size_t i;
360
+
361
+ for (i = 0; i < CPRMAN_NUM_PLL; i++) {
362
+ object_initialize_child(obj, PLL_INIT_INFO[i].name,
363
+ &s->plls[i], TYPE_CPRMAN_PLL);
364
+ set_pll_init_info(s, &s->plls[i], i);
365
+ }
366
367
s->xosc = clock_new(obj, "xosc");
368
369
@@ -XXX,XX +XXX,XX @@ static void cprman_init(Object *obj)
370
sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->iomem);
371
}
372
373
+static void cprman_realize(DeviceState *dev, Error **errp)
374
+{
375
+ BCM2835CprmanState *s = CPRMAN(dev);
376
+ size_t i;
377
+
378
+ for (i = 0; i < CPRMAN_NUM_PLL; i++) {
379
+ CprmanPllState *pll = &s->plls[i];
380
+
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)
393
{
50
{
394
DeviceClass *dc = DEVICE_CLASS(klass);
51
DeviceClass *dc = DEVICE_CLASS(klass);
395
52
+ ResettableClass *rc = RESETTABLE_CLASS(klass);
396
+ dc->realize = cprman_realize;
53
397
dc->reset = cprman_reset;
54
dc->desc = "PXA2xx PIC";
398
dc->vmsd = &cprman_vmstate;
55
dc->vmsd = &vmstate_pxa2xx_pic_regs;
399
device_class_set_props(dc, cprman_properties);
56
+ rc->phases.hold = pxa2xx_pic_reset_hold;
400
@@ -XXX,XX +XXX,XX @@ static const TypeInfo cprman_info = {
401
static void cprman_register_types(void)
402
{
403
type_register_static(&cprman_info);
404
+ type_register_static(&cprman_pll_info);
405
}
57
}
406
58
407
type_init(cprman_register_types);
59
static const TypeInfo pxa2xx_pic_info = {
408
--
60
--
409
2.20.1
61
2.34.1
410
62
411
63
diff view generated by jsdifflib
1
From: Havard Skinnemoen <hskinnemoen@google.com>
1
From: Philippe Mathieu-Daudé <philmd@linaro.org>
2
2
3
The NPCM730 and NPCM750 chips have a single USB host port shared between
3
QOM objects shouldn't access each other internals fields
4
a USB 2.0 EHCI host controller and a USB 1.1 OHCI host controller. This
4
except using the QOM API.
5
adds support for both of them.
6
5
7
Testing notes:
6
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
8
* With -device usb-kbd, qemu will automatically insert a full-speed
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
9
hub, and the keyboard becomes controlled by the OHCI controller.
8
Reviewed-by: Thomas Huth <thuth@redhat.com>
10
* With -device usb-kbd,bus=usb-bus.0,port=1, the keyboard is directly
9
Message-id: 20231020130331.50048-8-philmd@linaro.org
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>
23
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
24
---
11
---
25
docs/system/arm/nuvoton.rst | 2 +-
12
hw/arm/pxa2xx_pic.c | 11 ++++++++++-
26
hw/usb/hcd-ehci.h | 1 +
13
1 file changed, 10 insertions(+), 1 deletion(-)
27
include/hw/arm/npcm7xx.h | 4 ++++
28
hw/arm/npcm7xx.c | 27 +++++++++++++++++++++++++--
29
hw/usb/hcd-ehci-sysbus.c | 19 +++++++++++++++++++
30
5 files changed, 50 insertions(+), 3 deletions(-)
31
14
32
diff --git a/docs/system/arm/nuvoton.rst b/docs/system/arm/nuvoton.rst
15
diff --git a/hw/arm/pxa2xx_pic.c b/hw/arm/pxa2xx_pic.c
33
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
34
--- a/docs/system/arm/nuvoton.rst
17
--- a/hw/arm/pxa2xx_pic.c
35
+++ b/docs/system/arm/nuvoton.rst
18
+++ b/hw/arm/pxa2xx_pic.c
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
68
@@ -XXX,XX +XXX,XX @@
19
@@ -XXX,XX +XXX,XX @@
69
#include "hw/nvram/npcm7xx_otp.h"
20
#include "cpu.h"
70
#include "hw/timer/npcm7xx_timer.h"
21
#include "hw/arm/pxa.h"
71
#include "hw/ssi/npcm7xx_fiu.h"
22
#include "hw/sysbus.h"
72
+#include "hw/usb/hcd-ehci.h"
23
+#include "hw/qdev-properties.h"
73
+#include "hw/usb/hcd-ohci.h"
24
#include "migration/vmstate.h"
74
#include "target/arm/cpu.h"
25
#include "qom/object.h"
75
26
#include "target/arm/cpregs.h"
76
#define NPCM7XX_MAX_NUM_CPUS (2)
27
@@ -XXX,XX +XXX,XX @@ DeviceState *pxa2xx_pic_init(hwaddr base, ARMCPU *cpu)
77
@@ -XXX,XX +XXX,XX @@ typedef struct NPCM7xxState {
28
DeviceState *dev = qdev_new(TYPE_PXA2XX_PIC);
78
NPCM7xxOTPState fuse_array;
29
PXA2xxPICState *s = PXA2XX_PIC(dev);
79
NPCM7xxMCState mc;
30
80
NPCM7xxRNGState rng;
31
- s->cpu = cpu;
81
+ EHCISysBusState ehci;
32
+ object_property_set_link(OBJECT(dev), "arm-cpu",
82
+ OHCISysBusState ohci;
33
+ OBJECT(cpu), &error_abort);
83
NPCM7xxFIUState fiu[2];
34
84
} NPCM7xxState;
35
sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
85
36
86
diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c
37
@@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_pxa2xx_pic_regs = {
87
index XXXXXXX..XXXXXXX 100644
38
},
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)
97
+
98
/* Internal AHB SRAM */
99
#define NPCM7XX_RAM3_BA (0xc0008000)
100
#define NPCM7XX_RAM3_SZ (4 * KiB)
101
@@ -XXX,XX +XXX,XX @@ enum NPCM7xxInterrupt {
102
NPCM7XX_WDG0_IRQ = 47, /* Timer Module 0 Watchdog */
103
NPCM7XX_WDG1_IRQ, /* Timer Module 1 Watchdog */
104
NPCM7XX_WDG2_IRQ, /* Timer Module 2 Watchdog */
105
+ NPCM7XX_EHCI_IRQ = 61,
106
+ NPCM7XX_OHCI_IRQ = 62,
107
};
39
};
108
40
109
/* Total number of GIC interrupts, including internal Cortex-A9 interrupts. */
41
+static Property pxa2xx_pic_properties[] = {
110
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_init(Object *obj)
42
+ DEFINE_PROP_LINK("arm-cpu", PXA2xxPICState, cpu,
111
object_initialize_child(obj, "tim[*]", &s->tim[i], TYPE_NPCM7XX_TIMER);
43
+ TYPE_ARM_CPU, ARMCPU *),
112
}
44
+ DEFINE_PROP_END_OF_LIST(),
113
114
+ object_initialize_child(obj, "ehci", &s->ehci, TYPE_NPCM7XX_EHCI);
115
+ object_initialize_child(obj, "ohci", &s->ohci, TYPE_SYSBUS_OHCI);
116
+
117
QEMU_BUILD_BUG_ON(ARRAY_SIZE(npcm7xx_fiu) != ARRAY_SIZE(s->fiu));
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));
131
+
132
+ object_property_set_str(OBJECT(&s->ohci), "masterbus", "usb-bus.0",
133
+ &error_abort);
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));
139
+
140
/*
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
153
index XXXXXXX..XXXXXXX 100644
154
--- a/hw/usb/hcd-ehci-sysbus.c
155
+++ b/hw/usb/hcd-ehci-sysbus.c
156
@@ -XXX,XX +XXX,XX @@ static const TypeInfo ehci_aw_h3_type_info = {
157
.class_init = ehci_aw_h3_class_init,
158
};
159
160
+static void ehci_npcm7xx_class_init(ObjectClass *oc, void *data)
161
+{
162
+ SysBusEHCIClass *sec = SYS_BUS_EHCI_CLASS(oc);
163
+ DeviceClass *dc = DEVICE_CLASS(oc);
164
+
165
+ sec->capsbase = 0x0;
166
+ sec->opregbase = 0x10;
167
+ sec->portscbase = 0x44;
168
+ sec->portnr = 1;
169
+ set_bit(DEVICE_CATEGORY_USB, dc->categories);
170
+}
171
+
172
+static const TypeInfo ehci_npcm7xx_type_info = {
173
+ .name = TYPE_NPCM7XX_EHCI,
174
+ .parent = TYPE_SYS_BUS_EHCI,
175
+ .class_init = ehci_npcm7xx_class_init,
176
+};
45
+};
177
+
46
+
178
static void ehci_tegra2_class_init(ObjectClass *oc, void *data)
47
static void pxa2xx_pic_class_init(ObjectClass *klass, void *data)
179
{
48
{
180
SysBusEHCIClass *sec = SYS_BUS_EHCI_CLASS(oc);
49
DeviceClass *dc = DEVICE_CLASS(klass);
181
@@ -XXX,XX +XXX,XX @@ static void ehci_sysbus_register_types(void)
50
ResettableClass *rc = RESETTABLE_CLASS(klass);
182
type_register_static(&ehci_platform_type_info);
51
183
type_register_static(&ehci_exynos4210_type_info);
52
+ device_class_set_props(dc, pxa2xx_pic_properties);
184
type_register_static(&ehci_aw_h3_type_info);
53
dc->desc = "PXA2xx PIC";
185
+ type_register_static(&ehci_npcm7xx_type_info);
54
dc->vmsd = &vmstate_pxa2xx_pic_regs;
186
type_register_static(&ehci_tegra2_type_info);
55
rc->phases.hold = pxa2xx_pic_reset_hold;
187
type_register_static(&ehci_ppc4xx_type_info);
188
type_register_static(&ehci_fusbh200_type_info);
189
--
56
--
190
2.20.1
57
2.34.1
191
58
192
59
diff view generated by jsdifflib
1
From: Luc Michel <luc@lmichel.fr>
1
From: Philippe Mathieu-Daudé <philmd@linaro.org>
2
2
3
The CPRMAN PLLs generate a clock based on a prescaler, a multiplier and
3
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
4
a divider. The prescaler doubles the parent (xosc) frequency, then the
4
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
5
multiplier/divider are applied. The multiplier has an integer and a
5
Reviewed-by: Thomas Huth <thuth@redhat.com>
6
fractional part.
6
Message-id: 20231020130331.50048-9-philmd@linaro.org
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>
17
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
18
---
8
---
19
include/hw/misc/bcm2835_cprman_internals.h | 8 +++
9
hw/arm/pxa2xx_pic.c | 16 ++++++++++------
20
hw/misc/bcm2835_cprman.c | 64 +++++++++++++++++++++-
10
1 file changed, 10 insertions(+), 6 deletions(-)
21
2 files changed, 71 insertions(+), 1 deletion(-)
22
11
23
diff --git a/include/hw/misc/bcm2835_cprman_internals.h b/include/hw/misc/bcm2835_cprman_internals.h
12
diff --git a/hw/arm/pxa2xx_pic.c b/hw/arm/pxa2xx_pic.c
24
index XXXXXXX..XXXXXXX 100644
13
index XXXXXXX..XXXXXXX 100644
25
--- a/include/hw/misc/bcm2835_cprman_internals.h
14
--- a/hw/arm/pxa2xx_pic.c
26
+++ b/include/hw/misc/bcm2835_cprman_internals.h
15
+++ b/hw/arm/pxa2xx_pic.c
27
@@ -XXX,XX +XXX,XX @@ REG32(A2W_PLLD_FRAC, 0x1240)
16
@@ -XXX,XX +XXX,XX @@ static void pxa2xx_pic_reset_hold(Object *obj)
28
REG32(A2W_PLLH_FRAC, 0x1260)
17
DeviceState *pxa2xx_pic_init(hwaddr base, ARMCPU *cpu)
29
REG32(A2W_PLLB_FRAC, 0x12e0)
18
{
30
19
DeviceState *dev = qdev_new(TYPE_PXA2XX_PIC);
31
+/* misc registers */
20
- PXA2xxPICState *s = PXA2XX_PIC(dev);
32
+REG32(CM_LOCK, 0x114)
21
33
+ FIELD(CM_LOCK, FLOCKH, 12, 1)
22
object_property_set_link(OBJECT(dev), "arm-cpu",
34
+ FIELD(CM_LOCK, FLOCKD, 11, 1)
23
OBJECT(cpu), &error_abort);
35
+ FIELD(CM_LOCK, FLOCKC, 10, 1)
24
-
36
+ FIELD(CM_LOCK, FLOCKB, 9, 1)
25
sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
37
+ FIELD(CM_LOCK, FLOCKA, 8, 1)
26
+ sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base);
38
+
27
+
39
/*
28
+ return dev;
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)
51
+{
52
+ return !FIELD_EX32(*pll->reg_a2w_ctrl, A2W_PLLx_CTRL, PWRDN)
53
+ && !FIELD_EX32(*pll->reg_cm, CM_PLLx, ANARST);
54
+}
29
+}
55
+
30
+
56
static void pll_update(CprmanPllState *pll)
31
+static void pxa2xx_pic_realize(DeviceState *dev, Error **errp)
57
{
32
+{
58
- clock_update(pll->out, 0);
33
+ PXA2xxPICState *s = PXA2XX_PIC(dev);
59
+ uint64_t freq, ndiv, fdiv, pdiv;
34
60
+
35
qdev_init_gpio_in(dev, pxa2xx_pic_set_irq, PXA2XX_PIC_SRCS);
61
+ if (!pll_is_locked(pll)) {
36
62
+ clock_update(pll->out, 0);
37
@@ -XXX,XX +XXX,XX @@ DeviceState *pxa2xx_pic_init(hwaddr base, ARMCPU *cpu)
63
+ return;
38
memory_region_init_io(&s->iomem, OBJECT(s), &pxa2xx_pic_ops, s,
64
+ }
39
"pxa2xx-pic", 0x00100000);
65
+
40
sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->iomem);
66
+ pdiv = FIELD_EX32(*pll->reg_a2w_ctrl, A2W_PLLx_CTRL, PDIV);
41
- sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base);
67
+
42
68
+ if (!pdiv) {
43
/* Enable IC coprocessor access. */
69
+ clock_update(pll->out, 0);
44
- define_arm_cp_regs_with_opaque(cpu, pxa_pic_cp_reginfo, s);
70
+ return;
45
-
71
+ }
46
- return dev;
72
+
47
+ define_arm_cp_regs_with_opaque(s->cpu, pxa_pic_cp_reginfo, s);
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);
92
}
48
}
93
49
94
static void pll_xosc_update(void *opaque)
50
static const VMStateDescription vmstate_pxa2xx_pic_regs = {
95
@@ -XXX,XX +XXX,XX @@ static const TypeInfo cprman_pll_info = {
51
@@ -XXX,XX +XXX,XX @@ static void pxa2xx_pic_class_init(ObjectClass *klass, void *data)
96
52
ResettableClass *rc = RESETTABLE_CLASS(klass);
97
/* CPRMAN "top level" model */
53
98
54
device_class_set_props(dc, pxa2xx_pic_properties);
99
+static uint32_t get_cm_lock(const BCM2835CprmanState *s)
55
+ dc->realize = pxa2xx_pic_realize;
100
+{
56
dc->desc = "PXA2xx PIC";
101
+ static const int CM_LOCK_MAPPING[CPRMAN_NUM_PLL] = {
57
dc->vmsd = &vmstate_pxa2xx_pic_regs;
102
+ [CPRMAN_PLLA] = R_CM_LOCK_FLOCKA_SHIFT,
58
rc->phases.hold = pxa2xx_pic_reset_hold;
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;
117
+}
118
+
119
static uint64_t cprman_read(void *opaque, hwaddr offset,
120
unsigned size)
121
{
122
@@ -XXX,XX +XXX,XX @@ static uint64_t cprman_read(void *opaque, hwaddr offset,
123
size_t idx = offset / sizeof(uint32_t);
124
125
switch (idx) {
126
+ case R_CM_LOCK:
127
+ r = get_cm_lock(s);
128
+ break;
129
+
130
default:
131
r = s->regs[idx];
132
}
133
--
59
--
134
2.20.1
60
2.34.1
135
61
136
62
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
1
From: Philippe Mathieu-Daudé <philmd@linaro.org>
2
2
3
The BCM2835 has only one core. Introduce the core_count field to
3
qbus_new(), called in i2c_init_bus(), should not be called
4
be able to use values different than BCM283X_NCPUS (4).
4
on unrealized device.
5
5
6
Reviewed-by: Luc Michel <luc.michel@greensocs.com>
6
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
7
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Message-id: 20201024170127.3592182-4-f4bug@amsat.org
8
Reviewed-by: Thomas Huth <thuth@redhat.com>
9
Message-id: 20231020130331.50048-10-philmd@linaro.org
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
---
11
---
11
hw/arm/bcm2836.c | 5 ++++-
12
hw/arm/pxa2xx.c | 5 +++--
12
1 file changed, 4 insertions(+), 1 deletion(-)
13
1 file changed, 3 insertions(+), 2 deletions(-)
13
14
14
diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c
15
diff --git a/hw/arm/pxa2xx.c b/hw/arm/pxa2xx.c
15
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
16
--- a/hw/arm/bcm2836.c
17
--- a/hw/arm/pxa2xx.c
17
+++ b/hw/arm/bcm2836.c
18
+++ b/hw/arm/pxa2xx.c
18
@@ -XXX,XX +XXX,XX @@ typedef struct BCM283XClass {
19
@@ -XXX,XX +XXX,XX @@ PXA2xxI2CState *pxa2xx_i2c_init(hwaddr base,
19
/*< public >*/
20
qdev_prop_set_uint32(dev, "size", region_size + 1);
20
const char *name;
21
qdev_prop_set_uint32(dev, "offset", base & region_size);
21
const char *cpu_type;
22
22
+ unsigned core_count;
23
+ /* FIXME: Should the slave device really be on a separate bus? */
23
hwaddr peri_base; /* Peripheral base address seen by the CPU */
24
+ i2cbus = i2c_init_bus(dev, "dummy");
24
hwaddr ctrl_base; /* Interrupt controller and mailboxes etc. */
25
+
25
int clusterid;
26
i2c_dev = SYS_BUS_DEVICE(dev);
26
@@ -XXX,XX +XXX,XX @@ static void bcm2836_init(Object *obj)
27
sysbus_realize_and_unref(i2c_dev, &error_fatal);
27
BCM283XClass *bc = BCM283X_GET_CLASS(obj);
28
sysbus_mmio_map(i2c_dev, 0, base & ~region_size);
28
int n;
29
sysbus_connect_irq(i2c_dev, 0, irq);
29
30
30
- for (n = 0; n < BCM283X_NCPUS; n++) {
31
s = PXA2XX_I2C(i2c_dev);
31
+ for (n = 0; n < bc->core_count; n++) {
32
- /* FIXME: Should the slave device really be on a separate bus? */
32
object_initialize_child(obj, "cpu[*]", &s->cpu[n].core,
33
- i2cbus = i2c_init_bus(dev, "dummy");
33
bc->cpu_type);
34
s->slave = PXA2XX_I2C_SLAVE(i2c_slave_create_simple(i2cbus,
34
}
35
TYPE_PXA2XX_I2C_SLAVE,
35
@@ -XXX,XX +XXX,XX @@ static void bcm2836_class_init(ObjectClass *oc, void *data)
36
0));
36
BCM283XClass *bc = BCM283X_CLASS(oc);
37
38
bc->cpu_type = ARM_CPU_TYPE_NAME("cortex-a7");
39
+ bc->core_count = BCM283X_NCPUS;
40
bc->peri_base = 0x3f000000;
41
bc->ctrl_base = 0x40000000;
42
bc->clusterid = 0xf;
43
@@ -XXX,XX +XXX,XX @@ static void bcm2837_class_init(ObjectClass *oc, void *data)
44
BCM283XClass *bc = BCM283X_CLASS(oc);
45
46
bc->cpu_type = ARM_CPU_TYPE_NAME("cortex-a53");
47
+ bc->core_count = BCM283X_NCPUS;
48
bc->peri_base = 0x3f000000;
49
bc->ctrl_base = 0x40000000;
50
bc->clusterid = 0x0;
51
--
37
--
52
2.20.1
38
2.34.1
53
39
54
40
diff view generated by jsdifflib
1
From: Luc Michel <luc@lmichel.fr>
1
From: Philippe Mathieu-Daudé <philmd@linaro.org>
2
2
3
Those reset values have been extracted from a Raspberry Pi 3 model B
3
Prefer using a well known local first CPU rather than a global one.
4
v1.2, using the 2020-08-20 version of raspios. The dump was done using
5
the debugfs interface of the CPRMAN driver in Linux (under
6
'/sys/kernel/debug/clk'). Each exposed clock tree stage (PLLs, channels
7
and muxes) can be observed by reading the 'regdump' file (e.g.
8
'plla/regdump').
9
4
10
Those values are set by the Raspberry Pi firmware at boot time (Linux
5
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
11
expects them to be set when it boots up).
6
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
12
7
Message-id: 20231025065909.57344-1-philmd@linaro.org
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>
25
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
26
---
9
---
27
include/hw/misc/bcm2835_cprman_internals.h | 269 +++++++++++++++++++++
10
hw/arm/bananapi_m2u.c | 2 +-
28
hw/misc/bcm2835_cprman.c | 31 +++
11
hw/arm/exynos4_boards.c | 7 ++++---
29
2 files changed, 300 insertions(+)
12
hw/arm/orangepi.c | 2 +-
13
hw/arm/realview.c | 2 +-
14
hw/arm/xilinx_zynq.c | 2 +-
15
5 files changed, 8 insertions(+), 7 deletions(-)
30
16
31
diff --git a/include/hw/misc/bcm2835_cprman_internals.h b/include/hw/misc/bcm2835_cprman_internals.h
17
diff --git a/hw/arm/bananapi_m2u.c b/hw/arm/bananapi_m2u.c
32
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
33
--- a/include/hw/misc/bcm2835_cprman_internals.h
19
--- a/hw/arm/bananapi_m2u.c
34
+++ b/include/hw/misc/bcm2835_cprman_internals.h
20
+++ b/hw/arm/bananapi_m2u.c
35
@@ -XXX,XX +XXX,XX @@ static inline void set_clock_mux_init_info(BCM2835CprmanState *s,
21
@@ -XXX,XX +XXX,XX @@ static void bpim2u_init(MachineState *machine)
36
mux->frac_bits = CLOCK_MUX_INIT_INFO[id].frac_bits;
22
bpim2u_binfo.loader_start = r40->memmap[AW_R40_DEV_SDRAM];
23
bpim2u_binfo.ram_size = machine->ram_size;
24
bpim2u_binfo.psci_conduit = QEMU_PSCI_CONDUIT_SMC;
25
- arm_load_kernel(ARM_CPU(first_cpu), machine, &bpim2u_binfo);
26
+ arm_load_kernel(&r40->cpus[0], machine, &bpim2u_binfo);
37
}
27
}
38
28
39
+
29
static void bpim2u_machine_init(MachineClass *mc)
40
+/*
30
diff --git a/hw/arm/exynos4_boards.c b/hw/arm/exynos4_boards.c
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
31
index XXXXXXX..XXXXXXX 100644
311
--- a/hw/misc/bcm2835_cprman.c
32
--- a/hw/arm/exynos4_boards.c
312
+++ b/hw/misc/bcm2835_cprman.c
33
+++ b/hw/arm/exynos4_boards.c
313
@@ -XXX,XX +XXX,XX @@
34
@@ -XXX,XX +XXX,XX @@ exynos4_boards_init_common(MachineState *machine,
314
35
315
/* PLL */
36
static void nuri_init(MachineState *machine)
316
317
+static void pll_reset(DeviceState *dev)
318
+{
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;
326
+}
327
+
328
static bool pll_is_locked(const CprmanPllState *pll)
329
{
37
{
330
return !FIELD_EX32(*pll->reg_a2w_ctrl, A2W_PLLx_CTRL, PWRDN)
38
- exynos4_boards_init_common(machine, EXYNOS4_BOARD_NURI);
331
@@ -XXX,XX +XXX,XX @@ static void pll_class_init(ObjectClass *klass, void *data)
39
+ Exynos4BoardState *s = exynos4_boards_init_common(machine,
332
{
40
+ EXYNOS4_BOARD_NURI);
333
DeviceClass *dc = DEVICE_CLASS(klass);
41
334
42
- arm_load_kernel(ARM_CPU(first_cpu), machine, &exynos4_board_binfo);
335
+ dc->reset = pll_reset;
43
+ arm_load_kernel(s->soc.cpu[0], machine, &exynos4_board_binfo);
336
dc->vmsd = &pll_vmstate;
337
}
44
}
338
45
339
@@ -XXX,XX +XXX,XX @@ static const TypeInfo cprman_pll_info = {
46
static void smdkc210_init(MachineState *machine)
340
47
@@ -XXX,XX +XXX,XX @@ static void smdkc210_init(MachineState *machine)
341
/* PLL channel */
48
342
49
lan9215_init(SMDK_LAN9118_BASE_ADDR,
343
+static void pll_channel_reset(DeviceState *dev)
50
qemu_irq_invert(s->soc.irq_table[exynos4210_get_irq(37, 1)]));
344
+{
51
- arm_load_kernel(ARM_CPU(first_cpu), machine, &exynos4_board_binfo);
345
+ CprmanPllChannelState *s = CPRMAN_PLL_CHANNEL(dev);
52
+ arm_load_kernel(s->soc.cpu[0], machine, &exynos4_board_binfo);
346
+ const PLLChannelResetInfo *info = &PLL_CHANNEL_RESET_INFO[s->id];
347
+
348
+ *s->reg_a2w_ctrl = info->a2w_ctrl;
349
+}
350
+
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)
355
{
356
DeviceClass *dc = DEVICE_CLASS(klass);
357
358
+ dc->reset = pll_channel_reset;
359
dc->vmsd = &pll_channel_vmstate;
360
}
53
}
361
54
362
@@ -XXX,XX +XXX,XX @@ static void clock_mux_src_update(void *opaque)
55
static void nuri_class_init(ObjectClass *oc, void *data)
363
clock_mux_update(s);
56
diff --git a/hw/arm/orangepi.c b/hw/arm/orangepi.c
57
index XXXXXXX..XXXXXXX 100644
58
--- a/hw/arm/orangepi.c
59
+++ b/hw/arm/orangepi.c
60
@@ -XXX,XX +XXX,XX @@ static void orangepi_init(MachineState *machine)
61
orangepi_binfo.loader_start = h3->memmap[AW_H3_DEV_SDRAM];
62
orangepi_binfo.ram_size = machine->ram_size;
63
orangepi_binfo.psci_conduit = QEMU_PSCI_CONDUIT_SMC;
64
- arm_load_kernel(ARM_CPU(first_cpu), machine, &orangepi_binfo);
65
+ arm_load_kernel(&h3->cpus[0], machine, &orangepi_binfo);
364
}
66
}
365
67
366
+static void clock_mux_reset(DeviceState *dev)
68
static void orangepi_machine_init(MachineClass *mc)
367
+{
69
diff --git a/hw/arm/realview.c b/hw/arm/realview.c
368
+ CprmanClockMuxState *clock = CPRMAN_CLOCK_MUX(dev);
70
index XXXXXXX..XXXXXXX 100644
369
+ const ClockMuxResetInfo *info = &CLOCK_MUX_RESET_INFO[clock->id];
71
--- a/hw/arm/realview.c
370
+
72
+++ b/hw/arm/realview.c
371
+ *clock->reg_ctl = info->cm_ctl;
73
@@ -XXX,XX +XXX,XX @@ static void realview_init(MachineState *machine,
372
+ *clock->reg_div = info->cm_div;
74
realview_binfo.ram_size = ram_size;
373
+}
75
realview_binfo.board_id = realview_board_id[board_type];
374
+
76
realview_binfo.loader_start = (board_type == BOARD_PB_A8 ? 0x70000000 : 0);
375
static void clock_mux_init(Object *obj)
77
- arm_load_kernel(ARM_CPU(first_cpu), machine, &realview_binfo);
376
{
78
+ arm_load_kernel(cpu, machine, &realview_binfo);
377
CprmanClockMuxState *s = CPRMAN_CLOCK_MUX(obj);
378
@@ -XXX,XX +XXX,XX @@ static void clock_mux_class_init(ObjectClass *klass, void *data)
379
{
380
DeviceClass *dc = DEVICE_CLASS(klass);
381
382
+ dc->reset = clock_mux_reset;
383
dc->vmsd = &clock_mux_vmstate;
384
}
79
}
385
80
81
static void realview_eb_init(MachineState *machine)
82
diff --git a/hw/arm/xilinx_zynq.c b/hw/arm/xilinx_zynq.c
83
index XXXXXXX..XXXXXXX 100644
84
--- a/hw/arm/xilinx_zynq.c
85
+++ b/hw/arm/xilinx_zynq.c
86
@@ -XXX,XX +XXX,XX @@ static void zynq_init(MachineState *machine)
87
zynq_binfo.board_setup_addr = BOARD_SETUP_ADDR;
88
zynq_binfo.write_board_setup = zynq_write_board_setup;
89
90
- arm_load_kernel(ARM_CPU(first_cpu), machine, &zynq_binfo);
91
+ arm_load_kernel(cpu, machine, &zynq_binfo);
92
}
93
94
static void zynq_machine_class_init(ObjectClass *oc, void *data)
386
--
95
--
387
2.20.1
96
2.34.1
388
97
389
98
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Glenn Miles <milesg@linux.vnet.ibm.com>
2
2
3
This is slightly clearer than just using strerror, though
3
Testing of the LED state showed that when the LED polarity was
4
the different forms produced by error_setg_file_open and
4
set to GPIO_POLARITY_ACTIVE_LOW and a low logic value was set on
5
error_setg_errno isn't entirely convenient.
5
the input GPIO of the LED, the LED was being turn off when it was
6
expected to be turned on.
6
7
7
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
8
Fixes: ddb67f6402 ("hw/misc/led: Allow connecting from GPIO output")
8
Message-id: 20201021173749.111103-10-richard.henderson@linaro.org
9
Signed-off-by: Glenn Miles <milesg@linux.vnet.ibm.com>
9
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
10
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
11
Reviewed-by: Andrew Jeffery <andrew@codeconstruct.com.au>
12
Message-id: 20231024191945.4135036-1-milesg@linux.vnet.ibm.com
13
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
14
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
---
15
---
12
linux-user/elfload.c | 15 ++++++++-------
16
hw/misc/led.c | 2 +-
13
1 file changed, 8 insertions(+), 7 deletions(-)
17
1 file changed, 1 insertion(+), 1 deletion(-)
14
18
15
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
19
diff --git a/hw/misc/led.c b/hw/misc/led.c
16
index XXXXXXX..XXXXXXX 100644
20
index XXXXXXX..XXXXXXX 100644
17
--- a/linux-user/elfload.c
21
--- a/hw/misc/led.c
18
+++ b/linux-user/elfload.c
22
+++ b/hw/misc/led.c
19
@@ -XXX,XX +XXX,XX @@ static void load_elf_interp(const char *filename, struct image_info *info,
23
@@ -XXX,XX +XXX,XX @@ static void led_set_state_gpio_handler(void *opaque, int line, int new_state)
20
char bprm_buf[BPRM_BUF_SIZE])
24
LEDState *s = LED(opaque);
21
{
25
22
int fd, retval;
26
assert(line == 0);
23
+ Error *err = NULL;
27
- led_set_state(s, !!new_state != s->gpio_active_high);
24
28
+ led_set_state(s, !!new_state == s->gpio_active_high);
25
fd = open(path(filename), O_RDONLY);
26
if (fd < 0) {
27
- goto exit_perror;
28
+ error_setg_file_open(&err, errno, filename);
29
+ error_report_err(err);
30
+ exit(-1);
31
}
32
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);
39
}
40
+
41
if (retval < BPRM_BUF_SIZE) {
42
memset(bprm_buf + retval, 0, BPRM_BUF_SIZE - retval);
43
}
44
45
load_elf_image(filename, fd, info, NULL, bprm_buf);
46
- return;
47
-
48
- exit_perror:
49
- fprintf(stderr, "%s: %s\n", filename, strerror(errno));
50
- exit(-1);
51
}
29
}
52
30
53
static int symfind(const void *s0, const void *s1)
31
static void led_reset(DeviceState *dev)
54
--
32
--
55
2.20.1
33
2.34.1
56
34
57
35
diff view generated by jsdifflib
1
From: Luc Michel <luc@lmichel.fr>
1
From: Luc Michel <luc.michel@amd.com>
2
2
3
The clock multiplexers are the last clock stage in the CPRMAN. Each mux
3
Replace register defines with the REG32 macro from registerfields.h in
4
outputs one clock signal that goes out of the CPRMAN to the SoC
4
the Cadence GEM device.
5
peripherals.
6
5
7
Each mux has at most 10 sources. The sources 0 to 3 are common to all
6
Signed-off-by: Luc Michel <luc.michel@amd.com>
8
muxes. They are:
7
Reviewed-by: sai.pavan.boddu@amd.com
9
0. ground (no clock signal)
8
Message-id: 20231017194422.4124691-2-luc.michel@amd.com
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>
40
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
41
---
10
---
42
include/hw/misc/bcm2835_cprman.h | 85 +++++
11
hw/net/cadence_gem.c | 527 +++++++++++++++++++++----------------------
43
include/hw/misc/bcm2835_cprman_internals.h | 422 +++++++++++++++++++++
12
1 file changed, 261 insertions(+), 266 deletions(-)
44
hw/misc/bcm2835_cprman.c | 151 ++++++++
45
3 files changed, 658 insertions(+)
46
13
47
diff --git a/include/hw/misc/bcm2835_cprman.h b/include/hw/misc/bcm2835_cprman.h
14
diff --git a/hw/net/cadence_gem.c b/hw/net/cadence_gem.c
48
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
49
--- a/include/hw/misc/bcm2835_cprman.h
16
--- a/hw/net/cadence_gem.c
50
+++ b/include/hw/misc/bcm2835_cprman.h
17
+++ b/hw/net/cadence_gem.c
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
168
@@ -XXX,XX +XXX,XX @@
18
@@ -XXX,XX +XXX,XX @@
169
19
#include "hw/irq.h"
170
#define TYPE_CPRMAN_PLL "bcm2835-cprman-pll"
20
#include "hw/net/cadence_gem.h"
171
#define TYPE_CPRMAN_PLL_CHANNEL "bcm2835-cprman-pll-channel"
21
#include "hw/qdev-properties.h"
172
+#define TYPE_CPRMAN_CLOCK_MUX "bcm2835-cprman-clock-mux"
22
+#include "hw/registerfields.h"
173
23
#include "migration/vmstate.h"
174
DECLARE_INSTANCE_CHECKER(CprmanPllState, CPRMAN_PLL,
24
#include "qapi/error.h"
175
TYPE_CPRMAN_PLL)
25
#include "qemu/log.h"
176
DECLARE_INSTANCE_CHECKER(CprmanPllChannelState, CPRMAN_PLL_CHANNEL,
26
@@ -XXX,XX +XXX,XX @@
177
TYPE_CPRMAN_PLL_CHANNEL)
27
} \
178
+DECLARE_INSTANCE_CHECKER(CprmanClockMuxState, CPRMAN_CLOCK_MUX,
28
} while (0)
179
+ TYPE_CPRMAN_CLOCK_MUX)
29
180
30
-#define GEM_NWCTRL (0x00000000 / 4) /* Network Control reg */
181
/* Register map */
31
-#define GEM_NWCFG (0x00000004 / 4) /* Network Config reg */
182
32
-#define GEM_NWSTATUS (0x00000008 / 4) /* Network Status reg */
183
@@ -XXX,XX +XXX,XX @@ REG32(A2W_PLLH_STS, 0x1660)
33
-#define GEM_USERIO (0x0000000C / 4) /* User IO reg */
184
34
-#define GEM_DMACFG (0x00000010 / 4) /* DMA Control reg */
185
REG32(A2W_PLLB_ARM, 0x13e0)
35
-#define GEM_TXSTATUS (0x00000014 / 4) /* TX Status reg */
186
36
-#define GEM_RXQBASE (0x00000018 / 4) /* RX Q Base address reg */
187
+/* Clock muxes */
37
-#define GEM_TXQBASE (0x0000001C / 4) /* TX Q Base address reg */
188
+REG32(CM_GNRICCTL, 0x000)
38
-#define GEM_RXSTATUS (0x00000020 / 4) /* RX Status reg */
189
+ FIELD(CM_CLOCKx_CTL, SRC, 0, 4)
39
-#define GEM_ISR (0x00000024 / 4) /* Interrupt Status reg */
190
+ FIELD(CM_CLOCKx_CTL, ENABLE, 4, 1)
40
-#define GEM_IER (0x00000028 / 4) /* Interrupt Enable reg */
191
+ FIELD(CM_CLOCKx_CTL, KILL, 5, 1)
41
-#define GEM_IDR (0x0000002C / 4) /* Interrupt Disable reg */
192
+ FIELD(CM_CLOCKx_CTL, GATE, 6, 1)
42
-#define GEM_IMR (0x00000030 / 4) /* Interrupt Mask reg */
193
+ FIELD(CM_CLOCKx_CTL, BUSY, 7, 1)
43
-#define GEM_PHYMNTNC (0x00000034 / 4) /* Phy Maintenance reg */
194
+ FIELD(CM_CLOCKx_CTL, BUSYD, 8, 1)
44
-#define GEM_RXPAUSE (0x00000038 / 4) /* RX Pause Time reg */
195
+ FIELD(CM_CLOCKx_CTL, MASH, 9, 2)
45
-#define GEM_TXPAUSE (0x0000003C / 4) /* TX Pause Time reg */
196
+ FIELD(CM_CLOCKx_CTL, FLIP, 11, 1)
46
-#define GEM_TXPARTIALSF (0x00000040 / 4) /* TX Partial Store and Forward */
197
+REG32(CM_GNRICDIV, 0x004)
47
-#define GEM_RXPARTIALSF (0x00000044 / 4) /* RX Partial Store and Forward */
198
+ FIELD(CM_CLOCKx_DIV, FRAC, 0, 12)
48
-#define GEM_JUMBO_MAX_LEN (0x00000048 / 4) /* Max Jumbo Frame Size */
199
+REG32(CM_VPUCTL, 0x008)
49
-#define GEM_HASHLO (0x00000080 / 4) /* Hash Low address reg */
200
+REG32(CM_VPUDIV, 0x00c)
50
-#define GEM_HASHHI (0x00000084 / 4) /* Hash High address reg */
201
+REG32(CM_SYSCTL, 0x010)
51
-#define GEM_SPADDR1LO (0x00000088 / 4) /* Specific addr 1 low reg */
202
+REG32(CM_SYSDIV, 0x014)
52
-#define GEM_SPADDR1HI (0x0000008C / 4) /* Specific addr 1 high reg */
203
+REG32(CM_PERIACTL, 0x018)
53
-#define GEM_SPADDR2LO (0x00000090 / 4) /* Specific addr 2 low reg */
204
+REG32(CM_PERIADIV, 0x01c)
54
-#define GEM_SPADDR2HI (0x00000094 / 4) /* Specific addr 2 high reg */
205
+REG32(CM_PERIICTL, 0x020)
55
-#define GEM_SPADDR3LO (0x00000098 / 4) /* Specific addr 3 low reg */
206
+REG32(CM_PERIIDIV, 0x024)
56
-#define GEM_SPADDR3HI (0x0000009C / 4) /* Specific addr 3 high reg */
207
+REG32(CM_H264CTL, 0x028)
57
-#define GEM_SPADDR4LO (0x000000A0 / 4) /* Specific addr 4 low reg */
208
+REG32(CM_H264DIV, 0x02c)
58
-#define GEM_SPADDR4HI (0x000000A4 / 4) /* Specific addr 4 high reg */
209
+REG32(CM_ISPCTL, 0x030)
59
-#define GEM_TIDMATCH1 (0x000000A8 / 4) /* Type ID1 Match reg */
210
+REG32(CM_ISPDIV, 0x034)
60
-#define GEM_TIDMATCH2 (0x000000AC / 4) /* Type ID2 Match reg */
211
+REG32(CM_V3DCTL, 0x038)
61
-#define GEM_TIDMATCH3 (0x000000B0 / 4) /* Type ID3 Match reg */
212
+REG32(CM_V3DDIV, 0x03c)
62
-#define GEM_TIDMATCH4 (0x000000B4 / 4) /* Type ID4 Match reg */
213
+REG32(CM_CAM0CTL, 0x040)
63
-#define GEM_WOLAN (0x000000B8 / 4) /* Wake on LAN reg */
214
+REG32(CM_CAM0DIV, 0x044)
64
-#define GEM_IPGSTRETCH (0x000000BC / 4) /* IPG Stretch reg */
215
+REG32(CM_CAM1CTL, 0x048)
65
-#define GEM_SVLAN (0x000000C0 / 4) /* Stacked VLAN reg */
216
+REG32(CM_CAM1DIV, 0x04c)
66
-#define GEM_MODID (0x000000FC / 4) /* Module ID reg */
217
+REG32(CM_CCP2CTL, 0x050)
67
-#define GEM_OCTTXLO (0x00000100 / 4) /* Octets transmitted Low reg */
218
+REG32(CM_CCP2DIV, 0x054)
68
-#define GEM_OCTTXHI (0x00000104 / 4) /* Octets transmitted High reg */
219
+REG32(CM_DSI0ECTL, 0x058)
69
-#define GEM_TXCNT (0x00000108 / 4) /* Error-free Frames transmitted */
220
+REG32(CM_DSI0EDIV, 0x05c)
70
-#define GEM_TXBCNT (0x0000010C / 4) /* Error-free Broadcast Frames */
221
+REG32(CM_DSI0PCTL, 0x060)
71
-#define GEM_TXMCNT (0x00000110 / 4) /* Error-free Multicast Frame */
222
+REG32(CM_DSI0PDIV, 0x064)
72
-#define GEM_TXPAUSECNT (0x00000114 / 4) /* Pause Frames Transmitted */
223
+REG32(CM_DPICTL, 0x068)
73
-#define GEM_TX64CNT (0x00000118 / 4) /* Error-free 64 TX */
224
+REG32(CM_DPIDIV, 0x06c)
74
-#define GEM_TX65CNT (0x0000011C / 4) /* Error-free 65-127 TX */
225
+REG32(CM_GP0CTL, 0x070)
75
-#define GEM_TX128CNT (0x00000120 / 4) /* Error-free 128-255 TX */
226
+REG32(CM_GP0DIV, 0x074)
76
-#define GEM_TX256CNT (0x00000124 / 4) /* Error-free 256-511 */
227
+REG32(CM_GP1CTL, 0x078)
77
-#define GEM_TX512CNT (0x00000128 / 4) /* Error-free 512-1023 TX */
228
+REG32(CM_GP1DIV, 0x07c)
78
-#define GEM_TX1024CNT (0x0000012C / 4) /* Error-free 1024-1518 TX */
229
+REG32(CM_GP2CTL, 0x080)
79
-#define GEM_TX1519CNT (0x00000130 / 4) /* Error-free larger than 1519 TX */
230
+REG32(CM_GP2DIV, 0x084)
80
-#define GEM_TXURUNCNT (0x00000134 / 4) /* TX under run error counter */
231
+REG32(CM_HSMCTL, 0x088)
81
-#define GEM_SINGLECOLLCNT (0x00000138 / 4) /* Single Collision Frames */
232
+REG32(CM_HSMDIV, 0x08c)
82
-#define GEM_MULTCOLLCNT (0x0000013C / 4) /* Multiple Collision Frames */
233
+REG32(CM_OTPCTL, 0x090)
83
-#define GEM_EXCESSCOLLCNT (0x00000140 / 4) /* Excessive Collision Frames */
234
+REG32(CM_OTPDIV, 0x094)
84
-#define GEM_LATECOLLCNT (0x00000144 / 4) /* Late Collision Frames */
235
+REG32(CM_PCMCTL, 0x098)
85
-#define GEM_DEFERTXCNT (0x00000148 / 4) /* Deferred Transmission Frames */
236
+REG32(CM_PCMDIV, 0x09c)
86
-#define GEM_CSENSECNT (0x0000014C / 4) /* Carrier Sense Error Counter */
237
+REG32(CM_PWMCTL, 0x0a0)
87
-#define GEM_OCTRXLO (0x00000150 / 4) /* Octets Received register Low */
238
+REG32(CM_PWMDIV, 0x0a4)
88
-#define GEM_OCTRXHI (0x00000154 / 4) /* Octets Received register High */
239
+REG32(CM_SLIMCTL, 0x0a8)
89
-#define GEM_RXCNT (0x00000158 / 4) /* Error-free Frames Received */
240
+REG32(CM_SLIMDIV, 0x0ac)
90
-#define GEM_RXBROADCNT (0x0000015C / 4) /* Error-free Broadcast Frames RX */
241
+REG32(CM_SMICTL, 0x0b0)
91
-#define GEM_RXMULTICNT (0x00000160 / 4) /* Error-free Multicast Frames RX */
242
+REG32(CM_SMIDIV, 0x0b4)
92
-#define GEM_RXPAUSECNT (0x00000164 / 4) /* Pause Frames Received Counter */
243
+REG32(CM_TCNTCTL, 0x0c0)
93
-#define GEM_RX64CNT (0x00000168 / 4) /* Error-free 64 byte Frames RX */
244
+REG32(CM_TCNTCNT, 0x0c4)
94
-#define GEM_RX65CNT (0x0000016C / 4) /* Error-free 65-127B Frames RX */
245
+REG32(CM_TECCTL, 0x0c8)
95
-#define GEM_RX128CNT (0x00000170 / 4) /* Error-free 128-255B Frames RX */
246
+REG32(CM_TECDIV, 0x0cc)
96
-#define GEM_RX256CNT (0x00000174 / 4) /* Error-free 256-512B Frames RX */
247
+REG32(CM_TD0CTL, 0x0d0)
97
-#define GEM_RX512CNT (0x00000178 / 4) /* Error-free 512-1023B Frames RX */
248
+REG32(CM_TD0DIV, 0x0d4)
98
-#define GEM_RX1024CNT (0x0000017C / 4) /* Error-free 1024-1518B Frames RX */
249
+REG32(CM_TD1CTL, 0x0d8)
99
-#define GEM_RX1519CNT (0x00000180 / 4) /* Error-free 1519-max Frames RX */
250
+REG32(CM_TD1DIV, 0x0dc)
100
-#define GEM_RXUNDERCNT (0x00000184 / 4) /* Undersize Frames Received */
251
+REG32(CM_TSENSCTL, 0x0e0)
101
-#define GEM_RXOVERCNT (0x00000188 / 4) /* Oversize Frames Received */
252
+REG32(CM_TSENSDIV, 0x0e4)
102
-#define GEM_RXJABCNT (0x0000018C / 4) /* Jabbers Received Counter */
253
+REG32(CM_TIMERCTL, 0x0e8)
103
-#define GEM_RXFCSCNT (0x00000190 / 4) /* Frame Check seq. Error Counter */
254
+REG32(CM_TIMERDIV, 0x0ec)
104
-#define GEM_RXLENERRCNT (0x00000194 / 4) /* Length Field Error Counter */
255
+REG32(CM_UARTCTL, 0x0f0)
105
-#define GEM_RXSYMERRCNT (0x00000198 / 4) /* Symbol Error Counter */
256
+REG32(CM_UARTDIV, 0x0f4)
106
-#define GEM_RXALIGNERRCNT (0x0000019C / 4) /* Alignment Error Counter */
257
+REG32(CM_VECCTL, 0x0f8)
107
-#define GEM_RXRSCERRCNT (0x000001A0 / 4) /* Receive Resource Error Counter */
258
+REG32(CM_VECDIV, 0x0fc)
108
-#define GEM_RXORUNCNT (0x000001A4 / 4) /* Receive Overrun Counter */
259
+REG32(CM_PULSECTL, 0x190)
109
-#define GEM_RXIPCSERRCNT (0x000001A8 / 4) /* IP header Checksum Err Counter */
260
+REG32(CM_PULSEDIV, 0x194)
110
-#define GEM_RXTCPCCNT (0x000001AC / 4) /* TCP Checksum Error Counter */
261
+REG32(CM_SDCCTL, 0x1a8)
111
-#define GEM_RXUDPCCNT (0x000001B0 / 4) /* UDP Checksum Error Counter */
262
+REG32(CM_SDCDIV, 0x1ac)
112
+REG32(NWCTRL, 0x0) /* Network Control reg */
263
+REG32(CM_ARMCTL, 0x1b0)
113
+REG32(NWCFG, 0x4) /* Network Config reg */
264
+REG32(CM_AVEOCTL, 0x1b8)
114
+REG32(NWSTATUS, 0x8) /* Network Status reg */
265
+REG32(CM_AVEODIV, 0x1bc)
115
+REG32(USERIO, 0xc) /* User IO reg */
266
+REG32(CM_EMMCCTL, 0x1c0)
116
+REG32(DMACFG, 0x10) /* DMA Control reg */
267
+REG32(CM_EMMCDIV, 0x1c4)
117
+REG32(TXSTATUS, 0x14) /* TX Status reg */
268
+REG32(CM_EMMC2CTL, 0x1d0)
118
+REG32(RXQBASE, 0x18) /* RX Q Base address reg */
269
+REG32(CM_EMMC2DIV, 0x1d4)
119
+REG32(TXQBASE, 0x1c) /* TX Q Base address reg */
270
+
120
+REG32(RXSTATUS, 0x20) /* RX Status reg */
271
/* misc registers */
121
+REG32(ISR, 0x24) /* Interrupt Status reg */
272
REG32(CM_LOCK, 0x114)
122
+REG32(IER, 0x28) /* Interrupt Enable reg */
273
FIELD(CM_LOCK, FLOCKH, 12, 1)
123
+REG32(IDR, 0x2c) /* Interrupt Disable reg */
274
@@ -XXX,XX +XXX,XX @@ static inline void set_pll_channel_init_info(BCM2835CprmanState *s,
124
+REG32(IMR, 0x30) /* Interrupt Mask reg */
275
channel->fixed_divider = PLL_CHANNEL_INIT_INFO[id].fixed_divider;
125
+REG32(PHYMNTNC, 0x34) /* Phy Maintenance reg */
126
+REG32(RXPAUSE, 0x38) /* RX Pause Time reg */
127
+REG32(TXPAUSE, 0x3c) /* TX Pause Time reg */
128
+REG32(TXPARTIALSF, 0x40) /* TX Partial Store and Forward */
129
+REG32(RXPARTIALSF, 0x44) /* RX Partial Store and Forward */
130
+REG32(JUMBO_MAX_LEN, 0x48) /* Max Jumbo Frame Size */
131
+REG32(HASHLO, 0x80) /* Hash Low address reg */
132
+REG32(HASHHI, 0x84) /* Hash High address reg */
133
+REG32(SPADDR1LO, 0x88) /* Specific addr 1 low reg */
134
+REG32(SPADDR1HI, 0x8c) /* Specific addr 1 high reg */
135
+REG32(SPADDR2LO, 0x90) /* Specific addr 2 low reg */
136
+REG32(SPADDR2HI, 0x94) /* Specific addr 2 high reg */
137
+REG32(SPADDR3LO, 0x98) /* Specific addr 3 low reg */
138
+REG32(SPADDR3HI, 0x9c) /* Specific addr 3 high reg */
139
+REG32(SPADDR4LO, 0xa0) /* Specific addr 4 low reg */
140
+REG32(SPADDR4HI, 0xa4) /* Specific addr 4 high reg */
141
+REG32(TIDMATCH1, 0xa8) /* Type ID1 Match reg */
142
+REG32(TIDMATCH2, 0xac) /* Type ID2 Match reg */
143
+REG32(TIDMATCH3, 0xb0) /* Type ID3 Match reg */
144
+REG32(TIDMATCH4, 0xb4) /* Type ID4 Match reg */
145
+REG32(WOLAN, 0xb8) /* Wake on LAN reg */
146
+REG32(IPGSTRETCH, 0xbc) /* IPG Stretch reg */
147
+REG32(SVLAN, 0xc0) /* Stacked VLAN reg */
148
+REG32(MODID, 0xfc) /* Module ID reg */
149
+REG32(OCTTXLO, 0x100) /* Octects transmitted Low reg */
150
+REG32(OCTTXHI, 0x104) /* Octects transmitted High reg */
151
+REG32(TXCNT, 0x108) /* Error-free Frames transmitted */
152
+REG32(TXBCNT, 0x10c) /* Error-free Broadcast Frames */
153
+REG32(TXMCNT, 0x110) /* Error-free Multicast Frame */
154
+REG32(TXPAUSECNT, 0x114) /* Pause Frames Transmitted */
155
+REG32(TX64CNT, 0x118) /* Error-free 64 TX */
156
+REG32(TX65CNT, 0x11c) /* Error-free 65-127 TX */
157
+REG32(TX128CNT, 0x120) /* Error-free 128-255 TX */
158
+REG32(TX256CNT, 0x124) /* Error-free 256-511 */
159
+REG32(TX512CNT, 0x128) /* Error-free 512-1023 TX */
160
+REG32(TX1024CNT, 0x12c) /* Error-free 1024-1518 TX */
161
+REG32(TX1519CNT, 0x130) /* Error-free larger than 1519 TX */
162
+REG32(TXURUNCNT, 0x134) /* TX under run error counter */
163
+REG32(SINGLECOLLCNT, 0x138) /* Single Collision Frames */
164
+REG32(MULTCOLLCNT, 0x13c) /* Multiple Collision Frames */
165
+REG32(EXCESSCOLLCNT, 0x140) /* Excessive Collision Frames */
166
+REG32(LATECOLLCNT, 0x144) /* Late Collision Frames */
167
+REG32(DEFERTXCNT, 0x148) /* Deferred Transmission Frames */
168
+REG32(CSENSECNT, 0x14c) /* Carrier Sense Error Counter */
169
+REG32(OCTRXLO, 0x150) /* Octects Received register Low */
170
+REG32(OCTRXHI, 0x154) /* Octects Received register High */
171
+REG32(RXCNT, 0x158) /* Error-free Frames Received */
172
+REG32(RXBROADCNT, 0x15c) /* Error-free Broadcast Frames RX */
173
+REG32(RXMULTICNT, 0x160) /* Error-free Multicast Frames RX */
174
+REG32(RXPAUSECNT, 0x164) /* Pause Frames Received Counter */
175
+REG32(RX64CNT, 0x168) /* Error-free 64 byte Frames RX */
176
+REG32(RX65CNT, 0x16c) /* Error-free 65-127B Frames RX */
177
+REG32(RX128CNT, 0x170) /* Error-free 128-255B Frames RX */
178
+REG32(RX256CNT, 0x174) /* Error-free 256-512B Frames RX */
179
+REG32(RX512CNT, 0x178) /* Error-free 512-1023B Frames RX */
180
+REG32(RX1024CNT, 0x17c) /* Error-free 1024-1518B Frames RX */
181
+REG32(RX1519CNT, 0x180) /* Error-free 1519-max Frames RX */
182
+REG32(RXUNDERCNT, 0x184) /* Undersize Frames Received */
183
+REG32(RXOVERCNT, 0x188) /* Oversize Frames Received */
184
+REG32(RXJABCNT, 0x18c) /* Jabbers Received Counter */
185
+REG32(RXFCSCNT, 0x190) /* Frame Check seq. Error Counter */
186
+REG32(RXLENERRCNT, 0x194) /* Length Field Error Counter */
187
+REG32(RXSYMERRCNT, 0x198) /* Symbol Error Counter */
188
+REG32(RXALIGNERRCNT, 0x19c) /* Alignment Error Counter */
189
+REG32(RXRSCERRCNT, 0x1a0) /* Receive Resource Error Counter */
190
+REG32(RXORUNCNT, 0x1a4) /* Receive Overrun Counter */
191
+REG32(RXIPCSERRCNT, 0x1a8) /* IP header Checksum Err Counter */
192
+REG32(RXTCPCCNT, 0x1ac) /* TCP Checksum Error Counter */
193
+REG32(RXUDPCCNT, 0x1b0) /* UDP Checksum Error Counter */
194
195
-#define GEM_1588S (0x000001D0 / 4) /* 1588 Timer Seconds */
196
-#define GEM_1588NS (0x000001D4 / 4) /* 1588 Timer Nanoseconds */
197
-#define GEM_1588ADJ (0x000001D8 / 4) /* 1588 Timer Adjust */
198
-#define GEM_1588INC (0x000001DC / 4) /* 1588 Timer Increment */
199
-#define GEM_PTPETXS (0x000001E0 / 4) /* PTP Event Frame Transmitted (s) */
200
-#define GEM_PTPETXNS (0x000001E4 / 4) /*
201
- * PTP Event Frame Transmitted (ns)
202
- */
203
-#define GEM_PTPERXS (0x000001E8 / 4) /* PTP Event Frame Received (s) */
204
-#define GEM_PTPERXNS (0x000001EC / 4) /* PTP Event Frame Received (ns) */
205
-#define GEM_PTPPTXS (0x000001E0 / 4) /* PTP Peer Frame Transmitted (s) */
206
-#define GEM_PTPPTXNS (0x000001E4 / 4) /* PTP Peer Frame Transmitted (ns) */
207
-#define GEM_PTPPRXS (0x000001E8 / 4) /* PTP Peer Frame Received (s) */
208
-#define GEM_PTPPRXNS (0x000001EC / 4) /* PTP Peer Frame Received (ns) */
209
+REG32(1588S, 0x1d0) /* 1588 Timer Seconds */
210
+REG32(1588NS, 0x1d4) /* 1588 Timer Nanoseconds */
211
+REG32(1588ADJ, 0x1d8) /* 1588 Timer Adjust */
212
+REG32(1588INC, 0x1dc) /* 1588 Timer Increment */
213
+REG32(PTPETXS, 0x1e0) /* PTP Event Frame Transmitted (s) */
214
+REG32(PTPETXNS, 0x1e4) /* PTP Event Frame Transmitted (ns) */
215
+REG32(PTPERXS, 0x1e8) /* PTP Event Frame Received (s) */
216
+REG32(PTPERXNS, 0x1ec) /* PTP Event Frame Received (ns) */
217
+REG32(PTPPTXS, 0x1e0) /* PTP Peer Frame Transmitted (s) */
218
+REG32(PTPPTXNS, 0x1e4) /* PTP Peer Frame Transmitted (ns) */
219
+REG32(PTPPRXS, 0x1e8) /* PTP Peer Frame Received (s) */
220
+REG32(PTPPRXNS, 0x1ec) /* PTP Peer Frame Received (ns) */
221
222
/* Design Configuration Registers */
223
-#define GEM_DESCONF (0x00000280 / 4)
224
-#define GEM_DESCONF2 (0x00000284 / 4)
225
-#define GEM_DESCONF3 (0x00000288 / 4)
226
-#define GEM_DESCONF4 (0x0000028C / 4)
227
-#define GEM_DESCONF5 (0x00000290 / 4)
228
-#define GEM_DESCONF6 (0x00000294 / 4)
229
+REG32(DESCONF, 0x280)
230
+REG32(DESCONF2, 0x284)
231
+REG32(DESCONF3, 0x288)
232
+REG32(DESCONF4, 0x28c)
233
+REG32(DESCONF5, 0x290)
234
+REG32(DESCONF6, 0x294)
235
#define GEM_DESCONF6_64B_MASK (1U << 23)
236
-#define GEM_DESCONF7 (0x00000298 / 4)
237
+REG32(DESCONF7, 0x298)
238
239
-#define GEM_INT_Q1_STATUS (0x00000400 / 4)
240
-#define GEM_INT_Q1_MASK (0x00000640 / 4)
241
+REG32(INT_Q1_STATUS, 0x400)
242
+REG32(INT_Q1_MASK, 0x640)
243
244
-#define GEM_TRANSMIT_Q1_PTR (0x00000440 / 4)
245
-#define GEM_TRANSMIT_Q7_PTR (GEM_TRANSMIT_Q1_PTR + 6)
246
+REG32(TRANSMIT_Q1_PTR, 0x440)
247
+REG32(TRANSMIT_Q7_PTR, 0x458)
248
249
-#define GEM_RECEIVE_Q1_PTR (0x00000480 / 4)
250
-#define GEM_RECEIVE_Q7_PTR (GEM_RECEIVE_Q1_PTR + 6)
251
+REG32(RECEIVE_Q1_PTR, 0x480)
252
+REG32(RECEIVE_Q7_PTR, 0x498)
253
254
-#define GEM_TBQPH (0x000004C8 / 4)
255
-#define GEM_RBQPH (0x000004D4 / 4)
256
+REG32(TBQPH, 0x4c8)
257
+REG32(RBQPH, 0x4d4)
258
259
-#define GEM_INT_Q1_ENABLE (0x00000600 / 4)
260
-#define GEM_INT_Q7_ENABLE (GEM_INT_Q1_ENABLE + 6)
261
+REG32(INT_Q1_ENABLE, 0x600)
262
+REG32(INT_Q7_ENABLE, 0x618)
263
264
-#define GEM_INT_Q1_DISABLE (0x00000620 / 4)
265
-#define GEM_INT_Q7_DISABLE (GEM_INT_Q1_DISABLE + 6)
266
+REG32(INT_Q1_DISABLE, 0x620)
267
+REG32(INT_Q7_DISABLE, 0x638)
268
269
-#define GEM_INT_Q1_MASK (0x00000640 / 4)
270
-#define GEM_INT_Q7_MASK (GEM_INT_Q1_MASK + 6)
271
-
272
-#define GEM_SCREENING_TYPE1_REGISTER_0 (0x00000500 / 4)
273
+REG32(SCREENING_TYPE1_REG0, 0x500)
274
275
#define GEM_ST1R_UDP_PORT_MATCH_ENABLE (1 << 29)
276
#define GEM_ST1R_DSTC_ENABLE (1 << 28)
277
@@ -XXX,XX +XXX,XX @@
278
#define GEM_ST1R_QUEUE_SHIFT (0)
279
#define GEM_ST1R_QUEUE_WIDTH (3 - GEM_ST1R_QUEUE_SHIFT + 1)
280
281
-#define GEM_SCREENING_TYPE2_REGISTER_0 (0x00000540 / 4)
282
+REG32(SCREENING_TYPE2_REG0, 0x540)
283
284
#define GEM_ST2R_COMPARE_A_ENABLE (1 << 18)
285
#define GEM_ST2R_COMPARE_A_SHIFT (13)
286
@@ -XXX,XX +XXX,XX @@
287
#define GEM_ST2R_QUEUE_SHIFT (0)
288
#define GEM_ST2R_QUEUE_WIDTH (3 - GEM_ST2R_QUEUE_SHIFT + 1)
289
290
-#define GEM_SCREENING_TYPE2_ETHERTYPE_REG_0 (0x000006e0 / 4)
291
-#define GEM_TYPE2_COMPARE_0_WORD_0 (0x00000700 / 4)
292
+REG32(SCREENING_TYPE2_ETHERTYPE_REG0, 0x6e0)
293
+REG32(TYPE2_COMPARE_0_WORD_0, 0x700)
294
295
#define GEM_T2CW1_COMPARE_OFFSET_SHIFT (7)
296
#define GEM_T2CW1_COMPARE_OFFSET_WIDTH (8 - GEM_T2CW1_COMPARE_OFFSET_SHIFT + 1)
297
@@ -XXX,XX +XXX,XX @@ static inline uint64_t tx_desc_get_buffer(CadenceGEMState *s, uint32_t *desc)
298
{
299
uint64_t ret = desc[0];
300
301
- if (s->regs[GEM_DMACFG] & GEM_DMACFG_ADDR_64B) {
302
+ if (s->regs[R_DMACFG] & GEM_DMACFG_ADDR_64B) {
303
ret |= (uint64_t)desc[2] << 32;
304
}
305
return ret;
306
@@ -XXX,XX +XXX,XX @@ static inline uint64_t rx_desc_get_buffer(CadenceGEMState *s, uint32_t *desc)
307
{
308
uint64_t ret = desc[0] & ~0x3UL;
309
310
- if (s->regs[GEM_DMACFG] & GEM_DMACFG_ADDR_64B) {
311
+ if (s->regs[R_DMACFG] & GEM_DMACFG_ADDR_64B) {
312
ret |= (uint64_t)desc[2] << 32;
313
}
314
return ret;
315
@@ -XXX,XX +XXX,XX @@ static inline int gem_get_desc_len(CadenceGEMState *s, bool rx_n_tx)
316
{
317
int ret = 2;
318
319
- if (s->regs[GEM_DMACFG] & GEM_DMACFG_ADDR_64B) {
320
+ if (s->regs[R_DMACFG] & GEM_DMACFG_ADDR_64B) {
321
ret += 2;
322
}
323
- if (s->regs[GEM_DMACFG] & (rx_n_tx ? GEM_DMACFG_RX_BD_EXT
324
+ if (s->regs[R_DMACFG] & (rx_n_tx ? GEM_DMACFG_RX_BD_EXT
325
: GEM_DMACFG_TX_BD_EXT)) {
326
ret += 2;
327
}
328
@@ -XXX,XX +XXX,XX @@ static const uint8_t broadcast_addr[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
329
static uint32_t gem_get_max_buf_len(CadenceGEMState *s, bool tx)
330
{
331
uint32_t size;
332
- if (s->regs[GEM_NWCFG] & GEM_NWCFG_JUMBO_FRAME) {
333
- size = s->regs[GEM_JUMBO_MAX_LEN];
334
+ if (s->regs[R_NWCFG] & GEM_NWCFG_JUMBO_FRAME) {
335
+ size = s->regs[R_JUMBO_MAX_LEN];
336
if (size > s->jumbo_max_len) {
337
size = s->jumbo_max_len;
338
qemu_log_mask(LOG_GUEST_ERROR, "GEM_JUMBO_MAX_LEN reg cannot be"
339
@@ -XXX,XX +XXX,XX @@ static uint32_t gem_get_max_buf_len(CadenceGEMState *s, bool tx)
340
} else if (tx) {
341
size = 1518;
342
} else {
343
- size = s->regs[GEM_NWCFG] & GEM_NWCFG_RCV_1538 ? 1538 : 1518;
344
+ size = s->regs[R_NWCFG] & GEM_NWCFG_RCV_1538 ? 1538 : 1518;
345
}
346
return size;
276
}
347
}
277
348
@@ -XXX,XX +XXX,XX @@ static uint32_t gem_get_max_buf_len(CadenceGEMState *s, bool tx)
278
+/* Clock mux init info */
349
static void gem_set_isr(CadenceGEMState *s, int q, uint32_t flag)
279
+typedef struct ClockMuxInitInfo {
350
{
280
+ const char *name;
351
if (q == 0) {
281
+ size_t cm_offset; /* cm_offset[0]->CM_CTL, cm_offset[1]->CM_DIV */
352
- s->regs[GEM_ISR] |= flag & ~(s->regs[GEM_IMR]);
282
+ int int_bits;
353
+ s->regs[R_ISR] |= flag & ~(s->regs[R_IMR]);
283
+ int frac_bits;
354
} else {
284
+
355
- s->regs[GEM_INT_Q1_STATUS + q - 1] |= flag &
285
+ CprmanPllChannel src_mapping[CPRMAN_NUM_CLOCK_MUX_SRC];
356
- ~(s->regs[GEM_INT_Q1_MASK + q - 1]);
286
+} ClockMuxInitInfo;
357
+ s->regs[R_INT_Q1_STATUS + q - 1] |= flag &
287
+
358
+ ~(s->regs[R_INT_Q1_MASK + q - 1]);
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
615
index XXXXXXX..XXXXXXX 100644
616
--- a/hw/misc/bcm2835_cprman.c
617
+++ b/hw/misc/bcm2835_cprman.c
618
@@ -XXX,XX +XXX,XX @@
619
*
620
* The page at https://elinux.org/The_Undocumented_Pi gives the actual clock
621
* tree configuration.
622
+ *
623
+ * The CPRMAN exposes clock outputs with the name of the clock mux suffixed
624
+ * with "-out" (e.g. "uart-out", "h264-out", ...).
625
*/
626
627
#include "qemu/osdep.h"
628
@@ -XXX,XX +XXX,XX @@ static const TypeInfo cprman_pll_channel_info = {
629
};
630
631
632
+/* clock mux */
633
+
634
+static void clock_mux_update(CprmanClockMuxState *mux)
635
+{
636
+ clock_update(mux->out, 0);
637
+}
638
+
639
+static void clock_mux_src_update(void *opaque)
640
+{
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
+ }
673
+};
674
+
675
+static void clock_mux_class_init(ObjectClass *klass, void *data)
676
+{
677
+ DeviceClass *dc = DEVICE_CLASS(klass);
678
+
679
+ dc->vmsd = &clock_mux_vmstate;
680
+}
681
+
682
+static const TypeInfo cprman_clock_mux_info = {
683
+ .name = TYPE_CPRMAN_CLOCK_MUX,
684
+ .parent = TYPE_DEVICE,
685
+ .instance_size = sizeof(CprmanClockMuxState),
686
+ .class_init = clock_mux_class_init,
687
+ .instance_init = clock_mux_init,
688
+};
689
+
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
}
359
}
696
}
360
}
697
361
698
+static inline void update_mux_from_cm(BCM2835CprmanState *s, size_t idx)
362
@@ -XXX,XX +XXX,XX @@ static void gem_init_register_masks(CadenceGEMState *s)
699
+{
363
unsigned int i;
700
+ size_t i;
364
/* Mask of register bits which are read only */
701
+
365
memset(&s->regs_ro[0], 0, sizeof(s->regs_ro));
702
+ for (i = 0; i < CPRMAN_NUM_CLOCK_MUX; i++) {
366
- s->regs_ro[GEM_NWCTRL] = 0xFFF80000;
703
+ if ((CLOCK_MUX_INIT_INFO[i].cm_offset == idx) ||
367
- s->regs_ro[GEM_NWSTATUS] = 0xFFFFFFFF;
704
+ (CLOCK_MUX_INIT_INFO[i].cm_offset + 4 == idx)) {
368
- s->regs_ro[GEM_DMACFG] = 0x8E00F000;
705
+ /* matches CM_CTL or CM_DIV mux register */
369
- s->regs_ro[GEM_TXSTATUS] = 0xFFFFFE08;
706
+ clock_mux_update(&s->clock_muxes[i]);
370
- s->regs_ro[GEM_RXQBASE] = 0x00000003;
707
+ return;
371
- s->regs_ro[GEM_TXQBASE] = 0x00000003;
708
+ }
372
- s->regs_ro[GEM_RXSTATUS] = 0xFFFFFFF0;
709
+ }
373
- s->regs_ro[GEM_ISR] = 0xFFFFFFFF;
710
+}
374
- s->regs_ro[GEM_IMR] = 0xFFFFFFFF;
711
+
375
- s->regs_ro[GEM_MODID] = 0xFFFFFFFF;
712
#define CASE_PLL_A2W_REGS(pll_) \
376
+ s->regs_ro[R_NWCTRL] = 0xFFF80000;
713
case R_A2W_ ## pll_ ## _CTRL: \
377
+ s->regs_ro[R_NWSTATUS] = 0xFFFFFFFF;
714
case R_A2W_ ## pll_ ## _ANA0: \
378
+ s->regs_ro[R_DMACFG] = 0x8E00F000;
715
@@ -XXX,XX +XXX,XX @@ static void cprman_write(void *opaque, hwaddr offset,
379
+ s->regs_ro[R_TXSTATUS] = 0xFFFFFE08;
716
case R_A2W_PLLB_ARM:
380
+ s->regs_ro[R_RXQBASE] = 0x00000003;
717
update_channel_from_a2w(s, idx);
381
+ s->regs_ro[R_TXQBASE] = 0x00000003;
718
break;
382
+ s->regs_ro[R_RXSTATUS] = 0xFFFFFFF0;
719
+
383
+ s->regs_ro[R_ISR] = 0xFFFFFFFF;
720
+ case R_CM_GNRICCTL ... R_CM_SMIDIV:
384
+ s->regs_ro[R_IMR] = 0xFFFFFFFF;
721
+ case R_CM_TCNTCNT ... R_CM_VECDIV:
385
+ s->regs_ro[R_MODID] = 0xFFFFFFFF;
722
+ case R_CM_PULSECTL ... R_CM_PULSEDIV:
386
for (i = 0; i < s->num_priority_queues; i++) {
723
+ case R_CM_SDCCTL ... R_CM_ARMCTL:
387
- s->regs_ro[GEM_INT_Q1_STATUS + i] = 0xFFFFFFFF;
724
+ case R_CM_AVEOCTL ... R_CM_EMMCDIV:
388
- s->regs_ro[GEM_INT_Q1_ENABLE + i] = 0xFFFFF319;
725
+ case R_CM_EMMC2CTL ... R_CM_EMMC2DIV:
389
- s->regs_ro[GEM_INT_Q1_DISABLE + i] = 0xFFFFF319;
726
+ update_mux_from_cm(s, idx);
390
- s->regs_ro[GEM_INT_Q1_MASK + i] = 0xFFFFFFFF;
727
+ break;
391
+ s->regs_ro[R_INT_Q1_STATUS + i] = 0xFFFFFFFF;
392
+ s->regs_ro[R_INT_Q1_ENABLE + i] = 0xFFFFF319;
393
+ s->regs_ro[R_INT_Q1_DISABLE + i] = 0xFFFFF319;
394
+ s->regs_ro[R_INT_Q1_MASK + i] = 0xFFFFFFFF;
395
}
396
397
/* Mask of register bits which are clear on read */
398
memset(&s->regs_rtc[0], 0, sizeof(s->regs_rtc));
399
- s->regs_rtc[GEM_ISR] = 0xFFFFFFFF;
400
+ s->regs_rtc[R_ISR] = 0xFFFFFFFF;
401
for (i = 0; i < s->num_priority_queues; i++) {
402
- s->regs_rtc[GEM_INT_Q1_STATUS + i] = 0x00000CE6;
403
+ s->regs_rtc[R_INT_Q1_STATUS + i] = 0x00000CE6;
404
}
405
406
/* Mask of register bits which are write 1 to clear */
407
memset(&s->regs_w1c[0], 0, sizeof(s->regs_w1c));
408
- s->regs_w1c[GEM_TXSTATUS] = 0x000001F7;
409
- s->regs_w1c[GEM_RXSTATUS] = 0x0000000F;
410
+ s->regs_w1c[R_TXSTATUS] = 0x000001F7;
411
+ s->regs_w1c[R_RXSTATUS] = 0x0000000F;
412
413
/* Mask of register bits which are write only */
414
memset(&s->regs_wo[0], 0, sizeof(s->regs_wo));
415
- s->regs_wo[GEM_NWCTRL] = 0x00073E60;
416
- s->regs_wo[GEM_IER] = 0x07FFFFFF;
417
- s->regs_wo[GEM_IDR] = 0x07FFFFFF;
418
+ s->regs_wo[R_NWCTRL] = 0x00073E60;
419
+ s->regs_wo[R_IER] = 0x07FFFFFF;
420
+ s->regs_wo[R_IDR] = 0x07FFFFFF;
421
for (i = 0; i < s->num_priority_queues; i++) {
422
- s->regs_wo[GEM_INT_Q1_ENABLE + i] = 0x00000CE6;
423
- s->regs_wo[GEM_INT_Q1_DISABLE + i] = 0x00000CE6;
424
+ s->regs_wo[R_INT_Q1_ENABLE + i] = 0x00000CE6;
425
+ s->regs_wo[R_INT_Q1_DISABLE + i] = 0x00000CE6;
728
}
426
}
729
}
427
}
730
428
731
@@ -XXX,XX +XXX,XX @@ static void cprman_reset(DeviceState *dev)
429
@@ -XXX,XX +XXX,XX @@ static bool gem_can_receive(NetClientState *nc)
732
device_cold_reset(DEVICE(&s->channels[i]));
430
s = qemu_get_nic_opaque(nc);
733
}
431
734
432
/* Do nothing if receive is not enabled. */
735
+ for (i = 0; i < CPRMAN_NUM_CLOCK_MUX; i++) {
433
- if (!(s->regs[GEM_NWCTRL] & GEM_NWCTRL_RXENA)) {
736
+ device_cold_reset(DEVICE(&s->clock_muxes[i]));
434
+ if (!(s->regs[R_NWCTRL] & GEM_NWCTRL_RXENA)) {
737
+ }
435
if (s->can_rx_state != 1) {
738
+
436
s->can_rx_state = 1;
739
clock_update_hz(s->xosc, s->xosc_freq);
437
DB_PRINT("can't receive - no enable\n");
438
@@ -XXX,XX +XXX,XX @@ static void gem_update_int_status(CadenceGEMState *s)
439
{
440
int i;
441
442
- qemu_set_irq(s->irq[0], !!s->regs[GEM_ISR]);
443
+ qemu_set_irq(s->irq[0], !!s->regs[R_ISR]);
444
445
for (i = 1; i < s->num_priority_queues; ++i) {
446
- qemu_set_irq(s->irq[i], !!s->regs[GEM_INT_Q1_STATUS + i - 1]);
447
+ qemu_set_irq(s->irq[i], !!s->regs[R_INT_Q1_STATUS + i - 1]);
448
}
740
}
449
}
741
450
742
@@ -XXX,XX +XXX,XX @@ static void cprman_init(Object *obj)
451
@@ -XXX,XX +XXX,XX @@ static void gem_receive_updatestats(CadenceGEMState *s, const uint8_t *packet,
743
set_pll_channel_init_info(s, &s->channels[i], i);
452
uint64_t octets;
744
}
453
745
454
/* Total octets (bytes) received */
746
+ for (i = 0; i < CPRMAN_NUM_CLOCK_MUX; i++) {
455
- octets = ((uint64_t)(s->regs[GEM_OCTRXLO]) << 32) |
747
+ char *alias;
456
- s->regs[GEM_OCTRXHI];
748
+
457
+ octets = ((uint64_t)(s->regs[R_OCTRXLO]) << 32) |
749
+ object_initialize_child(obj, CLOCK_MUX_INIT_INFO[i].name,
458
+ s->regs[R_OCTRXHI];
750
+ &s->clock_muxes[i],
459
octets += bytes;
751
+ TYPE_CPRMAN_CLOCK_MUX);
460
- s->regs[GEM_OCTRXLO] = octets >> 32;
752
+ set_clock_mux_init_info(s, &s->clock_muxes[i], i);
461
- s->regs[GEM_OCTRXHI] = octets;
753
+
462
+ s->regs[R_OCTRXLO] = octets >> 32;
754
+ /* Expose muxes output as CPRMAN outputs */
463
+ s->regs[R_OCTRXHI] = octets;
755
+ alias = g_strdup_printf("%s-out", CLOCK_MUX_INIT_INFO[i].name);
464
756
+ qdev_alias_clock(DEVICE(&s->clock_muxes[i]), "out", DEVICE(obj), alias);
465
/* Error-free Frames received */
757
+ g_free(alias);
466
- s->regs[GEM_RXCNT]++;
758
+ }
467
+ s->regs[R_RXCNT]++;
759
+
468
760
s->xosc = clock_new(obj, "xosc");
469
/* Error-free Broadcast Frames counter */
761
+ s->gnd = clock_new(obj, "gnd");
470
if (!memcmp(packet, broadcast_addr, 6)) {
762
+
471
- s->regs[GEM_RXBROADCNT]++;
763
+ clock_set(s->gnd, 0);
472
+ s->regs[R_RXBROADCNT]++;
764
473
}
765
memory_region_init_io(&s->iomem, obj, &cprman_ops,
474
766
s, "bcm2835-cprman", 0x2000);
475
/* Error-free Multicast Frames counter */
767
sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->iomem);
476
if (packet[0] == 0x01) {
477
- s->regs[GEM_RXMULTICNT]++;
478
+ s->regs[R_RXMULTICNT]++;
479
}
480
481
if (bytes <= 64) {
482
- s->regs[GEM_RX64CNT]++;
483
+ s->regs[R_RX64CNT]++;
484
} else if (bytes <= 127) {
485
- s->regs[GEM_RX65CNT]++;
486
+ s->regs[R_RX65CNT]++;
487
} else if (bytes <= 255) {
488
- s->regs[GEM_RX128CNT]++;
489
+ s->regs[R_RX128CNT]++;
490
} else if (bytes <= 511) {
491
- s->regs[GEM_RX256CNT]++;
492
+ s->regs[R_RX256CNT]++;
493
} else if (bytes <= 1023) {
494
- s->regs[GEM_RX512CNT]++;
495
+ s->regs[R_RX512CNT]++;
496
} else if (bytes <= 1518) {
497
- s->regs[GEM_RX1024CNT]++;
498
+ s->regs[R_RX1024CNT]++;
499
} else {
500
- s->regs[GEM_RX1519CNT]++;
501
+ s->regs[R_RX1519CNT]++;
502
}
768
}
503
}
769
504
770
+static void connect_mux_sources(BCM2835CprmanState *s,
505
@@ -XXX,XX +XXX,XX @@ static int gem_mac_address_filter(CadenceGEMState *s, const uint8_t *packet)
771
+ CprmanClockMuxState *mux,
506
int i, is_mc;
772
+ const CprmanPllChannel *clk_mapping)
507
773
+{
508
/* Promiscuous mode? */
774
+ size_t i;
509
- if (s->regs[GEM_NWCFG] & GEM_NWCFG_PROMISC) {
775
+ Clock *td0 = s->clock_muxes[CPRMAN_CLOCK_TD0].out;
510
+ if (s->regs[R_NWCFG] & GEM_NWCFG_PROMISC) {
776
+ Clock *td1 = s->clock_muxes[CPRMAN_CLOCK_TD1].out;
511
return GEM_RX_PROMISCUOUS_ACCEPT;
777
+
512
}
778
+ /* For sources from 0 to 3. Source 4 to 9 are mux specific */
513
779
+ Clock * const CLK_SRC_MAPPING[] = {
514
if (!memcmp(packet, broadcast_addr, 6)) {
780
+ [CPRMAN_CLOCK_SRC_GND] = s->gnd,
515
/* Reject broadcast packets? */
781
+ [CPRMAN_CLOCK_SRC_XOSC] = s->xosc,
516
- if (s->regs[GEM_NWCFG] & GEM_NWCFG_BCAST_REJ) {
782
+ [CPRMAN_CLOCK_SRC_TD0] = td0,
517
+ if (s->regs[R_NWCFG] & GEM_NWCFG_BCAST_REJ) {
783
+ [CPRMAN_CLOCK_SRC_TD1] = td1,
518
return GEM_RX_REJECT;
784
+ };
519
}
785
+
520
return GEM_RX_BROADCAST_ACCEPT;
786
+ for (i = 0; i < CPRMAN_NUM_CLOCK_MUX_SRC; i++) {
521
@@ -XXX,XX +XXX,XX @@ static int gem_mac_address_filter(CadenceGEMState *s, const uint8_t *packet)
787
+ CprmanPllChannel mapping = clk_mapping[i];
522
788
+ Clock *src;
523
/* Accept packets -w- hash match? */
789
+
524
is_mc = is_multicast_ether_addr(packet);
790
+ if (mapping == CPRMAN_CLOCK_SRC_FORCE_GROUND) {
525
- if ((is_mc && (s->regs[GEM_NWCFG] & GEM_NWCFG_MCAST_HASH)) ||
791
+ src = s->gnd;
526
- (!is_mc && (s->regs[GEM_NWCFG] & GEM_NWCFG_UCAST_HASH))) {
792
+ } else if (mapping == CPRMAN_CLOCK_SRC_DSI0HSCK) {
527
+ if ((is_mc && (s->regs[R_NWCFG] & GEM_NWCFG_MCAST_HASH)) ||
793
+ src = s->gnd; /* TODO */
528
+ (!is_mc && (s->regs[R_NWCFG] & GEM_NWCFG_UCAST_HASH))) {
794
+ } else if (i < CPRMAN_CLOCK_SRC_PLLA) {
529
uint64_t buckets;
795
+ src = CLK_SRC_MAPPING[i];
530
unsigned hash_index;
796
+ } else {
531
797
+ src = s->channels[mapping].out;
532
hash_index = calc_mac_hash(packet);
798
+ }
533
- buckets = ((uint64_t)s->regs[GEM_HASHHI] << 32) | s->regs[GEM_HASHLO];
799
+
534
+ buckets = ((uint64_t)s->regs[R_HASHHI] << 32) | s->regs[R_HASHLO];
800
+ clock_set_source(mux->srcs[i], src);
535
if ((buckets >> hash_index) & 1) {
801
+ }
536
return is_mc ? GEM_RX_MULTICAST_HASH_ACCEPT
802
+}
537
: GEM_RX_UNICAST_HASH_ACCEPT;
803
+
538
@@ -XXX,XX +XXX,XX @@ static int gem_mac_address_filter(CadenceGEMState *s, const uint8_t *packet)
804
static void cprman_realize(DeviceState *dev, Error **errp)
539
}
540
541
/* Check all 4 specific addresses */
542
- gem_spaddr = (uint8_t *)&(s->regs[GEM_SPADDR1LO]);
543
+ gem_spaddr = (uint8_t *)&(s->regs[R_SPADDR1LO]);
544
for (i = 3; i >= 0; i--) {
545
if (s->sar_active[i] && !memcmp(packet, gem_spaddr + 8 * i, 6)) {
546
return GEM_RX_SAR_ACCEPT + i;
547
@@ -XXX,XX +XXX,XX @@ static int get_queue_from_screen(CadenceGEMState *s, uint8_t *rxbuf_ptr,
548
int i, j;
549
550
for (i = 0; i < s->num_type1_screeners; i++) {
551
- reg = s->regs[GEM_SCREENING_TYPE1_REGISTER_0 + i];
552
+ reg = s->regs[R_SCREENING_TYPE1_REG0 + i];
553
matched = false;
554
mismatched = false;
555
556
@@ -XXX,XX +XXX,XX @@ static int get_queue_from_screen(CadenceGEMState *s, uint8_t *rxbuf_ptr,
557
}
558
559
for (i = 0; i < s->num_type2_screeners; i++) {
560
- reg = s->regs[GEM_SCREENING_TYPE2_REGISTER_0 + i];
561
+ reg = s->regs[R_SCREENING_TYPE2_REG0 + i];
562
matched = false;
563
mismatched = false;
564
565
@@ -XXX,XX +XXX,XX @@ static int get_queue_from_screen(CadenceGEMState *s, uint8_t *rxbuf_ptr,
566
qemu_log_mask(LOG_GUEST_ERROR, "Out of range ethertype "
567
"register index: %d\n", et_idx);
568
}
569
- if (type == s->regs[GEM_SCREENING_TYPE2_ETHERTYPE_REG_0 +
570
+ if (type == s->regs[R_SCREENING_TYPE2_ETHERTYPE_REG0 +
571
et_idx]) {
572
matched = true;
573
} else {
574
@@ -XXX,XX +XXX,XX @@ static int get_queue_from_screen(CadenceGEMState *s, uint8_t *rxbuf_ptr,
575
"register index: %d\n", cr_idx);
576
}
577
578
- cr0 = s->regs[GEM_TYPE2_COMPARE_0_WORD_0 + cr_idx * 2];
579
- cr1 = s->regs[GEM_TYPE2_COMPARE_0_WORD_0 + cr_idx * 2 + 1];
580
+ cr0 = s->regs[R_TYPE2_COMPARE_0_WORD_0 + cr_idx * 2];
581
+ cr1 = s->regs[R_TYPE2_COMPARE_0_WORD_0 + cr_idx * 2 + 1];
582
offset = extract32(cr1, GEM_T2CW1_OFFSET_VALUE_SHIFT,
583
GEM_T2CW1_OFFSET_VALUE_WIDTH);
584
585
@@ -XXX,XX +XXX,XX @@ static uint32_t gem_get_queue_base_addr(CadenceGEMState *s, bool tx, int q)
586
587
switch (q) {
588
case 0:
589
- base_addr = s->regs[tx ? GEM_TXQBASE : GEM_RXQBASE];
590
+ base_addr = s->regs[tx ? R_TXQBASE : R_RXQBASE];
591
break;
592
case 1 ... (MAX_PRIORITY_QUEUES - 1):
593
- base_addr = s->regs[(tx ? GEM_TRANSMIT_Q1_PTR :
594
- GEM_RECEIVE_Q1_PTR) + q - 1];
595
+ base_addr = s->regs[(tx ? R_TRANSMIT_Q1_PTR :
596
+ R_RECEIVE_Q1_PTR) + q - 1];
597
break;
598
default:
599
g_assert_not_reached();
600
@@ -XXX,XX +XXX,XX @@ static hwaddr gem_get_desc_addr(CadenceGEMState *s, bool tx, int q)
805
{
601
{
806
BCM2835CprmanState *s = CPRMAN(dev);
602
hwaddr desc_addr = 0;
807
@@ -XXX,XX +XXX,XX @@ static void cprman_realize(DeviceState *dev, Error **errp)
603
808
return;
604
- if (s->regs[GEM_DMACFG] & GEM_DMACFG_ADDR_64B) {
605
- desc_addr = s->regs[tx ? GEM_TBQPH : GEM_RBQPH];
606
+ if (s->regs[R_DMACFG] & GEM_DMACFG_ADDR_64B) {
607
+ desc_addr = s->regs[tx ? R_TBQPH : R_RBQPH];
608
}
609
desc_addr <<= 32;
610
desc_addr |= tx ? s->tx_desc_addr[q] : s->rx_desc_addr[q];
611
@@ -XXX,XX +XXX,XX @@ static void gem_get_rx_desc(CadenceGEMState *s, int q)
612
/* Descriptor owned by software ? */
613
if (rx_desc_get_ownership(s->rx_desc[q]) == 1) {
614
DB_PRINT("descriptor 0x%" HWADDR_PRIx " owned by sw.\n", desc_addr);
615
- s->regs[GEM_RXSTATUS] |= GEM_RXSTATUS_NOBUF;
616
+ s->regs[R_RXSTATUS] |= GEM_RXSTATUS_NOBUF;
617
gem_set_isr(s, q, GEM_INT_RXUSED);
618
/* Handle interrupt consequences */
619
gem_update_int_status(s);
620
@@ -XXX,XX +XXX,XX @@ static ssize_t gem_receive(NetClientState *nc, const uint8_t *buf, size_t size)
621
}
622
623
/* Discard packets with receive length error enabled ? */
624
- if (s->regs[GEM_NWCFG] & GEM_NWCFG_LERR_DISC) {
625
+ if (s->regs[R_NWCFG] & GEM_NWCFG_LERR_DISC) {
626
unsigned type_len;
627
628
/* Fish the ethertype / length field out of the RX packet */
629
@@ -XXX,XX +XXX,XX @@ static ssize_t gem_receive(NetClientState *nc, const uint8_t *buf, size_t size)
630
/*
631
* Determine configured receive buffer offset (probably 0)
632
*/
633
- rxbuf_offset = (s->regs[GEM_NWCFG] & GEM_NWCFG_BUFF_OFST_M) >>
634
+ rxbuf_offset = (s->regs[R_NWCFG] & GEM_NWCFG_BUFF_OFST_M) >>
635
GEM_NWCFG_BUFF_OFST_S;
636
637
/* The configure size of each receive buffer. Determines how many
638
* buffers needed to hold this packet.
639
*/
640
- rxbufsize = ((s->regs[GEM_DMACFG] & GEM_DMACFG_RBUFSZ_M) >>
641
+ rxbufsize = ((s->regs[R_DMACFG] & GEM_DMACFG_RBUFSZ_M) >>
642
GEM_DMACFG_RBUFSZ_S) * GEM_DMACFG_RBUFSZ_MUL;
643
bytes_to_copy = size;
644
645
@@ -XXX,XX +XXX,XX @@ static ssize_t gem_receive(NetClientState *nc, const uint8_t *buf, size_t size)
646
}
647
648
/* Strip of FCS field ? (usually yes) */
649
- if (s->regs[GEM_NWCFG] & GEM_NWCFG_STRIP_FCS) {
650
+ if (s->regs[R_NWCFG] & GEM_NWCFG_STRIP_FCS) {
651
rxbuf_ptr = (void *)buf;
652
} else {
653
unsigned crc_val;
654
@@ -XXX,XX +XXX,XX @@ static ssize_t gem_receive(NetClientState *nc, const uint8_t *buf, size_t size)
655
/* Count it */
656
gem_receive_updatestats(s, buf, size);
657
658
- s->regs[GEM_RXSTATUS] |= GEM_RXSTATUS_FRMRCVD;
659
+ s->regs[R_RXSTATUS] |= GEM_RXSTATUS_FRMRCVD;
660
gem_set_isr(s, q, GEM_INT_RXCMPL);
661
662
/* Handle interrupt consequences */
663
@@ -XXX,XX +XXX,XX @@ static void gem_transmit_updatestats(CadenceGEMState *s, const uint8_t *packet,
664
uint64_t octets;
665
666
/* Total octets (bytes) transmitted */
667
- octets = ((uint64_t)(s->regs[GEM_OCTTXLO]) << 32) |
668
- s->regs[GEM_OCTTXHI];
669
+ octets = ((uint64_t)(s->regs[R_OCTTXLO]) << 32) |
670
+ s->regs[R_OCTTXHI];
671
octets += bytes;
672
- s->regs[GEM_OCTTXLO] = octets >> 32;
673
- s->regs[GEM_OCTTXHI] = octets;
674
+ s->regs[R_OCTTXLO] = octets >> 32;
675
+ s->regs[R_OCTTXHI] = octets;
676
677
/* Error-free Frames transmitted */
678
- s->regs[GEM_TXCNT]++;
679
+ s->regs[R_TXCNT]++;
680
681
/* Error-free Broadcast Frames counter */
682
if (!memcmp(packet, broadcast_addr, 6)) {
683
- s->regs[GEM_TXBCNT]++;
684
+ s->regs[R_TXBCNT]++;
685
}
686
687
/* Error-free Multicast Frames counter */
688
if (packet[0] == 0x01) {
689
- s->regs[GEM_TXMCNT]++;
690
+ s->regs[R_TXMCNT]++;
691
}
692
693
if (bytes <= 64) {
694
- s->regs[GEM_TX64CNT]++;
695
+ s->regs[R_TX64CNT]++;
696
} else if (bytes <= 127) {
697
- s->regs[GEM_TX65CNT]++;
698
+ s->regs[R_TX65CNT]++;
699
} else if (bytes <= 255) {
700
- s->regs[GEM_TX128CNT]++;
701
+ s->regs[R_TX128CNT]++;
702
} else if (bytes <= 511) {
703
- s->regs[GEM_TX256CNT]++;
704
+ s->regs[R_TX256CNT]++;
705
} else if (bytes <= 1023) {
706
- s->regs[GEM_TX512CNT]++;
707
+ s->regs[R_TX512CNT]++;
708
} else if (bytes <= 1518) {
709
- s->regs[GEM_TX1024CNT]++;
710
+ s->regs[R_TX1024CNT]++;
711
} else {
712
- s->regs[GEM_TX1519CNT]++;
713
+ s->regs[R_TX1519CNT]++;
714
}
715
}
716
717
@@ -XXX,XX +XXX,XX @@ static void gem_transmit(CadenceGEMState *s)
718
int q = 0;
719
720
/* Do nothing if transmit is not enabled. */
721
- if (!(s->regs[GEM_NWCTRL] & GEM_NWCTRL_TXENA)) {
722
+ if (!(s->regs[R_NWCTRL] & GEM_NWCTRL_TXENA)) {
723
return;
724
}
725
726
@@ -XXX,XX +XXX,XX @@ static void gem_transmit(CadenceGEMState *s)
727
while (tx_desc_get_used(desc) == 0) {
728
729
/* Do nothing if transmit is not enabled. */
730
- if (!(s->regs[GEM_NWCTRL] & GEM_NWCTRL_TXENA)) {
731
+ if (!(s->regs[R_NWCTRL] & GEM_NWCTRL_TXENA)) {
732
return;
733
}
734
print_gem_tx_desc(desc, q);
735
@@ -XXX,XX +XXX,XX @@ static void gem_transmit(CadenceGEMState *s)
736
}
737
DB_PRINT("TX descriptor next: 0x%08x\n", s->tx_desc_addr[q]);
738
739
- s->regs[GEM_TXSTATUS] |= GEM_TXSTATUS_TXCMPL;
740
+ s->regs[R_TXSTATUS] |= GEM_TXSTATUS_TXCMPL;
741
gem_set_isr(s, q, GEM_INT_TXCMPL);
742
743
/* Handle interrupt consequences */
744
gem_update_int_status(s);
745
746
/* Is checksum offload enabled? */
747
- if (s->regs[GEM_DMACFG] & GEM_DMACFG_TXCSUM_OFFL) {
748
+ if (s->regs[R_DMACFG] & GEM_DMACFG_TXCSUM_OFFL) {
749
net_checksum_calculate(s->tx_packet, total_bytes, CSUM_ALL);
750
}
751
752
@@ -XXX,XX +XXX,XX @@ static void gem_transmit(CadenceGEMState *s)
753
gem_transmit_updatestats(s, s->tx_packet, total_bytes);
754
755
/* Send the packet somewhere */
756
- if (s->phy_loop || (s->regs[GEM_NWCTRL] &
757
+ if (s->phy_loop || (s->regs[R_NWCTRL] &
758
GEM_NWCTRL_LOCALLOOP)) {
759
qemu_receive_packet(qemu_get_queue(s->nic), s->tx_packet,
760
total_bytes);
761
@@ -XXX,XX +XXX,XX @@ static void gem_transmit(CadenceGEMState *s)
762
763
/* read next descriptor */
764
if (tx_desc_get_wrap(desc)) {
765
-
766
- if (s->regs[GEM_DMACFG] & GEM_DMACFG_ADDR_64B) {
767
- packet_desc_addr = s->regs[GEM_TBQPH];
768
+ if (s->regs[R_DMACFG] & GEM_DMACFG_ADDR_64B) {
769
+ packet_desc_addr = s->regs[R_TBQPH];
770
packet_desc_addr <<= 32;
771
} else {
772
packet_desc_addr = 0;
773
@@ -XXX,XX +XXX,XX @@ static void gem_transmit(CadenceGEMState *s)
809
}
774
}
810
}
775
811
+
776
if (tx_desc_get_used(desc)) {
812
+ for (i = 0; i < CPRMAN_NUM_CLOCK_MUX; i++) {
777
- s->regs[GEM_TXSTATUS] |= GEM_TXSTATUS_USED;
813
+ CprmanClockMuxState *clock_mux = &s->clock_muxes[i];
778
+ s->regs[R_TXSTATUS] |= GEM_TXSTATUS_USED;
814
+
779
/* IRQ TXUSED is defined only for queue 0 */
815
+ connect_mux_sources(s, clock_mux, CLOCK_MUX_INIT_INFO[i].src_mapping);
780
if (q == 0) {
816
+
781
gem_set_isr(s, 0, GEM_INT_TXUSED);
817
+ if (!qdev_realize(DEVICE(clock_mux), NULL, errp)) {
782
@@ -XXX,XX +XXX,XX @@ static void gem_reset(DeviceState *d)
818
+ return;
783
819
+ }
784
/* Set post reset register values */
820
+ }
785
memset(&s->regs[0], 0, sizeof(s->regs));
821
}
786
- s->regs[GEM_NWCFG] = 0x00080000;
822
787
- s->regs[GEM_NWSTATUS] = 0x00000006;
823
static const VMStateDescription cprman_vmstate = {
788
- s->regs[GEM_DMACFG] = 0x00020784;
824
@@ -XXX,XX +XXX,XX @@ static void cprman_register_types(void)
789
- s->regs[GEM_IMR] = 0x07ffffff;
825
type_register_static(&cprman_info);
790
- s->regs[GEM_TXPAUSE] = 0x0000ffff;
826
type_register_static(&cprman_pll_info);
791
- s->regs[GEM_TXPARTIALSF] = 0x000003ff;
827
type_register_static(&cprman_pll_channel_info);
792
- s->regs[GEM_RXPARTIALSF] = 0x000003ff;
828
+ type_register_static(&cprman_clock_mux_info);
793
- s->regs[GEM_MODID] = s->revision;
829
}
794
- s->regs[GEM_DESCONF] = 0x02D00111;
830
795
- s->regs[GEM_DESCONF2] = 0x2ab10000 | s->jumbo_max_len;
831
type_init(cprman_register_types);
796
- s->regs[GEM_DESCONF5] = 0x002f2045;
797
- s->regs[GEM_DESCONF6] = GEM_DESCONF6_64B_MASK;
798
- s->regs[GEM_INT_Q1_MASK] = 0x00000CE6;
799
- s->regs[GEM_JUMBO_MAX_LEN] = s->jumbo_max_len;
800
+ s->regs[R_NWCFG] = 0x00080000;
801
+ s->regs[R_NWSTATUS] = 0x00000006;
802
+ s->regs[R_DMACFG] = 0x00020784;
803
+ s->regs[R_IMR] = 0x07ffffff;
804
+ s->regs[R_TXPAUSE] = 0x0000ffff;
805
+ s->regs[R_TXPARTIALSF] = 0x000003ff;
806
+ s->regs[R_RXPARTIALSF] = 0x000003ff;
807
+ s->regs[R_MODID] = s->revision;
808
+ s->regs[R_DESCONF] = 0x02D00111;
809
+ s->regs[R_DESCONF2] = 0x2ab10000 | s->jumbo_max_len;
810
+ s->regs[R_DESCONF5] = 0x002f2045;
811
+ s->regs[R_DESCONF6] = GEM_DESCONF6_64B_MASK;
812
+ s->regs[R_INT_Q1_MASK] = 0x00000CE6;
813
+ s->regs[R_JUMBO_MAX_LEN] = s->jumbo_max_len;
814
815
if (s->num_priority_queues > 1) {
816
queues_mask = MAKE_64BIT_MASK(1, s->num_priority_queues - 1);
817
- s->regs[GEM_DESCONF6] |= queues_mask;
818
+ s->regs[R_DESCONF6] |= queues_mask;
819
}
820
821
/* Set MAC address */
822
a = &s->conf.macaddr.a[0];
823
- s->regs[GEM_SPADDR1LO] = a[0] | (a[1] << 8) | (a[2] << 16) | (a[3] << 24);
824
- s->regs[GEM_SPADDR1HI] = a[4] | (a[5] << 8);
825
+ s->regs[R_SPADDR1LO] = a[0] | (a[1] << 8) | (a[2] << 16) | (a[3] << 24);
826
+ s->regs[R_SPADDR1HI] = a[4] | (a[5] << 8);
827
828
for (i = 0; i < 4; i++) {
829
s->sar_active[i] = false;
830
@@ -XXX,XX +XXX,XX @@ static uint64_t gem_read(void *opaque, hwaddr offset, unsigned size)
831
DB_PRINT("offset: 0x%04x read: 0x%08x\n", (unsigned)offset*4, retval);
832
833
switch (offset) {
834
- case GEM_ISR:
835
+ case R_ISR:
836
DB_PRINT("lowering irqs on ISR read\n");
837
/* The interrupts get updated at the end of the function. */
838
break;
839
- case GEM_PHYMNTNC:
840
+ case R_PHYMNTNC:
841
if (retval & GEM_PHYMNTNC_OP_R) {
842
uint32_t phy_addr, reg_num;
843
844
@@ -XXX,XX +XXX,XX @@ static void gem_write(void *opaque, hwaddr offset, uint64_t val,
845
846
/* Handle register write side effects */
847
switch (offset) {
848
- case GEM_NWCTRL:
849
+ case R_NWCTRL:
850
if (val & GEM_NWCTRL_RXENA) {
851
for (i = 0; i < s->num_priority_queues; ++i) {
852
gem_get_rx_desc(s, i);
853
@@ -XXX,XX +XXX,XX @@ static void gem_write(void *opaque, hwaddr offset, uint64_t val,
854
}
855
break;
856
857
- case GEM_TXSTATUS:
858
+ case R_TXSTATUS:
859
gem_update_int_status(s);
860
break;
861
- case GEM_RXQBASE:
862
+ case R_RXQBASE:
863
s->rx_desc_addr[0] = val;
864
break;
865
- case GEM_RECEIVE_Q1_PTR ... GEM_RECEIVE_Q7_PTR:
866
- s->rx_desc_addr[offset - GEM_RECEIVE_Q1_PTR + 1] = val;
867
+ case R_RECEIVE_Q1_PTR ... R_RECEIVE_Q7_PTR:
868
+ s->rx_desc_addr[offset - R_RECEIVE_Q1_PTR + 1] = val;
869
break;
870
- case GEM_TXQBASE:
871
+ case R_TXQBASE:
872
s->tx_desc_addr[0] = val;
873
break;
874
- case GEM_TRANSMIT_Q1_PTR ... GEM_TRANSMIT_Q7_PTR:
875
- s->tx_desc_addr[offset - GEM_TRANSMIT_Q1_PTR + 1] = val;
876
+ case R_TRANSMIT_Q1_PTR ... R_TRANSMIT_Q7_PTR:
877
+ s->tx_desc_addr[offset - R_TRANSMIT_Q1_PTR + 1] = val;
878
break;
879
- case GEM_RXSTATUS:
880
+ case R_RXSTATUS:
881
gem_update_int_status(s);
882
break;
883
- case GEM_IER:
884
- s->regs[GEM_IMR] &= ~val;
885
+ case R_IER:
886
+ s->regs[R_IMR] &= ~val;
887
gem_update_int_status(s);
888
break;
889
- case GEM_JUMBO_MAX_LEN:
890
- s->regs[GEM_JUMBO_MAX_LEN] = val & MAX_JUMBO_FRAME_SIZE_MASK;
891
+ case R_JUMBO_MAX_LEN:
892
+ s->regs[R_JUMBO_MAX_LEN] = val & MAX_JUMBO_FRAME_SIZE_MASK;
893
break;
894
- case GEM_INT_Q1_ENABLE ... GEM_INT_Q7_ENABLE:
895
- s->regs[GEM_INT_Q1_MASK + offset - GEM_INT_Q1_ENABLE] &= ~val;
896
+ case R_INT_Q1_ENABLE ... R_INT_Q7_ENABLE:
897
+ s->regs[R_INT_Q1_MASK + offset - R_INT_Q1_ENABLE] &= ~val;
898
gem_update_int_status(s);
899
break;
900
- case GEM_IDR:
901
- s->regs[GEM_IMR] |= val;
902
+ case R_IDR:
903
+ s->regs[R_IMR] |= val;
904
gem_update_int_status(s);
905
break;
906
- case GEM_INT_Q1_DISABLE ... GEM_INT_Q7_DISABLE:
907
- s->regs[GEM_INT_Q1_MASK + offset - GEM_INT_Q1_DISABLE] |= val;
908
+ case R_INT_Q1_DISABLE ... R_INT_Q7_DISABLE:
909
+ s->regs[R_INT_Q1_MASK + offset - R_INT_Q1_DISABLE] |= val;
910
gem_update_int_status(s);
911
break;
912
- case GEM_SPADDR1LO:
913
- case GEM_SPADDR2LO:
914
- case GEM_SPADDR3LO:
915
- case GEM_SPADDR4LO:
916
- s->sar_active[(offset - GEM_SPADDR1LO) / 2] = false;
917
+ case R_SPADDR1LO:
918
+ case R_SPADDR2LO:
919
+ case R_SPADDR3LO:
920
+ case R_SPADDR4LO:
921
+ s->sar_active[(offset - R_SPADDR1LO) / 2] = false;
922
break;
923
- case GEM_SPADDR1HI:
924
- case GEM_SPADDR2HI:
925
- case GEM_SPADDR3HI:
926
- case GEM_SPADDR4HI:
927
- s->sar_active[(offset - GEM_SPADDR1HI) / 2] = true;
928
+ case R_SPADDR1HI:
929
+ case R_SPADDR2HI:
930
+ case R_SPADDR3HI:
931
+ case R_SPADDR4HI:
932
+ s->sar_active[(offset - R_SPADDR1HI) / 2] = true;
933
break;
934
- case GEM_PHYMNTNC:
935
+ case R_PHYMNTNC:
936
if (val & GEM_PHYMNTNC_OP_W) {
937
uint32_t phy_addr, reg_num;
938
832
--
939
--
833
2.20.1
940
2.34.1
834
835
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Luc Michel <luc.michel@amd.com>
2
2
3
For BTI, we need to know if the executable is static or dynamic,
3
Describe screening registers fields using the FIELD macros.
4
which means looking for PT_INTERP earlier.
5
4
6
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
5
Signed-off-by: Luc Michel <luc.michel@amd.com>
7
Message-id: 20201021173749.111103-8-richard.henderson@linaro.org
6
Reviewed-by: sai.pavan.boddu@amd.com
8
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
7
Message-id: 20231017194422.4124691-3-luc.michel@amd.com
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
---
9
---
11
linux-user/elfload.c | 60 +++++++++++++++++++++++---------------------
10
hw/net/cadence_gem.c | 94 ++++++++++++++++++++++----------------------
12
1 file changed, 31 insertions(+), 29 deletions(-)
11
1 file changed, 48 insertions(+), 46 deletions(-)
13
12
14
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
13
diff --git a/hw/net/cadence_gem.c b/hw/net/cadence_gem.c
15
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
16
--- a/linux-user/elfload.c
15
--- a/hw/net/cadence_gem.c
17
+++ b/linux-user/elfload.c
16
+++ b/hw/net/cadence_gem.c
18
@@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd,
17
@@ -XXX,XX +XXX,XX @@ REG32(INT_Q1_DISABLE, 0x620)
19
18
REG32(INT_Q7_DISABLE, 0x638)
20
mmap_lock();
19
21
20
REG32(SCREENING_TYPE1_REG0, 0x500)
22
- /* Find the maximum size of the image and allocate an appropriate
21
-
23
- amount of memory to handle that. */
22
-#define GEM_ST1R_UDP_PORT_MATCH_ENABLE (1 << 29)
24
+ /*
23
-#define GEM_ST1R_DSTC_ENABLE (1 << 28)
25
+ * Find the maximum size of the image and allocate an appropriate
24
-#define GEM_ST1R_UDP_PORT_MATCH_SHIFT (12)
26
+ * amount of memory to handle that. Locate the interpreter, if any.
25
-#define GEM_ST1R_UDP_PORT_MATCH_WIDTH (27 - GEM_ST1R_UDP_PORT_MATCH_SHIFT + 1)
27
+ */
26
-#define GEM_ST1R_DSTC_MATCH_SHIFT (4)
28
loaddr = -1, hiaddr = 0;
27
-#define GEM_ST1R_DSTC_MATCH_WIDTH (11 - GEM_ST1R_DSTC_MATCH_SHIFT + 1)
29
info->alignment = 0;
28
-#define GEM_ST1R_QUEUE_SHIFT (0)
30
for (i = 0; i < ehdr->e_phnum; ++i) {
29
-#define GEM_ST1R_QUEUE_WIDTH (3 - GEM_ST1R_QUEUE_SHIFT + 1)
31
@@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd,
30
+ FIELD(SCREENING_TYPE1_REG0, QUEUE_NUM, 0, 4)
32
}
31
+ FIELD(SCREENING_TYPE1_REG0, DSTC_MATCH, 4, 8)
33
++info->nsegs;
32
+ FIELD(SCREENING_TYPE1_REG0, UDP_PORT_MATCH, 12, 16)
34
info->alignment |= eppnt->p_align;
33
+ FIELD(SCREENING_TYPE1_REG0, DSTC_ENABLE, 28, 1)
35
+ } else if (eppnt->p_type == PT_INTERP && pinterp_name) {
34
+ FIELD(SCREENING_TYPE1_REG0, UDP_PORT_MATCH_EN, 29, 1)
36
+ g_autofree char *interp_name = NULL;
35
+ FIELD(SCREENING_TYPE1_REG0, DROP_ON_MATCH, 30, 1)
36
37
REG32(SCREENING_TYPE2_REG0, 0x540)
38
-
39
-#define GEM_ST2R_COMPARE_A_ENABLE (1 << 18)
40
-#define GEM_ST2R_COMPARE_A_SHIFT (13)
41
-#define GEM_ST2R_COMPARE_WIDTH (17 - GEM_ST2R_COMPARE_A_SHIFT + 1)
42
-#define GEM_ST2R_ETHERTYPE_ENABLE (1 << 12)
43
-#define GEM_ST2R_ETHERTYPE_INDEX_SHIFT (9)
44
-#define GEM_ST2R_ETHERTYPE_INDEX_WIDTH (11 - GEM_ST2R_ETHERTYPE_INDEX_SHIFT \
45
- + 1)
46
-#define GEM_ST2R_QUEUE_SHIFT (0)
47
-#define GEM_ST2R_QUEUE_WIDTH (3 - GEM_ST2R_QUEUE_SHIFT + 1)
48
+ FIELD(SCREENING_TYPE2_REG0, QUEUE_NUM, 0, 4)
49
+ FIELD(SCREENING_TYPE2_REG0, VLAN_PRIORITY, 4, 3)
50
+ FIELD(SCREENING_TYPE2_REG0, VLAN_ENABLE, 8, 1)
51
+ FIELD(SCREENING_TYPE2_REG0, ETHERTYPE_REG_INDEX, 9, 3)
52
+ FIELD(SCREENING_TYPE2_REG0, ETHERTYPE_ENABLE, 12, 1)
53
+ FIELD(SCREENING_TYPE2_REG0, COMPARE_A, 13, 5)
54
+ FIELD(SCREENING_TYPE2_REG0, COMPARE_A_ENABLE, 18, 1)
55
+ FIELD(SCREENING_TYPE2_REG0, COMPARE_B, 19, 5)
56
+ FIELD(SCREENING_TYPE2_REG0, COMPARE_B_ENABLE, 24, 1)
57
+ FIELD(SCREENING_TYPE2_REG0, COMPARE_C, 25, 5)
58
+ FIELD(SCREENING_TYPE2_REG0, COMPARE_C_ENABLE, 30, 1)
59
+ FIELD(SCREENING_TYPE2_REG0, DROP_ON_MATCH, 31, 1)
60
61
REG32(SCREENING_TYPE2_ETHERTYPE_REG0, 0x6e0)
62
-REG32(TYPE2_COMPARE_0_WORD_0, 0x700)
63
64
-#define GEM_T2CW1_COMPARE_OFFSET_SHIFT (7)
65
-#define GEM_T2CW1_COMPARE_OFFSET_WIDTH (8 - GEM_T2CW1_COMPARE_OFFSET_SHIFT + 1)
66
-#define GEM_T2CW1_OFFSET_VALUE_SHIFT (0)
67
-#define GEM_T2CW1_OFFSET_VALUE_WIDTH (6 - GEM_T2CW1_OFFSET_VALUE_SHIFT + 1)
68
+REG32(TYPE2_COMPARE_0_WORD_0, 0x700)
69
+ FIELD(TYPE2_COMPARE_0_WORD_0, MASK_VALUE, 0, 16)
70
+ FIELD(TYPE2_COMPARE_0_WORD_0, COMPARE_VALUE, 16, 16)
37
+
71
+
38
+ if (*pinterp_name) {
72
+REG32(TYPE2_COMPARE_0_WORD_1, 0x704)
39
+ errmsg = "Multiple PT_INTERP entries";
73
+ FIELD(TYPE2_COMPARE_0_WORD_1, OFFSET_VALUE, 0, 7)
40
+ goto exit_errmsg;
74
+ FIELD(TYPE2_COMPARE_0_WORD_1, COMPARE_OFFSET, 7, 2)
41
+ }
75
+ FIELD(TYPE2_COMPARE_0_WORD_1, DISABLE_MASK, 9, 1)
42
+ interp_name = g_malloc(eppnt->p_filesz);
76
+ FIELD(TYPE2_COMPARE_0_WORD_1, COMPARE_VLAN_ID, 10, 1)
43
+ if (!interp_name) {
77
44
+ goto exit_perror;
78
/*****************************************/
45
+ }
79
#define GEM_NWCTRL_TXSTART 0x00000200 /* Transmit Enable */
46
+
80
@@ -XXX,XX +XXX,XX @@ static int get_queue_from_screen(CadenceGEMState *s, uint8_t *rxbuf_ptr,
47
+ if (eppnt->p_offset + eppnt->p_filesz <= BPRM_BUF_SIZE) {
81
mismatched = false;
48
+ memcpy(interp_name, bprm_buf + eppnt->p_offset,
82
49
+ eppnt->p_filesz);
83
/* Screening is based on UDP Port */
50
+ } else {
84
- if (reg & GEM_ST1R_UDP_PORT_MATCH_ENABLE) {
51
+ retval = pread(image_fd, interp_name, eppnt->p_filesz,
85
+ if (FIELD_EX32(reg, SCREENING_TYPE1_REG0, UDP_PORT_MATCH_EN)) {
52
+ eppnt->p_offset);
86
uint16_t udp_port = rxbuf_ptr[14 + 22] << 8 | rxbuf_ptr[14 + 23];
53
+ if (retval != eppnt->p_filesz) {
87
- if (udp_port == extract32(reg, GEM_ST1R_UDP_PORT_MATCH_SHIFT,
54
+ goto exit_perror;
88
- GEM_ST1R_UDP_PORT_MATCH_WIDTH)) {
55
+ }
89
+ if (udp_port == FIELD_EX32(reg, SCREENING_TYPE1_REG0, UDP_PORT_MATCH)) {
56
+ }
90
matched = true;
57
+ if (interp_name[eppnt->p_filesz - 1] != 0) {
91
} else {
58
+ errmsg = "Invalid PT_INTERP entry";
92
mismatched = true;
59
+ goto exit_errmsg;
93
@@ -XXX,XX +XXX,XX @@ static int get_queue_from_screen(CadenceGEMState *s, uint8_t *rxbuf_ptr,
60
+ }
94
}
61
+ *pinterp_name = g_steal_pointer(&interp_name);
95
96
/* Screening is based on DS/TC */
97
- if (reg & GEM_ST1R_DSTC_ENABLE) {
98
+ if (FIELD_EX32(reg, SCREENING_TYPE1_REG0, DSTC_ENABLE)) {
99
uint8_t dscp = rxbuf_ptr[14 + 1];
100
- if (dscp == extract32(reg, GEM_ST1R_DSTC_MATCH_SHIFT,
101
- GEM_ST1R_DSTC_MATCH_WIDTH)) {
102
+ if (dscp == FIELD_EX32(reg, SCREENING_TYPE1_REG0, DSTC_MATCH)) {
103
matched = true;
104
} else {
105
mismatched = true;
106
@@ -XXX,XX +XXX,XX @@ static int get_queue_from_screen(CadenceGEMState *s, uint8_t *rxbuf_ptr,
107
}
108
109
if (matched && !mismatched) {
110
- return extract32(reg, GEM_ST1R_QUEUE_SHIFT, GEM_ST1R_QUEUE_WIDTH);
111
+ return FIELD_EX32(reg, SCREENING_TYPE1_REG0, QUEUE_NUM);
62
}
112
}
63
}
113
}
64
114
65
@@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd,
115
@@ -XXX,XX +XXX,XX @@ static int get_queue_from_screen(CadenceGEMState *s, uint8_t *rxbuf_ptr,
66
if (vaddr_em > info->brk) {
116
matched = false;
67
info->brk = vaddr_em;
117
mismatched = false;
118
119
- if (reg & GEM_ST2R_ETHERTYPE_ENABLE) {
120
+ if (FIELD_EX32(reg, SCREENING_TYPE2_REG0, ETHERTYPE_ENABLE)) {
121
uint16_t type = rxbuf_ptr[12] << 8 | rxbuf_ptr[13];
122
- int et_idx = extract32(reg, GEM_ST2R_ETHERTYPE_INDEX_SHIFT,
123
- GEM_ST2R_ETHERTYPE_INDEX_WIDTH);
124
+ int et_idx = FIELD_EX32(reg, SCREENING_TYPE2_REG0,
125
+ ETHERTYPE_REG_INDEX);
126
127
if (et_idx > s->num_type2_screeners) {
128
qemu_log_mask(LOG_GUEST_ERROR, "Out of range ethertype "
129
@@ -XXX,XX +XXX,XX @@ static int get_queue_from_screen(CadenceGEMState *s, uint8_t *rxbuf_ptr,
130
131
/* Compare A, B, C */
132
for (j = 0; j < 3; j++) {
133
- uint32_t cr0, cr1, mask;
134
+ uint32_t cr0, cr1, mask, compare;
135
uint16_t rx_cmp;
136
int offset;
137
- int cr_idx = extract32(reg, GEM_ST2R_COMPARE_A_SHIFT + j * 6,
138
- GEM_ST2R_COMPARE_WIDTH);
139
+ int cr_idx = extract32(reg, R_SCREENING_TYPE2_REG0_COMPARE_A_SHIFT + j * 6,
140
+ R_SCREENING_TYPE2_REG0_COMPARE_A_LENGTH);
141
142
- if (!(reg & (GEM_ST2R_COMPARE_A_ENABLE << (j * 6)))) {
143
+ if (!extract32(reg, R_SCREENING_TYPE2_REG0_COMPARE_A_ENABLE_SHIFT + j * 6,
144
+ R_SCREENING_TYPE2_REG0_COMPARE_A_ENABLE_LENGTH)) {
145
continue;
68
}
146
}
69
- } else if (eppnt->p_type == PT_INTERP && pinterp_name) {
147
+
70
- g_autofree char *interp_name = NULL;
148
if (cr_idx > s->num_type2_screeners) {
71
-
149
qemu_log_mask(LOG_GUEST_ERROR, "Out of range compare "
72
- if (*pinterp_name) {
150
"register index: %d\n", cr_idx);
73
- errmsg = "Multiple PT_INTERP entries";
151
}
74
- goto exit_errmsg;
152
75
- }
153
cr0 = s->regs[R_TYPE2_COMPARE_0_WORD_0 + cr_idx * 2];
76
- interp_name = g_malloc(eppnt->p_filesz);
154
- cr1 = s->regs[R_TYPE2_COMPARE_0_WORD_0 + cr_idx * 2 + 1];
77
- if (!interp_name) {
155
- offset = extract32(cr1, GEM_T2CW1_OFFSET_VALUE_SHIFT,
78
- goto exit_perror;
156
- GEM_T2CW1_OFFSET_VALUE_WIDTH);
79
- }
157
+ cr1 = s->regs[R_TYPE2_COMPARE_0_WORD_1 + cr_idx * 2];
80
-
158
+ offset = FIELD_EX32(cr1, TYPE2_COMPARE_0_WORD_1, OFFSET_VALUE);
81
- if (eppnt->p_offset + eppnt->p_filesz <= BPRM_BUF_SIZE) {
159
82
- memcpy(interp_name, bprm_buf + eppnt->p_offset,
160
- switch (extract32(cr1, GEM_T2CW1_COMPARE_OFFSET_SHIFT,
83
- eppnt->p_filesz);
161
- GEM_T2CW1_COMPARE_OFFSET_WIDTH)) {
84
- } else {
162
+ switch (FIELD_EX32(cr1, TYPE2_COMPARE_0_WORD_1, COMPARE_OFFSET)) {
85
- retval = pread(image_fd, interp_name, eppnt->p_filesz,
163
case 3: /* Skip UDP header */
86
- eppnt->p_offset);
164
qemu_log_mask(LOG_UNIMP, "TCP compare offsets"
87
- if (retval != eppnt->p_filesz) {
165
"unimplemented - assuming UDP\n");
88
- goto exit_perror;
166
@@ -XXX,XX +XXX,XX @@ static int get_queue_from_screen(CadenceGEMState *s, uint8_t *rxbuf_ptr,
89
- }
167
}
90
- }
168
91
- if (interp_name[eppnt->p_filesz - 1] != 0) {
169
rx_cmp = rxbuf_ptr[offset] << 8 | rxbuf_ptr[offset];
92
- errmsg = "Invalid PT_INTERP entry";
170
- mask = extract32(cr0, 0, 16);
93
- goto exit_errmsg;
171
+ mask = FIELD_EX32(cr0, TYPE2_COMPARE_0_WORD_0, MASK_VALUE);
94
- }
172
+ compare = FIELD_EX32(cr0, TYPE2_COMPARE_0_WORD_0, COMPARE_VALUE);
95
- *pinterp_name = g_steal_pointer(&interp_name);
173
96
#ifdef TARGET_MIPS
174
- if ((rx_cmp & mask) == (extract32(cr0, 16, 16) & mask)) {
97
} else if (eppnt->p_type == PT_MIPS_ABIFLAGS) {
175
+ if ((rx_cmp & mask) == (compare & mask)) {
98
Mips_elf_abiflags_v0 abiflags;
176
matched = true;
177
} else {
178
mismatched = true;
179
@@ -XXX,XX +XXX,XX @@ static int get_queue_from_screen(CadenceGEMState *s, uint8_t *rxbuf_ptr,
180
}
181
182
if (matched && !mismatched) {
183
- return extract32(reg, GEM_ST2R_QUEUE_SHIFT, GEM_ST2R_QUEUE_WIDTH);
184
+ return FIELD_EX32(reg, SCREENING_TYPE2_REG0, QUEUE_NUM);
185
}
186
}
187
99
--
188
--
100
2.20.1
189
2.34.1
101
102
diff view generated by jsdifflib
1
From: Luc Michel <luc@lmichel.fr>
1
From: Luc Michel <luc.michel@amd.com>
2
2
3
The BCM2835 CPRMAN is the clock manager of the SoC. It is composed of a
3
Use the FIELD macro to describe the NWCTRL register fields.
4
main oscillator, and several sub-components (PLLs, multiplexers, ...) to
5
generate the BCM2835 clock tree.
6
4
7
This commit adds a skeleton of the CPRMAN, with a dummy register
5
Signed-off-by: Luc Michel <luc.michel@amd.com>
8
read/write implementation. It embeds the main oscillator (xosc) from
6
Reviewed-by: sai.pavan.boddu@amd.com
9
which all the clocks will be derived.
7
Message-id: 20231017194422.4124691-4-luc.michel@amd.com
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>
15
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
16
---
9
---
17
include/hw/arm/bcm2835_peripherals.h | 3 +-
10
hw/net/cadence_gem.c | 53 +++++++++++++++++++++++++++++++++-----------
18
include/hw/misc/bcm2835_cprman.h | 37 +++++
11
1 file changed, 40 insertions(+), 13 deletions(-)
19
include/hw/misc/bcm2835_cprman_internals.h | 24 +++
20
hw/arm/bcm2835_peripherals.c | 11 +-
21
hw/misc/bcm2835_cprman.c | 163 +++++++++++++++++++++
22
hw/misc/meson.build | 1 +
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
12
29
diff --git a/include/hw/arm/bcm2835_peripherals.h b/include/hw/arm/bcm2835_peripherals.h
13
diff --git a/hw/net/cadence_gem.c b/hw/net/cadence_gem.c
30
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
31
--- a/include/hw/arm/bcm2835_peripherals.h
15
--- a/hw/net/cadence_gem.c
32
+++ b/include/hw/arm/bcm2835_peripherals.h
16
+++ b/hw/net/cadence_gem.c
33
@@ -XXX,XX +XXX,XX @@
17
@@ -XXX,XX +XXX,XX @@
34
#include "hw/misc/bcm2835_mbox.h"
18
} while (0)
35
#include "hw/misc/bcm2835_mphi.h"
19
36
#include "hw/misc/bcm2835_thermal.h"
20
REG32(NWCTRL, 0x0) /* Network Control reg */
37
+#include "hw/misc/bcm2835_cprman.h"
21
+ FIELD(NWCTRL, LOOPBACK , 0, 1)
38
#include "hw/sd/sdhci.h"
22
+ FIELD(NWCTRL, LOOPBACK_LOCAL , 1, 1)
39
#include "hw/sd/bcm2835_sdhost.h"
23
+ FIELD(NWCTRL, ENABLE_RECEIVE, 2, 1)
40
#include "hw/gpio/bcm2835_gpio.h"
24
+ FIELD(NWCTRL, ENABLE_TRANSMIT, 3, 1)
41
@@ -XXX,XX +XXX,XX @@ struct BCM2835PeripheralState {
25
+ FIELD(NWCTRL, MAN_PORT_EN , 4, 1)
42
UnimplementedDeviceState txp;
26
+ FIELD(NWCTRL, CLEAR_ALL_STATS_REGS , 5, 1)
43
UnimplementedDeviceState armtmr;
27
+ FIELD(NWCTRL, INC_ALL_STATS_REGS, 6, 1)
44
UnimplementedDeviceState powermgt;
28
+ FIELD(NWCTRL, STATS_WRITE_EN, 7, 1)
45
- UnimplementedDeviceState cprman;
29
+ FIELD(NWCTRL, BACK_PRESSURE, 8, 1)
46
+ BCM2835CprmanState cprman;
30
+ FIELD(NWCTRL, TRANSMIT_START , 9, 1)
47
PL011State uart0;
31
+ FIELD(NWCTRL, TRANSMIT_HALT, 10, 1)
48
BCM2835AuxState aux;
32
+ FIELD(NWCTRL, TX_PAUSE_FRAME_RE, 11, 1)
49
BCM2835FBState fb;
33
+ FIELD(NWCTRL, TX_PAUSE_FRAME_ZE, 12, 1)
50
diff --git a/include/hw/misc/bcm2835_cprman.h b/include/hw/misc/bcm2835_cprman.h
34
+ FIELD(NWCTRL, STATS_TAKE_SNAP, 13, 1)
51
new file mode 100644
35
+ FIELD(NWCTRL, STATS_READ_SNAP, 14, 1)
52
index XXXXXXX..XXXXXXX
36
+ FIELD(NWCTRL, STORE_RX_TS, 15, 1)
53
--- /dev/null
37
+ FIELD(NWCTRL, PFC_ENABLE, 16, 1)
54
+++ b/include/hw/misc/bcm2835_cprman.h
38
+ FIELD(NWCTRL, PFC_PRIO_BASED, 17, 1)
55
@@ -XXX,XX +XXX,XX @@
39
+ FIELD(NWCTRL, FLUSH_RX_PKT_PCLK , 18, 1)
56
+/*
40
+ FIELD(NWCTRL, TX_LPI_EN, 19, 1)
57
+ * BCM2835 CPRMAN clock manager
41
+ FIELD(NWCTRL, PTP_UNICAST_ENA, 20, 1)
58
+ *
42
+ FIELD(NWCTRL, ALT_SGMII_MODE, 21, 1)
59
+ * Copyright (c) 2020 Luc Michel <luc@lmichel.fr>
43
+ FIELD(NWCTRL, STORE_UDP_OFFSET, 22, 1)
60
+ *
44
+ FIELD(NWCTRL, EXT_TSU_PORT_EN, 23, 1)
61
+ * SPDX-License-Identifier: GPL-2.0-or-later
45
+ FIELD(NWCTRL, ONE_STEP_SYNC_MO, 24, 1)
62
+ */
46
+ FIELD(NWCTRL, PFC_CTRL , 25, 1)
47
+ FIELD(NWCTRL, EXT_RXQ_SEL_EN , 26, 1)
48
+ FIELD(NWCTRL, OSS_CORRECTION_FIELD, 27, 1)
49
+ FIELD(NWCTRL, SEL_MII_ON_RGMII, 28, 1)
50
+ FIELD(NWCTRL, TWO_PT_FIVE_GIG, 29, 1)
51
+ FIELD(NWCTRL, IFG_EATS_QAV_CREDIT, 30, 1)
63
+
52
+
64
+#ifndef HW_MISC_CPRMAN_H
53
REG32(NWCFG, 0x4) /* Network Config reg */
65
+#define HW_MISC_CPRMAN_H
54
REG32(NWSTATUS, 0x8) /* Network Status reg */
66
+
55
REG32(USERIO, 0xc) /* User IO reg */
67
+#include "hw/sysbus.h"
56
@@ -XXX,XX +XXX,XX @@ REG32(TYPE2_COMPARE_0_WORD_1, 0x704)
68
+#include "hw/qdev-clock.h"
57
FIELD(TYPE2_COMPARE_0_WORD_1, COMPARE_VLAN_ID, 10, 1)
69
+
58
70
+#define TYPE_BCM2835_CPRMAN "bcm2835-cprman"
59
/*****************************************/
71
+
60
-#define GEM_NWCTRL_TXSTART 0x00000200 /* Transmit Enable */
72
+typedef struct BCM2835CprmanState BCM2835CprmanState;
61
-#define GEM_NWCTRL_TXENA 0x00000008 /* Transmit Enable */
73
+
62
-#define GEM_NWCTRL_RXENA 0x00000004 /* Receive Enable */
74
+DECLARE_INSTANCE_CHECKER(BCM2835CprmanState, CPRMAN,
63
-#define GEM_NWCTRL_LOCALLOOP 0x00000002 /* Local Loopback */
75
+ TYPE_BCM2835_CPRMAN)
64
-
76
+
65
#define GEM_NWCFG_STRIP_FCS 0x00020000 /* Strip FCS field */
77
+#define CPRMAN_NUM_REGS (0x2000 / sizeof(uint32_t))
66
#define GEM_NWCFG_LERR_DISC 0x00010000 /* Discard RX frames with len err */
78
+
67
#define GEM_NWCFG_BUFF_OFST_M 0x0000C000 /* Receive buffer offset mask */
79
+struct BCM2835CprmanState {
68
@@ -XXX,XX +XXX,XX @@ static bool gem_can_receive(NetClientState *nc)
80
+ /*< private >*/
69
s = qemu_get_nic_opaque(nc);
81
+ SysBusDevice parent_obj;
70
82
+
71
/* Do nothing if receive is not enabled. */
83
+ /*< public >*/
72
- if (!(s->regs[R_NWCTRL] & GEM_NWCTRL_RXENA)) {
84
+ MemoryRegion iomem;
73
+ if (!FIELD_EX32(s->regs[R_NWCTRL], NWCTRL, ENABLE_RECEIVE)) {
85
+
74
if (s->can_rx_state != 1) {
86
+ uint32_t regs[CPRMAN_NUM_REGS];
75
s->can_rx_state = 1;
87
+ uint32_t xosc_freq;
76
DB_PRINT("can't receive - no enable\n");
88
+
77
@@ -XXX,XX +XXX,XX @@ static void gem_transmit(CadenceGEMState *s)
89
+ Clock *xosc;
78
int q = 0;
90
+};
79
91
+
80
/* Do nothing if transmit is not enabled. */
92
+#endif
81
- if (!(s->regs[R_NWCTRL] & GEM_NWCTRL_TXENA)) {
93
diff --git a/include/hw/misc/bcm2835_cprman_internals.h b/include/hw/misc/bcm2835_cprman_internals.h
82
+ if (!FIELD_EX32(s->regs[R_NWCTRL], NWCTRL, ENABLE_TRANSMIT)) {
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
124
index XXXXXXX..XXXXXXX 100644
125
--- a/hw/arm/bcm2835_peripherals.c
126
+++ b/hw/arm/bcm2835_peripherals.c
127
@@ -XXX,XX +XXX,XX @@ static void bcm2835_peripherals_init(Object *obj)
128
/* DWC2 */
129
object_initialize_child(obj, "dwc2", &s->dwc2, TYPE_DWC2_USB);
130
131
+ /* CPRMAN clock manager */
132
+ object_initialize_child(obj, "cprman", &s->cprman, TYPE_BCM2835_CPRMAN);
133
+
134
object_property_add_const_link(OBJECT(&s->dwc2), "dma-mr",
135
OBJECT(&s->gpu_bus_mr));
136
}
137
@@ -XXX,XX +XXX,XX @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)
138
return;
83
return;
139
}
84
}
140
85
141
+ /* CPRMAN clock manager */
86
@@ -XXX,XX +XXX,XX @@ static void gem_transmit(CadenceGEMState *s)
142
+ if (!sysbus_realize(SYS_BUS_DEVICE(&s->cprman), errp)) {
87
while (tx_desc_get_used(desc) == 0) {
143
+ return;
88
144
+ }
89
/* Do nothing if transmit is not enabled. */
145
+ memory_region_add_subregion(&s->peri_mr, CPRMAN_OFFSET,
90
- if (!(s->regs[R_NWCTRL] & GEM_NWCTRL_TXENA)) {
146
+ sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->cprman), 0));
91
+ if (!FIELD_EX32(s->regs[R_NWCTRL], NWCTRL, ENABLE_TRANSMIT)) {
147
+
92
return;
148
memory_region_add_subregion(&s->peri_mr, ARMCTRL_IC_OFFSET,
93
}
149
sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->ic), 0));
94
print_gem_tx_desc(desc, q);
150
sysbus_pass_irq(SYS_BUS_DEVICE(s), SYS_BUS_DEVICE(&s->ic));
95
@@ -XXX,XX +XXX,XX @@ static void gem_transmit(CadenceGEMState *s)
151
@@ -XXX,XX +XXX,XX @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)
96
gem_transmit_updatestats(s, s->tx_packet, total_bytes);
152
create_unimp(s, &s->txp, "bcm2835-txp", TXP_OFFSET, 0x1000);
97
153
create_unimp(s, &s->armtmr, "bcm2835-sp804", ARMCTRL_TIMER0_1_OFFSET, 0x40);
98
/* Send the packet somewhere */
154
create_unimp(s, &s->powermgt, "bcm2835-powermgt", PM_OFFSET, 0x114);
99
- if (s->phy_loop || (s->regs[R_NWCTRL] &
155
- create_unimp(s, &s->cprman, "bcm2835-cprman", CPRMAN_OFFSET, 0x2000);
100
- GEM_NWCTRL_LOCALLOOP)) {
156
create_unimp(s, &s->i2s, "bcm2835-i2s", I2S_OFFSET, 0x100);
101
+ if (s->phy_loop || FIELD_EX32(s->regs[R_NWCTRL], NWCTRL,
157
create_unimp(s, &s->smi, "bcm2835-smi", SMI_OFFSET, 0x100);
102
+ LOOPBACK_LOCAL)) {
158
create_unimp(s, &s->spi[0], "bcm2835-spi0", SPI0_OFFSET, 0x20);
103
qemu_receive_packet(qemu_get_queue(s->nic), s->tx_packet,
159
diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c
104
total_bytes);
160
new file mode 100644
105
} else {
161
index XXXXXXX..XXXXXXX
106
@@ -XXX,XX +XXX,XX @@ static void gem_write(void *opaque, hwaddr offset, uint64_t val,
162
--- /dev/null
107
/* Handle register write side effects */
163
+++ b/hw/misc/bcm2835_cprman.c
108
switch (offset) {
164
@@ -XXX,XX +XXX,XX @@
109
case R_NWCTRL:
165
+/*
110
- if (val & GEM_NWCTRL_RXENA) {
166
+ * BCM2835 CPRMAN clock manager
111
+ if (FIELD_EX32(val, NWCTRL, ENABLE_RECEIVE)) {
167
+ *
112
for (i = 0; i < s->num_priority_queues; ++i) {
168
+ * Copyright (c) 2020 Luc Michel <luc@lmichel.fr>
113
gem_get_rx_desc(s, i);
169
+ *
114
}
170
+ * SPDX-License-Identifier: GPL-2.0-or-later
115
}
171
+ */
116
- if (val & GEM_NWCTRL_TXSTART) {
172
+
117
+ if (FIELD_EX32(val, NWCTRL, TRANSMIT_START)) {
173
+/*
118
gem_transmit(s);
174
+ * This peripheral is roughly divided into 3 main parts:
119
}
175
+ * - the PLLs
120
- if (!(val & GEM_NWCTRL_TXENA)) {
176
+ * - the PLL channels
121
+ if (!(FIELD_EX32(val, NWCTRL, ENABLE_TRANSMIT))) {
177
+ * - the clock muxes
122
/* Reset to start of Q when transmit disabled. */
178
+ *
123
for (i = 0; i < s->num_priority_queues; i++) {
179
+ * A main oscillator (xosc) feeds all the PLLs. Each PLLs has one or more
124
s->tx_desc_addr[i] = gem_get_tx_queue_base_addr(s, i);
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);
241
+ return;
242
+ }
243
+
244
+ value &= ~R_CPRMAN_PASSWORD_MASK;
245
+
246
+ trace_bcm2835_cprman_write(offset, value);
247
+ s->regs[idx] = value;
248
+
249
+}
250
+
251
+static const MemoryRegionOps cprman_ops = {
252
+ .read = cprman_read,
253
+ .write = cprman_write,
254
+ .endianness = DEVICE_LITTLE_ENDIAN,
255
+ .valid = {
256
+ /*
257
+ * Although this hasn't been checked against real hardware, nor the
258
+ * information can be found in a datasheet, it seems reasonable because
259
+ * of the "PASSWORD" magic value found in every registers.
260
+ */
261
+ .min_access_size = 4,
262
+ .max_access_size = 4,
263
+ .unaligned = false,
264
+ },
265
+ .impl = {
266
+ .max_access_size = 4,
267
+ },
268
+};
269
+
270
+static void cprman_reset(DeviceState *dev)
271
+{
272
+ BCM2835CprmanState *s = CPRMAN(dev);
273
+
274
+ memset(s->regs, 0, sizeof(s->regs));
275
+
276
+ clock_update_hz(s->xosc, s->xosc_freq);
277
+}
278
+
279
+static void cprman_init(Object *obj)
280
+{
281
+ BCM2835CprmanState *s = CPRMAN(obj);
282
+
283
+ s->xosc = clock_new(obj, "xosc");
284
+
285
+ memory_region_init_io(&s->iomem, obj, &cprman_ops,
286
+ s, "bcm2835-cprman", 0x2000);
287
+ sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->iomem);
288
+}
289
+
290
+static const VMStateDescription cprman_vmstate = {
291
+ .name = TYPE_BCM2835_CPRMAN,
292
+ .version_id = 1,
293
+ .minimum_version_id = 1,
294
+ .fields = (VMStateField[]) {
295
+ VMSTATE_UINT32_ARRAY(regs, BCM2835CprmanState, CPRMAN_NUM_REGS),
296
+ VMSTATE_END_OF_LIST()
297
+ }
298
+};
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)
306
+{
307
+ DeviceClass *dc = DEVICE_CLASS(klass);
308
+
309
+ dc->reset = cprman_reset;
310
+ dc->vmsd = &cprman_vmstate;
311
+ device_class_set_props(dc, cprman_properties);
312
+}
313
+
314
+static const TypeInfo cprman_info = {
315
+ .name = TYPE_BCM2835_CPRMAN,
316
+ .parent = TYPE_SYS_BUS_DEVICE,
317
+ .instance_size = sizeof(BCM2835CprmanState),
318
+ .class_init = cprman_class_init,
319
+ .instance_init = cprman_init,
320
+};
321
+
322
+static void cprman_register_types(void)
323
+{
324
+ type_register_static(&cprman_info);
325
+}
326
+
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
353
--
125
--
354
2.20.1
126
2.34.1
355
356
diff view generated by jsdifflib
1
From: Luc Michel <luc@lmichel.fr>
1
From: Luc Michel <luc.michel@amd.com>
2
2
3
This simple mux sits between the PLL channels and the DSI0E and DSI0P
3
Use de FIELD macro to describe the NWCFG register fields.
4
clock muxes. This mux selects between PLLA-DSI0 and PLLD-DSI0 channel
5
and outputs the selected signal to source number 4 of DSI0E/P clock
6
muxes. It is controlled by the cm_dsi0hsck register.
7
4
8
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
5
Signed-off-by: Luc Michel <luc.michel@amd.com>
9
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
6
Reviewed-by: sai.pavan.boddu@amd.com
10
Signed-off-by: Luc Michel <luc@lmichel.fr>
7
Message-id: 20231017194422.4124691-5-luc.michel@amd.com
11
Tested-by: Guenter Roeck <linux@roeck-us.net>
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
---
9
---
14
include/hw/misc/bcm2835_cprman.h | 15 +++++
10
hw/net/cadence_gem.c | 60 ++++++++++++++++++++++++++++----------------
15
include/hw/misc/bcm2835_cprman_internals.h | 6 ++
11
1 file changed, 39 insertions(+), 21 deletions(-)
16
hw/misc/bcm2835_cprman.c | 74 +++++++++++++++++++++-
17
3 files changed, 94 insertions(+), 1 deletion(-)
18
12
19
diff --git a/include/hw/misc/bcm2835_cprman.h b/include/hw/misc/bcm2835_cprman.h
13
diff --git a/hw/net/cadence_gem.c b/hw/net/cadence_gem.c
20
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
21
--- a/include/hw/misc/bcm2835_cprman.h
15
--- a/hw/net/cadence_gem.c
22
+++ b/include/hw/misc/bcm2835_cprman.h
16
+++ b/hw/net/cadence_gem.c
23
@@ -XXX,XX +XXX,XX @@ typedef struct CprmanClockMuxState {
17
@@ -XXX,XX +XXX,XX @@ REG32(NWCTRL, 0x0) /* Network Control reg */
24
struct CprmanClockMuxState *backref[CPRMAN_NUM_CLOCK_MUX_SRC];
18
FIELD(NWCTRL, IFG_EATS_QAV_CREDIT, 30, 1)
25
} CprmanClockMuxState;
19
26
20
REG32(NWCFG, 0x4) /* Network Config reg */
27
+typedef struct CprmanDsi0HsckMuxState {
21
+ FIELD(NWCFG, SPEED, 0, 1)
28
+ /*< private >*/
22
+ FIELD(NWCFG, FULL_DUPLEX, 1, 1)
29
+ DeviceState parent_obj;
23
+ FIELD(NWCFG, DISCARD_NON_VLAN_FRAMES, 2, 1)
24
+ FIELD(NWCFG, JUMBO_FRAMES, 3, 1)
25
+ FIELD(NWCFG, PROMISC, 4, 1)
26
+ FIELD(NWCFG, NO_BROADCAST, 5, 1)
27
+ FIELD(NWCFG, MULTICAST_HASH_EN, 6, 1)
28
+ FIELD(NWCFG, UNICAST_HASH_EN, 7, 1)
29
+ FIELD(NWCFG, RECV_1536_BYTE_FRAMES, 8, 1)
30
+ FIELD(NWCFG, EXTERNAL_ADDR_MATCH_EN, 9, 1)
31
+ FIELD(NWCFG, GIGABIT_MODE_ENABLE, 10, 1)
32
+ FIELD(NWCFG, PCS_SELECT, 11, 1)
33
+ FIELD(NWCFG, RETRY_TEST, 12, 1)
34
+ FIELD(NWCFG, PAUSE_ENABLE, 13, 1)
35
+ FIELD(NWCFG, RECV_BUF_OFFSET, 14, 2)
36
+ FIELD(NWCFG, LEN_ERR_DISCARD, 16, 1)
37
+ FIELD(NWCFG, FCS_REMOVE, 17, 1)
38
+ FIELD(NWCFG, MDC_CLOCK_DIV, 18, 3)
39
+ FIELD(NWCFG, DATA_BUS_WIDTH, 21, 2)
40
+ FIELD(NWCFG, DISABLE_COPY_PAUSE_FRAMES, 23, 1)
41
+ FIELD(NWCFG, RECV_CSUM_OFFLOAD_EN, 24, 1)
42
+ FIELD(NWCFG, EN_HALF_DUPLEX_RX, 25, 1)
43
+ FIELD(NWCFG, IGNORE_RX_FCS, 26, 1)
44
+ FIELD(NWCFG, SGMII_MODE_ENABLE, 27, 1)
45
+ FIELD(NWCFG, IPG_STRETCH_ENABLE, 28, 1)
46
+ FIELD(NWCFG, NSP_ACCEPT, 29, 1)
47
+ FIELD(NWCFG, IGNORE_IPG_RX_ER, 30, 1)
48
+ FIELD(NWCFG, UNI_DIRECTION_ENABLE, 31, 1)
30
+
49
+
31
+ /*< public >*/
50
REG32(NWSTATUS, 0x8) /* Network Status reg */
32
+ CprmanClockMux id;
51
REG32(USERIO, 0xc) /* User IO reg */
33
+
52
REG32(DMACFG, 0x10) /* DMA Control reg */
34
+ uint32_t *reg_cm;
53
@@ -XXX,XX +XXX,XX @@ REG32(TYPE2_COMPARE_0_WORD_1, 0x704)
35
+
54
FIELD(TYPE2_COMPARE_0_WORD_1, COMPARE_VLAN_ID, 10, 1)
36
+ Clock *plla_in;
55
37
+ Clock *plld_in;
56
/*****************************************/
38
+ Clock *out;
57
-#define GEM_NWCFG_STRIP_FCS 0x00020000 /* Strip FCS field */
39
+} CprmanDsi0HsckMuxState;
58
-#define GEM_NWCFG_LERR_DISC 0x00010000 /* Discard RX frames with len err */
40
+
59
-#define GEM_NWCFG_BUFF_OFST_M 0x0000C000 /* Receive buffer offset mask */
41
struct BCM2835CprmanState {
60
-#define GEM_NWCFG_BUFF_OFST_S 14 /* Receive buffer offset shift */
42
/*< private >*/
61
-#define GEM_NWCFG_RCV_1538 0x00000100 /* Receive 1538 bytes frame */
43
SysBusDevice parent_obj;
62
-#define GEM_NWCFG_UCAST_HASH 0x00000080 /* accept unicast if hash match */
44
@@ -XXX,XX +XXX,XX @@ struct BCM2835CprmanState {
63
-#define GEM_NWCFG_MCAST_HASH 0x00000040 /* accept multicast if hash match */
45
CprmanPllState plls[CPRMAN_NUM_PLL];
64
-#define GEM_NWCFG_BCAST_REJ 0x00000020 /* Reject broadcast packets */
46
CprmanPllChannelState channels[CPRMAN_NUM_PLL_CHANNEL];
65
-#define GEM_NWCFG_PROMISC 0x00000010 /* Accept all packets */
47
CprmanClockMuxState clock_muxes[CPRMAN_NUM_CLOCK_MUX];
66
-#define GEM_NWCFG_JUMBO_FRAME 0x00000008 /* Jumbo Frames enable */
48
+ CprmanDsi0HsckMuxState dsi0hsck_mux;
67
-
49
68
#define GEM_DMACFG_ADDR_64B (1U << 30)
50
uint32_t regs[CPRMAN_NUM_REGS];
69
#define GEM_DMACFG_TX_BD_EXT (1U << 29)
51
uint32_t xosc_freq;
70
#define GEM_DMACFG_RX_BD_EXT (1U << 28)
52
diff --git a/include/hw/misc/bcm2835_cprman_internals.h b/include/hw/misc/bcm2835_cprman_internals.h
71
@@ -XXX,XX +XXX,XX @@ static const uint8_t broadcast_addr[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
53
index XXXXXXX..XXXXXXX 100644
72
static uint32_t gem_get_max_buf_len(CadenceGEMState *s, bool tx)
54
--- a/include/hw/misc/bcm2835_cprman_internals.h
73
{
55
+++ b/include/hw/misc/bcm2835_cprman_internals.h
74
uint32_t size;
56
@@ -XXX,XX +XXX,XX @@
75
- if (s->regs[R_NWCFG] & GEM_NWCFG_JUMBO_FRAME) {
57
#define TYPE_CPRMAN_PLL "bcm2835-cprman-pll"
76
+ if (FIELD_EX32(s->regs[R_NWCFG], NWCFG, JUMBO_FRAMES)) {
58
#define TYPE_CPRMAN_PLL_CHANNEL "bcm2835-cprman-pll-channel"
77
size = s->regs[R_JUMBO_MAX_LEN];
59
#define TYPE_CPRMAN_CLOCK_MUX "bcm2835-cprman-clock-mux"
78
if (size > s->jumbo_max_len) {
60
+#define TYPE_CPRMAN_DSI0HSCK_MUX "bcm2835-cprman-dsi0hsck-mux"
79
size = s->jumbo_max_len;
61
80
@@ -XXX,XX +XXX,XX @@ static uint32_t gem_get_max_buf_len(CadenceGEMState *s, bool tx)
62
DECLARE_INSTANCE_CHECKER(CprmanPllState, CPRMAN_PLL,
81
} else if (tx) {
63
TYPE_CPRMAN_PLL)
82
size = 1518;
64
@@ -XXX,XX +XXX,XX @@ DECLARE_INSTANCE_CHECKER(CprmanPllChannelState, CPRMAN_PLL_CHANNEL,
83
} else {
65
TYPE_CPRMAN_PLL_CHANNEL)
84
- size = s->regs[R_NWCFG] & GEM_NWCFG_RCV_1538 ? 1538 : 1518;
66
DECLARE_INSTANCE_CHECKER(CprmanClockMuxState, CPRMAN_CLOCK_MUX,
85
+ size = FIELD_EX32(s->regs[R_NWCFG],
67
TYPE_CPRMAN_CLOCK_MUX)
86
+ NWCFG, RECV_1536_BYTE_FRAMES) ? 1538 : 1518;
68
+DECLARE_INSTANCE_CHECKER(CprmanDsi0HsckMuxState, CPRMAN_DSI0HSCK_MUX,
69
+ TYPE_CPRMAN_DSI0HSCK_MUX)
70
71
/* Register map */
72
73
@@ -XXX,XX +XXX,XX @@ REG32(CM_LOCK, 0x114)
74
FIELD(CM_LOCK, FLOCKB, 9, 1)
75
FIELD(CM_LOCK, FLOCKA, 8, 1)
76
77
+REG32(CM_DSI0HSCK, 0x120)
78
+ FIELD(CM_DSI0HSCK, SELPLLD, 0, 1)
79
+
80
/*
81
* This field is common to all registers. Each register write value must match
82
* the CPRMAN_PASSWORD magic value in its 8 MSB.
83
diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c
84
index XXXXXXX..XXXXXXX 100644
85
--- a/hw/misc/bcm2835_cprman.c
86
+++ b/hw/misc/bcm2835_cprman.c
87
@@ -XXX,XX +XXX,XX @@ static const TypeInfo cprman_clock_mux_info = {
88
};
89
90
91
+/* DSI0HSCK mux */
92
+
93
+static void dsi0hsck_mux_update(CprmanDsi0HsckMuxState *s)
94
+{
95
+ bool src_is_plld = FIELD_EX32(*s->reg_cm, CM_DSI0HSCK, SELPLLD);
96
+ Clock *src = src_is_plld ? s->plld_in : s->plla_in;
97
+
98
+ clock_update(s->out, clock_get(src));
99
+}
100
+
101
+static void dsi0hsck_mux_in_update(void *opaque)
102
+{
103
+ dsi0hsck_mux_update(CPRMAN_DSI0HSCK_MUX(opaque));
104
+}
105
+
106
+static void dsi0hsck_mux_init(Object *obj)
107
+{
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
+ }
125
+};
126
+
127
+static void dsi0hsck_mux_class_init(ObjectClass *klass, void *data)
128
+{
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,
140
+};
141
+
142
+
143
/* CPRMAN "top level" model */
144
145
static uint32_t get_cm_lock(const BCM2835CprmanState *s)
146
@@ -XXX,XX +XXX,XX @@ static void cprman_write(void *opaque, hwaddr offset,
147
case R_CM_EMMC2CTL ... R_CM_EMMC2DIV:
148
update_mux_from_cm(s, idx);
149
break;
150
+
151
+ case R_CM_DSI0HSCK:
152
+ dsi0hsck_mux_update(&s->dsi0hsck_mux);
153
+ break;
154
}
87
}
88
return size;
155
}
89
}
156
90
@@ -XXX,XX +XXX,XX @@ static int gem_mac_address_filter(CadenceGEMState *s, const uint8_t *packet)
157
@@ -XXX,XX +XXX,XX @@ static void cprman_reset(DeviceState *dev)
91
int i, is_mc;
158
device_cold_reset(DEVICE(&s->channels[i]));
92
93
/* Promiscuous mode? */
94
- if (s->regs[R_NWCFG] & GEM_NWCFG_PROMISC) {
95
+ if (FIELD_EX32(s->regs[R_NWCFG], NWCFG, PROMISC)) {
96
return GEM_RX_PROMISCUOUS_ACCEPT;
159
}
97
}
160
98
161
+ device_cold_reset(DEVICE(&s->dsi0hsck_mux));
99
if (!memcmp(packet, broadcast_addr, 6)) {
162
+
100
/* Reject broadcast packets? */
163
for (i = 0; i < CPRMAN_NUM_CLOCK_MUX; i++) {
101
- if (s->regs[R_NWCFG] & GEM_NWCFG_BCAST_REJ) {
164
device_cold_reset(DEVICE(&s->clock_muxes[i]));
102
+ if (FIELD_EX32(s->regs[R_NWCFG], NWCFG, NO_BROADCAST)) {
103
return GEM_RX_REJECT;
104
}
105
return GEM_RX_BROADCAST_ACCEPT;
106
@@ -XXX,XX +XXX,XX @@ static int gem_mac_address_filter(CadenceGEMState *s, const uint8_t *packet)
107
108
/* Accept packets -w- hash match? */
109
is_mc = is_multicast_ether_addr(packet);
110
- if ((is_mc && (s->regs[R_NWCFG] & GEM_NWCFG_MCAST_HASH)) ||
111
- (!is_mc && (s->regs[R_NWCFG] & GEM_NWCFG_UCAST_HASH))) {
112
+ if ((is_mc && (FIELD_EX32(s->regs[R_NWCFG], NWCFG, MULTICAST_HASH_EN))) ||
113
+ (!is_mc && FIELD_EX32(s->regs[R_NWCFG], NWCFG, UNICAST_HASH_EN))) {
114
uint64_t buckets;
115
unsigned hash_index;
116
117
@@ -XXX,XX +XXX,XX @@ static ssize_t gem_receive(NetClientState *nc, const uint8_t *buf, size_t size)
165
}
118
}
166
@@ -XXX,XX +XXX,XX @@ static void cprman_init(Object *obj)
119
167
set_pll_channel_init_info(s, &s->channels[i], i);
120
/* Discard packets with receive length error enabled ? */
121
- if (s->regs[R_NWCFG] & GEM_NWCFG_LERR_DISC) {
122
+ if (FIELD_EX32(s->regs[R_NWCFG], NWCFG, LEN_ERR_DISCARD)) {
123
unsigned type_len;
124
125
/* Fish the ethertype / length field out of the RX packet */
126
@@ -XXX,XX +XXX,XX @@ static ssize_t gem_receive(NetClientState *nc, const uint8_t *buf, size_t size)
127
/*
128
* Determine configured receive buffer offset (probably 0)
129
*/
130
- rxbuf_offset = (s->regs[R_NWCFG] & GEM_NWCFG_BUFF_OFST_M) >>
131
- GEM_NWCFG_BUFF_OFST_S;
132
+ rxbuf_offset = FIELD_EX32(s->regs[R_NWCFG], NWCFG, RECV_BUF_OFFSET);
133
134
/* The configure size of each receive buffer. Determines how many
135
* buffers needed to hold this packet.
136
@@ -XXX,XX +XXX,XX @@ static ssize_t gem_receive(NetClientState *nc, const uint8_t *buf, size_t size)
168
}
137
}
169
138
170
+ object_initialize_child(obj, "dsi0hsck-mux",
139
/* Strip of FCS field ? (usually yes) */
171
+ &s->dsi0hsck_mux, TYPE_CPRMAN_DSI0HSCK_MUX);
140
- if (s->regs[R_NWCFG] & GEM_NWCFG_STRIP_FCS) {
172
+ s->dsi0hsck_mux.reg_cm = &s->regs[R_CM_DSI0HSCK];
141
+ if (FIELD_EX32(s->regs[R_NWCFG], NWCFG, FCS_REMOVE)) {
173
+
142
rxbuf_ptr = (void *)buf;
174
for (i = 0; i < CPRMAN_NUM_CLOCK_MUX; i++) {
143
} else {
175
char *alias;
144
unsigned crc_val;
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;
197
+ }
198
+
199
for (i = 0; i < CPRMAN_NUM_CLOCK_MUX; i++) {
200
CprmanClockMuxState *clock_mux = &s->clock_muxes[i];
201
202
@@ -XXX,XX +XXX,XX @@ static void cprman_register_types(void)
203
type_register_static(&cprman_pll_info);
204
type_register_static(&cprman_pll_channel_info);
205
type_register_static(&cprman_clock_mux_info);
206
+ type_register_static(&cprman_dsi0hsck_mux_info);
207
}
208
209
type_init(cprman_register_types);
210
--
145
--
211
2.20.1
146
2.34.1
212
213
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
1
From: Luc Michel <luc.michel@amd.com>
2
2
3
No code out of bcm2836.c uses (or requires) the BCM283XInfo
3
Use de FIELD macro to describe the DMACFG register fields.
4
declarations. Move it locally to the C source file.
5
4
6
Reviewed-by: Luc Michel <luc.michel@greensocs.com>
5
Signed-off-by: Luc Michel <luc.michel@amd.com>
7
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
6
Reviewed-by: sai.pavan.boddu@amd.com
8
Message-id: 20201024170127.3592182-2-f4bug@amsat.org
7
Message-id: 20231017194422.4124691-6-luc.michel@amd.com
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
---
9
---
11
include/hw/arm/bcm2836.h | 8 --------
10
hw/net/cadence_gem.c | 48 ++++++++++++++++++++++++++++----------------
12
hw/arm/bcm2836.c | 14 ++++++++++++++
11
1 file changed, 31 insertions(+), 17 deletions(-)
13
2 files changed, 14 insertions(+), 8 deletions(-)
14
12
15
diff --git a/include/hw/arm/bcm2836.h b/include/hw/arm/bcm2836.h
13
diff --git a/hw/net/cadence_gem.c b/hw/net/cadence_gem.c
16
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
17
--- a/include/hw/arm/bcm2836.h
15
--- a/hw/net/cadence_gem.c
18
+++ b/include/hw/arm/bcm2836.h
16
+++ b/hw/net/cadence_gem.c
19
@@ -XXX,XX +XXX,XX @@ struct BCM283XState {
17
@@ -XXX,XX +XXX,XX @@ REG32(NWCFG, 0x4) /* Network Config reg */
20
BCM2835PeripheralState peripherals;
18
21
};
19
REG32(NWSTATUS, 0x8) /* Network Status reg */
22
20
REG32(USERIO, 0xc) /* User IO reg */
23
-typedef struct BCM283XInfo BCM283XInfo;
24
-
25
-struct BCM283XClass {
26
- DeviceClass parent_class;
27
- const BCM283XInfo *info;
28
-};
29
-
30
-
31
#endif /* BCM2836_H */
32
diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c
33
index XXXXXXX..XXXXXXX 100644
34
--- a/hw/arm/bcm2836.c
35
+++ b/hw/arm/bcm2836.c
36
@@ -XXX,XX +XXX,XX @@
37
#include "hw/arm/raspi_platform.h"
38
#include "hw/sysbus.h"
39
40
+typedef struct BCM283XInfo BCM283XInfo;
41
+
21
+
42
+typedef struct BCM283XClass {
22
REG32(DMACFG, 0x10) /* DMA Control reg */
43
+ /*< private >*/
23
+ FIELD(DMACFG, SEND_BCAST_TO_ALL_QS, 31, 1)
44
+ DeviceClass parent_class;
24
+ FIELD(DMACFG, DMA_ADDR_BUS_WIDTH, 30, 1)
45
+ /*< public >*/
25
+ FIELD(DMACFG, TX_BD_EXT_MODE_EN , 29, 1)
46
+ const BCM283XInfo *info;
26
+ FIELD(DMACFG, RX_BD_EXT_MODE_EN , 28, 1)
47
+} BCM283XClass;
27
+ FIELD(DMACFG, FORCE_MAX_AMBA_BURST_TX, 26, 1)
28
+ FIELD(DMACFG, FORCE_MAX_AMBA_BURST_RX, 25, 1)
29
+ FIELD(DMACFG, FORCE_DISCARD_ON_ERR, 24, 1)
30
+ FIELD(DMACFG, RX_BUF_SIZE, 16, 8)
31
+ FIELD(DMACFG, CRC_ERROR_REPORT, 13, 1)
32
+ FIELD(DMACFG, INF_LAST_DBUF_SIZE_EN, 12, 1)
33
+ FIELD(DMACFG, TX_PBUF_CSUM_OFFLOAD, 11, 1)
34
+ FIELD(DMACFG, TX_PBUF_SIZE, 10, 1)
35
+ FIELD(DMACFG, RX_PBUF_SIZE, 8, 2)
36
+ FIELD(DMACFG, ENDIAN_SWAP_PACKET, 7, 1)
37
+ FIELD(DMACFG, ENDIAN_SWAP_MGNT, 6, 1)
38
+ FIELD(DMACFG, HDR_DATA_SPLIT_EN, 5, 1)
39
+ FIELD(DMACFG, AMBA_BURST_LEN , 0, 5)
40
+#define GEM_DMACFG_RBUFSZ_MUL 64 /* DMA RX Buffer Size multiplier */
48
+
41
+
49
struct BCM283XInfo {
42
REG32(TXSTATUS, 0x14) /* TX Status reg */
50
const char *name;
43
REG32(RXQBASE, 0x18) /* RX Q Base address reg */
51
const char *cpu_type;
44
REG32(TXQBASE, 0x1c) /* TX Q Base address reg */
52
@@ -XXX,XX +XXX,XX @@ struct BCM283XInfo {
45
@@ -XXX,XX +XXX,XX @@ REG32(TYPE2_COMPARE_0_WORD_1, 0x704)
53
int clusterid;
46
FIELD(TYPE2_COMPARE_0_WORD_1, COMPARE_VLAN_ID, 10, 1)
54
};
47
55
48
/*****************************************/
56
+#define BCM283X_CLASS(klass) \
49
-#define GEM_DMACFG_ADDR_64B (1U << 30)
57
+ OBJECT_CLASS_CHECK(BCM283XClass, (klass), TYPE_BCM283X)
50
-#define GEM_DMACFG_TX_BD_EXT (1U << 29)
58
+#define BCM283X_GET_CLASS(obj) \
51
-#define GEM_DMACFG_RX_BD_EXT (1U << 28)
59
+ OBJECT_GET_CLASS(BCM283XClass, (obj), TYPE_BCM283X)
52
-#define GEM_DMACFG_RBUFSZ_M 0x00FF0000 /* DMA RX Buffer Size mask */
53
-#define GEM_DMACFG_RBUFSZ_S 16 /* DMA RX Buffer Size shift */
54
-#define GEM_DMACFG_RBUFSZ_MUL 64 /* DMA RX Buffer Size multiplier */
55
-#define GEM_DMACFG_TXCSUM_OFFL 0x00000800 /* Transmit checksum offload */
56
57
#define GEM_TXSTATUS_TXCMPL 0x00000020 /* Transmit Complete */
58
#define GEM_TXSTATUS_USED 0x00000001 /* sw owned descriptor encountered */
59
@@ -XXX,XX +XXX,XX @@ static inline uint64_t tx_desc_get_buffer(CadenceGEMState *s, uint32_t *desc)
60
{
61
uint64_t ret = desc[0];
62
63
- if (s->regs[R_DMACFG] & GEM_DMACFG_ADDR_64B) {
64
+ if (FIELD_EX32(s->regs[R_DMACFG], DMACFG, DMA_ADDR_BUS_WIDTH)) {
65
ret |= (uint64_t)desc[2] << 32;
66
}
67
return ret;
68
@@ -XXX,XX +XXX,XX @@ static inline uint64_t rx_desc_get_buffer(CadenceGEMState *s, uint32_t *desc)
69
{
70
uint64_t ret = desc[0] & ~0x3UL;
71
72
- if (s->regs[R_DMACFG] & GEM_DMACFG_ADDR_64B) {
73
+ if (FIELD_EX32(s->regs[R_DMACFG], DMACFG, DMA_ADDR_BUS_WIDTH)) {
74
ret |= (uint64_t)desc[2] << 32;
75
}
76
return ret;
77
@@ -XXX,XX +XXX,XX @@ static inline int gem_get_desc_len(CadenceGEMState *s, bool rx_n_tx)
78
{
79
int ret = 2;
80
81
- if (s->regs[R_DMACFG] & GEM_DMACFG_ADDR_64B) {
82
+ if (FIELD_EX32(s->regs[R_DMACFG], DMACFG, DMA_ADDR_BUS_WIDTH)) {
83
ret += 2;
84
}
85
- if (s->regs[R_DMACFG] & (rx_n_tx ? GEM_DMACFG_RX_BD_EXT
86
- : GEM_DMACFG_TX_BD_EXT)) {
87
+ if (s->regs[R_DMACFG] & (rx_n_tx ? R_DMACFG_RX_BD_EXT_MODE_EN_MASK
88
+ : R_DMACFG_TX_BD_EXT_MODE_EN_MASK)) {
89
ret += 2;
90
}
91
92
@@ -XXX,XX +XXX,XX @@ static hwaddr gem_get_desc_addr(CadenceGEMState *s, bool tx, int q)
93
{
94
hwaddr desc_addr = 0;
95
96
- if (s->regs[R_DMACFG] & GEM_DMACFG_ADDR_64B) {
97
+ if (FIELD_EX32(s->regs[R_DMACFG], DMACFG, DMA_ADDR_BUS_WIDTH)) {
98
desc_addr = s->regs[tx ? R_TBQPH : R_RBQPH];
99
}
100
desc_addr <<= 32;
101
@@ -XXX,XX +XXX,XX @@ static ssize_t gem_receive(NetClientState *nc, const uint8_t *buf, size_t size)
102
/* The configure size of each receive buffer. Determines how many
103
* buffers needed to hold this packet.
104
*/
105
- rxbufsize = ((s->regs[R_DMACFG] & GEM_DMACFG_RBUFSZ_M) >>
106
- GEM_DMACFG_RBUFSZ_S) * GEM_DMACFG_RBUFSZ_MUL;
107
+ rxbufsize = FIELD_EX32(s->regs[R_DMACFG], DMACFG, RX_BUF_SIZE);
108
+ rxbufsize *= GEM_DMACFG_RBUFSZ_MUL;
60
+
109
+
61
static const BCM283XInfo bcm283x_socs[] = {
110
bytes_to_copy = size;
62
{
111
63
.name = TYPE_BCM2836,
112
/* Hardware allows a zero value here but warns against it. To avoid QEMU
113
@@ -XXX,XX +XXX,XX @@ static void gem_transmit(CadenceGEMState *s)
114
gem_update_int_status(s);
115
116
/* Is checksum offload enabled? */
117
- if (s->regs[R_DMACFG] & GEM_DMACFG_TXCSUM_OFFL) {
118
+ if (FIELD_EX32(s->regs[R_DMACFG], DMACFG, TX_PBUF_CSUM_OFFLOAD)) {
119
net_checksum_calculate(s->tx_packet, total_bytes, CSUM_ALL);
120
}
121
122
@@ -XXX,XX +XXX,XX @@ static void gem_transmit(CadenceGEMState *s)
123
124
/* read next descriptor */
125
if (tx_desc_get_wrap(desc)) {
126
- if (s->regs[R_DMACFG] & GEM_DMACFG_ADDR_64B) {
127
+ if (FIELD_EX32(s->regs[R_DMACFG], DMACFG, DMA_ADDR_BUS_WIDTH)) {
128
packet_desc_addr = s->regs[R_TBQPH];
129
packet_desc_addr <<= 32;
130
} else {
64
--
131
--
65
2.20.1
132
2.34.1
66
67
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
1
From: Luc Michel <luc.michel@amd.com>
2
2
3
Remove usage of TypeInfo::class_data. Instead fill the fields in
3
Use de FIELD macro to describe the TXSTATUS and RXSTATUS register
4
the corresponding class_init().
4
fields.
5
5
6
So far all children use the same values for almost all fields,
6
Signed-off-by: Luc Michel <luc.michel@amd.com>
7
but we are going to add the BCM2711/BCM2838 SoC for the raspi4
7
Reviewed-by: sai.pavan.boddu@amd.com
8
machine which use different fields.
8
Message-id: 20231017194422.4124691-7-luc.michel@amd.com
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
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
14
---
10
---
15
hw/arm/bcm2836.c | 108 ++++++++++++++++++++++-------------------------
11
hw/net/cadence_gem.c | 34 +++++++++++++++++++++++++---------
16
1 file changed, 51 insertions(+), 57 deletions(-)
12
1 file changed, 25 insertions(+), 9 deletions(-)
17
13
18
diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c
14
diff --git a/hw/net/cadence_gem.c b/hw/net/cadence_gem.c
19
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
20
--- a/hw/arm/bcm2836.c
16
--- a/hw/net/cadence_gem.c
21
+++ b/hw/arm/bcm2836.c
17
+++ b/hw/net/cadence_gem.c
22
@@ -XXX,XX +XXX,XX @@
18
@@ -XXX,XX +XXX,XX @@ REG32(DMACFG, 0x10) /* DMA Control reg */
23
#include "hw/arm/raspi_platform.h"
19
#define GEM_DMACFG_RBUFSZ_MUL 64 /* DMA RX Buffer Size multiplier */
24
#include "hw/sysbus.h"
20
25
21
REG32(TXSTATUS, 0x14) /* TX Status reg */
26
-typedef struct BCM283XInfo BCM283XInfo;
22
+ FIELD(TXSTATUS, TX_USED_BIT_READ_MIDFRAME, 12, 1)
23
+ FIELD(TXSTATUS, TX_FRAME_TOO_LARGE, 11, 1)
24
+ FIELD(TXSTATUS, TX_DMA_LOCKUP, 10, 1)
25
+ FIELD(TXSTATUS, TX_MAC_LOCKUP, 9, 1)
26
+ FIELD(TXSTATUS, RESP_NOT_OK, 8, 1)
27
+ FIELD(TXSTATUS, LATE_COLLISION, 7, 1)
28
+ FIELD(TXSTATUS, TRANSMIT_UNDER_RUN, 6, 1)
29
+ FIELD(TXSTATUS, TRANSMIT_COMPLETE, 5, 1)
30
+ FIELD(TXSTATUS, AMBA_ERROR, 4, 1)
31
+ FIELD(TXSTATUS, TRANSMIT_GO, 3, 1)
32
+ FIELD(TXSTATUS, RETRY_LIMIT, 2, 1)
33
+ FIELD(TXSTATUS, COLLISION, 1, 1)
34
+ FIELD(TXSTATUS, USED_BIT_READ, 0, 1)
35
+
36
REG32(RXQBASE, 0x18) /* RX Q Base address reg */
37
REG32(TXQBASE, 0x1c) /* TX Q Base address reg */
38
REG32(RXSTATUS, 0x20) /* RX Status reg */
39
+ FIELD(RXSTATUS, RX_DMA_LOCKUP, 5, 1)
40
+ FIELD(RXSTATUS, RX_MAC_LOCKUP, 4, 1)
41
+ FIELD(RXSTATUS, RESP_NOT_OK, 3, 1)
42
+ FIELD(RXSTATUS, RECEIVE_OVERRUN, 2, 1)
43
+ FIELD(RXSTATUS, FRAME_RECEIVED, 1, 1)
44
+ FIELD(RXSTATUS, BUF_NOT_AVAILABLE, 0, 1)
45
+
46
REG32(ISR, 0x24) /* Interrupt Status reg */
47
REG32(IER, 0x28) /* Interrupt Enable reg */
48
REG32(IDR, 0x2c) /* Interrupt Disable reg */
49
@@ -XXX,XX +XXX,XX @@ REG32(TYPE2_COMPARE_0_WORD_1, 0x704)
50
51
/*****************************************/
52
53
-#define GEM_TXSTATUS_TXCMPL 0x00000020 /* Transmit Complete */
54
-#define GEM_TXSTATUS_USED 0x00000001 /* sw owned descriptor encountered */
27
-
55
-
28
typedef struct BCM283XClass {
56
-#define GEM_RXSTATUS_FRMRCVD 0x00000002 /* Frame received */
29
/*< private >*/
57
-#define GEM_RXSTATUS_NOBUF 0x00000001 /* Buffer unavailable */
30
DeviceClass parent_class;
58
31
/*< public >*/
59
/* GEM_ISR GEM_IER GEM_IDR GEM_IMR */
32
- const BCM283XInfo *info;
60
#define GEM_INT_TXCMPL 0x00000080 /* Transmit Complete */
33
-} BCM283XClass;
61
@@ -XXX,XX +XXX,XX @@ static void gem_get_rx_desc(CadenceGEMState *s, int q)
34
-
62
/* Descriptor owned by software ? */
35
-struct BCM283XInfo {
63
if (rx_desc_get_ownership(s->rx_desc[q]) == 1) {
36
const char *name;
64
DB_PRINT("descriptor 0x%" HWADDR_PRIx " owned by sw.\n", desc_addr);
37
const char *cpu_type;
65
- s->regs[R_RXSTATUS] |= GEM_RXSTATUS_NOBUF;
38
hwaddr peri_base; /* Peripheral base address seen by the CPU */
66
+ s->regs[R_RXSTATUS] |= R_RXSTATUS_BUF_NOT_AVAILABLE_MASK;
39
hwaddr ctrl_base; /* Interrupt controller and mailboxes etc. */
67
gem_set_isr(s, q, GEM_INT_RXUSED);
40
int clusterid;
68
/* Handle interrupt consequences */
41
-};
69
gem_update_int_status(s);
42
+} BCM283XClass;
70
@@ -XXX,XX +XXX,XX @@ static ssize_t gem_receive(NetClientState *nc, const uint8_t *buf, size_t size)
43
71
/* Count it */
44
#define BCM283X_CLASS(klass) \
72
gem_receive_updatestats(s, buf, size);
45
OBJECT_CLASS_CHECK(BCM283XClass, (klass), TYPE_BCM283X)
73
46
#define BCM283X_GET_CLASS(obj) \
74
- s->regs[R_RXSTATUS] |= GEM_RXSTATUS_FRMRCVD;
47
OBJECT_GET_CLASS(BCM283XClass, (obj), TYPE_BCM283X)
75
+ s->regs[R_RXSTATUS] |= R_RXSTATUS_FRAME_RECEIVED_MASK;
48
76
gem_set_isr(s, q, GEM_INT_RXCMPL);
49
-static const BCM283XInfo bcm283x_socs[] = {
77
50
- {
78
/* Handle interrupt consequences */
51
- .name = TYPE_BCM2836,
79
@@ -XXX,XX +XXX,XX @@ static void gem_transmit(CadenceGEMState *s)
52
- .cpu_type = ARM_CPU_TYPE_NAME("cortex-a7"),
80
}
53
- .peri_base = 0x3f000000,
81
DB_PRINT("TX descriptor next: 0x%08x\n", s->tx_desc_addr[q]);
54
- .ctrl_base = 0x40000000,
82
55
- .clusterid = 0xf,
83
- s->regs[R_TXSTATUS] |= GEM_TXSTATUS_TXCMPL;
56
- },
84
+ s->regs[R_TXSTATUS] |= R_TXSTATUS_TRANSMIT_COMPLETE_MASK;
57
-#ifdef TARGET_AARCH64
85
gem_set_isr(s, q, GEM_INT_TXCMPL);
58
- {
86
59
- .name = TYPE_BCM2837,
87
/* Handle interrupt consequences */
60
- .cpu_type = ARM_CPU_TYPE_NAME("cortex-a53"),
88
@@ -XXX,XX +XXX,XX @@ static void gem_transmit(CadenceGEMState *s)
61
- .peri_base = 0x3f000000,
62
- .ctrl_base = 0x40000000,
63
- .clusterid = 0x0,
64
- },
65
-#endif
66
-};
67
-
68
static void bcm2836_init(Object *obj)
69
{
70
BCM283XState *s = BCM283X(obj);
71
BCM283XClass *bc = BCM283X_GET_CLASS(obj);
72
- const BCM283XInfo *info = bc->info;
73
int n;
74
75
for (n = 0; n < BCM283X_NCPUS; n++) {
76
object_initialize_child(obj, "cpu[*]", &s->cpu[n].core,
77
- info->cpu_type);
78
+ bc->cpu_type);
79
}
80
81
object_initialize_child(obj, "control", &s->control, TYPE_BCM2836_CONTROL);
82
@@ -XXX,XX +XXX,XX @@ static void bcm2836_realize(DeviceState *dev, Error **errp)
83
{
84
BCM283XState *s = BCM283X(dev);
85
BCM283XClass *bc = BCM283X_GET_CLASS(dev);
86
- const BCM283XInfo *info = bc->info;
87
Object *obj;
88
int n;
89
90
@@ -XXX,XX +XXX,XX @@ static void bcm2836_realize(DeviceState *dev, Error **errp)
91
"sd-bus");
92
93
sysbus_mmio_map_overlap(SYS_BUS_DEVICE(&s->peripherals), 0,
94
- info->peri_base, 1);
95
+ bc->peri_base, 1);
96
97
/* bcm2836 interrupt controller (and mailboxes, etc.) */
98
if (!sysbus_realize(SYS_BUS_DEVICE(&s->control), errp)) {
99
return;
100
}
101
102
- sysbus_mmio_map(SYS_BUS_DEVICE(&s->control), 0, info->ctrl_base);
103
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->control), 0, bc->ctrl_base);
104
105
sysbus_connect_irq(SYS_BUS_DEVICE(&s->peripherals), 0,
106
qdev_get_gpio_in_named(DEVICE(&s->control), "gpu-irq", 0));
107
@@ -XXX,XX +XXX,XX @@ static void bcm2836_realize(DeviceState *dev, Error **errp)
108
109
for (n = 0; n < BCM283X_NCPUS; n++) {
110
/* TODO: this should be converted to a property of ARM_CPU */
111
- s->cpu[n].core.mp_affinity = (info->clusterid << 8) | n;
112
+ s->cpu[n].core.mp_affinity = (bc->clusterid << 8) | n;
113
114
/* set periphbase/CBAR value for CPU-local registers */
115
if (!object_property_set_int(OBJECT(&s->cpu[n].core), "reset-cbar",
116
- info->peri_base, errp)) {
117
+ bc->peri_base, errp)) {
118
return;
119
}
89
}
120
90
121
@@ -XXX,XX +XXX,XX @@ static Property bcm2836_props[] = {
91
if (tx_desc_get_used(desc)) {
122
static void bcm283x_class_init(ObjectClass *oc, void *data)
92
- s->regs[R_TXSTATUS] |= GEM_TXSTATUS_USED;
123
{
93
+ s->regs[R_TXSTATUS] |= R_TXSTATUS_USED_BIT_READ_MASK;
124
DeviceClass *dc = DEVICE_CLASS(oc);
94
/* IRQ TXUSED is defined only for queue 0 */
125
- BCM283XClass *bc = BCM283X_CLASS(oc);
95
if (q == 0) {
126
96
gem_set_isr(s, 0, GEM_INT_TXUSED);
127
- bc->info = data;
128
- dc->realize = bcm2836_realize;
129
- device_class_set_props(dc, bcm2836_props);
130
/* Reason: Must be wired up in code (see raspi_init() function) */
131
dc->user_creatable = false;
132
}
133
134
-static const TypeInfo bcm283x_type_info = {
135
- .name = TYPE_BCM283X,
136
- .parent = TYPE_DEVICE,
137
- .instance_size = sizeof(BCM283XState),
138
- .instance_init = bcm2836_init,
139
- .class_size = sizeof(BCM283XClass),
140
- .abstract = true,
141
+static void bcm2836_class_init(ObjectClass *oc, void *data)
142
+{
143
+ DeviceClass *dc = DEVICE_CLASS(oc);
144
+ BCM283XClass *bc = BCM283X_CLASS(oc);
145
+
146
+ bc->cpu_type = ARM_CPU_TYPE_NAME("cortex-a7");
147
+ bc->peri_base = 0x3f000000;
148
+ bc->ctrl_base = 0x40000000;
149
+ bc->clusterid = 0xf;
150
+ dc->realize = bcm2836_realize;
151
+ device_class_set_props(dc, bcm2836_props);
152
};
153
154
-static void bcm2836_register_types(void)
155
+#ifdef TARGET_AARCH64
156
+static void bcm2837_class_init(ObjectClass *oc, void *data)
157
{
158
- int i;
159
+ DeviceClass *dc = DEVICE_CLASS(oc);
160
+ BCM283XClass *bc = BCM283X_CLASS(oc);
161
162
- type_register_static(&bcm283x_type_info);
163
- for (i = 0; i < ARRAY_SIZE(bcm283x_socs); i++) {
164
- TypeInfo ti = {
165
- .name = bcm283x_socs[i].name,
166
- .parent = TYPE_BCM283X,
167
- .class_init = bcm283x_class_init,
168
- .class_data = (void *) &bcm283x_socs[i],
169
- };
170
- type_register(&ti);
171
+ bc->cpu_type = ARM_CPU_TYPE_NAME("cortex-a53");
172
+ bc->peri_base = 0x3f000000;
173
+ bc->ctrl_base = 0x40000000;
174
+ bc->clusterid = 0x0;
175
+ dc->realize = bcm2836_realize;
176
+ device_class_set_props(dc, bcm2836_props);
177
+};
178
+#endif
179
+
180
+static const TypeInfo bcm283x_types[] = {
181
+ {
182
+ .name = TYPE_BCM2836,
183
+ .parent = TYPE_BCM283X,
184
+ .class_init = bcm2836_class_init,
185
+#ifdef TARGET_AARCH64
186
+ }, {
187
+ .name = TYPE_BCM2837,
188
+ .parent = TYPE_BCM283X,
189
+ .class_init = bcm2837_class_init,
190
+#endif
191
+ }, {
192
+ .name = TYPE_BCM283X,
193
+ .parent = TYPE_DEVICE,
194
+ .instance_size = sizeof(BCM283XState),
195
+ .instance_init = bcm2836_init,
196
+ .class_size = sizeof(BCM283XClass),
197
+ .class_init = bcm283x_class_init,
198
+ .abstract = true,
199
}
200
-}
201
+};
202
203
-type_init(bcm2836_register_types)
204
+DEFINE_TYPES(bcm283x_types)
205
--
97
--
206
2.20.1
98
2.34.1
207
208
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Luc Michel <luc.michel@amd.com>
2
2
3
This is a bit clearer than open-coding some of this
3
Use de FIELD macro to describe the IRQ related register fields.
4
with a bare c string.
5
4
6
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
5
Signed-off-by: Luc Michel <luc.michel@amd.com>
7
Message-id: 20201021173749.111103-9-richard.henderson@linaro.org
6
Reviewed-by: sai.pavan.boddu@amd.com
8
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
7
Message-id: 20231017194422.4124691-8-luc.michel@amd.com
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
---
9
---
11
linux-user/elfload.c | 37 ++++++++++++++++++++-----------------
10
hw/net/cadence_gem.c | 51 +++++++++++++++++++++++++++++++++-----------
12
1 file changed, 20 insertions(+), 17 deletions(-)
11
1 file changed, 39 insertions(+), 12 deletions(-)
13
12
14
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
13
diff --git a/hw/net/cadence_gem.c b/hw/net/cadence_gem.c
15
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
16
--- a/linux-user/elfload.c
15
--- a/hw/net/cadence_gem.c
17
+++ b/linux-user/elfload.c
16
+++ b/hw/net/cadence_gem.c
18
@@ -XXX,XX +XXX,XX @@
17
@@ -XXX,XX +XXX,XX @@ REG32(RXSTATUS, 0x20) /* RX Status reg */
19
#include "qemu/guest-random.h"
18
FIELD(RXSTATUS, BUF_NOT_AVAILABLE, 0, 1)
20
#include "qemu/units.h"
19
21
#include "qemu/selfmap.h"
20
REG32(ISR, 0x24) /* Interrupt Status reg */
22
+#include "qapi/error.h"
21
+ FIELD(ISR, TX_LOCKUP, 31, 1)
23
22
+ FIELD(ISR, RX_LOCKUP, 30, 1)
24
#ifdef _ARCH_PPC64
23
+ FIELD(ISR, TSU_TIMER, 29, 1)
25
#undef ARCH_DLINFO
24
+ FIELD(ISR, WOL, 28, 1)
26
@@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd,
25
+ FIELD(ISR, RECV_LPI, 27, 1)
27
struct elf_phdr *phdr;
26
+ FIELD(ISR, TSU_SEC_INCR, 26, 1)
28
abi_ulong load_addr, load_bias, loaddr, hiaddr, error;
27
+ FIELD(ISR, PTP_PDELAY_RESP_XMIT, 25, 1)
29
int i, retval;
28
+ FIELD(ISR, PTP_PDELAY_REQ_XMIT, 24, 1)
30
- const char *errmsg;
29
+ FIELD(ISR, PTP_PDELAY_RESP_RECV, 23, 1)
31
+ Error *err = NULL;
30
+ FIELD(ISR, PTP_PDELAY_REQ_RECV, 22, 1)
32
31
+ FIELD(ISR, PTP_SYNC_XMIT, 21, 1)
33
/* First of all, some simple consistency checks */
32
+ FIELD(ISR, PTP_DELAY_REQ_XMIT, 20, 1)
34
- errmsg = "Invalid ELF image for this architecture";
33
+ FIELD(ISR, PTP_SYNC_RECV, 19, 1)
35
if (!elf_check_ident(ehdr)) {
34
+ FIELD(ISR, PTP_DELAY_REQ_RECV, 18, 1)
36
+ error_setg(&err, "Invalid ELF image for this architecture");
35
+ FIELD(ISR, PCS_LP_PAGE_RECV, 17, 1)
37
goto exit_errmsg;
36
+ FIELD(ISR, PCS_AN_COMPLETE, 16, 1)
37
+ FIELD(ISR, EXT_IRQ, 15, 1)
38
+ FIELD(ISR, PAUSE_FRAME_XMIT, 14, 1)
39
+ FIELD(ISR, PAUSE_TIME_ELAPSED, 13, 1)
40
+ FIELD(ISR, PAUSE_FRAME_RECV, 12, 1)
41
+ FIELD(ISR, RESP_NOT_OK, 11, 1)
42
+ FIELD(ISR, RECV_OVERRUN, 10, 1)
43
+ FIELD(ISR, LINK_CHANGE, 9, 1)
44
+ FIELD(ISR, USXGMII_INT, 8, 1)
45
+ FIELD(ISR, XMIT_COMPLETE, 7, 1)
46
+ FIELD(ISR, AMBA_ERROR, 6, 1)
47
+ FIELD(ISR, RETRY_EXCEEDED, 5, 1)
48
+ FIELD(ISR, XMIT_UNDER_RUN, 4, 1)
49
+ FIELD(ISR, TX_USED, 3, 1)
50
+ FIELD(ISR, RX_USED, 2, 1)
51
+ FIELD(ISR, RECV_COMPLETE, 1, 1)
52
+ FIELD(ISR, MGNT_FRAME_SENT, 0, 1)
53
REG32(IER, 0x28) /* Interrupt Enable reg */
54
REG32(IDR, 0x2c) /* Interrupt Disable reg */
55
REG32(IMR, 0x30) /* Interrupt Mask reg */
56
+
57
REG32(PHYMNTNC, 0x34) /* Phy Maintenance reg */
58
REG32(RXPAUSE, 0x38) /* RX Pause Time reg */
59
REG32(TXPAUSE, 0x3c) /* TX Pause Time reg */
60
@@ -XXX,XX +XXX,XX @@ REG32(TYPE2_COMPARE_0_WORD_1, 0x704)
61
/*****************************************/
62
63
64
-/* GEM_ISR GEM_IER GEM_IDR GEM_IMR */
65
-#define GEM_INT_TXCMPL 0x00000080 /* Transmit Complete */
66
-#define GEM_INT_AMBA_ERR 0x00000040
67
-#define GEM_INT_TXUSED 0x00000008
68
-#define GEM_INT_RXUSED 0x00000004
69
-#define GEM_INT_RXCMPL 0x00000002
70
71
#define GEM_PHYMNTNC_OP_R 0x20000000 /* read operation */
72
#define GEM_PHYMNTNC_OP_W 0x10000000 /* write operation */
73
@@ -XXX,XX +XXX,XX @@ static void gem_get_rx_desc(CadenceGEMState *s, int q)
74
if (rx_desc_get_ownership(s->rx_desc[q]) == 1) {
75
DB_PRINT("descriptor 0x%" HWADDR_PRIx " owned by sw.\n", desc_addr);
76
s->regs[R_RXSTATUS] |= R_RXSTATUS_BUF_NOT_AVAILABLE_MASK;
77
- gem_set_isr(s, q, GEM_INT_RXUSED);
78
+ gem_set_isr(s, q, R_ISR_RX_USED_MASK);
79
/* Handle interrupt consequences */
80
gem_update_int_status(s);
38
}
81
}
39
bswap_ehdr(ehdr);
82
@@ -XXX,XX +XXX,XX @@ static ssize_t gem_receive(NetClientState *nc, const uint8_t *buf, size_t size)
40
if (!elf_check_ehdr(ehdr)) {
83
41
+ error_setg(&err, "Invalid ELF image for this architecture");
84
if (size > gem_get_max_buf_len(s, false)) {
42
goto exit_errmsg;
85
qemu_log_mask(LOG_GUEST_ERROR, "rx frame too long\n");
86
- gem_set_isr(s, q, GEM_INT_AMBA_ERR);
87
+ gem_set_isr(s, q, R_ISR_AMBA_ERROR_MASK);
88
return -1;
43
}
89
}
44
90
45
@@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd,
91
@@ -XXX,XX +XXX,XX @@ static ssize_t gem_receive(NetClientState *nc, const uint8_t *buf, size_t size)
46
g_autofree char *interp_name = NULL;
92
gem_receive_updatestats(s, buf, size);
47
93
48
if (*pinterp_name) {
94
s->regs[R_RXSTATUS] |= R_RXSTATUS_FRAME_RECEIVED_MASK;
49
- errmsg = "Multiple PT_INTERP entries";
95
- gem_set_isr(s, q, GEM_INT_RXCMPL);
50
+ error_setg(&err, "Multiple PT_INTERP entries");
96
+ gem_set_isr(s, q, R_ISR_RECV_COMPLETE_MASK);
51
goto exit_errmsg;
97
98
/* Handle interrupt consequences */
99
gem_update_int_status(s);
100
@@ -XXX,XX +XXX,XX @@ static void gem_transmit(CadenceGEMState *s)
101
HWADDR_PRIx " too large: size 0x%x space 0x%zx\n",
102
packet_desc_addr, tx_desc_get_length(desc),
103
gem_get_max_buf_len(s, true) - (p - s->tx_packet));
104
- gem_set_isr(s, q, GEM_INT_AMBA_ERR);
105
+ gem_set_isr(s, q, R_ISR_AMBA_ERROR_MASK);
106
break;
52
}
107
}
53
+
108
54
interp_name = g_malloc(eppnt->p_filesz);
109
@@ -XXX,XX +XXX,XX @@ static void gem_transmit(CadenceGEMState *s)
55
- if (!interp_name) {
110
DB_PRINT("TX descriptor next: 0x%08x\n", s->tx_desc_addr[q]);
56
- goto exit_perror;
111
57
- }
112
s->regs[R_TXSTATUS] |= R_TXSTATUS_TRANSMIT_COMPLETE_MASK;
58
113
- gem_set_isr(s, q, GEM_INT_TXCMPL);
59
if (eppnt->p_offset + eppnt->p_filesz <= BPRM_BUF_SIZE) {
114
+ gem_set_isr(s, q, R_ISR_XMIT_COMPLETE_MASK);
60
memcpy(interp_name, bprm_buf + eppnt->p_offset,
115
61
@@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd,
116
/* Handle interrupt consequences */
62
retval = pread(image_fd, interp_name, eppnt->p_filesz,
117
gem_update_int_status(s);
63
eppnt->p_offset);
118
@@ -XXX,XX +XXX,XX @@ static void gem_transmit(CadenceGEMState *s)
64
if (retval != eppnt->p_filesz) {
119
s->regs[R_TXSTATUS] |= R_TXSTATUS_USED_BIT_READ_MASK;
65
- goto exit_perror;
120
/* IRQ TXUSED is defined only for queue 0 */
66
+ goto exit_read;
121
if (q == 0) {
67
}
122
- gem_set_isr(s, 0, GEM_INT_TXUSED);
123
+ gem_set_isr(s, 0, R_ISR_TX_USED_MASK);
68
}
124
}
69
if (interp_name[eppnt->p_filesz - 1] != 0) {
125
gem_update_int_status(s);
70
- errmsg = "Invalid PT_INTERP entry";
126
}
71
+ error_setg(&err, "Invalid PT_INTERP entry");
72
goto exit_errmsg;
73
}
74
*pinterp_name = g_steal_pointer(&interp_name);
75
@@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd,
76
(ehdr->e_type == ET_EXEC ? MAP_FIXED : 0),
77
-1, 0);
78
if (load_addr == -1) {
79
- goto exit_perror;
80
+ goto exit_mmap;
81
}
82
load_bias = load_addr - loaddr;
83
84
@@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd,
85
image_fd, eppnt->p_offset - vaddr_po);
86
87
if (error == -1) {
88
- goto exit_perror;
89
+ goto exit_mmap;
90
}
91
}
92
93
@@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd,
94
} else if (eppnt->p_type == PT_MIPS_ABIFLAGS) {
95
Mips_elf_abiflags_v0 abiflags;
96
if (eppnt->p_filesz < sizeof(Mips_elf_abiflags_v0)) {
97
- errmsg = "Invalid PT_MIPS_ABIFLAGS entry";
98
+ error_setg(&err, "Invalid PT_MIPS_ABIFLAGS entry");
99
goto exit_errmsg;
100
}
101
if (eppnt->p_offset + eppnt->p_filesz <= BPRM_BUF_SIZE) {
102
@@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd,
103
retval = pread(image_fd, &abiflags, sizeof(Mips_elf_abiflags_v0),
104
eppnt->p_offset);
105
if (retval != sizeof(Mips_elf_abiflags_v0)) {
106
- goto exit_perror;
107
+ goto exit_read;
108
}
109
}
110
bswap_mips_abiflags(&abiflags);
111
@@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd,
112
113
exit_read:
114
if (retval >= 0) {
115
- errmsg = "Incomplete read of file header";
116
- goto exit_errmsg;
117
+ error_setg(&err, "Incomplete read of file header");
118
+ } else {
119
+ error_setg_errno(&err, errno, "Error reading file header");
120
}
121
- exit_perror:
122
- errmsg = strerror(errno);
123
+ goto exit_errmsg;
124
+ exit_mmap:
125
+ error_setg_errno(&err, errno, "Error mapping file");
126
+ goto exit_errmsg;
127
exit_errmsg:
128
- fprintf(stderr, "%s: %s\n", image_name, errmsg);
129
+ error_reportf_err(err, "%s: ", image_name);
130
exit(-1);
131
}
132
133
--
127
--
134
2.20.1
128
2.34.1
135
136
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Luc Michel <luc.michel@amd.com>
2
2
3
The second loop uses a loop induction variable, and the first
3
Use the FIELD macro to describe the DESCONF6 register fields.
4
does not. Transform the first to match the second, to simplify
5
a following patch moving code between them.
6
4
7
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
5
Signed-off-by: Luc Michel <luc.michel@amd.com>
8
Message-id: 20201021173749.111103-7-richard.henderson@linaro.org
6
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
9
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
7
Message-id: 20231017194422.4124691-9-luc.michel@amd.com
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
---
9
---
12
linux-user/elfload.c | 9 +++++----
10
hw/net/cadence_gem.c | 4 ++--
13
1 file changed, 5 insertions(+), 4 deletions(-)
11
1 file changed, 2 insertions(+), 2 deletions(-)
14
12
15
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
13
diff --git a/hw/net/cadence_gem.c b/hw/net/cadence_gem.c
16
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
17
--- a/linux-user/elfload.c
15
--- a/hw/net/cadence_gem.c
18
+++ b/linux-user/elfload.c
16
+++ b/hw/net/cadence_gem.c
19
@@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd,
17
@@ -XXX,XX +XXX,XX @@ REG32(DESCONF3, 0x288)
20
loaddr = -1, hiaddr = 0;
18
REG32(DESCONF4, 0x28c)
21
info->alignment = 0;
19
REG32(DESCONF5, 0x290)
22
for (i = 0; i < ehdr->e_phnum; ++i) {
20
REG32(DESCONF6, 0x294)
23
- if (phdr[i].p_type == PT_LOAD) {
21
-#define GEM_DESCONF6_64B_MASK (1U << 23)
24
- abi_ulong a = phdr[i].p_vaddr - phdr[i].p_offset;
22
+ FIELD(DESCONF6, DMA_ADDR_64B, 23, 1)
25
+ struct elf_phdr *eppnt = phdr + i;
23
REG32(DESCONF7, 0x298)
26
+ if (eppnt->p_type == PT_LOAD) {
24
27
+ abi_ulong a = eppnt->p_vaddr - eppnt->p_offset;
25
REG32(INT_Q1_STATUS, 0x400)
28
if (a < loaddr) {
26
@@ -XXX,XX +XXX,XX @@ static void gem_reset(DeviceState *d)
29
loaddr = a;
27
s->regs[R_DESCONF] = 0x02D00111;
30
}
28
s->regs[R_DESCONF2] = 0x2ab10000 | s->jumbo_max_len;
31
- a = phdr[i].p_vaddr + phdr[i].p_memsz;
29
s->regs[R_DESCONF5] = 0x002f2045;
32
+ a = eppnt->p_vaddr + eppnt->p_memsz;
30
- s->regs[R_DESCONF6] = GEM_DESCONF6_64B_MASK;
33
if (a > hiaddr) {
31
+ s->regs[R_DESCONF6] = R_DESCONF6_DMA_ADDR_64B_MASK;
34
hiaddr = a;
32
s->regs[R_INT_Q1_MASK] = 0x00000CE6;
35
}
33
s->regs[R_JUMBO_MAX_LEN] = s->jumbo_max_len;
36
++info->nsegs;
37
- info->alignment |= phdr[i].p_align;
38
+ info->alignment |= eppnt->p_align;
39
}
40
}
41
34
42
--
35
--
43
2.20.1
36
2.34.1
44
37
45
38
diff view generated by jsdifflib
Deleted patch
1
From: Richard Henderson <richard.henderson@linaro.org>
2
1
3
Use the new generic support for NT_GNU_PROPERTY_TYPE_0.
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>
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
---
10
linux-user/elfload.c | 48 ++++++++++++++++++++++++++++++++++++++++++--
11
1 file changed, 46 insertions(+), 2 deletions(-)
12
13
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
14
index XXXXXXX..XXXXXXX 100644
15
--- a/linux-user/elfload.c
16
+++ b/linux-user/elfload.c
17
@@ -XXX,XX +XXX,XX @@ static void elf_core_copy_regs(target_elf_gregset_t *regs,
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,
47
}
48
#define ARCH_USE_GNU_PROPERTY 0
49
50
+#endif
51
+
52
struct exec
53
{
54
unsigned int a_info; /* Use macros N_MAGIC, etc for access */
55
@@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd,
56
struct elfhdr *ehdr = (struct elfhdr *)bprm_buf;
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
87
+
88
for (i = 0; i < ehdr->e_phnum; i++) {
89
struct elf_phdr *eppnt = phdr + i;
90
if (eppnt->p_type == PT_LOAD) {
91
@@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd,
92
elf_prot |= PROT_WRITE;
93
}
94
if (eppnt->p_flags & PF_X) {
95
- elf_prot |= PROT_EXEC;
96
+ elf_prot |= prot_exec;
97
}
98
99
vaddr = load_bias + eppnt->p_vaddr;
100
--
101
2.20.1
102
103
diff view generated by jsdifflib
Deleted patch
1
From: Thomas Huth <thuth@redhat.com>
2
1
3
When compiling with -Werror=implicit-fallthrough, gcc complains about
4
missing fallthrough annotations in this file. Looking at the code,
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>
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
---
13
hw/arm/highbank.c | 2 ++
14
1 file changed, 2 insertions(+)
15
16
diff --git a/hw/arm/highbank.c b/hw/arm/highbank.c
17
index XXXXXXX..XXXXXXX 100644
18
--- a/hw/arm/highbank.c
19
+++ b/hw/arm/highbank.c
20
@@ -XXX,XX +XXX,XX @@ static void hb_reset_secondary(ARMCPU *cpu, const struct arm_boot_info *info)
21
address_space_stl_notdirty(&address_space_memory,
22
SMP_BOOT_REG + 0x30, 0,
23
MEMTXATTRS_UNSPECIFIED, NULL);
24
+ /* fallthrough */
25
case 3:
26
address_space_stl_notdirty(&address_space_memory,
27
SMP_BOOT_REG + 0x20, 0,
28
MEMTXATTRS_UNSPECIFIED, NULL);
29
+ /* fallthrough */
30
case 2:
31
address_space_stl_notdirty(&address_space_memory,
32
SMP_BOOT_REG + 0x10, 0,
33
--
34
2.20.1
35
36
diff view generated by jsdifflib
1
In ptimer_reload(), we call the callback function provided by the
1
From: Luc Michel <luc.michel@amd.com>
2
timer device that is using the ptimer. This callback might disable
3
the ptimer. The code mostly handles this correctly, except that
4
we'll still print the warning about "Timer with delta zero,
5
disabling" if the now-disabled timer happened to be set such that it
6
would fire again immediately if it were enabled (eg because the
7
limit/reload value is zero).
8
2
9
Suppress the spurious warning message and the unnecessary
3
Use the FIELD macro to describe the PHYMNTNC register fields.
10
repeat-deletion of the underlying timer in this case.
11
4
5
Signed-off-by: Luc Michel <luc.michel@amd.com>
6
Reviewed-by: sai.pavan.boddu@amd.com
7
Message-id: 20231017194422.4124691-10-luc.michel@amd.com
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
14
Message-id: 20201015151829.14656-2-peter.maydell@linaro.org
15
---
9
---
16
hw/core/ptimer.c | 4 ++++
10
hw/net/cadence_gem.c | 27 ++++++++++++++-------------
17
1 file changed, 4 insertions(+)
11
1 file changed, 14 insertions(+), 13 deletions(-)
18
12
19
diff --git a/hw/core/ptimer.c b/hw/core/ptimer.c
13
diff --git a/hw/net/cadence_gem.c b/hw/net/cadence_gem.c
20
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
21
--- a/hw/core/ptimer.c
15
--- a/hw/net/cadence_gem.c
22
+++ b/hw/core/ptimer.c
16
+++ b/hw/net/cadence_gem.c
23
@@ -XXX,XX +XXX,XX @@ static void ptimer_reload(ptimer_state *s, int delta_adjust)
17
@@ -XXX,XX +XXX,XX @@ REG32(IDR, 0x2c) /* Interrupt Disable reg */
24
}
18
REG32(IMR, 0x30) /* Interrupt Mask reg */
25
19
26
if (delta == 0) {
20
REG32(PHYMNTNC, 0x34) /* Phy Maintenance reg */
27
+ if (s->enabled == 0) {
21
+ FIELD(PHYMNTNC, DATA, 0, 16)
28
+ /* trigger callback disabled the timer already */
22
+ FIELD(PHYMNTNC, REG_ADDR, 18, 5)
29
+ return;
23
+ FIELD(PHYMNTNC, PHY_ADDR, 23, 5)
30
+ }
24
+ FIELD(PHYMNTNC, OP, 28, 2)
31
if (!qtest_enabled()) {
25
+ FIELD(PHYMNTNC, ST, 30, 2)
32
fprintf(stderr, "Timer with delta zero, disabling\n");
26
+#define MDIO_OP_READ 0x3
27
+#define MDIO_OP_WRITE 0x2
28
+
29
REG32(RXPAUSE, 0x38) /* RX Pause Time reg */
30
REG32(TXPAUSE, 0x3c) /* TX Pause Time reg */
31
REG32(TXPARTIALSF, 0x40) /* TX Partial Store and Forward */
32
@@ -XXX,XX +XXX,XX @@ REG32(TYPE2_COMPARE_0_WORD_1, 0x704)
33
34
35
36
-#define GEM_PHYMNTNC_OP_R 0x20000000 /* read operation */
37
-#define GEM_PHYMNTNC_OP_W 0x10000000 /* write operation */
38
-#define GEM_PHYMNTNC_ADDR 0x0F800000 /* Address bits */
39
-#define GEM_PHYMNTNC_ADDR_SHFT 23
40
-#define GEM_PHYMNTNC_REG 0x007C0000 /* register bits */
41
-#define GEM_PHYMNTNC_REG_SHIFT 18
42
-
43
/* Marvell PHY definitions */
44
#define BOARD_PHY_ADDRESS 0 /* PHY address we will emulate a device at */
45
46
@@ -XXX,XX +XXX,XX @@ static uint64_t gem_read(void *opaque, hwaddr offset, unsigned size)
47
/* The interrupts get updated at the end of the function. */
48
break;
49
case R_PHYMNTNC:
50
- if (retval & GEM_PHYMNTNC_OP_R) {
51
+ if (FIELD_EX32(retval, PHYMNTNC, OP) == MDIO_OP_READ) {
52
uint32_t phy_addr, reg_num;
53
54
- phy_addr = (retval & GEM_PHYMNTNC_ADDR) >> GEM_PHYMNTNC_ADDR_SHFT;
55
+ phy_addr = FIELD_EX32(retval, PHYMNTNC, PHY_ADDR);
56
if (phy_addr == s->phy_addr) {
57
- reg_num = (retval & GEM_PHYMNTNC_REG) >> GEM_PHYMNTNC_REG_SHIFT;
58
+ reg_num = FIELD_EX32(retval, PHYMNTNC, REG_ADDR);
59
retval &= 0xFFFF0000;
60
retval |= gem_phy_read(s, reg_num);
61
} else {
62
@@ -XXX,XX +XXX,XX @@ static void gem_write(void *opaque, hwaddr offset, uint64_t val,
63
s->sar_active[(offset - R_SPADDR1HI) / 2] = true;
64
break;
65
case R_PHYMNTNC:
66
- if (val & GEM_PHYMNTNC_OP_W) {
67
+ if (FIELD_EX32(val, PHYMNTNC, OP) == MDIO_OP_WRITE) {
68
uint32_t phy_addr, reg_num;
69
70
- phy_addr = (val & GEM_PHYMNTNC_ADDR) >> GEM_PHYMNTNC_ADDR_SHFT;
71
+ phy_addr = FIELD_EX32(val, PHYMNTNC, PHY_ADDR);
72
if (phy_addr == s->phy_addr) {
73
- reg_num = (val & GEM_PHYMNTNC_REG) >> GEM_PHYMNTNC_REG_SHIFT;
74
+ reg_num = FIELD_EX32(val, PHYMNTNC, REG_ADDR);
75
gem_phy_write(s, reg_num, val);
76
}
33
}
77
}
34
--
78
--
35
2.20.1
79
2.34.1
36
37
diff view generated by jsdifflib
1
From: Havard Skinnemoen <hskinnemoen@google.com>
1
From: Luc Michel <luc.michel@amd.com>
2
2
3
The NPCM7xx chips have multiple GPIO controllers that are mostly
3
The MDIO access is done only on a write to the PHYMNTNC register. A
4
identical except for some minor differences like the reset values of
4
subsequent read is used to retrieve the result but does not trigger an
5
some registers. Each controller controls up to 32 pins.
5
MDIO access by itself.
6
6
7
Each individual pin is modeled as a pair of unnamed GPIOs -- one for
7
Refactor the PHY access logic to perform all accesses (MDIO reads and
8
emitting the actual pin state, and one for driving the pin externally.
8
writes) at PHYMNTNC write time.
9
Like the nRF51 GPIO controller, a gpio level may be negative, which
10
means the pin is not driven, or floating.
11
9
12
Reviewed-by: Tyrone Ting <kfting@nuvoton.com>
10
Signed-off-by: Luc Michel <luc.michel@amd.com>
13
Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
11
Reviewed-by: sai.pavan.boddu@amd.com
14
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
12
Message-id: 20231017194422.4124691-11-luc.michel@amd.com
15
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
16
---
14
---
17
docs/system/arm/nuvoton.rst | 2 +-
15
hw/net/cadence_gem.c | 56 ++++++++++++++++++++++++++------------------
18
include/hw/arm/npcm7xx.h | 2 +
16
1 file changed, 33 insertions(+), 23 deletions(-)
19
include/hw/gpio/npcm7xx_gpio.h | 55 +++++
20
hw/arm/npcm7xx.c | 80 ++++++
21
hw/gpio/npcm7xx_gpio.c | 424 ++++++++++++++++++++++++++++++++
22
tests/qtest/npcm7xx_gpio-test.c | 385 +++++++++++++++++++++++++++++
23
hw/gpio/meson.build | 1 +
24
hw/gpio/trace-events | 7 +
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
30
17
31
diff --git a/docs/system/arm/nuvoton.rst b/docs/system/arm/nuvoton.rst
18
diff --git a/hw/net/cadence_gem.c b/hw/net/cadence_gem.c
32
index XXXXXXX..XXXXXXX 100644
19
index XXXXXXX..XXXXXXX 100644
33
--- a/docs/system/arm/nuvoton.rst
20
--- a/hw/net/cadence_gem.c
34
+++ b/docs/system/arm/nuvoton.rst
21
+++ b/hw/net/cadence_gem.c
35
@@ -XXX,XX +XXX,XX @@ Supported devices
22
@@ -XXX,XX +XXX,XX @@ static void gem_phy_write(CadenceGEMState *s, unsigned reg_num, uint16_t val)
36
* Flash Interface Unit (FIU; no protection features)
23
s->phy_regs[reg_num] = val;
37
* Random Number Generator (RNG)
24
}
38
* USB host (USBH)
25
39
+ * GPIO controller
26
+static void gem_handle_phy_access(CadenceGEMState *s)
40
27
+{
41
Missing devices
28
+ uint32_t val = s->regs[R_PHYMNTNC];
42
---------------
29
+ uint32_t phy_addr, reg_num;
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
49
index XXXXXXX..XXXXXXX 100644
50
--- a/include/hw/arm/npcm7xx.h
51
+++ b/include/hw/arm/npcm7xx.h
52
@@ -XXX,XX +XXX,XX @@
53
54
#include "hw/boards.h"
55
#include "hw/cpu/a9mpcore.h"
56
+#include "hw/gpio/npcm7xx_gpio.h"
57
#include "hw/mem/npcm7xx_mc.h"
58
#include "hw/misc/npcm7xx_clk.h"
59
#include "hw/misc/npcm7xx_gcr.h"
60
@@ -XXX,XX +XXX,XX @@ typedef struct NPCM7xxState {
61
NPCM7xxOTPState fuse_array;
62
NPCM7xxMCState mc;
63
NPCM7xxRNGState rng;
64
+ NPCM7xxGPIOState gpio[8];
65
EHCISysBusState ehci;
66
OHCISysBusState ohci;
67
NPCM7xxFIUState fiu[2];
68
diff --git a/include/hw/gpio/npcm7xx_gpio.h b/include/hw/gpio/npcm7xx_gpio.h
69
new file mode 100644
70
index XXXXXXX..XXXXXXX
71
--- /dev/null
72
+++ b/include/hw/gpio/npcm7xx_gpio.h
73
@@ -XXX,XX +XXX,XX @@
74
+/*
75
+ * Nuvoton NPCM7xx General Purpose Input / Output (GPIO)
76
+ *
77
+ * Copyright 2020 Google LLC
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.
87
+ */
88
+#ifndef NPCM7XX_GPIO_H
89
+#define NPCM7XX_GPIO_H
90
+
30
+
91
+#include "exec/memory.h"
31
+ phy_addr = FIELD_EX32(val, PHYMNTNC, PHY_ADDR);
92
+#include "hw/sysbus.h"
93
+
32
+
94
+/* Number of pins managed by each controller. */
33
+ if (phy_addr != s->phy_addr) {
95
+#define NPCM7XX_GPIO_NR_PINS (32)
34
+ /* no phy at this address */
96
+
35
+ if (FIELD_EX32(val, PHYMNTNC, OP) == MDIO_OP_READ) {
97
+/*
36
+ s->regs[R_PHYMNTNC] = FIELD_DP32(val, PHYMNTNC, DATA, 0xffff);
98
+ * Number of registers in our device state structure. Don't change this without
37
+ }
99
+ * incrementing the version_id in the vmstate.
38
+ return;
100
+ */
101
+#define NPCM7XX_GPIO_NR_REGS (0x80 / sizeof(uint32_t))
102
+
103
+typedef struct NPCM7xxGPIOState {
104
+ SysBusDevice parent;
105
+
106
+ /* Properties to be defined by the SoC */
107
+ uint32_t reset_pu;
108
+ uint32_t reset_pd;
109
+ uint32_t reset_osrc;
110
+ uint32_t reset_odsc;
111
+
112
+ MemoryRegion mmio;
113
+
114
+ qemu_irq irq;
115
+ qemu_irq output[NPCM7XX_GPIO_NR_PINS];
116
+
117
+ uint32_t pin_level;
118
+ uint32_t ext_level;
119
+ uint32_t ext_driven;
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
130
index XXXXXXX..XXXXXXX 100644
131
--- a/hw/arm/npcm7xx.c
132
+++ b/hw/arm/npcm7xx.c
133
@@ -XXX,XX +XXX,XX @@ enum NPCM7xxInterrupt {
134
NPCM7XX_WDG2_IRQ, /* Timer Module 2 Watchdog */
135
NPCM7XX_EHCI_IRQ = 61,
136
NPCM7XX_OHCI_IRQ = 62,
137
+ NPCM7XX_GPIO0_IRQ = 116,
138
+ NPCM7XX_GPIO1_IRQ,
139
+ NPCM7XX_GPIO2_IRQ,
140
+ NPCM7XX_GPIO3_IRQ,
141
+ NPCM7XX_GPIO4_IRQ,
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);
206
}
207
208
+ for (i = 0; i < ARRAY_SIZE(s->gpio); i++) {
209
+ object_initialize_child(obj, "gpio[*]", &s->gpio[i], TYPE_NPCM7XX_GPIO);
210
+ }
39
+ }
211
+
40
+
212
object_initialize_child(obj, "ehci", &s->ehci, TYPE_NPCM7XX_EHCI);
41
+ reg_num = FIELD_EX32(val, PHYMNTNC, REG_ADDR);
213
object_initialize_child(obj, "ohci", &s->ohci, TYPE_SYSBUS_OHCI);
214
215
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp)
216
sysbus_realize(SYS_BUS_DEVICE(&s->rng), &error_abort);
217
sysbus_mmio_map(SYS_BUS_DEVICE(&s->rng), 0, NPCM7XX_RNG_BA);
218
219
+ /* GPIO modules. Cannot fail. */
220
+ QEMU_BUILD_BUG_ON(ARRAY_SIZE(npcm7xx_gpio) != ARRAY_SIZE(s->gpio));
221
+ for (i = 0; i < ARRAY_SIZE(s->gpio); i++) {
222
+ Object *obj = OBJECT(&s->gpio[i]);
223
+
42
+
224
+ object_property_set_uint(obj, "reset-pullup",
43
+ switch (FIELD_EX32(val, PHYMNTNC, OP)) {
225
+ npcm7xx_gpio[i].reset_pu, &error_abort);
44
+ case MDIO_OP_READ:
226
+ object_property_set_uint(obj, "reset-pulldown",
45
+ s->regs[R_PHYMNTNC] = FIELD_DP32(val, PHYMNTNC, DATA,
227
+ npcm7xx_gpio[i].reset_pd, &error_abort);
46
+ gem_phy_read(s, reg_num));
228
+ object_property_set_uint(obj, "reset-osrc",
229
+ npcm7xx_gpio[i].reset_osrc, &error_abort);
230
+ object_property_set_uint(obj, "reset-odsc",
231
+ npcm7xx_gpio[i].reset_odsc, &error_abort);
232
+ sysbus_realize(SYS_BUS_DEVICE(obj), &error_abort);
233
+ sysbus_mmio_map(SYS_BUS_DEVICE(obj), 0, npcm7xx_gpio[i].regs_addr);
234
+ sysbus_connect_irq(SYS_BUS_DEVICE(obj), 0,
235
+ npcm7xx_irq(s, NPCM7XX_GPIO0_IRQ + i));
236
+ }
237
+
238
/* USB Host */
239
object_property_set_bool(OBJECT(&s->ehci), "companion-enable", true,
240
&error_abort);
241
diff --git a/hw/gpio/npcm7xx_gpio.c b/hw/gpio/npcm7xx_gpio.c
242
new file mode 100644
243
index XXXXXXX..XXXXXXX
244
--- /dev/null
245
+++ b/hw/gpio/npcm7xx_gpio.c
246
@@ -XXX,XX +XXX,XX @@
247
+/*
248
+ * Nuvoton NPCM7xx General Purpose Input / Output (GPIO)
249
+ *
250
+ * Copyright 2020 Google LLC
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.
260
+ */
261
+
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"
269
+#include "qemu/log.h"
270
+#include "qemu/module.h"
271
+#include "qemu/units.h"
272
+#include "trace.h"
273
+
274
+/* 32-bit register indices. */
275
+enum NPCM7xxGPIORegister {
276
+ NPCM7XX_GPIO_TLOCK1,
277
+ NPCM7XX_GPIO_DIN,
278
+ NPCM7XX_GPIO_POL,
279
+ NPCM7XX_GPIO_DOUT,
280
+ NPCM7XX_GPIO_OE,
281
+ NPCM7XX_GPIO_OTYP,
282
+ NPCM7XX_GPIO_MP,
283
+ NPCM7XX_GPIO_PU,
284
+ NPCM7XX_GPIO_PD,
285
+ NPCM7XX_GPIO_DBNC,
286
+ NPCM7XX_GPIO_EVTYP,
287
+ NPCM7XX_GPIO_EVBE,
288
+ NPCM7XX_GPIO_OBL0,
289
+ NPCM7XX_GPIO_OBL1,
290
+ NPCM7XX_GPIO_OBL2,
291
+ NPCM7XX_GPIO_OBL3,
292
+ NPCM7XX_GPIO_EVEN,
293
+ NPCM7XX_GPIO_EVENS,
294
+ NPCM7XX_GPIO_EVENC,
295
+ NPCM7XX_GPIO_EVST,
296
+ NPCM7XX_GPIO_SPLCK,
297
+ NPCM7XX_GPIO_MPLCK,
298
+ NPCM7XX_GPIO_IEM,
299
+ NPCM7XX_GPIO_OSRC,
300
+ NPCM7XX_GPIO_ODSC,
301
+ NPCM7XX_GPIO_DOS = 0x68 / sizeof(uint32_t),
302
+ NPCM7XX_GPIO_DOC,
303
+ NPCM7XX_GPIO_OES,
304
+ NPCM7XX_GPIO_OEC,
305
+ NPCM7XX_GPIO_TLOCK2 = 0x7c / sizeof(uint32_t),
306
+ NPCM7XX_GPIO_REGS_END,
307
+};
308
+
309
+#define NPCM7XX_GPIO_REGS_SIZE (4 * KiB)
310
+
311
+#define NPCM7XX_GPIO_LOCK_MAGIC1 (0xc0defa73)
312
+#define NPCM7XX_GPIO_LOCK_MAGIC2 (0xc0de1248)
313
+
314
+static void npcm7xx_gpio_update_events(NPCM7xxGPIOState *s, uint32_t din_diff)
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
+ }
386
+ }
387
+ }
388
+
389
+ /* Calculate new value of DIN after masking and polarity setting. */
390
+ din_old = s->regs[NPCM7XX_GPIO_DIN];
391
+ s->regs[NPCM7XX_GPIO_DIN] = ((s->pin_level & s->regs[NPCM7XX_GPIO_IEM])
392
+ ^ s->regs[NPCM7XX_GPIO_POL]);
393
+
394
+ /* See if any new events triggered because of all this. */
395
+ npcm7xx_gpio_update_events(s, din_old ^ s->regs[NPCM7XX_GPIO_DIN]);
396
+}
397
+
398
+static bool npcm7xx_gpio_is_locked(NPCM7xxGPIOState *s)
399
+{
400
+ return s->regs[NPCM7XX_GPIO_TLOCK1] == 1;
401
+}
402
+
403
+static uint64_t npcm7xx_gpio_regs_read(void *opaque, hwaddr addr,
404
+ unsigned int size)
405
+{
406
+ hwaddr reg = addr / sizeof(uint32_t);
407
+ NPCM7xxGPIOState *s = opaque;
408
+ uint64_t value = 0;
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;
47
+ break;
415
+
48
+
416
+ case NPCM7XX_GPIO_EVENS ... NPCM7XX_GPIO_EVENC:
49
+ case MDIO_OP_WRITE:
417
+ case NPCM7XX_GPIO_DOS ... NPCM7XX_GPIO_TLOCK2:
50
+ gem_phy_write(s, reg_num, val);
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;
51
+ break;
422
+
52
+
423
+ default:
53
+ default:
424
+ qemu_log_mask(LOG_GUEST_ERROR,
54
+ break; /* only clause 22 operations are supported */
425
+ "%s: read from invalid offset 0x%" HWADDR_PRIx "\n",
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:
460
+ qemu_log_mask(LOG_GUEST_ERROR,
461
+ "%s: write to locked register @ 0x%" HWADDR_PRIx "\n",
462
+ DEVICE(s)->canonical_path, addr);
463
+ break;
464
+ }
465
+
466
+ return;
467
+ }
468
+
469
+ diff = s->regs[reg] ^ value;
470
+
471
+ switch (reg) {
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
+ }
55
+ }
562
+}
56
+}
563
+
57
+
564
+static const MemoryRegionOps npcm7xx_gpio_regs_ops = {
58
/*
565
+ .read = npcm7xx_gpio_regs_read,
59
* gem_read32:
566
+ .write = npcm7xx_gpio_regs_write,
60
* Read a GEM register.
567
+ .endianness = DEVICE_NATIVE_ENDIAN,
61
@@ -XXX,XX +XXX,XX @@ static uint64_t gem_read(void *opaque, hwaddr offset, unsigned size)
568
+ .valid = {
62
DB_PRINT("lowering irqs on ISR read\n");
569
+ .min_access_size = 4,
63
/* The interrupts get updated at the end of the function. */
570
+ .max_access_size = 4,
64
break;
571
+ .unaligned = false,
65
- case R_PHYMNTNC:
572
+ },
66
- if (FIELD_EX32(retval, PHYMNTNC, OP) == MDIO_OP_READ) {
573
+};
67
- uint32_t phy_addr, reg_num;
574
+
68
-
575
+static void npcm7xx_gpio_set_input(void *opaque, int line, int level)
69
- phy_addr = FIELD_EX32(retval, PHYMNTNC, PHY_ADDR);
576
+{
70
- if (phy_addr == s->phy_addr) {
577
+ NPCM7xxGPIOState *s = opaque;
71
- reg_num = FIELD_EX32(retval, PHYMNTNC, REG_ADDR);
578
+
72
- retval &= 0xFFFF0000;
579
+ trace_npcm7xx_gpio_set_input(DEVICE(s)->canonical_path, line, level);
73
- retval |= gem_phy_read(s, reg_num);
580
+
74
- } else {
581
+ g_assert(line >= 0 && line < NPCM7XX_GPIO_NR_PINS);
75
- retval |= 0xFFFF; /* No device at this address */
582
+
76
- }
583
+ s->ext_driven = deposit32(s->ext_driven, line, 1, level >= 0);
77
- }
584
+ s->ext_level = deposit32(s->ext_level, line, 1, level > 0);
78
- break;
585
+
79
}
586
+ npcm7xx_gpio_update_pins(s, BIT(line));
80
587
+}
81
/* Squash read to clear bits */
588
+
82
@@ -XXX,XX +XXX,XX @@ static void gem_write(void *opaque, hwaddr offset, uint64_t val,
589
+static void npcm7xx_gpio_enter_reset(Object *obj, ResetType type)
83
s->sar_active[(offset - R_SPADDR1HI) / 2] = true;
590
+{
84
break;
591
+ NPCM7xxGPIOState *s = NPCM7XX_GPIO(obj);
85
case R_PHYMNTNC:
592
+
86
- if (FIELD_EX32(val, PHYMNTNC, OP) == MDIO_OP_WRITE) {
593
+ memset(s->regs, 0, sizeof(s->regs));
87
- uint32_t phy_addr, reg_num;
594
+
88
-
595
+ s->regs[NPCM7XX_GPIO_PU] = s->reset_pu;
89
- phy_addr = FIELD_EX32(val, PHYMNTNC, PHY_ADDR);
596
+ s->regs[NPCM7XX_GPIO_PD] = s->reset_pd;
90
- if (phy_addr == s->phy_addr) {
597
+ s->regs[NPCM7XX_GPIO_OSRC] = s->reset_osrc;
91
- reg_num = FIELD_EX32(val, PHYMNTNC, REG_ADDR);
598
+ s->regs[NPCM7XX_GPIO_ODSC] = s->reset_odsc;
92
- gem_phy_write(s, reg_num, val);
599
+}
93
- }
600
+
94
- }
601
+static void npcm7xx_gpio_hold_reset(Object *obj)
95
+ gem_handle_phy_access(s);
602
+{
96
break;
603
+ NPCM7xxGPIOState *s = NPCM7XX_GPIO(obj);
97
}
604
+
98
605
+ npcm7xx_gpio_update_pins(s, -1);
606
+}
607
+
608
+static void npcm7xx_gpio_init(Object *obj)
609
+{
610
+ NPCM7xxGPIOState *s = NPCM7XX_GPIO(obj);
611
+ DeviceState *dev = DEVICE(obj);
612
+
613
+ memory_region_init_io(&s->mmio, obj, &npcm7xx_gpio_regs_ops, s,
614
+ "regs", NPCM7XX_GPIO_REGS_SIZE);
615
+ sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->mmio);
616
+ sysbus_init_irq(SYS_BUS_DEVICE(obj), &s->irq);
617
+
618
+ qdev_init_gpio_in(dev, npcm7xx_gpio_set_input, NPCM7XX_GPIO_NR_PINS);
619
+ qdev_init_gpio_out(dev, s->output, NPCM7XX_GPIO_NR_PINS);
620
+}
621
+
622
+static const VMStateDescription vmstate_npcm7xx_gpio = {
623
+ .name = "npcm7xx-gpio",
624
+ .version_id = 0,
625
+ .minimum_version_id = 0,
626
+ .fields = (VMStateField[]) {
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),
631
+ VMSTATE_END_OF_LIST(),
632
+ },
633
+};
634
+
635
+static Property npcm7xx_gpio_properties[] = {
636
+ /* Bit n set => pin n has pullup enabled by default. */
637
+ DEFINE_PROP_UINT32("reset-pullup", NPCM7xxGPIOState, reset_pu, 0),
638
+ /* Bit n set => pin n has pulldown enabled by default. */
639
+ DEFINE_PROP_UINT32("reset-pulldown", NPCM7xxGPIOState, reset_pd, 0),
640
+ /* Bit n set => pin n has high slew rate by default. */
641
+ DEFINE_PROP_UINT32("reset-osrc", NPCM7xxGPIOState, reset_osrc, 0),
642
+ /* Bit n set => pin n has high drive strength by default. */
643
+ DEFINE_PROP_UINT32("reset-odsc", NPCM7xxGPIOState, reset_odsc, 0),
644
+ DEFINE_PROP_END_OF_LIST(),
645
+};
646
+
647
+static void npcm7xx_gpio_class_init(ObjectClass *klass, void *data)
648
+{
649
+ ResettableClass *reset = RESETTABLE_CLASS(klass);
650
+ DeviceClass *dc = DEVICE_CLASS(klass);
651
+
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 = \
1105
--
99
--
1106
2.20.1
100
2.34.1
1107
1108
diff view generated by jsdifflib
Deleted patch
1
From: Zenghui Yu <yuzenghui@huawei.com>
2
1
3
Ensure the vSMMUv3 will be restored before all PCIe devices so that DMA
4
translation can work properly during migration.
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>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
---
11
hw/arm/smmuv3.c | 1 +
12
1 file changed, 1 insertion(+)
13
14
diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c
15
index XXXXXXX..XXXXXXX 100644
16
--- a/hw/arm/smmuv3.c
17
+++ b/hw/arm/smmuv3.c
18
@@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_smmuv3 = {
19
.name = "smmuv3",
20
.version_id = 1,
21
.minimum_version_id = 1,
22
+ .priority = MIG_PRI_IOMMU,
23
.fields = (VMStateField[]) {
24
VMSTATE_UINT32(features, SMMUv3State),
25
VMSTATE_UINT8(sid_size, SMMUv3State),
26
--
27
2.20.1
28
29
diff view generated by jsdifflib
1
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
1
From: Luc Michel <luc.michel@amd.com>
2
2
3
Use of 0x%d - make up our mind as 0x%x
3
The CRC was stored in an unsigned variable in gem_receive. Change it for
4
a uint32_t to ensure we have the correct variable size here.
4
5
5
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
6
Signed-off-by: Luc Michel <luc.michel@amd.com>
6
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
7
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
7
Acked-by: Eric Auger <eric.auger@redhat.com>
8
Reviewed-by: sai.pavan.boddu@amd.com
8
Message-id: 20201014193355.53074-1-dgilbert@redhat.com
9
Message-id: 20231017194422.4124691-12-luc.michel@amd.com
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
---
11
---
11
hw/arm/trace-events | 2 +-
12
hw/net/cadence_gem.c | 2 +-
12
1 file changed, 1 insertion(+), 1 deletion(-)
13
1 file changed, 1 insertion(+), 1 deletion(-)
13
14
14
diff --git a/hw/arm/trace-events b/hw/arm/trace-events
15
diff --git a/hw/net/cadence_gem.c b/hw/net/cadence_gem.c
15
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
16
--- a/hw/arm/trace-events
17
--- a/hw/net/cadence_gem.c
17
+++ b/hw/arm/trace-events
18
+++ b/hw/net/cadence_gem.c
18
@@ -XXX,XX +XXX,XX @@ smmuv3_get_cd(uint64_t addr) "CD addr: 0x%"PRIx64
19
@@ -XXX,XX +XXX,XX @@ static ssize_t gem_receive(NetClientState *nc, const uint8_t *buf, size_t size)
19
smmuv3_decode_cd(uint32_t oas) "oas=%d"
20
if (FIELD_EX32(s->regs[R_NWCFG], NWCFG, FCS_REMOVE)) {
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"
21
rxbuf_ptr = (void *)buf;
21
smmuv3_cmdq_cfgi_ste(int streamid) "streamid =%d"
22
} else {
22
-smmuv3_cmdq_cfgi_ste_range(int start, int end) "start=0x%d - end=0x%d"
23
- unsigned crc_val;
23
+smmuv3_cmdq_cfgi_ste_range(int start, int end) "start=0x%x - end=0x%x"
24
+ uint32_t crc_val;
24
smmuv3_cmdq_cfgi_cd(uint32_t sid) "streamid = %d"
25
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)"
26
if (size > MAX_FRAME_SIZE - sizeof(crc_val)) {
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)"
27
size = MAX_FRAME_SIZE - sizeof(crc_val);
27
--
28
--
28
2.20.1
29
2.34.1
29
30
30
31
diff view generated by jsdifflib