1 | Another lump of target-arm patches. I still have some patches in | 1 | Last minute pullreq for arm related patches; quite large because |
---|---|---|---|
2 | my to-review queue, but this is a big enough set that I wanted | 2 | there were several series that only just made it through code review |
3 | to send it out. | 3 | in time. |
4 | 4 | ||
5 | thanks | 5 | thanks |
6 | -- PMM | 6 | -- PMM |
7 | 7 | ||
8 | The following changes since commit 04bb7fe2bf55bdf66d5b7a5a719b40bbb4048178: | 8 | The following changes since commit 091e3e3dbc499d84c004e1c50bc9870af37f6e99: |
9 | 9 | ||
10 | Merge remote-tracking branch 'remotes/rth/tags/pull-tcg-20180208' into staging (2018-02-08 17:41:15 +0000) | 10 | Merge remote-tracking branch 'remotes/ericb/tags/pull-bitmaps-2020-10-26' into staging (2020-10-26 22:36:35 +0000) |
11 | 11 | ||
12 | are available in the Git repository at: | 12 | are available in the Git repository at: |
13 | 13 | ||
14 | git://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20180209 | 14 | https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20201027-1 |
15 | 15 | ||
16 | for you to fetch changes up to bbba7757bacc9f890a3f028d328b4b429dbe78ec: | 16 | for you to fetch changes up to 32bd322a0134ed89db00f2b9b3894982db3dedcb: |
17 | 17 | ||
18 | hw/core/generic-loader: Allow PC to be set on command line (2018-02-09 10:55:40 +0000) | 18 | hw/timer/armv7m_systick: Rewrite to use ptimers (2020-10-27 11:15:31 +0000) |
19 | 19 | ||
20 | ---------------------------------------------------------------- | 20 | ---------------------------------------------------------------- |
21 | target-arm queue: | 21 | target-arm queue: |
22 | * Support M profile derived exceptions on exception entry and exit | 22 | * raspi: add model of cprman clock manager |
23 | * Implement AArch64 v8.2 crypto insns (SHA-512, SHA-3, SM3, SM4) | 23 | * sbsa-ref: add an SBSA generic watchdog device |
24 | * Implement working i.MX6 SD controller | 24 | * arm/trace: Fix hex printing |
25 | * Various devices preparatory to i.MX7 support | 25 | * raspi: Add models of Pi 3 model A+, Pi Zero and Pi A+ |
26 | * Preparatory patches for SVE emulation | 26 | * hw/arm/smmuv3: Set the restoration priority of the vSMMUv3 explicitly |
27 | * v8M: Fix bug in implementation of 'TT' insn | 27 | * Nuvoton NPCM7xx: Add USB, RNG, GPIO and watchdog support |
28 | * Give useful error if user tries to use userspace GICv3 with KVM | 28 | * hw/arm: fix min_cpus for xlnx-versal-virt platform |
29 | * hw/arm/highbank: Silence warnings about missing fallthrough statements | ||
30 | * linux-user: Support Aarch64 BTI | ||
31 | * Armv7M systick: fix corner case bugs by rewriting to use ptimer | ||
29 | 32 | ||
30 | ---------------------------------------------------------------- | 33 | ---------------------------------------------------------------- |
31 | Andrey Smirnov (10): | 34 | Dr. David Alan Gilbert (1): |
32 | sdhci: Add i.MX specific subtype of SDHCI | 35 | arm/trace: Fix hex printing |
33 | hw: i.MX: Convert i.MX6 to use TYPE_IMX_USDHC | ||
34 | i.MX: Add code to emulate i.MX7 CCM, PMU and ANALOG IP blocks | ||
35 | i.MX: Add code to emulate i.MX2 watchdog IP block | ||
36 | i.MX: Add code to emulate i.MX7 SNVS IP-block | ||
37 | i.MX: Add code to emulate GPCv2 IP block | ||
38 | i.MX: Add i.MX7 GPT variant | ||
39 | i.MX: Add implementation of i.MX7 GPR IP block | ||
40 | usb: Add basic code to emulate Chipidea USB IP | ||
41 | hw/arm: Move virt's PSCI DT fixup code to arm/boot.c | ||
42 | 36 | ||
43 | Ard Biesheuvel (5): | 37 | Hao Wu (1): |
44 | target/arm: implement SHA-512 instructions | 38 | hw/timer: Adding watchdog for NPCM7XX Timer. |
45 | target/arm: implement SHA-3 instructions | ||
46 | target/arm: implement SM3 instructions | ||
47 | target/arm: implement SM4 instructions | ||
48 | target/arm: enable user-mode SHA-3, SM3, SM4 and SHA-512 instruction support | ||
49 | 39 | ||
50 | Christoffer Dall (1): | 40 | Havard Skinnemoen (4): |
51 | target/arm/kvm: gic: Prevent creating userspace GICv3 with KVM | 41 | Move npcm7xx_timer_reached_zero call out of npcm7xx_timer_pause |
42 | hw/misc: Add npcm7xx random number generator | ||
43 | hw/arm/npcm7xx: Add EHCI and OHCI controllers | ||
44 | hw/gpio: Add GPIO model for Nuvoton NPCM7xx | ||
52 | 45 | ||
53 | Peter Maydell (9): | 46 | Luc Michel (14): |
54 | target/arm: Add armv7m_nvic_set_pending_derived() | 47 | hw/core/clock: provide the VMSTATE_ARRAY_CLOCK macro |
55 | target/arm: Split "get pending exception info" from "acknowledge it" | 48 | hw/core/clock: trace clock values in Hz instead of ns |
56 | target/arm: Add ignore_stackfaults argument to v7m_exception_taken() | 49 | hw/arm/raspi: fix CPRMAN base address |
57 | target/arm: Make v7M exception entry stack push check MPU | 50 | hw/arm/raspi: add a skeleton implementation of the CPRMAN |
58 | target/arm: Make v7m_push_callee_stack() honour MPU | 51 | hw/misc/bcm2835_cprman: add a PLL skeleton implementation |
59 | target/arm: Make exception vector loads honour the SAU | 52 | hw/misc/bcm2835_cprman: implement PLLs behaviour |
60 | target/arm: Handle exceptions during exception stack pop | 53 | hw/misc/bcm2835_cprman: add a PLL channel skeleton implementation |
61 | target/arm/translate.c: Fix missing 'break' for TT insns | 54 | hw/misc/bcm2835_cprman: implement PLL channels behaviour |
62 | hw/core/generic-loader: Allow PC to be set on command line | 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 | ||
63 | 61 | ||
64 | Richard Henderson (5): | 62 | Pavel Dovgalyuk (1): |
65 | target/arm: Expand vector registers for SVE | 63 | hw/arm: fix min_cpus for xlnx-versal-virt platform |
66 | target/arm: Add predicate registers for SVE | ||
67 | target/arm: Add SVE to migration state | ||
68 | target/arm: Add ZCR_ELx | ||
69 | target/arm: Add SVE state to TB->FLAGS | ||
70 | 64 | ||
71 | hw/intc/Makefile.objs | 2 +- | 65 | Peter Maydell (2): |
72 | hw/misc/Makefile.objs | 4 + | 66 | hw/core/ptimer: Support ptimer being disabled by timer callback |
73 | hw/usb/Makefile.objs | 1 + | 67 | hw/timer/armv7m_systick: Rewrite to use ptimers |
74 | hw/sd/sdhci-internal.h | 23 ++ | ||
75 | include/hw/intc/imx_gpcv2.h | 22 ++ | ||
76 | include/hw/misc/imx2_wdt.h | 33 +++ | ||
77 | include/hw/misc/imx7_ccm.h | 139 +++++++++++ | ||
78 | include/hw/misc/imx7_gpr.h | 28 +++ | ||
79 | include/hw/misc/imx7_snvs.h | 35 +++ | ||
80 | include/hw/sd/sdhci.h | 13 ++ | ||
81 | include/hw/timer/imx_gpt.h | 1 + | ||
82 | include/hw/usb/chipidea.h | 16 ++ | ||
83 | target/arm/cpu.h | 120 ++++++++-- | ||
84 | target/arm/helper.h | 12 + | ||
85 | target/arm/kvm_arm.h | 4 + | ||
86 | target/arm/translate.h | 2 + | ||
87 | hw/arm/boot.c | 65 ++++++ | ||
88 | hw/arm/fsl-imx6.c | 2 +- | ||
89 | hw/arm/virt.c | 61 ----- | ||
90 | hw/core/generic-loader.c | 2 +- | ||
91 | hw/intc/armv7m_nvic.c | 98 +++++++- | ||
92 | hw/intc/imx_gpcv2.c | 125 ++++++++++ | ||
93 | hw/misc/imx2_wdt.c | 89 +++++++ | ||
94 | hw/misc/imx7_ccm.c | 277 ++++++++++++++++++++++ | ||
95 | hw/misc/imx7_gpr.c | 124 ++++++++++ | ||
96 | hw/misc/imx7_snvs.c | 83 +++++++ | ||
97 | hw/sd/sdhci.c | 230 ++++++++++++++++++- | ||
98 | hw/timer/imx_gpt.c | 25 ++ | ||
99 | hw/usb/chipidea.c | 176 ++++++++++++++ | ||
100 | linux-user/elfload.c | 19 ++ | ||
101 | target/arm/cpu64.c | 4 + | ||
102 | target/arm/crypto_helper.c | 277 +++++++++++++++++++++- | ||
103 | target/arm/helper.c | 548 +++++++++++++++++++++++++++++++++++++------- | ||
104 | target/arm/machine.c | 88 ++++++- | ||
105 | target/arm/translate-a64.c | 350 +++++++++++++++++++++++++++- | ||
106 | target/arm/translate.c | 8 +- | ||
107 | hw/intc/trace-events | 5 +- | ||
108 | hw/misc/trace-events | 4 + | ||
109 | 38 files changed, 2928 insertions(+), 187 deletions(-) | ||
110 | create mode 100644 include/hw/intc/imx_gpcv2.h | ||
111 | create mode 100644 include/hw/misc/imx2_wdt.h | ||
112 | create mode 100644 include/hw/misc/imx7_ccm.h | ||
113 | create mode 100644 include/hw/misc/imx7_gpr.h | ||
114 | create mode 100644 include/hw/misc/imx7_snvs.h | ||
115 | create mode 100644 include/hw/usb/chipidea.h | ||
116 | create mode 100644 hw/intc/imx_gpcv2.c | ||
117 | create mode 100644 hw/misc/imx2_wdt.c | ||
118 | create mode 100644 hw/misc/imx7_ccm.c | ||
119 | create mode 100644 hw/misc/imx7_gpr.c | ||
120 | create mode 100644 hw/misc/imx7_snvs.c | ||
121 | create mode 100644 hw/usb/chipidea.c | ||
122 | 68 | ||
69 | Philippe Mathieu-Daudé (10): | ||
70 | linux-user/elfload: Avoid leaking interp_name using GLib memory API | ||
71 | hw/arm/bcm2836: Restrict BCM283XInfo declaration to C source | ||
72 | hw/arm/bcm2836: QOM'ify more by adding class_init() to each SoC type | ||
73 | hw/arm/bcm2836: Introduce BCM283XClass::core_count | ||
74 | hw/arm/bcm2836: Only provide "enabled-cpus" property to multicore SoCs | ||
75 | hw/arm/bcm2836: Split out common realize() code | ||
76 | hw/arm/bcm2836: Introduce the BCM2835 SoC | ||
77 | hw/arm/raspi: Add the Raspberry Pi A+ machine | ||
78 | hw/arm/raspi: Add the Raspberry Pi Zero machine | ||
79 | hw/arm/raspi: Add the Raspberry Pi 3 model A+ | ||
80 | |||
81 | Richard Henderson (11): | ||
82 | linux-user/aarch64: Reset btype for signals | ||
83 | linux-user: Set PAGE_TARGET_1 for TARGET_PROT_BTI | ||
84 | include/elf: Add defines related to GNU property notes for AArch64 | ||
85 | linux-user/elfload: Fix coding style in load_elf_image | ||
86 | linux-user/elfload: Adjust iteration over phdr | ||
87 | linux-user/elfload: Move PT_INTERP detection to first loop | ||
88 | linux-user/elfload: Use Error for load_elf_image | ||
89 | linux-user/elfload: Use Error for load_elf_interp | ||
90 | linux-user/elfload: Parse NT_GNU_PROPERTY_TYPE_0 notes | ||
91 | linux-user/elfload: Parse GNU_PROPERTY_AARCH64_FEATURE_1_AND | ||
92 | tests/tcg/aarch64: Add bti smoke tests | ||
93 | |||
94 | Shashi Mallela (2): | ||
95 | hw/watchdog: Implement SBSA watchdog device | ||
96 | hw/arm/sbsa-ref: add SBSA watchdog device | ||
97 | |||
98 | Thomas Huth (1): | ||
99 | hw/arm/highbank: Silence warnings about missing fallthrough statements | ||
100 | |||
101 | Zenghui Yu (1): | ||
102 | hw/arm/smmuv3: Set the restoration priority of the vSMMUv3 explicitly | ||
103 | |||
104 | docs/system/arm/nuvoton.rst | 6 +- | ||
105 | hw/usb/hcd-ehci.h | 1 + | ||
106 | include/elf.h | 22 + | ||
107 | include/exec/cpu-all.h | 2 + | ||
108 | include/hw/arm/bcm2835_peripherals.h | 5 +- | ||
109 | include/hw/arm/bcm2836.h | 9 +- | ||
110 | include/hw/arm/npcm7xx.h | 8 + | ||
111 | include/hw/arm/raspi_platform.h | 5 +- | ||
112 | include/hw/char/pl011.h | 1 + | ||
113 | include/hw/clock.h | 5 + | ||
114 | include/hw/gpio/npcm7xx_gpio.h | 55 ++ | ||
115 | include/hw/misc/bcm2835_cprman.h | 210 ++++++ | ||
116 | include/hw/misc/bcm2835_cprman_internals.h | 1019 ++++++++++++++++++++++++++++ | ||
117 | include/hw/misc/npcm7xx_clk.h | 2 + | ||
118 | include/hw/misc/npcm7xx_rng.h | 34 + | ||
119 | include/hw/timer/armv7m_systick.h | 3 +- | ||
120 | include/hw/timer/npcm7xx_timer.h | 48 +- | ||
121 | include/hw/watchdog/sbsa_gwdt.h | 79 +++ | ||
122 | linux-user/qemu.h | 4 + | ||
123 | linux-user/syscall_defs.h | 4 + | ||
124 | target/arm/cpu.h | 5 + | ||
125 | hw/arm/bcm2835_peripherals.c | 15 +- | ||
126 | hw/arm/bcm2836.c | 182 +++-- | ||
127 | hw/arm/highbank.c | 2 + | ||
128 | hw/arm/npcm7xx.c | 126 +++- | ||
129 | hw/arm/raspi.c | 41 ++ | ||
130 | hw/arm/sbsa-ref.c | 23 + | ||
131 | hw/arm/smmuv3.c | 1 + | ||
132 | hw/arm/xlnx-versal-virt.c | 1 + | ||
133 | hw/char/pl011.c | 45 ++ | ||
134 | hw/core/clock.c | 6 +- | ||
135 | hw/core/ptimer.c | 4 + | ||
136 | hw/gpio/npcm7xx_gpio.c | 424 ++++++++++++ | ||
137 | hw/misc/bcm2835_cprman.c | 808 ++++++++++++++++++++++ | ||
138 | hw/misc/npcm7xx_clk.c | 28 + | ||
139 | hw/misc/npcm7xx_rng.c | 180 +++++ | ||
140 | hw/timer/armv7m_systick.c | 124 ++-- | ||
141 | hw/timer/npcm7xx_timer.c | 270 ++++++-- | ||
142 | hw/usb/hcd-ehci-sysbus.c | 19 + | ||
143 | hw/watchdog/sbsa_gwdt.c | 293 ++++++++ | ||
144 | linux-user/aarch64/signal.c | 10 +- | ||
145 | linux-user/elfload.c | 326 +++++++-- | ||
146 | linux-user/mmap.c | 16 + | ||
147 | target/arm/translate-a64.c | 6 +- | ||
148 | tests/qtest/npcm7xx_gpio-test.c | 385 +++++++++++ | ||
149 | tests/qtest/npcm7xx_rng-test.c | 278 ++++++++ | ||
150 | tests/qtest/npcm7xx_watchdog_timer-test.c | 319 +++++++++ | ||
151 | tests/tcg/aarch64/bti-1.c | 62 ++ | ||
152 | tests/tcg/aarch64/bti-2.c | 116 ++++ | ||
153 | tests/tcg/aarch64/bti-crt.inc.c | 51 ++ | ||
154 | MAINTAINERS | 1 + | ||
155 | hw/arm/Kconfig | 1 + | ||
156 | hw/arm/trace-events | 2 +- | ||
157 | hw/char/trace-events | 1 + | ||
158 | hw/core/trace-events | 4 +- | ||
159 | hw/gpio/meson.build | 1 + | ||
160 | hw/gpio/trace-events | 7 + | ||
161 | hw/misc/meson.build | 2 + | ||
162 | hw/misc/trace-events | 9 + | ||
163 | hw/watchdog/Kconfig | 3 + | ||
164 | hw/watchdog/meson.build | 1 + | ||
165 | tests/qtest/meson.build | 6 +- | ||
166 | tests/tcg/aarch64/Makefile.target | 10 + | ||
167 | tests/tcg/configure.sh | 4 + | ||
168 | 64 files changed, 5461 insertions(+), 279 deletions(-) | ||
169 | create mode 100644 include/hw/gpio/npcm7xx_gpio.h | ||
170 | create mode 100644 include/hw/misc/bcm2835_cprman.h | ||
171 | create mode 100644 include/hw/misc/bcm2835_cprman_internals.h | ||
172 | create mode 100644 include/hw/misc/npcm7xx_rng.h | ||
173 | create mode 100644 include/hw/watchdog/sbsa_gwdt.h | ||
174 | create mode 100644 hw/gpio/npcm7xx_gpio.c | ||
175 | create mode 100644 hw/misc/bcm2835_cprman.c | ||
176 | create mode 100644 hw/misc/npcm7xx_rng.c | ||
177 | create mode 100644 hw/watchdog/sbsa_gwdt.c | ||
178 | create mode 100644 tests/qtest/npcm7xx_gpio-test.c | ||
179 | create mode 100644 tests/qtest/npcm7xx_rng-test.c | ||
180 | create mode 100644 tests/qtest/npcm7xx_watchdog_timer-test.c | ||
181 | create mode 100644 tests/tcg/aarch64/bti-1.c | ||
182 | create mode 100644 tests/tcg/aarch64/bti-2.c | ||
183 | create mode 100644 tests/tcg/aarch64/bti-crt.inc.c | ||
184 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Richard Henderson <richard.henderson@linaro.org> | ||
1 | 2 | ||
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: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Change vfp.regs as a uint64_t to vfp.zregs as an ARMVectorReg. | 3 | Transform the prot bit to a qemu internal page bit, and save |
4 | The previous patches have made the change in representation | 4 | it in the page tables. |
5 | relatively painless. | ||
6 | 5 | ||
7 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
8 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Message-id: 20201021173749.111103-3-richard.henderson@linaro.org |
10 | Message-id: 20180123035349.24538-2-richard.henderson@linaro.org | ||
11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
12 | --- | 10 | --- |
13 | target/arm/cpu.h | 59 +++++++++++++++++++++++++++++++--------------- | 11 | include/exec/cpu-all.h | 2 ++ |
14 | target/arm/machine.c | 35 ++++++++++++++++++++++++++- | 12 | linux-user/syscall_defs.h | 4 ++++ |
15 | target/arm/translate-a64.c | 8 +++---- | 13 | target/arm/cpu.h | 5 +++++ |
16 | target/arm/translate.c | 7 +++--- | 14 | linux-user/mmap.c | 16 ++++++++++++++++ |
17 | 4 files changed, 81 insertions(+), 28 deletions(-) | 15 | target/arm/translate-a64.c | 6 +++--- |
16 | 5 files changed, 30 insertions(+), 3 deletions(-) | ||
18 | 17 | ||
18 | diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h | ||
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/include/exec/cpu-all.h | ||
21 | +++ b/include/exec/cpu-all.h | ||
22 | @@ -XXX,XX +XXX,XX @@ extern intptr_t qemu_host_page_mask; | ||
23 | /* FIXME: Code that sets/uses this is broken and needs to go away. */ | ||
24 | #define PAGE_RESERVED 0x0020 | ||
25 | #endif | ||
26 | +/* Target-specific bits that will be used via page_get_flags(). */ | ||
27 | +#define PAGE_TARGET_1 0x0080 | ||
28 | |||
29 | #if defined(CONFIG_USER_ONLY) | ||
30 | void page_dump(FILE *f); | ||
31 | diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h | ||
32 | index XXXXXXX..XXXXXXX 100644 | ||
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 */ | ||
19 | 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 |
20 | index XXXXXXX..XXXXXXX 100644 | 47 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/target/arm/cpu.h | 48 | --- a/target/arm/cpu.h |
22 | +++ b/target/arm/cpu.h | 49 | +++ b/target/arm/cpu.h |
23 | @@ -XXX,XX +XXX,XX @@ typedef struct { | 50 | @@ -XXX,XX +XXX,XX @@ static inline MemTxAttrs *typecheck_memtxattrs(MemTxAttrs *x) |
24 | uint32_t base_mask; | 51 | #define arm_tlb_bti_gp(x) (typecheck_memtxattrs(x)->target_tlb_bit0) |
25 | } TCR; | 52 | #define arm_tlb_mte_tagged(x) (typecheck_memtxattrs(x)->target_tlb_bit1) |
26 | 53 | ||
27 | +/* Define a maximum sized vector register. | 54 | +/* |
28 | + * For 32-bit, this is a 128-bit NEON/AdvSIMD register. | 55 | + * AArch64 usage of the PAGE_TARGET_* bits for linux-user. |
29 | + * For 64-bit, this is a 2048-bit SVE register. | ||
30 | + * | ||
31 | + * Note that the mapping between S, D, and Q views of the register bank | ||
32 | + * differs between AArch64 and AArch32. | ||
33 | + * In AArch32: | ||
34 | + * Qn = regs[n].d[1]:regs[n].d[0] | ||
35 | + * Dn = regs[n / 2].d[n & 1] | ||
36 | + * Sn = regs[n / 4].d[n % 4 / 2], | ||
37 | + * bits 31..0 for even n, and bits 63..32 for odd n | ||
38 | + * (and regs[16] to regs[31] are inaccessible) | ||
39 | + * In AArch64: | ||
40 | + * Zn = regs[n].d[*] | ||
41 | + * Qn = regs[n].d[1]:regs[n].d[0] | ||
42 | + * Dn = regs[n].d[0] | ||
43 | + * Sn = regs[n].d[0] bits 31..0 | ||
44 | + * | ||
45 | + * This corresponds to the architecturally defined mapping between | ||
46 | + * the two execution states, and means we do not need to explicitly | ||
47 | + * map these registers when changing states. | ||
48 | + * | ||
49 | + * Align the data for use with TCG host vector operations. | ||
50 | + */ | 56 | + */ |
57 | +#define PAGE_BTI PAGE_TARGET_1 | ||
51 | + | 58 | + |
59 | /* | ||
60 | * Naming convention for isar_feature functions: | ||
61 | * Functions which test 32-bit ID registers should have _aa32_ in | ||
62 | diff --git a/linux-user/mmap.c b/linux-user/mmap.c | ||
63 | index XXXXXXX..XXXXXXX 100644 | ||
64 | --- a/linux-user/mmap.c | ||
65 | +++ b/linux-user/mmap.c | ||
66 | @@ -XXX,XX +XXX,XX @@ static int validate_prot_to_pageflags(int *host_prot, int prot) | ||
67 | *host_prot = (prot & (PROT_READ | PROT_WRITE)) | ||
68 | | (prot & PROT_EXEC ? PROT_READ : 0); | ||
69 | |||
52 | +#ifdef TARGET_AARCH64 | 70 | +#ifdef TARGET_AARCH64 |
53 | +# define ARM_MAX_VQ 16 | 71 | + /* |
54 | +#else | 72 | + * The PROT_BTI bit is only accepted if the cpu supports the feature. |
55 | +# define ARM_MAX_VQ 1 | 73 | + * Since this is the unusual case, don't bother checking unless |
74 | + * the bit has been requested. If set and valid, record the bit | ||
75 | + * within QEMU's page_flags. | ||
76 | + */ | ||
77 | + if (prot & TARGET_PROT_BTI) { | ||
78 | + ARMCPU *cpu = ARM_CPU(thread_cpu); | ||
79 | + if (cpu_isar_feature(aa64_bti, cpu)) { | ||
80 | + valid |= TARGET_PROT_BTI; | ||
81 | + page_flags |= PAGE_BTI; | ||
82 | + } | ||
83 | + } | ||
56 | +#endif | 84 | +#endif |
57 | + | 85 | + |
58 | +typedef struct ARMVectorReg { | 86 | return prot & ~valid ? 0 : page_flags; |
59 | + uint64_t d[2 * ARM_MAX_VQ] QEMU_ALIGNED(16); | ||
60 | +} ARMVectorReg; | ||
61 | + | ||
62 | + | ||
63 | typedef struct CPUARMState { | ||
64 | /* Regs for current mode. */ | ||
65 | uint32_t regs[16]; | ||
66 | @@ -XXX,XX +XXX,XX @@ typedef struct CPUARMState { | ||
67 | |||
68 | /* VFP coprocessor state. */ | ||
69 | struct { | ||
70 | - /* VFP/Neon register state. Note that the mapping between S, D and Q | ||
71 | - * views of the register bank differs between AArch64 and AArch32: | ||
72 | - * In AArch32: | ||
73 | - * Qn = regs[2n+1]:regs[2n] | ||
74 | - * Dn = regs[n] | ||
75 | - * Sn = regs[n/2] bits 31..0 for even n, and bits 63..32 for odd n | ||
76 | - * (and regs[32] to regs[63] are inaccessible) | ||
77 | - * In AArch64: | ||
78 | - * Qn = regs[2n+1]:regs[2n] | ||
79 | - * Dn = regs[2n] | ||
80 | - * Sn = regs[2n] bits 31..0 | ||
81 | - * This corresponds to the architecturally defined mapping between | ||
82 | - * the two execution states, and means we do not need to explicitly | ||
83 | - * map these registers when changing states. | ||
84 | - */ | ||
85 | - uint64_t regs[64] QEMU_ALIGNED(16); | ||
86 | + ARMVectorReg zregs[32]; | ||
87 | |||
88 | uint32_t xregs[16]; | ||
89 | /* We store these fpcsr fields separately for convenience. */ | ||
90 | @@ -XXX,XX +XXX,XX @@ static inline void *arm_get_el_change_hook_opaque(ARMCPU *cpu) | ||
91 | */ | ||
92 | static inline uint64_t *aa32_vfp_dreg(CPUARMState *env, unsigned regno) | ||
93 | { | ||
94 | - return &env->vfp.regs[regno]; | ||
95 | + return &env->vfp.zregs[regno >> 1].d[regno & 1]; | ||
96 | } | 87 | } |
97 | 88 | ||
98 | /** | ||
99 | @@ -XXX,XX +XXX,XX @@ static inline uint64_t *aa32_vfp_dreg(CPUARMState *env, unsigned regno) | ||
100 | */ | ||
101 | static inline uint64_t *aa32_vfp_qreg(CPUARMState *env, unsigned regno) | ||
102 | { | ||
103 | - return &env->vfp.regs[2 * regno]; | ||
104 | + return &env->vfp.zregs[regno].d[0]; | ||
105 | } | ||
106 | |||
107 | /** | ||
108 | @@ -XXX,XX +XXX,XX @@ static inline uint64_t *aa32_vfp_qreg(CPUARMState *env, unsigned regno) | ||
109 | */ | ||
110 | static inline uint64_t *aa64_vfp_qreg(CPUARMState *env, unsigned regno) | ||
111 | { | ||
112 | - return &env->vfp.regs[2 * regno]; | ||
113 | + return &env->vfp.zregs[regno].d[0]; | ||
114 | } | ||
115 | |||
116 | #endif | ||
117 | diff --git a/target/arm/machine.c b/target/arm/machine.c | ||
118 | index XXXXXXX..XXXXXXX 100644 | ||
119 | --- a/target/arm/machine.c | ||
120 | +++ b/target/arm/machine.c | ||
121 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_vfp = { | ||
122 | .minimum_version_id = 3, | ||
123 | .needed = vfp_needed, | ||
124 | .fields = (VMStateField[]) { | ||
125 | - VMSTATE_UINT64_ARRAY(env.vfp.regs, ARMCPU, 64), | ||
126 | + /* For compatibility, store Qn out of Zn here. */ | ||
127 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[0].d, ARMCPU, 0, 2), | ||
128 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[1].d, ARMCPU, 0, 2), | ||
129 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[2].d, ARMCPU, 0, 2), | ||
130 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[3].d, ARMCPU, 0, 2), | ||
131 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[4].d, ARMCPU, 0, 2), | ||
132 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[5].d, ARMCPU, 0, 2), | ||
133 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[6].d, ARMCPU, 0, 2), | ||
134 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[7].d, ARMCPU, 0, 2), | ||
135 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[8].d, ARMCPU, 0, 2), | ||
136 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[9].d, ARMCPU, 0, 2), | ||
137 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[10].d, ARMCPU, 0, 2), | ||
138 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[11].d, ARMCPU, 0, 2), | ||
139 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[12].d, ARMCPU, 0, 2), | ||
140 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[13].d, ARMCPU, 0, 2), | ||
141 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[14].d, ARMCPU, 0, 2), | ||
142 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[15].d, ARMCPU, 0, 2), | ||
143 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[16].d, ARMCPU, 0, 2), | ||
144 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[17].d, ARMCPU, 0, 2), | ||
145 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[18].d, ARMCPU, 0, 2), | ||
146 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[19].d, ARMCPU, 0, 2), | ||
147 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[20].d, ARMCPU, 0, 2), | ||
148 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[21].d, ARMCPU, 0, 2), | ||
149 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[22].d, ARMCPU, 0, 2), | ||
150 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[23].d, ARMCPU, 0, 2), | ||
151 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[24].d, ARMCPU, 0, 2), | ||
152 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[25].d, ARMCPU, 0, 2), | ||
153 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[26].d, ARMCPU, 0, 2), | ||
154 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[27].d, ARMCPU, 0, 2), | ||
155 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[28].d, ARMCPU, 0, 2), | ||
156 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[29].d, ARMCPU, 0, 2), | ||
157 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[30].d, ARMCPU, 0, 2), | ||
158 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[31].d, ARMCPU, 0, 2), | ||
159 | + | ||
160 | /* The xregs array is a little awkward because element 1 (FPSCR) | ||
161 | * requires a specific accessor, so we have to split it up in | ||
162 | * the vmstate: | ||
163 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | 89 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c |
164 | index XXXXXXX..XXXXXXX 100644 | 90 | index XXXXXXX..XXXXXXX 100644 |
165 | --- a/target/arm/translate-a64.c | 91 | --- a/target/arm/translate-a64.c |
166 | +++ b/target/arm/translate-a64.c | 92 | +++ b/target/arm/translate-a64.c |
167 | @@ -XXX,XX +XXX,XX @@ static inline int vec_reg_offset(DisasContext *s, int regno, | 93 | @@ -XXX,XX +XXX,XX @@ static void disas_data_proc_simd_fp(DisasContext *s, uint32_t insn) |
94 | */ | ||
95 | static bool is_guarded_page(CPUARMState *env, DisasContext *s) | ||
168 | { | 96 | { |
169 | int offs = 0; | 97 | -#ifdef CONFIG_USER_ONLY |
170 | #ifdef HOST_WORDS_BIGENDIAN | 98 | - return false; /* FIXME */ |
171 | - /* This is complicated slightly because vfp.regs[2n] is | 99 | -#else |
172 | - * still the low half and vfp.regs[2n+1] the high half | 100 | uint64_t addr = s->base.pc_first; |
173 | + /* This is complicated slightly because vfp.zregs[n].d[0] is | 101 | +#ifdef CONFIG_USER_ONLY |
174 | + * still the low half and vfp.zregs[n].d[1] the high half | 102 | + return page_get_flags(addr) & PAGE_BTI; |
175 | * of the 128 bit vector, even on big endian systems. | 103 | +#else |
176 | * Calculate the offset assuming a fully bigendian 128 bits, | 104 | int mmu_idx = arm_to_core_mmu_idx(s->mmu_idx); |
177 | * then XOR to account for the order of the two 64 bit halves. | 105 | unsigned int index = tlb_index(env, mmu_idx, addr); |
178 | @@ -XXX,XX +XXX,XX @@ static inline int vec_reg_offset(DisasContext *s, int regno, | 106 | CPUTLBEntry *entry = tlb_entry(env, mmu_idx, addr); |
179 | #else | ||
180 | offs += element * (1 << size); | ||
181 | #endif | ||
182 | - offs += offsetof(CPUARMState, vfp.regs[regno * 2]); | ||
183 | + offs += offsetof(CPUARMState, vfp.zregs[regno]); | ||
184 | assert_fp_access_checked(s); | ||
185 | return offs; | ||
186 | } | ||
187 | @@ -XXX,XX +XXX,XX @@ static inline int vec_reg_offset(DisasContext *s, int regno, | ||
188 | static inline int vec_full_reg_offset(DisasContext *s, int regno) | ||
189 | { | ||
190 | assert_fp_access_checked(s); | ||
191 | - return offsetof(CPUARMState, vfp.regs[regno * 2]); | ||
192 | + return offsetof(CPUARMState, vfp.zregs[regno]); | ||
193 | } | ||
194 | |||
195 | /* Return a newly allocated pointer to the vector register. */ | ||
196 | diff --git a/target/arm/translate.c b/target/arm/translate.c | ||
197 | index XXXXXXX..XXXXXXX 100644 | ||
198 | --- a/target/arm/translate.c | ||
199 | +++ b/target/arm/translate.c | ||
200 | @@ -XXX,XX +XXX,XX @@ static inline void gen_vfp_st(DisasContext *s, int dp, TCGv_i32 addr) | ||
201 | } | ||
202 | } | ||
203 | |||
204 | -static inline long | ||
205 | -vfp_reg_offset (int dp, int reg) | ||
206 | +static inline long vfp_reg_offset(bool dp, unsigned reg) | ||
207 | { | ||
208 | if (dp) { | ||
209 | - return offsetof(CPUARMState, vfp.regs[reg]); | ||
210 | + return offsetof(CPUARMState, vfp.zregs[reg >> 1].d[reg & 1]); | ||
211 | } else { | ||
212 | - long ofs = offsetof(CPUARMState, vfp.regs[reg >> 1]); | ||
213 | + long ofs = offsetof(CPUARMState, vfp.zregs[reg >> 2].d[(reg >> 1) & 1]); | ||
214 | if (reg & 1) { | ||
215 | ofs += offsetof(CPU_DoubleU, l.upper); | ||
216 | } else { | ||
217 | -- | 107 | -- |
218 | 2.16.1 | 108 | 2.20.1 |
219 | 109 | ||
220 | 110 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Richard Henderson <richard.henderson@linaro.org> | ||
1 | 2 | ||
3 | These are all of the defines required to parse | ||
4 | GNU_PROPERTY_AARCH64_FEATURE_1_AND, copied from binutils. | ||
5 | Other missing defines related to other GNU program headers | ||
6 | and notes are elided for now. | ||
7 | |||
8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
9 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
10 | Message-id: 20201021173749.111103-4-richard.henderson@linaro.org | ||
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 |
New patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
1 | 2 | ||
3 | Fix an unlikely memory leak in load_elf_image(). | ||
4 | |||
5 | Fixes: bf858897b7 ("linux-user: Re-use load_elf_image for the main binary.") | ||
6 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Message-id: 20201021173749.111103-5-richard.henderson@linaro.org | ||
9 | Message-Id: <20201003174944.1972444-1-f4bug@amsat.org> | ||
10 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
11 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
13 | --- | ||
14 | linux-user/elfload.c | 8 ++++---- | ||
15 | 1 file changed, 4 insertions(+), 4 deletions(-) | ||
16 | |||
17 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/linux-user/elfload.c | ||
20 | +++ b/linux-user/elfload.c | ||
21 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, | ||
22 | info->brk = vaddr_em; | ||
23 | } | ||
24 | } else if (eppnt->p_type == PT_INTERP && pinterp_name) { | ||
25 | - char *interp_name; | ||
26 | + g_autofree char *interp_name = NULL; | ||
27 | |||
28 | if (*pinterp_name) { | ||
29 | errmsg = "Multiple PT_INTERP entries"; | ||
30 | goto exit_errmsg; | ||
31 | } | ||
32 | - interp_name = malloc(eppnt->p_filesz); | ||
33 | + interp_name = g_malloc(eppnt->p_filesz); | ||
34 | if (!interp_name) { | ||
35 | goto exit_perror; | ||
36 | } | ||
37 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, | ||
38 | errmsg = "Invalid PT_INTERP entry"; | ||
39 | goto exit_errmsg; | ||
40 | } | ||
41 | - *pinterp_name = interp_name; | ||
42 | + *pinterp_name = g_steal_pointer(&interp_name); | ||
43 | #ifdef TARGET_MIPS | ||
44 | } else if (eppnt->p_type == PT_MIPS_ABIFLAGS) { | ||
45 | Mips_elf_abiflags_v0 abiflags; | ||
46 | @@ -XXX,XX +XXX,XX @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info) | ||
47 | if (elf_interpreter) { | ||
48 | info->load_bias = interp_info.load_bias; | ||
49 | info->entry = interp_info.entry; | ||
50 | - free(elf_interpreter); | ||
51 | + g_free(elf_interpreter); | ||
52 | } | ||
53 | |||
54 | #ifdef USE_ELF_CORE_DUMP | ||
55 | -- | ||
56 | 2.20.1 | ||
57 | |||
58 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Richard Henderson <richard.henderson@linaro.org> | ||
1 | 2 | ||
3 | Fixing this now will clarify following patches. | ||
4 | |||
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | Message-id: 20201021173749.111103-6-richard.henderson@linaro.org | ||
7 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
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: Andrey Smirnov <andrew.smirnov@gmail.com> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Move virt's PSCI DT fixup code to arm/boot.c and set this fixup to | 3 | The second loop uses a loop induction variable, and the first |
4 | happen automatically for every board that doesn't mark "psci-conduit" | 4 | does not. Transform the first to match the second, to simplify |
5 | as disabled. This way emulated boards other than "virt" that rely on | 5 | a following patch moving code between them. |
6 | PSIC for SMP could benefit from that code. | ||
7 | 6 | ||
8 | Cc: Peter Maydell <peter.maydell@linaro.org> | 7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
9 | Cc: Jason Wang <jasowang@redhat.com> | 8 | Message-id: 20201021173749.111103-7-richard.henderson@linaro.org |
10 | Cc: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
11 | Cc: Marcel Apfelbaum <marcel.apfelbaum@zoho.com> | ||
12 | Cc: Michael S. Tsirkin <mst@redhat.com> | ||
13 | Cc: qemu-devel@nongnu.org | ||
14 | Cc: qemu-arm@nongnu.org | ||
15 | Cc: yurovsky@gmail.com | ||
16 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
17 | Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> | ||
18 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 9 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
19 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
20 | --- | 11 | --- |
21 | hw/arm/boot.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | 12 | linux-user/elfload.c | 9 +++++---- |
22 | hw/arm/virt.c | 61 ------------------------------------------------------- | 13 | 1 file changed, 5 insertions(+), 4 deletions(-) |
23 | 2 files changed, 65 insertions(+), 61 deletions(-) | ||
24 | 14 | ||
25 | diff --git a/hw/arm/boot.c b/hw/arm/boot.c | 15 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c |
26 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
27 | --- a/hw/arm/boot.c | 17 | --- a/linux-user/elfload.c |
28 | +++ b/hw/arm/boot.c | 18 | +++ b/linux-user/elfload.c |
29 | @@ -XXX,XX +XXX,XX @@ static void set_kernel_args_old(const struct arm_boot_info *info) | 19 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, |
30 | } | 20 | loaddr = -1, hiaddr = 0; |
31 | } | 21 | info->alignment = 0; |
32 | 22 | for (i = 0; i < ehdr->e_phnum; ++i) { | |
33 | +static void fdt_add_psci_node(void *fdt) | 23 | - if (phdr[i].p_type == PT_LOAD) { |
34 | +{ | 24 | - abi_ulong a = phdr[i].p_vaddr - phdr[i].p_offset; |
35 | + uint32_t cpu_suspend_fn; | 25 | + struct elf_phdr *eppnt = phdr + i; |
36 | + uint32_t cpu_off_fn; | 26 | + if (eppnt->p_type == PT_LOAD) { |
37 | + uint32_t cpu_on_fn; | 27 | + abi_ulong a = eppnt->p_vaddr - eppnt->p_offset; |
38 | + uint32_t migrate_fn; | 28 | if (a < loaddr) { |
39 | + ARMCPU *armcpu = ARM_CPU(qemu_get_cpu(0)); | 29 | loaddr = a; |
40 | + const char *psci_method; | 30 | } |
41 | + int64_t psci_conduit; | 31 | - a = phdr[i].p_vaddr + phdr[i].p_memsz; |
42 | + | 32 | + a = eppnt->p_vaddr + eppnt->p_memsz; |
43 | + psci_conduit = object_property_get_int(OBJECT(armcpu), | 33 | if (a > hiaddr) { |
44 | + "psci-conduit", | 34 | hiaddr = a; |
45 | + &error_abort); | 35 | } |
46 | + switch (psci_conduit) { | 36 | ++info->nsegs; |
47 | + case QEMU_PSCI_CONDUIT_DISABLED: | 37 | - info->alignment |= phdr[i].p_align; |
48 | + return; | 38 | + info->alignment |= eppnt->p_align; |
49 | + case QEMU_PSCI_CONDUIT_HVC: | ||
50 | + psci_method = "hvc"; | ||
51 | + break; | ||
52 | + case QEMU_PSCI_CONDUIT_SMC: | ||
53 | + psci_method = "smc"; | ||
54 | + break; | ||
55 | + default: | ||
56 | + g_assert_not_reached(); | ||
57 | + } | ||
58 | + | ||
59 | + qemu_fdt_add_subnode(fdt, "/psci"); | ||
60 | + if (armcpu->psci_version == 2) { | ||
61 | + const char comp[] = "arm,psci-0.2\0arm,psci"; | ||
62 | + qemu_fdt_setprop(fdt, "/psci", "compatible", comp, sizeof(comp)); | ||
63 | + | ||
64 | + cpu_off_fn = QEMU_PSCI_0_2_FN_CPU_OFF; | ||
65 | + if (arm_feature(&armcpu->env, ARM_FEATURE_AARCH64)) { | ||
66 | + cpu_suspend_fn = QEMU_PSCI_0_2_FN64_CPU_SUSPEND; | ||
67 | + cpu_on_fn = QEMU_PSCI_0_2_FN64_CPU_ON; | ||
68 | + migrate_fn = QEMU_PSCI_0_2_FN64_MIGRATE; | ||
69 | + } else { | ||
70 | + cpu_suspend_fn = QEMU_PSCI_0_2_FN_CPU_SUSPEND; | ||
71 | + cpu_on_fn = QEMU_PSCI_0_2_FN_CPU_ON; | ||
72 | + migrate_fn = QEMU_PSCI_0_2_FN_MIGRATE; | ||
73 | + } | ||
74 | + } else { | ||
75 | + qemu_fdt_setprop_string(fdt, "/psci", "compatible", "arm,psci"); | ||
76 | + | ||
77 | + cpu_suspend_fn = QEMU_PSCI_0_1_FN_CPU_SUSPEND; | ||
78 | + cpu_off_fn = QEMU_PSCI_0_1_FN_CPU_OFF; | ||
79 | + cpu_on_fn = QEMU_PSCI_0_1_FN_CPU_ON; | ||
80 | + migrate_fn = QEMU_PSCI_0_1_FN_MIGRATE; | ||
81 | + } | ||
82 | + | ||
83 | + /* We adopt the PSCI spec's nomenclature, and use 'conduit' to refer | ||
84 | + * to the instruction that should be used to invoke PSCI functions. | ||
85 | + * However, the device tree binding uses 'method' instead, so that is | ||
86 | + * what we should use here. | ||
87 | + */ | ||
88 | + qemu_fdt_setprop_string(fdt, "/psci", "method", psci_method); | ||
89 | + | ||
90 | + qemu_fdt_setprop_cell(fdt, "/psci", "cpu_suspend", cpu_suspend_fn); | ||
91 | + qemu_fdt_setprop_cell(fdt, "/psci", "cpu_off", cpu_off_fn); | ||
92 | + qemu_fdt_setprop_cell(fdt, "/psci", "cpu_on", cpu_on_fn); | ||
93 | + qemu_fdt_setprop_cell(fdt, "/psci", "migrate", migrate_fn); | ||
94 | +} | ||
95 | + | ||
96 | /** | ||
97 | * load_dtb() - load a device tree binary image into memory | ||
98 | * @addr: the address to load the image at | ||
99 | @@ -XXX,XX +XXX,XX @@ static int load_dtb(hwaddr addr, const struct arm_boot_info *binfo, | ||
100 | } | 39 | } |
101 | } | 40 | } |
102 | 41 | ||
103 | + fdt_add_psci_node(fdt); | ||
104 | + | ||
105 | if (binfo->modify_dtb) { | ||
106 | binfo->modify_dtb(binfo, fdt); | ||
107 | } | ||
108 | diff --git a/hw/arm/virt.c b/hw/arm/virt.c | ||
109 | index XXXXXXX..XXXXXXX 100644 | ||
110 | --- a/hw/arm/virt.c | ||
111 | +++ b/hw/arm/virt.c | ||
112 | @@ -XXX,XX +XXX,XX @@ static void create_fdt(VirtMachineState *vms) | ||
113 | } | ||
114 | } | ||
115 | |||
116 | -static void fdt_add_psci_node(const VirtMachineState *vms) | ||
117 | -{ | ||
118 | - uint32_t cpu_suspend_fn; | ||
119 | - uint32_t cpu_off_fn; | ||
120 | - uint32_t cpu_on_fn; | ||
121 | - uint32_t migrate_fn; | ||
122 | - void *fdt = vms->fdt; | ||
123 | - ARMCPU *armcpu = ARM_CPU(qemu_get_cpu(0)); | ||
124 | - const char *psci_method; | ||
125 | - | ||
126 | - switch (vms->psci_conduit) { | ||
127 | - case QEMU_PSCI_CONDUIT_DISABLED: | ||
128 | - return; | ||
129 | - case QEMU_PSCI_CONDUIT_HVC: | ||
130 | - psci_method = "hvc"; | ||
131 | - break; | ||
132 | - case QEMU_PSCI_CONDUIT_SMC: | ||
133 | - psci_method = "smc"; | ||
134 | - break; | ||
135 | - default: | ||
136 | - g_assert_not_reached(); | ||
137 | - } | ||
138 | - | ||
139 | - qemu_fdt_add_subnode(fdt, "/psci"); | ||
140 | - if (armcpu->psci_version == 2) { | ||
141 | - const char comp[] = "arm,psci-0.2\0arm,psci"; | ||
142 | - qemu_fdt_setprop(fdt, "/psci", "compatible", comp, sizeof(comp)); | ||
143 | - | ||
144 | - cpu_off_fn = QEMU_PSCI_0_2_FN_CPU_OFF; | ||
145 | - if (arm_feature(&armcpu->env, ARM_FEATURE_AARCH64)) { | ||
146 | - cpu_suspend_fn = QEMU_PSCI_0_2_FN64_CPU_SUSPEND; | ||
147 | - cpu_on_fn = QEMU_PSCI_0_2_FN64_CPU_ON; | ||
148 | - migrate_fn = QEMU_PSCI_0_2_FN64_MIGRATE; | ||
149 | - } else { | ||
150 | - cpu_suspend_fn = QEMU_PSCI_0_2_FN_CPU_SUSPEND; | ||
151 | - cpu_on_fn = QEMU_PSCI_0_2_FN_CPU_ON; | ||
152 | - migrate_fn = QEMU_PSCI_0_2_FN_MIGRATE; | ||
153 | - } | ||
154 | - } else { | ||
155 | - qemu_fdt_setprop_string(fdt, "/psci", "compatible", "arm,psci"); | ||
156 | - | ||
157 | - cpu_suspend_fn = QEMU_PSCI_0_1_FN_CPU_SUSPEND; | ||
158 | - cpu_off_fn = QEMU_PSCI_0_1_FN_CPU_OFF; | ||
159 | - cpu_on_fn = QEMU_PSCI_0_1_FN_CPU_ON; | ||
160 | - migrate_fn = QEMU_PSCI_0_1_FN_MIGRATE; | ||
161 | - } | ||
162 | - | ||
163 | - /* We adopt the PSCI spec's nomenclature, and use 'conduit' to refer | ||
164 | - * to the instruction that should be used to invoke PSCI functions. | ||
165 | - * However, the device tree binding uses 'method' instead, so that is | ||
166 | - * what we should use here. | ||
167 | - */ | ||
168 | - qemu_fdt_setprop_string(fdt, "/psci", "method", psci_method); | ||
169 | - | ||
170 | - qemu_fdt_setprop_cell(fdt, "/psci", "cpu_suspend", cpu_suspend_fn); | ||
171 | - qemu_fdt_setprop_cell(fdt, "/psci", "cpu_off", cpu_off_fn); | ||
172 | - qemu_fdt_setprop_cell(fdt, "/psci", "cpu_on", cpu_on_fn); | ||
173 | - qemu_fdt_setprop_cell(fdt, "/psci", "migrate", migrate_fn); | ||
174 | -} | ||
175 | - | ||
176 | static void fdt_add_timer_nodes(const VirtMachineState *vms) | ||
177 | { | ||
178 | /* On real hardware these interrupts are level-triggered. | ||
179 | @@ -XXX,XX +XXX,XX @@ static void machvirt_init(MachineState *machine) | ||
180 | } | ||
181 | fdt_add_timer_nodes(vms); | ||
182 | fdt_add_cpu_nodes(vms); | ||
183 | - fdt_add_psci_node(vms); | ||
184 | |||
185 | memory_region_allocate_system_memory(ram, NULL, "mach-virt.ram", | ||
186 | machine->ram_size); | ||
187 | -- | 42 | -- |
188 | 2.16.1 | 43 | 2.20.1 |
189 | 44 | ||
190 | 45 | diff view generated by jsdifflib |
1 | From: Ard Biesheuvel <ard.biesheuvel@linaro.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Add support for the new ARMv8.2 SHA-3, SM3, SM4 and SHA-512 instructions to | 3 | For BTI, we need to know if the executable is static or dynamic, |
4 | AArch64 user mode emulation. | 4 | which means looking for PT_INTERP earlier. |
5 | 5 | ||
6 | Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
7 | Message-id: 20180207111729.15737-6-ard.biesheuvel@linaro.org | 7 | Message-id: 20201021173749.111103-8-richard.henderson@linaro.org |
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 | 19 +++++++++++++++++++ | 11 | linux-user/elfload.c | 60 +++++++++++++++++++++++--------------------- |
12 | target/arm/cpu64.c | 4 ++++ | 12 | 1 file changed, 31 insertions(+), 29 deletions(-) |
13 | 2 files changed, 23 insertions(+) | ||
14 | 13 | ||
15 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c | 14 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c |
16 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/linux-user/elfload.c | 16 | --- a/linux-user/elfload.c |
18 | +++ b/linux-user/elfload.c | 17 | +++ b/linux-user/elfload.c |
19 | @@ -XXX,XX +XXX,XX @@ enum { | 18 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, |
20 | ARM_HWCAP_A64_SHA1 = 1 << 5, | 19 | |
21 | ARM_HWCAP_A64_SHA2 = 1 << 6, | 20 | mmap_lock(); |
22 | ARM_HWCAP_A64_CRC32 = 1 << 7, | 21 | |
23 | + ARM_HWCAP_A64_ATOMICS = 1 << 8, | 22 | - /* Find the maximum size of the image and allocate an appropriate |
24 | + ARM_HWCAP_A64_FPHP = 1 << 9, | 23 | - amount of memory to handle that. */ |
25 | + ARM_HWCAP_A64_ASIMDHP = 1 << 10, | 24 | + /* |
26 | + ARM_HWCAP_A64_CPUID = 1 << 11, | 25 | + * Find the maximum size of the image and allocate an appropriate |
27 | + ARM_HWCAP_A64_ASIMDRDM = 1 << 12, | 26 | + * amount of memory to handle that. Locate the interpreter, if any. |
28 | + ARM_HWCAP_A64_JSCVT = 1 << 13, | 27 | + */ |
29 | + ARM_HWCAP_A64_FCMA = 1 << 14, | 28 | loaddr = -1, hiaddr = 0; |
30 | + ARM_HWCAP_A64_LRCPC = 1 << 15, | 29 | info->alignment = 0; |
31 | + ARM_HWCAP_A64_DCPOP = 1 << 16, | 30 | for (i = 0; i < ehdr->e_phnum; ++i) { |
32 | + ARM_HWCAP_A64_SHA3 = 1 << 17, | 31 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, |
33 | + ARM_HWCAP_A64_SM3 = 1 << 18, | 32 | } |
34 | + ARM_HWCAP_A64_SM4 = 1 << 19, | 33 | ++info->nsegs; |
35 | + ARM_HWCAP_A64_ASIMDDP = 1 << 20, | 34 | info->alignment |= eppnt->p_align; |
36 | + ARM_HWCAP_A64_SHA512 = 1 << 21, | 35 | + } else if (eppnt->p_type == PT_INTERP && pinterp_name) { |
37 | + ARM_HWCAP_A64_SVE = 1 << 22, | 36 | + g_autofree char *interp_name = NULL; |
38 | }; | 37 | + |
39 | 38 | + if (*pinterp_name) { | |
40 | #define ELF_HWCAP get_elf_hwcap() | 39 | + errmsg = "Multiple PT_INTERP entries"; |
41 | @@ -XXX,XX +XXX,XX @@ static uint32_t get_elf_hwcap(void) | 40 | + goto exit_errmsg; |
42 | GET_FEATURE(ARM_FEATURE_V8_SHA1, ARM_HWCAP_A64_SHA1); | 41 | + } |
43 | GET_FEATURE(ARM_FEATURE_V8_SHA256, ARM_HWCAP_A64_SHA2); | 42 | + interp_name = g_malloc(eppnt->p_filesz); |
44 | GET_FEATURE(ARM_FEATURE_CRC, ARM_HWCAP_A64_CRC32); | 43 | + if (!interp_name) { |
45 | + GET_FEATURE(ARM_FEATURE_V8_SHA3, ARM_HWCAP_A64_SHA3); | 44 | + goto exit_perror; |
46 | + GET_FEATURE(ARM_FEATURE_V8_SM3, ARM_HWCAP_A64_SM3); | 45 | + } |
47 | + GET_FEATURE(ARM_FEATURE_V8_SM4, ARM_HWCAP_A64_SM4); | 46 | + |
48 | + GET_FEATURE(ARM_FEATURE_V8_SHA512, ARM_HWCAP_A64_SHA512); | 47 | + if (eppnt->p_offset + eppnt->p_filesz <= BPRM_BUF_SIZE) { |
49 | #undef GET_FEATURE | 48 | + memcpy(interp_name, bprm_buf + eppnt->p_offset, |
50 | 49 | + eppnt->p_filesz); | |
51 | return hwcaps; | 50 | + } else { |
52 | diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c | 51 | + retval = pread(image_fd, interp_name, eppnt->p_filesz, |
53 | index XXXXXXX..XXXXXXX 100644 | 52 | + eppnt->p_offset); |
54 | --- a/target/arm/cpu64.c | 53 | + if (retval != eppnt->p_filesz) { |
55 | +++ b/target/arm/cpu64.c | 54 | + goto exit_perror; |
56 | @@ -XXX,XX +XXX,XX @@ static void aarch64_any_initfn(Object *obj) | 55 | + } |
57 | set_feature(&cpu->env, ARM_FEATURE_V8_AES); | 56 | + } |
58 | set_feature(&cpu->env, ARM_FEATURE_V8_SHA1); | 57 | + if (interp_name[eppnt->p_filesz - 1] != 0) { |
59 | set_feature(&cpu->env, ARM_FEATURE_V8_SHA256); | 58 | + errmsg = "Invalid PT_INTERP entry"; |
60 | + set_feature(&cpu->env, ARM_FEATURE_V8_SHA512); | 59 | + goto exit_errmsg; |
61 | + set_feature(&cpu->env, ARM_FEATURE_V8_SHA3); | 60 | + } |
62 | + set_feature(&cpu->env, ARM_FEATURE_V8_SM3); | 61 | + *pinterp_name = g_steal_pointer(&interp_name); |
63 | + set_feature(&cpu->env, ARM_FEATURE_V8_SM4); | 62 | } |
64 | set_feature(&cpu->env, ARM_FEATURE_V8_PMULL); | 63 | } |
65 | set_feature(&cpu->env, ARM_FEATURE_CRC); | 64 | |
66 | cpu->ctr = 0x80038003; /* 32 byte I and D cacheline size, VIPT icache */ | 65 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, |
66 | if (vaddr_em > info->brk) { | ||
67 | info->brk = vaddr_em; | ||
68 | } | ||
69 | - } else if (eppnt->p_type == PT_INTERP && pinterp_name) { | ||
70 | - g_autofree char *interp_name = NULL; | ||
71 | - | ||
72 | - if (*pinterp_name) { | ||
73 | - errmsg = "Multiple PT_INTERP entries"; | ||
74 | - goto exit_errmsg; | ||
75 | - } | ||
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; | ||
67 | -- | 99 | -- |
68 | 2.16.1 | 100 | 2.20.1 |
69 | 101 | ||
70 | 102 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Add both SVE exception state and vector length. | 3 | This is a bit clearer than open-coding some of this |
4 | with a bare c string. | ||
4 | 5 | ||
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 7 | Message-id: 20201021173749.111103-9-richard.henderson@linaro.org |
7 | Message-id: 20180123035349.24538-6-richard.henderson@linaro.org | 8 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
9 | --- | 10 | --- |
10 | target/arm/cpu.h | 8 ++++++++ | 11 | linux-user/elfload.c | 37 ++++++++++++++++++++----------------- |
11 | target/arm/translate.h | 2 ++ | 12 | 1 file changed, 20 insertions(+), 17 deletions(-) |
12 | target/arm/helper.c | 25 ++++++++++++++++++++++++- | ||
13 | target/arm/translate-a64.c | 2 ++ | ||
14 | 4 files changed, 36 insertions(+), 1 deletion(-) | ||
15 | 13 | ||
16 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | 14 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c |
17 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/target/arm/cpu.h | 16 | --- a/linux-user/elfload.c |
19 | +++ b/target/arm/cpu.h | 17 | +++ b/linux-user/elfload.c |
20 | @@ -XXX,XX +XXX,XX @@ static inline bool arm_cpu_data_is_big_endian(CPUARMState *env) | 18 | @@ -XXX,XX +XXX,XX @@ |
21 | #define ARM_TBFLAG_TBI0_MASK (0x1ull << ARM_TBFLAG_TBI0_SHIFT) | 19 | #include "qemu/guest-random.h" |
22 | #define ARM_TBFLAG_TBI1_SHIFT 1 /* TBI1 for EL0/1 */ | 20 | #include "qemu/units.h" |
23 | #define ARM_TBFLAG_TBI1_MASK (0x1ull << ARM_TBFLAG_TBI1_SHIFT) | 21 | #include "qemu/selfmap.h" |
24 | +#define ARM_TBFLAG_SVEEXC_EL_SHIFT 2 | 22 | +#include "qapi/error.h" |
25 | +#define ARM_TBFLAG_SVEEXC_EL_MASK (0x3 << ARM_TBFLAG_SVEEXC_EL_SHIFT) | 23 | |
26 | +#define ARM_TBFLAG_ZCR_LEN_SHIFT 4 | 24 | #ifdef _ARCH_PPC64 |
27 | +#define ARM_TBFLAG_ZCR_LEN_MASK (0xf << ARM_TBFLAG_ZCR_LEN_SHIFT) | 25 | #undef ARCH_DLINFO |
28 | 26 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, | |
29 | /* some convenience accessor macros */ | 27 | struct elf_phdr *phdr; |
30 | #define ARM_TBFLAG_AARCH64_STATE(F) \ | 28 | abi_ulong load_addr, load_bias, loaddr, hiaddr, error; |
31 | @@ -XXX,XX +XXX,XX @@ static inline bool arm_cpu_data_is_big_endian(CPUARMState *env) | 29 | int i, retval; |
32 | (((F) & ARM_TBFLAG_TBI0_MASK) >> ARM_TBFLAG_TBI0_SHIFT) | 30 | - const char *errmsg; |
33 | #define ARM_TBFLAG_TBI1(F) \ | 31 | + Error *err = NULL; |
34 | (((F) & ARM_TBFLAG_TBI1_MASK) >> ARM_TBFLAG_TBI1_SHIFT) | 32 | |
35 | +#define ARM_TBFLAG_SVEEXC_EL(F) \ | 33 | /* First of all, some simple consistency checks */ |
36 | + (((F) & ARM_TBFLAG_SVEEXC_EL_MASK) >> ARM_TBFLAG_SVEEXC_EL_SHIFT) | 34 | - errmsg = "Invalid ELF image for this architecture"; |
37 | +#define ARM_TBFLAG_ZCR_LEN(F) \ | 35 | if (!elf_check_ident(ehdr)) { |
38 | + (((F) & ARM_TBFLAG_ZCR_LEN_MASK) >> ARM_TBFLAG_ZCR_LEN_SHIFT) | 36 | + error_setg(&err, "Invalid ELF image for this architecture"); |
39 | 37 | goto exit_errmsg; | |
40 | static inline bool bswap_code(bool sctlr_b) | 38 | } |
41 | { | 39 | bswap_ehdr(ehdr); |
42 | diff --git a/target/arm/translate.h b/target/arm/translate.h | 40 | if (!elf_check_ehdr(ehdr)) { |
43 | index XXXXXXX..XXXXXXX 100644 | 41 | + error_setg(&err, "Invalid ELF image for this architecture"); |
44 | --- a/target/arm/translate.h | 42 | goto exit_errmsg; |
45 | +++ b/target/arm/translate.h | 43 | } |
46 | @@ -XXX,XX +XXX,XX @@ typedef struct DisasContext { | 44 | |
47 | bool tbi1; /* TBI1 for EL0/1, not used for EL2/3 */ | 45 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, |
48 | bool ns; /* Use non-secure CPREG bank on access */ | 46 | g_autofree char *interp_name = NULL; |
49 | int fp_excp_el; /* FP exception EL or 0 if enabled */ | 47 | |
50 | + int sve_excp_el; /* SVE exception EL or 0 if enabled */ | 48 | if (*pinterp_name) { |
51 | + int sve_len; /* SVE vector length in bytes */ | 49 | - errmsg = "Multiple PT_INTERP entries"; |
52 | /* Flag indicating that exceptions from secure mode are routed to EL3. */ | 50 | + error_setg(&err, "Multiple PT_INTERP entries"); |
53 | bool secure_routed_to_el3; | 51 | goto exit_errmsg; |
54 | bool vfp_enabled; /* FP enabled via FPSCR.EN */ | 52 | } |
55 | diff --git a/target/arm/helper.c b/target/arm/helper.c | ||
56 | index XXXXXXX..XXXXXXX 100644 | ||
57 | --- a/target/arm/helper.c | ||
58 | +++ b/target/arm/helper.c | ||
59 | @@ -XXX,XX +XXX,XX @@ void cpu_get_tb_cpu_state(CPUARMState *env, target_ulong *pc, | ||
60 | target_ulong *cs_base, uint32_t *pflags) | ||
61 | { | ||
62 | ARMMMUIdx mmu_idx = core_to_arm_mmu_idx(env, cpu_mmu_index(env, false)); | ||
63 | + int fp_el = fp_exception_el(env); | ||
64 | uint32_t flags; | ||
65 | |||
66 | if (is_a64(env)) { | ||
67 | + int sve_el = sve_exception_el(env); | ||
68 | + uint32_t zcr_len; | ||
69 | + | 53 | + |
70 | *pc = env->pc; | 54 | interp_name = g_malloc(eppnt->p_filesz); |
71 | flags = ARM_TBFLAG_AARCH64_STATE_MASK; | 55 | - if (!interp_name) { |
72 | /* Get control bits for tagged addresses */ | 56 | - goto exit_perror; |
73 | flags |= (arm_regime_tbi0(env, mmu_idx) << ARM_TBFLAG_TBI0_SHIFT); | 57 | - } |
74 | flags |= (arm_regime_tbi1(env, mmu_idx) << ARM_TBFLAG_TBI1_SHIFT); | 58 | |
75 | + flags |= sve_el << ARM_TBFLAG_SVEEXC_EL_SHIFT; | 59 | if (eppnt->p_offset + eppnt->p_filesz <= BPRM_BUF_SIZE) { |
76 | + | 60 | memcpy(interp_name, bprm_buf + eppnt->p_offset, |
77 | + /* If SVE is disabled, but FP is enabled, | 61 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, |
78 | + then the effective len is 0. */ | 62 | retval = pread(image_fd, interp_name, eppnt->p_filesz, |
79 | + if (sve_el != 0 && fp_el == 0) { | 63 | eppnt->p_offset); |
80 | + zcr_len = 0; | 64 | if (retval != eppnt->p_filesz) { |
81 | + } else { | 65 | - goto exit_perror; |
82 | + int current_el = arm_current_el(env); | 66 | + goto exit_read; |
83 | + | 67 | } |
84 | + zcr_len = env->vfp.zcr_el[current_el <= 1 ? 1 : current_el]; | 68 | } |
85 | + zcr_len &= 0xf; | 69 | if (interp_name[eppnt->p_filesz - 1] != 0) { |
86 | + if (current_el < 2 && arm_feature(env, ARM_FEATURE_EL2)) { | 70 | - errmsg = "Invalid PT_INTERP entry"; |
87 | + zcr_len = MIN(zcr_len, 0xf & (uint32_t)env->vfp.zcr_el[2]); | 71 | + error_setg(&err, "Invalid PT_INTERP entry"); |
88 | + } | 72 | goto exit_errmsg; |
89 | + if (current_el < 3 && arm_feature(env, ARM_FEATURE_EL3)) { | 73 | } |
90 | + zcr_len = MIN(zcr_len, 0xf & (uint32_t)env->vfp.zcr_el[3]); | 74 | *pinterp_name = g_steal_pointer(&interp_name); |
91 | + } | 75 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, |
92 | + } | 76 | (ehdr->e_type == ET_EXEC ? MAP_FIXED : 0), |
93 | + flags |= zcr_len << ARM_TBFLAG_ZCR_LEN_SHIFT; | 77 | -1, 0); |
94 | } else { | 78 | if (load_addr == -1) { |
95 | *pc = env->regs[15]; | 79 | - goto exit_perror; |
96 | flags = (env->thumb << ARM_TBFLAG_THUMB_SHIFT) | 80 | + goto exit_mmap; |
97 | @@ -XXX,XX +XXX,XX @@ void cpu_get_tb_cpu_state(CPUARMState *env, target_ulong *pc, | ||
98 | if (arm_cpu_data_is_big_endian(env)) { | ||
99 | flags |= ARM_TBFLAG_BE_DATA_MASK; | ||
100 | } | 81 | } |
101 | - flags |= fp_exception_el(env) << ARM_TBFLAG_FPEXC_EL_SHIFT; | 82 | load_bias = load_addr - loaddr; |
102 | + flags |= fp_el << ARM_TBFLAG_FPEXC_EL_SHIFT; | 83 | |
103 | 84 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, | |
104 | if (arm_v7m_is_handler_mode(env)) { | 85 | image_fd, eppnt->p_offset - vaddr_po); |
105 | flags |= ARM_TBFLAG_HANDLER_MASK; | 86 | |
106 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | 87 | if (error == -1) { |
107 | index XXXXXXX..XXXXXXX 100644 | 88 | - goto exit_perror; |
108 | --- a/target/arm/translate-a64.c | 89 | + goto exit_mmap; |
109 | +++ b/target/arm/translate-a64.c | 90 | } |
110 | @@ -XXX,XX +XXX,XX @@ static int aarch64_tr_init_disas_context(DisasContextBase *dcbase, | 91 | } |
111 | dc->user = (dc->current_el == 0); | 92 | |
112 | #endif | 93 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, |
113 | dc->fp_excp_el = ARM_TBFLAG_FPEXC_EL(dc->base.tb->flags); | 94 | } else if (eppnt->p_type == PT_MIPS_ABIFLAGS) { |
114 | + dc->sve_excp_el = ARM_TBFLAG_SVEEXC_EL(dc->base.tb->flags); | 95 | Mips_elf_abiflags_v0 abiflags; |
115 | + dc->sve_len = (ARM_TBFLAG_ZCR_LEN(dc->base.tb->flags) + 1) * 16; | 96 | if (eppnt->p_filesz < sizeof(Mips_elf_abiflags_v0)) { |
116 | dc->vec_len = 0; | 97 | - errmsg = "Invalid PT_MIPS_ABIFLAGS entry"; |
117 | dc->vec_stride = 0; | 98 | + error_setg(&err, "Invalid PT_MIPS_ABIFLAGS entry"); |
118 | dc->cp_regs = arm_cpu->cp_regs; | 99 | goto exit_errmsg; |
100 | } | ||
101 | if (eppnt->p_offset + eppnt->p_filesz <= BPRM_BUF_SIZE) { | ||
102 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, | ||
103 | retval = pread(image_fd, &abiflags, sizeof(Mips_elf_abiflags_v0), | ||
104 | eppnt->p_offset); | ||
105 | if (retval != sizeof(Mips_elf_abiflags_v0)) { | ||
106 | - goto exit_perror; | ||
107 | + goto exit_read; | ||
108 | } | ||
109 | } | ||
110 | bswap_mips_abiflags(&abiflags); | ||
111 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, | ||
112 | |||
113 | exit_read: | ||
114 | if (retval >= 0) { | ||
115 | - errmsg = "Incomplete read of file header"; | ||
116 | - goto exit_errmsg; | ||
117 | + error_setg(&err, "Incomplete read of file header"); | ||
118 | + } else { | ||
119 | + error_setg_errno(&err, errno, "Error reading file header"); | ||
120 | } | ||
121 | - exit_perror: | ||
122 | - errmsg = strerror(errno); | ||
123 | + goto exit_errmsg; | ||
124 | + exit_mmap: | ||
125 | + error_setg_errno(&err, errno, "Error mapping file"); | ||
126 | + goto exit_errmsg; | ||
127 | exit_errmsg: | ||
128 | - fprintf(stderr, "%s: %s\n", image_name, errmsg); | ||
129 | + error_reportf_err(err, "%s: ", image_name); | ||
130 | exit(-1); | ||
131 | } | ||
132 | |||
119 | -- | 133 | -- |
120 | 2.16.1 | 134 | 2.20.1 |
121 | 135 | ||
122 | 136 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Define ZCR_EL[1-3]. | 3 | This is slightly clearer than just using strerror, though |
4 | the different forms produced by error_setg_file_open and | ||
5 | error_setg_errno isn't entirely convenient. | ||
4 | 6 | ||
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Message-id: 20201021173749.111103-10-richard.henderson@linaro.org |
7 | Message-id: 20180123035349.24538-5-richard.henderson@linaro.org | 9 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
9 | --- | 11 | --- |
10 | target/arm/cpu.h | 5 ++ | 12 | linux-user/elfload.c | 15 ++++++++------- |
11 | target/arm/helper.c | 131 ++++++++++++++++++++++++++++++++++++++++++++++++++++ | 13 | 1 file changed, 8 insertions(+), 7 deletions(-) |
12 | 2 files changed, 136 insertions(+) | ||
13 | 14 | ||
14 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | 15 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c |
15 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/target/arm/cpu.h | 17 | --- a/linux-user/elfload.c |
17 | +++ b/target/arm/cpu.h | 18 | +++ b/linux-user/elfload.c |
18 | @@ -XXX,XX +XXX,XX @@ typedef struct CPUARMState { | 19 | @@ -XXX,XX +XXX,XX @@ static void load_elf_interp(const char *filename, struct image_info *info, |
19 | */ | 20 | char bprm_buf[BPRM_BUF_SIZE]) |
20 | float_status fp_status; | ||
21 | float_status standard_fp_status; | ||
22 | + | ||
23 | + /* ZCR_EL[1-3] */ | ||
24 | + uint64_t zcr_el[4]; | ||
25 | } vfp; | ||
26 | uint64_t exclusive_addr; | ||
27 | uint64_t exclusive_val; | ||
28 | @@ -XXX,XX +XXX,XX @@ void pmccntr_sync(CPUARMState *env); | ||
29 | #define CPTR_TCPAC (1U << 31) | ||
30 | #define CPTR_TTA (1U << 20) | ||
31 | #define CPTR_TFP (1U << 10) | ||
32 | +#define CPTR_TZ (1U << 8) /* CPTR_EL2 */ | ||
33 | +#define CPTR_EZ (1U << 8) /* CPTR_EL3 */ | ||
34 | |||
35 | #define MDCR_EPMAD (1U << 21) | ||
36 | #define MDCR_EDAD (1U << 20) | ||
37 | diff --git a/target/arm/helper.c b/target/arm/helper.c | ||
38 | index XXXXXXX..XXXXXXX 100644 | ||
39 | --- a/target/arm/helper.c | ||
40 | +++ b/target/arm/helper.c | ||
41 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo debug_lpae_cp_reginfo[] = { | ||
42 | REGINFO_SENTINEL | ||
43 | }; | ||
44 | |||
45 | +/* Return the exception level to which SVE-disabled exceptions should | ||
46 | + * be taken, or 0 if SVE is enabled. | ||
47 | + */ | ||
48 | +static int sve_exception_el(CPUARMState *env) | ||
49 | +{ | ||
50 | +#ifndef CONFIG_USER_ONLY | ||
51 | + unsigned current_el = arm_current_el(env); | ||
52 | + | ||
53 | + /* The CPACR.ZEN controls traps to EL1: | ||
54 | + * 0, 2 : trap EL0 and EL1 accesses | ||
55 | + * 1 : trap only EL0 accesses | ||
56 | + * 3 : trap no accesses | ||
57 | + */ | ||
58 | + switch (extract32(env->cp15.cpacr_el1, 16, 2)) { | ||
59 | + default: | ||
60 | + if (current_el <= 1) { | ||
61 | + /* Trap to PL1, which might be EL1 or EL3 */ | ||
62 | + if (arm_is_secure(env) && !arm_el_is_aa64(env, 3)) { | ||
63 | + return 3; | ||
64 | + } | ||
65 | + return 1; | ||
66 | + } | ||
67 | + break; | ||
68 | + case 1: | ||
69 | + if (current_el == 0) { | ||
70 | + return 1; | ||
71 | + } | ||
72 | + break; | ||
73 | + case 3: | ||
74 | + break; | ||
75 | + } | ||
76 | + | ||
77 | + /* Similarly for CPACR.FPEN, after having checked ZEN. */ | ||
78 | + switch (extract32(env->cp15.cpacr_el1, 20, 2)) { | ||
79 | + default: | ||
80 | + if (current_el <= 1) { | ||
81 | + if (arm_is_secure(env) && !arm_el_is_aa64(env, 3)) { | ||
82 | + return 3; | ||
83 | + } | ||
84 | + return 1; | ||
85 | + } | ||
86 | + break; | ||
87 | + case 1: | ||
88 | + if (current_el == 0) { | ||
89 | + return 1; | ||
90 | + } | ||
91 | + break; | ||
92 | + case 3: | ||
93 | + break; | ||
94 | + } | ||
95 | + | ||
96 | + /* CPTR_EL2. Check both TZ and TFP. */ | ||
97 | + if (current_el <= 2 | ||
98 | + && (env->cp15.cptr_el[2] & (CPTR_TFP | CPTR_TZ)) | ||
99 | + && !arm_is_secure_below_el3(env)) { | ||
100 | + return 2; | ||
101 | + } | ||
102 | + | ||
103 | + /* CPTR_EL3. Check both EZ and TFP. */ | ||
104 | + if (!(env->cp15.cptr_el[3] & CPTR_EZ) | ||
105 | + || (env->cp15.cptr_el[3] & CPTR_TFP)) { | ||
106 | + return 3; | ||
107 | + } | ||
108 | +#endif | ||
109 | + return 0; | ||
110 | +} | ||
111 | + | ||
112 | +static CPAccessResult zcr_access(CPUARMState *env, const ARMCPRegInfo *ri, | ||
113 | + bool isread) | ||
114 | +{ | ||
115 | + switch (sve_exception_el(env)) { | ||
116 | + case 3: | ||
117 | + return CP_ACCESS_TRAP_EL3; | ||
118 | + case 2: | ||
119 | + return CP_ACCESS_TRAP_EL2; | ||
120 | + case 1: | ||
121 | + return CP_ACCESS_TRAP; | ||
122 | + } | ||
123 | + return CP_ACCESS_OK; | ||
124 | +} | ||
125 | + | ||
126 | +static void zcr_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
127 | + uint64_t value) | ||
128 | +{ | ||
129 | + /* Bits other than [3:0] are RAZ/WI. */ | ||
130 | + raw_write(env, ri, value & 0xf); | ||
131 | +} | ||
132 | + | ||
133 | +static const ARMCPRegInfo zcr_el1_reginfo = { | ||
134 | + .name = "ZCR_EL1", .state = ARM_CP_STATE_AA64, | ||
135 | + .opc0 = 3, .opc1 = 0, .crn = 1, .crm = 2, .opc2 = 0, | ||
136 | + .access = PL1_RW, .accessfn = zcr_access, .type = ARM_CP_64BIT, | ||
137 | + .fieldoffset = offsetof(CPUARMState, vfp.zcr_el[1]), | ||
138 | + .writefn = zcr_write, .raw_writefn = raw_write | ||
139 | +}; | ||
140 | + | ||
141 | +static const ARMCPRegInfo zcr_el2_reginfo = { | ||
142 | + .name = "ZCR_EL2", .state = ARM_CP_STATE_AA64, | ||
143 | + .opc0 = 3, .opc1 = 4, .crn = 1, .crm = 2, .opc2 = 0, | ||
144 | + .access = PL2_RW, .accessfn = zcr_access, .type = ARM_CP_64BIT, | ||
145 | + .fieldoffset = offsetof(CPUARMState, vfp.zcr_el[2]), | ||
146 | + .writefn = zcr_write, .raw_writefn = raw_write | ||
147 | +}; | ||
148 | + | ||
149 | +static const ARMCPRegInfo zcr_no_el2_reginfo = { | ||
150 | + .name = "ZCR_EL2", .state = ARM_CP_STATE_AA64, | ||
151 | + .opc0 = 3, .opc1 = 4, .crn = 1, .crm = 2, .opc2 = 0, | ||
152 | + .access = PL2_RW, .type = ARM_CP_64BIT, | ||
153 | + .readfn = arm_cp_read_zero, .writefn = arm_cp_write_ignore | ||
154 | +}; | ||
155 | + | ||
156 | +static const ARMCPRegInfo zcr_el3_reginfo = { | ||
157 | + .name = "ZCR_EL3", .state = ARM_CP_STATE_AA64, | ||
158 | + .opc0 = 3, .opc1 = 6, .crn = 1, .crm = 2, .opc2 = 0, | ||
159 | + .access = PL3_RW, .accessfn = zcr_access, .type = ARM_CP_64BIT, | ||
160 | + .fieldoffset = offsetof(CPUARMState, vfp.zcr_el[3]), | ||
161 | + .writefn = zcr_write, .raw_writefn = raw_write | ||
162 | +}; | ||
163 | + | ||
164 | void hw_watchpoint_update(ARMCPU *cpu, int n) | ||
165 | { | 21 | { |
166 | CPUARMState *env = &cpu->env; | 22 | int fd, retval; |
167 | @@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu) | 23 | + Error *err = NULL; |
168 | } | 24 | |
169 | define_one_arm_cp_reg(cpu, &sctlr); | 25 | fd = open(path(filename), O_RDONLY); |
26 | if (fd < 0) { | ||
27 | - goto exit_perror; | ||
28 | + error_setg_file_open(&err, errno, filename); | ||
29 | + error_report_err(err); | ||
30 | + exit(-1); | ||
31 | } | ||
32 | |||
33 | retval = read(fd, bprm_buf, BPRM_BUF_SIZE); | ||
34 | if (retval < 0) { | ||
35 | - goto exit_perror; | ||
36 | + error_setg_errno(&err, errno, "Error reading file header"); | ||
37 | + error_reportf_err(err, "%s: ", filename); | ||
38 | + exit(-1); | ||
170 | } | 39 | } |
171 | + | 40 | + |
172 | + if (arm_feature(env, ARM_FEATURE_SVE)) { | 41 | if (retval < BPRM_BUF_SIZE) { |
173 | + define_one_arm_cp_reg(cpu, &zcr_el1_reginfo); | 42 | memset(bprm_buf + retval, 0, BPRM_BUF_SIZE - retval); |
174 | + if (arm_feature(env, ARM_FEATURE_EL2)) { | 43 | } |
175 | + define_one_arm_cp_reg(cpu, &zcr_el2_reginfo); | 44 | |
176 | + } else { | 45 | load_elf_image(filename, fd, info, NULL, bprm_buf); |
177 | + define_one_arm_cp_reg(cpu, &zcr_no_el2_reginfo); | 46 | - return; |
178 | + } | 47 | - |
179 | + if (arm_feature(env, ARM_FEATURE_EL3)) { | 48 | - exit_perror: |
180 | + define_one_arm_cp_reg(cpu, &zcr_el3_reginfo); | 49 | - fprintf(stderr, "%s: %s\n", filename, strerror(errno)); |
181 | + } | 50 | - exit(-1); |
182 | + } | ||
183 | } | 51 | } |
184 | 52 | ||
185 | void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu) | 53 | static int symfind(const void *s0, const void *s1) |
186 | -- | 54 | -- |
187 | 2.16.1 | 55 | 2.20.1 |
188 | 56 | ||
189 | 57 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | From: Richard Henderson <richard.henderson@linaro.org> | |
2 | |||
3 | This is generic support, with the code disabled for all targets. | ||
4 | |||
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | Message-id: 20201021173749.111103-11-richard.henderson@linaro.org | ||
7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
9 | --- | ||
10 | linux-user/qemu.h | 4 ++ | ||
11 | linux-user/elfload.c | 157 +++++++++++++++++++++++++++++++++++++++++++ | ||
12 | 2 files changed, 161 insertions(+) | ||
13 | |||
14 | diff --git a/linux-user/qemu.h b/linux-user/qemu.h | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/linux-user/qemu.h | ||
17 | +++ b/linux-user/qemu.h | ||
18 | @@ -XXX,XX +XXX,XX @@ struct image_info { | ||
19 | abi_ulong interpreter_loadmap_addr; | ||
20 | abi_ulong interpreter_pt_dynamic_addr; | ||
21 | struct image_info *other_info; | ||
22 | + | ||
23 | + /* For target-specific processing of NT_GNU_PROPERTY_TYPE_0. */ | ||
24 | + uint32_t note_flags; | ||
25 | + | ||
26 | #ifdef TARGET_MIPS | ||
27 | int fp_abi; | ||
28 | int interp_fp_abi; | ||
29 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c | ||
30 | index XXXXXXX..XXXXXXX 100644 | ||
31 | --- a/linux-user/elfload.c | ||
32 | +++ b/linux-user/elfload.c | ||
33 | @@ -XXX,XX +XXX,XX @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, | ||
34 | |||
35 | #include "elf.h" | ||
36 | |||
37 | +static bool arch_parse_elf_property(uint32_t pr_type, uint32_t pr_datasz, | ||
38 | + const uint32_t *data, | ||
39 | + struct image_info *info, | ||
40 | + Error **errp) | ||
41 | +{ | ||
42 | + g_assert_not_reached(); | ||
43 | +} | ||
44 | +#define ARCH_USE_GNU_PROPERTY 0 | ||
45 | + | ||
46 | struct exec | ||
47 | { | ||
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(¬e, bprm_buf + phdr->p_offset, n); | ||
146 | + } else { | ||
147 | + ssize_t len = pread(image_fd, ¬e, n, phdr->p_offset); | ||
148 | + if (len != n) { | ||
149 | + error_setg_errno(errp, errno, "Error reading file header"); | ||
150 | + return false; | ||
151 | + } | ||
152 | + } | ||
153 | + | ||
154 | + /* | ||
155 | + * The contents of a valid PT_GNU_PROPERTY is a sequence | ||
156 | + * of uint32_t -- swap them all now. | ||
157 | + */ | ||
158 | +#ifdef BSWAP_NEEDED | ||
159 | + for (int i = 0; i < n / 4; i++) { | ||
160 | + bswap32s(note.data + i); | ||
161 | + } | ||
162 | +#endif | ||
163 | + | ||
164 | + /* | ||
165 | + * Note that nhdr is 3 words, and that the "name" described by namesz | ||
166 | + * immediately follows nhdr and is thus at the 4th word. Further, all | ||
167 | + * of the inputs to the kernel's round_up are multiples of 4. | ||
168 | + */ | ||
169 | + if (note.nhdr.n_type != NT_GNU_PROPERTY_TYPE_0 || | ||
170 | + note.nhdr.n_namesz != NOTE_NAME_SZ || | ||
171 | + note.data[3] != GNU0_MAGIC) { | ||
172 | + error_setg(errp, "Invalid note in PT_GNU_PROPERTY"); | ||
173 | + return false; | ||
174 | + } | ||
175 | + off = sizeof(note.nhdr) + NOTE_NAME_SZ; | ||
176 | + | ||
177 | + datasz = note.nhdr.n_descsz + off; | ||
178 | + if (datasz > n) { | ||
179 | + error_setg(errp, "Invalid note size in PT_GNU_PROPERTY"); | ||
180 | + return false; | ||
181 | + } | ||
182 | + | ||
183 | + have_prev_type = false; | ||
184 | + prev_type = 0; | ||
185 | + while (1) { | ||
186 | + if (off == datasz) { | ||
187 | + return true; /* end, exit ok */ | ||
188 | + } | ||
189 | + if (!parse_elf_property(note.data, &off, datasz, info, | ||
190 | + have_prev_type, &prev_type, errp)) { | ||
191 | + return false; | ||
192 | + } | ||
193 | + have_prev_type = true; | ||
194 | + } | ||
195 | +} | ||
196 | + | ||
197 | /* Load an ELF image into the address space. | ||
198 | |||
199 | IMAGE_NAME is the filename of the image, to use in error messages. | ||
200 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, | ||
201 | goto exit_errmsg; | ||
202 | } | ||
203 | *pinterp_name = g_steal_pointer(&interp_name); | ||
204 | + } else if (eppnt->p_type == PT_GNU_PROPERTY) { | ||
205 | + if (!parse_elf_properties(image_fd, info, eppnt, bprm_buf, &err)) { | ||
206 | + goto exit_errmsg; | ||
207 | + } | ||
208 | } | ||
209 | } | ||
210 | |||
211 | -- | ||
212 | 2.20.1 | ||
213 | |||
214 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Use the new generic support for NT_GNU_PROPERTY_TYPE_0. | ||
4 | |||
3 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
4 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 6 | Message-id: 20201021173749.111103-12-richard.henderson@linaro.org |
5 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
6 | Message-id: 20180123035349.24538-3-richard.henderson@linaro.org | ||
7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
8 | --- | 9 | --- |
9 | target/arm/cpu.h | 12 ++++++++++++ | 10 | linux-user/elfload.c | 48 ++++++++++++++++++++++++++++++++++++++++++-- |
10 | 1 file changed, 12 insertions(+) | 11 | 1 file changed, 46 insertions(+), 2 deletions(-) |
11 | 12 | ||
12 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | 13 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c |
13 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/target/arm/cpu.h | 15 | --- a/linux-user/elfload.c |
15 | +++ b/target/arm/cpu.h | 16 | +++ b/linux-user/elfload.c |
16 | @@ -XXX,XX +XXX,XX @@ typedef struct ARMVectorReg { | 17 | @@ -XXX,XX +XXX,XX @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, |
17 | uint64_t d[2 * ARM_MAX_VQ] QEMU_ALIGNED(16); | 18 | |
18 | } ARMVectorReg; | 19 | #include "elf.h" |
19 | 20 | ||
20 | +/* In AArch32 mode, predicate registers do not exist at all. */ | 21 | +/* We must delay the following stanzas until after "elf.h". */ |
21 | +#ifdef TARGET_AARCH64 | 22 | +#if defined(TARGET_AARCH64) |
22 | +typedef struct ARMPredicateReg { | 23 | + |
23 | + uint64_t p[2 * ARM_MAX_VQ / 8] QEMU_ALIGNED(16); | 24 | +static bool arch_parse_elf_property(uint32_t pr_type, uint32_t pr_datasz, |
24 | +} ARMPredicateReg; | 25 | + const uint32_t *data, |
26 | + struct image_info *info, | ||
27 | + Error **errp) | ||
28 | +{ | ||
29 | + if (pr_type == GNU_PROPERTY_AARCH64_FEATURE_1_AND) { | ||
30 | + if (pr_datasz != sizeof(uint32_t)) { | ||
31 | + error_setg(errp, "Ill-formed GNU_PROPERTY_AARCH64_FEATURE_1_AND"); | ||
32 | + return false; | ||
33 | + } | ||
34 | + /* We will extract GNU_PROPERTY_AARCH64_FEATURE_1_BTI later. */ | ||
35 | + info->note_flags = *data; | ||
36 | + } | ||
37 | + return true; | ||
38 | +} | ||
39 | +#define ARCH_USE_GNU_PROPERTY 1 | ||
40 | + | ||
41 | +#else | ||
42 | + | ||
43 | static bool arch_parse_elf_property(uint32_t pr_type, uint32_t pr_datasz, | ||
44 | const uint32_t *data, | ||
45 | struct image_info *info, | ||
46 | @@ -XXX,XX +XXX,XX @@ static bool arch_parse_elf_property(uint32_t pr_type, uint32_t pr_datasz, | ||
47 | } | ||
48 | #define ARCH_USE_GNU_PROPERTY 0 | ||
49 | |||
25 | +#endif | 50 | +#endif |
26 | + | 51 | + |
27 | 52 | struct exec | |
28 | typedef struct CPUARMState { | 53 | { |
29 | /* Regs for current mode. */ | 54 | unsigned int a_info; /* Use macros N_MAGIC, etc for access */ |
30 | @@ -XXX,XX +XXX,XX @@ typedef struct CPUARMState { | 55 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, |
31 | struct { | 56 | struct elfhdr *ehdr = (struct elfhdr *)bprm_buf; |
32 | ARMVectorReg zregs[32]; | 57 | struct elf_phdr *phdr; |
33 | 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; | ||
34 | +#ifdef TARGET_AARCH64 | 69 | +#ifdef TARGET_AARCH64 |
35 | + /* Store FFR as pregs[16] to make it easier to treat as any other. */ | 70 | + /* |
36 | + ARMPredicateReg pregs[17]; | 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 | + } | ||
37 | +#endif | 86 | +#endif |
38 | + | 87 | + |
39 | uint32_t xregs[16]; | 88 | for (i = 0; i < ehdr->e_phnum; i++) { |
40 | /* We store these fpcsr fields separately for convenience. */ | 89 | struct elf_phdr *eppnt = phdr + i; |
41 | int vec_len; | 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; | ||
42 | -- | 100 | -- |
43 | 2.16.1 | 101 | 2.20.1 |
44 | 102 | ||
45 | 103 | diff view generated by jsdifflib |
1 | From: Andrey Smirnov <andrew.smirnov@gmail.com> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Add code to emulate SNVS IP-block. Currently only the bits needed to | 3 | The note test requires gcc 10 for -mbranch-protection=standard. |
4 | be able to emulate machine shutdown are implemented. | 4 | The mmap test uses PROT_BTI and does not require special compiler support. |
5 | 5 | ||
6 | Cc: Peter Maydell <peter.maydell@linaro.org> | 6 | Acked-by: Alex Bennée <alex.bennee@linaro.org> |
7 | Cc: Jason Wang <jasowang@redhat.com> | ||
8 | Cc: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
9 | Cc: Marcel Apfelbaum <marcel.apfelbaum@zoho.com> | ||
10 | Cc: Michael S. Tsirkin <mst@redhat.com> | ||
11 | Cc: qemu-devel@nongnu.org | ||
12 | Cc: qemu-arm@nongnu.org | ||
13 | Cc: yurovsky@gmail.com | ||
14 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
15 | Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> | 8 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
9 | Message-id: 20201021173749.111103-13-richard.henderson@linaro.org | ||
16 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
17 | --- | 11 | --- |
18 | hw/misc/Makefile.objs | 1 + | 12 | tests/tcg/aarch64/bti-1.c | 62 ++++++++++++++++ |
19 | include/hw/misc/imx7_snvs.h | 35 +++++++++++++++++++ | 13 | tests/tcg/aarch64/bti-2.c | 116 ++++++++++++++++++++++++++++++ |
20 | hw/misc/imx7_snvs.c | 83 +++++++++++++++++++++++++++++++++++++++++++++ | 14 | tests/tcg/aarch64/bti-crt.inc.c | 51 +++++++++++++ |
21 | 3 files changed, 119 insertions(+) | 15 | tests/tcg/aarch64/Makefile.target | 10 +++ |
22 | create mode 100644 include/hw/misc/imx7_snvs.h | 16 | tests/tcg/configure.sh | 4 ++ |
23 | create mode 100644 hw/misc/imx7_snvs.c | 17 | 5 files changed, 243 insertions(+) |
24 | 18 | create mode 100644 tests/tcg/aarch64/bti-1.c | |
25 | diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs | 19 | create mode 100644 tests/tcg/aarch64/bti-2.c |
26 | index XXXXXXX..XXXXXXX 100644 | 20 | create mode 100644 tests/tcg/aarch64/bti-crt.inc.c |
27 | --- a/hw/misc/Makefile.objs | 21 | |
28 | +++ b/hw/misc/Makefile.objs | 22 | diff --git a/tests/tcg/aarch64/bti-1.c b/tests/tcg/aarch64/bti-1.c |
29 | @@ -XXX,XX +XXX,XX @@ obj-$(CONFIG_IMX) += imx6_ccm.o | ||
30 | obj-$(CONFIG_IMX) += imx6_src.o | ||
31 | obj-$(CONFIG_IMX) += imx7_ccm.o | ||
32 | obj-$(CONFIG_IMX) += imx2_wdt.o | ||
33 | +obj-$(CONFIG_IMX) += imx7_snvs.o | ||
34 | obj-$(CONFIG_MILKYMIST) += milkymist-hpdmc.o | ||
35 | obj-$(CONFIG_MILKYMIST) += milkymist-pfpu.o | ||
36 | obj-$(CONFIG_MAINSTONE) += mst_fpga.o | ||
37 | diff --git a/include/hw/misc/imx7_snvs.h b/include/hw/misc/imx7_snvs.h | ||
38 | new file mode 100644 | 23 | new file mode 100644 |
39 | index XXXXXXX..XXXXXXX | 24 | index XXXXXXX..XXXXXXX |
40 | --- /dev/null | 25 | --- /dev/null |
41 | +++ b/include/hw/misc/imx7_snvs.h | 26 | +++ b/tests/tcg/aarch64/bti-1.c |
42 | @@ -XXX,XX +XXX,XX @@ | 27 | @@ -XXX,XX +XXX,XX @@ |
43 | +/* | 28 | +/* |
44 | + * Copyright (c) 2017, Impinj, Inc. | 29 | + * Branch target identification, basic notskip cases. |
45 | + * | ||
46 | + * i.MX7 SNVS block emulation code | ||
47 | + * | ||
48 | + * Author: Andrey Smirnov <andrew.smirnov@gmail.com> | ||
49 | + * | ||
50 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
51 | + * See the COPYING file in the top-level directory. | ||
52 | + */ | 30 | + */ |
53 | + | 31 | + |
54 | +#ifndef IMX7_SNVS_H | 32 | +#include "bti-crt.inc.c" |
55 | +#define IMX7_SNVS_H | 33 | + |
56 | + | 34 | +static void skip2_sigill(int sig, siginfo_t *info, ucontext_t *uc) |
57 | +#include "qemu/bitops.h" | 35 | +{ |
58 | +#include "hw/sysbus.h" | 36 | + uc->uc_mcontext.pc += 8; |
59 | + | 37 | + uc->uc_mcontext.pstate = 1; |
60 | + | 38 | +} |
61 | +enum IMX7SNVSRegisters { | 39 | + |
62 | + SNVS_LPCR = 0x38, | 40 | +#define NOP "nop" |
63 | + SNVS_LPCR_TOP = BIT(6), | 41 | +#define BTI_N "hint #32" |
64 | + SNVS_LPCR_DP_EN = BIT(5) | 42 | +#define BTI_C "hint #34" |
65 | +}; | 43 | +#define BTI_J "hint #36" |
66 | + | 44 | +#define BTI_JC "hint #38" |
67 | +#define TYPE_IMX7_SNVS "imx7.snvs" | 45 | + |
68 | +#define IMX7_SNVS(obj) OBJECT_CHECK(IMX7SNVSState, (obj), TYPE_IMX7_SNVS) | 46 | +#define BTYPE_1(DEST) \ |
69 | + | 47 | + asm("mov %0,#1; adr x16, 1f; br x16; 1: " DEST "; mov %0,#0" \ |
70 | +typedef struct IMX7SNVSState { | 48 | + : "=r"(skipped) : : "x16") |
71 | + /* <private> */ | 49 | + |
72 | + SysBusDevice parent_obj; | 50 | +#define BTYPE_2(DEST) \ |
73 | + | 51 | + asm("mov %0,#1; adr x16, 1f; blr x16; 1: " DEST "; mov %0,#0" \ |
74 | + MemoryRegion mmio; | 52 | + : "=r"(skipped) : : "x16", "x30") |
75 | +} IMX7SNVSState; | 53 | + |
76 | + | 54 | +#define BTYPE_3(DEST) \ |
77 | +#endif /* IMX7_SNVS_H */ | 55 | + asm("mov %0,#1; adr x15, 1f; br x15; 1: " DEST "; mov %0,#0" \ |
78 | diff --git a/hw/misc/imx7_snvs.c b/hw/misc/imx7_snvs.c | 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 | ||
79 | new file mode 100644 | 91 | new file mode 100644 |
80 | index XXXXXXX..XXXXXXX | 92 | index XXXXXXX..XXXXXXX |
81 | --- /dev/null | 93 | --- /dev/null |
82 | +++ b/hw/misc/imx7_snvs.c | 94 | +++ b/tests/tcg/aarch64/bti-2.c |
83 | @@ -XXX,XX +XXX,XX @@ | 95 | @@ -XXX,XX +XXX,XX @@ |
84 | +/* | 96 | +/* |
85 | + * IMX7 Secure Non-Volatile Storage | 97 | + * Branch target identification, basic notskip cases. |
98 | + */ | ||
99 | + | ||
100 | +#include <stdio.h> | ||
101 | +#include <signal.h> | ||
102 | +#include <string.h> | ||
103 | +#include <unistd.h> | ||
104 | +#include <sys/mman.h> | ||
105 | + | ||
106 | +#ifndef PROT_BTI | ||
107 | +#define PROT_BTI 0x10 | ||
108 | +#endif | ||
109 | + | ||
110 | +static void skip2_sigill(int sig, siginfo_t *info, void *vuc) | ||
111 | +{ | ||
112 | + ucontext_t *uc = vuc; | ||
113 | + uc->uc_mcontext.pc += 8; | ||
114 | + uc->uc_mcontext.pstate = 1; | ||
115 | +} | ||
116 | + | ||
117 | +#define NOP "nop" | ||
118 | +#define BTI_N "hint #32" | ||
119 | +#define BTI_C "hint #34" | ||
120 | +#define BTI_J "hint #36" | ||
121 | +#define BTI_JC "hint #38" | ||
122 | + | ||
123 | +#define BTYPE_1(DEST) \ | ||
124 | + "mov x1, #1\n\t" \ | ||
125 | + "adr x16, 1f\n\t" \ | ||
126 | + "br x16\n" \ | ||
127 | +"1: " DEST "\n\t" \ | ||
128 | + "mov x1, #0" | ||
129 | + | ||
130 | +#define BTYPE_2(DEST) \ | ||
131 | + "mov x1, #1\n\t" \ | ||
132 | + "adr x16, 1f\n\t" \ | ||
133 | + "blr x16\n" \ | ||
134 | +"1: " DEST "\n\t" \ | ||
135 | + "mov x1, #0" | ||
136 | + | ||
137 | +#define BTYPE_3(DEST) \ | ||
138 | + "mov x1, #1\n\t" \ | ||
139 | + "adr x15, 1f\n\t" \ | ||
140 | + "br x15\n" \ | ||
141 | +"1: " DEST "\n\t" \ | ||
142 | + "mov x1, #0" | ||
143 | + | ||
144 | +#define TEST(WHICH, DEST, EXPECT) \ | ||
145 | + WHICH(DEST) "\n" \ | ||
146 | + ".if " #EXPECT "\n\t" \ | ||
147 | + "eor x1, x1," #EXPECT "\n" \ | ||
148 | + ".endif\n\t" \ | ||
149 | + "add x0, x0, x1\n\t" | ||
150 | + | ||
151 | +asm("\n" | ||
152 | +"test_begin:\n\t" | ||
153 | + BTI_C "\n\t" | ||
154 | + "mov x2, x30\n\t" | ||
155 | + "mov x0, #0\n\t" | ||
156 | + | ||
157 | + TEST(BTYPE_1, NOP, 1) | ||
158 | + TEST(BTYPE_1, BTI_N, 1) | ||
159 | + TEST(BTYPE_1, BTI_C, 0) | ||
160 | + TEST(BTYPE_1, BTI_J, 0) | ||
161 | + TEST(BTYPE_1, BTI_JC, 0) | ||
162 | + | ||
163 | + TEST(BTYPE_2, NOP, 1) | ||
164 | + TEST(BTYPE_2, BTI_N, 1) | ||
165 | + TEST(BTYPE_2, BTI_C, 0) | ||
166 | + TEST(BTYPE_2, BTI_J, 1) | ||
167 | + TEST(BTYPE_2, BTI_JC, 0) | ||
168 | + | ||
169 | + TEST(BTYPE_3, NOP, 1) | ||
170 | + TEST(BTYPE_3, BTI_N, 1) | ||
171 | + TEST(BTYPE_3, BTI_C, 1) | ||
172 | + TEST(BTYPE_3, BTI_J, 0) | ||
173 | + TEST(BTYPE_3, BTI_JC, 0) | ||
174 | + | ||
175 | + "ret x2\n" | ||
176 | +"test_end:" | ||
177 | +); | ||
178 | + | ||
179 | +int main() | ||
180 | +{ | ||
181 | + struct sigaction sa; | ||
182 | + void *tb, *te; | ||
183 | + | ||
184 | + void *p = mmap(0, getpagesize(), | ||
185 | + PROT_EXEC | PROT_READ | PROT_WRITE | PROT_BTI, | ||
186 | + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); | ||
187 | + if (p == MAP_FAILED) { | ||
188 | + perror("mmap"); | ||
189 | + return 1; | ||
190 | + } | ||
191 | + | ||
192 | + memset(&sa, 0, sizeof(sa)); | ||
193 | + sa.sa_sigaction = skip2_sigill; | ||
194 | + sa.sa_flags = SA_SIGINFO; | ||
195 | + if (sigaction(SIGILL, &sa, NULL) < 0) { | ||
196 | + perror("sigaction"); | ||
197 | + return 1; | ||
198 | + } | ||
199 | + | ||
200 | + /* | ||
201 | + * ??? With "extern char test_begin[]", some compiler versions | ||
202 | + * will use :got references, and some linker versions will | ||
203 | + * resolve this reference to a static symbol incorrectly. | ||
204 | + * Bypass this error by using a pc-relative reference directly. | ||
205 | + */ | ||
206 | + asm("adr %0, test_begin; adr %1, test_end" : "=r"(tb), "=r"(te)); | ||
207 | + | ||
208 | + memcpy(p, tb, te - tb); | ||
209 | + | ||
210 | + return ((int (*)(void))p)(); | ||
211 | +} | ||
212 | diff --git a/tests/tcg/aarch64/bti-crt.inc.c b/tests/tcg/aarch64/bti-crt.inc.c | ||
213 | new file mode 100644 | ||
214 | index XXXXXXX..XXXXXXX | ||
215 | --- /dev/null | ||
216 | +++ b/tests/tcg/aarch64/bti-crt.inc.c | ||
217 | @@ -XXX,XX +XXX,XX @@ | ||
218 | +/* | ||
219 | + * Minimal user-environment for testing BTI. | ||
86 | + * | 220 | + * |
87 | + * Copyright (c) 2018, Impinj, Inc. | 221 | + * Normal libc is not (yet) built with BTI support enabled, |
88 | + * | 222 | + * and so could generate a BTI TRAP before ever reaching main. |
89 | + * Author: Andrey Smirnov <andrew.smirnov@gmail.com> | ||
90 | + * | ||
91 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
92 | + * See the COPYING file in the top-level directory. | ||
93 | + * | ||
94 | + * Bare minimum emulation code needed to support being able to shut | ||
95 | + * down linux guest gracefully. | ||
96 | + */ | 223 | + */ |
97 | + | 224 | + |
98 | +#include "qemu/osdep.h" | 225 | +#include <stdlib.h> |
99 | +#include "hw/misc/imx7_snvs.h" | 226 | +#include <signal.h> |
100 | +#include "qemu/log.h" | 227 | +#include <ucontext.h> |
101 | +#include "sysemu/sysemu.h" | 228 | +#include <asm/unistd.h> |
102 | + | 229 | + |
103 | +static uint64_t imx7_snvs_read(void *opaque, hwaddr offset, unsigned size) | 230 | +int main(void); |
104 | +{ | 231 | + |
105 | + return 0; | 232 | +void _start(void) |
106 | +} | 233 | +{ |
107 | + | 234 | + exit(main()); |
108 | +static void imx7_snvs_write(void *opaque, hwaddr offset, | 235 | +} |
109 | + uint64_t v, unsigned size) | 236 | + |
110 | +{ | 237 | +void exit(int ret) |
111 | + const uint32_t value = v; | 238 | +{ |
112 | + const uint32_t mask = SNVS_LPCR_TOP | SNVS_LPCR_DP_EN; | 239 | + register int x0 __asm__("x0") = ret; |
113 | + | 240 | + register int x8 __asm__("x8") = __NR_exit; |
114 | + if (offset == SNVS_LPCR && ((value & mask) == mask)) { | 241 | + |
115 | + qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN); | 242 | + asm volatile("svc #0" : : "r"(x0), "r"(x8)); |
116 | + } | 243 | + __builtin_unreachable(); |
117 | +} | 244 | +} |
118 | + | 245 | + |
119 | +static const struct MemoryRegionOps imx7_snvs_ops = { | 246 | +/* |
120 | + .read = imx7_snvs_read, | 247 | + * Irritatingly, the user API struct sigaction does not match the |
121 | + .write = imx7_snvs_write, | 248 | + * kernel API struct sigaction. So for simplicity, isolate the |
122 | + .endianness = DEVICE_NATIVE_ENDIAN, | 249 | + * kernel ABI here, and make this act like signal. |
123 | + .impl = { | 250 | + */ |
124 | + /* | 251 | +void signal_info(int sig, void (*fn)(int, siginfo_t *, ucontext_t *)) |
125 | + * Our device would not work correctly if the guest was doing | 252 | +{ |
126 | + * unaligned access. This might not be a limitation on the real | 253 | + struct kernel_sigaction { |
127 | + * device but in practice there is no reason for a guest to access | 254 | + void (*handler)(int, siginfo_t *, ucontext_t *); |
128 | + * this device unaligned. | 255 | + unsigned long flags; |
129 | + */ | 256 | + unsigned long restorer; |
130 | + .min_access_size = 4, | 257 | + unsigned long mask; |
131 | + .max_access_size = 4, | 258 | + } sa = { fn, SA_SIGINFO, 0, 0 }; |
132 | + .unaligned = false, | 259 | + |
133 | + }, | 260 | + register int x0 __asm__("x0") = sig; |
134 | +}; | 261 | + register void *x1 __asm__("x1") = &sa; |
135 | + | 262 | + register void *x2 __asm__("x2") = 0; |
136 | +static void imx7_snvs_init(Object *obj) | 263 | + register int x3 __asm__("x3") = sizeof(unsigned long); |
137 | +{ | 264 | + register int x8 __asm__("x8") = __NR_rt_sigaction; |
138 | + SysBusDevice *sd = SYS_BUS_DEVICE(obj); | 265 | + |
139 | + IMX7SNVSState *s = IMX7_SNVS(obj); | 266 | + asm volatile("svc #0" |
140 | + | 267 | + : : "r"(x0), "r"(x1), "r"(x2), "r"(x3), "r"(x8) : "memory"); |
141 | + memory_region_init_io(&s->mmio, obj, &imx7_snvs_ops, s, | 268 | +} |
142 | + TYPE_IMX7_SNVS, 0x1000); | 269 | diff --git a/tests/tcg/aarch64/Makefile.target b/tests/tcg/aarch64/Makefile.target |
143 | + | 270 | index XXXXXXX..XXXXXXX 100644 |
144 | + sysbus_init_mmio(sd, &s->mmio); | 271 | --- a/tests/tcg/aarch64/Makefile.target |
145 | +} | 272 | +++ b/tests/tcg/aarch64/Makefile.target |
146 | + | 273 | @@ -XXX,XX +XXX,XX @@ run-pauth-%: QEMU_OPTS += -cpu max |
147 | +static void imx7_snvs_class_init(ObjectClass *klass, void *data) | 274 | run-plugin-pauth-%: QEMU_OPTS += -cpu max |
148 | +{ | 275 | endif |
149 | + DeviceClass *dc = DEVICE_CLASS(klass); | 276 | |
150 | + | 277 | +# BTI Tests |
151 | + dc->desc = "i.MX7 Secure Non-Volatile Storage Module"; | 278 | +# bti-1 tests the elf notes, so we require special compiler support. |
152 | +} | 279 | +ifneq ($(DOCKER_IMAGE)$(CROSS_CC_HAS_ARMV8_BTI),) |
153 | + | 280 | +AARCH64_TESTS += bti-1 |
154 | +static const TypeInfo imx7_snvs_info = { | 281 | +bti-1: CFLAGS += -mbranch-protection=standard |
155 | + .name = TYPE_IMX7_SNVS, | 282 | +bti-1: LDFLAGS += -nostdlib |
156 | + .parent = TYPE_SYS_BUS_DEVICE, | 283 | +endif |
157 | + .instance_size = sizeof(IMX7SNVSState), | 284 | +# bti-2 tests PROT_BTI, so no special compiler support required. |
158 | + .instance_init = imx7_snvs_init, | 285 | +AARCH64_TESTS += bti-2 |
159 | + .class_init = imx7_snvs_class_init, | 286 | + |
160 | +}; | 287 | # Semihosting smoke test for linux-user |
161 | + | 288 | AARCH64_TESTS += semihosting |
162 | +static void imx7_snvs_register_type(void) | 289 | run-semihosting: semihosting |
163 | +{ | 290 | diff --git a/tests/tcg/configure.sh b/tests/tcg/configure.sh |
164 | + type_register_static(&imx7_snvs_info); | 291 | index XXXXXXX..XXXXXXX 100755 |
165 | +} | 292 | --- a/tests/tcg/configure.sh |
166 | +type_init(imx7_snvs_register_type) | 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 | |||
167 | -- | 305 | -- |
168 | 2.16.1 | 306 | 2.20.1 |
169 | 307 | ||
170 | 308 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Thomas Huth <thuth@redhat.com> | ||
1 | 2 | ||
3 | When compiling with -Werror=implicit-fallthrough, gcc complains about | ||
4 | missing fallthrough annotations in this file. Looking at the code, | ||
5 | the fallthrough is very likely intended here, so add some comments | ||
6 | to silence the compiler warnings. | ||
7 | |||
8 | Signed-off-by: Thomas Huth <thuth@redhat.com> | ||
9 | Message-id: 20201020105938.23209-1-thuth@redhat.com | ||
10 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
12 | --- | ||
13 | hw/arm/highbank.c | 2 ++ | ||
14 | 1 file changed, 2 insertions(+) | ||
15 | |||
16 | diff --git a/hw/arm/highbank.c b/hw/arm/highbank.c | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/hw/arm/highbank.c | ||
19 | +++ b/hw/arm/highbank.c | ||
20 | @@ -XXX,XX +XXX,XX @@ static void hb_reset_secondary(ARMCPU *cpu, const struct arm_boot_info *info) | ||
21 | address_space_stl_notdirty(&address_space_memory, | ||
22 | SMP_BOOT_REG + 0x30, 0, | ||
23 | MEMTXATTRS_UNSPECIFIED, NULL); | ||
24 | + /* fallthrough */ | ||
25 | case 3: | ||
26 | address_space_stl_notdirty(&address_space_memory, | ||
27 | SMP_BOOT_REG + 0x20, 0, | ||
28 | MEMTXATTRS_UNSPECIFIED, NULL); | ||
29 | + /* fallthrough */ | ||
30 | case 2: | ||
31 | address_space_stl_notdirty(&address_space_memory, | ||
32 | SMP_BOOT_REG + 0x10, 0, | ||
33 | -- | ||
34 | 2.20.1 | ||
35 | |||
36 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Pavel Dovgalyuk <pavel.dovgalyuk@ispras.ru> | ||
1 | 2 | ||
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: Christoffer Dall <christoffer.dall@linaro.org> | 1 | From: Havard Skinnemoen <hskinnemoen@google.com> |
---|---|---|---|
2 | 2 | ||
3 | KVM doesn't support emulating a GICv3 in userspace, only GICv2. We | 3 | This allows us to reuse npcm7xx_timer_pause for the watchdog timer. |
4 | currently attempt this anyway, and as a result a KVM guest doesn't | ||
5 | receive interrupts and the user is left wondering why. Report an error | ||
6 | to the user if this particular combination is requested. | ||
7 | 4 | ||
8 | Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org> | ||
9 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 5 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
10 | Message-id: 20180201205307.30343-1-christoffer.dall@linaro.org | 6 | Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com> |
11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
12 | --- | 8 | --- |
13 | target/arm/kvm_arm.h | 4 ++++ | 9 | hw/timer/npcm7xx_timer.c | 6 +++--- |
14 | 1 file changed, 4 insertions(+) | 10 | 1 file changed, 3 insertions(+), 3 deletions(-) |
15 | 11 | ||
16 | diff --git a/target/arm/kvm_arm.h b/target/arm/kvm_arm.h | 12 | diff --git a/hw/timer/npcm7xx_timer.c b/hw/timer/npcm7xx_timer.c |
17 | index XXXXXXX..XXXXXXX 100644 | 13 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/target/arm/kvm_arm.h | 14 | --- a/hw/timer/npcm7xx_timer.c |
19 | +++ b/target/arm/kvm_arm.h | 15 | +++ b/hw/timer/npcm7xx_timer.c |
20 | @@ -XXX,XX +XXX,XX @@ static inline const char *gicv3_class_name(void) | 16 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_pause(NPCM7xxTimer *t) |
21 | exit(1); | 17 | timer_del(&t->qtimer); |
22 | #endif | 18 | now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); |
23 | } else { | 19 | t->remaining_ns = t->expires_ns - now; |
24 | + if (kvm_enabled()) { | 20 | - if (t->remaining_ns <= 0) { |
25 | + error_report("Userspace GICv3 is not supported with KVM"); | 21 | - npcm7xx_timer_reached_zero(t); |
26 | + exit(1); | 22 | - } |
27 | + } | 23 | } |
28 | return "arm-gicv3"; | 24 | |
25 | /* | ||
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 | } | ||
29 | } | 34 | } |
30 | } | 35 | } |
31 | -- | 36 | -- |
32 | 2.16.1 | 37 | 2.20.1 |
33 | 38 | ||
34 | 39 | diff view generated by jsdifflib |
1 | From: Ard Biesheuvel <ard.biesheuvel@linaro.org> | 1 | From: Hao Wu <wuhaotsh@google.com> |
---|---|---|---|
2 | 2 | ||
3 | This implements emulation of the new SHA-3 instructions that have | 3 | The watchdog is part of NPCM7XX's timer module. Its behavior is |
4 | been added as an optional extensions to the ARMv8 Crypto Extensions | 4 | controlled by the WTCR register in the timer. |
5 | in ARM v8.2. | ||
6 | 5 | ||
7 | Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> | 6 | When enabled, the watchdog issues an interrupt signal after a pre-set |
8 | Message-id: 20180207111729.15737-3-ard.biesheuvel@linaro.org | 7 | amount of cycles, and issues a reset signal shortly after that. |
8 | |||
9 | Reviewed-by: Tyrone Ting <kfting@nuvoton.com> | ||
10 | Signed-off-by: Hao Wu <wuhaotsh@google.com> | ||
11 | Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com> | ||
9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 12 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
13 | [PMM: deleted blank line at end of npcm_watchdog_timer-test.c] | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 14 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
11 | --- | 15 | --- |
12 | target/arm/cpu.h | 1 + | 16 | include/hw/misc/npcm7xx_clk.h | 2 + |
13 | target/arm/translate-a64.c | 148 +++++++++++++++++++++++++++++++++++++++++++-- | 17 | include/hw/timer/npcm7xx_timer.h | 48 +++- |
14 | 2 files changed, 145 insertions(+), 4 deletions(-) | 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 | ||
15 | 26 | ||
16 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | 27 | diff --git a/include/hw/misc/npcm7xx_clk.h b/include/hw/misc/npcm7xx_clk.h |
17 | index XXXXXXX..XXXXXXX 100644 | 28 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/target/arm/cpu.h | 29 | --- a/include/hw/misc/npcm7xx_clk.h |
19 | +++ b/target/arm/cpu.h | 30 | +++ b/include/hw/misc/npcm7xx_clk.h |
20 | @@ -XXX,XX +XXX,XX @@ enum arm_features { | 31 | @@ -XXX,XX +XXX,XX @@ |
21 | ARM_FEATURE_JAZELLE, /* has (trivial) Jazelle implementation */ | 32 | */ |
22 | ARM_FEATURE_SVE, /* has Scalable Vector Extension */ | 33 | #define NPCM7XX_CLK_NR_REGS (0x70 / sizeof(uint32_t)) |
23 | ARM_FEATURE_V8_SHA512, /* implements SHA512 part of v8 Crypto Extensions */ | 34 | |
24 | + ARM_FEATURE_V8_SHA3, /* implements SHA3 part of v8 Crypto Extensions */ | 35 | +#define NPCM7XX_WATCHDOG_RESET_GPIO_IN "npcm7xx-clk-watchdog-reset-gpio-in" |
36 | + | ||
37 | typedef struct NPCM7xxCLKState { | ||
38 | SysBusDevice parent; | ||
39 | |||
40 | diff --git a/include/hw/timer/npcm7xx_timer.h b/include/hw/timer/npcm7xx_timer.h | ||
41 | index XXXXXXX..XXXXXXX 100644 | ||
42 | --- a/include/hw/timer/npcm7xx_timer.h | ||
43 | +++ b/include/hw/timer/npcm7xx_timer.h | ||
44 | @@ -XXX,XX +XXX,XX @@ | ||
45 | */ | ||
46 | #define NPCM7XX_TIMER_NR_REGS (0x54 / sizeof(uint32_t)) | ||
47 | |||
48 | +/* The basic watchdog timer period is 2^14 clock cycles. */ | ||
49 | +#define NPCM7XX_WATCHDOG_BASETIME_SHIFT 14 | ||
50 | + | ||
51 | +#define NPCM7XX_WATCHDOG_RESET_GPIO_OUT "npcm7xx-clk-watchdog-reset-gpio-out" | ||
52 | + | ||
53 | typedef struct NPCM7xxTimerCtrlState NPCM7xxTimerCtrlState; | ||
54 | |||
55 | /** | ||
56 | - * struct NPCM7xxTimer - Individual timer state. | ||
57 | - * @irq: GIC interrupt line to fire on expiration (if enabled). | ||
58 | + * struct NPCM7xxBaseTimer - Basic functionality that both regular timer and | ||
59 | + * watchdog timer use. | ||
60 | * @qtimer: QEMU timer that notifies us on expiration. | ||
61 | * @expires_ns: Absolute virtual expiration time. | ||
62 | * @remaining_ns: Remaining time until expiration if timer is paused. | ||
63 | + */ | ||
64 | +typedef struct NPCM7xxBaseTimer { | ||
65 | + QEMUTimer qtimer; | ||
66 | + int64_t expires_ns; | ||
67 | + int64_t remaining_ns; | ||
68 | +} NPCM7xxBaseTimer; | ||
69 | + | ||
70 | +/** | ||
71 | + * struct NPCM7xxTimer - Individual timer state. | ||
72 | + * @ctrl: The timer module that owns this timer. | ||
73 | + * @irq: GIC interrupt line to fire on expiration (if enabled). | ||
74 | + * @base_timer: The basic timer functionality for this timer. | ||
75 | * @tcsr: The Timer Control and Status Register. | ||
76 | * @ticr: The Timer Initial Count Register. | ||
77 | */ | ||
78 | @@ -XXX,XX +XXX,XX @@ typedef struct NPCM7xxTimer { | ||
79 | NPCM7xxTimerCtrlState *ctrl; | ||
80 | |||
81 | qemu_irq irq; | ||
82 | - QEMUTimer qtimer; | ||
83 | - int64_t expires_ns; | ||
84 | - int64_t remaining_ns; | ||
85 | + NPCM7xxBaseTimer base_timer; | ||
86 | |||
87 | uint32_t tcsr; | ||
88 | uint32_t ticr; | ||
89 | } NPCM7xxTimer; | ||
90 | |||
91 | +/** | ||
92 | + * struct NPCM7xxWatchdogTimer - The watchdog timer state. | ||
93 | + * @ctrl: The timer module that owns this timer. | ||
94 | + * @irq: GIC interrupt line to fire on expiration (if enabled). | ||
95 | + * @reset_signal: The GPIO used to send a reset signal. | ||
96 | + * @base_timer: The basic timer functionality for this timer. | ||
97 | + * @wtcr: The Watchdog Timer Control Register. | ||
98 | + */ | ||
99 | +typedef struct NPCM7xxWatchdogTimer { | ||
100 | + NPCM7xxTimerCtrlState *ctrl; | ||
101 | + | ||
102 | + qemu_irq irq; | ||
103 | + qemu_irq reset_signal; | ||
104 | + NPCM7xxBaseTimer base_timer; | ||
105 | + | ||
106 | + uint32_t wtcr; | ||
107 | +} NPCM7xxWatchdogTimer; | ||
108 | + | ||
109 | /** | ||
110 | * struct NPCM7xxTimerCtrlState - Timer Module device state. | ||
111 | * @parent: System bus device. | ||
112 | * @iomem: Memory region through which registers are accessed. | ||
113 | + * @index: The index of this timer module. | ||
114 | * @tisr: The Timer Interrupt Status Register. | ||
115 | - * @wtcr: The Watchdog Timer Control Register. | ||
116 | * @timer: The five individual timers managed by this module. | ||
117 | + * @watchdog_timer: The watchdog timer managed by this module. | ||
118 | */ | ||
119 | struct NPCM7xxTimerCtrlState { | ||
120 | SysBusDevice parent; | ||
121 | @@ -XXX,XX +XXX,XX @@ struct NPCM7xxTimerCtrlState { | ||
122 | MemoryRegion iomem; | ||
123 | |||
124 | uint32_t tisr; | ||
125 | - uint32_t wtcr; | ||
126 | |||
127 | NPCM7xxTimer timer[NPCM7XX_TIMERS_PER_CTRL]; | ||
128 | + NPCM7xxWatchdogTimer watchdog_timer; | ||
25 | }; | 129 | }; |
26 | 130 | ||
27 | static inline int arm_feature(CPUARMState *env, int feature) | 131 | #define TYPE_NPCM7XX_TIMER "npcm7xx-timer" |
28 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | 132 | diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c |
29 | index XXXXXXX..XXXXXXX 100644 | 133 | index XXXXXXX..XXXXXXX 100644 |
30 | --- a/target/arm/translate-a64.c | 134 | --- a/hw/arm/npcm7xx.c |
31 | +++ b/target/arm/translate-a64.c | 135 | +++ b/hw/arm/npcm7xx.c |
32 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_three_reg_sha512(DisasContext *s, uint32_t insn) | 136 | @@ -XXX,XX +XXX,XX @@ enum NPCM7xxInterrupt { |
33 | feature = ARM_FEATURE_V8_SHA512; | 137 | NPCM7XX_TIMER12_IRQ, |
34 | genfn = gen_helper_crypto_sha512su1; | 138 | NPCM7XX_TIMER13_IRQ, |
35 | break; | 139 | NPCM7XX_TIMER14_IRQ, |
36 | - default: | 140 | + NPCM7XX_WDG0_IRQ = 47, /* Timer Module 0 Watchdog */ |
37 | - unallocated_encoding(s); | 141 | + NPCM7XX_WDG1_IRQ, /* Timer Module 1 Watchdog */ |
38 | - return; | 142 | + NPCM7XX_WDG2_IRQ, /* Timer Module 2 Watchdog */ |
39 | + case 3: /* RAX1 */ | 143 | }; |
40 | + feature = ARM_FEATURE_V8_SHA3; | 144 | |
41 | + genfn = NULL; | 145 | /* Total number of GIC interrupts, including internal Cortex-A9 interrupts. */ |
42 | + break; | 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); | ||
43 | } | 371 | } |
44 | } else { | 372 | } else { |
45 | unallocated_encoding(s); | 373 | t->tcsr &= ~(NPCM7XX_TCSR_CEN | NPCM7XX_TCSR_CACT); |
46 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_three_reg_sha512(DisasContext *s, uint32_t insn) | 374 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_reached_zero(NPCM7xxTimer *t) |
47 | tcg_temp_free_ptr(tcg_rn_ptr); | 375 | npcm7xx_timer_check_interrupt(t); |
48 | tcg_temp_free_ptr(tcg_rm_ptr); | 376 | } |
49 | } else { | 377 | |
50 | - g_assert_not_reached(); | 378 | -/* Stop counting. Record the time remaining so we can continue later. */ |
51 | + TCGv_i64 tcg_op1, tcg_op2, tcg_res[2]; | 379 | -static void npcm7xx_timer_pause(NPCM7xxTimer *t) |
52 | + int pass; | 380 | -{ |
53 | + | 381 | - int64_t now; |
54 | + tcg_op1 = tcg_temp_new_i64(); | 382 | - |
55 | + tcg_op2 = tcg_temp_new_i64(); | 383 | - timer_del(&t->qtimer); |
56 | + tcg_res[0] = tcg_temp_new_i64(); | 384 | - now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); |
57 | + tcg_res[1] = tcg_temp_new_i64(); | 385 | - t->remaining_ns = t->expires_ns - now; |
58 | + | 386 | -} |
59 | + for (pass = 0; pass < 2; pass++) { | 387 | |
60 | + read_vec_element(s, tcg_op1, rn, pass, MO_64); | 388 | /* |
61 | + read_vec_element(s, tcg_op2, rm, pass, MO_64); | 389 | * Restart the timer from its initial value. If the timer was enabled and stays |
62 | + | 390 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_pause(NPCM7xxTimer *t) |
63 | + tcg_gen_rotli_i64(tcg_res[pass], tcg_op2, 1); | 391 | */ |
64 | + tcg_gen_xor_i64(tcg_res[pass], tcg_res[pass], tcg_op1); | 392 | static void npcm7xx_timer_restart(NPCM7xxTimer *t, uint32_t old_tcsr) |
65 | + } | 393 | { |
66 | + write_vec_element(s, tcg_res[0], rd, 0, MO_64); | 394 | - t->remaining_ns = npcm7xx_timer_count_to_ns(t, t->ticr); |
67 | + write_vec_element(s, tcg_res[1], rd, 1, MO_64); | 395 | + t->base_timer.remaining_ns = npcm7xx_timer_count_to_ns(t, t->ticr); |
68 | + | 396 | |
69 | + tcg_temp_free_i64(tcg_op1); | 397 | if (old_tcsr & t->tcsr & NPCM7XX_TCSR_CEN) { |
70 | + tcg_temp_free_i64(tcg_op2); | 398 | - npcm7xx_timer_start(t); |
71 | + tcg_temp_free_i64(tcg_res[0]); | 399 | + npcm7xx_timer_start(&t->base_timer); |
72 | + tcg_temp_free_i64(tcg_res[1]); | ||
73 | } | 400 | } |
74 | } | 401 | } |
75 | 402 | ||
76 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_two_reg_sha512(DisasContext *s, uint32_t insn) | 403 | @@ -XXX,XX +XXX,XX @@ static uint32_t npcm7xx_timer_read_tdr(NPCM7xxTimer *t) |
77 | tcg_temp_free_ptr(tcg_rn_ptr); | 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); | ||
78 | } | 413 | } |
79 | 414 | ||
80 | +/* Crypto four-register | 415 | static void npcm7xx_timer_write_tcsr(NPCM7xxTimer *t, uint32_t new_tcsr) |
81 | + * 31 23 22 21 20 16 15 14 10 9 5 4 0 | 416 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_write_tcsr(NPCM7xxTimer *t, uint32_t new_tcsr) |
82 | + * +-------------------+-----+------+---+------+------+------+ | 417 | |
83 | + * | 1 1 0 0 1 1 1 0 0 | Op0 | Rm | 0 | Ra | Rn | Rd | | 418 | if (npcm7xx_tcsr_prescaler(old_tcsr) != npcm7xx_tcsr_prescaler(new_tcsr)) { |
84 | + * +-------------------+-----+------+---+------+------+------+ | 419 | /* Recalculate time remaining based on the current TDR value. */ |
420 | - t->remaining_ns = npcm7xx_timer_count_to_ns(t, tdr); | ||
421 | + t->base_timer.remaining_ns = npcm7xx_timer_count_to_ns(t, tdr); | ||
422 | if (old_tcsr & t->tcsr & NPCM7XX_TCSR_CEN) { | ||
423 | - npcm7xx_timer_start(t); | ||
424 | + npcm7xx_timer_start(&t->base_timer); | ||
425 | } | ||
426 | } | ||
427 | |||
428 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_write_tcsr(NPCM7xxTimer *t, uint32_t new_tcsr) | ||
429 | if ((old_tcsr ^ new_tcsr) & NPCM7XX_TCSR_CEN) { | ||
430 | if (new_tcsr & NPCM7XX_TCSR_CEN) { | ||
431 | t->tcsr |= NPCM7XX_TCSR_CACT; | ||
432 | - npcm7xx_timer_start(t); | ||
433 | + npcm7xx_timer_start(&t->base_timer); | ||
434 | } else { | ||
435 | t->tcsr &= ~NPCM7XX_TCSR_CACT; | ||
436 | - npcm7xx_timer_pause(t); | ||
437 | - if (t->remaining_ns <= 0) { | ||
438 | + npcm7xx_timer_pause(&t->base_timer); | ||
439 | + if (t->base_timer.remaining_ns <= 0) { | ||
440 | npcm7xx_timer_reached_zero(t); | ||
441 | } | ||
442 | } | ||
443 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_write_tisr(NPCM7xxTimerCtrlState *s, uint32_t value) | ||
444 | if (value & (1U << i)) { | ||
445 | npcm7xx_timer_check_interrupt(&s->timer[i]); | ||
446 | } | ||
447 | + | ||
448 | } | ||
449 | } | ||
450 | |||
451 | +static void npcm7xx_timer_write_wtcr(NPCM7xxWatchdogTimer *t, uint32_t new_wtcr) | ||
452 | +{ | ||
453 | + uint32_t old_wtcr = t->wtcr; | ||
454 | + | ||
455 | + /* | ||
456 | + * WTIF and WTRF are cleared by writing 1. Writing 0 makes these bits | ||
457 | + * unchanged. | ||
458 | + */ | ||
459 | + if (new_wtcr & NPCM7XX_WTCR_WTIF) { | ||
460 | + new_wtcr &= ~NPCM7XX_WTCR_WTIF; | ||
461 | + } else if (old_wtcr & NPCM7XX_WTCR_WTIF) { | ||
462 | + new_wtcr |= NPCM7XX_WTCR_WTIF; | ||
463 | + } | ||
464 | + if (new_wtcr & NPCM7XX_WTCR_WTRF) { | ||
465 | + new_wtcr &= ~NPCM7XX_WTCR_WTRF; | ||
466 | + } else if (old_wtcr & NPCM7XX_WTCR_WTRF) { | ||
467 | + new_wtcr |= NPCM7XX_WTCR_WTRF; | ||
468 | + } | ||
469 | + | ||
470 | + t->wtcr = new_wtcr; | ||
471 | + | ||
472 | + if (new_wtcr & NPCM7XX_WTCR_WTR) { | ||
473 | + t->wtcr &= ~NPCM7XX_WTCR_WTR; | ||
474 | + npcm7xx_watchdog_timer_reset(t); | ||
475 | + if (new_wtcr & NPCM7XX_WTCR_WTE) { | ||
476 | + npcm7xx_timer_start(&t->base_timer); | ||
477 | + } | ||
478 | + } else if ((old_wtcr ^ new_wtcr) & NPCM7XX_WTCR_WTE) { | ||
479 | + if (new_wtcr & NPCM7XX_WTCR_WTE) { | ||
480 | + npcm7xx_timer_start(&t->base_timer); | ||
481 | + } else { | ||
482 | + npcm7xx_timer_pause(&t->base_timer); | ||
483 | + } | ||
484 | + } | ||
485 | + | ||
486 | +} | ||
487 | + | ||
488 | static hwaddr npcm7xx_tcsr_index(hwaddr reg) | ||
489 | { | ||
490 | switch (reg) { | ||
491 | @@ -XXX,XX +XXX,XX @@ static uint64_t npcm7xx_timer_read(void *opaque, hwaddr offset, unsigned size) | ||
492 | break; | ||
493 | |||
494 | case NPCM7XX_TIMER_WTCR: | ||
495 | - value = s->wtcr; | ||
496 | + value = s->watchdog_timer.wtcr; | ||
497 | break; | ||
498 | |||
499 | default: | ||
500 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_write(void *opaque, hwaddr offset, | ||
501 | return; | ||
502 | |||
503 | case NPCM7XX_TIMER_WTCR: | ||
504 | - qemu_log_mask(LOG_UNIMP, "%s: WTCR write not implemented: 0x%08x\n", | ||
505 | - __func__, value); | ||
506 | + npcm7xx_timer_write_wtcr(&s->watchdog_timer, value); | ||
507 | return; | ||
508 | } | ||
509 | |||
510 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_enter_reset(Object *obj, ResetType type) | ||
511 | for (i = 0; i < NPCM7XX_TIMERS_PER_CTRL; i++) { | ||
512 | NPCM7xxTimer *t = &s->timer[i]; | ||
513 | |||
514 | - timer_del(&t->qtimer); | ||
515 | - t->expires_ns = 0; | ||
516 | - t->remaining_ns = 0; | ||
517 | + npcm7xx_timer_clear(&t->base_timer); | ||
518 | t->tcsr = 0x00000005; | ||
519 | t->ticr = 0x00000000; | ||
520 | } | ||
521 | |||
522 | s->tisr = 0x00000000; | ||
523 | - s->wtcr = 0x00000400; | ||
524 | + /* | ||
525 | + * Set WTCLK to 1(default) and reset all flags except WTRF. | ||
526 | + * WTRF is not reset during a core domain reset. | ||
527 | + */ | ||
528 | + s->watchdog_timer.wtcr = 0x00000400 | (s->watchdog_timer.wtcr & | ||
529 | + NPCM7XX_WTCR_WTRF); | ||
530 | +} | ||
531 | + | ||
532 | +static void npcm7xx_watchdog_timer_expired(void *opaque) | ||
533 | +{ | ||
534 | + NPCM7xxWatchdogTimer *t = opaque; | ||
535 | + | ||
536 | + if (t->wtcr & NPCM7XX_WTCR_WTE) { | ||
537 | + if (t->wtcr & NPCM7XX_WTCR_WTIF) { | ||
538 | + if (t->wtcr & NPCM7XX_WTCR_WTRE) { | ||
539 | + t->wtcr |= NPCM7XX_WTCR_WTRF; | ||
540 | + /* send reset signal to CLK module*/ | ||
541 | + qemu_irq_raise(t->reset_signal); | ||
542 | + } | ||
543 | + } else { | ||
544 | + t->wtcr |= NPCM7XX_WTCR_WTIF; | ||
545 | + if (t->wtcr & NPCM7XX_WTCR_WTIE) { | ||
546 | + /* send interrupt */ | ||
547 | + qemu_irq_raise(t->irq); | ||
548 | + } | ||
549 | + npcm7xx_watchdog_timer_reset_cycles(t, | ||
550 | + NPCM7XX_WATCHDOG_INTERRUPT_TO_RESET_CYCLES); | ||
551 | + npcm7xx_timer_start(&t->base_timer); | ||
552 | + } | ||
553 | + } | ||
554 | } | ||
555 | |||
556 | static void npcm7xx_timer_hold_reset(Object *obj) | ||
557 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_hold_reset(Object *obj) | ||
558 | for (i = 0; i < NPCM7XX_TIMERS_PER_CTRL; i++) { | ||
559 | qemu_irq_lower(s->timer[i].irq); | ||
560 | } | ||
561 | + qemu_irq_lower(s->watchdog_timer.irq); | ||
562 | } | ||
563 | |||
564 | static void npcm7xx_timer_realize(DeviceState *dev, Error **errp) | ||
565 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_realize(DeviceState *dev, Error **errp) | ||
566 | NPCM7xxTimerCtrlState *s = NPCM7XX_TIMER(dev); | ||
567 | SysBusDevice *sbd = &s->parent; | ||
568 | int i; | ||
569 | + NPCM7xxWatchdogTimer *w; | ||
570 | |||
571 | for (i = 0; i < NPCM7XX_TIMERS_PER_CTRL; i++) { | ||
572 | NPCM7xxTimer *t = &s->timer[i]; | ||
573 | t->ctrl = s; | ||
574 | - timer_init_ns(&t->qtimer, QEMU_CLOCK_VIRTUAL, npcm7xx_timer_expired, t); | ||
575 | + timer_init_ns(&t->base_timer.qtimer, QEMU_CLOCK_VIRTUAL, | ||
576 | + npcm7xx_timer_expired, t); | ||
577 | sysbus_init_irq(sbd, &t->irq); | ||
578 | } | ||
579 | |||
580 | + w = &s->watchdog_timer; | ||
581 | + w->ctrl = s; | ||
582 | + timer_init_ns(&w->base_timer.qtimer, QEMU_CLOCK_VIRTUAL, | ||
583 | + npcm7xx_watchdog_timer_expired, w); | ||
584 | + sysbus_init_irq(sbd, &w->irq); | ||
585 | + | ||
586 | memory_region_init_io(&s->iomem, OBJECT(s), &npcm7xx_timer_ops, s, | ||
587 | TYPE_NPCM7XX_TIMER, 4 * KiB); | ||
588 | sysbus_init_mmio(sbd, &s->iomem); | ||
589 | + qdev_init_gpio_out_named(dev, &w->reset_signal, | ||
590 | + NPCM7XX_WATCHDOG_RESET_GPIO_OUT, 1); | ||
591 | } | ||
592 | |||
593 | -static const VMStateDescription vmstate_npcm7xx_timer = { | ||
594 | - .name = "npcm7xx-timer", | ||
595 | +static const VMStateDescription vmstate_npcm7xx_base_timer = { | ||
596 | + .name = "npcm7xx-base-timer", | ||
597 | .version_id = 0, | ||
598 | .minimum_version_id = 0, | ||
599 | .fields = (VMStateField[]) { | ||
600 | - VMSTATE_TIMER(qtimer, NPCM7xxTimer), | ||
601 | - VMSTATE_INT64(expires_ns, NPCM7xxTimer), | ||
602 | - VMSTATE_INT64(remaining_ns, NPCM7xxTimer), | ||
603 | + VMSTATE_TIMER(qtimer, NPCM7xxBaseTimer), | ||
604 | + VMSTATE_INT64(expires_ns, NPCM7xxBaseTimer), | ||
605 | + VMSTATE_INT64(remaining_ns, NPCM7xxBaseTimer), | ||
606 | + VMSTATE_END_OF_LIST(), | ||
607 | + }, | ||
608 | +}; | ||
609 | + | ||
610 | +static const VMStateDescription vmstate_npcm7xx_timer = { | ||
611 | + .name = "npcm7xx-timer", | ||
612 | + .version_id = 1, | ||
613 | + .minimum_version_id = 1, | ||
614 | + .fields = (VMStateField[]) { | ||
615 | + VMSTATE_STRUCT(base_timer, NPCM7xxTimer, | ||
616 | + 0, vmstate_npcm7xx_base_timer, | ||
617 | + NPCM7xxBaseTimer), | ||
618 | VMSTATE_UINT32(tcsr, NPCM7xxTimer), | ||
619 | VMSTATE_UINT32(ticr, NPCM7xxTimer), | ||
620 | VMSTATE_END_OF_LIST(), | ||
621 | }, | ||
622 | }; | ||
623 | |||
624 | -static const VMStateDescription vmstate_npcm7xx_timer_ctrl = { | ||
625 | - .name = "npcm7xx-timer-ctrl", | ||
626 | +static const VMStateDescription vmstate_npcm7xx_watchdog_timer = { | ||
627 | + .name = "npcm7xx-watchdog-timer", | ||
628 | .version_id = 0, | ||
629 | .minimum_version_id = 0, | ||
630 | + .fields = (VMStateField[]) { | ||
631 | + VMSTATE_STRUCT(base_timer, NPCM7xxWatchdogTimer, | ||
632 | + 0, vmstate_npcm7xx_base_timer, | ||
633 | + NPCM7xxBaseTimer), | ||
634 | + VMSTATE_UINT32(wtcr, NPCM7xxWatchdogTimer), | ||
635 | + VMSTATE_END_OF_LIST(), | ||
636 | + }, | ||
637 | +}; | ||
638 | + | ||
639 | +static const VMStateDescription vmstate_npcm7xx_timer_ctrl = { | ||
640 | + .name = "npcm7xx-timer-ctrl", | ||
641 | + .version_id = 1, | ||
642 | + .minimum_version_id = 1, | ||
643 | .fields = (VMStateField[]) { | ||
644 | VMSTATE_UINT32(tisr, NPCM7xxTimerCtrlState), | ||
645 | - VMSTATE_UINT32(wtcr, NPCM7xxTimerCtrlState), | ||
646 | VMSTATE_STRUCT_ARRAY(timer, NPCM7xxTimerCtrlState, | ||
647 | NPCM7XX_TIMERS_PER_CTRL, 0, vmstate_npcm7xx_timer, | ||
648 | NPCM7xxTimer), | ||
649 | + VMSTATE_STRUCT(watchdog_timer, NPCM7xxTimerCtrlState, | ||
650 | + 0, vmstate_npcm7xx_watchdog_timer, | ||
651 | + NPCM7xxWatchdogTimer), | ||
652 | VMSTATE_END_OF_LIST(), | ||
653 | }, | ||
654 | }; | ||
655 | diff --git a/tests/qtest/npcm7xx_watchdog_timer-test.c b/tests/qtest/npcm7xx_watchdog_timer-test.c | ||
656 | new file mode 100644 | ||
657 | index XXXXXXX..XXXXXXX | ||
658 | --- /dev/null | ||
659 | +++ b/tests/qtest/npcm7xx_watchdog_timer-test.c | ||
660 | @@ -XXX,XX +XXX,XX @@ | ||
661 | +/* | ||
662 | + * QTests for Nuvoton NPCM7xx Timer Watchdog Modules. | ||
663 | + * | ||
664 | + * Copyright 2020 Google LLC | ||
665 | + * | ||
666 | + * This program is free software; you can redistribute it and/or modify it | ||
667 | + * under the terms of the GNU General Public License as published by the | ||
668 | + * Free Software Foundation; either version 2 of the License, or | ||
669 | + * (at your option) any later version. | ||
670 | + * | ||
671 | + * This program is distributed in the hope that it will be useful, but WITHOUT | ||
672 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
673 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
674 | + * for more details. | ||
85 | + */ | 675 | + */ |
86 | +static void disas_crypto_four_reg(DisasContext *s, uint32_t insn) | 676 | + |
87 | +{ | 677 | +#include "qemu/osdep.h" |
88 | + int op0 = extract32(insn, 21, 2); | 678 | +#include "qemu/timer.h" |
89 | + int rm = extract32(insn, 16, 5); | 679 | + |
90 | + int ra = extract32(insn, 10, 5); | 680 | +#include "libqos/libqtest.h" |
91 | + int rn = extract32(insn, 5, 5); | 681 | +#include "qapi/qmp/qdict.h" |
92 | + int rd = extract32(insn, 0, 5); | 682 | + |
93 | + int feature; | 683 | +#define WTCR_OFFSET 0x1c |
94 | + | 684 | +#define REF_HZ (25000000) |
95 | + switch (op0) { | 685 | + |
96 | + case 0: /* EOR3 */ | 686 | +/* WTCR bit fields */ |
97 | + case 1: /* BCAX */ | 687 | +#define WTCLK(rv) ((rv) << 10) |
98 | + feature = ARM_FEATURE_V8_SHA3; | 688 | +#define WTE BIT(7) |
99 | + break; | 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; | ||
100 | + default: | 747 | + default: |
101 | + unallocated_encoding(s); | ||
102 | + return; | ||
103 | + } | ||
104 | + | ||
105 | + if (!arm_dc_feature(s, feature)) { | ||
106 | + unallocated_encoding(s); | ||
107 | + return; | ||
108 | + } | ||
109 | + | ||
110 | + if (!fp_access_check(s)) { | ||
111 | + return; | ||
112 | + } | ||
113 | + | ||
114 | + if (op0 < 2) { | ||
115 | + TCGv_i64 tcg_op1, tcg_op2, tcg_op3, tcg_res[2]; | ||
116 | + int pass; | ||
117 | + | ||
118 | + tcg_op1 = tcg_temp_new_i64(); | ||
119 | + tcg_op2 = tcg_temp_new_i64(); | ||
120 | + tcg_op3 = tcg_temp_new_i64(); | ||
121 | + tcg_res[0] = tcg_temp_new_i64(); | ||
122 | + tcg_res[1] = tcg_temp_new_i64(); | ||
123 | + | ||
124 | + for (pass = 0; pass < 2; pass++) { | ||
125 | + read_vec_element(s, tcg_op1, rn, pass, MO_64); | ||
126 | + read_vec_element(s, tcg_op2, rm, pass, MO_64); | ||
127 | + read_vec_element(s, tcg_op3, ra, pass, MO_64); | ||
128 | + | ||
129 | + if (op0 == 0) { | ||
130 | + /* EOR3 */ | ||
131 | + tcg_gen_xor_i64(tcg_res[pass], tcg_op2, tcg_op3); | ||
132 | + } else { | ||
133 | + /* BCAX */ | ||
134 | + tcg_gen_andc_i64(tcg_res[pass], tcg_op2, tcg_op3); | ||
135 | + } | ||
136 | + tcg_gen_xor_i64(tcg_res[pass], tcg_res[pass], tcg_op1); | ||
137 | + } | ||
138 | + write_vec_element(s, tcg_res[0], rd, 0, MO_64); | ||
139 | + write_vec_element(s, tcg_res[1], rd, 1, MO_64); | ||
140 | + | ||
141 | + tcg_temp_free_i64(tcg_op1); | ||
142 | + tcg_temp_free_i64(tcg_op2); | ||
143 | + tcg_temp_free_i64(tcg_op3); | ||
144 | + tcg_temp_free_i64(tcg_res[0]); | ||
145 | + tcg_temp_free_i64(tcg_res[1]); | ||
146 | + } else { | ||
147 | + g_assert_not_reached(); | 748 | + g_assert_not_reached(); |
148 | + } | 749 | + } |
149 | +} | 750 | +} |
150 | + | 751 | + |
151 | +/* Crypto XAR | 752 | +static QDict *get_watchdog_action(QTestState *qts) |
152 | + * 31 21 20 16 15 10 9 5 4 0 | 753 | +{ |
153 | + * +-----------------------+------+--------+------+------+ | 754 | + QDict *ev = qtest_qmp_eventwait_ref(qts, "WATCHDOG"); |
154 | + * | 1 1 0 0 1 1 1 0 1 0 0 | Rm | imm6 | Rn | Rd | | 755 | + QDict *data; |
155 | + * +-----------------------+------+--------+------+------+ | 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. | ||
156 | + */ | 862 | + */ |
157 | +static void disas_crypto_xar(DisasContext *s, uint32_t insn) | 863 | +static void test_enabling_flags(gconstpointer watchdog) |
158 | +{ | 864 | +{ |
159 | + int rm = extract32(insn, 16, 5); | 865 | + const Watchdog *wd = watchdog; |
160 | + int imm6 = extract32(insn, 10, 6); | 866 | + QTestState *qts; |
161 | + int rn = extract32(insn, 5, 5); | 867 | + |
162 | + int rd = extract32(insn, 0, 5); | 868 | + /* Neither WTIE or WTRE is set, no interrupt or reset should happen */ |
163 | + TCGv_i64 tcg_op1, tcg_op2, tcg_res[2]; | 869 | + qts = qtest_init("-machine quanta-gsj"); |
164 | + int pass; | 870 | + qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic"); |
165 | + | 871 | + watchdog_write_wtcr(qts, wd, WTCLK(0) | WTE | WTIF | WTRF | WTR); |
166 | + if (!arm_dc_feature(s, ARM_FEATURE_V8_SHA3)) { | 872 | + qtest_clock_step(qts, watchdog_interrupt_steps(qts, wd)); |
167 | + unallocated_encoding(s); | 873 | + g_assert_true(watchdog_read_wtcr(qts, wd) & WTIF); |
168 | + return; | 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); | ||
169 | + } | 976 | + } |
170 | + | 977 | + |
171 | + if (!fp_access_check(s)) { | 978 | + return g_test_run(); |
172 | + return; | 979 | +} |
173 | + } | 980 | diff --git a/MAINTAINERS b/MAINTAINERS |
174 | + | 981 | index XXXXXXX..XXXXXXX 100644 |
175 | + tcg_op1 = tcg_temp_new_i64(); | 982 | --- a/MAINTAINERS |
176 | + tcg_op2 = tcg_temp_new_i64(); | 983 | +++ b/MAINTAINERS |
177 | + tcg_res[0] = tcg_temp_new_i64(); | 984 | @@ -XXX,XX +XXX,XX @@ L: qemu-arm@nongnu.org |
178 | + tcg_res[1] = tcg_temp_new_i64(); | 985 | S: Supported |
179 | + | 986 | F: hw/*/npcm7xx* |
180 | + for (pass = 0; pass < 2; pass++) { | 987 | F: include/hw/*/npcm7xx* |
181 | + read_vec_element(s, tcg_op1, rn, pass, MO_64); | 988 | +F: tests/qtest/npcm7xx* |
182 | + read_vec_element(s, tcg_op2, rm, pass, MO_64); | 989 | F: pc-bios/npcm7xx_bootrom.bin |
183 | + | 990 | F: roms/vbootrom |
184 | + tcg_gen_xor_i64(tcg_res[pass], tcg_op1, tcg_op2); | 991 | |
185 | + tcg_gen_rotri_i64(tcg_res[pass], tcg_res[pass], imm6); | 992 | diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build |
186 | + } | 993 | index XXXXXXX..XXXXXXX 100644 |
187 | + write_vec_element(s, tcg_res[0], rd, 0, MO_64); | 994 | --- a/tests/qtest/meson.build |
188 | + write_vec_element(s, tcg_res[1], rd, 1, MO_64); | 995 | +++ b/tests/qtest/meson.build |
189 | + | 996 | @@ -XXX,XX +XXX,XX @@ qtests_sparc64 = \ |
190 | + tcg_temp_free_i64(tcg_op1); | 997 | (config_all_devices.has_key('CONFIG_ISA_TESTDEV') ? ['endianness-test'] : []) + \ |
191 | + tcg_temp_free_i64(tcg_op2); | 998 | ['prom-env-test', 'boot-serial-test'] |
192 | + tcg_temp_free_i64(tcg_res[0]); | 999 | |
193 | + tcg_temp_free_i64(tcg_res[1]); | 1000 | -qtests_npcm7xx = ['npcm7xx_timer-test'] |
194 | +} | 1001 | +qtests_npcm7xx = ['npcm7xx_timer-test', 'npcm7xx_watchdog_timer-test'] |
195 | + | 1002 | qtests_arm = \ |
196 | /* C3.6 Data processing - SIMD, inc Crypto | 1003 | (config_all_devices.has_key('CONFIG_PFLASH_CFI02') ? ['pflash-cfi02-test'] : []) + \ |
197 | * | 1004 | (config_all_devices.has_key('CONFIG_NPCM7XX') ? qtests_npcm7xx : []) + \ |
198 | * As the decode gets a little complex we are using a table based | ||
199 | @@ -XXX,XX +XXX,XX @@ static const AArch64DecodeTable data_proc_simd[] = { | ||
200 | { 0x5e280800, 0xff3e0c00, disas_crypto_two_reg_sha }, | ||
201 | { 0xce608000, 0xffe0b000, disas_crypto_three_reg_sha512 }, | ||
202 | { 0xcec08000, 0xfffff000, disas_crypto_two_reg_sha512 }, | ||
203 | + { 0xce000000, 0xff808000, disas_crypto_four_reg }, | ||
204 | + { 0xce800000, 0xffe00000, disas_crypto_xar }, | ||
205 | { 0x00000000, 0x00000000, NULL } | ||
206 | }; | ||
207 | |||
208 | -- | 1005 | -- |
209 | 2.16.1 | 1006 | 2.20.1 |
210 | 1007 | ||
211 | 1008 | diff view generated by jsdifflib |
1 | From: Andrey Smirnov <andrew.smirnov@gmail.com> | 1 | From: Havard Skinnemoen <hskinnemoen@google.com> |
---|---|---|---|
2 | 2 | ||
3 | Add minimal code needed to allow upstream Linux guest to boot. | 3 | The RNG module returns a byte of randomness when the Data Valid bit is |
4 | set. | ||
4 | 5 | ||
5 | Cc: Peter Maydell <peter.maydell@linaro.org> | 6 | This implementation ignores the prescaler setting, and loads a new value |
6 | Cc: Jason Wang <jasowang@redhat.com> | 7 | into RNGD every time RNGCS is read while the RNG is enabled and random |
7 | Cc: Philippe Mathieu-Daudé <f4bug@amsat.org> | 8 | data is available. |
8 | Cc: Marcel Apfelbaum <marcel.apfelbaum@zoho.com> | 9 | |
9 | Cc: Michael S. Tsirkin <mst@redhat.com> | 10 | A qtest featuring some simple randomness tests is included. |
10 | Cc: qemu-devel@nongnu.org | 11 | |
11 | Cc: qemu-arm@nongnu.org | 12 | Reviewed-by: Tyrone Ting <kfting@nuvoton.com> |
12 | Cc: yurovsky@gmail.com | ||
13 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
14 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 13 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
15 | Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> | 14 | Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com> |
16 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 15 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
17 | --- | 16 | --- |
18 | hw/misc/Makefile.objs | 1 + | 17 | docs/system/arm/nuvoton.rst | 2 +- |
19 | include/hw/misc/imx7_gpr.h | 28 ++++++++++ | 18 | include/hw/arm/npcm7xx.h | 2 + |
20 | hw/misc/imx7_gpr.c | 124 +++++++++++++++++++++++++++++++++++++++++++++ | 19 | include/hw/misc/npcm7xx_rng.h | 34 ++++ |
21 | hw/misc/trace-events | 4 ++ | 20 | hw/arm/npcm7xx.c | 7 +- |
22 | 4 files changed, 157 insertions(+) | 21 | hw/misc/npcm7xx_rng.c | 180 +++++++++++++++++++++ |
23 | create mode 100644 include/hw/misc/imx7_gpr.h | 22 | tests/qtest/npcm7xx_rng-test.c | 278 +++++++++++++++++++++++++++++++++ |
24 | create mode 100644 hw/misc/imx7_gpr.c | 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 | ||
25 | 30 | ||
26 | diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs | 31 | diff --git a/docs/system/arm/nuvoton.rst b/docs/system/arm/nuvoton.rst |
27 | index XXXXXXX..XXXXXXX 100644 | 32 | index XXXXXXX..XXXXXXX 100644 |
28 | --- a/hw/misc/Makefile.objs | 33 | --- a/docs/system/arm/nuvoton.rst |
29 | +++ b/hw/misc/Makefile.objs | 34 | +++ b/docs/system/arm/nuvoton.rst |
30 | @@ -XXX,XX +XXX,XX @@ obj-$(CONFIG_IMX) += imx6_src.o | 35 | @@ -XXX,XX +XXX,XX @@ Supported devices |
31 | obj-$(CONFIG_IMX) += imx7_ccm.o | 36 | * DDR4 memory controller (dummy interface indicating memory training is done) |
32 | obj-$(CONFIG_IMX) += imx2_wdt.o | 37 | * OTP controllers (no protection features) |
33 | obj-$(CONFIG_IMX) += imx7_snvs.o | 38 | * Flash Interface Unit (FIU; no protection features) |
34 | +obj-$(CONFIG_IMX) += imx7_gpr.o | 39 | + * Random Number Generator (RNG) |
35 | obj-$(CONFIG_MILKYMIST) += milkymist-hpdmc.o | 40 | |
36 | obj-$(CONFIG_MILKYMIST) += milkymist-pfpu.o | 41 | Missing devices |
37 | obj-$(CONFIG_MAINSTONE) += mst_fpga.o | 42 | --------------- |
38 | diff --git a/include/hw/misc/imx7_gpr.h b/include/hw/misc/imx7_gpr.h | 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 | ||
39 | new file mode 100644 | 72 | new file mode 100644 |
40 | index XXXXXXX..XXXXXXX | 73 | index XXXXXXX..XXXXXXX |
41 | --- /dev/null | 74 | --- /dev/null |
42 | +++ b/include/hw/misc/imx7_gpr.h | 75 | +++ b/include/hw/misc/npcm7xx_rng.h |
43 | @@ -XXX,XX +XXX,XX @@ | 76 | @@ -XXX,XX +XXX,XX @@ |
44 | +/* | 77 | +/* |
45 | + * Copyright (c) 2017, Impinj, Inc. | 78 | + * Nuvoton NPCM7xx Random Number Generator. |
46 | + * | 79 | + * |
47 | + * i.MX7 GPR IP block emulation code | 80 | + * Copyright 2020 Google LLC |
48 | + * | 81 | + * |
49 | + * Author: Andrey Smirnov <andrew.smirnov@gmail.com> | 82 | + * This program is free software; you can redistribute it and/or modify it |
50 | + * | 83 | + * under the terms of the GNU General Public License as published by the |
51 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | 84 | + * Free Software Foundation; either version 2 of the License, or |
52 | + * See the COPYING file in the top-level directory. | 85 | + * (at your option) any later version. |
53 | + */ | 86 | + * |
54 | + | 87 | + * This program is distributed in the hope that it will be useful, but WITHOUT |
55 | +#ifndef IMX7_GPR_H | 88 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
56 | +#define IMX7_GPR_H | 89 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
57 | + | 90 | + * for more details. |
58 | +#include "qemu/bitops.h" | 91 | + */ |
92 | +#ifndef NPCM7XX_RNG_H | ||
93 | +#define NPCM7XX_RNG_H | ||
94 | + | ||
59 | +#include "hw/sysbus.h" | 95 | +#include "hw/sysbus.h" |
60 | + | 96 | + |
61 | +#define TYPE_IMX7_GPR "imx7.gpr" | 97 | +typedef struct NPCM7xxRNGState { |
62 | +#define IMX7_GPR(obj) OBJECT_CHECK(IMX7GPRState, (obj), TYPE_IMX7_GPR) | 98 | + SysBusDevice parent; |
63 | + | 99 | + |
64 | +typedef struct IMX7GPRState { | 100 | + MemoryRegion iomem; |
65 | + /* <private> */ | 101 | + |
66 | + SysBusDevice parent_obj; | 102 | + uint8_t rngcs; |
67 | + | 103 | + uint8_t rngd; |
68 | + MemoryRegion mmio; | 104 | + uint8_t rngmode; |
69 | +} IMX7GPRState; | 105 | +} NPCM7xxRNGState; |
70 | + | 106 | + |
71 | +#endif /* IMX7_GPR_H */ | 107 | +#define TYPE_NPCM7XX_RNG "npcm7xx-rng" |
72 | diff --git a/hw/misc/imx7_gpr.c b/hw/misc/imx7_gpr.c | 108 | +#define NPCM7XX_RNG(obj) OBJECT_CHECK(NPCM7xxRNGState, (obj), TYPE_NPCM7XX_RNG) |
109 | + | ||
110 | +#endif /* NPCM7XX_RNG_H */ | ||
111 | diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c | ||
112 | index XXXXXXX..XXXXXXX 100644 | ||
113 | --- a/hw/arm/npcm7xx.c | ||
114 | +++ b/hw/arm/npcm7xx.c | ||
115 | @@ -XXX,XX +XXX,XX @@ | ||
116 | #define NPCM7XX_GCR_BA (0xf0800000) | ||
117 | #define NPCM7XX_CLK_BA (0xf0801000) | ||
118 | #define NPCM7XX_MC_BA (0xf0824000) | ||
119 | +#define NPCM7XX_RNG_BA (0xf000b000) | ||
120 | |||
121 | /* Internal AHB SRAM */ | ||
122 | #define NPCM7XX_RAM3_BA (0xc0008000) | ||
123 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_init(Object *obj) | ||
124 | object_initialize_child(obj, "otp2", &s->fuse_array, | ||
125 | TYPE_NPCM7XX_FUSE_ARRAY); | ||
126 | object_initialize_child(obj, "mc", &s->mc, TYPE_NPCM7XX_MC); | ||
127 | + object_initialize_child(obj, "rng", &s->rng, TYPE_NPCM7XX_RNG); | ||
128 | |||
129 | for (i = 0; i < ARRAY_SIZE(s->tim); i++) { | ||
130 | object_initialize_child(obj, "tim[*]", &s->tim[i], TYPE_NPCM7XX_TIMER); | ||
131 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp) | ||
132 | serial_hd(i), DEVICE_LITTLE_ENDIAN); | ||
133 | } | ||
134 | |||
135 | + /* Random Number Generator. Cannot fail. */ | ||
136 | + sysbus_realize(SYS_BUS_DEVICE(&s->rng), &error_abort); | ||
137 | + sysbus_mmio_map(SYS_BUS_DEVICE(&s->rng), 0, NPCM7XX_RNG_BA); | ||
138 | + | ||
139 | /* | ||
140 | * Flash Interface Unit (FIU). Can fail if incorrect number of chip selects | ||
141 | * specified, but this is a programming error. | ||
142 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp) | ||
143 | create_unimplemented_device("npcm7xx.vdmx", 0xe0800000, 4 * KiB); | ||
144 | create_unimplemented_device("npcm7xx.pcierc", 0xe1000000, 64 * KiB); | ||
145 | create_unimplemented_device("npcm7xx.kcs", 0xf0007000, 4 * KiB); | ||
146 | - create_unimplemented_device("npcm7xx.rng", 0xf000b000, 4 * KiB); | ||
147 | create_unimplemented_device("npcm7xx.adc", 0xf000c000, 4 * KiB); | ||
148 | create_unimplemented_device("npcm7xx.gfxi", 0xf000e000, 4 * KiB); | ||
149 | create_unimplemented_device("npcm7xx.gpio[0]", 0xf0010000, 4 * KiB); | ||
150 | diff --git a/hw/misc/npcm7xx_rng.c b/hw/misc/npcm7xx_rng.c | ||
73 | new file mode 100644 | 151 | new file mode 100644 |
74 | index XXXXXXX..XXXXXXX | 152 | index XXXXXXX..XXXXXXX |
75 | --- /dev/null | 153 | --- /dev/null |
76 | +++ b/hw/misc/imx7_gpr.c | 154 | +++ b/hw/misc/npcm7xx_rng.c |
77 | @@ -XXX,XX +XXX,XX @@ | 155 | @@ -XXX,XX +XXX,XX @@ |
78 | +/* | 156 | +/* |
79 | + * Copyright (c) 2018, Impinj, Inc. | 157 | + * Nuvoton NPCM7xx Random Number Generator. |
80 | + * | 158 | + * |
81 | + * i.MX7 GPR IP block emulation code | 159 | + * Copyright 2020 Google LLC |
82 | + * | 160 | + * |
83 | + * Author: Andrey Smirnov <andrew.smirnov@gmail.com> | 161 | + * This program is free software; you can redistribute it and/or modify it |
84 | + * | 162 | + * under the terms of the GNU General Public License as published by the |
85 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | 163 | + * Free Software Foundation; either version 2 of the License, or |
86 | + * See the COPYING file in the top-level directory. | 164 | + * (at your option) any later version. |
87 | + * | 165 | + * |
88 | + * Bare minimum emulation code needed to support being able to shut | 166 | + * This program is distributed in the hope that it will be useful, but WITHOUT |
89 | + * down linux guest gracefully. | 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. | ||
90 | + */ | 170 | + */ |
91 | + | 171 | + |
92 | +#include "qemu/osdep.h" | 172 | +#include "qemu/osdep.h" |
93 | +#include "hw/misc/imx7_gpr.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" | ||
94 | +#include "qemu/log.h" | 178 | +#include "qemu/log.h" |
95 | +#include "sysemu/sysemu.h" | 179 | +#include "qemu/module.h" |
180 | +#include "qemu/units.h" | ||
96 | + | 181 | + |
97 | +#include "trace.h" | 182 | +#include "trace.h" |
98 | + | 183 | + |
99 | +enum IMX7GPRRegisters { | 184 | +#define NPCM7XX_RNG_REGS_SIZE (4 * KiB) |
100 | + IOMUXC_GPR0 = 0x00, | 185 | + |
101 | + IOMUXC_GPR1 = 0x04, | 186 | +#define NPCM7XX_RNGCS (0x00) |
102 | + IOMUXC_GPR2 = 0x08, | 187 | +#define NPCM7XX_RNGCS_CLKP(rv) extract32(rv, 2, 4) |
103 | + IOMUXC_GPR3 = 0x0c, | 188 | +#define NPCM7XX_RNGCS_DVALID BIT(1) |
104 | + IOMUXC_GPR4 = 0x10, | 189 | +#define NPCM7XX_RNGCS_RNGE BIT(0) |
105 | + IOMUXC_GPR5 = 0x14, | 190 | + |
106 | + IOMUXC_GPR6 = 0x18, | 191 | +#define NPCM7XX_RNGD (0x04) |
107 | + IOMUXC_GPR7 = 0x1c, | 192 | +#define NPCM7XX_RNGMODE (0x08) |
108 | + IOMUXC_GPR8 = 0x20, | 193 | +#define NPCM7XX_RNGMODE_NORMAL (0x02) |
109 | + IOMUXC_GPR9 = 0x24, | 194 | + |
110 | + IOMUXC_GPR10 = 0x28, | 195 | +static bool npcm7xx_rng_is_enabled(NPCM7xxRNGState *s) |
111 | + IOMUXC_GPR11 = 0x2c, | 196 | +{ |
112 | + IOMUXC_GPR12 = 0x30, | 197 | + return (s->rngcs & NPCM7XX_RNGCS_RNGE) && |
113 | + IOMUXC_GPR13 = 0x34, | 198 | + (s->rngmode == NPCM7XX_RNGMODE_NORMAL); |
114 | + IOMUXC_GPR14 = 0x38, | 199 | +} |
115 | + IOMUXC_GPR15 = 0x3c, | 200 | + |
116 | + IOMUXC_GPR16 = 0x40, | 201 | +static uint64_t npcm7xx_rng_read(void *opaque, hwaddr offset, unsigned size) |
117 | + IOMUXC_GPR17 = 0x44, | 202 | +{ |
118 | + IOMUXC_GPR18 = 0x48, | 203 | + NPCM7xxRNGState *s = opaque; |
119 | + IOMUXC_GPR19 = 0x4c, | 204 | + uint64_t value = 0; |
120 | + IOMUXC_GPR20 = 0x50, | 205 | + |
121 | + IOMUXC_GPR21 = 0x54, | 206 | + switch (offset) { |
122 | + IOMUXC_GPR22 = 0x58, | 207 | + case NPCM7XX_RNGCS: |
123 | +}; | ||
124 | + | ||
125 | +#define IMX7D_GPR1_IRQ_MASK BIT(12) | ||
126 | +#define IMX7D_GPR1_ENET1_TX_CLK_SEL_MASK BIT(13) | ||
127 | +#define IMX7D_GPR1_ENET2_TX_CLK_SEL_MASK BIT(14) | ||
128 | +#define IMX7D_GPR1_ENET_TX_CLK_SEL_MASK (0x3 << 13) | ||
129 | +#define IMX7D_GPR1_ENET1_CLK_DIR_MASK BIT(17) | ||
130 | +#define IMX7D_GPR1_ENET2_CLK_DIR_MASK BIT(18) | ||
131 | +#define IMX7D_GPR1_ENET_CLK_DIR_MASK (0x3 << 17) | ||
132 | + | ||
133 | +#define IMX7D_GPR5_CSI_MUX_CONTROL_MIPI BIT(4) | ||
134 | +#define IMX7D_GPR12_PCIE_PHY_REFCLK_SEL BIT(5) | ||
135 | +#define IMX7D_GPR22_PCIE_PHY_PLL_LOCKED BIT(31) | ||
136 | + | ||
137 | + | ||
138 | +static uint64_t imx7_gpr_read(void *opaque, hwaddr offset, unsigned size) | ||
139 | +{ | ||
140 | + trace_imx7_gpr_read(offset); | ||
141 | + | ||
142 | + if (offset == IOMUXC_GPR22) { | ||
143 | + return IMX7D_GPR22_PCIE_PHY_PLL_LOCKED; | ||
144 | + } | ||
145 | + | ||
146 | + return 0; | ||
147 | +} | ||
148 | + | ||
149 | +static void imx7_gpr_write(void *opaque, hwaddr offset, | ||
150 | + uint64_t v, unsigned size) | ||
151 | +{ | ||
152 | + trace_imx7_gpr_write(offset, v); | ||
153 | +} | ||
154 | + | ||
155 | +static const struct MemoryRegionOps imx7_gpr_ops = { | ||
156 | + .read = imx7_gpr_read, | ||
157 | + .write = imx7_gpr_write, | ||
158 | + .endianness = DEVICE_NATIVE_ENDIAN, | ||
159 | + .impl = { | ||
160 | + /* | 208 | + /* |
161 | + * Our device would not work correctly if the guest was doing | 209 | + * If the RNG is enabled, but we don't have any valid random data, try |
162 | + * unaligned access. This might not be a limitation on the | 210 | + * obtaining some and update the DVALID bit accordingly. |
163 | + * real device but in practice there is no reason for a guest | ||
164 | + * to access this device unaligned. | ||
165 | + */ | 211 | + */ |
166 | + .min_access_size = 4, | 212 | + if (!npcm7xx_rng_is_enabled(s)) { |
213 | + s->rngcs &= ~NPCM7XX_RNGCS_DVALID; | ||
214 | + } else if (!(s->rngcs & NPCM7XX_RNGCS_DVALID)) { | ||
215 | + uint8_t byte = 0; | ||
216 | + | ||
217 | + if (qemu_guest_getrandom(&byte, sizeof(byte), NULL) == 0) { | ||
218 | + s->rngd = byte; | ||
219 | + s->rngcs |= NPCM7XX_RNGCS_DVALID; | ||
220 | + } | ||
221 | + } | ||
222 | + value = s->rngcs; | ||
223 | + break; | ||
224 | + case NPCM7XX_RNGD: | ||
225 | + if (npcm7xx_rng_is_enabled(s) && s->rngcs & NPCM7XX_RNGCS_DVALID) { | ||
226 | + s->rngcs &= ~NPCM7XX_RNGCS_DVALID; | ||
227 | + value = s->rngd; | ||
228 | + s->rngd = 0; | ||
229 | + } | ||
230 | + break; | ||
231 | + case NPCM7XX_RNGMODE: | ||
232 | + value = s->rngmode; | ||
233 | + break; | ||
234 | + | ||
235 | + default: | ||
236 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
237 | + "%s: read from invalid offset 0x%" HWADDR_PRIx "\n", | ||
238 | + DEVICE(s)->canonical_path, offset); | ||
239 | + break; | ||
240 | + } | ||
241 | + | ||
242 | + trace_npcm7xx_rng_read(offset, value, size); | ||
243 | + | ||
244 | + return value; | ||
245 | +} | ||
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, | ||
167 | + .max_access_size = 4, | 281 | + .max_access_size = 4, |
168 | + .unaligned = false, | 282 | + .unaligned = false, |
169 | + }, | 283 | + }, |
170 | +}; | 284 | +}; |
171 | + | 285 | + |
172 | +static void imx7_gpr_init(Object *obj) | 286 | +static void npcm7xx_rng_enter_reset(Object *obj, ResetType type) |
173 | +{ | 287 | +{ |
174 | + SysBusDevice *sd = SYS_BUS_DEVICE(obj); | 288 | + NPCM7xxRNGState *s = NPCM7XX_RNG(obj); |
175 | + IMX7GPRState *s = IMX7_GPR(obj); | 289 | + |
176 | + | 290 | + s->rngcs = 0; |
177 | + memory_region_init_io(&s->mmio, obj, &imx7_gpr_ops, s, | 291 | + s->rngd = 0; |
178 | + TYPE_IMX7_GPR, 64 * 1024); | 292 | + s->rngmode = 0; |
179 | + sysbus_init_mmio(sd, &s->mmio); | 293 | +} |
180 | +} | 294 | + |
181 | + | 295 | +static void npcm7xx_rng_init(Object *obj) |
182 | +static void imx7_gpr_class_init(ObjectClass *klass, void *data) | 296 | +{ |
183 | +{ | 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); | ||
184 | + DeviceClass *dc = DEVICE_CLASS(klass); | 319 | + DeviceClass *dc = DEVICE_CLASS(klass); |
185 | + | 320 | + |
186 | + dc->desc = "i.MX7 General Purpose Registers Module"; | 321 | + dc->desc = "NPCM7xx Random Number Generator"; |
187 | +} | 322 | + dc->vmsd = &vmstate_npcm7xx_rng; |
188 | + | 323 | + rc->phases.enter = npcm7xx_rng_enter_reset; |
189 | +static const TypeInfo imx7_gpr_info = { | 324 | +} |
190 | + .name = TYPE_IMX7_GPR, | 325 | + |
191 | + .parent = TYPE_SYS_BUS_DEVICE, | 326 | +static const TypeInfo npcm7xx_rng_types[] = { |
192 | + .instance_size = sizeof(IMX7GPRState), | 327 | + { |
193 | + .instance_init = imx7_gpr_init, | 328 | + .name = TYPE_NPCM7XX_RNG, |
194 | + .class_init = imx7_gpr_class_init, | 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 | + }, | ||
195 | +}; | 334 | +}; |
196 | + | 335 | +DEFINE_TYPES(npcm7xx_rng_types); |
197 | +static void imx7_gpr_register_type(void) | 336 | diff --git a/tests/qtest/npcm7xx_rng-test.c b/tests/qtest/npcm7xx_rng-test.c |
198 | +{ | 337 | new file mode 100644 |
199 | + type_register_static(&imx7_gpr_info); | 338 | index XXXXXXX..XXXXXXX |
200 | +} | 339 | --- /dev/null |
201 | +type_init(imx7_gpr_register_type) | 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', | ||
202 | diff --git a/hw/misc/trace-events b/hw/misc/trace-events | 632 | diff --git a/hw/misc/trace-events b/hw/misc/trace-events |
203 | index XXXXXXX..XXXXXXX 100644 | 633 | index XXXXXXX..XXXXXXX 100644 |
204 | --- a/hw/misc/trace-events | 634 | --- a/hw/misc/trace-events |
205 | +++ b/hw/misc/trace-events | 635 | +++ b/hw/misc/trace-events |
206 | @@ -XXX,XX +XXX,XX @@ mps2_scc_cfg_read(unsigned function, unsigned device, uint32_t value) "MPS2 SCC | 636 | @@ -XXX,XX +XXX,XX @@ npcm7xx_clk_write(uint64_t offset, uint32_t value) "offset: 0x%04" PRIx64 " valu |
207 | msf2_sysreg_write(uint64_t offset, uint32_t val, uint32_t prev) "msf2-sysreg write: addr 0x%08" HWADDR_PRIx " data 0x%" PRIx32 " prev 0x%" PRIx32 | 637 | npcm7xx_gcr_read(uint64_t offset, uint32_t value) " offset: 0x%04" PRIx64 " value: 0x%08" PRIx32 |
208 | msf2_sysreg_read(uint64_t offset, uint32_t val) "msf2-sysreg read: addr 0x%08" HWADDR_PRIx " data 0x%08" PRIx32 | 638 | npcm7xx_gcr_write(uint64_t offset, uint32_t value) "offset: 0x%04" PRIx64 " value: 0x%08" PRIx32 |
209 | msf2_sysreg_write_pll_status(void) "Invalid write to read only PLL status register" | 639 | |
210 | + | 640 | +# npcm7xx_rng.c |
211 | +#hw/misc/imx7_gpr.c | 641 | +npcm7xx_rng_read(uint64_t offset, uint64_t value, unsigned size) "offset: 0x%04" PRIx64 " value: 0x%02" PRIx64 " size: %u" |
212 | +imx7_gpr_read(uint64_t offset) "addr 0x%08" HWADDR_PRIx | 642 | +npcm7xx_rng_write(uint64_t offset, uint64_t value, unsigned size) "offset: 0x%04" PRIx64 " value: 0x%02" PRIx64 " size: %u" |
213 | +imx7_gpr_write(uint64_t offset, uint64_t value) "addr 0x%08" HWADDR_PRIx "value 0x%08" HWADDR_PRIx | 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 : []) + \ | ||
214 | -- | 663 | -- |
215 | 2.16.1 | 664 | 2.20.1 |
216 | 665 | ||
217 | 666 | diff view generated by jsdifflib |
1 | From: Andrey Smirnov <andrew.smirnov@gmail.com> | 1 | From: Havard Skinnemoen <hskinnemoen@google.com> |
---|---|---|---|
2 | 2 | ||
3 | Convert i.MX6 to use TYPE_IMX_USDHC since that's what real HW comes | 3 | The NPCM730 and NPCM750 chips have a single USB host port shared between |
4 | with. | 4 | a USB 2.0 EHCI host controller and a USB 1.1 OHCI host controller. This |
5 | adds support for both of them. | ||
5 | 6 | ||
6 | Cc: Peter Maydell <peter.maydell@linaro.org> | 7 | Testing notes: |
7 | Cc: Jason Wang <jasowang@redhat.com> | 8 | * With -device usb-kbd, qemu will automatically insert a full-speed |
8 | Cc: Philippe Mathieu-Daudé <f4bug@amsat.org> | 9 | hub, and the keyboard becomes controlled by the OHCI controller. |
9 | Cc: Marcel Apfelbaum <marcel.apfelbaum@zoho.com> | 10 | * With -device usb-kbd,bus=usb-bus.0,port=1, the keyboard is directly |
10 | Cc: Michael S. Tsirkin <mst@redhat.com> | 11 | attached to the port without any hubs, and the device becomes |
11 | Cc: qemu-devel@nongnu.org | 12 | controlled by the EHCI controller since it's high speed capable. |
12 | Cc: qemu-arm@nongnu.org | 13 | * With -device usb-kbd,bus=usb-bus.0,port=1,usb_version=1, the |
13 | Cc: yurovsky@gmail.com | 14 | keyboard is directly attached to the port, but it only advertises |
14 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 15 | itself as full-speed capable, so it becomes controlled by the OHCI |
15 | Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> | 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> | ||
16 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 23 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
17 | --- | 24 | --- |
18 | hw/arm/fsl-imx6.c | 2 +- | 25 | docs/system/arm/nuvoton.rst | 2 +- |
19 | 1 file changed, 1 insertion(+), 1 deletion(-) | 26 | hw/usb/hcd-ehci.h | 1 + |
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(-) | ||
20 | 31 | ||
21 | diff --git a/hw/arm/fsl-imx6.c b/hw/arm/fsl-imx6.c | 32 | diff --git a/docs/system/arm/nuvoton.rst b/docs/system/arm/nuvoton.rst |
22 | index XXXXXXX..XXXXXXX 100644 | 33 | index XXXXXXX..XXXXXXX 100644 |
23 | --- a/hw/arm/fsl-imx6.c | 34 | --- a/docs/system/arm/nuvoton.rst |
24 | +++ b/hw/arm/fsl-imx6.c | 35 | +++ b/docs/system/arm/nuvoton.rst |
25 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx6_init(Object *obj) | 36 | @@ -XXX,XX +XXX,XX @@ Supported devices |
37 | * OTP controllers (no protection features) | ||
38 | * Flash Interface Unit (FIU; no protection features) | ||
39 | * Random Number Generator (RNG) | ||
40 | + * USB host (USBH) | ||
41 | |||
42 | Missing devices | ||
43 | --------------- | ||
44 | @@ -XXX,XX +XXX,XX @@ Missing devices | ||
45 | * eSPI slave interface | ||
46 | |||
47 | * Ethernet controllers (GMAC and EMC) | ||
48 | - * USB host (USBH) | ||
49 | * USB device (USBD) | ||
50 | * SMBus controller (SMBF) | ||
51 | * Peripheral SPI controller (PSPI) | ||
52 | diff --git a/hw/usb/hcd-ehci.h b/hw/usb/hcd-ehci.h | ||
53 | index XXXXXXX..XXXXXXX 100644 | ||
54 | --- a/hw/usb/hcd-ehci.h | ||
55 | +++ b/hw/usb/hcd-ehci.h | ||
56 | @@ -XXX,XX +XXX,XX @@ struct EHCIPCIState { | ||
57 | #define TYPE_PLATFORM_EHCI "platform-ehci-usb" | ||
58 | #define TYPE_EXYNOS4210_EHCI "exynos4210-ehci-usb" | ||
59 | #define TYPE_AW_H3_EHCI "aw-h3-ehci-usb" | ||
60 | +#define TYPE_NPCM7XX_EHCI "npcm7xx-ehci-usb" | ||
61 | #define TYPE_TEGRA2_EHCI "tegra2-ehci-usb" | ||
62 | #define TYPE_PPC4xx_EHCI "ppc4xx-ehci-usb" | ||
63 | #define TYPE_FUSBH200_EHCI "fusbh200-ehci-usb" | ||
64 | diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h | ||
65 | index XXXXXXX..XXXXXXX 100644 | ||
66 | --- a/include/hw/arm/npcm7xx.h | ||
67 | +++ b/include/hw/arm/npcm7xx.h | ||
68 | @@ -XXX,XX +XXX,XX @@ | ||
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 | + | ||
98 | /* Internal AHB SRAM */ | ||
99 | #define NPCM7XX_RAM3_BA (0xc0008000) | ||
100 | #define NPCM7XX_RAM3_SZ (4 * KiB) | ||
101 | @@ -XXX,XX +XXX,XX @@ enum NPCM7xxInterrupt { | ||
102 | NPCM7XX_WDG0_IRQ = 47, /* Timer Module 0 Watchdog */ | ||
103 | NPCM7XX_WDG1_IRQ, /* Timer Module 1 Watchdog */ | ||
104 | NPCM7XX_WDG2_IRQ, /* Timer Module 2 Watchdog */ | ||
105 | + NPCM7XX_EHCI_IRQ = 61, | ||
106 | + NPCM7XX_OHCI_IRQ = 62, | ||
107 | }; | ||
108 | |||
109 | /* Total number of GIC interrupts, including internal Cortex-A9 interrupts. */ | ||
110 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_init(Object *obj) | ||
111 | object_initialize_child(obj, "tim[*]", &s->tim[i], TYPE_NPCM7XX_TIMER); | ||
26 | } | 112 | } |
27 | 113 | ||
28 | for (i = 0; i < FSL_IMX6_NUM_ESDHCS; i++) { | 114 | + object_initialize_child(obj, "ehci", &s->ehci, TYPE_NPCM7XX_EHCI); |
29 | - object_initialize(&s->esdhc[i], sizeof(s->esdhc[i]), TYPE_SYSBUS_SDHCI); | 115 | + object_initialize_child(obj, "ohci", &s->ohci, TYPE_SYSBUS_OHCI); |
30 | + object_initialize(&s->esdhc[i], sizeof(s->esdhc[i]), TYPE_IMX_USDHC); | 116 | + |
31 | qdev_set_parent_bus(DEVICE(&s->esdhc[i]), sysbus_get_default()); | 117 | QEMU_BUILD_BUG_ON(ARRAY_SIZE(npcm7xx_fiu) != ARRAY_SIZE(s->fiu)); |
32 | snprintf(name, NAME_SIZE, "sdhc%d", i + 1); | 118 | for (i = 0; i < ARRAY_SIZE(s->fiu); i++) { |
33 | object_property_add_child(obj, name, OBJECT(&s->esdhc[i]), NULL); | 119 | object_initialize_child(obj, npcm7xx_fiu[i].name, &s->fiu[i], |
120 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp) | ||
121 | sysbus_realize(SYS_BUS_DEVICE(&s->rng), &error_abort); | ||
122 | sysbus_mmio_map(SYS_BUS_DEVICE(&s->rng), 0, NPCM7XX_RNG_BA); | ||
123 | |||
124 | + /* USB Host */ | ||
125 | + object_property_set_bool(OBJECT(&s->ehci), "companion-enable", true, | ||
126 | + &error_abort); | ||
127 | + sysbus_realize(SYS_BUS_DEVICE(&s->ehci), &error_abort); | ||
128 | + sysbus_mmio_map(SYS_BUS_DEVICE(&s->ehci), 0, NPCM7XX_EHCI_BA); | ||
129 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->ehci), 0, | ||
130 | + npcm7xx_irq(s, NPCM7XX_EHCI_IRQ)); | ||
131 | + | ||
132 | + object_property_set_str(OBJECT(&s->ohci), "masterbus", "usb-bus.0", | ||
133 | + &error_abort); | ||
134 | + object_property_set_uint(OBJECT(&s->ohci), "num-ports", 1, &error_abort); | ||
135 | + sysbus_realize(SYS_BUS_DEVICE(&s->ohci), &error_abort); | ||
136 | + sysbus_mmio_map(SYS_BUS_DEVICE(&s->ohci), 0, NPCM7XX_OHCI_BA); | ||
137 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->ohci), 0, | ||
138 | + npcm7xx_irq(s, NPCM7XX_OHCI_IRQ)); | ||
139 | + | ||
140 | /* | ||
141 | * Flash Interface Unit (FIU). Can fail if incorrect number of chip selects | ||
142 | * specified, but this is a programming error. | ||
143 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp) | ||
144 | create_unimplemented_device("npcm7xx.mcphy", 0xf05f0000, 64 * KiB); | ||
145 | create_unimplemented_device("npcm7xx.gmac1", 0xf0802000, 8 * KiB); | ||
146 | create_unimplemented_device("npcm7xx.gmac2", 0xf0804000, 8 * KiB); | ||
147 | - create_unimplemented_device("npcm7xx.ehci", 0xf0806000, 4 * KiB); | ||
148 | - create_unimplemented_device("npcm7xx.ohci", 0xf0807000, 4 * KiB); | ||
149 | create_unimplemented_device("npcm7xx.vcd", 0xf0810000, 64 * KiB); | ||
150 | create_unimplemented_device("npcm7xx.ece", 0xf0820000, 8 * KiB); | ||
151 | create_unimplemented_device("npcm7xx.vdma", 0xf0822000, 8 * KiB); | ||
152 | diff --git a/hw/usb/hcd-ehci-sysbus.c b/hw/usb/hcd-ehci-sysbus.c | ||
153 | index XXXXXXX..XXXXXXX 100644 | ||
154 | --- a/hw/usb/hcd-ehci-sysbus.c | ||
155 | +++ b/hw/usb/hcd-ehci-sysbus.c | ||
156 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo ehci_aw_h3_type_info = { | ||
157 | .class_init = ehci_aw_h3_class_init, | ||
158 | }; | ||
159 | |||
160 | +static void ehci_npcm7xx_class_init(ObjectClass *oc, void *data) | ||
161 | +{ | ||
162 | + SysBusEHCIClass *sec = SYS_BUS_EHCI_CLASS(oc); | ||
163 | + DeviceClass *dc = DEVICE_CLASS(oc); | ||
164 | + | ||
165 | + sec->capsbase = 0x0; | ||
166 | + sec->opregbase = 0x10; | ||
167 | + sec->portscbase = 0x44; | ||
168 | + sec->portnr = 1; | ||
169 | + set_bit(DEVICE_CATEGORY_USB, dc->categories); | ||
170 | +} | ||
171 | + | ||
172 | +static const TypeInfo ehci_npcm7xx_type_info = { | ||
173 | + .name = TYPE_NPCM7XX_EHCI, | ||
174 | + .parent = TYPE_SYS_BUS_EHCI, | ||
175 | + .class_init = ehci_npcm7xx_class_init, | ||
176 | +}; | ||
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); | ||
34 | -- | 189 | -- |
35 | 2.16.1 | 190 | 2.20.1 |
36 | 191 | ||
37 | 192 | diff view generated by jsdifflib |
1 | From: Andrey Smirnov <andrew.smirnov@gmail.com> | 1 | From: Havard Skinnemoen <hskinnemoen@google.com> |
---|---|---|---|
2 | 2 | ||
3 | Add code to emulate Chipidea USB IP (used in i.MX SoCs). Tested to | 3 | The NPCM7xx chips have multiple GPIO controllers that are mostly |
4 | work against: | 4 | identical except for some minor differences like the reset values of |
5 | some registers. Each controller controls up to 32 pins. | ||
5 | 6 | ||
6 | -usb -drive if=none,id=stick,file=usb.img,format=raw -device \ | 7 | Each individual pin is modeled as a pair of unnamed GPIOs -- one for |
7 | usb-storage,bus=usb-bus.0,drive=stick | 8 | emitting the actual pin state, and one for driving the pin externally. |
9 | Like the nRF51 GPIO controller, a gpio level may be negative, which | ||
10 | means the pin is not driven, or floating. | ||
8 | 11 | ||
9 | Cc: Peter Maydell <peter.maydell@linaro.org> | 12 | Reviewed-by: Tyrone Ting <kfting@nuvoton.com> |
10 | Cc: Jason Wang <jasowang@redhat.com> | 13 | Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com> |
11 | Cc: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
12 | Cc: Marcel Apfelbaum <marcel.apfelbaum@zoho.com> | ||
13 | Cc: Michael S. Tsirkin <mst@redhat.com> | ||
14 | Cc: qemu-devel@nongnu.org | ||
15 | Cc: qemu-arm@nongnu.org | ||
16 | Cc: yurovsky@gmail.com | ||
17 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 14 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
18 | Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> | ||
19 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 15 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
20 | --- | 16 | --- |
21 | hw/usb/Makefile.objs | 1 + | 17 | docs/system/arm/nuvoton.rst | 2 +- |
22 | include/hw/usb/chipidea.h | 16 +++++ | 18 | include/hw/arm/npcm7xx.h | 2 + |
23 | hw/usb/chipidea.c | 176 ++++++++++++++++++++++++++++++++++++++++++++++ | 19 | include/hw/gpio/npcm7xx_gpio.h | 55 +++++ |
24 | 3 files changed, 193 insertions(+) | 20 | hw/arm/npcm7xx.c | 80 ++++++ |
25 | create mode 100644 include/hw/usb/chipidea.h | 21 | hw/gpio/npcm7xx_gpio.c | 424 ++++++++++++++++++++++++++++++++ |
26 | create mode 100644 hw/usb/chipidea.c | 22 | tests/qtest/npcm7xx_gpio-test.c | 385 +++++++++++++++++++++++++++++ |
23 | hw/gpio/meson.build | 1 + | ||
24 | hw/gpio/trace-events | 7 + | ||
25 | tests/qtest/meson.build | 3 +- | ||
26 | 9 files changed, 957 insertions(+), 2 deletions(-) | ||
27 | create mode 100644 include/hw/gpio/npcm7xx_gpio.h | ||
28 | create mode 100644 hw/gpio/npcm7xx_gpio.c | ||
29 | create mode 100644 tests/qtest/npcm7xx_gpio-test.c | ||
27 | 30 | ||
28 | diff --git a/hw/usb/Makefile.objs b/hw/usb/Makefile.objs | 31 | diff --git a/docs/system/arm/nuvoton.rst b/docs/system/arm/nuvoton.rst |
29 | index XXXXXXX..XXXXXXX 100644 | 32 | index XXXXXXX..XXXXXXX 100644 |
30 | --- a/hw/usb/Makefile.objs | 33 | --- a/docs/system/arm/nuvoton.rst |
31 | +++ b/hw/usb/Makefile.objs | 34 | +++ b/docs/system/arm/nuvoton.rst |
32 | @@ -XXX,XX +XXX,XX @@ common-obj-$(CONFIG_USB_XHCI_NEC) += hcd-xhci-nec.o | 35 | @@ -XXX,XX +XXX,XX @@ Supported devices |
33 | common-obj-$(CONFIG_USB_MUSB) += hcd-musb.o | 36 | * Flash Interface Unit (FIU; no protection features) |
34 | 37 | * Random Number Generator (RNG) | |
35 | obj-$(CONFIG_TUSB6010) += tusb6010.o | 38 | * USB host (USBH) |
36 | +obj-$(CONFIG_IMX) += chipidea.o | 39 | + * GPIO controller |
37 | 40 | ||
38 | # emulated usb devices | 41 | Missing devices |
39 | common-obj-$(CONFIG_USB) += dev-hub.o | 42 | --------------- |
40 | diff --git a/include/hw/usb/chipidea.h b/include/hw/usb/chipidea.h | 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 | ||
41 | new file mode 100644 | 69 | new file mode 100644 |
42 | index XXXXXXX..XXXXXXX | 70 | index XXXXXXX..XXXXXXX |
43 | --- /dev/null | 71 | --- /dev/null |
44 | +++ b/include/hw/usb/chipidea.h | 72 | +++ b/include/hw/gpio/npcm7xx_gpio.h |
45 | @@ -XXX,XX +XXX,XX @@ | 73 | @@ -XXX,XX +XXX,XX @@ |
46 | +#ifndef CHIPIDEA_H | 74 | +/* |
47 | +#define CHIPIDEA_H | 75 | + * Nuvoton NPCM7xx General Purpose Input / Output (GPIO) |
48 | + | 76 | + * |
49 | +#include "hw/usb/hcd-ehci.h" | 77 | + * Copyright 2020 Google LLC |
50 | + | 78 | + * |
51 | +typedef struct ChipideaState { | 79 | + * This program is free software; you can redistribute it and/or |
52 | + /*< private >*/ | 80 | + * modify it under the terms of the GNU General Public License |
53 | + EHCISysBusState parent_obj; | 81 | + * version 2 as published by the Free Software Foundation. |
54 | + | 82 | + * |
55 | + MemoryRegion iomem[3]; | 83 | + * This program is distributed in the hope that it will be useful, |
56 | +} ChipideaState; | 84 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
57 | + | 85 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
58 | +#define TYPE_CHIPIDEA "usb-chipidea" | 86 | + * GNU General Public License for more details. |
59 | +#define CHIPIDEA(obj) OBJECT_CHECK(ChipideaState, (obj), TYPE_CHIPIDEA) | 87 | + */ |
60 | + | 88 | +#ifndef NPCM7XX_GPIO_H |
61 | +#endif /* CHIPIDEA_H */ | 89 | +#define NPCM7XX_GPIO_H |
62 | diff --git a/hw/usb/chipidea.c b/hw/usb/chipidea.c | 90 | + |
91 | +#include "exec/memory.h" | ||
92 | +#include "hw/sysbus.h" | ||
93 | + | ||
94 | +/* Number of pins managed by each controller. */ | ||
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 | ||
131 | --- a/hw/arm/npcm7xx.c | ||
132 | +++ b/hw/arm/npcm7xx.c | ||
133 | @@ -XXX,XX +XXX,XX @@ enum NPCM7xxInterrupt { | ||
134 | NPCM7XX_WDG2_IRQ, /* Timer Module 2 Watchdog */ | ||
135 | NPCM7XX_EHCI_IRQ = 61, | ||
136 | NPCM7XX_OHCI_IRQ = 62, | ||
137 | + NPCM7XX_GPIO0_IRQ = 116, | ||
138 | + NPCM7XX_GPIO1_IRQ, | ||
139 | + NPCM7XX_GPIO2_IRQ, | ||
140 | + NPCM7XX_GPIO3_IRQ, | ||
141 | + NPCM7XX_GPIO4_IRQ, | ||
142 | + NPCM7XX_GPIO5_IRQ, | ||
143 | + NPCM7XX_GPIO6_IRQ, | ||
144 | + NPCM7XX_GPIO7_IRQ, | ||
145 | }; | ||
146 | |||
147 | /* Total number of GIC interrupts, including internal Cortex-A9 interrupts. */ | ||
148 | @@ -XXX,XX +XXX,XX @@ static const hwaddr npcm7xx_fiu3_flash_addr[] = { | ||
149 | 0xb8000000, /* CS3 */ | ||
150 | }; | ||
151 | |||
152 | +static const struct { | ||
153 | + hwaddr regs_addr; | ||
154 | + uint32_t unconnected_pins; | ||
155 | + uint32_t reset_pu; | ||
156 | + uint32_t reset_pd; | ||
157 | + uint32_t reset_osrc; | ||
158 | + uint32_t reset_odsc; | ||
159 | +} npcm7xx_gpio[] = { | ||
160 | + { | ||
161 | + .regs_addr = 0xf0010000, | ||
162 | + .reset_pu = 0xff03ffff, | ||
163 | + .reset_pd = 0x00fc0000, | ||
164 | + }, { | ||
165 | + .regs_addr = 0xf0011000, | ||
166 | + .unconnected_pins = 0x0000001e, | ||
167 | + .reset_pu = 0xfefffe07, | ||
168 | + .reset_pd = 0x010001e0, | ||
169 | + }, { | ||
170 | + .regs_addr = 0xf0012000, | ||
171 | + .reset_pu = 0x780fffff, | ||
172 | + .reset_pd = 0x07f00000, | ||
173 | + .reset_odsc = 0x00700000, | ||
174 | + }, { | ||
175 | + .regs_addr = 0xf0013000, | ||
176 | + .reset_pu = 0x00fc0000, | ||
177 | + .reset_pd = 0xff000000, | ||
178 | + }, { | ||
179 | + .regs_addr = 0xf0014000, | ||
180 | + .reset_pu = 0xffffffff, | ||
181 | + }, { | ||
182 | + .regs_addr = 0xf0015000, | ||
183 | + .reset_pu = 0xbf83f801, | ||
184 | + .reset_pd = 0x007c0000, | ||
185 | + .reset_osrc = 0x000000f1, | ||
186 | + .reset_odsc = 0x3f9f80f1, | ||
187 | + }, { | ||
188 | + .regs_addr = 0xf0016000, | ||
189 | + .reset_pu = 0xfc00f801, | ||
190 | + .reset_pd = 0x000007fe, | ||
191 | + .reset_odsc = 0x00000800, | ||
192 | + }, { | ||
193 | + .regs_addr = 0xf0017000, | ||
194 | + .unconnected_pins = 0xffffff00, | ||
195 | + .reset_pu = 0x0000007f, | ||
196 | + .reset_osrc = 0x0000007f, | ||
197 | + .reset_odsc = 0x0000007f, | ||
198 | + }, | ||
199 | +}; | ||
200 | + | ||
201 | static const struct { | ||
202 | const char *name; | ||
203 | hwaddr regs_addr; | ||
204 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_init(Object *obj) | ||
205 | object_initialize_child(obj, "tim[*]", &s->tim[i], TYPE_NPCM7XX_TIMER); | ||
206 | } | ||
207 | |||
208 | + for (i = 0; i < ARRAY_SIZE(s->gpio); i++) { | ||
209 | + object_initialize_child(obj, "gpio[*]", &s->gpio[i], TYPE_NPCM7XX_GPIO); | ||
210 | + } | ||
211 | + | ||
212 | object_initialize_child(obj, "ehci", &s->ehci, TYPE_NPCM7XX_EHCI); | ||
213 | object_initialize_child(obj, "ohci", &s->ohci, TYPE_SYSBUS_OHCI); | ||
214 | |||
215 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp) | ||
216 | sysbus_realize(SYS_BUS_DEVICE(&s->rng), &error_abort); | ||
217 | sysbus_mmio_map(SYS_BUS_DEVICE(&s->rng), 0, NPCM7XX_RNG_BA); | ||
218 | |||
219 | + /* GPIO modules. Cannot fail. */ | ||
220 | + QEMU_BUILD_BUG_ON(ARRAY_SIZE(npcm7xx_gpio) != ARRAY_SIZE(s->gpio)); | ||
221 | + for (i = 0; i < ARRAY_SIZE(s->gpio); i++) { | ||
222 | + Object *obj = OBJECT(&s->gpio[i]); | ||
223 | + | ||
224 | + object_property_set_uint(obj, "reset-pullup", | ||
225 | + npcm7xx_gpio[i].reset_pu, &error_abort); | ||
226 | + object_property_set_uint(obj, "reset-pulldown", | ||
227 | + npcm7xx_gpio[i].reset_pd, &error_abort); | ||
228 | + object_property_set_uint(obj, "reset-osrc", | ||
229 | + npcm7xx_gpio[i].reset_osrc, &error_abort); | ||
230 | + object_property_set_uint(obj, "reset-odsc", | ||
231 | + npcm7xx_gpio[i].reset_odsc, &error_abort); | ||
232 | + sysbus_realize(SYS_BUS_DEVICE(obj), &error_abort); | ||
233 | + sysbus_mmio_map(SYS_BUS_DEVICE(obj), 0, npcm7xx_gpio[i].regs_addr); | ||
234 | + sysbus_connect_irq(SYS_BUS_DEVICE(obj), 0, | ||
235 | + npcm7xx_irq(s, NPCM7XX_GPIO0_IRQ + i)); | ||
236 | + } | ||
237 | + | ||
238 | /* USB Host */ | ||
239 | object_property_set_bool(OBJECT(&s->ehci), "companion-enable", true, | ||
240 | &error_abort); | ||
241 | diff --git a/hw/gpio/npcm7xx_gpio.c b/hw/gpio/npcm7xx_gpio.c | ||
63 | new file mode 100644 | 242 | new file mode 100644 |
64 | index XXXXXXX..XXXXXXX | 243 | index XXXXXXX..XXXXXXX |
65 | --- /dev/null | 244 | --- /dev/null |
66 | +++ b/hw/usb/chipidea.c | 245 | +++ b/hw/gpio/npcm7xx_gpio.c |
67 | @@ -XXX,XX +XXX,XX @@ | 246 | @@ -XXX,XX +XXX,XX @@ |
68 | +/* | 247 | +/* |
69 | + * Copyright (c) 2018, Impinj, Inc. | 248 | + * Nuvoton NPCM7xx General Purpose Input / Output (GPIO) |
70 | + * | 249 | + * |
71 | + * Chipidea USB block emulation code | 250 | + * Copyright 2020 Google LLC |
72 | + * | 251 | + * |
73 | + * Author: Andrey Smirnov <andrew.smirnov@gmail.com> | 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. | ||
74 | + * | 255 | + * |
75 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | 256 | + * This program is distributed in the hope that it will be useful, |
76 | + * See the COPYING file in the top-level directory. | 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. | ||
77 | + */ | 260 | + */ |
78 | + | 261 | + |
79 | +#include "qemu/osdep.h" | 262 | +#include "qemu/osdep.h" |
80 | +#include "hw/usb/hcd-ehci.h" | 263 | + |
81 | +#include "hw/usb/chipidea.h" | 264 | +#include "hw/gpio/npcm7xx_gpio.h" |
265 | +#include "hw/irq.h" | ||
266 | +#include "hw/qdev-properties.h" | ||
267 | +#include "migration/vmstate.h" | ||
268 | +#include "qapi/error.h" | ||
82 | +#include "qemu/log.h" | 269 | +#include "qemu/log.h" |
83 | + | 270 | +#include "qemu/module.h" |
84 | +enum { | 271 | +#include "qemu/units.h" |
85 | + CHIPIDEA_USBx_DCIVERSION = 0x000, | 272 | +#include "trace.h" |
86 | + CHIPIDEA_USBx_DCCPARAMS = 0x004, | 273 | + |
87 | + CHIPIDEA_USBx_DCCPARAMS_HC = BIT(8), | 274 | +/* 32-bit register indices. */ |
275 | +enum NPCM7xxGPIORegister { | ||
276 | + NPCM7XX_GPIO_TLOCK1, | ||
277 | + NPCM7XX_GPIO_DIN, | ||
278 | + NPCM7XX_GPIO_POL, | ||
279 | + NPCM7XX_GPIO_DOUT, | ||
280 | + NPCM7XX_GPIO_OE, | ||
281 | + NPCM7XX_GPIO_OTYP, | ||
282 | + NPCM7XX_GPIO_MP, | ||
283 | + NPCM7XX_GPIO_PU, | ||
284 | + NPCM7XX_GPIO_PD, | ||
285 | + NPCM7XX_GPIO_DBNC, | ||
286 | + NPCM7XX_GPIO_EVTYP, | ||
287 | + NPCM7XX_GPIO_EVBE, | ||
288 | + NPCM7XX_GPIO_OBL0, | ||
289 | + NPCM7XX_GPIO_OBL1, | ||
290 | + NPCM7XX_GPIO_OBL2, | ||
291 | + NPCM7XX_GPIO_OBL3, | ||
292 | + NPCM7XX_GPIO_EVEN, | ||
293 | + NPCM7XX_GPIO_EVENS, | ||
294 | + NPCM7XX_GPIO_EVENC, | ||
295 | + NPCM7XX_GPIO_EVST, | ||
296 | + NPCM7XX_GPIO_SPLCK, | ||
297 | + NPCM7XX_GPIO_MPLCK, | ||
298 | + NPCM7XX_GPIO_IEM, | ||
299 | + NPCM7XX_GPIO_OSRC, | ||
300 | + NPCM7XX_GPIO_ODSC, | ||
301 | + NPCM7XX_GPIO_DOS = 0x68 / sizeof(uint32_t), | ||
302 | + NPCM7XX_GPIO_DOC, | ||
303 | + NPCM7XX_GPIO_OES, | ||
304 | + NPCM7XX_GPIO_OEC, | ||
305 | + NPCM7XX_GPIO_TLOCK2 = 0x7c / sizeof(uint32_t), | ||
306 | + NPCM7XX_GPIO_REGS_END, | ||
88 | +}; | 307 | +}; |
89 | + | 308 | + |
90 | +static uint64_t chipidea_read(void *opaque, hwaddr offset, | 309 | +#define NPCM7XX_GPIO_REGS_SIZE (4 * KiB) |
91 | + unsigned size) | 310 | + |
92 | +{ | 311 | +#define NPCM7XX_GPIO_LOCK_MAGIC1 (0xc0defa73) |
93 | + return 0; | 312 | +#define NPCM7XX_GPIO_LOCK_MAGIC2 (0xc0de1248) |
94 | +} | 313 | + |
95 | + | 314 | +static void npcm7xx_gpio_update_events(NPCM7xxGPIOState *s, uint32_t din_diff) |
96 | +static void chipidea_write(void *opaque, hwaddr offset, | 315 | +{ |
97 | + uint64_t value, unsigned size) | 316 | + uint32_t din_new = s->regs[NPCM7XX_GPIO_DIN]; |
98 | +{ | 317 | + |
99 | +} | 318 | + /* Trigger on high level */ |
100 | + | 319 | + s->regs[NPCM7XX_GPIO_EVST] |= din_new & ~s->regs[NPCM7XX_GPIO_EVTYP]; |
101 | +static const struct MemoryRegionOps chipidea_ops = { | 320 | + /* Trigger on both edges */ |
102 | + .read = chipidea_read, | 321 | + s->regs[NPCM7XX_GPIO_EVST] |= (din_diff & s->regs[NPCM7XX_GPIO_EVTYP] |
103 | + .write = chipidea_write, | 322 | + & s->regs[NPCM7XX_GPIO_EVBE]); |
323 | + /* Trigger on rising edge */ | ||
324 | + s->regs[NPCM7XX_GPIO_EVST] |= (din_diff & din_new | ||
325 | + & s->regs[NPCM7XX_GPIO_EVTYP]); | ||
326 | + | ||
327 | + trace_npcm7xx_gpio_update_events(DEVICE(s)->canonical_path, | ||
328 | + s->regs[NPCM7XX_GPIO_EVST], | ||
329 | + s->regs[NPCM7XX_GPIO_EVEN]); | ||
330 | + qemu_set_irq(s->irq, !!(s->regs[NPCM7XX_GPIO_EVST] | ||
331 | + & s->regs[NPCM7XX_GPIO_EVEN])); | ||
332 | +} | ||
333 | + | ||
334 | +static void npcm7xx_gpio_update_pins(NPCM7xxGPIOState *s, uint32_t diff) | ||
335 | +{ | ||
336 | + uint32_t drive_en; | ||
337 | + uint32_t drive_lvl; | ||
338 | + uint32_t not_driven; | ||
339 | + uint32_t undefined; | ||
340 | + uint32_t pin_diff; | ||
341 | + uint32_t din_old; | ||
342 | + | ||
343 | + /* Calculate level of each pin driven by GPIO controller. */ | ||
344 | + drive_lvl = s->regs[NPCM7XX_GPIO_DOUT] ^ s->regs[NPCM7XX_GPIO_POL]; | ||
345 | + /* If OTYP=1, only drive low (open drain) */ | ||
346 | + drive_en = s->regs[NPCM7XX_GPIO_OE] & ~(s->regs[NPCM7XX_GPIO_OTYP] | ||
347 | + & drive_lvl); | ||
348 | + /* | ||
349 | + * If a pin is driven to opposite levels by the GPIO controller and the | ||
350 | + * external driver, the result is undefined. | ||
351 | + */ | ||
352 | + undefined = drive_en & s->ext_driven & (drive_lvl ^ s->ext_level); | ||
353 | + if (undefined) { | ||
354 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
355 | + "%s: pins have multiple drivers: 0x%" PRIx32 "\n", | ||
356 | + DEVICE(s)->canonical_path, undefined); | ||
357 | + } | ||
358 | + | ||
359 | + not_driven = ~(drive_en | s->ext_driven); | ||
360 | + pin_diff = s->pin_level; | ||
361 | + | ||
362 | + /* Set pins to externally driven level. */ | ||
363 | + s->pin_level = s->ext_level & s->ext_driven; | ||
364 | + /* Set internally driven pins, ignoring any conflicts. */ | ||
365 | + s->pin_level |= drive_lvl & drive_en; | ||
366 | + /* Pull up undriven pins with internal pull-up enabled. */ | ||
367 | + s->pin_level |= not_driven & s->regs[NPCM7XX_GPIO_PU]; | ||
368 | + /* Pins not driven, pulled up or pulled down are undefined */ | ||
369 | + undefined |= not_driven & ~(s->regs[NPCM7XX_GPIO_PU] | ||
370 | + | s->regs[NPCM7XX_GPIO_PD]); | ||
371 | + | ||
372 | + /* If any pins changed state, update the outgoing GPIOs. */ | ||
373 | + pin_diff ^= s->pin_level; | ||
374 | + pin_diff |= undefined & diff; | ||
375 | + if (pin_diff) { | ||
376 | + int i; | ||
377 | + | ||
378 | + for (i = 0; i < NPCM7XX_GPIO_NR_PINS; i++) { | ||
379 | + uint32_t mask = BIT(i); | ||
380 | + if (pin_diff & mask) { | ||
381 | + int level = (undefined & mask) ? -1 : !!(s->pin_level & mask); | ||
382 | + trace_npcm7xx_gpio_set_output(DEVICE(s)->canonical_path, | ||
383 | + i, level); | ||
384 | + qemu_set_irq(s->output[i], level); | ||
385 | + } | ||
386 | + } | ||
387 | + } | ||
388 | + | ||
389 | + /* Calculate new value of DIN after masking and polarity setting. */ | ||
390 | + din_old = s->regs[NPCM7XX_GPIO_DIN]; | ||
391 | + s->regs[NPCM7XX_GPIO_DIN] = ((s->pin_level & s->regs[NPCM7XX_GPIO_IEM]) | ||
392 | + ^ s->regs[NPCM7XX_GPIO_POL]); | ||
393 | + | ||
394 | + /* See if any new events triggered because of all this. */ | ||
395 | + npcm7xx_gpio_update_events(s, din_old ^ s->regs[NPCM7XX_GPIO_DIN]); | ||
396 | +} | ||
397 | + | ||
398 | +static bool npcm7xx_gpio_is_locked(NPCM7xxGPIOState *s) | ||
399 | +{ | ||
400 | + return s->regs[NPCM7XX_GPIO_TLOCK1] == 1; | ||
401 | +} | ||
402 | + | ||
403 | +static uint64_t npcm7xx_gpio_regs_read(void *opaque, hwaddr addr, | ||
404 | + unsigned int size) | ||
405 | +{ | ||
406 | + hwaddr reg = addr / sizeof(uint32_t); | ||
407 | + NPCM7xxGPIOState *s = opaque; | ||
408 | + uint64_t value = 0; | ||
409 | + | ||
410 | + switch (reg) { | ||
411 | + case NPCM7XX_GPIO_TLOCK1 ... NPCM7XX_GPIO_EVEN: | ||
412 | + case NPCM7XX_GPIO_EVST ... NPCM7XX_GPIO_ODSC: | ||
413 | + value = s->regs[reg]; | ||
414 | + break; | ||
415 | + | ||
416 | + case NPCM7XX_GPIO_EVENS ... NPCM7XX_GPIO_EVENC: | ||
417 | + case NPCM7XX_GPIO_DOS ... NPCM7XX_GPIO_TLOCK2: | ||
418 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
419 | + "%s: read from write-only register 0x%" HWADDR_PRIx "\n", | ||
420 | + DEVICE(s)->canonical_path, addr); | ||
421 | + break; | ||
422 | + | ||
423 | + default: | ||
424 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
425 | + "%s: read from invalid offset 0x%" HWADDR_PRIx "\n", | ||
426 | + DEVICE(s)->canonical_path, addr); | ||
427 | + break; | ||
428 | + } | ||
429 | + | ||
430 | + trace_npcm7xx_gpio_read(DEVICE(s)->canonical_path, addr, value); | ||
431 | + | ||
432 | + return value; | ||
433 | +} | ||
434 | + | ||
435 | +static void npcm7xx_gpio_regs_write(void *opaque, hwaddr addr, uint64_t v, | ||
436 | + unsigned int size) | ||
437 | +{ | ||
438 | + hwaddr reg = addr / sizeof(uint32_t); | ||
439 | + NPCM7xxGPIOState *s = opaque; | ||
440 | + uint32_t value = v; | ||
441 | + uint32_t diff; | ||
442 | + | ||
443 | + trace_npcm7xx_gpio_write(DEVICE(s)->canonical_path, addr, v); | ||
444 | + | ||
445 | + if (npcm7xx_gpio_is_locked(s)) { | ||
446 | + switch (reg) { | ||
447 | + case NPCM7XX_GPIO_TLOCK1: | ||
448 | + if (s->regs[NPCM7XX_GPIO_TLOCK2] == NPCM7XX_GPIO_LOCK_MAGIC2 && | ||
449 | + value == NPCM7XX_GPIO_LOCK_MAGIC1) { | ||
450 | + s->regs[NPCM7XX_GPIO_TLOCK1] = 0; | ||
451 | + s->regs[NPCM7XX_GPIO_TLOCK2] = 0; | ||
452 | + } | ||
453 | + break; | ||
454 | + | ||
455 | + case NPCM7XX_GPIO_TLOCK2: | ||
456 | + s->regs[reg] = value; | ||
457 | + break; | ||
458 | + | ||
459 | + default: | ||
460 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
461 | + "%s: write to locked register @ 0x%" HWADDR_PRIx "\n", | ||
462 | + DEVICE(s)->canonical_path, addr); | ||
463 | + break; | ||
464 | + } | ||
465 | + | ||
466 | + return; | ||
467 | + } | ||
468 | + | ||
469 | + diff = s->regs[reg] ^ value; | ||
470 | + | ||
471 | + switch (reg) { | ||
472 | + case NPCM7XX_GPIO_TLOCK1: | ||
473 | + case NPCM7XX_GPIO_TLOCK2: | ||
474 | + s->regs[NPCM7XX_GPIO_TLOCK1] = 1; | ||
475 | + s->regs[NPCM7XX_GPIO_TLOCK2] = 0; | ||
476 | + break; | ||
477 | + | ||
478 | + case NPCM7XX_GPIO_DIN: | ||
479 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
480 | + "%s: write to read-only register @ 0x%" HWADDR_PRIx "\n", | ||
481 | + DEVICE(s)->canonical_path, addr); | ||
482 | + break; | ||
483 | + | ||
484 | + case NPCM7XX_GPIO_POL: | ||
485 | + case NPCM7XX_GPIO_DOUT: | ||
486 | + case NPCM7XX_GPIO_OE: | ||
487 | + case NPCM7XX_GPIO_OTYP: | ||
488 | + case NPCM7XX_GPIO_PU: | ||
489 | + case NPCM7XX_GPIO_PD: | ||
490 | + case NPCM7XX_GPIO_IEM: | ||
491 | + s->regs[reg] = value; | ||
492 | + npcm7xx_gpio_update_pins(s, diff); | ||
493 | + break; | ||
494 | + | ||
495 | + case NPCM7XX_GPIO_DOS: | ||
496 | + s->regs[NPCM7XX_GPIO_DOUT] |= value; | ||
497 | + npcm7xx_gpio_update_pins(s, value); | ||
498 | + break; | ||
499 | + case NPCM7XX_GPIO_DOC: | ||
500 | + s->regs[NPCM7XX_GPIO_DOUT] &= ~value; | ||
501 | + npcm7xx_gpio_update_pins(s, value); | ||
502 | + break; | ||
503 | + case NPCM7XX_GPIO_OES: | ||
504 | + s->regs[NPCM7XX_GPIO_OE] |= value; | ||
505 | + npcm7xx_gpio_update_pins(s, value); | ||
506 | + break; | ||
507 | + case NPCM7XX_GPIO_OEC: | ||
508 | + s->regs[NPCM7XX_GPIO_OE] &= ~value; | ||
509 | + npcm7xx_gpio_update_pins(s, value); | ||
510 | + break; | ||
511 | + | ||
512 | + case NPCM7XX_GPIO_EVTYP: | ||
513 | + case NPCM7XX_GPIO_EVBE: | ||
514 | + case NPCM7XX_GPIO_EVEN: | ||
515 | + s->regs[reg] = value; | ||
516 | + npcm7xx_gpio_update_events(s, 0); | ||
517 | + break; | ||
518 | + | ||
519 | + case NPCM7XX_GPIO_EVENS: | ||
520 | + s->regs[NPCM7XX_GPIO_EVEN] |= value; | ||
521 | + npcm7xx_gpio_update_events(s, 0); | ||
522 | + break; | ||
523 | + case NPCM7XX_GPIO_EVENC: | ||
524 | + s->regs[NPCM7XX_GPIO_EVEN] &= ~value; | ||
525 | + npcm7xx_gpio_update_events(s, 0); | ||
526 | + break; | ||
527 | + | ||
528 | + case NPCM7XX_GPIO_EVST: | ||
529 | + s->regs[reg] &= ~value; | ||
530 | + npcm7xx_gpio_update_events(s, 0); | ||
531 | + break; | ||
532 | + | ||
533 | + case NPCM7XX_GPIO_MP: | ||
534 | + case NPCM7XX_GPIO_DBNC: | ||
535 | + case NPCM7XX_GPIO_OSRC: | ||
536 | + case NPCM7XX_GPIO_ODSC: | ||
537 | + /* Nothing to do; just store the value. */ | ||
538 | + s->regs[reg] = value; | ||
539 | + break; | ||
540 | + | ||
541 | + case NPCM7XX_GPIO_OBL0: | ||
542 | + case NPCM7XX_GPIO_OBL1: | ||
543 | + case NPCM7XX_GPIO_OBL2: | ||
544 | + case NPCM7XX_GPIO_OBL3: | ||
545 | + s->regs[reg] = value; | ||
546 | + qemu_log_mask(LOG_UNIMP, "%s: Blinking is not implemented\n", | ||
547 | + __func__); | ||
548 | + break; | ||
549 | + | ||
550 | + case NPCM7XX_GPIO_SPLCK: | ||
551 | + case NPCM7XX_GPIO_MPLCK: | ||
552 | + qemu_log_mask(LOG_UNIMP, "%s: Per-pin lock is not implemented\n", | ||
553 | + __func__); | ||
554 | + break; | ||
555 | + | ||
556 | + default: | ||
557 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
558 | + "%s: write to invalid offset 0x%" HWADDR_PRIx "\n", | ||
559 | + DEVICE(s)->canonical_path, addr); | ||
560 | + break; | ||
561 | + } | ||
562 | +} | ||
563 | + | ||
564 | +static const MemoryRegionOps npcm7xx_gpio_regs_ops = { | ||
565 | + .read = npcm7xx_gpio_regs_read, | ||
566 | + .write = npcm7xx_gpio_regs_write, | ||
104 | + .endianness = DEVICE_NATIVE_ENDIAN, | 567 | + .endianness = DEVICE_NATIVE_ENDIAN, |
105 | + .impl = { | 568 | + .valid = { |
106 | + /* | ||
107 | + * Our device would not work correctly if the guest was doing | ||
108 | + * unaligned access. This might not be a limitation on the | ||
109 | + * real device but in practice there is no reason for a guest | ||
110 | + * to access this device unaligned. | ||
111 | + */ | ||
112 | + .min_access_size = 4, | 569 | + .min_access_size = 4, |
113 | + .max_access_size = 4, | 570 | + .max_access_size = 4, |
114 | + .unaligned = false, | 571 | + .unaligned = false, |
115 | + }, | 572 | + }, |
116 | +}; | 573 | +}; |
117 | + | 574 | + |
118 | +static uint64_t chipidea_dc_read(void *opaque, hwaddr offset, | 575 | +static void npcm7xx_gpio_set_input(void *opaque, int line, int level) |
119 | + unsigned size) | 576 | +{ |
120 | +{ | 577 | + NPCM7xxGPIOState *s = opaque; |
121 | + switch (offset) { | 578 | + |
122 | + case CHIPIDEA_USBx_DCIVERSION: | 579 | + trace_npcm7xx_gpio_set_input(DEVICE(s)->canonical_path, line, level); |
123 | + return 0x1; | 580 | + |
124 | + case CHIPIDEA_USBx_DCCPARAMS: | 581 | + g_assert(line >= 0 && line < NPCM7XX_GPIO_NR_PINS); |
125 | + /* | 582 | + |
126 | + * Real hardware (at least i.MX7) will also report the | 583 | + s->ext_driven = deposit32(s->ext_driven, line, 1, level >= 0); |
127 | + * controller as "Device Capable" (and 8 supported endpoints), | 584 | + s->ext_level = deposit32(s->ext_level, line, 1, level > 0); |
128 | + * but there doesn't seem to be much point in doing so, since | 585 | + |
129 | + * we don't emulate that part. | 586 | + npcm7xx_gpio_update_pins(s, BIT(line)); |
130 | + */ | 587 | +} |
131 | + return CHIPIDEA_USBx_DCCPARAMS_HC; | 588 | + |
132 | + } | 589 | +static void npcm7xx_gpio_enter_reset(Object *obj, ResetType type) |
133 | + | 590 | +{ |
134 | + return 0; | 591 | + NPCM7xxGPIOState *s = NPCM7XX_GPIO(obj); |
135 | +} | 592 | + |
136 | + | 593 | + memset(s->regs, 0, sizeof(s->regs)); |
137 | +static void chipidea_dc_write(void *opaque, hwaddr offset, | 594 | + |
138 | + uint64_t value, unsigned size) | 595 | + s->regs[NPCM7XX_GPIO_PU] = s->reset_pu; |
139 | +{ | 596 | + s->regs[NPCM7XX_GPIO_PD] = s->reset_pd; |
140 | +} | 597 | + s->regs[NPCM7XX_GPIO_OSRC] = s->reset_osrc; |
141 | + | 598 | + s->regs[NPCM7XX_GPIO_ODSC] = s->reset_odsc; |
142 | +static const struct MemoryRegionOps chipidea_dc_ops = { | 599 | +} |
143 | + .read = chipidea_dc_read, | 600 | + |
144 | + .write = chipidea_dc_write, | 601 | +static void npcm7xx_gpio_hold_reset(Object *obj) |
145 | + .endianness = DEVICE_NATIVE_ENDIAN, | 602 | +{ |
146 | + .impl = { | 603 | + NPCM7xxGPIOState *s = NPCM7XX_GPIO(obj); |
147 | + /* | 604 | + |
148 | + * Our device would not work correctly if the guest was doing | 605 | + npcm7xx_gpio_update_pins(s, -1); |
149 | + * unaligned access. This might not be a limitation on the real | 606 | +} |
150 | + * device but in practice there is no reason for a guest to access | 607 | + |
151 | + * this device unaligned. | 608 | +static void npcm7xx_gpio_init(Object *obj) |
152 | + */ | 609 | +{ |
153 | + .min_access_size = 4, | 610 | + NPCM7xxGPIOState *s = NPCM7XX_GPIO(obj); |
154 | + .max_access_size = 4, | 611 | + DeviceState *dev = DEVICE(obj); |
155 | + .unaligned = false, | 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(), | ||
156 | + }, | 632 | + }, |
157 | +}; | 633 | +}; |
158 | + | 634 | + |
159 | +static void chipidea_init(Object *obj) | 635 | +static Property npcm7xx_gpio_properties[] = { |
160 | +{ | 636 | + /* Bit n set => pin n has pullup enabled by default. */ |
161 | + EHCIState *ehci = &SYS_BUS_EHCI(obj)->ehci; | 637 | + DEFINE_PROP_UINT32("reset-pullup", NPCM7xxGPIOState, reset_pu, 0), |
162 | + ChipideaState *ci = CHIPIDEA(obj); | 638 | + /* Bit n set => pin n has pulldown enabled by default. */ |
639 | + DEFINE_PROP_UINT32("reset-pulldown", NPCM7xxGPIOState, reset_pd, 0), | ||
640 | + /* Bit n set => pin n has high slew rate by default. */ | ||
641 | + DEFINE_PROP_UINT32("reset-osrc", NPCM7xxGPIOState, reset_osrc, 0), | ||
642 | + /* Bit n set => pin n has high drive strength by default. */ | ||
643 | + DEFINE_PROP_UINT32("reset-odsc", NPCM7xxGPIOState, reset_odsc, 0), | ||
644 | + DEFINE_PROP_END_OF_LIST(), | ||
645 | +}; | ||
646 | + | ||
647 | +static void npcm7xx_gpio_class_init(ObjectClass *klass, void *data) | ||
648 | +{ | ||
649 | + ResettableClass *reset = RESETTABLE_CLASS(klass); | ||
650 | + DeviceClass *dc = DEVICE_CLASS(klass); | ||
651 | + | ||
652 | + QEMU_BUILD_BUG_ON(NPCM7XX_GPIO_REGS_END > NPCM7XX_GPIO_NR_REGS); | ||
653 | + | ||
654 | + dc->desc = "NPCM7xx GPIO Controller"; | ||
655 | + dc->vmsd = &vmstate_npcm7xx_gpio; | ||
656 | + reset->phases.enter = npcm7xx_gpio_enter_reset; | ||
657 | + reset->phases.hold = npcm7xx_gpio_hold_reset; | ||
658 | + device_class_set_props(dc, npcm7xx_gpio_properties); | ||
659 | +} | ||
660 | + | ||
661 | +static const TypeInfo npcm7xx_gpio_types[] = { | ||
662 | + { | ||
663 | + .name = TYPE_NPCM7XX_GPIO, | ||
664 | + .parent = TYPE_SYS_BUS_DEVICE, | ||
665 | + .instance_size = sizeof(NPCM7xxGPIOState), | ||
666 | + .class_init = npcm7xx_gpio_class_init, | ||
667 | + .instance_init = npcm7xx_gpio_init, | ||
668 | + }, | ||
669 | +}; | ||
670 | +DEFINE_TYPES(npcm7xx_gpio_types); | ||
671 | diff --git a/tests/qtest/npcm7xx_gpio-test.c b/tests/qtest/npcm7xx_gpio-test.c | ||
672 | new file mode 100644 | ||
673 | index XXXXXXX..XXXXXXX | ||
674 | --- /dev/null | ||
675 | +++ b/tests/qtest/npcm7xx_gpio-test.c | ||
676 | @@ -XXX,XX +XXX,XX @@ | ||
677 | +/* | ||
678 | + * QTest testcase for the Nuvoton NPCM7xx GPIO modules. | ||
679 | + * | ||
680 | + * Copyright 2020 Google LLC | ||
681 | + * | ||
682 | + * This program is free software; you can redistribute it and/or modify it | ||
683 | + * under the terms of the GNU General Public License as published by the | ||
684 | + * Free Software Foundation; either version 2 of the License, or | ||
685 | + * (at your option) any later version. | ||
686 | + * | ||
687 | + * This program is distributed in the hope that it will be useful, but WITHOUT | ||
688 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
689 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
690 | + * for more details. | ||
691 | + */ | ||
692 | + | ||
693 | +#include "qemu/osdep.h" | ||
694 | +#include "libqtest-single.h" | ||
695 | + | ||
696 | +#define NR_GPIO_DEVICES (8) | ||
697 | +#define GPIO(x) (0xf0010000 + (x) * 0x1000) | ||
698 | +#define GPIO_IRQ(x) (116 + (x)) | ||
699 | + | ||
700 | +/* GPIO registers */ | ||
701 | +#define GP_N_TLOCK1 0x00 | ||
702 | +#define GP_N_DIN 0x04 /* Data IN */ | ||
703 | +#define GP_N_POL 0x08 /* Polarity */ | ||
704 | +#define GP_N_DOUT 0x0c /* Data OUT */ | ||
705 | +#define GP_N_OE 0x10 /* Output Enable */ | ||
706 | +#define GP_N_OTYP 0x14 | ||
707 | +#define GP_N_MP 0x18 | ||
708 | +#define GP_N_PU 0x1c /* Pull-up */ | ||
709 | +#define GP_N_PD 0x20 /* Pull-down */ | ||
710 | +#define GP_N_DBNC 0x24 /* Debounce */ | ||
711 | +#define GP_N_EVTYP 0x28 /* Event Type */ | ||
712 | +#define GP_N_EVBE 0x2c /* Event Both Edge */ | ||
713 | +#define GP_N_OBL0 0x30 | ||
714 | +#define GP_N_OBL1 0x34 | ||
715 | +#define GP_N_OBL2 0x38 | ||
716 | +#define GP_N_OBL3 0x3c | ||
717 | +#define GP_N_EVEN 0x40 /* Event Enable */ | ||
718 | +#define GP_N_EVENS 0x44 /* Event Set (enable) */ | ||
719 | +#define GP_N_EVENC 0x48 /* Event Clear (disable) */ | ||
720 | +#define GP_N_EVST 0x4c /* Event Status */ | ||
721 | +#define GP_N_SPLCK 0x50 | ||
722 | +#define GP_N_MPLCK 0x54 | ||
723 | +#define GP_N_IEM 0x58 /* Input Enable */ | ||
724 | +#define GP_N_OSRC 0x5c | ||
725 | +#define GP_N_ODSC 0x60 | ||
726 | +#define GP_N_DOS 0x68 /* Data OUT Set */ | ||
727 | +#define GP_N_DOC 0x6c /* Data OUT Clear */ | ||
728 | +#define GP_N_OES 0x70 /* Output Enable Set */ | ||
729 | +#define GP_N_OEC 0x74 /* Output Enable Clear */ | ||
730 | +#define GP_N_TLOCK2 0x7c | ||
731 | + | ||
732 | +static void gpio_unlock(int n) | ||
733 | +{ | ||
734 | + if (readl(GPIO(n) + GP_N_TLOCK1) != 0) { | ||
735 | + writel(GPIO(n) + GP_N_TLOCK2, 0xc0de1248); | ||
736 | + writel(GPIO(n) + GP_N_TLOCK1, 0xc0defa73); | ||
737 | + } | ||
738 | +} | ||
739 | + | ||
740 | +/* Restore the GPIO controller to a sensible default state. */ | ||
741 | +static void gpio_reset(int n) | ||
742 | +{ | ||
743 | + gpio_unlock(0); | ||
744 | + | ||
745 | + writel(GPIO(n) + GP_N_EVEN, 0x00000000); | ||
746 | + writel(GPIO(n) + GP_N_EVST, 0xffffffff); | ||
747 | + writel(GPIO(n) + GP_N_POL, 0x00000000); | ||
748 | + writel(GPIO(n) + GP_N_DOUT, 0x00000000); | ||
749 | + writel(GPIO(n) + GP_N_OE, 0x00000000); | ||
750 | + writel(GPIO(n) + GP_N_OTYP, 0x00000000); | ||
751 | + writel(GPIO(n) + GP_N_PU, 0xffffffff); | ||
752 | + writel(GPIO(n) + GP_N_PD, 0x00000000); | ||
753 | + writel(GPIO(n) + GP_N_IEM, 0xffffffff); | ||
754 | +} | ||
755 | + | ||
756 | +static void test_dout_to_din(void) | ||
757 | +{ | ||
758 | + gpio_reset(0); | ||
759 | + | ||
760 | + /* When output is enabled, DOUT should be reflected on DIN. */ | ||
761 | + writel(GPIO(0) + GP_N_OE, 0xffffffff); | ||
762 | + /* PU and PD shouldn't have any impact on DIN. */ | ||
763 | + writel(GPIO(0) + GP_N_PU, 0xffff0000); | ||
764 | + writel(GPIO(0) + GP_N_PD, 0x0000ffff); | ||
765 | + writel(GPIO(0) + GP_N_DOUT, 0x12345678); | ||
766 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DOUT), ==, 0x12345678); | ||
767 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DIN), ==, 0x12345678); | ||
768 | +} | ||
769 | + | ||
770 | +static void test_pullup_pulldown(void) | ||
771 | +{ | ||
772 | + gpio_reset(0); | ||
773 | + | ||
774 | + /* | ||
775 | + * When output is disabled, and PD is the inverse of PU, PU should be | ||
776 | + * reflected on DIN. If PD is not the inverse of PU, the state of DIN is | ||
777 | + * undefined, so we don't test that. | ||
778 | + */ | ||
779 | + writel(GPIO(0) + GP_N_OE, 0x00000000); | ||
780 | + /* DOUT shouldn't have any impact on DIN. */ | ||
781 | + writel(GPIO(0) + GP_N_DOUT, 0xffff0000); | ||
782 | + writel(GPIO(0) + GP_N_PU, 0x23456789); | ||
783 | + writel(GPIO(0) + GP_N_PD, ~0x23456789U); | ||
784 | + g_assert_cmphex(readl(GPIO(0) + GP_N_PU), ==, 0x23456789); | ||
785 | + g_assert_cmphex(readl(GPIO(0) + GP_N_PD), ==, ~0x23456789U); | ||
786 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DIN), ==, 0x23456789); | ||
787 | +} | ||
788 | + | ||
789 | +static void test_output_enable(void) | ||
790 | +{ | ||
791 | + gpio_reset(0); | ||
792 | + | ||
793 | + /* | ||
794 | + * With all pins weakly pulled down, and DOUT all-ones, OE should be | ||
795 | + * reflected on DIN. | ||
796 | + */ | ||
797 | + writel(GPIO(0) + GP_N_DOUT, 0xffffffff); | ||
798 | + writel(GPIO(0) + GP_N_PU, 0x00000000); | ||
799 | + writel(GPIO(0) + GP_N_PD, 0xffffffff); | ||
800 | + writel(GPIO(0) + GP_N_OE, 0x3456789a); | ||
801 | + g_assert_cmphex(readl(GPIO(0) + GP_N_OE), ==, 0x3456789a); | ||
802 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DIN), ==, 0x3456789a); | ||
803 | + | ||
804 | + writel(GPIO(0) + GP_N_OEC, 0x00030002); | ||
805 | + g_assert_cmphex(readl(GPIO(0) + GP_N_OE), ==, 0x34547898); | ||
806 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DIN), ==, 0x34547898); | ||
807 | + | ||
808 | + writel(GPIO(0) + GP_N_OES, 0x0000f001); | ||
809 | + g_assert_cmphex(readl(GPIO(0) + GP_N_OE), ==, 0x3454f899); | ||
810 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DIN), ==, 0x3454f899); | ||
811 | +} | ||
812 | + | ||
813 | +static void test_open_drain(void) | ||
814 | +{ | ||
815 | + gpio_reset(0); | ||
816 | + | ||
817 | + /* | ||
818 | + * Upper half of DOUT drives a 1 only if the corresponding bit in OTYP is | ||
819 | + * not set. If OTYP is set, DIN is determined by PU/PD. Lower half of | ||
820 | + * DOUT always drives a 0 regardless of OTYP; PU/PD have no effect. When | ||
821 | + * OE is 0, output is determined by PU/PD; OTYP has no effect. | ||
822 | + */ | ||
823 | + writel(GPIO(0) + GP_N_OTYP, 0x456789ab); | ||
824 | + writel(GPIO(0) + GP_N_OE, 0xf0f0f0f0); | ||
825 | + writel(GPIO(0) + GP_N_DOUT, 0xffff0000); | ||
826 | + writel(GPIO(0) + GP_N_PU, 0xff00ff00); | ||
827 | + writel(GPIO(0) + GP_N_PD, 0x00ff00ff); | ||
828 | + g_assert_cmphex(readl(GPIO(0) + GP_N_OTYP), ==, 0x456789ab); | ||
829 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DIN), ==, 0xff900f00); | ||
830 | +} | ||
831 | + | ||
832 | +static void test_polarity(void) | ||
833 | +{ | ||
834 | + gpio_reset(0); | ||
835 | + | ||
836 | + /* | ||
837 | + * In push-pull mode, DIN should reflect DOUT because the signal is | ||
838 | + * inverted in both directions. | ||
839 | + */ | ||
840 | + writel(GPIO(0) + GP_N_OTYP, 0x00000000); | ||
841 | + writel(GPIO(0) + GP_N_OE, 0xffffffff); | ||
842 | + writel(GPIO(0) + GP_N_DOUT, 0x56789abc); | ||
843 | + writel(GPIO(0) + GP_N_POL, 0x6789abcd); | ||
844 | + g_assert_cmphex(readl(GPIO(0) + GP_N_POL), ==, 0x6789abcd); | ||
845 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DIN), ==, 0x56789abc); | ||
846 | + | ||
847 | + /* | ||
848 | + * When turning off the drivers, DIN should reflect the inverse of the | ||
849 | + * pulled-up lines. | ||
850 | + */ | ||
851 | + writel(GPIO(0) + GP_N_OE, 0x00000000); | ||
852 | + writel(GPIO(0) + GP_N_POL, 0xffffffff); | ||
853 | + writel(GPIO(0) + GP_N_PU, 0x789abcde); | ||
854 | + writel(GPIO(0) + GP_N_PD, ~0x789abcdeU); | ||
855 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DIN), ==, ~0x789abcdeU); | ||
856 | + | ||
857 | + /* | ||
858 | + * In open-drain mode, DOUT=1 will appear to drive the pin high (since DIN | ||
859 | + * is inverted), while DOUT=0 will leave the pin floating. | ||
860 | + */ | ||
861 | + writel(GPIO(0) + GP_N_OTYP, 0xffffffff); | ||
862 | + writel(GPIO(0) + GP_N_OE, 0xffffffff); | ||
863 | + writel(GPIO(0) + GP_N_PU, 0xffff0000); | ||
864 | + writel(GPIO(0) + GP_N_PD, 0x0000ffff); | ||
865 | + writel(GPIO(0) + GP_N_DOUT, 0xff00ff00); | ||
866 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DIN), ==, 0xff00ffff); | ||
867 | +} | ||
868 | + | ||
869 | +static void test_input_mask(void) | ||
870 | +{ | ||
871 | + gpio_reset(0); | ||
872 | + | ||
873 | + /* IEM=0 forces the input to zero before polarity inversion. */ | ||
874 | + writel(GPIO(0) + GP_N_OE, 0xffffffff); | ||
875 | + writel(GPIO(0) + GP_N_DOUT, 0xff00ff00); | ||
876 | + writel(GPIO(0) + GP_N_POL, 0xffff0000); | ||
877 | + writel(GPIO(0) + GP_N_IEM, 0x87654321); | ||
878 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DIN), ==, 0xff9a4300); | ||
879 | +} | ||
880 | + | ||
881 | +static void test_temp_lock(void) | ||
882 | +{ | ||
883 | + gpio_reset(0); | ||
884 | + | ||
885 | + writel(GPIO(0) + GP_N_DOUT, 0x98765432); | ||
886 | + | ||
887 | + /* Make sure we're unlocked initially. */ | ||
888 | + g_assert_cmphex(readl(GPIO(0) + GP_N_TLOCK1), ==, 0); | ||
889 | + /* Writing any value to TLOCK1 will lock. */ | ||
890 | + writel(GPIO(0) + GP_N_TLOCK1, 0); | ||
891 | + g_assert_cmphex(readl(GPIO(0) + GP_N_TLOCK1), ==, 1); | ||
892 | + writel(GPIO(0) + GP_N_DOUT, 0xa9876543); | ||
893 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DOUT), ==, 0x98765432); | ||
894 | + /* Now, try to unlock. */ | ||
895 | + gpio_unlock(0); | ||
896 | + g_assert_cmphex(readl(GPIO(0) + GP_N_TLOCK1), ==, 0); | ||
897 | + writel(GPIO(0) + GP_N_DOUT, 0xa9876543); | ||
898 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DOUT), ==, 0xa9876543); | ||
899 | + | ||
900 | + /* Try it again, but write TLOCK2 to lock. */ | ||
901 | + writel(GPIO(0) + GP_N_TLOCK2, 0); | ||
902 | + g_assert_cmphex(readl(GPIO(0) + GP_N_TLOCK1), ==, 1); | ||
903 | + writel(GPIO(0) + GP_N_DOUT, 0x98765432); | ||
904 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DOUT), ==, 0xa9876543); | ||
905 | + /* Now, try to unlock. */ | ||
906 | + gpio_unlock(0); | ||
907 | + g_assert_cmphex(readl(GPIO(0) + GP_N_TLOCK1), ==, 0); | ||
908 | + writel(GPIO(0) + GP_N_DOUT, 0x98765432); | ||
909 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DOUT), ==, 0x98765432); | ||
910 | +} | ||
911 | + | ||
912 | +static void test_events_level(void) | ||
913 | +{ | ||
914 | + gpio_reset(0); | ||
915 | + | ||
916 | + writel(GPIO(0) + GP_N_EVTYP, 0x00000000); | ||
917 | + writel(GPIO(0) + GP_N_DOUT, 0xba987654); | ||
918 | + writel(GPIO(0) + GP_N_OE, 0xffffffff); | ||
919 | + writel(GPIO(0) + GP_N_EVST, 0xffffffff); | ||
920 | + | ||
921 | + g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0xba987654); | ||
922 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0))); | ||
923 | + writel(GPIO(0) + GP_N_DOUT, 0x00000000); | ||
924 | + g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0xba987654); | ||
925 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0))); | ||
926 | + writel(GPIO(0) + GP_N_EVST, 0x00007654); | ||
927 | + g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0xba980000); | ||
928 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0))); | ||
929 | + writel(GPIO(0) + GP_N_EVST, 0xba980000); | ||
930 | + g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0x00000000); | ||
931 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0))); | ||
932 | +} | ||
933 | + | ||
934 | +static void test_events_rising_edge(void) | ||
935 | +{ | ||
936 | + gpio_reset(0); | ||
937 | + | ||
938 | + writel(GPIO(0) + GP_N_EVTYP, 0xffffffff); | ||
939 | + writel(GPIO(0) + GP_N_EVBE, 0x00000000); | ||
940 | + writel(GPIO(0) + GP_N_DOUT, 0xffff0000); | ||
941 | + writel(GPIO(0) + GP_N_OE, 0xffffffff); | ||
942 | + writel(GPIO(0) + GP_N_EVST, 0xffffffff); | ||
943 | + | ||
944 | + g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0x00000000); | ||
945 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0))); | ||
946 | + writel(GPIO(0) + GP_N_DOUT, 0xff00ff00); | ||
947 | + g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0x0000ff00); | ||
948 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0))); | ||
949 | + writel(GPIO(0) + GP_N_DOUT, 0x00ff0000); | ||
950 | + g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0x00ffff00); | ||
951 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0))); | ||
952 | + writel(GPIO(0) + GP_N_EVST, 0x0000f000); | ||
953 | + g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0x00ff0f00); | ||
954 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0))); | ||
955 | + writel(GPIO(0) + GP_N_EVST, 0x00ff0f00); | ||
956 | + g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0x00000000); | ||
957 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0))); | ||
958 | +} | ||
959 | + | ||
960 | +static void test_events_both_edges(void) | ||
961 | +{ | ||
962 | + gpio_reset(0); | ||
963 | + | ||
964 | + writel(GPIO(0) + GP_N_EVTYP, 0xffffffff); | ||
965 | + writel(GPIO(0) + GP_N_EVBE, 0xffffffff); | ||
966 | + writel(GPIO(0) + GP_N_DOUT, 0xffff0000); | ||
967 | + writel(GPIO(0) + GP_N_OE, 0xffffffff); | ||
968 | + writel(GPIO(0) + GP_N_EVST, 0xffffffff); | ||
969 | + | ||
970 | + g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0x00000000); | ||
971 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0))); | ||
972 | + writel(GPIO(0) + GP_N_DOUT, 0xff00ff00); | ||
973 | + g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0x00ffff00); | ||
974 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0))); | ||
975 | + writel(GPIO(0) + GP_N_DOUT, 0xef00ff08); | ||
976 | + g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0x10ffff08); | ||
977 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0))); | ||
978 | + writel(GPIO(0) + GP_N_EVST, 0x0000f000); | ||
979 | + g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0x10ff0f08); | ||
980 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0))); | ||
981 | + writel(GPIO(0) + GP_N_EVST, 0x10ff0f08); | ||
982 | + g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0x00000000); | ||
983 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0))); | ||
984 | +} | ||
985 | + | ||
986 | +static void test_gpion_irq(gconstpointer test_data) | ||
987 | +{ | ||
988 | + intptr_t n = (intptr_t)test_data; | ||
989 | + | ||
990 | + gpio_reset(n); | ||
991 | + | ||
992 | + writel(GPIO(n) + GP_N_EVTYP, 0x00000000); | ||
993 | + writel(GPIO(n) + GP_N_DOUT, 0x00000000); | ||
994 | + writel(GPIO(n) + GP_N_OE, 0xffffffff); | ||
995 | + writel(GPIO(n) + GP_N_EVST, 0xffffffff); | ||
996 | + writel(GPIO(n) + GP_N_EVEN, 0x00000000); | ||
997 | + | ||
998 | + /* Trigger an event; interrupts are masked. */ | ||
999 | + g_assert_cmphex(readl(GPIO(n) + GP_N_EVST), ==, 0x00000000); | ||
1000 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(n))); | ||
1001 | + writel(GPIO(n) + GP_N_DOS, 0x00008000); | ||
1002 | + g_assert_cmphex(readl(GPIO(n) + GP_N_EVST), ==, 0x00008000); | ||
1003 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(n))); | ||
1004 | + | ||
1005 | + /* Unmask all event interrupts; verify that the interrupt fired. */ | ||
1006 | + writel(GPIO(n) + GP_N_EVEN, 0xffffffff); | ||
1007 | + g_assert_true(qtest_get_irq(global_qtest, GPIO_IRQ(n))); | ||
1008 | + | ||
1009 | + /* Clear the current bit, set a new bit, irq stays asserted. */ | ||
1010 | + writel(GPIO(n) + GP_N_DOC, 0x00008000); | ||
1011 | + g_assert_true(qtest_get_irq(global_qtest, GPIO_IRQ(n))); | ||
1012 | + writel(GPIO(n) + GP_N_DOS, 0x00000200); | ||
1013 | + g_assert_true(qtest_get_irq(global_qtest, GPIO_IRQ(n))); | ||
1014 | + writel(GPIO(n) + GP_N_EVST, 0x00008000); | ||
1015 | + g_assert_true(qtest_get_irq(global_qtest, GPIO_IRQ(n))); | ||
1016 | + | ||
1017 | + /* Mask/unmask the event that's currently active. */ | ||
1018 | + writel(GPIO(n) + GP_N_EVENC, 0x00000200); | ||
1019 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(n))); | ||
1020 | + writel(GPIO(n) + GP_N_EVENS, 0x00000200); | ||
1021 | + g_assert_true(qtest_get_irq(global_qtest, GPIO_IRQ(n))); | ||
1022 | + | ||
1023 | + /* Clear the input and the status bit, irq is deasserted. */ | ||
1024 | + writel(GPIO(n) + GP_N_DOC, 0x00000200); | ||
1025 | + g_assert_true(qtest_get_irq(global_qtest, GPIO_IRQ(n))); | ||
1026 | + writel(GPIO(n) + GP_N_EVST, 0x00000200); | ||
1027 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(n))); | ||
1028 | +} | ||
1029 | + | ||
1030 | +int main(int argc, char **argv) | ||
1031 | +{ | ||
1032 | + int ret; | ||
163 | + int i; | 1033 | + int i; |
164 | + | 1034 | + |
165 | + for (i = 0; i < ARRAY_SIZE(ci->iomem); i++) { | 1035 | + g_test_init(&argc, &argv, NULL); |
166 | + const struct { | 1036 | + g_test_set_nonfatal_assertions(); |
167 | + const char *name; | 1037 | + |
168 | + hwaddr offset; | 1038 | + qtest_add_func("/npcm7xx_gpio/dout_to_din", test_dout_to_din); |
169 | + uint64_t size; | 1039 | + qtest_add_func("/npcm7xx_gpio/pullup_pulldown", test_pullup_pulldown); |
170 | + const struct MemoryRegionOps *ops; | 1040 | + qtest_add_func("/npcm7xx_gpio/output_enable", test_output_enable); |
171 | + } regions[ARRAY_SIZE(ci->iomem)] = { | 1041 | + qtest_add_func("/npcm7xx_gpio/open_drain", test_open_drain); |
172 | + /* | 1042 | + qtest_add_func("/npcm7xx_gpio/polarity", test_polarity); |
173 | + * Registers located between offsets 0x000 and 0xFC | 1043 | + qtest_add_func("/npcm7xx_gpio/input_mask", test_input_mask); |
174 | + */ | 1044 | + qtest_add_func("/npcm7xx_gpio/temp_lock", test_temp_lock); |
175 | + { | 1045 | + qtest_add_func("/npcm7xx_gpio/events/level", test_events_level); |
176 | + .name = TYPE_CHIPIDEA ".misc", | 1046 | + qtest_add_func("/npcm7xx_gpio/events/rising_edge", test_events_rising_edge); |
177 | + .offset = 0x000, | 1047 | + qtest_add_func("/npcm7xx_gpio/events/both_edges", test_events_both_edges); |
178 | + .size = 0x100, | 1048 | + |
179 | + .ops = &chipidea_ops, | 1049 | + for (i = 0; i < NR_GPIO_DEVICES; i++) { |
180 | + }, | 1050 | + g_autofree char *test_name = |
181 | + /* | 1051 | + g_strdup_printf("/npcm7xx_gpio/gpio[%d]/irq", i); |
182 | + * Registers located between offsets 0x1A4 and 0x1DC | 1052 | + qtest_add_data_func(test_name, (void *)(intptr_t)i, test_gpion_irq); |
183 | + */ | ||
184 | + { | ||
185 | + .name = TYPE_CHIPIDEA ".endpoints", | ||
186 | + .offset = 0x1A4, | ||
187 | + .size = 0x1DC - 0x1A4 + 4, | ||
188 | + .ops = &chipidea_ops, | ||
189 | + }, | ||
190 | + /* | ||
191 | + * USB_x_DCIVERSION and USB_x_DCCPARAMS | ||
192 | + */ | ||
193 | + { | ||
194 | + .name = TYPE_CHIPIDEA ".dc", | ||
195 | + .offset = 0x120, | ||
196 | + .size = 8, | ||
197 | + .ops = &chipidea_dc_ops, | ||
198 | + }, | ||
199 | + }; | ||
200 | + | ||
201 | + memory_region_init_io(&ci->iomem[i], | ||
202 | + obj, | ||
203 | + regions[i].ops, | ||
204 | + ci, | ||
205 | + regions[i].name, | ||
206 | + regions[i].size); | ||
207 | + | ||
208 | + memory_region_add_subregion(&ehci->mem, | ||
209 | + regions[i].offset, | ||
210 | + &ci->iomem[i]); | ||
211 | + } | 1053 | + } |
212 | +} | 1054 | + |
213 | + | 1055 | + qtest_start("-machine npcm750-evb"); |
214 | +static void chipidea_class_init(ObjectClass *klass, void *data) | 1056 | + qtest_irq_intercept_in(global_qtest, "/machine/soc/a9mpcore/gic"); |
215 | +{ | 1057 | + ret = g_test_run(); |
216 | + DeviceClass *dc = DEVICE_CLASS(klass); | 1058 | + qtest_end(); |
217 | + SysBusEHCIClass *sec = SYS_BUS_EHCI_CLASS(klass); | 1059 | + |
218 | + | 1060 | + return ret; |
219 | + /* | 1061 | +} |
220 | + * Offsets used were taken from i.MX7Dual Applications Processor | 1062 | diff --git a/hw/gpio/meson.build b/hw/gpio/meson.build |
221 | + * Reference Manual, Rev 0.1, p. 3177, Table 11-59 | 1063 | index XXXXXXX..XXXXXXX 100644 |
222 | + */ | 1064 | --- a/hw/gpio/meson.build |
223 | + sec->capsbase = 0x100; | 1065 | +++ b/hw/gpio/meson.build |
224 | + sec->opregbase = 0x140; | 1066 | @@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_PUV3', if_true: files('puv3_gpio.c')) |
225 | + sec->portnr = 1; | 1067 | softmmu_ss.add(when: 'CONFIG_ZAURUS', if_true: files('zaurus.c')) |
226 | + | 1068 | |
227 | + set_bit(DEVICE_CATEGORY_USB, dc->categories); | 1069 | softmmu_ss.add(when: 'CONFIG_IMX', if_true: files('imx_gpio.c')) |
228 | + dc->desc = "Chipidea USB Module"; | 1070 | +softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_gpio.c')) |
229 | +} | 1071 | softmmu_ss.add(when: 'CONFIG_NRF51_SOC', if_true: files('nrf51_gpio.c')) |
230 | + | 1072 | softmmu_ss.add(when: 'CONFIG_OMAP', if_true: files('omap_gpio.c')) |
231 | +static const TypeInfo chipidea_info = { | 1073 | softmmu_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2835_gpio.c')) |
232 | + .name = TYPE_CHIPIDEA, | 1074 | diff --git a/hw/gpio/trace-events b/hw/gpio/trace-events |
233 | + .parent = TYPE_SYS_BUS_EHCI, | 1075 | index XXXXXXX..XXXXXXX 100644 |
234 | + .instance_size = sizeof(ChipideaState), | 1076 | --- a/hw/gpio/trace-events |
235 | + .instance_init = chipidea_init, | 1077 | +++ b/hw/gpio/trace-events |
236 | + .class_init = chipidea_class_init, | 1078 | @@ -XXX,XX +XXX,XX @@ |
237 | +}; | 1079 | # See docs/devel/tracing.txt for syntax documentation. |
238 | + | 1080 | |
239 | +static void chipidea_register_type(void) | 1081 | +# npcm7xx_gpio.c |
240 | +{ | 1082 | +npcm7xx_gpio_read(const char *id, uint64_t offset, uint64_t value) " %s offset: 0x%04" PRIx64 " value 0x%08" PRIx64 |
241 | + type_register_static(&chipidea_info); | 1083 | +npcm7xx_gpio_write(const char *id, uint64_t offset, uint64_t value) "%s offset: 0x%04" PRIx64 " value 0x%08" PRIx64 |
242 | +} | 1084 | +npcm7xx_gpio_set_input(const char *id, int32_t line, int32_t level) "%s line: %" PRIi32 " level: %" PRIi32 |
243 | +type_init(chipidea_register_type) | 1085 | +npcm7xx_gpio_set_output(const char *id, int32_t line, int32_t level) "%s line: %" PRIi32 " level: %" PRIi32 |
1086 | +npcm7xx_gpio_update_events(const char *id, uint32_t evst, uint32_t even) "%s evst: 0x%08" PRIx32 " even: 0x%08" PRIx32 | ||
1087 | + | ||
1088 | # nrf51_gpio.c | ||
1089 | nrf51_gpio_read(uint64_t offset, uint64_t r) "offset 0x%" PRIx64 " value 0x%" PRIx64 | ||
1090 | nrf51_gpio_write(uint64_t offset, uint64_t value) "offset 0x%" PRIx64 " value 0x%" PRIx64 | ||
1091 | diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build | ||
1092 | index XXXXXXX..XXXXXXX 100644 | ||
1093 | --- a/tests/qtest/meson.build | ||
1094 | +++ b/tests/qtest/meson.build | ||
1095 | @@ -XXX,XX +XXX,XX @@ qtests_sparc64 = \ | ||
1096 | ['prom-env-test', 'boot-serial-test'] | ||
1097 | |||
1098 | qtests_npcm7xx = \ | ||
1099 | - ['npcm7xx_rng-test', | ||
1100 | + ['npcm7xx_gpio-test', | ||
1101 | + 'npcm7xx_rng-test', | ||
1102 | 'npcm7xx_timer-test', | ||
1103 | 'npcm7xx_watchdog_timer-test'] | ||
1104 | qtests_arm = \ | ||
244 | -- | 1105 | -- |
245 | 2.16.1 | 1106 | 2.20.1 |
246 | 1107 | ||
247 | 1108 | diff view generated by jsdifflib |
1 | The code where we added the TT instruction was accidentally | 1 | From: Zenghui Yu <yuzenghui@huawei.com> |
---|---|---|---|
2 | missing a 'break', which meant that after generating the code | ||
3 | to execute the TT we would fall through to 'goto illegal_op' | ||
4 | and generate code to take an UNDEF insn. | ||
5 | 2 | ||
3 | Ensure the vSMMUv3 will be restored before all PCIe devices so that DMA | ||
4 | translation can work properly during migration. | ||
5 | |||
6 | Signed-off-by: Zenghui Yu <yuzenghui@huawei.com> | ||
7 | Message-id: 20201019091508.197-1-yuzenghui@huawei.com | ||
8 | Acked-by: Eric Auger <eric.auger@redhat.com> | ||
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
7 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
8 | Message-id: 20180206103941.13985-1-peter.maydell@linaro.org | ||
9 | --- | 10 | --- |
10 | target/arm/translate.c | 1 + | 11 | hw/arm/smmuv3.c | 1 + |
11 | 1 file changed, 1 insertion(+) | 12 | 1 file changed, 1 insertion(+) |
12 | 13 | ||
13 | diff --git a/target/arm/translate.c b/target/arm/translate.c | 14 | diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c |
14 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/target/arm/translate.c | 16 | --- a/hw/arm/smmuv3.c |
16 | +++ b/target/arm/translate.c | 17 | +++ b/hw/arm/smmuv3.c |
17 | @@ -XXX,XX +XXX,XX @@ static void disas_thumb2_insn(DisasContext *s, uint32_t insn) | 18 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_smmuv3 = { |
18 | tcg_temp_free_i32(addr); | 19 | .name = "smmuv3", |
19 | tcg_temp_free_i32(op); | 20 | .version_id = 1, |
20 | store_reg(s, rd, ttresp); | 21 | .minimum_version_id = 1, |
21 | + break; | 22 | + .priority = MIG_PRI_IOMMU, |
22 | } | 23 | .fields = (VMStateField[]) { |
23 | goto illegal_op; | 24 | VMSTATE_UINT32(features, SMMUv3State), |
24 | } | 25 | VMSTATE_UINT8(sid_size, SMMUv3State), |
25 | -- | 26 | -- |
26 | 2.16.1 | 27 | 2.20.1 |
27 | 28 | ||
28 | 29 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
1 | 2 | ||
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 |
New patch | |||
---|---|---|---|
1 | 1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | |
2 | |||
3 | Remove usage of TypeInfo::class_data. Instead fill the fields in | ||
4 | the corresponding class_init(). | ||
5 | |||
6 | So far all children use the same values for almost all fields, | ||
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 | ||
20 | --- a/hw/arm/bcm2836.c | ||
21 | +++ b/hw/arm/bcm2836.c | ||
22 | @@ -XXX,XX +XXX,XX @@ | ||
23 | #include "hw/arm/raspi_platform.h" | ||
24 | #include "hw/sysbus.h" | ||
25 | |||
26 | -typedef struct BCM283XInfo BCM283XInfo; | ||
27 | - | ||
28 | typedef struct BCM283XClass { | ||
29 | /*< private >*/ | ||
30 | DeviceClass parent_class; | ||
31 | /*< public >*/ | ||
32 | - const BCM283XInfo *info; | ||
33 | -} BCM283XClass; | ||
34 | - | ||
35 | -struct BCM283XInfo { | ||
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 | } | ||
80 | |||
81 | object_initialize_child(obj, "control", &s->control, TYPE_BCM2836_CONTROL); | ||
82 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_realize(DeviceState *dev, Error **errp) | ||
83 | { | ||
84 | BCM283XState *s = BCM283X(dev); | ||
85 | BCM283XClass *bc = BCM283X_GET_CLASS(dev); | ||
86 | - const BCM283XInfo *info = bc->info; | ||
87 | Object *obj; | ||
88 | int n; | ||
89 | |||
90 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_realize(DeviceState *dev, Error **errp) | ||
91 | "sd-bus"); | ||
92 | |||
93 | sysbus_mmio_map_overlap(SYS_BUS_DEVICE(&s->peripherals), 0, | ||
94 | - info->peri_base, 1); | ||
95 | + bc->peri_base, 1); | ||
96 | |||
97 | /* bcm2836 interrupt controller (and mailboxes, etc.) */ | ||
98 | if (!sysbus_realize(SYS_BUS_DEVICE(&s->control), errp)) { | ||
99 | return; | ||
100 | } | ||
101 | |||
102 | - sysbus_mmio_map(SYS_BUS_DEVICE(&s->control), 0, info->ctrl_base); | ||
103 | + sysbus_mmio_map(SYS_BUS_DEVICE(&s->control), 0, bc->ctrl_base); | ||
104 | |||
105 | sysbus_connect_irq(SYS_BUS_DEVICE(&s->peripherals), 0, | ||
106 | qdev_get_gpio_in_named(DEVICE(&s->control), "gpu-irq", 0)); | ||
107 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_realize(DeviceState *dev, Error **errp) | ||
108 | |||
109 | for (n = 0; n < BCM283X_NCPUS; n++) { | ||
110 | /* TODO: this should be converted to a property of ARM_CPU */ | ||
111 | - s->cpu[n].core.mp_affinity = (info->clusterid << 8) | n; | ||
112 | + s->cpu[n].core.mp_affinity = (bc->clusterid << 8) | n; | ||
113 | |||
114 | /* set periphbase/CBAR value for CPU-local registers */ | ||
115 | if (!object_property_set_int(OBJECT(&s->cpu[n].core), "reset-cbar", | ||
116 | - info->peri_base, errp)) { | ||
117 | + bc->peri_base, errp)) { | ||
118 | return; | ||
119 | } | ||
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 | } | ||
133 | |||
134 | -static const TypeInfo bcm283x_type_info = { | ||
135 | - .name = TYPE_BCM283X, | ||
136 | - .parent = TYPE_DEVICE, | ||
137 | - .instance_size = sizeof(BCM283XState), | ||
138 | - .instance_init = bcm2836_init, | ||
139 | - .class_size = sizeof(BCM283XClass), | ||
140 | - .abstract = true, | ||
141 | +static void bcm2836_class_init(ObjectClass *oc, void *data) | ||
142 | +{ | ||
143 | + DeviceClass *dc = DEVICE_CLASS(oc); | ||
144 | + BCM283XClass *bc = BCM283X_CLASS(oc); | ||
145 | + | ||
146 | + bc->cpu_type = ARM_CPU_TYPE_NAME("cortex-a7"); | ||
147 | + bc->peri_base = 0x3f000000; | ||
148 | + bc->ctrl_base = 0x40000000; | ||
149 | + bc->clusterid = 0xf; | ||
150 | + dc->realize = bcm2836_realize; | ||
151 | + device_class_set_props(dc, bcm2836_props); | ||
152 | }; | ||
153 | |||
154 | -static void bcm2836_register_types(void) | ||
155 | +#ifdef TARGET_AARCH64 | ||
156 | +static void bcm2837_class_init(ObjectClass *oc, void *data) | ||
157 | { | ||
158 | - int i; | ||
159 | + DeviceClass *dc = DEVICE_CLASS(oc); | ||
160 | + BCM283XClass *bc = BCM283X_CLASS(oc); | ||
161 | |||
162 | - type_register_static(&bcm283x_type_info); | ||
163 | - for (i = 0; i < ARRAY_SIZE(bcm283x_socs); i++) { | ||
164 | - TypeInfo ti = { | ||
165 | - .name = bcm283x_socs[i].name, | ||
166 | - .parent = TYPE_BCM283X, | ||
167 | - .class_init = bcm283x_class_init, | ||
168 | - .class_data = (void *) &bcm283x_socs[i], | ||
169 | - }; | ||
170 | - type_register(&ti); | ||
171 | + bc->cpu_type = ARM_CPU_TYPE_NAME("cortex-a53"); | ||
172 | + bc->peri_base = 0x3f000000; | ||
173 | + bc->ctrl_base = 0x40000000; | ||
174 | + bc->clusterid = 0x0; | ||
175 | + dc->realize = bcm2836_realize; | ||
176 | + device_class_set_props(dc, bcm2836_props); | ||
177 | +}; | ||
178 | +#endif | ||
179 | + | ||
180 | +static const TypeInfo bcm283x_types[] = { | ||
181 | + { | ||
182 | + .name = TYPE_BCM2836, | ||
183 | + .parent = TYPE_BCM283X, | ||
184 | + .class_init = bcm2836_class_init, | ||
185 | +#ifdef TARGET_AARCH64 | ||
186 | + }, { | ||
187 | + .name = TYPE_BCM2837, | ||
188 | + .parent = TYPE_BCM283X, | ||
189 | + .class_init = bcm2837_class_init, | ||
190 | +#endif | ||
191 | + }, { | ||
192 | + .name = TYPE_BCM283X, | ||
193 | + .parent = TYPE_DEVICE, | ||
194 | + .instance_size = sizeof(BCM283XState), | ||
195 | + .instance_init = bcm2836_init, | ||
196 | + .class_size = sizeof(BCM283XClass), | ||
197 | + .class_init = bcm283x_class_init, | ||
198 | + .abstract = true, | ||
199 | } | ||
200 | -} | ||
201 | +}; | ||
202 | |||
203 | -type_init(bcm2836_register_types) | ||
204 | +DEFINE_TYPES(bcm283x_types) | ||
205 | -- | ||
206 | 2.20.1 | ||
207 | |||
208 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
1 | 2 | ||
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 | The memory writes done to push registers on the stack | 1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> |
---|---|---|---|
2 | on exception entry in M profile CPUs are supposed to | ||
3 | go via MPU permissions checks, which may cause us to | ||
4 | take a derived exception instead of the original one of | ||
5 | the MPU lookup fails. We were implementing these as | ||
6 | always-succeeds direct writes to physical memory. | ||
7 | Rewrite v7m_push_stack() to do the necessary checks. | ||
8 | 2 | ||
3 | It makes no sense to set enabled-cpus=0 on single core SoCs. | ||
4 | |||
5 | Reviewed-by: Luc Michel <luc.michel@greensocs.com> | ||
6 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
7 | Message-id: 20201024170127.3592182-5-f4bug@amsat.org | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
10 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
11 | Message-id: 1517324542-6607-5-git-send-email-peter.maydell@linaro.org | ||
12 | --- | 9 | --- |
13 | target/arm/helper.c | 103 ++++++++++++++++++++++++++++++++++++++++++++-------- | 10 | hw/arm/bcm2836.c | 15 +++++++-------- |
14 | 1 file changed, 87 insertions(+), 16 deletions(-) | 11 | 1 file changed, 7 insertions(+), 8 deletions(-) |
15 | 12 | ||
16 | diff --git a/target/arm/helper.c b/target/arm/helper.c | 13 | diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c |
17 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/target/arm/helper.c | 15 | --- a/hw/arm/bcm2836.c |
19 | +++ b/target/arm/helper.c | 16 | +++ b/hw/arm/bcm2836.c |
20 | @@ -XXX,XX +XXX,XX @@ uint32_t arm_phys_excp_target_el(CPUState *cs, uint32_t excp_idx, | 17 | @@ -XXX,XX +XXX,XX @@ typedef struct BCM283XClass { |
21 | return target_el; | 18 | #define BCM283X_GET_CLASS(obj) \ |
19 | OBJECT_GET_CLASS(BCM283XClass, (obj), TYPE_BCM283X) | ||
20 | |||
21 | +static Property bcm2836_enabled_cores_property = | ||
22 | + DEFINE_PROP_UINT32("enabled-cpus", BCM283XState, enabled_cpus, 0); | ||
23 | + | ||
24 | static void bcm2836_init(Object *obj) | ||
25 | { | ||
26 | BCM283XState *s = BCM283X(obj); | ||
27 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_init(Object *obj) | ||
28 | object_initialize_child(obj, "cpu[*]", &s->cpu[n].core, | ||
29 | bc->cpu_type); | ||
30 | } | ||
31 | + if (bc->core_count > 1) { | ||
32 | + qdev_property_add_static(DEVICE(obj), &bcm2836_enabled_cores_property); | ||
33 | + qdev_prop_set_uint32(DEVICE(obj), "enabled-cpus", bc->core_count); | ||
34 | + } | ||
35 | |||
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 | } | ||
22 | } | 40 | } |
23 | 41 | ||
24 | -static void v7m_push(CPUARMState *env, uint32_t val) | 42 | -static Property bcm2836_props[] = { |
25 | +static bool v7m_stack_write(ARMCPU *cpu, uint32_t addr, uint32_t value, | 43 | - DEFINE_PROP_UINT32("enabled-cpus", BCM283XState, enabled_cpus, |
26 | + ARMMMUIdx mmu_idx, bool ignfault) | 44 | - BCM283X_NCPUS), |
45 | - DEFINE_PROP_END_OF_LIST() | ||
46 | -}; | ||
47 | - | ||
48 | static void bcm283x_class_init(ObjectClass *oc, void *data) | ||
27 | { | 49 | { |
28 | - CPUState *cs = CPU(arm_env_get_cpu(env)); | 50 | DeviceClass *dc = DEVICE_CLASS(oc); |
29 | + CPUState *cs = CPU(cpu); | 51 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_class_init(ObjectClass *oc, void *data) |
30 | + CPUARMState *env = &cpu->env; | 52 | bc->ctrl_base = 0x40000000; |
31 | + MemTxAttrs attrs = {}; | 53 | bc->clusterid = 0xf; |
32 | + MemTxResult txres; | 54 | dc->realize = bcm2836_realize; |
33 | + target_ulong page_size; | 55 | - device_class_set_props(dc, bcm2836_props); |
34 | + hwaddr physaddr; | 56 | }; |
35 | + int prot; | 57 | |
36 | + ARMMMUFaultInfo fi; | 58 | #ifdef TARGET_AARCH64 |
37 | + bool secure = mmu_idx & ARM_MMU_IDX_M_S; | 59 | @@ -XXX,XX +XXX,XX @@ static void bcm2837_class_init(ObjectClass *oc, void *data) |
38 | + int exc; | 60 | bc->ctrl_base = 0x40000000; |
39 | + bool exc_secure; | 61 | bc->clusterid = 0x0; |
40 | 62 | dc->realize = bcm2836_realize; | |
41 | - env->regs[13] -= 4; | 63 | - device_class_set_props(dc, bcm2836_props); |
42 | - stl_phys(cs->as, env->regs[13], val); | 64 | }; |
43 | + if (get_phys_addr(env, addr, MMU_DATA_STORE, mmu_idx, &physaddr, | 65 | #endif |
44 | + &attrs, &prot, &page_size, &fi, NULL)) { | 66 | |
45 | + /* MPU/SAU lookup failed */ | ||
46 | + if (fi.type == ARMFault_QEMU_SFault) { | ||
47 | + qemu_log_mask(CPU_LOG_INT, | ||
48 | + "...SecureFault with SFSR.AUVIOL during stacking\n"); | ||
49 | + env->v7m.sfsr |= R_V7M_SFSR_AUVIOL_MASK | R_V7M_SFSR_SFARVALID_MASK; | ||
50 | + env->v7m.sfar = addr; | ||
51 | + exc = ARMV7M_EXCP_SECURE; | ||
52 | + exc_secure = false; | ||
53 | + } else { | ||
54 | + qemu_log_mask(CPU_LOG_INT, "...MemManageFault with CFSR.MSTKERR\n"); | ||
55 | + env->v7m.cfsr[secure] |= R_V7M_CFSR_MSTKERR_MASK; | ||
56 | + exc = ARMV7M_EXCP_MEM; | ||
57 | + exc_secure = secure; | ||
58 | + } | ||
59 | + goto pend_fault; | ||
60 | + } | ||
61 | + address_space_stl_le(arm_addressspace(cs, attrs), physaddr, value, | ||
62 | + attrs, &txres); | ||
63 | + if (txres != MEMTX_OK) { | ||
64 | + /* BusFault trying to write the data */ | ||
65 | + qemu_log_mask(CPU_LOG_INT, "...BusFault with BFSR.STKERR\n"); | ||
66 | + env->v7m.cfsr[M_REG_NS] |= R_V7M_CFSR_STKERR_MASK; | ||
67 | + exc = ARMV7M_EXCP_BUS; | ||
68 | + exc_secure = false; | ||
69 | + goto pend_fault; | ||
70 | + } | ||
71 | + return true; | ||
72 | + | ||
73 | +pend_fault: | ||
74 | + /* By pending the exception at this point we are making | ||
75 | + * the IMPDEF choice "overridden exceptions pended" (see the | ||
76 | + * MergeExcInfo() pseudocode). The other choice would be to not | ||
77 | + * pend them now and then make a choice about which to throw away | ||
78 | + * later if we have two derived exceptions. | ||
79 | + * The only case when we must not pend the exception but instead | ||
80 | + * throw it away is if we are doing the push of the callee registers | ||
81 | + * and we've already generated a derived exception. Even in this | ||
82 | + * case we will still update the fault status registers. | ||
83 | + */ | ||
84 | + if (!ignfault) { | ||
85 | + armv7m_nvic_set_pending_derived(env->nvic, exc, exc_secure); | ||
86 | + } | ||
87 | + return false; | ||
88 | } | ||
89 | |||
90 | /* Return true if we're using the process stack pointer (not the MSP) */ | ||
91 | @@ -XXX,XX +XXX,XX @@ static bool v7m_push_stack(ARMCPU *cpu) | ||
92 | * should ignore further stack faults trying to process | ||
93 | * that derived exception.) | ||
94 | */ | ||
95 | + bool stacked_ok; | ||
96 | CPUARMState *env = &cpu->env; | ||
97 | uint32_t xpsr = xpsr_read(env); | ||
98 | + uint32_t frameptr = env->regs[13]; | ||
99 | + ARMMMUIdx mmu_idx = core_to_arm_mmu_idx(env, cpu_mmu_index(env, false)); | ||
100 | |||
101 | /* Align stack pointer if the guest wants that */ | ||
102 | - if ((env->regs[13] & 4) && | ||
103 | + if ((frameptr & 4) && | ||
104 | (env->v7m.ccr[env->v7m.secure] & R_V7M_CCR_STKALIGN_MASK)) { | ||
105 | - env->regs[13] -= 4; | ||
106 | + frameptr -= 4; | ||
107 | xpsr |= XPSR_SPREALIGN; | ||
108 | } | ||
109 | - /* Switch to the handler mode. */ | ||
110 | - v7m_push(env, xpsr); | ||
111 | - v7m_push(env, env->regs[15]); | ||
112 | - v7m_push(env, env->regs[14]); | ||
113 | - v7m_push(env, env->regs[12]); | ||
114 | - v7m_push(env, env->regs[3]); | ||
115 | - v7m_push(env, env->regs[2]); | ||
116 | - v7m_push(env, env->regs[1]); | ||
117 | - v7m_push(env, env->regs[0]); | ||
118 | |||
119 | - return false; | ||
120 | + frameptr -= 0x20; | ||
121 | + | ||
122 | + /* Write as much of the stack frame as we can. If we fail a stack | ||
123 | + * write this will result in a derived exception being pended | ||
124 | + * (which may be taken in preference to the one we started with | ||
125 | + * if it has higher priority). | ||
126 | + */ | ||
127 | + stacked_ok = | ||
128 | + v7m_stack_write(cpu, frameptr, env->regs[0], mmu_idx, false) && | ||
129 | + v7m_stack_write(cpu, frameptr + 4, env->regs[1], mmu_idx, false) && | ||
130 | + v7m_stack_write(cpu, frameptr + 8, env->regs[2], mmu_idx, false) && | ||
131 | + v7m_stack_write(cpu, frameptr + 12, env->regs[3], mmu_idx, false) && | ||
132 | + v7m_stack_write(cpu, frameptr + 16, env->regs[12], mmu_idx, false) && | ||
133 | + v7m_stack_write(cpu, frameptr + 20, env->regs[14], mmu_idx, false) && | ||
134 | + v7m_stack_write(cpu, frameptr + 24, env->regs[15], mmu_idx, false) && | ||
135 | + v7m_stack_write(cpu, frameptr + 28, xpsr, mmu_idx, false); | ||
136 | + | ||
137 | + /* Update SP regardless of whether any of the stack accesses failed. | ||
138 | + * When we implement v8M stack limit checking then this attempt to | ||
139 | + * update SP might also fail and result in a derived exception. | ||
140 | + */ | ||
141 | + env->regs[13] = frameptr; | ||
142 | + | ||
143 | + return !stacked_ok; | ||
144 | } | ||
145 | |||
146 | static void do_v7m_exception_exit(ARMCPU *cpu) | ||
147 | -- | 67 | -- |
148 | 2.16.1 | 68 | 2.20.1 |
149 | 69 | ||
150 | 70 | diff view generated by jsdifflib |
1 | Make the load of the exception vector from the vector table honour | 1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> |
---|---|---|---|
2 | the SAU and any bus error on the load (possibly provoking a derived | ||
3 | exception), rather than simply aborting if the load fails. | ||
4 | 2 | ||
3 | The realize() function is clearly composed of two parts, | ||
4 | each described by a comment: | ||
5 | |||
6 | void realize() | ||
7 | { | ||
8 | /* common peripherals from bcm2835 */ | ||
9 | ... | ||
10 | /* bcm2836 interrupt controller (and mailboxes, etc.) */ | ||
11 | ... | ||
12 | } | ||
13 | |||
14 | Split the two part, so we can reuse the common part with other | ||
15 | SoCs from this family. | ||
16 | |||
17 | Reviewed-by: Luc Michel <luc.michel@greensocs.com> | ||
18 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
19 | Message-id: 20201024170127.3592182-6-f4bug@amsat.org | ||
5 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 20 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
6 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | Message-id: 1517324542-6607-7-git-send-email-peter.maydell@linaro.org | ||
8 | --- | 21 | --- |
9 | target/arm/helper.c | 71 +++++++++++++++++++++++++++++++++++++++++------------ | 22 | hw/arm/bcm2836.c | 22 ++++++++++++++++++---- |
10 | 1 file changed, 55 insertions(+), 16 deletions(-) | 23 | 1 file changed, 18 insertions(+), 4 deletions(-) |
11 | 24 | ||
12 | diff --git a/target/arm/helper.c b/target/arm/helper.c | 25 | diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c |
13 | index XXXXXXX..XXXXXXX 100644 | 26 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/target/arm/helper.c | 27 | --- a/hw/arm/bcm2836.c |
15 | +++ b/target/arm/helper.c | 28 | +++ b/hw/arm/bcm2836.c |
16 | @@ -XXX,XX +XXX,XX @@ static uint32_t *get_v7m_sp_ptr(CPUARMState *env, bool secure, bool threadmode, | 29 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_init(Object *obj) |
30 | qdev_prop_set_uint32(DEVICE(obj), "enabled-cpus", bc->core_count); | ||
17 | } | 31 | } |
32 | |||
33 | - object_initialize_child(obj, "control", &s->control, TYPE_BCM2836_CONTROL); | ||
34 | + if (bc->ctrl_base) { | ||
35 | + object_initialize_child(obj, "control", &s->control, | ||
36 | + TYPE_BCM2836_CONTROL); | ||
37 | + } | ||
38 | |||
39 | object_initialize_child(obj, "peripherals", &s->peripherals, | ||
40 | TYPE_BCM2835_PERIPHERALS); | ||
41 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_init(Object *obj) | ||
42 | "vcram-size"); | ||
18 | } | 43 | } |
19 | 44 | ||
20 | -static uint32_t arm_v7m_load_vector(ARMCPU *cpu, int exc, bool targets_secure) | 45 | -static void bcm2836_realize(DeviceState *dev, Error **errp) |
21 | +static bool arm_v7m_load_vector(ARMCPU *cpu, int exc, bool targets_secure, | 46 | +static bool bcm283x_common_realize(DeviceState *dev, Error **errp) |
22 | + uint32_t *pvec) | ||
23 | { | 47 | { |
24 | CPUState *cs = CPU(cpu); | 48 | BCM283XState *s = BCM283X(dev); |
25 | CPUARMState *env = &cpu->env; | 49 | BCM283XClass *bc = BCM283X_GET_CLASS(dev); |
26 | MemTxResult result; | 50 | Object *obj; |
27 | - hwaddr vec = env->v7m.vecbase[targets_secure] + exc * 4; | 51 | - int n; |
28 | - uint32_t addr; | 52 | |
29 | + uint32_t addr = env->v7m.vecbase[targets_secure] + exc * 4; | 53 | /* common peripherals from bcm2835 */ |
30 | + uint32_t vector_entry; | 54 | |
31 | + MemTxAttrs attrs = {}; | 55 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_realize(DeviceState *dev, Error **errp) |
32 | + ARMMMUIdx mmu_idx; | 56 | object_property_add_const_link(OBJECT(&s->peripherals), "ram", obj); |
33 | + bool exc_secure; | 57 | |
58 | if (!sysbus_realize(SYS_BUS_DEVICE(&s->peripherals), errp)) { | ||
59 | - return; | ||
60 | + return false; | ||
61 | } | ||
62 | |||
63 | object_property_add_alias(OBJECT(s), "sd-bus", OBJECT(&s->peripherals), | ||
64 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_realize(DeviceState *dev, Error **errp) | ||
65 | |||
66 | sysbus_mmio_map_overlap(SYS_BUS_DEVICE(&s->peripherals), 0, | ||
67 | bc->peri_base, 1); | ||
68 | + return true; | ||
69 | +} | ||
34 | + | 70 | + |
35 | + mmu_idx = arm_v7m_mmu_idx_for_secstate_and_priv(env, targets_secure, true); | 71 | +static void bcm2836_realize(DeviceState *dev, Error **errp) |
36 | 72 | +{ | |
37 | - addr = address_space_ldl(cs->as, vec, | 73 | + BCM283XState *s = BCM283X(dev); |
38 | - MEMTXATTRS_UNSPECIFIED, &result); | 74 | + BCM283XClass *bc = BCM283X_GET_CLASS(dev); |
39 | + /* We don't do a get_phys_addr() here because the rules for vector | 75 | + int n; |
40 | + * loads are special: they always use the default memory map, and | ||
41 | + * the default memory map permits reads from all addresses. | ||
42 | + * Since there's no easy way to pass through to pmsav8_mpu_lookup() | ||
43 | + * that we want this special case which would always say "yes", | ||
44 | + * we just do the SAU lookup here followed by a direct physical load. | ||
45 | + */ | ||
46 | + attrs.secure = targets_secure; | ||
47 | + attrs.user = false; | ||
48 | + | 76 | + |
49 | + if (arm_feature(env, ARM_FEATURE_M_SECURITY)) { | 77 | + if (!bcm283x_common_realize(dev, errp)) { |
50 | + V8M_SAttributes sattrs = {}; | ||
51 | + | ||
52 | + v8m_security_lookup(env, addr, MMU_DATA_LOAD, mmu_idx, &sattrs); | ||
53 | + if (sattrs.ns) { | ||
54 | + attrs.secure = false; | ||
55 | + } else if (!targets_secure) { | ||
56 | + /* NS access to S memory */ | ||
57 | + goto load_fail; | ||
58 | + } | ||
59 | + } | ||
60 | + | ||
61 | + vector_entry = address_space_ldl(arm_addressspace(cs, attrs), addr, | ||
62 | + attrs, &result); | ||
63 | if (result != MEMTX_OK) { | ||
64 | - /* Architecturally this should cause a HardFault setting HSFR.VECTTBL, | ||
65 | - * which would then be immediately followed by our failing to load | ||
66 | - * the entry vector for that HardFault, which is a Lockup case. | ||
67 | - * Since we don't model Lockup, we just report this guest error | ||
68 | - * via cpu_abort(). | ||
69 | - */ | ||
70 | - cpu_abort(cs, "Failed to read from %s exception vector table " | ||
71 | - "entry %08x\n", targets_secure ? "secure" : "nonsecure", | ||
72 | - (unsigned)vec); | ||
73 | + goto load_fail; | ||
74 | } | ||
75 | - return addr; | ||
76 | + *pvec = vector_entry; | ||
77 | + return true; | ||
78 | + | ||
79 | +load_fail: | ||
80 | + /* All vector table fetch fails are reported as HardFault, with | ||
81 | + * HFSR.VECTTBL and .FORCED set. (FORCED is set because | ||
82 | + * technically the underlying exception is a MemManage or BusFault | ||
83 | + * that is escalated to HardFault.) This is a terminal exception, | ||
84 | + * so we will either take the HardFault immediately or else enter | ||
85 | + * lockup (the latter case is handled in armv7m_nvic_set_pending_derived()). | ||
86 | + */ | ||
87 | + exc_secure = targets_secure || | ||
88 | + !(cpu->env.v7m.aircr & R_V7M_AIRCR_BFHFNMINS_MASK); | ||
89 | + env->v7m.hfsr |= R_V7M_HFSR_VECTTBL_MASK | R_V7M_HFSR_FORCED_MASK; | ||
90 | + armv7m_nvic_set_pending_derived(env->nvic, ARMV7M_EXCP_HARD, exc_secure); | ||
91 | + return false; | ||
92 | } | ||
93 | |||
94 | static bool v7m_push_callee_stack(ARMCPU *cpu, uint32_t lr, bool dotailchain, | ||
95 | @@ -XXX,XX +XXX,XX @@ static void v7m_exception_taken(ARMCPU *cpu, uint32_t lr, bool dotailchain, | ||
96 | return; | ||
97 | } | ||
98 | |||
99 | - addr = arm_v7m_load_vector(cpu, exc, targets_secure); | ||
100 | + if (!arm_v7m_load_vector(cpu, exc, targets_secure, &addr)) { | ||
101 | + /* Vector load failed: derived exception */ | ||
102 | + v7m_exception_taken(cpu, lr, true, true); | ||
103 | + return; | 78 | + return; |
104 | + } | 79 | + } |
105 | 80 | ||
106 | /* Now we've done everything that might cause a derived exception | 81 | /* bcm2836 interrupt controller (and mailboxes, etc.) */ |
107 | * we can go ahead and activate whichever exception we're going to | 82 | if (!sysbus_realize(SYS_BUS_DEVICE(&s->control), errp)) { |
108 | -- | 83 | -- |
109 | 2.16.1 | 84 | 2.20.1 |
110 | 85 | ||
111 | 86 | diff view generated by jsdifflib |
1 | Handle possible MPU faults, SAU faults or bus errors when | 1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> |
---|---|---|---|
2 | popping register state off the stack during exception return. | ||
3 | 2 | ||
3 | Reviewed-by: Luc Michel <luc.michel@greensocs.com> | ||
4 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
5 | Message-id: 20201024170127.3592182-7-f4bug@amsat.org | ||
4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
5 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | Message-id: 1517324542-6607-8-git-send-email-peter.maydell@linaro.org | ||
7 | --- | 7 | --- |
8 | target/arm/helper.c | 115 ++++++++++++++++++++++++++++++++++++++++++---------- | 8 | include/hw/arm/bcm2836.h | 1 + |
9 | 1 file changed, 94 insertions(+), 21 deletions(-) | 9 | hw/arm/bcm2836.c | 34 ++++++++++++++++++++++++++++++++++ |
10 | hw/arm/raspi.c | 2 ++ | ||
11 | 3 files changed, 37 insertions(+) | ||
10 | 12 | ||
11 | diff --git a/target/arm/helper.c b/target/arm/helper.c | 13 | diff --git a/include/hw/arm/bcm2836.h b/include/hw/arm/bcm2836.h |
12 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/target/arm/helper.c | 15 | --- a/include/hw/arm/bcm2836.h |
14 | +++ b/target/arm/helper.c | 16 | +++ b/include/hw/arm/bcm2836.h |
15 | @@ -XXX,XX +XXX,XX @@ pend_fault: | 17 | @@ -XXX,XX +XXX,XX @@ OBJECT_DECLARE_TYPE(BCM283XState, BCM283XClass, BCM283X) |
16 | return false; | 18 | * them, code using these devices should always handle them via the |
19 | * BCM283x base class, so they have no BCM2836(obj) etc macros. | ||
20 | */ | ||
21 | +#define TYPE_BCM2835 "bcm2835" | ||
22 | #define TYPE_BCM2836 "bcm2836" | ||
23 | #define TYPE_BCM2837 "bcm2837" | ||
24 | |||
25 | diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c | ||
26 | index XXXXXXX..XXXXXXX 100644 | ||
27 | --- a/hw/arm/bcm2836.c | ||
28 | +++ b/hw/arm/bcm2836.c | ||
29 | @@ -XXX,XX +XXX,XX @@ static bool bcm283x_common_realize(DeviceState *dev, Error **errp) | ||
30 | return true; | ||
17 | } | 31 | } |
18 | 32 | ||
19 | +static bool v7m_stack_read(ARMCPU *cpu, uint32_t *dest, uint32_t addr, | 33 | +static void bcm2835_realize(DeviceState *dev, Error **errp) |
20 | + ARMMMUIdx mmu_idx) | ||
21 | +{ | 34 | +{ |
22 | + CPUState *cs = CPU(cpu); | 35 | + BCM283XState *s = BCM283X(dev); |
23 | + CPUARMState *env = &cpu->env; | ||
24 | + MemTxAttrs attrs = {}; | ||
25 | + MemTxResult txres; | ||
26 | + target_ulong page_size; | ||
27 | + hwaddr physaddr; | ||
28 | + int prot; | ||
29 | + ARMMMUFaultInfo fi; | ||
30 | + bool secure = mmu_idx & ARM_MMU_IDX_M_S; | ||
31 | + int exc; | ||
32 | + bool exc_secure; | ||
33 | + uint32_t value; | ||
34 | + | 36 | + |
35 | + if (get_phys_addr(env, addr, MMU_DATA_LOAD, mmu_idx, &physaddr, | 37 | + if (!bcm283x_common_realize(dev, errp)) { |
36 | + &attrs, &prot, &page_size, &fi, NULL)) { | 38 | + return; |
37 | + /* MPU/SAU lookup failed */ | ||
38 | + if (fi.type == ARMFault_QEMU_SFault) { | ||
39 | + qemu_log_mask(CPU_LOG_INT, | ||
40 | + "...SecureFault with SFSR.AUVIOL during unstack\n"); | ||
41 | + env->v7m.sfsr |= R_V7M_SFSR_AUVIOL_MASK | R_V7M_SFSR_SFARVALID_MASK; | ||
42 | + env->v7m.sfar = addr; | ||
43 | + exc = ARMV7M_EXCP_SECURE; | ||
44 | + exc_secure = false; | ||
45 | + } else { | ||
46 | + qemu_log_mask(CPU_LOG_INT, | ||
47 | + "...MemManageFault with CFSR.MUNSTKERR\n"); | ||
48 | + env->v7m.cfsr[secure] |= R_V7M_CFSR_MUNSTKERR_MASK; | ||
49 | + exc = ARMV7M_EXCP_MEM; | ||
50 | + exc_secure = secure; | ||
51 | + } | ||
52 | + goto pend_fault; | ||
53 | + } | 39 | + } |
54 | + | 40 | + |
55 | + value = address_space_ldl(arm_addressspace(cs, attrs), physaddr, | 41 | + if (!qdev_realize(DEVICE(&s->cpu[0].core), NULL, errp)) { |
56 | + attrs, &txres); | 42 | + return; |
57 | + if (txres != MEMTX_OK) { | ||
58 | + /* BusFault trying to read the data */ | ||
59 | + qemu_log_mask(CPU_LOG_INT, "...BusFault with BFSR.UNSTKERR\n"); | ||
60 | + env->v7m.cfsr[M_REG_NS] |= R_V7M_CFSR_UNSTKERR_MASK; | ||
61 | + exc = ARMV7M_EXCP_BUS; | ||
62 | + exc_secure = false; | ||
63 | + goto pend_fault; | ||
64 | + } | 43 | + } |
65 | + | 44 | + |
66 | + *dest = value; | 45 | + /* Connect irq/fiq outputs from the interrupt controller. */ |
67 | + return true; | 46 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->peripherals), 0, |
68 | + | 47 | + qdev_get_gpio_in(DEVICE(&s->cpu[0].core), ARM_CPU_IRQ)); |
69 | +pend_fault: | 48 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->peripherals), 1, |
70 | + /* By pending the exception at this point we are making | 49 | + qdev_get_gpio_in(DEVICE(&s->cpu[0].core), ARM_CPU_FIQ)); |
71 | + * the IMPDEF choice "overridden exceptions pended" (see the | ||
72 | + * MergeExcInfo() pseudocode). The other choice would be to not | ||
73 | + * pend them now and then make a choice about which to throw away | ||
74 | + * later if we have two derived exceptions. | ||
75 | + */ | ||
76 | + armv7m_nvic_set_pending(env->nvic, exc, exc_secure); | ||
77 | + return false; | ||
78 | +} | 50 | +} |
79 | + | 51 | + |
80 | /* Return true if we're using the process stack pointer (not the MSP) */ | 52 | static void bcm2836_realize(DeviceState *dev, Error **errp) |
81 | static bool v7m_using_psp(CPUARMState *env) | ||
82 | { | 53 | { |
83 | @@ -XXX,XX +XXX,XX @@ static void do_v7m_exception_exit(ARMCPU *cpu) | 54 | BCM283XState *s = BCM283X(dev); |
84 | !return_to_handler, | 55 | @@ -XXX,XX +XXX,XX @@ static void bcm283x_class_init(ObjectClass *oc, void *data) |
85 | return_to_sp_process); | 56 | dc->user_creatable = false; |
86 | uint32_t frameptr = *frame_sp_p; | 57 | } |
87 | + bool pop_ok = true; | 58 | |
88 | + ARMMMUIdx mmu_idx; | 59 | +static void bcm2835_class_init(ObjectClass *oc, void *data) |
60 | +{ | ||
61 | + DeviceClass *dc = DEVICE_CLASS(oc); | ||
62 | + BCM283XClass *bc = BCM283X_CLASS(oc); | ||
89 | + | 63 | + |
90 | + mmu_idx = arm_v7m_mmu_idx_for_secstate_and_priv(env, return_to_secure, | 64 | + bc->cpu_type = ARM_CPU_TYPE_NAME("arm1176"); |
91 | + !return_to_handler); | 65 | + bc->core_count = 1; |
92 | 66 | + bc->peri_base = 0x20000000; | |
93 | if (!QEMU_IS_ALIGNED(frameptr, 8) && | 67 | + dc->realize = bcm2835_realize; |
94 | arm_feature(env, ARM_FEATURE_V8)) { | 68 | +}; |
95 | @@ -XXX,XX +XXX,XX @@ static void do_v7m_exception_exit(ARMCPU *cpu) | ||
96 | return; | ||
97 | } | ||
98 | |||
99 | - env->regs[4] = ldl_phys(cs->as, frameptr + 0x8); | ||
100 | - env->regs[5] = ldl_phys(cs->as, frameptr + 0xc); | ||
101 | - env->regs[6] = ldl_phys(cs->as, frameptr + 0x10); | ||
102 | - env->regs[7] = ldl_phys(cs->as, frameptr + 0x14); | ||
103 | - env->regs[8] = ldl_phys(cs->as, frameptr + 0x18); | ||
104 | - env->regs[9] = ldl_phys(cs->as, frameptr + 0x1c); | ||
105 | - env->regs[10] = ldl_phys(cs->as, frameptr + 0x20); | ||
106 | - env->regs[11] = ldl_phys(cs->as, frameptr + 0x24); | ||
107 | + pop_ok = | ||
108 | + v7m_stack_read(cpu, &env->regs[4], frameptr + 0x8, mmu_idx) && | ||
109 | + v7m_stack_read(cpu, &env->regs[4], frameptr + 0x8, mmu_idx) && | ||
110 | + v7m_stack_read(cpu, &env->regs[5], frameptr + 0xc, mmu_idx) && | ||
111 | + v7m_stack_read(cpu, &env->regs[6], frameptr + 0x10, mmu_idx) && | ||
112 | + v7m_stack_read(cpu, &env->regs[7], frameptr + 0x14, mmu_idx) && | ||
113 | + v7m_stack_read(cpu, &env->regs[8], frameptr + 0x18, mmu_idx) && | ||
114 | + v7m_stack_read(cpu, &env->regs[9], frameptr + 0x1c, mmu_idx) && | ||
115 | + v7m_stack_read(cpu, &env->regs[10], frameptr + 0x20, mmu_idx) && | ||
116 | + v7m_stack_read(cpu, &env->regs[11], frameptr + 0x24, mmu_idx); | ||
117 | |||
118 | frameptr += 0x28; | ||
119 | } | ||
120 | |||
121 | - /* Pop registers. TODO: make these accesses use the correct | ||
122 | - * attributes and address space (S/NS, priv/unpriv) and handle | ||
123 | - * memory transaction failures. | ||
124 | - */ | ||
125 | - env->regs[0] = ldl_phys(cs->as, frameptr); | ||
126 | - env->regs[1] = ldl_phys(cs->as, frameptr + 0x4); | ||
127 | - env->regs[2] = ldl_phys(cs->as, frameptr + 0x8); | ||
128 | - env->regs[3] = ldl_phys(cs->as, frameptr + 0xc); | ||
129 | - env->regs[12] = ldl_phys(cs->as, frameptr + 0x10); | ||
130 | - env->regs[14] = ldl_phys(cs->as, frameptr + 0x14); | ||
131 | - env->regs[15] = ldl_phys(cs->as, frameptr + 0x18); | ||
132 | + /* Pop registers */ | ||
133 | + pop_ok = pop_ok && | ||
134 | + v7m_stack_read(cpu, &env->regs[0], frameptr, mmu_idx) && | ||
135 | + v7m_stack_read(cpu, &env->regs[1], frameptr + 0x4, mmu_idx) && | ||
136 | + v7m_stack_read(cpu, &env->regs[2], frameptr + 0x8, mmu_idx) && | ||
137 | + v7m_stack_read(cpu, &env->regs[3], frameptr + 0xc, mmu_idx) && | ||
138 | + v7m_stack_read(cpu, &env->regs[12], frameptr + 0x10, mmu_idx) && | ||
139 | + v7m_stack_read(cpu, &env->regs[14], frameptr + 0x14, mmu_idx) && | ||
140 | + v7m_stack_read(cpu, &env->regs[15], frameptr + 0x18, mmu_idx) && | ||
141 | + v7m_stack_read(cpu, &xpsr, frameptr + 0x1c, mmu_idx); | ||
142 | + | 69 | + |
143 | + if (!pop_ok) { | 70 | static void bcm2836_class_init(ObjectClass *oc, void *data) |
144 | + /* v7m_stack_read() pended a fault, so take it (as a tail | 71 | { |
145 | + * chained exception on the same stack frame) | 72 | DeviceClass *dc = DEVICE_CLASS(oc); |
146 | + */ | 73 | @@ -XXX,XX +XXX,XX @@ static void bcm2837_class_init(ObjectClass *oc, void *data) |
147 | + v7m_exception_taken(cpu, excret, true, false); | 74 | |
148 | + return; | 75 | static const TypeInfo bcm283x_types[] = { |
149 | + } | 76 | { |
150 | 77 | + .name = TYPE_BCM2835, | |
151 | /* Returning from an exception with a PC with bit 0 set is defined | 78 | + .parent = TYPE_BCM283X, |
152 | * behaviour on v8M (bit 0 is ignored), but for v7M it was specified | 79 | + .class_init = bcm2835_class_init, |
153 | @@ -XXX,XX +XXX,XX @@ static void do_v7m_exception_exit(ARMCPU *cpu) | 80 | + }, { |
154 | } | 81 | .name = TYPE_BCM2836, |
155 | } | 82 | .parent = TYPE_BCM283X, |
156 | 83 | .class_init = bcm2836_class_init, | |
157 | - xpsr = ldl_phys(cs->as, frameptr + 0x1c); | 84 | diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c |
158 | - | 85 | index XXXXXXX..XXXXXXX 100644 |
159 | if (arm_feature(env, ARM_FEATURE_V8)) { | 86 | --- a/hw/arm/raspi.c |
160 | /* For v8M we have to check whether the xPSR exception field | 87 | +++ b/hw/arm/raspi.c |
161 | * matches the EXCRET value for return to handler/thread | 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 | }; | ||
162 | -- | 104 | -- |
163 | 2.16.1 | 105 | 2.20.1 |
164 | 106 | ||
165 | 107 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
1 | 2 | ||
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 |
1 | From: Andrey Smirnov <andrew.smirnov@gmail.com> | 1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> |
---|---|---|---|
2 | 2 | ||
3 | Add minimal code needed to allow upstream Linux guest to boot. | 3 | Similarly to the Pi A, the Pi Zero uses a BCM2835 SoC (ARMv6Z core). |
4 | 4 | ||
5 | Cc: Peter Maydell <peter.maydell@linaro.org> | 5 | The only difference between the revision 1.2 and 1.3 is the latter |
6 | Cc: Jason Wang <jasowang@redhat.com> | 6 | exposes a CSI camera connector. As we do not implement the Unicam |
7 | Cc: Philippe Mathieu-Daudé <f4bug@amsat.org> | 7 | peripheral, there is no point in exposing a camera connector :) |
8 | Cc: Marcel Apfelbaum <marcel.apfelbaum@zoho.com> | 8 | Therefore we choose to model the 1.2 revision. |
9 | Cc: Michael S. Tsirkin <mst@redhat.com> | 9 | |
10 | Cc: qemu-devel@nongnu.org | 10 | Example booting the machine using content from [*]: |
11 | Cc: qemu-arm@nongnu.org | 11 | |
12 | Cc: yurovsky@gmail.com | 12 | $ qemu-system-arm -M raspi0 -serial stdio \ |
13 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 13 | -kernel raspberrypi/firmware/boot/kernel.img \ |
14 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 14 | -dtb raspberrypi/firmware/boot/bcm2708-rpi-zero.dtb \ |
15 | Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> | 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 | ||
16 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 29 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
17 | --- | 30 | --- |
18 | include/hw/timer/imx_gpt.h | 1 + | 31 | hw/arm/raspi.c | 13 +++++++++++++ |
19 | hw/timer/imx_gpt.c | 25 +++++++++++++++++++++++++ | 32 | 1 file changed, 13 insertions(+) |
20 | 2 files changed, 26 insertions(+) | ||
21 | 33 | ||
22 | diff --git a/include/hw/timer/imx_gpt.h b/include/hw/timer/imx_gpt.h | 34 | diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c |
23 | index XXXXXXX..XXXXXXX 100644 | 35 | index XXXXXXX..XXXXXXX 100644 |
24 | --- a/include/hw/timer/imx_gpt.h | 36 | --- a/hw/arm/raspi.c |
25 | +++ b/include/hw/timer/imx_gpt.h | 37 | +++ b/hw/arm/raspi.c |
26 | @@ -XXX,XX +XXX,XX @@ | 38 | @@ -XXX,XX +XXX,XX @@ static void raspi_machine_class_common_init(MachineClass *mc, |
27 | #define TYPE_IMX25_GPT "imx25.gpt" | 39 | mc->default_ram_id = "ram"; |
28 | #define TYPE_IMX31_GPT "imx31.gpt" | ||
29 | #define TYPE_IMX6_GPT "imx6.gpt" | ||
30 | +#define TYPE_IMX7_GPT "imx7.gpt" | ||
31 | |||
32 | #define TYPE_IMX_GPT TYPE_IMX25_GPT | ||
33 | |||
34 | diff --git a/hw/timer/imx_gpt.c b/hw/timer/imx_gpt.c | ||
35 | index XXXXXXX..XXXXXXX 100644 | ||
36 | --- a/hw/timer/imx_gpt.c | ||
37 | +++ b/hw/timer/imx_gpt.c | ||
38 | @@ -XXX,XX +XXX,XX @@ static const IMXClk imx6_gpt_clocks[] = { | ||
39 | CLK_HIGH, /* 111 reference clock */ | ||
40 | }; | 40 | }; |
41 | 41 | ||
42 | +static const IMXClk imx7_gpt_clocks[] = { | 42 | +static void raspi0_machine_class_init(ObjectClass *oc, void *data) |
43 | + CLK_NONE, /* 000 No clock source */ | 43 | +{ |
44 | + CLK_IPG, /* 001 ipg_clk, 532MHz*/ | 44 | + MachineClass *mc = MACHINE_CLASS(oc); |
45 | + CLK_IPG_HIGH, /* 010 ipg_clk_highfreq */ | 45 | + RaspiMachineClass *rmc = RASPI_MACHINE_CLASS(oc); |
46 | + CLK_EXT, /* 011 External clock */ | 46 | + |
47 | + CLK_32k, /* 100 ipg_clk_32k */ | 47 | + rmc->board_rev = 0x920092; /* Revision 1.2 */ |
48 | + CLK_HIGH, /* 101 reference clock */ | 48 | + raspi_machine_class_common_init(mc, rmc->board_rev); |
49 | + CLK_NONE, /* 110 not defined */ | ||
50 | + CLK_NONE, /* 111 not defined */ | ||
51 | +}; | 49 | +}; |
52 | + | 50 | + |
53 | static void imx_gpt_set_freq(IMXGPTState *s) | 51 | static void raspi1ap_machine_class_init(ObjectClass *oc, void *data) |
54 | { | 52 | { |
55 | uint32_t clksrc = extract32(s->cr, GPT_CR_CLKSRC_SHIFT, 3); | 53 | MachineClass *mc = MACHINE_CLASS(oc); |
56 | @@ -XXX,XX +XXX,XX @@ static void imx6_gpt_init(Object *obj) | 54 | @@ -XXX,XX +XXX,XX @@ static void raspi3b_machine_class_init(ObjectClass *oc, void *data) |
57 | s->clocks = imx6_gpt_clocks; | 55 | |
58 | } | 56 | static const TypeInfo raspi_machine_types[] = { |
59 | 57 | { | |
60 | +static void imx7_gpt_init(Object *obj) | 58 | + .name = MACHINE_TYPE_NAME("raspi0"), |
61 | +{ | 59 | + .parent = TYPE_RASPI_MACHINE, |
62 | + IMXGPTState *s = IMX_GPT(obj); | 60 | + .class_init = raspi0_machine_class_init, |
63 | + | 61 | + }, { |
64 | + s->clocks = imx7_gpt_clocks; | 62 | .name = MACHINE_TYPE_NAME("raspi1ap"), |
65 | +} | 63 | .parent = TYPE_RASPI_MACHINE, |
66 | + | 64 | .class_init = raspi1ap_machine_class_init, |
67 | static const TypeInfo imx25_gpt_info = { | ||
68 | .name = TYPE_IMX25_GPT, | ||
69 | .parent = TYPE_SYS_BUS_DEVICE, | ||
70 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo imx6_gpt_info = { | ||
71 | .instance_init = imx6_gpt_init, | ||
72 | }; | ||
73 | |||
74 | +static const TypeInfo imx7_gpt_info = { | ||
75 | + .name = TYPE_IMX7_GPT, | ||
76 | + .parent = TYPE_IMX25_GPT, | ||
77 | + .instance_init = imx7_gpt_init, | ||
78 | +}; | ||
79 | + | ||
80 | static void imx_gpt_register_types(void) | ||
81 | { | ||
82 | type_register_static(&imx25_gpt_info); | ||
83 | type_register_static(&imx31_gpt_info); | ||
84 | type_register_static(&imx6_gpt_info); | ||
85 | + type_register_static(&imx7_gpt_info); | ||
86 | } | ||
87 | |||
88 | type_init(imx_gpt_register_types) | ||
89 | -- | 65 | -- |
90 | 2.16.1 | 66 | 2.20.1 |
91 | 67 | ||
92 | 68 | diff view generated by jsdifflib |
1 | From: Ard Biesheuvel <ard.biesheuvel@linaro.org> | 1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> |
---|---|---|---|
2 | 2 | ||
3 | This implements emulation of the new SM4 instructions that have | 3 | The Pi 3A+ is a stripped down version of the 3B: |
4 | been added as an optional extension to the ARMv8 Crypto Extensions | 4 | - 512 MiB of RAM instead of 1 GiB |
5 | in ARM v8.2. | 5 | - no on-board ethernet chipset |
6 | 6 | ||
7 | Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> | 7 | Add it as it is a closer match to what we model. |
8 | Message-id: 20180207111729.15737-5-ard.biesheuvel@linaro.org | 8 | |
9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Reviewed-by: Igor Mammedov <imammedo@redhat.com> |
10 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
11 | Message-id: 20201024170127.3592182-10-f4bug@amsat.org | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
11 | --- | 13 | --- |
12 | target/arm/cpu.h | 1 + | 14 | hw/arm/raspi.c | 13 +++++++++++++ |
13 | target/arm/helper.h | 3 ++ | 15 | 1 file changed, 13 insertions(+) |
14 | target/arm/crypto_helper.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++ | ||
15 | target/arm/translate-a64.c | 8 ++++ | ||
16 | 4 files changed, 103 insertions(+) | ||
17 | 16 | ||
18 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | 17 | diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c |
19 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/target/arm/cpu.h | 19 | --- a/hw/arm/raspi.c |
21 | +++ b/target/arm/cpu.h | 20 | +++ b/hw/arm/raspi.c |
22 | @@ -XXX,XX +XXX,XX @@ enum arm_features { | 21 | @@ -XXX,XX +XXX,XX @@ static void raspi2b_machine_class_init(ObjectClass *oc, void *data) |
23 | ARM_FEATURE_V8_SHA512, /* implements SHA512 part of v8 Crypto Extensions */ | ||
24 | ARM_FEATURE_V8_SHA3, /* implements SHA3 part of v8 Crypto Extensions */ | ||
25 | ARM_FEATURE_V8_SM3, /* implements SM3 part of v8 Crypto Extensions */ | ||
26 | + ARM_FEATURE_V8_SM4, /* implements SM4 part of v8 Crypto Extensions */ | ||
27 | }; | 22 | }; |
28 | 23 | ||
29 | static inline int arm_feature(CPUARMState *env, int feature) | 24 | #ifdef TARGET_AARCH64 |
30 | diff --git a/target/arm/helper.h b/target/arm/helper.h | 25 | +static void raspi3ap_machine_class_init(ObjectClass *oc, void *data) |
31 | index XXXXXXX..XXXXXXX 100644 | 26 | +{ |
32 | --- a/target/arm/helper.h | 27 | + MachineClass *mc = MACHINE_CLASS(oc); |
33 | +++ b/target/arm/helper.h | 28 | + RaspiMachineClass *rmc = RASPI_MACHINE_CLASS(oc); |
34 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_5(crypto_sm3tt, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32, i32) | ||
35 | DEF_HELPER_FLAGS_3(crypto_sm3partw1, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) | ||
36 | DEF_HELPER_FLAGS_3(crypto_sm3partw2, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) | ||
37 | |||
38 | +DEF_HELPER_FLAGS_2(crypto_sm4e, TCG_CALL_NO_RWG, void, ptr, ptr) | ||
39 | +DEF_HELPER_FLAGS_3(crypto_sm4ekey, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) | ||
40 | + | 29 | + |
41 | DEF_HELPER_FLAGS_3(crc32, TCG_CALL_NO_RWG_SE, i32, i32, i32, i32) | 30 | + rmc->board_rev = 0x9020e0; /* Revision 1.0 */ |
42 | DEF_HELPER_FLAGS_3(crc32c, TCG_CALL_NO_RWG_SE, i32, i32, i32, i32) | 31 | + raspi_machine_class_common_init(mc, rmc->board_rev); |
43 | DEF_HELPER_2(dc_zva, void, env, i64) | ||
44 | diff --git a/target/arm/crypto_helper.c b/target/arm/crypto_helper.c | ||
45 | index XXXXXXX..XXXXXXX 100644 | ||
46 | --- a/target/arm/crypto_helper.c | ||
47 | +++ b/target/arm/crypto_helper.c | ||
48 | @@ -XXX,XX +XXX,XX @@ void HELPER(crypto_sm3tt)(void *vd, void *vn, void *vm, uint32_t imm2, | ||
49 | rd[0] = d.l[0]; | ||
50 | rd[1] = d.l[1]; | ||
51 | } | ||
52 | + | ||
53 | +static uint8_t const sm4_sbox[] = { | ||
54 | + 0xd6, 0x90, 0xe9, 0xfe, 0xcc, 0xe1, 0x3d, 0xb7, | ||
55 | + 0x16, 0xb6, 0x14, 0xc2, 0x28, 0xfb, 0x2c, 0x05, | ||
56 | + 0x2b, 0x67, 0x9a, 0x76, 0x2a, 0xbe, 0x04, 0xc3, | ||
57 | + 0xaa, 0x44, 0x13, 0x26, 0x49, 0x86, 0x06, 0x99, | ||
58 | + 0x9c, 0x42, 0x50, 0xf4, 0x91, 0xef, 0x98, 0x7a, | ||
59 | + 0x33, 0x54, 0x0b, 0x43, 0xed, 0xcf, 0xac, 0x62, | ||
60 | + 0xe4, 0xb3, 0x1c, 0xa9, 0xc9, 0x08, 0xe8, 0x95, | ||
61 | + 0x80, 0xdf, 0x94, 0xfa, 0x75, 0x8f, 0x3f, 0xa6, | ||
62 | + 0x47, 0x07, 0xa7, 0xfc, 0xf3, 0x73, 0x17, 0xba, | ||
63 | + 0x83, 0x59, 0x3c, 0x19, 0xe6, 0x85, 0x4f, 0xa8, | ||
64 | + 0x68, 0x6b, 0x81, 0xb2, 0x71, 0x64, 0xda, 0x8b, | ||
65 | + 0xf8, 0xeb, 0x0f, 0x4b, 0x70, 0x56, 0x9d, 0x35, | ||
66 | + 0x1e, 0x24, 0x0e, 0x5e, 0x63, 0x58, 0xd1, 0xa2, | ||
67 | + 0x25, 0x22, 0x7c, 0x3b, 0x01, 0x21, 0x78, 0x87, | ||
68 | + 0xd4, 0x00, 0x46, 0x57, 0x9f, 0xd3, 0x27, 0x52, | ||
69 | + 0x4c, 0x36, 0x02, 0xe7, 0xa0, 0xc4, 0xc8, 0x9e, | ||
70 | + 0xea, 0xbf, 0x8a, 0xd2, 0x40, 0xc7, 0x38, 0xb5, | ||
71 | + 0xa3, 0xf7, 0xf2, 0xce, 0xf9, 0x61, 0x15, 0xa1, | ||
72 | + 0xe0, 0xae, 0x5d, 0xa4, 0x9b, 0x34, 0x1a, 0x55, | ||
73 | + 0xad, 0x93, 0x32, 0x30, 0xf5, 0x8c, 0xb1, 0xe3, | ||
74 | + 0x1d, 0xf6, 0xe2, 0x2e, 0x82, 0x66, 0xca, 0x60, | ||
75 | + 0xc0, 0x29, 0x23, 0xab, 0x0d, 0x53, 0x4e, 0x6f, | ||
76 | + 0xd5, 0xdb, 0x37, 0x45, 0xde, 0xfd, 0x8e, 0x2f, | ||
77 | + 0x03, 0xff, 0x6a, 0x72, 0x6d, 0x6c, 0x5b, 0x51, | ||
78 | + 0x8d, 0x1b, 0xaf, 0x92, 0xbb, 0xdd, 0xbc, 0x7f, | ||
79 | + 0x11, 0xd9, 0x5c, 0x41, 0x1f, 0x10, 0x5a, 0xd8, | ||
80 | + 0x0a, 0xc1, 0x31, 0x88, 0xa5, 0xcd, 0x7b, 0xbd, | ||
81 | + 0x2d, 0x74, 0xd0, 0x12, 0xb8, 0xe5, 0xb4, 0xb0, | ||
82 | + 0x89, 0x69, 0x97, 0x4a, 0x0c, 0x96, 0x77, 0x7e, | ||
83 | + 0x65, 0xb9, 0xf1, 0x09, 0xc5, 0x6e, 0xc6, 0x84, | ||
84 | + 0x18, 0xf0, 0x7d, 0xec, 0x3a, 0xdc, 0x4d, 0x20, | ||
85 | + 0x79, 0xee, 0x5f, 0x3e, 0xd7, 0xcb, 0x39, 0x48, | ||
86 | +}; | 32 | +}; |
87 | + | 33 | + |
88 | +void HELPER(crypto_sm4e)(void *vd, void *vn) | 34 | static void raspi3b_machine_class_init(ObjectClass *oc, void *data) |
89 | +{ | 35 | { |
90 | + uint64_t *rd = vd; | 36 | MachineClass *mc = MACHINE_CLASS(oc); |
91 | + uint64_t *rn = vn; | 37 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo raspi_machine_types[] = { |
92 | + union CRYPTO_STATE d = { .l = { rd[0], rd[1] } }; | 38 | .parent = TYPE_RASPI_MACHINE, |
93 | + union CRYPTO_STATE n = { .l = { rn[0], rn[1] } }; | 39 | .class_init = raspi2b_machine_class_init, |
94 | + uint32_t t, i; | 40 | #ifdef TARGET_AARCH64 |
95 | + | 41 | + }, { |
96 | + for (i = 0; i < 4; i++) { | 42 | + .name = MACHINE_TYPE_NAME("raspi3ap"), |
97 | + t = CR_ST_WORD(d, (i + 1) % 4) ^ | 43 | + .parent = TYPE_RASPI_MACHINE, |
98 | + CR_ST_WORD(d, (i + 2) % 4) ^ | 44 | + .class_init = raspi3ap_machine_class_init, |
99 | + CR_ST_WORD(d, (i + 3) % 4) ^ | 45 | }, { |
100 | + CR_ST_WORD(n, i); | 46 | .name = MACHINE_TYPE_NAME("raspi3b"), |
101 | + | 47 | .parent = TYPE_RASPI_MACHINE, |
102 | + t = sm4_sbox[t & 0xff] | | ||
103 | + sm4_sbox[(t >> 8) & 0xff] << 8 | | ||
104 | + sm4_sbox[(t >> 16) & 0xff] << 16 | | ||
105 | + sm4_sbox[(t >> 24) & 0xff] << 24; | ||
106 | + | ||
107 | + CR_ST_WORD(d, i) ^= t ^ rol32(t, 2) ^ rol32(t, 10) ^ rol32(t, 18) ^ | ||
108 | + rol32(t, 24); | ||
109 | + } | ||
110 | + | ||
111 | + rd[0] = d.l[0]; | ||
112 | + rd[1] = d.l[1]; | ||
113 | +} | ||
114 | + | ||
115 | +void HELPER(crypto_sm4ekey)(void *vd, void *vn, void* vm) | ||
116 | +{ | ||
117 | + uint64_t *rd = vd; | ||
118 | + uint64_t *rn = vn; | ||
119 | + uint64_t *rm = vm; | ||
120 | + union CRYPTO_STATE d; | ||
121 | + union CRYPTO_STATE n = { .l = { rn[0], rn[1] } }; | ||
122 | + union CRYPTO_STATE m = { .l = { rm[0], rm[1] } }; | ||
123 | + uint32_t t, i; | ||
124 | + | ||
125 | + d = n; | ||
126 | + for (i = 0; i < 4; i++) { | ||
127 | + t = CR_ST_WORD(d, (i + 1) % 4) ^ | ||
128 | + CR_ST_WORD(d, (i + 2) % 4) ^ | ||
129 | + CR_ST_WORD(d, (i + 3) % 4) ^ | ||
130 | + CR_ST_WORD(m, i); | ||
131 | + | ||
132 | + t = sm4_sbox[t & 0xff] | | ||
133 | + sm4_sbox[(t >> 8) & 0xff] << 8 | | ||
134 | + sm4_sbox[(t >> 16) & 0xff] << 16 | | ||
135 | + sm4_sbox[(t >> 24) & 0xff] << 24; | ||
136 | + | ||
137 | + CR_ST_WORD(d, i) ^= t ^ rol32(t, 13) ^ rol32(t, 23); | ||
138 | + } | ||
139 | + | ||
140 | + rd[0] = d.l[0]; | ||
141 | + rd[1] = d.l[1]; | ||
142 | +} | ||
143 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | ||
144 | index XXXXXXX..XXXXXXX 100644 | ||
145 | --- a/target/arm/translate-a64.c | ||
146 | +++ b/target/arm/translate-a64.c | ||
147 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_three_reg_sha512(DisasContext *s, uint32_t insn) | ||
148 | feature = ARM_FEATURE_V8_SM3; | ||
149 | genfn = gen_helper_crypto_sm3partw2; | ||
150 | break; | ||
151 | + case 2: /* SM4EKEY */ | ||
152 | + feature = ARM_FEATURE_V8_SM4; | ||
153 | + genfn = gen_helper_crypto_sm4ekey; | ||
154 | + break; | ||
155 | default: | ||
156 | unallocated_encoding(s); | ||
157 | return; | ||
158 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_two_reg_sha512(DisasContext *s, uint32_t insn) | ||
159 | feature = ARM_FEATURE_V8_SHA512; | ||
160 | genfn = gen_helper_crypto_sha512su0; | ||
161 | break; | ||
162 | + case 1: /* SM4E */ | ||
163 | + feature = ARM_FEATURE_V8_SM4; | ||
164 | + genfn = gen_helper_crypto_sm4e; | ||
165 | + break; | ||
166 | default: | ||
167 | unallocated_encoding(s); | ||
168 | return; | ||
169 | -- | 48 | -- |
170 | 2.16.1 | 49 | 2.20.1 |
171 | 50 | ||
172 | 51 | diff view generated by jsdifflib |
1 | The documentation for the generic loader claims that you can | 1 | From: "Dr. David Alan Gilbert" <dgilbert@redhat.com> |
---|---|---|---|
2 | set the PC for a CPU with an option of the form | ||
3 | -device loader,cpu-num=0,addr=0x10000004 | ||
4 | 2 | ||
5 | However if you try this QEMU complains: | 3 | Use of 0x%d - make up our mind as 0x%x |
6 | cpu_num must be specified when setting a program counter | ||
7 | 4 | ||
8 | This is because we were testing against 0 rather than CPU_NONE. | 5 | Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com> |
9 | 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 | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
11 | Reviewed-by: Alistair Francis <alistair.francis@xilinx.com> | ||
12 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
13 | Message-id: 20180205150426.20542-1-peter.maydell@linaro.org | ||
14 | --- | 10 | --- |
15 | hw/core/generic-loader.c | 2 +- | 11 | hw/arm/trace-events | 2 +- |
16 | 1 file changed, 1 insertion(+), 1 deletion(-) | 12 | 1 file changed, 1 insertion(+), 1 deletion(-) |
17 | 13 | ||
18 | diff --git a/hw/core/generic-loader.c b/hw/core/generic-loader.c | 14 | diff --git a/hw/arm/trace-events b/hw/arm/trace-events |
19 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/hw/core/generic-loader.c | 16 | --- a/hw/arm/trace-events |
21 | +++ b/hw/core/generic-loader.c | 17 | +++ b/hw/arm/trace-events |
22 | @@ -XXX,XX +XXX,XX @@ static void generic_loader_realize(DeviceState *dev, Error **errp) | 18 | @@ -XXX,XX +XXX,XX @@ smmuv3_get_cd(uint64_t addr) "CD addr: 0x%"PRIx64 |
23 | error_setg(errp, "data can not be specified when setting a " | 19 | smmuv3_decode_cd(uint32_t oas) "oas=%d" |
24 | "program counter"); | 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" |
25 | return; | 21 | smmuv3_cmdq_cfgi_ste(int streamid) "streamid =%d" |
26 | - } else if (!s->cpu_num) { | 22 | -smmuv3_cmdq_cfgi_ste_range(int start, int end) "start=0x%d - end=0x%d" |
27 | + } else if (s->cpu_num == CPU_NONE) { | 23 | +smmuv3_cmdq_cfgi_ste_range(int start, int end) "start=0x%x - end=0x%x" |
28 | error_setg(errp, "cpu_num must be specified when setting a " | 24 | smmuv3_cmdq_cfgi_cd(uint32_t sid) "streamid = %d" |
29 | "program counter"); | 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)" |
30 | return; | 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)" |
31 | -- | 27 | -- |
32 | 2.16.1 | 28 | 2.20.1 |
33 | 29 | ||
34 | 30 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Luc Michel <luc@lmichel.fr> | ||
1 | 2 | ||
3 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
4 | Reviewed-by: Damien Hedde <damien.hedde@greensocs.com> | ||
5 | Signed-off-by: Luc Michel <luc@lmichel.fr> | ||
6 | Tested-by: Guenter Roeck <linux@roeck-us.net> | ||
7 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
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 |
New patch | |||
---|---|---|---|
1 | From: Luc Michel <luc@lmichel.fr> | ||
1 | 2 | ||
3 | The nanosecond unit greatly limits the dynamic range we can display in | ||
4 | clock value traces, for values in the order of 1GHz and more. The | ||
5 | internal representation can go way beyond this value and it is quite | ||
6 | common for today's clocks to be within those ranges. | ||
7 | |||
8 | For example, a frequency between 500MHz+ and 1GHz will be displayed as | ||
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 | ||
27 | --- a/hw/core/clock.c | ||
28 | +++ b/hw/core/clock.c | ||
29 | @@ -XXX,XX +XXX,XX @@ bool clock_set(Clock *clk, uint64_t period) | ||
30 | if (clk->period == period) { | ||
31 | return false; | ||
32 | } | ||
33 | - trace_clock_set(CLOCK_PATH(clk), CLOCK_PERIOD_TO_NS(clk->period), | ||
34 | - CLOCK_PERIOD_TO_NS(period)); | ||
35 | + trace_clock_set(CLOCK_PATH(clk), CLOCK_PERIOD_TO_HZ(clk->period), | ||
36 | + CLOCK_PERIOD_TO_HZ(period)); | ||
37 | clk->period = period; | ||
38 | |||
39 | return true; | ||
40 | @@ -XXX,XX +XXX,XX @@ static void clock_propagate_period(Clock *clk, bool call_callbacks) | ||
41 | if (child->period != clk->period) { | ||
42 | child->period = clk->period; | ||
43 | trace_clock_update(CLOCK_PATH(child), CLOCK_PATH(clk), | ||
44 | - CLOCK_PERIOD_TO_NS(clk->period), | ||
45 | + CLOCK_PERIOD_TO_HZ(clk->period), | ||
46 | call_callbacks); | ||
47 | if (call_callbacks && child->callback) { | ||
48 | child->callback(child->callback_opaque); | ||
49 | diff --git a/hw/core/trace-events b/hw/core/trace-events | ||
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 | -- | ||
63 | 2.20.1 | ||
64 | |||
65 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Luc Michel <luc@lmichel.fr> | ||
1 | 2 | ||
3 | The CPRMAN (clock controller) was mapped at the watchdog/power manager | ||
4 | address. It was also split into two unimplemented peripherals (CM and | ||
5 | A2W) but this is really the same one, as shown by this extract of the | ||
6 | Raspberry Pi 3 Linux device tree: | ||
7 | |||
8 | watchdog@7e100000 { | ||
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 | ||
36 | --- a/include/hw/arm/bcm2835_peripherals.h | ||
37 | +++ b/include/hw/arm/bcm2835_peripherals.h | ||
38 | @@ -XXX,XX +XXX,XX @@ struct BCM2835PeripheralState { | ||
39 | BCM2835MphiState mphi; | ||
40 | UnimplementedDeviceState txp; | ||
41 | UnimplementedDeviceState armtmr; | ||
42 | + UnimplementedDeviceState powermgt; | ||
43 | UnimplementedDeviceState cprman; | ||
44 | - UnimplementedDeviceState a2w; | ||
45 | PL011State uart0; | ||
46 | BCM2835AuxState aux; | ||
47 | BCM2835FBState fb; | ||
48 | diff --git a/include/hw/arm/raspi_platform.h b/include/hw/arm/raspi_platform.h | ||
49 | index XXXXXXX..XXXXXXX 100644 | ||
50 | --- a/include/hw/arm/raspi_platform.h | ||
51 | +++ b/include/hw/arm/raspi_platform.h | ||
52 | @@ -XXX,XX +XXX,XX @@ | ||
53 | #define ARMCTRL_TIMER0_1_OFFSET (ARM_OFFSET + 0x400) /* Timer 0 and 1 (SP804) */ | ||
54 | #define ARMCTRL_0_SBM_OFFSET (ARM_OFFSET + 0x800) /* User 0 (ARM) Semaphores | ||
55 | * Doorbells & Mailboxes */ | ||
56 | -#define CPRMAN_OFFSET 0x100000 /* Power Management, Watchdog */ | ||
57 | -#define CM_OFFSET 0x101000 /* Clock Management */ | ||
58 | -#define A2W_OFFSET 0x102000 /* Reset controller */ | ||
59 | +#define PM_OFFSET 0x100000 /* Power Management */ | ||
60 | +#define CPRMAN_OFFSET 0x101000 /* Clock Management */ | ||
61 | #define AVS_OFFSET 0x103000 /* Audio Video Standard */ | ||
62 | #define RNG_OFFSET 0x104000 | ||
63 | #define GPIO_OFFSET 0x200000 | ||
64 | diff --git a/hw/arm/bcm2835_peripherals.c b/hw/arm/bcm2835_peripherals.c | ||
65 | index XXXXXXX..XXXXXXX 100644 | ||
66 | --- a/hw/arm/bcm2835_peripherals.c | ||
67 | +++ b/hw/arm/bcm2835_peripherals.c | ||
68 | @@ -XXX,XX +XXX,XX @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp) | ||
69 | |||
70 | create_unimp(s, &s->txp, "bcm2835-txp", TXP_OFFSET, 0x1000); | ||
71 | create_unimp(s, &s->armtmr, "bcm2835-sp804", ARMCTRL_TIMER0_1_OFFSET, 0x40); | ||
72 | - create_unimp(s, &s->cprman, "bcm2835-cprman", CPRMAN_OFFSET, 0x1000); | ||
73 | - create_unimp(s, &s->a2w, "bcm2835-a2w", A2W_OFFSET, 0x1000); | ||
74 | + create_unimp(s, &s->powermgt, "bcm2835-powermgt", PM_OFFSET, 0x114); | ||
75 | + create_unimp(s, &s->cprman, "bcm2835-cprman", CPRMAN_OFFSET, 0x2000); | ||
76 | create_unimp(s, &s->i2s, "bcm2835-i2s", I2S_OFFSET, 0x100); | ||
77 | create_unimp(s, &s->smi, "bcm2835-smi", SMI_OFFSET, 0x100); | ||
78 | create_unimp(s, &s->spi[0], "bcm2835-spi0", SPI0_OFFSET, 0x20); | ||
79 | -- | ||
80 | 2.20.1 | ||
81 | |||
82 | diff view generated by jsdifflib |
1 | From: Andrey Smirnov <andrew.smirnov@gmail.com> | 1 | From: Luc Michel <luc@lmichel.fr> |
---|---|---|---|
2 | 2 | ||
3 | Add minimal code needed to allow upstream Linux guest to boot. | 3 | The BCM2835 CPRMAN is the clock manager of the SoC. It is composed of a |
4 | 4 | main oscillator, and several sub-components (PLLs, multiplexers, ...) to | |
5 | Cc: Peter Maydell <peter.maydell@linaro.org> | 5 | generate the BCM2835 clock tree. |
6 | Cc: Jason Wang <jasowang@redhat.com> | 6 | |
7 | Cc: Philippe Mathieu-Daudé <f4bug@amsat.org> | 7 | This commit adds a skeleton of the CPRMAN, with a dummy register |
8 | Cc: Marcel Apfelbaum <marcel.apfelbaum@zoho.com> | 8 | read/write implementation. It embeds the main oscillator (xosc) from |
9 | Cc: Michael S. Tsirkin <mst@redhat.com> | 9 | which all the clocks will be derived. |
10 | Cc: qemu-devel@nongnu.org | 10 | |
11 | Cc: qemu-arm@nongnu.org | 11 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
12 | Cc: yurovsky@gmail.com | 12 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
13 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 13 | Signed-off-by: Luc Michel <luc@lmichel.fr> |
14 | Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> | 14 | Tested-by: Guenter Roeck <linux@roeck-us.net> |
15 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 15 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
16 | --- | 16 | --- |
17 | hw/intc/Makefile.objs | 2 +- | 17 | include/hw/arm/bcm2835_peripherals.h | 3 +- |
18 | include/hw/intc/imx_gpcv2.h | 22 ++++++++ | 18 | include/hw/misc/bcm2835_cprman.h | 37 +++++ |
19 | hw/intc/imx_gpcv2.c | 125 ++++++++++++++++++++++++++++++++++++++++++++ | 19 | include/hw/misc/bcm2835_cprman_internals.h | 24 +++ |
20 | 3 files changed, 148 insertions(+), 1 deletion(-) | 20 | hw/arm/bcm2835_peripherals.c | 11 +- |
21 | create mode 100644 include/hw/intc/imx_gpcv2.h | 21 | hw/misc/bcm2835_cprman.c | 163 +++++++++++++++++++++ |
22 | create mode 100644 hw/intc/imx_gpcv2.c | 22 | hw/misc/meson.build | 1 + |
23 | 23 | hw/misc/trace-events | 5 + | |
24 | diff --git a/hw/intc/Makefile.objs b/hw/intc/Makefile.objs | 24 | 7 files changed, 242 insertions(+), 2 deletions(-) |
25 | create mode 100644 include/hw/misc/bcm2835_cprman.h | ||
26 | create mode 100644 include/hw/misc/bcm2835_cprman_internals.h | ||
27 | create mode 100644 hw/misc/bcm2835_cprman.c | ||
28 | |||
29 | diff --git a/include/hw/arm/bcm2835_peripherals.h b/include/hw/arm/bcm2835_peripherals.h | ||
25 | index XXXXXXX..XXXXXXX 100644 | 30 | index XXXXXXX..XXXXXXX 100644 |
26 | --- a/hw/intc/Makefile.objs | 31 | --- a/include/hw/arm/bcm2835_peripherals.h |
27 | +++ b/hw/intc/Makefile.objs | 32 | +++ b/include/hw/arm/bcm2835_peripherals.h |
28 | @@ -XXX,XX +XXX,XX @@ common-obj-$(CONFIG_XILINX) += xilinx_intc.o | 33 | @@ -XXX,XX +XXX,XX @@ |
29 | common-obj-$(CONFIG_XLNX_ZYNQMP) += xlnx-pmu-iomod-intc.o | 34 | #include "hw/misc/bcm2835_mbox.h" |
30 | common-obj-$(CONFIG_XLNX_ZYNQMP) += xlnx-zynqmp-ipi.o | 35 | #include "hw/misc/bcm2835_mphi.h" |
31 | common-obj-$(CONFIG_ETRAXFS) += etraxfs_pic.o | 36 | #include "hw/misc/bcm2835_thermal.h" |
32 | -common-obj-$(CONFIG_IMX) += imx_avic.o | 37 | +#include "hw/misc/bcm2835_cprman.h" |
33 | +common-obj-$(CONFIG_IMX) += imx_avic.o imx_gpcv2.o | 38 | #include "hw/sd/sdhci.h" |
34 | common-obj-$(CONFIG_LM32) += lm32_pic.o | 39 | #include "hw/sd/bcm2835_sdhost.h" |
35 | common-obj-$(CONFIG_REALVIEW) += realview_gic.o | 40 | #include "hw/gpio/bcm2835_gpio.h" |
36 | common-obj-$(CONFIG_SLAVIO) += slavio_intctl.o | 41 | @@ -XXX,XX +XXX,XX @@ struct BCM2835PeripheralState { |
37 | diff --git a/include/hw/intc/imx_gpcv2.h b/include/hw/intc/imx_gpcv2.h | 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 | ||
38 | new file mode 100644 | 51 | new file mode 100644 |
39 | index XXXXXXX..XXXXXXX | 52 | index XXXXXXX..XXXXXXX |
40 | --- /dev/null | 53 | --- /dev/null |
41 | +++ b/include/hw/intc/imx_gpcv2.h | 54 | +++ b/include/hw/misc/bcm2835_cprman.h |
42 | @@ -XXX,XX +XXX,XX @@ | 55 | @@ -XXX,XX +XXX,XX @@ |
43 | +#ifndef IMX_GPCV2_H | 56 | +/* |
44 | +#define IMX_GPCV2_H | 57 | + * BCM2835 CPRMAN clock manager |
58 | + * | ||
59 | + * Copyright (c) 2020 Luc Michel <luc@lmichel.fr> | ||
60 | + * | ||
61 | + * SPDX-License-Identifier: GPL-2.0-or-later | ||
62 | + */ | ||
63 | + | ||
64 | +#ifndef HW_MISC_CPRMAN_H | ||
65 | +#define HW_MISC_CPRMAN_H | ||
45 | + | 66 | + |
46 | +#include "hw/sysbus.h" | 67 | +#include "hw/sysbus.h" |
47 | + | 68 | +#include "hw/qdev-clock.h" |
48 | +enum IMXGPCv2Registers { | 69 | + |
49 | + GPC_NUM = 0xE00 / sizeof(uint32_t), | 70 | +#define TYPE_BCM2835_CPRMAN "bcm2835-cprman" |
50 | +}; | 71 | + |
51 | + | 72 | +typedef struct BCM2835CprmanState BCM2835CprmanState; |
52 | +typedef struct IMXGPCv2State { | 73 | + |
74 | +DECLARE_INSTANCE_CHECKER(BCM2835CprmanState, CPRMAN, | ||
75 | + TYPE_BCM2835_CPRMAN) | ||
76 | + | ||
77 | +#define CPRMAN_NUM_REGS (0x2000 / sizeof(uint32_t)) | ||
78 | + | ||
79 | +struct BCM2835CprmanState { | ||
53 | + /*< private >*/ | 80 | + /*< private >*/ |
54 | + SysBusDevice parent_obj; | 81 | + SysBusDevice parent_obj; |
55 | + | 82 | + |
56 | + /*< public >*/ | 83 | + /*< public >*/ |
57 | + MemoryRegion iomem; | 84 | + MemoryRegion iomem; |
58 | + uint32_t regs[GPC_NUM]; | 85 | + |
59 | +} IMXGPCv2State; | 86 | + uint32_t regs[CPRMAN_NUM_REGS]; |
60 | + | 87 | + uint32_t xosc_freq; |
61 | +#define TYPE_IMX_GPCV2 "imx-gpcv2" | 88 | + |
62 | +#define IMX_GPCV2(obj) OBJECT_CHECK(IMXGPCv2State, (obj), TYPE_IMX_GPCV2) | 89 | + Clock *xosc; |
63 | + | 90 | +}; |
64 | +#endif /* IMX_GPCV2_H */ | 91 | + |
65 | diff --git a/hw/intc/imx_gpcv2.c b/hw/intc/imx_gpcv2.c | 92 | +#endif |
93 | diff --git a/include/hw/misc/bcm2835_cprman_internals.h b/include/hw/misc/bcm2835_cprman_internals.h | ||
66 | new file mode 100644 | 94 | new file mode 100644 |
67 | index XXXXXXX..XXXXXXX | 95 | index XXXXXXX..XXXXXXX |
68 | --- /dev/null | 96 | --- /dev/null |
69 | +++ b/hw/intc/imx_gpcv2.c | 97 | +++ b/include/hw/misc/bcm2835_cprman_internals.h |
70 | @@ -XXX,XX +XXX,XX @@ | 98 | @@ -XXX,XX +XXX,XX @@ |
71 | +/* | 99 | +/* |
72 | + * Copyright (c) 2018, Impinj, Inc. | 100 | + * BCM2835 CPRMAN clock manager |
73 | + * | 101 | + * |
74 | + * i.MX7 GPCv2 block emulation code | 102 | + * Copyright (c) 2020 Luc Michel <luc@lmichel.fr> |
75 | + * | 103 | + * |
76 | + * Author: Andrey Smirnov <andrew.smirnov@gmail.com> | 104 | + * SPDX-License-Identifier: GPL-2.0-or-later |
77 | + * | 105 | + */ |
78 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | 106 | + |
79 | + * See the COPYING file in the top-level directory. | 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. | ||
80 | + */ | 205 | + */ |
81 | + | 206 | + |
82 | +#include "qemu/osdep.h" | 207 | +#include "qemu/osdep.h" |
83 | +#include "hw/intc/imx_gpcv2.h" | ||
84 | +#include "qemu/log.h" | 208 | +#include "qemu/log.h" |
85 | + | 209 | +#include "migration/vmstate.h" |
86 | +#define GPC_PU_PGC_SW_PUP_REQ 0x0f8 | 210 | +#include "hw/qdev-properties.h" |
87 | +#define GPC_PU_PGC_SW_PDN_REQ 0x104 | 211 | +#include "hw/misc/bcm2835_cprman.h" |
88 | + | 212 | +#include "hw/misc/bcm2835_cprman_internals.h" |
89 | +#define USB_HSIC_PHY_SW_Pxx_REQ BIT(4) | 213 | +#include "trace.h" |
90 | +#define USB_OTG2_PHY_SW_Pxx_REQ BIT(3) | 214 | + |
91 | +#define USB_OTG1_PHY_SW_Pxx_REQ BIT(2) | 215 | +/* CPRMAN "top level" model */ |
92 | +#define PCIE_PHY_SW_Pxx_REQ BIT(1) | 216 | + |
93 | +#define MIPI_PHY_SW_Pxx_REQ BIT(0) | 217 | +static uint64_t cprman_read(void *opaque, hwaddr offset, |
94 | + | 218 | + unsigned size) |
95 | + | 219 | +{ |
96 | +static void imx_gpcv2_reset(DeviceState *dev) | 220 | + BCM2835CprmanState *s = CPRMAN(opaque); |
97 | +{ | 221 | + uint64_t r = 0; |
98 | + IMXGPCv2State *s = IMX_GPCV2(dev); | 222 | + size_t idx = offset / sizeof(uint32_t); |
223 | + | ||
224 | + switch (idx) { | ||
225 | + default: | ||
226 | + r = s->regs[idx]; | ||
227 | + } | ||
228 | + | ||
229 | + trace_bcm2835_cprman_read(offset, r); | ||
230 | + return r; | ||
231 | +} | ||
232 | + | ||
233 | +static void cprman_write(void *opaque, hwaddr offset, | ||
234 | + uint64_t value, unsigned size) | ||
235 | +{ | ||
236 | + BCM2835CprmanState *s = CPRMAN(opaque); | ||
237 | + size_t idx = offset / sizeof(uint32_t); | ||
238 | + | ||
239 | + if (FIELD_EX32(value, CPRMAN, PASSWORD) != CPRMAN_PASSWORD) { | ||
240 | + trace_bcm2835_cprman_write_invalid_magic(offset, value); | ||
241 | + return; | ||
242 | + } | ||
243 | + | ||
244 | + value &= ~R_CPRMAN_PASSWORD_MASK; | ||
245 | + | ||
246 | + trace_bcm2835_cprman_write(offset, value); | ||
247 | + s->regs[idx] = value; | ||
248 | + | ||
249 | +} | ||
250 | + | ||
251 | +static const MemoryRegionOps cprman_ops = { | ||
252 | + .read = cprman_read, | ||
253 | + .write = cprman_write, | ||
254 | + .endianness = DEVICE_LITTLE_ENDIAN, | ||
255 | + .valid = { | ||
256 | + /* | ||
257 | + * Although this hasn't been checked against real hardware, nor the | ||
258 | + * information can be found in a datasheet, it seems reasonable because | ||
259 | + * of the "PASSWORD" magic value found in every registers. | ||
260 | + */ | ||
261 | + .min_access_size = 4, | ||
262 | + .max_access_size = 4, | ||
263 | + .unaligned = false, | ||
264 | + }, | ||
265 | + .impl = { | ||
266 | + .max_access_size = 4, | ||
267 | + }, | ||
268 | +}; | ||
269 | + | ||
270 | +static void cprman_reset(DeviceState *dev) | ||
271 | +{ | ||
272 | + BCM2835CprmanState *s = CPRMAN(dev); | ||
99 | + | 273 | + |
100 | + memset(s->regs, 0, sizeof(s->regs)); | 274 | + memset(s->regs, 0, sizeof(s->regs)); |
101 | +} | 275 | + |
102 | + | 276 | + clock_update_hz(s->xosc, s->xosc_freq); |
103 | +static uint64_t imx_gpcv2_read(void *opaque, hwaddr offset, | 277 | +} |
104 | + unsigned size) | 278 | + |
105 | +{ | 279 | +static void cprman_init(Object *obj) |
106 | + IMXGPCv2State *s = opaque; | 280 | +{ |
107 | + | 281 | + BCM2835CprmanState *s = CPRMAN(obj); |
108 | + return s->regs[offset / sizeof(uint32_t)]; | 282 | + |
109 | +} | 283 | + s->xosc = clock_new(obj, "xosc"); |
110 | + | 284 | + |
111 | +static void imx_gpcv2_write(void *opaque, hwaddr offset, | 285 | + memory_region_init_io(&s->iomem, obj, &cprman_ops, |
112 | + uint64_t value, unsigned size) | 286 | + s, "bcm2835-cprman", 0x2000); |
113 | +{ | 287 | + sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->iomem); |
114 | + IMXGPCv2State *s = opaque; | 288 | +} |
115 | + const size_t idx = offset / sizeof(uint32_t); | 289 | + |
116 | + | 290 | +static const VMStateDescription cprman_vmstate = { |
117 | + s->regs[idx] = value; | 291 | + .name = TYPE_BCM2835_CPRMAN, |
118 | + | ||
119 | + /* | ||
120 | + * Real HW will clear those bits once as a way to indicate that | ||
121 | + * power up request is complete | ||
122 | + */ | ||
123 | + if (offset == GPC_PU_PGC_SW_PUP_REQ || | ||
124 | + offset == GPC_PU_PGC_SW_PDN_REQ) { | ||
125 | + s->regs[idx] &= ~(USB_HSIC_PHY_SW_Pxx_REQ | | ||
126 | + USB_OTG2_PHY_SW_Pxx_REQ | | ||
127 | + USB_OTG1_PHY_SW_Pxx_REQ | | ||
128 | + PCIE_PHY_SW_Pxx_REQ | | ||
129 | + MIPI_PHY_SW_Pxx_REQ); | ||
130 | + } | ||
131 | +} | ||
132 | + | ||
133 | +static const struct MemoryRegionOps imx_gpcv2_ops = { | ||
134 | + .read = imx_gpcv2_read, | ||
135 | + .write = imx_gpcv2_write, | ||
136 | + .endianness = DEVICE_NATIVE_ENDIAN, | ||
137 | + .impl = { | ||
138 | + /* | ||
139 | + * Our device would not work correctly if the guest was doing | ||
140 | + * unaligned access. This might not be a limitation on the real | ||
141 | + * device but in practice there is no reason for a guest to access | ||
142 | + * this device unaligned. | ||
143 | + */ | ||
144 | + .min_access_size = 4, | ||
145 | + .max_access_size = 4, | ||
146 | + .unaligned = false, | ||
147 | + }, | ||
148 | +}; | ||
149 | + | ||
150 | +static void imx_gpcv2_init(Object *obj) | ||
151 | +{ | ||
152 | + SysBusDevice *sd = SYS_BUS_DEVICE(obj); | ||
153 | + IMXGPCv2State *s = IMX_GPCV2(obj); | ||
154 | + | ||
155 | + memory_region_init_io(&s->iomem, | ||
156 | + obj, | ||
157 | + &imx_gpcv2_ops, | ||
158 | + s, | ||
159 | + TYPE_IMX_GPCV2 ".iomem", | ||
160 | + sizeof(s->regs)); | ||
161 | + sysbus_init_mmio(sd, &s->iomem); | ||
162 | +} | ||
163 | + | ||
164 | +static const VMStateDescription vmstate_imx_gpcv2 = { | ||
165 | + .name = TYPE_IMX_GPCV2, | ||
166 | + .version_id = 1, | 292 | + .version_id = 1, |
167 | + .minimum_version_id = 1, | 293 | + .minimum_version_id = 1, |
168 | + .fields = (VMStateField[]) { | 294 | + .fields = (VMStateField[]) { |
169 | + VMSTATE_UINT32_ARRAY(regs, IMXGPCv2State, GPC_NUM), | 295 | + VMSTATE_UINT32_ARRAY(regs, BCM2835CprmanState, CPRMAN_NUM_REGS), |
170 | + VMSTATE_END_OF_LIST() | 296 | + VMSTATE_END_OF_LIST() |
171 | + }, | 297 | + } |
172 | +}; | 298 | +}; |
173 | + | 299 | + |
174 | +static void imx_gpcv2_class_init(ObjectClass *klass, void *data) | 300 | +static Property cprman_properties[] = { |
301 | + DEFINE_PROP_UINT32("xosc-freq-hz", BCM2835CprmanState, xosc_freq, 19200000), | ||
302 | + DEFINE_PROP_END_OF_LIST() | ||
303 | +}; | ||
304 | + | ||
305 | +static void cprman_class_init(ObjectClass *klass, void *data) | ||
175 | +{ | 306 | +{ |
176 | + DeviceClass *dc = DEVICE_CLASS(klass); | 307 | + DeviceClass *dc = DEVICE_CLASS(klass); |
177 | + | 308 | + |
178 | + dc->reset = imx_gpcv2_reset; | 309 | + dc->reset = cprman_reset; |
179 | + dc->vmsd = &vmstate_imx_gpcv2; | 310 | + dc->vmsd = &cprman_vmstate; |
180 | + dc->desc = "i.MX GPCv2 Module"; | 311 | + device_class_set_props(dc, cprman_properties); |
181 | +} | 312 | +} |
182 | + | 313 | + |
183 | +static const TypeInfo imx_gpcv2_info = { | 314 | +static const TypeInfo cprman_info = { |
184 | + .name = TYPE_IMX_GPCV2, | 315 | + .name = TYPE_BCM2835_CPRMAN, |
185 | + .parent = TYPE_SYS_BUS_DEVICE, | 316 | + .parent = TYPE_SYS_BUS_DEVICE, |
186 | + .instance_size = sizeof(IMXGPCv2State), | 317 | + .instance_size = sizeof(BCM2835CprmanState), |
187 | + .instance_init = imx_gpcv2_init, | 318 | + .class_init = cprman_class_init, |
188 | + .class_init = imx_gpcv2_class_init, | 319 | + .instance_init = cprman_init, |
189 | +}; | 320 | +}; |
190 | + | 321 | + |
191 | +static void imx_gpcv2_register_type(void) | 322 | +static void cprman_register_types(void) |
192 | +{ | 323 | +{ |
193 | + type_register_static(&imx_gpcv2_info); | 324 | + type_register_static(&cprman_info); |
194 | +} | 325 | +} |
195 | +type_init(imx_gpcv2_register_type) | 326 | + |
327 | +type_init(cprman_register_types); | ||
328 | diff --git a/hw/misc/meson.build b/hw/misc/meson.build | ||
329 | index XXXXXXX..XXXXXXX 100644 | ||
330 | --- a/hw/misc/meson.build | ||
331 | +++ b/hw/misc/meson.build | ||
332 | @@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_RASPI', if_true: files( | ||
333 | 'bcm2835_property.c', | ||
334 | 'bcm2835_rng.c', | ||
335 | 'bcm2835_thermal.c', | ||
336 | + 'bcm2835_cprman.c', | ||
337 | )) | ||
338 | softmmu_ss.add(when: 'CONFIG_SLAVIO', if_true: files('slavio_misc.c')) | ||
339 | softmmu_ss.add(when: 'CONFIG_ZYNQ', if_true: files('zynq_slcr.c', 'zynq-xadc.c')) | ||
340 | diff --git a/hw/misc/trace-events b/hw/misc/trace-events | ||
341 | index XXXXXXX..XXXXXXX 100644 | ||
342 | --- a/hw/misc/trace-events | ||
343 | +++ b/hw/misc/trace-events | ||
344 | @@ -XXX,XX +XXX,XX @@ grlib_apb_pnp_read(uint64_t addr, uint32_t value) "APB PnP read addr:0x%03"PRIx6 | ||
345 | # pca9552.c | ||
346 | pca955x_gpio_status(const char *description, const char *buf) "%s GPIOs 0-15 [%s]" | ||
347 | pca955x_gpio_change(const char *description, unsigned id, unsigned prev_state, unsigned current_state) "%s GPIO id:%u status: %u -> %u" | ||
348 | + | ||
349 | +# bcm2835_cprman.c | ||
350 | +bcm2835_cprman_read(uint64_t offset, uint64_t value) "offset:0x%" PRIx64 " value:0x%" PRIx64 | ||
351 | +bcm2835_cprman_write(uint64_t offset, uint64_t value) "offset:0x%" PRIx64 " value:0x%" PRIx64 | ||
352 | +bcm2835_cprman_write_invalid_magic(uint64_t offset, uint64_t value) "offset:0x%" PRIx64 " value:0x%" PRIx64 | ||
196 | -- | 353 | -- |
197 | 2.16.1 | 354 | 2.20.1 |
198 | 355 | ||
199 | 356 | diff view generated by jsdifflib |
1 | From: Andrey Smirnov <andrew.smirnov@gmail.com> | 1 | From: Luc Michel <luc@lmichel.fr> |
---|---|---|---|
2 | 2 | ||
3 | IP block found on several generations of i.MX family does not use | 3 | There are 5 PLLs in the CPRMAN, namely PLL A, C, D, H and B. All of them |
4 | vanilla SDHCI implementation and it comes with a number of quirks. | 4 | take the xosc clock as input and produce a new clock. |
5 | 5 | ||
6 | Introduce i.MX SDHCI subtype of SDHCI block to add code necessary to | 6 | This commit adds a skeleton implementation for the PLLs as sub-devices |
7 | support unmodified Linux guest driver. | 7 | of the CPRMAN. The PLLs are instantiated and connected internally to the |
8 | 8 | main oscillator. | |
9 | Cc: Peter Maydell <peter.maydell@linaro.org> | 9 | |
10 | Cc: Jason Wang <jasowang@redhat.com> | 10 | Each PLL has 6 registers : CM, A2W_CTRL, A2W_ANA[0,1,2,3], A2W_FRAC. A |
11 | Cc: Philippe Mathieu-Daudé <f4bug@amsat.org> | 11 | write to any of them triggers a call to the (not yet implemented) |
12 | Cc: Marcel Apfelbaum <marcel.apfelbaum@zoho.com> | 12 | pll_update function. |
13 | Cc: Michael S. Tsirkin <mst@redhat.com> | 13 | |
14 | Cc: qemu-devel@nongnu.org | 14 | If the main oscillator changes frequency, an update is also triggered. |
15 | Cc: qemu-arm@nongnu.org | 15 | |
16 | Cc: yurovsky@gmail.com | ||
17 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
18 | Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> | ||
19 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 16 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
20 | [PMM: define and use ESDHC_UNDOCUMENTED_REG27] | 17 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
18 | Signed-off-by: Luc Michel <luc@lmichel.fr> | ||
19 | Tested-by: Guenter Roeck <linux@roeck-us.net> | ||
21 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 20 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
22 | --- | 21 | --- |
23 | hw/sd/sdhci-internal.h | 23 +++++ | 22 | include/hw/misc/bcm2835_cprman.h | 29 +++++ |
24 | include/hw/sd/sdhci.h | 13 +++ | 23 | include/hw/misc/bcm2835_cprman_internals.h | 144 +++++++++++++++++++++ |
25 | hw/sd/sdhci.c | 230 ++++++++++++++++++++++++++++++++++++++++++++++++- | 24 | hw/misc/bcm2835_cprman.c | 108 ++++++++++++++++ |
26 | 3 files changed, 265 insertions(+), 1 deletion(-) | 25 | 3 files changed, 281 insertions(+) |
27 | 26 | ||
28 | diff --git a/hw/sd/sdhci-internal.h b/hw/sd/sdhci-internal.h | 27 | diff --git a/include/hw/misc/bcm2835_cprman.h b/include/hw/misc/bcm2835_cprman.h |
29 | index XXXXXXX..XXXXXXX 100644 | 28 | index XXXXXXX..XXXXXXX 100644 |
30 | --- a/hw/sd/sdhci-internal.h | 29 | --- a/include/hw/misc/bcm2835_cprman.h |
31 | +++ b/hw/sd/sdhci-internal.h | 30 | +++ b/include/hw/misc/bcm2835_cprman.h |
31 | @@ -XXX,XX +XXX,XX @@ DECLARE_INSTANCE_CHECKER(BCM2835CprmanState, CPRMAN, | ||
32 | |||
33 | #define CPRMAN_NUM_REGS (0x2000 / sizeof(uint32_t)) | ||
34 | |||
35 | +typedef enum CprmanPll { | ||
36 | + CPRMAN_PLLA = 0, | ||
37 | + CPRMAN_PLLC, | ||
38 | + CPRMAN_PLLD, | ||
39 | + CPRMAN_PLLH, | ||
40 | + CPRMAN_PLLB, | ||
41 | + | ||
42 | + CPRMAN_NUM_PLL | ||
43 | +} CprmanPll; | ||
44 | + | ||
45 | +typedef struct CprmanPllState { | ||
46 | + /*< private >*/ | ||
47 | + DeviceState parent_obj; | ||
48 | + | ||
49 | + /*< public >*/ | ||
50 | + CprmanPll id; | ||
51 | + | ||
52 | + uint32_t *reg_cm; | ||
53 | + uint32_t *reg_a2w_ctrl; | ||
54 | + uint32_t *reg_a2w_ana; /* ANA[0] .. ANA[3] */ | ||
55 | + uint32_t prediv_mask; /* prediv bit in ana[1] */ | ||
56 | + uint32_t *reg_a2w_frac; | ||
57 | + | ||
58 | + Clock *xosc_in; | ||
59 | + Clock *out; | ||
60 | +} CprmanPllState; | ||
61 | + | ||
62 | struct BCM2835CprmanState { | ||
63 | /*< private >*/ | ||
64 | SysBusDevice parent_obj; | ||
65 | @@ -XXX,XX +XXX,XX @@ struct BCM2835CprmanState { | ||
66 | /*< public >*/ | ||
67 | MemoryRegion iomem; | ||
68 | |||
69 | + CprmanPllState plls[CPRMAN_NUM_PLL]; | ||
70 | + | ||
71 | uint32_t regs[CPRMAN_NUM_REGS]; | ||
72 | uint32_t xosc_freq; | ||
73 | |||
74 | diff --git a/include/hw/misc/bcm2835_cprman_internals.h b/include/hw/misc/bcm2835_cprman_internals.h | ||
75 | index XXXXXXX..XXXXXXX 100644 | ||
76 | --- a/include/hw/misc/bcm2835_cprman_internals.h | ||
77 | +++ b/include/hw/misc/bcm2835_cprman_internals.h | ||
32 | @@ -XXX,XX +XXX,XX @@ | 78 | @@ -XXX,XX +XXX,XX @@ |
33 | 79 | #include "hw/registerfields.h" | |
34 | /* R/W Host control Register 0x0 */ | 80 | #include "hw/misc/bcm2835_cprman.h" |
35 | #define SDHC_HOSTCTL 0x28 | 81 | |
36 | +#define SDHC_CTRL_LED 0x01 | 82 | +#define TYPE_CPRMAN_PLL "bcm2835-cprman-pll" |
37 | #define SDHC_CTRL_DMA_CHECK_MASK 0x18 | 83 | + |
38 | #define SDHC_CTRL_SDMA 0x00 | 84 | +DECLARE_INSTANCE_CHECKER(CprmanPllState, CPRMAN_PLL, |
39 | #define SDHC_CTRL_ADMA1_32 0x08 | 85 | + TYPE_CPRMAN_PLL) |
40 | #define SDHC_CTRL_ADMA2_32 0x10 | 86 | + |
41 | #define SDHC_CTRL_ADMA2_64 0x18 | 87 | /* Register map */ |
42 | #define SDHC_DMA_TYPE(x) ((x) & SDHC_CTRL_DMA_CHECK_MASK) | 88 | |
43 | +#define SDHC_CTRL_4BITBUS 0x02 | 89 | +/* PLLs */ |
44 | +#define SDHC_CTRL_8BITBUS 0x20 | 90 | +REG32(CM_PLLA, 0x104) |
45 | +#define SDHC_CTRL_CDTEST_INS 0x40 | 91 | + FIELD(CM_PLLA, LOADDSI0, 0, 1) |
46 | +#define SDHC_CTRL_CDTEST_EN 0x80 | 92 | + FIELD(CM_PLLA, HOLDDSI0, 1, 1) |
47 | + | 93 | + FIELD(CM_PLLA, LOADCCP2, 2, 1) |
48 | 94 | + FIELD(CM_PLLA, HOLDCCP2, 3, 1) | |
49 | /* R/W Power Control Register 0x0 */ | 95 | + FIELD(CM_PLLA, LOADCORE, 4, 1) |
50 | #define SDHC_PWRCON 0x29 | 96 | + FIELD(CM_PLLA, HOLDCORE, 5, 1) |
51 | @@ -XXX,XX +XXX,XX @@ enum { | 97 | + FIELD(CM_PLLA, LOADPER, 6, 1) |
52 | sdhc_gap_write = 2 /* SDHC stopped at block gap during write operation */ | 98 | + FIELD(CM_PLLA, HOLDPER, 7, 1) |
53 | }; | 99 | + FIELD(CM_PLLx, ANARST, 8, 1) |
54 | 100 | +REG32(CM_PLLC, 0x108) | |
55 | +extern const VMStateDescription sdhci_vmstate; | 101 | + FIELD(CM_PLLC, LOADCORE0, 0, 1) |
56 | + | 102 | + FIELD(CM_PLLC, HOLDCORE0, 1, 1) |
57 | + | 103 | + FIELD(CM_PLLC, LOADCORE1, 2, 1) |
58 | +#define ESDHC_MIX_CTRL 0x48 | 104 | + FIELD(CM_PLLC, HOLDCORE1, 3, 1) |
59 | +#define ESDHC_VENDOR_SPEC 0xc0 | 105 | + FIELD(CM_PLLC, LOADCORE2, 4, 1) |
60 | +#define ESDHC_DLL_CTRL 0x60 | 106 | + FIELD(CM_PLLC, HOLDCORE2, 5, 1) |
61 | + | 107 | + FIELD(CM_PLLC, LOADPER, 6, 1) |
62 | +#define ESDHC_TUNING_CTRL 0xcc | 108 | + FIELD(CM_PLLC, HOLDPER, 7, 1) |
63 | +#define ESDHC_TUNE_CTRL_STATUS 0x68 | 109 | +REG32(CM_PLLD, 0x10c) |
64 | +#define ESDHC_WTMK_LVL 0x44 | 110 | + FIELD(CM_PLLD, LOADDSI0, 0, 1) |
65 | + | 111 | + FIELD(CM_PLLD, HOLDDSI0, 1, 1) |
66 | +/* Undocumented register used by guests working around erratum ERR004536 */ | 112 | + FIELD(CM_PLLD, LOADDSI1, 2, 1) |
67 | +#define ESDHC_UNDOCUMENTED_REG27 0x6c | 113 | + FIELD(CM_PLLD, HOLDDSI1, 3, 1) |
68 | + | 114 | + FIELD(CM_PLLD, LOADCORE, 4, 1) |
69 | +#define ESDHC_CTRL_4BITBUS (0x1 << 1) | 115 | + FIELD(CM_PLLD, HOLDCORE, 5, 1) |
70 | +#define ESDHC_CTRL_8BITBUS (0x2 << 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 | +} | ||
71 | + | 234 | + |
72 | #endif | 235 | #endif |
73 | diff --git a/include/hw/sd/sdhci.h b/include/hw/sd/sdhci.h | 236 | diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c |
74 | index XXXXXXX..XXXXXXX 100644 | 237 | index XXXXXXX..XXXXXXX 100644 |
75 | --- a/include/hw/sd/sdhci.h | 238 | --- a/hw/misc/bcm2835_cprman.c |
76 | +++ b/include/hw/sd/sdhci.h | 239 | +++ b/hw/misc/bcm2835_cprman.c |
77 | @@ -XXX,XX +XXX,XX @@ typedef struct SDHCIState { | 240 | @@ -XXX,XX +XXX,XX @@ |
78 | AddressSpace sysbus_dma_as; | 241 | #include "hw/misc/bcm2835_cprman_internals.h" |
79 | AddressSpace *dma_as; | 242 | #include "trace.h" |
80 | MemoryRegion *dma_mr; | 243 | |
81 | + const MemoryRegionOps *io_ops; | 244 | +/* PLL */ |
82 | 245 | + | |
83 | QEMUTimer *insert_timer; /* timer for 'changing' sd card. */ | 246 | +static void pll_update(CprmanPllState *pll) |
84 | QEMUTimer *transfer_timer; | 247 | +{ |
85 | @@ -XXX,XX +XXX,XX @@ typedef struct SDHCIState { | 248 | + clock_update(pll->out, 0); |
86 | 249 | +} | |
87 | /* Configurable properties */ | 250 | + |
88 | bool pending_insert_quirk; /* Quirk for Raspberry Pi card insert int */ | 251 | +static void pll_xosc_update(void *opaque) |
89 | + uint32_t quirks; | 252 | +{ |
90 | } SDHCIState; | 253 | + pll_update(CPRMAN_PLL(opaque)); |
91 | 254 | +} | |
92 | +/* | 255 | + |
93 | + * Controller does not provide transfer-complete interrupt when not | 256 | +static void pll_init(Object *obj) |
94 | + * busy. | 257 | +{ |
95 | + * | 258 | + CprmanPllState *s = CPRMAN_PLL(obj); |
96 | + * NOTE: This definition is taken out of Linux kernel and so the | 259 | + |
97 | + * original bit number is preserved | 260 | + s->xosc_in = qdev_init_clock_in(DEVICE(s), "xosc-in", pll_xosc_update, s); |
98 | + */ | 261 | + s->out = qdev_init_clock_out(DEVICE(s), "out"); |
99 | +#define SDHCI_QUIRK_NO_BUSY_IRQ BIT(14) | 262 | +} |
100 | + | 263 | + |
101 | #define TYPE_PCI_SDHCI "sdhci-pci" | 264 | +static const VMStateDescription pll_vmstate = { |
102 | #define PCI_SDHCI(obj) OBJECT_CHECK(SDHCIState, (obj), TYPE_PCI_SDHCI) | 265 | + .name = TYPE_CPRMAN_PLL, |
103 | 266 | + .version_id = 1, | |
104 | @@ -XXX,XX +XXX,XX @@ typedef struct SDHCIState { | 267 | + .minimum_version_id = 1, |
105 | #define SYSBUS_SDHCI(obj) \ | 268 | + .fields = (VMStateField[]) { |
106 | OBJECT_CHECK(SDHCIState, (obj), TYPE_SYSBUS_SDHCI) | 269 | + VMSTATE_CLOCK(xosc_in, CprmanPllState), |
107 | 270 | + VMSTATE_END_OF_LIST() | |
108 | +#define TYPE_IMX_USDHC "imx-usdhc" | 271 | + } |
109 | + | 272 | +}; |
110 | #endif /* SDHCI_H */ | 273 | + |
111 | diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c | 274 | +static void pll_class_init(ObjectClass *klass, void *data) |
112 | index XXXXXXX..XXXXXXX 100644 | 275 | +{ |
113 | --- a/hw/sd/sdhci.c | 276 | + DeviceClass *dc = DEVICE_CLASS(klass); |
114 | +++ b/hw/sd/sdhci.c | 277 | + |
115 | @@ -XXX,XX +XXX,XX @@ static void sdhci_send_command(SDHCIState *s) | 278 | + dc->vmsd = &pll_vmstate; |
116 | } | 279 | +} |
117 | } | 280 | + |
118 | 281 | +static const TypeInfo cprman_pll_info = { | |
119 | - if ((s->norintstsen & SDHC_NISEN_TRSCMP) && | 282 | + .name = TYPE_CPRMAN_PLL, |
120 | + if (!(s->quirks & SDHCI_QUIRK_NO_BUSY_IRQ) && | 283 | + .parent = TYPE_DEVICE, |
121 | + (s->norintstsen & SDHC_NISEN_TRSCMP) && | 284 | + .instance_size = sizeof(CprmanPllState), |
122 | (s->cmdreg & SDHC_CMD_RESPONSE) == SDHC_CMD_RSP_WITH_BUSY) { | 285 | + .class_init = pll_class_init, |
123 | s->norintsts |= SDHC_NIS_TRSCMP; | 286 | + .instance_init = pll_init, |
124 | } | 287 | +}; |
125 | @@ -XXX,XX +XXX,XX @@ static void sdhci_initfn(SDHCIState *s) | 288 | + |
126 | 289 | + | |
127 | s->insert_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, sdhci_raise_insertion_irq, s); | 290 | /* CPRMAN "top level" model */ |
128 | s->transfer_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, sdhci_data_transfer, s); | 291 | |
129 | + | 292 | static uint64_t cprman_read(void *opaque, hwaddr offset, |
130 | + s->io_ops = &sdhci_mmio_ops; | 293 | @@ -XXX,XX +XXX,XX @@ static uint64_t cprman_read(void *opaque, hwaddr offset, |
294 | return r; | ||
131 | } | 295 | } |
132 | 296 | ||
133 | static void sdhci_uninitfn(SDHCIState *s) | 297 | +#define CASE_PLL_REGS(pll_) \ |
134 | @@ -XXX,XX +XXX,XX @@ static void sdhci_sysbus_realize(DeviceState *dev, Error ** errp) | 298 | + case R_CM_ ## pll_: \ |
135 | } | 299 | + case R_A2W_ ## pll_ ## _CTRL: \ |
136 | 300 | + case R_A2W_ ## pll_ ## _ANA0: \ | |
137 | sysbus_init_irq(sbd, &s->irq); | 301 | + case R_A2W_ ## pll_ ## _ANA1: \ |
138 | + | 302 | + case R_A2W_ ## pll_ ## _ANA2: \ |
139 | + memory_region_init_io(&s->iomem, OBJECT(s), s->io_ops, s, "sdhci", | 303 | + case R_A2W_ ## pll_ ## _ANA3: \ |
140 | + SDHC_REGISTERS_MAP_SIZE); | 304 | + case R_A2W_ ## pll_ ## _FRAC |
141 | + | 305 | + |
142 | sysbus_init_mmio(sbd, &s->iomem); | 306 | static void cprman_write(void *opaque, hwaddr offset, |
143 | } | 307 | uint64_t value, unsigned size) |
144 | 308 | { | |
145 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo sdhci_bus_info = { | 309 | @@ -XXX,XX +XXX,XX @@ static void cprman_write(void *opaque, hwaddr offset, |
146 | .class_init = sdhci_bus_class_init, | 310 | trace_bcm2835_cprman_write(offset, value); |
147 | }; | 311 | s->regs[idx] = value; |
148 | 312 | ||
149 | +static uint64_t usdhc_read(void *opaque, hwaddr offset, unsigned size) | 313 | + switch (idx) { |
150 | +{ | 314 | + CASE_PLL_REGS(PLLA) : |
151 | + SDHCIState *s = SYSBUS_SDHCI(opaque); | 315 | + pll_update(&s->plls[CPRMAN_PLLA]); |
152 | + uint32_t ret; | ||
153 | + uint16_t hostctl; | ||
154 | + | ||
155 | + switch (offset) { | ||
156 | + default: | ||
157 | + return sdhci_read(opaque, offset, size); | ||
158 | + | ||
159 | + case SDHC_HOSTCTL: | ||
160 | + /* | ||
161 | + * For a detailed explanation on the following bit | ||
162 | + * manipulation code see comments in a similar part of | ||
163 | + * usdhc_write() | ||
164 | + */ | ||
165 | + hostctl = SDHC_DMA_TYPE(s->hostctl) << (8 - 3); | ||
166 | + | ||
167 | + if (s->hostctl & SDHC_CTRL_8BITBUS) { | ||
168 | + hostctl |= ESDHC_CTRL_8BITBUS; | ||
169 | + } | ||
170 | + | ||
171 | + if (s->hostctl & SDHC_CTRL_4BITBUS) { | ||
172 | + hostctl |= ESDHC_CTRL_4BITBUS; | ||
173 | + } | ||
174 | + | ||
175 | + ret = hostctl; | ||
176 | + ret |= (uint32_t)s->blkgap << 16; | ||
177 | + ret |= (uint32_t)s->wakcon << 24; | ||
178 | + | ||
179 | + break; | 316 | + break; |
180 | + | 317 | + |
181 | + case ESDHC_DLL_CTRL: | 318 | + CASE_PLL_REGS(PLLC) : |
182 | + case ESDHC_TUNE_CTRL_STATUS: | 319 | + pll_update(&s->plls[CPRMAN_PLLC]); |
183 | + case ESDHC_UNDOCUMENTED_REG27: | 320 | + break; |
184 | + case ESDHC_TUNING_CTRL: | 321 | + |
185 | + case ESDHC_VENDOR_SPEC: | 322 | + CASE_PLL_REGS(PLLD) : |
186 | + case ESDHC_MIX_CTRL: | 323 | + pll_update(&s->plls[CPRMAN_PLLD]); |
187 | + case ESDHC_WTMK_LVL: | 324 | + break; |
188 | + ret = 0; | 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]); | ||
189 | + break; | 332 | + break; |
190 | + } | 333 | + } |
191 | + | 334 | } |
192 | + return ret; | 335 | |
193 | +} | 336 | +#undef CASE_PLL_REGS |
194 | + | 337 | + |
195 | +static void | 338 | static const MemoryRegionOps cprman_ops = { |
196 | +usdhc_write(void *opaque, hwaddr offset, uint64_t val, unsigned size) | 339 | .read = cprman_read, |
197 | +{ | 340 | .write = cprman_write, |
198 | + SDHCIState *s = SYSBUS_SDHCI(opaque); | 341 | @@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps cprman_ops = { |
199 | + uint8_t hostctl; | 342 | static void cprman_reset(DeviceState *dev) |
200 | + uint32_t value = (uint32_t)val; | 343 | { |
201 | + | 344 | BCM2835CprmanState *s = CPRMAN(dev); |
202 | + switch (offset) { | 345 | + size_t i; |
203 | + case ESDHC_DLL_CTRL: | 346 | |
204 | + case ESDHC_TUNE_CTRL_STATUS: | 347 | memset(s->regs, 0, sizeof(s->regs)); |
205 | + case ESDHC_UNDOCUMENTED_REG27: | 348 | |
206 | + case ESDHC_TUNING_CTRL: | 349 | + for (i = 0; i < CPRMAN_NUM_PLL; i++) { |
207 | + case ESDHC_WTMK_LVL: | 350 | + device_cold_reset(DEVICE(&s->plls[i])); |
208 | + case ESDHC_VENDOR_SPEC: | 351 | + } |
209 | + break; | 352 | + |
210 | + | 353 | clock_update_hz(s->xosc, s->xosc_freq); |
211 | + case SDHC_HOSTCTL: | 354 | } |
212 | + /* | 355 | |
213 | + * Here's What ESDHCI has at offset 0x28 (SDHC_HOSTCTL) | 356 | static void cprman_init(Object *obj) |
214 | + * | 357 | { |
215 | + * 7 6 5 4 3 2 1 0 | 358 | BCM2835CprmanState *s = CPRMAN(obj); |
216 | + * |-----------+--------+--------+-----------+----------+---------| | 359 | + size_t i; |
217 | + * | Card | Card | Endian | DATA3 | Data | Led | | 360 | + |
218 | + * | Detect | Detect | Mode | as Card | Transfer | Control | | 361 | + for (i = 0; i < CPRMAN_NUM_PLL; i++) { |
219 | + * | Signal | Test | | Detection | Width | | | 362 | + object_initialize_child(obj, PLL_INIT_INFO[i].name, |
220 | + * | Selection | Level | | Pin | | | | 363 | + &s->plls[i], TYPE_CPRMAN_PLL); |
221 | + * |-----------+--------+--------+-----------+----------+---------| | 364 | + set_pll_init_info(s, &s->plls[i], i); |
222 | + * | 365 | + } |
223 | + * and 0x29 | 366 | |
224 | + * | 367 | s->xosc = clock_new(obj, "xosc"); |
225 | + * 15 10 9 8 | 368 | |
226 | + * |----------+------| | 369 | @@ -XXX,XX +XXX,XX @@ static void cprman_init(Object *obj) |
227 | + * | Reserved | DMA | | 370 | sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->iomem); |
228 | + * | | Sel. | | 371 | } |
229 | + * | | | | 372 | |
230 | + * |----------+------| | 373 | +static void cprman_realize(DeviceState *dev, Error **errp) |
231 | + * | 374 | +{ |
232 | + * and here's what SDCHI spec expects those offsets to be: | 375 | + BCM2835CprmanState *s = CPRMAN(dev); |
233 | + * | 376 | + size_t i; |
234 | + * 0x28 (Host Control Register) | 377 | + |
235 | + * | 378 | + for (i = 0; i < CPRMAN_NUM_PLL; i++) { |
236 | + * 7 6 5 4 3 2 1 0 | 379 | + CprmanPllState *pll = &s->plls[i]; |
237 | + * |--------+--------+----------+------+--------+----------+---------| | 380 | + |
238 | + * | Card | Card | Extended | DMA | High | Data | LED | | 381 | + clock_set_source(pll->xosc_in, s->xosc); |
239 | + * | Detect | Detect | Data | Sel. | Speed | Transfer | Control | | 382 | + |
240 | + * | Signal | Test | Transfer | | Enable | Width | | | 383 | + if (!qdev_realize(DEVICE(pll), NULL, errp)) { |
241 | + * | Sel. | Level | Width | | | | | | 384 | + return; |
242 | + * |--------+--------+----------+------+--------+----------+---------| | ||
243 | + * | ||
244 | + * and 0x29 (Power Control Register) | ||
245 | + * | ||
246 | + * |----------------------------------| | ||
247 | + * | Power Control Register | | ||
248 | + * | | | ||
249 | + * | Description omitted, | | ||
250 | + * | since it has no analog in ESDHCI | | ||
251 | + * | | | ||
252 | + * |----------------------------------| | ||
253 | + * | ||
254 | + * Since offsets 0x2A and 0x2B should be compatible between | ||
255 | + * both IP specs we only need to reconcile least 16-bit of the | ||
256 | + * word we've been given. | ||
257 | + */ | ||
258 | + | ||
259 | + /* | ||
260 | + * First, save bits 7 6 and 0 since they are identical | ||
261 | + */ | ||
262 | + hostctl = value & (SDHC_CTRL_LED | | ||
263 | + SDHC_CTRL_CDTEST_INS | | ||
264 | + SDHC_CTRL_CDTEST_EN); | ||
265 | + /* | ||
266 | + * Second, split "Data Transfer Width" from bits 2 and 1 in to | ||
267 | + * bits 5 and 1 | ||
268 | + */ | ||
269 | + if (value & ESDHC_CTRL_8BITBUS) { | ||
270 | + hostctl |= SDHC_CTRL_8BITBUS; | ||
271 | + } | 385 | + } |
272 | + | ||
273 | + if (value & ESDHC_CTRL_4BITBUS) { | ||
274 | + hostctl |= ESDHC_CTRL_4BITBUS; | ||
275 | + } | ||
276 | + | ||
277 | + /* | ||
278 | + * Third, move DMA select from bits 9 and 8 to bits 4 and 3 | ||
279 | + */ | ||
280 | + hostctl |= SDHC_DMA_TYPE(value >> (8 - 3)); | ||
281 | + | ||
282 | + /* | ||
283 | + * Now place the corrected value into low 16-bit of the value | ||
284 | + * we are going to give standard SDHCI write function | ||
285 | + * | ||
286 | + * NOTE: This transformation should be the inverse of what can | ||
287 | + * be found in drivers/mmc/host/sdhci-esdhc-imx.c in Linux | ||
288 | + * kernel | ||
289 | + */ | ||
290 | + value &= ~UINT16_MAX; | ||
291 | + value |= hostctl; | ||
292 | + value |= (uint16_t)s->pwrcon << 8; | ||
293 | + | ||
294 | + sdhci_write(opaque, offset, value, size); | ||
295 | + break; | ||
296 | + | ||
297 | + case ESDHC_MIX_CTRL: | ||
298 | + /* | ||
299 | + * So, when SD/MMC stack in Linux tries to write to "Transfer | ||
300 | + * Mode Register", ESDHC i.MX quirk code will translate it | ||
301 | + * into a write to ESDHC_MIX_CTRL, so we do the opposite in | ||
302 | + * order to get where we started | ||
303 | + * | ||
304 | + * Note that Auto CMD23 Enable bit is located in a wrong place | ||
305 | + * on i.MX, but since it is not used by QEMU we do not care. | ||
306 | + * | ||
307 | + * We don't want to call sdhci_write(.., SDHC_TRNMOD, ...) | ||
308 | + * here becuase it will result in a call to | ||
309 | + * sdhci_send_command(s) which we don't want. | ||
310 | + * | ||
311 | + */ | ||
312 | + s->trnmod = value & UINT16_MAX; | ||
313 | + break; | ||
314 | + case SDHC_TRNMOD: | ||
315 | + /* | ||
316 | + * Similar to above, but this time a write to "Command | ||
317 | + * Register" will be translated into a 4-byte write to | ||
318 | + * "Transfer Mode register" where lower 16-bit of value would | ||
319 | + * be set to zero. So what we do is fill those bits with | ||
320 | + * cached value from s->trnmod and let the SDHCI | ||
321 | + * infrastructure handle the rest | ||
322 | + */ | ||
323 | + sdhci_write(opaque, offset, val | s->trnmod, size); | ||
324 | + break; | ||
325 | + case SDHC_BLKSIZE: | ||
326 | + /* | ||
327 | + * ESDHCI does not implement "Host SDMA Buffer Boundary", and | ||
328 | + * Linux driver will try to zero this field out which will | ||
329 | + * break the rest of SDHCI emulation. | ||
330 | + * | ||
331 | + * Linux defaults to maximum possible setting (512K boundary) | ||
332 | + * and it seems to be the only option that i.MX IP implements, | ||
333 | + * so we artificially set it to that value. | ||
334 | + */ | ||
335 | + val |= 0x7 << 12; | ||
336 | + /* FALLTHROUGH */ | ||
337 | + default: | ||
338 | + sdhci_write(opaque, offset, val, size); | ||
339 | + break; | ||
340 | + } | 386 | + } |
341 | +} | 387 | +} |
342 | + | 388 | + |
343 | + | 389 | static const VMStateDescription cprman_vmstate = { |
344 | +static const MemoryRegionOps usdhc_mmio_ops = { | 390 | .name = TYPE_BCM2835_CPRMAN, |
345 | + .read = usdhc_read, | 391 | .version_id = 1, |
346 | + .write = usdhc_write, | 392 | @@ -XXX,XX +XXX,XX @@ static void cprman_class_init(ObjectClass *klass, void *data) |
347 | + .valid = { | ||
348 | + .min_access_size = 1, | ||
349 | + .max_access_size = 4, | ||
350 | + .unaligned = false | ||
351 | + }, | ||
352 | + .endianness = DEVICE_LITTLE_ENDIAN, | ||
353 | +}; | ||
354 | + | ||
355 | +static void imx_usdhc_init(Object *obj) | ||
356 | +{ | ||
357 | + SDHCIState *s = SYSBUS_SDHCI(obj); | ||
358 | + | ||
359 | + s->io_ops = &usdhc_mmio_ops; | ||
360 | + s->quirks = SDHCI_QUIRK_NO_BUSY_IRQ; | ||
361 | +} | ||
362 | + | ||
363 | +static const TypeInfo imx_usdhc_info = { | ||
364 | + .name = TYPE_IMX_USDHC, | ||
365 | + .parent = TYPE_SYSBUS_SDHCI, | ||
366 | + .instance_init = imx_usdhc_init, | ||
367 | +}; | ||
368 | + | ||
369 | static void sdhci_register_types(void) | ||
370 | { | 393 | { |
371 | type_register_static(&sdhci_pci_info); | 394 | DeviceClass *dc = DEVICE_CLASS(klass); |
372 | type_register_static(&sdhci_sysbus_info); | 395 | |
373 | type_register_static(&sdhci_bus_info); | 396 | + dc->realize = cprman_realize; |
374 | + type_register_static(&imx_usdhc_info); | 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); | ||
375 | } | 405 | } |
376 | 406 | ||
377 | type_init(sdhci_register_types) | 407 | type_init(cprman_register_types); |
378 | -- | 408 | -- |
379 | 2.16.1 | 409 | 2.20.1 |
380 | 410 | ||
381 | 411 | diff view generated by jsdifflib |
1 | From: Ard Biesheuvel <ard.biesheuvel@linaro.org> | 1 | From: Luc Michel <luc@lmichel.fr> |
---|---|---|---|
2 | 2 | ||
3 | This implements emulation of the new SM3 instructions that have | 3 | The CPRMAN PLLs generate a clock based on a prescaler, a multiplier and |
4 | been added as an optional extension to the ARMv8 Crypto Extensions | 4 | a divider. The prescaler doubles the parent (xosc) frequency, then the |
5 | in ARM v8.2. | 5 | multiplier/divider are applied. The multiplier has an integer and a |
6 | fractional part. | ||
6 | 7 | ||
7 | Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> | 8 | This commit also implements the CPRMAN CM_LOCK register. This register |
8 | Message-id: 20180207111729.15737-4-ard.biesheuvel@linaro.org | 9 | reports which PLL is currently locked. We consider a PLL has being |
9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 10 | locked as soon as it is enabled (on real hardware, there is a delay |
11 | after turning a PLL on, for it to stabilize). | ||
12 | |||
13 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
14 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
15 | Signed-off-by: Luc Michel <luc@lmichel.fr> | ||
16 | Tested-by: Guenter Roeck <linux@roeck-us.net> | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 17 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
11 | --- | 18 | --- |
12 | target/arm/cpu.h | 1 + | 19 | include/hw/misc/bcm2835_cprman_internals.h | 8 +++ |
13 | target/arm/helper.h | 4 ++ | 20 | hw/misc/bcm2835_cprman.c | 64 +++++++++++++++++++++- |
14 | target/arm/crypto_helper.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++ | 21 | 2 files changed, 71 insertions(+), 1 deletion(-) |
15 | target/arm/translate-a64.c | 88 ++++++++++++++++++++++++++++++++++++++++-- | ||
16 | 4 files changed, 186 insertions(+), 3 deletions(-) | ||
17 | 22 | ||
18 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | 23 | diff --git a/include/hw/misc/bcm2835_cprman_internals.h b/include/hw/misc/bcm2835_cprman_internals.h |
19 | index XXXXXXX..XXXXXXX 100644 | 24 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/target/arm/cpu.h | 25 | --- a/include/hw/misc/bcm2835_cprman_internals.h |
21 | +++ b/target/arm/cpu.h | 26 | +++ b/include/hw/misc/bcm2835_cprman_internals.h |
22 | @@ -XXX,XX +XXX,XX @@ enum arm_features { | 27 | @@ -XXX,XX +XXX,XX @@ REG32(A2W_PLLD_FRAC, 0x1240) |
23 | ARM_FEATURE_SVE, /* has Scalable Vector Extension */ | 28 | REG32(A2W_PLLH_FRAC, 0x1260) |
24 | ARM_FEATURE_V8_SHA512, /* implements SHA512 part of v8 Crypto Extensions */ | 29 | REG32(A2W_PLLB_FRAC, 0x12e0) |
25 | ARM_FEATURE_V8_SHA3, /* implements SHA3 part of v8 Crypto Extensions */ | 30 | |
26 | + ARM_FEATURE_V8_SM3, /* implements SM3 part of v8 Crypto Extensions */ | 31 | +/* misc registers */ |
27 | }; | 32 | +REG32(CM_LOCK, 0x114) |
28 | 33 | + FIELD(CM_LOCK, FLOCKH, 12, 1) | |
29 | static inline int arm_feature(CPUARMState *env, int feature) | 34 | + FIELD(CM_LOCK, FLOCKD, 11, 1) |
30 | diff --git a/target/arm/helper.h b/target/arm/helper.h | 35 | + FIELD(CM_LOCK, FLOCKC, 10, 1) |
36 | + FIELD(CM_LOCK, FLOCKB, 9, 1) | ||
37 | + FIELD(CM_LOCK, FLOCKA, 8, 1) | ||
38 | + | ||
39 | /* | ||
40 | * This field is common to all registers. Each register write value must match | ||
41 | * the CPRMAN_PASSWORD magic value in its 8 MSB. | ||
42 | diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c | ||
31 | index XXXXXXX..XXXXXXX 100644 | 43 | index XXXXXXX..XXXXXXX 100644 |
32 | --- a/target/arm/helper.h | 44 | --- a/hw/misc/bcm2835_cprman.c |
33 | +++ b/target/arm/helper.h | 45 | +++ b/hw/misc/bcm2835_cprman.c |
34 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_3(crypto_sha512h2, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) | 46 | @@ -XXX,XX +XXX,XX @@ |
35 | DEF_HELPER_FLAGS_2(crypto_sha512su0, TCG_CALL_NO_RWG, void, ptr, ptr) | 47 | |
36 | DEF_HELPER_FLAGS_3(crypto_sha512su1, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) | 48 | /* PLL */ |
37 | 49 | ||
38 | +DEF_HELPER_FLAGS_5(crypto_sm3tt, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32, i32) | 50 | +static bool pll_is_locked(const CprmanPllState *pll) |
39 | +DEF_HELPER_FLAGS_3(crypto_sm3partw1, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) | ||
40 | +DEF_HELPER_FLAGS_3(crypto_sm3partw2, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) | ||
41 | + | ||
42 | DEF_HELPER_FLAGS_3(crc32, TCG_CALL_NO_RWG_SE, i32, i32, i32, i32) | ||
43 | DEF_HELPER_FLAGS_3(crc32c, TCG_CALL_NO_RWG_SE, i32, i32, i32, i32) | ||
44 | DEF_HELPER_2(dc_zva, void, env, i64) | ||
45 | diff --git a/target/arm/crypto_helper.c b/target/arm/crypto_helper.c | ||
46 | index XXXXXXX..XXXXXXX 100644 | ||
47 | --- a/target/arm/crypto_helper.c | ||
48 | +++ b/target/arm/crypto_helper.c | ||
49 | @@ -XXX,XX +XXX,XX @@ void HELPER(crypto_sha512su1)(void *vd, void *vn, void *vm) | ||
50 | rd[0] += s1_512(rn[0]) + rm[0]; | ||
51 | rd[1] += s1_512(rn[1]) + rm[1]; | ||
52 | } | ||
53 | + | ||
54 | +void HELPER(crypto_sm3partw1)(void *vd, void *vn, void *vm) | ||
55 | +{ | 51 | +{ |
56 | + uint64_t *rd = vd; | 52 | + return !FIELD_EX32(*pll->reg_a2w_ctrl, A2W_PLLx_CTRL, PWRDN) |
57 | + uint64_t *rn = vn; | 53 | + && !FIELD_EX32(*pll->reg_cm, CM_PLLx, ANARST); |
58 | + uint64_t *rm = vm; | ||
59 | + union CRYPTO_STATE d = { .l = { rd[0], rd[1] } }; | ||
60 | + union CRYPTO_STATE n = { .l = { rn[0], rn[1] } }; | ||
61 | + union CRYPTO_STATE m = { .l = { rm[0], rm[1] } }; | ||
62 | + uint32_t t; | ||
63 | + | ||
64 | + t = CR_ST_WORD(d, 0) ^ CR_ST_WORD(n, 0) ^ ror32(CR_ST_WORD(m, 1), 17); | ||
65 | + CR_ST_WORD(d, 0) = t ^ ror32(t, 17) ^ ror32(t, 9); | ||
66 | + | ||
67 | + t = CR_ST_WORD(d, 1) ^ CR_ST_WORD(n, 1) ^ ror32(CR_ST_WORD(m, 2), 17); | ||
68 | + CR_ST_WORD(d, 1) = t ^ ror32(t, 17) ^ ror32(t, 9); | ||
69 | + | ||
70 | + t = CR_ST_WORD(d, 2) ^ CR_ST_WORD(n, 2) ^ ror32(CR_ST_WORD(m, 3), 17); | ||
71 | + CR_ST_WORD(d, 2) = t ^ ror32(t, 17) ^ ror32(t, 9); | ||
72 | + | ||
73 | + t = CR_ST_WORD(d, 3) ^ CR_ST_WORD(n, 3) ^ ror32(CR_ST_WORD(d, 0), 17); | ||
74 | + CR_ST_WORD(d, 3) = t ^ ror32(t, 17) ^ ror32(t, 9); | ||
75 | + | ||
76 | + rd[0] = d.l[0]; | ||
77 | + rd[1] = d.l[1]; | ||
78 | +} | 54 | +} |
79 | + | 55 | + |
80 | +void HELPER(crypto_sm3partw2)(void *vd, void *vn, void *vm) | 56 | static void pll_update(CprmanPllState *pll) |
81 | +{ | 57 | { |
82 | + uint64_t *rd = vd; | 58 | - clock_update(pll->out, 0); |
83 | + uint64_t *rn = vn; | 59 | + uint64_t freq, ndiv, fdiv, pdiv; |
84 | + uint64_t *rm = vm; | ||
85 | + union CRYPTO_STATE d = { .l = { rd[0], rd[1] } }; | ||
86 | + union CRYPTO_STATE n = { .l = { rn[0], rn[1] } }; | ||
87 | + union CRYPTO_STATE m = { .l = { rm[0], rm[1] } }; | ||
88 | + uint32_t t = CR_ST_WORD(n, 0) ^ ror32(CR_ST_WORD(m, 0), 25); | ||
89 | + | 60 | + |
90 | + CR_ST_WORD(d, 0) ^= t; | 61 | + if (!pll_is_locked(pll)) { |
91 | + CR_ST_WORD(d, 1) ^= CR_ST_WORD(n, 1) ^ ror32(CR_ST_WORD(m, 1), 25); | 62 | + clock_update(pll->out, 0); |
92 | + CR_ST_WORD(d, 2) ^= CR_ST_WORD(n, 2) ^ ror32(CR_ST_WORD(m, 2), 25); | ||
93 | + CR_ST_WORD(d, 3) ^= CR_ST_WORD(n, 3) ^ ror32(CR_ST_WORD(m, 3), 25) ^ | ||
94 | + ror32(t, 17) ^ ror32(t, 2) ^ ror32(t, 26); | ||
95 | + | ||
96 | + rd[0] = d.l[0]; | ||
97 | + rd[1] = d.l[1]; | ||
98 | +} | ||
99 | + | ||
100 | +void HELPER(crypto_sm3tt)(void *vd, void *vn, void *vm, uint32_t imm2, | ||
101 | + uint32_t opcode) | ||
102 | +{ | ||
103 | + uint64_t *rd = vd; | ||
104 | + uint64_t *rn = vn; | ||
105 | + uint64_t *rm = vm; | ||
106 | + union CRYPTO_STATE d = { .l = { rd[0], rd[1] } }; | ||
107 | + union CRYPTO_STATE n = { .l = { rn[0], rn[1] } }; | ||
108 | + union CRYPTO_STATE m = { .l = { rm[0], rm[1] } }; | ||
109 | + uint32_t t; | ||
110 | + | ||
111 | + assert(imm2 < 4); | ||
112 | + | ||
113 | + if (opcode == 0 || opcode == 2) { | ||
114 | + /* SM3TT1A, SM3TT2A */ | ||
115 | + t = par(CR_ST_WORD(d, 3), CR_ST_WORD(d, 2), CR_ST_WORD(d, 1)); | ||
116 | + } else if (opcode == 1) { | ||
117 | + /* SM3TT1B */ | ||
118 | + t = maj(CR_ST_WORD(d, 3), CR_ST_WORD(d, 2), CR_ST_WORD(d, 1)); | ||
119 | + } else if (opcode == 3) { | ||
120 | + /* SM3TT2B */ | ||
121 | + t = cho(CR_ST_WORD(d, 3), CR_ST_WORD(d, 2), CR_ST_WORD(d, 1)); | ||
122 | + } else { | ||
123 | + g_assert_not_reached(); | ||
124 | + } | ||
125 | + | ||
126 | + t += CR_ST_WORD(d, 0) + CR_ST_WORD(m, imm2); | ||
127 | + | ||
128 | + CR_ST_WORD(d, 0) = CR_ST_WORD(d, 1); | ||
129 | + | ||
130 | + if (opcode < 2) { | ||
131 | + /* SM3TT1A, SM3TT1B */ | ||
132 | + t += CR_ST_WORD(n, 3) ^ ror32(CR_ST_WORD(d, 3), 20); | ||
133 | + | ||
134 | + CR_ST_WORD(d, 1) = ror32(CR_ST_WORD(d, 2), 23); | ||
135 | + } else { | ||
136 | + /* SM3TT2A, SM3TT2B */ | ||
137 | + t += CR_ST_WORD(n, 3); | ||
138 | + t ^= rol32(t, 9) ^ rol32(t, 17); | ||
139 | + | ||
140 | + CR_ST_WORD(d, 1) = ror32(CR_ST_WORD(d, 2), 13); | ||
141 | + } | ||
142 | + | ||
143 | + CR_ST_WORD(d, 2) = CR_ST_WORD(d, 3); | ||
144 | + CR_ST_WORD(d, 3) = t; | ||
145 | + | ||
146 | + rd[0] = d.l[0]; | ||
147 | + rd[1] = d.l[1]; | ||
148 | +} | ||
149 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | ||
150 | index XXXXXXX..XXXXXXX 100644 | ||
151 | --- a/target/arm/translate-a64.c | ||
152 | +++ b/target/arm/translate-a64.c | ||
153 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_three_reg_sha512(DisasContext *s, uint32_t insn) | ||
154 | break; | ||
155 | } | ||
156 | } else { | ||
157 | - unallocated_encoding(s); | ||
158 | - return; | ||
159 | + switch (opcode) { | ||
160 | + case 0: /* SM3PARTW1 */ | ||
161 | + feature = ARM_FEATURE_V8_SM3; | ||
162 | + genfn = gen_helper_crypto_sm3partw1; | ||
163 | + break; | ||
164 | + case 1: /* SM3PARTW2 */ | ||
165 | + feature = ARM_FEATURE_V8_SM3; | ||
166 | + genfn = gen_helper_crypto_sm3partw2; | ||
167 | + break; | ||
168 | + default: | ||
169 | + unallocated_encoding(s); | ||
170 | + return; | ||
171 | + } | ||
172 | } | ||
173 | |||
174 | if (!arm_dc_feature(s, feature)) { | ||
175 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_four_reg(DisasContext *s, uint32_t insn) | ||
176 | case 1: /* BCAX */ | ||
177 | feature = ARM_FEATURE_V8_SHA3; | ||
178 | break; | ||
179 | + case 2: /* SM3SS1 */ | ||
180 | + feature = ARM_FEATURE_V8_SM3; | ||
181 | + break; | ||
182 | default: | ||
183 | unallocated_encoding(s); | ||
184 | return; | ||
185 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_four_reg(DisasContext *s, uint32_t insn) | ||
186 | tcg_temp_free_i64(tcg_res[0]); | ||
187 | tcg_temp_free_i64(tcg_res[1]); | ||
188 | } else { | ||
189 | - g_assert_not_reached(); | ||
190 | + TCGv_i32 tcg_op1, tcg_op2, tcg_op3, tcg_res, tcg_zero; | ||
191 | + | ||
192 | + tcg_op1 = tcg_temp_new_i32(); | ||
193 | + tcg_op2 = tcg_temp_new_i32(); | ||
194 | + tcg_op3 = tcg_temp_new_i32(); | ||
195 | + tcg_res = tcg_temp_new_i32(); | ||
196 | + tcg_zero = tcg_const_i32(0); | ||
197 | + | ||
198 | + read_vec_element_i32(s, tcg_op1, rn, 3, MO_32); | ||
199 | + read_vec_element_i32(s, tcg_op2, rm, 3, MO_32); | ||
200 | + read_vec_element_i32(s, tcg_op3, ra, 3, MO_32); | ||
201 | + | ||
202 | + tcg_gen_rotri_i32(tcg_res, tcg_op1, 20); | ||
203 | + tcg_gen_add_i32(tcg_res, tcg_res, tcg_op2); | ||
204 | + tcg_gen_add_i32(tcg_res, tcg_res, tcg_op3); | ||
205 | + tcg_gen_rotri_i32(tcg_res, tcg_res, 25); | ||
206 | + | ||
207 | + write_vec_element_i32(s, tcg_zero, rd, 0, MO_32); | ||
208 | + write_vec_element_i32(s, tcg_zero, rd, 1, MO_32); | ||
209 | + write_vec_element_i32(s, tcg_zero, rd, 2, MO_32); | ||
210 | + write_vec_element_i32(s, tcg_res, rd, 3, MO_32); | ||
211 | + | ||
212 | + tcg_temp_free_i32(tcg_op1); | ||
213 | + tcg_temp_free_i32(tcg_op2); | ||
214 | + tcg_temp_free_i32(tcg_op3); | ||
215 | + tcg_temp_free_i32(tcg_res); | ||
216 | + tcg_temp_free_i32(tcg_zero); | ||
217 | } | ||
218 | } | ||
219 | |||
220 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_xar(DisasContext *s, uint32_t insn) | ||
221 | tcg_temp_free_i64(tcg_res[1]); | ||
222 | } | ||
223 | |||
224 | +/* Crypto three-reg imm2 | ||
225 | + * 31 21 20 16 15 14 13 12 11 10 9 5 4 0 | ||
226 | + * +-----------------------+------+-----+------+--------+------+------+ | ||
227 | + * | 1 1 0 0 1 1 1 0 0 1 0 | Rm | 1 0 | imm2 | opcode | Rn | Rd | | ||
228 | + * +-----------------------+------+-----+------+--------+------+------+ | ||
229 | + */ | ||
230 | +static void disas_crypto_three_reg_imm2(DisasContext *s, uint32_t insn) | ||
231 | +{ | ||
232 | + int opcode = extract32(insn, 10, 2); | ||
233 | + int imm2 = extract32(insn, 12, 2); | ||
234 | + int rm = extract32(insn, 16, 5); | ||
235 | + int rn = extract32(insn, 5, 5); | ||
236 | + int rd = extract32(insn, 0, 5); | ||
237 | + TCGv_ptr tcg_rd_ptr, tcg_rn_ptr, tcg_rm_ptr; | ||
238 | + TCGv_i32 tcg_imm2, tcg_opcode; | ||
239 | + | ||
240 | + if (!arm_dc_feature(s, ARM_FEATURE_V8_SM3)) { | ||
241 | + unallocated_encoding(s); | ||
242 | + return; | 63 | + return; |
243 | + } | 64 | + } |
244 | + | 65 | + |
245 | + if (!fp_access_check(s)) { | 66 | + pdiv = FIELD_EX32(*pll->reg_a2w_ctrl, A2W_PLLx_CTRL, PDIV); |
67 | + | ||
68 | + if (!pdiv) { | ||
69 | + clock_update(pll->out, 0); | ||
246 | + return; | 70 | + return; |
247 | + } | 71 | + } |
248 | + | 72 | + |
249 | + tcg_rd_ptr = vec_full_reg_ptr(s, rd); | 73 | + ndiv = FIELD_EX32(*pll->reg_a2w_ctrl, A2W_PLLx_CTRL, NDIV); |
250 | + tcg_rn_ptr = vec_full_reg_ptr(s, rn); | 74 | + fdiv = FIELD_EX32(*pll->reg_a2w_frac, A2W_PLLx_FRAC, FRAC); |
251 | + tcg_rm_ptr = vec_full_reg_ptr(s, rm); | ||
252 | + tcg_imm2 = tcg_const_i32(imm2); | ||
253 | + tcg_opcode = tcg_const_i32(opcode); | ||
254 | + | 75 | + |
255 | + gen_helper_crypto_sm3tt(tcg_rd_ptr, tcg_rn_ptr, tcg_rm_ptr, tcg_imm2, | 76 | + if (pll->reg_a2w_ana[1] & pll->prediv_mask) { |
256 | + tcg_opcode); | 77 | + /* The prescaler doubles the parent frequency */ |
78 | + ndiv *= 2; | ||
79 | + fdiv *= 2; | ||
80 | + } | ||
257 | + | 81 | + |
258 | + tcg_temp_free_ptr(tcg_rd_ptr); | 82 | + /* |
259 | + tcg_temp_free_ptr(tcg_rn_ptr); | 83 | + * We have a multiplier with an integer part (ndiv) and a fractional part |
260 | + tcg_temp_free_ptr(tcg_rm_ptr); | 84 | + * (fdiv), and a divider (pdiv). |
261 | + tcg_temp_free_i32(tcg_imm2); | 85 | + */ |
262 | + tcg_temp_free_i32(tcg_opcode); | 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; | ||
263 | +} | 117 | +} |
264 | + | 118 | + |
265 | /* C3.6 Data processing - SIMD, inc Crypto | 119 | static uint64_t cprman_read(void *opaque, hwaddr offset, |
266 | * | 120 | unsigned size) |
267 | * As the decode gets a little complex we are using a table based | 121 | { |
268 | @@ -XXX,XX +XXX,XX @@ static const AArch64DecodeTable data_proc_simd[] = { | 122 | @@ -XXX,XX +XXX,XX @@ static uint64_t cprman_read(void *opaque, hwaddr offset, |
269 | { 0xcec08000, 0xfffff000, disas_crypto_two_reg_sha512 }, | 123 | size_t idx = offset / sizeof(uint32_t); |
270 | { 0xce000000, 0xff808000, disas_crypto_four_reg }, | 124 | |
271 | { 0xce800000, 0xffe00000, disas_crypto_xar }, | 125 | switch (idx) { |
272 | + { 0xce408000, 0xffe0c000, disas_crypto_three_reg_imm2 }, | 126 | + case R_CM_LOCK: |
273 | { 0x00000000, 0x00000000, NULL } | 127 | + r = get_cm_lock(s); |
274 | }; | 128 | + break; |
275 | 129 | + | |
130 | default: | ||
131 | r = s->regs[idx]; | ||
132 | } | ||
276 | -- | 133 | -- |
277 | 2.16.1 | 134 | 2.20.1 |
278 | 135 | ||
279 | 136 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | From: Luc Michel <luc@lmichel.fr> | |
2 | |||
3 | PLLs are composed of multiple channels. Each channel outputs one clock | ||
4 | signal. They are modeled as one device taking the PLL generated clock as | ||
5 | input, and outputting a new clock. | ||
6 | |||
7 | A channel shares the CM register with its parent PLL, and has its own | ||
8 | A2W_CTRL register. A write to the CM register will trigger an update of | ||
9 | the PLL and all its channels, while a write to an A2W_CTRL channel | ||
10 | register will update the required channel only. | ||
11 | |||
12 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
13 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
14 | Signed-off-by: Luc Michel <luc@lmichel.fr> | ||
15 | Tested-by: Guenter Roeck <linux@roeck-us.net> | ||
16 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
17 | --- | ||
18 | include/hw/misc/bcm2835_cprman.h | 44 ++++++ | ||
19 | include/hw/misc/bcm2835_cprman_internals.h | 146 +++++++++++++++++++ | ||
20 | hw/misc/bcm2835_cprman.c | 155 +++++++++++++++++++-- | ||
21 | 3 files changed, 337 insertions(+), 8 deletions(-) | ||
22 | |||
23 | diff --git a/include/hw/misc/bcm2835_cprman.h b/include/hw/misc/bcm2835_cprman.h | ||
24 | index XXXXXXX..XXXXXXX 100644 | ||
25 | --- a/include/hw/misc/bcm2835_cprman.h | ||
26 | +++ b/include/hw/misc/bcm2835_cprman.h | ||
27 | @@ -XXX,XX +XXX,XX @@ typedef enum CprmanPll { | ||
28 | CPRMAN_NUM_PLL | ||
29 | } CprmanPll; | ||
30 | |||
31 | +typedef enum CprmanPllChannel { | ||
32 | + CPRMAN_PLLA_CHANNEL_DSI0 = 0, | ||
33 | + CPRMAN_PLLA_CHANNEL_CORE, | ||
34 | + CPRMAN_PLLA_CHANNEL_PER, | ||
35 | + CPRMAN_PLLA_CHANNEL_CCP2, | ||
36 | + | ||
37 | + CPRMAN_PLLC_CHANNEL_CORE2, | ||
38 | + CPRMAN_PLLC_CHANNEL_CORE1, | ||
39 | + CPRMAN_PLLC_CHANNEL_PER, | ||
40 | + CPRMAN_PLLC_CHANNEL_CORE0, | ||
41 | + | ||
42 | + CPRMAN_PLLD_CHANNEL_DSI0, | ||
43 | + CPRMAN_PLLD_CHANNEL_CORE, | ||
44 | + CPRMAN_PLLD_CHANNEL_PER, | ||
45 | + CPRMAN_PLLD_CHANNEL_DSI1, | ||
46 | + | ||
47 | + CPRMAN_PLLH_CHANNEL_AUX, | ||
48 | + CPRMAN_PLLH_CHANNEL_RCAL, | ||
49 | + CPRMAN_PLLH_CHANNEL_PIX, | ||
50 | + | ||
51 | + CPRMAN_PLLB_CHANNEL_ARM, | ||
52 | + | ||
53 | + CPRMAN_NUM_PLL_CHANNEL, | ||
54 | +} CprmanPllChannel; | ||
55 | + | ||
56 | typedef struct CprmanPllState { | ||
57 | /*< private >*/ | ||
58 | DeviceState parent_obj; | ||
59 | @@ -XXX,XX +XXX,XX @@ typedef struct CprmanPllState { | ||
60 | Clock *out; | ||
61 | } CprmanPllState; | ||
62 | |||
63 | +typedef struct CprmanPllChannelState { | ||
64 | + /*< private >*/ | ||
65 | + DeviceState parent_obj; | ||
66 | + | ||
67 | + /*< public >*/ | ||
68 | + CprmanPllChannel id; | ||
69 | + CprmanPll parent; | ||
70 | + | ||
71 | + uint32_t *reg_cm; | ||
72 | + uint32_t hold_mask; | ||
73 | + uint32_t load_mask; | ||
74 | + uint32_t *reg_a2w_ctrl; | ||
75 | + int fixed_divider; | ||
76 | + | ||
77 | + Clock *pll_in; | ||
78 | + Clock *out; | ||
79 | +} CprmanPllChannelState; | ||
80 | + | ||
81 | struct BCM2835CprmanState { | ||
82 | /*< private >*/ | ||
83 | SysBusDevice parent_obj; | ||
84 | @@ -XXX,XX +XXX,XX @@ struct BCM2835CprmanState { | ||
85 | MemoryRegion iomem; | ||
86 | |||
87 | CprmanPllState plls[CPRMAN_NUM_PLL]; | ||
88 | + CprmanPllChannelState channels[CPRMAN_NUM_PLL_CHANNEL]; | ||
89 | |||
90 | uint32_t regs[CPRMAN_NUM_REGS]; | ||
91 | uint32_t xosc_freq; | ||
92 | diff --git a/include/hw/misc/bcm2835_cprman_internals.h b/include/hw/misc/bcm2835_cprman_internals.h | ||
93 | index XXXXXXX..XXXXXXX 100644 | ||
94 | --- a/include/hw/misc/bcm2835_cprman_internals.h | ||
95 | +++ b/include/hw/misc/bcm2835_cprman_internals.h | ||
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; | ||
390 | |||
391 | - CASE_PLL_REGS(PLLC) : | ||
392 | + CASE_PLL_A2W_REGS(PLLC) : | ||
393 | pll_update(&s->plls[CPRMAN_PLLC]); | ||
394 | break; | ||
395 | |||
396 | - CASE_PLL_REGS(PLLD) : | ||
397 | + CASE_PLL_A2W_REGS(PLLD) : | ||
398 | pll_update(&s->plls[CPRMAN_PLLD]); | ||
399 | break; | ||
400 | |||
401 | - CASE_PLL_REGS(PLLH) : | ||
402 | + CASE_PLL_A2W_REGS(PLLH) : | ||
403 | pll_update(&s->plls[CPRMAN_PLLH]); | ||
404 | break; | ||
405 | |||
406 | - CASE_PLL_REGS(PLLB) : | ||
407 | + CASE_PLL_A2W_REGS(PLLB) : | ||
408 | pll_update(&s->plls[CPRMAN_PLLB]); | ||
409 | break; | ||
410 | + | ||
411 | + case R_A2W_PLLA_DSI0: | ||
412 | + case R_A2W_PLLA_CORE: | ||
413 | + case R_A2W_PLLA_PER: | ||
414 | + case R_A2W_PLLA_CCP2: | ||
415 | + case R_A2W_PLLC_CORE2: | ||
416 | + case R_A2W_PLLC_CORE1: | ||
417 | + case R_A2W_PLLC_PER: | ||
418 | + case R_A2W_PLLC_CORE0: | ||
419 | + case R_A2W_PLLD_DSI0: | ||
420 | + case R_A2W_PLLD_CORE: | ||
421 | + case R_A2W_PLLD_PER: | ||
422 | + case R_A2W_PLLD_DSI1: | ||
423 | + case R_A2W_PLLH_AUX: | ||
424 | + case R_A2W_PLLH_RCAL: | ||
425 | + case R_A2W_PLLH_PIX: | ||
426 | + case R_A2W_PLLB_ARM: | ||
427 | + update_channel_from_a2w(s, idx); | ||
428 | + break; | ||
429 | } | ||
430 | } | ||
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 | -- | ||
490 | 2.20.1 | ||
491 | |||
492 | diff view generated by jsdifflib |
1 | Currently armv7m_nvic_acknowledge_irq() does three things: | 1 | From: Luc Michel <luc@lmichel.fr> |
---|---|---|---|
2 | * make the current highest priority pending interrupt active | ||
3 | * return a bool indicating whether that interrupt is targeting | ||
4 | Secure or NonSecure state | ||
5 | * implicitly tell the caller which is the highest priority | ||
6 | pending interrupt by setting env->v7m.exception | ||
7 | 2 | ||
8 | We need to split these jobs, because v7m_exception_taken() | 3 | A PLL channel is able to further divide the generated PLL frequency. |
9 | needs to know whether the pending interrupt targets Secure so | 4 | The divider is given in the CTRL_A2W register. Some channels have an |
10 | it can choose to stack callee-saves registers or not, but it | 5 | additional fixed divider which is always applied to the signal. |
11 | must not make the interrupt active until after it has done | ||
12 | that stacking, in case the stacking causes a derived exception. | ||
13 | Similarly, it needs to know the number of the pending interrupt | ||
14 | so it can read the correct vector table entry before the | ||
15 | interrupt is made active, because vector table reads might | ||
16 | also cause a derived exception. | ||
17 | 6 | ||
18 | Create a new armv7m_nvic_get_pending_irq_info() function which simply | 7 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
19 | returns information about the highest priority pending interrupt, and | 8 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
20 | use it to rearrange the v7m_exception_taken() code so we don't | 9 | Signed-off-by: Luc Michel <luc@lmichel.fr> |
21 | acknowledge the exception until we've done all the things which could | 10 | Tested-by: Guenter Roeck <linux@roeck-us.net> |
22 | possibly cause a derived exception. | 11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
12 | --- | ||
13 | hw/misc/bcm2835_cprman.c | 33 ++++++++++++++++++++++++++++++++- | ||
14 | 1 file changed, 32 insertions(+), 1 deletion(-) | ||
23 | 15 | ||
24 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 16 | diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c |
25 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
26 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
27 | Message-id: 1517324542-6607-3-git-send-email-peter.maydell@linaro.org | ||
28 | --- | ||
29 | target/arm/cpu.h | 19 ++++++++++++++++--- | ||
30 | hw/intc/armv7m_nvic.c | 30 +++++++++++++++++++++++------- | ||
31 | target/arm/helper.c | 16 ++++++++++++---- | ||
32 | hw/intc/trace-events | 3 ++- | ||
33 | 4 files changed, 53 insertions(+), 15 deletions(-) | ||
34 | |||
35 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | ||
36 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
37 | --- a/target/arm/cpu.h | 18 | --- a/hw/misc/bcm2835_cprman.c |
38 | +++ b/target/arm/cpu.h | 19 | +++ b/hw/misc/bcm2835_cprman.c |
39 | @@ -XXX,XX +XXX,XX @@ void armv7m_nvic_set_pending(void *opaque, int irq, bool secure); | 20 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo cprman_pll_info = { |
40 | * a different exception). | 21 | |
41 | */ | 22 | /* PLL channel */ |
42 | void armv7m_nvic_set_pending_derived(void *opaque, int irq, bool secure); | 23 | |
43 | +/** | 24 | +static bool pll_channel_is_enabled(CprmanPllChannelState *channel) |
44 | + * armv7m_nvic_get_pending_irq_info: return highest priority pending | 25 | +{ |
45 | + * exception, and whether it targets Secure state | 26 | + /* |
46 | + * @opaque: the NVIC | 27 | + * XXX I'm not sure of the purpose of the LOAD field. The Linux driver does |
47 | + * @pirq: set to pending exception number | 28 | + * not set it when enabling the channel, but does clear it when disabling |
48 | + * @ptargets_secure: set to whether pending exception targets Secure | 29 | + * it. |
49 | + * | 30 | + */ |
50 | + * This function writes the number of the highest priority pending | 31 | + return !FIELD_EX32(*channel->reg_a2w_ctrl, A2W_PLLx_CHANNELy, DISABLE) |
51 | + * exception (the one which would be made active by | 32 | + && !(*channel->reg_cm & channel->hold_mask); |
52 | + * armv7m_nvic_acknowledge_irq()) to @pirq, and sets @ptargets_secure | ||
53 | + * to true if the current highest priority pending exception should | ||
54 | + * be taken to Secure state, false for NS. | ||
55 | + */ | ||
56 | +void armv7m_nvic_get_pending_irq_info(void *opaque, int *pirq, | ||
57 | + bool *ptargets_secure); | ||
58 | /** | ||
59 | * armv7m_nvic_acknowledge_irq: make highest priority pending exception active | ||
60 | * @opaque: the NVIC | ||
61 | @@ -XXX,XX +XXX,XX @@ void armv7m_nvic_set_pending_derived(void *opaque, int irq, bool secure); | ||
62 | * Move the current highest priority pending exception from the pending | ||
63 | * state to the active state, and update v7m.exception to indicate that | ||
64 | * it is the exception currently being handled. | ||
65 | - * | ||
66 | - * Returns: true if exception should be taken to Secure state, false for NS | ||
67 | */ | ||
68 | -bool armv7m_nvic_acknowledge_irq(void *opaque); | ||
69 | +void armv7m_nvic_acknowledge_irq(void *opaque); | ||
70 | /** | ||
71 | * armv7m_nvic_complete_irq: complete specified interrupt or exception | ||
72 | * @opaque: the NVIC | ||
73 | diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c | ||
74 | index XXXXXXX..XXXXXXX 100644 | ||
75 | --- a/hw/intc/armv7m_nvic.c | ||
76 | +++ b/hw/intc/armv7m_nvic.c | ||
77 | @@ -XXX,XX +XXX,XX @@ void armv7m_nvic_set_pending_derived(void *opaque, int irq, bool secure) | ||
78 | } | ||
79 | |||
80 | /* Make pending IRQ active. */ | ||
81 | -bool armv7m_nvic_acknowledge_irq(void *opaque) | ||
82 | +void armv7m_nvic_acknowledge_irq(void *opaque) | ||
83 | { | ||
84 | NVICState *s = (NVICState *)opaque; | ||
85 | CPUARMState *env = &s->cpu->env; | ||
86 | const int pending = s->vectpending; | ||
87 | const int running = nvic_exec_prio(s); | ||
88 | VecInfo *vec; | ||
89 | - bool targets_secure; | ||
90 | |||
91 | assert(pending > ARMV7M_EXCP_RESET && pending < s->num_irq); | ||
92 | |||
93 | if (s->vectpending_is_s_banked) { | ||
94 | vec = &s->sec_vectors[pending]; | ||
95 | - targets_secure = true; | ||
96 | } else { | ||
97 | vec = &s->vectors[pending]; | ||
98 | - targets_secure = !exc_is_banked(s->vectpending) && | ||
99 | - exc_targets_secure(s, s->vectpending); | ||
100 | } | ||
101 | |||
102 | assert(vec->enabled); | ||
103 | @@ -XXX,XX +XXX,XX @@ bool armv7m_nvic_acknowledge_irq(void *opaque) | ||
104 | |||
105 | assert(s->vectpending_prio < running); | ||
106 | |||
107 | - trace_nvic_acknowledge_irq(pending, s->vectpending_prio, targets_secure); | ||
108 | + trace_nvic_acknowledge_irq(pending, s->vectpending_prio); | ||
109 | |||
110 | vec->active = 1; | ||
111 | vec->pending = 0; | ||
112 | @@ -XXX,XX +XXX,XX @@ bool armv7m_nvic_acknowledge_irq(void *opaque) | ||
113 | write_v7m_exception(env, s->vectpending); | ||
114 | |||
115 | nvic_irq_update(s); | ||
116 | +} | 33 | +} |
117 | + | 34 | + |
118 | +void armv7m_nvic_get_pending_irq_info(void *opaque, | 35 | static void pll_channel_update(CprmanPllChannelState *channel) |
119 | + int *pirq, bool *ptargets_secure) | 36 | { |
120 | +{ | 37 | - clock_update(channel->out, 0); |
121 | + NVICState *s = (NVICState *)opaque; | 38 | + uint64_t freq, div; |
122 | + const int pending = s->vectpending; | ||
123 | + bool targets_secure; | ||
124 | + | 39 | + |
125 | + assert(pending > ARMV7M_EXCP_RESET && pending < s->num_irq); | 40 | + if (!pll_channel_is_enabled(channel)) { |
126 | + | 41 | + clock_update(channel->out, 0); |
127 | + if (s->vectpending_is_s_banked) { | 42 | + return; |
128 | + targets_secure = true; | ||
129 | + } else { | ||
130 | + targets_secure = !exc_is_banked(pending) && | ||
131 | + exc_targets_secure(s, pending); | ||
132 | + } | 43 | + } |
133 | + | 44 | + |
134 | + trace_nvic_get_pending_irq_info(pending, targets_secure); | 45 | + div = FIELD_EX32(*channel->reg_a2w_ctrl, A2W_PLLx_CHANNELy, DIV); |
135 | 46 | + | |
136 | - return targets_secure; | 47 | + if (!div) { |
137 | + *ptargets_secure = targets_secure; | 48 | + /* |
138 | + *pirq = pending; | 49 | + * It seems that when the divider value is 0, it is considered as |
50 | + * being maximum by the hardware (see the Linux driver). | ||
51 | + */ | ||
52 | + div = R_A2W_PLLx_CHANNELy_DIV_MASK; | ||
53 | + } | ||
54 | + | ||
55 | + /* Some channels have an additional fixed divider */ | ||
56 | + freq = clock_get_hz(channel->pll_in) / (div * channel->fixed_divider); | ||
57 | + | ||
58 | + clock_update_hz(channel->out, freq); | ||
139 | } | 59 | } |
140 | 60 | ||
141 | int armv7m_nvic_complete_irq(void *opaque, int irq, bool secure) | 61 | /* Update a PLL and all its channels */ |
142 | diff --git a/target/arm/helper.c b/target/arm/helper.c | ||
143 | index XXXXXXX..XXXXXXX 100644 | ||
144 | --- a/target/arm/helper.c | ||
145 | +++ b/target/arm/helper.c | ||
146 | @@ -XXX,XX +XXX,XX @@ static uint32_t *get_v7m_sp_ptr(CPUARMState *env, bool secure, bool threadmode, | ||
147 | } | ||
148 | } | ||
149 | |||
150 | -static uint32_t arm_v7m_load_vector(ARMCPU *cpu, bool targets_secure) | ||
151 | +static uint32_t arm_v7m_load_vector(ARMCPU *cpu, int exc, bool targets_secure) | ||
152 | { | ||
153 | CPUState *cs = CPU(cpu); | ||
154 | CPUARMState *env = &cpu->env; | ||
155 | MemTxResult result; | ||
156 | - hwaddr vec = env->v7m.vecbase[targets_secure] + env->v7m.exception * 4; | ||
157 | + hwaddr vec = env->v7m.vecbase[targets_secure] + exc * 4; | ||
158 | uint32_t addr; | ||
159 | |||
160 | addr = address_space_ldl(cs->as, vec, | ||
161 | @@ -XXX,XX +XXX,XX @@ static void v7m_exception_taken(ARMCPU *cpu, uint32_t lr, bool dotailchain) | ||
162 | CPUARMState *env = &cpu->env; | ||
163 | uint32_t addr; | ||
164 | bool targets_secure; | ||
165 | + int exc; | ||
166 | |||
167 | - targets_secure = armv7m_nvic_acknowledge_irq(env->nvic); | ||
168 | + armv7m_nvic_get_pending_irq_info(env->nvic, &exc, &targets_secure); | ||
169 | |||
170 | if (arm_feature(env, ARM_FEATURE_V8)) { | ||
171 | if (arm_feature(env, ARM_FEATURE_M_SECURITY) && | ||
172 | @@ -XXX,XX +XXX,XX @@ static void v7m_exception_taken(ARMCPU *cpu, uint32_t lr, bool dotailchain) | ||
173 | } | ||
174 | } | ||
175 | |||
176 | + addr = arm_v7m_load_vector(cpu, exc, targets_secure); | ||
177 | + | ||
178 | + /* Now we've done everything that might cause a derived exception | ||
179 | + * we can go ahead and activate whichever exception we're going to | ||
180 | + * take (which might now be the derived exception). | ||
181 | + */ | ||
182 | + armv7m_nvic_acknowledge_irq(env->nvic); | ||
183 | + | ||
184 | /* Switch to target security state -- must do this before writing SPSEL */ | ||
185 | switch_v7m_security_state(env, targets_secure); | ||
186 | write_v7m_control_spsel(env, 0); | ||
187 | @@ -XXX,XX +XXX,XX @@ static void v7m_exception_taken(ARMCPU *cpu, uint32_t lr, bool dotailchain) | ||
188 | /* Clear IT bits */ | ||
189 | env->condexec_bits = 0; | ||
190 | env->regs[14] = lr; | ||
191 | - addr = arm_v7m_load_vector(cpu, targets_secure); | ||
192 | env->regs[15] = addr & 0xfffffffe; | ||
193 | env->thumb = addr & 1; | ||
194 | } | ||
195 | diff --git a/hw/intc/trace-events b/hw/intc/trace-events | ||
196 | index XXXXXXX..XXXXXXX 100644 | ||
197 | --- a/hw/intc/trace-events | ||
198 | +++ b/hw/intc/trace-events | ||
199 | @@ -XXX,XX +XXX,XX @@ nvic_escalate_disabled(int irq) "NVIC escalating irq %d to HardFault: disabled" | ||
200 | nvic_set_pending(int irq, bool secure, bool derived, int en, int prio) "NVIC set pending irq %d secure-bank %d derived %d (enabled: %d priority %d)" | ||
201 | nvic_clear_pending(int irq, bool secure, int en, int prio) "NVIC clear pending irq %d secure-bank %d (enabled: %d priority %d)" | ||
202 | nvic_set_pending_level(int irq) "NVIC set pending: irq %d higher prio than vectpending: setting irq line to 1" | ||
203 | -nvic_acknowledge_irq(int irq, int prio, bool targets_secure) "NVIC acknowledge IRQ: %d now active (prio %d targets_secure %d)" | ||
204 | +nvic_acknowledge_irq(int irq, int prio) "NVIC acknowledge IRQ: %d now active (prio %d)" | ||
205 | +nvic_get_pending_irq_info(int irq, bool secure) "NVIC next IRQ %d: targets_secure: %d" | ||
206 | nvic_complete_irq(int irq, bool secure) "NVIC complete IRQ %d (secure %d)" | ||
207 | nvic_set_irq_level(int irq, int level) "NVIC external irq %d level set to %d" | ||
208 | nvic_sysreg_read(uint64_t addr, uint32_t value, unsigned size) "NVIC sysreg read addr 0x%" PRIx64 " data 0x%" PRIx32 " size %u" | ||
209 | -- | 62 | -- |
210 | 2.16.1 | 63 | 2.20.1 |
211 | 64 | ||
212 | 65 | diff view generated by jsdifflib |
1 | From: Andrey Smirnov <andrew.smirnov@gmail.com> | 1 | From: Luc Michel <luc@lmichel.fr> |
---|---|---|---|
2 | 2 | ||
3 | Add minimal code needed to allow upstream Linux guest to boot. | 3 | The clock multiplexers are the last clock stage in the CPRMAN. Each mux |
4 | 4 | outputs one clock signal that goes out of the CPRMAN to the SoC | |
5 | Cc: Peter Maydell <peter.maydell@linaro.org> | 5 | peripherals. |
6 | Cc: Jason Wang <jasowang@redhat.com> | 6 | |
7 | Cc: Philippe Mathieu-Daudé <f4bug@amsat.org> | 7 | Each mux has at most 10 sources. The sources 0 to 3 are common to all |
8 | Cc: Marcel Apfelbaum <marcel.apfelbaum@zoho.com> | 8 | muxes. They are: |
9 | Cc: Michael S. Tsirkin <mst@redhat.com> | 9 | 0. ground (no clock signal) |
10 | Cc: qemu-devel@nongnu.org | 10 | 1. the main oscillator (xosc) |
11 | Cc: qemu-arm@nongnu.org | 11 | 2. "test debug 0" clock |
12 | Cc: yurovsky@gmail.com | 12 | 3. "test debug 1" clock |
13 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 13 | |
14 | Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> | 14 | Test debug 0 and 1 are actual clock muxes that can be used as sources to |
15 | other muxes (for debug purpose). | ||
16 | |||
17 | Sources 4 to 9 are mux specific and can be unpopulated (grounded). Those | ||
18 | sources are fed by the PLL channels outputs. | ||
19 | |||
20 | One corner case exists for DSI0E and DSI0P muxes. They have their source | ||
21 | number 4 connected to an intermediate multiplexer that can select | ||
22 | between PLLA-DSI0 and PLLD-DSI0 channel. This multiplexer is called | ||
23 | DSI0HSCK and is not a clock mux as such. It is really a simple mux from | ||
24 | the hardware point of view (see https://elinux.org/The_Undocumented_Pi). | ||
25 | This mux is not implemented in this commit. | ||
26 | |||
27 | Note that there is some muxes for which sources are unknown (because of | ||
28 | a lack of documentation). For those cases all the sources are connected | ||
29 | to ground in this implementation. | ||
30 | |||
31 | Each clock mux output is exported by the CPRMAN at the qdev level, | ||
32 | adding the suffix '-out' to the mux name to form the output clock name. | ||
33 | (E.g. the 'uart' mux sees its output exported as 'uart-out' at the | ||
34 | CPRMAN level.) | ||
35 | |||
36 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
37 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
38 | Signed-off-by: Luc Michel <luc@lmichel.fr> | ||
39 | Tested-by: Guenter Roeck <linux@roeck-us.net> | ||
15 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 40 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
16 | --- | 41 | --- |
17 | hw/misc/Makefile.objs | 1 + | 42 | include/hw/misc/bcm2835_cprman.h | 85 +++++ |
18 | include/hw/misc/imx7_ccm.h | 139 +++++++++++++++++++++++ | 43 | include/hw/misc/bcm2835_cprman_internals.h | 422 +++++++++++++++++++++ |
19 | hw/misc/imx7_ccm.c | 277 +++++++++++++++++++++++++++++++++++++++++++++ | 44 | hw/misc/bcm2835_cprman.c | 151 ++++++++ |
20 | 3 files changed, 417 insertions(+) | 45 | 3 files changed, 658 insertions(+) |
21 | create mode 100644 include/hw/misc/imx7_ccm.h | 46 | |
22 | create mode 100644 hw/misc/imx7_ccm.c | 47 | diff --git a/include/hw/misc/bcm2835_cprman.h b/include/hw/misc/bcm2835_cprman.h |
23 | |||
24 | diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs | ||
25 | index XXXXXXX..XXXXXXX 100644 | 48 | index XXXXXXX..XXXXXXX 100644 |
26 | --- a/hw/misc/Makefile.objs | 49 | --- a/include/hw/misc/bcm2835_cprman.h |
27 | +++ b/hw/misc/Makefile.objs | 50 | +++ b/include/hw/misc/bcm2835_cprman.h |
28 | @@ -XXX,XX +XXX,XX @@ obj-$(CONFIG_IMX) += imx31_ccm.o | 51 | @@ -XXX,XX +XXX,XX @@ typedef enum CprmanPllChannel { |
29 | obj-$(CONFIG_IMX) += imx25_ccm.o | 52 | CPRMAN_PLLB_CHANNEL_ARM, |
30 | obj-$(CONFIG_IMX) += imx6_ccm.o | 53 | |
31 | obj-$(CONFIG_IMX) += imx6_src.o | 54 | CPRMAN_NUM_PLL_CHANNEL, |
32 | +obj-$(CONFIG_IMX) += imx7_ccm.o | 55 | + |
33 | obj-$(CONFIG_MILKYMIST) += milkymist-hpdmc.o | 56 | + /* Special values used when connecting clock sources to clocks */ |
34 | obj-$(CONFIG_MILKYMIST) += milkymist-pfpu.o | 57 | + CPRMAN_CLOCK_SRC_NORMAL = -1, |
35 | obj-$(CONFIG_MAINSTONE) += mst_fpga.o | 58 | + CPRMAN_CLOCK_SRC_FORCE_GROUND = -2, |
36 | diff --git a/include/hw/misc/imx7_ccm.h b/include/hw/misc/imx7_ccm.h | 59 | + CPRMAN_CLOCK_SRC_DSI0HSCK = -3, |
37 | new file mode 100644 | 60 | } CprmanPllChannel; |
38 | index XXXXXXX..XXXXXXX | 61 | |
39 | --- /dev/null | 62 | +typedef enum CprmanClockMux { |
40 | +++ b/include/hw/misc/imx7_ccm.h | 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 | ||
41 | @@ -XXX,XX +XXX,XX @@ | 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 | + | ||
42 | +/* | 288 | +/* |
43 | + * Copyright (c) 2017, Impinj, Inc. | 289 | + * Each clock mux can have up to 10 sources. Sources 0 to 3 are always the |
290 | + * same (ground, xosc, td0, td1). Sources 4 to 9 are mux specific, and are not | ||
291 | + * always populated. The following macros catch all those cases. | ||
292 | + */ | ||
293 | + | ||
294 | +/* Unknown mapping. Connect everything to ground */ | ||
295 | +#define SRC_MAPPING_INFO_unknown \ | ||
296 | + .src_mapping = { \ | ||
297 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, /* gnd */ \ | ||
298 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, /* xosc */ \ | ||
299 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, /* test debug 0 */ \ | ||
300 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, /* test debug 1 */ \ | ||
301 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, /* pll a */ \ | ||
302 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, /* pll c */ \ | ||
303 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, /* pll d */ \ | ||
304 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, /* pll h */ \ | ||
305 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, /* pll c, core1 */ \ | ||
306 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, /* pll c, core2 */ \ | ||
307 | + } | ||
308 | + | ||
309 | +/* Only the oscillator and the two test debug clocks */ | ||
310 | +#define SRC_MAPPING_INFO_xosc \ | ||
311 | + .src_mapping = { \ | ||
312 | + CPRMAN_CLOCK_SRC_NORMAL, \ | ||
313 | + CPRMAN_CLOCK_SRC_NORMAL, \ | ||
314 | + CPRMAN_CLOCK_SRC_NORMAL, \ | ||
315 | + CPRMAN_CLOCK_SRC_NORMAL, \ | ||
316 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, \ | ||
317 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, \ | ||
318 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, \ | ||
319 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, \ | ||
320 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, \ | ||
321 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, \ | ||
322 | + } | ||
323 | + | ||
324 | +/* All the PLL "core" channels */ | ||
325 | +#define SRC_MAPPING_INFO_core \ | ||
326 | + .src_mapping = { \ | ||
327 | + CPRMAN_CLOCK_SRC_NORMAL, \ | ||
328 | + CPRMAN_CLOCK_SRC_NORMAL, \ | ||
329 | + CPRMAN_CLOCK_SRC_NORMAL, \ | ||
330 | + CPRMAN_CLOCK_SRC_NORMAL, \ | ||
331 | + CPRMAN_PLLA_CHANNEL_CORE, \ | ||
332 | + CPRMAN_PLLC_CHANNEL_CORE0, \ | ||
333 | + CPRMAN_PLLD_CHANNEL_CORE, \ | ||
334 | + CPRMAN_PLLH_CHANNEL_AUX, \ | ||
335 | + CPRMAN_PLLC_CHANNEL_CORE1, \ | ||
336 | + CPRMAN_PLLC_CHANNEL_CORE2, \ | ||
337 | + } | ||
338 | + | ||
339 | +/* All the PLL "per" channels */ | ||
340 | +#define SRC_MAPPING_INFO_periph \ | ||
341 | + .src_mapping = { \ | ||
342 | + CPRMAN_CLOCK_SRC_NORMAL, \ | ||
343 | + CPRMAN_CLOCK_SRC_NORMAL, \ | ||
344 | + CPRMAN_CLOCK_SRC_NORMAL, \ | ||
345 | + CPRMAN_CLOCK_SRC_NORMAL, \ | ||
346 | + CPRMAN_PLLA_CHANNEL_PER, \ | ||
347 | + CPRMAN_PLLC_CHANNEL_PER, \ | ||
348 | + CPRMAN_PLLD_CHANNEL_PER, \ | ||
349 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, \ | ||
350 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, \ | ||
351 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, \ | ||
352 | + } | ||
353 | + | ||
354 | +/* | ||
355 | + * The DSI0 channels. This one got an intermediate mux between the PLL channels | ||
356 | + * and the clock input. | ||
357 | + */ | ||
358 | +#define SRC_MAPPING_INFO_dsi0 \ | ||
359 | + .src_mapping = { \ | ||
360 | + CPRMAN_CLOCK_SRC_NORMAL, \ | ||
361 | + CPRMAN_CLOCK_SRC_NORMAL, \ | ||
362 | + CPRMAN_CLOCK_SRC_NORMAL, \ | ||
363 | + CPRMAN_CLOCK_SRC_NORMAL, \ | ||
364 | + CPRMAN_CLOCK_SRC_DSI0HSCK, \ | ||
365 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, \ | ||
366 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, \ | ||
367 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, \ | ||
368 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, \ | ||
369 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, \ | ||
370 | + } | ||
371 | + | ||
372 | +/* The DSI1 channel */ | ||
373 | +#define SRC_MAPPING_INFO_dsi1 \ | ||
374 | + .src_mapping = { \ | ||
375 | + CPRMAN_CLOCK_SRC_NORMAL, \ | ||
376 | + CPRMAN_CLOCK_SRC_NORMAL, \ | ||
377 | + CPRMAN_CLOCK_SRC_NORMAL, \ | ||
378 | + CPRMAN_CLOCK_SRC_NORMAL, \ | ||
379 | + CPRMAN_PLLD_CHANNEL_DSI1, \ | ||
380 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, \ | ||
381 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, \ | ||
382 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, \ | ||
383 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, \ | ||
384 | + CPRMAN_CLOCK_SRC_FORCE_GROUND, \ | ||
385 | + } | ||
386 | + | ||
387 | +#define FILL_CLOCK_MUX_SRC_MAPPING_INIT_INFO(kind_) \ | ||
388 | + SRC_MAPPING_INFO_ ## kind_ | ||
389 | + | ||
390 | +#define FILL_CLOCK_MUX_INIT_INFO(clock_, kind_) \ | ||
391 | + .cm_offset = R_CM_ ## clock_ ## CTL, \ | ||
392 | + FILL_CLOCK_MUX_SRC_MAPPING_INIT_INFO(kind_) | ||
393 | + | ||
394 | +static ClockMuxInitInfo CLOCK_MUX_INIT_INFO[] = { | ||
395 | + [CPRMAN_CLOCK_GNRIC] = { | ||
396 | + .name = "gnric", | ||
397 | + FILL_CLOCK_MUX_INIT_INFO(GNRIC, unknown), | ||
398 | + }, | ||
399 | + [CPRMAN_CLOCK_VPU] = { | ||
400 | + .name = "vpu", | ||
401 | + .int_bits = 12, | ||
402 | + .frac_bits = 8, | ||
403 | + FILL_CLOCK_MUX_INIT_INFO(VPU, core), | ||
404 | + }, | ||
405 | + [CPRMAN_CLOCK_SYS] = { | ||
406 | + .name = "sys", | ||
407 | + FILL_CLOCK_MUX_INIT_INFO(SYS, unknown), | ||
408 | + }, | ||
409 | + [CPRMAN_CLOCK_PERIA] = { | ||
410 | + .name = "peria", | ||
411 | + FILL_CLOCK_MUX_INIT_INFO(PERIA, unknown), | ||
412 | + }, | ||
413 | + [CPRMAN_CLOCK_PERII] = { | ||
414 | + .name = "perii", | ||
415 | + FILL_CLOCK_MUX_INIT_INFO(PERII, unknown), | ||
416 | + }, | ||
417 | + [CPRMAN_CLOCK_H264] = { | ||
418 | + .name = "h264", | ||
419 | + .int_bits = 4, | ||
420 | + .frac_bits = 8, | ||
421 | + FILL_CLOCK_MUX_INIT_INFO(H264, core), | ||
422 | + }, | ||
423 | + [CPRMAN_CLOCK_ISP] = { | ||
424 | + .name = "isp", | ||
425 | + .int_bits = 4, | ||
426 | + .frac_bits = 8, | ||
427 | + FILL_CLOCK_MUX_INIT_INFO(ISP, core), | ||
428 | + }, | ||
429 | + [CPRMAN_CLOCK_V3D] = { | ||
430 | + .name = "v3d", | ||
431 | + FILL_CLOCK_MUX_INIT_INFO(V3D, core), | ||
432 | + }, | ||
433 | + [CPRMAN_CLOCK_CAM0] = { | ||
434 | + .name = "cam0", | ||
435 | + .int_bits = 4, | ||
436 | + .frac_bits = 8, | ||
437 | + FILL_CLOCK_MUX_INIT_INFO(CAM0, periph), | ||
438 | + }, | ||
439 | + [CPRMAN_CLOCK_CAM1] = { | ||
440 | + .name = "cam1", | ||
441 | + .int_bits = 4, | ||
442 | + .frac_bits = 8, | ||
443 | + FILL_CLOCK_MUX_INIT_INFO(CAM1, periph), | ||
444 | + }, | ||
445 | + [CPRMAN_CLOCK_CCP2] = { | ||
446 | + .name = "ccp2", | ||
447 | + FILL_CLOCK_MUX_INIT_INFO(CCP2, unknown), | ||
448 | + }, | ||
449 | + [CPRMAN_CLOCK_DSI0E] = { | ||
450 | + .name = "dsi0e", | ||
451 | + .int_bits = 4, | ||
452 | + .frac_bits = 8, | ||
453 | + FILL_CLOCK_MUX_INIT_INFO(DSI0E, dsi0), | ||
454 | + }, | ||
455 | + [CPRMAN_CLOCK_DSI0P] = { | ||
456 | + .name = "dsi0p", | ||
457 | + .int_bits = 0, | ||
458 | + .frac_bits = 0, | ||
459 | + FILL_CLOCK_MUX_INIT_INFO(DSI0P, dsi0), | ||
460 | + }, | ||
461 | + [CPRMAN_CLOCK_DPI] = { | ||
462 | + .name = "dpi", | ||
463 | + .int_bits = 4, | ||
464 | + .frac_bits = 8, | ||
465 | + FILL_CLOCK_MUX_INIT_INFO(DPI, periph), | ||
466 | + }, | ||
467 | + [CPRMAN_CLOCK_GP0] = { | ||
468 | + .name = "gp0", | ||
469 | + .int_bits = 12, | ||
470 | + .frac_bits = 12, | ||
471 | + FILL_CLOCK_MUX_INIT_INFO(GP0, periph), | ||
472 | + }, | ||
473 | + [CPRMAN_CLOCK_GP1] = { | ||
474 | + .name = "gp1", | ||
475 | + .int_bits = 12, | ||
476 | + .frac_bits = 12, | ||
477 | + FILL_CLOCK_MUX_INIT_INFO(GP1, periph), | ||
478 | + }, | ||
479 | + [CPRMAN_CLOCK_GP2] = { | ||
480 | + .name = "gp2", | ||
481 | + .int_bits = 12, | ||
482 | + .frac_bits = 12, | ||
483 | + FILL_CLOCK_MUX_INIT_INFO(GP2, periph), | ||
484 | + }, | ||
485 | + [CPRMAN_CLOCK_HSM] = { | ||
486 | + .name = "hsm", | ||
487 | + .int_bits = 4, | ||
488 | + .frac_bits = 8, | ||
489 | + FILL_CLOCK_MUX_INIT_INFO(HSM, periph), | ||
490 | + }, | ||
491 | + [CPRMAN_CLOCK_OTP] = { | ||
492 | + .name = "otp", | ||
493 | + .int_bits = 4, | ||
494 | + .frac_bits = 0, | ||
495 | + FILL_CLOCK_MUX_INIT_INFO(OTP, xosc), | ||
496 | + }, | ||
497 | + [CPRMAN_CLOCK_PCM] = { | ||
498 | + .name = "pcm", | ||
499 | + .int_bits = 12, | ||
500 | + .frac_bits = 12, | ||
501 | + FILL_CLOCK_MUX_INIT_INFO(PCM, periph), | ||
502 | + }, | ||
503 | + [CPRMAN_CLOCK_PWM] = { | ||
504 | + .name = "pwm", | ||
505 | + .int_bits = 12, | ||
506 | + .frac_bits = 12, | ||
507 | + FILL_CLOCK_MUX_INIT_INFO(PWM, periph), | ||
508 | + }, | ||
509 | + [CPRMAN_CLOCK_SLIM] = { | ||
510 | + .name = "slim", | ||
511 | + .int_bits = 12, | ||
512 | + .frac_bits = 12, | ||
513 | + FILL_CLOCK_MUX_INIT_INFO(SLIM, periph), | ||
514 | + }, | ||
515 | + [CPRMAN_CLOCK_SMI] = { | ||
516 | + .name = "smi", | ||
517 | + .int_bits = 4, | ||
518 | + .frac_bits = 8, | ||
519 | + FILL_CLOCK_MUX_INIT_INFO(SMI, periph), | ||
520 | + }, | ||
521 | + [CPRMAN_CLOCK_TEC] = { | ||
522 | + .name = "tec", | ||
523 | + .int_bits = 6, | ||
524 | + .frac_bits = 0, | ||
525 | + FILL_CLOCK_MUX_INIT_INFO(TEC, xosc), | ||
526 | + }, | ||
527 | + [CPRMAN_CLOCK_TD0] = { | ||
528 | + .name = "td0", | ||
529 | + FILL_CLOCK_MUX_INIT_INFO(TD0, unknown), | ||
530 | + }, | ||
531 | + [CPRMAN_CLOCK_TD1] = { | ||
532 | + .name = "td1", | ||
533 | + FILL_CLOCK_MUX_INIT_INFO(TD1, unknown), | ||
534 | + }, | ||
535 | + [CPRMAN_CLOCK_TSENS] = { | ||
536 | + .name = "tsens", | ||
537 | + .int_bits = 5, | ||
538 | + .frac_bits = 0, | ||
539 | + FILL_CLOCK_MUX_INIT_INFO(TSENS, xosc), | ||
540 | + }, | ||
541 | + [CPRMAN_CLOCK_TIMER] = { | ||
542 | + .name = "timer", | ||
543 | + .int_bits = 6, | ||
544 | + .frac_bits = 12, | ||
545 | + FILL_CLOCK_MUX_INIT_INFO(TIMER, xosc), | ||
546 | + }, | ||
547 | + [CPRMAN_CLOCK_UART] = { | ||
548 | + .name = "uart", | ||
549 | + .int_bits = 10, | ||
550 | + .frac_bits = 12, | ||
551 | + FILL_CLOCK_MUX_INIT_INFO(UART, periph), | ||
552 | + }, | ||
553 | + [CPRMAN_CLOCK_VEC] = { | ||
554 | + .name = "vec", | ||
555 | + .int_bits = 4, | ||
556 | + .frac_bits = 0, | ||
557 | + FILL_CLOCK_MUX_INIT_INFO(VEC, periph), | ||
558 | + }, | ||
559 | + [CPRMAN_CLOCK_PULSE] = { | ||
560 | + .name = "pulse", | ||
561 | + FILL_CLOCK_MUX_INIT_INFO(PULSE, xosc), | ||
562 | + }, | ||
563 | + [CPRMAN_CLOCK_SDC] = { | ||
564 | + .name = "sdram", | ||
565 | + .int_bits = 6, | ||
566 | + .frac_bits = 0, | ||
567 | + FILL_CLOCK_MUX_INIT_INFO(SDC, core), | ||
568 | + }, | ||
569 | + [CPRMAN_CLOCK_ARM] = { | ||
570 | + .name = "arm", | ||
571 | + FILL_CLOCK_MUX_INIT_INFO(ARM, unknown), | ||
572 | + }, | ||
573 | + [CPRMAN_CLOCK_AVEO] = { | ||
574 | + .name = "aveo", | ||
575 | + .int_bits = 4, | ||
576 | + .frac_bits = 0, | ||
577 | + FILL_CLOCK_MUX_INIT_INFO(AVEO, periph), | ||
578 | + }, | ||
579 | + [CPRMAN_CLOCK_EMMC] = { | ||
580 | + .name = "emmc", | ||
581 | + .int_bits = 4, | ||
582 | + .frac_bits = 8, | ||
583 | + FILL_CLOCK_MUX_INIT_INFO(EMMC, periph), | ||
584 | + }, | ||
585 | + [CPRMAN_CLOCK_EMMC2] = { | ||
586 | + .name = "emmc2", | ||
587 | + .int_bits = 4, | ||
588 | + .frac_bits = 8, | ||
589 | + FILL_CLOCK_MUX_INIT_INFO(EMMC2, unknown), | ||
590 | + }, | ||
591 | +}; | ||
592 | + | ||
593 | +#undef FILL_CLOCK_MUX_INIT_INFO | ||
594 | +#undef FILL_CLOCK_MUX_SRC_MAPPING_INIT_INFO | ||
595 | +#undef SRC_MAPPING_INFO_dsi1 | ||
596 | +#undef SRC_MAPPING_INFO_dsi0 | ||
597 | +#undef SRC_MAPPING_INFO_periph | ||
598 | +#undef SRC_MAPPING_INFO_core | ||
599 | +#undef SRC_MAPPING_INFO_xosc | ||
600 | +#undef SRC_MAPPING_INFO_unknown | ||
601 | + | ||
602 | +static inline void set_clock_mux_init_info(BCM2835CprmanState *s, | ||
603 | + CprmanClockMuxState *mux, | ||
604 | + CprmanClockMux id) | ||
605 | +{ | ||
606 | + mux->id = id; | ||
607 | + mux->reg_ctl = &s->regs[CLOCK_MUX_INIT_INFO[id].cm_offset]; | ||
608 | + mux->reg_div = &s->regs[CLOCK_MUX_INIT_INFO[id].cm_offset + 1]; | ||
609 | + mux->int_bits = CLOCK_MUX_INIT_INFO[id].int_bits; | ||
610 | + mux->frac_bits = CLOCK_MUX_INIT_INFO[id].frac_bits; | ||
611 | +} | ||
612 | + | ||
613 | #endif | ||
614 | diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c | ||
615 | index XXXXXXX..XXXXXXX 100644 | ||
616 | --- a/hw/misc/bcm2835_cprman.c | ||
617 | +++ b/hw/misc/bcm2835_cprman.c | ||
618 | @@ -XXX,XX +XXX,XX @@ | ||
619 | * | ||
620 | * The page at https://elinux.org/The_Undocumented_Pi gives the actual clock | ||
621 | * tree configuration. | ||
44 | + * | 622 | + * |
45 | + * i.MX7 CCM, PMU and ANALOG IP blocks emulation code | 623 | + * The CPRMAN exposes clock outputs with the name of the clock mux suffixed |
46 | + * | 624 | + * with "-out" (e.g. "uart-out", "h264-out", ...). |
47 | + * Author: Andrey Smirnov <andrew.smirnov@gmail.com> | 625 | */ |
48 | + * | 626 | |
49 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | 627 | #include "qemu/osdep.h" |
50 | + * See the COPYING file in the top-level directory. | 628 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo cprman_pll_channel_info = { |
51 | + */ | 629 | }; |
52 | + | 630 | |
53 | +#ifndef IMX7_CCM_H | 631 | |
54 | +#define IMX7_CCM_H | 632 | +/* clock mux */ |
55 | + | 633 | + |
56 | +#include "hw/misc/imx_ccm.h" | 634 | +static void clock_mux_update(CprmanClockMuxState *mux) |
57 | +#include "qemu/bitops.h" | ||
58 | + | ||
59 | +enum IMX7AnalogRegisters { | ||
60 | + ANALOG_PLL_ARM, | ||
61 | + ANALOG_PLL_ARM_SET, | ||
62 | + ANALOG_PLL_ARM_CLR, | ||
63 | + ANALOG_PLL_ARM_TOG, | ||
64 | + ANALOG_PLL_DDR, | ||
65 | + ANALOG_PLL_DDR_SET, | ||
66 | + ANALOG_PLL_DDR_CLR, | ||
67 | + ANALOG_PLL_DDR_TOG, | ||
68 | + ANALOG_PLL_DDR_SS, | ||
69 | + ANALOG_PLL_DDR_SS_SET, | ||
70 | + ANALOG_PLL_DDR_SS_CLR, | ||
71 | + ANALOG_PLL_DDR_SS_TOG, | ||
72 | + ANALOG_PLL_DDR_NUM, | ||
73 | + ANALOG_PLL_DDR_NUM_SET, | ||
74 | + ANALOG_PLL_DDR_NUM_CLR, | ||
75 | + ANALOG_PLL_DDR_NUM_TOG, | ||
76 | + ANALOG_PLL_DDR_DENOM, | ||
77 | + ANALOG_PLL_DDR_DENOM_SET, | ||
78 | + ANALOG_PLL_DDR_DENOM_CLR, | ||
79 | + ANALOG_PLL_DDR_DENOM_TOG, | ||
80 | + ANALOG_PLL_480, | ||
81 | + ANALOG_PLL_480_SET, | ||
82 | + ANALOG_PLL_480_CLR, | ||
83 | + ANALOG_PLL_480_TOG, | ||
84 | + ANALOG_PLL_480A, | ||
85 | + ANALOG_PLL_480A_SET, | ||
86 | + ANALOG_PLL_480A_CLR, | ||
87 | + ANALOG_PLL_480A_TOG, | ||
88 | + ANALOG_PLL_480B, | ||
89 | + ANALOG_PLL_480B_SET, | ||
90 | + ANALOG_PLL_480B_CLR, | ||
91 | + ANALOG_PLL_480B_TOG, | ||
92 | + ANALOG_PLL_ENET, | ||
93 | + ANALOG_PLL_ENET_SET, | ||
94 | + ANALOG_PLL_ENET_CLR, | ||
95 | + ANALOG_PLL_ENET_TOG, | ||
96 | + ANALOG_PLL_AUDIO, | ||
97 | + ANALOG_PLL_AUDIO_SET, | ||
98 | + ANALOG_PLL_AUDIO_CLR, | ||
99 | + ANALOG_PLL_AUDIO_TOG, | ||
100 | + ANALOG_PLL_AUDIO_SS, | ||
101 | + ANALOG_PLL_AUDIO_SS_SET, | ||
102 | + ANALOG_PLL_AUDIO_SS_CLR, | ||
103 | + ANALOG_PLL_AUDIO_SS_TOG, | ||
104 | + ANALOG_PLL_AUDIO_NUM, | ||
105 | + ANALOG_PLL_AUDIO_NUM_SET, | ||
106 | + ANALOG_PLL_AUDIO_NUM_CLR, | ||
107 | + ANALOG_PLL_AUDIO_NUM_TOG, | ||
108 | + ANALOG_PLL_AUDIO_DENOM, | ||
109 | + ANALOG_PLL_AUDIO_DENOM_SET, | ||
110 | + ANALOG_PLL_AUDIO_DENOM_CLR, | ||
111 | + ANALOG_PLL_AUDIO_DENOM_TOG, | ||
112 | + ANALOG_PLL_VIDEO, | ||
113 | + ANALOG_PLL_VIDEO_SET, | ||
114 | + ANALOG_PLL_VIDEO_CLR, | ||
115 | + ANALOG_PLL_VIDEO_TOG, | ||
116 | + ANALOG_PLL_VIDEO_SS, | ||
117 | + ANALOG_PLL_VIDEO_SS_SET, | ||
118 | + ANALOG_PLL_VIDEO_SS_CLR, | ||
119 | + ANALOG_PLL_VIDEO_SS_TOG, | ||
120 | + ANALOG_PLL_VIDEO_NUM, | ||
121 | + ANALOG_PLL_VIDEO_NUM_SET, | ||
122 | + ANALOG_PLL_VIDEO_NUM_CLR, | ||
123 | + ANALOG_PLL_VIDEO_NUM_TOG, | ||
124 | + ANALOG_PLL_VIDEO_DENOM, | ||
125 | + ANALOG_PLL_VIDEO_DENOM_SET, | ||
126 | + ANALOG_PLL_VIDEO_DENOM_CLR, | ||
127 | + ANALOG_PLL_VIDEO_DENOM_TOG, | ||
128 | + ANALOG_PLL_MISC0, | ||
129 | + ANALOG_PLL_MISC0_SET, | ||
130 | + ANALOG_PLL_MISC0_CLR, | ||
131 | + ANALOG_PLL_MISC0_TOG, | ||
132 | + | ||
133 | + ANALOG_DIGPROG = 0x800 / sizeof(uint32_t), | ||
134 | + ANALOG_MAX, | ||
135 | + | ||
136 | + ANALOG_PLL_LOCK = BIT(31) | ||
137 | +}; | ||
138 | + | ||
139 | +enum IMX7CCMRegisters { | ||
140 | + CCM_MAX = 0xBE00 / sizeof(uint32_t) + 1, | ||
141 | +}; | ||
142 | + | ||
143 | +enum IMX7PMURegisters { | ||
144 | + PMU_MAX = 0x140 / sizeof(uint32_t), | ||
145 | +}; | ||
146 | + | ||
147 | +#define TYPE_IMX7_CCM "imx7.ccm" | ||
148 | +#define IMX7_CCM(obj) OBJECT_CHECK(IMX7CCMState, (obj), TYPE_IMX7_CCM) | ||
149 | + | ||
150 | +typedef struct IMX7CCMState { | ||
151 | + /* <private> */ | ||
152 | + IMXCCMState parent_obj; | ||
153 | + | ||
154 | + /* <public> */ | ||
155 | + MemoryRegion iomem; | ||
156 | + | ||
157 | + uint32_t ccm[CCM_MAX]; | ||
158 | +} IMX7CCMState; | ||
159 | + | ||
160 | + | ||
161 | +#define TYPE_IMX7_ANALOG "imx7.analog" | ||
162 | +#define IMX7_ANALOG(obj) OBJECT_CHECK(IMX7AnalogState, (obj), TYPE_IMX7_ANALOG) | ||
163 | + | ||
164 | +typedef struct IMX7AnalogState { | ||
165 | + /* <private> */ | ||
166 | + IMXCCMState parent_obj; | ||
167 | + | ||
168 | + /* <public> */ | ||
169 | + struct { | ||
170 | + MemoryRegion container; | ||
171 | + MemoryRegion analog; | ||
172 | + MemoryRegion digprog; | ||
173 | + MemoryRegion pmu; | ||
174 | + } mmio; | ||
175 | + | ||
176 | + uint32_t analog[ANALOG_MAX]; | ||
177 | + uint32_t pmu[PMU_MAX]; | ||
178 | +} IMX7AnalogState; | ||
179 | + | ||
180 | +#endif /* IMX7_CCM_H */ | ||
181 | diff --git a/hw/misc/imx7_ccm.c b/hw/misc/imx7_ccm.c | ||
182 | new file mode 100644 | ||
183 | index XXXXXXX..XXXXXXX | ||
184 | --- /dev/null | ||
185 | +++ b/hw/misc/imx7_ccm.c | ||
186 | @@ -XXX,XX +XXX,XX @@ | ||
187 | +/* | ||
188 | + * Copyright (c) 2018, Impinj, Inc. | ||
189 | + * | ||
190 | + * i.MX7 CCM, PMU and ANALOG IP blocks emulation code | ||
191 | + * | ||
192 | + * Author: Andrey Smirnov <andrew.smirnov@gmail.com> | ||
193 | + * | ||
194 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
195 | + * See the COPYING file in the top-level directory. | ||
196 | + */ | ||
197 | + | ||
198 | +#include "qemu/osdep.h" | ||
199 | +#include "qemu/log.h" | ||
200 | + | ||
201 | +#include "hw/misc/imx7_ccm.h" | ||
202 | + | ||
203 | +static void imx7_analog_reset(DeviceState *dev) | ||
204 | +{ | 635 | +{ |
205 | + IMX7AnalogState *s = IMX7_ANALOG(dev); | 636 | + clock_update(mux->out, 0); |
206 | + | ||
207 | + memset(s->pmu, 0, sizeof(s->pmu)); | ||
208 | + memset(s->analog, 0, sizeof(s->analog)); | ||
209 | + | ||
210 | + s->analog[ANALOG_PLL_ARM] = 0x00002042; | ||
211 | + s->analog[ANALOG_PLL_DDR] = 0x0060302c; | ||
212 | + s->analog[ANALOG_PLL_DDR_SS] = 0x00000000; | ||
213 | + s->analog[ANALOG_PLL_DDR_NUM] = 0x06aaac4d; | ||
214 | + s->analog[ANALOG_PLL_DDR_DENOM] = 0x100003ec; | ||
215 | + s->analog[ANALOG_PLL_480] = 0x00002000; | ||
216 | + s->analog[ANALOG_PLL_480A] = 0x52605a56; | ||
217 | + s->analog[ANALOG_PLL_480B] = 0x52525216; | ||
218 | + s->analog[ANALOG_PLL_ENET] = 0x00001fc0; | ||
219 | + s->analog[ANALOG_PLL_AUDIO] = 0x0001301b; | ||
220 | + s->analog[ANALOG_PLL_AUDIO_SS] = 0x00000000; | ||
221 | + s->analog[ANALOG_PLL_AUDIO_NUM] = 0x05f5e100; | ||
222 | + s->analog[ANALOG_PLL_AUDIO_DENOM] = 0x2964619c; | ||
223 | + s->analog[ANALOG_PLL_VIDEO] = 0x0008201b; | ||
224 | + s->analog[ANALOG_PLL_VIDEO_SS] = 0x00000000; | ||
225 | + s->analog[ANALOG_PLL_VIDEO_NUM] = 0x0000f699; | ||
226 | + s->analog[ANALOG_PLL_VIDEO_DENOM] = 0x000f4240; | ||
227 | + s->analog[ANALOG_PLL_MISC0] = 0x00000000; | ||
228 | + | ||
229 | + /* all PLLs need to be locked */ | ||
230 | + s->analog[ANALOG_PLL_ARM] |= ANALOG_PLL_LOCK; | ||
231 | + s->analog[ANALOG_PLL_DDR] |= ANALOG_PLL_LOCK; | ||
232 | + s->analog[ANALOG_PLL_480] |= ANALOG_PLL_LOCK; | ||
233 | + s->analog[ANALOG_PLL_480A] |= ANALOG_PLL_LOCK; | ||
234 | + s->analog[ANALOG_PLL_480B] |= ANALOG_PLL_LOCK; | ||
235 | + s->analog[ANALOG_PLL_ENET] |= ANALOG_PLL_LOCK; | ||
236 | + s->analog[ANALOG_PLL_AUDIO] |= ANALOG_PLL_LOCK; | ||
237 | + s->analog[ANALOG_PLL_VIDEO] |= ANALOG_PLL_LOCK; | ||
238 | + s->analog[ANALOG_PLL_MISC0] |= ANALOG_PLL_LOCK; | ||
239 | + | ||
240 | + /* | ||
241 | + * Since I couldn't find any info about this in the reference | ||
242 | + * manual the value of this register is based strictly on matching | ||
243 | + * what Linux kernel expects it to be. | ||
244 | + */ | ||
245 | + s->analog[ANALOG_DIGPROG] = 0x720000; | ||
246 | + /* | ||
247 | + * Set revision to be 1.0 (Arbitrary choice, no particular | ||
248 | + * reason). | ||
249 | + */ | ||
250 | + s->analog[ANALOG_DIGPROG] |= 0x000010; | ||
251 | +} | 637 | +} |
252 | + | 638 | + |
253 | +static void imx7_ccm_reset(DeviceState *dev) | 639 | +static void clock_mux_src_update(void *opaque) |
254 | +{ | 640 | +{ |
255 | + IMX7CCMState *s = IMX7_CCM(dev); | 641 | + CprmanClockMuxState **backref = opaque; |
256 | + | 642 | + CprmanClockMuxState *s = *backref; |
257 | + memset(s->ccm, 0, sizeof(s->ccm)); | 643 | + |
644 | + clock_mux_update(s); | ||
258 | +} | 645 | +} |
259 | + | 646 | + |
260 | +#define CCM_INDEX(offset) (((offset) & ~(hwaddr)0xF) / sizeof(uint32_t)) | 647 | +static void clock_mux_init(Object *obj) |
261 | +#define CCM_BITOP(offset) ((offset) & (hwaddr)0xF) | ||
262 | + | ||
263 | +enum { | ||
264 | + CCM_BITOP_NONE = 0x00, | ||
265 | + CCM_BITOP_SET = 0x04, | ||
266 | + CCM_BITOP_CLR = 0x08, | ||
267 | + CCM_BITOP_TOG = 0x0C, | ||
268 | +}; | ||
269 | + | ||
270 | +static uint64_t imx7_set_clr_tog_read(void *opaque, hwaddr offset, | ||
271 | + unsigned size) | ||
272 | +{ | 648 | +{ |
273 | + const uint32_t *mmio = opaque; | 649 | + CprmanClockMuxState *s = CPRMAN_CLOCK_MUX(obj); |
274 | + | 650 | + size_t i; |
275 | + return mmio[CCM_INDEX(offset)]; | 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"); | ||
276 | +} | 662 | +} |
277 | + | 663 | + |
278 | +static void imx7_set_clr_tog_write(void *opaque, hwaddr offset, | 664 | +static const VMStateDescription clock_mux_vmstate = { |
279 | + uint64_t value, unsigned size) | 665 | + .name = TYPE_CPRMAN_CLOCK_MUX, |
280 | +{ | ||
281 | + const uint8_t bitop = CCM_BITOP(offset); | ||
282 | + const uint32_t index = CCM_INDEX(offset); | ||
283 | + uint32_t *mmio = opaque; | ||
284 | + | ||
285 | + switch (bitop) { | ||
286 | + case CCM_BITOP_NONE: | ||
287 | + mmio[index] = value; | ||
288 | + break; | ||
289 | + case CCM_BITOP_SET: | ||
290 | + mmio[index] |= value; | ||
291 | + break; | ||
292 | + case CCM_BITOP_CLR: | ||
293 | + mmio[index] &= ~value; | ||
294 | + break; | ||
295 | + case CCM_BITOP_TOG: | ||
296 | + mmio[index] ^= value; | ||
297 | + break; | ||
298 | + }; | ||
299 | +} | ||
300 | + | ||
301 | +static const struct MemoryRegionOps imx7_set_clr_tog_ops = { | ||
302 | + .read = imx7_set_clr_tog_read, | ||
303 | + .write = imx7_set_clr_tog_write, | ||
304 | + .endianness = DEVICE_NATIVE_ENDIAN, | ||
305 | + .impl = { | ||
306 | + /* | ||
307 | + * Our device would not work correctly if the guest was doing | ||
308 | + * unaligned access. This might not be a limitation on the real | ||
309 | + * device but in practice there is no reason for a guest to access | ||
310 | + * this device unaligned. | ||
311 | + */ | ||
312 | + .min_access_size = 4, | ||
313 | + .max_access_size = 4, | ||
314 | + .unaligned = false, | ||
315 | + }, | ||
316 | +}; | ||
317 | + | ||
318 | +static const struct MemoryRegionOps imx7_digprog_ops = { | ||
319 | + .read = imx7_set_clr_tog_read, | ||
320 | + .endianness = DEVICE_NATIVE_ENDIAN, | ||
321 | + .impl = { | ||
322 | + .min_access_size = 4, | ||
323 | + .max_access_size = 4, | ||
324 | + .unaligned = false, | ||
325 | + }, | ||
326 | +}; | ||
327 | + | ||
328 | +static void imx7_ccm_init(Object *obj) | ||
329 | +{ | ||
330 | + SysBusDevice *sd = SYS_BUS_DEVICE(obj); | ||
331 | + IMX7CCMState *s = IMX7_CCM(obj); | ||
332 | + | ||
333 | + memory_region_init_io(&s->iomem, | ||
334 | + obj, | ||
335 | + &imx7_set_clr_tog_ops, | ||
336 | + s->ccm, | ||
337 | + TYPE_IMX7_CCM ".ccm", | ||
338 | + sizeof(s->ccm)); | ||
339 | + | ||
340 | + sysbus_init_mmio(sd, &s->iomem); | ||
341 | +} | ||
342 | + | ||
343 | +static void imx7_analog_init(Object *obj) | ||
344 | +{ | ||
345 | + SysBusDevice *sd = SYS_BUS_DEVICE(obj); | ||
346 | + IMX7AnalogState *s = IMX7_ANALOG(obj); | ||
347 | + | ||
348 | + memory_region_init(&s->mmio.container, obj, TYPE_IMX7_ANALOG, | ||
349 | + 0x10000); | ||
350 | + | ||
351 | + memory_region_init_io(&s->mmio.analog, | ||
352 | + obj, | ||
353 | + &imx7_set_clr_tog_ops, | ||
354 | + s->analog, | ||
355 | + TYPE_IMX7_ANALOG, | ||
356 | + sizeof(s->analog)); | ||
357 | + | ||
358 | + memory_region_add_subregion(&s->mmio.container, | ||
359 | + 0x60, &s->mmio.analog); | ||
360 | + | ||
361 | + memory_region_init_io(&s->mmio.pmu, | ||
362 | + obj, | ||
363 | + &imx7_set_clr_tog_ops, | ||
364 | + s->pmu, | ||
365 | + TYPE_IMX7_ANALOG ".pmu", | ||
366 | + sizeof(s->pmu)); | ||
367 | + | ||
368 | + memory_region_add_subregion(&s->mmio.container, | ||
369 | + 0x200, &s->mmio.pmu); | ||
370 | + | ||
371 | + memory_region_init_io(&s->mmio.digprog, | ||
372 | + obj, | ||
373 | + &imx7_digprog_ops, | ||
374 | + &s->analog[ANALOG_DIGPROG], | ||
375 | + TYPE_IMX7_ANALOG ".digprog", | ||
376 | + sizeof(uint32_t)); | ||
377 | + | ||
378 | + memory_region_add_subregion_overlap(&s->mmio.container, | ||
379 | + 0x800, &s->mmio.digprog, 10); | ||
380 | + | ||
381 | + | ||
382 | + sysbus_init_mmio(sd, &s->mmio.container); | ||
383 | +} | ||
384 | + | ||
385 | +static const VMStateDescription vmstate_imx7_ccm = { | ||
386 | + .name = TYPE_IMX7_CCM, | ||
387 | + .version_id = 1, | 666 | + .version_id = 1, |
388 | + .minimum_version_id = 1, | 667 | + .minimum_version_id = 1, |
389 | + .fields = (VMStateField[]) { | 668 | + .fields = (VMStateField[]) { |
390 | + VMSTATE_UINT32_ARRAY(ccm, IMX7CCMState, CCM_MAX), | 669 | + VMSTATE_ARRAY_CLOCK(srcs, CprmanClockMuxState, |
670 | + CPRMAN_NUM_CLOCK_MUX_SRC), | ||
391 | + VMSTATE_END_OF_LIST() | 671 | + VMSTATE_END_OF_LIST() |
392 | + }, | 672 | + } |
393 | +}; | 673 | +}; |
394 | + | 674 | + |
395 | +static uint32_t imx7_ccm_get_clock_frequency(IMXCCMState *dev, IMXClk clock) | 675 | +static void clock_mux_class_init(ObjectClass *klass, void *data) |
396 | +{ | ||
397 | + /* | ||
398 | + * This function is "consumed" by GPT emulation code, however on | ||
399 | + * i.MX7 each GPT block can have their own clock root. This means | ||
400 | + * that this functions needs somehow to know requester's identity | ||
401 | + * and the way to pass it: be it via additional IMXClk constants | ||
402 | + * or by adding another argument to this method needs to be | ||
403 | + * figured out | ||
404 | + */ | ||
405 | + qemu_log_mask(LOG_GUEST_ERROR, "[%s]%s: Not implemented\n", | ||
406 | + TYPE_IMX7_CCM, __func__); | ||
407 | + return 0; | ||
408 | +} | ||
409 | + | ||
410 | +static void imx7_ccm_class_init(ObjectClass *klass, void *data) | ||
411 | +{ | 676 | +{ |
412 | + DeviceClass *dc = DEVICE_CLASS(klass); | 677 | + DeviceClass *dc = DEVICE_CLASS(klass); |
413 | + IMXCCMClass *ccm = IMX_CCM_CLASS(klass); | 678 | + |
414 | + | 679 | + dc->vmsd = &clock_mux_vmstate; |
415 | + dc->reset = imx7_ccm_reset; | ||
416 | + dc->vmsd = &vmstate_imx7_ccm; | ||
417 | + dc->desc = "i.MX7 Clock Control Module"; | ||
418 | + | ||
419 | + ccm->get_clock_frequency = imx7_ccm_get_clock_frequency; | ||
420 | +} | 680 | +} |
421 | + | 681 | + |
422 | +static const TypeInfo imx7_ccm_info = { | 682 | +static const TypeInfo cprman_clock_mux_info = { |
423 | + .name = TYPE_IMX7_CCM, | 683 | + .name = TYPE_CPRMAN_CLOCK_MUX, |
424 | + .parent = TYPE_IMX_CCM, | 684 | + .parent = TYPE_DEVICE, |
425 | + .instance_size = sizeof(IMX7CCMState), | 685 | + .instance_size = sizeof(CprmanClockMuxState), |
426 | + .instance_init = imx7_ccm_init, | 686 | + .class_init = clock_mux_class_init, |
427 | + .class_init = imx7_ccm_class_init, | 687 | + .instance_init = clock_mux_init, |
428 | +}; | 688 | +}; |
429 | + | 689 | + |
430 | +static const VMStateDescription vmstate_imx7_analog = { | 690 | + |
431 | + .name = TYPE_IMX7_ANALOG, | 691 | /* CPRMAN "top level" model */ |
432 | + .version_id = 1, | 692 | |
433 | + .minimum_version_id = 1, | 693 | static uint32_t get_cm_lock(const BCM2835CprmanState *s) |
434 | + .fields = (VMStateField[]) { | 694 | @@ -XXX,XX +XXX,XX @@ static inline void update_channel_from_a2w(BCM2835CprmanState *s, size_t idx) |
435 | + VMSTATE_UINT32_ARRAY(analog, IMX7AnalogState, ANALOG_MAX), | 695 | } |
436 | + VMSTATE_UINT32_ARRAY(pmu, IMX7AnalogState, PMU_MAX), | 696 | } |
437 | + VMSTATE_END_OF_LIST() | 697 | |
438 | + }, | 698 | +static inline void update_mux_from_cm(BCM2835CprmanState *s, size_t idx) |
439 | +}; | ||
440 | + | ||
441 | +static void imx7_analog_class_init(ObjectClass *klass, void *data) | ||
442 | +{ | 699 | +{ |
443 | + DeviceClass *dc = DEVICE_CLASS(klass); | 700 | + size_t i; |
444 | + | 701 | + |
445 | + dc->reset = imx7_analog_reset; | 702 | + for (i = 0; i < CPRMAN_NUM_CLOCK_MUX; i++) { |
446 | + dc->vmsd = &vmstate_imx7_analog; | 703 | + if ((CLOCK_MUX_INIT_INFO[i].cm_offset == idx) || |
447 | + dc->desc = "i.MX7 Analog Module"; | 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 | + } | ||
448 | +} | 710 | +} |
449 | + | 711 | + |
450 | +static const TypeInfo imx7_analog_info = { | 712 | #define CASE_PLL_A2W_REGS(pll_) \ |
451 | + .name = TYPE_IMX7_ANALOG, | 713 | case R_A2W_ ## pll_ ## _CTRL: \ |
452 | + .parent = TYPE_SYS_BUS_DEVICE, | 714 | case R_A2W_ ## pll_ ## _ANA0: \ |
453 | + .instance_size = sizeof(IMX7AnalogState), | 715 | @@ -XXX,XX +XXX,XX @@ static void cprman_write(void *opaque, hwaddr offset, |
454 | + .instance_init = imx7_analog_init, | 716 | case R_A2W_PLLB_ARM: |
455 | + .class_init = imx7_analog_class_init, | 717 | update_channel_from_a2w(s, idx); |
456 | +}; | 718 | break; |
457 | + | 719 | + |
458 | +static void imx7_ccm_register_type(void) | 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) | ||
459 | +{ | 773 | +{ |
460 | + type_register_static(&imx7_ccm_info); | 774 | + size_t i; |
461 | + type_register_static(&imx7_analog_info); | 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 | + } | ||
462 | +} | 802 | +} |
463 | +type_init(imx7_ccm_register_type) | 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); | ||
464 | -- | 832 | -- |
465 | 2.16.1 | 833 | 2.20.1 |
466 | 834 | ||
467 | 835 | diff view generated by jsdifflib |
1 | From: Ard Biesheuvel <ard.biesheuvel@linaro.org> | 1 | From: Luc Michel <luc@lmichel.fr> |
---|---|---|---|
2 | 2 | ||
3 | This implements emulation of the new SHA-512 instructions that have | 3 | A clock mux can be configured to select one of its 10 sources through |
4 | been added as an optional extensions to the ARMv8 Crypto Extensions | 4 | the CM_CTL register. It also embeds yet another clock divider, composed |
5 | in ARM v8.2. | 5 | of an integer part and a fractional part. The number of bits of each |
6 | part is mux dependent. | ||
6 | 7 | ||
7 | Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> | 8 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
8 | Message-id: 20180207111729.15737-2-ard.biesheuvel@linaro.org | 9 | Signed-off-by: Luc Michel <luc@lmichel.fr> |
9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
11 | Tested-by: Guenter Roeck <linux@roeck-us.net> | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
11 | --- | 13 | --- |
12 | target/arm/cpu.h | 1 + | 14 | hw/misc/bcm2835_cprman.c | 53 +++++++++++++++++++++++++++++++++++++++- |
13 | target/arm/helper.h | 5 +++ | 15 | 1 file changed, 52 insertions(+), 1 deletion(-) |
14 | target/arm/crypto_helper.c | 90 ++++++++++++++++++++++++++++++++++++- | ||
15 | target/arm/translate-a64.c | 110 +++++++++++++++++++++++++++++++++++++++++++++ | ||
16 | 4 files changed, 205 insertions(+), 1 deletion(-) | ||
17 | 16 | ||
18 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | 17 | diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c |
19 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/target/arm/cpu.h | 19 | --- a/hw/misc/bcm2835_cprman.c |
21 | +++ b/target/arm/cpu.h | 20 | +++ b/hw/misc/bcm2835_cprman.c |
22 | @@ -XXX,XX +XXX,XX @@ enum arm_features { | 21 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo cprman_pll_channel_info = { |
23 | ARM_FEATURE_M_SECURITY, /* M profile Security Extension */ | 22 | |
24 | ARM_FEATURE_JAZELLE, /* has (trivial) Jazelle implementation */ | 23 | /* clock mux */ |
25 | ARM_FEATURE_SVE, /* has Scalable Vector Extension */ | 24 | |
26 | + ARM_FEATURE_V8_SHA512, /* implements SHA512 part of v8 Crypto Extensions */ | 25 | +static bool clock_mux_is_enabled(CprmanClockMuxState *mux) |
27 | }; | ||
28 | |||
29 | static inline int arm_feature(CPUARMState *env, int feature) | ||
30 | diff --git a/target/arm/helper.h b/target/arm/helper.h | ||
31 | index XXXXXXX..XXXXXXX 100644 | ||
32 | --- a/target/arm/helper.h | ||
33 | +++ b/target/arm/helper.h | ||
34 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_3(crypto_sha256h2, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) | ||
35 | DEF_HELPER_FLAGS_2(crypto_sha256su0, TCG_CALL_NO_RWG, void, ptr, ptr) | ||
36 | DEF_HELPER_FLAGS_3(crypto_sha256su1, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) | ||
37 | |||
38 | +DEF_HELPER_FLAGS_3(crypto_sha512h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) | ||
39 | +DEF_HELPER_FLAGS_3(crypto_sha512h2, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) | ||
40 | +DEF_HELPER_FLAGS_2(crypto_sha512su0, TCG_CALL_NO_RWG, void, ptr, ptr) | ||
41 | +DEF_HELPER_FLAGS_3(crypto_sha512su1, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) | ||
42 | + | ||
43 | DEF_HELPER_FLAGS_3(crc32, TCG_CALL_NO_RWG_SE, i32, i32, i32, i32) | ||
44 | DEF_HELPER_FLAGS_3(crc32c, TCG_CALL_NO_RWG_SE, i32, i32, i32, i32) | ||
45 | DEF_HELPER_2(dc_zva, void, env, i64) | ||
46 | diff --git a/target/arm/crypto_helper.c b/target/arm/crypto_helper.c | ||
47 | index XXXXXXX..XXXXXXX 100644 | ||
48 | --- a/target/arm/crypto_helper.c | ||
49 | +++ b/target/arm/crypto_helper.c | ||
50 | @@ -XXX,XX +XXX,XX @@ | ||
51 | /* | ||
52 | * crypto_helper.c - emulate v8 Crypto Extensions instructions | ||
53 | * | ||
54 | - * Copyright (C) 2013 - 2014 Linaro Ltd <ard.biesheuvel@linaro.org> | ||
55 | + * Copyright (C) 2013 - 2018 Linaro Ltd <ard.biesheuvel@linaro.org> | ||
56 | * | ||
57 | * This library is free software; you can redistribute it and/or | ||
58 | * modify it under the terms of the GNU Lesser General Public | ||
59 | @@ -XXX,XX +XXX,XX @@ void HELPER(crypto_sha256su1)(void *vd, void *vn, void *vm) | ||
60 | rd[0] = d.l[0]; | ||
61 | rd[1] = d.l[1]; | ||
62 | } | ||
63 | + | ||
64 | +/* | ||
65 | + * The SHA-512 logical functions (same as above but using 64-bit operands) | ||
66 | + */ | ||
67 | + | ||
68 | +static uint64_t cho512(uint64_t x, uint64_t y, uint64_t z) | ||
69 | +{ | 26 | +{ |
70 | + return (x & (y ^ z)) ^ z; | 27 | + return FIELD_EX32(*mux->reg_ctl, CM_CLOCKx_CTL, ENABLE); |
71 | +} | 28 | +} |
72 | + | 29 | + |
73 | +static uint64_t maj512(uint64_t x, uint64_t y, uint64_t z) | 30 | static void clock_mux_update(CprmanClockMuxState *mux) |
74 | +{ | 31 | { |
75 | + return (x & y) | ((x | y) & z); | 32 | - clock_update(mux->out, 0); |
76 | +} | 33 | + uint64_t freq; |
34 | + uint32_t div, src = FIELD_EX32(*mux->reg_ctl, CM_CLOCKx_CTL, SRC); | ||
35 | + bool enabled = clock_mux_is_enabled(mux); | ||
77 | + | 36 | + |
78 | +static uint64_t S0_512(uint64_t x) | 37 | + *mux->reg_ctl = FIELD_DP32(*mux->reg_ctl, CM_CLOCKx_CTL, BUSY, enabled); |
79 | +{ | ||
80 | + return ror64(x, 28) ^ ror64(x, 34) ^ ror64(x, 39); | ||
81 | +} | ||
82 | + | 38 | + |
83 | +static uint64_t S1_512(uint64_t x) | 39 | + if (!enabled) { |
84 | +{ | 40 | + clock_update(mux->out, 0); |
85 | + return ror64(x, 14) ^ ror64(x, 18) ^ ror64(x, 41); | ||
86 | +} | ||
87 | + | ||
88 | +static uint64_t s0_512(uint64_t x) | ||
89 | +{ | ||
90 | + return ror64(x, 1) ^ ror64(x, 8) ^ (x >> 7); | ||
91 | +} | ||
92 | + | ||
93 | +static uint64_t s1_512(uint64_t x) | ||
94 | +{ | ||
95 | + return ror64(x, 19) ^ ror64(x, 61) ^ (x >> 6); | ||
96 | +} | ||
97 | + | ||
98 | +void HELPER(crypto_sha512h)(void *vd, void *vn, void *vm) | ||
99 | +{ | ||
100 | + uint64_t *rd = vd; | ||
101 | + uint64_t *rn = vn; | ||
102 | + uint64_t *rm = vm; | ||
103 | + uint64_t d0 = rd[0]; | ||
104 | + uint64_t d1 = rd[1]; | ||
105 | + | ||
106 | + d1 += S1_512(rm[1]) + cho512(rm[1], rn[0], rn[1]); | ||
107 | + d0 += S1_512(d1 + rm[0]) + cho512(d1 + rm[0], rm[1], rn[0]); | ||
108 | + | ||
109 | + rd[0] = d0; | ||
110 | + rd[1] = d1; | ||
111 | +} | ||
112 | + | ||
113 | +void HELPER(crypto_sha512h2)(void *vd, void *vn, void *vm) | ||
114 | +{ | ||
115 | + uint64_t *rd = vd; | ||
116 | + uint64_t *rn = vn; | ||
117 | + uint64_t *rm = vm; | ||
118 | + uint64_t d0 = rd[0]; | ||
119 | + uint64_t d1 = rd[1]; | ||
120 | + | ||
121 | + d1 += S0_512(rm[0]) + maj512(rn[0], rm[1], rm[0]); | ||
122 | + d0 += S0_512(d1) + maj512(d1, rm[0], rm[1]); | ||
123 | + | ||
124 | + rd[0] = d0; | ||
125 | + rd[1] = d1; | ||
126 | +} | ||
127 | + | ||
128 | +void HELPER(crypto_sha512su0)(void *vd, void *vn) | ||
129 | +{ | ||
130 | + uint64_t *rd = vd; | ||
131 | + uint64_t *rn = vn; | ||
132 | + uint64_t d0 = rd[0]; | ||
133 | + uint64_t d1 = rd[1]; | ||
134 | + | ||
135 | + d0 += s0_512(rd[1]); | ||
136 | + d1 += s0_512(rn[0]); | ||
137 | + | ||
138 | + rd[0] = d0; | ||
139 | + rd[1] = d1; | ||
140 | +} | ||
141 | + | ||
142 | +void HELPER(crypto_sha512su1)(void *vd, void *vn, void *vm) | ||
143 | +{ | ||
144 | + uint64_t *rd = vd; | ||
145 | + uint64_t *rn = vn; | ||
146 | + uint64_t *rm = vm; | ||
147 | + | ||
148 | + rd[0] += s1_512(rn[0]) + rm[0]; | ||
149 | + rd[1] += s1_512(rn[1]) + rm[1]; | ||
150 | +} | ||
151 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | ||
152 | index XXXXXXX..XXXXXXX 100644 | ||
153 | --- a/target/arm/translate-a64.c | ||
154 | +++ b/target/arm/translate-a64.c | ||
155 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_two_reg_sha(DisasContext *s, uint32_t insn) | ||
156 | tcg_temp_free_ptr(tcg_rn_ptr); | ||
157 | } | ||
158 | |||
159 | +/* Crypto three-reg SHA512 | ||
160 | + * 31 21 20 16 15 14 13 12 11 10 9 5 4 0 | ||
161 | + * +-----------------------+------+---+---+-----+--------+------+------+ | ||
162 | + * | 1 1 0 0 1 1 1 0 0 1 1 | Rm | 1 | O | 0 0 | opcode | Rn | Rd | | ||
163 | + * +-----------------------+------+---+---+-----+--------+------+------+ | ||
164 | + */ | ||
165 | +static void disas_crypto_three_reg_sha512(DisasContext *s, uint32_t insn) | ||
166 | +{ | ||
167 | + int opcode = extract32(insn, 10, 2); | ||
168 | + int o = extract32(insn, 14, 1); | ||
169 | + int rm = extract32(insn, 16, 5); | ||
170 | + int rn = extract32(insn, 5, 5); | ||
171 | + int rd = extract32(insn, 0, 5); | ||
172 | + int feature; | ||
173 | + CryptoThreeOpFn *genfn; | ||
174 | + | ||
175 | + if (o == 0) { | ||
176 | + switch (opcode) { | ||
177 | + case 0: /* SHA512H */ | ||
178 | + feature = ARM_FEATURE_V8_SHA512; | ||
179 | + genfn = gen_helper_crypto_sha512h; | ||
180 | + break; | ||
181 | + case 1: /* SHA512H2 */ | ||
182 | + feature = ARM_FEATURE_V8_SHA512; | ||
183 | + genfn = gen_helper_crypto_sha512h2; | ||
184 | + break; | ||
185 | + case 2: /* SHA512SU1 */ | ||
186 | + feature = ARM_FEATURE_V8_SHA512; | ||
187 | + genfn = gen_helper_crypto_sha512su1; | ||
188 | + break; | ||
189 | + default: | ||
190 | + unallocated_encoding(s); | ||
191 | + return; | ||
192 | + } | ||
193 | + } else { | ||
194 | + unallocated_encoding(s); | ||
195 | + return; | 41 | + return; |
196 | + } | 42 | + } |
197 | + | 43 | + |
198 | + if (!arm_dc_feature(s, feature)) { | 44 | + freq = clock_get_hz(mux->srcs[src]); |
199 | + unallocated_encoding(s); | 45 | + |
46 | + if (mux->int_bits == 0 && mux->frac_bits == 0) { | ||
47 | + clock_update_hz(mux->out, freq); | ||
200 | + return; | 48 | + return; |
201 | + } | 49 | + } |
202 | + | 50 | + |
203 | + if (!fp_access_check(s)) { | 51 | + /* |
52 | + * The divider has an integer and a fractional part. The size of each part | ||
53 | + * varies with the muxes (int_bits and frac_bits). Both parts are | ||
54 | + * concatenated, with the integer part always starting at bit 12. | ||
55 | + * | ||
56 | + * 31 12 11 0 | ||
57 | + * ------------------------------ | ||
58 | + * CM_DIV | | int | frac | | | ||
59 | + * ------------------------------ | ||
60 | + * <-----> <------> | ||
61 | + * int_bits frac_bits | ||
62 | + */ | ||
63 | + div = extract32(*mux->reg_div, | ||
64 | + R_CM_CLOCKx_DIV_FRAC_LENGTH - mux->frac_bits, | ||
65 | + mux->int_bits + mux->frac_bits); | ||
66 | + | ||
67 | + if (!div) { | ||
68 | + clock_update(mux->out, 0); | ||
204 | + return; | 69 | + return; |
205 | + } | 70 | + } |
206 | + | 71 | + |
207 | + if (genfn) { | 72 | + freq = muldiv64(freq, 1 << mux->frac_bits, div); |
208 | + TCGv_ptr tcg_rd_ptr, tcg_rn_ptr, tcg_rm_ptr; | ||
209 | + | 73 | + |
210 | + tcg_rd_ptr = vec_full_reg_ptr(s, rd); | 74 | + clock_update_hz(mux->out, freq); |
211 | + tcg_rn_ptr = vec_full_reg_ptr(s, rn); | 75 | } |
212 | + tcg_rm_ptr = vec_full_reg_ptr(s, rm); | 76 | |
77 | static void clock_mux_src_update(void *opaque) | ||
78 | { | ||
79 | CprmanClockMuxState **backref = opaque; | ||
80 | CprmanClockMuxState *s = *backref; | ||
81 | + CprmanClockMuxSource src = backref - s->backref; | ||
213 | + | 82 | + |
214 | + genfn(tcg_rd_ptr, tcg_rn_ptr, tcg_rm_ptr); | 83 | + if (FIELD_EX32(*s->reg_ctl, CM_CLOCKx_CTL, SRC) != src) { |
215 | + | ||
216 | + tcg_temp_free_ptr(tcg_rd_ptr); | ||
217 | + tcg_temp_free_ptr(tcg_rn_ptr); | ||
218 | + tcg_temp_free_ptr(tcg_rm_ptr); | ||
219 | + } else { | ||
220 | + g_assert_not_reached(); | ||
221 | + } | ||
222 | +} | ||
223 | + | ||
224 | +/* Crypto two-reg SHA512 | ||
225 | + * 31 12 11 10 9 5 4 0 | ||
226 | + * +-----------------------------------------+--------+------+------+ | ||
227 | + * | 1 1 0 0 1 1 1 0 1 1 0 0 0 0 0 0 1 0 0 0 | opcode | Rn | Rd | | ||
228 | + * +-----------------------------------------+--------+------+------+ | ||
229 | + */ | ||
230 | +static void disas_crypto_two_reg_sha512(DisasContext *s, uint32_t insn) | ||
231 | +{ | ||
232 | + int opcode = extract32(insn, 10, 2); | ||
233 | + int rn = extract32(insn, 5, 5); | ||
234 | + int rd = extract32(insn, 0, 5); | ||
235 | + TCGv_ptr tcg_rd_ptr, tcg_rn_ptr; | ||
236 | + int feature; | ||
237 | + CryptoTwoOpFn *genfn; | ||
238 | + | ||
239 | + switch (opcode) { | ||
240 | + case 0: /* SHA512SU0 */ | ||
241 | + feature = ARM_FEATURE_V8_SHA512; | ||
242 | + genfn = gen_helper_crypto_sha512su0; | ||
243 | + break; | ||
244 | + default: | ||
245 | + unallocated_encoding(s); | ||
246 | + return; | 84 | + return; |
247 | + } | 85 | + } |
248 | + | 86 | |
249 | + if (!arm_dc_feature(s, feature)) { | 87 | clock_mux_update(s); |
250 | + unallocated_encoding(s); | 88 | } |
251 | + return; | ||
252 | + } | ||
253 | + | ||
254 | + if (!fp_access_check(s)) { | ||
255 | + return; | ||
256 | + } | ||
257 | + | ||
258 | + tcg_rd_ptr = vec_full_reg_ptr(s, rd); | ||
259 | + tcg_rn_ptr = vec_full_reg_ptr(s, rn); | ||
260 | + | ||
261 | + genfn(tcg_rd_ptr, tcg_rn_ptr); | ||
262 | + | ||
263 | + tcg_temp_free_ptr(tcg_rd_ptr); | ||
264 | + tcg_temp_free_ptr(tcg_rn_ptr); | ||
265 | +} | ||
266 | + | ||
267 | /* C3.6 Data processing - SIMD, inc Crypto | ||
268 | * | ||
269 | * As the decode gets a little complex we are using a table based | ||
270 | @@ -XXX,XX +XXX,XX @@ static const AArch64DecodeTable data_proc_simd[] = { | ||
271 | { 0x4e280800, 0xff3e0c00, disas_crypto_aes }, | ||
272 | { 0x5e000000, 0xff208c00, disas_crypto_three_reg_sha }, | ||
273 | { 0x5e280800, 0xff3e0c00, disas_crypto_two_reg_sha }, | ||
274 | + { 0xce608000, 0xffe0b000, disas_crypto_three_reg_sha512 }, | ||
275 | + { 0xcec08000, 0xfffff000, disas_crypto_two_reg_sha512 }, | ||
276 | { 0x00000000, 0x00000000, NULL } | ||
277 | }; | ||
278 | |||
279 | -- | 89 | -- |
280 | 2.16.1 | 90 | 2.20.1 |
281 | 91 | ||
282 | 92 | diff view generated by jsdifflib |
1 | Make v7m_push_callee_stack() honour the MPU by using the | 1 | From: Luc Michel <luc@lmichel.fr> |
---|---|---|---|
2 | new v7m_stack_write() function. We return a flag to indicate | 2 | |
3 | whether the pushes failed, which we can then use in | 3 | This simple mux sits between the PLL channels and the DSI0E and DSI0P |
4 | v7m_exception_taken() to cause us to handle the derived | 4 | clock muxes. This mux selects between PLLA-DSI0 and PLLD-DSI0 channel |
5 | exception correctly. | 5 | and outputs the selected signal to source number 4 of DSI0E/P clock |
6 | 6 | muxes. It is controlled by the cm_dsi0hsck register. | |
7 | |||
8 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
9 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
10 | Signed-off-by: Luc Michel <luc@lmichel.fr> | ||
11 | Tested-by: Guenter Roeck <linux@roeck-us.net> | ||
7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
8 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
9 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
10 | Message-id: 1517324542-6607-6-git-send-email-peter.maydell@linaro.org | ||
11 | --- | 13 | --- |
12 | target/arm/helper.c | 64 ++++++++++++++++++++++++++++++++++++++++------------- | 14 | include/hw/misc/bcm2835_cprman.h | 15 +++++ |
13 | 1 file changed, 49 insertions(+), 15 deletions(-) | 15 | include/hw/misc/bcm2835_cprman_internals.h | 6 ++ |
14 | 16 | hw/misc/bcm2835_cprman.c | 74 +++++++++++++++++++++- | |
15 | diff --git a/target/arm/helper.c b/target/arm/helper.c | 17 | 3 files changed, 94 insertions(+), 1 deletion(-) |
18 | |||
19 | diff --git a/include/hw/misc/bcm2835_cprman.h b/include/hw/misc/bcm2835_cprman.h | ||
16 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/target/arm/helper.c | 21 | --- a/include/hw/misc/bcm2835_cprman.h |
18 | +++ b/target/arm/helper.c | 22 | +++ b/include/hw/misc/bcm2835_cprman.h |
19 | @@ -XXX,XX +XXX,XX @@ static uint32_t arm_v7m_load_vector(ARMCPU *cpu, int exc, bool targets_secure) | 23 | @@ -XXX,XX +XXX,XX @@ typedef struct CprmanClockMuxState { |
20 | return addr; | 24 | struct CprmanClockMuxState *backref[CPRMAN_NUM_CLOCK_MUX_SRC]; |
25 | } CprmanClockMuxState; | ||
26 | |||
27 | +typedef struct CprmanDsi0HsckMuxState { | ||
28 | + /*< private >*/ | ||
29 | + DeviceState parent_obj; | ||
30 | + | ||
31 | + /*< public >*/ | ||
32 | + CprmanClockMux id; | ||
33 | + | ||
34 | + uint32_t *reg_cm; | ||
35 | + | ||
36 | + Clock *plla_in; | ||
37 | + Clock *plld_in; | ||
38 | + Clock *out; | ||
39 | +} CprmanDsi0HsckMuxState; | ||
40 | + | ||
41 | struct BCM2835CprmanState { | ||
42 | /*< private >*/ | ||
43 | SysBusDevice parent_obj; | ||
44 | @@ -XXX,XX +XXX,XX @@ struct BCM2835CprmanState { | ||
45 | CprmanPllState plls[CPRMAN_NUM_PLL]; | ||
46 | CprmanPllChannelState channels[CPRMAN_NUM_PLL_CHANNEL]; | ||
47 | CprmanClockMuxState clock_muxes[CPRMAN_NUM_CLOCK_MUX]; | ||
48 | + CprmanDsi0HsckMuxState dsi0hsck_mux; | ||
49 | |||
50 | uint32_t regs[CPRMAN_NUM_REGS]; | ||
51 | uint32_t xosc_freq; | ||
52 | diff --git a/include/hw/misc/bcm2835_cprman_internals.h b/include/hw/misc/bcm2835_cprman_internals.h | ||
53 | index XXXXXXX..XXXXXXX 100644 | ||
54 | --- a/include/hw/misc/bcm2835_cprman_internals.h | ||
55 | +++ b/include/hw/misc/bcm2835_cprman_internals.h | ||
56 | @@ -XXX,XX +XXX,XX @@ | ||
57 | #define TYPE_CPRMAN_PLL "bcm2835-cprman-pll" | ||
58 | #define TYPE_CPRMAN_PLL_CHANNEL "bcm2835-cprman-pll-channel" | ||
59 | #define TYPE_CPRMAN_CLOCK_MUX "bcm2835-cprman-clock-mux" | ||
60 | +#define TYPE_CPRMAN_DSI0HSCK_MUX "bcm2835-cprman-dsi0hsck-mux" | ||
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 | } | ||
21 | } | 155 | } |
22 | 156 | ||
23 | -static void v7m_push_callee_stack(ARMCPU *cpu, uint32_t lr, bool dotailchain, | 157 | @@ -XXX,XX +XXX,XX @@ static void cprman_reset(DeviceState *dev) |
24 | +static bool v7m_push_callee_stack(ARMCPU *cpu, uint32_t lr, bool dotailchain, | 158 | device_cold_reset(DEVICE(&s->channels[i])); |
25 | bool ignore_faults) | 159 | } |
26 | { | 160 | |
27 | /* For v8M, push the callee-saves register part of the stack frame. | 161 | + device_cold_reset(DEVICE(&s->dsi0hsck_mux)); |
28 | @@ -XXX,XX +XXX,XX @@ static void v7m_push_callee_stack(ARMCPU *cpu, uint32_t lr, bool dotailchain, | 162 | + |
29 | * In the tailchaining case this may not be the current stack. | 163 | for (i = 0; i < CPRMAN_NUM_CLOCK_MUX; i++) { |
30 | */ | 164 | device_cold_reset(DEVICE(&s->clock_muxes[i])); |
31 | CPUARMState *env = &cpu->env; | 165 | } |
32 | - CPUState *cs = CPU(cpu); | 166 | @@ -XXX,XX +XXX,XX @@ static void cprman_init(Object *obj) |
33 | uint32_t *frame_sp_p; | 167 | set_pll_channel_init_info(s, &s->channels[i], i); |
34 | uint32_t frameptr; | 168 | } |
35 | + ARMMMUIdx mmu_idx; | 169 | |
36 | + bool stacked_ok; | 170 | + object_initialize_child(obj, "dsi0hsck-mux", |
37 | 171 | + &s->dsi0hsck_mux, TYPE_CPRMAN_DSI0HSCK_MUX); | |
38 | if (dotailchain) { | 172 | + s->dsi0hsck_mux.reg_cm = &s->regs[R_CM_DSI0HSCK]; |
39 | - frame_sp_p = get_v7m_sp_ptr(env, true, | 173 | + |
40 | - lr & R_V7M_EXCRET_MODE_MASK, | 174 | for (i = 0; i < CPRMAN_NUM_CLOCK_MUX; i++) { |
41 | + bool mode = lr & R_V7M_EXCRET_MODE_MASK; | 175 | char *alias; |
42 | + bool priv = !(env->v7m.control[M_REG_S] & R_V7M_CONTROL_NPRIV_MASK) || | 176 | |
43 | + !mode; | 177 | @@ -XXX,XX +XXX,XX @@ static void connect_mux_sources(BCM2835CprmanState *s, |
44 | + | 178 | if (mapping == CPRMAN_CLOCK_SRC_FORCE_GROUND) { |
45 | + mmu_idx = arm_v7m_mmu_idx_for_secstate_and_priv(env, M_REG_S, priv); | 179 | src = s->gnd; |
46 | + frame_sp_p = get_v7m_sp_ptr(env, M_REG_S, mode, | 180 | } else if (mapping == CPRMAN_CLOCK_SRC_DSI0HSCK) { |
47 | lr & R_V7M_EXCRET_SPSEL_MASK); | 181 | - src = s->gnd; /* TODO */ |
48 | } else { | 182 | + src = s->dsi0hsck_mux.out; |
49 | + mmu_idx = core_to_arm_mmu_idx(env, cpu_mmu_index(env, false)); | 183 | } else if (i < CPRMAN_CLOCK_SRC_PLLA) { |
50 | frame_sp_p = &env->regs[13]; | 184 | src = CLK_SRC_MAPPING[i]; |
51 | } | 185 | } else { |
52 | 186 | @@ -XXX,XX +XXX,XX @@ static void cprman_realize(DeviceState *dev, Error **errp) | |
53 | frameptr = *frame_sp_p - 0x28; | ||
54 | |||
55 | - stl_phys(cs->as, frameptr, 0xfefa125b); | ||
56 | - stl_phys(cs->as, frameptr + 0x8, env->regs[4]); | ||
57 | - stl_phys(cs->as, frameptr + 0xc, env->regs[5]); | ||
58 | - stl_phys(cs->as, frameptr + 0x10, env->regs[6]); | ||
59 | - stl_phys(cs->as, frameptr + 0x14, env->regs[7]); | ||
60 | - stl_phys(cs->as, frameptr + 0x18, env->regs[8]); | ||
61 | - stl_phys(cs->as, frameptr + 0x1c, env->regs[9]); | ||
62 | - stl_phys(cs->as, frameptr + 0x20, env->regs[10]); | ||
63 | - stl_phys(cs->as, frameptr + 0x24, env->regs[11]); | ||
64 | + /* Write as much of the stack frame as we can. A write failure may | ||
65 | + * cause us to pend a derived exception. | ||
66 | + */ | ||
67 | + stacked_ok = | ||
68 | + v7m_stack_write(cpu, frameptr, 0xfefa125b, mmu_idx, ignore_faults) && | ||
69 | + v7m_stack_write(cpu, frameptr + 0x8, env->regs[4], mmu_idx, | ||
70 | + ignore_faults) && | ||
71 | + v7m_stack_write(cpu, frameptr + 0xc, env->regs[5], mmu_idx, | ||
72 | + ignore_faults) && | ||
73 | + v7m_stack_write(cpu, frameptr + 0x10, env->regs[6], mmu_idx, | ||
74 | + ignore_faults) && | ||
75 | + v7m_stack_write(cpu, frameptr + 0x14, env->regs[7], mmu_idx, | ||
76 | + ignore_faults) && | ||
77 | + v7m_stack_write(cpu, frameptr + 0x18, env->regs[8], mmu_idx, | ||
78 | + ignore_faults) && | ||
79 | + v7m_stack_write(cpu, frameptr + 0x1c, env->regs[9], mmu_idx, | ||
80 | + ignore_faults) && | ||
81 | + v7m_stack_write(cpu, frameptr + 0x20, env->regs[10], mmu_idx, | ||
82 | + ignore_faults) && | ||
83 | + v7m_stack_write(cpu, frameptr + 0x24, env->regs[11], mmu_idx, | ||
84 | + ignore_faults); | ||
85 | |||
86 | + /* Update SP regardless of whether any of the stack accesses failed. | ||
87 | + * When we implement v8M stack limit checking then this attempt to | ||
88 | + * update SP might also fail and result in a derived exception. | ||
89 | + */ | ||
90 | *frame_sp_p = frameptr; | ||
91 | + | ||
92 | + return !stacked_ok; | ||
93 | } | ||
94 | |||
95 | static void v7m_exception_taken(ARMCPU *cpu, uint32_t lr, bool dotailchain, | ||
96 | @@ -XXX,XX +XXX,XX @@ static void v7m_exception_taken(ARMCPU *cpu, uint32_t lr, bool dotailchain, | ||
97 | uint32_t addr; | ||
98 | bool targets_secure; | ||
99 | int exc; | ||
100 | + bool push_failed = false; | ||
101 | |||
102 | armv7m_nvic_get_pending_irq_info(env->nvic, &exc, &targets_secure); | ||
103 | |||
104 | @@ -XXX,XX +XXX,XX @@ static void v7m_exception_taken(ARMCPU *cpu, uint32_t lr, bool dotailchain, | ||
105 | */ | ||
106 | if (lr & R_V7M_EXCRET_DCRS_MASK && | ||
107 | !(dotailchain && (lr & R_V7M_EXCRET_ES_MASK))) { | ||
108 | - v7m_push_callee_stack(cpu, lr, dotailchain, | ||
109 | - ignore_stackfaults); | ||
110 | + push_failed = v7m_push_callee_stack(cpu, lr, dotailchain, | ||
111 | + ignore_stackfaults); | ||
112 | } | ||
113 | lr |= R_V7M_EXCRET_DCRS_MASK; | ||
114 | } | ||
115 | @@ -XXX,XX +XXX,XX @@ static void v7m_exception_taken(ARMCPU *cpu, uint32_t lr, bool dotailchain, | ||
116 | } | 187 | } |
117 | } | 188 | } |
118 | 189 | ||
119 | + if (push_failed && !ignore_stackfaults) { | 190 | + clock_set_source(s->dsi0hsck_mux.plla_in, |
120 | + /* Derived exception on callee-saves register stacking: | 191 | + s->channels[CPRMAN_PLLA_CHANNEL_DSI0].out); |
121 | + * we might now want to take a different exception which | 192 | + clock_set_source(s->dsi0hsck_mux.plld_in, |
122 | + * targets a different security state, so try again from the top. | 193 | + s->channels[CPRMAN_PLLD_CHANNEL_DSI0].out); |
123 | + */ | 194 | + |
124 | + v7m_exception_taken(cpu, lr, true, true); | 195 | + if (!qdev_realize(DEVICE(&s->dsi0hsck_mux), NULL, errp)) { |
125 | + return; | 196 | + return; |
126 | + } | 197 | + } |
127 | + | 198 | + |
128 | addr = arm_v7m_load_vector(cpu, exc, targets_secure); | 199 | for (i = 0; i < CPRMAN_NUM_CLOCK_MUX; i++) { |
129 | 200 | CprmanClockMuxState *clock_mux = &s->clock_muxes[i]; | |
130 | /* Now we've done everything that might cause a derived exception | 201 | |
202 | @@ -XXX,XX +XXX,XX @@ static void cprman_register_types(void) | ||
203 | type_register_static(&cprman_pll_info); | ||
204 | type_register_static(&cprman_pll_channel_info); | ||
205 | type_register_static(&cprman_clock_mux_info); | ||
206 | + type_register_static(&cprman_dsi0hsck_mux_info); | ||
207 | } | ||
208 | |||
209 | type_init(cprman_register_types); | ||
131 | -- | 210 | -- |
132 | 2.16.1 | 211 | 2.20.1 |
133 | 212 | ||
134 | 213 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | From: Luc Michel <luc@lmichel.fr> | |
2 | |||
3 | Those reset values have been extracted from a Raspberry Pi 3 model B | ||
4 | v1.2, using the 2020-08-20 version of raspios. The dump was done using | ||
5 | the debugfs interface of the CPRMAN driver in Linux (under | ||
6 | '/sys/kernel/debug/clk'). Each exposed clock tree stage (PLLs, channels | ||
7 | and muxes) can be observed by reading the 'regdump' file (e.g. | ||
8 | 'plla/regdump'). | ||
9 | |||
10 | Those values are set by the Raspberry Pi firmware at boot time (Linux | ||
11 | expects them to be set when it boots up). | ||
12 | |||
13 | Some stages are not exposed by the Linux driver (e.g. the PLL B). For | ||
14 | those, the reset values are unknown and left to 0 which implies a | ||
15 | disabled output. | ||
16 | |||
17 | Once booted in QEMU, the final clock tree is very similar to the one | ||
18 | visible on real hardware. The differences come from some unimplemented | ||
19 | devices for which the driver simply disable the corresponding clock. | ||
20 | |||
21 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
22 | Signed-off-by: Luc Michel <luc@lmichel.fr> | ||
23 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
24 | Tested-by: Guenter Roeck <linux@roeck-us.net> | ||
25 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
26 | --- | ||
27 | include/hw/misc/bcm2835_cprman_internals.h | 269 +++++++++++++++++++++ | ||
28 | hw/misc/bcm2835_cprman.c | 31 +++ | ||
29 | 2 files changed, 300 insertions(+) | ||
30 | |||
31 | diff --git a/include/hw/misc/bcm2835_cprman_internals.h b/include/hw/misc/bcm2835_cprman_internals.h | ||
32 | index XXXXXXX..XXXXXXX 100644 | ||
33 | --- a/include/hw/misc/bcm2835_cprman_internals.h | ||
34 | +++ b/include/hw/misc/bcm2835_cprman_internals.h | ||
35 | @@ -XXX,XX +XXX,XX @@ static inline void set_clock_mux_init_info(BCM2835CprmanState *s, | ||
36 | mux->frac_bits = CLOCK_MUX_INIT_INFO[id].frac_bits; | ||
37 | } | ||
38 | |||
39 | + | ||
40 | +/* | ||
41 | + * Object reset info | ||
42 | + * Those values have been dumped from a Raspberry Pi 3 Model B v1.2 using the | ||
43 | + * clk debugfs interface in Linux. | ||
44 | + */ | ||
45 | +typedef struct PLLResetInfo { | ||
46 | + uint32_t cm; | ||
47 | + uint32_t a2w_ctrl; | ||
48 | + uint32_t a2w_ana[4]; | ||
49 | + uint32_t a2w_frac; | ||
50 | +} PLLResetInfo; | ||
51 | + | ||
52 | +static const PLLResetInfo PLL_RESET_INFO[] = { | ||
53 | + [CPRMAN_PLLA] = { | ||
54 | + .cm = 0x0000008a, | ||
55 | + .a2w_ctrl = 0x0002103a, | ||
56 | + .a2w_frac = 0x00098000, | ||
57 | + .a2w_ana = { 0x00000000, 0x00144000, 0x00000000, 0x00000100 } | ||
58 | + }, | ||
59 | + | ||
60 | + [CPRMAN_PLLC] = { | ||
61 | + .cm = 0x00000228, | ||
62 | + .a2w_ctrl = 0x0002103e, | ||
63 | + .a2w_frac = 0x00080000, | ||
64 | + .a2w_ana = { 0x00000000, 0x00144000, 0x00000000, 0x00000100 } | ||
65 | + }, | ||
66 | + | ||
67 | + [CPRMAN_PLLD] = { | ||
68 | + .cm = 0x0000020a, | ||
69 | + .a2w_ctrl = 0x00021034, | ||
70 | + .a2w_frac = 0x00015556, | ||
71 | + .a2w_ana = { 0x00000000, 0x00144000, 0x00000000, 0x00000100 } | ||
72 | + }, | ||
73 | + | ||
74 | + [CPRMAN_PLLH] = { | ||
75 | + .cm = 0x00000000, | ||
76 | + .a2w_ctrl = 0x0002102d, | ||
77 | + .a2w_frac = 0x00000000, | ||
78 | + .a2w_ana = { 0x00900000, 0x0000000c, 0x00000000, 0x00000000 } | ||
79 | + }, | ||
80 | + | ||
81 | + [CPRMAN_PLLB] = { | ||
82 | + /* unknown */ | ||
83 | + .cm = 0x00000000, | ||
84 | + .a2w_ctrl = 0x00000000, | ||
85 | + .a2w_frac = 0x00000000, | ||
86 | + .a2w_ana = { 0x00000000, 0x00000000, 0x00000000, 0x00000000 } | ||
87 | + } | ||
88 | +}; | ||
89 | + | ||
90 | +typedef struct PLLChannelResetInfo { | ||
91 | + /* | ||
92 | + * Even though a PLL channel has a CM register, it shares it with its | ||
93 | + * parent PLL. The parent already takes care of the reset value. | ||
94 | + */ | ||
95 | + uint32_t a2w_ctrl; | ||
96 | +} PLLChannelResetInfo; | ||
97 | + | ||
98 | +static const PLLChannelResetInfo PLL_CHANNEL_RESET_INFO[] = { | ||
99 | + [CPRMAN_PLLA_CHANNEL_DSI0] = { .a2w_ctrl = 0x00000100 }, | ||
100 | + [CPRMAN_PLLA_CHANNEL_CORE] = { .a2w_ctrl = 0x00000003 }, | ||
101 | + [CPRMAN_PLLA_CHANNEL_PER] = { .a2w_ctrl = 0x00000000 }, /* unknown */ | ||
102 | + [CPRMAN_PLLA_CHANNEL_CCP2] = { .a2w_ctrl = 0x00000100 }, | ||
103 | + | ||
104 | + [CPRMAN_PLLC_CHANNEL_CORE2] = { .a2w_ctrl = 0x00000100 }, | ||
105 | + [CPRMAN_PLLC_CHANNEL_CORE1] = { .a2w_ctrl = 0x00000100 }, | ||
106 | + [CPRMAN_PLLC_CHANNEL_PER] = { .a2w_ctrl = 0x00000002 }, | ||
107 | + [CPRMAN_PLLC_CHANNEL_CORE0] = { .a2w_ctrl = 0x00000002 }, | ||
108 | + | ||
109 | + [CPRMAN_PLLD_CHANNEL_DSI0] = { .a2w_ctrl = 0x00000100 }, | ||
110 | + [CPRMAN_PLLD_CHANNEL_CORE] = { .a2w_ctrl = 0x00000004 }, | ||
111 | + [CPRMAN_PLLD_CHANNEL_PER] = { .a2w_ctrl = 0x00000004 }, | ||
112 | + [CPRMAN_PLLD_CHANNEL_DSI1] = { .a2w_ctrl = 0x00000100 }, | ||
113 | + | ||
114 | + [CPRMAN_PLLH_CHANNEL_AUX] = { .a2w_ctrl = 0x00000004 }, | ||
115 | + [CPRMAN_PLLH_CHANNEL_RCAL] = { .a2w_ctrl = 0x00000000 }, | ||
116 | + [CPRMAN_PLLH_CHANNEL_PIX] = { .a2w_ctrl = 0x00000000 }, | ||
117 | + | ||
118 | + [CPRMAN_PLLB_CHANNEL_ARM] = { .a2w_ctrl = 0x00000000 }, /* unknown */ | ||
119 | +}; | ||
120 | + | ||
121 | +typedef struct ClockMuxResetInfo { | ||
122 | + uint32_t cm_ctl; | ||
123 | + uint32_t cm_div; | ||
124 | +} ClockMuxResetInfo; | ||
125 | + | ||
126 | +static const ClockMuxResetInfo CLOCK_MUX_RESET_INFO[] = { | ||
127 | + [CPRMAN_CLOCK_GNRIC] = { | ||
128 | + .cm_ctl = 0, /* unknown */ | ||
129 | + .cm_div = 0 | ||
130 | + }, | ||
131 | + | ||
132 | + [CPRMAN_CLOCK_VPU] = { | ||
133 | + .cm_ctl = 0x00000245, | ||
134 | + .cm_div = 0x00003000, | ||
135 | + }, | ||
136 | + | ||
137 | + [CPRMAN_CLOCK_SYS] = { | ||
138 | + .cm_ctl = 0, /* unknown */ | ||
139 | + .cm_div = 0 | ||
140 | + }, | ||
141 | + | ||
142 | + [CPRMAN_CLOCK_PERIA] = { | ||
143 | + .cm_ctl = 0, /* unknown */ | ||
144 | + .cm_div = 0 | ||
145 | + }, | ||
146 | + | ||
147 | + [CPRMAN_CLOCK_PERII] = { | ||
148 | + .cm_ctl = 0, /* unknown */ | ||
149 | + .cm_div = 0 | ||
150 | + }, | ||
151 | + | ||
152 | + [CPRMAN_CLOCK_H264] = { | ||
153 | + .cm_ctl = 0x00000244, | ||
154 | + .cm_div = 0x00003000, | ||
155 | + }, | ||
156 | + | ||
157 | + [CPRMAN_CLOCK_ISP] = { | ||
158 | + .cm_ctl = 0x00000244, | ||
159 | + .cm_div = 0x00003000, | ||
160 | + }, | ||
161 | + | ||
162 | + [CPRMAN_CLOCK_V3D] = { | ||
163 | + .cm_ctl = 0, /* unknown */ | ||
164 | + .cm_div = 0 | ||
165 | + }, | ||
166 | + | ||
167 | + [CPRMAN_CLOCK_CAM0] = { | ||
168 | + .cm_ctl = 0x00000000, | ||
169 | + .cm_div = 0x00000000, | ||
170 | + }, | ||
171 | + | ||
172 | + [CPRMAN_CLOCK_CAM1] = { | ||
173 | + .cm_ctl = 0x00000000, | ||
174 | + .cm_div = 0x00000000, | ||
175 | + }, | ||
176 | + | ||
177 | + [CPRMAN_CLOCK_CCP2] = { | ||
178 | + .cm_ctl = 0, /* unknown */ | ||
179 | + .cm_div = 0 | ||
180 | + }, | ||
181 | + | ||
182 | + [CPRMAN_CLOCK_DSI0E] = { | ||
183 | + .cm_ctl = 0x00000000, | ||
184 | + .cm_div = 0x00000000, | ||
185 | + }, | ||
186 | + | ||
187 | + [CPRMAN_CLOCK_DSI0P] = { | ||
188 | + .cm_ctl = 0x00000000, | ||
189 | + .cm_div = 0x00000000, | ||
190 | + }, | ||
191 | + | ||
192 | + [CPRMAN_CLOCK_DPI] = { | ||
193 | + .cm_ctl = 0x00000000, | ||
194 | + .cm_div = 0x00000000, | ||
195 | + }, | ||
196 | + | ||
197 | + [CPRMAN_CLOCK_GP0] = { | ||
198 | + .cm_ctl = 0x00000200, | ||
199 | + .cm_div = 0x00000000, | ||
200 | + }, | ||
201 | + | ||
202 | + [CPRMAN_CLOCK_GP1] = { | ||
203 | + .cm_ctl = 0x00000096, | ||
204 | + .cm_div = 0x00014000, | ||
205 | + }, | ||
206 | + | ||
207 | + [CPRMAN_CLOCK_GP2] = { | ||
208 | + .cm_ctl = 0x00000291, | ||
209 | + .cm_div = 0x00249f00, | ||
210 | + }, | ||
211 | + | ||
212 | + [CPRMAN_CLOCK_HSM] = { | ||
213 | + .cm_ctl = 0x00000000, | ||
214 | + .cm_div = 0x00000000, | ||
215 | + }, | ||
216 | + | ||
217 | + [CPRMAN_CLOCK_OTP] = { | ||
218 | + .cm_ctl = 0x00000091, | ||
219 | + .cm_div = 0x00004000, | ||
220 | + }, | ||
221 | + | ||
222 | + [CPRMAN_CLOCK_PCM] = { | ||
223 | + .cm_ctl = 0x00000200, | ||
224 | + .cm_div = 0x00000000, | ||
225 | + }, | ||
226 | + | ||
227 | + [CPRMAN_CLOCK_PWM] = { | ||
228 | + .cm_ctl = 0x00000200, | ||
229 | + .cm_div = 0x00000000, | ||
230 | + }, | ||
231 | + | ||
232 | + [CPRMAN_CLOCK_SLIM] = { | ||
233 | + .cm_ctl = 0x00000200, | ||
234 | + .cm_div = 0x00000000, | ||
235 | + }, | ||
236 | + | ||
237 | + [CPRMAN_CLOCK_SMI] = { | ||
238 | + .cm_ctl = 0x00000000, | ||
239 | + .cm_div = 0x00000000, | ||
240 | + }, | ||
241 | + | ||
242 | + [CPRMAN_CLOCK_TEC] = { | ||
243 | + .cm_ctl = 0x00000000, | ||
244 | + .cm_div = 0x00000000, | ||
245 | + }, | ||
246 | + | ||
247 | + [CPRMAN_CLOCK_TD0] = { | ||
248 | + .cm_ctl = 0, /* unknown */ | ||
249 | + .cm_div = 0 | ||
250 | + }, | ||
251 | + | ||
252 | + [CPRMAN_CLOCK_TD1] = { | ||
253 | + .cm_ctl = 0, /* unknown */ | ||
254 | + .cm_div = 0 | ||
255 | + }, | ||
256 | + | ||
257 | + [CPRMAN_CLOCK_TSENS] = { | ||
258 | + .cm_ctl = 0x00000091, | ||
259 | + .cm_div = 0x0000a000, | ||
260 | + }, | ||
261 | + | ||
262 | + [CPRMAN_CLOCK_TIMER] = { | ||
263 | + .cm_ctl = 0x00000291, | ||
264 | + .cm_div = 0x00013333, | ||
265 | + }, | ||
266 | + | ||
267 | + [CPRMAN_CLOCK_UART] = { | ||
268 | + .cm_ctl = 0x00000296, | ||
269 | + .cm_div = 0x0000a6ab, | ||
270 | + }, | ||
271 | + | ||
272 | + [CPRMAN_CLOCK_VEC] = { | ||
273 | + .cm_ctl = 0x00000097, | ||
274 | + .cm_div = 0x00002000, | ||
275 | + }, | ||
276 | + | ||
277 | + [CPRMAN_CLOCK_PULSE] = { | ||
278 | + .cm_ctl = 0, /* unknown */ | ||
279 | + .cm_div = 0 | ||
280 | + }, | ||
281 | + | ||
282 | + [CPRMAN_CLOCK_SDC] = { | ||
283 | + .cm_ctl = 0x00004006, | ||
284 | + .cm_div = 0x00003000, | ||
285 | + }, | ||
286 | + | ||
287 | + [CPRMAN_CLOCK_ARM] = { | ||
288 | + .cm_ctl = 0, /* unknown */ | ||
289 | + .cm_div = 0 | ||
290 | + }, | ||
291 | + | ||
292 | + [CPRMAN_CLOCK_AVEO] = { | ||
293 | + .cm_ctl = 0x00000000, | ||
294 | + .cm_div = 0x00000000, | ||
295 | + }, | ||
296 | + | ||
297 | + [CPRMAN_CLOCK_EMMC] = { | ||
298 | + .cm_ctl = 0x00000295, | ||
299 | + .cm_div = 0x00006000, | ||
300 | + }, | ||
301 | + | ||
302 | + [CPRMAN_CLOCK_EMMC2] = { | ||
303 | + .cm_ctl = 0, /* unknown */ | ||
304 | + .cm_div = 0 | ||
305 | + }, | ||
306 | +}; | ||
307 | + | ||
308 | #endif | ||
309 | diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c | ||
310 | index XXXXXXX..XXXXXXX 100644 | ||
311 | --- a/hw/misc/bcm2835_cprman.c | ||
312 | +++ b/hw/misc/bcm2835_cprman.c | ||
313 | @@ -XXX,XX +XXX,XX @@ | ||
314 | |||
315 | /* PLL */ | ||
316 | |||
317 | +static void pll_reset(DeviceState *dev) | ||
318 | +{ | ||
319 | + CprmanPllState *s = CPRMAN_PLL(dev); | ||
320 | + const PLLResetInfo *info = &PLL_RESET_INFO[s->id]; | ||
321 | + | ||
322 | + *s->reg_cm = info->cm; | ||
323 | + *s->reg_a2w_ctrl = info->a2w_ctrl; | ||
324 | + memcpy(s->reg_a2w_ana, info->a2w_ana, sizeof(info->a2w_ana)); | ||
325 | + *s->reg_a2w_frac = info->a2w_frac; | ||
326 | +} | ||
327 | + | ||
328 | static bool pll_is_locked(const CprmanPllState *pll) | ||
329 | { | ||
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 | -- | ||
387 | 2.20.1 | ||
388 | |||
389 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Luc Michel <luc@lmichel.fr> |
---|---|---|---|
2 | 2 | ||
3 | Save the high parts of the Zregs and all of the Pregs. | 3 | Add a clock input to the PL011 UART so we can compute the current baud |
4 | The ZCR_ELx registers are migrated via the CP mechanism. | 4 | rate and trace it. This is intended for developers who wish to use QEMU |
5 | to e.g. debug their firmware or to figure out the baud rate configured | ||
6 | by an unknown/closed source binary. | ||
5 | 7 | ||
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 8 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
7 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 9 | Signed-off-by: Luc Michel <luc@lmichel.fr> |
8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Tested-by: Guenter Roeck <linux@roeck-us.net> |
9 | Message-id: 20180123035349.24538-4-richard.henderson@linaro.org | 11 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
11 | --- | 13 | --- |
12 | target/arm/machine.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++ | 14 | include/hw/char/pl011.h | 1 + |
13 | 1 file changed, 53 insertions(+) | 15 | hw/char/pl011.c | 45 +++++++++++++++++++++++++++++++++++++++++ |
16 | hw/char/trace-events | 1 + | ||
17 | 3 files changed, 47 insertions(+) | ||
14 | 18 | ||
15 | diff --git a/target/arm/machine.c b/target/arm/machine.c | 19 | diff --git a/include/hw/char/pl011.h b/include/hw/char/pl011.h |
16 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/target/arm/machine.c | 21 | --- a/include/hw/char/pl011.h |
18 | +++ b/target/arm/machine.c | 22 | +++ b/include/hw/char/pl011.h |
19 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_iwmmxt = { | 23 | @@ -XXX,XX +XXX,XX @@ struct PL011State { |
20 | } | 24 | int read_trigger; |
25 | CharBackend chr; | ||
26 | qemu_irq irq[6]; | ||
27 | + Clock *clk; | ||
28 | const unsigned char *id; | ||
21 | }; | 29 | }; |
22 | 30 | ||
23 | +#ifdef TARGET_AARCH64 | 31 | diff --git a/hw/char/pl011.c b/hw/char/pl011.c |
24 | +/* The expression ARM_MAX_VQ - 2 is 0 for pure AArch32 build, | 32 | index XXXXXXX..XXXXXXX 100644 |
25 | + * and ARMPredicateReg is actively empty. This triggers errors | 33 | --- a/hw/char/pl011.c |
26 | + * in the expansion of the VMSTATE macros. | 34 | +++ b/hw/char/pl011.c |
27 | + */ | 35 | @@ -XXX,XX +XXX,XX @@ |
36 | #include "hw/char/pl011.h" | ||
37 | #include "hw/irq.h" | ||
38 | #include "hw/sysbus.h" | ||
39 | +#include "hw/qdev-clock.h" | ||
40 | #include "migration/vmstate.h" | ||
41 | #include "chardev/char-fe.h" | ||
42 | #include "qemu/log.h" | ||
43 | @@ -XXX,XX +XXX,XX @@ static void pl011_set_read_trigger(PL011State *s) | ||
44 | s->read_trigger = 1; | ||
45 | } | ||
46 | |||
47 | +static unsigned int pl011_get_baudrate(const PL011State *s) | ||
48 | +{ | ||
49 | + uint64_t clk; | ||
28 | + | 50 | + |
29 | +static bool sve_needed(void *opaque) | 51 | + if (s->fbrd == 0) { |
30 | +{ | 52 | + return 0; |
31 | + ARMCPU *cpu = opaque; | 53 | + } |
32 | + CPUARMState *env = &cpu->env; | ||
33 | + | 54 | + |
34 | + return arm_feature(env, ARM_FEATURE_SVE); | 55 | + clk = clock_get_hz(s->clk); |
56 | + return (clk / ((s->ibrd << 6) + s->fbrd)) << 2; | ||
35 | +} | 57 | +} |
36 | + | 58 | + |
37 | +/* The first two words of each Zreg is stored in VFP state. */ | 59 | +static void pl011_trace_baudrate_change(const PL011State *s) |
38 | +static const VMStateDescription vmstate_zreg_hi_reg = { | 60 | +{ |
39 | + .name = "cpu/sve/zreg_hi", | 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", | ||
40 | + .version_id = 1, | 100 | + .version_id = 1, |
41 | + .minimum_version_id = 1, | 101 | + .minimum_version_id = 1, |
42 | + .fields = (VMStateField[]) { | 102 | + .fields = (VMStateField[]) { |
43 | + VMSTATE_UINT64_SUB_ARRAY(d, ARMVectorReg, 2, ARM_MAX_VQ - 2), | 103 | + VMSTATE_CLOCK(clk, PL011State), |
44 | + VMSTATE_END_OF_LIST() | 104 | + VMSTATE_END_OF_LIST() |
45 | + } | 105 | + } |
46 | +}; | 106 | +}; |
47 | + | 107 | + |
48 | +static const VMStateDescription vmstate_preg_reg = { | 108 | static const VMStateDescription vmstate_pl011 = { |
49 | + .name = "cpu/sve/preg", | 109 | .name = "pl011", |
50 | + .version_id = 1, | 110 | .version_id = 2, |
51 | + .minimum_version_id = 1, | 111 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_pl011 = { |
52 | + .fields = (VMStateField[]) { | 112 | VMSTATE_INT32(read_count, PL011State), |
53 | + VMSTATE_UINT64_ARRAY(p, ARMPredicateReg, 2 * ARM_MAX_VQ / 8), | 113 | VMSTATE_INT32(read_trigger, PL011State), |
54 | + VMSTATE_END_OF_LIST() | 114 | VMSTATE_END_OF_LIST() |
55 | + } | 115 | + }, |
56 | +}; | 116 | + .subsections = (const VMStateDescription * []) { |
57 | + | 117 | + &vmstate_pl011_clock, |
58 | +static const VMStateDescription vmstate_sve = { | 118 | + NULL |
59 | + .name = "cpu/sve", | ||
60 | + .version_id = 1, | ||
61 | + .minimum_version_id = 1, | ||
62 | + .needed = sve_needed, | ||
63 | + .fields = (VMStateField[]) { | ||
64 | + VMSTATE_STRUCT_ARRAY(env.vfp.zregs, ARMCPU, 32, 0, | ||
65 | + vmstate_zreg_hi_reg, ARMVectorReg), | ||
66 | + VMSTATE_STRUCT_ARRAY(env.vfp.pregs, ARMCPU, 17, 0, | ||
67 | + vmstate_preg_reg, ARMPredicateReg), | ||
68 | + VMSTATE_END_OF_LIST() | ||
69 | + } | ||
70 | +}; | ||
71 | +#endif /* AARCH64 */ | ||
72 | + | ||
73 | static bool m_needed(void *opaque) | ||
74 | { | ||
75 | ARMCPU *cpu = opaque; | ||
76 | @@ -XXX,XX +XXX,XX @@ const VMStateDescription vmstate_arm_cpu = { | ||
77 | &vmstate_pmsav7, | ||
78 | &vmstate_pmsav8, | ||
79 | &vmstate_m_security, | ||
80 | +#ifdef TARGET_AARCH64 | ||
81 | + &vmstate_sve, | ||
82 | +#endif | ||
83 | NULL | ||
84 | } | 119 | } |
85 | }; | 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" | ||
86 | -- | 143 | -- |
87 | 2.16.1 | 144 | 2.20.1 |
88 | 145 | ||
89 | 146 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Luc Michel <luc@lmichel.fr> | ||
1 | 2 | ||
3 | Connect the 'uart-out' clock from the CPRMAN to the PL011 instance. | ||
4 | |||
5 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
6 | Signed-off-by: Luc Michel <luc@lmichel.fr> | ||
7 | Tested-by: Guenter Roeck <linux@roeck-us.net> | ||
8 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
10 | --- | ||
11 | hw/arm/bcm2835_peripherals.c | 2 ++ | ||
12 | 1 file changed, 2 insertions(+) | ||
13 | |||
14 | diff --git a/hw/arm/bcm2835_peripherals.c b/hw/arm/bcm2835_peripherals.c | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/hw/arm/bcm2835_peripherals.c | ||
17 | +++ b/hw/arm/bcm2835_peripherals.c | ||
18 | @@ -XXX,XX +XXX,XX @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp) | ||
19 | } | ||
20 | memory_region_add_subregion(&s->peri_mr, CPRMAN_OFFSET, | ||
21 | sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->cprman), 0)); | ||
22 | + qdev_connect_clock_in(DEVICE(&s->uart0), "clk", | ||
23 | + qdev_get_clock_out(DEVICE(&s->cprman), "uart-out")); | ||
24 | |||
25 | memory_region_add_subregion(&s->peri_mr, ARMCTRL_IC_OFFSET, | ||
26 | sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->ic), 0)); | ||
27 | -- | ||
28 | 2.20.1 | ||
29 | |||
30 | diff view generated by jsdifflib |
1 | From: Andrey Smirnov <andrew.smirnov@gmail.com> | 1 | From: Shashi Mallela <shashi.mallela@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Add enough code to emulate i.MX2 watchdog IP block so it would be | 3 | Generic watchdog device model implementation as per ARM SBSA v6.0 |
4 | possible to reboot the machine running Linux Guest. | ||
5 | 4 | ||
6 | Cc: Peter Maydell <peter.maydell@linaro.org> | 5 | Signed-off-by: Shashi Mallela <shashi.mallela@linaro.org> |
7 | Cc: Jason Wang <jasowang@redhat.com> | 6 | Message-id: 20201027015927.29495-2-shashi.mallela@linaro.org |
8 | Cc: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
9 | Cc: Marcel Apfelbaum <marcel.apfelbaum@zoho.com> | ||
10 | Cc: Michael S. Tsirkin <mst@redhat.com> | ||
11 | Cc: qemu-devel@nongnu.org | ||
12 | Cc: qemu-arm@nongnu.org | ||
13 | Cc: yurovsky@gmail.com | ||
14 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
15 | Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> | ||
16 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
17 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
18 | --- | 9 | --- |
19 | hw/misc/Makefile.objs | 1 + | 10 | include/hw/watchdog/sbsa_gwdt.h | 79 +++++++++ |
20 | include/hw/misc/imx2_wdt.h | 33 +++++++++++++++++ | 11 | hw/watchdog/sbsa_gwdt.c | 293 ++++++++++++++++++++++++++++++++ |
21 | hw/misc/imx2_wdt.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++ | 12 | hw/arm/Kconfig | 1 + |
22 | 3 files changed, 123 insertions(+) | 13 | hw/watchdog/Kconfig | 3 + |
23 | create mode 100644 include/hw/misc/imx2_wdt.h | 14 | hw/watchdog/meson.build | 1 + |
24 | create mode 100644 hw/misc/imx2_wdt.c | 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 | ||
25 | 18 | ||
26 | diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs | 19 | diff --git a/include/hw/watchdog/sbsa_gwdt.h b/include/hw/watchdog/sbsa_gwdt.h |
27 | index XXXXXXX..XXXXXXX 100644 | ||
28 | --- a/hw/misc/Makefile.objs | ||
29 | +++ b/hw/misc/Makefile.objs | ||
30 | @@ -XXX,XX +XXX,XX @@ obj-$(CONFIG_IMX) += imx25_ccm.o | ||
31 | obj-$(CONFIG_IMX) += imx6_ccm.o | ||
32 | obj-$(CONFIG_IMX) += imx6_src.o | ||
33 | obj-$(CONFIG_IMX) += imx7_ccm.o | ||
34 | +obj-$(CONFIG_IMX) += imx2_wdt.o | ||
35 | obj-$(CONFIG_MILKYMIST) += milkymist-hpdmc.o | ||
36 | obj-$(CONFIG_MILKYMIST) += milkymist-pfpu.o | ||
37 | obj-$(CONFIG_MAINSTONE) += mst_fpga.o | ||
38 | diff --git a/include/hw/misc/imx2_wdt.h b/include/hw/misc/imx2_wdt.h | ||
39 | new file mode 100644 | 20 | new file mode 100644 |
40 | index XXXXXXX..XXXXXXX | 21 | index XXXXXXX..XXXXXXX |
41 | --- /dev/null | 22 | --- /dev/null |
42 | +++ b/include/hw/misc/imx2_wdt.h | 23 | +++ b/include/hw/watchdog/sbsa_gwdt.h |
43 | @@ -XXX,XX +XXX,XX @@ | 24 | @@ -XXX,XX +XXX,XX @@ |
44 | +/* | 25 | +/* |
45 | + * Copyright (c) 2017, Impinj, Inc. | 26 | + * Copyright (c) 2020 Linaro Limited |
46 | + * | 27 | + * |
47 | + * i.MX2 Watchdog IP block | 28 | + * Authors: |
48 | + * | 29 | + * Shashi Mallela <shashi.mallela@linaro.org> |
49 | + * Author: Andrey Smirnov <andrew.smirnov@gmail.com> | 30 | + * |
50 | + * | 31 | + * This work is licensed under the terms of the GNU GPL, version 2 or (at your |
51 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | 32 | + * option) any later version. See the COPYING file in the top-level directory. |
52 | + * See the COPYING file in the top-level directory. | 33 | + * |
53 | + */ | 34 | + */ |
54 | + | 35 | + |
55 | +#ifndef IMX2_WDT_H | 36 | +#ifndef WDT_SBSA_GWDT_H |
56 | +#define IMX2_WDT_H | 37 | +#define WDT_SBSA_GWDT_H |
57 | + | 38 | + |
39 | +#include "qemu/bitops.h" | ||
58 | +#include "hw/sysbus.h" | 40 | +#include "hw/sysbus.h" |
59 | + | 41 | +#include "hw/irq.h" |
60 | +#define TYPE_IMX2_WDT "imx2.wdt" | 42 | + |
61 | +#define IMX2_WDT(obj) OBJECT_CHECK(IMX2WdtState, (obj), TYPE_IMX2_WDT) | 43 | +#define TYPE_WDT_SBSA "sbsa_gwdt" |
62 | + | 44 | +#define SBSA_GWDT(obj) \ |
63 | +enum IMX2WdtRegisters { | 45 | + OBJECT_CHECK(SBSA_GWDTState, (obj), TYPE_WDT_SBSA) |
64 | + IMX2_WDT_WCR = 0x0000, | 46 | +#define SBSA_GWDT_CLASS(klass) \ |
65 | + IMX2_WDT_REG_NUM = 0x0008 / sizeof(uint16_t) + 1, | 47 | + OBJECT_CLASS_CHECK(SBSA_GWDTClass, (klass), TYPE_WDT_SBSA) |
66 | +}; | 48 | +#define SBSA_GWDT_GET_CLASS(obj) \ |
67 | + | 49 | + OBJECT_GET_CLASS(SBSA_GWDTClass, (obj), TYPE_WDT_SBSA) |
68 | + | 50 | + |
69 | +typedef struct IMX2WdtState { | 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 { | ||
70 | + /* <private> */ | 85 | + /* <private> */ |
71 | + SysBusDevice parent_obj; | 86 | + SysBusDevice parent_obj; |
72 | + | 87 | + |
73 | + MemoryRegion mmio; | 88 | + /*< public >*/ |
74 | +} IMX2WdtState; | 89 | + MemoryRegion rmmio; |
75 | + | 90 | + MemoryRegion cmmio; |
76 | +#endif /* IMX7_SNVS_H */ | 91 | + qemu_irq irq; |
77 | diff --git a/hw/misc/imx2_wdt.c b/hw/misc/imx2_wdt.c | 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 | ||
78 | new file mode 100644 | 105 | new file mode 100644 |
79 | index XXXXXXX..XXXXXXX | 106 | index XXXXXXX..XXXXXXX |
80 | --- /dev/null | 107 | --- /dev/null |
81 | +++ b/hw/misc/imx2_wdt.c | 108 | +++ b/hw/watchdog/sbsa_gwdt.c |
82 | @@ -XXX,XX +XXX,XX @@ | 109 | @@ -XXX,XX +XXX,XX @@ |
83 | +/* | 110 | +/* |
84 | + * Copyright (c) 2018, Impinj, Inc. | 111 | + * Generic watchdog device model for SBSA |
85 | + * | 112 | + * |
86 | + * i.MX2 Watchdog IP block | 113 | + * The watchdog device has been implemented as revision 1 variant of |
87 | + * | 114 | + * the ARM SBSA specification v6.0 |
88 | + * Author: Andrey Smirnov <andrew.smirnov@gmail.com> | 115 | + * (https://developer.arm.com/documentation/den0029/d?lang=en) |
89 | + * | 116 | + * |
90 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | 117 | + * Copyright Linaro.org 2020 |
91 | + * See the COPYING file in the top-level directory. | 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 | + * | ||
92 | + */ | 125 | + */ |
93 | + | 126 | + |
94 | +#include "qemu/osdep.h" | 127 | +#include "qemu/osdep.h" |
95 | +#include "qemu/bitops.h" | 128 | +#include "sysemu/reset.h" |
96 | +#include "sysemu/watchdog.h" | 129 | +#include "sysemu/watchdog.h" |
97 | + | 130 | +#include "hw/watchdog/sbsa_gwdt.h" |
98 | +#include "hw/misc/imx2_wdt.h" | 131 | +#include "qemu/timer.h" |
99 | + | 132 | +#include "migration/vmstate.h" |
100 | +#define IMX2_WDT_WCR_WDA BIT(5) /* -> External Reset WDOG_B */ | 133 | +#include "qemu/log.h" |
101 | +#define IMX2_WDT_WCR_SRS BIT(4) /* -> Software Reset Signal */ | 134 | +#include "qemu/module.h" |
102 | + | 135 | + |
103 | +static uint64_t imx2_wdt_read(void *opaque, hwaddr addr, | 136 | +static WatchdogTimerModel model = { |
104 | + unsigned int size) | 137 | + .wdt_name = TYPE_WDT_SBSA, |
105 | +{ | 138 | + .wdt_description = "SBSA-compliant generic watchdog device", |
106 | + return 0; | 139 | +}; |
107 | +} | 140 | + |
108 | + | 141 | +static const VMStateDescription vmstate_sbsa_gwdt = { |
109 | +static void imx2_wdt_write(void *opaque, hwaddr addr, | 142 | + .name = "sbsa-gwdt", |
110 | + uint64_t value, unsigned int size) | 143 | + .version_id = 1, |
111 | +{ | 144 | + .minimum_version_id = 1, |
112 | + if (addr == IMX2_WDT_WCR && | 145 | + .fields = (VMStateField[]) { |
113 | + (value & (IMX2_WDT_WCR_WDA | IMX2_WDT_WCR_SRS))) { | 146 | + VMSTATE_TIMER_PTR(timer, SBSA_GWDTState), |
147 | + VMSTATE_UINT32(wcs, SBSA_GWDTState), | ||
148 | + VMSTATE_UINT32(worl, SBSA_GWDTState), | ||
149 | + VMSTATE_UINT32(woru, SBSA_GWDTState), | ||
150 | + VMSTATE_UINT32(wcvl, SBSA_GWDTState), | ||
151 | + VMSTATE_UINT32(wcvu, SBSA_GWDTState), | ||
152 | + VMSTATE_END_OF_LIST() | ||
153 | + } | ||
154 | +}; | ||
155 | + | ||
156 | +typedef enum WdtRefreshType { | ||
157 | + EXPLICIT_REFRESH = 0, | ||
158 | + TIMEOUT_REFRESH = 1, | ||
159 | +} WdtRefreshType; | ||
160 | + | ||
161 | +static uint64_t sbsa_gwdt_rread(void *opaque, hwaddr addr, unsigned int size) | ||
162 | +{ | ||
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 | + } | ||
178 | + return ret; | ||
179 | +} | ||
180 | + | ||
181 | +static uint64_t sbsa_gwdt_read(void *opaque, hwaddr addr, unsigned int size) | ||
182 | +{ | ||
183 | + SBSA_GWDTState *s = SBSA_GWDT(opaque); | ||
184 | + uint32_t ret = 0; | ||
185 | + | ||
186 | + switch (addr) { | ||
187 | + case SBSA_GWDT_WCS: | ||
188 | + ret = s->wcs; | ||
189 | + break; | ||
190 | + case SBSA_GWDT_WOR: | ||
191 | + ret = s->worl; | ||
192 | + break; | ||
193 | + case SBSA_GWDT_WORU: | ||
194 | + ret = s->woru; | ||
195 | + break; | ||
196 | + case SBSA_GWDT_WCV: | ||
197 | + ret = s->wcvl; | ||
198 | + break; | ||
199 | + case SBSA_GWDT_WCVU: | ||
200 | + ret = s->wcvu; | ||
201 | + break; | ||
202 | + case SBSA_GWDT_W_IIDR: | ||
203 | + ret = s->id; | ||
204 | + break; | ||
205 | + default: | ||
206 | + qemu_log_mask(LOG_GUEST_ERROR, "bad address in control frame read :" | ||
207 | + " 0x%x\n", (int)addr); | ||
208 | + } | ||
209 | + return ret; | ||
210 | +} | ||
211 | + | ||
212 | +static void sbsa_gwdt_update_timer(SBSA_GWDTState *s, WdtRefreshType rtype) | ||
213 | +{ | ||
214 | + uint64_t timeout = 0; | ||
215 | + | ||
216 | + timer_del(s->timer); | ||
217 | + | ||
218 | + if (s->wcs & SBSA_GWDT_WCS_EN) { | ||
219 | + /* | ||
220 | + * Extract the upper 16 bits from woru & 32 bits from worl | ||
221 | + * registers to construct the 48 bit offset value | ||
222 | + */ | ||
223 | + timeout = s->woru; | ||
224 | + timeout <<= 32; | ||
225 | + timeout |= s->worl; | ||
226 | + timeout = muldiv64(timeout, NANOSECONDS_PER_SECOND, SBSA_TIMER_FREQ); | ||
227 | + timeout += qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); | ||
228 | + | ||
229 | + if ((rtype == EXPLICIT_REFRESH) || ((rtype == TIMEOUT_REFRESH) && | ||
230 | + (!(s->wcs & SBSA_GWDT_WCS_WS0)))) { | ||
231 | + /* store the current timeout value into compare registers */ | ||
232 | + s->wcvu = timeout >> 32; | ||
233 | + s->wcvl = timeout; | ||
234 | + } | ||
235 | + timer_mod(s->timer, timeout); | ||
236 | + } | ||
237 | +} | ||
238 | + | ||
239 | +static void sbsa_gwdt_rwrite(void *opaque, hwaddr offset, uint64_t data, | ||
240 | + unsigned size) { | ||
241 | + SBSA_GWDTState *s = SBSA_GWDT(opaque); | ||
242 | + | ||
243 | + if (offset == SBSA_GWDT_WRR) { | ||
244 | + s->wcs &= ~(SBSA_GWDT_WCS_WS0 | SBSA_GWDT_WCS_WS1); | ||
245 | + | ||
246 | + sbsa_gwdt_update_timer(s, EXPLICIT_REFRESH); | ||
247 | + } else { | ||
248 | + qemu_log_mask(LOG_GUEST_ERROR, "bad address in refresh frame write :" | ||
249 | + " 0x%x\n", (int)offset); | ||
250 | + } | ||
251 | +} | ||
252 | + | ||
253 | +static void sbsa_gwdt_write(void *opaque, hwaddr offset, uint64_t data, | ||
254 | + unsigned size) { | ||
255 | + SBSA_GWDTState *s = SBSA_GWDT(opaque); | ||
256 | + | ||
257 | + switch (offset) { | ||
258 | + case SBSA_GWDT_WCS: | ||
259 | + s->wcs = data & SBSA_GWDT_WCS_EN; | ||
260 | + qemu_set_irq(s->irq, 0); | ||
261 | + sbsa_gwdt_update_timer(s, EXPLICIT_REFRESH); | ||
262 | + break; | ||
263 | + | ||
264 | + case SBSA_GWDT_WOR: | ||
265 | + s->worl = data; | ||
266 | + s->wcs &= ~(SBSA_GWDT_WCS_WS0 | SBSA_GWDT_WCS_WS1); | ||
267 | + qemu_set_irq(s->irq, 0); | ||
268 | + sbsa_gwdt_update_timer(s, EXPLICIT_REFRESH); | ||
269 | + break; | ||
270 | + | ||
271 | + case SBSA_GWDT_WORU: | ||
272 | + s->woru = data & SBSA_GWDT_WOR_MASK; | ||
273 | + s->wcs &= ~(SBSA_GWDT_WCS_WS0 | SBSA_GWDT_WCS_WS1); | ||
274 | + qemu_set_irq(s->irq, 0); | ||
275 | + sbsa_gwdt_update_timer(s, EXPLICIT_REFRESH); | ||
276 | + break; | ||
277 | + | ||
278 | + case SBSA_GWDT_WCV: | ||
279 | + s->wcvl = data; | ||
280 | + break; | ||
281 | + | ||
282 | + case SBSA_GWDT_WCVU: | ||
283 | + s->wcvu = data; | ||
284 | + break; | ||
285 | + | ||
286 | + default: | ||
287 | + qemu_log_mask(LOG_GUEST_ERROR, "bad address in control frame write :" | ||
288 | + " 0x%x\n", (int)offset); | ||
289 | + } | ||
290 | + return; | ||
291 | +} | ||
292 | + | ||
293 | +static void wdt_sbsa_gwdt_reset(DeviceState *dev) | ||
294 | +{ | ||
295 | + SBSA_GWDTState *s = SBSA_GWDT(dev); | ||
296 | + | ||
297 | + timer_del(s->timer); | ||
298 | + | ||
299 | + s->wcs = 0; | ||
300 | + s->wcvl = 0; | ||
301 | + s->wcvu = 0; | ||
302 | + s->worl = 0; | ||
303 | + s->woru = 0; | ||
304 | + s->id = SBSA_GWDT_ID; | ||
305 | +} | ||
306 | + | ||
307 | +static void sbsa_gwdt_timer_sysinterrupt(void *opaque) | ||
308 | +{ | ||
309 | + SBSA_GWDTState *s = SBSA_GWDT(opaque); | ||
310 | + | ||
311 | + if (!(s->wcs & SBSA_GWDT_WCS_WS0)) { | ||
312 | + s->wcs |= SBSA_GWDT_WCS_WS0; | ||
313 | + sbsa_gwdt_update_timer(s, TIMEOUT_REFRESH); | ||
314 | + qemu_set_irq(s->irq, 1); | ||
315 | + } else { | ||
316 | + s->wcs |= SBSA_GWDT_WCS_WS1; | ||
317 | + qemu_log_mask(CPU_LOG_RESET, "Watchdog timer expired.\n"); | ||
318 | + /* | ||
319 | + * Reset the watchdog only if the guest gets notified about | ||
320 | + * expiry. watchdog_perform_action() may temporarily relinquish | ||
321 | + * the BQL; reset before triggering the action to avoid races with | ||
322 | + * sbsa_gwdt instructions. | ||
323 | + */ | ||
324 | + switch (get_watchdog_action()) { | ||
325 | + case WATCHDOG_ACTION_DEBUG: | ||
326 | + case WATCHDOG_ACTION_NONE: | ||
327 | + case WATCHDOG_ACTION_PAUSE: | ||
328 | + break; | ||
329 | + default: | ||
330 | + wdt_sbsa_gwdt_reset(DEVICE(s)); | ||
331 | + } | ||
114 | + watchdog_perform_action(); | 332 | + watchdog_perform_action(); |
115 | + } | 333 | + } |
116 | +} | 334 | +} |
117 | + | 335 | + |
118 | +static const MemoryRegionOps imx2_wdt_ops = { | 336 | +static const MemoryRegionOps sbsa_gwdt_rops = { |
119 | + .read = imx2_wdt_read, | 337 | + .read = sbsa_gwdt_rread, |
120 | + .write = imx2_wdt_write, | 338 | + .write = sbsa_gwdt_rwrite, |
121 | + .endianness = DEVICE_NATIVE_ENDIAN, | 339 | + .endianness = DEVICE_LITTLE_ENDIAN, |
122 | + .impl = { | 340 | + .valid.min_access_size = 4, |
123 | + /* | 341 | + .valid.max_access_size = 4, |
124 | + * Our device would not work correctly if the guest was doing | 342 | + .valid.unaligned = false, |
125 | + * unaligned access. This might not be a limitation on the | ||
126 | + * real device but in practice there is no reason for a guest | ||
127 | + * to access this device unaligned. | ||
128 | + */ | ||
129 | + .min_access_size = 4, | ||
130 | + .max_access_size = 4, | ||
131 | + .unaligned = false, | ||
132 | + }, | ||
133 | +}; | 343 | +}; |
134 | + | 344 | + |
135 | +static void imx2_wdt_realize(DeviceState *dev, Error **errp) | 345 | +static const MemoryRegionOps sbsa_gwdt_ops = { |
136 | +{ | 346 | + .read = sbsa_gwdt_read, |
137 | + IMX2WdtState *s = IMX2_WDT(dev); | 347 | + .write = sbsa_gwdt_write, |
138 | + | 348 | + .endianness = DEVICE_LITTLE_ENDIAN, |
139 | + memory_region_init_io(&s->mmio, OBJECT(dev), | 349 | + .valid.min_access_size = 4, |
140 | + &imx2_wdt_ops, s, | 350 | + .valid.max_access_size = 4, |
141 | + TYPE_IMX2_WDT".mmio", | 351 | + .valid.unaligned = false, |
142 | + IMX2_WDT_REG_NUM * sizeof(uint16_t)); | 352 | +}; |
143 | + sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->mmio); | 353 | + |
144 | +} | 354 | +static void wdt_sbsa_gwdt_realize(DeviceState *dev, Error **errp) |
145 | + | 355 | +{ |
146 | +static void imx2_wdt_class_init(ObjectClass *klass, void *data) | 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) | ||
147 | +{ | 379 | +{ |
148 | + DeviceClass *dc = DEVICE_CLASS(klass); | 380 | + DeviceClass *dc = DEVICE_CLASS(klass); |
149 | + | 381 | + |
150 | + dc->realize = imx2_wdt_realize; | 382 | + dc->realize = wdt_sbsa_gwdt_realize; |
383 | + dc->reset = wdt_sbsa_gwdt_reset; | ||
384 | + dc->hotpluggable = false; | ||
151 | + set_bit(DEVICE_CATEGORY_MISC, dc->categories); | 385 | + set_bit(DEVICE_CATEGORY_MISC, dc->categories); |
152 | +} | 386 | + dc->vmsd = &vmstate_sbsa_gwdt; |
153 | + | 387 | +} |
154 | +static const TypeInfo imx2_wdt_info = { | 388 | + |
155 | + .name = TYPE_IMX2_WDT, | 389 | +static const TypeInfo wdt_sbsa_gwdt_info = { |
156 | + .parent = TYPE_SYS_BUS_DEVICE, | 390 | + .class_init = wdt_sbsa_gwdt_class_init, |
157 | + .instance_size = sizeof(IMX2WdtState), | 391 | + .parent = TYPE_SYS_BUS_DEVICE, |
158 | + .class_init = imx2_wdt_class_init, | 392 | + .name = TYPE_WDT_SBSA, |
393 | + .instance_size = sizeof(SBSA_GWDTState), | ||
159 | +}; | 394 | +}; |
160 | + | 395 | + |
161 | +static WatchdogTimerModel model = { | 396 | +static void wdt_sbsa_gwdt_register_types(void) |
162 | + .wdt_name = "imx2-watchdog", | ||
163 | + .wdt_description = "i.MX2 Watchdog", | ||
164 | +}; | ||
165 | + | ||
166 | +static void imx2_wdt_register_type(void) | ||
167 | +{ | 397 | +{ |
168 | + watchdog_add_model(&model); | 398 | + watchdog_add_model(&model); |
169 | + type_register_static(&imx2_wdt_info); | 399 | + type_register_static(&wdt_sbsa_gwdt_info); |
170 | +} | 400 | +} |
171 | +type_init(imx2_wdt_register_type) | 401 | + |
402 | +type_init(wdt_sbsa_gwdt_register_types) | ||
403 | diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig | ||
404 | index XXXXXXX..XXXXXXX 100644 | ||
405 | --- a/hw/arm/Kconfig | ||
406 | +++ b/hw/arm/Kconfig | ||
407 | @@ -XXX,XX +XXX,XX @@ config SBSA_REF | ||
408 | select PL031 # RTC | ||
409 | select PL061 # GPIO | ||
410 | select USB_EHCI_SYSBUS | ||
411 | + select WDT_SBSA | ||
412 | |||
413 | config SABRELITE | ||
414 | bool | ||
415 | diff --git a/hw/watchdog/Kconfig b/hw/watchdog/Kconfig | ||
416 | index XXXXXXX..XXXXXXX 100644 | ||
417 | --- a/hw/watchdog/Kconfig | ||
418 | +++ b/hw/watchdog/Kconfig | ||
419 | @@ -XXX,XX +XXX,XX @@ config WDT_DIAG288 | ||
420 | |||
421 | config WDT_IMX2 | ||
422 | bool | ||
423 | + | ||
424 | +config WDT_SBSA | ||
425 | + bool | ||
426 | diff --git a/hw/watchdog/meson.build b/hw/watchdog/meson.build | ||
427 | index XXXXXXX..XXXXXXX 100644 | ||
428 | --- a/hw/watchdog/meson.build | ||
429 | +++ b/hw/watchdog/meson.build | ||
430 | @@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_WDT_IB700', if_true: files('wdt_ib700.c')) | ||
431 | softmmu_ss.add(when: 'CONFIG_WDT_DIAG288', if_true: files('wdt_diag288.c')) | ||
432 | softmmu_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('wdt_aspeed.c')) | ||
433 | softmmu_ss.add(when: 'CONFIG_WDT_IMX2', if_true: files('wdt_imx2.c')) | ||
434 | +softmmu_ss.add(when: 'CONFIG_WDT_SBSA', if_true: files('sbsa_gwdt.c')) | ||
172 | -- | 435 | -- |
173 | 2.16.1 | 436 | 2.20.1 |
174 | 437 | ||
175 | 438 | diff view generated by jsdifflib |
1 | In order to support derived exceptions (exceptions generated in | 1 | From: Shashi Mallela <shashi.mallela@linaro.org> |
---|---|---|---|
2 | the course of trying to take an exception), we need to be able | ||
3 | to handle prioritizing whether to take the original exception | ||
4 | or the derived exception. | ||
5 | 2 | ||
6 | We do this by introducing a new function | 3 | Included the newly implemented SBSA generic watchdog device model into |
7 | armv7m_nvic_set_pending_derived() which the exception-taking code in | 4 | SBSA platform |
8 | helper.c will call when a derived exception occurs. Derived | ||
9 | exceptions are dealt with mostly like normal pending exceptions, so | ||
10 | we share the implementation with the armv7m_nvic_set_pending() | ||
11 | function. | ||
12 | 5 | ||
13 | Note that the way we structure this is significantly different | 6 | Signed-off-by: Shashi Mallela <shashi.mallela@linaro.org> |
14 | from the v8M Arm ARM pseudocode: that does all the prioritization | 7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
15 | logic in the DerivedLateArrival() function, whereas we choose to | 8 | Message-id: 20201027015927.29495-3-shashi.mallela@linaro.org |
16 | let the existing "identify highest priority exception" logic | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
17 | do the prioritization for us. The effect is the same, though. | 10 | --- |
11 | hw/arm/sbsa-ref.c | 23 +++++++++++++++++++++++ | ||
12 | 1 file changed, 23 insertions(+) | ||
18 | 13 | ||
19 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 14 | diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c |
20 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
21 | Message-id: 1517324542-6607-2-git-send-email-peter.maydell@linaro.org | ||
22 | --- | ||
23 | target/arm/cpu.h | 13 ++++++++++ | ||
24 | hw/intc/armv7m_nvic.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++-- | ||
25 | hw/intc/trace-events | 2 +- | ||
26 | 3 files changed, 80 insertions(+), 3 deletions(-) | ||
27 | |||
28 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | ||
29 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
30 | --- a/target/arm/cpu.h | 16 | --- a/hw/arm/sbsa-ref.c |
31 | +++ b/target/arm/cpu.h | 17 | +++ b/hw/arm/sbsa-ref.c |
32 | @@ -XXX,XX +XXX,XX @@ static inline bool armv7m_nvic_can_take_pending_exception(void *opaque) | 18 | @@ -XXX,XX +XXX,XX @@ |
33 | * of architecturally banked exceptions. | 19 | #include "hw/qdev-properties.h" |
34 | */ | 20 | #include "hw/usb.h" |
35 | void armv7m_nvic_set_pending(void *opaque, int irq, bool secure); | 21 | #include "hw/char/pl011.h" |
36 | +/** | 22 | +#include "hw/watchdog/sbsa_gwdt.h" |
37 | + * armv7m_nvic_set_pending_derived: mark this derived exception as pending | 23 | #include "net/net.h" |
38 | + * @opaque: the NVIC | 24 | #include "qom/object.h" |
39 | + * @irq: the exception number to mark pending | 25 | |
40 | + * @secure: false for non-banked exceptions or for the nonsecure | 26 | @@ -XXX,XX +XXX,XX @@ enum { |
41 | + * version of a banked exception, true for the secure version of a banked | 27 | SBSA_GIC_DIST, |
42 | + * exception. | 28 | SBSA_GIC_REDIST, |
43 | + * | 29 | SBSA_SECURE_EC, |
44 | + * Similar to armv7m_nvic_set_pending(), but specifically for derived | 30 | + SBSA_GWDT, |
45 | + * exceptions (exceptions generated in the course of trying to take | 31 | + SBSA_GWDT_REFRESH, |
46 | + * a different exception). | 32 | + SBSA_GWDT_CONTROL, |
47 | + */ | 33 | SBSA_SMMU, |
48 | +void armv7m_nvic_set_pending_derived(void *opaque, int irq, bool secure); | 34 | SBSA_UART, |
49 | /** | 35 | SBSA_RTC, |
50 | * armv7m_nvic_acknowledge_irq: make highest priority pending exception active | 36 | @@ -XXX,XX +XXX,XX @@ static const MemMapEntry sbsa_ref_memmap[] = { |
51 | * @opaque: the NVIC | 37 | [SBSA_GIC_DIST] = { 0x40060000, 0x00010000 }, |
52 | diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c | 38 | [SBSA_GIC_REDIST] = { 0x40080000, 0x04000000 }, |
53 | index XXXXXXX..XXXXXXX 100644 | 39 | [SBSA_SECURE_EC] = { 0x50000000, 0x00001000 }, |
54 | --- a/hw/intc/armv7m_nvic.c | 40 | + [SBSA_GWDT_REFRESH] = { 0x50010000, 0x00001000 }, |
55 | +++ b/hw/intc/armv7m_nvic.c | 41 | + [SBSA_GWDT_CONTROL] = { 0x50011000, 0x00001000 }, |
56 | @@ -XXX,XX +XXX,XX @@ static void armv7m_nvic_clear_pending(void *opaque, int irq, bool secure) | 42 | [SBSA_UART] = { 0x60000000, 0x00001000 }, |
57 | } | 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)); | ||
58 | } | 55 | } |
59 | 56 | ||
60 | -void armv7m_nvic_set_pending(void *opaque, int irq, bool secure) | 57 | +static void create_wdt(const SBSAMachineState *sms) |
61 | +static void do_armv7m_nvic_set_pending(void *opaque, int irq, bool secure, | 58 | +{ |
62 | + bool derived) | 59 | + hwaddr rbase = sbsa_ref_memmap[SBSA_GWDT_REFRESH].base; |
63 | { | 60 | + hwaddr cbase = sbsa_ref_memmap[SBSA_GWDT_CONTROL].base; |
64 | + /* Pend an exception, including possibly escalating it to HardFault. | 61 | + DeviceState *dev = qdev_new(TYPE_WDT_SBSA); |
65 | + * | 62 | + SysBusDevice *s = SYS_BUS_DEVICE(dev); |
66 | + * This function handles both "normal" pending of interrupts and | 63 | + int irq = sbsa_ref_irqmap[SBSA_GWDT]; |
67 | + * exceptions, and also derived exceptions (ones which occur as | ||
68 | + * a result of trying to take some other exception). | ||
69 | + * | ||
70 | + * If derived == true, the caller guarantees that we are part way through | ||
71 | + * trying to take an exception (but have not yet called | ||
72 | + * armv7m_nvic_acknowledge_irq() to make it active), and so: | ||
73 | + * - s->vectpending is the "original exception" we were trying to take | ||
74 | + * - irq is the "derived exception" | ||
75 | + * - nvic_exec_prio(s) gives the priority before exception entry | ||
76 | + * Here we handle the prioritization logic which the pseudocode puts | ||
77 | + * in the DerivedLateArrival() function. | ||
78 | + */ | ||
79 | + | 64 | + |
80 | NVICState *s = (NVICState *)opaque; | 65 | + sysbus_realize_and_unref(s, &error_fatal); |
81 | bool banked = exc_is_banked(irq); | 66 | + sysbus_mmio_map(s, 0, rbase); |
82 | VecInfo *vec; | 67 | + sysbus_mmio_map(s, 1, cbase); |
83 | @@ -XXX,XX +XXX,XX @@ void armv7m_nvic_set_pending(void *opaque, int irq, bool secure) | 68 | + sysbus_connect_irq(s, 0, qdev_get_gpio_in(sms->gic, irq)); |
84 | |||
85 | vec = (banked && secure) ? &s->sec_vectors[irq] : &s->vectors[irq]; | ||
86 | |||
87 | - trace_nvic_set_pending(irq, secure, vec->enabled, vec->prio); | ||
88 | + trace_nvic_set_pending(irq, secure, derived, vec->enabled, vec->prio); | ||
89 | + | ||
90 | + if (derived) { | ||
91 | + /* Derived exceptions are always synchronous. */ | ||
92 | + assert(irq >= ARMV7M_EXCP_HARD && irq < ARMV7M_EXCP_PENDSV); | ||
93 | + | ||
94 | + if (irq == ARMV7M_EXCP_DEBUG && | ||
95 | + exc_group_prio(s, vec->prio, secure) >= nvic_exec_prio(s)) { | ||
96 | + /* DebugMonitorFault, but its priority is lower than the | ||
97 | + * preempted exception priority: just ignore it. | ||
98 | + */ | ||
99 | + return; | ||
100 | + } | ||
101 | + | ||
102 | + if (irq == ARMV7M_EXCP_HARD && vec->prio >= s->vectpending_prio) { | ||
103 | + /* If this is a terminal exception (one which means we cannot | ||
104 | + * take the original exception, like a failure to read its | ||
105 | + * vector table entry), then we must take the derived exception. | ||
106 | + * If the derived exception can't take priority over the | ||
107 | + * original exception, then we go into Lockup. | ||
108 | + * | ||
109 | + * For QEMU, we rely on the fact that a derived exception is | ||
110 | + * terminal if and only if it's reported to us as HardFault, | ||
111 | + * which saves having to have an extra argument is_terminal | ||
112 | + * that we'd only use in one place. | ||
113 | + */ | ||
114 | + cpu_abort(&s->cpu->parent_obj, | ||
115 | + "Lockup: can't take terminal derived exception " | ||
116 | + "(original exception priority %d)\n", | ||
117 | + s->vectpending_prio); | ||
118 | + } | ||
119 | + /* We now continue with the same code as for a normal pending | ||
120 | + * exception, which will cause us to pend the derived exception. | ||
121 | + * We'll then take either the original or the derived exception | ||
122 | + * based on which is higher priority by the usual mechanism | ||
123 | + * for selecting the highest priority pending interrupt. | ||
124 | + */ | ||
125 | + } | ||
126 | |||
127 | if (irq >= ARMV7M_EXCP_HARD && irq < ARMV7M_EXCP_PENDSV) { | ||
128 | /* If a synchronous exception is pending then it may be | ||
129 | @@ -XXX,XX +XXX,XX @@ void armv7m_nvic_set_pending(void *opaque, int irq, bool secure) | ||
130 | } | ||
131 | } | ||
132 | |||
133 | +void armv7m_nvic_set_pending(void *opaque, int irq, bool secure) | ||
134 | +{ | ||
135 | + do_armv7m_nvic_set_pending(opaque, irq, secure, false); | ||
136 | +} | 69 | +} |
137 | + | 70 | + |
138 | +void armv7m_nvic_set_pending_derived(void *opaque, int irq, bool secure) | 71 | static DeviceState *gpio_key_dev; |
139 | +{ | 72 | static void sbsa_ref_powerdown_req(Notifier *n, void *opaque) |
140 | + do_armv7m_nvic_set_pending(opaque, irq, secure, true); | 73 | { |
141 | +} | 74 | @@ -XXX,XX +XXX,XX @@ static void sbsa_ref_init(MachineState *machine) |
75 | |||
76 | create_rtc(sms); | ||
77 | |||
78 | + create_wdt(sms); | ||
142 | + | 79 | + |
143 | /* Make pending IRQ active. */ | 80 | create_gpio(sms); |
144 | bool armv7m_nvic_acknowledge_irq(void *opaque) | 81 | |
145 | { | 82 | create_ahci(sms); |
146 | diff --git a/hw/intc/trace-events b/hw/intc/trace-events | ||
147 | index XXXXXXX..XXXXXXX 100644 | ||
148 | --- a/hw/intc/trace-events | ||
149 | +++ b/hw/intc/trace-events | ||
150 | @@ -XXX,XX +XXX,XX @@ nvic_set_prio(int irq, bool secure, uint8_t prio) "NVIC set irq %d secure-bank % | ||
151 | nvic_irq_update(int vectpending, int pendprio, int exception_prio, int level) "NVIC vectpending %d pending prio %d exception_prio %d: setting irq line to %d" | ||
152 | nvic_escalate_prio(int irq, int irqprio, int runprio) "NVIC escalating irq %d to HardFault: insufficient priority %d >= %d" | ||
153 | nvic_escalate_disabled(int irq) "NVIC escalating irq %d to HardFault: disabled" | ||
154 | -nvic_set_pending(int irq, bool secure, int en, int prio) "NVIC set pending irq %d secure-bank %d (enabled: %d priority %d)" | ||
155 | +nvic_set_pending(int irq, bool secure, bool derived, int en, int prio) "NVIC set pending irq %d secure-bank %d derived %d (enabled: %d priority %d)" | ||
156 | nvic_clear_pending(int irq, bool secure, int en, int prio) "NVIC clear pending irq %d secure-bank %d (enabled: %d priority %d)" | ||
157 | nvic_set_pending_level(int irq) "NVIC set pending: irq %d higher prio than vectpending: setting irq line to 1" | ||
158 | nvic_acknowledge_irq(int irq, int prio, bool targets_secure) "NVIC acknowledge IRQ: %d now active (prio %d targets_secure %d)" | ||
159 | -- | 83 | -- |
160 | 2.16.1 | 84 | 2.20.1 |
161 | 85 | ||
162 | 86 | diff view generated by jsdifflib |
1 | In the v8M architecture, if the process of taking an exception | 1 | In ptimer_reload(), we call the callback function provided by the |
---|---|---|---|
2 | results in a further exception this is called a derived exception | 2 | timer device that is using the ptimer. This callback might disable |
3 | (for example, an MPU exception when writing the exception frame to | 3 | the ptimer. The code mostly handles this correctly, except that |
4 | memory). If the derived exception happens while pushing the initial | 4 | we'll still print the warning about "Timer with delta zero, |
5 | stack frame, we must ignore any subsequent possible exception | 5 | disabling" if the now-disabled timer happened to be set such that it |
6 | pushing the callee-saves registers. | 6 | would fire again immediately if it were enabled (eg because the |
7 | limit/reload value is zero). | ||
7 | 8 | ||
8 | In preparation for making the stack writes check for exceptions, | 9 | Suppress the spurious warning message and the unnecessary |
9 | add a return value from v7m_push_stack() and a new parameter to | 10 | repeat-deletion of the underlying timer in this case. |
10 | v7m_exception_taken(), so that the former can tell the latter that | ||
11 | it needs to ignore failures to write to the stack. We also plumb | ||
12 | the argument through to v7m_push_callee_stack(), which is where | ||
13 | the code to ignore the failures will be. | ||
14 | |||
15 | (Note that the v8M ARM pseudocode structures this slightly differently: | ||
16 | derived exceptions cause the attempt to process the original | ||
17 | exception to be abandoned; then at the top level it calls | ||
18 | DerivedLateArrival to prioritize the derived exception and call | ||
19 | TakeException from there. We choose to let the NVIC do the prioritization | ||
20 | and continue forward with a call to TakeException which will then | ||
21 | take either the original or the derived exception. The effect is | ||
22 | the same, but this structure works better for QEMU because we don't | ||
23 | have a convenient top level place to do the abandon-and-retry logic.) | ||
24 | 11 | ||
25 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
26 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 13 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> |
27 | Message-id: 1517324542-6607-4-git-send-email-peter.maydell@linaro.org | 14 | Message-id: 20201015151829.14656-2-peter.maydell@linaro.org |
28 | --- | 15 | --- |
29 | target/arm/helper.c | 35 +++++++++++++++++++++++------------ | 16 | hw/core/ptimer.c | 4 ++++ |
30 | 1 file changed, 23 insertions(+), 12 deletions(-) | 17 | 1 file changed, 4 insertions(+) |
31 | 18 | ||
32 | diff --git a/target/arm/helper.c b/target/arm/helper.c | 19 | diff --git a/hw/core/ptimer.c b/hw/core/ptimer.c |
33 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
34 | --- a/target/arm/helper.c | 21 | --- a/hw/core/ptimer.c |
35 | +++ b/target/arm/helper.c | 22 | +++ b/hw/core/ptimer.c |
36 | @@ -XXX,XX +XXX,XX @@ static uint32_t arm_v7m_load_vector(ARMCPU *cpu, int exc, bool targets_secure) | 23 | @@ -XXX,XX +XXX,XX @@ static void ptimer_reload(ptimer_state *s, int delta_adjust) |
37 | return addr; | ||
38 | } | ||
39 | |||
40 | -static void v7m_push_callee_stack(ARMCPU *cpu, uint32_t lr, bool dotailchain) | ||
41 | +static void v7m_push_callee_stack(ARMCPU *cpu, uint32_t lr, bool dotailchain, | ||
42 | + bool ignore_faults) | ||
43 | { | ||
44 | /* For v8M, push the callee-saves register part of the stack frame. | ||
45 | * Compare the v8M pseudocode PushCalleeStack(). | ||
46 | @@ -XXX,XX +XXX,XX @@ static void v7m_push_callee_stack(ARMCPU *cpu, uint32_t lr, bool dotailchain) | ||
47 | *frame_sp_p = frameptr; | ||
48 | } | ||
49 | |||
50 | -static void v7m_exception_taken(ARMCPU *cpu, uint32_t lr, bool dotailchain) | ||
51 | +static void v7m_exception_taken(ARMCPU *cpu, uint32_t lr, bool dotailchain, | ||
52 | + bool ignore_stackfaults) | ||
53 | { | ||
54 | /* Do the "take the exception" parts of exception entry, | ||
55 | * but not the pushing of state to the stack. This is | ||
56 | @@ -XXX,XX +XXX,XX @@ static void v7m_exception_taken(ARMCPU *cpu, uint32_t lr, bool dotailchain) | ||
57 | */ | ||
58 | if (lr & R_V7M_EXCRET_DCRS_MASK && | ||
59 | !(dotailchain && (lr & R_V7M_EXCRET_ES_MASK))) { | ||
60 | - v7m_push_callee_stack(cpu, lr, dotailchain); | ||
61 | + v7m_push_callee_stack(cpu, lr, dotailchain, | ||
62 | + ignore_stackfaults); | ||
63 | } | ||
64 | lr |= R_V7M_EXCRET_DCRS_MASK; | ||
65 | } | ||
66 | @@ -XXX,XX +XXX,XX @@ static void v7m_exception_taken(ARMCPU *cpu, uint32_t lr, bool dotailchain) | ||
67 | env->thumb = addr & 1; | ||
68 | } | ||
69 | |||
70 | -static void v7m_push_stack(ARMCPU *cpu) | ||
71 | +static bool v7m_push_stack(ARMCPU *cpu) | ||
72 | { | ||
73 | /* Do the "set up stack frame" part of exception entry, | ||
74 | * similar to pseudocode PushStack(). | ||
75 | + * Return true if we generate a derived exception (and so | ||
76 | + * should ignore further stack faults trying to process | ||
77 | + * that derived exception.) | ||
78 | */ | ||
79 | CPUARMState *env = &cpu->env; | ||
80 | uint32_t xpsr = xpsr_read(env); | ||
81 | @@ -XXX,XX +XXX,XX @@ static void v7m_push_stack(ARMCPU *cpu) | ||
82 | v7m_push(env, env->regs[2]); | ||
83 | v7m_push(env, env->regs[1]); | ||
84 | v7m_push(env, env->regs[0]); | ||
85 | + | ||
86 | + return false; | ||
87 | } | ||
88 | |||
89 | static void do_v7m_exception_exit(ARMCPU *cpu) | ||
90 | @@ -XXX,XX +XXX,XX @@ static void do_v7m_exception_exit(ARMCPU *cpu) | ||
91 | if (sfault) { | ||
92 | env->v7m.sfsr |= R_V7M_SFSR_INVER_MASK; | ||
93 | armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_SECURE, false); | ||
94 | - v7m_exception_taken(cpu, excret, true); | ||
95 | + v7m_exception_taken(cpu, excret, true, false); | ||
96 | qemu_log_mask(CPU_LOG_INT, "...taking SecureFault on existing " | ||
97 | "stackframe: failed EXC_RETURN.ES validity check\n"); | ||
98 | return; | ||
99 | @@ -XXX,XX +XXX,XX @@ static void do_v7m_exception_exit(ARMCPU *cpu) | ||
100 | */ | ||
101 | env->v7m.cfsr[env->v7m.secure] |= R_V7M_CFSR_INVPC_MASK; | ||
102 | armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_USAGE, env->v7m.secure); | ||
103 | - v7m_exception_taken(cpu, excret, true); | ||
104 | + v7m_exception_taken(cpu, excret, true, false); | ||
105 | qemu_log_mask(CPU_LOG_INT, "...taking UsageFault on existing " | ||
106 | "stackframe: failed exception return integrity check\n"); | ||
107 | return; | ||
108 | @@ -XXX,XX +XXX,XX @@ static void do_v7m_exception_exit(ARMCPU *cpu) | ||
109 | /* Take a SecureFault on the current stack */ | ||
110 | env->v7m.sfsr |= R_V7M_SFSR_INVIS_MASK; | ||
111 | armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_SECURE, false); | ||
112 | - v7m_exception_taken(cpu, excret, true); | ||
113 | + v7m_exception_taken(cpu, excret, true, false); | ||
114 | qemu_log_mask(CPU_LOG_INT, "...taking SecureFault on existing " | ||
115 | "stackframe: failed exception return integrity " | ||
116 | "signature check\n"); | ||
117 | @@ -XXX,XX +XXX,XX @@ static void do_v7m_exception_exit(ARMCPU *cpu) | ||
118 | armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_USAGE, | ||
119 | env->v7m.secure); | ||
120 | env->v7m.cfsr[env->v7m.secure] |= R_V7M_CFSR_INVPC_MASK; | ||
121 | - v7m_exception_taken(cpu, excret, true); | ||
122 | + v7m_exception_taken(cpu, excret, true, false); | ||
123 | qemu_log_mask(CPU_LOG_INT, "...taking UsageFault on existing " | ||
124 | "stackframe: failed exception return integrity " | ||
125 | "check\n"); | ||
126 | @@ -XXX,XX +XXX,XX @@ static void do_v7m_exception_exit(ARMCPU *cpu) | ||
127 | /* Take an INVPC UsageFault by pushing the stack again; | ||
128 | * we know we're v7M so this is never a Secure UsageFault. | ||
129 | */ | ||
130 | + bool ignore_stackfaults; | ||
131 | + | ||
132 | assert(!arm_feature(env, ARM_FEATURE_V8)); | ||
133 | armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_USAGE, false); | ||
134 | env->v7m.cfsr[env->v7m.secure] |= R_V7M_CFSR_INVPC_MASK; | ||
135 | - v7m_push_stack(cpu); | ||
136 | - v7m_exception_taken(cpu, excret, false); | ||
137 | + ignore_stackfaults = v7m_push_stack(cpu); | ||
138 | + v7m_exception_taken(cpu, excret, false, ignore_stackfaults); | ||
139 | qemu_log_mask(CPU_LOG_INT, "...taking UsageFault on new stackframe: " | ||
140 | "failed exception return integrity check\n"); | ||
141 | return; | ||
142 | @@ -XXX,XX +XXX,XX @@ void arm_v7m_cpu_do_interrupt(CPUState *cs) | ||
143 | ARMCPU *cpu = ARM_CPU(cs); | ||
144 | CPUARMState *env = &cpu->env; | ||
145 | uint32_t lr; | ||
146 | + bool ignore_stackfaults; | ||
147 | |||
148 | arm_log_exception(cs->exception_index); | ||
149 | |||
150 | @@ -XXX,XX +XXX,XX @@ void arm_v7m_cpu_do_interrupt(CPUState *cs) | ||
151 | lr |= R_V7M_EXCRET_MODE_MASK; | ||
152 | } | 24 | } |
153 | 25 | ||
154 | - v7m_push_stack(cpu); | 26 | if (delta == 0) { |
155 | - v7m_exception_taken(cpu, lr, false); | 27 | + if (s->enabled == 0) { |
156 | + ignore_stackfaults = v7m_push_stack(cpu); | 28 | + /* trigger callback disabled the timer already */ |
157 | + v7m_exception_taken(cpu, lr, false, ignore_stackfaults); | 29 | + return; |
158 | qemu_log_mask(CPU_LOG_INT, "... as %d\n", env->v7m.exception); | 30 | + } |
159 | } | 31 | if (!qtest_enabled()) { |
160 | 32 | fprintf(stderr, "Timer with delta zero, disabling\n"); | |
33 | } | ||
161 | -- | 34 | -- |
162 | 2.16.1 | 35 | 2.20.1 |
163 | 36 | ||
164 | 37 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | The armv7m systick timer is a 24-bit decrementing, wrap-on-zero, | |
2 | clear-on-write counter. Our current implementation has various | ||
3 | bugs and dubious workarounds in it (for instance see | ||
4 | https://bugs.launchpad.net/qemu/+bug/1872237). | ||
5 | |||
6 | We have an implementation of a simple decrementing counter | ||
7 | and we put a lot of effort into making sure it handles the | ||
8 | interesting corner cases (like "spend a cycle at 0 before | ||
9 | reloading") -- ptimer. | ||
10 | |||
11 | Rewrite the systick timer to use a ptimer rather than | ||
12 | a raw QEMU timer. | ||
13 | |||
14 | Unfortunately this is a migration compatibility break, | ||
15 | which will affect all M-profile boards. | ||
16 | |||
17 | Among other bugs, this fixes | ||
18 | https://bugs.launchpad.net/qemu/+bug/1872237 : | ||
19 | now writes to SYST_CVR when the timer is enabled correctly | ||
20 | do nothing; when the timer is enabled via SYST_CSR.ENABLE, | ||
21 | the ptimer code will (because of POLICY_NO_IMMEDIATE_RELOAD) | ||
22 | arrange that after one timer tick the counter is reloaded | ||
23 | from SYST_RVR and then counts down from there, as the | ||
24 | architecture requires. | ||
25 | |||
26 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
27 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
28 | Message-id: 20201015151829.14656-3-peter.maydell@linaro.org | ||
29 | --- | ||
30 | include/hw/timer/armv7m_systick.h | 3 +- | ||
31 | hw/timer/armv7m_systick.c | 124 +++++++++++++----------------- | ||
32 | 2 files changed, 54 insertions(+), 73 deletions(-) | ||
33 | |||
34 | diff --git a/include/hw/timer/armv7m_systick.h b/include/hw/timer/armv7m_systick.h | ||
35 | index XXXXXXX..XXXXXXX 100644 | ||
36 | --- a/include/hw/timer/armv7m_systick.h | ||
37 | +++ b/include/hw/timer/armv7m_systick.h | ||
38 | @@ -XXX,XX +XXX,XX @@ | ||
39 | |||
40 | #include "hw/sysbus.h" | ||
41 | #include "qom/object.h" | ||
42 | +#include "hw/ptimer.h" | ||
43 | |||
44 | #define TYPE_SYSTICK "armv7m_systick" | ||
45 | |||
46 | @@ -XXX,XX +XXX,XX @@ struct SysTickState { | ||
47 | uint32_t control; | ||
48 | uint32_t reload; | ||
49 | int64_t tick; | ||
50 | - QEMUTimer *timer; | ||
51 | + ptimer_state *ptimer; | ||
52 | MemoryRegion iomem; | ||
53 | qemu_irq irq; | ||
54 | }; | ||
55 | diff --git a/hw/timer/armv7m_systick.c b/hw/timer/armv7m_systick.c | ||
56 | index XXXXXXX..XXXXXXX 100644 | ||
57 | --- a/hw/timer/armv7m_systick.c | ||
58 | +++ b/hw/timer/armv7m_systick.c | ||
59 | @@ -XXX,XX +XXX,XX @@ static inline int64_t systick_scale(SysTickState *s) | ||
60 | } | ||
61 | } | ||
62 | |||
63 | -static void systick_reload(SysTickState *s, int reset) | ||
64 | -{ | ||
65 | - /* The Cortex-M3 Devices Generic User Guide says that "When the | ||
66 | - * ENABLE bit is set to 1, the counter loads the RELOAD value from the | ||
67 | - * SYST RVR register and then counts down". So, we need to check the | ||
68 | - * ENABLE bit before reloading the value. | ||
69 | - */ | ||
70 | - trace_systick_reload(); | ||
71 | - | ||
72 | - if ((s->control & SYSTICK_ENABLE) == 0) { | ||
73 | - return; | ||
74 | - } | ||
75 | - | ||
76 | - if (reset) { | ||
77 | - s->tick = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); | ||
78 | - } | ||
79 | - s->tick += (s->reload + 1) * systick_scale(s); | ||
80 | - timer_mod(s->timer, s->tick); | ||
81 | -} | ||
82 | - | ||
83 | static void systick_timer_tick(void *opaque) | ||
84 | { | ||
85 | SysTickState *s = (SysTickState *)opaque; | ||
86 | @@ -XXX,XX +XXX,XX @@ static void systick_timer_tick(void *opaque) | ||
87 | /* Tell the NVIC to pend the SysTick exception */ | ||
88 | qemu_irq_pulse(s->irq); | ||
89 | } | ||
90 | - if (s->reload == 0) { | ||
91 | - s->control &= ~SYSTICK_ENABLE; | ||
92 | - } else { | ||
93 | - systick_reload(s, 0); | ||
94 | + if (ptimer_get_limit(s->ptimer) == 0) { | ||
95 | + /* | ||
96 | + * Timer expiry with SYST_RVR zero disables the timer | ||
97 | + * (but doesn't clear SYST_CSR.ENABLE) | ||
98 | + */ | ||
99 | + ptimer_stop(s->ptimer); | ||
100 | } | ||
101 | } | ||
102 | |||
103 | @@ -XXX,XX +XXX,XX @@ static MemTxResult systick_read(void *opaque, hwaddr addr, uint64_t *data, | ||
104 | s->control &= ~SYSTICK_COUNTFLAG; | ||
105 | break; | ||
106 | case 0x4: /* SysTick Reload Value. */ | ||
107 | - val = s->reload; | ||
108 | + val = ptimer_get_limit(s->ptimer); | ||
109 | break; | ||
110 | case 0x8: /* SysTick Current Value. */ | ||
111 | - { | ||
112 | - int64_t t; | ||
113 | - | ||
114 | - if ((s->control & SYSTICK_ENABLE) == 0) { | ||
115 | - val = 0; | ||
116 | - break; | ||
117 | - } | ||
118 | - t = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); | ||
119 | - if (t >= s->tick) { | ||
120 | - val = 0; | ||
121 | - break; | ||
122 | - } | ||
123 | - val = ((s->tick - (t + 1)) / systick_scale(s)) + 1; | ||
124 | - /* The interrupt in triggered when the timer reaches zero. | ||
125 | - However the counter is not reloaded until the next clock | ||
126 | - tick. This is a hack to return zero during the first tick. */ | ||
127 | - if (val > s->reload) { | ||
128 | - val = 0; | ||
129 | - } | ||
130 | + val = ptimer_get_count(s->ptimer); | ||
131 | break; | ||
132 | - } | ||
133 | case 0xc: /* SysTick Calibration Value. */ | ||
134 | val = 10000; | ||
135 | break; | ||
136 | @@ -XXX,XX +XXX,XX @@ static MemTxResult systick_write(void *opaque, hwaddr addr, | ||
137 | switch (addr) { | ||
138 | case 0x0: /* SysTick Control and Status. */ | ||
139 | { | ||
140 | - uint32_t oldval = s->control; | ||
141 | + uint32_t oldval; | ||
142 | |||
143 | + ptimer_transaction_begin(s->ptimer); | ||
144 | + oldval = s->control; | ||
145 | s->control &= 0xfffffff8; | ||
146 | s->control |= value & 7; | ||
147 | + | ||
148 | if ((oldval ^ value) & SYSTICK_ENABLE) { | ||
149 | - int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); | ||
150 | if (value & SYSTICK_ENABLE) { | ||
151 | - if (s->tick) { | ||
152 | - s->tick += now; | ||
153 | - timer_mod(s->timer, s->tick); | ||
154 | - } else { | ||
155 | - systick_reload(s, 1); | ||
156 | - } | ||
157 | + /* | ||
158 | + * Always reload the period in case board code has | ||
159 | + * changed system_clock_scale. If we ever replace that | ||
160 | + * global with a more sensible API then we might be able | ||
161 | + * to set the period only when it actually changes. | ||
162 | + */ | ||
163 | + ptimer_set_period(s->ptimer, systick_scale(s)); | ||
164 | + ptimer_run(s->ptimer, 0); | ||
165 | } else { | ||
166 | - timer_del(s->timer); | ||
167 | - s->tick -= now; | ||
168 | - if (s->tick < 0) { | ||
169 | - s->tick = 0; | ||
170 | - } | ||
171 | + ptimer_stop(s->ptimer); | ||
172 | } | ||
173 | } else if ((oldval ^ value) & SYSTICK_CLKSOURCE) { | ||
174 | - /* This is a hack. Force the timer to be reloaded | ||
175 | - when the reference clock is changed. */ | ||
176 | - systick_reload(s, 1); | ||
177 | + ptimer_set_period(s->ptimer, systick_scale(s)); | ||
178 | } | ||
179 | + ptimer_transaction_commit(s->ptimer); | ||
180 | break; | ||
181 | } | ||
182 | case 0x4: /* SysTick Reload Value. */ | ||
183 | - s->reload = value; | ||
184 | + ptimer_transaction_begin(s->ptimer); | ||
185 | + ptimer_set_limit(s->ptimer, value & 0xffffff, 0); | ||
186 | + ptimer_transaction_commit(s->ptimer); | ||
187 | break; | ||
188 | - case 0x8: /* SysTick Current Value. Writes reload the timer. */ | ||
189 | - systick_reload(s, 1); | ||
190 | + case 0x8: /* SysTick Current Value. */ | ||
191 | + /* | ||
192 | + * Writing any value clears SYST_CVR to zero and clears | ||
193 | + * SYST_CSR.COUNTFLAG. The counter will then reload from SYST_RVR | ||
194 | + * on the next clock edge unless SYST_RVR is zero. | ||
195 | + */ | ||
196 | + ptimer_transaction_begin(s->ptimer); | ||
197 | + if (ptimer_get_limit(s->ptimer) == 0) { | ||
198 | + ptimer_stop(s->ptimer); | ||
199 | + } | ||
200 | + ptimer_set_count(s->ptimer, 0); | ||
201 | s->control &= ~SYSTICK_COUNTFLAG; | ||
202 | + ptimer_transaction_commit(s->ptimer); | ||
203 | break; | ||
204 | default: | ||
205 | qemu_log_mask(LOG_GUEST_ERROR, | ||
206 | @@ -XXX,XX +XXX,XX @@ static void systick_reset(DeviceState *dev) | ||
207 | */ | ||
208 | assert(system_clock_scale != 0); | ||
209 | |||
210 | + ptimer_transaction_begin(s->ptimer); | ||
211 | s->control = 0; | ||
212 | - s->reload = 0; | ||
213 | - s->tick = 0; | ||
214 | - timer_del(s->timer); | ||
215 | + ptimer_stop(s->ptimer); | ||
216 | + ptimer_set_count(s->ptimer, 0); | ||
217 | + ptimer_set_limit(s->ptimer, 0, 0); | ||
218 | + ptimer_set_period(s->ptimer, systick_scale(s)); | ||
219 | + ptimer_transaction_commit(s->ptimer); | ||
220 | } | ||
221 | |||
222 | static void systick_instance_init(Object *obj) | ||
223 | @@ -XXX,XX +XXX,XX @@ static void systick_instance_init(Object *obj) | ||
224 | static void systick_realize(DeviceState *dev, Error **errp) | ||
225 | { | ||
226 | SysTickState *s = SYSTICK(dev); | ||
227 | - s->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, systick_timer_tick, s); | ||
228 | + s->ptimer = ptimer_init(systick_timer_tick, s, | ||
229 | + PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD | | ||
230 | + PTIMER_POLICY_NO_COUNTER_ROUND_DOWN | | ||
231 | + PTIMER_POLICY_NO_IMMEDIATE_RELOAD | | ||
232 | + PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT); | ||
233 | } | ||
234 | |||
235 | static const VMStateDescription vmstate_systick = { | ||
236 | .name = "armv7m_systick", | ||
237 | - .version_id = 1, | ||
238 | - .minimum_version_id = 1, | ||
239 | + .version_id = 2, | ||
240 | + .minimum_version_id = 2, | ||
241 | .fields = (VMStateField[]) { | ||
242 | VMSTATE_UINT32(control, SysTickState), | ||
243 | - VMSTATE_UINT32(reload, SysTickState), | ||
244 | VMSTATE_INT64(tick, SysTickState), | ||
245 | - VMSTATE_TIMER_PTR(timer, SysTickState), | ||
246 | + VMSTATE_PTIMER(ptimer, SysTickState), | ||
247 | VMSTATE_END_OF_LIST() | ||
248 | } | ||
249 | }; | ||
250 | -- | ||
251 | 2.20.1 | ||
252 | |||
253 | diff view generated by jsdifflib |