1
Last minute pullreq for arm related patches; quite large because
1
The following changes since commit b10d00d8811fa4eed4862963273d7353ce310c82:
2
there were several series that only just made it through code review
3
in time.
4
2
5
thanks
3
Merge remote-tracking branch 'remotes/kraxel/tags/seabios-20220118-pull-request' into staging (2022-01-19 18:46:28 +0000)
6
-- PMM
7
8
The following changes since commit 091e3e3dbc499d84c004e1c50bc9870af37f6e99:
9
10
Merge remote-tracking branch 'remotes/ericb/tags/pull-bitmaps-2020-10-26' into staging (2020-10-26 22:36:35 +0000)
11
4
12
are available in the Git repository at:
5
are available in the Git repository at:
13
6
14
https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20201027-1
7
https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20220120
15
8
16
for you to fetch changes up to 32bd322a0134ed89db00f2b9b3894982db3dedcb:
9
for you to fetch changes up to 9705e3c1dcff96b0b3c7e594b6cd68d27d6c4ced:
17
10
18
hw/timer/armv7m_systick: Rewrite to use ptimers (2020-10-27 11:15:31 +0000)
11
hw/intc/arm_gicv3: Check for !MEMTX_OK instead of MEMTX_ERROR (2022-01-20 11:47:54 +0000)
19
12
20
----------------------------------------------------------------
13
----------------------------------------------------------------
21
target-arm queue:
14
target-arm:
22
* raspi: add model of cprman clock manager
15
* hw/intc/arm_gicv3_its: Fix various minor bugs
23
* sbsa-ref: add an SBSA generic watchdog device
16
* hw/arm/aspeed: Add the i3c device to the AST2600 SoC
24
* arm/trace: Fix hex printing
17
* hw/arm: kudo: add lm75s behind bus 1 switch at 75
25
* raspi: Add models of Pi 3 model A+, Pi Zero and Pi A+
18
* hw/arm/virt: Fix support for running guests on hosts
26
* hw/arm/smmuv3: Set the restoration priority of the vSMMUv3 explicitly
19
with restricted IPA ranges
27
* Nuvoton NPCM7xx: Add USB, RNG, GPIO and watchdog support
20
* hw/intc/arm_gic: Allow reset of the running priority
28
* hw/arm: fix min_cpus for xlnx-versal-virt platform
21
* hw/intc/arm_gic: Implement read of GICC_IIDR
29
* hw/arm/highbank: Silence warnings about missing fallthrough statements
22
* hw/arm/virt: Support for virtio-mem-pci
30
* linux-user: Support Aarch64 BTI
23
* hw/arm/virt: Support CPU cluster on ARM virt machine
31
* Armv7M systick: fix corner case bugs by rewriting to use ptimer
24
* docs/can: convert to restructuredText
25
* hw/net: Move MV88W8618 network device out of hw/arm/ directory
26
* hw/arm/virt: KVM: Enable PAuth when supported by the host
32
27
33
----------------------------------------------------------------
28
----------------------------------------------------------------
34
Dr. David Alan Gilbert (1):
29
Gavin Shan (2):
35
arm/trace: Fix hex printing
30
virtio-mem: Correct default THP size for ARM64
31
hw/arm/virt: Support for virtio-mem-pci
36
32
37
Hao Wu (1):
33
Lucas Ramage (1):
38
hw/timer: Adding watchdog for NPCM7XX Timer.
34
docs/can: convert to restructuredText
39
35
40
Havard Skinnemoen (4):
36
Marc Zyngier (7):
41
Move npcm7xx_timer_reached_zero call out of npcm7xx_timer_pause
37
hw/arm/virt: KVM: Enable PAuth when supported by the host
42
hw/misc: Add npcm7xx random number generator
38
hw/arm/virt: Add a control for the the highmem PCIe MMIO
43
hw/arm/npcm7xx: Add EHCI and OHCI controllers
39
hw/arm/virt: Add a control for the the highmem redistributors
44
hw/gpio: Add GPIO model for Nuvoton NPCM7xx
40
hw/arm/virt: Honor highmem setting when computing the memory map
41
hw/arm/virt: Use the PA range to compute the memory map
42
hw/arm/virt: Disable highmem devices that don't fit in the PA range
43
hw/arm/virt: Drop superfluous checks against highmem
45
44
46
Luc Michel (14):
45
Patrick Venture (1):
47
hw/core/clock: provide the VMSTATE_ARRAY_CLOCK macro
46
hw/arm: kudo add lm75s behind bus 1 switch at 75
48
hw/core/clock: trace clock values in Hz instead of ns
49
hw/arm/raspi: fix CPRMAN base address
50
hw/arm/raspi: add a skeleton implementation of the CPRMAN
51
hw/misc/bcm2835_cprman: add a PLL skeleton implementation
52
hw/misc/bcm2835_cprman: implement PLLs behaviour
53
hw/misc/bcm2835_cprman: add a PLL channel skeleton implementation
54
hw/misc/bcm2835_cprman: implement PLL channels behaviour
55
hw/misc/bcm2835_cprman: add a clock mux skeleton implementation
56
hw/misc/bcm2835_cprman: implement clock mux behaviour
57
hw/misc/bcm2835_cprman: add the DSI0HSCK multiplexer
58
hw/misc/bcm2835_cprman: add sane reset values to the registers
59
hw/char/pl011: add a clock input
60
hw/arm/bcm2835_peripherals: connect the UART clock
61
47
62
Pavel Dovgalyuk (1):
48
Peter Maydell (13):
63
hw/arm: fix min_cpus for xlnx-versal-virt platform
49
hw/intc/arm_gicv3_its: Fix event ID bounds checks
50
hw/intc/arm_gicv3_its: Convert int ID check to num_intids convention
51
hw/intc/arm_gicv3_its: Fix handling of process_its_cmd() return value
52
hw/intc/arm_gicv3_its: Don't use data if reading command failed
53
hw/intc/arm_gicv3_its: Use enum for return value of process_* functions
54
hw/intc/arm_gicv3_its: Fix return codes in process_its_cmd()
55
hw/intc/arm_gicv3_its: Refactor process_its_cmd() to reduce nesting
56
hw/intc/arm_gicv3_its: Fix return codes in process_mapti()
57
hw/intc/arm_gicv3_its: Fix return codes in process_mapc()
58
hw/intc/arm_gicv3_its: Fix return codes in process_mapd()
59
hw/intc/arm_gicv3_its: Factor out "find address of table entry" code
60
hw/intc/arm_gicv3_its: Check indexes before use, not after
61
hw/intc/arm_gicv3_its: Range-check ICID before indexing into collection table
64
62
65
Peter Maydell (2):
63
Petr Pavlu (2):
66
hw/core/ptimer: Support ptimer being disabled by timer callback
64
hw/intc/arm_gic: Implement read of GICC_IIDR
67
hw/timer/armv7m_systick: Rewrite to use ptimers
65
hw/intc/arm_gic: Allow reset of the running priority
68
66
69
Philippe Mathieu-Daudé (10):
67
Philippe Mathieu-Daudé (4):
70
linux-user/elfload: Avoid leaking interp_name using GLib memory API
68
hw: Move MARVELL_88W8618 Kconfig from audio/ to arm/
71
hw/arm/bcm2836: Restrict BCM283XInfo declaration to C source
69
hw/arm/musicpal: Fix coding style of code related to MV88W8618 device
72
hw/arm/bcm2836: QOM'ify more by adding class_init() to each SoC type
70
hw/net: Move MV88W8618 network device out of hw/arm/ directory
73
hw/arm/bcm2836: Introduce BCM283XClass::core_count
71
hw/intc/arm_gicv3: Check for !MEMTX_OK instead of MEMTX_ERROR
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
72
81
Richard Henderson (11):
73
Troy Lee (2):
82
linux-user/aarch64: Reset btype for signals
74
hw/misc/aspeed_i3c.c: Introduce a dummy AST2600 I3C model.
83
linux-user: Set PAGE_TARGET_1 for TARGET_PROT_BTI
75
hw/arm/aspeed: Add the i3c device to the AST2600 SoC
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
76
94
Shashi Mallela (2):
77
Yanan Wang (6):
95
hw/watchdog: Implement SBSA watchdog device
78
hw/arm/virt: Support CPU cluster on ARM virt machine
96
hw/arm/sbsa-ref: add SBSA watchdog device
79
hw/arm/virt: Support cluster level in DT cpu-map
80
hw/acpi/aml-build: Improve scalability of PPTT generation
81
tests/acpi/bios-tables-test: Allow changes to virt/PPTT file
82
hw/acpi/aml-build: Support cluster level in PPTT generation
83
tests/acpi/bios-table-test: Update expected virt/PPTT file
97
84
98
Thomas Huth (1):
85
docs/system/arm/cpu-features.rst | 4 -
99
hw/arm/highbank: Silence warnings about missing fallthrough statements
86
docs/system/device-emulation.rst | 1 +
87
docs/{can.txt => system/devices/can.rst} | 90 +++---
88
include/hw/arm/aspeed_soc.h | 3 +
89
include/hw/arm/virt.h | 5 +-
90
include/hw/misc/aspeed_i3c.h | 48 +++
91
include/hw/net/mv88w8618_eth.h | 12 +
92
target/arm/cpu.h | 1 +
93
hw/acpi/aml-build.c | 68 +++--
94
hw/arm/aspeed_ast2600.c | 16 +
95
hw/arm/musicpal.c | 381 +-----------------------
96
hw/arm/npcm7xx_boards.c | 10 +-
97
hw/arm/virt-acpi-build.c | 10 +-
98
hw/arm/virt.c | 184 ++++++++++--
99
hw/intc/arm_gic.c | 11 +
100
hw/intc/arm_gicv3_its.c | 492 ++++++++++++++-----------------
101
hw/intc/arm_gicv3_redist.c | 4 +-
102
hw/misc/aspeed_i3c.c | 381 ++++++++++++++++++++++++
103
hw/net/mv88w8618_eth.c | 403 +++++++++++++++++++++++++
104
hw/virtio/virtio-mem.c | 36 ++-
105
target/arm/cpu.c | 16 +-
106
target/arm/cpu64.c | 31 +-
107
target/arm/kvm64.c | 21 ++
108
MAINTAINERS | 2 +
109
hw/arm/Kconfig | 4 +
110
hw/audio/Kconfig | 3 -
111
hw/misc/meson.build | 1 +
112
hw/misc/trace-events | 6 +
113
hw/net/meson.build | 1 +
114
qemu-options.hx | 10 +
115
tests/data/acpi/virt/PPTT | Bin 76 -> 96 bytes
116
31 files changed, 1473 insertions(+), 782 deletions(-)
117
rename docs/{can.txt => system/devices/can.rst} (68%)
118
create mode 100644 include/hw/misc/aspeed_i3c.h
119
create mode 100644 include/hw/net/mv88w8618_eth.h
120
create mode 100644 hw/misc/aspeed_i3c.c
121
create mode 100644 hw/net/mv88w8618_eth.c
100
122
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
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Marc Zyngier <maz@kernel.org>
2
2
3
Transform the prot bit to a qemu internal page bit, and save
3
Add basic support for Pointer Authentication when running a KVM
4
it in the page tables.
4
guest and that the host supports it, loosely based on the SVE
5
5
support.
6
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
6
7
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
7
Although the feature is enabled by default when the host advertises
8
Message-id: 20201021173749.111103-3-richard.henderson@linaro.org
8
it, it is possible to disable it by setting the 'pauth=off' CPU
9
property. The 'pauth' comment is removed from cpu-features.rst,
10
as it is now common to both TCG and KVM.
11
12
Tested on an Apple M1 running 5.16-rc6.
13
14
Cc: Eric Auger <eric.auger@redhat.com>
15
Cc: Richard Henderson <richard.henderson@linaro.org>
16
Cc: Peter Maydell <peter.maydell@linaro.org>
17
Reviewed-by: Andrew Jones <drjones@redhat.com>
18
Signed-off-by: Marc Zyngier <maz@kernel.org>
19
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
20
Message-id: 20220107150154.2490308-1-maz@kernel.org
21
[PMM: fixed indentation]
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
22
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
---
23
---
11
include/exec/cpu-all.h | 2 ++
24
docs/system/arm/cpu-features.rst | 4 ----
12
linux-user/syscall_defs.h | 4 ++++
25
target/arm/cpu.h | 1 +
13
target/arm/cpu.h | 5 +++++
26
target/arm/cpu.c | 16 +++++-----------
14
linux-user/mmap.c | 16 ++++++++++++++++
27
target/arm/cpu64.c | 31 +++++++++++++++++++++++++++----
15
target/arm/translate-a64.c | 6 +++---
28
target/arm/kvm64.c | 21 +++++++++++++++++++++
16
5 files changed, 30 insertions(+), 3 deletions(-)
29
5 files changed, 54 insertions(+), 19 deletions(-)
17
30
18
diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
31
diff --git a/docs/system/arm/cpu-features.rst b/docs/system/arm/cpu-features.rst
19
index XXXXXXX..XXXXXXX 100644
32
index XXXXXXX..XXXXXXX 100644
20
--- a/include/exec/cpu-all.h
33
--- a/docs/system/arm/cpu-features.rst
21
+++ b/include/exec/cpu-all.h
34
+++ b/docs/system/arm/cpu-features.rst
22
@@ -XXX,XX +XXX,XX @@ extern intptr_t qemu_host_page_mask;
35
@@ -XXX,XX +XXX,XX @@ TCG VCPU Features
23
/* FIXME: Code that sets/uses this is broken and needs to go away. */
36
TCG VCPU features are CPU features that are specific to TCG.
24
#define PAGE_RESERVED 0x0020
37
Below is the list of TCG VCPU features and their descriptions.
25
#endif
38
26
+/* Target-specific bits that will be used via page_get_flags(). */
39
- pauth Enable or disable ``FEAT_Pauth``, pointer
27
+#define PAGE_TARGET_1 0x0080
40
- authentication. By default, the feature is
28
41
- enabled with ``-cpu max``.
29
#if defined(CONFIG_USER_ONLY)
42
-
30
void page_dump(FILE *f);
43
pauth-impdef When ``FEAT_Pauth`` is enabled, either the
31
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
44
*impdef* (Implementation Defined) algorithm
32
index XXXXXXX..XXXXXXX 100644
45
is enabled or the *architected* QARMA algorithm
33
--- a/linux-user/syscall_defs.h
34
+++ b/linux-user/syscall_defs.h
35
@@ -XXX,XX +XXX,XX @@ struct target_winsize {
36
#define TARGET_PROT_SEM 0x08
37
#endif
38
39
+#ifdef TARGET_AARCH64
40
+#define TARGET_PROT_BTI 0x10
41
+#endif
42
+
43
/* Common */
44
#define TARGET_MAP_SHARED    0x01        /* Share changes */
45
#define TARGET_MAP_PRIVATE    0x02        /* Changes are private */
46
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
46
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
47
index XXXXXXX..XXXXXXX 100644
47
index XXXXXXX..XXXXXXX 100644
48
--- a/target/arm/cpu.h
48
--- a/target/arm/cpu.h
49
+++ b/target/arm/cpu.h
49
+++ b/target/arm/cpu.h
50
@@ -XXX,XX +XXX,XX @@ static inline MemTxAttrs *typecheck_memtxattrs(MemTxAttrs *x)
50
@@ -XXX,XX +XXX,XX @@ void aarch64_sve_narrow_vq(CPUARMState *env, unsigned vq);
51
#define arm_tlb_bti_gp(x) (typecheck_memtxattrs(x)->target_tlb_bit0)
51
void aarch64_sve_change_el(CPUARMState *env, int old_el,
52
#define arm_tlb_mte_tagged(x) (typecheck_memtxattrs(x)->target_tlb_bit1)
52
int new_el, bool el0_a64);
53
53
void aarch64_add_sve_properties(Object *obj);
54
+/*
54
+void aarch64_add_pauth_properties(Object *obj);
55
+ * AArch64 usage of the PAGE_TARGET_* bits for linux-user.
55
56
+ */
57
+#define PAGE_BTI PAGE_TARGET_1
58
+
59
/*
56
/*
60
* Naming convention for isar_feature functions:
57
* SVE registers are encoded in KVM's memory in an endianness-invariant format.
61
* Functions which test 32-bit ID registers should have _aa32_ in
58
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
62
diff --git a/linux-user/mmap.c b/linux-user/mmap.c
59
index XXXXXXX..XXXXXXX 100644
63
index XXXXXXX..XXXXXXX 100644
60
--- a/target/arm/cpu.c
64
--- a/linux-user/mmap.c
61
+++ b/target/arm/cpu.c
65
+++ b/linux-user/mmap.c
62
@@ -XXX,XX +XXX,XX @@ void arm_cpu_finalize_features(ARMCPU *cpu, Error **errp)
66
@@ -XXX,XX +XXX,XX @@ static int validate_prot_to_pageflags(int *host_prot, int prot)
63
return;
67
*host_prot = (prot & (PROT_READ | PROT_WRITE))
64
}
68
| (prot & PROT_EXEC ? PROT_READ : 0);
65
69
66
- /*
70
+#ifdef TARGET_AARCH64
67
- * KVM does not support modifications to this feature.
68
- * We have not registered the cpu properties when KVM
69
- * is in use, so the user will not be able to set them.
70
- */
71
- if (!kvm_enabled()) {
72
- arm_cpu_pauth_finalize(cpu, &local_err);
73
- if (local_err != NULL) {
74
- error_propagate(errp, local_err);
75
- return;
76
- }
77
+ arm_cpu_pauth_finalize(cpu, &local_err);
78
+ if (local_err != NULL) {
79
+ error_propagate(errp, local_err);
80
+ return;
81
}
82
}
83
84
@@ -XXX,XX +XXX,XX @@ static void arm_host_initfn(Object *obj)
85
kvm_arm_set_cpu_features_from_host(cpu);
86
if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) {
87
aarch64_add_sve_properties(obj);
88
+ aarch64_add_pauth_properties(obj);
89
}
90
#else
91
hvf_arm_set_cpu_features_from_host(cpu);
92
diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c
93
index XXXXXXX..XXXXXXX 100644
94
--- a/target/arm/cpu64.c
95
+++ b/target/arm/cpu64.c
96
@@ -XXX,XX +XXX,XX @@ void arm_cpu_pauth_finalize(ARMCPU *cpu, Error **errp)
97
int arch_val = 0, impdef_val = 0;
98
uint64_t t;
99
100
+ /* Exit early if PAuth is enabled, and fall through to disable it */
101
+ if (kvm_enabled() && cpu->prop_pauth) {
102
+ if (!cpu_isar_feature(aa64_pauth, cpu)) {
103
+ error_setg(errp, "'pauth' feature not supported by KVM on this host");
104
+ }
105
+
106
+ return;
107
+ }
108
+
109
/* TODO: Handle HaveEnhancedPAC, HaveEnhancedPAC2, HaveFPAC. */
110
if (cpu->prop_pauth) {
111
if (cpu->prop_pauth_impdef) {
112
@@ -XXX,XX +XXX,XX @@ static Property arm_cpu_pauth_property =
113
static Property arm_cpu_pauth_impdef_property =
114
DEFINE_PROP_BOOL("pauth-impdef", ARMCPU, prop_pauth_impdef, false);
115
116
+void aarch64_add_pauth_properties(Object *obj)
117
+{
118
+ ARMCPU *cpu = ARM_CPU(obj);
119
+
120
+ /* Default to PAUTH on, with the architected algorithm on TCG. */
121
+ qdev_property_add_static(DEVICE(obj), &arm_cpu_pauth_property);
122
+ if (kvm_enabled()) {
123
+ /*
124
+ * Mirror PAuth support from the probed sysregs back into the
125
+ * property for KVM. Is it just a bit backward? Yes it is!
126
+ */
127
+ cpu->prop_pauth = cpu_isar_feature(aa64_pauth, cpu);
128
+ } else {
129
+ qdev_property_add_static(DEVICE(obj), &arm_cpu_pauth_impdef_property);
130
+ }
131
+}
132
+
133
/* -cpu max: if KVM is enabled, like -cpu host (best possible with this host);
134
* otherwise, a CPU with as many features enabled as our emulation supports.
135
* The version of '-cpu max' for qemu-system-arm is defined in cpu.c;
136
@@ -XXX,XX +XXX,XX @@ static void aarch64_max_initfn(Object *obj)
137
cpu->dcz_blocksize = 7; /* 512 bytes */
138
#endif
139
140
- /* Default to PAUTH on, with the architected algorithm. */
141
- qdev_property_add_static(DEVICE(obj), &arm_cpu_pauth_property);
142
- qdev_property_add_static(DEVICE(obj), &arm_cpu_pauth_impdef_property);
143
-
144
bitmap_fill(cpu->sve_vq_supported, ARM_MAX_VQ);
145
}
146
147
+ aarch64_add_pauth_properties(obj);
148
aarch64_add_sve_properties(obj);
149
object_property_add(obj, "sve-max-vq", "uint32", cpu_max_get_sve_max_vq,
150
cpu_max_set_sve_max_vq, NULL, NULL);
151
diff --git a/target/arm/kvm64.c b/target/arm/kvm64.c
152
index XXXXXXX..XXXXXXX 100644
153
--- a/target/arm/kvm64.c
154
+++ b/target/arm/kvm64.c
155
@@ -XXX,XX +XXX,XX @@ static int read_sys_reg64(int fd, uint64_t *pret, uint64_t id)
156
return ioctl(fd, KVM_GET_ONE_REG, &idreg);
157
}
158
159
+static bool kvm_arm_pauth_supported(void)
160
+{
161
+ return (kvm_check_extension(kvm_state, KVM_CAP_ARM_PTRAUTH_ADDRESS) &&
162
+ kvm_check_extension(kvm_state, KVM_CAP_ARM_PTRAUTH_GENERIC));
163
+}
164
+
165
bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
166
{
167
/* Identify the feature bits corresponding to the host CPU, and
168
@@ -XXX,XX +XXX,XX @@ bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
169
*/
170
struct kvm_vcpu_init init = { .target = -1, };
171
71
+ /*
172
+ /*
72
+ * The PROT_BTI bit is only accepted if the cpu supports the feature.
173
+ * Ask for Pointer Authentication if supported. We can't play the
73
+ * Since this is the unusual case, don't bother checking unless
174
+ * SVE trick of synthesising the ID reg as KVM won't tell us
74
+ * the bit has been requested. If set and valid, record the bit
175
+ * whether we have the architected or IMPDEF version of PAuth, so
75
+ * within QEMU's page_flags.
176
+ * we have to use the actual ID regs.
76
+ */
177
+ */
77
+ if (prot & TARGET_PROT_BTI) {
178
+ if (kvm_arm_pauth_supported()) {
78
+ ARMCPU *cpu = ARM_CPU(thread_cpu);
179
+ init.features[0] |= (1 << KVM_ARM_VCPU_PTRAUTH_ADDRESS |
79
+ if (cpu_isar_feature(aa64_bti, cpu)) {
180
+ 1 << KVM_ARM_VCPU_PTRAUTH_GENERIC);
80
+ valid |= TARGET_PROT_BTI;
181
+ }
81
+ page_flags |= PAGE_BTI;
182
+
82
+ }
183
if (!kvm_arm_create_scratch_host_vcpu(cpus_to_try, fdarray, &init)) {
83
+ }
184
return false;
84
+#endif
185
}
85
+
186
@@ -XXX,XX +XXX,XX @@ int kvm_arch_init_vcpu(CPUState *cs)
86
return prot & ~valid ? 0 : page_flags;
187
assert(kvm_arm_sve_supported());
87
}
188
cpu->kvm_init_features[0] |= 1 << KVM_ARM_VCPU_SVE;
88
189
}
89
diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c
190
+ if (cpu_isar_feature(aa64_pauth, cpu)) {
90
index XXXXXXX..XXXXXXX 100644
191
+ cpu->kvm_init_features[0] |= (1 << KVM_ARM_VCPU_PTRAUTH_ADDRESS |
91
--- a/target/arm/translate-a64.c
192
+ 1 << KVM_ARM_VCPU_PTRAUTH_GENERIC);
92
+++ b/target/arm/translate-a64.c
193
+ }
93
@@ -XXX,XX +XXX,XX @@ static void disas_data_proc_simd_fp(DisasContext *s, uint32_t insn)
194
94
*/
195
/* Do KVM_ARM_VCPU_INIT ioctl */
95
static bool is_guarded_page(CPUARMState *env, DisasContext *s)
196
ret = kvm_arm_vcpu_init(cs);
96
{
97
-#ifdef CONFIG_USER_ONLY
98
- return false; /* FIXME */
99
-#else
100
uint64_t addr = s->base.pc_first;
101
+#ifdef CONFIG_USER_ONLY
102
+ return page_get_flags(addr) & PAGE_BTI;
103
+#else
104
int mmu_idx = arm_to_core_mmu_idx(s->mmu_idx);
105
unsigned int index = tlb_index(env, mmu_idx, addr);
106
CPUTLBEntry *entry = tlb_entry(env, mmu_idx, addr);
107
--
197
--
108
2.20.1
198
2.25.1
109
199
110
200
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
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
2
2
3
The Pi 3A+ is a stripped down version of the 3B:
3
The Marvell 88W8618 is a system-on-chip with an ARM core.
4
- 512 MiB of RAM instead of 1 GiB
4
We implement its audio codecs and network interface.
5
- no on-board ethernet chipset
5
Homogeneous SoC Kconfig are usually defined in the hw/$ARCH
6
directory. Move it there.
6
7
7
Add it as it is a closer match to what we model.
8
Suggested-by: Richard Henderson <richard.henderson@linaro.org>
8
9
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
9
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
10
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
10
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
11
Message-id: 20201024170127.3592182-10-f4bug@amsat.org
11
Message-id: 20220107184429.423572-2-f4bug@amsat.org
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
---
13
---
14
hw/arm/raspi.c | 13 +++++++++++++
14
hw/arm/Kconfig | 3 +++
15
1 file changed, 13 insertions(+)
15
hw/audio/Kconfig | 3 ---
16
2 files changed, 3 insertions(+), 3 deletions(-)
16
17
17
diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c
18
diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
18
index XXXXXXX..XXXXXXX 100644
19
index XXXXXXX..XXXXXXX 100644
19
--- a/hw/arm/raspi.c
20
--- a/hw/arm/Kconfig
20
+++ b/hw/arm/raspi.c
21
+++ b/hw/arm/Kconfig
21
@@ -XXX,XX +XXX,XX @@ static void raspi2b_machine_class_init(ObjectClass *oc, void *data)
22
@@ -XXX,XX +XXX,XX @@ config MUSCA
22
};
23
select SPLIT_IRQ
23
24
select UNIMP
24
#ifdef TARGET_AARCH64
25
25
+static void raspi3ap_machine_class_init(ObjectClass *oc, void *data)
26
+config MARVELL_88W8618
26
+{
27
+ bool
27
+ MachineClass *mc = MACHINE_CLASS(oc);
28
+ RaspiMachineClass *rmc = RASPI_MACHINE_CLASS(oc);
29
+
28
+
30
+ rmc->board_rev = 0x9020e0; /* Revision 1.0 */
29
config MUSICPAL
31
+ raspi_machine_class_common_init(mc, rmc->board_rev);
30
bool
32
+};
31
select OR_IRQ
33
+
32
diff --git a/hw/audio/Kconfig b/hw/audio/Kconfig
34
static void raspi3b_machine_class_init(ObjectClass *oc, void *data)
33
index XXXXXXX..XXXXXXX 100644
35
{
34
--- a/hw/audio/Kconfig
36
MachineClass *mc = MACHINE_CLASS(oc);
35
+++ b/hw/audio/Kconfig
37
@@ -XXX,XX +XXX,XX @@ static const TypeInfo raspi_machine_types[] = {
36
@@ -XXX,XX +XXX,XX @@ config PL041
38
.parent = TYPE_RASPI_MACHINE,
37
39
.class_init = raspi2b_machine_class_init,
38
config CS4231
40
#ifdef TARGET_AARCH64
39
bool
41
+ }, {
40
-
42
+ .name = MACHINE_TYPE_NAME("raspi3ap"),
41
-config MARVELL_88W8618
43
+ .parent = TYPE_RASPI_MACHINE,
42
- bool
44
+ .class_init = raspi3ap_machine_class_init,
45
}, {
46
.name = MACHINE_TYPE_NAME("raspi3b"),
47
.parent = TYPE_RASPI_MACHINE,
48
--
43
--
49
2.20.1
44
2.25.1
50
45
51
46
diff view generated by jsdifflib
1
From: Luc Michel <luc@lmichel.fr>
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
2
2
3
PLLs are composed of multiple channels. Each channel outputs one clock
3
We are going to move this code, so fix its style first to avoid:
4
signal. They are modeled as one device taking the PLL generated clock as
5
input, and outputting a new clock.
6
4
7
A channel shares the CM register with its parent PLL, and has its own
5
ERROR: spaces required around that '/' (ctx:VxV)
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
6
12
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
13
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
8
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
14
Signed-off-by: Luc Michel <luc@lmichel.fr>
9
Message-id: 20220107184429.423572-3-f4bug@amsat.org
15
Tested-by: Guenter Roeck <linux@roeck-us.net>
16
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
17
---
11
---
18
include/hw/misc/bcm2835_cprman.h | 44 ++++++
12
hw/arm/musicpal.c | 14 +++++++-------
19
include/hw/misc/bcm2835_cprman_internals.h | 146 +++++++++++++++++++
13
1 file changed, 7 insertions(+), 7 deletions(-)
20
hw/misc/bcm2835_cprman.c | 155 +++++++++++++++++++--
21
3 files changed, 337 insertions(+), 8 deletions(-)
22
14
23
diff --git a/include/hw/misc/bcm2835_cprman.h b/include/hw/misc/bcm2835_cprman.h
15
diff --git a/hw/arm/musicpal.c b/hw/arm/musicpal.c
24
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
25
--- a/include/hw/misc/bcm2835_cprman.h
17
--- a/hw/arm/musicpal.c
26
+++ b/include/hw/misc/bcm2835_cprman.h
18
+++ b/hw/arm/musicpal.c
27
@@ -XXX,XX +XXX,XX @@ typedef enum CprmanPll {
19
@@ -XXX,XX +XXX,XX @@ static uint64_t mv88w8618_eth_read(void *opaque, hwaddr offset,
28
CPRMAN_NUM_PLL
20
return s->imr;
29
} CprmanPll;
21
30
22
case MP_ETH_FRDP0 ... MP_ETH_FRDP3:
31
+typedef enum CprmanPllChannel {
23
- return s->frx_queue[(offset - MP_ETH_FRDP0)/4];
32
+ CPRMAN_PLLA_CHANNEL_DSI0 = 0,
24
+ return s->frx_queue[(offset - MP_ETH_FRDP0) / 4];
33
+ CPRMAN_PLLA_CHANNEL_CORE,
25
34
+ CPRMAN_PLLA_CHANNEL_PER,
26
case MP_ETH_CRDP0 ... MP_ETH_CRDP3:
35
+ CPRMAN_PLLA_CHANNEL_CCP2,
27
- return s->rx_queue[(offset - MP_ETH_CRDP0)/4];
36
+
28
+ return s->rx_queue[(offset - MP_ETH_CRDP0) / 4];
37
+ CPRMAN_PLLC_CHANNEL_CORE2,
29
38
+ CPRMAN_PLLC_CHANNEL_CORE1,
30
case MP_ETH_CTDP0 ... MP_ETH_CTDP1:
39
+ CPRMAN_PLLC_CHANNEL_PER,
31
- return s->tx_queue[(offset - MP_ETH_CTDP0)/4];
40
+ CPRMAN_PLLC_CHANNEL_CORE0,
32
+ return s->tx_queue[(offset - MP_ETH_CTDP0) / 4];
41
+
33
42
+ CPRMAN_PLLD_CHANNEL_DSI0,
34
default:
43
+ CPRMAN_PLLD_CHANNEL_CORE,
35
return 0;
44
+ CPRMAN_PLLD_CHANNEL_PER,
36
@@ -XXX,XX +XXX,XX @@ static void mv88w8618_eth_write(void *opaque, hwaddr offset,
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
}
144
145
+
146
+/* PLL channel init info */
147
+typedef struct PLLChannelInitInfo {
148
+ const char *name;
149
+ CprmanPll parent;
150
+ size_t cm_offset;
151
+ uint32_t cm_hold_mask;
152
+ uint32_t cm_load_mask;
153
+ size_t a2w_ctrl_offset;
154
+ unsigned int fixed_divider;
155
+} PLLChannelInitInfo;
156
+
157
+#define FILL_PLL_CHANNEL_INIT_INFO_common(pll_, channel_) \
158
+ .parent = CPRMAN_ ## pll_, \
159
+ .cm_offset = R_CM_ ## pll_, \
160
+ .cm_load_mask = R_CM_ ## pll_ ## _ ## LOAD ## channel_ ## _MASK, \
161
+ .a2w_ctrl_offset = R_A2W_ ## pll_ ## _ ## channel_
162
+
163
+#define FILL_PLL_CHANNEL_INIT_INFO(pll_, channel_) \
164
+ FILL_PLL_CHANNEL_INIT_INFO_common(pll_, channel_), \
165
+ .cm_hold_mask = R_CM_ ## pll_ ## _ ## HOLD ## channel_ ## _MASK, \
166
+ .fixed_divider = 1
167
+
168
+#define FILL_PLL_CHANNEL_INIT_INFO_nohold(pll_, channel_) \
169
+ FILL_PLL_CHANNEL_INIT_INFO_common(pll_, channel_), \
170
+ .cm_hold_mask = 0
171
+
172
+static PLLChannelInitInfo PLL_CHANNEL_INIT_INFO[] = {
173
+ [CPRMAN_PLLA_CHANNEL_DSI0] = {
174
+ .name = "plla-dsi0",
175
+ FILL_PLL_CHANNEL_INIT_INFO(PLLA, DSI0),
176
+ },
177
+ [CPRMAN_PLLA_CHANNEL_CORE] = {
178
+ .name = "plla-core",
179
+ FILL_PLL_CHANNEL_INIT_INFO(PLLA, CORE),
180
+ },
181
+ [CPRMAN_PLLA_CHANNEL_PER] = {
182
+ .name = "plla-per",
183
+ FILL_PLL_CHANNEL_INIT_INFO(PLLA, PER),
184
+ },
185
+ [CPRMAN_PLLA_CHANNEL_CCP2] = {
186
+ .name = "plla-ccp2",
187
+ FILL_PLL_CHANNEL_INIT_INFO(PLLA, CCP2),
188
+ },
189
+
190
+ [CPRMAN_PLLC_CHANNEL_CORE2] = {
191
+ .name = "pllc-core2",
192
+ FILL_PLL_CHANNEL_INIT_INFO(PLLC, CORE2),
193
+ },
194
+ [CPRMAN_PLLC_CHANNEL_CORE1] = {
195
+ .name = "pllc-core1",
196
+ FILL_PLL_CHANNEL_INIT_INFO(PLLC, CORE1),
197
+ },
198
+ [CPRMAN_PLLC_CHANNEL_PER] = {
199
+ .name = "pllc-per",
200
+ FILL_PLL_CHANNEL_INIT_INFO(PLLC, PER),
201
+ },
202
+ [CPRMAN_PLLC_CHANNEL_CORE0] = {
203
+ .name = "pllc-core0",
204
+ FILL_PLL_CHANNEL_INIT_INFO(PLLC, CORE0),
205
+ },
206
+
207
+ [CPRMAN_PLLD_CHANNEL_DSI0] = {
208
+ .name = "plld-dsi0",
209
+ FILL_PLL_CHANNEL_INIT_INFO(PLLD, DSI0),
210
+ },
211
+ [CPRMAN_PLLD_CHANNEL_CORE] = {
212
+ .name = "plld-core",
213
+ FILL_PLL_CHANNEL_INIT_INFO(PLLD, CORE),
214
+ },
215
+ [CPRMAN_PLLD_CHANNEL_PER] = {
216
+ .name = "plld-per",
217
+ FILL_PLL_CHANNEL_INIT_INFO(PLLD, PER),
218
+ },
219
+ [CPRMAN_PLLD_CHANNEL_DSI1] = {
220
+ .name = "plld-dsi1",
221
+ FILL_PLL_CHANNEL_INIT_INFO(PLLD, DSI1),
222
+ },
223
+
224
+ [CPRMAN_PLLH_CHANNEL_AUX] = {
225
+ .name = "pllh-aux",
226
+ .fixed_divider = 1,
227
+ FILL_PLL_CHANNEL_INIT_INFO_nohold(PLLH, AUX),
228
+ },
229
+ [CPRMAN_PLLH_CHANNEL_RCAL] = {
230
+ .name = "pllh-rcal",
231
+ .fixed_divider = 10,
232
+ FILL_PLL_CHANNEL_INIT_INFO_nohold(PLLH, RCAL),
233
+ },
234
+ [CPRMAN_PLLH_CHANNEL_PIX] = {
235
+ .name = "pllh-pix",
236
+ .fixed_divider = 10,
237
+ FILL_PLL_CHANNEL_INIT_INFO_nohold(PLLH, PIX),
238
+ },
239
+
240
+ [CPRMAN_PLLB_CHANNEL_ARM] = {
241
+ .name = "pllb-arm",
242
+ FILL_PLL_CHANNEL_INIT_INFO(PLLB, ARM),
243
+ },
244
+};
245
+
246
+#undef FILL_PLL_CHANNEL_INIT_INFO_nohold
247
+#undef FILL_PLL_CHANNEL_INIT_INFO
248
+#undef FILL_PLL_CHANNEL_INIT_INFO_common
249
+
250
+static inline void set_pll_channel_init_info(BCM2835CprmanState *s,
251
+ CprmanPllChannelState *channel,
252
+ CprmanPllChannel id)
253
+{
254
+ channel->id = id;
255
+ channel->parent = PLL_CHANNEL_INIT_INFO[id].parent;
256
+ channel->reg_cm = &s->regs[PLL_CHANNEL_INIT_INFO[id].cm_offset];
257
+ channel->hold_mask = PLL_CHANNEL_INIT_INFO[id].cm_hold_mask;
258
+ channel->load_mask = PLL_CHANNEL_INIT_INFO[id].cm_load_mask;
259
+ channel->reg_a2w_ctrl = &s->regs[PLL_CHANNEL_INIT_INFO[id].a2w_ctrl_offset];
260
+ channel->fixed_divider = PLL_CHANNEL_INIT_INFO[id].fixed_divider;
261
+}
262
+
263
#endif
264
diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c
265
index XXXXXXX..XXXXXXX 100644
266
--- a/hw/misc/bcm2835_cprman.c
267
+++ b/hw/misc/bcm2835_cprman.c
268
@@ -XXX,XX +XXX,XX @@ static const TypeInfo cprman_pll_info = {
269
};
270
271
272
+/* PLL channel */
273
+
274
+static void pll_channel_update(CprmanPllChannelState *channel)
275
+{
276
+ clock_update(channel->out, 0);
277
+}
278
+
279
+/* Update a PLL and all its channels */
280
+static void pll_update_all_channels(BCM2835CprmanState *s,
281
+ CprmanPllState *pll)
282
+{
283
+ size_t i;
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
+}
294
+
295
+static void pll_channel_pll_in_update(void *opaque)
296
+{
297
+ pll_channel_update(CPRMAN_PLL_CHANNEL(opaque));
298
+}
299
+
300
+static void pll_channel_init(Object *obj)
301
+{
302
+ CprmanPllChannelState *s = CPRMAN_PLL_CHANNEL(obj);
303
+
304
+ s->pll_in = qdev_init_clock_in(DEVICE(s), "pll-in",
305
+ pll_channel_pll_in_update, s);
306
+ s->out = qdev_init_clock_out(DEVICE(s), "out");
307
+}
308
+
309
+static const VMStateDescription pll_channel_vmstate = {
310
+ .name = TYPE_CPRMAN_PLL_CHANNEL,
311
+ .version_id = 1,
312
+ .minimum_version_id = 1,
313
+ .fields = (VMStateField[]) {
314
+ VMSTATE_CLOCK(pll_in, CprmanPllChannelState),
315
+ VMSTATE_END_OF_LIST()
316
+ }
317
+};
318
+
319
+static void pll_channel_class_init(ObjectClass *klass, void *data)
320
+{
321
+ DeviceClass *dc = DEVICE_CLASS(klass);
322
+
323
+ dc->vmsd = &pll_channel_vmstate;
324
+}
325
+
326
+static const TypeInfo cprman_pll_channel_info = {
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
+{
347
+ size_t i;
348
+
349
+ for (i = 0; i < CPRMAN_NUM_PLL; i++) {
350
+ if (PLL_INIT_INFO[i].cm_offset == idx) {
351
+ pll_update_all_channels(s, &s->plls[i]);
352
+ return;
353
+ }
354
+ }
355
+}
356
+
357
+static inline void update_channel_from_a2w(BCM2835CprmanState *s, size_t idx)
358
+{
359
+ size_t i;
360
+
361
+ for (i = 0; i < CPRMAN_NUM_PLL_CHANNEL; i++) {
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;
37
break;
390
38
391
- CASE_PLL_REGS(PLLC) :
39
case MP_ETH_FRDP0 ... MP_ETH_FRDP3:
392
+ CASE_PLL_A2W_REGS(PLLC) :
40
- s->frx_queue[(offset - MP_ETH_FRDP0)/4] = value;
393
pll_update(&s->plls[CPRMAN_PLLC]);
41
+ s->frx_queue[(offset - MP_ETH_FRDP0) / 4] = value;
394
break;
42
break;
395
43
396
- CASE_PLL_REGS(PLLD) :
44
case MP_ETH_CRDP0 ... MP_ETH_CRDP3:
397
+ CASE_PLL_A2W_REGS(PLLD) :
45
- s->rx_queue[(offset - MP_ETH_CRDP0)/4] =
398
pll_update(&s->plls[CPRMAN_PLLD]);
46
- s->cur_rx[(offset - MP_ETH_CRDP0)/4] = value;
47
+ s->rx_queue[(offset - MP_ETH_CRDP0) / 4] =
48
+ s->cur_rx[(offset - MP_ETH_CRDP0) / 4] = value;
399
break;
49
break;
400
50
401
- CASE_PLL_REGS(PLLH) :
51
case MP_ETH_CTDP0 ... MP_ETH_CTDP1:
402
+ CASE_PLL_A2W_REGS(PLLH) :
52
- s->tx_queue[(offset - MP_ETH_CTDP0)/4] = value;
403
pll_update(&s->plls[CPRMAN_PLLH]);
53
+ s->tx_queue[(offset - MP_ETH_CTDP0) / 4] = value;
404
break;
54
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
}
55
}
430
}
56
}
431
432
-#undef CASE_PLL_REGS
433
+#undef CASE_PLL_A2W_REGS
434
435
static const MemoryRegionOps cprman_ops = {
436
.read = cprman_read,
437
@@ -XXX,XX +XXX,XX @@ static void cprman_reset(DeviceState *dev)
438
device_cold_reset(DEVICE(&s->plls[i]));
439
}
440
441
+ for (i = 0; i < CPRMAN_NUM_PLL_CHANNEL; i++) {
442
+ device_cold_reset(DEVICE(&s->channels[i]));
443
+ }
444
+
445
clock_update_hz(s->xosc, s->xosc_freq);
446
}
447
448
@@ -XXX,XX +XXX,XX @@ static void cprman_init(Object *obj)
449
set_pll_init_info(s, &s->plls[i], i);
450
}
451
452
+ for (i = 0; i < CPRMAN_NUM_PLL_CHANNEL; i++) {
453
+ object_initialize_child(obj, PLL_CHANNEL_INIT_INFO[i].name,
454
+ &s->channels[i],
455
+ TYPE_CPRMAN_PLL_CHANNEL);
456
+ set_pll_channel_init_info(s, &s->channels[i], i);
457
+ }
458
+
459
s->xosc = clock_new(obj, "xosc");
460
461
memory_region_init_io(&s->iomem, obj, &cprman_ops,
462
@@ -XXX,XX +XXX,XX @@ static void cprman_realize(DeviceState *dev, Error **errp)
463
return;
464
}
465
}
466
+
467
+ for (i = 0; i < CPRMAN_NUM_PLL_CHANNEL; i++) {
468
+ CprmanPllChannelState *channel = &s->channels[i];
469
+ CprmanPll parent = PLL_CHANNEL_INIT_INFO[i].parent;
470
+ Clock *parent_clk = s->plls[parent].out;
471
+
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
{
483
type_register_static(&cprman_info);
484
type_register_static(&cprman_pll_info);
485
+ type_register_static(&cprman_pll_channel_info);
486
}
487
488
type_init(cprman_register_types);
489
--
57
--
490
2.20.1
58
2.25.1
491
59
492
60
diff view generated by jsdifflib
1
From: Havard Skinnemoen <hskinnemoen@google.com>
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
2
2
3
The NPCM7xx chips have multiple GPIO controllers that are mostly
3
The Marvell 88W8618 network device is hidden in the Musicpal
4
identical except for some minor differences like the reset values of
4
machine. Move it into a new unit file under the hw/net/ directory.
5
some registers. Each controller controls up to 32 pins.
6
5
7
Each individual pin is modeled as a pair of unnamed GPIOs -- one for
6
Acked-by: Richard Henderson <richard.henderson@linaro.org>
8
emitting the actual pin state, and one for driving the pin externally.
7
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
9
Like the nRF51 GPIO controller, a gpio level may be negative, which
8
Message-id: 20220107184429.423572-4-f4bug@amsat.org
10
means the pin is not driven, or floating.
11
12
Reviewed-by: Tyrone Ting <kfting@nuvoton.com>
13
Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
14
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
9
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
15
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
16
---
11
---
17
docs/system/arm/nuvoton.rst | 2 +-
12
include/hw/net/mv88w8618_eth.h | 12 +
18
include/hw/arm/npcm7xx.h | 2 +
13
hw/arm/musicpal.c | 381 +------------------------------
19
include/hw/gpio/npcm7xx_gpio.h | 55 +++++
14
hw/net/mv88w8618_eth.c | 403 +++++++++++++++++++++++++++++++++
20
hw/arm/npcm7xx.c | 80 ++++++
15
MAINTAINERS | 2 +
21
hw/gpio/npcm7xx_gpio.c | 424 ++++++++++++++++++++++++++++++++
16
hw/net/meson.build | 1 +
22
tests/qtest/npcm7xx_gpio-test.c | 385 +++++++++++++++++++++++++++++
17
5 files changed, 419 insertions(+), 380 deletions(-)
23
hw/gpio/meson.build | 1 +
18
create mode 100644 include/hw/net/mv88w8618_eth.h
24
hw/gpio/trace-events | 7 +
19
create mode 100644 hw/net/mv88w8618_eth.c
25
tests/qtest/meson.build | 3 +-
26
9 files changed, 957 insertions(+), 2 deletions(-)
27
create mode 100644 include/hw/gpio/npcm7xx_gpio.h
28
create mode 100644 hw/gpio/npcm7xx_gpio.c
29
create mode 100644 tests/qtest/npcm7xx_gpio-test.c
30
20
31
diff --git a/docs/system/arm/nuvoton.rst b/docs/system/arm/nuvoton.rst
21
diff --git a/include/hw/net/mv88w8618_eth.h b/include/hw/net/mv88w8618_eth.h
32
index XXXXXXX..XXXXXXX 100644
33
--- a/docs/system/arm/nuvoton.rst
34
+++ b/docs/system/arm/nuvoton.rst
35
@@ -XXX,XX +XXX,XX @@ Supported devices
36
* Flash Interface Unit (FIU; no protection features)
37
* Random Number Generator (RNG)
38
* USB host (USBH)
39
+ * GPIO controller
40
41
Missing devices
42
---------------
43
44
- * GPIO controller
45
* LPC/eSPI host-to-BMC interface, including
46
47
* Keyboard and mouse controller interface (KBCI)
48
diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h
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
22
new file mode 100644
70
index XXXXXXX..XXXXXXX
23
index XXXXXXX..XXXXXXX
71
--- /dev/null
24
--- /dev/null
72
+++ b/include/hw/gpio/npcm7xx_gpio.h
25
+++ b/include/hw/net/mv88w8618_eth.h
73
@@ -XXX,XX +XXX,XX @@
26
@@ -XXX,XX +XXX,XX @@
27
+/* SPDX-License-Identifier: GPL-2.0-or-later */
74
+/*
28
+/*
75
+ * Nuvoton NPCM7xx General Purpose Input / Output (GPIO)
29
+ * Marvell MV88W8618 / Freecom MusicPal emulation.
76
+ *
30
+ *
77
+ * Copyright 2020 Google LLC
31
+ * Copyright (c) 2008-2021 QEMU contributors
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
+ */
32
+ */
88
+#ifndef NPCM7XX_GPIO_H
33
+#ifndef HW_NET_MV88W8618_H
89
+#define NPCM7XX_GPIO_H
34
+#define HW_NET_MV88W8618_H
90
+
35
+
91
+#include "exec/memory.h"
36
+#define TYPE_MV88W8618_ETH "mv88w8618_eth"
92
+#include "hw/sysbus.h"
37
+
93
+
38
+#endif
94
+/* Number of pins managed by each controller. */
39
diff --git a/hw/arm/musicpal.c b/hw/arm/musicpal.c
95
+#define NPCM7XX_GPIO_NR_PINS (32)
96
+
97
+/*
98
+ * Number of registers in our device state structure. Don't change this without
99
+ * incrementing the version_id in the vmstate.
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
40
index XXXXXXX..XXXXXXX 100644
131
--- a/hw/arm/npcm7xx.c
41
--- a/hw/arm/musicpal.c
132
+++ b/hw/arm/npcm7xx.c
42
+++ b/hw/arm/musicpal.c
133
@@ -XXX,XX +XXX,XX @@ enum NPCM7xxInterrupt {
43
@@ -XXX,XX +XXX,XX @@
134
NPCM7XX_WDG2_IRQ, /* Timer Module 2 Watchdog */
44
#include "ui/pixel_ops.h"
135
NPCM7XX_EHCI_IRQ = 61,
45
#include "qemu/cutils.h"
136
NPCM7XX_OHCI_IRQ = 62,
46
#include "qom/object.h"
137
+ NPCM7XX_GPIO0_IRQ = 116,
47
+#include "hw/net/mv88w8618_eth.h"
138
+ NPCM7XX_GPIO1_IRQ,
48
139
+ NPCM7XX_GPIO2_IRQ,
49
#define MP_MISC_BASE 0x80002000
140
+ NPCM7XX_GPIO3_IRQ,
50
#define MP_MISC_SIZE 0x00001000
141
+ NPCM7XX_GPIO4_IRQ,
51
142
+ NPCM7XX_GPIO5_IRQ,
52
#define MP_ETH_BASE 0x80008000
143
+ NPCM7XX_GPIO6_IRQ,
53
-#define MP_ETH_SIZE 0x00001000
144
+ NPCM7XX_GPIO7_IRQ,
54
145
};
55
#define MP_WLAN_BASE 0x8000C000
146
56
#define MP_WLAN_SIZE 0x00000800
147
/* Total number of GIC interrupts, including internal Cortex-A9 interrupts. */
57
@@ -XXX,XX +XXX,XX @@
148
@@ -XXX,XX +XXX,XX @@ static const hwaddr npcm7xx_fiu3_flash_addr[] = {
58
/* Wolfson 8750 I2C address */
149
0xb8000000, /* CS3 */
59
#define MP_WM_ADDR 0x1A
150
};
60
151
61
-/* Ethernet register offsets */
152
+static const struct {
62
-#define MP_ETH_SMIR 0x010
153
+ hwaddr regs_addr;
63
-#define MP_ETH_PCXR 0x408
154
+ uint32_t unconnected_pins;
64
-#define MP_ETH_SDCMR 0x448
155
+ uint32_t reset_pu;
65
-#define MP_ETH_ICR 0x450
156
+ uint32_t reset_pd;
66
-#define MP_ETH_IMR 0x458
157
+ uint32_t reset_osrc;
67
-#define MP_ETH_FRDP0 0x480
158
+ uint32_t reset_odsc;
68
-#define MP_ETH_FRDP1 0x484
159
+} npcm7xx_gpio[] = {
69
-#define MP_ETH_FRDP2 0x488
160
+ {
70
-#define MP_ETH_FRDP3 0x48C
161
+ .regs_addr = 0xf0010000,
71
-#define MP_ETH_CRDP0 0x4A0
162
+ .reset_pu = 0xff03ffff,
72
-#define MP_ETH_CRDP1 0x4A4
163
+ .reset_pd = 0x00fc0000,
73
-#define MP_ETH_CRDP2 0x4A8
164
+ }, {
74
-#define MP_ETH_CRDP3 0x4AC
165
+ .regs_addr = 0xf0011000,
75
-#define MP_ETH_CTDP0 0x4E0
166
+ .unconnected_pins = 0x0000001e,
76
-#define MP_ETH_CTDP1 0x4E4
167
+ .reset_pu = 0xfefffe07,
77
-
168
+ .reset_pd = 0x010001e0,
78
-/* MII PHY access */
169
+ }, {
79
-#define MP_ETH_SMIR_DATA 0x0000FFFF
170
+ .regs_addr = 0xf0012000,
80
-#define MP_ETH_SMIR_ADDR 0x03FF0000
171
+ .reset_pu = 0x780fffff,
81
-#define MP_ETH_SMIR_OPCODE (1 << 26) /* Read value */
172
+ .reset_pd = 0x07f00000,
82
-#define MP_ETH_SMIR_RDVALID (1 << 27)
173
+ .reset_odsc = 0x00700000,
83
-
174
+ }, {
84
-/* PHY registers */
175
+ .regs_addr = 0xf0013000,
85
-#define MP_ETH_PHY1_BMSR 0x00210000
176
+ .reset_pu = 0x00fc0000,
86
-#define MP_ETH_PHY1_PHYSID1 0x00410000
177
+ .reset_pd = 0xff000000,
87
-#define MP_ETH_PHY1_PHYSID2 0x00610000
178
+ }, {
88
-
179
+ .regs_addr = 0xf0014000,
89
-#define MP_PHY_BMSR_LINK 0x0004
180
+ .reset_pu = 0xffffffff,
90
-#define MP_PHY_BMSR_AUTONEG 0x0008
181
+ }, {
91
-
182
+ .regs_addr = 0xf0015000,
92
-#define MP_PHY_88E3015 0x01410E20
183
+ .reset_pu = 0xbf83f801,
93
-
184
+ .reset_pd = 0x007c0000,
94
-/* TX descriptor status */
185
+ .reset_osrc = 0x000000f1,
95
-#define MP_ETH_TX_OWN (1U << 31)
186
+ .reset_odsc = 0x3f9f80f1,
96
-
187
+ }, {
97
-/* RX descriptor status */
188
+ .regs_addr = 0xf0016000,
98
-#define MP_ETH_RX_OWN (1U << 31)
189
+ .reset_pu = 0xfc00f801,
99
-
190
+ .reset_pd = 0x000007fe,
100
-/* Interrupt cause/mask bits */
191
+ .reset_odsc = 0x00000800,
101
-#define MP_ETH_IRQ_RX_BIT 0
192
+ }, {
102
-#define MP_ETH_IRQ_RX (1 << MP_ETH_IRQ_RX_BIT)
193
+ .regs_addr = 0xf0017000,
103
-#define MP_ETH_IRQ_TXHI_BIT 2
194
+ .unconnected_pins = 0xffffff00,
104
-#define MP_ETH_IRQ_TXLO_BIT 3
195
+ .reset_pu = 0x0000007f,
105
-
196
+ .reset_osrc = 0x0000007f,
106
-/* Port config bits */
197
+ .reset_odsc = 0x0000007f,
107
-#define MP_ETH_PCXR_2BSM_BIT 28 /* 2-byte incoming suffix */
198
+ },
108
-
199
+};
109
-/* SDMA command bits */
200
+
110
-#define MP_ETH_CMD_TXHI (1 << 23)
201
static const struct {
111
-#define MP_ETH_CMD_TXLO (1 << 22)
202
const char *name;
112
-
203
hwaddr regs_addr;
113
-typedef struct mv88w8618_tx_desc {
204
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_init(Object *obj)
114
- uint32_t cmdstat;
205
object_initialize_child(obj, "tim[*]", &s->tim[i], TYPE_NPCM7XX_TIMER);
115
- uint16_t res;
206
}
116
- uint16_t bytes;
207
117
- uint32_t buffer;
208
+ for (i = 0; i < ARRAY_SIZE(s->gpio); i++) {
118
- uint32_t next;
209
+ object_initialize_child(obj, "gpio[*]", &s->gpio[i], TYPE_NPCM7XX_GPIO);
119
-} mv88w8618_tx_desc;
210
+ }
120
-
211
+
121
-typedef struct mv88w8618_rx_desc {
212
object_initialize_child(obj, "ehci", &s->ehci, TYPE_NPCM7XX_EHCI);
122
- uint32_t cmdstat;
213
object_initialize_child(obj, "ohci", &s->ohci, TYPE_SYSBUS_OHCI);
123
- uint16_t bytes;
214
124
- uint16_t buffer_size;
215
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp)
125
- uint32_t buffer;
216
sysbus_realize(SYS_BUS_DEVICE(&s->rng), &error_abort);
126
- uint32_t next;
217
sysbus_mmio_map(SYS_BUS_DEVICE(&s->rng), 0, NPCM7XX_RNG_BA);
127
-} mv88w8618_rx_desc;
218
128
-
219
+ /* GPIO modules. Cannot fail. */
129
-#define TYPE_MV88W8618_ETH "mv88w8618_eth"
220
+ QEMU_BUILD_BUG_ON(ARRAY_SIZE(npcm7xx_gpio) != ARRAY_SIZE(s->gpio));
130
-OBJECT_DECLARE_SIMPLE_TYPE(mv88w8618_eth_state, MV88W8618_ETH)
221
+ for (i = 0; i < ARRAY_SIZE(s->gpio); i++) {
131
-
222
+ Object *obj = OBJECT(&s->gpio[i]);
132
-struct mv88w8618_eth_state {
223
+
133
- /*< private >*/
224
+ object_property_set_uint(obj, "reset-pullup",
134
- SysBusDevice parent_obj;
225
+ npcm7xx_gpio[i].reset_pu, &error_abort);
135
- /*< public >*/
226
+ object_property_set_uint(obj, "reset-pulldown",
136
-
227
+ npcm7xx_gpio[i].reset_pd, &error_abort);
137
- MemoryRegion iomem;
228
+ object_property_set_uint(obj, "reset-osrc",
138
- qemu_irq irq;
229
+ npcm7xx_gpio[i].reset_osrc, &error_abort);
139
- MemoryRegion *dma_mr;
230
+ object_property_set_uint(obj, "reset-odsc",
140
- AddressSpace dma_as;
231
+ npcm7xx_gpio[i].reset_odsc, &error_abort);
141
- uint32_t smir;
232
+ sysbus_realize(SYS_BUS_DEVICE(obj), &error_abort);
142
- uint32_t icr;
233
+ sysbus_mmio_map(SYS_BUS_DEVICE(obj), 0, npcm7xx_gpio[i].regs_addr);
143
- uint32_t imr;
234
+ sysbus_connect_irq(SYS_BUS_DEVICE(obj), 0,
144
- int mmio_index;
235
+ npcm7xx_irq(s, NPCM7XX_GPIO0_IRQ + i));
145
- uint32_t vlan_header;
236
+ }
146
- uint32_t tx_queue[2];
237
+
147
- uint32_t rx_queue[4];
238
/* USB Host */
148
- uint32_t frx_queue[4];
239
object_property_set_bool(OBJECT(&s->ehci), "companion-enable", true,
149
- uint32_t cur_rx[4];
240
&error_abort);
150
- NICState *nic;
241
diff --git a/hw/gpio/npcm7xx_gpio.c b/hw/gpio/npcm7xx_gpio.c
151
- NICConf conf;
152
-};
153
-
154
-static void eth_rx_desc_put(AddressSpace *dma_as, uint32_t addr,
155
- mv88w8618_rx_desc *desc)
156
-{
157
- cpu_to_le32s(&desc->cmdstat);
158
- cpu_to_le16s(&desc->bytes);
159
- cpu_to_le16s(&desc->buffer_size);
160
- cpu_to_le32s(&desc->buffer);
161
- cpu_to_le32s(&desc->next);
162
- dma_memory_write(dma_as, addr, desc, sizeof(*desc), MEMTXATTRS_UNSPECIFIED);
163
-}
164
-
165
-static void eth_rx_desc_get(AddressSpace *dma_as, uint32_t addr,
166
- mv88w8618_rx_desc *desc)
167
-{
168
- dma_memory_read(dma_as, addr, desc, sizeof(*desc), MEMTXATTRS_UNSPECIFIED);
169
- le32_to_cpus(&desc->cmdstat);
170
- le16_to_cpus(&desc->bytes);
171
- le16_to_cpus(&desc->buffer_size);
172
- le32_to_cpus(&desc->buffer);
173
- le32_to_cpus(&desc->next);
174
-}
175
-
176
-static ssize_t eth_receive(NetClientState *nc, const uint8_t *buf, size_t size)
177
-{
178
- mv88w8618_eth_state *s = qemu_get_nic_opaque(nc);
179
- uint32_t desc_addr;
180
- mv88w8618_rx_desc desc;
181
- int i;
182
-
183
- for (i = 0; i < 4; i++) {
184
- desc_addr = s->cur_rx[i];
185
- if (!desc_addr) {
186
- continue;
187
- }
188
- do {
189
- eth_rx_desc_get(&s->dma_as, desc_addr, &desc);
190
- if ((desc.cmdstat & MP_ETH_RX_OWN) && desc.buffer_size >= size) {
191
- dma_memory_write(&s->dma_as, desc.buffer + s->vlan_header,
192
- buf, size, MEMTXATTRS_UNSPECIFIED);
193
- desc.bytes = size + s->vlan_header;
194
- desc.cmdstat &= ~MP_ETH_RX_OWN;
195
- s->cur_rx[i] = desc.next;
196
-
197
- s->icr |= MP_ETH_IRQ_RX;
198
- if (s->icr & s->imr) {
199
- qemu_irq_raise(s->irq);
200
- }
201
- eth_rx_desc_put(&s->dma_as, desc_addr, &desc);
202
- return size;
203
- }
204
- desc_addr = desc.next;
205
- } while (desc_addr != s->rx_queue[i]);
206
- }
207
- return size;
208
-}
209
-
210
-static void eth_tx_desc_put(AddressSpace *dma_as, uint32_t addr,
211
- mv88w8618_tx_desc *desc)
212
-{
213
- cpu_to_le32s(&desc->cmdstat);
214
- cpu_to_le16s(&desc->res);
215
- cpu_to_le16s(&desc->bytes);
216
- cpu_to_le32s(&desc->buffer);
217
- cpu_to_le32s(&desc->next);
218
- dma_memory_write(dma_as, addr, desc, sizeof(*desc), MEMTXATTRS_UNSPECIFIED);
219
-}
220
-
221
-static void eth_tx_desc_get(AddressSpace *dma_as, uint32_t addr,
222
- mv88w8618_tx_desc *desc)
223
-{
224
- dma_memory_read(dma_as, addr, desc, sizeof(*desc), MEMTXATTRS_UNSPECIFIED);
225
- le32_to_cpus(&desc->cmdstat);
226
- le16_to_cpus(&desc->res);
227
- le16_to_cpus(&desc->bytes);
228
- le32_to_cpus(&desc->buffer);
229
- le32_to_cpus(&desc->next);
230
-}
231
-
232
-static void eth_send(mv88w8618_eth_state *s, int queue_index)
233
-{
234
- uint32_t desc_addr = s->tx_queue[queue_index];
235
- mv88w8618_tx_desc desc;
236
- uint32_t next_desc;
237
- uint8_t buf[2048];
238
- int len;
239
-
240
- do {
241
- eth_tx_desc_get(&s->dma_as, desc_addr, &desc);
242
- next_desc = desc.next;
243
- if (desc.cmdstat & MP_ETH_TX_OWN) {
244
- len = desc.bytes;
245
- if (len < 2048) {
246
- dma_memory_read(&s->dma_as, desc.buffer, buf, len,
247
- MEMTXATTRS_UNSPECIFIED);
248
- qemu_send_packet(qemu_get_queue(s->nic), buf, len);
249
- }
250
- desc.cmdstat &= ~MP_ETH_TX_OWN;
251
- s->icr |= 1 << (MP_ETH_IRQ_TXLO_BIT - queue_index);
252
- eth_tx_desc_put(&s->dma_as, desc_addr, &desc);
253
- }
254
- desc_addr = next_desc;
255
- } while (desc_addr != s->tx_queue[queue_index]);
256
-}
257
-
258
-static uint64_t mv88w8618_eth_read(void *opaque, hwaddr offset,
259
- unsigned size)
260
-{
261
- mv88w8618_eth_state *s = opaque;
262
-
263
- switch (offset) {
264
- case MP_ETH_SMIR:
265
- if (s->smir & MP_ETH_SMIR_OPCODE) {
266
- switch (s->smir & MP_ETH_SMIR_ADDR) {
267
- case MP_ETH_PHY1_BMSR:
268
- return MP_PHY_BMSR_LINK | MP_PHY_BMSR_AUTONEG |
269
- MP_ETH_SMIR_RDVALID;
270
- case MP_ETH_PHY1_PHYSID1:
271
- return (MP_PHY_88E3015 >> 16) | MP_ETH_SMIR_RDVALID;
272
- case MP_ETH_PHY1_PHYSID2:
273
- return (MP_PHY_88E3015 & 0xFFFF) | MP_ETH_SMIR_RDVALID;
274
- default:
275
- return MP_ETH_SMIR_RDVALID;
276
- }
277
- }
278
- return 0;
279
-
280
- case MP_ETH_ICR:
281
- return s->icr;
282
-
283
- case MP_ETH_IMR:
284
- return s->imr;
285
-
286
- case MP_ETH_FRDP0 ... MP_ETH_FRDP3:
287
- return s->frx_queue[(offset - MP_ETH_FRDP0) / 4];
288
-
289
- case MP_ETH_CRDP0 ... MP_ETH_CRDP3:
290
- return s->rx_queue[(offset - MP_ETH_CRDP0) / 4];
291
-
292
- case MP_ETH_CTDP0 ... MP_ETH_CTDP1:
293
- return s->tx_queue[(offset - MP_ETH_CTDP0) / 4];
294
-
295
- default:
296
- return 0;
297
- }
298
-}
299
-
300
-static void mv88w8618_eth_write(void *opaque, hwaddr offset,
301
- uint64_t value, unsigned size)
302
-{
303
- mv88w8618_eth_state *s = opaque;
304
-
305
- switch (offset) {
306
- case MP_ETH_SMIR:
307
- s->smir = value;
308
- break;
309
-
310
- case MP_ETH_PCXR:
311
- s->vlan_header = ((value >> MP_ETH_PCXR_2BSM_BIT) & 1) * 2;
312
- break;
313
-
314
- case MP_ETH_SDCMR:
315
- if (value & MP_ETH_CMD_TXHI) {
316
- eth_send(s, 1);
317
- }
318
- if (value & MP_ETH_CMD_TXLO) {
319
- eth_send(s, 0);
320
- }
321
- if (value & (MP_ETH_CMD_TXHI | MP_ETH_CMD_TXLO) && s->icr & s->imr) {
322
- qemu_irq_raise(s->irq);
323
- }
324
- break;
325
-
326
- case MP_ETH_ICR:
327
- s->icr &= value;
328
- break;
329
-
330
- case MP_ETH_IMR:
331
- s->imr = value;
332
- if (s->icr & s->imr) {
333
- qemu_irq_raise(s->irq);
334
- }
335
- break;
336
-
337
- case MP_ETH_FRDP0 ... MP_ETH_FRDP3:
338
- s->frx_queue[(offset - MP_ETH_FRDP0) / 4] = value;
339
- break;
340
-
341
- case MP_ETH_CRDP0 ... MP_ETH_CRDP3:
342
- s->rx_queue[(offset - MP_ETH_CRDP0) / 4] =
343
- s->cur_rx[(offset - MP_ETH_CRDP0) / 4] = value;
344
- break;
345
-
346
- case MP_ETH_CTDP0 ... MP_ETH_CTDP1:
347
- s->tx_queue[(offset - MP_ETH_CTDP0) / 4] = value;
348
- break;
349
- }
350
-}
351
-
352
-static const MemoryRegionOps mv88w8618_eth_ops = {
353
- .read = mv88w8618_eth_read,
354
- .write = mv88w8618_eth_write,
355
- .endianness = DEVICE_NATIVE_ENDIAN,
356
-};
357
-
358
-static void eth_cleanup(NetClientState *nc)
359
-{
360
- mv88w8618_eth_state *s = qemu_get_nic_opaque(nc);
361
-
362
- s->nic = NULL;
363
-}
364
-
365
-static NetClientInfo net_mv88w8618_info = {
366
- .type = NET_CLIENT_DRIVER_NIC,
367
- .size = sizeof(NICState),
368
- .receive = eth_receive,
369
- .cleanup = eth_cleanup,
370
-};
371
-
372
-static void mv88w8618_eth_init(Object *obj)
373
-{
374
- SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
375
- DeviceState *dev = DEVICE(sbd);
376
- mv88w8618_eth_state *s = MV88W8618_ETH(dev);
377
-
378
- sysbus_init_irq(sbd, &s->irq);
379
- memory_region_init_io(&s->iomem, obj, &mv88w8618_eth_ops, s,
380
- "mv88w8618-eth", MP_ETH_SIZE);
381
- sysbus_init_mmio(sbd, &s->iomem);
382
-}
383
-
384
-static void mv88w8618_eth_realize(DeviceState *dev, Error **errp)
385
-{
386
- mv88w8618_eth_state *s = MV88W8618_ETH(dev);
387
-
388
- if (!s->dma_mr) {
389
- error_setg(errp, TYPE_MV88W8618_ETH " 'dma-memory' link not set");
390
- return;
391
- }
392
-
393
- address_space_init(&s->dma_as, s->dma_mr, "emac-dma");
394
- s->nic = qemu_new_nic(&net_mv88w8618_info, &s->conf,
395
- object_get_typename(OBJECT(dev)), dev->id, s);
396
-}
397
-
398
-static const VMStateDescription mv88w8618_eth_vmsd = {
399
- .name = "mv88w8618_eth",
400
- .version_id = 1,
401
- .minimum_version_id = 1,
402
- .fields = (VMStateField[]) {
403
- VMSTATE_UINT32(smir, mv88w8618_eth_state),
404
- VMSTATE_UINT32(icr, mv88w8618_eth_state),
405
- VMSTATE_UINT32(imr, mv88w8618_eth_state),
406
- VMSTATE_UINT32(vlan_header, mv88w8618_eth_state),
407
- VMSTATE_UINT32_ARRAY(tx_queue, mv88w8618_eth_state, 2),
408
- VMSTATE_UINT32_ARRAY(rx_queue, mv88w8618_eth_state, 4),
409
- VMSTATE_UINT32_ARRAY(frx_queue, mv88w8618_eth_state, 4),
410
- VMSTATE_UINT32_ARRAY(cur_rx, mv88w8618_eth_state, 4),
411
- VMSTATE_END_OF_LIST()
412
- }
413
-};
414
-
415
-static Property mv88w8618_eth_properties[] = {
416
- DEFINE_NIC_PROPERTIES(mv88w8618_eth_state, conf),
417
- DEFINE_PROP_LINK("dma-memory", mv88w8618_eth_state, dma_mr,
418
- TYPE_MEMORY_REGION, MemoryRegion *),
419
- DEFINE_PROP_END_OF_LIST(),
420
-};
421
-
422
-static void mv88w8618_eth_class_init(ObjectClass *klass, void *data)
423
-{
424
- DeviceClass *dc = DEVICE_CLASS(klass);
425
-
426
- dc->vmsd = &mv88w8618_eth_vmsd;
427
- device_class_set_props(dc, mv88w8618_eth_properties);
428
- dc->realize = mv88w8618_eth_realize;
429
-}
430
-
431
-static const TypeInfo mv88w8618_eth_info = {
432
- .name = TYPE_MV88W8618_ETH,
433
- .parent = TYPE_SYS_BUS_DEVICE,
434
- .instance_size = sizeof(mv88w8618_eth_state),
435
- .instance_init = mv88w8618_eth_init,
436
- .class_init = mv88w8618_eth_class_init,
437
-};
438
-
439
/* LCD register offsets */
440
#define MP_LCD_IRQCTRL 0x180
441
#define MP_LCD_IRQSTAT 0x184
442
@@ -XXX,XX +XXX,XX @@ static void musicpal_register_types(void)
443
type_register_static(&mv88w8618_pic_info);
444
type_register_static(&mv88w8618_pit_info);
445
type_register_static(&mv88w8618_flashcfg_info);
446
- type_register_static(&mv88w8618_eth_info);
447
type_register_static(&mv88w8618_wlan_info);
448
type_register_static(&musicpal_lcd_info);
449
type_register_static(&musicpal_gpio_info);
450
diff --git a/hw/net/mv88w8618_eth.c b/hw/net/mv88w8618_eth.c
242
new file mode 100644
451
new file mode 100644
243
index XXXXXXX..XXXXXXX
452
index XXXXXXX..XXXXXXX
244
--- /dev/null
453
--- /dev/null
245
+++ b/hw/gpio/npcm7xx_gpio.c
454
+++ b/hw/net/mv88w8618_eth.c
246
@@ -XXX,XX +XXX,XX @@
455
@@ -XXX,XX +XXX,XX @@
456
+/* SPDX-License-Identifier: GPL-2.0-or-later */
247
+/*
457
+/*
248
+ * Nuvoton NPCM7xx General Purpose Input / Output (GPIO)
458
+ * Marvell MV88W8618 / Freecom MusicPal emulation.
249
+ *
459
+ *
250
+ * Copyright 2020 Google LLC
460
+ * Copyright (c) 2008 Jan Kiszka
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
+ */
461
+ */
261
+
462
+
262
+#include "qemu/osdep.h"
463
+#include "qemu/osdep.h"
263
+
464
+#include "qapi/error.h"
264
+#include "hw/gpio/npcm7xx_gpio.h"
465
+#include "hw/qdev-properties.h"
466
+#include "hw/sysbus.h"
265
+#include "hw/irq.h"
467
+#include "hw/irq.h"
266
+#include "hw/qdev-properties.h"
468
+#include "hw/net/mv88w8618_eth.h"
267
+#include "migration/vmstate.h"
469
+#include "migration/vmstate.h"
268
+#include "qapi/error.h"
470
+#include "sysemu/dma.h"
269
+#include "qemu/log.h"
471
+#include "net/net.h"
270
+#include "qemu/module.h"
472
+
271
+#include "qemu/units.h"
473
+#define MP_ETH_SIZE 0x00001000
272
+#include "trace.h"
474
+
273
+
475
+/* Ethernet register offsets */
274
+/* 32-bit register indices. */
476
+#define MP_ETH_SMIR 0x010
275
+enum NPCM7xxGPIORegister {
477
+#define MP_ETH_PCXR 0x408
276
+ NPCM7XX_GPIO_TLOCK1,
478
+#define MP_ETH_SDCMR 0x448
277
+ NPCM7XX_GPIO_DIN,
479
+#define MP_ETH_ICR 0x450
278
+ NPCM7XX_GPIO_POL,
480
+#define MP_ETH_IMR 0x458
279
+ NPCM7XX_GPIO_DOUT,
481
+#define MP_ETH_FRDP0 0x480
280
+ NPCM7XX_GPIO_OE,
482
+#define MP_ETH_FRDP1 0x484
281
+ NPCM7XX_GPIO_OTYP,
483
+#define MP_ETH_FRDP2 0x488
282
+ NPCM7XX_GPIO_MP,
484
+#define MP_ETH_FRDP3 0x48C
283
+ NPCM7XX_GPIO_PU,
485
+#define MP_ETH_CRDP0 0x4A0
284
+ NPCM7XX_GPIO_PD,
486
+#define MP_ETH_CRDP1 0x4A4
285
+ NPCM7XX_GPIO_DBNC,
487
+#define MP_ETH_CRDP2 0x4A8
286
+ NPCM7XX_GPIO_EVTYP,
488
+#define MP_ETH_CRDP3 0x4AC
287
+ NPCM7XX_GPIO_EVBE,
489
+#define MP_ETH_CTDP0 0x4E0
288
+ NPCM7XX_GPIO_OBL0,
490
+#define MP_ETH_CTDP1 0x4E4
289
+ NPCM7XX_GPIO_OBL1,
491
+
290
+ NPCM7XX_GPIO_OBL2,
492
+/* MII PHY access */
291
+ NPCM7XX_GPIO_OBL3,
493
+#define MP_ETH_SMIR_DATA 0x0000FFFF
292
+ NPCM7XX_GPIO_EVEN,
494
+#define MP_ETH_SMIR_ADDR 0x03FF0000
293
+ NPCM7XX_GPIO_EVENS,
495
+#define MP_ETH_SMIR_OPCODE (1 << 26) /* Read value */
294
+ NPCM7XX_GPIO_EVENC,
496
+#define MP_ETH_SMIR_RDVALID (1 << 27)
295
+ NPCM7XX_GPIO_EVST,
497
+
296
+ NPCM7XX_GPIO_SPLCK,
498
+/* PHY registers */
297
+ NPCM7XX_GPIO_MPLCK,
499
+#define MP_ETH_PHY1_BMSR 0x00210000
298
+ NPCM7XX_GPIO_IEM,
500
+#define MP_ETH_PHY1_PHYSID1 0x00410000
299
+ NPCM7XX_GPIO_OSRC,
501
+#define MP_ETH_PHY1_PHYSID2 0x00610000
300
+ NPCM7XX_GPIO_ODSC,
502
+
301
+ NPCM7XX_GPIO_DOS = 0x68 / sizeof(uint32_t),
503
+#define MP_PHY_BMSR_LINK 0x0004
302
+ NPCM7XX_GPIO_DOC,
504
+#define MP_PHY_BMSR_AUTONEG 0x0008
303
+ NPCM7XX_GPIO_OES,
505
+
304
+ NPCM7XX_GPIO_OEC,
506
+#define MP_PHY_88E3015 0x01410E20
305
+ NPCM7XX_GPIO_TLOCK2 = 0x7c / sizeof(uint32_t),
507
+
306
+ NPCM7XX_GPIO_REGS_END,
508
+/* TX descriptor status */
509
+#define MP_ETH_TX_OWN (1U << 31)
510
+
511
+/* RX descriptor status */
512
+#define MP_ETH_RX_OWN (1U << 31)
513
+
514
+/* Interrupt cause/mask bits */
515
+#define MP_ETH_IRQ_RX_BIT 0
516
+#define MP_ETH_IRQ_RX (1 << MP_ETH_IRQ_RX_BIT)
517
+#define MP_ETH_IRQ_TXHI_BIT 2
518
+#define MP_ETH_IRQ_TXLO_BIT 3
519
+
520
+/* Port config bits */
521
+#define MP_ETH_PCXR_2BSM_BIT 28 /* 2-byte incoming suffix */
522
+
523
+/* SDMA command bits */
524
+#define MP_ETH_CMD_TXHI (1 << 23)
525
+#define MP_ETH_CMD_TXLO (1 << 22)
526
+
527
+typedef struct mv88w8618_tx_desc {
528
+ uint32_t cmdstat;
529
+ uint16_t res;
530
+ uint16_t bytes;
531
+ uint32_t buffer;
532
+ uint32_t next;
533
+} mv88w8618_tx_desc;
534
+
535
+typedef struct mv88w8618_rx_desc {
536
+ uint32_t cmdstat;
537
+ uint16_t bytes;
538
+ uint16_t buffer_size;
539
+ uint32_t buffer;
540
+ uint32_t next;
541
+} mv88w8618_rx_desc;
542
+
543
+OBJECT_DECLARE_SIMPLE_TYPE(mv88w8618_eth_state, MV88W8618_ETH)
544
+
545
+struct mv88w8618_eth_state {
546
+ /*< private >*/
547
+ SysBusDevice parent_obj;
548
+ /*< public >*/
549
+
550
+ MemoryRegion iomem;
551
+ qemu_irq irq;
552
+ MemoryRegion *dma_mr;
553
+ AddressSpace dma_as;
554
+ uint32_t smir;
555
+ uint32_t icr;
556
+ uint32_t imr;
557
+ int mmio_index;
558
+ uint32_t vlan_header;
559
+ uint32_t tx_queue[2];
560
+ uint32_t rx_queue[4];
561
+ uint32_t frx_queue[4];
562
+ uint32_t cur_rx[4];
563
+ NICState *nic;
564
+ NICConf conf;
307
+};
565
+};
308
+
566
+
309
+#define NPCM7XX_GPIO_REGS_SIZE (4 * KiB)
567
+static void eth_rx_desc_put(AddressSpace *dma_as, uint32_t addr,
310
+
568
+ mv88w8618_rx_desc *desc)
311
+#define NPCM7XX_GPIO_LOCK_MAGIC1 (0xc0defa73)
569
+{
312
+#define NPCM7XX_GPIO_LOCK_MAGIC2 (0xc0de1248)
570
+ cpu_to_le32s(&desc->cmdstat);
313
+
571
+ cpu_to_le16s(&desc->bytes);
314
+static void npcm7xx_gpio_update_events(NPCM7xxGPIOState *s, uint32_t din_diff)
572
+ cpu_to_le16s(&desc->buffer_size);
315
+{
573
+ cpu_to_le32s(&desc->buffer);
316
+ uint32_t din_new = s->regs[NPCM7XX_GPIO_DIN];
574
+ cpu_to_le32s(&desc->next);
317
+
575
+ dma_memory_write(dma_as, addr, desc, sizeof(*desc), MEMTXATTRS_UNSPECIFIED);
318
+ /* Trigger on high level */
576
+}
319
+ s->regs[NPCM7XX_GPIO_EVST] |= din_new & ~s->regs[NPCM7XX_GPIO_EVTYP];
577
+
320
+ /* Trigger on both edges */
578
+static void eth_rx_desc_get(AddressSpace *dma_as, uint32_t addr,
321
+ s->regs[NPCM7XX_GPIO_EVST] |= (din_diff & s->regs[NPCM7XX_GPIO_EVTYP]
579
+ mv88w8618_rx_desc *desc)
322
+ & s->regs[NPCM7XX_GPIO_EVBE]);
580
+{
323
+ /* Trigger on rising edge */
581
+ dma_memory_read(dma_as, addr, desc, sizeof(*desc), MEMTXATTRS_UNSPECIFIED);
324
+ s->regs[NPCM7XX_GPIO_EVST] |= (din_diff & din_new
582
+ le32_to_cpus(&desc->cmdstat);
325
+ & s->regs[NPCM7XX_GPIO_EVTYP]);
583
+ le16_to_cpus(&desc->bytes);
326
+
584
+ le16_to_cpus(&desc->buffer_size);
327
+ trace_npcm7xx_gpio_update_events(DEVICE(s)->canonical_path,
585
+ le32_to_cpus(&desc->buffer);
328
+ s->regs[NPCM7XX_GPIO_EVST],
586
+ le32_to_cpus(&desc->next);
329
+ s->regs[NPCM7XX_GPIO_EVEN]);
587
+}
330
+ qemu_set_irq(s->irq, !!(s->regs[NPCM7XX_GPIO_EVST]
588
+
331
+ & s->regs[NPCM7XX_GPIO_EVEN]));
589
+static ssize_t eth_receive(NetClientState *nc, const uint8_t *buf, size_t size)
332
+}
590
+{
333
+
591
+ mv88w8618_eth_state *s = qemu_get_nic_opaque(nc);
334
+static void npcm7xx_gpio_update_pins(NPCM7xxGPIOState *s, uint32_t diff)
592
+ uint32_t desc_addr;
335
+{
593
+ mv88w8618_rx_desc desc;
336
+ uint32_t drive_en;
594
+ int i;
337
+ uint32_t drive_lvl;
595
+
338
+ uint32_t not_driven;
596
+ for (i = 0; i < 4; i++) {
339
+ uint32_t undefined;
597
+ desc_addr = s->cur_rx[i];
340
+ uint32_t pin_diff;
598
+ if (!desc_addr) {
341
+ uint32_t din_old;
599
+ continue;
342
+
600
+ }
343
+ /* Calculate level of each pin driven by GPIO controller. */
601
+ do {
344
+ drive_lvl = s->regs[NPCM7XX_GPIO_DOUT] ^ s->regs[NPCM7XX_GPIO_POL];
602
+ eth_rx_desc_get(&s->dma_as, desc_addr, &desc);
345
+ /* If OTYP=1, only drive low (open drain) */
603
+ if ((desc.cmdstat & MP_ETH_RX_OWN) && desc.buffer_size >= size) {
346
+ drive_en = s->regs[NPCM7XX_GPIO_OE] & ~(s->regs[NPCM7XX_GPIO_OTYP]
604
+ dma_memory_write(&s->dma_as, desc.buffer + s->vlan_header,
347
+ & drive_lvl);
605
+ buf, size, MEMTXATTRS_UNSPECIFIED);
348
+ /*
606
+ desc.bytes = size + s->vlan_header;
349
+ * If a pin is driven to opposite levels by the GPIO controller and the
607
+ desc.cmdstat &= ~MP_ETH_RX_OWN;
350
+ * external driver, the result is undefined.
608
+ s->cur_rx[i] = desc.next;
351
+ */
609
+
352
+ undefined = drive_en & s->ext_driven & (drive_lvl ^ s->ext_level);
610
+ s->icr |= MP_ETH_IRQ_RX;
353
+ if (undefined) {
611
+ if (s->icr & s->imr) {
354
+ qemu_log_mask(LOG_GUEST_ERROR,
612
+ qemu_irq_raise(s->irq);
355
+ "%s: pins have multiple drivers: 0x%" PRIx32 "\n",
613
+ }
356
+ DEVICE(s)->canonical_path, undefined);
614
+ eth_rx_desc_put(&s->dma_as, desc_addr, &desc);
615
+ return size;
616
+ }
617
+ desc_addr = desc.next;
618
+ } while (desc_addr != s->rx_queue[i]);
357
+ }
619
+ }
358
+
620
+ return size;
359
+ not_driven = ~(drive_en | s->ext_driven);
621
+}
360
+ pin_diff = s->pin_level;
622
+
361
+
623
+static void eth_tx_desc_put(AddressSpace *dma_as, uint32_t addr,
362
+ /* Set pins to externally driven level. */
624
+ mv88w8618_tx_desc *desc)
363
+ s->pin_level = s->ext_level & s->ext_driven;
625
+{
364
+ /* Set internally driven pins, ignoring any conflicts. */
626
+ cpu_to_le32s(&desc->cmdstat);
365
+ s->pin_level |= drive_lvl & drive_en;
627
+ cpu_to_le16s(&desc->res);
366
+ /* Pull up undriven pins with internal pull-up enabled. */
628
+ cpu_to_le16s(&desc->bytes);
367
+ s->pin_level |= not_driven & s->regs[NPCM7XX_GPIO_PU];
629
+ cpu_to_le32s(&desc->buffer);
368
+ /* Pins not driven, pulled up or pulled down are undefined */
630
+ cpu_to_le32s(&desc->next);
369
+ undefined |= not_driven & ~(s->regs[NPCM7XX_GPIO_PU]
631
+ dma_memory_write(dma_as, addr, desc, sizeof(*desc), MEMTXATTRS_UNSPECIFIED);
370
+ | s->regs[NPCM7XX_GPIO_PD]);
632
+}
371
+
633
+
372
+ /* If any pins changed state, update the outgoing GPIOs. */
634
+static void eth_tx_desc_get(AddressSpace *dma_as, uint32_t addr,
373
+ pin_diff ^= s->pin_level;
635
+ mv88w8618_tx_desc *desc)
374
+ pin_diff |= undefined & diff;
636
+{
375
+ if (pin_diff) {
637
+ dma_memory_read(dma_as, addr, desc, sizeof(*desc), MEMTXATTRS_UNSPECIFIED);
376
+ int i;
638
+ le32_to_cpus(&desc->cmdstat);
377
+
639
+ le16_to_cpus(&desc->res);
378
+ for (i = 0; i < NPCM7XX_GPIO_NR_PINS; i++) {
640
+ le16_to_cpus(&desc->bytes);
379
+ uint32_t mask = BIT(i);
641
+ le32_to_cpus(&desc->buffer);
380
+ if (pin_diff & mask) {
642
+ le32_to_cpus(&desc->next);
381
+ int level = (undefined & mask) ? -1 : !!(s->pin_level & mask);
643
+}
382
+ trace_npcm7xx_gpio_set_output(DEVICE(s)->canonical_path,
644
+
383
+ i, level);
645
+static void eth_send(mv88w8618_eth_state *s, int queue_index)
384
+ qemu_set_irq(s->output[i], level);
646
+{
647
+ uint32_t desc_addr = s->tx_queue[queue_index];
648
+ mv88w8618_tx_desc desc;
649
+ uint32_t next_desc;
650
+ uint8_t buf[2048];
651
+ int len;
652
+
653
+ do {
654
+ eth_tx_desc_get(&s->dma_as, desc_addr, &desc);
655
+ next_desc = desc.next;
656
+ if (desc.cmdstat & MP_ETH_TX_OWN) {
657
+ len = desc.bytes;
658
+ if (len < 2048) {
659
+ dma_memory_read(&s->dma_as, desc.buffer, buf, len,
660
+ MEMTXATTRS_UNSPECIFIED);
661
+ qemu_send_packet(qemu_get_queue(s->nic), buf, len);
662
+ }
663
+ desc.cmdstat &= ~MP_ETH_TX_OWN;
664
+ s->icr |= 1 << (MP_ETH_IRQ_TXLO_BIT - queue_index);
665
+ eth_tx_desc_put(&s->dma_as, desc_addr, &desc);
666
+ }
667
+ desc_addr = next_desc;
668
+ } while (desc_addr != s->tx_queue[queue_index]);
669
+}
670
+
671
+static uint64_t mv88w8618_eth_read(void *opaque, hwaddr offset,
672
+ unsigned size)
673
+{
674
+ mv88w8618_eth_state *s = opaque;
675
+
676
+ switch (offset) {
677
+ case MP_ETH_SMIR:
678
+ if (s->smir & MP_ETH_SMIR_OPCODE) {
679
+ switch (s->smir & MP_ETH_SMIR_ADDR) {
680
+ case MP_ETH_PHY1_BMSR:
681
+ return MP_PHY_BMSR_LINK | MP_PHY_BMSR_AUTONEG |
682
+ MP_ETH_SMIR_RDVALID;
683
+ case MP_ETH_PHY1_PHYSID1:
684
+ return (MP_PHY_88E3015 >> 16) | MP_ETH_SMIR_RDVALID;
685
+ case MP_ETH_PHY1_PHYSID2:
686
+ return (MP_PHY_88E3015 & 0xFFFF) | MP_ETH_SMIR_RDVALID;
687
+ default:
688
+ return MP_ETH_SMIR_RDVALID;
385
+ }
689
+ }
386
+ }
690
+ }
691
+ return 0;
692
+
693
+ case MP_ETH_ICR:
694
+ return s->icr;
695
+
696
+ case MP_ETH_IMR:
697
+ return s->imr;
698
+
699
+ case MP_ETH_FRDP0 ... MP_ETH_FRDP3:
700
+ return s->frx_queue[(offset - MP_ETH_FRDP0) / 4];
701
+
702
+ case MP_ETH_CRDP0 ... MP_ETH_CRDP3:
703
+ return s->rx_queue[(offset - MP_ETH_CRDP0) / 4];
704
+
705
+ case MP_ETH_CTDP0 ... MP_ETH_CTDP1:
706
+ return s->tx_queue[(offset - MP_ETH_CTDP0) / 4];
707
+
708
+ default:
709
+ return 0;
387
+ }
710
+ }
388
+
711
+}
389
+ /* Calculate new value of DIN after masking and polarity setting. */
712
+
390
+ din_old = s->regs[NPCM7XX_GPIO_DIN];
713
+static void mv88w8618_eth_write(void *opaque, hwaddr offset,
391
+ s->regs[NPCM7XX_GPIO_DIN] = ((s->pin_level & s->regs[NPCM7XX_GPIO_IEM])
714
+ uint64_t value, unsigned size)
392
+ ^ s->regs[NPCM7XX_GPIO_POL]);
715
+{
393
+
716
+ mv88w8618_eth_state *s = opaque;
394
+ /* See if any new events triggered because of all this. */
717
+
395
+ npcm7xx_gpio_update_events(s, din_old ^ s->regs[NPCM7XX_GPIO_DIN]);
718
+ switch (offset) {
396
+}
719
+ case MP_ETH_SMIR:
397
+
720
+ s->smir = value;
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;
721
+ break;
415
+
722
+
416
+ case NPCM7XX_GPIO_EVENS ... NPCM7XX_GPIO_EVENC:
723
+ case MP_ETH_PCXR:
417
+ case NPCM7XX_GPIO_DOS ... NPCM7XX_GPIO_TLOCK2:
724
+ s->vlan_header = ((value >> MP_ETH_PCXR_2BSM_BIT) & 1) * 2;
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;
725
+ break;
422
+
726
+
423
+ default:
727
+ case MP_ETH_SDCMR:
424
+ qemu_log_mask(LOG_GUEST_ERROR,
728
+ if (value & MP_ETH_CMD_TXHI) {
425
+ "%s: read from invalid offset 0x%" HWADDR_PRIx "\n",
729
+ eth_send(s, 1);
426
+ DEVICE(s)->canonical_path, addr);
730
+ }
731
+ if (value & MP_ETH_CMD_TXLO) {
732
+ eth_send(s, 0);
733
+ }
734
+ if (value & (MP_ETH_CMD_TXHI | MP_ETH_CMD_TXLO) && s->icr & s->imr) {
735
+ qemu_irq_raise(s->irq);
736
+ }
737
+ break;
738
+
739
+ case MP_ETH_ICR:
740
+ s->icr &= value;
741
+ break;
742
+
743
+ case MP_ETH_IMR:
744
+ s->imr = value;
745
+ if (s->icr & s->imr) {
746
+ qemu_irq_raise(s->irq);
747
+ }
748
+ break;
749
+
750
+ case MP_ETH_FRDP0 ... MP_ETH_FRDP3:
751
+ s->frx_queue[(offset - MP_ETH_FRDP0) / 4] = value;
752
+ break;
753
+
754
+ case MP_ETH_CRDP0 ... MP_ETH_CRDP3:
755
+ s->rx_queue[(offset - MP_ETH_CRDP0) / 4] =
756
+ s->cur_rx[(offset - MP_ETH_CRDP0) / 4] = value;
757
+ break;
758
+
759
+ case MP_ETH_CTDP0 ... MP_ETH_CTDP1:
760
+ s->tx_queue[(offset - MP_ETH_CTDP0) / 4] = value;
427
+ break;
761
+ break;
428
+ }
762
+ }
429
+
763
+}
430
+ trace_npcm7xx_gpio_read(DEVICE(s)->canonical_path, addr, value);
764
+
431
+
765
+static const MemoryRegionOps mv88w8618_eth_ops = {
432
+ return value;
766
+ .read = mv88w8618_eth_read,
433
+}
767
+ .write = mv88w8618_eth_write,
434
+
768
+ .endianness = DEVICE_NATIVE_ENDIAN,
435
+static void npcm7xx_gpio_regs_write(void *opaque, hwaddr addr, uint64_t v,
769
+};
436
+ unsigned int size)
770
+
437
+{
771
+static void eth_cleanup(NetClientState *nc)
438
+ hwaddr reg = addr / sizeof(uint32_t);
772
+{
439
+ NPCM7xxGPIOState *s = opaque;
773
+ mv88w8618_eth_state *s = qemu_get_nic_opaque(nc);
440
+ uint32_t value = v;
774
+
441
+ uint32_t diff;
775
+ s->nic = NULL;
442
+
776
+}
443
+ trace_npcm7xx_gpio_write(DEVICE(s)->canonical_path, addr, v);
777
+
444
+
778
+static NetClientInfo net_mv88w8618_info = {
445
+ if (npcm7xx_gpio_is_locked(s)) {
779
+ .type = NET_CLIENT_DRIVER_NIC,
446
+ switch (reg) {
780
+ .size = sizeof(NICState),
447
+ case NPCM7XX_GPIO_TLOCK1:
781
+ .receive = eth_receive,
448
+ if (s->regs[NPCM7XX_GPIO_TLOCK2] == NPCM7XX_GPIO_LOCK_MAGIC2 &&
782
+ .cleanup = eth_cleanup,
449
+ value == NPCM7XX_GPIO_LOCK_MAGIC1) {
783
+};
450
+ s->regs[NPCM7XX_GPIO_TLOCK1] = 0;
784
+
451
+ s->regs[NPCM7XX_GPIO_TLOCK2] = 0;
785
+static void mv88w8618_eth_init(Object *obj)
452
+ }
786
+{
453
+ break;
787
+ SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
454
+
788
+ DeviceState *dev = DEVICE(sbd);
455
+ case NPCM7XX_GPIO_TLOCK2:
789
+ mv88w8618_eth_state *s = MV88W8618_ETH(dev);
456
+ s->regs[reg] = value;
790
+
457
+ break;
791
+ sysbus_init_irq(sbd, &s->irq);
458
+
792
+ memory_region_init_io(&s->iomem, obj, &mv88w8618_eth_ops, s,
459
+ default:
793
+ "mv88w8618-eth", MP_ETH_SIZE);
460
+ qemu_log_mask(LOG_GUEST_ERROR,
794
+ sysbus_init_mmio(sbd, &s->iomem);
461
+ "%s: write to locked register @ 0x%" HWADDR_PRIx "\n",
795
+}
462
+ DEVICE(s)->canonical_path, addr);
796
+
463
+ break;
797
+static void mv88w8618_eth_realize(DeviceState *dev, Error **errp)
464
+ }
798
+{
465
+
799
+ mv88w8618_eth_state *s = MV88W8618_ETH(dev);
800
+
801
+ if (!s->dma_mr) {
802
+ error_setg(errp, TYPE_MV88W8618_ETH " 'dma-memory' link not set");
466
+ return;
803
+ return;
467
+ }
804
+ }
468
+
805
+
469
+ diff = s->regs[reg] ^ value;
806
+ address_space_init(&s->dma_as, s->dma_mr, "emac-dma");
470
+
807
+ s->nic = qemu_new_nic(&net_mv88w8618_info, &s->conf,
471
+ switch (reg) {
808
+ object_get_typename(OBJECT(dev)), dev->id, s);
472
+ case NPCM7XX_GPIO_TLOCK1:
809
+}
473
+ case NPCM7XX_GPIO_TLOCK2:
810
+
474
+ s->regs[NPCM7XX_GPIO_TLOCK1] = 1;
811
+static const VMStateDescription mv88w8618_eth_vmsd = {
475
+ s->regs[NPCM7XX_GPIO_TLOCK2] = 0;
812
+ .name = "mv88w8618_eth",
476
+ break;
813
+ .version_id = 1,
477
+
814
+ .minimum_version_id = 1,
478
+ case NPCM7XX_GPIO_DIN:
815
+ .fields = (VMStateField[]) {
479
+ qemu_log_mask(LOG_GUEST_ERROR,
816
+ VMSTATE_UINT32(smir, mv88w8618_eth_state),
480
+ "%s: write to read-only register @ 0x%" HWADDR_PRIx "\n",
817
+ VMSTATE_UINT32(icr, mv88w8618_eth_state),
481
+ DEVICE(s)->canonical_path, addr);
818
+ VMSTATE_UINT32(imr, mv88w8618_eth_state),
482
+ break;
819
+ VMSTATE_UINT32(vlan_header, mv88w8618_eth_state),
483
+
820
+ VMSTATE_UINT32_ARRAY(tx_queue, mv88w8618_eth_state, 2),
484
+ case NPCM7XX_GPIO_POL:
821
+ VMSTATE_UINT32_ARRAY(rx_queue, mv88w8618_eth_state, 4),
485
+ case NPCM7XX_GPIO_DOUT:
822
+ VMSTATE_UINT32_ARRAY(frx_queue, mv88w8618_eth_state, 4),
486
+ case NPCM7XX_GPIO_OE:
823
+ VMSTATE_UINT32_ARRAY(cur_rx, mv88w8618_eth_state, 4),
487
+ case NPCM7XX_GPIO_OTYP:
824
+ VMSTATE_END_OF_LIST()
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
+ }
825
+ }
562
+}
563
+
564
+static const MemoryRegionOps npcm7xx_gpio_regs_ops = {
565
+ .read = npcm7xx_gpio_regs_read,
566
+ .write = npcm7xx_gpio_regs_write,
567
+ .endianness = DEVICE_NATIVE_ENDIAN,
568
+ .valid = {
569
+ .min_access_size = 4,
570
+ .max_access_size = 4,
571
+ .unaligned = false,
572
+ },
573
+};
826
+};
574
+
827
+
575
+static void npcm7xx_gpio_set_input(void *opaque, int line, int level)
828
+static Property mv88w8618_eth_properties[] = {
576
+{
829
+ DEFINE_NIC_PROPERTIES(mv88w8618_eth_state, conf),
577
+ NPCM7xxGPIOState *s = opaque;
830
+ DEFINE_PROP_LINK("dma-memory", mv88w8618_eth_state, dma_mr,
578
+
831
+ TYPE_MEMORY_REGION, MemoryRegion *),
579
+ trace_npcm7xx_gpio_set_input(DEVICE(s)->canonical_path, line, level);
580
+
581
+ g_assert(line >= 0 && line < NPCM7XX_GPIO_NR_PINS);
582
+
583
+ s->ext_driven = deposit32(s->ext_driven, line, 1, level >= 0);
584
+ s->ext_level = deposit32(s->ext_level, line, 1, level > 0);
585
+
586
+ npcm7xx_gpio_update_pins(s, BIT(line));
587
+}
588
+
589
+static void npcm7xx_gpio_enter_reset(Object *obj, ResetType type)
590
+{
591
+ NPCM7xxGPIOState *s = NPCM7XX_GPIO(obj);
592
+
593
+ memset(s->regs, 0, sizeof(s->regs));
594
+
595
+ s->regs[NPCM7XX_GPIO_PU] = s->reset_pu;
596
+ s->regs[NPCM7XX_GPIO_PD] = s->reset_pd;
597
+ s->regs[NPCM7XX_GPIO_OSRC] = s->reset_osrc;
598
+ s->regs[NPCM7XX_GPIO_ODSC] = s->reset_odsc;
599
+}
600
+
601
+static void npcm7xx_gpio_hold_reset(Object *obj)
602
+{
603
+ NPCM7xxGPIOState *s = NPCM7XX_GPIO(obj);
604
+
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(),
832
+ DEFINE_PROP_END_OF_LIST(),
645
+};
833
+};
646
+
834
+
647
+static void npcm7xx_gpio_class_init(ObjectClass *klass, void *data)
835
+static void mv88w8618_eth_class_init(ObjectClass *klass, void *data)
648
+{
836
+{
649
+ ResettableClass *reset = RESETTABLE_CLASS(klass);
650
+ DeviceClass *dc = DEVICE_CLASS(klass);
837
+ DeviceClass *dc = DEVICE_CLASS(klass);
651
+
838
+
652
+ QEMU_BUILD_BUG_ON(NPCM7XX_GPIO_REGS_END > NPCM7XX_GPIO_NR_REGS);
839
+ dc->vmsd = &mv88w8618_eth_vmsd;
653
+
840
+ device_class_set_props(dc, mv88w8618_eth_properties);
654
+ dc->desc = "NPCM7xx GPIO Controller";
841
+ dc->realize = mv88w8618_eth_realize;
655
+ dc->vmsd = &vmstate_npcm7xx_gpio;
842
+}
656
+ reset->phases.enter = npcm7xx_gpio_enter_reset;
843
+
657
+ reset->phases.hold = npcm7xx_gpio_hold_reset;
844
+static const TypeInfo mv88w8618_eth_info = {
658
+ device_class_set_props(dc, npcm7xx_gpio_properties);
845
+ .name = TYPE_MV88W8618_ETH,
659
+}
846
+ .parent = TYPE_SYS_BUS_DEVICE,
660
+
847
+ .instance_size = sizeof(mv88w8618_eth_state),
661
+static const TypeInfo npcm7xx_gpio_types[] = {
848
+ .instance_init = mv88w8618_eth_init,
662
+ {
849
+ .class_init = mv88w8618_eth_class_init,
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
+};
850
+};
670
+DEFINE_TYPES(npcm7xx_gpio_types);
851
+
671
diff --git a/tests/qtest/npcm7xx_gpio-test.c b/tests/qtest/npcm7xx_gpio-test.c
852
+static void musicpal_register_types(void)
672
new file mode 100644
853
+{
673
index XXXXXXX..XXXXXXX
854
+ type_register_static(&mv88w8618_eth_info);
674
--- /dev/null
855
+}
675
+++ b/tests/qtest/npcm7xx_gpio-test.c
856
+
676
@@ -XXX,XX +XXX,XX @@
857
+type_init(musicpal_register_types)
677
+/*
858
+
678
+ * QTest testcase for the Nuvoton NPCM7xx GPIO modules.
859
diff --git a/MAINTAINERS b/MAINTAINERS
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
860
index XXXXXXX..XXXXXXX 100644
1064
--- a/hw/gpio/meson.build
861
--- a/MAINTAINERS
1065
+++ b/hw/gpio/meson.build
862
+++ b/MAINTAINERS
1066
@@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_PUV3', if_true: files('puv3_gpio.c'))
863
@@ -XXX,XX +XXX,XX @@ M: Peter Maydell <peter.maydell@linaro.org>
1067
softmmu_ss.add(when: 'CONFIG_ZAURUS', if_true: files('zaurus.c'))
864
L: qemu-arm@nongnu.org
1068
865
S: Odd Fixes
1069
softmmu_ss.add(when: 'CONFIG_IMX', if_true: files('imx_gpio.c'))
866
F: hw/arm/musicpal.c
1070
+softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_gpio.c'))
867
+F: hw/net/mv88w8618_eth.c
1071
softmmu_ss.add(when: 'CONFIG_NRF51_SOC', if_true: files('nrf51_gpio.c'))
868
+F: include/hw/net/mv88w8618_eth.h
1072
softmmu_ss.add(when: 'CONFIG_OMAP', if_true: files('omap_gpio.c'))
869
F: docs/system/arm/musicpal.rst
1073
softmmu_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2835_gpio.c'))
870
1074
diff --git a/hw/gpio/trace-events b/hw/gpio/trace-events
871
Nuvoton NPCM7xx
872
diff --git a/hw/net/meson.build b/hw/net/meson.build
1075
index XXXXXXX..XXXXXXX 100644
873
index XXXXXXX..XXXXXXX 100644
1076
--- a/hw/gpio/trace-events
874
--- a/hw/net/meson.build
1077
+++ b/hw/gpio/trace-events
875
+++ b/hw/net/meson.build
1078
@@ -XXX,XX +XXX,XX @@
876
@@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_ALLWINNER_EMAC', if_true: files('allwinner_emac.c')
1079
# See docs/devel/tracing.txt for syntax documentation.
877
softmmu_ss.add(when: 'CONFIG_ALLWINNER_SUN8I_EMAC', if_true: files('allwinner-sun8i-emac.c'))
1080
878
softmmu_ss.add(when: 'CONFIG_IMX_FEC', if_true: files('imx_fec.c'))
1081
+# npcm7xx_gpio.c
879
softmmu_ss.add(when: 'CONFIG_MSF2', if_true: files('msf2-emac.c'))
1082
+npcm7xx_gpio_read(const char *id, uint64_t offset, uint64_t value) " %s offset: 0x%04" PRIx64 " value 0x%08" PRIx64
880
+softmmu_ss.add(when: 'CONFIG_MARVELL_88W8618', if_true: files('mv88w8618_eth.c'))
1083
+npcm7xx_gpio_write(const char *id, uint64_t offset, uint64_t value) "%s offset: 0x%04" PRIx64 " value 0x%08" PRIx64
881
1084
+npcm7xx_gpio_set_input(const char *id, int32_t line, int32_t level) "%s line: %" PRIi32 " level: %" PRIi32
882
softmmu_ss.add(when: 'CONFIG_CADENCE', if_true: files('cadence_gem.c'))
1085
+npcm7xx_gpio_set_output(const char *id, int32_t line, int32_t level) "%s line: %" PRIi32 " level: %" PRIi32
883
softmmu_ss.add(when: 'CONFIG_STELLARIS_ENET', if_true: files('stellaris_enet.c'))
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
--
884
--
1106
2.20.1
885
2.25.1
1107
886
1108
887
diff view generated by jsdifflib
1
From: Shashi Mallela <shashi.mallela@linaro.org>
1
From: Yanan Wang <wangyanan55@huawei.com>
2
2
3
Included the newly implemented SBSA generic watchdog device model into
3
ARM64 machines like Kunpeng Family Server Chips have a level
4
SBSA platform
4
of hardware topology in which a group of CPU cores share L3
5
cache tag or L2 cache. For example, Kunpeng 920 typically
6
has 6 or 8 clusters in each NUMA node (also represent range
7
of CPU die), and each cluster has 4 CPU cores. All clusters
8
share L3 cache data, but CPU cores in each cluster share a
9
local L3 tag.
5
10
6
Signed-off-by: Shashi Mallela <shashi.mallela@linaro.org>
11
Running a guest kernel with Cluster-Aware Scheduling on the
7
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
12
Hosts which have physical clusters, if we can design a vCPU
8
Message-id: 20201027015927.29495-3-shashi.mallela@linaro.org
13
topology with cluster level for guest kernel and then have
14
a dedicated vCPU pinning, the guest will gain scheduling
15
performance improvement from cache affinity of CPU cluster.
16
17
So let's enable the support for this new parameter on ARM
18
virt machines. After this patch, we can define a 4-level
19
CPU hierarchy like: cpus=*,maxcpus=*,sockets=*,clusters=*,
20
cores=*,threads=*.
21
22
Signed-off-by: Yanan Wang <wangyanan55@huawei.com>
23
Reviewed-by: Andrew Jones <drjones@redhat.com>
24
Message-id: 20220107083232.16256-2-wangyanan55@huawei.com
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
25
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
---
26
---
11
hw/arm/sbsa-ref.c | 23 +++++++++++++++++++++++
27
hw/arm/virt.c | 1 +
12
1 file changed, 23 insertions(+)
28
qemu-options.hx | 10 ++++++++++
29
2 files changed, 11 insertions(+)
13
30
14
diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c
31
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
15
index XXXXXXX..XXXXXXX 100644
32
index XXXXXXX..XXXXXXX 100644
16
--- a/hw/arm/sbsa-ref.c
33
--- a/hw/arm/virt.c
17
+++ b/hw/arm/sbsa-ref.c
34
+++ b/hw/arm/virt.c
18
@@ -XXX,XX +XXX,XX @@
35
@@ -XXX,XX +XXX,XX @@ static void virt_machine_class_init(ObjectClass *oc, void *data)
19
#include "hw/qdev-properties.h"
36
hc->unplug_request = virt_machine_device_unplug_request_cb;
20
#include "hw/usb.h"
37
hc->unplug = virt_machine_device_unplug_cb;
21
#include "hw/char/pl011.h"
38
mc->nvdimm_supported = true;
22
+#include "hw/watchdog/sbsa_gwdt.h"
39
+ mc->smp_props.clusters_supported = true;
23
#include "net/net.h"
40
mc->auto_enable_numa_with_memhp = true;
24
#include "qom/object.h"
41
mc->auto_enable_numa_with_memdev = true;
25
42
mc->default_ram_id = "mach-virt.ram";
26
@@ -XXX,XX +XXX,XX @@ enum {
43
diff --git a/qemu-options.hx b/qemu-options.hx
27
SBSA_GIC_DIST,
44
index XXXXXXX..XXXXXXX 100644
28
SBSA_GIC_REDIST,
45
--- a/qemu-options.hx
29
SBSA_SECURE_EC,
46
+++ b/qemu-options.hx
30
+ SBSA_GWDT,
47
@@ -XXX,XX +XXX,XX @@ SRST
31
+ SBSA_GWDT_REFRESH,
48
32
+ SBSA_GWDT_CONTROL,
49
-smp 16,sockets=2,dies=2,cores=2,threads=2,maxcpus=16
33
SBSA_SMMU,
50
34
SBSA_UART,
51
+ The following sub-option defines a CPU topology hierarchy (2 sockets
35
SBSA_RTC,
52
+ totally on the machine, 2 clusters per socket, 2 cores per cluster,
36
@@ -XXX,XX +XXX,XX @@ static const MemMapEntry sbsa_ref_memmap[] = {
53
+ 2 threads per core) for ARM virt machines which support sockets/clusters
37
[SBSA_GIC_DIST] = { 0x40060000, 0x00010000 },
54
+ /cores/threads. Some members of the option can be omitted but their values
38
[SBSA_GIC_REDIST] = { 0x40080000, 0x04000000 },
55
+ will be automatically computed:
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
};
51
52
static uint64_t sbsa_ref_cpu_mp_affinity(SBSAMachineState *sms, int idx)
53
@@ -XXX,XX +XXX,XX @@ static void create_rtc(const SBSAMachineState *sms)
54
sysbus_create_simple("pl031", base, qdev_get_gpio_in(sms->gic, irq));
55
}
56
57
+static void create_wdt(const SBSAMachineState *sms)
58
+{
59
+ hwaddr rbase = sbsa_ref_memmap[SBSA_GWDT_REFRESH].base;
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
+
56
+
65
+ sysbus_realize_and_unref(s, &error_fatal);
57
+ ::
66
+ sysbus_mmio_map(s, 0, rbase);
67
+ sysbus_mmio_map(s, 1, cbase);
68
+ sysbus_connect_irq(s, 0, qdev_get_gpio_in(sms->gic, irq));
69
+}
70
+
58
+
71
static DeviceState *gpio_key_dev;
59
+ -smp 16,sockets=2,clusters=2,cores=2,threads=2,maxcpus=16
72
static void sbsa_ref_powerdown_req(Notifier *n, void *opaque)
73
{
74
@@ -XXX,XX +XXX,XX @@ static void sbsa_ref_init(MachineState *machine)
75
76
create_rtc(sms);
77
78
+ create_wdt(sms);
79
+
60
+
80
create_gpio(sms);
61
Historically preference was given to the coarsest topology parameters
81
62
when computing missing values (ie sockets preferred over cores, which
82
create_ahci(sms);
63
were preferred over threads), however, this behaviour is considered
83
--
64
--
84
2.20.1
65
2.25.1
85
66
86
67
diff view generated by jsdifflib
1
From: Luc Michel <luc@lmichel.fr>
1
From: Yanan Wang <wangyanan55@huawei.com>
2
2
3
Connect the 'uart-out' clock from the CPRMAN to the PL011 instance.
3
Support one cluster level between core and physical package in the
4
cpu-map of Arm/virt devicetree. This is also consistent with Linux
5
Doc "Documentation/devicetree/bindings/cpu/cpu-topology.txt".
4
6
5
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
7
Signed-off-by: Yanan Wang <wangyanan55@huawei.com>
6
Signed-off-by: Luc Michel <luc@lmichel.fr>
8
Reviewed-by: Andrew Jones <drjones@redhat.com>
7
Tested-by: Guenter Roeck <linux@roeck-us.net>
9
Message-id: 20220107083232.16256-3-wangyanan55@huawei.com
8
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.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/bcm2835_peripherals.c | 2 ++
12
hw/arm/virt.c | 15 ++++++++-------
12
1 file changed, 2 insertions(+)
13
1 file changed, 8 insertions(+), 7 deletions(-)
13
14
14
diff --git a/hw/arm/bcm2835_peripherals.c b/hw/arm/bcm2835_peripherals.c
15
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
15
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
16
--- a/hw/arm/bcm2835_peripherals.c
17
--- a/hw/arm/virt.c
17
+++ b/hw/arm/bcm2835_peripherals.c
18
+++ b/hw/arm/virt.c
18
@@ -XXX,XX +XXX,XX @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)
19
@@ -XXX,XX +XXX,XX @@ static void fdt_add_cpu_nodes(const VirtMachineState *vms)
19
}
20
* can contain several layers of clustering within a single physical
20
memory_region_add_subregion(&s->peri_mr, CPRMAN_OFFSET,
21
* package and cluster nodes can be contained in parent cluster nodes.
21
sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->cprman), 0));
22
*
22
+ qdev_connect_clock_in(DEVICE(&s->uart0), "clk",
23
- * Given that cluster is not yet supported in the vCPU topology,
23
+ qdev_get_clock_out(DEVICE(&s->cprman), "uart-out"));
24
- * we currently generate one cluster node within each socket node
24
25
- * by default.
25
memory_region_add_subregion(&s->peri_mr, ARMCTRL_IC_OFFSET,
26
+ * Note: currently we only support one layer of clustering within
26
sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->ic), 0));
27
+ * each physical package.
28
*/
29
qemu_fdt_add_subnode(ms->fdt, "/cpus/cpu-map");
30
31
@@ -XXX,XX +XXX,XX @@ static void fdt_add_cpu_nodes(const VirtMachineState *vms)
32
33
if (ms->smp.threads > 1) {
34
map_path = g_strdup_printf(
35
- "/cpus/cpu-map/socket%d/cluster0/core%d/thread%d",
36
- cpu / (ms->smp.cores * ms->smp.threads),
37
+ "/cpus/cpu-map/socket%d/cluster%d/core%d/thread%d",
38
+ cpu / (ms->smp.clusters * ms->smp.cores * ms->smp.threads),
39
+ (cpu / (ms->smp.cores * ms->smp.threads)) % ms->smp.clusters,
40
(cpu / ms->smp.threads) % ms->smp.cores,
41
cpu % ms->smp.threads);
42
} else {
43
map_path = g_strdup_printf(
44
- "/cpus/cpu-map/socket%d/cluster0/core%d",
45
- cpu / ms->smp.cores,
46
+ "/cpus/cpu-map/socket%d/cluster%d/core%d",
47
+ cpu / (ms->smp.clusters * ms->smp.cores),
48
+ (cpu / ms->smp.cores) % ms->smp.clusters,
49
cpu % ms->smp.cores);
50
}
51
qemu_fdt_add_path(ms->fdt, map_path);
27
--
52
--
28
2.20.1
53
2.25.1
29
54
30
55
diff view generated by jsdifflib
1
From: Luc Michel <luc@lmichel.fr>
1
From: Yanan Wang <wangyanan55@huawei.com>
2
2
3
This simple mux sits between the PLL channels and the DSI0E and DSI0P
3
Use g_queue APIs to reduce the nested loops and code indentation
4
clock muxes. This mux selects between PLLA-DSI0 and PLLD-DSI0 channel
4
with the processor hierarchy levels increasing. Consenquently,
5
and outputs the selected signal to source number 4 of DSI0E/P clock
5
it's more scalable to add new topology level to build_pptt.
6
muxes. It is controlled by the cm_dsi0hsck register.
7
6
8
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
7
No functional change intended.
9
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
8
10
Signed-off-by: Luc Michel <luc@lmichel.fr>
9
Signed-off-by: Yanan Wang <wangyanan55@huawei.com>
11
Tested-by: Guenter Roeck <linux@roeck-us.net>
10
Reviewed-by: Andrew Jones <drjones@redhat.com>
11
Message-id: 20220107083232.16256-4-wangyanan55@huawei.com
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
---
13
---
14
include/hw/misc/bcm2835_cprman.h | 15 +++++
14
hw/acpi/aml-build.c | 50 +++++++++++++++++++++++++++++----------------
15
include/hw/misc/bcm2835_cprman_internals.h | 6 ++
15
1 file changed, 32 insertions(+), 18 deletions(-)
16
hw/misc/bcm2835_cprman.c | 74 +++++++++++++++++++++-
17
3 files changed, 94 insertions(+), 1 deletion(-)
18
16
19
diff --git a/include/hw/misc/bcm2835_cprman.h b/include/hw/misc/bcm2835_cprman.h
17
diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
20
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
21
--- a/include/hw/misc/bcm2835_cprman.h
19
--- a/hw/acpi/aml-build.c
22
+++ b/include/hw/misc/bcm2835_cprman.h
20
+++ b/hw/acpi/aml-build.c
23
@@ -XXX,XX +XXX,XX @@ typedef struct CprmanClockMuxState {
21
@@ -XXX,XX +XXX,XX @@ static void build_processor_hierarchy_node(GArray *tbl, uint32_t flags,
24
struct CprmanClockMuxState *backref[CPRMAN_NUM_CLOCK_MUX_SRC];
22
void build_pptt(GArray *table_data, BIOSLinker *linker, MachineState *ms,
25
} CprmanClockMuxState;
23
const char *oem_id, const char *oem_table_id)
26
24
{
27
+typedef struct CprmanDsi0HsckMuxState {
25
- int pptt_start = table_data->len;
28
+ /*< private >*/
26
+ GQueue *list = g_queue_new();
29
+ DeviceState parent_obj;
27
+ guint pptt_start = table_data->len;
28
+ guint parent_offset;
29
+ guint length, i;
30
int uid = 0;
31
int socket;
32
AcpiTable table = { .sig = "PPTT", .rev = 2,
33
@@ -XXX,XX +XXX,XX @@ void build_pptt(GArray *table_data, BIOSLinker *linker, MachineState *ms,
34
acpi_table_begin(&table, table_data);
35
36
for (socket = 0; socket < ms->smp.sockets; socket++) {
37
- uint32_t socket_offset = table_data->len - pptt_start;
38
- int core;
39
-
40
+ g_queue_push_tail(list,
41
+ GUINT_TO_POINTER(table_data->len - pptt_start));
42
build_processor_hierarchy_node(
43
table_data,
44
/*
45
@@ -XXX,XX +XXX,XX @@ void build_pptt(GArray *table_data, BIOSLinker *linker, MachineState *ms,
46
*/
47
(1 << 0),
48
0, socket, NULL, 0);
49
+ }
50
51
+ length = g_queue_get_length(list);
52
+ for (i = 0; i < length; i++) {
53
+ int core;
30
+
54
+
31
+ /*< public >*/
55
+ parent_offset = GPOINTER_TO_UINT(g_queue_pop_head(list));
32
+ CprmanClockMux id;
56
for (core = 0; core < ms->smp.cores; core++) {
33
+
57
- uint32_t core_offset = table_data->len - pptt_start;
34
+ uint32_t *reg_cm;
58
- int thread;
35
+
59
-
36
+ Clock *plla_in;
60
if (ms->smp.threads > 1) {
37
+ Clock *plld_in;
61
+ g_queue_push_tail(list,
38
+ Clock *out;
62
+ GUINT_TO_POINTER(table_data->len - pptt_start));
39
+} CprmanDsi0HsckMuxState;
63
build_processor_hierarchy_node(
40
+
64
table_data,
41
struct BCM2835CprmanState {
65
(0 << 0), /* not a physical package */
42
/*< private >*/
66
- socket_offset, core, NULL, 0);
43
SysBusDevice parent_obj;
67
-
44
@@ -XXX,XX +XXX,XX @@ struct BCM2835CprmanState {
68
- for (thread = 0; thread < ms->smp.threads; thread++) {
45
CprmanPllState plls[CPRMAN_NUM_PLL];
69
- build_processor_hierarchy_node(
46
CprmanPllChannelState channels[CPRMAN_NUM_PLL_CHANNEL];
70
- table_data,
47
CprmanClockMuxState clock_muxes[CPRMAN_NUM_CLOCK_MUX];
71
- (1 << 1) | /* ACPI Processor ID valid */
48
+ CprmanDsi0HsckMuxState dsi0hsck_mux;
72
- (1 << 2) | /* Processor is a Thread */
49
73
- (1 << 3), /* Node is a Leaf */
50
uint32_t regs[CPRMAN_NUM_REGS];
74
- core_offset, uid++, NULL, 0);
51
uint32_t xosc_freq;
75
- }
52
diff --git a/include/hw/misc/bcm2835_cprman_internals.h b/include/hw/misc/bcm2835_cprman_internals.h
76
+ parent_offset, core, NULL, 0);
53
index XXXXXXX..XXXXXXX 100644
77
} else {
54
--- a/include/hw/misc/bcm2835_cprman_internals.h
78
build_processor_hierarchy_node(
55
+++ b/include/hw/misc/bcm2835_cprman_internals.h
79
table_data,
56
@@ -XXX,XX +XXX,XX @@
80
(1 << 1) | /* ACPI Processor ID valid */
57
#define TYPE_CPRMAN_PLL "bcm2835-cprman-pll"
81
(1 << 3), /* Node is a Leaf */
58
#define TYPE_CPRMAN_PLL_CHANNEL "bcm2835-cprman-pll-channel"
82
- socket_offset, uid++, NULL, 0);
59
#define TYPE_CPRMAN_CLOCK_MUX "bcm2835-cprman-clock-mux"
83
+ parent_offset, uid++, NULL, 0);
60
+#define TYPE_CPRMAN_DSI0HSCK_MUX "bcm2835-cprman-dsi0hsck-mux"
84
}
61
62
DECLARE_INSTANCE_CHECKER(CprmanPllState, CPRMAN_PLL,
63
TYPE_CPRMAN_PLL)
64
@@ -XXX,XX +XXX,XX @@ DECLARE_INSTANCE_CHECKER(CprmanPllChannelState, CPRMAN_PLL_CHANNEL,
65
TYPE_CPRMAN_PLL_CHANNEL)
66
DECLARE_INSTANCE_CHECKER(CprmanClockMuxState, CPRMAN_CLOCK_MUX,
67
TYPE_CPRMAN_CLOCK_MUX)
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
}
155
}
156
157
@@ -XXX,XX +XXX,XX @@ static void cprman_reset(DeviceState *dev)
158
device_cold_reset(DEVICE(&s->channels[i]));
159
}
160
161
+ device_cold_reset(DEVICE(&s->dsi0hsck_mux));
162
+
163
for (i = 0; i < CPRMAN_NUM_CLOCK_MUX; i++) {
164
device_cold_reset(DEVICE(&s->clock_muxes[i]));
165
}
166
@@ -XXX,XX +XXX,XX @@ static void cprman_init(Object *obj)
167
set_pll_channel_init_info(s, &s->channels[i], i);
168
}
169
170
+ object_initialize_child(obj, "dsi0hsck-mux",
171
+ &s->dsi0hsck_mux, TYPE_CPRMAN_DSI0HSCK_MUX);
172
+ s->dsi0hsck_mux.reg_cm = &s->regs[R_CM_DSI0HSCK];
173
+
174
for (i = 0; i < CPRMAN_NUM_CLOCK_MUX; i++) {
175
char *alias;
176
177
@@ -XXX,XX +XXX,XX @@ static void connect_mux_sources(BCM2835CprmanState *s,
178
if (mapping == CPRMAN_CLOCK_SRC_FORCE_GROUND) {
179
src = s->gnd;
180
} else if (mapping == CPRMAN_CLOCK_SRC_DSI0HSCK) {
181
- src = s->gnd; /* TODO */
182
+ src = s->dsi0hsck_mux.out;
183
} else if (i < CPRMAN_CLOCK_SRC_PLLA) {
184
src = CLK_SRC_MAPPING[i];
185
} else {
186
@@ -XXX,XX +XXX,XX @@ static void cprman_realize(DeviceState *dev, Error **errp)
187
}
85
}
188
}
86
}
189
87
190
+ clock_set_source(s->dsi0hsck_mux.plla_in,
88
+ length = g_queue_get_length(list);
191
+ s->channels[CPRMAN_PLLA_CHANNEL_DSI0].out);
89
+ for (i = 0; i < length; i++) {
192
+ clock_set_source(s->dsi0hsck_mux.plld_in,
90
+ int thread;
193
+ s->channels[CPRMAN_PLLD_CHANNEL_DSI0].out);
194
+
91
+
195
+ if (!qdev_realize(DEVICE(&s->dsi0hsck_mux), NULL, errp)) {
92
+ parent_offset = GPOINTER_TO_UINT(g_queue_pop_head(list));
196
+ return;
93
+ for (thread = 0; thread < ms->smp.threads; thread++) {
94
+ build_processor_hierarchy_node(
95
+ table_data,
96
+ (1 << 1) | /* ACPI Processor ID valid */
97
+ (1 << 2) | /* Processor is a Thread */
98
+ (1 << 3), /* Node is a Leaf */
99
+ parent_offset, uid++, NULL, 0);
100
+ }
197
+ }
101
+ }
198
+
102
+
199
for (i = 0; i < CPRMAN_NUM_CLOCK_MUX; i++) {
103
+ g_queue_free(list);
200
CprmanClockMuxState *clock_mux = &s->clock_muxes[i];
104
acpi_table_end(linker, &table);
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
}
105
}
208
106
209
type_init(cprman_register_types);
210
--
107
--
211
2.20.1
108
2.25.1
212
109
213
110
diff view generated by jsdifflib
1
From: Zenghui Yu <yuzenghui@huawei.com>
1
From: Yanan Wang <wangyanan55@huawei.com>
2
2
3
Ensure the vSMMUv3 will be restored before all PCIe devices so that DMA
3
List test/data/acpi/virt/PPTT as the expected files allowed to
4
translation can work properly during migration.
4
be changed in tests/qtest/bios-tables-test-allowed-diff.h
5
5
6
Signed-off-by: Zenghui Yu <yuzenghui@huawei.com>
6
Signed-off-by: Yanan Wang <wangyanan55@huawei.com>
7
Message-id: 20201019091508.197-1-yuzenghui@huawei.com
7
Acked-by: Ani Sinha <ani@anisinha.ca>
8
Acked-by: Eric Auger <eric.auger@redhat.com>
8
Message-id: 20220107083232.16256-5-wangyanan55@huawei.com
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/smmuv3.c | 1 +
11
tests/qtest/bios-tables-test-allowed-diff.h | 1 +
12
1 file changed, 1 insertion(+)
12
1 file changed, 1 insertion(+)
13
13
14
diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c
14
diff --git a/tests/qtest/bios-tables-test-allowed-diff.h b/tests/qtest/bios-tables-test-allowed-diff.h
15
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
16
--- a/hw/arm/smmuv3.c
16
--- a/tests/qtest/bios-tables-test-allowed-diff.h
17
+++ b/hw/arm/smmuv3.c
17
+++ b/tests/qtest/bios-tables-test-allowed-diff.h
18
@@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_smmuv3 = {
18
@@ -1 +1,2 @@
19
.name = "smmuv3",
19
/* List of comma-separated changed AML files to ignore */
20
.version_id = 1,
20
+"tests/data/acpi/virt/PPTT",
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
--
21
--
27
2.20.1
22
2.25.1
28
23
29
24
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Yanan Wang <wangyanan55@huawei.com>
2
2
3
This is generic support, with the code disabled for all targets.
3
Support CPU cluster topology level in generation of ACPI
4
Processor Properties Topology Table (PPTT).
4
5
5
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
6
Signed-off-by: Yanan Wang <wangyanan55@huawei.com>
6
Message-id: 20201021173749.111103-11-richard.henderson@linaro.org
7
Reviewed-by: Andrew Jones <drjones@redhat.com>
7
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
8
Message-id: 20220107083232.16256-6-wangyanan55@huawei.com
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
---
10
---
10
linux-user/qemu.h | 4 ++
11
hw/acpi/aml-build.c | 18 ++++++++++++++++++
11
linux-user/elfload.c | 157 +++++++++++++++++++++++++++++++++++++++++++
12
1 file changed, 18 insertions(+)
12
2 files changed, 161 insertions(+)
13
13
14
diff --git a/linux-user/qemu.h b/linux-user/qemu.h
14
diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c
15
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
16
--- a/linux-user/qemu.h
16
--- a/hw/acpi/aml-build.c
17
+++ b/linux-user/qemu.h
17
+++ b/hw/acpi/aml-build.c
18
@@ -XXX,XX +XXX,XX @@ struct image_info {
18
@@ -XXX,XX +XXX,XX @@ static void build_processor_hierarchy_node(GArray *tbl, uint32_t flags,
19
abi_ulong interpreter_loadmap_addr;
19
void build_pptt(GArray *table_data, BIOSLinker *linker, MachineState *ms,
20
abi_ulong interpreter_pt_dynamic_addr;
20
const char *oem_id, const char *oem_table_id)
21
struct image_info *other_info;
21
{
22
+ MachineClass *mc = MACHINE_GET_CLASS(ms);
23
GQueue *list = g_queue_new();
24
guint pptt_start = table_data->len;
25
guint parent_offset;
26
@@ -XXX,XX +XXX,XX @@ void build_pptt(GArray *table_data, BIOSLinker *linker, MachineState *ms,
27
0, socket, NULL, 0);
28
}
29
30
+ if (mc->smp_props.clusters_supported) {
31
+ length = g_queue_get_length(list);
32
+ for (i = 0; i < length; i++) {
33
+ int cluster;
22
+
34
+
23
+ /* For target-specific processing of NT_GNU_PROPERTY_TYPE_0. */
35
+ parent_offset = GPOINTER_TO_UINT(g_queue_pop_head(list));
24
+ uint32_t note_flags;
36
+ for (cluster = 0; cluster < ms->smp.clusters; cluster++) {
25
+
37
+ g_queue_push_tail(list,
26
#ifdef TARGET_MIPS
38
+ GUINT_TO_POINTER(table_data->len - pptt_start));
27
int fp_abi;
39
+ build_processor_hierarchy_node(
28
int interp_fp_abi;
40
+ table_data,
29
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
41
+ (0 << 0), /* not a physical package */
30
index XXXXXXX..XXXXXXX 100644
42
+ parent_offset, cluster, NULL, 0);
31
--- a/linux-user/elfload.c
43
+ }
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
{
48
unsigned int a_info; /* Use macros N_MAGIC, etc for access */
49
@@ -XXX,XX +XXX,XX @@ void probe_guest_base(const char *image_name, abi_ulong guest_loaddr,
50
"@ 0x%" PRIx64 "\n", (uint64_t)guest_base);
51
}
52
53
+enum {
54
+ /* The string "GNU\0" as a magic number. */
55
+ GNU0_MAGIC = const_le32('G' | 'N' << 8 | 'U' << 16),
56
+ NOTE_DATA_SZ = 1 * KiB,
57
+ NOTE_NAME_SZ = 4,
58
+ ELF_GNU_PROPERTY_ALIGN = ELF_CLASS == ELFCLASS32 ? 4 : 8,
59
+};
60
+
61
+/*
62
+ * Process a single gnu_property entry.
63
+ * Return false for error.
64
+ */
65
+static bool parse_elf_property(const uint32_t *data, int *off, int datasz,
66
+ struct image_info *info, bool have_prev_type,
67
+ uint32_t *prev_type, Error **errp)
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
+ }
44
+ }
152
+ }
45
+ }
153
+
46
+
154
+ /*
47
length = g_queue_get_length(list);
155
+ * The contents of a valid PT_GNU_PROPERTY is a sequence
48
for (i = 0; i < length; i++) {
156
+ * of uint32_t -- swap them all now.
49
int core;
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
211
--
50
--
212
2.20.1
51
2.25.1
213
52
214
53
diff view generated by jsdifflib
1
From: Luc Michel <luc@lmichel.fr>
1
From: Yanan Wang <wangyanan55@huawei.com>
2
2
3
Add a clock input to the PL011 UART so we can compute the current baud
3
Run ./tests/data/acpi/rebuild-expected-aml.sh from build directory
4
rate and trace it. This is intended for developers who wish to use QEMU
4
to update PPTT binary. Also empty bios-tables-test-allowed-diff.h.
5
to e.g. debug their firmware or to figure out the baud rate configured
6
by an unknown/closed source binary.
7
5
8
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
6
The disassembled differences between actual and expected PPTT:
9
Signed-off-by: Luc Michel <luc@lmichel.fr>
7
10
Tested-by: Guenter Roeck <linux@roeck-us.net>
8
/*
11
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
9
* Intel ACPI Component Architecture
10
* AML/ASL+ Disassembler version 20200528 (64-bit version)
11
* Copyright (c) 2000 - 2020 Intel Corporation
12
*
13
- * Disassembly of tests/data/acpi/virt/PPTT, Tue Jan 4 12:51:11 2022
14
+ * Disassembly of /tmp/aml-2ZGOF1, Tue Jan 4 12:51:11 2022
15
*
16
* ACPI Data Table [PPTT]
17
*
18
* Format: [HexOffset DecimalOffset ByteLength] FieldName : FieldValue
19
*/
20
21
[000h 0000 4] Signature : "PPTT" [Processor Properties Topology Table]
22
-[004h 0004 4] Table Length : 0000004C
23
+[004h 0004 4] Table Length : 00000060
24
[008h 0008 1] Revision : 02
25
-[009h 0009 1] Checksum : A8
26
+[009h 0009 1] Checksum : 48
27
[00Ah 0010 6] Oem ID : "BOCHS "
28
[010h 0016 8] Oem Table ID : "BXPC "
29
[018h 0024 4] Oem Revision : 00000001
30
[01Ch 0028 4] Asl Compiler ID : "BXPC"
31
[020h 0032 4] Asl Compiler Revision : 00000001
32
33
[024h 0036 1] Subtable Type : 00 [Processor Hierarchy Node]
34
[025h 0037 1] Length : 14
35
[026h 0038 2] Reserved : 0000
36
[028h 0040 4] Flags (decoded below) : 00000001
37
Physical package : 1
38
ACPI Processor ID valid : 0
39
Processor is a thread : 0
40
Node is a leaf : 0
41
Identical Implementation : 0
42
[02Ch 0044 4] Parent : 00000000
43
[030h 0048 4] ACPI Processor ID : 00000000
44
[034h 0052 4] Private Resource Number : 00000000
45
46
[038h 0056 1] Subtable Type : 00 [Processor Hierarchy Node]
47
[039h 0057 1] Length : 14
48
[03Ah 0058 2] Reserved : 0000
49
-[03Ch 0060 4] Flags (decoded below) : 0000000A
50
+[03Ch 0060 4] Flags (decoded below) : 00000000
51
Physical package : 0
52
- ACPI Processor ID valid : 1
53
+ ACPI Processor ID valid : 0
54
Processor is a thread : 0
55
- Node is a leaf : 1
56
+ Node is a leaf : 0
57
Identical Implementation : 0
58
[040h 0064 4] Parent : 00000024
59
[044h 0068 4] ACPI Processor ID : 00000000
60
[048h 0072 4] Private Resource Number : 00000000
61
62
-Raw Table Data: Length 76 (0x4C)
63
+[04Ch 0076 1] Subtable Type : 00 [Processor Hierarchy Node]
64
+[04Dh 0077 1] Length : 14
65
+[04Eh 0078 2] Reserved : 0000
66
+[050h 0080 4] Flags (decoded below) : 0000000A
67
+ Physical package : 0
68
+ ACPI Processor ID valid : 1
69
+ Processor is a thread : 0
70
+ Node is a leaf : 1
71
+ Identical Implementation : 0
72
+[054h 0084 4] Parent : 00000038
73
+[058h 0088 4] ACPI Processor ID : 00000000
74
+[05Ch 0092 4] Private Resource Number : 00000000
75
+
76
+Raw Table Data: Length 96 (0x60)
77
78
- 0000: 50 50 54 54 4C 00 00 00 02 A8 42 4F 43 48 53 20 // PPTTL.....BOCHS
79
+ 0000: 50 50 54 54 60 00 00 00 02 48 42 4F 43 48 53 20 // PPTT`....HBOCHS
80
0010: 42 58 50 43 20 20 20 20 01 00 00 00 42 58 50 43 // BXPC ....BXPC
81
0020: 01 00 00 00 00 14 00 00 01 00 00 00 00 00 00 00 // ................
82
- 0030: 00 00 00 00 00 00 00 00 00 14 00 00 0A 00 00 00 // ................
83
- 0040: 24 00 00 00 00 00 00 00 00 00 00 00 // $...........
84
+ 0030: 00 00 00 00 00 00 00 00 00 14 00 00 00 00 00 00 // ................
85
+ 0040: 24 00 00 00 00 00 00 00 00 00 00 00 00 14 00 00 // $...............
86
+ 0050: 0A 00 00 00 38 00 00 00 00 00 00 00 00 00 00 00 // ....8...........
87
88
Signed-off-by: Yanan Wang <wangyanan55@huawei.com>
89
Reviewed-by: Ani Sinha <ani@anisinha.ca>
90
Message-id: 20220107083232.16256-7-wangyanan55@huawei.com
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
91
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
---
92
---
14
include/hw/char/pl011.h | 1 +
93
tests/qtest/bios-tables-test-allowed-diff.h | 1 -
15
hw/char/pl011.c | 45 +++++++++++++++++++++++++++++++++++++++++
94
tests/data/acpi/virt/PPTT | Bin 76 -> 96 bytes
16
hw/char/trace-events | 1 +
95
2 files changed, 1 deletion(-)
17
3 files changed, 47 insertions(+)
18
96
19
diff --git a/include/hw/char/pl011.h b/include/hw/char/pl011.h
97
diff --git a/tests/qtest/bios-tables-test-allowed-diff.h b/tests/qtest/bios-tables-test-allowed-diff.h
20
index XXXXXXX..XXXXXXX 100644
98
index XXXXXXX..XXXXXXX 100644
21
--- a/include/hw/char/pl011.h
99
--- a/tests/qtest/bios-tables-test-allowed-diff.h
22
+++ b/include/hw/char/pl011.h
100
+++ b/tests/qtest/bios-tables-test-allowed-diff.h
23
@@ -XXX,XX +XXX,XX @@ struct PL011State {
101
@@ -1,2 +1 @@
24
int read_trigger;
102
/* List of comma-separated changed AML files to ignore */
25
CharBackend chr;
103
-"tests/data/acpi/virt/PPTT",
26
qemu_irq irq[6];
104
diff --git a/tests/data/acpi/virt/PPTT b/tests/data/acpi/virt/PPTT
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
105
index XXXXXXX..XXXXXXX 100644
33
--- a/hw/char/pl011.c
106
GIT binary patch
34
+++ b/hw/char/pl011.c
107
delta 53
35
@@ -XXX,XX +XXX,XX @@
108
pcmeZC;0g!`2}xjJU|{l?$YrDgWH5jU5Ca567#O&Klm(arApowi1QY-O
36
#include "hw/char/pl011.h"
109
37
#include "hw/irq.h"
110
delta 32
38
#include "hw/sysbus.h"
111
fcmYfB;R*-{3GrcIU|?D?k;`ae01J-_kOKn%ZFdCM
39
+#include "hw/qdev-clock.h"
112
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
}
46
47
+static unsigned int pl011_get_baudrate(const PL011State *s)
48
+{
49
+ uint64_t clk;
50
+
51
+ if (s->fbrd == 0) {
52
+ return 0;
53
+ }
54
+
55
+ clk = clock_get_hz(s->clk);
56
+ return (clk / ((s->ibrd << 6) + s->fbrd)) << 2;
57
+}
58
+
59
+static void pl011_trace_baudrate_change(const PL011State *s)
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
{
69
@@ -XXX,XX +XXX,XX @@ static void pl011_write(void *opaque, hwaddr offset,
70
break;
71
case 9: /* UARTIBRD */
72
s->ibrd = value;
73
+ pl011_trace_baudrate_change(s);
74
break;
75
case 10: /* UARTFBRD */
76
s->fbrd = value;
77
+ pl011_trace_baudrate_change(s);
78
break;
79
case 11: /* UARTLCR_H */
80
/* Reset the FIFO state on FIFO enable or disable */
81
@@ -XXX,XX +XXX,XX @@ static void pl011_event(void *opaque, QEMUChrEvent event)
82
pl011_put_fifo(opaque, 0x400);
83
}
84
85
+static void pl011_clock_update(void *opaque)
86
+{
87
+ PL011State *s = PL011(opaque);
88
+
89
+ pl011_trace_baudrate_change(s);
90
+}
91
+
92
static const MemoryRegionOps pl011_ops = {
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
--
113
--
144
2.20.1
114
2.25.1
145
115
146
116
diff view generated by jsdifflib
1
From: Luc Michel <luc@lmichel.fr>
1
From: Lucas Ramage <lucas.ramage@infinite-omicron.com>
2
2
3
A clock mux can be configured to select one of its 10 sources through
3
Buglink: https://gitlab.com/qemu-project/qemu/-/issues/527
4
the CM_CTL register. It also embeds yet another clock divider, composed
4
Signed-off-by: Lucas Ramage <lucas.ramage@infinite-omicron.com>
5
of an integer part and a fractional part. The number of bits of each
5
Message-id: 20220105205628.5491-1-oxr463@gmx.us
6
part is mux dependent.
6
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
7
7
[PMM: Move to docs/system/devices/ rather than top-level;
8
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
8
fix a pre-existing typo in passing]
9
Signed-off-by: Luc Michel <luc@lmichel.fr>
10
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
11
Tested-by: Guenter Roeck <linux@roeck-us.net>
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
---
10
---
14
hw/misc/bcm2835_cprman.c | 53 +++++++++++++++++++++++++++++++++++++++-
11
docs/system/device-emulation.rst | 1 +
15
1 file changed, 52 insertions(+), 1 deletion(-)
12
docs/{can.txt => system/devices/can.rst} | 90 +++++++++++-------------
16
13
2 files changed, 41 insertions(+), 50 deletions(-)
17
diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c
14
rename docs/{can.txt => system/devices/can.rst} (68%)
15
16
diff --git a/docs/system/device-emulation.rst b/docs/system/device-emulation.rst
18
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
19
--- a/hw/misc/bcm2835_cprman.c
18
--- a/docs/system/device-emulation.rst
20
+++ b/hw/misc/bcm2835_cprman.c
19
+++ b/docs/system/device-emulation.rst
21
@@ -XXX,XX +XXX,XX @@ static const TypeInfo cprman_pll_channel_info = {
20
@@ -XXX,XX +XXX,XX @@ Emulated Devices
22
21
.. toctree::
23
/* clock mux */
22
:maxdepth: 1
24
23
25
+static bool clock_mux_is_enabled(CprmanClockMuxState *mux)
24
+ devices/can.rst
26
+{
25
devices/ivshmem.rst
27
+ return FIELD_EX32(*mux->reg_ctl, CM_CLOCKx_CTL, ENABLE);
26
devices/net.rst
28
+}
27
devices/nvme.rst
29
+
28
diff --git a/docs/can.txt b/docs/system/devices/can.rst
30
static void clock_mux_update(CprmanClockMuxState *mux)
29
similarity index 68%
31
{
30
rename from docs/can.txt
32
- clock_update(mux->out, 0);
31
rename to docs/system/devices/can.rst
33
+ uint64_t freq;
32
index XXXXXXX..XXXXXXX 100644
34
+ uint32_t div, src = FIELD_EX32(*mux->reg_ctl, CM_CLOCKx_CTL, SRC);
33
--- a/docs/can.txt
35
+ bool enabled = clock_mux_is_enabled(mux);
34
+++ b/docs/system/devices/can.rst
36
+
35
@@ -XXX,XX +XXX,XX @@
37
+ *mux->reg_ctl = FIELD_DP32(*mux->reg_ctl, CM_CLOCKx_CTL, BUSY, enabled);
36
-QEMU CAN bus emulation support
38
+
37
-==============================
39
+ if (!enabled) {
38
-
40
+ clock_update(mux->out, 0);
39
+CAN Bus Emulation Support
41
+ return;
40
+=========================
42
+ }
41
The CAN bus emulation provides mechanism to connect multiple
43
+
42
emulated CAN controller chips together by one or multiple CAN busses
44
+ freq = clock_get_hz(mux->srcs[src]);
43
(the controller device "canbus" parameter). The individual busses
45
+
44
@@ -XXX,XX +XXX,XX @@ emulated environment for testing and RTEMS GSoC slot has been donated
46
+ if (mux->int_bits == 0 && mux->frac_bits == 0) {
45
to work on CAN hardware emulation on QEMU.
47
+ clock_update_hz(mux->out, freq);
46
48
+ return;
47
Examples how to use CAN emulation for SJA1000 based boards
49
+ }
48
-==========================================================
50
+
49
-
51
+ /*
50
+----------------------------------------------------------
52
+ * The divider has an integer and a fractional part. The size of each part
51
When QEMU with CAN PCI support is compiled then one of the next
53
+ * varies with the muxes (int_bits and frac_bits). Both parts are
52
CAN boards can be selected
54
+ * concatenated, with the integer part always starting at bit 12.
53
55
+ *
54
- (1) CAN bus Kvaser PCI CAN-S (single SJA1000 channel) boad. QEMU startup options
56
+ * 31 12 11 0
55
+(1) CAN bus Kvaser PCI CAN-S (single SJA1000 channel) board. QEMU startup options::
57
+ * ------------------------------
56
+
58
+ * CM_DIV | | int | frac | |
57
-object can-bus,id=canbus0
59
+ * ------------------------------
58
-device kvaser_pci,canbus=canbus0
60
+ * <-----> <------>
59
- Add "can-host-socketcan" object to connect device to host system CAN bus
61
+ * int_bits frac_bits
60
+
62
+ */
61
+Add "can-host-socketcan" object to connect device to host system CAN bus::
63
+ div = extract32(*mux->reg_div,
62
+
64
+ R_CM_CLOCKx_DIV_FRAC_LENGTH - mux->frac_bits,
63
-object can-host-socketcan,id=canhost0,if=can0,canbus=canbus0
65
+ mux->int_bits + mux->frac_bits);
64
66
+
65
- (2) CAN bus PCM-3680I PCI (dual SJA1000 channel) emulation
67
+ if (!div) {
66
+(2) CAN bus PCM-3680I PCI (dual SJA1000 channel) emulation::
68
+ clock_update(mux->out, 0);
67
+
69
+ return;
68
-object can-bus,id=canbus0
70
+ }
69
-device pcm3680_pci,canbus0=canbus0,canbus1=canbus0
71
+
70
72
+ freq = muldiv64(freq, 1 << mux->frac_bits, div);
71
- another example:
73
+
72
+Another example::
74
+ clock_update_hz(mux->out, freq);
73
+
75
}
74
-object can-bus,id=canbus0
76
75
-object can-bus,id=canbus1
77
static void clock_mux_src_update(void *opaque)
76
-device pcm3680_pci,canbus0=canbus0,canbus1=canbus1
78
{
77
79
CprmanClockMuxState **backref = opaque;
78
- (3) CAN bus MIOe-3680 PCI (dual SJA1000 channel) emulation
80
CprmanClockMuxState *s = *backref;
79
+(3) CAN bus MIOe-3680 PCI (dual SJA1000 channel) emulation::
81
+ CprmanClockMuxSource src = backref - s->backref;
80
+
82
+
81
-device mioe3680_pci,canbus0=canbus0
83
+ if (FIELD_EX32(*s->reg_ctl, CM_CLOCKx_CTL, SRC) != src) {
82
84
+ return;
83
-
85
+ }
84
The ''kvaser_pci'' board/device model is compatible with and has been tested with
86
85
-''kvaser_pci'' driver included in mainline Linux kernel.
87
clock_mux_update(s);
86
+the ''kvaser_pci'' driver included in mainline Linux kernel.
88
}
87
The tested setup was Linux 4.9 kernel on the host and guest side.
88
-Example for qemu-system-x86_64:
89
+
90
+Example for qemu-system-x86_64::
91
92
qemu-system-x86_64 -accel kvm -kernel /boot/vmlinuz-4.9.0-4-amd64 \
93
-initrd ramdisk.cpio \
94
@@ -XXX,XX +XXX,XX @@ Example for qemu-system-x86_64:
95
-device kvaser_pci,canbus=canbus0 \
96
-nographic -append "console=ttyS0"
97
98
-Example for qemu-system-arm:
99
+Example for qemu-system-arm::
100
101
qemu-system-arm -cpu arm1176 -m 256 -M versatilepb \
102
-kernel kernel-qemu-arm1176-versatilepb \
103
@@ -XXX,XX +XXX,XX @@ Example for qemu-system-arm:
104
The CAN interface of the host system has to be configured for proper
105
bitrate and set up. Configuration is not propagated from emulated
106
devices through bus to the physical host device. Example configuration
107
-for 1 Mbit/s
108
+for 1 Mbit/s::
109
110
ip link set can0 type can bitrate 1000000
111
ip link set can0 up
112
113
Virtual (host local only) can interface can be used on the host
114
-side instead of physical interface
115
+side instead of physical interface::
116
117
ip link add dev can0 type vcan
118
119
The CAN interface on the host side can be used to analyze CAN
120
-traffic with "candump" command which is included in "can-utils".
121
+traffic with "candump" command which is included in "can-utils"::
122
123
candump can0
124
125
CTU CAN FD support examples
126
-===========================
127
-
128
+---------------------------
129
This open-source core provides CAN FD support. CAN FD drames are
130
delivered even to the host systems when SocketCAN interface is found
131
CAN FD capable.
132
@@ -XXX,XX +XXX,XX @@ on the board.
133
Example how to connect the canbus0-bus (virtual wire) to the host
134
Linux system (SocketCAN used) and to both CTU CAN FD cores emulated
135
on the corresponding PCI card expects that host system CAN bus
136
-is setup according to the previous SJA1000 section.
137
+is setup according to the previous SJA1000 section::
138
139
qemu-system-x86_64 -enable-kvm -kernel /boot/vmlinuz-4.19.52+ \
140
-initrd ramdisk.cpio \
141
@@ -XXX,XX +XXX,XX @@ is setup according to the previous SJA1000 section.
142
-device ctucan_pci,canbus0=canbus0-bus,canbus1=canbus0-bus \
143
-nographic
144
145
-Setup of CTU CAN FD controller in a guest Linux system
146
+Setup of CTU CAN FD controller in a guest Linux system::
147
148
insmod ctucanfd.ko || modprobe ctucanfd
149
insmod ctucanfd_pci.ko || modprobe ctucanfd_pci
150
@@ -XXX,XX +XXX,XX @@ Setup of CTU CAN FD controller in a guest Linux system
151
/bin/ip link set $ifc up
152
done
153
154
-The test can run for example
155
+The test can run for example::
156
157
candump can1
158
159
-in the guest system and next commands in the host system for basic CAN
160
+in the guest system and next commands in the host system for basic CAN::
161
162
cangen can0
163
164
-for CAN FD without bitrate switch
165
+for CAN FD without bitrate switch::
166
167
cangen can0 -f
168
169
-and with bitrate switch
170
+and with bitrate switch::
171
172
cangen can0 -b
173
174
@@ -XXX,XX +XXX,XX @@ The test can be run viceversa, generate messages in the guest system and capture
175
in the host one and much more combinations.
176
177
Links to other resources
178
-========================
179
+------------------------
180
181
- (1) CAN related projects at Czech Technical University, Faculty of Electrical Engineering
182
- http://canbus.pages.fel.cvut.cz/
183
- (2) Repository with development can-pci branch at Czech Technical University
184
- https://gitlab.fel.cvut.cz/canbus/qemu-canbus
185
- (3) RTEMS page describing project
186
- https://devel.rtems.org/wiki/Developer/Simulators/QEMU/CANEmulation
187
- (4) RTLWS 2015 article about the project and its use with CANopen emulation
188
- http://cmp.felk.cvut.cz/~pisa/can/doc/rtlws-17-pisa-qemu-can.pdf
189
- (5) GNU/Linux, CAN and CANopen in Real-time Control Applications
190
- Slides from LinuxDays 2017 (include updated RTLWS 2015 content)
191
- https://www.linuxdays.cz/2017/video/Pavel_Pisa-CAN_canopen.pdf
192
- (6) Linux SocketCAN utilities
193
- https://github.com/linux-can/can-utils/
194
- (7) CTU CAN FD project including core VHDL design, Linux driver,
195
- test utilities etc.
196
- https://gitlab.fel.cvut.cz/canbus/ctucanfd_ip_core
197
- (8) CTU CAN FD Core Datasheet Documentation
198
- http://canbus.pages.fel.cvut.cz/ctucanfd_ip_core/Progdokum.pdf
199
- (9) CTU CAN FD Core System Architecture Documentation
200
- http://canbus.pages.fel.cvut.cz/ctucanfd_ip_core/ctu_can_fd_architecture.pdf
201
- (10) CTU CAN FD Driver Documentation
202
- http://canbus.pages.fel.cvut.cz/ctucanfd_ip_core/driver_doc/ctucanfd-driver.html
203
- (11) Integration with PCIe interfacing for Intel/Altera Cyclone IV based board
204
- https://gitlab.fel.cvut.cz/canbus/pcie-ctu_can_fd
205
+ (1) `CAN related projects at Czech Technical University, Faculty of Electrical Engineering <http://canbus.pages.fel.cvut.cz>`_
206
+ (2) `Repository with development can-pci branch at Czech Technical University <https://gitlab.fel.cvut.cz/canbus/qemu-canbus>`_
207
+ (3) `RTEMS page describing project <https://devel.rtems.org/wiki/Developer/Simulators/QEMU/CANEmulation>`_
208
+ (4) `RTLWS 2015 article about the project and its use with CANopen emulation <http://cmp.felk.cvut.cz/~pisa/can/doc/rtlws-17-pisa-qemu-can.pdf>`_
209
+ (5) `GNU/Linux, CAN and CANopen in Real-time Control Applications Slides from LinuxDays 2017 (include updated RTLWS 2015 content) <https://www.linuxdays.cz/2017/video/Pavel_Pisa-CAN_canopen.pdf>`_
210
+ (6) `Linux SocketCAN utilities <https://github.com/linux-can/can-utils>`_
211
+ (7) `CTU CAN FD project including core VHDL design, Linux driver, test utilities etc. <https://gitlab.fel.cvut.cz/canbus/ctucanfd_ip_core>`_
212
+ (8) `CTU CAN FD Core Datasheet Documentation <http://canbus.pages.fel.cvut.cz/ctucanfd_ip_core/Progdokum.pdf>`_
213
+ (9) `CTU CAN FD Core System Architecture Documentation <http://canbus.pages.fel.cvut.cz/ctucanfd_ip_core/ctu_can_fd_architecture.pdf>`_
214
+ (10) `CTU CAN FD Driver Documentation <http://canbus.pages.fel.cvut.cz/ctucanfd_ip_core/driver_doc/ctucanfd-driver.html>`_
215
+ (11) `Integration with PCIe interfacing for Intel/Altera Cyclone IV based board <https://gitlab.fel.cvut.cz/canbus/pcie-ctu_can_fd>`_
89
--
216
--
90
2.20.1
217
2.25.1
91
218
92
219
diff view generated by jsdifflib
1
From: Luc Michel <luc@lmichel.fr>
1
From: Gavin Shan <gshan@redhat.com>
2
2
3
The CPRMAN PLLs generate a clock based on a prescaler, a multiplier and
3
The default block size is same as to the THP size, which is either
4
a divider. The prescaler doubles the parent (xosc) frequency, then the
4
retrieved from "/sys/kernel/mm/transparent_hugepage/hpage_pmd_size"
5
multiplier/divider are applied. The multiplier has an integer and a
5
or hardcoded to 2MB. There are flaws in both mechanisms and this
6
fractional part.
6
intends to fix them up.
7
7
8
This commit also implements the CPRMAN CM_LOCK register. This register
8
* When "/sys/kernel/mm/transparent_hugepage/hpage_pmd_size" is
9
reports which PLL is currently locked. We consider a PLL has being
9
used to getting the THP size, 32MB and 512MB are valid values
10
locked as soon as it is enabled (on real hardware, there is a delay
10
when we have 16KB and 64KB page size on ARM64.
11
after turning a PLL on, for it to stabilize).
12
11
13
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
12
* When the hardcoded THP size is used, 2MB, 32MB and 512MB are
14
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
13
valid values when we have 4KB, 16KB and 64KB page sizes on
15
Signed-off-by: Luc Michel <luc@lmichel.fr>
14
ARM64.
16
Tested-by: Guenter Roeck <linux@roeck-us.net>
15
16
Co-developed-by: David Hildenbrand <david@redhat.com>
17
Signed-off-by: Gavin Shan <gshan@redhat.com>
18
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
19
Reviewed-by: David Hildenbrand <david@redhat.com>
20
Message-id: 20220111063329.74447-2-gshan@redhat.com
17
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
21
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
18
---
22
---
19
include/hw/misc/bcm2835_cprman_internals.h | 8 +++
23
hw/virtio/virtio-mem.c | 32 ++++++++++++++++++++------------
20
hw/misc/bcm2835_cprman.c | 64 +++++++++++++++++++++-
24
1 file changed, 20 insertions(+), 12 deletions(-)
21
2 files changed, 71 insertions(+), 1 deletion(-)
22
25
23
diff --git a/include/hw/misc/bcm2835_cprman_internals.h b/include/hw/misc/bcm2835_cprman_internals.h
26
diff --git a/hw/virtio/virtio-mem.c b/hw/virtio/virtio-mem.c
24
index XXXXXXX..XXXXXXX 100644
27
index XXXXXXX..XXXXXXX 100644
25
--- a/include/hw/misc/bcm2835_cprman_internals.h
28
--- a/hw/virtio/virtio-mem.c
26
+++ b/include/hw/misc/bcm2835_cprman_internals.h
29
+++ b/hw/virtio/virtio-mem.c
27
@@ -XXX,XX +XXX,XX @@ REG32(A2W_PLLD_FRAC, 0x1240)
30
@@ -XXX,XX +XXX,XX @@
28
REG32(A2W_PLLH_FRAC, 0x1260)
31
*/
29
REG32(A2W_PLLB_FRAC, 0x12e0)
32
#define VIRTIO_MEM_MIN_BLOCK_SIZE ((uint32_t)(1 * MiB))
30
33
31
+/* misc registers */
34
-#if defined(__x86_64__) || defined(__arm__) || defined(__aarch64__) || \
32
+REG32(CM_LOCK, 0x114)
35
- defined(__powerpc64__)
33
+ FIELD(CM_LOCK, FLOCKH, 12, 1)
36
-#define VIRTIO_MEM_DEFAULT_THP_SIZE ((uint32_t)(2 * MiB))
34
+ FIELD(CM_LOCK, FLOCKD, 11, 1)
37
-#else
35
+ FIELD(CM_LOCK, FLOCKC, 10, 1)
38
- /* fallback to 1 MiB (e.g., the THP size on s390x) */
36
+ FIELD(CM_LOCK, FLOCKB, 9, 1)
39
-#define VIRTIO_MEM_DEFAULT_THP_SIZE VIRTIO_MEM_MIN_BLOCK_SIZE
37
+ FIELD(CM_LOCK, FLOCKA, 8, 1)
40
+static uint32_t virtio_mem_default_thp_size(void)
41
+{
42
+ uint32_t default_thp_size = VIRTIO_MEM_MIN_BLOCK_SIZE;
43
+
44
+#if defined(__x86_64__) || defined(__arm__) || defined(__powerpc64__)
45
+ default_thp_size = 2 * MiB;
46
+#elif defined(__aarch64__)
47
+ if (qemu_real_host_page_size == 4 * KiB) {
48
+ default_thp_size = 2 * MiB;
49
+ } else if (qemu_real_host_page_size == 16 * KiB) {
50
+ default_thp_size = 32 * MiB;
51
+ } else if (qemu_real_host_page_size == 64 * KiB) {
52
+ default_thp_size = 512 * MiB;
53
+ }
54
#endif
55
56
+ return default_thp_size;
57
+}
38
+
58
+
39
/*
59
/*
40
* This field is common to all registers. Each register write value must match
60
* We want to have a reasonable default block size such that
41
* the CPRMAN_PASSWORD magic value in its 8 MSB.
61
* 1. We avoid splitting THPs when unplugging memory, which degrades
42
diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c
62
@@ -XXX,XX +XXX,XX @@ static uint32_t virtio_mem_thp_size(void)
43
index XXXXXXX..XXXXXXX 100644
63
if (g_file_get_contents(HPAGE_PMD_SIZE_PATH, &content, NULL, NULL) &&
44
--- a/hw/misc/bcm2835_cprman.c
64
!qemu_strtou64(content, &endptr, 0, &tmp) &&
45
+++ b/hw/misc/bcm2835_cprman.c
65
(!endptr || *endptr == '\n')) {
46
@@ -XXX,XX +XXX,XX @@
66
- /*
47
67
- * Sanity-check the value, if it's too big (e.g., aarch64 with 64k base
48
/* PLL */
68
- * pages) or weird, fallback to something smaller.
49
69
- */
50
+static bool pll_is_locked(const CprmanPllState *pll)
70
- if (!tmp || !is_power_of_2(tmp) || tmp > 16 * MiB) {
51
+{
71
+ /* Sanity-check the value and fallback to something reasonable. */
52
+ return !FIELD_EX32(*pll->reg_a2w_ctrl, A2W_PLLx_CTRL, PWRDN)
72
+ if (!tmp || !is_power_of_2(tmp)) {
53
+ && !FIELD_EX32(*pll->reg_cm, CM_PLLx, ANARST);
73
warn_report("Read unsupported THP size: %" PRIx64, tmp);
54
+}
74
} else {
55
+
75
thp_size = tmp;
56
static void pll_update(CprmanPllState *pll)
76
@@ -XXX,XX +XXX,XX @@ static uint32_t virtio_mem_thp_size(void)
57
{
77
}
58
- clock_update(pll->out, 0);
78
59
+ uint64_t freq, ndiv, fdiv, pdiv;
79
if (!thp_size) {
60
+
80
- thp_size = VIRTIO_MEM_DEFAULT_THP_SIZE;
61
+ if (!pll_is_locked(pll)) {
81
+ thp_size = virtio_mem_default_thp_size();
62
+ clock_update(pll->out, 0);
82
warn_report("Could not detect THP size, falling back to %" PRIx64
63
+ return;
83
" MiB.", thp_size / MiB);
64
+ }
65
+
66
+ pdiv = FIELD_EX32(*pll->reg_a2w_ctrl, A2W_PLLx_CTRL, PDIV);
67
+
68
+ if (!pdiv) {
69
+ clock_update(pll->out, 0);
70
+ return;
71
+ }
72
+
73
+ ndiv = FIELD_EX32(*pll->reg_a2w_ctrl, A2W_PLLx_CTRL, NDIV);
74
+ fdiv = FIELD_EX32(*pll->reg_a2w_frac, A2W_PLLx_FRAC, FRAC);
75
+
76
+ if (pll->reg_a2w_ana[1] & pll->prediv_mask) {
77
+ /* The prescaler doubles the parent frequency */
78
+ ndiv *= 2;
79
+ fdiv *= 2;
80
+ }
81
+
82
+ /*
83
+ * We have a multiplier with an integer part (ndiv) and a fractional part
84
+ * (fdiv), and a divider (pdiv).
85
+ */
86
+ freq = clock_get_hz(pll->xosc_in) *
87
+ ((ndiv << R_A2W_PLLx_FRAC_FRAC_LENGTH) + fdiv);
88
+ freq /= pdiv;
89
+ freq >>= R_A2W_PLLx_FRAC_FRAC_LENGTH;
90
+
91
+ clock_update_hz(pll->out, freq);
92
}
93
94
static void pll_xosc_update(void *opaque)
95
@@ -XXX,XX +XXX,XX @@ static const TypeInfo cprman_pll_info = {
96
97
/* CPRMAN "top level" model */
98
99
+static uint32_t get_cm_lock(const BCM2835CprmanState *s)
100
+{
101
+ static const int CM_LOCK_MAPPING[CPRMAN_NUM_PLL] = {
102
+ [CPRMAN_PLLA] = R_CM_LOCK_FLOCKA_SHIFT,
103
+ [CPRMAN_PLLC] = R_CM_LOCK_FLOCKC_SHIFT,
104
+ [CPRMAN_PLLD] = R_CM_LOCK_FLOCKD_SHIFT,
105
+ [CPRMAN_PLLH] = R_CM_LOCK_FLOCKH_SHIFT,
106
+ [CPRMAN_PLLB] = R_CM_LOCK_FLOCKB_SHIFT,
107
+ };
108
+
109
+ uint32_t r = 0;
110
+ size_t i;
111
+
112
+ for (i = 0; i < CPRMAN_NUM_PLL; i++) {
113
+ r |= pll_is_locked(&s->plls[i]) << CM_LOCK_MAPPING[i];
114
+ }
115
+
116
+ return r;
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
}
84
}
133
--
85
--
134
2.20.1
86
2.25.1
135
87
136
88
diff view generated by jsdifflib
1
From: Shashi Mallela <shashi.mallela@linaro.org>
1
From: Gavin Shan <gshan@redhat.com>
2
2
3
Generic watchdog device model implementation as per ARM SBSA v6.0
3
This supports virtio-mem-pci device on "virt" platform, by simply
4
following the implementation on x86.
4
5
5
Signed-off-by: Shashi Mallela <shashi.mallela@linaro.org>
6
* This implements the hotplug handlers to support virtio-mem-pci
6
Message-id: 20201027015927.29495-2-shashi.mallela@linaro.org
7
device hot-add, while the hot-remove isn't supported as we have
7
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
8
on x86.
9
10
* The block size is 512MB on ARM64 instead of 128MB on x86.
11
12
* It has been passing the tests with various combinations like 64KB
13
and 4KB page sizes on host and guest, different memory device
14
backends like normal, transparent huge page and HugeTLB, plus
15
migration.
16
17
Co-developed-by: David Hildenbrand <david@redhat.com>
18
Co-developed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
19
Signed-off-by: Gavin Shan <gshan@redhat.com>
20
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
21
Reviewed-by: David Hildenbrand <david@redhat.com>
22
Message-id: 20220111063329.74447-3-gshan@redhat.com
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
23
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
---
24
---
10
include/hw/watchdog/sbsa_gwdt.h | 79 +++++++++
25
hw/arm/virt.c | 70 ++++++++++++++++++++++++++++++++++++++++++
11
hw/watchdog/sbsa_gwdt.c | 293 ++++++++++++++++++++++++++++++++
26
hw/virtio/virtio-mem.c | 4 ++-
12
hw/arm/Kconfig | 1 +
27
hw/arm/Kconfig | 1 +
13
hw/watchdog/Kconfig | 3 +
28
3 files changed, 74 insertions(+), 1 deletion(-)
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
29
19
diff --git a/include/hw/watchdog/sbsa_gwdt.h b/include/hw/watchdog/sbsa_gwdt.h
30
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
20
new file mode 100644
31
index XXXXXXX..XXXXXXX 100644
21
index XXXXXXX..XXXXXXX
32
--- a/hw/arm/virt.c
22
--- /dev/null
33
+++ b/hw/arm/virt.c
23
+++ b/include/hw/watchdog/sbsa_gwdt.h
24
@@ -XXX,XX +XXX,XX @@
34
@@ -XXX,XX +XXX,XX @@
25
+/*
35
#include "hw/arm/smmuv3.h"
26
+ * Copyright (c) 2020 Linaro Limited
36
#include "hw/acpi/acpi.h"
27
+ *
37
#include "target/arm/internals.h"
28
+ * Authors:
38
+#include "hw/mem/memory-device.h"
29
+ * Shashi Mallela <shashi.mallela@linaro.org>
39
#include "hw/mem/pc-dimm.h"
30
+ *
40
#include "hw/mem/nvdimm.h"
31
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at your
41
#include "hw/acpi/generic_event_device.h"
32
+ * option) any later version. See the COPYING file in the top-level directory.
42
+#include "hw/virtio/virtio-mem-pci.h"
33
+ *
43
#include "hw/virtio/virtio-iommu.h"
34
+ */
44
#include "hw/char/pl011.h"
45
#include "qemu/guest-random.h"
46
@@ -XXX,XX +XXX,XX @@ static void virt_memory_plug(HotplugHandler *hotplug_dev,
47
dev, &error_abort);
48
}
49
50
+static void virt_virtio_md_pci_pre_plug(HotplugHandler *hotplug_dev,
51
+ DeviceState *dev, Error **errp)
52
+{
53
+ HotplugHandler *hotplug_dev2 = qdev_get_bus_hotplug_handler(dev);
54
+ Error *local_err = NULL;
35
+
55
+
36
+#ifndef WDT_SBSA_GWDT_H
56
+ if (!hotplug_dev2 && dev->hotplugged) {
37
+#define WDT_SBSA_GWDT_H
57
+ /*
38
+
58
+ * Without a bus hotplug handler, we cannot control the plug/unplug
39
+#include "qemu/bitops.h"
59
+ * order. We should never reach this point when hotplugging on ARM.
40
+#include "hw/sysbus.h"
60
+ * However, it's nice to add a safety net, similar to what we have
41
+#include "hw/irq.h"
61
+ * on x86.
42
+
62
+ */
43
+#define TYPE_WDT_SBSA "sbsa_gwdt"
63
+ error_setg(errp, "hotplug of virtio based memory devices not supported"
44
+#define SBSA_GWDT(obj) \
64
+ " on this bus.");
45
+ OBJECT_CHECK(SBSA_GWDTState, (obj), TYPE_WDT_SBSA)
65
+ return;
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
+ }
66
+ }
154
+};
67
+ /*
155
+
68
+ * First, see if we can plug this memory device at all. If that
156
+typedef enum WdtRefreshType {
69
+ * succeeds, branch of to the actual hotplug handler.
157
+ EXPLICIT_REFRESH = 0,
70
+ */
158
+ TIMEOUT_REFRESH = 1,
71
+ memory_device_pre_plug(MEMORY_DEVICE(dev), MACHINE(hotplug_dev), NULL,
159
+} WdtRefreshType;
72
+ &local_err);
160
+
73
+ if (!local_err && hotplug_dev2) {
161
+static uint64_t sbsa_gwdt_rread(void *opaque, hwaddr addr, unsigned int size)
74
+ hotplug_handler_pre_plug(hotplug_dev2, dev, &local_err);
162
+{
163
+ SBSA_GWDTState *s = SBSA_GWDT(opaque);
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
+ }
75
+ }
178
+ return ret;
76
+ error_propagate(errp, local_err);
179
+}
77
+}
180
+
78
+
181
+static uint64_t sbsa_gwdt_read(void *opaque, hwaddr addr, unsigned int size)
79
+static void virt_virtio_md_pci_plug(HotplugHandler *hotplug_dev,
80
+ DeviceState *dev, Error **errp)
182
+{
81
+{
183
+ SBSA_GWDTState *s = SBSA_GWDT(opaque);
82
+ HotplugHandler *hotplug_dev2 = qdev_get_bus_hotplug_handler(dev);
184
+ uint32_t ret = 0;
83
+ Error *local_err = NULL;
185
+
84
+
186
+ switch (addr) {
85
+ /*
187
+ case SBSA_GWDT_WCS:
86
+ * Plug the memory device first and then branch off to the actual
188
+ ret = s->wcs;
87
+ * hotplug handler. If that one fails, we can easily undo the memory
189
+ break;
88
+ * device bits.
190
+ case SBSA_GWDT_WOR:
89
+ */
191
+ ret = s->worl;
90
+ memory_device_plug(MEMORY_DEVICE(dev), MACHINE(hotplug_dev));
192
+ break;
91
+ if (hotplug_dev2) {
193
+ case SBSA_GWDT_WORU:
92
+ hotplug_handler_plug(hotplug_dev2, dev, &local_err);
194
+ ret = s->woru;
93
+ if (local_err) {
195
+ break;
94
+ memory_device_unplug(MEMORY_DEVICE(dev), MACHINE(hotplug_dev));
196
+ case SBSA_GWDT_WCV:
95
+ }
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
+ }
96
+ }
209
+ return ret;
97
+ error_propagate(errp, local_err);
210
+}
98
+}
211
+
99
+
212
+static void sbsa_gwdt_update_timer(SBSA_GWDTState *s, WdtRefreshType rtype)
100
+static void virt_virtio_md_pci_unplug_request(HotplugHandler *hotplug_dev,
101
+ DeviceState *dev, Error **errp)
213
+{
102
+{
214
+ uint64_t timeout = 0;
103
+ /* We don't support hot unplug of virtio based memory devices */
215
+
104
+ error_setg(errp, "virtio based memory devices cannot be unplugged.");
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
+}
105
+}
238
+
106
+
239
+static void sbsa_gwdt_rwrite(void *opaque, hwaddr offset, uint64_t data,
240
+ unsigned size) {
241
+ SBSA_GWDTState *s = SBSA_GWDT(opaque);
242
+
107
+
243
+ if (offset == SBSA_GWDT_WRR) {
108
static void virt_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev,
244
+ s->wcs &= ~(SBSA_GWDT_WCS_WS0 | SBSA_GWDT_WCS_WS1);
109
DeviceState *dev, Error **errp)
110
{
111
@@ -XXX,XX +XXX,XX @@ static void virt_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev,
112
113
if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
114
virt_memory_pre_plug(hotplug_dev, dev, errp);
115
+ } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MEM_PCI)) {
116
+ virt_virtio_md_pci_pre_plug(hotplug_dev, dev, errp);
117
} else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_IOMMU_PCI)) {
118
hwaddr db_start = 0, db_end = 0;
119
char *resv_prop_str;
120
@@ -XXX,XX +XXX,XX @@ static void virt_machine_device_plug_cb(HotplugHandler *hotplug_dev,
121
if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
122
virt_memory_plug(hotplug_dev, dev, errp);
123
}
245
+
124
+
246
+ sbsa_gwdt_update_timer(s, EXPLICIT_REFRESH);
125
+ if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MEM_PCI)) {
247
+ } else {
126
+ virt_virtio_md_pci_plug(hotplug_dev, dev, errp);
248
+ qemu_log_mask(LOG_GUEST_ERROR, "bad address in refresh frame write :"
249
+ " 0x%x\n", (int)offset);
250
+ }
127
+ }
251
+}
252
+
128
+
253
+static void sbsa_gwdt_write(void *opaque, hwaddr offset, uint64_t data,
129
if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_IOMMU_PCI)) {
254
+ unsigned size) {
130
PCIDevice *pdev = PCI_DEVICE(dev);
255
+ SBSA_GWDTState *s = SBSA_GWDT(opaque);
131
256
+
132
@@ -XXX,XX +XXX,XX @@ static void virt_machine_device_unplug_request_cb(HotplugHandler *hotplug_dev,
257
+ switch (offset) {
133
{
258
+ case SBSA_GWDT_WCS:
134
if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) {
259
+ s->wcs = data & SBSA_GWDT_WCS_EN;
135
virt_dimm_unplug_request(hotplug_dev, dev, errp);
260
+ qemu_set_irq(s->irq, 0);
136
+ } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MEM_PCI)) {
261
+ sbsa_gwdt_update_timer(s, EXPLICIT_REFRESH);
137
+ virt_virtio_md_pci_unplug_request(hotplug_dev, dev, errp);
262
+ break;
138
} else {
263
+
139
error_setg(errp, "device unplug request for unsupported device"
264
+ case SBSA_GWDT_WOR:
140
" type: %s", object_get_typename(OBJECT(dev)));
265
+ s->worl = data;
141
@@ -XXX,XX +XXX,XX @@ static HotplugHandler *virt_machine_get_hotplug_handler(MachineState *machine,
266
+ s->wcs &= ~(SBSA_GWDT_WCS_WS0 | SBSA_GWDT_WCS_WS1);
142
267
+ qemu_set_irq(s->irq, 0);
143
if (device_is_dynamic_sysbus(mc, dev) ||
268
+ sbsa_gwdt_update_timer(s, EXPLICIT_REFRESH);
144
object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM) ||
269
+ break;
145
+ object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MEM_PCI) ||
270
+
146
object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_IOMMU_PCI)) {
271
+ case SBSA_GWDT_WORU:
147
return HOTPLUG_HANDLER(machine);
272
+ s->woru = data & SBSA_GWDT_WOR_MASK;
148
}
273
+ s->wcs &= ~(SBSA_GWDT_WCS_WS0 | SBSA_GWDT_WCS_WS1);
149
diff --git a/hw/virtio/virtio-mem.c b/hw/virtio/virtio-mem.c
274
+ qemu_set_irq(s->irq, 0);
150
index XXXXXXX..XXXXXXX 100644
275
+ sbsa_gwdt_update_timer(s, EXPLICIT_REFRESH);
151
--- a/hw/virtio/virtio-mem.c
276
+ break;
152
+++ b/hw/virtio/virtio-mem.c
277
+
153
@@ -XXX,XX +XXX,XX @@ static bool virtio_mem_has_shared_zeropage(RAMBlock *rb)
278
+ case SBSA_GWDT_WCV:
154
* The memory block size corresponds mostly to the section size.
279
+ s->wcvl = data;
155
*
280
+ break;
156
* This allows e.g., to add 20MB with a section size of 128MB on x86_64, and
281
+
157
- * a section size of 1GB on arm64 (as long as the start address is properly
282
+ case SBSA_GWDT_WCVU:
158
+ * a section size of 512MB on arm64 (as long as the start address is properly
283
+ s->wcvu = data;
159
* aligned, similar to ordinary DIMMs).
284
+ break;
160
*
285
+
161
* We can change this at any time and maybe even make it configurable if
286
+ default:
162
@@ -XXX,XX +XXX,XX @@ static bool virtio_mem_has_shared_zeropage(RAMBlock *rb)
287
+ qemu_log_mask(LOG_GUEST_ERROR, "bad address in control frame write :"
163
*/
288
+ " 0x%x\n", (int)offset);
164
#if defined(TARGET_X86_64) || defined(TARGET_I386)
289
+ }
165
#define VIRTIO_MEM_USABLE_EXTENT (2 * (128 * MiB))
290
+ return;
166
+#elif defined(TARGET_ARM)
291
+}
167
+#define VIRTIO_MEM_USABLE_EXTENT (2 * (512 * MiB))
292
+
168
#else
293
+static void wdt_sbsa_gwdt_reset(DeviceState *dev)
169
#error VIRTIO_MEM_USABLE_EXTENT not defined
294
+{
170
#endif
295
+ SBSA_GWDTState *s = SBSA_GWDT(dev);
296
+
297
+ timer_del(s->timer);
298
+
299
+ s->wcs = 0;
300
+ s->wcvl = 0;
301
+ s->wcvu = 0;
302
+ s->worl = 0;
303
+ s->woru = 0;
304
+ s->id = SBSA_GWDT_ID;
305
+}
306
+
307
+static void sbsa_gwdt_timer_sysinterrupt(void *opaque)
308
+{
309
+ SBSA_GWDTState *s = SBSA_GWDT(opaque);
310
+
311
+ if (!(s->wcs & SBSA_GWDT_WCS_WS0)) {
312
+ s->wcs |= SBSA_GWDT_WCS_WS0;
313
+ sbsa_gwdt_update_timer(s, TIMEOUT_REFRESH);
314
+ qemu_set_irq(s->irq, 1);
315
+ } else {
316
+ s->wcs |= SBSA_GWDT_WCS_WS1;
317
+ qemu_log_mask(CPU_LOG_RESET, "Watchdog timer expired.\n");
318
+ /*
319
+ * Reset the watchdog only if the guest gets notified about
320
+ * expiry. watchdog_perform_action() may temporarily relinquish
321
+ * the BQL; reset before triggering the action to avoid races with
322
+ * sbsa_gwdt instructions.
323
+ */
324
+ switch (get_watchdog_action()) {
325
+ case WATCHDOG_ACTION_DEBUG:
326
+ case WATCHDOG_ACTION_NONE:
327
+ case WATCHDOG_ACTION_PAUSE:
328
+ break;
329
+ default:
330
+ wdt_sbsa_gwdt_reset(DEVICE(s));
331
+ }
332
+ watchdog_perform_action();
333
+ }
334
+}
335
+
336
+static const MemoryRegionOps sbsa_gwdt_rops = {
337
+ .read = sbsa_gwdt_rread,
338
+ .write = sbsa_gwdt_rwrite,
339
+ .endianness = DEVICE_LITTLE_ENDIAN,
340
+ .valid.min_access_size = 4,
341
+ .valid.max_access_size = 4,
342
+ .valid.unaligned = false,
343
+};
344
+
345
+static const MemoryRegionOps sbsa_gwdt_ops = {
346
+ .read = sbsa_gwdt_read,
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
171
diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
404
index XXXXXXX..XXXXXXX 100644
172
index XXXXXXX..XXXXXXX 100644
405
--- a/hw/arm/Kconfig
173
--- a/hw/arm/Kconfig
406
+++ b/hw/arm/Kconfig
174
+++ b/hw/arm/Kconfig
407
@@ -XXX,XX +XXX,XX @@ config SBSA_REF
175
@@ -XXX,XX +XXX,XX @@ config ARM_VIRT
408
select PL031 # RTC
176
select ACPI_HW_REDUCED
409
select PL061 # GPIO
177
select ACPI_APEI
410
select USB_EHCI_SYSBUS
178
select ACPI_VIOT
411
+ select WDT_SBSA
179
+ select VIRTIO_MEM_SUPPORTED
412
180
413
config SABRELITE
181
config CHEETAH
414
bool
182
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
--
183
--
436
2.20.1
184
2.25.1
437
185
438
186
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Petr Pavlu <petr.pavlu@suse.com>
2
2
3
For BTI, we need to know if the executable is static or dynamic,
3
Implement support for reading GICC_IIDR. This register is used by the
4
which means looking for PT_INTERP earlier.
4
Linux kernel to recognize that GICv2 with GICC_APRn is present.
5
5
6
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
6
Signed-off-by: Petr Pavlu <petr.pavlu@suse.com>
7
Message-id: 20201021173749.111103-8-richard.henderson@linaro.org
7
Message-id: 20220113151916.17978-2-ppavlu@suse.cz
8
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
8
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
---
10
---
11
linux-user/elfload.c | 60 +++++++++++++++++++++++---------------------
11
hw/intc/arm_gic.c | 9 +++++++++
12
1 file changed, 31 insertions(+), 29 deletions(-)
12
1 file changed, 9 insertions(+)
13
13
14
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
14
diff --git a/hw/intc/arm_gic.c b/hw/intc/arm_gic.c
15
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
16
--- a/linux-user/elfload.c
16
--- a/hw/intc/arm_gic.c
17
+++ b/linux-user/elfload.c
17
+++ b/hw/intc/arm_gic.c
18
@@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd,
18
@@ -XXX,XX +XXX,XX @@ static MemTxResult gic_cpu_read(GICState *s, int cpu, int offset,
19
20
mmap_lock();
21
22
- /* Find the maximum size of the image and allocate an appropriate
23
- amount of memory to handle that. */
24
+ /*
25
+ * Find the maximum size of the image and allocate an appropriate
26
+ * amount of memory to handle that. Locate the interpreter, if any.
27
+ */
28
loaddr = -1, hiaddr = 0;
29
info->alignment = 0;
30
for (i = 0; i < ehdr->e_phnum; ++i) {
31
@@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd,
32
}
33
++info->nsegs;
34
info->alignment |= eppnt->p_align;
35
+ } else if (eppnt->p_type == PT_INTERP && pinterp_name) {
36
+ g_autofree char *interp_name = NULL;
37
+
38
+ if (*pinterp_name) {
39
+ errmsg = "Multiple PT_INTERP entries";
40
+ goto exit_errmsg;
41
+ }
42
+ interp_name = g_malloc(eppnt->p_filesz);
43
+ if (!interp_name) {
44
+ goto exit_perror;
45
+ }
46
+
47
+ if (eppnt->p_offset + eppnt->p_filesz <= BPRM_BUF_SIZE) {
48
+ memcpy(interp_name, bprm_buf + eppnt->p_offset,
49
+ eppnt->p_filesz);
50
+ } else {
51
+ retval = pread(image_fd, interp_name, eppnt->p_filesz,
52
+ eppnt->p_offset);
53
+ if (retval != eppnt->p_filesz) {
54
+ goto exit_perror;
55
+ }
56
+ }
57
+ if (interp_name[eppnt->p_filesz - 1] != 0) {
58
+ errmsg = "Invalid PT_INTERP entry";
59
+ goto exit_errmsg;
60
+ }
61
+ *pinterp_name = g_steal_pointer(&interp_name);
62
}
19
}
20
break;
63
}
21
}
64
22
+ case 0xfc:
65
@@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd,
23
+ if (s->revision == REV_11MPCORE) {
66
if (vaddr_em > info->brk) {
24
+ /* Reserved on 11MPCore */
67
info->brk = vaddr_em;
25
+ *data = 0;
68
}
26
+ } else {
69
- } else if (eppnt->p_type == PT_INTERP && pinterp_name) {
27
+ /* GICv1 or v2; Arm implementation */
70
- g_autofree char *interp_name = NULL;
28
+ *data = (s->revision << 16) | 0x43b;
71
-
29
+ }
72
- if (*pinterp_name) {
30
+ break;
73
- errmsg = "Multiple PT_INTERP entries";
31
default:
74
- goto exit_errmsg;
32
qemu_log_mask(LOG_GUEST_ERROR,
75
- }
33
"gic_cpu_read: Bad offset %x\n", (int)offset);
76
- interp_name = g_malloc(eppnt->p_filesz);
77
- if (!interp_name) {
78
- goto exit_perror;
79
- }
80
-
81
- if (eppnt->p_offset + eppnt->p_filesz <= BPRM_BUF_SIZE) {
82
- memcpy(interp_name, bprm_buf + eppnt->p_offset,
83
- eppnt->p_filesz);
84
- } else {
85
- retval = pread(image_fd, interp_name, eppnt->p_filesz,
86
- eppnt->p_offset);
87
- if (retval != eppnt->p_filesz) {
88
- goto exit_perror;
89
- }
90
- }
91
- if (interp_name[eppnt->p_filesz - 1] != 0) {
92
- errmsg = "Invalid PT_INTERP entry";
93
- goto exit_errmsg;
94
- }
95
- *pinterp_name = g_steal_pointer(&interp_name);
96
#ifdef TARGET_MIPS
97
} else if (eppnt->p_type == PT_MIPS_ABIFLAGS) {
98
Mips_elf_abiflags_v0 abiflags;
99
--
34
--
100
2.20.1
35
2.25.1
101
36
102
37
diff view generated by jsdifflib
1
From: Thomas Huth <thuth@redhat.com>
1
From: Petr Pavlu <petr.pavlu@suse.com>
2
2
3
When compiling with -Werror=implicit-fallthrough, gcc complains about
3
When running Linux on a machine with GICv2, the kernel can crash while
4
missing fallthrough annotations in this file. Looking at the code,
4
processing an interrupt and can subsequently start a kdump kernel from
5
the fallthrough is very likely intended here, so add some comments
5
the active interrupt handler. In such a case, the crashed kernel might
6
to silence the compiler warnings.
6
not gracefully signal the end of interrupt to the GICv2 hardware. The
7
kdump kernel will however try to reset the GIC state on startup to get
8
the controller into a sane state, in particular the kernel writes ones
9
to GICD_ICACTIVERn and wipes out GICC_APRn to make sure that no
10
interrupt is active.
7
11
8
Signed-off-by: Thomas Huth <thuth@redhat.com>
12
The patch adds a logic to recalculate the running priority when
9
Message-id: 20201020105938.23209-1-thuth@redhat.com
13
GICC_APRn/GICC_NSAPRn is written which makes sure that the mentioned
14
reset works with the GICv2 emulation in QEMU too and the kdump kernel
15
starts receiving interrupts.
16
17
The described scenario can be reproduced on an AArch64 QEMU virt machine
18
with a kdump-enabled Linux system by using the softdog module. The kdump
19
kernel will hang at some point because QEMU still thinks the running
20
priority is that of the timer interrupt and asserts no new interrupts to
21
the system:
22
$ modprobe softdog soft_margin=10 soft_panic=1
23
$ cat > /dev/watchdog
24
[Press Enter to start the watchdog, wait for its timeout and observe
25
that the kdump kernel hangs on startup.]
26
27
Signed-off-by: Petr Pavlu <petr.pavlu@suse.com>
28
Message-id: 20220113151916.17978-3-ppavlu@suse.cz
10
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
29
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
30
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
---
31
---
13
hw/arm/highbank.c | 2 ++
32
hw/intc/arm_gic.c | 2 ++
14
1 file changed, 2 insertions(+)
33
1 file changed, 2 insertions(+)
15
34
16
diff --git a/hw/arm/highbank.c b/hw/arm/highbank.c
35
diff --git a/hw/intc/arm_gic.c b/hw/intc/arm_gic.c
17
index XXXXXXX..XXXXXXX 100644
36
index XXXXXXX..XXXXXXX 100644
18
--- a/hw/arm/highbank.c
37
--- a/hw/intc/arm_gic.c
19
+++ b/hw/arm/highbank.c
38
+++ b/hw/intc/arm_gic.c
20
@@ -XXX,XX +XXX,XX @@ static void hb_reset_secondary(ARMCPU *cpu, const struct arm_boot_info *info)
39
@@ -XXX,XX +XXX,XX @@ static MemTxResult gic_cpu_write(GICState *s, int cpu, int offset,
21
address_space_stl_notdirty(&address_space_memory,
40
} else {
22
SMP_BOOT_REG + 0x30, 0,
41
s->apr[regno][cpu] = value;
23
MEMTXATTRS_UNSPECIFIED, NULL);
42
}
24
+ /* fallthrough */
43
+ s->running_priority[cpu] = gic_get_prio_from_apr_bits(s, cpu);
25
case 3:
44
break;
26
address_space_stl_notdirty(&address_space_memory,
45
}
27
SMP_BOOT_REG + 0x20, 0,
46
case 0xe0: case 0xe4: case 0xe8: case 0xec:
28
MEMTXATTRS_UNSPECIFIED, NULL);
47
@@ -XXX,XX +XXX,XX @@ static MemTxResult gic_cpu_write(GICState *s, int cpu, int offset,
29
+ /* fallthrough */
48
return MEMTX_OK;
30
case 2:
49
}
31
address_space_stl_notdirty(&address_space_memory,
50
s->nsapr[regno][cpu] = value;
32
SMP_BOOT_REG + 0x10, 0,
51
+ s->running_priority[cpu] = gic_get_prio_from_apr_bits(s, cpu);
52
break;
53
}
54
case 0x1000:
33
--
55
--
34
2.20.1
56
2.25.1
35
57
36
58
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Marc Zyngier <maz@kernel.org>
2
2
3
The second loop uses a loop induction variable, and the first
3
Just like we can control the enablement of the highmem PCIe ECAM
4
does not. Transform the first to match the second, to simplify
4
region using highmem_ecam, let's add a control for the highmem
5
a following patch moving code between them.
5
PCIe MMIO region.
6
6
7
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
7
Similarily to highmem_ecam, this region is disabled when highmem
8
Message-id: 20201021173749.111103-7-richard.henderson@linaro.org
8
is off.
9
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
9
10
Signed-off-by: Marc Zyngier <maz@kernel.org>
11
Reviewed-by: Eric Auger <eric.auger@redhat.com>
12
Message-id: 20220114140741.1358263-2-maz@kernel.org
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
---
14
---
12
linux-user/elfload.c | 9 +++++----
15
include/hw/arm/virt.h | 1 +
13
1 file changed, 5 insertions(+), 4 deletions(-)
16
hw/arm/virt-acpi-build.c | 10 ++++------
17
hw/arm/virt.c | 7 +++++--
18
3 files changed, 10 insertions(+), 8 deletions(-)
14
19
15
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
20
diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h
16
index XXXXXXX..XXXXXXX 100644
21
index XXXXXXX..XXXXXXX 100644
17
--- a/linux-user/elfload.c
22
--- a/include/hw/arm/virt.h
18
+++ b/linux-user/elfload.c
23
+++ b/include/hw/arm/virt.h
19
@@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd,
24
@@ -XXX,XX +XXX,XX @@ struct VirtMachineState {
20
loaddr = -1, hiaddr = 0;
25
bool secure;
21
info->alignment = 0;
26
bool highmem;
22
for (i = 0; i < ehdr->e_phnum; ++i) {
27
bool highmem_ecam;
23
- if (phdr[i].p_type == PT_LOAD) {
28
+ bool highmem_mmio;
24
- abi_ulong a = phdr[i].p_vaddr - phdr[i].p_offset;
29
bool its;
25
+ struct elf_phdr *eppnt = phdr + i;
30
bool tcg_its;
26
+ if (eppnt->p_type == PT_LOAD) {
31
bool virt;
27
+ abi_ulong a = eppnt->p_vaddr - eppnt->p_offset;
32
diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
28
if (a < loaddr) {
33
index XXXXXXX..XXXXXXX 100644
29
loaddr = a;
34
--- a/hw/arm/virt-acpi-build.c
30
}
35
+++ b/hw/arm/virt-acpi-build.c
31
- a = phdr[i].p_vaddr + phdr[i].p_memsz;
36
@@ -XXX,XX +XXX,XX @@ static void acpi_dsdt_add_virtio(Aml *scope,
32
+ a = eppnt->p_vaddr + eppnt->p_memsz;
37
}
33
if (a > hiaddr) {
38
34
hiaddr = a;
39
static void acpi_dsdt_add_pci(Aml *scope, const MemMapEntry *memmap,
35
}
40
- uint32_t irq, bool use_highmem, bool highmem_ecam,
36
++info->nsegs;
41
- VirtMachineState *vms)
37
- info->alignment |= phdr[i].p_align;
42
+ uint32_t irq, VirtMachineState *vms)
38
+ info->alignment |= eppnt->p_align;
43
{
39
}
44
- int ecam_id = VIRT_ECAM_ID(highmem_ecam);
45
+ int ecam_id = VIRT_ECAM_ID(vms->highmem_ecam);
46
struct GPEXConfig cfg = {
47
.mmio32 = memmap[VIRT_PCIE_MMIO],
48
.pio = memmap[VIRT_PCIE_PIO],
49
@@ -XXX,XX +XXX,XX @@ static void acpi_dsdt_add_pci(Aml *scope, const MemMapEntry *memmap,
50
.bus = vms->bus,
51
};
52
53
- if (use_highmem) {
54
+ if (vms->highmem_mmio) {
55
cfg.mmio64 = memmap[VIRT_HIGH_PCIE_MMIO];
40
}
56
}
41
57
58
@@ -XXX,XX +XXX,XX @@ build_dsdt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
59
acpi_dsdt_add_fw_cfg(scope, &memmap[VIRT_FW_CFG]);
60
acpi_dsdt_add_virtio(scope, &memmap[VIRT_MMIO],
61
(irqmap[VIRT_MMIO] + ARM_SPI_BASE), NUM_VIRTIO_TRANSPORTS);
62
- acpi_dsdt_add_pci(scope, memmap, (irqmap[VIRT_PCIE] + ARM_SPI_BASE),
63
- vms->highmem, vms->highmem_ecam, vms);
64
+ acpi_dsdt_add_pci(scope, memmap, irqmap[VIRT_PCIE] + ARM_SPI_BASE, vms);
65
if (vms->acpi_dev) {
66
build_ged_aml(scope, "\\_SB."GED_DEVICE,
67
HOTPLUG_HANDLER(vms->acpi_dev),
68
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
69
index XXXXXXX..XXXXXXX 100644
70
--- a/hw/arm/virt.c
71
+++ b/hw/arm/virt.c
72
@@ -XXX,XX +XXX,XX @@ static void create_pcie(VirtMachineState *vms)
73
mmio_reg, base_mmio, size_mmio);
74
memory_region_add_subregion(get_system_memory(), base_mmio, mmio_alias);
75
76
- if (vms->highmem) {
77
+ if (vms->highmem_mmio) {
78
/* Map high MMIO space */
79
MemoryRegion *high_mmio_alias = g_new0(MemoryRegion, 1);
80
81
@@ -XXX,XX +XXX,XX @@ static void create_pcie(VirtMachineState *vms)
82
qemu_fdt_setprop_sized_cells(ms->fdt, nodename, "reg",
83
2, base_ecam, 2, size_ecam);
84
85
- if (vms->highmem) {
86
+ if (vms->highmem_mmio) {
87
qemu_fdt_setprop_sized_cells(ms->fdt, nodename, "ranges",
88
1, FDT_PCI_RANGE_IOPORT, 2, 0,
89
2, base_pio, 2, size_pio,
90
@@ -XXX,XX +XXX,XX @@ static void machvirt_init(MachineState *machine)
91
92
virt_flash_fdt(vms, sysmem, secure_sysmem ?: sysmem);
93
94
+ vms->highmem_mmio &= vms->highmem;
95
+
96
create_gic(vms, sysmem);
97
98
virt_cpu_post_init(vms, sysmem);
99
@@ -XXX,XX +XXX,XX @@ static void virt_instance_init(Object *obj)
100
vms->gic_version = VIRT_GIC_VERSION_NOSEL;
101
102
vms->highmem_ecam = !vmc->no_highmem_ecam;
103
+ vms->highmem_mmio = true;
104
105
if (vmc->no_its) {
106
vms->its = false;
42
--
107
--
43
2.20.1
108
2.25.1
44
109
45
110
diff view generated by jsdifflib
1
From: Luc Michel <luc@lmichel.fr>
1
From: Marc Zyngier <maz@kernel.org>
2
2
3
Those reset values have been extracted from a Raspberry Pi 3 model B
3
Just like we can control the enablement of the highmem PCIe region
4
v1.2, using the 2020-08-20 version of raspios. The dump was done using
4
using highmem_ecam, let's add a control for the highmem GICv3
5
the debugfs interface of the CPRMAN driver in Linux (under
5
redistributor region.
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
6
10
Those values are set by the Raspberry Pi firmware at boot time (Linux
7
Similarily to highmem_ecam, these redistributors are disabled when
11
expects them to be set when it boots up).
8
highmem is off.
12
9
13
Some stages are not exposed by the Linux driver (e.g. the PLL B). For
10
Reviewed-by: Andrew Jones <drjones@redhat.com>
14
those, the reset values are unknown and left to 0 which implies a
11
Signed-off-by: Marc Zyngier <maz@kernel.org>
15
disabled output.
12
Reviewed-by: Eric Auger <eric.auger@redhat.com>
16
13
Message-id: 20220114140741.1358263-3-maz@kernel.org
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>
14
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
26
---
15
---
27
include/hw/misc/bcm2835_cprman_internals.h | 269 +++++++++++++++++++++
16
include/hw/arm/virt.h | 4 +++-
28
hw/misc/bcm2835_cprman.c | 31 +++
17
hw/arm/virt-acpi-build.c | 2 ++
29
2 files changed, 300 insertions(+)
18
hw/arm/virt.c | 2 ++
19
3 files changed, 7 insertions(+), 1 deletion(-)
30
20
31
diff --git a/include/hw/misc/bcm2835_cprman_internals.h b/include/hw/misc/bcm2835_cprman_internals.h
21
diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h
32
index XXXXXXX..XXXXXXX 100644
22
index XXXXXXX..XXXXXXX 100644
33
--- a/include/hw/misc/bcm2835_cprman_internals.h
23
--- a/include/hw/arm/virt.h
34
+++ b/include/hw/misc/bcm2835_cprman_internals.h
24
+++ b/include/hw/arm/virt.h
35
@@ -XXX,XX +XXX,XX @@ static inline void set_clock_mux_init_info(BCM2835CprmanState *s,
25
@@ -XXX,XX +XXX,XX @@ struct VirtMachineState {
36
mux->frac_bits = CLOCK_MUX_INIT_INFO[id].frac_bits;
26
bool highmem;
27
bool highmem_ecam;
28
bool highmem_mmio;
29
+ bool highmem_redists;
30
bool its;
31
bool tcg_its;
32
bool virt;
33
@@ -XXX,XX +XXX,XX @@ static inline int virt_gicv3_redist_region_count(VirtMachineState *vms)
34
35
assert(vms->gic_version == VIRT_GIC_VERSION_3);
36
37
- return MACHINE(vms)->smp.cpus > redist0_capacity ? 2 : 1;
38
+ return (MACHINE(vms)->smp.cpus > redist0_capacity &&
39
+ vms->highmem_redists) ? 2 : 1;
37
}
40
}
38
41
42
#endif /* QEMU_ARM_VIRT_H */
43
diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
44
index XXXXXXX..XXXXXXX 100644
45
--- a/hw/arm/virt-acpi-build.c
46
+++ b/hw/arm/virt-acpi-build.c
47
@@ -XXX,XX +XXX,XX @@ void virt_acpi_build(VirtMachineState *vms, AcpiBuildTables *tables)
48
acpi_add_table(table_offsets, tables_blob);
49
build_fadt_rev5(tables_blob, tables->linker, vms, dsdt);
50
51
+ vms->highmem_redists &= vms->highmem;
39
+
52
+
40
+/*
53
acpi_add_table(table_offsets, tables_blob);
41
+ * Object reset info
54
build_madt(tables_blob, tables->linker, vms);
42
+ * Those values have been dumped from a Raspberry Pi 3 Model B v1.2 using the
55
43
+ * clk debugfs interface in Linux.
56
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
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
57
index XXXXXXX..XXXXXXX 100644
311
--- a/hw/misc/bcm2835_cprman.c
58
--- a/hw/arm/virt.c
312
+++ b/hw/misc/bcm2835_cprman.c
59
+++ b/hw/arm/virt.c
313
@@ -XXX,XX +XXX,XX @@
60
@@ -XXX,XX +XXX,XX @@ static void machvirt_init(MachineState *machine)
314
61
virt_flash_fdt(vms, sysmem, secure_sysmem ?: sysmem);
315
/* PLL */
62
316
63
vms->highmem_mmio &= vms->highmem;
317
+static void pll_reset(DeviceState *dev)
64
+ vms->highmem_redists &= vms->highmem;
318
+{
65
319
+ CprmanPllState *s = CPRMAN_PLL(dev);
66
create_gic(vms, sysmem);
320
+ const PLLResetInfo *info = &PLL_RESET_INFO[s->id];
67
321
+
68
@@ -XXX,XX +XXX,XX @@ static void virt_instance_init(Object *obj)
322
+ *s->reg_cm = info->cm;
69
323
+ *s->reg_a2w_ctrl = info->a2w_ctrl;
70
vms->highmem_ecam = !vmc->no_highmem_ecam;
324
+ memcpy(s->reg_a2w_ana, info->a2w_ana, sizeof(info->a2w_ana));
71
vms->highmem_mmio = true;
325
+ *s->reg_a2w_frac = info->a2w_frac;
72
+ vms->highmem_redists = true;
326
+}
73
327
+
74
if (vmc->no_its) {
328
static bool pll_is_locked(const CprmanPllState *pll)
75
vms->its = false;
329
{
330
return !FIELD_EX32(*pll->reg_a2w_ctrl, A2W_PLLx_CTRL, PWRDN)
331
@@ -XXX,XX +XXX,XX @@ static void pll_class_init(ObjectClass *klass, void *data)
332
{
333
DeviceClass *dc = DEVICE_CLASS(klass);
334
335
+ dc->reset = pll_reset;
336
dc->vmsd = &pll_vmstate;
337
}
338
339
@@ -XXX,XX +XXX,XX @@ static const TypeInfo cprman_pll_info = {
340
341
/* PLL channel */
342
343
+static void pll_channel_reset(DeviceState *dev)
344
+{
345
+ CprmanPllChannelState *s = CPRMAN_PLL_CHANNEL(dev);
346
+ const PLLChannelResetInfo *info = &PLL_CHANNEL_RESET_INFO[s->id];
347
+
348
+ *s->reg_a2w_ctrl = info->a2w_ctrl;
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
}
361
362
@@ -XXX,XX +XXX,XX @@ static void clock_mux_src_update(void *opaque)
363
clock_mux_update(s);
364
}
365
366
+static void clock_mux_reset(DeviceState *dev)
367
+{
368
+ CprmanClockMuxState *clock = CPRMAN_CLOCK_MUX(dev);
369
+ const ClockMuxResetInfo *info = &CLOCK_MUX_RESET_INFO[clock->id];
370
+
371
+ *clock->reg_ctl = info->cm_ctl;
372
+ *clock->reg_div = info->cm_div;
373
+}
374
+
375
static void clock_mux_init(Object *obj)
376
{
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
}
385
386
--
76
--
387
2.20.1
77
2.25.1
388
78
389
79
diff view generated by jsdifflib
1
From: Luc Michel <luc@lmichel.fr>
1
From: Marc Zyngier <maz@kernel.org>
2
2
3
There are 5 PLLs in the CPRMAN, namely PLL A, C, D, H and B. All of them
3
Even when the VM is configured with highmem=off, the highest_gpa
4
take the xosc clock as input and produce a new clock.
4
field includes devices that are above the 4GiB limit.
5
Similarily, nothing seem to check that the memory is within
6
the limit set by the highmem=off option.
5
7
6
This commit adds a skeleton implementation for the PLLs as sub-devices
8
This leads to failures in virt_kvm_type() on systems that have
7
of the CPRMAN. The PLLs are instantiated and connected internally to the
9
a crippled IPA range, as the reported IPA space is larger than
8
main oscillator.
10
what it should be.
9
11
10
Each PLL has 6 registers : CM, A2W_CTRL, A2W_ANA[0,1,2,3], A2W_FRAC. A
12
Instead, honor the user-specified limit to only use the devices
11
write to any of them triggers a call to the (not yet implemented)
13
at the lowest end of the spectrum, and fail if we have memory
12
pll_update function.
14
crossing the 4GiB limit.
13
15
14
If the main oscillator changes frequency, an update is also triggered.
16
Reviewed-by: Andrew Jones <drjones@redhat.com>
15
17
Reviewed-by: Eric Auger <eric.auger@redhat.com>
16
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
18
Signed-off-by: Marc Zyngier <maz@kernel.org>
17
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
19
Message-id: 20220114140741.1358263-4-maz@kernel.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>
20
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
21
---
21
---
22
include/hw/misc/bcm2835_cprman.h | 29 +++++
22
hw/arm/virt.c | 10 +++++++---
23
include/hw/misc/bcm2835_cprman_internals.h | 144 +++++++++++++++++++++
23
1 file changed, 7 insertions(+), 3 deletions(-)
24
hw/misc/bcm2835_cprman.c | 108 ++++++++++++++++
25
3 files changed, 281 insertions(+)
26
24
27
diff --git a/include/hw/misc/bcm2835_cprman.h b/include/hw/misc/bcm2835_cprman.h
25
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
28
index XXXXXXX..XXXXXXX 100644
26
index XXXXXXX..XXXXXXX 100644
29
--- a/include/hw/misc/bcm2835_cprman.h
27
--- a/hw/arm/virt.c
30
+++ b/include/hw/misc/bcm2835_cprman.h
28
+++ b/hw/arm/virt.c
31
@@ -XXX,XX +XXX,XX @@ DECLARE_INSTANCE_CHECKER(BCM2835CprmanState, CPRMAN,
29
@@ -XXX,XX +XXX,XX @@ static uint64_t virt_cpu_mp_affinity(VirtMachineState *vms, int idx)
32
30
static void virt_set_memmap(VirtMachineState *vms)
33
#define CPRMAN_NUM_REGS (0x2000 / sizeof(uint32_t))
31
{
34
32
MachineState *ms = MACHINE(vms);
35
+typedef enum CprmanPll {
33
- hwaddr base, device_memory_base, device_memory_size;
36
+ CPRMAN_PLLA = 0,
34
+ hwaddr base, device_memory_base, device_memory_size, memtop;
37
+ CPRMAN_PLLC,
35
int i;
38
+ CPRMAN_PLLD,
36
39
+ CPRMAN_PLLH,
37
vms->memmap = extended_memmap;
40
+ CPRMAN_PLLB,
38
@@ -XXX,XX +XXX,XX @@ static void virt_set_memmap(VirtMachineState *vms)
41
+
39
device_memory_size = ms->maxram_size - ms->ram_size + ms->ram_slots * GiB;
42
+ CPRMAN_NUM_PLL
40
43
+} CprmanPll;
41
/* Base address of the high IO region */
44
+
42
- base = device_memory_base + ROUND_UP(device_memory_size, GiB);
45
+typedef struct CprmanPllState {
43
+ memtop = base = device_memory_base + ROUND_UP(device_memory_size, GiB);
46
+ /*< private >*/
44
+ if (!vms->highmem && memtop > 4 * GiB) {
47
+ DeviceState parent_obj;
45
+ error_report("highmem=off, but memory crosses the 4GiB limit\n");
48
+
46
+ exit(EXIT_FAILURE);
49
+ /*< public >*/
50
+ CprmanPll id;
51
+
52
+ uint32_t *reg_cm;
53
+ uint32_t *reg_a2w_ctrl;
54
+ uint32_t *reg_a2w_ana; /* ANA[0] .. ANA[3] */
55
+ uint32_t prediv_mask; /* prediv bit in ana[1] */
56
+ uint32_t *reg_a2w_frac;
57
+
58
+ Clock *xosc_in;
59
+ Clock *out;
60
+} CprmanPllState;
61
+
62
struct BCM2835CprmanState {
63
/*< private >*/
64
SysBusDevice parent_obj;
65
@@ -XXX,XX +XXX,XX @@ struct BCM2835CprmanState {
66
/*< public >*/
67
MemoryRegion iomem;
68
69
+ CprmanPllState plls[CPRMAN_NUM_PLL];
70
+
71
uint32_t regs[CPRMAN_NUM_REGS];
72
uint32_t xosc_freq;
73
74
diff --git a/include/hw/misc/bcm2835_cprman_internals.h b/include/hw/misc/bcm2835_cprman_internals.h
75
index XXXXXXX..XXXXXXX 100644
76
--- a/include/hw/misc/bcm2835_cprman_internals.h
77
+++ b/include/hw/misc/bcm2835_cprman_internals.h
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
+}
234
+
235
#endif
236
diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c
237
index XXXXXXX..XXXXXXX 100644
238
--- a/hw/misc/bcm2835_cprman.c
239
+++ b/hw/misc/bcm2835_cprman.c
240
@@ -XXX,XX +XXX,XX @@
241
#include "hw/misc/bcm2835_cprman_internals.h"
242
#include "trace.h"
243
244
+/* PLL */
245
+
246
+static void pll_update(CprmanPllState *pll)
247
+{
248
+ clock_update(pll->out, 0);
249
+}
250
+
251
+static void pll_xosc_update(void *opaque)
252
+{
253
+ pll_update(CPRMAN_PLL(opaque));
254
+}
255
+
256
+static void pll_init(Object *obj)
257
+{
258
+ CprmanPllState *s = CPRMAN_PLL(obj);
259
+
260
+ s->xosc_in = qdev_init_clock_in(DEVICE(s), "xosc-in", pll_xosc_update, s);
261
+ s->out = qdev_init_clock_out(DEVICE(s), "out");
262
+}
263
+
264
+static const VMStateDescription pll_vmstate = {
265
+ .name = TYPE_CPRMAN_PLL,
266
+ .version_id = 1,
267
+ .minimum_version_id = 1,
268
+ .fields = (VMStateField[]) {
269
+ VMSTATE_CLOCK(xosc_in, CprmanPllState),
270
+ VMSTATE_END_OF_LIST()
271
+ }
47
+ }
272
+};
48
if (base < device_memory_base) {
273
+
49
error_report("maxmem/slots too huge");
274
+static void pll_class_init(ObjectClass *klass, void *data)
50
exit(EXIT_FAILURE);
275
+{
51
@@ -XXX,XX +XXX,XX @@ static void virt_set_memmap(VirtMachineState *vms)
276
+ DeviceClass *dc = DEVICE_CLASS(klass);
52
vms->memmap[i].size = size;
277
+
53
base += size;
278
+ dc->vmsd = &pll_vmstate;
54
}
279
+}
55
- vms->highest_gpa = base - 1;
280
+
56
+ vms->highest_gpa = (vms->highmem ? base : memtop) - 1;
281
+static const TypeInfo cprman_pll_info = {
57
if (device_memory_size > 0) {
282
+ .name = TYPE_CPRMAN_PLL,
58
ms->device_memory = g_malloc0(sizeof(*ms->device_memory));
283
+ .parent = TYPE_DEVICE,
59
ms->device_memory->base = device_memory_base;
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
{
394
DeviceClass *dc = DEVICE_CLASS(klass);
395
396
+ dc->realize = cprman_realize;
397
dc->reset = cprman_reset;
398
dc->vmsd = &cprman_vmstate;
399
device_class_set_props(dc, cprman_properties);
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
}
406
407
type_init(cprman_register_types);
408
--
60
--
409
2.20.1
61
2.25.1
410
62
411
63
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Marc Zyngier <maz@kernel.org>
2
2
3
The note test requires gcc 10 for -mbranch-protection=standard.
3
The highmem attribute is nothing but another way to express the
4
The mmap test uses PROT_BTI and does not require special compiler support.
4
PA range of a VM. To support HW that has a smaller PA range then
5
what QEMU assumes, pass this PA range to the virt_set_memmap()
6
function, allowing it to correctly exclude highmem devices
7
if they are outside of the PA range.
5
8
6
Acked-by: Alex Bennée <alex.bennee@linaro.org>
9
Signed-off-by: Marc Zyngier <maz@kernel.org>
7
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
10
Reviewed-by: Eric Auger <eric.auger@redhat.com>
8
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
11
Message-id: 20220114140741.1358263-5-maz@kernel.org
9
Message-id: 20201021173749.111103-13-richard.henderson@linaro.org
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
---
13
---
12
tests/tcg/aarch64/bti-1.c | 62 ++++++++++++++++
14
hw/arm/virt.c | 64 +++++++++++++++++++++++++++++++++++++++++----------
13
tests/tcg/aarch64/bti-2.c | 116 ++++++++++++++++++++++++++++++
15
1 file changed, 52 insertions(+), 12 deletions(-)
14
tests/tcg/aarch64/bti-crt.inc.c | 51 +++++++++++++
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
16
22
diff --git a/tests/tcg/aarch64/bti-1.c b/tests/tcg/aarch64/bti-1.c
17
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
23
new file mode 100644
18
index XXXXXXX..XXXXXXX 100644
24
index XXXXXXX..XXXXXXX
19
--- a/hw/arm/virt.c
25
--- /dev/null
20
+++ b/hw/arm/virt.c
26
+++ b/tests/tcg/aarch64/bti-1.c
21
@@ -XXX,XX +XXX,XX @@ static uint64_t virt_cpu_mp_affinity(VirtMachineState *vms, int idx)
27
@@ -XXX,XX +XXX,XX @@
22
return arm_cpu_mp_affinity(idx, clustersz);
28
+/*
23
}
29
+ * Branch target identification, basic notskip cases.
24
30
+ */
25
-static void virt_set_memmap(VirtMachineState *vms)
31
+
26
+static void virt_set_memmap(VirtMachineState *vms, int pa_bits)
32
+#include "bti-crt.inc.c"
27
{
33
+
28
MachineState *ms = MACHINE(vms);
34
+static void skip2_sigill(int sig, siginfo_t *info, ucontext_t *uc)
29
hwaddr base, device_memory_base, device_memory_size, memtop;
35
+{
30
@@ -XXX,XX +XXX,XX @@ static void virt_set_memmap(VirtMachineState *vms)
36
+ uc->uc_mcontext.pc += 8;
31
exit(EXIT_FAILURE);
37
+ uc->uc_mcontext.pstate = 1;
32
}
38
+}
33
39
+
34
+ /*
40
+#define NOP "nop"
35
+ * !highmem is exactly the same as limiting the PA space to 32bit,
41
+#define BTI_N "hint #32"
36
+ * irrespective of the underlying capabilities of the HW.
42
+#define BTI_C "hint #34"
37
+ */
43
+#define BTI_J "hint #36"
38
+ if (!vms->highmem) {
44
+#define BTI_JC "hint #38"
39
+ pa_bits = 32;
45
+
46
+#define BTYPE_1(DEST) \
47
+ asm("mov %0,#1; adr x16, 1f; br x16; 1: " DEST "; mov %0,#0" \
48
+ : "=r"(skipped) : : "x16")
49
+
50
+#define BTYPE_2(DEST) \
51
+ asm("mov %0,#1; adr x16, 1f; blr x16; 1: " DEST "; mov %0,#0" \
52
+ : "=r"(skipped) : : "x16", "x30")
53
+
54
+#define BTYPE_3(DEST) \
55
+ asm("mov %0,#1; adr x15, 1f; br x15; 1: " DEST "; mov %0,#0" \
56
+ : "=r"(skipped) : : "x15")
57
+
58
+#define TEST(WHICH, DEST, EXPECT) \
59
+ do { WHICH(DEST); fail += skipped ^ EXPECT; } while (0)
60
+
61
+
62
+int main()
63
+{
64
+ int fail = 0;
65
+ int skipped;
66
+
67
+ /* Signal-like with SA_SIGINFO. */
68
+ signal_info(SIGILL, skip2_sigill);
69
+
70
+ TEST(BTYPE_1, NOP, 1);
71
+ TEST(BTYPE_1, BTI_N, 1);
72
+ TEST(BTYPE_1, BTI_C, 0);
73
+ TEST(BTYPE_1, BTI_J, 0);
74
+ TEST(BTYPE_1, BTI_JC, 0);
75
+
76
+ TEST(BTYPE_2, NOP, 1);
77
+ TEST(BTYPE_2, BTI_N, 1);
78
+ TEST(BTYPE_2, BTI_C, 0);
79
+ TEST(BTYPE_2, BTI_J, 1);
80
+ TEST(BTYPE_2, BTI_JC, 0);
81
+
82
+ TEST(BTYPE_3, NOP, 1);
83
+ TEST(BTYPE_3, BTI_N, 1);
84
+ TEST(BTYPE_3, BTI_C, 1);
85
+ TEST(BTYPE_3, BTI_J, 0);
86
+ TEST(BTYPE_3, BTI_JC, 0);
87
+
88
+ return fail;
89
+}
90
diff --git a/tests/tcg/aarch64/bti-2.c b/tests/tcg/aarch64/bti-2.c
91
new file mode 100644
92
index XXXXXXX..XXXXXXX
93
--- /dev/null
94
+++ b/tests/tcg/aarch64/bti-2.c
95
@@ -XXX,XX +XXX,XX @@
96
+/*
97
+ * Branch target identification, basic notskip cases.
98
+ */
99
+
100
+#include <stdio.h>
101
+#include <signal.h>
102
+#include <string.h>
103
+#include <unistd.h>
104
+#include <sys/mman.h>
105
+
106
+#ifndef PROT_BTI
107
+#define PROT_BTI 0x10
108
+#endif
109
+
110
+static void skip2_sigill(int sig, siginfo_t *info, void *vuc)
111
+{
112
+ ucontext_t *uc = vuc;
113
+ uc->uc_mcontext.pc += 8;
114
+ uc->uc_mcontext.pstate = 1;
115
+}
116
+
117
+#define NOP "nop"
118
+#define BTI_N "hint #32"
119
+#define BTI_C "hint #34"
120
+#define BTI_J "hint #36"
121
+#define BTI_JC "hint #38"
122
+
123
+#define BTYPE_1(DEST) \
124
+ "mov x1, #1\n\t" \
125
+ "adr x16, 1f\n\t" \
126
+ "br x16\n" \
127
+"1: " DEST "\n\t" \
128
+ "mov x1, #0"
129
+
130
+#define BTYPE_2(DEST) \
131
+ "mov x1, #1\n\t" \
132
+ "adr x16, 1f\n\t" \
133
+ "blr x16\n" \
134
+"1: " DEST "\n\t" \
135
+ "mov x1, #0"
136
+
137
+#define BTYPE_3(DEST) \
138
+ "mov x1, #1\n\t" \
139
+ "adr x15, 1f\n\t" \
140
+ "br x15\n" \
141
+"1: " DEST "\n\t" \
142
+ "mov x1, #0"
143
+
144
+#define TEST(WHICH, DEST, EXPECT) \
145
+ WHICH(DEST) "\n" \
146
+ ".if " #EXPECT "\n\t" \
147
+ "eor x1, x1," #EXPECT "\n" \
148
+ ".endif\n\t" \
149
+ "add x0, x0, x1\n\t"
150
+
151
+asm("\n"
152
+"test_begin:\n\t"
153
+ BTI_C "\n\t"
154
+ "mov x2, x30\n\t"
155
+ "mov x0, #0\n\t"
156
+
157
+ TEST(BTYPE_1, NOP, 1)
158
+ TEST(BTYPE_1, BTI_N, 1)
159
+ TEST(BTYPE_1, BTI_C, 0)
160
+ TEST(BTYPE_1, BTI_J, 0)
161
+ TEST(BTYPE_1, BTI_JC, 0)
162
+
163
+ TEST(BTYPE_2, NOP, 1)
164
+ TEST(BTYPE_2, BTI_N, 1)
165
+ TEST(BTYPE_2, BTI_C, 0)
166
+ TEST(BTYPE_2, BTI_J, 1)
167
+ TEST(BTYPE_2, BTI_JC, 0)
168
+
169
+ TEST(BTYPE_3, NOP, 1)
170
+ TEST(BTYPE_3, BTI_N, 1)
171
+ TEST(BTYPE_3, BTI_C, 1)
172
+ TEST(BTYPE_3, BTI_J, 0)
173
+ TEST(BTYPE_3, BTI_JC, 0)
174
+
175
+ "ret x2\n"
176
+"test_end:"
177
+);
178
+
179
+int main()
180
+{
181
+ struct sigaction sa;
182
+ void *tb, *te;
183
+
184
+ void *p = mmap(0, getpagesize(),
185
+ PROT_EXEC | PROT_READ | PROT_WRITE | PROT_BTI,
186
+ MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
187
+ if (p == MAP_FAILED) {
188
+ perror("mmap");
189
+ return 1;
190
+ }
40
+ }
191
+
41
+
192
+ memset(&sa, 0, sizeof(sa));
42
/*
193
+ sa.sa_sigaction = skip2_sigill;
43
* We compute the base of the high IO region depending on the
194
+ sa.sa_flags = SA_SIGINFO;
44
* amount of initial and device memory. The device memory start/size
195
+ if (sigaction(SIGILL, &sa, NULL) < 0) {
45
@@ -XXX,XX +XXX,XX @@ static void virt_set_memmap(VirtMachineState *vms)
196
+ perror("sigaction");
46
197
+ return 1;
47
/* Base address of the high IO region */
48
memtop = base = device_memory_base + ROUND_UP(device_memory_size, GiB);
49
- if (!vms->highmem && memtop > 4 * GiB) {
50
- error_report("highmem=off, but memory crosses the 4GiB limit\n");
51
+ if (memtop > BIT_ULL(pa_bits)) {
52
+     error_report("Addressing limited to %d bits, but memory exceeds it by %llu bytes\n",
53
+             pa_bits, memtop - BIT_ULL(pa_bits));
54
exit(EXIT_FAILURE);
55
}
56
if (base < device_memory_base) {
57
@@ -XXX,XX +XXX,XX @@ static void virt_set_memmap(VirtMachineState *vms)
58
vms->memmap[i].size = size;
59
base += size;
60
}
61
- vms->highest_gpa = (vms->highmem ? base : memtop) - 1;
62
+
63
+ /*
64
+ * If base fits within pa_bits, all good. If it doesn't, limit it
65
+ * to the end of RAM, which is guaranteed to fit within pa_bits.
66
+ */
67
+ vms->highest_gpa = (base <= BIT_ULL(pa_bits) ? base : memtop) - 1;
68
+
69
if (device_memory_size > 0) {
70
ms->device_memory = g_malloc0(sizeof(*ms->device_memory));
71
ms->device_memory->base = device_memory_base;
72
@@ -XXX,XX +XXX,XX @@ static void machvirt_init(MachineState *machine)
73
unsigned int smp_cpus = machine->smp.cpus;
74
unsigned int max_cpus = machine->smp.max_cpus;
75
76
+ if (!cpu_type_valid(machine->cpu_type)) {
77
+ error_report("mach-virt: CPU type %s not supported", machine->cpu_type);
78
+ exit(1);
198
+ }
79
+ }
199
+
80
+
200
+ /*
81
+ possible_cpus = mc->possible_cpu_arch_ids(machine);
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
+
82
+
208
+ memcpy(p, tb, te - tb);
83
/*
84
* In accelerated mode, the memory map is computed earlier in kvm_type()
85
* to create a VM with the right number of IPA bits.
86
*/
87
if (!vms->memmap) {
88
- virt_set_memmap(vms);
89
+ Object *cpuobj;
90
+ ARMCPU *armcpu;
91
+ int pa_bits;
209
+
92
+
210
+ return ((int (*)(void))p)();
93
+ /*
211
+}
94
+ * Instanciate a temporary CPU object to find out about what
212
diff --git a/tests/tcg/aarch64/bti-crt.inc.c b/tests/tcg/aarch64/bti-crt.inc.c
95
+ * we are about to deal with. Once this is done, get rid of
213
new file mode 100644
96
+ * the object.
214
index XXXXXXX..XXXXXXX
97
+ */
215
--- /dev/null
98
+ cpuobj = object_new(possible_cpus->cpus[0].type);
216
+++ b/tests/tcg/aarch64/bti-crt.inc.c
99
+ armcpu = ARM_CPU(cpuobj);
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
+
100
+
225
+#include <stdlib.h>
101
+ if (object_property_get_bool(cpuobj, "aarch64", NULL)) {
226
+#include <signal.h>
102
+ pa_bits = arm_pamax(armcpu);
227
+#include <ucontext.h>
103
+ } else if (arm_feature(&armcpu->env, ARM_FEATURE_LPAE)) {
228
+#include <asm/unistd.h>
104
+ /* v7 with LPAE */
105
+ pa_bits = 40;
106
+ } else {
107
+ /* Anything else */
108
+ pa_bits = 32;
109
+ }
229
+
110
+
230
+int main(void);
111
+ object_unref(cpuobj);
231
+
112
+
232
+void _start(void)
113
+ virt_set_memmap(vms, pa_bits);
233
+{
114
}
234
+ exit(main());
115
235
+}
116
/* We can probe only here because during property set
236
+
117
@@ -XXX,XX +XXX,XX @@ static void machvirt_init(MachineState *machine)
237
+void exit(int ret)
118
*/
238
+{
119
finalize_gic_version(vms);
239
+ register int x0 __asm__("x0") = ret;
120
240
+ register int x8 __asm__("x8") = __NR_exit;
121
- if (!cpu_type_valid(machine->cpu_type)) {
241
+
122
- error_report("mach-virt: CPU type %s not supported", machine->cpu_type);
242
+ asm volatile("svc #0" : : "r"(x0), "r"(x8));
123
- exit(1);
243
+ __builtin_unreachable();
124
- }
244
+}
125
-
245
+
126
if (vms->secure) {
246
+/*
127
/*
247
+ * Irritatingly, the user API struct sigaction does not match the
128
* The Secure view of the world is the same as the NonSecure,
248
+ * kernel API struct sigaction. So for simplicity, isolate the
129
@@ -XXX,XX +XXX,XX @@ static void machvirt_init(MachineState *machine)
249
+ * kernel ABI here, and make this act like signal.
130
250
+ */
131
create_fdt(vms);
251
+void signal_info(int sig, void (*fn)(int, siginfo_t *, ucontext_t *))
132
252
+{
133
- possible_cpus = mc->possible_cpu_arch_ids(machine);
253
+ struct kernel_sigaction {
134
assert(possible_cpus->len == max_cpus);
254
+ void (*handler)(int, siginfo_t *, ucontext_t *);
135
for (n = 0; n < possible_cpus->len; n++) {
255
+ unsigned long flags;
136
Object *cpuobj;
256
+ unsigned long restorer;
137
@@ -XXX,XX +XXX,XX @@ static int virt_kvm_type(MachineState *ms, const char *type_str)
257
+ unsigned long mask;
138
max_vm_pa_size = kvm_arm_get_max_vm_ipa_size(ms, &fixed_ipa);
258
+ } sa = { fn, SA_SIGINFO, 0, 0 };
139
259
+
140
/* we freeze the memory map to compute the highest gpa */
260
+ register int x0 __asm__("x0") = sig;
141
- virt_set_memmap(vms);
261
+ register void *x1 __asm__("x1") = &sa;
142
+ virt_set_memmap(vms, max_vm_pa_size);
262
+ register void *x2 __asm__("x2") = 0;
143
263
+ register int x3 __asm__("x3") = sizeof(unsigned long);
144
requested_pa_size = 64 - clz64(vms->highest_gpa);
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
145
305
--
146
--
306
2.20.1
147
2.25.1
307
148
308
149
diff view generated by jsdifflib
1
From: Havard Skinnemoen <hskinnemoen@google.com>
1
From: Marc Zyngier <maz@kernel.org>
2
2
3
The NPCM730 and NPCM750 chips have a single USB host port shared between
3
In order to only keep the highmem devices that actually fit in
4
a USB 2.0 EHCI host controller and a USB 1.1 OHCI host controller. This
4
the PA range, check their location against the range and update
5
adds support for both of them.
5
highest_gpa if they fit. If they don't, mark them as disabled.
6
6
7
Testing notes:
7
Signed-off-by: Marc Zyngier <maz@kernel.org>
8
* With -device usb-kbd, qemu will automatically insert a full-speed
8
Reviewed-by: Eric Auger <eric.auger@redhat.com>
9
hub, and the keyboard becomes controlled by the OHCI controller.
9
Message-id: 20220114140741.1358263-6-maz@kernel.org
10
* With -device usb-kbd,bus=usb-bus.0,port=1, the keyboard is directly
11
attached to the port without any hubs, and the device becomes
12
controlled by the EHCI controller since it's high speed capable.
13
* With -device usb-kbd,bus=usb-bus.0,port=1,usb_version=1, the
14
keyboard is directly attached to the port, but it only advertises
15
itself as full-speed capable, so it becomes controlled by the OHCI
16
controller.
17
18
In all cases, the keyboard device enumerates correctly.
19
20
Reviewed-by: Tyrone Ting <kfting@nuvoton.com>
21
Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
22
Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
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/virt.c | 34 ++++++++++++++++++++++++++++------
26
hw/usb/hcd-ehci.h | 1 +
13
1 file changed, 28 insertions(+), 6 deletions(-)
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/virt.c b/hw/arm/virt.c
33
index XXXXXXX..XXXXXXX 100644
16
index XXXXXXX..XXXXXXX 100644
34
--- a/docs/system/arm/nuvoton.rst
17
--- a/hw/arm/virt.c
35
+++ b/docs/system/arm/nuvoton.rst
18
+++ b/hw/arm/virt.c
36
@@ -XXX,XX +XXX,XX @@ Supported devices
19
@@ -XXX,XX +XXX,XX @@ static void virt_set_memmap(VirtMachineState *vms, int pa_bits)
37
* OTP controllers (no protection features)
20
base = vms->memmap[VIRT_MEM].base + LEGACY_RAMLIMIT_BYTES;
38
* Flash Interface Unit (FIU; no protection features)
21
}
39
* Random Number Generator (RNG)
22
40
+ * USB host (USBH)
23
+ /* We know for sure that at least the memory fits in the PA space */
41
24
+ vms->highest_gpa = memtop - 1;
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 @@
69
#include "hw/nvram/npcm7xx_otp.h"
70
#include "hw/timer/npcm7xx_timer.h"
71
#include "hw/ssi/npcm7xx_fiu.h"
72
+#include "hw/usb/hcd-ehci.h"
73
+#include "hw/usb/hcd-ohci.h"
74
#include "target/arm/cpu.h"
75
76
#define NPCM7XX_MAX_NUM_CPUS (2)
77
@@ -XXX,XX +XXX,XX @@ typedef struct NPCM7xxState {
78
NPCM7xxOTPState fuse_array;
79
NPCM7xxMCState mc;
80
NPCM7xxRNGState rng;
81
+ EHCISysBusState ehci;
82
+ OHCISysBusState ohci;
83
NPCM7xxFIUState fiu[2];
84
} NPCM7xxState;
85
86
diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c
87
index XXXXXXX..XXXXXXX 100644
88
--- a/hw/arm/npcm7xx.c
89
+++ b/hw/arm/npcm7xx.c
90
@@ -XXX,XX +XXX,XX @@
91
#define NPCM7XX_MC_BA (0xf0824000)
92
#define NPCM7XX_RNG_BA (0xf000b000)
93
94
+/* USB Host modules */
95
+#define NPCM7XX_EHCI_BA (0xf0806000)
96
+#define NPCM7XX_OHCI_BA (0xf0807000)
97
+
25
+
98
/* Internal AHB SRAM */
26
for (i = VIRT_LOWMEMMAP_LAST; i < ARRAY_SIZE(extended_memmap); i++) {
99
#define NPCM7XX_RAM3_BA (0xc0008000)
27
hwaddr size = extended_memmap[i].size;
100
#define NPCM7XX_RAM3_SZ (4 * KiB)
28
+ bool fits;
101
@@ -XXX,XX +XXX,XX @@ enum NPCM7xxInterrupt {
29
102
NPCM7XX_WDG0_IRQ = 47, /* Timer Module 0 Watchdog */
30
base = ROUND_UP(base, size);
103
NPCM7XX_WDG1_IRQ, /* Timer Module 1 Watchdog */
31
vms->memmap[i].base = base;
104
NPCM7XX_WDG2_IRQ, /* Timer Module 2 Watchdog */
32
vms->memmap[i].size = size;
105
+ NPCM7XX_EHCI_IRQ = 61,
33
+
106
+ NPCM7XX_OHCI_IRQ = 62,
34
+ /*
107
};
35
+ * Check each device to see if they fit in the PA space,
108
36
+ * moving highest_gpa as we go.
109
/* Total number of GIC interrupts, including internal Cortex-A9 interrupts. */
37
+ *
110
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_init(Object *obj)
38
+ * For each device that doesn't fit, disable it.
111
object_initialize_child(obj, "tim[*]", &s->tim[i], TYPE_NPCM7XX_TIMER);
39
+ */
40
+ fits = (base + size) <= BIT_ULL(pa_bits);
41
+ if (fits) {
42
+ vms->highest_gpa = base + size - 1;
43
+ }
44
+
45
+ switch (i) {
46
+ case VIRT_HIGH_GIC_REDIST2:
47
+ vms->highmem_redists &= fits;
48
+ break;
49
+ case VIRT_HIGH_PCIE_ECAM:
50
+ vms->highmem_ecam &= fits;
51
+ break;
52
+ case VIRT_HIGH_PCIE_MMIO:
53
+ vms->highmem_mmio &= fits;
54
+ break;
55
+ }
56
+
57
base += size;
112
}
58
}
113
59
114
+ object_initialize_child(obj, "ehci", &s->ehci, TYPE_NPCM7XX_EHCI);
60
- /*
115
+ object_initialize_child(obj, "ohci", &s->ohci, TYPE_SYSBUS_OHCI);
61
- * If base fits within pa_bits, all good. If it doesn't, limit it
116
+
62
- * to the end of RAM, which is guaranteed to fit within pa_bits.
117
QEMU_BUILD_BUG_ON(ARRAY_SIZE(npcm7xx_fiu) != ARRAY_SIZE(s->fiu));
63
- */
118
for (i = 0; i < ARRAY_SIZE(s->fiu); i++) {
64
- vms->highest_gpa = (base <= BIT_ULL(pa_bits) ? base : memtop) - 1;
119
object_initialize_child(obj, npcm7xx_fiu[i].name, &s->fiu[i],
65
-
120
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp)
66
if (device_memory_size > 0) {
121
sysbus_realize(SYS_BUS_DEVICE(&s->rng), &error_abort);
67
ms->device_memory = g_malloc0(sizeof(*ms->device_memory));
122
sysbus_mmio_map(SYS_BUS_DEVICE(&s->rng), 0, NPCM7XX_RNG_BA);
68
ms->device_memory->base = device_memory_base;
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
+};
177
+
178
static void ehci_tegra2_class_init(ObjectClass *oc, void *data)
179
{
180
SysBusEHCIClass *sec = SYS_BUS_EHCI_CLASS(oc);
181
@@ -XXX,XX +XXX,XX @@ static void ehci_sysbus_register_types(void)
182
type_register_static(&ehci_platform_type_info);
183
type_register_static(&ehci_exynos4210_type_info);
184
type_register_static(&ehci_aw_h3_type_info);
185
+ type_register_static(&ehci_npcm7xx_type_info);
186
type_register_static(&ehci_tegra2_type_info);
187
type_register_static(&ehci_ppc4xx_type_info);
188
type_register_static(&ehci_fusbh200_type_info);
189
--
69
--
190
2.20.1
70
2.25.1
191
71
192
72
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
1
From: Marc Zyngier <maz@kernel.org>
2
2
3
It makes no sense to set enabled-cpus=0 on single core SoCs.
3
Now that the devices present in the extended memory map are checked
4
against the available PA space and disabled when they don't fit,
5
there is no need to keep the same checks against highmem, as
6
highmem really is a shortcut for the PA space being 32bit.
4
7
5
Reviewed-by: Luc Michel <luc.michel@greensocs.com>
8
Reviewed-by: Eric Auger <eric.auger@redhat.com>
6
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
9
Signed-off-by: Marc Zyngier <maz@kernel.org>
7
Message-id: 20201024170127.3592182-5-f4bug@amsat.org
10
Message-id: 20220114140741.1358263-7-maz@kernel.org
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
---
12
---
10
hw/arm/bcm2836.c | 15 +++++++--------
13
hw/arm/virt-acpi-build.c | 2 --
11
1 file changed, 7 insertions(+), 8 deletions(-)
14
hw/arm/virt.c | 5 +----
15
2 files changed, 1 insertion(+), 6 deletions(-)
12
16
13
diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c
17
diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c
14
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
15
--- a/hw/arm/bcm2836.c
19
--- a/hw/arm/virt-acpi-build.c
16
+++ b/hw/arm/bcm2836.c
20
+++ b/hw/arm/virt-acpi-build.c
17
@@ -XXX,XX +XXX,XX @@ typedef struct BCM283XClass {
21
@@ -XXX,XX +XXX,XX @@ void virt_acpi_build(VirtMachineState *vms, AcpiBuildTables *tables)
18
#define BCM283X_GET_CLASS(obj) \
22
acpi_add_table(table_offsets, tables_blob);
19
OBJECT_GET_CLASS(BCM283XClass, (obj), TYPE_BCM283X)
23
build_fadt_rev5(tables_blob, tables->linker, vms, dsdt);
20
24
21
+static Property bcm2836_enabled_cores_property =
25
- vms->highmem_redists &= vms->highmem;
22
+ DEFINE_PROP_UINT32("enabled-cpus", BCM283XState, enabled_cpus, 0);
26
-
23
+
27
acpi_add_table(table_offsets, tables_blob);
24
static void bcm2836_init(Object *obj)
28
build_madt(tables_blob, tables->linker, vms);
25
{
29
26
BCM283XState *s = BCM283X(obj);
30
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
27
@@ -XXX,XX +XXX,XX @@ static void bcm2836_init(Object *obj)
31
index XXXXXXX..XXXXXXX 100644
28
object_initialize_child(obj, "cpu[*]", &s->cpu[n].core,
32
--- a/hw/arm/virt.c
29
bc->cpu_type);
33
+++ b/hw/arm/virt.c
34
@@ -XXX,XX +XXX,XX @@ static void machvirt_init(MachineState *machine)
35
36
virt_flash_fdt(vms, sysmem, secure_sysmem ?: sysmem);
37
38
- vms->highmem_mmio &= vms->highmem;
39
- vms->highmem_redists &= vms->highmem;
40
-
41
create_gic(vms, sysmem);
42
43
virt_cpu_post_init(vms, sysmem);
44
@@ -XXX,XX +XXX,XX @@ static void machvirt_init(MachineState *machine)
45
machine->ram_size, "mach-virt.tag");
30
}
46
}
31
+ if (bc->core_count > 1) {
47
32
+ qdev_property_add_static(DEVICE(obj), &bcm2836_enabled_cores_property);
48
- vms->highmem_ecam &= vms->highmem && (!firmware_loaded || aarch64);
33
+ qdev_prop_set_uint32(DEVICE(obj), "enabled-cpus", bc->core_count);
49
+ vms->highmem_ecam &= (!firmware_loaded || aarch64);
34
+ }
50
35
51
create_rtc(vms);
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
52
67
--
53
--
68
2.20.1
54
2.25.1
69
55
70
56
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
From: Patrick Venture <venture@google.com>
2
2
3
Use the new generic support for NT_GNU_PROPERTY_TYPE_0.
3
Reviewed-by: Hao Wu <wuhaotsh@google.com>
4
4
Signed-off-by: Patrick Venture <venture@google.com>
5
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
5
Message-id: 20220111172338.1525587-1-venture@google.com
6
Message-id: 20201021173749.111103-12-richard.henderson@linaro.org
7
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
6
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/elfload.c | 48 ++++++++++++++++++++++++++++++++++++++++++--
9
hw/arm/npcm7xx_boards.c | 10 +++++++++-
11
1 file changed, 46 insertions(+), 2 deletions(-)
10
1 file changed, 9 insertions(+), 1 deletion(-)
12
11
13
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
12
diff --git a/hw/arm/npcm7xx_boards.c b/hw/arm/npcm7xx_boards.c
14
index XXXXXXX..XXXXXXX 100644
13
index XXXXXXX..XXXXXXX 100644
15
--- a/linux-user/elfload.c
14
--- a/hw/arm/npcm7xx_boards.c
16
+++ b/linux-user/elfload.c
15
+++ b/hw/arm/npcm7xx_boards.c
17
@@ -XXX,XX +XXX,XX @@ static void elf_core_copy_regs(target_elf_gregset_t *regs,
16
@@ -XXX,XX +XXX,XX @@ static void kudo_bmc_i2c_init(NPCM7xxState *soc)
18
17
{
19
#include "elf.h"
18
I2CSlave *i2c_mux;
20
19
21
+/* We must delay the following stanzas until after "elf.h". */
20
- i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 1), TYPE_PCA9548, 0x75);
22
+#if defined(TARGET_AARCH64)
21
+ i2c_mux = i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 1),
22
+ TYPE_PCA9548, 0x75);
23
+
23
+
24
+static bool arch_parse_elf_property(uint32_t pr_type, uint32_t pr_datasz,
24
+ /* tmp105 is compatible with the lm75 */
25
+ const uint32_t *data,
25
+ i2c_slave_create_simple(pca954x_i2c_get_bus(i2c_mux, 4), "tmp105", 0x5c);
26
+ struct image_info *info,
26
+ i2c_slave_create_simple(pca954x_i2c_get_bus(i2c_mux, 5), "tmp105", 0x5c);
27
+ Error **errp)
27
+ i2c_slave_create_simple(pca954x_i2c_get_bus(i2c_mux, 6), "tmp105", 0x5c);
28
+{
28
+ i2c_slave_create_simple(pca954x_i2c_get_bus(i2c_mux, 7), "tmp105", 0x5c);
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
+
29
+
41
+#else
30
i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 1), TYPE_PCA9548, 0x77);
42
+
31
43
static bool arch_parse_elf_property(uint32_t pr_type, uint32_t pr_datasz,
32
i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 4), TYPE_PCA9548, 0x77);
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
--
33
--
101
2.20.1
34
2.25.1
102
35
103
36
diff view generated by jsdifflib
1
From: Luc Michel <luc@lmichel.fr>
1
From: Troy Lee <troy_lee@aspeedtech.com>
2
2
3
The BCM2835 CPRMAN is the clock manager of the SoC. It is composed of a
3
Aspeed 2600 SDK enables I3C support by default. The I3C driver will try
4
main oscillator, and several sub-components (PLLs, multiplexers, ...) to
4
to reset the device controller and set it up through device address table
5
generate the BCM2835 clock tree.
5
register. This dummy model responds to these registers with default values
6
as listed in the ast2600v10 datasheet chapter 54.2.
6
7
7
This commit adds a skeleton of the CPRMAN, with a dummy register
8
This avoids a guest machine kernel panic due to referencing an
8
read/write implementation. It embeds the main oscillator (xosc) from
9
invalid kernel address if the device address table register isn't
9
which all the clocks will be derived.
10
set correctly.
10
11
11
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
12
Signed-off-by: Troy Lee <troy_lee@aspeedtech.com>
12
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
13
Reviewed-by: Graeme Gregory <quic_ggregory@quicinc.com>
13
Signed-off-by: Luc Michel <luc@lmichel.fr>
14
Reviewed-by: Cédric Le Goater <clg@kaod.org>
14
Tested-by: Guenter Roeck <linux@roeck-us.net>
15
Tested-by: Graeme Gregory <quic_ggregory@quicinc.com>
16
Message-id: 20220111084546.4145785-2-troy_lee@aspeedtech.com
17
[PMM: tidied commit message]
15
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
18
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
16
---
19
---
17
include/hw/arm/bcm2835_peripherals.h | 3 +-
20
include/hw/misc/aspeed_i3c.h | 48 +++++
18
include/hw/misc/bcm2835_cprman.h | 37 +++++
21
hw/misc/aspeed_i3c.c | 381 +++++++++++++++++++++++++++++++++++
19
include/hw/misc/bcm2835_cprman_internals.h | 24 +++
22
hw/misc/meson.build | 1 +
20
hw/arm/bcm2835_peripherals.c | 11 +-
23
hw/misc/trace-events | 6 +
21
hw/misc/bcm2835_cprman.c | 163 +++++++++++++++++++++
24
4 files changed, 436 insertions(+)
22
hw/misc/meson.build | 1 +
25
create mode 100644 include/hw/misc/aspeed_i3c.h
23
hw/misc/trace-events | 5 +
26
create mode 100644 hw/misc/aspeed_i3c.c
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
27
29
diff --git a/include/hw/arm/bcm2835_peripherals.h b/include/hw/arm/bcm2835_peripherals.h
28
diff --git a/include/hw/misc/aspeed_i3c.h b/include/hw/misc/aspeed_i3c.h
30
index XXXXXXX..XXXXXXX 100644
31
--- a/include/hw/arm/bcm2835_peripherals.h
32
+++ b/include/hw/arm/bcm2835_peripherals.h
33
@@ -XXX,XX +XXX,XX @@
34
#include "hw/misc/bcm2835_mbox.h"
35
#include "hw/misc/bcm2835_mphi.h"
36
#include "hw/misc/bcm2835_thermal.h"
37
+#include "hw/misc/bcm2835_cprman.h"
38
#include "hw/sd/sdhci.h"
39
#include "hw/sd/bcm2835_sdhost.h"
40
#include "hw/gpio/bcm2835_gpio.h"
41
@@ -XXX,XX +XXX,XX @@ struct BCM2835PeripheralState {
42
UnimplementedDeviceState txp;
43
UnimplementedDeviceState armtmr;
44
UnimplementedDeviceState powermgt;
45
- UnimplementedDeviceState cprman;
46
+ BCM2835CprmanState cprman;
47
PL011State uart0;
48
BCM2835AuxState aux;
49
BCM2835FBState fb;
50
diff --git a/include/hw/misc/bcm2835_cprman.h b/include/hw/misc/bcm2835_cprman.h
51
new file mode 100644
29
new file mode 100644
52
index XXXXXXX..XXXXXXX
30
index XXXXXXX..XXXXXXX
53
--- /dev/null
31
--- /dev/null
54
+++ b/include/hw/misc/bcm2835_cprman.h
32
+++ b/include/hw/misc/aspeed_i3c.h
55
@@ -XXX,XX +XXX,XX @@
33
@@ -XXX,XX +XXX,XX @@
56
+/*
34
+/*
57
+ * BCM2835 CPRMAN clock manager
35
+ * ASPEED I3C Controller
58
+ *
36
+ *
59
+ * Copyright (c) 2020 Luc Michel <luc@lmichel.fr>
37
+ * Copyright (C) 2021 ASPEED Technology Inc.
60
+ *
38
+ *
61
+ * SPDX-License-Identifier: GPL-2.0-or-later
39
+ * This code is licensed under the GPL version 2 or later. See
40
+ * the COPYING file in the top-level directory.
62
+ */
41
+ */
63
+
42
+
64
+#ifndef HW_MISC_CPRMAN_H
43
+#ifndef ASPEED_I3C_H
65
+#define HW_MISC_CPRMAN_H
44
+#define ASPEED_I3C_H
66
+
45
+
67
+#include "hw/sysbus.h"
46
+#include "hw/sysbus.h"
68
+#include "hw/qdev-clock.h"
47
+
69
+
48
+#define TYPE_ASPEED_I3C "aspeed.i3c"
70
+#define TYPE_BCM2835_CPRMAN "bcm2835-cprman"
49
+#define TYPE_ASPEED_I3C_DEVICE "aspeed.i3c.device"
71
+
50
+OBJECT_DECLARE_TYPE(AspeedI3CState, AspeedI3CClass, ASPEED_I3C)
72
+typedef struct BCM2835CprmanState BCM2835CprmanState;
51
+
73
+
52
+#define ASPEED_I3C_NR_REGS (0x70 >> 2)
74
+DECLARE_INSTANCE_CHECKER(BCM2835CprmanState, CPRMAN,
53
+#define ASPEED_I3C_DEVICE_NR_REGS (0x300 >> 2)
75
+ TYPE_BCM2835_CPRMAN)
54
+#define ASPEED_I3C_NR_DEVICES 6
76
+
55
+
77
+#define CPRMAN_NUM_REGS (0x2000 / sizeof(uint32_t))
56
+OBJECT_DECLARE_SIMPLE_TYPE(AspeedI3CDevice, ASPEED_I3C_DEVICE)
78
+
57
+typedef struct AspeedI3CDevice {
79
+struct BCM2835CprmanState {
58
+ /* <private> */
80
+ /*< private >*/
59
+ SysBusDevice parent;
81
+ SysBusDevice parent_obj;
60
+
82
+
61
+ /* <public> */
83
+ /*< public >*/
62
+ MemoryRegion mr;
63
+ qemu_irq irq;
64
+
65
+ uint8_t id;
66
+ uint32_t regs[ASPEED_I3C_DEVICE_NR_REGS];
67
+} AspeedI3CDevice;
68
+
69
+typedef struct AspeedI3CState {
70
+ /* <private> */
71
+ SysBusDevice parent;
72
+
73
+ /* <public> */
84
+ MemoryRegion iomem;
74
+ MemoryRegion iomem;
85
+
75
+ MemoryRegion iomem_container;
86
+ uint32_t regs[CPRMAN_NUM_REGS];
76
+ qemu_irq irq;
87
+ uint32_t xosc_freq;
77
+
88
+
78
+ uint32_t regs[ASPEED_I3C_NR_REGS];
89
+ Clock *xosc;
79
+ AspeedI3CDevice devices[ASPEED_I3C_NR_DEVICES];
90
+};
80
+} AspeedI3CState;
91
+
81
+#endif /* ASPEED_I3C_H */
92
+#endif
82
diff --git a/hw/misc/aspeed_i3c.c b/hw/misc/aspeed_i3c.c
93
diff --git a/include/hw/misc/bcm2835_cprman_internals.h b/include/hw/misc/bcm2835_cprman_internals.h
94
new file mode 100644
83
new file mode 100644
95
index XXXXXXX..XXXXXXX
84
index XXXXXXX..XXXXXXX
96
--- /dev/null
85
--- /dev/null
97
+++ b/include/hw/misc/bcm2835_cprman_internals.h
86
+++ b/hw/misc/aspeed_i3c.c
98
@@ -XXX,XX +XXX,XX @@
87
@@ -XXX,XX +XXX,XX @@
99
+/*
88
+/*
100
+ * BCM2835 CPRMAN clock manager
89
+ * ASPEED I3C Controller
101
+ *
90
+ *
102
+ * Copyright (c) 2020 Luc Michel <luc@lmichel.fr>
91
+ * Copyright (C) 2021 ASPEED Technology Inc.
103
+ *
92
+ *
104
+ * SPDX-License-Identifier: GPL-2.0-or-later
93
+ * This code is licensed under the GPL version 2 or later. See
105
+ */
94
+ * the COPYING file in the top-level directory.
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;
139
}
140
141
+ /* CPRMAN clock manager */
142
+ if (!sysbus_realize(SYS_BUS_DEVICE(&s->cprman), errp)) {
143
+ return;
144
+ }
145
+ memory_region_add_subregion(&s->peri_mr, CPRMAN_OFFSET,
146
+ sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->cprman), 0));
147
+
148
memory_region_add_subregion(&s->peri_mr, ARMCTRL_IC_OFFSET,
149
sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->ic), 0));
150
sysbus_pass_irq(SYS_BUS_DEVICE(s), SYS_BUS_DEVICE(&s->ic));
151
@@ -XXX,XX +XXX,XX @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)
152
create_unimp(s, &s->txp, "bcm2835-txp", TXP_OFFSET, 0x1000);
153
create_unimp(s, &s->armtmr, "bcm2835-sp804", ARMCTRL_TIMER0_1_OFFSET, 0x40);
154
create_unimp(s, &s->powermgt, "bcm2835-powermgt", PM_OFFSET, 0x114);
155
- create_unimp(s, &s->cprman, "bcm2835-cprman", CPRMAN_OFFSET, 0x2000);
156
create_unimp(s, &s->i2s, "bcm2835-i2s", I2S_OFFSET, 0x100);
157
create_unimp(s, &s->smi, "bcm2835-smi", SMI_OFFSET, 0x100);
158
create_unimp(s, &s->spi[0], "bcm2835-spi0", SPI0_OFFSET, 0x20);
159
diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c
160
new file mode 100644
161
index XXXXXXX..XXXXXXX
162
--- /dev/null
163
+++ b/hw/misc/bcm2835_cprman.c
164
@@ -XXX,XX +XXX,XX @@
165
+/*
166
+ * BCM2835 CPRMAN clock manager
167
+ *
168
+ * Copyright (c) 2020 Luc Michel <luc@lmichel.fr>
169
+ *
170
+ * SPDX-License-Identifier: GPL-2.0-or-later
171
+ */
172
+
173
+/*
174
+ * This peripheral is roughly divided into 3 main parts:
175
+ * - the PLLs
176
+ * - the PLL channels
177
+ * - the clock muxes
178
+ *
179
+ * A main oscillator (xosc) feeds all the PLLs. Each PLLs has one or more
180
+ * channels. Those channel are then connected to the clock muxes. Each mux has
181
+ * multiples sources (usually the xosc, some of the PLL channels and some "test
182
+ * debug" clocks). A mux is configured to select a given source through its
183
+ * control register. Each mux has one output clock that also goes out of the
184
+ * CPRMAN. This output clock usually connects to another peripheral in the SoC
185
+ * (so a given mux is dedicated to a peripheral).
186
+ *
187
+ * At each level (PLL, channel and mux), the clock can be altered through
188
+ * dividers (and multipliers in case of the PLLs), and can be disabled (in this
189
+ * case, the next levels see no clock).
190
+ *
191
+ * This can be sum-up as follows (this is an example and not the actual BCM2835
192
+ * clock tree):
193
+ *
194
+ * /-->[PLL]-|->[PLL channel]--... [mux]--> to peripherals
195
+ * | |->[PLL channel] muxes takes [mux]
196
+ * | \->[PLL channel] inputs from [mux]
197
+ * | some channels [mux]
198
+ * [xosc]---|-->[PLL]-|->[PLL channel] and other srcs [mux]
199
+ * | \->[PLL channel] ...-->[mux]
200
+ * | [mux]
201
+ * \-->[PLL]--->[PLL channel] [mux]
202
+ *
203
+ * The page at https://elinux.org/The_Undocumented_Pi gives the actual clock
204
+ * tree configuration.
205
+ */
95
+ */
206
+
96
+
207
+#include "qemu/osdep.h"
97
+#include "qemu/osdep.h"
208
+#include "qemu/log.h"
98
+#include "qemu/log.h"
99
+#include "qemu/error-report.h"
100
+#include "hw/misc/aspeed_i3c.h"
101
+#include "hw/registerfields.h"
102
+#include "hw/qdev-properties.h"
103
+#include "qapi/error.h"
209
+#include "migration/vmstate.h"
104
+#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"
105
+#include "trace.h"
214
+
106
+
215
+/* CPRMAN "top level" model */
107
+/* I3C Controller Registers */
216
+
108
+REG32(I3C1_REG0, 0x10)
217
+static uint64_t cprman_read(void *opaque, hwaddr offset,
109
+REG32(I3C1_REG1, 0x14)
218
+ unsigned size)
110
+ FIELD(I3C1_REG1, I2C_MODE, 0, 1)
219
+{
111
+ FIELD(I3C1_REG1, SA_EN, 15, 1)
220
+ BCM2835CprmanState *s = CPRMAN(opaque);
112
+REG32(I3C2_REG0, 0x20)
221
+ uint64_t r = 0;
113
+REG32(I3C2_REG1, 0x24)
222
+ size_t idx = offset / sizeof(uint32_t);
114
+ FIELD(I3C2_REG1, I2C_MODE, 0, 1)
223
+
115
+ FIELD(I3C2_REG1, SA_EN, 15, 1)
224
+ switch (idx) {
116
+REG32(I3C3_REG0, 0x30)
117
+REG32(I3C3_REG1, 0x34)
118
+ FIELD(I3C3_REG1, I2C_MODE, 0, 1)
119
+ FIELD(I3C3_REG1, SA_EN, 15, 1)
120
+REG32(I3C4_REG0, 0x40)
121
+REG32(I3C4_REG1, 0x44)
122
+ FIELD(I3C4_REG1, I2C_MODE, 0, 1)
123
+ FIELD(I3C4_REG1, SA_EN, 15, 1)
124
+REG32(I3C5_REG0, 0x50)
125
+REG32(I3C5_REG1, 0x54)
126
+ FIELD(I3C5_REG1, I2C_MODE, 0, 1)
127
+ FIELD(I3C5_REG1, SA_EN, 15, 1)
128
+REG32(I3C6_REG0, 0x60)
129
+REG32(I3C6_REG1, 0x64)
130
+ FIELD(I3C6_REG1, I2C_MODE, 0, 1)
131
+ FIELD(I3C6_REG1, SA_EN, 15, 1)
132
+
133
+/* I3C Device Registers */
134
+REG32(DEVICE_CTRL, 0x00)
135
+REG32(DEVICE_ADDR, 0x04)
136
+REG32(HW_CAPABILITY, 0x08)
137
+REG32(COMMAND_QUEUE_PORT, 0x0c)
138
+REG32(RESPONSE_QUEUE_PORT, 0x10)
139
+REG32(RX_TX_DATA_PORT, 0x14)
140
+REG32(IBI_QUEUE_STATUS, 0x18)
141
+REG32(IBI_QUEUE_DATA, 0x18)
142
+REG32(QUEUE_THLD_CTRL, 0x1c)
143
+REG32(DATA_BUFFER_THLD_CTRL, 0x20)
144
+REG32(IBI_QUEUE_CTRL, 0x24)
145
+REG32(IBI_MR_REQ_REJECT, 0x2c)
146
+REG32(IBI_SIR_REQ_REJECT, 0x30)
147
+REG32(RESET_CTRL, 0x34)
148
+REG32(SLV_EVENT_CTRL, 0x38)
149
+REG32(INTR_STATUS, 0x3c)
150
+REG32(INTR_STATUS_EN, 0x40)
151
+REG32(INTR_SIGNAL_EN, 0x44)
152
+REG32(INTR_FORCE, 0x48)
153
+REG32(QUEUE_STATUS_LEVEL, 0x4c)
154
+REG32(DATA_BUFFER_STATUS_LEVEL, 0x50)
155
+REG32(PRESENT_STATE, 0x54)
156
+REG32(CCC_DEVICE_STATUS, 0x58)
157
+REG32(DEVICE_ADDR_TABLE_POINTER, 0x5c)
158
+ FIELD(DEVICE_ADDR_TABLE_POINTER, DEPTH, 16, 16)
159
+ FIELD(DEVICE_ADDR_TABLE_POINTER, ADDR, 0, 16)
160
+REG32(DEV_CHAR_TABLE_POINTER, 0x60)
161
+REG32(VENDOR_SPECIFIC_REG_POINTER, 0x6c)
162
+REG32(SLV_MIPI_PID_VALUE, 0x70)
163
+REG32(SLV_PID_VALUE, 0x74)
164
+REG32(SLV_CHAR_CTRL, 0x78)
165
+REG32(SLV_MAX_LEN, 0x7c)
166
+REG32(MAX_READ_TURNAROUND, 0x80)
167
+REG32(MAX_DATA_SPEED, 0x84)
168
+REG32(SLV_DEBUG_STATUS, 0x88)
169
+REG32(SLV_INTR_REQ, 0x8c)
170
+REG32(DEVICE_CTRL_EXTENDED, 0xb0)
171
+REG32(SCL_I3C_OD_TIMING, 0xb4)
172
+REG32(SCL_I3C_PP_TIMING, 0xb8)
173
+REG32(SCL_I2C_FM_TIMING, 0xbc)
174
+REG32(SCL_I2C_FMP_TIMING, 0xc0)
175
+REG32(SCL_EXT_LCNT_TIMING, 0xc8)
176
+REG32(SCL_EXT_TERMN_LCNT_TIMING, 0xcc)
177
+REG32(BUS_FREE_TIMING, 0xd4)
178
+REG32(BUS_IDLE_TIMING, 0xd8)
179
+REG32(I3C_VER_ID, 0xe0)
180
+REG32(I3C_VER_TYPE, 0xe4)
181
+REG32(EXTENDED_CAPABILITY, 0xe8)
182
+REG32(SLAVE_CONFIG, 0xec)
183
+
184
+static const uint32_t ast2600_i3c_device_resets[ASPEED_I3C_DEVICE_NR_REGS] = {
185
+ [R_HW_CAPABILITY] = 0x000e00bf,
186
+ [R_QUEUE_THLD_CTRL] = 0x01000101,
187
+ [R_I3C_VER_ID] = 0x3130302a,
188
+ [R_I3C_VER_TYPE] = 0x6c633033,
189
+ [R_DEVICE_ADDR_TABLE_POINTER] = 0x00080280,
190
+ [R_DEV_CHAR_TABLE_POINTER] = 0x00020200,
191
+ [A_VENDOR_SPECIFIC_REG_POINTER] = 0x000000b0,
192
+ [R_SLV_MAX_LEN] = 0x00ff00ff,
193
+};
194
+
195
+static uint64_t aspeed_i3c_device_read(void *opaque, hwaddr offset,
196
+ unsigned size)
197
+{
198
+ AspeedI3CDevice *s = ASPEED_I3C_DEVICE(opaque);
199
+ uint32_t addr = offset >> 2;
200
+ uint64_t value;
201
+
202
+ switch (addr) {
203
+ case R_COMMAND_QUEUE_PORT:
204
+ value = 0;
205
+ break;
225
+ default:
206
+ default:
226
+ r = s->regs[idx];
207
+ value = s->regs[addr];
227
+ }
208
+ break;
228
+
209
+ }
229
+ trace_bcm2835_cprman_read(offset, r);
210
+
230
+ return r;
211
+ trace_aspeed_i3c_device_read(s->id, offset, value);
231
+}
212
+
232
+
213
+ return value;
233
+static void cprman_write(void *opaque, hwaddr offset,
214
+}
234
+ uint64_t value, unsigned size)
215
+
235
+{
216
+static void aspeed_i3c_device_write(void *opaque, hwaddr offset,
236
+ BCM2835CprmanState *s = CPRMAN(opaque);
217
+ uint64_t value, unsigned size)
237
+ size_t idx = offset / sizeof(uint32_t);
218
+{
238
+
219
+ AspeedI3CDevice *s = ASPEED_I3C_DEVICE(opaque);
239
+ if (FIELD_EX32(value, CPRMAN, PASSWORD) != CPRMAN_PASSWORD) {
220
+ uint32_t addr = offset >> 2;
240
+ trace_bcm2835_cprman_write_invalid_magic(offset, value);
221
+
241
+ return;
222
+ trace_aspeed_i3c_device_write(s->id, offset, value);
242
+ }
223
+
243
+
224
+ switch (addr) {
244
+ value &= ~R_CPRMAN_PASSWORD_MASK;
225
+ case R_HW_CAPABILITY:
245
+
226
+ case R_RESPONSE_QUEUE_PORT:
246
+ trace_bcm2835_cprman_write(offset, value);
227
+ case R_IBI_QUEUE_DATA:
247
+ s->regs[idx] = value;
228
+ case R_QUEUE_STATUS_LEVEL:
248
+
229
+ case R_PRESENT_STATE:
249
+}
230
+ case R_CCC_DEVICE_STATUS:
250
+
231
+ case R_DEVICE_ADDR_TABLE_POINTER:
251
+static const MemoryRegionOps cprman_ops = {
232
+ case R_VENDOR_SPECIFIC_REG_POINTER:
252
+ .read = cprman_read,
233
+ case R_SLV_CHAR_CTRL:
253
+ .write = cprman_write,
234
+ case R_SLV_MAX_LEN:
235
+ case R_MAX_READ_TURNAROUND:
236
+ case R_I3C_VER_ID:
237
+ case R_I3C_VER_TYPE:
238
+ case R_EXTENDED_CAPABILITY:
239
+ qemu_log_mask(LOG_GUEST_ERROR,
240
+ "%s: write to readonly register[%02lx] = %08lx\n",
241
+ __func__, offset, value);
242
+ break;
243
+ case R_RX_TX_DATA_PORT:
244
+ break;
245
+ case R_RESET_CTRL:
246
+ break;
247
+ default:
248
+ s->regs[addr] = value;
249
+ break;
250
+ }
251
+}
252
+
253
+static const VMStateDescription aspeed_i3c_device_vmstate = {
254
+ .name = TYPE_ASPEED_I3C,
255
+ .version_id = 1,
256
+ .minimum_version_id = 1,
257
+ .fields = (VMStateField[]){
258
+ VMSTATE_UINT32_ARRAY(regs, AspeedI3CDevice, ASPEED_I3C_DEVICE_NR_REGS),
259
+ VMSTATE_END_OF_LIST(),
260
+ }
261
+};
262
+
263
+static const MemoryRegionOps aspeed_i3c_device_ops = {
264
+ .read = aspeed_i3c_device_read,
265
+ .write = aspeed_i3c_device_write,
266
+ .endianness = DEVICE_LITTLE_ENDIAN,
267
+};
268
+
269
+static void aspeed_i3c_device_reset(DeviceState *dev)
270
+{
271
+ AspeedI3CDevice *s = ASPEED_I3C_DEVICE(dev);
272
+
273
+ memcpy(s->regs, ast2600_i3c_device_resets, sizeof(s->regs));
274
+}
275
+
276
+static void aspeed_i3c_device_realize(DeviceState *dev, Error **errp)
277
+{
278
+ AspeedI3CDevice *s = ASPEED_I3C_DEVICE(dev);
279
+ g_autofree char *name = g_strdup_printf(TYPE_ASPEED_I3C_DEVICE ".%d",
280
+ s->id);
281
+
282
+ sysbus_init_irq(SYS_BUS_DEVICE(dev), &s->irq);
283
+
284
+ memory_region_init_io(&s->mr, OBJECT(s), &aspeed_i3c_device_ops,
285
+ s, name, ASPEED_I3C_DEVICE_NR_REGS << 2);
286
+}
287
+
288
+static uint64_t aspeed_i3c_read(void *opaque, hwaddr addr, unsigned int size)
289
+{
290
+ AspeedI3CState *s = ASPEED_I3C(opaque);
291
+ uint64_t val = 0;
292
+
293
+ val = s->regs[addr >> 2];
294
+
295
+ trace_aspeed_i3c_read(addr, val);
296
+
297
+ return val;
298
+}
299
+
300
+static void aspeed_i3c_write(void *opaque,
301
+ hwaddr addr,
302
+ uint64_t data,
303
+ unsigned int size)
304
+{
305
+ AspeedI3CState *s = ASPEED_I3C(opaque);
306
+
307
+ trace_aspeed_i3c_write(addr, data);
308
+
309
+ addr >>= 2;
310
+
311
+ /* I3C controller register */
312
+ switch (addr) {
313
+ case R_I3C1_REG1:
314
+ case R_I3C2_REG1:
315
+ case R_I3C3_REG1:
316
+ case R_I3C4_REG1:
317
+ case R_I3C5_REG1:
318
+ case R_I3C6_REG1:
319
+ if (data & R_I3C1_REG1_I2C_MODE_MASK) {
320
+ qemu_log_mask(LOG_UNIMP,
321
+ "%s: Not support I2C mode [%08lx]=%08lx",
322
+ __func__, addr << 2, data);
323
+ break;
324
+ }
325
+ if (data & R_I3C1_REG1_SA_EN_MASK) {
326
+ qemu_log_mask(LOG_UNIMP,
327
+ "%s: Not support slave mode [%08lx]=%08lx",
328
+ __func__, addr << 2, data);
329
+ break;
330
+ }
331
+ s->regs[addr] = data;
332
+ break;
333
+ default:
334
+ s->regs[addr] = data;
335
+ break;
336
+ }
337
+}
338
+
339
+static const MemoryRegionOps aspeed_i3c_ops = {
340
+ .read = aspeed_i3c_read,
341
+ .write = aspeed_i3c_write,
254
+ .endianness = DEVICE_LITTLE_ENDIAN,
342
+ .endianness = DEVICE_LITTLE_ENDIAN,
255
+ .valid = {
343
+ .valid = {
344
+ .min_access_size = 1,
345
+ .max_access_size = 4,
346
+ }
347
+};
348
+
349
+static void aspeed_i3c_reset(DeviceState *dev)
350
+{
351
+ AspeedI3CState *s = ASPEED_I3C(dev);
352
+ memset(s->regs, 0, sizeof(s->regs));
353
+}
354
+
355
+static void aspeed_i3c_instance_init(Object *obj)
356
+{
357
+ AspeedI3CState *s = ASPEED_I3C(obj);
358
+ int i;
359
+
360
+ for (i = 0; i < ASPEED_I3C_NR_DEVICES; ++i) {
361
+ object_initialize_child(obj, "device[*]", &s->devices[i],
362
+ TYPE_ASPEED_I3C_DEVICE);
363
+ }
364
+}
365
+
366
+static void aspeed_i3c_realize(DeviceState *dev, Error **errp)
367
+{
368
+ int i;
369
+ AspeedI3CState *s = ASPEED_I3C(dev);
370
+ SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
371
+
372
+ memory_region_init(&s->iomem_container, OBJECT(s),
373
+ TYPE_ASPEED_I3C ".container", 0x8000);
374
+
375
+ sysbus_init_mmio(sbd, &s->iomem_container);
376
+
377
+ memory_region_init_io(&s->iomem, OBJECT(s), &aspeed_i3c_ops, s,
378
+ TYPE_ASPEED_I3C ".regs", ASPEED_I3C_NR_REGS << 2);
379
+
380
+ memory_region_add_subregion(&s->iomem_container, 0x0, &s->iomem);
381
+
382
+ for (i = 0; i < ASPEED_I3C_NR_DEVICES; ++i) {
383
+ Object *dev = OBJECT(&s->devices[i]);
384
+
385
+ if (!object_property_set_uint(dev, "device-id", i, errp)) {
386
+ return;
387
+ }
388
+
389
+ if (!sysbus_realize(SYS_BUS_DEVICE(dev), errp)) {
390
+ return;
391
+ }
392
+
256
+ /*
393
+ /*
257
+ * Although this hasn't been checked against real hardware, nor the
394
+ * Register Address of I3CX Device =
258
+ * information can be found in a datasheet, it seems reasonable because
395
+ * (Base Address of Global Register) + (Offset of I3CX) + Offset
259
+ * of the "PASSWORD" magic value found in every registers.
396
+ * X = 0, 1, 2, 3, 4, 5
397
+ * Offset of I3C0 = 0x2000
398
+ * Offset of I3C1 = 0x3000
399
+ * Offset of I3C2 = 0x4000
400
+ * Offset of I3C3 = 0x5000
401
+ * Offset of I3C4 = 0x6000
402
+ * Offset of I3C5 = 0x7000
260
+ */
403
+ */
261
+ .min_access_size = 4,
404
+ memory_region_add_subregion(&s->iomem_container,
262
+ .max_access_size = 4,
405
+ 0x2000 + i * 0x1000, &s->devices[i].mr);
263
+ .unaligned = false,
406
+ }
264
+ },
407
+
265
+ .impl = {
408
+}
266
+ .max_access_size = 4,
409
+
267
+ },
410
+static Property aspeed_i3c_device_properties[] = {
268
+};
411
+ DEFINE_PROP_UINT8("device-id", AspeedI3CDevice, id, 0),
269
+
412
+ DEFINE_PROP_END_OF_LIST(),
270
+static void cprman_reset(DeviceState *dev)
413
+};
271
+{
414
+
272
+ BCM2835CprmanState *s = CPRMAN(dev);
415
+static void aspeed_i3c_device_class_init(ObjectClass *klass, void *data)
273
+
416
+{
274
+ memset(s->regs, 0, sizeof(s->regs));
417
+ DeviceClass *dc = DEVICE_CLASS(klass);
275
+
418
+
276
+ clock_update_hz(s->xosc, s->xosc_freq);
419
+ dc->desc = "Aspeed I3C Device";
277
+}
420
+ dc->realize = aspeed_i3c_device_realize;
278
+
421
+ dc->reset = aspeed_i3c_device_reset;
279
+static void cprman_init(Object *obj)
422
+ device_class_set_props(dc, aspeed_i3c_device_properties);
280
+{
423
+}
281
+ BCM2835CprmanState *s = CPRMAN(obj);
424
+
282
+
425
+static const TypeInfo aspeed_i3c_device_info = {
283
+ s->xosc = clock_new(obj, "xosc");
426
+ .name = TYPE_ASPEED_I3C_DEVICE,
284
+
427
+ .parent = TYPE_SYS_BUS_DEVICE,
285
+ memory_region_init_io(&s->iomem, obj, &cprman_ops,
428
+ .instance_size = sizeof(AspeedI3CDevice),
286
+ s, "bcm2835-cprman", 0x2000);
429
+ .class_init = aspeed_i3c_device_class_init,
287
+ sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->iomem);
430
+};
288
+}
431
+
289
+
432
+static const VMStateDescription vmstate_aspeed_i3c = {
290
+static const VMStateDescription cprman_vmstate = {
433
+ .name = TYPE_ASPEED_I3C,
291
+ .name = TYPE_BCM2835_CPRMAN,
292
+ .version_id = 1,
434
+ .version_id = 1,
293
+ .minimum_version_id = 1,
435
+ .minimum_version_id = 1,
294
+ .fields = (VMStateField[]) {
436
+ .fields = (VMStateField[]) {
295
+ VMSTATE_UINT32_ARRAY(regs, BCM2835CprmanState, CPRMAN_NUM_REGS),
437
+ VMSTATE_UINT32_ARRAY(regs, AspeedI3CState, ASPEED_I3C_NR_REGS),
296
+ VMSTATE_END_OF_LIST()
438
+ VMSTATE_STRUCT_ARRAY(devices, AspeedI3CState, ASPEED_I3C_NR_DEVICES, 1,
297
+ }
439
+ aspeed_i3c_device_vmstate, AspeedI3CDevice),
298
+};
440
+ VMSTATE_END_OF_LIST(),
299
+
441
+ }
300
+static Property cprman_properties[] = {
442
+};
301
+ DEFINE_PROP_UINT32("xosc-freq-hz", BCM2835CprmanState, xosc_freq, 19200000),
443
+
302
+ DEFINE_PROP_END_OF_LIST()
444
+static void aspeed_i3c_class_init(ObjectClass *klass, void *data)
303
+};
304
+
305
+static void cprman_class_init(ObjectClass *klass, void *data)
306
+{
445
+{
307
+ DeviceClass *dc = DEVICE_CLASS(klass);
446
+ DeviceClass *dc = DEVICE_CLASS(klass);
308
+
447
+
309
+ dc->reset = cprman_reset;
448
+ dc->realize = aspeed_i3c_realize;
310
+ dc->vmsd = &cprman_vmstate;
449
+ dc->reset = aspeed_i3c_reset;
311
+ device_class_set_props(dc, cprman_properties);
450
+ dc->desc = "Aspeed I3C Controller";
312
+}
451
+ dc->vmsd = &vmstate_aspeed_i3c;
313
+
452
+}
314
+static const TypeInfo cprman_info = {
453
+
315
+ .name = TYPE_BCM2835_CPRMAN,
454
+static const TypeInfo aspeed_i3c_info = {
455
+ .name = TYPE_ASPEED_I3C,
316
+ .parent = TYPE_SYS_BUS_DEVICE,
456
+ .parent = TYPE_SYS_BUS_DEVICE,
317
+ .instance_size = sizeof(BCM2835CprmanState),
457
+ .instance_init = aspeed_i3c_instance_init,
318
+ .class_init = cprman_class_init,
458
+ .instance_size = sizeof(AspeedI3CState),
319
+ .instance_init = cprman_init,
459
+ .class_init = aspeed_i3c_class_init,
320
+};
460
+};
321
+
461
+
322
+static void cprman_register_types(void)
462
+static void aspeed_i3c_register_types(void)
323
+{
463
+{
324
+ type_register_static(&cprman_info);
464
+ type_register_static(&aspeed_i3c_device_info);
325
+}
465
+ type_register_static(&aspeed_i3c_info);
326
+
466
+}
327
+type_init(cprman_register_types);
467
+
468
+type_init(aspeed_i3c_register_types);
328
diff --git a/hw/misc/meson.build b/hw/misc/meson.build
469
diff --git a/hw/misc/meson.build b/hw/misc/meson.build
329
index XXXXXXX..XXXXXXX 100644
470
index XXXXXXX..XXXXXXX 100644
330
--- a/hw/misc/meson.build
471
--- a/hw/misc/meson.build
331
+++ b/hw/misc/meson.build
472
+++ b/hw/misc/meson.build
332
@@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_RASPI', if_true: files(
473
@@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_PVPANIC_PCI', if_true: files('pvpanic-pci.c'))
333
'bcm2835_property.c',
474
softmmu_ss.add(when: 'CONFIG_AUX', if_true: files('auxbus.c'))
334
'bcm2835_rng.c',
475
softmmu_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files(
335
'bcm2835_thermal.c',
476
'aspeed_hace.c',
336
+ 'bcm2835_cprman.c',
477
+ 'aspeed_i3c.c',
337
))
478
'aspeed_lpc.c',
338
softmmu_ss.add(when: 'CONFIG_SLAVIO', if_true: files('slavio_misc.c'))
479
'aspeed_scu.c',
339
softmmu_ss.add(when: 'CONFIG_ZYNQ', if_true: files('zynq_slcr.c', 'zynq-xadc.c'))
480
'aspeed_sdmc.c',
340
diff --git a/hw/misc/trace-events b/hw/misc/trace-events
481
diff --git a/hw/misc/trace-events b/hw/misc/trace-events
341
index XXXXXXX..XXXXXXX 100644
482
index XXXXXXX..XXXXXXX 100644
342
--- a/hw/misc/trace-events
483
--- a/hw/misc/trace-events
343
+++ b/hw/misc/trace-events
484
+++ 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
485
@@ -XXX,XX +XXX,XX @@ armsse_mhu_write(uint64_t offset, uint64_t data, unsigned size) "SSE-200 MHU wri
345
# pca9552.c
486
# aspeed_xdma.c
346
pca955x_gpio_status(const char *description, const char *buf) "%s GPIOs 0-15 [%s]"
487
aspeed_xdma_write(uint64_t offset, uint64_t data) "XDMA write: offset 0x%" PRIx64 " data 0x%" PRIx64
347
pca955x_gpio_change(const char *description, unsigned id, unsigned prev_state, unsigned current_state) "%s GPIO id:%u status: %u -> %u"
488
348
+
489
+# aspeed_i3c.c
349
+# bcm2835_cprman.c
490
+aspeed_i3c_read(uint64_t offset, uint64_t data) "I3C read: offset 0x%" PRIx64 " data 0x%" PRIx64
350
+bcm2835_cprman_read(uint64_t offset, uint64_t value) "offset:0x%" PRIx64 " value:0x%" PRIx64
491
+aspeed_i3c_write(uint64_t offset, uint64_t data) "I3C write: offset 0x%" PRIx64 " data 0x%" PRIx64
351
+bcm2835_cprman_write(uint64_t offset, uint64_t value) "offset:0x%" PRIx64 " value:0x%" PRIx64
492
+aspeed_i3c_device_read(uint32_t deviceid, uint64_t offset, uint64_t data) "I3C Dev[%u] read: offset 0x%" PRIx64 " data 0x%" PRIx64
352
+bcm2835_cprman_write_invalid_magic(uint64_t offset, uint64_t value) "offset:0x%" PRIx64 " value:0x%" PRIx64
493
+aspeed_i3c_device_write(uint32_t deviceid, uint64_t offset, uint64_t data) "I3C Dev[%u] write: offset 0x%" PRIx64 " data 0x%" PRIx64
494
+
495
# bcm2835_property.c
496
bcm2835_mbox_property(uint32_t tag, uint32_t bufsize, size_t resplen) "mbox property tag:0x%08x in_sz:%u out_sz:%zu"
497
353
--
498
--
354
2.20.1
499
2.25.1
355
500
356
501
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
1
From: Troy Lee <troy_lee@aspeedtech.com>
2
2
3
Reviewed-by: Luc Michel <luc.michel@greensocs.com>
3
Add the new i3c device to the AST2600 SoC.
4
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
4
5
Message-id: 20201024170127.3592182-7-f4bug@amsat.org
5
Signed-off-by: Troy Lee <troy_lee@aspeedtech.com>
6
Reviewed-by: Graeme Gregory <quic_ggregory@quicinc.com>
7
Reviewed-by: Cédric Le Goater <clg@kaod.org>
8
Tested-by: Graeme Gregory <quic_ggregory@quicinc.com>
9
Message-id: 20220111084546.4145785-3-troy_lee@aspeedtech.com
10
[PMM: tidied commit message]
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
---
12
---
8
include/hw/arm/bcm2836.h | 1 +
13
include/hw/arm/aspeed_soc.h | 3 +++
9
hw/arm/bcm2836.c | 34 ++++++++++++++++++++++++++++++++++
14
hw/arm/aspeed_ast2600.c | 16 ++++++++++++++++
10
hw/arm/raspi.c | 2 ++
15
2 files changed, 19 insertions(+)
11
3 files changed, 37 insertions(+)
12
16
13
diff --git a/include/hw/arm/bcm2836.h b/include/hw/arm/bcm2836.h
17
diff --git a/include/hw/arm/aspeed_soc.h b/include/hw/arm/aspeed_soc.h
14
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
15
--- a/include/hw/arm/bcm2836.h
19
--- a/include/hw/arm/aspeed_soc.h
16
+++ b/include/hw/arm/bcm2836.h
20
+++ b/include/hw/arm/aspeed_soc.h
17
@@ -XXX,XX +XXX,XX @@ OBJECT_DECLARE_TYPE(BCM283XState, BCM283XClass, BCM283X)
21
@@ -XXX,XX +XXX,XX @@
18
* them, code using these devices should always handle them via the
22
#include "hw/timer/aspeed_timer.h"
19
* BCM283x base class, so they have no BCM2836(obj) etc macros.
23
#include "hw/rtc/aspeed_rtc.h"
20
*/
24
#include "hw/i2c/aspeed_i2c.h"
21
+#define TYPE_BCM2835 "bcm2835"
25
+#include "hw/misc/aspeed_i3c.h"
22
#define TYPE_BCM2836 "bcm2836"
26
#include "hw/ssi/aspeed_smc.h"
23
#define TYPE_BCM2837 "bcm2837"
27
#include "hw/misc/aspeed_hace.h"
24
28
#include "hw/watchdog/wdt_aspeed.h"
25
diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c
29
@@ -XXX,XX +XXX,XX @@ struct AspeedSoCState {
30
AspeedRtcState rtc;
31
AspeedTimerCtrlState timerctrl;
32
AspeedI2CState i2c;
33
+ AspeedI3CState i3c;
34
AspeedSCUState scu;
35
AspeedHACEState hace;
36
AspeedXDMAState xdma;
37
@@ -XXX,XX +XXX,XX @@ enum {
38
ASPEED_DEV_HACE,
39
ASPEED_DEV_DPMCU,
40
ASPEED_DEV_DP,
41
+ ASPEED_DEV_I3C,
42
};
43
44
#endif /* ASPEED_SOC_H */
45
diff --git a/hw/arm/aspeed_ast2600.c b/hw/arm/aspeed_ast2600.c
26
index XXXXXXX..XXXXXXX 100644
46
index XXXXXXX..XXXXXXX 100644
27
--- a/hw/arm/bcm2836.c
47
--- a/hw/arm/aspeed_ast2600.c
28
+++ b/hw/arm/bcm2836.c
48
+++ b/hw/arm/aspeed_ast2600.c
29
@@ -XXX,XX +XXX,XX @@ static bool bcm283x_common_realize(DeviceState *dev, Error **errp)
49
@@ -XXX,XX +XXX,XX @@ static const hwaddr aspeed_soc_ast2600_memmap[] = {
30
return true;
50
[ASPEED_DEV_UART1] = 0x1E783000,
51
[ASPEED_DEV_UART5] = 0x1E784000,
52
[ASPEED_DEV_VUART] = 0x1E787000,
53
+ [ASPEED_DEV_I3C] = 0x1E7A0000,
54
[ASPEED_DEV_SDRAM] = 0x80000000,
55
};
56
57
@@ -XXX,XX +XXX,XX @@ static const int aspeed_soc_ast2600_irqmap[] = {
58
[ASPEED_DEV_ETH4] = 33,
59
[ASPEED_DEV_KCS] = 138, /* 138 -> 142 */
60
[ASPEED_DEV_DP] = 62,
61
+ [ASPEED_DEV_I3C] = 102, /* 102 -> 107 */
62
};
63
64
static qemu_irq aspeed_soc_get_irq(AspeedSoCState *s, int ctrl)
65
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_ast2600_init(Object *obj)
66
67
snprintf(typename, sizeof(typename), "aspeed.hace-%s", socname);
68
object_initialize_child(obj, "hace", &s->hace, typename);
69
+
70
+ object_initialize_child(obj, "i3c", &s->i3c, TYPE_ASPEED_I3C);
31
}
71
}
32
72
33
+static void bcm2835_realize(DeviceState *dev, Error **errp)
73
/*
34
+{
74
@@ -XXX,XX +XXX,XX @@ static void aspeed_soc_ast2600_realize(DeviceState *dev, Error **errp)
35
+ BCM283XState *s = BCM283X(dev);
75
sysbus_mmio_map(SYS_BUS_DEVICE(&s->hace), 0, sc->memmap[ASPEED_DEV_HACE]);
76
sysbus_connect_irq(SYS_BUS_DEVICE(&s->hace), 0,
77
aspeed_soc_get_irq(s, ASPEED_DEV_HACE));
36
+
78
+
37
+ if (!bcm283x_common_realize(dev, errp)) {
79
+ /* I3C */
80
+ if (!sysbus_realize(SYS_BUS_DEVICE(&s->i3c), errp)) {
38
+ return;
81
+ return;
39
+ }
82
+ }
40
+
83
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->i3c), 0, sc->memmap[ASPEED_DEV_I3C]);
41
+ if (!qdev_realize(DEVICE(&s->cpu[0].core), NULL, errp)) {
84
+ for (i = 0; i < ASPEED_I3C_NR_DEVICES; i++) {
42
+ return;
85
+ qemu_irq irq = qdev_get_gpio_in(DEVICE(&s->a7mpcore),
86
+ sc->irqmap[ASPEED_DEV_I3C] + i);
87
+ /* The AST2600 I3C controller has one IRQ per bus. */
88
+ sysbus_connect_irq(SYS_BUS_DEVICE(&s->i3c.devices[i]), 0, irq);
43
+ }
89
+ }
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
}
90
}
58
91
59
+static void bcm2835_class_init(ObjectClass *oc, void *data)
92
static void aspeed_soc_ast2600_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
--
93
--
105
2.20.1
94
2.25.1
106
95
107
96
diff view generated by jsdifflib
1
From: Luc Michel <luc@lmichel.fr>
1
In process_its_cmd() and process_mapti() we must check the
2
event ID against a limit defined by the size field in the DTE,
3
which specifies the number of ID bits minus one. Convert
4
this code to our num_foo convention:
5
* change the variable names
6
* use uint64_t and 1ULL when calculating the number
7
of valid event IDs, because DTE.SIZE is 5 bits and
8
so num_eventids may be up to 2^32
9
* fix the off-by-one error in the comparison
2
10
3
The CPRMAN (clock controller) was mapped at the watchdog/power manager
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
4
address. It was also split into two unimplemented peripherals (CM and
12
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
5
A2W) but this is really the same one, as shown by this extract of the
13
Message-id: 20220111171048.3545974-2-peter.maydell@linaro.org
6
Raspberry Pi 3 Linux device tree:
14
---
15
hw/intc/arm_gicv3_its.c | 18 ++++++++++--------
16
1 file changed, 10 insertions(+), 8 deletions(-)
7
17
8
watchdog@7e100000 {
18
diff --git a/hw/intc/arm_gicv3_its.c b/hw/intc/arm_gicv3_its.c
9
compatible = "brcm,bcm2835-pm\0brcm,bcm2835-pm-wdt";
10
[...]
11
reg = <0x7e100000 0x114 0x7e00a000 0x24>;
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>
28
---
29
include/hw/arm/bcm2835_peripherals.h | 2 +-
30
include/hw/arm/raspi_platform.h | 5 ++---
31
hw/arm/bcm2835_peripherals.c | 4 ++--
32
3 files changed, 5 insertions(+), 6 deletions(-)
33
34
diff --git a/include/hw/arm/bcm2835_peripherals.h b/include/hw/arm/bcm2835_peripherals.h
35
index XXXXXXX..XXXXXXX 100644
19
index XXXXXXX..XXXXXXX 100644
36
--- a/include/hw/arm/bcm2835_peripherals.h
20
--- a/hw/intc/arm_gicv3_its.c
37
+++ b/include/hw/arm/bcm2835_peripherals.h
21
+++ b/hw/intc/arm_gicv3_its.c
38
@@ -XXX,XX +XXX,XX @@ struct BCM2835PeripheralState {
22
@@ -XXX,XX +XXX,XX @@ static bool process_its_cmd(GICv3ITSState *s, uint64_t value, uint32_t offset,
39
BCM2835MphiState mphi;
23
MemTxResult res = MEMTX_OK;
40
UnimplementedDeviceState txp;
24
bool dte_valid;
41
UnimplementedDeviceState armtmr;
25
uint64_t dte = 0;
42
+ UnimplementedDeviceState powermgt;
26
- uint32_t max_eventid;
43
UnimplementedDeviceState cprman;
27
+ uint64_t num_eventids;
44
- UnimplementedDeviceState a2w;
28
uint16_t icid = 0;
45
PL011State uart0;
29
uint32_t pIntid = 0;
46
BCM2835AuxState aux;
30
bool ite_valid = false;
47
BCM2835FBState fb;
31
@@ -XXX,XX +XXX,XX @@ static bool process_its_cmd(GICv3ITSState *s, uint64_t value, uint32_t offset,
48
diff --git a/include/hw/arm/raspi_platform.h b/include/hw/arm/raspi_platform.h
32
dte_valid = FIELD_EX64(dte, DTE, VALID);
49
index XXXXXXX..XXXXXXX 100644
33
50
--- a/include/hw/arm/raspi_platform.h
34
if (dte_valid) {
51
+++ b/include/hw/arm/raspi_platform.h
35
- max_eventid = 1UL << (FIELD_EX64(dte, DTE, SIZE) + 1);
52
@@ -XXX,XX +XXX,XX @@
36
+ num_eventids = 1ULL << (FIELD_EX64(dte, DTE, SIZE) + 1);
53
#define ARMCTRL_TIMER0_1_OFFSET (ARM_OFFSET + 0x400) /* Timer 0 and 1 (SP804) */
37
54
#define ARMCTRL_0_SBM_OFFSET (ARM_OFFSET + 0x800) /* User 0 (ARM) Semaphores
38
ite_valid = get_ite(s, eventid, dte, &icid, &pIntid, &res);
55
* Doorbells & Mailboxes */
39
56
-#define CPRMAN_OFFSET 0x100000 /* Power Management, Watchdog */
40
@@ -XXX,XX +XXX,XX @@ static bool process_its_cmd(GICv3ITSState *s, uint64_t value, uint32_t offset,
57
-#define CM_OFFSET 0x101000 /* Clock Management */
41
dte_valid ? "valid" : "invalid",
58
-#define A2W_OFFSET 0x102000 /* Reset controller */
42
ite_valid ? "valid" : "invalid",
59
+#define PM_OFFSET 0x100000 /* Power Management */
43
cte_valid ? "valid" : "invalid");
60
+#define CPRMAN_OFFSET 0x101000 /* Clock Management */
44
- } else if (eventid > max_eventid) {
61
#define AVS_OFFSET 0x103000 /* Audio Video Standard */
45
+ } else if (eventid >= num_eventids) {
62
#define RNG_OFFSET 0x104000
46
qemu_log_mask(LOG_GUEST_ERROR,
63
#define GPIO_OFFSET 0x200000
47
- "%s: invalid command attributes: eventid %d > %d\n",
64
diff --git a/hw/arm/bcm2835_peripherals.c b/hw/arm/bcm2835_peripherals.c
48
- __func__, eventid, max_eventid);
65
index XXXXXXX..XXXXXXX 100644
49
+ "%s: invalid command attributes: eventid %d >= %"
66
--- a/hw/arm/bcm2835_peripherals.c
50
+ PRId64 "\n",
67
+++ b/hw/arm/bcm2835_peripherals.c
51
+ __func__, eventid, num_eventids);
68
@@ -XXX,XX +XXX,XX @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)
52
} else {
69
53
/*
70
create_unimp(s, &s->txp, "bcm2835-txp", TXP_OFFSET, 0x1000);
54
* Current implementation only supports rdbase == procnum
71
create_unimp(s, &s->armtmr, "bcm2835-sp804", ARMCTRL_TIMER0_1_OFFSET, 0x40);
55
@@ -XXX,XX +XXX,XX @@ static bool process_mapti(GICv3ITSState *s, uint64_t value, uint32_t offset,
72
- create_unimp(s, &s->cprman, "bcm2835-cprman", CPRMAN_OFFSET, 0x1000);
56
AddressSpace *as = &s->gicv3->dma_as;
73
- create_unimp(s, &s->a2w, "bcm2835-a2w", A2W_OFFSET, 0x1000);
57
uint32_t devid, eventid;
74
+ create_unimp(s, &s->powermgt, "bcm2835-powermgt", PM_OFFSET, 0x114);
58
uint32_t pIntid = 0;
75
+ create_unimp(s, &s->cprman, "bcm2835-cprman", CPRMAN_OFFSET, 0x2000);
59
- uint32_t max_eventid, max_Intid;
76
create_unimp(s, &s->i2s, "bcm2835-i2s", I2S_OFFSET, 0x100);
60
+ uint64_t num_eventids;
77
create_unimp(s, &s->smi, "bcm2835-smi", SMI_OFFSET, 0x100);
61
+ uint32_t max_Intid;
78
create_unimp(s, &s->spi[0], "bcm2835-spi0", SPI0_OFFSET, 0x20);
62
bool dte_valid;
63
MemTxResult res = MEMTX_OK;
64
uint16_t icid = 0;
65
@@ -XXX,XX +XXX,XX @@ static bool process_mapti(GICv3ITSState *s, uint64_t value, uint32_t offset,
66
return result;
67
}
68
dte_valid = FIELD_EX64(dte, DTE, VALID);
69
- max_eventid = 1UL << (FIELD_EX64(dte, DTE, SIZE) + 1);
70
+ num_eventids = 1ULL << (FIELD_EX64(dte, DTE, SIZE) + 1);
71
max_Intid = (1ULL << (GICD_TYPER_IDBITS + 1)) - 1;
72
73
if ((devid >= s->dt.num_ids) || (icid >= s->ct.num_ids)
74
- || !dte_valid || (eventid > max_eventid) ||
75
+ || !dte_valid || (eventid >= num_eventids) ||
76
(((pIntid < GICV3_LPI_INTID_START) || (pIntid > max_Intid)) &&
77
(pIntid != INTID_SPURIOUS))) {
78
qemu_log_mask(LOG_GUEST_ERROR,
79
--
79
--
80
2.20.1
80
2.25.1
81
81
82
82
diff view generated by jsdifflib
1
From: Havard Skinnemoen <hskinnemoen@google.com>
1
The bounds check on the number of interrupt IDs is correct, but
2
doesn't match our convention; change the variable name, initialize it
3
to the 2^n value rather than (2^n)-1, and use >= instead of > in the
4
comparison.
2
5
3
This allows us to reuse npcm7xx_timer_pause for the watchdog timer.
4
5
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
6
Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com>
7
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
8
Message-id: 20220111171048.3545974-3-peter.maydell@linaro.org
8
---
9
---
9
hw/timer/npcm7xx_timer.c | 6 +++---
10
hw/intc/arm_gicv3_its.c | 6 +++---
10
1 file changed, 3 insertions(+), 3 deletions(-)
11
1 file changed, 3 insertions(+), 3 deletions(-)
11
12
12
diff --git a/hw/timer/npcm7xx_timer.c b/hw/timer/npcm7xx_timer.c
13
diff --git a/hw/intc/arm_gicv3_its.c b/hw/intc/arm_gicv3_its.c
13
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
14
--- a/hw/timer/npcm7xx_timer.c
15
--- a/hw/intc/arm_gicv3_its.c
15
+++ b/hw/timer/npcm7xx_timer.c
16
+++ b/hw/intc/arm_gicv3_its.c
16
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_pause(NPCM7xxTimer *t)
17
@@ -XXX,XX +XXX,XX @@ static bool process_mapti(GICv3ITSState *s, uint64_t value, uint32_t offset,
17
timer_del(&t->qtimer);
18
uint32_t devid, eventid;
18
now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
19
uint32_t pIntid = 0;
19
t->remaining_ns = t->expires_ns - now;
20
uint64_t num_eventids;
20
- if (t->remaining_ns <= 0) {
21
- uint32_t max_Intid;
21
- npcm7xx_timer_reached_zero(t);
22
+ uint32_t num_intids;
22
- }
23
bool dte_valid;
23
}
24
MemTxResult res = MEMTX_OK;
24
25
uint16_t icid = 0;
25
/*
26
@@ -XXX,XX +XXX,XX @@ static bool process_mapti(GICv3ITSState *s, uint64_t value, uint32_t offset,
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
}
27
}
35
}
28
dte_valid = FIELD_EX64(dte, DTE, VALID);
29
num_eventids = 1ULL << (FIELD_EX64(dte, DTE, SIZE) + 1);
30
- max_Intid = (1ULL << (GICD_TYPER_IDBITS + 1)) - 1;
31
+ num_intids = 1ULL << (GICD_TYPER_IDBITS + 1);
32
33
if ((devid >= s->dt.num_ids) || (icid >= s->ct.num_ids)
34
|| !dte_valid || (eventid >= num_eventids) ||
35
- (((pIntid < GICV3_LPI_INTID_START) || (pIntid > max_Intid)) &&
36
+ (((pIntid < GICV3_LPI_INTID_START) || (pIntid >= num_intids)) &&
37
(pIntid != INTID_SPURIOUS))) {
38
qemu_log_mask(LOG_GUEST_ERROR,
39
"%s: invalid command attributes "
36
--
40
--
37
2.20.1
41
2.25.1
38
42
39
43
diff view generated by jsdifflib
1
From: Luc Michel <luc@lmichel.fr>
1
process_its_cmd() returns a bool, like all the other process_ functions.
2
However we were putting its return value into 'res', not 'result',
3
which meant we would ignore it when deciding whether to continue
4
or stall the command queue. Fix the typo.
2
5
3
The nanosecond unit greatly limits the dynamic range we can display in
6
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
4
clock value traces, for values in the order of 1GHz and more. The
7
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
5
internal representation can go way beyond this value and it is quite
8
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
6
common for today's clocks to be within those ranges.
9
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
10
Message-id: 20220111171048.3545974-4-peter.maydell@linaro.org
11
---
12
hw/intc/arm_gicv3_its.c | 4 ++--
13
1 file changed, 2 insertions(+), 2 deletions(-)
7
14
8
For example, a frequency between 500MHz+ and 1GHz will be displayed as
15
diff --git a/hw/intc/arm_gicv3_its.c b/hw/intc/arm_gicv3_its.c
9
1ns. Beyond 1GHz, it will show up as 0ns.
10
11
Replace nanosecond periods traces with frequencies in the Hz unit
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
16
index XXXXXXX..XXXXXXX 100644
27
--- a/hw/core/clock.c
17
--- a/hw/intc/arm_gicv3_its.c
28
+++ b/hw/core/clock.c
18
+++ b/hw/intc/arm_gicv3_its.c
29
@@ -XXX,XX +XXX,XX @@ bool clock_set(Clock *clk, uint64_t period)
19
@@ -XXX,XX +XXX,XX @@ static void process_cmdq(GICv3ITSState *s)
30
if (clk->period == period) {
20
31
return false;
21
switch (cmd) {
32
}
22
case GITS_CMD_INT:
33
- trace_clock_set(CLOCK_PATH(clk), CLOCK_PERIOD_TO_NS(clk->period),
23
- res = process_its_cmd(s, data, cq_offset, INTERRUPT);
34
- CLOCK_PERIOD_TO_NS(period));
24
+ result = process_its_cmd(s, data, cq_offset, INTERRUPT);
35
+ trace_clock_set(CLOCK_PATH(clk), CLOCK_PERIOD_TO_HZ(clk->period),
25
break;
36
+ CLOCK_PERIOD_TO_HZ(period));
26
case GITS_CMD_CLEAR:
37
clk->period = period;
27
- res = process_its_cmd(s, data, cq_offset, CLEAR);
38
28
+ result = process_its_cmd(s, data, cq_offset, CLEAR);
39
return true;
29
break;
40
@@ -XXX,XX +XXX,XX @@ static void clock_propagate_period(Clock *clk, bool call_callbacks)
30
case GITS_CMD_SYNC:
41
if (child->period != clk->period) {
31
/*
42
child->period = clk->period;
43
trace_clock_update(CLOCK_PATH(child), CLOCK_PATH(clk),
44
- CLOCK_PERIOD_TO_NS(clk->period),
45
+ CLOCK_PERIOD_TO_HZ(clk->period),
46
call_callbacks);
47
if (call_callbacks && child->callback) {
48
child->callback(child->callback_opaque);
49
diff --git a/hw/core/trace-events b/hw/core/trace-events
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
--
32
--
63
2.20.1
33
2.25.1
64
34
65
35
diff view generated by jsdifflib
1
In ptimer_reload(), we call the callback function provided by the
1
In process_cmdq(), we read 64 bits of the command packet, which
2
timer device that is using the ptimer. This callback might disable
2
contain the command identifier, which we then switch() on to dispatch
3
the ptimer. The code mostly handles this correctly, except that
3
to an appropriate sub-function. However, if address_space_ldq_le()
4
we'll still print the warning about "Timer with delta zero,
4
reports a memory transaction failure, we still read the command
5
disabling" if the now-disabled timer happened to be set such that it
5
identifier out of the data and switch() on it. Restructure the code
6
would fire again immediately if it were enabled (eg because the
6
so that we stop immediately (stalling the command queue) in this
7
limit/reload value is zero).
7
case.
8
9
Suppress the spurious warning message and the unnecessary
10
repeat-deletion of the underlying timer in this case.
11
8
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
13
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
10
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
14
Message-id: 20201015151829.14656-2-peter.maydell@linaro.org
11
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
12
Message-id: 20220111171048.3545974-5-peter.maydell@linaro.org
15
---
13
---
16
hw/core/ptimer.c | 4 ++++
14
hw/intc/arm_gicv3_its.c | 7 ++++++-
17
1 file changed, 4 insertions(+)
15
1 file changed, 6 insertions(+), 1 deletion(-)
18
16
19
diff --git a/hw/core/ptimer.c b/hw/core/ptimer.c
17
diff --git a/hw/intc/arm_gicv3_its.c b/hw/intc/arm_gicv3_its.c
20
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
21
--- a/hw/core/ptimer.c
19
--- a/hw/intc/arm_gicv3_its.c
22
+++ b/hw/core/ptimer.c
20
+++ b/hw/intc/arm_gicv3_its.c
23
@@ -XXX,XX +XXX,XX @@ static void ptimer_reload(ptimer_state *s, int delta_adjust)
21
@@ -XXX,XX +XXX,XX @@ static void process_cmdq(GICv3ITSState *s)
24
}
22
data = address_space_ldq_le(as, s->cq.base_addr + cq_offset,
25
23
MEMTXATTRS_UNSPECIFIED, &res);
26
if (delta == 0) {
24
if (res != MEMTX_OK) {
27
+ if (s->enabled == 0) {
25
- result = false;
28
+ /* trigger callback disabled the timer already */
26
+ s->creadr = FIELD_DP64(s->creadr, GITS_CREADR, STALLED, 1);
29
+ return;
27
+ qemu_log_mask(LOG_GUEST_ERROR,
30
+ }
28
+ "%s: could not read command at 0x%" PRIx64 "\n",
31
if (!qtest_enabled()) {
29
+ __func__, s->cq.base_addr + cq_offset);
32
fprintf(stderr, "Timer with delta zero, disabling\n");
30
+ break;
33
}
31
}
32
+
33
cmd = (data & CMD_MASK);
34
35
switch (cmd) {
34
--
36
--
35
2.20.1
37
2.25.1
36
38
37
39
diff view generated by jsdifflib
1
The armv7m systick timer is a 24-bit decrementing, wrap-on-zero,
1
When an ITS detects an error in a command, it has an
2
clear-on-write counter. Our current implementation has various
2
implementation-defined (CONSTRAINED UNPREDICTABLE) choice of whether
3
bugs and dubious workarounds in it (for instance see
3
to ignore the command, proceeding to the next one in the queue, or to
4
https://bugs.launchpad.net/qemu/+bug/1872237).
4
stall the ITS command queue, processing nothing further. The
5
5
behaviour required when the read of the command packet from memory
6
We have an implementation of a simple decrementing counter
6
fails is less clearly documented, but the same set of choices as for
7
and we put a lot of effort into making sure it handles the
7
command errors seem reasonable.
8
interesting corner cases (like "spend a cycle at 0 before
8
9
reloading") -- ptimer.
9
The intention of the QEMU implementation, as documented in the
10
10
comments, is that if we encounter a memory error reading the command
11
Rewrite the systick timer to use a ptimer rather than
11
packet or one of the various data tables then we should stall, but
12
a raw QEMU timer.
12
for command parameter errors we should ignore the queue and continue.
13
13
However, we don't actually do this. To get the desired behaviour,
14
Unfortunately this is a migration compatibility break,
14
the various process_* functions need to return true to cause
15
which will affect all M-profile boards.
15
process_cmdq() to advance to the next command and keep processing,
16
16
and false to stall command processing. What they mostly do is return
17
Among other bugs, this fixes
17
false for any kind of error.
18
https://bugs.launchpad.net/qemu/+bug/1872237 :
18
19
now writes to SYST_CVR when the timer is enabled correctly
19
To make the code clearer, replace the 'bool' return from the process_
20
do nothing; when the timer is enabled via SYST_CSR.ENABLE,
20
functions with an enum which may be either CMD_STALL or CMD_CONTINUE.
21
the ptimer code will (because of POLICY_NO_IMMEDIATE_RELOAD)
21
In this commit no behaviour changes; in subsequent commits we will
22
arrange that after one timer tick the counter is reloaded
22
adjust the error-return paths for the process_ functions one by one.
23
from SYST_RVR and then counts down from there, as the
24
architecture requires.
25
23
26
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
24
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
25
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
26
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
27
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
27
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
28
Message-id: 20201015151829.14656-3-peter.maydell@linaro.org
28
Message-id: 20220111171048.3545974-6-peter.maydell@linaro.org
29
---
29
---
30
include/hw/timer/armv7m_systick.h | 3 +-
30
hw/intc/arm_gicv3_its.c | 59 ++++++++++++++++++++++++++---------------
31
hw/timer/armv7m_systick.c | 124 +++++++++++++-----------------
31
1 file changed, 38 insertions(+), 21 deletions(-)
32
2 files changed, 54 insertions(+), 73 deletions(-)
32
33
33
diff --git a/hw/intc/arm_gicv3_its.c b/hw/intc/arm_gicv3_its.c
34
diff --git a/include/hw/timer/armv7m_systick.h b/include/hw/timer/armv7m_systick.h
35
index XXXXXXX..XXXXXXX 100644
34
index XXXXXXX..XXXXXXX 100644
36
--- a/include/hw/timer/armv7m_systick.h
35
--- a/hw/intc/arm_gicv3_its.c
37
+++ b/include/hw/timer/armv7m_systick.h
36
+++ b/hw/intc/arm_gicv3_its.c
38
@@ -XXX,XX +XXX,XX @@
37
@@ -XXX,XX +XXX,XX @@ typedef struct {
39
38
uint64_t itel;
40
#include "hw/sysbus.h"
39
} IteEntry;
41
#include "qom/object.h"
40
42
+#include "hw/ptimer.h"
41
+/*
43
42
+ * The ITS spec permits a range of CONSTRAINED UNPREDICTABLE options
44
#define TYPE_SYSTICK "armv7m_systick"
43
+ * if a command parameter is not correct. These include both "stall
45
44
+ * processing of the command queue" and "ignore this command, and
46
@@ -XXX,XX +XXX,XX @@ struct SysTickState {
45
+ * keep processing the queue". In our implementation we choose that
47
uint32_t control;
46
+ * memory transaction errors reading the command packet provoke a
48
uint32_t reload;
47
+ * stall, but errors in parameters cause us to ignore the command
49
int64_t tick;
48
+ * and continue processing.
50
- QEMUTimer *timer;
49
+ * The process_* functions which handle individual ITS commands all
51
+ ptimer_state *ptimer;
50
+ * return an ItsCmdResult which tells process_cmdq() whether it should
52
MemoryRegion iomem;
51
+ * stall or keep going.
53
qemu_irq irq;
52
+ */
54
};
53
+typedef enum ItsCmdResult {
55
diff --git a/hw/timer/armv7m_systick.c b/hw/timer/armv7m_systick.c
54
+ CMD_STALL = 0,
56
index XXXXXXX..XXXXXXX 100644
55
+ CMD_CONTINUE = 1,
57
--- a/hw/timer/armv7m_systick.c
56
+} ItsCmdResult;
58
+++ b/hw/timer/armv7m_systick.c
57
+
59
@@ -XXX,XX +XXX,XX @@ static inline int64_t systick_scale(SysTickState *s)
58
static uint64_t baser_base_addr(uint64_t value, uint32_t page_sz)
60
}
59
{
60
uint64_t result = 0;
61
@@ -XXX,XX +XXX,XX @@ static uint64_t get_dte(GICv3ITSState *s, uint32_t devid, MemTxResult *res)
62
* 3. handling of ITS CLEAR command
63
* 4. handling of ITS DISCARD command
64
*/
65
-static bool process_its_cmd(GICv3ITSState *s, uint64_t value, uint32_t offset,
66
- ItsCmdType cmd)
67
+static ItsCmdResult process_its_cmd(GICv3ITSState *s, uint64_t value,
68
+ uint32_t offset, ItsCmdType cmd)
69
{
70
AddressSpace *as = &s->gicv3->dma_as;
71
uint32_t devid, eventid;
72
@@ -XXX,XX +XXX,XX @@ static bool process_its_cmd(GICv3ITSState *s, uint64_t value, uint32_t offset,
73
bool ite_valid = false;
74
uint64_t cte = 0;
75
bool cte_valid = false;
76
- bool result = false;
77
+ ItsCmdResult result = CMD_STALL;
78
uint64_t rdbase;
79
80
if (cmd == NONE) {
81
@@ -XXX,XX +XXX,XX @@ static bool process_its_cmd(GICv3ITSState *s, uint64_t value, uint32_t offset,
82
if (cmd == DISCARD) {
83
IteEntry ite = {};
84
/* remove mapping from interrupt translation table */
85
- result = update_ite(s, eventid, dte, ite);
86
+ result = update_ite(s, eventid, dte, ite) ? CMD_CONTINUE : CMD_STALL;
87
}
88
}
89
90
return result;
61
}
91
}
62
92
63
-static void systick_reload(SysTickState *s, int reset)
93
-static bool process_mapti(GICv3ITSState *s, uint64_t value, uint32_t offset,
64
-{
94
- bool ignore_pInt)
65
- /* The Cortex-M3 Devices Generic User Guide says that "When the
95
+static ItsCmdResult process_mapti(GICv3ITSState *s, uint64_t value,
66
- * ENABLE bit is set to 1, the counter loads the RELOAD value from the
96
+ uint32_t offset, bool ignore_pInt)
67
- * SYST RVR register and then counts down". So, we need to check the
97
{
68
- * ENABLE bit before reloading the value.
98
AddressSpace *as = &s->gicv3->dma_as;
69
- */
99
uint32_t devid, eventid;
70
- trace_systick_reload();
100
@@ -XXX,XX +XXX,XX @@ static bool process_mapti(GICv3ITSState *s, uint64_t value, uint32_t offset,
71
-
101
MemTxResult res = MEMTX_OK;
72
- if ((s->control & SYSTICK_ENABLE) == 0) {
102
uint16_t icid = 0;
73
- return;
103
uint64_t dte = 0;
74
- }
104
- bool result = false;
75
-
105
+ ItsCmdResult result = CMD_STALL;
76
- if (reset) {
106
77
- s->tick = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
107
devid = ((value & DEVID_MASK) >> DEVID_SHIFT);
78
- }
108
offset += NUM_BYTES_IN_DW;
79
- s->tick += (s->reload + 1) * systick_scale(s);
109
@@ -XXX,XX +XXX,XX @@ static bool process_mapti(GICv3ITSState *s, uint64_t value, uint32_t offset,
80
- timer_mod(s->timer, s->tick);
110
ite.itel = FIELD_DP64(ite.itel, ITE_L, DOORBELL, INTID_SPURIOUS);
81
-}
111
ite.iteh = FIELD_DP32(ite.iteh, ITE_H, ICID, icid);
82
-
112
83
static void systick_timer_tick(void *opaque)
113
- result = update_ite(s, eventid, dte, ite);
84
{
114
+ result = update_ite(s, eventid, dte, ite) ? CMD_CONTINUE : CMD_STALL;
85
SysTickState *s = (SysTickState *)opaque;
115
}
86
@@ -XXX,XX +XXX,XX @@ static void systick_timer_tick(void *opaque)
116
87
/* Tell the NVIC to pend the SysTick exception */
117
return result;
88
qemu_irq_pulse(s->irq);
118
@@ -XXX,XX +XXX,XX @@ static bool update_cte(GICv3ITSState *s, uint16_t icid, bool valid,
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
}
119
}
101
}
120
}
102
121
103
@@ -XXX,XX +XXX,XX @@ static MemTxResult systick_read(void *opaque, hwaddr addr, uint64_t *data,
122
-static bool process_mapc(GICv3ITSState *s, uint32_t offset)
104
s->control &= ~SYSTICK_COUNTFLAG;
123
+static ItsCmdResult process_mapc(GICv3ITSState *s, uint32_t offset)
105
break;
124
{
106
case 0x4: /* SysTick Reload Value. */
125
AddressSpace *as = &s->gicv3->dma_as;
107
- val = s->reload;
126
uint16_t icid;
108
+ val = ptimer_get_limit(s->ptimer);
127
uint64_t rdbase;
109
break;
128
bool valid;
110
case 0x8: /* SysTick Current Value. */
129
MemTxResult res = MEMTX_OK;
111
- {
130
- bool result = false;
112
- int64_t t;
131
+ ItsCmdResult result = CMD_STALL;
113
-
132
uint64_t value;
114
- if ((s->control & SYSTICK_ENABLE) == 0) {
133
115
- val = 0;
134
offset += NUM_BYTES_IN_DW;
116
- break;
135
@@ -XXX,XX +XXX,XX @@ static bool process_mapc(GICv3ITSState *s, uint32_t offset)
117
- }
136
* command in the queue
118
- t = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
137
*/
119
- if (t >= s->tick) {
138
} else {
120
- val = 0;
139
- result = update_cte(s, icid, valid, rdbase);
121
- break;
140
+ result = update_cte(s, icid, valid, rdbase) ? CMD_CONTINUE : CMD_STALL;
122
- }
141
}
123
- val = ((s->tick - (t + 1)) / systick_scale(s)) + 1;
142
124
- /* The interrupt in triggered when the timer reaches zero.
143
return result;
125
- However the counter is not reloaded until the next clock
144
@@ -XXX,XX +XXX,XX @@ static bool update_dte(GICv3ITSState *s, uint32_t devid, bool valid,
126
- tick. This is a hack to return zero during the first tick. */
145
}
127
- if (val > s->reload) {
146
}
128
- val = 0;
147
129
- }
148
-static bool process_mapd(GICv3ITSState *s, uint64_t value, uint32_t offset)
130
+ val = ptimer_get_count(s->ptimer);
149
+static ItsCmdResult process_mapd(GICv3ITSState *s, uint64_t value,
131
break;
150
+ uint32_t offset)
132
- }
151
{
133
case 0xc: /* SysTick Calibration Value. */
152
AddressSpace *as = &s->gicv3->dma_as;
134
val = 10000;
153
uint32_t devid;
135
break;
154
@@ -XXX,XX +XXX,XX @@ static bool process_mapd(GICv3ITSState *s, uint64_t value, uint32_t offset)
136
@@ -XXX,XX +XXX,XX @@ static MemTxResult systick_write(void *opaque, hwaddr addr,
155
uint64_t itt_addr;
137
switch (addr) {
156
bool valid;
138
case 0x0: /* SysTick Control and Status. */
157
MemTxResult res = MEMTX_OK;
139
{
158
- bool result = false;
140
- uint32_t oldval = s->control;
159
+ ItsCmdResult result = CMD_STALL;
141
+ uint32_t oldval;
160
142
161
devid = ((value & DEVID_MASK) >> DEVID_SHIFT);
143
+ ptimer_transaction_begin(s->ptimer);
162
144
+ oldval = s->control;
163
@@ -XXX,XX +XXX,XX @@ static bool process_mapd(GICv3ITSState *s, uint64_t value, uint32_t offset)
145
s->control &= 0xfffffff8;
164
* command in the queue
146
s->control |= value & 7;
165
*/
166
} else {
167
- result = update_dte(s, devid, valid, size, itt_addr);
168
+ result = update_dte(s, devid, valid, size, itt_addr) ? CMD_CONTINUE : CMD_STALL;
169
}
170
171
return result;
172
@@ -XXX,XX +XXX,XX @@ static void process_cmdq(GICv3ITSState *s)
173
uint64_t data;
174
AddressSpace *as = &s->gicv3->dma_as;
175
MemTxResult res = MEMTX_OK;
176
- bool result = true;
177
uint8_t cmd;
178
int i;
179
180
@@ -XXX,XX +XXX,XX @@ static void process_cmdq(GICv3ITSState *s)
181
}
182
183
while (wr_offset != rd_offset) {
184
+ ItsCmdResult result = CMD_CONTINUE;
147
+
185
+
148
if ((oldval ^ value) & SYSTICK_ENABLE) {
186
cq_offset = (rd_offset * GITS_CMDQ_ENTRY_SIZE);
149
- int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
187
data = address_space_ldq_le(as, s->cq.base_addr + cq_offset,
150
if (value & SYSTICK_ENABLE) {
188
MEMTXATTRS_UNSPECIFIED, &res);
151
- if (s->tick) {
189
@@ -XXX,XX +XXX,XX @@ static void process_cmdq(GICv3ITSState *s)
152
- s->tick += now;
190
default:
153
- timer_mod(s->timer, s->tick);
191
break;
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
}
192
}
179
+ ptimer_transaction_commit(s->ptimer);
193
- if (result) {
180
break;
194
+ if (result == CMD_CONTINUE) {
181
}
195
rd_offset++;
182
case 0x4: /* SysTick Reload Value. */
196
rd_offset %= s->cq.num_entries;
183
- s->reload = value;
197
s->creadr = FIELD_DP64(s->creadr, GITS_CREADR, OFFSET, rd_offset);
184
+ ptimer_transaction_begin(s->ptimer);
198
} else {
185
+ ptimer_set_limit(s->ptimer, value & 0xffffff, 0);
199
- /*
186
+ ptimer_transaction_commit(s->ptimer);
200
- * in this implementation, in case of dma read/write error
187
break;
201
- * we stall the command processing
188
- case 0x8: /* SysTick Current Value. Writes reload the timer. */
202
- */
189
- systick_reload(s, 1);
203
+ /* CMD_STALL */
190
+ case 0x8: /* SysTick Current Value. */
204
s->creadr = FIELD_DP64(s->creadr, GITS_CREADR, STALLED, 1);
191
+ /*
205
qemu_log_mask(LOG_GUEST_ERROR,
192
+ * Writing any value clears SYST_CVR to zero and clears
206
- "%s: %x cmd processing failed\n", __func__, cmd);
193
+ * SYST_CSR.COUNTFLAG. The counter will then reload from SYST_RVR
207
+ "%s: 0x%x cmd processing failed, stalling\n",
194
+ * on the next clock edge unless SYST_RVR is zero.
208
+ __func__, cmd);
195
+ */
209
break;
196
+ ptimer_transaction_begin(s->ptimer);
210
}
197
+ if (ptimer_get_limit(s->ptimer) == 0) {
211
}
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
--
212
--
251
2.20.1
213
2.25.1
252
214
253
215
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
1
Fix process_its_cmd() to consistently return CMD_STALL for
2
memory errors and CMD_CONTINUE for parameter errors, as
3
we claim in the comments that we do.
2
4
3
Fix an unlikely memory leak in load_elf_image().
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
6
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Message-id: 20220111171048.3545974-7-peter.maydell@linaro.org
9
---
10
hw/intc/arm_gicv3_its.c | 22 +++++++++++-----------
11
1 file changed, 11 insertions(+), 11 deletions(-)
4
12
5
Fixes: bf858897b7 ("linux-user: Re-use load_elf_image for the main binary.")
13
diff --git a/hw/intc/arm_gicv3_its.c b/hw/intc/arm_gicv3_its.c
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
14
index XXXXXXX..XXXXXXX 100644
19
--- a/linux-user/elfload.c
15
--- a/hw/intc/arm_gicv3_its.c
20
+++ b/linux-user/elfload.c
16
+++ b/hw/intc/arm_gicv3_its.c
21
@@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd,
17
@@ -XXX,XX +XXX,XX @@ static ItsCmdResult process_its_cmd(GICv3ITSState *s, uint64_t value,
22
info->brk = vaddr_em;
18
bool ite_valid = false;
23
}
19
uint64_t cte = 0;
24
} else if (eppnt->p_type == PT_INTERP && pinterp_name) {
20
bool cte_valid = false;
25
- char *interp_name;
21
- ItsCmdResult result = CMD_STALL;
26
+ g_autofree char *interp_name = NULL;
22
uint64_t rdbase;
27
23
28
if (*pinterp_name) {
24
if (cmd == NONE) {
29
errmsg = "Multiple PT_INTERP entries";
25
@@ -XXX,XX +XXX,XX @@ static ItsCmdResult process_its_cmd(GICv3ITSState *s, uint64_t value,
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
}
26
}
53
27
54
#ifdef USE_ELF_CORE_DUMP
28
if (res != MEMTX_OK) {
29
- return result;
30
+ return CMD_STALL;
31
}
32
33
eventid = (value & EVENTID_MASK);
34
@@ -XXX,XX +XXX,XX @@ static ItsCmdResult process_its_cmd(GICv3ITSState *s, uint64_t value,
35
dte = get_dte(s, devid, &res);
36
37
if (res != MEMTX_OK) {
38
- return result;
39
+ return CMD_STALL;
40
}
41
dte_valid = FIELD_EX64(dte, DTE, VALID);
42
43
@@ -XXX,XX +XXX,XX @@ static ItsCmdResult process_its_cmd(GICv3ITSState *s, uint64_t value,
44
ite_valid = get_ite(s, eventid, dte, &icid, &pIntid, &res);
45
46
if (res != MEMTX_OK) {
47
- return result;
48
+ return CMD_STALL;
49
}
50
51
if (ite_valid) {
52
@@ -XXX,XX +XXX,XX @@ static ItsCmdResult process_its_cmd(GICv3ITSState *s, uint64_t value,
53
}
54
55
if (res != MEMTX_OK) {
56
- return result;
57
+ return CMD_STALL;
58
}
59
} else {
60
qemu_log_mask(LOG_GUEST_ERROR,
61
"%s: invalid command attributes: "
62
"invalid dte: %"PRIx64" for %d (MEM_TX: %d)\n",
63
__func__, dte, devid, res);
64
- return result;
65
+ return CMD_CONTINUE;
66
}
67
68
69
@@ -XXX,XX +XXX,XX @@ static ItsCmdResult process_its_cmd(GICv3ITSState *s, uint64_t value,
70
qemu_log_mask(LOG_GUEST_ERROR,
71
"%s: invalid command attributes: devid %d>=%d",
72
__func__, devid, s->dt.num_ids);
73
-
74
+ return CMD_CONTINUE;
75
} else if (!dte_valid || !ite_valid || !cte_valid) {
76
qemu_log_mask(LOG_GUEST_ERROR,
77
"%s: invalid command attributes: "
78
@@ -XXX,XX +XXX,XX @@ static ItsCmdResult process_its_cmd(GICv3ITSState *s, uint64_t value,
79
dte_valid ? "valid" : "invalid",
80
ite_valid ? "valid" : "invalid",
81
cte_valid ? "valid" : "invalid");
82
+ return CMD_CONTINUE;
83
} else if (eventid >= num_eventids) {
84
qemu_log_mask(LOG_GUEST_ERROR,
85
"%s: invalid command attributes: eventid %d >= %"
86
PRId64 "\n",
87
__func__, eventid, num_eventids);
88
+ return CMD_CONTINUE;
89
} else {
90
/*
91
* Current implementation only supports rdbase == procnum
92
@@ -XXX,XX +XXX,XX @@ static ItsCmdResult process_its_cmd(GICv3ITSState *s, uint64_t value,
93
rdbase = FIELD_EX64(cte, CTE, RDBASE);
94
95
if (rdbase >= s->gicv3->num_cpu) {
96
- return result;
97
+ return CMD_CONTINUE;
98
}
99
100
if ((cmd == CLEAR) || (cmd == DISCARD)) {
101
@@ -XXX,XX +XXX,XX @@ static ItsCmdResult process_its_cmd(GICv3ITSState *s, uint64_t value,
102
if (cmd == DISCARD) {
103
IteEntry ite = {};
104
/* remove mapping from interrupt translation table */
105
- result = update_ite(s, eventid, dte, ite) ? CMD_CONTINUE : CMD_STALL;
106
+ return update_ite(s, eventid, dte, ite) ? CMD_CONTINUE : CMD_STALL;
107
}
108
+ return CMD_CONTINUE;
109
}
110
-
111
- return result;
112
}
113
114
static ItsCmdResult process_mapti(GICv3ITSState *s, uint64_t value,
55
--
115
--
56
2.20.1
116
2.25.1
57
117
58
118
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: Luc Michel <luc@lmichel.fr>
1
Refactor process_its_cmd() so that it consistently uses
2
the structure
3
do thing;
4
if (error condition) {
5
return early;
6
}
7
do next thing;
2
8
3
The clock multiplexers are the last clock stage in the CPRMAN. Each mux
9
rather than doing some of the work nested inside if (not error)
4
outputs one clock signal that goes out of the CPRMAN to the SoC
10
code blocks.
5
peripherals.
6
11
7
Each mux has at most 10 sources. The sources 0 to 3 are common to all
12
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
8
muxes. They are:
13
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
9
0. ground (no clock signal)
14
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
10
1. the main oscillator (xosc)
15
Message-id: 20220111171048.3545974-8-peter.maydell@linaro.org
11
2. "test debug 0" clock
16
---
12
3. "test debug 1" clock
17
hw/intc/arm_gicv3_its.c | 103 +++++++++++++++++++---------------------
18
1 file changed, 50 insertions(+), 53 deletions(-)
13
19
14
Test debug 0 and 1 are actual clock muxes that can be used as sources to
20
diff --git a/hw/intc/arm_gicv3_its.c b/hw/intc/arm_gicv3_its.c
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>
41
---
42
include/hw/misc/bcm2835_cprman.h | 85 +++++
43
include/hw/misc/bcm2835_cprman_internals.h | 422 +++++++++++++++++++++
44
hw/misc/bcm2835_cprman.c | 151 ++++++++
45
3 files changed, 658 insertions(+)
46
47
diff --git a/include/hw/misc/bcm2835_cprman.h b/include/hw/misc/bcm2835_cprman.h
48
index XXXXXXX..XXXXXXX 100644
21
index XXXXXXX..XXXXXXX 100644
49
--- a/include/hw/misc/bcm2835_cprman.h
22
--- a/hw/intc/arm_gicv3_its.c
50
+++ b/include/hw/misc/bcm2835_cprman.h
23
+++ b/hw/intc/arm_gicv3_its.c
51
@@ -XXX,XX +XXX,XX @@ typedef enum CprmanPllChannel {
24
@@ -XXX,XX +XXX,XX @@ static ItsCmdResult process_its_cmd(GICv3ITSState *s, uint64_t value,
52
CPRMAN_PLLB_CHANNEL_ARM,
25
}
53
26
dte_valid = FIELD_EX64(dte, DTE, VALID);
54
CPRMAN_NUM_PLL_CHANNEL,
27
28
- if (dte_valid) {
29
- num_eventids = 1ULL << (FIELD_EX64(dte, DTE, SIZE) + 1);
30
-
31
- ite_valid = get_ite(s, eventid, dte, &icid, &pIntid, &res);
32
-
33
- if (res != MEMTX_OK) {
34
- return CMD_STALL;
35
- }
36
-
37
- if (ite_valid) {
38
- cte_valid = get_cte(s, icid, &cte, &res);
39
- }
40
-
41
- if (res != MEMTX_OK) {
42
- return CMD_STALL;
43
- }
44
- } else {
45
+ if (!dte_valid) {
46
qemu_log_mask(LOG_GUEST_ERROR,
47
"%s: invalid command attributes: "
48
- "invalid dte: %"PRIx64" for %d (MEM_TX: %d)\n",
49
- __func__, dte, devid, res);
50
+ "invalid dte: %"PRIx64" for %d\n",
51
+ __func__, dte, devid);
52
return CMD_CONTINUE;
53
}
54
55
+ num_eventids = 1ULL << (FIELD_EX64(dte, DTE, SIZE) + 1);
55
+
56
+
56
+ /* Special values used when connecting clock sources to clocks */
57
+ ite_valid = get_ite(s, eventid, dte, &icid, &pIntid, &res);
57
+ CPRMAN_CLOCK_SRC_NORMAL = -1,
58
+ if (res != MEMTX_OK) {
58
+ CPRMAN_CLOCK_SRC_FORCE_GROUND = -2,
59
+ return CMD_STALL;
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 @@
169
170
#define TYPE_CPRMAN_PLL "bcm2835-cprman-pll"
171
#define TYPE_CPRMAN_PLL_CHANNEL "bcm2835-cprman-pll-channel"
172
+#define TYPE_CPRMAN_CLOCK_MUX "bcm2835-cprman-clock-mux"
173
174
DECLARE_INSTANCE_CHECKER(CprmanPllState, CPRMAN_PLL,
175
TYPE_CPRMAN_PLL)
176
DECLARE_INSTANCE_CHECKER(CprmanPllChannelState, CPRMAN_PLL_CHANNEL,
177
TYPE_CPRMAN_PLL_CHANNEL)
178
+DECLARE_INSTANCE_CHECKER(CprmanClockMuxState, CPRMAN_CLOCK_MUX,
179
+ TYPE_CPRMAN_CLOCK_MUX)
180
181
/* Register map */
182
183
@@ -XXX,XX +XXX,XX @@ REG32(A2W_PLLH_STS, 0x1660)
184
185
REG32(A2W_PLLB_ARM, 0x13e0)
186
187
+/* Clock muxes */
188
+REG32(CM_GNRICCTL, 0x000)
189
+ FIELD(CM_CLOCKx_CTL, SRC, 0, 4)
190
+ FIELD(CM_CLOCKx_CTL, ENABLE, 4, 1)
191
+ FIELD(CM_CLOCKx_CTL, KILL, 5, 1)
192
+ FIELD(CM_CLOCKx_CTL, GATE, 6, 1)
193
+ FIELD(CM_CLOCKx_CTL, BUSY, 7, 1)
194
+ FIELD(CM_CLOCKx_CTL, BUSYD, 8, 1)
195
+ FIELD(CM_CLOCKx_CTL, MASH, 9, 2)
196
+ FIELD(CM_CLOCKx_CTL, FLIP, 11, 1)
197
+REG32(CM_GNRICDIV, 0x004)
198
+ FIELD(CM_CLOCKx_DIV, FRAC, 0, 12)
199
+REG32(CM_VPUCTL, 0x008)
200
+REG32(CM_VPUDIV, 0x00c)
201
+REG32(CM_SYSCTL, 0x010)
202
+REG32(CM_SYSDIV, 0x014)
203
+REG32(CM_PERIACTL, 0x018)
204
+REG32(CM_PERIADIV, 0x01c)
205
+REG32(CM_PERIICTL, 0x020)
206
+REG32(CM_PERIIDIV, 0x024)
207
+REG32(CM_H264CTL, 0x028)
208
+REG32(CM_H264DIV, 0x02c)
209
+REG32(CM_ISPCTL, 0x030)
210
+REG32(CM_ISPDIV, 0x034)
211
+REG32(CM_V3DCTL, 0x038)
212
+REG32(CM_V3DDIV, 0x03c)
213
+REG32(CM_CAM0CTL, 0x040)
214
+REG32(CM_CAM0DIV, 0x044)
215
+REG32(CM_CAM1CTL, 0x048)
216
+REG32(CM_CAM1DIV, 0x04c)
217
+REG32(CM_CCP2CTL, 0x050)
218
+REG32(CM_CCP2DIV, 0x054)
219
+REG32(CM_DSI0ECTL, 0x058)
220
+REG32(CM_DSI0EDIV, 0x05c)
221
+REG32(CM_DSI0PCTL, 0x060)
222
+REG32(CM_DSI0PDIV, 0x064)
223
+REG32(CM_DPICTL, 0x068)
224
+REG32(CM_DPIDIV, 0x06c)
225
+REG32(CM_GP0CTL, 0x070)
226
+REG32(CM_GP0DIV, 0x074)
227
+REG32(CM_GP1CTL, 0x078)
228
+REG32(CM_GP1DIV, 0x07c)
229
+REG32(CM_GP2CTL, 0x080)
230
+REG32(CM_GP2DIV, 0x084)
231
+REG32(CM_HSMCTL, 0x088)
232
+REG32(CM_HSMDIV, 0x08c)
233
+REG32(CM_OTPCTL, 0x090)
234
+REG32(CM_OTPDIV, 0x094)
235
+REG32(CM_PCMCTL, 0x098)
236
+REG32(CM_PCMDIV, 0x09c)
237
+REG32(CM_PWMCTL, 0x0a0)
238
+REG32(CM_PWMDIV, 0x0a4)
239
+REG32(CM_SLIMCTL, 0x0a8)
240
+REG32(CM_SLIMDIV, 0x0ac)
241
+REG32(CM_SMICTL, 0x0b0)
242
+REG32(CM_SMIDIV, 0x0b4)
243
+REG32(CM_TCNTCTL, 0x0c0)
244
+REG32(CM_TCNTCNT, 0x0c4)
245
+REG32(CM_TECCTL, 0x0c8)
246
+REG32(CM_TECDIV, 0x0cc)
247
+REG32(CM_TD0CTL, 0x0d0)
248
+REG32(CM_TD0DIV, 0x0d4)
249
+REG32(CM_TD1CTL, 0x0d8)
250
+REG32(CM_TD1DIV, 0x0dc)
251
+REG32(CM_TSENSCTL, 0x0e0)
252
+REG32(CM_TSENSDIV, 0x0e4)
253
+REG32(CM_TIMERCTL, 0x0e8)
254
+REG32(CM_TIMERDIV, 0x0ec)
255
+REG32(CM_UARTCTL, 0x0f0)
256
+REG32(CM_UARTDIV, 0x0f4)
257
+REG32(CM_VECCTL, 0x0f8)
258
+REG32(CM_VECDIV, 0x0fc)
259
+REG32(CM_PULSECTL, 0x190)
260
+REG32(CM_PULSEDIV, 0x194)
261
+REG32(CM_SDCCTL, 0x1a8)
262
+REG32(CM_SDCDIV, 0x1ac)
263
+REG32(CM_ARMCTL, 0x1b0)
264
+REG32(CM_AVEOCTL, 0x1b8)
265
+REG32(CM_AVEODIV, 0x1bc)
266
+REG32(CM_EMMCCTL, 0x1c0)
267
+REG32(CM_EMMCDIV, 0x1c4)
268
+REG32(CM_EMMC2CTL, 0x1d0)
269
+REG32(CM_EMMC2DIV, 0x1d4)
270
+
271
/* misc registers */
272
REG32(CM_LOCK, 0x114)
273
FIELD(CM_LOCK, FLOCKH, 12, 1)
274
@@ -XXX,XX +XXX,XX @@ static inline void set_pll_channel_init_info(BCM2835CprmanState *s,
275
channel->fixed_divider = PLL_CHANNEL_INIT_INFO[id].fixed_divider;
276
}
277
278
+/* Clock mux init info */
279
+typedef struct ClockMuxInitInfo {
280
+ const char *name;
281
+ size_t cm_offset; /* cm_offset[0]->CM_CTL, cm_offset[1]->CM_DIV */
282
+ int int_bits;
283
+ int frac_bits;
284
+
285
+ CprmanPllChannel src_mapping[CPRMAN_NUM_CLOCK_MUX_SRC];
286
+} ClockMuxInitInfo;
287
+
288
+/*
289
+ * Each clock mux can have up to 10 sources. Sources 0 to 3 are always the
290
+ * same (ground, xosc, td0, td1). Sources 4 to 9 are mux specific, and are not
291
+ * always populated. The following macros catch all those cases.
292
+ */
293
+
294
+/* Unknown mapping. Connect everything to ground */
295
+#define SRC_MAPPING_INFO_unknown \
296
+ .src_mapping = { \
297
+ CPRMAN_CLOCK_SRC_FORCE_GROUND, /* gnd */ \
298
+ CPRMAN_CLOCK_SRC_FORCE_GROUND, /* xosc */ \
299
+ CPRMAN_CLOCK_SRC_FORCE_GROUND, /* test debug 0 */ \
300
+ CPRMAN_CLOCK_SRC_FORCE_GROUND, /* test debug 1 */ \
301
+ CPRMAN_CLOCK_SRC_FORCE_GROUND, /* pll a */ \
302
+ CPRMAN_CLOCK_SRC_FORCE_GROUND, /* pll c */ \
303
+ CPRMAN_CLOCK_SRC_FORCE_GROUND, /* pll d */ \
304
+ CPRMAN_CLOCK_SRC_FORCE_GROUND, /* pll h */ \
305
+ CPRMAN_CLOCK_SRC_FORCE_GROUND, /* pll c, core1 */ \
306
+ CPRMAN_CLOCK_SRC_FORCE_GROUND, /* pll c, core2 */ \
307
+ }
60
+ }
308
+
61
+
309
+/* Only the oscillator and the two test debug clocks */
62
+ if (!ite_valid) {
310
+#define SRC_MAPPING_INFO_xosc \
63
+ qemu_log_mask(LOG_GUEST_ERROR,
311
+ .src_mapping = { \
64
+ "%s: invalid command attributes: invalid ITE\n",
312
+ CPRMAN_CLOCK_SRC_NORMAL, \
65
+ __func__);
313
+ CPRMAN_CLOCK_SRC_NORMAL, \
66
+ return CMD_CONTINUE;
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
+ }
67
+ }
323
+
68
+
324
+/* All the PLL "core" channels */
69
+ cte_valid = get_cte(s, icid, &cte, &res);
325
+#define SRC_MAPPING_INFO_core \
70
+ if (res != MEMTX_OK) {
326
+ .src_mapping = { \
71
+ return CMD_STALL;
327
+ CPRMAN_CLOCK_SRC_NORMAL, \
72
+ }
328
+ CPRMAN_CLOCK_SRC_NORMAL, \
73
+ if (!cte_valid) {
329
+ CPRMAN_CLOCK_SRC_NORMAL, \
74
+ qemu_log_mask(LOG_GUEST_ERROR,
330
+ CPRMAN_CLOCK_SRC_NORMAL, \
75
+ "%s: invalid command attributes: "
331
+ CPRMAN_PLLA_CHANNEL_CORE, \
76
+ "invalid cte: %"PRIx64"\n",
332
+ CPRMAN_PLLC_CHANNEL_CORE0, \
77
+ __func__, cte);
333
+ CPRMAN_PLLD_CHANNEL_CORE, \
78
+ return CMD_CONTINUE;
334
+ CPRMAN_PLLH_CHANNEL_AUX, \
79
+ }
335
+ CPRMAN_PLLC_CHANNEL_CORE1, \
80
336
+ CPRMAN_PLLC_CHANNEL_CORE2, \
81
- /*
82
- * In this implementation, in case of guest errors we ignore the
83
- * command and move onto the next command in the queue.
84
- */
85
if (devid >= s->dt.num_ids) {
86
qemu_log_mask(LOG_GUEST_ERROR,
87
"%s: invalid command attributes: devid %d>=%d",
88
__func__, devid, s->dt.num_ids);
89
return CMD_CONTINUE;
90
- } else if (!dte_valid || !ite_valid || !cte_valid) {
91
- qemu_log_mask(LOG_GUEST_ERROR,
92
- "%s: invalid command attributes: "
93
- "dte: %s, ite: %s, cte: %s\n",
94
- __func__,
95
- dte_valid ? "valid" : "invalid",
96
- ite_valid ? "valid" : "invalid",
97
- cte_valid ? "valid" : "invalid");
98
- return CMD_CONTINUE;
99
- } else if (eventid >= num_eventids) {
100
+ }
101
+ if (eventid >= num_eventids) {
102
qemu_log_mask(LOG_GUEST_ERROR,
103
"%s: invalid command attributes: eventid %d >= %"
104
PRId64 "\n",
105
__func__, eventid, num_eventids);
106
return CMD_CONTINUE;
107
- } else {
108
- /*
109
- * Current implementation only supports rdbase == procnum
110
- * Hence rdbase physical address is ignored
111
- */
112
- rdbase = FIELD_EX64(cte, CTE, RDBASE);
113
+ }
114
115
- if (rdbase >= s->gicv3->num_cpu) {
116
- return CMD_CONTINUE;
117
- }
118
+ /*
119
+ * Current implementation only supports rdbase == procnum
120
+ * Hence rdbase physical address is ignored
121
+ */
122
+ rdbase = FIELD_EX64(cte, CTE, RDBASE);
123
124
- if ((cmd == CLEAR) || (cmd == DISCARD)) {
125
- gicv3_redist_process_lpi(&s->gicv3->cpu[rdbase], pIntid, 0);
126
- } else {
127
- gicv3_redist_process_lpi(&s->gicv3->cpu[rdbase], pIntid, 1);
128
- }
129
-
130
- if (cmd == DISCARD) {
131
- IteEntry ite = {};
132
- /* remove mapping from interrupt translation table */
133
- return update_ite(s, eventid, dte, ite) ? CMD_CONTINUE : CMD_STALL;
134
- }
135
+ if (rdbase >= s->gicv3->num_cpu) {
136
return CMD_CONTINUE;
137
}
138
+
139
+ if ((cmd == CLEAR) || (cmd == DISCARD)) {
140
+ gicv3_redist_process_lpi(&s->gicv3->cpu[rdbase], pIntid, 0);
141
+ } else {
142
+ gicv3_redist_process_lpi(&s->gicv3->cpu[rdbase], pIntid, 1);
337
+ }
143
+ }
338
+
144
+
339
+/* All the PLL "per" channels */
145
+ if (cmd == DISCARD) {
340
+#define SRC_MAPPING_INFO_periph \
146
+ IteEntry ite = {};
341
+ .src_mapping = { \
147
+ /* remove mapping from interrupt translation table */
342
+ CPRMAN_CLOCK_SRC_NORMAL, \
148
+ return update_ite(s, eventid, dte, ite) ? CMD_CONTINUE : CMD_STALL;
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
+ }
149
+ }
353
+
150
+ return CMD_CONTINUE;
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
}
696
}
151
}
697
152
698
+static inline void update_mux_from_cm(BCM2835CprmanState *s, size_t idx)
153
static ItsCmdResult process_mapti(GICv3ITSState *s, uint64_t value,
699
+{
700
+ size_t i;
701
+
702
+ for (i = 0; i < CPRMAN_NUM_CLOCK_MUX; i++) {
703
+ if ((CLOCK_MUX_INIT_INFO[i].cm_offset == idx) ||
704
+ (CLOCK_MUX_INIT_INFO[i].cm_offset + 4 == idx)) {
705
+ /* matches CM_CTL or CM_DIV mux register */
706
+ clock_mux_update(&s->clock_muxes[i]);
707
+ return;
708
+ }
709
+ }
710
+}
711
+
712
#define CASE_PLL_A2W_REGS(pll_) \
713
case R_A2W_ ## pll_ ## _CTRL: \
714
case R_A2W_ ## pll_ ## _ANA0: \
715
@@ -XXX,XX +XXX,XX @@ static void cprman_write(void *opaque, hwaddr offset,
716
case R_A2W_PLLB_ARM:
717
update_channel_from_a2w(s, idx);
718
break;
719
+
720
+ case R_CM_GNRICCTL ... R_CM_SMIDIV:
721
+ case R_CM_TCNTCNT ... R_CM_VECDIV:
722
+ case R_CM_PULSECTL ... R_CM_PULSEDIV:
723
+ case R_CM_SDCCTL ... R_CM_ARMCTL:
724
+ case R_CM_AVEOCTL ... R_CM_EMMCDIV:
725
+ case R_CM_EMMC2CTL ... R_CM_EMMC2DIV:
726
+ update_mux_from_cm(s, idx);
727
+ break;
728
}
729
}
730
731
@@ -XXX,XX +XXX,XX @@ static void cprman_reset(DeviceState *dev)
732
device_cold_reset(DEVICE(&s->channels[i]));
733
}
734
735
+ for (i = 0; i < CPRMAN_NUM_CLOCK_MUX; i++) {
736
+ device_cold_reset(DEVICE(&s->clock_muxes[i]));
737
+ }
738
+
739
clock_update_hz(s->xosc, s->xosc_freq);
740
}
741
742
@@ -XXX,XX +XXX,XX @@ static void cprman_init(Object *obj)
743
set_pll_channel_init_info(s, &s->channels[i], i);
744
}
745
746
+ for (i = 0; i < CPRMAN_NUM_CLOCK_MUX; i++) {
747
+ char *alias;
748
+
749
+ object_initialize_child(obj, CLOCK_MUX_INIT_INFO[i].name,
750
+ &s->clock_muxes[i],
751
+ TYPE_CPRMAN_CLOCK_MUX);
752
+ set_clock_mux_init_info(s, &s->clock_muxes[i], i);
753
+
754
+ /* Expose muxes output as CPRMAN outputs */
755
+ alias = g_strdup_printf("%s-out", CLOCK_MUX_INIT_INFO[i].name);
756
+ qdev_alias_clock(DEVICE(&s->clock_muxes[i]), "out", DEVICE(obj), alias);
757
+ g_free(alias);
758
+ }
759
+
760
s->xosc = clock_new(obj, "xosc");
761
+ s->gnd = clock_new(obj, "gnd");
762
+
763
+ clock_set(s->gnd, 0);
764
765
memory_region_init_io(&s->iomem, obj, &cprman_ops,
766
s, "bcm2835-cprman", 0x2000);
767
sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->iomem);
768
}
769
770
+static void connect_mux_sources(BCM2835CprmanState *s,
771
+ CprmanClockMuxState *mux,
772
+ const CprmanPllChannel *clk_mapping)
773
+{
774
+ size_t i;
775
+ Clock *td0 = s->clock_muxes[CPRMAN_CLOCK_TD0].out;
776
+ Clock *td1 = s->clock_muxes[CPRMAN_CLOCK_TD1].out;
777
+
778
+ /* For sources from 0 to 3. Source 4 to 9 are mux specific */
779
+ Clock * const CLK_SRC_MAPPING[] = {
780
+ [CPRMAN_CLOCK_SRC_GND] = s->gnd,
781
+ [CPRMAN_CLOCK_SRC_XOSC] = s->xosc,
782
+ [CPRMAN_CLOCK_SRC_TD0] = td0,
783
+ [CPRMAN_CLOCK_SRC_TD1] = td1,
784
+ };
785
+
786
+ for (i = 0; i < CPRMAN_NUM_CLOCK_MUX_SRC; i++) {
787
+ CprmanPllChannel mapping = clk_mapping[i];
788
+ Clock *src;
789
+
790
+ if (mapping == CPRMAN_CLOCK_SRC_FORCE_GROUND) {
791
+ src = s->gnd;
792
+ } else if (mapping == CPRMAN_CLOCK_SRC_DSI0HSCK) {
793
+ src = s->gnd; /* TODO */
794
+ } else if (i < CPRMAN_CLOCK_SRC_PLLA) {
795
+ src = CLK_SRC_MAPPING[i];
796
+ } else {
797
+ src = s->channels[mapping].out;
798
+ }
799
+
800
+ clock_set_source(mux->srcs[i], src);
801
+ }
802
+}
803
+
804
static void cprman_realize(DeviceState *dev, Error **errp)
805
{
806
BCM2835CprmanState *s = CPRMAN(dev);
807
@@ -XXX,XX +XXX,XX @@ static void cprman_realize(DeviceState *dev, Error **errp)
808
return;
809
}
810
}
811
+
812
+ for (i = 0; i < CPRMAN_NUM_CLOCK_MUX; i++) {
813
+ CprmanClockMuxState *clock_mux = &s->clock_muxes[i];
814
+
815
+ connect_mux_sources(s, clock_mux, CLOCK_MUX_INIT_INFO[i].src_mapping);
816
+
817
+ if (!qdev_realize(DEVICE(clock_mux), NULL, errp)) {
818
+ return;
819
+ }
820
+ }
821
}
822
823
static const VMStateDescription cprman_vmstate = {
824
@@ -XXX,XX +XXX,XX @@ static void cprman_register_types(void)
825
type_register_static(&cprman_info);
826
type_register_static(&cprman_pll_info);
827
type_register_static(&cprman_pll_channel_info);
828
+ type_register_static(&cprman_clock_mux_info);
829
}
830
831
type_init(cprman_register_types);
832
--
154
--
833
2.20.1
155
2.25.1
834
156
835
157
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
Fix process_mapti() to consistently return CMD_STALL for memory
2
errors and CMD_CONTINUE for parameter errors, as we claim in the
3
comments that we do.
2
4
3
This is a bit clearer than open-coding some of this
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
4
with a bare c string.
6
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Message-id: 20220111171048.3545974-9-peter.maydell@linaro.org
9
---
10
hw/intc/arm_gicv3_its.c | 28 +++++++++++++---------------
11
1 file changed, 13 insertions(+), 15 deletions(-)
5
12
6
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
13
diff --git a/hw/intc/arm_gicv3_its.c b/hw/intc/arm_gicv3_its.c
7
Message-id: 20201021173749.111103-9-richard.henderson@linaro.org
8
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
---
11
linux-user/elfload.c | 37 ++++++++++++++++++++-----------------
12
1 file changed, 20 insertions(+), 17 deletions(-)
13
14
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
15
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
16
--- a/linux-user/elfload.c
15
--- a/hw/intc/arm_gicv3_its.c
17
+++ b/linux-user/elfload.c
16
+++ b/hw/intc/arm_gicv3_its.c
18
@@ -XXX,XX +XXX,XX @@
17
@@ -XXX,XX +XXX,XX @@ static ItsCmdResult process_mapti(GICv3ITSState *s, uint64_t value,
19
#include "qemu/guest-random.h"
18
MemTxResult res = MEMTX_OK;
20
#include "qemu/units.h"
19
uint16_t icid = 0;
21
#include "qemu/selfmap.h"
20
uint64_t dte = 0;
22
+#include "qapi/error.h"
21
- ItsCmdResult result = CMD_STALL;
23
22
+ IteEntry ite = {};
24
#ifdef _ARCH_PPC64
23
25
#undef ARCH_DLINFO
24
devid = ((value & DEVID_MASK) >> DEVID_SHIFT);
26
@@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd,
25
offset += NUM_BYTES_IN_DW;
27
struct elf_phdr *phdr;
26
@@ -XXX,XX +XXX,XX @@ static ItsCmdResult process_mapti(GICv3ITSState *s, uint64_t value,
28
abi_ulong load_addr, load_bias, loaddr, hiaddr, error;
27
MEMTXATTRS_UNSPECIFIED, &res);
29
int i, retval;
28
30
- const char *errmsg;
29
if (res != MEMTX_OK) {
31
+ Error *err = NULL;
30
- return result;
32
31
+ return CMD_STALL;
33
/* First of all, some simple consistency checks */
34
- errmsg = "Invalid ELF image for this architecture";
35
if (!elf_check_ident(ehdr)) {
36
+ error_setg(&err, "Invalid ELF image for this architecture");
37
goto exit_errmsg;
38
}
32
}
39
bswap_ehdr(ehdr);
33
40
if (!elf_check_ehdr(ehdr)) {
34
eventid = (value & EVENTID_MASK);
41
+ error_setg(&err, "Invalid ELF image for this architecture");
35
@@ -XXX,XX +XXX,XX @@ static ItsCmdResult process_mapti(GICv3ITSState *s, uint64_t value,
42
goto exit_errmsg;
36
MEMTXATTRS_UNSPECIFIED, &res);
37
38
if (res != MEMTX_OK) {
39
- return result;
40
+ return CMD_STALL;
43
}
41
}
44
42
45
@@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd,
43
icid = value & ICID_MASK;
46
g_autofree char *interp_name = NULL;
44
@@ -XXX,XX +XXX,XX @@ static ItsCmdResult process_mapti(GICv3ITSState *s, uint64_t value,
47
45
dte = get_dte(s, devid, &res);
48
if (*pinterp_name) {
46
49
- errmsg = "Multiple PT_INTERP entries";
47
if (res != MEMTX_OK) {
50
+ error_setg(&err, "Multiple PT_INTERP entries");
48
- return result;
51
goto exit_errmsg;
49
+ return CMD_STALL;
52
}
50
}
51
dte_valid = FIELD_EX64(dte, DTE, VALID);
52
num_eventids = 1ULL << (FIELD_EX64(dte, DTE, SIZE) + 1);
53
@@ -XXX,XX +XXX,XX @@ static ItsCmdResult process_mapti(GICv3ITSState *s, uint64_t value,
54
* we ignore this command and move onto the next
55
* command in the queue
56
*/
57
- } else {
58
- /* add ite entry to interrupt translation table */
59
- IteEntry ite = {};
60
- ite.itel = FIELD_DP64(ite.itel, ITE_L, VALID, dte_valid);
61
- ite.itel = FIELD_DP64(ite.itel, ITE_L, INTTYPE, ITE_INTTYPE_PHYSICAL);
62
- ite.itel = FIELD_DP64(ite.itel, ITE_L, INTID, pIntid);
63
- ite.itel = FIELD_DP64(ite.itel, ITE_L, DOORBELL, INTID_SPURIOUS);
64
- ite.iteh = FIELD_DP32(ite.iteh, ITE_H, ICID, icid);
65
-
66
- result = update_ite(s, eventid, dte, ite) ? CMD_CONTINUE : CMD_STALL;
67
+ return CMD_CONTINUE;
68
}
69
70
- return result;
71
+ /* add ite entry to interrupt translation table */
72
+ ite.itel = FIELD_DP64(ite.itel, ITE_L, VALID, dte_valid);
73
+ ite.itel = FIELD_DP64(ite.itel, ITE_L, INTTYPE, ITE_INTTYPE_PHYSICAL);
74
+ ite.itel = FIELD_DP64(ite.itel, ITE_L, INTID, pIntid);
75
+ ite.itel = FIELD_DP64(ite.itel, ITE_L, DOORBELL, INTID_SPURIOUS);
76
+ ite.iteh = FIELD_DP32(ite.iteh, ITE_H, ICID, icid);
53
+
77
+
54
interp_name = g_malloc(eppnt->p_filesz);
78
+ return update_ite(s, eventid, dte, ite) ? CMD_CONTINUE : CMD_STALL;
55
- if (!interp_name) {
56
- goto exit_perror;
57
- }
58
59
if (eppnt->p_offset + eppnt->p_filesz <= BPRM_BUF_SIZE) {
60
memcpy(interp_name, bprm_buf + eppnt->p_offset,
61
@@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd,
62
retval = pread(image_fd, interp_name, eppnt->p_filesz,
63
eppnt->p_offset);
64
if (retval != eppnt->p_filesz) {
65
- goto exit_perror;
66
+ goto exit_read;
67
}
68
}
69
if (interp_name[eppnt->p_filesz - 1] != 0) {
70
- errmsg = "Invalid PT_INTERP entry";
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
}
79
}
132
80
81
static bool update_cte(GICv3ITSState *s, uint16_t icid, bool valid,
133
--
82
--
134
2.20.1
83
2.25.1
135
84
136
85
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
1
Fix process_mapc() to consistently return CMD_STALL for memory
2
errors and CMD_CONTINUE for parameter errors, as we claim in the
3
comments that we do.
2
4
3
Remove usage of TypeInfo::class_data. Instead fill the fields in
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
4
the corresponding class_init().
6
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Message-id: 20220111171048.3545974-10-peter.maydell@linaro.org
9
---
10
hw/intc/arm_gicv3_its.c | 8 +++-----
11
1 file changed, 3 insertions(+), 5 deletions(-)
5
12
6
So far all children use the same values for almost all fields,
13
diff --git a/hw/intc/arm_gicv3_its.c b/hw/intc/arm_gicv3_its.c
7
but we are going to add the BCM2711/BCM2838 SoC for the raspi4
8
machine which use different fields.
9
10
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
11
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
12
Message-id: 20201024170127.3592182-3-f4bug@amsat.org
13
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
14
---
15
hw/arm/bcm2836.c | 108 ++++++++++++++++++++++-------------------------
16
1 file changed, 51 insertions(+), 57 deletions(-)
17
18
diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c
19
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
20
--- a/hw/arm/bcm2836.c
15
--- a/hw/intc/arm_gicv3_its.c
21
+++ b/hw/arm/bcm2836.c
16
+++ b/hw/intc/arm_gicv3_its.c
22
@@ -XXX,XX +XXX,XX @@
17
@@ -XXX,XX +XXX,XX @@ static ItsCmdResult process_mapc(GICv3ITSState *s, uint32_t offset)
23
#include "hw/arm/raspi_platform.h"
18
uint64_t rdbase;
24
#include "hw/sysbus.h"
19
bool valid;
25
20
MemTxResult res = MEMTX_OK;
26
-typedef struct BCM283XInfo BCM283XInfo;
21
- ItsCmdResult result = CMD_STALL;
27
-
22
uint64_t value;
28
typedef struct BCM283XClass {
23
29
/*< private >*/
24
offset += NUM_BYTES_IN_DW;
30
DeviceClass parent_class;
25
@@ -XXX,XX +XXX,XX @@ static ItsCmdResult process_mapc(GICv3ITSState *s, uint32_t offset)
31
/*< public >*/
26
MEMTXATTRS_UNSPECIFIED, &res);
32
- const BCM283XInfo *info;
27
33
-} BCM283XClass;
28
if (res != MEMTX_OK) {
34
-
29
- return result;
35
-struct BCM283XInfo {
30
+ return CMD_STALL;
36
const char *name;
37
const char *cpu_type;
38
hwaddr peri_base; /* Peripheral base address seen by the CPU */
39
hwaddr ctrl_base; /* Interrupt controller and mailboxes etc. */
40
int clusterid;
41
-};
42
+} BCM283XClass;
43
44
#define BCM283X_CLASS(klass) \
45
OBJECT_CLASS_CHECK(BCM283XClass, (klass), TYPE_BCM283X)
46
#define BCM283X_GET_CLASS(obj) \
47
OBJECT_GET_CLASS(BCM283XClass, (obj), TYPE_BCM283X)
48
49
-static const BCM283XInfo bcm283x_socs[] = {
50
- {
51
- .name = TYPE_BCM2836,
52
- .cpu_type = ARM_CPU_TYPE_NAME("cortex-a7"),
53
- .peri_base = 0x3f000000,
54
- .ctrl_base = 0x40000000,
55
- .clusterid = 0xf,
56
- },
57
-#ifdef TARGET_AARCH64
58
- {
59
- .name = TYPE_BCM2837,
60
- .cpu_type = ARM_CPU_TYPE_NAME("cortex-a53"),
61
- .peri_base = 0x3f000000,
62
- .ctrl_base = 0x40000000,
63
- .clusterid = 0x0,
64
- },
65
-#endif
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
}
31
}
80
32
81
object_initialize_child(obj, "control", &s->control, TYPE_BCM2836_CONTROL);
33
icid = value & ICID_MASK;
82
@@ -XXX,XX +XXX,XX @@ static void bcm2836_realize(DeviceState *dev, Error **errp)
34
@@ -XXX,XX +XXX,XX @@ static ItsCmdResult process_mapc(GICv3ITSState *s, uint32_t offset)
83
{
35
* we ignore this command and move onto the next
84
BCM283XState *s = BCM283X(dev);
36
* command in the queue
85
BCM283XClass *bc = BCM283X_GET_CLASS(dev);
37
*/
86
- const BCM283XInfo *info = bc->info;
38
- } else {
87
Object *obj;
39
- result = update_cte(s, icid, valid, rdbase) ? CMD_CONTINUE : CMD_STALL;
88
int n;
40
+ return CMD_CONTINUE;
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
}
41
}
101
42
102
- sysbus_mmio_map(SYS_BUS_DEVICE(&s->control), 0, info->ctrl_base);
43
- return result;
103
+ sysbus_mmio_map(SYS_BUS_DEVICE(&s->control), 0, bc->ctrl_base);
44
+ return update_cte(s, icid, valid, rdbase) ? CMD_CONTINUE : CMD_STALL;
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
}
120
121
@@ -XXX,XX +XXX,XX @@ static Property bcm2836_props[] = {
122
static void bcm283x_class_init(ObjectClass *oc, void *data)
123
{
124
DeviceClass *dc = DEVICE_CLASS(oc);
125
- BCM283XClass *bc = BCM283X_CLASS(oc);
126
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
}
45
}
133
46
134
-static const TypeInfo bcm283x_type_info = {
47
static bool update_dte(GICv3ITSState *s, uint32_t devid, bool valid,
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
--
48
--
206
2.20.1
49
2.25.1
207
50
208
51
diff view generated by jsdifflib
1
From: Richard Henderson <richard.henderson@linaro.org>
1
Fix process_mapd() to consistently return CMD_STALL for memory
2
errors and CMD_CONTINUE for parameter errors, as we claim in the
3
comments that we do.
2
4
3
This is slightly clearer than just using strerror, though
5
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
4
the different forms produced by error_setg_file_open and
6
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
5
error_setg_errno isn't entirely convenient.
7
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
8
Message-id: 20220111171048.3545974-11-peter.maydell@linaro.org
9
---
10
hw/intc/arm_gicv3_its.c | 10 ++++------
11
1 file changed, 4 insertions(+), 6 deletions(-)
6
12
7
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
13
diff --git a/hw/intc/arm_gicv3_its.c b/hw/intc/arm_gicv3_its.c
8
Message-id: 20201021173749.111103-10-richard.henderson@linaro.org
9
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
10
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
11
---
12
linux-user/elfload.c | 15 ++++++++-------
13
1 file changed, 8 insertions(+), 7 deletions(-)
14
15
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
16
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
17
--- a/linux-user/elfload.c
15
--- a/hw/intc/arm_gicv3_its.c
18
+++ b/linux-user/elfload.c
16
+++ b/hw/intc/arm_gicv3_its.c
19
@@ -XXX,XX +XXX,XX @@ static void load_elf_interp(const char *filename, struct image_info *info,
17
@@ -XXX,XX +XXX,XX @@ static ItsCmdResult process_mapd(GICv3ITSState *s, uint64_t value,
20
char bprm_buf[BPRM_BUF_SIZE])
18
uint64_t itt_addr;
21
{
19
bool valid;
22
int fd, retval;
20
MemTxResult res = MEMTX_OK;
23
+ Error *err = NULL;
21
- ItsCmdResult result = CMD_STALL;
24
22
25
fd = open(path(filename), O_RDONLY);
23
devid = ((value & DEVID_MASK) >> DEVID_SHIFT);
26
if (fd < 0) {
24
27
- goto exit_perror;
25
@@ -XXX,XX +XXX,XX @@ static ItsCmdResult process_mapd(GICv3ITSState *s, uint64_t value,
28
+ error_setg_file_open(&err, errno, filename);
26
MEMTXATTRS_UNSPECIFIED, &res);
29
+ error_report_err(err);
27
30
+ exit(-1);
28
if (res != MEMTX_OK) {
29
- return result;
30
+ return CMD_STALL;
31
}
31
}
32
32
33
retval = read(fd, bprm_buf, BPRM_BUF_SIZE);
33
size = (value & SIZE_MASK);
34
if (retval < 0) {
34
@@ -XXX,XX +XXX,XX @@ static ItsCmdResult process_mapd(GICv3ITSState *s, uint64_t value,
35
- goto exit_perror;
35
MEMTXATTRS_UNSPECIFIED, &res);
36
+ error_setg_errno(&err, errno, "Error reading file header");
36
37
+ error_reportf_err(err, "%s: ", filename);
37
if (res != MEMTX_OK) {
38
+ exit(-1);
38
- return result;
39
+ return CMD_STALL;
39
}
40
}
40
+
41
41
if (retval < BPRM_BUF_SIZE) {
42
itt_addr = (value & ITTADDR_MASK) >> ITTADDR_SHIFT;
42
memset(bprm_buf + retval, 0, BPRM_BUF_SIZE - retval);
43
@@ -XXX,XX +XXX,XX @@ static ItsCmdResult process_mapd(GICv3ITSState *s, uint64_t value,
44
* we ignore this command and move onto the next
45
* command in the queue
46
*/
47
- } else {
48
- result = update_dte(s, devid, valid, size, itt_addr) ? CMD_CONTINUE : CMD_STALL;
49
+ return CMD_CONTINUE;
43
}
50
}
44
51
45
load_elf_image(filename, fd, info, NULL, bprm_buf);
52
- return result;
46
- return;
53
+ return update_dte(s, devid, valid, size, itt_addr) ? CMD_CONTINUE : CMD_STALL;
47
-
48
- exit_perror:
49
- fprintf(stderr, "%s: %s\n", filename, strerror(errno));
50
- exit(-1);
51
}
54
}
52
55
53
static int symfind(const void *s0, const void *s1)
56
/*
54
--
57
--
55
2.20.1
58
2.25.1
56
59
57
60
diff view generated by jsdifflib
Deleted patch
1
From: Pavel Dovgalyuk <pavel.dovgalyuk@ispras.ru>
2
1
3
This patch sets min_cpus field for xlnx-versal-virt platform,
4
because it always creates XLNX_VERSAL_NR_ACPUS cpus even with
5
-smp 1 command line option.
6
7
Signed-off-by: Pavel Dovgalyuk <pavel.dovgalyuk@ispras.ru>
8
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
9
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
10
Message-id: 160343854912.8460.17915238517799132371.stgit@pasha-ThinkPad-X280
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
12
---
13
hw/arm/xlnx-versal-virt.c | 1 +
14
1 file changed, 1 insertion(+)
15
16
diff --git a/hw/arm/xlnx-versal-virt.c b/hw/arm/xlnx-versal-virt.c
17
index XXXXXXX..XXXXXXX 100644
18
--- a/hw/arm/xlnx-versal-virt.c
19
+++ b/hw/arm/xlnx-versal-virt.c
20
@@ -XXX,XX +XXX,XX @@ static void versal_virt_machine_class_init(ObjectClass *oc, void *data)
21
22
mc->desc = "Xilinx Versal Virtual development board";
23
mc->init = versal_virt_init;
24
+ mc->min_cpus = XLNX_VERSAL_NR_ACPUS;
25
mc->max_cpus = XLNX_VERSAL_NR_ACPUS;
26
mc->default_cpus = XLNX_VERSAL_NR_ACPUS;
27
mc->no_cdrom = true;
28
--
29
2.20.1
30
31
diff view generated by jsdifflib
1
From: Luc Michel <luc@lmichel.fr>
1
The ITS has several tables which all share a similar format,
2
2
described by the TableDesc struct: the guest may configure them
3
A PLL channel is able to further divide the generated PLL frequency.
3
to be a single-level table or a two-level table. Currently we
4
The divider is given in the CTRL_A2W register. Some channels have an
4
open-code the process of finding the table entry in all the
5
additional fixed divider which is always applied to the signal.
5
functions which read or write the device table or the collection
6
6
table. Factor out the "get the address of the table entry"
7
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
7
logic into a new function, so that the code which needs to
8
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
8
read or write a table entry only needs to call table_entry_addr()
9
Signed-off-by: Luc Michel <luc@lmichel.fr>
9
and then perform a suitable load or store to that address.
10
Tested-by: Guenter Roeck <linux@roeck-us.net>
10
11
Note that the error handling is slightly complicated because
12
we want to handle two cases differently:
13
* failure to read the L1 table entry should end up causing
14
a command stall, like other kinds of DMA error
15
* an L1 table entry that says there is no L2 table for this
16
index (ie whose valid bit is 0) must result in us treating
17
the table entry as not-valid on read, and discarding
18
writes (this is mandated by the spec)
19
11
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
20
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
21
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
22
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
23
Message-id: 20220111171048.3545974-12-peter.maydell@linaro.org
12
---
24
---
13
hw/misc/bcm2835_cprman.c | 33 ++++++++++++++++++++++++++++++++-
25
hw/intc/arm_gicv3_its.c | 212 +++++++++++++---------------------------
14
1 file changed, 32 insertions(+), 1 deletion(-)
26
1 file changed, 70 insertions(+), 142 deletions(-)
15
27
16
diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c
28
diff --git a/hw/intc/arm_gicv3_its.c b/hw/intc/arm_gicv3_its.c
17
index XXXXXXX..XXXXXXX 100644
29
index XXXXXXX..XXXXXXX 100644
18
--- a/hw/misc/bcm2835_cprman.c
30
--- a/hw/intc/arm_gicv3_its.c
19
+++ b/hw/misc/bcm2835_cprman.c
31
+++ b/hw/intc/arm_gicv3_its.c
20
@@ -XXX,XX +XXX,XX @@ static const TypeInfo cprman_pll_info = {
32
@@ -XXX,XX +XXX,XX @@ static uint64_t baser_base_addr(uint64_t value, uint32_t page_sz)
21
33
return result;
22
/* PLL channel */
34
}
23
35
24
+static bool pll_channel_is_enabled(CprmanPllChannelState *channel)
36
+static uint64_t table_entry_addr(GICv3ITSState *s, TableDesc *td,
37
+ uint32_t idx, MemTxResult *res)
25
+{
38
+{
26
+ /*
39
+ /*
27
+ * XXX I'm not sure of the purpose of the LOAD field. The Linux driver does
40
+ * Given a TableDesc describing one of the ITS in-guest-memory
28
+ * not set it when enabling the channel, but does clear it when disabling
41
+ * tables and an index into it, return the guest address
29
+ * it.
42
+ * corresponding to that table entry.
43
+ * If there was a memory error reading the L1 table of an
44
+ * indirect table, *res is set accordingly, and we return -1.
45
+ * If the L1 table entry is marked not valid, we return -1 with
46
+ * *res set to MEMTX_OK.
47
+ *
48
+ * The specification defines the format of level 1 entries of a
49
+ * 2-level table, but the format of level 2 entries and the format
50
+ * of flat-mapped tables is IMPDEF.
30
+ */
51
+ */
31
+ return !FIELD_EX32(*channel->reg_a2w_ctrl, A2W_PLLx_CHANNELy, DISABLE)
52
+ AddressSpace *as = &s->gicv3->dma_as;
32
+ && !(*channel->reg_cm & channel->hold_mask);
53
+ uint32_t l2idx;
54
+ uint64_t l2;
55
+ uint32_t num_l2_entries;
56
+
57
+ *res = MEMTX_OK;
58
+
59
+ if (!td->indirect) {
60
+ /* Single level table */
61
+ return td->base_addr + idx * td->entry_sz;
62
+ }
63
+
64
+ /* Two level table */
65
+ l2idx = idx / (td->page_sz / L1TABLE_ENTRY_SIZE);
66
+
67
+ l2 = address_space_ldq_le(as,
68
+ td->base_addr + (l2idx * L1TABLE_ENTRY_SIZE),
69
+ MEMTXATTRS_UNSPECIFIED, res);
70
+ if (*res != MEMTX_OK) {
71
+ return -1;
72
+ }
73
+ if (!(l2 & L2_TABLE_VALID_MASK)) {
74
+ return -1;
75
+ }
76
+
77
+ num_l2_entries = td->page_sz / td->entry_sz;
78
+ return (l2 & ((1ULL << 51) - 1)) + (idx % num_l2_entries) * td->entry_sz;
33
+}
79
+}
34
+
80
+
35
static void pll_channel_update(CprmanPllChannelState *channel)
81
static bool get_cte(GICv3ITSState *s, uint16_t icid, uint64_t *cte,
82
MemTxResult *res)
36
{
83
{
37
- clock_update(channel->out, 0);
84
AddressSpace *as = &s->gicv3->dma_as;
38
+ uint64_t freq, div;
85
- uint64_t l2t_addr;
39
+
86
- uint64_t value;
40
+ if (!pll_channel_is_enabled(channel)) {
87
- bool valid_l2t;
41
+ clock_update(channel->out, 0);
88
- uint32_t l2t_id;
42
+ return;
89
- uint32_t num_l2_entries;
43
+ }
90
+ uint64_t entry_addr = table_entry_addr(s, &s->ct, icid, res);
44
+
91
45
+ div = FIELD_EX32(*channel->reg_a2w_ctrl, A2W_PLLx_CHANNELy, DIV);
92
- if (s->ct.indirect) {
46
+
93
- l2t_id = icid / (s->ct.page_sz / L1TABLE_ENTRY_SIZE);
47
+ if (!div) {
94
-
48
+ /*
95
- value = address_space_ldq_le(as,
49
+ * It seems that when the divider value is 0, it is considered as
96
- s->ct.base_addr +
50
+ * being maximum by the hardware (see the Linux driver).
97
- (l2t_id * L1TABLE_ENTRY_SIZE),
51
+ */
98
- MEMTXATTRS_UNSPECIFIED, res);
52
+ div = R_A2W_PLLx_CHANNELy_DIV_MASK;
99
-
53
+ }
100
- if (*res == MEMTX_OK) {
54
+
101
- valid_l2t = (value & L2_TABLE_VALID_MASK) != 0;
55
+ /* Some channels have an additional fixed divider */
102
-
56
+ freq = clock_get_hz(channel->pll_in) / (div * channel->fixed_divider);
103
- if (valid_l2t) {
57
+
104
- num_l2_entries = s->ct.page_sz / s->ct.entry_sz;
58
+ clock_update_hz(channel->out, freq);
105
-
59
}
106
- l2t_addr = value & ((1ULL << 51) - 1);
60
107
-
61
/* Update a PLL and all its channels */
108
- *cte = address_space_ldq_le(as, l2t_addr +
109
- ((icid % num_l2_entries) * GITS_CTE_SIZE),
110
- MEMTXATTRS_UNSPECIFIED, res);
111
- }
112
- }
113
- } else {
114
- /* Flat level table */
115
- *cte = address_space_ldq_le(as, s->ct.base_addr +
116
- (icid * GITS_CTE_SIZE),
117
- MEMTXATTRS_UNSPECIFIED, res);
118
+ if (entry_addr == -1) {
119
+ return false; /* not valid */
120
}
121
122
+ *cte = address_space_ldq_le(as, entry_addr, MEMTXATTRS_UNSPECIFIED, res);
123
return FIELD_EX64(*cte, CTE, VALID);
124
}
125
126
@@ -XXX,XX +XXX,XX @@ static bool get_ite(GICv3ITSState *s, uint32_t eventid, uint64_t dte,
127
static uint64_t get_dte(GICv3ITSState *s, uint32_t devid, MemTxResult *res)
128
{
129
AddressSpace *as = &s->gicv3->dma_as;
130
- uint64_t l2t_addr;
131
- uint64_t value;
132
- bool valid_l2t;
133
- uint32_t l2t_id;
134
- uint32_t num_l2_entries;
135
+ uint64_t entry_addr = table_entry_addr(s, &s->dt, devid, res);
136
137
- if (s->dt.indirect) {
138
- l2t_id = devid / (s->dt.page_sz / L1TABLE_ENTRY_SIZE);
139
-
140
- value = address_space_ldq_le(as,
141
- s->dt.base_addr +
142
- (l2t_id * L1TABLE_ENTRY_SIZE),
143
- MEMTXATTRS_UNSPECIFIED, res);
144
-
145
- if (*res == MEMTX_OK) {
146
- valid_l2t = (value & L2_TABLE_VALID_MASK) != 0;
147
-
148
- if (valid_l2t) {
149
- num_l2_entries = s->dt.page_sz / s->dt.entry_sz;
150
-
151
- l2t_addr = value & ((1ULL << 51) - 1);
152
-
153
- value = address_space_ldq_le(as, l2t_addr +
154
- ((devid % num_l2_entries) * GITS_DTE_SIZE),
155
- MEMTXATTRS_UNSPECIFIED, res);
156
- }
157
- }
158
- } else {
159
- /* Flat level table */
160
- value = address_space_ldq_le(as, s->dt.base_addr +
161
- (devid * GITS_DTE_SIZE),
162
- MEMTXATTRS_UNSPECIFIED, res);
163
+ if (entry_addr == -1) {
164
+ return 0; /* a DTE entry with the Valid bit clear */
165
}
166
-
167
- return value;
168
+ return address_space_ldq_le(as, entry_addr, MEMTXATTRS_UNSPECIFIED, res);
169
}
170
171
/*
172
@@ -XXX,XX +XXX,XX @@ static bool update_cte(GICv3ITSState *s, uint16_t icid, bool valid,
173
uint64_t rdbase)
174
{
175
AddressSpace *as = &s->gicv3->dma_as;
176
- uint64_t value;
177
- uint64_t l2t_addr;
178
- bool valid_l2t;
179
- uint32_t l2t_id;
180
- uint32_t num_l2_entries;
181
+ uint64_t entry_addr;
182
uint64_t cte = 0;
183
MemTxResult res = MEMTX_OK;
184
185
@@ -XXX,XX +XXX,XX @@ static bool update_cte(GICv3ITSState *s, uint16_t icid, bool valid,
186
cte = FIELD_DP64(cte, CTE, RDBASE, rdbase);
187
}
188
189
- /*
190
- * The specification defines the format of level 1 entries of a
191
- * 2-level table, but the format of level 2 entries and the format
192
- * of flat-mapped tables is IMPDEF.
193
- */
194
- if (s->ct.indirect) {
195
- l2t_id = icid / (s->ct.page_sz / L1TABLE_ENTRY_SIZE);
196
-
197
- value = address_space_ldq_le(as,
198
- s->ct.base_addr +
199
- (l2t_id * L1TABLE_ENTRY_SIZE),
200
- MEMTXATTRS_UNSPECIFIED, &res);
201
-
202
- if (res != MEMTX_OK) {
203
- return false;
204
- }
205
-
206
- valid_l2t = (value & L2_TABLE_VALID_MASK) != 0;
207
-
208
- if (valid_l2t) {
209
- num_l2_entries = s->ct.page_sz / s->ct.entry_sz;
210
-
211
- l2t_addr = value & ((1ULL << 51) - 1);
212
-
213
- address_space_stq_le(as, l2t_addr +
214
- ((icid % num_l2_entries) * GITS_CTE_SIZE),
215
- cte, MEMTXATTRS_UNSPECIFIED, &res);
216
- }
217
- } else {
218
- /* Flat level table */
219
- address_space_stq_le(as, s->ct.base_addr + (icid * GITS_CTE_SIZE),
220
- cte, MEMTXATTRS_UNSPECIFIED, &res);
221
- }
222
+ entry_addr = table_entry_addr(s, &s->ct, icid, &res);
223
if (res != MEMTX_OK) {
224
+ /* memory access error: stall */
225
return false;
226
- } else {
227
+ }
228
+ if (entry_addr == -1) {
229
+ /* No L2 table for this index: discard write and continue */
230
return true;
231
}
232
+
233
+ address_space_stq_le(as, entry_addr, cte, MEMTXATTRS_UNSPECIFIED, &res);
234
+ return res == MEMTX_OK;
235
}
236
237
static ItsCmdResult process_mapc(GICv3ITSState *s, uint32_t offset)
238
@@ -XXX,XX +XXX,XX @@ static bool update_dte(GICv3ITSState *s, uint32_t devid, bool valid,
239
uint8_t size, uint64_t itt_addr)
240
{
241
AddressSpace *as = &s->gicv3->dma_as;
242
- uint64_t value;
243
- uint64_t l2t_addr;
244
- bool valid_l2t;
245
- uint32_t l2t_id;
246
- uint32_t num_l2_entries;
247
+ uint64_t entry_addr;
248
uint64_t dte = 0;
249
MemTxResult res = MEMTX_OK;
250
251
@@ -XXX,XX +XXX,XX @@ static bool update_dte(GICv3ITSState *s, uint32_t devid, bool valid,
252
return true;
253
}
254
255
- /*
256
- * The specification defines the format of level 1 entries of a
257
- * 2-level table, but the format of level 2 entries and the format
258
- * of flat-mapped tables is IMPDEF.
259
- */
260
- if (s->dt.indirect) {
261
- l2t_id = devid / (s->dt.page_sz / L1TABLE_ENTRY_SIZE);
262
-
263
- value = address_space_ldq_le(as,
264
- s->dt.base_addr +
265
- (l2t_id * L1TABLE_ENTRY_SIZE),
266
- MEMTXATTRS_UNSPECIFIED, &res);
267
-
268
- if (res != MEMTX_OK) {
269
- return false;
270
- }
271
-
272
- valid_l2t = (value & L2_TABLE_VALID_MASK) != 0;
273
-
274
- if (valid_l2t) {
275
- num_l2_entries = s->dt.page_sz / s->dt.entry_sz;
276
-
277
- l2t_addr = value & ((1ULL << 51) - 1);
278
-
279
- address_space_stq_le(as, l2t_addr +
280
- ((devid % num_l2_entries) * GITS_DTE_SIZE),
281
- dte, MEMTXATTRS_UNSPECIFIED, &res);
282
- }
283
- } else {
284
- /* Flat level table */
285
- address_space_stq_le(as, s->dt.base_addr + (devid * GITS_DTE_SIZE),
286
- dte, MEMTXATTRS_UNSPECIFIED, &res);
287
- }
288
+ entry_addr = table_entry_addr(s, &s->dt, devid, &res);
289
if (res != MEMTX_OK) {
290
+ /* memory access error: stall */
291
return false;
292
- } else {
293
+ }
294
+ if (entry_addr == -1) {
295
+ /* No L2 table for this index: discard write and continue */
296
return true;
297
}
298
+ address_space_stq_le(as, entry_addr, dte, MEMTXATTRS_UNSPECIFIED, &res);
299
+ return res == MEMTX_OK;
300
}
301
302
static ItsCmdResult process_mapd(GICv3ITSState *s, uint64_t value,
62
--
303
--
63
2.20.1
304
2.25.1
64
305
65
306
diff view generated by jsdifflib
1
From: Hao Wu <wuhaotsh@google.com>
1
In a few places in the ITS command handling functions, we were
2
doing the range-check of an event ID or device ID only after using
3
it as a table index; move the checks to before the uses.
2
4
3
The watchdog is part of NPCM7XX's timer module. Its behavior is
5
This misordering wouldn't have very bad effects because the
4
controlled by the WTCR register in the timer.
6
tables are in guest memory anyway.
5
7
6
When enabled, the watchdog issues an interrupt signal after a pre-set
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7
amount of cycles, and issues a reset signal shortly after that.
9
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
10
Message-id: 20220111171048.3545974-13-peter.maydell@linaro.org
11
---
12
hw/intc/arm_gicv3_its.c | 42 ++++++++++++++++++++++++-----------------
13
1 file changed, 25 insertions(+), 17 deletions(-)
8
14
9
Reviewed-by: Tyrone Ting <kfting@nuvoton.com>
15
diff --git a/hw/intc/arm_gicv3_its.c b/hw/intc/arm_gicv3_its.c
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
16
index XXXXXXX..XXXXXXX 100644
29
--- a/include/hw/misc/npcm7xx_clk.h
17
--- a/hw/intc/arm_gicv3_its.c
30
+++ b/include/hw/misc/npcm7xx_clk.h
18
+++ b/hw/intc/arm_gicv3_its.c
31
@@ -XXX,XX +XXX,XX @@
19
@@ -XXX,XX +XXX,XX @@ static ItsCmdResult process_its_cmd(GICv3ITSState *s, uint64_t value,
32
*/
20
33
#define NPCM7XX_CLK_NR_REGS (0x70 / sizeof(uint32_t))
21
eventid = (value & EVENTID_MASK);
34
22
35
+#define NPCM7XX_WATCHDOG_RESET_GPIO_IN "npcm7xx-clk-watchdog-reset-gpio-in"
23
+ if (devid >= s->dt.num_ids) {
36
+
24
+ qemu_log_mask(LOG_GUEST_ERROR,
37
typedef struct NPCM7xxCLKState {
25
+ "%s: invalid command attributes: devid %d>=%d",
38
SysBusDevice parent;
26
+ __func__, devid, s->dt.num_ids);
39
27
+ return CMD_CONTINUE;
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
}
198
199
+/* Perform reset action triggered by a watchdog */
200
+static void npcm7xx_clk_perform_watchdog_reset(void *opaque, int n,
201
+ int level)
202
+{
203
+ NPCM7xxCLKState *clk = NPCM7XX_CLK(opaque);
204
+ uint32_t rcr;
205
+
206
+ g_assert(n >= 0 && n <= NPCM7XX_NR_WATCHDOGS);
207
+ rcr = clk->regs[NPCM7XX_CLK_WD0RCR + n];
208
+ if (rcr & NPCM7XX_CLK_WDRCR_CA9C) {
209
+ watchdog_perform_action();
210
+ } else {
211
+ qemu_log_mask(LOG_UNIMP,
212
+ "%s: only CPU reset is implemented. (requested 0x%" PRIx32")\n",
213
+ __func__, rcr);
214
+ }
215
+}
216
+
217
static const struct MemoryRegionOps npcm7xx_clk_ops = {
218
.read = npcm7xx_clk_read,
219
.write = npcm7xx_clk_write,
220
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_clk_init(Object *obj)
221
memory_region_init_io(&s->iomem, obj, &npcm7xx_clk_ops, s,
222
TYPE_NPCM7XX_CLK, 4 * KiB);
223
sysbus_init_mmio(&s->parent, &s->iomem);
224
+ qdev_init_gpio_in_named(DEVICE(s), npcm7xx_clk_perform_watchdog_reset,
225
+ NPCM7XX_WATCHDOG_RESET_GPIO_IN, NPCM7XX_NR_WATCHDOGS);
226
}
227
228
static const VMStateDescription vmstate_npcm7xx_clk = {
229
diff --git a/hw/timer/npcm7xx_timer.c b/hw/timer/npcm7xx_timer.c
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
+{
264
+ int64_t now;
265
+
266
+ now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
267
+ t->expires_ns = now + t->remaining_ns;
268
+ timer_mod(&t->qtimer, t->expires_ns);
269
+}
270
+
271
+/* Stop counting. Record the time remaining so we can continue later. */
272
+static void npcm7xx_timer_pause(NPCM7xxBaseTimer *t)
273
+{
274
+ int64_t now;
275
+
276
+ timer_del(&t->qtimer);
277
+ now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
278
+ t->remaining_ns = t->expires_ns - now;
279
+}
280
+
281
+/* Delete the timer and reset it to default state. */
282
+static void npcm7xx_timer_clear(NPCM7xxBaseTimer *t)
283
+{
284
+ timer_del(&t->qtimer);
285
+ t->expires_ns = 0;
286
+ t->remaining_ns = 0;
287
+}
288
+
289
/*
290
* Returns the index of timer in the tc->timer array. This can be used to
291
* locate the registers that belong to this timer.
292
@@ -XXX,XX +XXX,XX @@ static uint32_t npcm7xx_timer_ns_to_count(NPCM7xxTimer *t, int64_t ns)
293
return count;
294
}
295
296
+static uint32_t npcm7xx_watchdog_timer_prescaler(const NPCM7xxWatchdogTimer *t)
297
+{
298
+ switch (NPCM7XX_WTCR_WTCLK(t->wtcr)) {
299
+ case 0:
300
+ return 1;
301
+ case 1:
302
+ return 256;
303
+ case 2:
304
+ return 2048;
305
+ case 3:
306
+ return 65536;
307
+ default:
308
+ g_assert_not_reached();
309
+ }
310
+}
311
+
312
+static void npcm7xx_watchdog_timer_reset_cycles(NPCM7xxWatchdogTimer *t,
313
+ int64_t cycles)
314
+{
315
+ uint32_t prescaler = npcm7xx_watchdog_timer_prescaler(t);
316
+ int64_t ns = (NANOSECONDS_PER_SECOND / NPCM7XX_TIMER_REF_HZ) * cycles;
317
+
318
+ /*
319
+ * The reset function always clears the current timer. The caller of the
320
+ * this needs to decide whether to start the watchdog timer based on
321
+ * specific flag in WTCR.
322
+ */
323
+ npcm7xx_timer_clear(&t->base_timer);
324
+
325
+ ns *= prescaler;
326
+ t->base_timer.remaining_ns = ns;
327
+}
328
+
329
+static void npcm7xx_watchdog_timer_reset(NPCM7xxWatchdogTimer *t)
330
+{
331
+ int64_t cycles = 1;
332
+ uint32_t s = NPCM7XX_WTCR_WTIS(t->wtcr);
333
+
334
+ g_assert(s <= 3);
335
+
336
+ cycles <<= NPCM7XX_WATCHDOG_BASETIME_SHIFT;
337
+ cycles <<= 2 * s;
338
+
339
+ npcm7xx_watchdog_timer_reset_cycles(t, cycles);
340
+}
341
+
342
/*
343
* Raise the interrupt line if there's a pending interrupt and interrupts are
344
* enabled for this timer. If not, lower it.
345
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_check_interrupt(NPCM7xxTimer *t)
346
trace_npcm7xx_timer_irq(DEVICE(tc)->canonical_path, index, pending);
347
}
348
349
-/* Start or resume the timer. */
350
-static void npcm7xx_timer_start(NPCM7xxTimer *t)
351
-{
352
- int64_t now;
353
-
354
- now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
355
- t->expires_ns = now + t->remaining_ns;
356
- timer_mod(&t->qtimer, t->expires_ns);
357
-}
358
-
359
/*
360
* Called when the counter reaches zero. Sets the interrupt flag, and either
361
* restarts or disables the timer.
362
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_reached_zero(NPCM7xxTimer *t)
363
tc->tisr |= BIT(index);
364
365
if (t->tcsr & NPCM7XX_TCSR_PERIODIC) {
366
- t->remaining_ns = npcm7xx_timer_count_to_ns(t, t->ticr);
367
+ t->base_timer.remaining_ns = npcm7xx_timer_count_to_ns(t, t->ticr);
368
if (t->tcsr & NPCM7XX_TCSR_CEN) {
369
- npcm7xx_timer_start(t);
370
+ npcm7xx_timer_start(&t->base_timer);
371
}
372
} else {
373
t->tcsr &= ~(NPCM7XX_TCSR_CEN | NPCM7XX_TCSR_CACT);
374
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_reached_zero(NPCM7xxTimer *t)
375
npcm7xx_timer_check_interrupt(t);
376
}
377
378
-/* Stop counting. Record the time remaining so we can continue later. */
379
-static void npcm7xx_timer_pause(NPCM7xxTimer *t)
380
-{
381
- int64_t now;
382
-
383
- timer_del(&t->qtimer);
384
- now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
385
- t->remaining_ns = t->expires_ns - now;
386
-}
387
388
/*
389
* Restart the timer from its initial value. If the timer was enabled and stays
390
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_pause(NPCM7xxTimer *t)
391
*/
392
static void npcm7xx_timer_restart(NPCM7xxTimer *t, uint32_t old_tcsr)
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
+ }
28
+ }
469
+
29
+
470
+ t->wtcr = new_wtcr;
30
dte = get_dte(s, devid, &res);
471
+
31
472
+ if (new_wtcr & NPCM7XX_WTCR_WTR) {
32
if (res != MEMTX_OK) {
473
+ t->wtcr &= ~NPCM7XX_WTCR_WTR;
33
@@ -XXX,XX +XXX,XX @@ static ItsCmdResult process_its_cmd(GICv3ITSState *s, uint64_t value,
474
+ npcm7xx_watchdog_timer_reset(t);
34
475
+ if (new_wtcr & NPCM7XX_WTCR_WTE) {
35
num_eventids = 1ULL << (FIELD_EX64(dte, DTE, SIZE) + 1);
476
+ npcm7xx_timer_start(&t->base_timer);
36
477
+ }
37
+ if (eventid >= num_eventids) {
478
+ } else if ((old_wtcr ^ new_wtcr) & NPCM7XX_WTCR_WTE) {
38
+ qemu_log_mask(LOG_GUEST_ERROR,
479
+ if (new_wtcr & NPCM7XX_WTCR_WTE) {
39
+ "%s: invalid command attributes: eventid %d >= %"
480
+ npcm7xx_timer_start(&t->base_timer);
40
+ PRId64 "\n",
481
+ } else {
41
+ __func__, eventid, num_eventids);
482
+ npcm7xx_timer_pause(&t->base_timer);
42
+ return CMD_CONTINUE;
483
+ }
484
+ }
43
+ }
485
+
44
+
486
+}
45
ite_valid = get_ite(s, eventid, dte, &icid, &pIntid, &res);
487
+
46
if (res != MEMTX_OK) {
488
static hwaddr npcm7xx_tcsr_index(hwaddr reg)
47
return CMD_STALL;
489
{
48
@@ -XXX,XX +XXX,XX @@ static ItsCmdResult process_its_cmd(GICv3ITSState *s, uint64_t value,
490
switch (reg) {
49
return CMD_CONTINUE;
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
}
50
}
509
51
510
@@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_enter_reset(Object *obj, ResetType type)
52
- if (devid >= s->dt.num_ids) {
511
for (i = 0; i < NPCM7XX_TIMERS_PER_CTRL; i++) {
53
- qemu_log_mask(LOG_GUEST_ERROR,
512
NPCM7xxTimer *t = &s->timer[i];
54
- "%s: invalid command attributes: devid %d>=%d",
513
55
- __func__, devid, s->dt.num_ids);
514
- timer_del(&t->qtimer);
56
- return CMD_CONTINUE;
515
- t->expires_ns = 0;
57
- }
516
- t->remaining_ns = 0;
58
- if (eventid >= num_eventids) {
517
+ npcm7xx_timer_clear(&t->base_timer);
59
- qemu_log_mask(LOG_GUEST_ERROR,
518
t->tcsr = 0x00000005;
60
- "%s: invalid command attributes: eventid %d >= %"
519
t->ticr = 0x00000000;
61
- PRId64 "\n",
520
}
62
- __func__, eventid, num_eventids);
521
63
- return CMD_CONTINUE;
522
s->tisr = 0x00000000;
64
- }
523
- s->wtcr = 0x00000400;
65
-
524
+ /*
66
/*
525
+ * Set WTCLK to 1(default) and reset all flags except WTRF.
67
* Current implementation only supports rdbase == procnum
526
+ * WTRF is not reset during a core domain reset.
68
* Hence rdbase physical address is ignored
527
+ */
69
@@ -XXX,XX +XXX,XX @@ static ItsCmdResult process_mapti(GICv3ITSState *s, uint64_t value,
528
+ s->watchdog_timer.wtcr = 0x00000400 | (s->watchdog_timer.wtcr &
70
529
+ NPCM7XX_WTCR_WTRF);
71
icid = value & ICID_MASK;
530
+}
72
531
+
73
+ if (devid >= s->dt.num_ids) {
532
+static void npcm7xx_watchdog_timer_expired(void *opaque)
74
+ qemu_log_mask(LOG_GUEST_ERROR,
533
+{
75
+ "%s: invalid command attributes: devid %d>=%d",
534
+ NPCM7xxWatchdogTimer *t = opaque;
76
+ __func__, devid, s->dt.num_ids);
535
+
77
+ return CMD_CONTINUE;
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
+ }
78
+ }
977
+
79
+
978
+ return g_test_run();
80
dte = get_dte(s, devid, &res);
979
+}
81
980
diff --git a/MAINTAINERS b/MAINTAINERS
82
if (res != MEMTX_OK) {
981
index XXXXXXX..XXXXXXX 100644
83
@@ -XXX,XX +XXX,XX @@ static ItsCmdResult process_mapti(GICv3ITSState *s, uint64_t value,
982
--- a/MAINTAINERS
84
num_eventids = 1ULL << (FIELD_EX64(dte, DTE, SIZE) + 1);
983
+++ b/MAINTAINERS
85
num_intids = 1ULL << (GICD_TYPER_IDBITS + 1);
984
@@ -XXX,XX +XXX,XX @@ L: qemu-arm@nongnu.org
86
985
S: Supported
87
- if ((devid >= s->dt.num_ids) || (icid >= s->ct.num_ids)
986
F: hw/*/npcm7xx*
88
+ if ((icid >= s->ct.num_ids)
987
F: include/hw/*/npcm7xx*
89
|| !dte_valid || (eventid >= num_eventids) ||
988
+F: tests/qtest/npcm7xx*
90
(((pIntid < GICV3_LPI_INTID_START) || (pIntid >= num_intids)) &&
989
F: pc-bios/npcm7xx_bootrom.bin
91
(pIntid != INTID_SPURIOUS))) {
990
F: roms/vbootrom
92
qemu_log_mask(LOG_GUEST_ERROR,
991
93
"%s: invalid command attributes "
992
diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
94
- "devid %d or icid %d or eventid %d or pIntid %d or"
993
index XXXXXXX..XXXXXXX 100644
95
- "unmapped dte %d\n", __func__, devid, icid, eventid,
994
--- a/tests/qtest/meson.build
96
+ "icid %d or eventid %d or pIntid %d or"
995
+++ b/tests/qtest/meson.build
97
+ "unmapped dte %d\n", __func__, icid, eventid,
996
@@ -XXX,XX +XXX,XX @@ qtests_sparc64 = \
98
pIntid, dte_valid);
997
(config_all_devices.has_key('CONFIG_ISA_TESTDEV') ? ['endianness-test'] : []) + \
99
/*
998
['prom-env-test', 'boot-serial-test']
100
* in this implementation, in case of error
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
--
101
--
1006
2.20.1
102
2.25.1
1007
103
1008
104
diff view generated by jsdifflib
1
From: Havard Skinnemoen <hskinnemoen@google.com>
1
In process_its_cmd(), we read an ICID out of the interrupt table
2
entry, and then use it as an index into the collection table. Add a
3
check that it is within range for the collection table first.
2
4
3
The RNG module returns a byte of randomness when the Data Valid bit is
5
This check is not strictly necessary, because:
4
set.
6
* we range check the ICID from the guest before writing it into
7
the interrupt table entry, so the the only way to get an
8
out of range ICID in process_its_cmd() is if a badly-behaved
9
guest is writing directly to the interrupt table memory
10
* the collection table is in guest memory, so QEMU won't fall
11
over if we read off the end of it
5
12
6
This implementation ignores the prescaler setting, and loads a new value
13
However, it seems clearer to include the check.
7
into RNGD every time RNGCS is read while the RNG is enabled and random
8
data is available.
9
14
10
A qtest featuring some simple randomness tests is included.
15
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
16
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
17
Message-id: 20220111171048.3545974-14-peter.maydell@linaro.org
18
---
19
hw/intc/arm_gicv3_its.c | 7 +++++++
20
1 file changed, 7 insertions(+)
11
21
12
Reviewed-by: Tyrone Ting <kfting@nuvoton.com>
22
diff --git a/hw/intc/arm_gicv3_its.c b/hw/intc/arm_gicv3_its.c
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
23
index XXXXXXX..XXXXXXX 100644
33
--- a/docs/system/arm/nuvoton.rst
24
--- a/hw/intc/arm_gicv3_its.c
34
+++ b/docs/system/arm/nuvoton.rst
25
+++ b/hw/intc/arm_gicv3_its.c
35
@@ -XXX,XX +XXX,XX @@ Supported devices
26
@@ -XXX,XX +XXX,XX @@ static ItsCmdResult process_its_cmd(GICv3ITSState *s, uint64_t value,
36
* DDR4 memory controller (dummy interface indicating memory training is done)
27
return CMD_CONTINUE;
37
* OTP controllers (no protection features)
38
* Flash Interface Unit (FIU; no protection features)
39
+ * Random Number Generator (RNG)
40
41
Missing devices
42
---------------
43
@@ -XXX,XX +XXX,XX @@ Missing devices
44
* Peripheral SPI controller (PSPI)
45
* Analog to Digital Converter (ADC)
46
* SD/MMC host
47
- * Random Number Generator (RNG)
48
* PECI interface
49
* Pulse Width Modulation (PWM)
50
* Tachometer
51
diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h
52
index XXXXXXX..XXXXXXX 100644
53
--- a/include/hw/arm/npcm7xx.h
54
+++ b/include/hw/arm/npcm7xx.h
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
}
28
}
134
29
135
+ /* Random Number Generator. Cannot fail. */
30
+ if (icid >= s->ct.num_ids) {
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
+{
197
+ return (s->rngcs & NPCM7XX_RNGCS_RNGE) &&
198
+ (s->rngmode == NPCM7XX_RNGMODE_NORMAL);
199
+}
200
+
201
+static uint64_t npcm7xx_rng_read(void *opaque, hwaddr offset, unsigned size)
202
+{
203
+ NPCM7xxRNGState *s = opaque;
204
+ uint64_t value = 0;
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,
31
+ qemu_log_mask(LOG_GUEST_ERROR,
237
+ "%s: read from invalid offset 0x%" HWADDR_PRIx "\n",
32
+ "%s: invalid ICID 0x%x in ITE (table corrupted?)\n",
238
+ DEVICE(s)->canonical_path, offset);
33
+ __func__, icid);
239
+ break;
34
+ return CMD_CONTINUE;
240
+ }
35
+ }
241
+
36
+
242
+ trace_npcm7xx_rng_read(offset, value, size);
37
cte_valid = get_cte(s, icid, &cte, &res);
243
+
38
if (res != MEMTX_OK) {
244
+ return value;
39
return CMD_STALL;
245
+}
246
+
247
+static void npcm7xx_rng_write(void *opaque, hwaddr offset, uint64_t value,
248
+ unsigned size)
249
+{
250
+ NPCM7xxRNGState *s = opaque;
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
+}
274
+
275
+static const MemoryRegionOps npcm7xx_rng_ops = {
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
+{
288
+ NPCM7xxRNGState *s = NPCM7XX_RNG(obj);
289
+
290
+ s->rngcs = 0;
291
+ s->rngd = 0;
292
+ s->rngmode = 0;
293
+}
294
+
295
+static void npcm7xx_rng_init(Object *obj)
296
+{
297
+ NPCM7xxRNGState *s = NPCM7XX_RNG(obj);
298
+
299
+ memory_region_init_io(&s->iomem, obj, &npcm7xx_rng_ops, s, "regs",
300
+ NPCM7XX_RNG_REGS_SIZE);
301
+ sysbus_init_mmio(&s->parent, &s->iomem);
302
+}
303
+
304
+static const VMStateDescription vmstate_npcm7xx_rng = {
305
+ .name = "npcm7xx-rng",
306
+ .version_id = 0,
307
+ .minimum_version_id = 0,
308
+ .fields = (VMStateField[]) {
309
+ VMSTATE_UINT8(rngcs, NPCM7xxRNGState),
310
+ VMSTATE_UINT8(rngd, NPCM7xxRNGState),
311
+ VMSTATE_UINT8(rngmode, NPCM7xxRNGState),
312
+ VMSTATE_END_OF_LIST(),
313
+ },
314
+};
315
+
316
+static void npcm7xx_rng_class_init(ObjectClass *klass, void *data)
317
+{
318
+ ResettableClass *rc = RESETTABLE_CLASS(klass);
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
+}
325
+
326
+static const TypeInfo npcm7xx_rng_types[] = {
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
+{
382
+ writeb(RNG_BASE_ADDR + offset, value);
383
+}
384
+
385
+static uint8_t rng_readb(unsigned int offset)
386
+{
387
+ return readb(RNG_BASE_ADDR + offset);
388
+}
389
+
390
+/* Disable RNG and set normal ring oscillator mode. */
391
+static void rng_reset(void)
392
+{
393
+ rng_writeb(RNGCS, 0);
394
+ rng_writeb(RNGMODE, ROSEL_NORMAL);
395
+}
396
+
397
+/* Reset RNG and then enable it. */
398
+static void rng_reset_enable(void)
399
+{
400
+ rng_reset();
401
+ rng_writeb(RNGCS, RNGE);
402
+}
403
+
404
+/* Wait until Data Valid bit is set. */
405
+static bool rng_wait_ready(void)
406
+{
407
+ /* qemu_guest_getrandom may fail. Assume it won't fail 10 times in a row. */
408
+ int retries = 10;
409
+
410
+ while (retries-- > 0) {
411
+ if (rng_readb(RNGCS) & DVALID) {
412
+ return true;
413
+ }
414
+ }
415
+
416
+ return false;
417
+}
418
+
419
+/*
420
+ * Perform a frequency (monobit) test, as defined by NIST SP 800-22, on the
421
+ * sequence in buf and return the P-value. This represents the probability of a
422
+ * truly random sequence having the same proportion of zeros and ones as the
423
+ * sequence in buf.
424
+ *
425
+ * An RNG which always returns 0x00 or 0xff, or has some bits stuck at 0 or 1,
426
+ * will fail this test. However, an RNG which always returns 0x55, 0xf0 or some
427
+ * other value with an equal number of zeroes and ones will pass.
428
+ */
429
+static double calc_monobit_p(const uint8_t *buf, unsigned int len)
430
+{
431
+ unsigned int i;
432
+ double s_obs;
433
+ int sn = 0;
434
+
435
+ for (i = 0; i < len; i++) {
436
+ /*
437
+ * Each 1 counts as 1, each 0 counts as -1.
438
+ * s = cp - (8 - cp) = 2 * cp - 8
439
+ */
440
+ sn += 2 * ctpop8(buf[i]) - 8;
441
+ }
442
+
443
+ s_obs = abs(sn) / sqrt(len * BITS_PER_BYTE);
444
+
445
+ return erfc(s_obs / sqrt(2));
446
+}
447
+
448
+/*
449
+ * Perform a runs test, as defined by NIST SP 800-22, and return the P-value.
450
+ * This represents the probability of a truly random sequence having the same
451
+ * number of runs (i.e. uninterrupted sequences of identical bits) as the
452
+ * sequence in buf.
453
+ */
454
+static double calc_runs_p(const unsigned long *buf, unsigned int nr_bits)
455
+{
456
+ unsigned int j;
457
+ unsigned int k;
458
+ int nr_ones = 0;
459
+ int vn_obs = 0;
460
+ double pi;
461
+
462
+ g_assert(nr_bits % BITS_PER_LONG == 0);
463
+
464
+ for (j = 0; j < nr_bits / BITS_PER_LONG; j++) {
465
+ nr_ones += __builtin_popcountl(buf[j]);
466
+ }
467
+ pi = (double)nr_ones / nr_bits;
468
+
469
+ for (k = 0; k < nr_bits - 1; k++) {
470
+ vn_obs += !(test_bit(k, buf) ^ test_bit(k + 1, buf));
471
+ }
472
+ vn_obs += 1;
473
+
474
+ return erfc(fabs(vn_obs - 2 * nr_bits * pi * (1.0 - pi))
475
+ / (2 * sqrt(2 * nr_bits) * pi * (1.0 - pi)));
476
+}
477
+
478
+/*
479
+ * Verifies that DVALID is clear, and RNGD reads zero, when RNGE is cleared,
480
+ * and DVALID eventually becomes set when RNGE is set.
481
+ */
482
+static void test_enable_disable(void)
483
+{
484
+ /* Disable: DVALID should not be set, and RNGD should read zero */
485
+ rng_reset();
486
+ g_assert_cmphex(rng_readb(RNGCS), ==, 0);
487
+ g_assert_cmphex(rng_readb(RNGD), ==, 0);
488
+
489
+ /* Enable: DVALID should be set, but we can't make assumptions about RNGD */
490
+ rng_writeb(RNGCS, RNGE);
491
+ g_assert_true(rng_wait_ready());
492
+ g_assert_cmphex(rng_readb(RNGCS), ==, DVALID | RNGE);
493
+
494
+ /* Disable: DVALID should not be set, and RNGD should read zero */
495
+ rng_writeb(RNGCS, 0);
496
+ g_assert_cmphex(rng_readb(RNGCS), ==, 0);
497
+ g_assert_cmphex(rng_readb(RNGD), ==, 0);
498
+}
499
+
500
+/*
501
+ * Verifies that the RNG only produces data when RNGMODE is set to 'normal'
502
+ * ring oscillator mode.
503
+ */
504
+static void test_rosel(void)
505
+{
506
+ rng_reset_enable();
507
+ g_assert_true(rng_wait_ready());
508
+ rng_writeb(RNGMODE, 0);
509
+ g_assert_false(rng_wait_ready());
510
+ rng_writeb(RNGMODE, ROSEL_NORMAL);
511
+ g_assert_true(rng_wait_ready());
512
+ rng_writeb(RNGMODE, 0);
513
+ g_assert_false(rng_wait_ready());
514
+}
515
+
516
+/*
517
+ * Verifies that a continuous sequence of bits collected after enabling the RNG
518
+ * satisfies a monobit test.
519
+ */
520
+static void test_continuous_monobit(void)
521
+{
522
+ uint8_t buf[TEST_INPUT_BITS / BITS_PER_BYTE];
523
+ unsigned int i;
524
+
525
+ rng_reset_enable();
526
+ for (i = 0; i < sizeof(buf); i++) {
527
+ g_assert_true(rng_wait_ready());
528
+ buf[i] = rng_readb(RNGD);
529
+ }
530
+
531
+ g_assert_cmpfloat(calc_monobit_p(buf, sizeof(buf)), >, 0.01);
532
+}
533
+
534
+/*
535
+ * Verifies that a continuous sequence of bits collected after enabling the RNG
536
+ * satisfies a runs test.
537
+ */
538
+static void test_continuous_runs(void)
539
+{
540
+ union {
541
+ unsigned long l[TEST_INPUT_BITS / BITS_PER_LONG];
542
+ uint8_t c[TEST_INPUT_BITS / BITS_PER_BYTE];
543
+ } buf;
544
+ unsigned int i;
545
+
546
+ rng_reset_enable();
547
+ for (i = 0; i < sizeof(buf); i++) {
548
+ g_assert_true(rng_wait_ready());
549
+ buf.c[i] = rng_readb(RNGD);
550
+ }
551
+
552
+ g_assert_cmpfloat(calc_runs_p(buf.l, sizeof(buf) * BITS_PER_BYTE), >, 0.01);
553
+}
554
+
555
+/*
556
+ * Verifies that the first data byte collected after enabling the RNG satisfies
557
+ * a monobit test.
558
+ */
559
+static void test_first_byte_monobit(void)
560
+{
561
+ /* Enable, collect one byte, disable. Repeat until we have 100 bits. */
562
+ uint8_t buf[TEST_INPUT_BITS / BITS_PER_BYTE];
563
+ unsigned int i;
564
+
565
+ rng_reset();
566
+ for (i = 0; i < sizeof(buf); i++) {
567
+ rng_writeb(RNGCS, RNGE);
568
+ g_assert_true(rng_wait_ready());
569
+ buf[i] = rng_readb(RNGD);
570
+ rng_writeb(RNGCS, 0);
571
+ }
572
+
573
+ g_assert_cmpfloat(calc_monobit_p(buf, sizeof(buf)), >, 0.01);
574
+}
575
+
576
+/*
577
+ * Verifies that the first data byte collected after enabling the RNG satisfies
578
+ * a runs test.
579
+ */
580
+static void test_first_byte_runs(void)
581
+{
582
+ /* Enable, collect one byte, disable. Repeat until we have 100 bits. */
583
+ union {
584
+ unsigned long l[TEST_INPUT_BITS / BITS_PER_LONG];
585
+ uint8_t c[TEST_INPUT_BITS / BITS_PER_BYTE];
586
+ } buf;
587
+ unsigned int i;
588
+
589
+ rng_reset();
590
+ for (i = 0; i < sizeof(buf); i++) {
591
+ rng_writeb(RNGCS, RNGE);
592
+ g_assert_true(rng_wait_ready());
593
+ buf.c[i] = rng_readb(RNGD);
594
+ rng_writeb(RNGCS, 0);
595
+ }
596
+
597
+ g_assert_cmpfloat(calc_runs_p(buf.l, sizeof(buf) * BITS_PER_BYTE), >, 0.01);
598
+}
599
+
600
+int main(int argc, char **argv)
601
+{
602
+ int ret;
603
+
604
+ g_test_init(&argc, &argv, NULL);
605
+ g_test_set_nonfatal_assertions();
606
+
607
+ qtest_add_func("npcm7xx_rng/enable_disable", test_enable_disable);
608
+ qtest_add_func("npcm7xx_rng/rosel", test_rosel);
609
+ qtest_add_func("npcm7xx_rng/continuous/monobit", test_continuous_monobit);
610
+ qtest_add_func("npcm7xx_rng/continuous/runs", test_continuous_runs);
611
+ qtest_add_func("npcm7xx_rng/first_byte/monobit", test_first_byte_monobit);
612
+ qtest_add_func("npcm7xx_rng/first_byte/runs", test_first_byte_runs);
613
+
614
+ qtest_start("-machine npcm750-evb");
615
+ ret = g_test_run();
616
+ qtest_end();
617
+
618
+ return ret;
619
+}
620
diff --git a/hw/misc/meson.build b/hw/misc/meson.build
621
index XXXXXXX..XXXXXXX 100644
622
--- a/hw/misc/meson.build
623
+++ b/hw/misc/meson.build
624
@@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_MAINSTONE', if_true: files('mst_fpga.c'))
625
softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files(
626
'npcm7xx_clk.c',
627
'npcm7xx_gcr.c',
628
+ 'npcm7xx_rng.c',
629
))
630
softmmu_ss.add(when: 'CONFIG_OMAP', if_true: files(
631
'omap_clk.c',
632
diff --git a/hw/misc/trace-events b/hw/misc/trace-events
633
index XXXXXXX..XXXXXXX 100644
634
--- a/hw/misc/trace-events
635
+++ b/hw/misc/trace-events
636
@@ -XXX,XX +XXX,XX @@ npcm7xx_clk_write(uint64_t offset, uint32_t value) "offset: 0x%04" PRIx64 " valu
637
npcm7xx_gcr_read(uint64_t offset, uint32_t value) " offset: 0x%04" PRIx64 " value: 0x%08" PRIx32
638
npcm7xx_gcr_write(uint64_t offset, uint32_t value) "offset: 0x%04" PRIx64 " value: 0x%08" PRIx32
639
640
+# npcm7xx_rng.c
641
+npcm7xx_rng_read(uint64_t offset, uint64_t value, unsigned size) "offset: 0x%04" PRIx64 " value: 0x%02" PRIx64 " size: %u"
642
+npcm7xx_rng_write(uint64_t offset, uint64_t value, unsigned size) "offset: 0x%04" PRIx64 " value: 0x%02" PRIx64 " size: %u"
643
+
644
# stm32f4xx_syscfg.c
645
stm32f4xx_syscfg_set_irq(int gpio, int line, int level) "Interupt: GPIO: %d, Line: %d; Level: %d"
646
stm32f4xx_pulse_exti(int irq) "Pulse EXTI: %d"
647
diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
648
index XXXXXXX..XXXXXXX 100644
649
--- a/tests/qtest/meson.build
650
+++ b/tests/qtest/meson.build
651
@@ -XXX,XX +XXX,XX @@ qtests_sparc64 = \
652
(config_all_devices.has_key('CONFIG_ISA_TESTDEV') ? ['endianness-test'] : []) + \
653
['prom-env-test', 'boot-serial-test']
654
655
-qtests_npcm7xx = ['npcm7xx_timer-test', 'npcm7xx_watchdog_timer-test']
656
+qtests_npcm7xx = \
657
+ ['npcm7xx_rng-test',
658
+ 'npcm7xx_timer-test',
659
+ 'npcm7xx_watchdog_timer-test']
660
qtests_arm = \
661
(config_all_devices.has_key('CONFIG_PFLASH_CFI02') ? ['pflash-cfi02-test'] : []) + \
662
(config_all_devices.has_key('CONFIG_NPCM7XX') ? qtests_npcm7xx : []) + \
663
--
40
--
664
2.20.1
41
2.25.1
665
42
666
43
diff view generated by jsdifflib
Deleted patch
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
2
1
3
No code out of bcm2836.c uses (or requires) the BCM283XInfo
4
declarations. Move it locally to the C source file.
5
6
Reviewed-by: Luc Michel <luc.michel@greensocs.com>
7
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
8
Message-id: 20201024170127.3592182-2-f4bug@amsat.org
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
---
11
include/hw/arm/bcm2836.h | 8 --------
12
hw/arm/bcm2836.c | 14 ++++++++++++++
13
2 files changed, 14 insertions(+), 8 deletions(-)
14
15
diff --git a/include/hw/arm/bcm2836.h b/include/hw/arm/bcm2836.h
16
index XXXXXXX..XXXXXXX 100644
17
--- a/include/hw/arm/bcm2836.h
18
+++ b/include/hw/arm/bcm2836.h
19
@@ -XXX,XX +XXX,XX @@ struct BCM283XState {
20
BCM2835PeripheralState peripherals;
21
};
22
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
+
42
+typedef struct BCM283XClass {
43
+ /*< private >*/
44
+ DeviceClass parent_class;
45
+ /*< public >*/
46
+ const BCM283XInfo *info;
47
+} BCM283XClass;
48
+
49
struct BCM283XInfo {
50
const char *name;
51
const char *cpu_type;
52
@@ -XXX,XX +XXX,XX @@ struct BCM283XInfo {
53
int clusterid;
54
};
55
56
+#define BCM283X_CLASS(klass) \
57
+ OBJECT_CLASS_CHECK(BCM283XClass, (klass), TYPE_BCM283X)
58
+#define BCM283X_GET_CLASS(obj) \
59
+ OBJECT_GET_CLASS(BCM283XClass, (obj), TYPE_BCM283X)
60
+
61
static const BCM283XInfo bcm283x_socs[] = {
62
{
63
.name = TYPE_BCM2836,
64
--
65
2.20.1
66
67
diff view generated by jsdifflib
Deleted patch
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
2
1
3
The BCM2835 has only one core. Introduce the core_count field to
4
be able to use values different than BCM283X_NCPUS (4).
5
6
Reviewed-by: Luc Michel <luc.michel@greensocs.com>
7
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
8
Message-id: 20201024170127.3592182-4-f4bug@amsat.org
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
---
11
hw/arm/bcm2836.c | 5 ++++-
12
1 file changed, 4 insertions(+), 1 deletion(-)
13
14
diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c
15
index XXXXXXX..XXXXXXX 100644
16
--- a/hw/arm/bcm2836.c
17
+++ b/hw/arm/bcm2836.c
18
@@ -XXX,XX +XXX,XX @@ typedef struct BCM283XClass {
19
/*< public >*/
20
const char *name;
21
const char *cpu_type;
22
+ unsigned core_count;
23
hwaddr peri_base; /* Peripheral base address seen by the CPU */
24
hwaddr ctrl_base; /* Interrupt controller and mailboxes etc. */
25
int clusterid;
26
@@ -XXX,XX +XXX,XX @@ static void bcm2836_init(Object *obj)
27
BCM283XClass *bc = BCM283X_GET_CLASS(obj);
28
int n;
29
30
- for (n = 0; n < BCM283X_NCPUS; n++) {
31
+ for (n = 0; n < bc->core_count; n++) {
32
object_initialize_child(obj, "cpu[*]", &s->cpu[n].core,
33
bc->cpu_type);
34
}
35
@@ -XXX,XX +XXX,XX @@ static void bcm2836_class_init(ObjectClass *oc, void *data)
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
--
52
2.20.1
53
54
diff view generated by jsdifflib
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
1
From: Philippe Mathieu-Daudé <philmd@redhat.com>
2
2
3
The realize() function is clearly composed of two parts,
3
Quoting Peter Maydell:
4
each described by a comment:
5
4
6
void realize()
5
"These MEMTX_* aren't from the memory transaction
7
{
6
API functions; they're just being used by gicd_readl() and
8
/* common peripherals from bcm2835 */
7
friends as a way to indicate a success/failure so that the
9
...
8
actual MemoryRegionOps read/write fns like gicv3_dist_read()
10
/* bcm2836 interrupt controller (and mailboxes, etc.) */
9
can log a guest error."
11
...
12
}
13
10
14
Split the two part, so we can reuse the common part with other
11
We are going to introduce more MemTxResult bits, so it is
15
SoCs from this family.
12
safer to check for !MEMTX_OK rather than MEMTX_ERROR.
16
13
17
Reviewed-by: Luc Michel <luc.michel@greensocs.com>
14
Reviewed-by: Peter Xu <peterx@redhat.com>
18
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
15
Reviewed-by: David Hildenbrand <david@redhat.com>
19
Message-id: 20201024170127.3592182-6-f4bug@amsat.org
16
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
17
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
18
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
20
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
19
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
21
---
20
---
22
hw/arm/bcm2836.c | 22 ++++++++++++++++++----
21
hw/intc/arm_gicv3_redist.c | 4 ++--
23
1 file changed, 18 insertions(+), 4 deletions(-)
22
1 file changed, 2 insertions(+), 2 deletions(-)
24
23
25
diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c
24
diff --git a/hw/intc/arm_gicv3_redist.c b/hw/intc/arm_gicv3_redist.c
26
index XXXXXXX..XXXXXXX 100644
25
index XXXXXXX..XXXXXXX 100644
27
--- a/hw/arm/bcm2836.c
26
--- a/hw/intc/arm_gicv3_redist.c
28
+++ b/hw/arm/bcm2836.c
27
+++ b/hw/intc/arm_gicv3_redist.c
29
@@ -XXX,XX +XXX,XX @@ static void bcm2836_init(Object *obj)
28
@@ -XXX,XX +XXX,XX @@ MemTxResult gicv3_redist_read(void *opaque, hwaddr offset, uint64_t *data,
30
qdev_prop_set_uint32(DEVICE(obj), "enabled-cpus", bc->core_count);
29
break;
31
}
30
}
32
31
33
- object_initialize_child(obj, "control", &s->control, TYPE_BCM2836_CONTROL);
32
- if (r == MEMTX_ERROR) {
34
+ if (bc->ctrl_base) {
33
+ if (r != MEMTX_OK) {
35
+ object_initialize_child(obj, "control", &s->control,
34
qemu_log_mask(LOG_GUEST_ERROR,
36
+ TYPE_BCM2836_CONTROL);
35
"%s: invalid guest read at offset " TARGET_FMT_plx
37
+ }
36
" size %u\n", __func__, offset, size);
38
37
@@ -XXX,XX +XXX,XX @@ MemTxResult gicv3_redist_write(void *opaque, hwaddr offset, uint64_t data,
39
object_initialize_child(obj, "peripherals", &s->peripherals,
38
break;
40
TYPE_BCM2835_PERIPHERALS);
41
@@ -XXX,XX +XXX,XX @@ static void bcm2836_init(Object *obj)
42
"vcram-size");
43
}
44
45
-static void bcm2836_realize(DeviceState *dev, Error **errp)
46
+static bool bcm283x_common_realize(DeviceState *dev, Error **errp)
47
{
48
BCM283XState *s = BCM283X(dev);
49
BCM283XClass *bc = BCM283X_GET_CLASS(dev);
50
Object *obj;
51
- int n;
52
53
/* common peripherals from bcm2835 */
54
55
@@ -XXX,XX +XXX,XX @@ static void bcm2836_realize(DeviceState *dev, Error **errp)
56
object_property_add_const_link(OBJECT(&s->peripherals), "ram", obj);
57
58
if (!sysbus_realize(SYS_BUS_DEVICE(&s->peripherals), errp)) {
59
- return;
60
+ return false;
61
}
39
}
62
40
63
object_property_add_alias(OBJECT(s), "sd-bus", OBJECT(&s->peripherals),
41
- if (r == MEMTX_ERROR) {
64
@@ -XXX,XX +XXX,XX @@ static void bcm2836_realize(DeviceState *dev, Error **errp)
42
+ if (r != MEMTX_OK) {
65
43
qemu_log_mask(LOG_GUEST_ERROR,
66
sysbus_mmio_map_overlap(SYS_BUS_DEVICE(&s->peripherals), 0,
44
"%s: invalid guest write at offset " TARGET_FMT_plx
67
bc->peri_base, 1);
45
" size %u\n", __func__, offset, size);
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
--
46
--
84
2.20.1
47
2.25.1
85
48
86
49
diff view generated by jsdifflib
Deleted patch
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
2
1
3
The Pi A is almost the first machine released.
4
It uses a BCM2835 SoC which includes a ARMv6Z core.
5
6
Example booting the machine using content from [*]
7
(we use the device tree from the B model):
8
9
$ qemu-system-arm -M raspi1ap -serial stdio \
10
-kernel raspberrypi/firmware/boot/kernel.img \
11
-dtb raspberrypi/firmware/boot/bcm2708-rpi-b-plus.dtb \
12
-append 'earlycon=pl011,0x20201000 console=ttyAMA0'
13
[ 0.000000] Booting Linux on physical CPU 0x0
14
[ 0.000000] Linux version 4.19.118+ (dom@buildbot) (gcc version 4.9.3 (crosstool-NG crosstool-ng-1.22.0-88-g8460611)) #1311 Mon Apr 27 14:16:15 BST 2020
15
[ 0.000000] CPU: ARMv6-compatible processor [410fb767] revision 7 (ARMv7), cr=00c5387d
16
[ 0.000000] CPU: VIPT aliasing data cache, unknown instruction cache
17
[ 0.000000] OF: fdt: Machine model: Raspberry Pi Model B+
18
...
19
20
[*] http://archive.raspberrypi.org/debian/pool/main/r/raspberrypi-firmware/raspberrypi-kernel_1.20200512-2_armhf.deb
21
22
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
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>
26
---
27
hw/arm/raspi.c | 13 +++++++++++++
28
1 file changed, 13 insertions(+)
29
30
diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c
31
index XXXXXXX..XXXXXXX 100644
32
--- a/hw/arm/raspi.c
33
+++ b/hw/arm/raspi.c
34
@@ -XXX,XX +XXX,XX @@ static void raspi_machine_class_common_init(MachineClass *mc,
35
mc->default_ram_id = "ram";
36
};
37
38
+static void raspi1ap_machine_class_init(ObjectClass *oc, void *data)
39
+{
40
+ MachineClass *mc = MACHINE_CLASS(oc);
41
+ RaspiMachineClass *rmc = RASPI_MACHINE_CLASS(oc);
42
+
43
+ rmc->board_rev = 0x900021; /* Revision 1.1 */
44
+ raspi_machine_class_common_init(mc, rmc->board_rev);
45
+};
46
+
47
static void raspi2b_machine_class_init(ObjectClass *oc, void *data)
48
{
49
MachineClass *mc = MACHINE_CLASS(oc);
50
@@ -XXX,XX +XXX,XX @@ static void raspi3b_machine_class_init(ObjectClass *oc, void *data)
51
52
static const TypeInfo raspi_machine_types[] = {
53
{
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
--
62
2.20.1
63
64
diff view generated by jsdifflib
Deleted patch
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
2
1
3
Similarly to the Pi A, the Pi Zero uses a BCM2835 SoC (ARMv6Z core).
4
5
The only difference between the revision 1.2 and 1.3 is the latter
6
exposes a CSI camera connector. As we do not implement the Unicam
7
peripheral, there is no point in exposing a camera connector :)
8
Therefore we choose to model the 1.2 revision.
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>
30
---
31
hw/arm/raspi.c | 13 +++++++++++++
32
1 file changed, 13 insertions(+)
33
34
diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c
35
index XXXXXXX..XXXXXXX 100644
36
--- a/hw/arm/raspi.c
37
+++ b/hw/arm/raspi.c
38
@@ -XXX,XX +XXX,XX @@ static void raspi_machine_class_common_init(MachineClass *mc,
39
mc->default_ram_id = "ram";
40
};
41
42
+static void raspi0_machine_class_init(ObjectClass *oc, void *data)
43
+{
44
+ MachineClass *mc = MACHINE_CLASS(oc);
45
+ RaspiMachineClass *rmc = RASPI_MACHINE_CLASS(oc);
46
+
47
+ rmc->board_rev = 0x920092; /* Revision 1.2 */
48
+ raspi_machine_class_common_init(mc, rmc->board_rev);
49
+};
50
+
51
static void raspi1ap_machine_class_init(ObjectClass *oc, void *data)
52
{
53
MachineClass *mc = MACHINE_CLASS(oc);
54
@@ -XXX,XX +XXX,XX @@ static void raspi3b_machine_class_init(ObjectClass *oc, void *data)
55
56
static const TypeInfo raspi_machine_types[] = {
57
{
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
--
66
2.20.1
67
68
diff view generated by jsdifflib
Deleted patch
1
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
2
1
3
Use of 0x%d - make up our mind as 0x%x
4
5
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
6
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
7
Acked-by: Eric Auger <eric.auger@redhat.com>
8
Message-id: 20201014193355.53074-1-dgilbert@redhat.com
9
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
10
---
11
hw/arm/trace-events | 2 +-
12
1 file changed, 1 insertion(+), 1 deletion(-)
13
14
diff --git a/hw/arm/trace-events b/hw/arm/trace-events
15
index XXXXXXX..XXXXXXX 100644
16
--- a/hw/arm/trace-events
17
+++ b/hw/arm/trace-events
18
@@ -XXX,XX +XXX,XX @@ smmuv3_get_cd(uint64_t addr) "CD addr: 0x%"PRIx64
19
smmuv3_decode_cd(uint32_t oas) "oas=%d"
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
smmuv3_cmdq_cfgi_ste(int streamid) "streamid =%d"
22
-smmuv3_cmdq_cfgi_ste_range(int start, int end) "start=0x%d - end=0x%d"
23
+smmuv3_cmdq_cfgi_ste_range(int start, int end) "start=0x%x - end=0x%x"
24
smmuv3_cmdq_cfgi_cd(uint32_t sid) "streamid = %d"
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
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
--
28
2.20.1
29
30
diff view generated by jsdifflib
Deleted patch
1
From: Luc Michel <luc@lmichel.fr>
2
1
3
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
4
Reviewed-by: Damien Hedde <damien.hedde@greensocs.com>
5
Signed-off-by: Luc Michel <luc@lmichel.fr>
6
Tested-by: Guenter Roeck <linux@roeck-us.net>
7
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
8
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
9
---
10
include/hw/clock.h | 5 +++++
11
1 file changed, 5 insertions(+)
12
13
diff --git a/include/hw/clock.h b/include/hw/clock.h
14
index XXXXXXX..XXXXXXX 100644
15
--- a/include/hw/clock.h
16
+++ b/include/hw/clock.h
17
@@ -XXX,XX +XXX,XX @@ extern const VMStateDescription vmstate_clock;
18
VMSTATE_CLOCK_V(field, state, 0)
19
#define VMSTATE_CLOCK_V(field, state, version) \
20
VMSTATE_STRUCT_POINTER_V(field, state, version, vmstate_clock, Clock)
21
+#define VMSTATE_ARRAY_CLOCK(field, state, num) \
22
+ VMSTATE_ARRAY_CLOCK_V(field, state, num, 0)
23
+#define VMSTATE_ARRAY_CLOCK_V(field, state, num, version) \
24
+ VMSTATE_ARRAY_OF_POINTER_TO_STRUCT(field, state, num, version, \
25
+ vmstate_clock, Clock)
26
27
/**
28
* clock_setup_canonical_path:
29
--
30
2.20.1
31
32
diff view generated by jsdifflib